From patchwork Tue Jan 23 10:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pu Lehui X-Patchwork-Id: 13527170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39B96C47258 for ; Tue, 23 Jan 2024 10:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NmRgCfcJQ3MhlfNqWtMhcEW55mSWFrLuVyOROsLz9Ew=; b=Y2BzSxjCKNFGWb WB/J1RD1gepepouk9z5qPGVGUr0zo4DUPS99WH7a22fg03nc5sz4M4rxpuFlLdzk3o7wv+ohEBtlf qUOpda99zURg9L2TJgM34KNXE3mfmnj0yAw9K4DlN7AkJ6tKyFoQUUGtYp0q2EapML7KIB9T61Fwz KnMXhaHbFBOxvCcBRoSmn+4qxAPQkWrq5U4IpAN19RQnAotM82KjS/C1DMthCcke8SEC5s7PCDBeE hRryzZ0NXtlNXG97OJkdnR3C7hcvSz3odjD4rsWylWmsdnvNled5XuHBLVtMhwYtT+q/Tou1u4kPV UoOjq3gKpOI/jaDKvn3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSE4r-00Fwkw-2k; Tue, 23 Jan 2024 10:32:21 +0000 Received: from [45.249.212.56] (helo=dggsgout12.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSE4m-00FwgU-0T for linux-riscv@lists.infradead.org; Tue, 23 Jan 2024 10:32:19 +0000 Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TK3L82Ylcz4f3khK for ; Tue, 23 Jan 2024 18:32:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 44C2F1A038B for ; Tue, 23 Jan 2024 18:32:04 +0800 (CST) Received: from ultra.huawei.com (unknown [10.90.53.71]) by APP2 (Coremail) with SMTP id Syh0CgBHaQyfla9ldy79Bg--.53064S2; Tue, 23 Jan 2024 18:32:01 +0800 (CST) From: Pu Lehui To: bpf@vger.kernel.org, linux-riscv@lists.infradead.org, netdev@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Song Liu , Puranjay Mohan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Palmer Dabbelt , Luke Nelson , Pu Lehui , Pu Lehui Subject: [PATCH bpf-next 0/3] Use bpf_prog_pack for RV64 bpf trampoline Date: Tue, 23 Jan 2024 10:32:38 +0000 Message-Id: <20240123103241.2282122-1-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: Syh0CgBHaQyfla9ldy79Bg--.53064S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr43KF1rCFy8Ww4xtw1DZFb_yoW8Gw15pF 43uw13Cr4jqr9rWrZ3Wa18Zr1Sqw48u3y7Gr9rt34rCasYvFy8ZrnYgr4rAFWrGr95uw1r Zryj9ry5ua4UZ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9a14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x 0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2 zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF 4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_ WFyUJwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJr UvcSsGvfC2KfnxnUUI43ZEXa7VUbmsjUUUUUU== X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_023216_566693_37807585 X-CRM114-Status: UNSURE ( 7.52 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We used bpf_prog_pack to aggregate bpf programs into huge page to relieve the iTLB pressure on the system. We can apply it to bpf trampoline, as Song had been implemented it in core and x86 [0]. This patch is going to use bpf_prog_pack to RV64 bpf trampoline. Since Song and Puranjay have done a lot of work for bpf_prog_pack on RV64, implementing this function will be easy. But one thing to mention is that emit_call in RV64 will generate the maximum number of instructions during dry run, but during real patching it may be optimized to 1 instruction due to distance. This is no problem as it does not overflow the allocated RO image. Tests about regular trampoline and struct_ops trampoline have passed, as well as "test_verifier" with no failure cases. Link: https://lore.kernel.org/all/20231206224054.492250-1-song@kernel.org [0] Pu Lehui (3): bpf: Use precise image size for struct_ops trampoline bpf: Keep im address consistent between dry run and real patching riscv, bpf: Use bpf_prog_pack for RV64 bpf trampoline arch/arm64/net/bpf_jit_comp.c | 7 ++-- arch/riscv/net/bpf_jit_comp64.c | 66 +++++++++++++++++++++++---------- arch/s390/net/bpf_jit_comp.c | 7 ++-- arch/x86/net/bpf_jit_comp.c | 7 ++-- include/linux/bpf.h | 4 +- kernel/bpf/bpf_struct_ops.c | 4 +- kernel/bpf/trampoline.c | 43 +++++++++++---------- 7 files changed, 81 insertions(+), 57 deletions(-) Tested-by: Björn Töpel #riscv