From patchwork Fri Jun 2 06:59:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13264769 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A2053D6D; Fri, 2 Jun 2023 07:01:26 +0000 (UTC) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC2C18D; Fri, 2 Jun 2023 00:01:09 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 41be03b00d2f7-53f9a376f3eso1558164a12.0; Fri, 02 Jun 2023 00:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685689269; x=1688281269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZnG52d2Dc9v7SzDlLP9SHsRobLYh/Fr6zYq50STRQGE=; b=I+xCs901C/zEpAM2hx4qv5g3BCXtFOxN/KhotSi7GKPxdlyKQgmDGMoJPqDgSEmufL 8C5/wuewZpjMI+8sadDOjVVMxxB/tugR9dzs6rQYdLN1bq/7kuXt5VUjJz7xni/VyuEz jVgNSbKs7e5i1Jg4iFAwm1rPoP2mAPoH17mcvjaTZqAftdzv6aZ3bjUcuLSON4yNjUpx JifOW/fzMZhFnQ0bWCd4tkkv5KnyeCMiJ3P4lxWw4QmRkFeI94dVxdZ4r3JrnaYO2K1e oG+9bdnKUBct1IWHXisqiiO6MTXEzS30p+EOMdjgbfr+Fz8WFc8eJLjY641VF7PZojjg WxTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685689269; x=1688281269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZnG52d2Dc9v7SzDlLP9SHsRobLYh/Fr6zYq50STRQGE=; b=Nwv20pJSI43HXKXhltOhfqHcukMYgMTyENL+fmaX0jtIjUTE4jbfscGtopP4BNfyJ/ UFJ869zkwUPG8qMxVqQHDj+rUtjf72bs8dLxmQ43fsrbYdmh0+oWJeTn8HVZRgZ+dL1t Shd+CGI7Z8PtaeQIAG0CpEJfEA5xr5J3UTW+u7lrbC8qPwJQVQtwdj5rvivHQU5hb0mZ jKOszVfQGzqNcYfNwmDbB3T8693mb0mZD3zztyQ0PwqZyTQm/BB0WPa5MBd/7GRO9JNr 1rPr36UB6YLuHudlr2LUzlBbwDtxsHbPNX0Irj7Rd/g85ZMgxu5B7/G8DJbyaf+vIuFT KgFQ== X-Gm-Message-State: AC+VfDyZWFkuGrBMHI1Hczwgn7GkbohDtY3wMpWmvTlYaLJIw8s0RxcO VRzBU6efp02CF0647HbCNig= X-Google-Smtp-Source: ACHHUZ6jTUPbQ8booJg0HcNCVWgN0R74kwYWjIkCH9W7pLwScUj7HdcQpJCgkgA3sCxUlp7PqE545A== X-Received: by 2002:a17:902:d485:b0:1b1:8e8b:7f6a with SMTP id c5-20020a170902d48500b001b18e8b7f6amr1661443plg.27.1685689269110; Fri, 02 Jun 2023 00:01:09 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.24]) by smtp.gmail.com with ESMTPSA id jk11-20020a170903330b00b001ac7c725c1asm572716plb.6.2023.06.02.00.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:01:08 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: olsajiri@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benbjiang@tencent.com, iii@linux.ibm.com, imagedong@tencent.com, xukuohai@huawei.com, chantr4@gmail.com, zwisler@google.com, eddyz87@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 1/5] bpf: make MAX_BPF_FUNC_ARGS 14 Date: Fri, 2 Jun 2023 14:59:54 +0800 Message-Id: <20230602065958.2869555-2-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602065958.2869555-1-imagedong@tencent.com> References: <20230602065958.2869555-1-imagedong@tencent.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Menglong Dong According to the current kernel version, below is a statistics of the function arguments count: argument count | FUNC_PROTO count 7 | 367 8 | 196 9 | 71 10 | 43 11 | 22 12 | 10 13 | 15 14 | 4 15 | 0 16 | 1 It's hard to statisics the function count, so I use FUNC_PROTO in the btf of vmlinux instead. The function with 16 arguments is ZSTD_buildCTable(), which I think can be ignored. Therefore, let's make the maximum of function arguments count 14. It used to be 12, but it seems that there is no harm to make it big enough. Reviewed-by: Jiang Biao Signed-off-by: Menglong Dong --- include/linux/bpf.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f58895830ada..8b997779faf7 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -961,10 +961,10 @@ enum bpf_cgroup_storage_type { #define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX -/* The longest tracepoint has 12 args. - * See include/trace/bpf_probe.h +/* The maximun number of the kernel function arguments. + * Let's make it 14, for now. */ -#define MAX_BPF_FUNC_ARGS 12 +#define MAX_BPF_FUNC_ARGS 14 /* The maximum number of arguments passed through registers * a single function may have. @@ -2273,7 +2273,8 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, static inline bool bpf_tracing_ctx_access(int off, int size, enum bpf_access_type type) { - if (off < 0 || off >= sizeof(__u64) * MAX_BPF_FUNC_ARGS) + /* "+1" here is for FEXIT return value. */ + if (off < 0 || off >= sizeof(__u64) * (MAX_BPF_FUNC_ARGS + 1)) return false; if (type != BPF_READ) return false; From patchwork Fri Jun 2 06:59:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13264770 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CCC410E5; Fri, 2 Jun 2023 07:01:50 +0000 (UTC) Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93E210F7; Fri, 2 Jun 2023 00:01:45 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-1b0201d9a9eso14056645ad.0; Fri, 02 Jun 2023 00:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685689305; x=1688281305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y+8XVx3y8n6Y+GjpWRIOvXBpe4uvQy5qGkQZlRQFRg0=; b=N+IBxNfaEIuqvGiEZKF575Uz1GMX5RdE45EJ+L8x1xiZQZ52EdkdXcEkj8oeFko28p UYjox/Hgb1oaXLeEmm2Pzid/HA8aCf7I8J4c1qDpSMC/2+D+c2GhTdCrCYpq9wLTHKEk cjIpgv/A+X8mQNE4E+fGrIFiUHVLIuEnEVNhCf6LO+4MVtWtlI/ScSC0YRNR7ss+KonT NJWB2rOXdcKl5WSWq+km7QCECWRvVzJxrOkwkrq+xQfvS5rZAFpeNJHbvgdCX7fBCJ1i hr8R02gHQfhGflCnhbq3pwnxma+7YLxn2lwSvTNZN0yetVjDxO2xxZjyG8olHtQRcky5 MPuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685689305; x=1688281305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y+8XVx3y8n6Y+GjpWRIOvXBpe4uvQy5qGkQZlRQFRg0=; b=kFVbqfy7LqnQW/glAJ36y+aVB04jofWLOdIvOur1P7DFqiGm5AgAuOQFpgk0cfuYlG vgrGqdV2wqBKDffCu+M1cfpuIyVPjw+zBQyPlj+xGyvrgs2ShpQhn+55jVuuNUPqgqF1 ndjIyfGvNQb9TtMx8gCDHuxA0W8bSErJZ+KHGiEKVRMbb22qC7QOm5sa/bhBxFOgOJo2 9VCben9/GtPrCnyuNi3yx0e3tFcqieR6MRWK810Xtf5Mfbv7vzDM6FWOlRK9cTNj3tLG GmEi8G3o61GwrqFfbZ3zi0D2jhKQCkW1S57W5f44JdixNUCMypMOeH27MW4Y6+03NwOm eYDw== X-Gm-Message-State: AC+VfDyT2ByO39g8soNOtSEXiiNIet40NFsSji6TvjIN3jMqlbU26PJK 68jOBkr1QiFbZ3OzbOUx2RQ= X-Google-Smtp-Source: ACHHUZ5XVqfLLDqt1ZI58VmRXBUd4W0Yzih+gMXxKCZcG5sSrZ4wrnPynOB5f/eUI6gEa/9L166S+w== X-Received: by 2002:a17:903:189:b0:1af:ea40:34f2 with SMTP id z9-20020a170903018900b001afea4034f2mr1748773plg.11.1685689305084; Fri, 02 Jun 2023 00:01:45 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.24]) by smtp.gmail.com with ESMTPSA id jk11-20020a170903330b00b001ac7c725c1asm572716plb.6.2023.06.02.00.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:01:44 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: olsajiri@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benbjiang@tencent.com, iii@linux.ibm.com, imagedong@tencent.com, xukuohai@huawei.com, chantr4@gmail.com, zwisler@google.com, eddyz87@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 2/5] bpf, x86: allow function arguments up to 14 for TRACING Date: Fri, 2 Jun 2023 14:59:55 +0800 Message-Id: <20230602065958.2869555-3-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602065958.2869555-1-imagedong@tencent.com> References: <20230602065958.2869555-1-imagedong@tencent.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Menglong Dong For now, the BPF program of type BPF_PROG_TYPE_TRACING can only be used on the kernel functions whose arguments count less than 6. This is not friendly at all, as too many functions have arguments count more than 6. Therefore, let's enhance it by increasing the function arguments count allowed in arch_prepare_bpf_trampoline(), for now, only x86_64. For the case that we don't need to call origin function, which means without BPF_TRAMP_F_CALL_ORIG, we need only copy the function arguments that stored in the frame of the caller to current frame. The arguments of arg6-argN are stored in "$rbp + 0x18", we need copy them to "$rbp - regs_off + (6 * 8)". For the case with BPF_TRAMP_F_CALL_ORIG, we need prepare the arguments in stack before call origin function, which means we need alloc extra "8 * (arg_count - 6)" memory in the top of the stack. Note, there should not be any data be pushed to the stack before call the origin function. Then, we have to store rbx with 'mov' instead of 'push'. It works well for the FENTRY and FEXIT, I'm not sure if there are other complicated cases. Reviewed-by: Jiang Biao Signed-off-by: Menglong Dong --- v2: - instead EMIT4 with EMIT3_off32 for "lea" to prevent overflow - make MAX_BPF_FUNC_ARGS as the maximum argument count --- arch/x86/net/bpf_jit_comp.c | 96 +++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 15 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 1056bbf55b17..0e247bb7d6f6 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -1868,7 +1868,7 @@ static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_regs, * mov QWORD PTR [rbp-0x10],rdi * mov QWORD PTR [rbp-0x8],rsi */ - for (i = 0, j = 0; i < min(nr_regs, 6); i++) { + for (i = 0, j = 0; i < min(nr_regs, MAX_BPF_FUNC_ARGS); i++) { /* The arg_size is at most 16 bytes, enforced by the verifier. */ arg_size = m->arg_size[j]; if (arg_size > 8) { @@ -1876,10 +1876,22 @@ static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_regs, next_same_struct = !next_same_struct; } - emit_stx(prog, bytes_to_bpf_size(arg_size), - BPF_REG_FP, - i == 5 ? X86_REG_R9 : BPF_REG_1 + i, - -(stack_size - i * 8)); + if (i <= 5) { + /* store function arguments in regs */ + emit_stx(prog, bytes_to_bpf_size(arg_size), + BPF_REG_FP, + i == 5 ? X86_REG_R9 : BPF_REG_1 + i, + -(stack_size - i * 8)); + } else { + /* store function arguments in stack */ + emit_ldx(prog, bytes_to_bpf_size(arg_size), + BPF_REG_0, BPF_REG_FP, + (i - 6) * 8 + 0x18); + emit_stx(prog, bytes_to_bpf_size(arg_size), + BPF_REG_FP, + BPF_REG_0, + -(stack_size - i * 8)); + } j = next_same_struct ? j : j + 1; } @@ -1913,6 +1925,41 @@ static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_regs, } } +static void prepare_origin_stack(const struct btf_func_model *m, u8 **prog, + int nr_regs, int stack_size) +{ + int i, j, arg_size; + bool next_same_struct = false; + + if (nr_regs <= 6) + return; + + /* Prepare the function arguments in stack before call origin + * function. These arguments must be stored in the top of the + * stack. + */ + for (i = 0, j = 0; i < min(nr_regs, MAX_BPF_FUNC_ARGS); i++) { + /* The arg_size is at most 16 bytes, enforced by the verifier. */ + arg_size = m->arg_size[j]; + if (arg_size > 8) { + arg_size = 8; + next_same_struct = !next_same_struct; + } + + if (i > 5) { + emit_ldx(prog, bytes_to_bpf_size(arg_size), + BPF_REG_0, BPF_REG_FP, + (i - 6) * 8 + 0x18); + emit_stx(prog, bytes_to_bpf_size(arg_size), + BPF_REG_FP, + BPF_REG_0, + -(stack_size - (i - 6) * 8)); + } + + j = next_same_struct ? j : j + 1; + } +} + static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog, struct bpf_tramp_link *l, int stack_size, int run_ctx_off, bool save_ret) @@ -1938,7 +1985,7 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog, /* arg1: mov rdi, progs[i] */ emit_mov_imm64(&prog, BPF_REG_1, (long) p >> 32, (u32) (long) p); /* arg2: lea rsi, [rbp - ctx_cookie_off] */ - EMIT4(0x48, 0x8D, 0x75, -run_ctx_off); + EMIT3_off32(0x48, 0x8D, 0xB5, -run_ctx_off); if (emit_rsb_call(&prog, bpf_trampoline_enter(p), prog)) return -EINVAL; @@ -1954,7 +2001,7 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog, emit_nops(&prog, 2); /* arg1: lea rdi, [rbp - stack_size] */ - EMIT4(0x48, 0x8D, 0x7D, -stack_size); + EMIT3_off32(0x48, 0x8D, 0xBD, -stack_size); /* arg2: progs[i]->insnsi for interpreter */ if (!p->jited) emit_mov_imm64(&prog, BPF_REG_2, @@ -1984,7 +2031,7 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog, /* arg2: mov rsi, rbx <- start time in nsec */ emit_mov_reg(&prog, true, BPF_REG_2, BPF_REG_6); /* arg3: lea rdx, [rbp - run_ctx_off] */ - EMIT4(0x48, 0x8D, 0x55, -run_ctx_off); + EMIT3_off32(0x48, 0x8D, 0x95, -run_ctx_off); if (emit_rsb_call(&prog, bpf_trampoline_exit(p), prog)) return -EINVAL; @@ -2136,7 +2183,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i void *func_addr) { int i, ret, nr_regs = m->nr_args, stack_size = 0; - int regs_off, nregs_off, ip_off, run_ctx_off; + int regs_off, nregs_off, ip_off, run_ctx_off, arg_stack_off, rbx_off; struct bpf_tramp_links *fentry = &tlinks[BPF_TRAMP_FENTRY]; struct bpf_tramp_links *fexit = &tlinks[BPF_TRAMP_FEXIT]; struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN]; @@ -2150,8 +2197,10 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG) nr_regs += (m->arg_size[i] + 7) / 8 - 1; - /* x86-64 supports up to 6 arguments. 7+ can be added in the future */ - if (nr_regs > 6) + /* x86-64 supports up to MAX_BPF_FUNC_ARGS arguments. 1-6 + * are passed through regs, the remains are through stack. + */ + if (nr_regs > MAX_BPF_FUNC_ARGS) return -ENOTSUPP; /* Generated trampoline stack layout: @@ -2170,7 +2219,14 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i * * RBP - ip_off [ traced function ] BPF_TRAMP_F_IP_ARG flag * + * RBP - rbx_off [ rbx value ] always + * * RBP - run_ctx_off [ bpf_tramp_run_ctx ] + * + * [ stack_argN ] BPF_TRAMP_F_CALL_ORIG + * [ ... ] + * [ stack_arg2 ] + * RBP - arg_stack_off [ stack_arg1 ] */ /* room for return value of orig_call or fentry prog */ @@ -2190,9 +2246,17 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i ip_off = stack_size; + stack_size += 8; + rbx_off = stack_size; + stack_size += (sizeof(struct bpf_tramp_run_ctx) + 7) & ~0x7; run_ctx_off = stack_size; + if (nr_regs > 6 && (flags & BPF_TRAMP_F_CALL_ORIG)) + stack_size += (nr_regs - 6) * 8; + + arg_stack_off = stack_size; + if (flags & BPF_TRAMP_F_SKIP_FRAME) { /* skip patched call instruction and point orig_call to actual * body of the kernel function. @@ -2212,8 +2276,9 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i x86_call_depth_emit_accounting(&prog, NULL); EMIT1(0x55); /* push rbp */ EMIT3(0x48, 0x89, 0xE5); /* mov rbp, rsp */ - EMIT4(0x48, 0x83, 0xEC, stack_size); /* sub rsp, stack_size */ - EMIT1(0x53); /* push rbx */ + EMIT3_off32(0x48, 0x81, 0xEC, stack_size); /* sub rsp, stack_size */ + /* mov QWORD PTR [rbp - rbx_off], rbx */ + emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_6, -rbx_off); /* Store number of argument registers of the traced function: * mov rax, nr_regs @@ -2262,6 +2327,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i if (flags & BPF_TRAMP_F_CALL_ORIG) { restore_regs(m, &prog, nr_regs, regs_off); + prepare_origin_stack(m, &prog, nr_regs, arg_stack_off); if (flags & BPF_TRAMP_F_ORIG_STACK) { emit_ldx(&prog, BPF_DW, BPF_REG_0, BPF_REG_FP, 8); @@ -2321,14 +2387,14 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i if (save_ret) emit_ldx(&prog, BPF_DW, BPF_REG_0, BPF_REG_FP, -8); - EMIT1(0x5B); /* pop rbx */ + emit_ldx(&prog, BPF_DW, BPF_REG_6, BPF_REG_FP, -rbx_off); EMIT1(0xC9); /* leave */ if (flags & BPF_TRAMP_F_SKIP_FRAME) /* skip our return address and return to parent */ EMIT4(0x48, 0x83, 0xC4, 8); /* add rsp, 8 */ emit_return(&prog, prog); /* Make sure the trampoline generation logic doesn't overflow */ - if (WARN_ON_ONCE(prog > (u8 *)image_end - BPF_INSN_SAFETY)) { + if (prog > (u8 *)image_end - BPF_INSN_SAFETY) { ret = -EFAULT; goto cleanup; } From patchwork Fri Jun 2 06:59:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13264771 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8154F10E5; Fri, 2 Jun 2023 07:02:27 +0000 (UTC) Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C610518C; Fri, 2 Jun 2023 00:02:24 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id 98e67ed59e1d1-25632c99eecso812975a91.2; Fri, 02 Jun 2023 00:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685689344; x=1688281344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YMePapRvx579minlQSYMxdALrJ1DqOKehZl4zrZxhok=; b=BxLYbhTWK8mJwbyPR/LlyVGVuQAcXwfCxqSsMg2YPA03+bbXxEdgOFXnqXRBM69X2q zmyFvjlMhIJ8vCnJt2rNASjwWqysYKceTpfaLCPhhSn9n38Z0xsqaU3ChoLXS7CXmOt+ N8Yub2RgyYxgM5iRVj7tcFwCKCjgha77xlAgdyUWN7b0y5rwy8geyPSo3ViN8tb9XS2G 8dorEvu+d7B9p0/tz0cp1BnFeOYYoSrJkpN46AaBm+D46ErKloGm9Zfw6LhIG/ns094b kvBM0UePowXsDo6wpLojXTbdMXcflBblDyIAdQYSYlKVGsVb1E2x7qYM4ABpwq58XIpY i59A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685689344; x=1688281344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YMePapRvx579minlQSYMxdALrJ1DqOKehZl4zrZxhok=; b=aYgiIhQrhAFaqoy+5Ja2n2I4Og2tYKMpbOnbiNzpgMTUR9+0MibP590GJn0mNgeqzx vJF+jwfG1K9Cjmw0zU6BS4Sqbv6svQLB2t4q2apeh7BJJButC5PJ3Zs5DpBgfUgFQ7aw sxvS7IqvX9r4IzZHcsl4Mic3YbUA9FJI7A74R5kB1O5BxUntm8Ry1JJLWyARoaBSG6HA HxB/mgzLQ5hvlHbJj/zdjVH4+QKO4cwCSFLC/dugB8VdtC+ke+rvLAM4w7y+p+YeDsSq BX7qXTm104zq1P9TfCcmRpr7pKj3qPyrx73z1Y8kCDAv6oHJQcs84Med1c8epHmJmRNE +kDA== X-Gm-Message-State: AC+VfDzSzN1nVN7MOon7ohw/yHjVetktKiqmuFd5tu0yzjz6p8xi7hZb mNu+arsn6SQwT1odLjSd4+M= X-Google-Smtp-Source: ACHHUZ5IYjqhQm+F1PrAShDiEjyMvthdktQ1ZccrIx7qbruCP1ksSKYkta6wA7EWSDdOOkm+qyUejg== X-Received: by 2002:a17:902:ef85:b0:1b1:9272:55f3 with SMTP id iz5-20020a170902ef8500b001b1927255f3mr776489plb.66.1685689344095; Fri, 02 Jun 2023 00:02:24 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.24]) by smtp.gmail.com with ESMTPSA id jk11-20020a170903330b00b001ac7c725c1asm572716plb.6.2023.06.02.00.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:02:23 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: olsajiri@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benbjiang@tencent.com, iii@linux.ibm.com, imagedong@tencent.com, xukuohai@huawei.com, chantr4@gmail.com, zwisler@google.com, eddyz87@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 3/5] libbpf: make BPF_PROG support 15 function arguments Date: Fri, 2 Jun 2023 14:59:56 +0800 Message-Id: <20230602065958.2869555-4-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602065958.2869555-1-imagedong@tencent.com> References: <20230602065958.2869555-1-imagedong@tencent.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Menglong Dong Now that we changed MAX_BPF_FUNC_ARGS from 12 to 14, we should update BPF_PROG() too. Extend BPF_PROG() to make it support 15 arguments, 14 for kernel function arguments and 1 for return value of FEXIT. Reviewed-by: Jiang Biao Signed-off-by: Menglong Dong --- tools/lib/bpf/bpf_helpers.h | 9 ++++++--- tools/lib/bpf/bpf_tracing.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index bbab9ad9dc5a..d1574491cf16 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -194,11 +194,13 @@ enum libbpf_tristate { #define ___bpf_apply(fn, n) ___bpf_concat(fn, n) #endif #ifndef ___bpf_nth -#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, N, ...) N +#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, \ + _d, _e, _f, N, ...) N #endif #ifndef ___bpf_narg #define ___bpf_narg(...) \ - ___bpf_nth(_, ##__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + ___bpf_nth(_, ##__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, \ + 6, 5, 4, 3, 2, 1, 0) #endif #define ___bpf_fill0(arr, p, x) do {} while (0) @@ -290,7 +292,8 @@ enum libbpf_tristate { #define ___bpf_pick_printk(...) \ ___bpf_nth(_, ##__VA_ARGS__, __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, \ __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, \ - __bpf_vprintk, __bpf_vprintk, __bpf_printk /*3*/, __bpf_printk /*2*/,\ + __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, \ + __bpf_vprintk, __bpf_printk /*3*/, __bpf_printk /*2*/, \ __bpf_printk /*1*/, __bpf_printk /*0*/) /* Helper macro to print out debug messages */ diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index be076a4041ab..4e940239f1c1 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -628,10 +628,13 @@ struct pt_regs; #define ___bpf_apply(fn, n) ___bpf_concat(fn, n) #endif #ifndef ___bpf_nth -#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, N, ...) N +#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, \ + _d, _e, _f, N, ...) N #endif #ifndef ___bpf_narg -#define ___bpf_narg(...) ___bpf_nth(_, ##__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) +#define ___bpf_narg(...) \ + ___bpf_nth(_, ##__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, \ + 6, 5, 4, 3, 2, 1, 0) #endif #define ___bpf_ctx_cast0() ctx @@ -647,6 +650,9 @@ struct pt_regs; #define ___bpf_ctx_cast10(x, args...) ___bpf_ctx_cast9(args), (void *)ctx[9] #define ___bpf_ctx_cast11(x, args...) ___bpf_ctx_cast10(args), (void *)ctx[10] #define ___bpf_ctx_cast12(x, args...) ___bpf_ctx_cast11(args), (void *)ctx[11] +#define ___bpf_ctx_cast13(x, args...) ___bpf_ctx_cast12(args), (void *)ctx[12] +#define ___bpf_ctx_cast14(x, args...) ___bpf_ctx_cast13(args), (void *)ctx[13] +#define ___bpf_ctx_cast15(x, args...) ___bpf_ctx_cast14(args), (void *)ctx[14] #define ___bpf_ctx_cast(args...) ___bpf_apply(___bpf_ctx_cast, ___bpf_narg(args))(args) /* From patchwork Fri Jun 2 06:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13264772 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E549291C; Fri, 2 Jun 2023 07:03:07 +0000 (UTC) Received: from mail-vs1-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10AC2C0; Fri, 2 Jun 2023 00:03:04 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id ada2fe7eead31-4392f532cdaso472861137.3; Fri, 02 Jun 2023 00:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685689383; x=1688281383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wIXI02zixY6EsiTaHFGNM2ccUEUsIDcKDYkgASQ6QgM=; b=ZwjXseJPcuvy30yQiFwevoIlY1cANqOz74spOTCFSu2ZehDMf6SnEw+eNyvV1LU0C7 +/RLe1PfCrvBaji5wEssKSrrMBMhnA9YoakaG9WtMtmuCej0QPwuIliIcyQZa8lu+UKK mRqqU2DEdf3VvtQiUW8oLgub/2v0YEIbllO862FMFsixSQOAZpjQQ5gm+raBzcKtbqPo KxRLO3C6txEZvg6Su3yDaGO5nRkgI90ke7YjSb4KcQh1/vSR0KwoRH9rUzUiQrFXcdQn IwLCG/SF8TPKnFA4JCKd9M5EAdaeYmh3hwI3EV8l5b/0uKUBTtVIUEPuZQjo55YNUuDi 9F4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685689383; x=1688281383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wIXI02zixY6EsiTaHFGNM2ccUEUsIDcKDYkgASQ6QgM=; b=UWUkyFOOy0US257RETGm0nOS+IV/cUWudDPunNEsxjfCtj0mbC3PM9qh+BUU5EOkxl AQjzL5xvouw+68yPeY7lKvUKoZz30fBxffZCZ1I1ZRdecBLiusyxt4A9WlAyJ/ZmWdOK nY2FJIpIaBVhqKXzsrKYqn2MOTZcLdRt1erPeKOfrQCH4Vijv+WDDNau7TqHz05tjpNv o7MHwG8rdUBxaXGRKJjOQ/9cLAdr8+xBqsJyRq+oGhGXCftQL1PC2EzWarfacO99ev2O WVXn+0qa8lpvFhY/ZgRyg1OhYX5rmnrpcubKGgSeIFhEHYFDqI+xhO1efC9kioHDk79d xDCg== X-Gm-Message-State: AC+VfDxzIMckcH5BGqVEMI2Tg5NZXJX9QstPw3qY4yk0aZvoN6mQk8bI YprkTit45sF6iNIUXF3SaZ8= X-Google-Smtp-Source: ACHHUZ7PXnqqc5a+MB1G9AlYJNXTAYbK2p962rQ/ccRRiOcWjz9p1RWS6auUkapSrBQj4yAGm1a+AA== X-Received: by 2002:a67:fa90:0:b0:439:49f1:bb4d with SMTP id f16-20020a67fa90000000b0043949f1bb4dmr5186464vsq.7.1685689383024; Fri, 02 Jun 2023 00:03:03 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.24]) by smtp.gmail.com with ESMTPSA id jk11-20020a170903330b00b001ac7c725c1asm572716plb.6.2023.06.02.00.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:03:02 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: olsajiri@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benbjiang@tencent.com, iii@linux.ibm.com, imagedong@tencent.com, xukuohai@huawei.com, chantr4@gmail.com, zwisler@google.com, eddyz87@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 4/5] selftests/bpf: rename bpf_fentry_test{7,8,9} to bpf_fentry_test_ptr* Date: Fri, 2 Jun 2023 14:59:57 +0800 Message-Id: <20230602065958.2869555-5-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602065958.2869555-1-imagedong@tencent.com> References: <20230602065958.2869555-1-imagedong@tencent.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Menglong Dong To make it more clear, let's make the N in bpf_fentry_testN as the count of target function arguments. Therefore, let's rename bpf_fentry_test{7,8,9} to bpf_fentry_test_ptr{1,2,3}. Meanwhile, to stop the checkpatch complaining, move the "noinline" ahead of "int". Reviewed-by: Jiang Biao Signed-off-by: Menglong Dong --- net/bpf/test_run.c | 12 +++++----- .../selftests/bpf/prog_tests/bpf_cookie.c | 24 +++++++++---------- .../bpf/prog_tests/kprobe_multi_test.c | 16 ++++++------- .../testing/selftests/bpf/progs/fentry_test.c | 16 ++++++------- .../testing/selftests/bpf/progs/fexit_test.c | 16 ++++++------- .../selftests/bpf/progs/get_func_ip_test.c | 2 +- .../selftests/bpf/progs/kprobe_multi.c | 12 +++++----- .../bpf/progs/verifier_btf_ctx_access.c | 2 +- .../selftests/bpf/verifier/atomic_fetch_add.c | 4 ++-- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 2321bd2f9964..c73f246a706f 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -540,17 +540,17 @@ struct bpf_fentry_test_t { struct bpf_fentry_test_t *a; }; -int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg) +noinline int bpf_fentry_test_ptr1(struct bpf_fentry_test_t *arg) { return (long)arg; } -int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg) +noinline int bpf_fentry_test_ptr2(struct bpf_fentry_test_t *arg) { return (long)arg->a; } -__bpf_kfunc u32 bpf_fentry_test9(u32 *a) +__bpf_kfunc u32 bpf_fentry_test_ptr3(u32 *a) { return *a; } @@ -655,9 +655,9 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog, bpf_fentry_test4((void *)7, 8, 9, 10) != 34 || bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || - bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 || - bpf_fentry_test8(&arg) != 0 || - bpf_fentry_test9(&retval) != 0) + bpf_fentry_test_ptr1((struct bpf_fentry_test_t *)0) != 0 || + bpf_fentry_test_ptr2(&arg) != 0 || + bpf_fentry_test_ptr3(&retval) != 0) goto out; break; case BPF_MODIFY_RETURN: diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c index 26b2d1bffdfd..320003b96c86 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c @@ -125,9 +125,9 @@ static void kprobe_multi_link_api_subtest(void) GET_ADDR("bpf_fentry_test4", addrs[2]); GET_ADDR("bpf_fentry_test5", addrs[3]); GET_ADDR("bpf_fentry_test6", addrs[4]); - GET_ADDR("bpf_fentry_test7", addrs[5]); + GET_ADDR("bpf_fentry_test_ptr1", addrs[5]); GET_ADDR("bpf_fentry_test2", addrs[6]); - GET_ADDR("bpf_fentry_test8", addrs[7]); + GET_ADDR("bpf_fentry_test_ptr2", addrs[7]); #undef GET_ADDR @@ -136,9 +136,9 @@ static void kprobe_multi_link_api_subtest(void) cookies[2] = 3; /* bpf_fentry_test4 */ cookies[3] = 4; /* bpf_fentry_test5 */ cookies[4] = 5; /* bpf_fentry_test6 */ - cookies[5] = 6; /* bpf_fentry_test7 */ + cookies[5] = 6; /* bpf_fentry_test_ptr1 */ cookies[6] = 7; /* bpf_fentry_test2 */ - cookies[7] = 8; /* bpf_fentry_test8 */ + cookies[7] = 8; /* bpf_fentry_test_ptr2 */ opts.kprobe_multi.addrs = (const unsigned long *) &addrs; opts.kprobe_multi.cnt = ARRAY_SIZE(addrs); @@ -154,9 +154,9 @@ static void kprobe_multi_link_api_subtest(void) cookies[2] = 6; /* bpf_fentry_test4 */ cookies[3] = 5; /* bpf_fentry_test5 */ cookies[4] = 4; /* bpf_fentry_test6 */ - cookies[5] = 3; /* bpf_fentry_test7 */ + cookies[5] = 3; /* bpf_fentry_test_ptr1 */ cookies[6] = 2; /* bpf_fentry_test2 */ - cookies[7] = 1; /* bpf_fentry_test8 */ + cookies[7] = 1; /* bpf_fentry_test_ptr2 */ opts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_RETURN; prog_fd = bpf_program__fd(skel->progs.test_kretprobe); @@ -185,9 +185,9 @@ static void kprobe_multi_attach_api_subtest(void) "bpf_fentry_test4", "bpf_fentry_test5", "bpf_fentry_test6", - "bpf_fentry_test7", + "bpf_fentry_test_ptr1", "bpf_fentry_test2", - "bpf_fentry_test8", + "bpf_fentry_test_ptr2", }; __u64 cookies[8]; @@ -203,9 +203,9 @@ static void kprobe_multi_attach_api_subtest(void) cookies[2] = 3; /* bpf_fentry_test4 */ cookies[3] = 4; /* bpf_fentry_test5 */ cookies[4] = 5; /* bpf_fentry_test6 */ - cookies[5] = 6; /* bpf_fentry_test7 */ + cookies[5] = 6; /* bpf_fentry_test_ptr1 */ cookies[6] = 7; /* bpf_fentry_test2 */ - cookies[7] = 8; /* bpf_fentry_test8 */ + cookies[7] = 8; /* bpf_fentry_test_ptr2 */ opts.syms = syms; opts.cnt = ARRAY_SIZE(syms); @@ -221,9 +221,9 @@ static void kprobe_multi_attach_api_subtest(void) cookies[2] = 6; /* bpf_fentry_test4 */ cookies[3] = 5; /* bpf_fentry_test5 */ cookies[4] = 4; /* bpf_fentry_test6 */ - cookies[5] = 3; /* bpf_fentry_test7 */ + cookies[5] = 3; /* bpf_fentry_test_ptr1 */ cookies[6] = 2; /* bpf_fentry_test2 */ - cookies[7] = 1; /* bpf_fentry_test8 */ + cookies[7] = 1; /* bpf_fentry_test_ptr2 */ opts.retprobe = true; diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c index 2173c4bb555e..15c77fe9fc16 100644 --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c @@ -105,8 +105,8 @@ static void test_link_api_addrs(void) GET_ADDR("bpf_fentry_test4", addrs[3]); GET_ADDR("bpf_fentry_test5", addrs[4]); GET_ADDR("bpf_fentry_test6", addrs[5]); - GET_ADDR("bpf_fentry_test7", addrs[6]); - GET_ADDR("bpf_fentry_test8", addrs[7]); + GET_ADDR("bpf_fentry_test_ptr1", addrs[6]); + GET_ADDR("bpf_fentry_test_ptr2", addrs[7]); opts.kprobe_multi.addrs = (const unsigned long*) addrs; opts.kprobe_multi.cnt = ARRAY_SIZE(addrs); @@ -123,8 +123,8 @@ static void test_link_api_syms(void) "bpf_fentry_test4", "bpf_fentry_test5", "bpf_fentry_test6", - "bpf_fentry_test7", - "bpf_fentry_test8", + "bpf_fentry_test_ptr1", + "bpf_fentry_test_ptr2", }; opts.kprobe_multi.syms = syms; @@ -183,8 +183,8 @@ static void test_attach_api_addrs(void) GET_ADDR("bpf_fentry_test4", addrs[3]); GET_ADDR("bpf_fentry_test5", addrs[4]); GET_ADDR("bpf_fentry_test6", addrs[5]); - GET_ADDR("bpf_fentry_test7", addrs[6]); - GET_ADDR("bpf_fentry_test8", addrs[7]); + GET_ADDR("bpf_fentry_test_ptr1", addrs[6]); + GET_ADDR("bpf_fentry_test_ptr2", addrs[7]); opts.addrs = (const unsigned long *) addrs; opts.cnt = ARRAY_SIZE(addrs); @@ -201,8 +201,8 @@ static void test_attach_api_syms(void) "bpf_fentry_test4", "bpf_fentry_test5", "bpf_fentry_test6", - "bpf_fentry_test7", - "bpf_fentry_test8", + "bpf_fentry_test_ptr1", + "bpf_fentry_test_ptr2", }; opts.syms = syms; diff --git a/tools/testing/selftests/bpf/progs/fentry_test.c b/tools/testing/selftests/bpf/progs/fentry_test.c index 52a550d281d9..558a5f1d3d5c 100644 --- a/tools/testing/selftests/bpf/progs/fentry_test.c +++ b/tools/testing/selftests/bpf/progs/fentry_test.c @@ -60,20 +60,20 @@ struct bpf_fentry_test_t { struct bpf_fentry_test_t *a; }; -__u64 test7_result = 0; -SEC("fentry/bpf_fentry_test7") -int BPF_PROG(test7, struct bpf_fentry_test_t *arg) +__u64 test_ptr1_result = 0; +SEC("fentry/bpf_fentry_test_ptr1") +int BPF_PROG(test_ptr1, struct bpf_fentry_test_t *arg) { if (!arg) - test7_result = 1; + test_ptr1_result = 1; return 0; } -__u64 test8_result = 0; -SEC("fentry/bpf_fentry_test8") -int BPF_PROG(test8, struct bpf_fentry_test_t *arg) +__u64 test_ptr2_result = 0; +SEC("fentry/bpf_fentry_test_ptr2") +int BPF_PROG(test_ptr2, struct bpf_fentry_test_t *arg) { if (arg->a == 0) - test8_result = 1; + test_ptr2_result = 1; return 0; } diff --git a/tools/testing/selftests/bpf/progs/fexit_test.c b/tools/testing/selftests/bpf/progs/fexit_test.c index 8f1ccb7302e1..f57886e6d918 100644 --- a/tools/testing/selftests/bpf/progs/fexit_test.c +++ b/tools/testing/selftests/bpf/progs/fexit_test.c @@ -61,20 +61,20 @@ struct bpf_fentry_test_t { struct bpf_fentry_test *a; }; -__u64 test7_result = 0; -SEC("fexit/bpf_fentry_test7") -int BPF_PROG(test7, struct bpf_fentry_test_t *arg) +__u64 test_ptr1_result = 0; +SEC("fexit/bpf_fentry_test_ptr1") +int BPF_PROG(test_ptr1, struct bpf_fentry_test_t *arg) { if (!arg) - test7_result = 1; + test_ptr1_result = 1; return 0; } -__u64 test8_result = 0; -SEC("fexit/bpf_fentry_test8") -int BPF_PROG(test8, struct bpf_fentry_test_t *arg) +__u64 test_ptr2_result = 0; +SEC("fexit/bpf_fentry_test_ptr2") +int BPF_PROG(test_ptr2, struct bpf_fentry_test_t *arg) { if (!arg->a) - test8_result = 1; + test_ptr2_result = 1; return 0; } diff --git a/tools/testing/selftests/bpf/progs/get_func_ip_test.c b/tools/testing/selftests/bpf/progs/get_func_ip_test.c index 8559e698b40d..7fffe2b563fa 100644 --- a/tools/testing/selftests/bpf/progs/get_func_ip_test.c +++ b/tools/testing/selftests/bpf/progs/get_func_ip_test.c @@ -12,7 +12,7 @@ extern const void bpf_fentry_test3 __ksym; extern const void bpf_fentry_test4 __ksym; extern const void bpf_modify_return_test __ksym; extern const void bpf_fentry_test6 __ksym; -extern const void bpf_fentry_test7 __ksym; +extern const void bpf_fentry_test_ptr1 __ksym; extern bool CONFIG_X86_KERNEL_IBT __kconfig __weak; diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi.c b/tools/testing/selftests/bpf/progs/kprobe_multi.c index 9e1ca8e34913..e676fb195595 100644 --- a/tools/testing/selftests/bpf/progs/kprobe_multi.c +++ b/tools/testing/selftests/bpf/progs/kprobe_multi.c @@ -12,8 +12,8 @@ extern const void bpf_fentry_test3 __ksym; extern const void bpf_fentry_test4 __ksym; extern const void bpf_fentry_test5 __ksym; extern const void bpf_fentry_test6 __ksym; -extern const void bpf_fentry_test7 __ksym; -extern const void bpf_fentry_test8 __ksym; +extern const void bpf_fentry_test_ptr1 __ksym; +extern const void bpf_fentry_test_ptr2 __ksym; int pid = 0; bool test_cookie = false; @@ -57,8 +57,8 @@ static void kprobe_multi_check(void *ctx, bool is_return) SET(kretprobe_test4_result, &bpf_fentry_test4, 6); SET(kretprobe_test5_result, &bpf_fentry_test5, 5); SET(kretprobe_test6_result, &bpf_fentry_test6, 4); - SET(kretprobe_test7_result, &bpf_fentry_test7, 3); - SET(kretprobe_test8_result, &bpf_fentry_test8, 1); + SET(kretprobe_test7_result, &bpf_fentry_test_ptr1, 3); + SET(kretprobe_test8_result, &bpf_fentry_test_ptr2, 1); } else { SET(kprobe_test1_result, &bpf_fentry_test1, 1); SET(kprobe_test2_result, &bpf_fentry_test2, 7); @@ -66,8 +66,8 @@ static void kprobe_multi_check(void *ctx, bool is_return) SET(kprobe_test4_result, &bpf_fentry_test4, 3); SET(kprobe_test5_result, &bpf_fentry_test5, 4); SET(kprobe_test6_result, &bpf_fentry_test6, 5); - SET(kprobe_test7_result, &bpf_fentry_test7, 6); - SET(kprobe_test8_result, &bpf_fentry_test8, 8); + SET(kprobe_test7_result, &bpf_fentry_test_ptr1, 6); + SET(kprobe_test8_result, &bpf_fentry_test_ptr2, 8); } #undef SET diff --git a/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c b/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c index a570e48b917a..b90b8a3bf169 100644 --- a/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c +++ b/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c @@ -17,7 +17,7 @@ __naked void btf_ctx_access_accept(void) " ::: __clobber_all); } -SEC("fentry/bpf_fentry_test9") +SEC("fentry/bpf_fentry_test_ptr3") __description("btf_ctx_access u32 pointer accept") __success __retval(0) __naked void ctx_access_u32_pointer_accept(void) diff --git a/tools/testing/selftests/bpf/verifier/atomic_fetch_add.c b/tools/testing/selftests/bpf/verifier/atomic_fetch_add.c index a91de8cd9def..23d70b11ab80 100644 --- a/tools/testing/selftests/bpf/verifier/atomic_fetch_add.c +++ b/tools/testing/selftests/bpf/verifier/atomic_fetch_add.c @@ -88,7 +88,7 @@ * kernel function being called. Load first arg into R2. */ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 0), - /* First arg of bpf_fentry_test7 is a pointer to a struct. + /* First arg of bpf_fentry_test_ptr1 is a pointer to a struct. * Attempt to modify that struct. Verifier shouldn't let us * because it's kernel memory. */ @@ -100,7 +100,7 @@ }, .prog_type = BPF_PROG_TYPE_TRACING, .expected_attach_type = BPF_TRACE_FENTRY, - .kfunc = "bpf_fentry_test7", + .kfunc = "bpf_fentry_test_ptr1", .result = REJECT, .errstr = "only read is supported", }, From patchwork Fri Jun 2 06:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13264773 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B21D3D6D; Fri, 2 Jun 2023 07:03:44 +0000 (UTC) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B06EC0; Fri, 2 Jun 2023 00:03:42 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 41be03b00d2f7-5428f63c73aso519262a12.1; Fri, 02 Jun 2023 00:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685689422; x=1688281422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u3BWlTPsObidXDtzIHPCXFfZL0M03uXUfgADlN6lrcg=; b=TXk2/MwUqulJx/q8I0vNt8DC69PD/dyJKYb4kGXCNUwgsYo95gxZUVCyNIHcqrpggE EL2SJmCCyQIgLzhBW/XTLEjgucx0l105f9m2zXrjsUQsdr9Hf/HpuO+d5z1AEwB6z+vV uDLuf9WLJc4Es259+K9sQdrsXPqKBbMDKKA5YGLd6JuMTpMF0AQPCpiIQZE4vlpd8Rzv YI1tflOl4RIwHFqGHofbO0flRXf+i37QHKvBZ2zAiVJDjsEmGdvAS2GMhiqJNNPA5naX gPVKo6l/KZZYuDS75QURcUhVnIsQ/VeVb5MrCMPMnjkSqkgQe73j/nnnZJ6UYRmmL3Wz JWpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685689422; x=1688281422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u3BWlTPsObidXDtzIHPCXFfZL0M03uXUfgADlN6lrcg=; b=GNpGUo9mxfL4WUjlOonyTjgEa05BgCwQTlXF5TAjH7ThDF23Wq4eYz7frVivUPGZlX kK52WLlTwyb8C01Hbb6wWIm35PIX/CDVUJQEOuYIM766wh5wZm4QBm1HC4XpuPh7SjEa WqunuIpGvk3U9D/yv7sQ9SN1CVLBsI/4zV7keYS3vP/NIRXhUJEHQCxuy08POpMuCNLm aPJNngx9Rq0VontItTEYG3DW2BelcbyprX7Kmq1GCVkQ8cAsZ7049gj4JsVo8ZqAOP8R i2ry9d2tQmkap9p86YtNQqtRVT8u5qrFLQqtvb1NSrHKWGwyjC3p+sLxYC55JH6hITVb HHBw== X-Gm-Message-State: AC+VfDwnln696chL2sDUx0Zuzwv8ph6K/k/1Dhf+3/pKT7Kejux8Eo+Y AMsk7ztkbqh0pebngcIMnVk= X-Google-Smtp-Source: ACHHUZ60WPIftH8KK8U9r7WrDhwPgFfK0MPgDpZGN2WWP2cXFtgmJ21UTbDQSerSEU9peFElOySexQ== X-Received: by 2002:a17:903:64e:b0:1ad:fcdc:2a9f with SMTP id kh14-20020a170903064e00b001adfcdc2a9fmr921370plb.51.1685689421937; Fri, 02 Jun 2023 00:03:41 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.24]) by smtp.gmail.com with ESMTPSA id jk11-20020a170903330b00b001ac7c725c1asm572716plb.6.2023.06.02.00.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:03:41 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: olsajiri@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, benbjiang@tencent.com, iii@linux.ibm.com, imagedong@tencent.com, xukuohai@huawei.com, chantr4@gmail.com, zwisler@google.com, eddyz87@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 5/5] selftests/bpf: add testcase for FENTRY/FEXIT with 6+ arguments Date: Fri, 2 Jun 2023 14:59:58 +0800 Message-Id: <20230602065958.2869555-6-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602065958.2869555-1-imagedong@tencent.com> References: <20230602065958.2869555-1-imagedong@tencent.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Menglong Dong Add test7/test12/test14 in fexit_test.c and fentry_test.c to test the fentry and fexit whose target function have 7/12/14 arguments. And the testcases passed: ./test_progs -t fexit $71 fentry_fexit:OK $73/1 fexit_bpf2bpf/target_no_callees:OK $73/2 fexit_bpf2bpf/target_yes_callees:OK $73/3 fexit_bpf2bpf/func_replace:OK $73/4 fexit_bpf2bpf/func_replace_verify:OK $73/5 fexit_bpf2bpf/func_sockmap_update:OK $73/6 fexit_bpf2bpf/func_replace_return_code:OK $73/7 fexit_bpf2bpf/func_map_prog_compatibility:OK $73/8 fexit_bpf2bpf/func_replace_multi:OK $73/9 fexit_bpf2bpf/fmod_ret_freplace:OK $73/10 fexit_bpf2bpf/func_replace_global_func:OK $73/11 fexit_bpf2bpf/fentry_to_cgroup_bpf:OK $73/12 fexit_bpf2bpf/func_replace_progmap:OK $73 fexit_bpf2bpf:OK $74 fexit_sleep:OK $75 fexit_stress:OK $76 fexit_test:OK Summary: 5/12 PASSED, 0 SKIPPED, 0 FAILED ./test_progs -t fentry $71 fentry_fexit:OK $72 fentry_test:OK $140 module_fentry_shadow:OK Summary: 3/0 PASSED, 0 SKIPPED, 0 FAILED Reviewed-by: Jiang Biao Signed-off-by: Menglong Dong --- net/bpf/test_run.c | 30 +++++++++++++++- .../testing/selftests/bpf/progs/fentry_test.c | 34 ++++++++++++++++++ .../testing/selftests/bpf/progs/fexit_test.c | 35 +++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index c73f246a706f..e12a72311eca 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -536,6 +536,27 @@ int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f) return a + (long)b + c + d + (long)e + f; } +noinline int bpf_fentry_test7(u64 a, void *b, short c, int d, void *e, + u64 f, u64 g) +{ + return a + (long)b + c + d + (long)e + f + g; +} + +noinline int bpf_fentry_test12(u64 a, void *b, short c, int d, void *e, + u64 f, u64 g, u64 h, u64 i, u64 j, + u64 k, u64 l) +{ + return a + (long)b + c + d + (long)e + f + g + h + i + j + k + l; +} + +noinline int bpf_fentry_test14(u64 a, void *b, short c, int d, void *e, + u64 f, u64 g, u64 h, u64 i, u64 j, + u64 k, u64 l, u64 m, u64 n) +{ + return a + (long)b + c + d + (long)e + f + g + h + i + j + k + l + + m + n; +} + struct bpf_fentry_test_t { struct bpf_fentry_test_t *a; }; @@ -657,7 +678,14 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog, bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || bpf_fentry_test_ptr1((struct bpf_fentry_test_t *)0) != 0 || bpf_fentry_test_ptr2(&arg) != 0 || - bpf_fentry_test_ptr3(&retval) != 0) + bpf_fentry_test_ptr3(&retval) != 0 || + bpf_fentry_test7(16, (void *)17, 18, 19, (void *)20, + 21, 22) != 133 || + bpf_fentry_test12(16, (void *)17, 18, 19, (void *)20, + 21, 22, 23, 24, 25, 26, 27) != 258 || + bpf_fentry_test14(16, (void *)17, 18, 19, (void *)20, + 21, 22, 23, 24, 25, 26, 27, 28, + 29) != 315) goto out; break; case BPF_MODIFY_RETURN: diff --git a/tools/testing/selftests/bpf/progs/fentry_test.c b/tools/testing/selftests/bpf/progs/fentry_test.c index 558a5f1d3d5c..0666a907f7ea 100644 --- a/tools/testing/selftests/bpf/progs/fentry_test.c +++ b/tools/testing/selftests/bpf/progs/fentry_test.c @@ -56,6 +56,40 @@ int BPF_PROG(test6, __u64 a, void *b, short c, int d, void * e, __u64 f) return 0; } +__u64 test7_result = 0; +SEC("fentry/bpf_fentry_test7") +int BPF_PROG(test7, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g) +{ + test7_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22; + return 0; +} + +__u64 test12_result = 0; +SEC("fentry/bpf_fentry_test12") +int BPF_PROG(test12, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g, __u64 h, __u64 i, __u64 j, __u64 k, __u64 l) +{ + test12_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22 && h == 23 && + i == 24 && j == 25 && k == 26 && l == 27; + return 0; +} + +__u64 test14_result = 0; +SEC("fentry/bpf_fentry_test14") +int BPF_PROG(test14, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g, __u64 h, __u64 i, __u64 j, __u64 k, __u64 l, + __u64 m, __u64 n) +{ + test14_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22 && h == 23 && + i == 24 && j == 25 && k == 26 && l == 27 && m == 28 && + n == 29; + return 0; +} + struct bpf_fentry_test_t { struct bpf_fentry_test_t *a; }; diff --git a/tools/testing/selftests/bpf/progs/fexit_test.c b/tools/testing/selftests/bpf/progs/fexit_test.c index f57886e6d918..1b9102ad1418 100644 --- a/tools/testing/selftests/bpf/progs/fexit_test.c +++ b/tools/testing/selftests/bpf/progs/fexit_test.c @@ -57,6 +57,41 @@ int BPF_PROG(test6, __u64 a, void *b, short c, int d, void *e, __u64 f, int ret) return 0; } +__u64 test7_result = 0; +SEC("fexit/bpf_fentry_test7") +int BPF_PROG(test7, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g, int ret) +{ + test7_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22 && ret == 133; + return 0; +} + +__u64 test12_result = 0; +SEC("fexit/bpf_fentry_test12") +int BPF_PROG(test12, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g, __u64 h, __u64 i, __u64 j, __u64 k, __u64 l, + int ret) +{ + test12_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22 && h == 23 && + i == 24 && j == 25 && k == 26 && l == 27 && ret == 258; + return 0; +} + +__u64 test14_result = 0; +SEC("fexit/bpf_fentry_test14") +int BPF_PROG(test14, __u64 a, void *b, short c, int d, void *e, __u64 f, + __u64 g, __u64 h, __u64 i, __u64 j, __u64 k, __u64 l, + __u64 m, __u64 n, int ret) +{ + test14_result = a == 16 && b == (void *)17 && c == 18 && d == 19 && + e == (void *)20 && f == 21 && g == 22 && h == 23 && + i == 24 && j == 25 && k == 26 && l == 27 && m == 28 && + n == 29 && ret == 315; + return 0; +} + struct bpf_fentry_test_t { struct bpf_fentry_test *a; };