From patchwork Tue Feb 20 03:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 13563364 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D12AA55787 for ; Tue, 20 Feb 2024 03:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401073; cv=none; b=fOglWIbJcVQyUT96SRRZYLQg/4R7VUifOnOtYRcA3IFOYXdVqkyLCrybBdstX9Key+6OKlQGYNkl316GDKSt1uo7pRAScjmELe2CHN5QDvvdKbmmnZWfSZ34Rvypk64EQWoWSsLO6ji1S7VuZpt+D+8fmUCRBAtgG/HM4Kqa8r8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401073; c=relaxed/simple; bh=WCeJYOWpFA4aAYG9AU6cqenBm2lq0LDB3RA405EROwc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XcDdRvWcnTlrY1ExqdhlKOE9U1LHVEOXl5aY6UeRkOTHgCwp1AGoa/z7eaRECG1qWjrOfIh7l44rKMARJ4GSUoIa9QPlccsyGp89FK0EsiZVW+u0+n+DblLTg3X113c7EPqR/e2tGtaaun0a0x7qQAZK1oOq0Dqgp5y3QsP4brY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ACTkIr9x; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ACTkIr9x" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6da4a923b1bso4207440b3a.2 for ; Mon, 19 Feb 2024 19:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401071; x=1709005871; darn=vger.kernel.org; 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=WHXPVUB1nr0Sthgk6cohE38ljuRgW7sUP/a10lgKv7E=; b=ACTkIr9xj//tSv77Mh3wVhdbBIsjhVyRHdOYAhRDLQaNIkaUoaZ++O3l7nP/RoYehB bCt3cPHQ7uhFW7Zf4pr3apx0NDDg7Ii9s1rEJubMsoHoJglDLlQaCsBWmzgudb5XAZO6 Z2haZQwfuMyO7GjCFAUPXuqNao+C1Xbt9nkIr1UkGZPoK07q/drH8KIKk6wlepejINzh mLE1wZ03+PIxARAlDtLZcdLeHfUK7su6ce4DaGecIKpY37SmTSKZhwQjFQNOWZngsrcO xY2ptpByehN0AxSFUz3jKqEBHmRII7iDcNJm4RmzVKD5NUMf1iBioxM4piMoj4VZ6Qsr OzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401071; x=1709005871; 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=WHXPVUB1nr0Sthgk6cohE38ljuRgW7sUP/a10lgKv7E=; b=SVq0GNXcrTo6vmaIgibDZdUQGs/6aYW8lv/bx6OMErG1HLkhIag+CyXRt32sZqn+/r bhzxdcO6NOa7/kT1WvhcGj4b3CGlfis04gX0sB+1JutiyC16YxHT0wcUlju2IkvgsppG m4fnGAxv04zld9QLM0w3BIMOmn2v/geJfyGYL3t/Uc5IpXeKsjkOAABxOTBO2wVSDqIF YDT1WD+mtwEjy9jLfBQJ/bDW9eVe6MbEHJlNpLI1Abn31gaKy+W/oZNxBuzSR/9+5vUr Y/OVPJgD2q/6CtyDOOfmuSNY87kVFRKLYBYK9t3z6GGI1W/Jlu9BmDDVV3EdaTTal1qP rfVg== X-Forwarded-Encrypted: i=1; AJvYcCXOiq+EJPbmaMS80hOtOYx7mQVqgu2ZzxJGDtqhgCRvQFkwch5y8cKSlsQQI/pSFYtg9cP+eyY5nuMS0CHvSxT3Qy6G3mpbq8e0+o0Te3nv X-Gm-Message-State: AOJu0Yyl0jFzxlOwMN01D2Q0Oy/HxCctXgcqChT2KhXtCkOEOyQhafHq OyQPZLlP9uZIJ5otU4iufLFmpfFgtTwcqdcM2Ho35apjxTkmut1cBSETss4SdPU= X-Google-Smtp-Source: AGHT+IGeBfzA8FmCoaAXcu5vb3lemy5d1ibyBHJoQ+3L0JF9gidLlGX8eVqpkabuA9fCIJVy1Z3Z2w== X-Received: by 2002:a05:6a20:6f88:b0:19a:47f2:5766 with SMTP id gv8-20020a056a206f8800b0019a47f25766mr13853615pzb.56.1708401071235; Mon, 19 Feb 2024 19:51:11 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:11 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 1/5] bpf: tracing: add support to record and check the accessed args Date: Tue, 20 Feb 2024 11:51:01 +0800 Message-Id: <20240220035105.34626-2-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In this commit, we add the 'accessed_args' field to struct bpf_prog_aux, which is used to record the accessed index of the function args in btf_ctx_access(). Meanwhile, we add the function btf_check_func_part_match() to compare the accessed function args of two function prototype. This function will be used in the following commit. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 4 ++ kernel/bpf/btf.c | 121 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index c7aa99b44dbd..0225b8dbdd9d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1464,6 +1464,7 @@ struct bpf_prog_aux { const struct btf_type *attach_func_proto; /* function name for valid attach_btf_id */ const char *attach_func_name; + u64 accessed_args; struct bpf_prog **func; void *jit_data; /* JIT specific data. arch dependent */ struct bpf_jit_poke_descriptor *poke_tab; @@ -2566,6 +2567,9 @@ struct bpf_reg_state; int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog); int btf_check_type_match(struct bpf_verifier_log *log, const struct bpf_prog *prog, struct btf *btf, const struct btf_type *t); +int btf_check_func_part_match(struct btf *btf1, const struct btf_type *t1, + struct btf *btf2, const struct btf_type *t2, + u64 func_args); const char *btf_find_decl_tag_value(const struct btf *btf, const struct btf_type *pt, int comp_idx, const char *tag_key); int btf_find_next_decl_tag(const struct btf *btf, const struct btf_type *pt, diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 6ff0bd1a91d5..3a6931402fe4 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6203,6 +6203,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, /* skip first 'void *__data' argument in btf_trace_##name typedef */ args++; nr_args--; + prog->aux->accessed_args |= (1 << (arg + 1)); + } else { + prog->aux->accessed_args |= (1 << arg); } if (arg > nr_args) { @@ -7010,6 +7013,124 @@ int btf_check_type_match(struct bpf_verifier_log *log, const struct bpf_prog *pr return btf_check_func_type_match(log, btf1, t1, btf2, t2); } +static u32 get_ctx_arg_total_size(struct btf *btf, const struct btf_type *t) +{ + const struct btf_param *args; + u32 size = 0, nr_args; + int i; + + nr_args = btf_type_vlen(t); + args = (const struct btf_param *)(t + 1); + for (i = 0; i < nr_args; i++) { + t = btf_type_skip_modifiers(btf, args[i].type, NULL); + size += btf_type_is_ptr(t) ? 8 : roundup(t->size, 8); + } + + return size; +} + +static int get_ctx_arg_idx_aligned(struct btf *btf, const struct btf_type *t, + int off) +{ + const struct btf_param *args; + u32 offset = 0, nr_args; + int i; + + nr_args = btf_type_vlen(t); + args = (const struct btf_param *)(t + 1); + for (i = 0; i < nr_args; i++) { + if (offset == off) + return i; + + t = btf_type_skip_modifiers(btf, args[i].type, NULL); + offset += btf_type_is_ptr(t) ? 8 : roundup(t->size, 8); + if (offset > off) + return -1; + } + return -1; +} + +/* This function is similar to btf_check_func_type_match(), except that it + * only compare some function args of the function prototype t1 and t2. + */ +int btf_check_func_part_match(struct btf *btf1, const struct btf_type *func1, + struct btf *btf2, const struct btf_type *func2, + u64 func_args) +{ + const struct btf_param *args1, *args2; + u32 nargs1, i, offset = 0; + const char *s1, *s2; + + if (!btf_type_is_func_proto(func1) || !btf_type_is_func_proto(func2)) + return -EINVAL; + + args1 = (const struct btf_param *)(func1 + 1); + args2 = (const struct btf_param *)(func2 + 1); + nargs1 = btf_type_vlen(func1); + + for (i = 0; i <= nargs1; i++) { + const struct btf_type *t1, *t2; + + if (!(func_args & (1 << i))) + goto next; + + if (i < nargs1) { + int t2_index; + + /* get the index of the arg corresponding to args1[i] + * by the offset. + */ + t2_index = get_ctx_arg_idx_aligned(btf2, func2, + offset); + if (t2_index < 0) + return -EINVAL; + + t1 = btf_type_skip_modifiers(btf1, args1[i].type, NULL); + t2 = btf_type_skip_modifiers(btf2, args2[t2_index].type, + NULL); + } else { + /* i == nargs1, this is the index of return value of t1 */ + if (get_ctx_arg_total_size(btf1, func1) != + get_ctx_arg_total_size(btf2, func2)) + return -EINVAL; + + /* check the return type of t1 and t2 */ + t1 = btf_type_skip_modifiers(btf1, func1->type, NULL); + t2 = btf_type_skip_modifiers(btf2, func2->type, NULL); + } + + if (t1->info != t2->info || + (btf_type_has_size(t1) && t1->size != t2->size)) + return -EINVAL; + if (btf_type_is_int(t1) || btf_is_any_enum(t1)) + goto next; + + if (btf_type_is_struct(t1)) + goto on_struct; + + if (!btf_type_is_ptr(t1)) + return -EINVAL; + + t1 = btf_type_skip_modifiers(btf1, t1->type, NULL); + t2 = btf_type_skip_modifiers(btf2, t2->type, NULL); + if (!btf_type_is_struct(t1) || !btf_type_is_struct(t2)) + return -EINVAL; + +on_struct: + s1 = btf_name_by_offset(btf1, t1->name_off); + s2 = btf_name_by_offset(btf2, t2->name_off); + if (strcmp(s1, s2)) + return -EINVAL; +next: + if (i < nargs1) { + t1 = btf_type_skip_modifiers(btf1, args1[i].type, NULL); + offset += btf_type_is_ptr(t1) ? 8 : roundup(t1->size, 8); + } + } + + return 0; +} + static bool btf_is_dynptr_ptr(const struct btf *btf, const struct btf_type *t) { const char *name; From patchwork Tue Feb 20 03:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 13563365 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4324047A4C for ; Tue, 20 Feb 2024 03:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401079; cv=none; b=L4N9dBcaZ1SMQcxJcp52bZJeFZHI6odpd92VWLW+w6H4IkWirIWfEBLzSehJCNBeipWS+5jK7qTDE54i7KqCcYsZPW5JZlkPpXJgr+O1XWvf9gE15XX/NlbUjVLew7IhaO3tDu2GU+Aoy2GsT0iZWdHbfeWWwQmriI3zM7sqKqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401079; c=relaxed/simple; bh=X/XHzTuV96b495jwUwOHbi9/5on4URE0t0YMMUjzwu8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dn1znp1viTMYfTXb56EWv4gFDKPrabPaomUIHZq6xPm0StqNExeHrTUgZy9aPBw2z8RHY7Av1BXbckBvj7mkYeUsY30snHPhWAWwjIMdPtPHx8HbHLGYDXCdNWlubGHtzk/P8Hbb2QAoIjP8kZB0p13IOUyeBAs5ZvnhV0VPArs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=MoyT/fNR; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MoyT/fNR" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d7431e702dso48793455ad.1 for ; Mon, 19 Feb 2024 19:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401077; x=1709005877; darn=vger.kernel.org; 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=md7RnHZfTkBhICmJ+OsuUTQkZUa+D/mBVSzgm1IZa1Q=; b=MoyT/fNRdbOsVl+6d7h8HQ39W1B2IPzgnI9FK9OOCEUvxChCRECFApBdQA/Qkh18Cs 2vmJQyz1dmaS4hqsIT2f3m6h65wJdonTi2f1cf24pQxN0Vm8K9/ccQS1vWgIUZs89s8c WgtFet+DSyrLCS0y4gjC/tijLMTqIBBlApM+lw/r+fWPBxXtM72qM+ALWqyMnim/gybG xzbki71iUX/CrlRK6CvhO3D+zYWfa/5jmh3AwPdY0tvwRhXbRWHxyx3Gjz73dUg7V7ja Bt+X9536+MRzyyIa1NKQcD3x5tWu7Q7G9k6YS+UHNz6EXEwaS5ssj5JZbeBPn2Aubdz6 IuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401077; x=1709005877; 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=md7RnHZfTkBhICmJ+OsuUTQkZUa+D/mBVSzgm1IZa1Q=; b=DEW/oaMHKtz7UKfeoSyTiIWRCnG9dwda+Hz1C6vWiHS7WPgG3BZEo3DdD1EA+vQQG+ ziwd2PLE0umhFiA+xHExRnStX/wAIGa7L45ybF5HlUSNLAMZkg/FZtdR5cN0gOvjgNDX MRzaNzuGbaF83K2PsmHfCrgYSP8LNGsBEof4047Ot0lIxOePHik6eV2c1NHD5Le20BBm JAo4s2NvJQAu5qEoiiXfp90On1+an1FhgEtAdRbfwZmUVuuq64q9eJabRIdn0DeoJwto sSkU1lf8K54ilCdqaPGbKcoZYF8GO/FFHCVqeXqsXnSB3mv+LEO5dnuvgidHK/jlvPgW fQTw== X-Forwarded-Encrypted: i=1; AJvYcCVBaHLCZQ3unwz/93wYdKzZBG/4GmK/jh99ayEEWuNNqhQzwUCRCWWBB3zZBTAGSu5P+eaPRbRLD4dWYG/lBgN+GIw5cHRRYcu0UqH9s2YP X-Gm-Message-State: AOJu0YwIZ88/ukcNFvDda88VD5OyhsMQe3gYXEPnpilKchluUpXSRswC V7yDGXPymY4y6c4hlyn0EkNIq7XPYwfxkc8NRL7QnJhxDcq9QLjm/ZAU41NrMhM= X-Google-Smtp-Source: AGHT+IGuK0d/wvsxyi5goDhOvkumTvcva9JkJqLkAQRozGUCQwA/xKzy+ovx1pKNvGjfNt1NySoBBg== X-Received: by 2002:a17:902:e886:b0:1dc:fb5:6f36 with SMTP id w6-20020a170902e88600b001dc0fb56f36mr2267217plg.32.1708401077579; Mon, 19 Feb 2024 19:51:17 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:17 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 2/5] bpf: tracing: support to attach program to multi hooks Date: Tue, 20 Feb 2024 11:51:02 +0800 Message-Id: <20240220035105.34626-3-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In this commit, we add the support to allow attaching a tracing BPF program to multi hooks. In the commit 4a1e7c0c63e0 ("bpf: Support attaching freplace programs to multiple attach points"), the freplace BPF program is made to support attach to multiple attach points. And in this commit, we extend it to fentry/fexit/raw_tp/... The use case is obvious. For now, we have to create a BPF program for each kernel function, for which we want to trace, even through all the program have the same (or similar logic). This can consume extra memory, and make the program loading slow if we have plenty of kernel function to trace. The KPROBE_MULTI maybe a alternative, but it can't what TRACING do. For example, the kretprobe can't obtain the function args, but the FEXIT can. Now, we need to hold the reference for the target btf and kernel module in the bpf link, as a program can have multiple target. Therefore, we introduce the attach_btf and mod field to the struct bpf_tracing_link. During the attach, we will check the target is compatible with the program, which means that the function args that the program accessed in the target function prototype should be the same as the origin target. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 2 + include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 117 +++++++++++++++++++++++++++++++-------- 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 0225b8dbdd9d..cf8f2df9afb9 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1606,6 +1606,8 @@ struct bpf_tracing_link { enum bpf_attach_type attach_type; struct bpf_trampoline *trampoline; struct bpf_prog *tgt_prog; + struct btf *attach_btf; + struct module *mod; }; struct bpf_link_primer { diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index d96708380e52..0ded10a85bfe 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1668,6 +1668,7 @@ union bpf_attr { union { __u32 target_fd; /* target object to attach to or ... */ __u32 target_ifindex; /* target ifindex */ + __u32 target_btf_obj_fd; }; __u32 attach_type; /* attach type */ __u32 flags; /* extra flags */ diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index b2750b79ac80..3b432fcd5bdb 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3178,6 +3178,9 @@ static void bpf_tracing_link_dealloc(struct bpf_link *link) struct bpf_tracing_link *tr_link = container_of(link, struct bpf_tracing_link, link.link); + + btf_put(tr_link->attach_btf); + module_put(tr_link->mod); kfree(tr_link); } @@ -3220,6 +3223,35 @@ static const struct bpf_link_ops bpf_tracing_link_lops = { .fill_link_info = bpf_tracing_link_fill_link_info, }; +static int bpf_tracing_check_multi(struct bpf_prog *prog, + struct bpf_prog *tgt_prog, + struct btf *btf2, + const struct btf_type *t2) +{ + struct btf *btf1 = prog->aux->attach_btf; + const struct btf_type *t1; + + /* this case is already valided in bpf_check_attach_target() */ + if (prog->type == BPF_PROG_TYPE_EXT) + return 0; + + /* For now, noly support multi attach for kernel function attach + * point. + */ + if (!btf1) + return -EOPNOTSUPP; + + btf2 = btf2 ?: tgt_prog->aux->btf; + t1 = prog->aux->attach_func_proto; + + /* the target is the same as the origin one, this is a re-attach */ + if (t1 == t2) + return 0; + + return btf_check_func_part_match(btf1, t1, btf2, t2, + prog->aux->accessed_args); +} + static int bpf_tracing_prog_attach(struct bpf_prog *prog, int tgt_prog_fd, u32 btf_id, @@ -3228,7 +3260,9 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, struct bpf_link_primer link_primer; struct bpf_prog *tgt_prog = NULL; struct bpf_trampoline *tr = NULL; + struct btf *attach_btf = NULL; struct bpf_tracing_link *link; + struct module *mod = NULL; u64 key = 0; int err; @@ -3258,31 +3292,50 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, goto out_put_prog; } - if (!!tgt_prog_fd != !!btf_id) { - err = -EINVAL; - goto out_put_prog; - } - if (tgt_prog_fd) { - /* - * For now we only allow new targets for BPF_PROG_TYPE_EXT. If this - * part would be changed to implement the same for - * BPF_PROG_TYPE_TRACING, do not forget to update the way how - * attach_tracing_prog flag is set. - */ - if (prog->type != BPF_PROG_TYPE_EXT) { + if (!btf_id) { err = -EINVAL; goto out_put_prog; } - tgt_prog = bpf_prog_get(tgt_prog_fd); if (IS_ERR(tgt_prog)) { - err = PTR_ERR(tgt_prog); tgt_prog = NULL; - goto out_put_prog; + /* tgt_prog_fd is the fd of the kernel module BTF */ + attach_btf = btf_get_by_fd(tgt_prog_fd); + if (IS_ERR(attach_btf)) { + attach_btf = NULL; + err = -EINVAL; + goto out_put_prog; + } + if (!btf_is_kernel(attach_btf)) { + btf_put(attach_btf); + err = -EOPNOTSUPP; + goto out_put_prog; + } + } else if (prog->type == BPF_PROG_TYPE_TRACING && + tgt_prog->type == BPF_PROG_TYPE_TRACING) { + prog->aux->attach_tracing_prog = true; } - - key = bpf_trampoline_compute_key(tgt_prog, NULL, btf_id); + key = bpf_trampoline_compute_key(tgt_prog, attach_btf, + btf_id); + } else if (btf_id) { + attach_btf = bpf_get_btf_vmlinux(); + if (IS_ERR(attach_btf)) { + attach_btf = NULL; + err = PTR_ERR(attach_btf); + goto out_unlock; + } + if (!attach_btf) { + err = -EINVAL; + goto out_unlock; + } + btf_get(attach_btf); + key = bpf_trampoline_compute_key(NULL, attach_btf, btf_id); + } else { + attach_btf = prog->aux->attach_btf; + /* get the reference of the btf for bpf link */ + if (attach_btf) + btf_get(attach_btf); } link = kzalloc(sizeof(*link), GFP_USER); @@ -3319,7 +3372,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, * are NULL, then program was already attached and user did not provide * tgt_prog_fd so we have no way to find out or create trampoline */ - if (!prog->aux->dst_trampoline && !tgt_prog) { + if (!prog->aux->dst_trampoline && !tgt_prog && !btf_id) { /* * Allow re-attach for TRACING and LSM programs. If it's * currently linked, bpf_trampoline_link_prog will fail. @@ -3346,17 +3399,27 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, * different from the destination specified at load time, we * need a new trampoline and a check for compatibility */ + struct btf *origin_btf = prog->aux->attach_btf; struct bpf_attach_target_info tgt_info = {}; + /* use the new attach_btf to check the target */ + prog->aux->attach_btf = attach_btf; err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, &tgt_info); + prog->aux->attach_btf = origin_btf; if (err) goto out_unlock; - if (tgt_info.tgt_mod) { - module_put(prog->aux->mod); - prog->aux->mod = tgt_info.tgt_mod; - } + mod = tgt_info.tgt_mod; + /* the new target and the previous target are in the same + * module, release the reference once. + */ + if (mod && mod == prog->aux->mod) + module_put(mod); + err = bpf_tracing_check_multi(prog, tgt_prog, attach_btf, + tgt_info.tgt_type); + if (err) + goto out_unlock; tr = bpf_trampoline_get(key, &tgt_info); if (!tr) { @@ -3373,6 +3436,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, */ tr = prog->aux->dst_trampoline; tgt_prog = prog->aux->dst_prog; + mod = prog->aux->mod; } err = bpf_link_prime(&link->link.link, &link_primer); @@ -3388,6 +3452,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, link->tgt_prog = tgt_prog; link->trampoline = tr; + link->attach_btf = attach_btf; + link->mod = mod; /* Always clear the trampoline and target prog from prog->aux to make * sure the original attach destination is not kept alive after a @@ -3400,20 +3466,27 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) /* we allocated a new trampoline, so free the old one */ bpf_trampoline_put(prog->aux->dst_trampoline); + if (prog->aux->mod && mod != prog->aux->mod) + /* the mod in prog is not used anywhere, move it to link */ + module_put(prog->aux->mod); prog->aux->dst_prog = NULL; prog->aux->dst_trampoline = NULL; + prog->aux->mod = NULL; mutex_unlock(&prog->aux->dst_mutex); return bpf_link_settle(&link_primer); out_unlock: if (tr && tr != prog->aux->dst_trampoline) bpf_trampoline_put(tr); + if (mod && mod != prog->aux->mod) + module_put(mod); mutex_unlock(&prog->aux->dst_mutex); kfree(link); out_put_prog: if (tgt_prog_fd && tgt_prog) bpf_prog_put(tgt_prog); + btf_put(attach_btf); return err; } From patchwork Tue Feb 20 03:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 13563366 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6EAB5577E for ; Tue, 20 Feb 2024 03:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401086; cv=none; b=nTDZaTpogjpXSqzN/lIUZaT5DIzDPBLb+R2WttU0sbHM6dDD4ZKnmeagT3RpH4bqqhJmr1LYdaY5LB6EYHfLb+ynG2qbb5Z1aRTgXfNL5kIvCLn3+0lEssD/M2Jv19DJGrPnSxVqpUmhjqI1DMGfCRhskynOxF709T4OA5VWFgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401086; c=relaxed/simple; bh=xa6vI2/sky4WmfzJ7YKtx++yDTvsili9mip7x/cutc4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y/bXJJFGL7EikfM0BiRxkBTvy+Hll/Z6nl5HaIBqG3Ge1tQ++75+e52dbiRN87AhNaRSTe6Lou/GzX7YJWiAQzSSYGeP5E7JxBRh4XzEJ8Bu7MyHw7WOoR0xXm/kxqgqDL0yPE0UKm6NuVTswU07SFbV0Tpla3W5PjFaGc8kRNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ie7uavN8; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ie7uavN8" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d73066880eso48157095ad.3 for ; Mon, 19 Feb 2024 19:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401084; x=1709005884; darn=vger.kernel.org; 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=uAc3ZPxMOkJPGWpWg+vGXamMVExiMG/0L8fGFtmgr8k=; b=ie7uavN8uSClt/TGncDB3TdnAw4Tvf0txv0yIiJdcQX+NgPVCwqTL/kmpM0V8tslCa 3YbV2X87SVV7njw4CNJDujdr4miqy1hvBOXajkNH0D+GQwuYsJ5SggFntej9nv+xyGFM 1CUSgRfg+JiAABgmaO8RV8GZ1KLuBlmHM/uTSHK+sj2AWb5xjuURqjzdW2qukDp2tBqg YD9m9/vprWf+oEnHrhRN1lAt0RA1cBTX3EKq7I6Vg44BtQlsn2D3AX3HMQJEuadhnNtd EhFd7gS17z5nob6bA2g1lBr4gAXTBQKQBzyzj961GpxarQCe8Q3g7E81ykCjstua4ugD 2bJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401084; x=1709005884; 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=uAc3ZPxMOkJPGWpWg+vGXamMVExiMG/0L8fGFtmgr8k=; b=Ww6ZudLKmYnAJ1op+Eye9Bo1bYxMH3o56Ojocgo5L+9pAfMGfh6ss1ZnVzGAQOiPcA G3+cydWWxGaiFxSiYj/X8Y4xws91FKswUZSmqO1kbwrNg/fiixnV982LQ4QQAhu4K9MO qBCBgq/+Gj2sJ0vMdpxgHAvzFSMcJa6E19Jhaw5Y3cmD2EYbo0+M4ZD6x000mcJImeD4 kf1S5OIk3X5QZi6LMjhL7GUOCZVfJhYiKKzGc4Zy+kpmSKYFYwkoJQd+6slWyR2CR9uS ps82Eh3Ph9NmGEOCqWQlCylATg+B1sQ7GbQqYxwf0xzwDMaBZLA8LGfMAvkmJ7/LN/ht fZLA== X-Forwarded-Encrypted: i=1; AJvYcCWCd7gnxP1YQwFoaoxpW35bI7BpY71wYCoOE5yin/Y6hZkztCC5vXhuPMxMqhlJY4BVr6GTPbz77BLzuBbcqgriquR6WyeQOaA4I7KnItEk X-Gm-Message-State: AOJu0YwnwmQZcZqzJDJzmvuT3QTba8tjnxCbT5dObqYbFCj1XE/Tw6pK TobvlJYBAqmr0kXHLuzgO7kDRfP3L5BGKEb60mB9UkqhkPKhKJTjOAOxjzdml3g= X-Google-Smtp-Source: AGHT+IHQpCxkiwyqn6Zm1Fes4enjMkFx89FgEyyFQDO3dIDdg+gKRtfhqWsxDi1vxYhI5FVDAqsFHw== X-Received: by 2002:a17:902:e744:b0:1d9:c367:201b with SMTP id p4-20020a170902e74400b001d9c367201bmr18728920plf.29.1708401084154; Mon, 19 Feb 2024 19:51:24 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:23 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 3/5] libbpf: allow to set coookie when target_btf_id is set in bpf_link_create Date: Tue, 20 Feb 2024 11:51:03 +0800 Message-Id: <20240220035105.34626-4-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As now we support to attach the tracing program to multiple target, we can set the bpf cookie even if the target btf id is offered in bpf_link_create(). Signed-off-by: Menglong Dong --- tools/lib/bpf/bpf.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 97ec005c3c47..0ca7c8375b40 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -737,23 +737,15 @@ int bpf_link_create(int prog_fd, int target_fd, target_btf_id = OPTS_GET(opts, target_btf_id, 0); /* validate we don't have unexpected combinations of non-zero fields */ - if (iter_info_len || target_btf_id) { - if (iter_info_len && target_btf_id) - return libbpf_err(-EINVAL); - if (!OPTS_ZEROED(opts, target_btf_id)) - return libbpf_err(-EINVAL); - } + if (iter_info_len && target_btf_id) + return libbpf_err(-EINVAL); memset(&attr, 0, attr_sz); attr.link_create.prog_fd = prog_fd; attr.link_create.target_fd = target_fd; attr.link_create.attach_type = attach_type; attr.link_create.flags = OPTS_GET(opts, flags, 0); - - if (target_btf_id) { - attr.link_create.target_btf_id = target_btf_id; - goto proceed; - } + attr.link_create.target_btf_id = target_btf_id; switch (attach_type) { case BPF_TRACE_ITER: @@ -834,11 +826,10 @@ int bpf_link_create(int prog_fd, int target_fd, return libbpf_err(-EINVAL); break; default: - if (!OPTS_ZEROED(opts, flags)) + if (!target_btf_id && !OPTS_ZEROED(opts, flags)) return libbpf_err(-EINVAL); break; } -proceed: fd = sys_bpf_fd(BPF_LINK_CREATE, &attr, attr_sz); if (fd >= 0) return fd; From patchwork Tue Feb 20 03:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 13563367 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7832858200 for ; Tue, 20 Feb 2024 03:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401091; cv=none; b=utw7F2pKLd/XguWLRt32lcXQkVPDjWUIXzsq3wdhLvB4aMu1w89yNUV9ttWR7S0mbX59dkKIBbwfmjFsqrs5yJd6m4cJHBECk2nv5t70qM8RR0s2Z4WcnDNG2iQ2RAnzQ4RYSvZndv0LEPy73eGk/8URhiO6FpNyU9Z+IAV92zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401091; c=relaxed/simple; bh=6+Gbjw6HF7/xondO+kClgQlDhke7d2kt7MutGrzeEn0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bsS9an/PTTaNxveJkWNyucVNgOQ0WNL/bmcAiN0hgCsLNek0ktqAqmsqUCITFS/yx7vsBI3CxrAcHDpr9a+t+vw6SlXED2B62wC8M8hq9JxJqjMAsgDuhQdu0TuKzQ0eflpZNoqmppeJz1qe9Zw4de5kjXWVc/dNyCE2Ie5SM1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=a8MUyTXR; arc=none smtp.client-ip=209.85.214.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="a8MUyTXR" Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-1d746ce7d13so32803245ad.0 for ; Mon, 19 Feb 2024 19:51:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401090; x=1709005890; darn=vger.kernel.org; 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=Snh1k6Nld5+bv3WZ3l7dPau1Zu+9Ra2XDZxa5NzBZqk=; b=a8MUyTXR7yP1fLN1nWIOnw2HxG5Xy5AKZOcM+fOaja0wIen1PJiPqjXrO8h/NibpX4 D9PJg+qoSd0oNjgJW4PVFh05q3U7EqAo+MtViXgXFa7YQBvTQFUKcaykgLnwxtN8et2t tDoyWJ1RII2Z7PIJX4qFup3JK4LW9ZbXWhOnhOIyGs+l+mU05KxP5z+ldChlBMsGFixA kOq7LrQOqbogP8HhJMIq2Ny5kWZlCbbVKXlqmmsiKJZpG5mjGpI//Mj8eeHfIQKeYuPj DoTVW4iRKohrMrX8Y/GD/FNcl4ttyc8kshUif4PASLqtXSNJHDgSbQM0QUGyyPo9j/NY G1iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401090; x=1709005890; 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=Snh1k6Nld5+bv3WZ3l7dPau1Zu+9Ra2XDZxa5NzBZqk=; b=XW4sKudk+nenZtGJ77iKOE1M22mQl1LiCmen6APm4wxVCwTdJ8IJuWr29haVmzqmmy OLUPCFZq5Pj7pgrCxR1cJYBQniHRqX9VBe2HZNEgSylY2y0Ok6bAXGH8vN/6tldNVPvD 1bQoE3DimfhgcNQPg0/2owPgpB0YvchOXFMyUfhNhk3VZ+7UAx5Ca4FK5d80uhb6NH1b IzxW1RH86Zr7V0WGRhYcwRDmbg5Z8ykH2AGVla4dXdCSlqKlwHmPZ50iLZFuS1Dv88cH 3s5u2tOFevWDW3uxjleshuFD2LTEGCSK4HGhpZffSsl5DADVn0qCxV50aGotBWbhZaFc G8Pw== X-Forwarded-Encrypted: i=1; AJvYcCXf51WY6X4j7RHD5iHkAf7JhZtA05xYagywXR+I5rOFXyK6oMRJ2m5I1b0THKyFKKTJKzsefUn+TtpyWW64uubgF2McjnDJkhZ/i8JXY5uB X-Gm-Message-State: AOJu0YyPwbJra+nDPymsmii+SRgzXDZVPazaR2E3OMZ/oIvBMtiOO6t1 KE2zS79HjPZu3l0qki2TDbSPH0scQcWNxO0ggQvxHjgBOxn8W/S6xZ3Tn/nEmBw= X-Google-Smtp-Source: AGHT+IE50Pp+2/Wa8GXXWTQqvcE4yzBnlnYNnnShgb/W714yZn0SAXzbdPgA3nC1n82GoyzcKq2MiQ== X-Received: by 2002:a17:902:6806:b0:1db:cbff:df15 with SMTP id h6-20020a170902680600b001dbcbffdf15mr7399748plk.9.1708401089700; Mon, 19 Feb 2024 19:51:29 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:29 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 4/5] libbpf: add the function libbpf_find_kernel_btf_id() Date: Tue, 20 Feb 2024 11:51:04 +0800 Message-Id: <20240220035105.34626-5-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add new function libbpf_find_kernel_btf_id() to find the btf type id of the kernel, including vmlinux and modules. Signed-off-by: Menglong Dong --- tools/lib/bpf/libbpf.c | 83 ++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 3 ++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 87 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 01f407591a92..44e34007de8c 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9500,6 +9500,89 @@ int libbpf_find_vmlinux_btf_id(const char *name, return libbpf_err(err); } +int libbpf_find_kernel_btf_id(const char *name, + enum bpf_attach_type attach_type, + int *btf_obj_fd, int *btf_type_id) +{ + struct btf *btf, *vmlinux_btf; + struct bpf_btf_info info; + __u32 btf_id = 0, len; + char btf_name[64]; + int err, fd; + + vmlinux_btf = btf__load_vmlinux_btf(); + err = libbpf_get_error(vmlinux_btf); + if (err) + return libbpf_err(err); + + err = find_attach_btf_id(vmlinux_btf, name, attach_type); + if (err > 0) { + *btf_type_id = err; + *btf_obj_fd = 0; + err = 0; + goto out; + } + + /* kernel too old to support module BTFs */ + if (!feat_supported(NULL, FEAT_MODULE_BTF)) { + err = -EOPNOTSUPP; + goto out; + } + + while (true) { + err = bpf_btf_get_next_id(btf_id, &btf_id); + if (err) { + err = -errno; + goto out; + } + + fd = bpf_btf_get_fd_by_id(btf_id); + if (fd < 0) { + if (errno == ENOENT) + continue; + err = -errno; + goto out; + } + + len = sizeof(info); + memset(&info, 0, sizeof(info)); + info.name = ptr_to_u64(btf_name); + info.name_len = sizeof(btf_name); + + err = bpf_btf_get_info_by_fd(fd, &info, &len); + if (err) { + err = -errno; + goto fd_out; + } + + if (!info.kernel_btf || strcmp(btf_name, "vmlinux") == 0) { + close(fd); + continue; + } + + btf = btf_get_from_fd(fd, vmlinux_btf); + err = libbpf_get_error(btf); + if (err) + goto fd_out; + + err = find_attach_btf_id(btf, name, attach_type); + if (err > 0) { + *btf_type_id = err; + *btf_obj_fd = fd; + err = 0; + break; + } + close(fd); + continue; +fd_out: + close(fd); + break; + } +out: + btf__free(vmlinux_btf); + return err; +} + static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd) { struct bpf_prog_info info; diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 5723cbbfcc41..ca151bbec833 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -306,6 +306,9 @@ LIBBPF_API int libbpf_attach_type_by_name(const char *name, enum bpf_attach_type *attach_type); LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name, enum bpf_attach_type attach_type); +LIBBPF_API int libbpf_find_kernel_btf_id(const char *name, + enum bpf_attach_type attach_type, + int *btf_obj_fd, int *btf_type_id); /* Accessors of bpf_program */ struct bpf_program; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 86804fd90dd1..73c60f47b4bb 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -413,4 +413,5 @@ LIBBPF_1.4.0 { bpf_token_create; btf__new_split; btf_ext__raw_data; + libbpf_find_kernel_btf_id; } LIBBPF_1.3.0; From patchwork Tue Feb 20 03:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 13563368 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B4F5822C for ; Tue, 20 Feb 2024 03:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401098; cv=none; b=cwSRm049PRT2cJuiKyN5z+XQ04Cu1A4Ovpx39k9q0QjcUBp5GxmFG6bxLjSwQmp0Gdr1nRCydiJwFfnlSU4QLNPDXsQMv6HY/nByrHomqQUkuA+R8g7fdVifTf0qOChMOPBWZUN+2Qw/FLofbimuaVHeqi+lI/B3+NsYegRchss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401098; c=relaxed/simple; bh=C3elKZgirtX7W4quQAT+pcAU39WJO4TotIfoaieEyx0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FKr1kqQpWVbQXzAT4NL2WdX0LnIa/06xBiusTM/qBOQcLzq60ro4VZonP3EJGOQdW8+Bi2fhIAMhdIn/eP3gpbEpzQxfi6GDABWa1GMZeS+aX+hIiiH92UhO3Rk+N32o4JmwyOATLaERfDLZNx0XuCyMHvi2EVdg4aj1GqShWLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=kIuiB9lI; arc=none smtp.client-ip=209.85.167.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="kIuiB9lI" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3bba50cd318so3870486b6e.0 for ; Mon, 19 Feb 2024 19:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401096; x=1709005896; darn=vger.kernel.org; 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=XIatRLdxp59gkCuXn1TM1+7Ffjtt7PxZsUax3x716A4=; b=kIuiB9lIdHcAmrh7dG0Vq56nvrYZrneaKgR4OHzLsAQPDFu3vxmqzAxcnPso9PebQz n/CzyF6z2BalvIVT/7AWV48xhbKfvu9t3pCRnXEaet61okgalvSpI2ORv/FGVHiRzeLz +P0zujx+U6xiWpDy3w7WV8dAccKJ6UDcTWA28AVokRLkqrWuyQrvMC0a0tTKXjkKZCPB KPSnVeQmN6DoLSIkeRQQ13v08S1W+TTujUK0b9O2jD7RXJ4Lj8ulpD60JI24uQ1FCikU Xwbv3WsoPFD47cAgraO6uB90i7nk/FmEyKIO3UsY8an/awj9QzVOgq1nfneA077E2/4F QqOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401096; x=1709005896; 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=XIatRLdxp59gkCuXn1TM1+7Ffjtt7PxZsUax3x716A4=; b=hlBLRoO5Wjx10Yr8AcO5jCW+JLbvslwQe2YfDz3TD/4BQnJr+7qpVMkdzQ0JSTfxP5 M0/OlRyKdXsyNYj88xTKoHHZQyU3BGVwoZa38PFSAbqntr7Xg5pHM2XtzFIa3jT+buXX ioj54BhbYWwa+p8EVQ3i9l8T130cX2If3diUn5EsjKIIqK+DUuGVw3RojNsp93Rk6J+2 wXGCOE1qolXmFg7axvLARIXxVU88M+/p4SvHABxyZNu3o0JlpHANh9bpczBXND68w55a wTsY1mJths6O2zYmqpZ5INN+sGeG7MCif2H6OfTUVkr0MllPH4Yih/FE7spok+nt/+yY BdkA== X-Forwarded-Encrypted: i=1; AJvYcCU036WfIlm4ta6mAmh79up0a593IlwtQ7P2fEcVK9L8Zg2XUrBRS+8/j/bCfyDNWaxnn0A38jseBm0OzQlVogJpqfJnR3TEfu/jNkg4jFL8 X-Gm-Message-State: AOJu0YxesdHFmuRihT3qt1s4ChTNzH03OfV8c+RpLUeEngTBhBsJnnzE eBSGSJDdTZUXavTLQbmVD9YT13i/p6dWZMcIj9dW9iESr3F7XYE1rQNNnkdZpug= X-Google-Smtp-Source: AGHT+IGR3ZiUXeeQYK4PiqThY08Xd9MG8AmFv61MNQVpDP2MDd+C2I7YVN1xqhHQa/R/QyD8+ZbFGQ== X-Received: by 2002:a05:6808:1646:b0:3c1:3427:fef3 with SMTP id az6-20020a056808164600b003c13427fef3mr18759661oib.48.1708401095822; Mon, 19 Feb 2024 19:51:35 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:35 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 5/5] selftests/bpf: add test cases for multiple attach of tracing program Date: Tue, 20 Feb 2024 11:51:05 +0800 Message-Id: <20240220035105.34626-6-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In this commit, we add the testcases for multiple attaching of tracing, include FENTRY, FEXIT, MODIFY_RETURN. Signed-off-by: Menglong Dong --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 49 ++++++ .../bpf/prog_tests/tracing_multi_attach.c | 155 ++++++++++++++++++ .../selftests/bpf/progs/tracing_multi_test.c | 72 ++++++++ 3 files changed, 276 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_multi_attach.c create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_test.c diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c index 66787e99ba1b..237eeb7daa07 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -98,12 +98,61 @@ bpf_testmod_test_struct_arg_8(u64 a, void *b, short c, int d, void *e, return bpf_testmod_test_struct_arg_result; } +noinline int +bpf_testmod_test_struct_arg_9(struct bpf_testmod_struct_arg_2 a, + struct bpf_testmod_struct_arg_1 b) { + bpf_testmod_test_struct_arg_result = a.a + a.b + b.a; + return bpf_testmod_test_struct_arg_result; +} + +noinline int +bpf_testmod_test_struct_arg_10(int a, struct bpf_testmod_struct_arg_2 b) { + bpf_testmod_test_struct_arg_result = a + b.a + b.b; + return bpf_testmod_test_struct_arg_result; +} + +noinline struct bpf_testmod_struct_arg_2 * +bpf_testmod_test_struct_arg_11(int a, struct bpf_testmod_struct_arg_2 b, int c) { + bpf_testmod_test_struct_arg_result = a + b.a + b.b + c; + return (void *)bpf_testmod_test_struct_arg_result; +} + +noinline int +bpf_testmod_test_struct_arg_12(int a, struct bpf_testmod_struct_arg_2 b, int *c) { + bpf_testmod_test_struct_arg_result = a + b.a + b.b + *c; + return bpf_testmod_test_struct_arg_result; +} + noinline int bpf_testmod_test_arg_ptr_to_struct(struct bpf_testmod_struct_arg_1 *a) { bpf_testmod_test_struct_arg_result = a->a; return bpf_testmod_test_struct_arg_result; } +noinline int +bpf_testmod_test_arg_ptr_1(struct bpf_testmod_struct_arg_1 *a) { + bpf_testmod_test_struct_arg_result = a->a; + return bpf_testmod_test_struct_arg_result; +} + +noinline int +bpf_testmod_test_arg_ptr_2(struct bpf_testmod_struct_arg_2 *a) { + bpf_testmod_test_struct_arg_result = a->a + a->b; + return bpf_testmod_test_struct_arg_result; +} + +noinline int +bpf_testmod_test_arg_ptr_3(int a, struct bpf_testmod_struct_arg_2 *b) { + bpf_testmod_test_struct_arg_result = a + b->a + b->b; + return bpf_testmod_test_struct_arg_result; +} + +noinline int +bpf_testmod_test_arg_ptr_4(struct bpf_testmod_struct_arg_2 *a, int b) { + bpf_testmod_test_struct_arg_result = a->a + a->b + b; + return bpf_testmod_test_struct_arg_result; +} + __bpf_kfunc void bpf_testmod_test_mod_kfunc(int i) { diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi_attach.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi_attach.c new file mode 100644 index 000000000000..6162d41cca9e --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi_attach.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Bytedance. */ + +#include +#include "tracing_multi_test.skel.h" + +struct test_item { + char *prog; + char *target; + int attach_type; + bool success; + int link_fd; +}; + +static struct test_item test_items[] = { + { + .prog = "fentry_test1", .target = "bpf_testmod_test_struct_arg_9", + .attach_type = BPF_TRACE_FENTRY, .success = true, + }, + { + .prog = "fentry_test1", .target = "bpf_testmod_test_struct_arg_1", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test1", .target = "bpf_testmod_test_struct_arg_2", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test1", .target = "bpf_testmod_test_arg_ptr_2", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test2", .target = "bpf_testmod_test_struct_arg_2", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test2", .target = "bpf_testmod_test_struct_arg_10", + .attach_type = BPF_TRACE_FENTRY, .success = true, + }, + { + .prog = "fentry_test2", .target = "bpf_testmod_test_struct_arg_9", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test2", .target = "bpf_testmod_test_arg_ptr_3", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test3", .target = "bpf_testmod_test_arg_ptr_3", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fentry_test3", .target = "bpf_testmod_test_arg_ptr_4", + .attach_type = BPF_TRACE_FENTRY, .success = true, + }, + { + .prog = "fentry_test4", .target = "bpf_testmod_test_struct_arg_4", + .attach_type = BPF_TRACE_FENTRY, .success = true, + }, + { + .prog = "fentry_test4", .target = "bpf_testmod_test_struct_arg_2", + .attach_type = BPF_TRACE_FENTRY, .success = true, + }, + { + .prog = "fentry_test4", .target = "bpf_testmod_test_struct_arg_12", + .attach_type = BPF_TRACE_FENTRY, .success = false, + }, + { + .prog = "fexit_test1", .target = "bpf_testmod_test_struct_arg_2", + .attach_type = BPF_TRACE_FEXIT, .success = true, + }, + { + .prog = "fexit_test1", .target = "bpf_testmod_test_struct_arg_3", + .attach_type = BPF_TRACE_FEXIT, .success = true, + }, + { + .prog = "fexit_test1", .target = "bpf_testmod_test_struct_arg_4", + .attach_type = BPF_TRACE_FEXIT, .success = false, + }, + { + .prog = "fexit_test2", .target = "bpf_testmod_test_struct_arg_10", + .attach_type = BPF_TRACE_FEXIT, .success = false, + }, + { + .prog = "fexit_test2", .target = "bpf_testmod_test_struct_arg_11", + .attach_type = BPF_TRACE_FEXIT, .success = false, + }, + { + .prog = "fexit_test2", .target = "bpf_testmod_test_struct_arg_12", + .attach_type = BPF_TRACE_FEXIT, .success = true, + }, + { + .prog = "fmod_ret_test1", .target = "bpf_modify_return_test2", + .attach_type = BPF_MODIFY_RETURN, .success = true, + }, +}; + +static int do_test_item(struct tracing_multi_test *skel, struct test_item *item) +{ + LIBBPF_OPTS(bpf_link_create_opts, link_opts); + struct bpf_program *prog; + int err, btf_fd = 0, btf_type_id; + + err = libbpf_find_kernel_btf_id(item->target, item->attach_type, + &btf_fd, &btf_type_id); + if (!ASSERT_OK(err, "find_vmlinux_btf_id")) + return -1; + + link_opts.target_btf_id = btf_type_id; + prog = bpf_object__find_program_by_name(skel->obj, item->prog); + if (!ASSERT_OK_PTR(prog, "find_program_by_name")) + return -1; + + err = bpf_link_create(bpf_program__fd(prog), btf_fd, item->attach_type, + &link_opts); + item->link_fd = err; + if (item->success) { + if (!ASSERT_GE(err, 0, "link_create")) + return -1; + } else { + if (!ASSERT_LT(err, 0, "link_create")) + return -1; + } + + return 0; +} + +void test_tracing_multi_attach(void) +{ + struct tracing_multi_test *skel; + int i = 0, err, fd; + + skel = tracing_multi_test__open_and_load(); + if (!ASSERT_OK_PTR(skel, "tracing_multi_test__open_and_load")) + return; + + err = tracing_multi_test__attach(skel); + if (!ASSERT_OK(err, "tracing_multi_test__attach")) + goto destroy_skel; + + for (; i < ARRAY_SIZE(test_items); i++) { + if (do_test_item(skel, &test_items[i])) + break; + } + + for (i = 0; i < ARRAY_SIZE(test_items); i++) { + fd = test_items[i].link_fd; + if (fd >= 0) + close(fd); + } + + tracing_multi_test__detach(skel); +destroy_skel: + tracing_multi_test__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_test.c b/tools/testing/selftests/bpf/progs/tracing_multi_test.c new file mode 100644 index 000000000000..f1ca8b64ed16 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/tracing_multi_test.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 ByteDance */ +#include +#include +#include + +char _license[] SEC("license") = "GPL"; + +struct bpf_testmod_struct_arg_1 { + int a; +}; +struct bpf_testmod_struct_arg_2 { + long a; + long b; +}; + +__u64 fentry_test1_result = 0; +SEC("fentry/bpf_testmod_test_struct_arg_1") +int BPF_PROG2(fentry_test1, struct bpf_testmod_struct_arg_2, a) +{ + fentry_test1_result = a.a + a.b; + return 0; +} + +__u64 fentry_test2_result = 0; +SEC("fentry/bpf_testmod_test_struct_arg_2") +int BPF_PROG2(fentry_test2, int, a, struct bpf_testmod_struct_arg_2, b) +{ + fentry_test2_result = a + b.a + b.b; + return 0; +} + +__u64 fentry_test3_result = 0; +SEC("fentry/bpf_testmod_test_arg_ptr_2") +int BPF_PROG(fentry_test3, struct bpf_testmod_struct_arg_2 *a) +{ + fentry_test3_result = a->a + a->b; + return 0; +} + +__u64 fentry_test4_result = 0; +SEC("fentry/bpf_testmod_test_struct_arg_1") +int BPF_PROG2(fentry_test4, struct bpf_testmod_struct_arg_2, a, int, b, + int, c) +{ + fentry_test3_result = c; + return 0; +} + +__u64 fexit_test1_result = 0; +SEC("fexit/bpf_testmod_test_struct_arg_1") +int BPF_PROG2(fexit_test1, struct bpf_testmod_struct_arg_2, a, int, b, + int, c, int, retval) +{ + fexit_test1_result = retval; + return 0; +} + +__u64 fexit_test2_result = 0; +SEC("fexit/bpf_testmod_test_struct_arg_2") +int BPF_PROG2(fexit_test2, int, a, struct bpf_testmod_struct_arg_2, b, + int, c, int, retval) +{ + fexit_test2_result = a + b.a + b.b + retval; + return 0; +} + +SEC("fmod_ret/bpf_modify_return_test") +int BPF_PROG(fmod_ret_test1, int a, int *b) +{ + return 0; +}