From patchwork Tue Jan 24 16:08:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 47756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2243701wrn; Tue, 24 Jan 2023 08:21:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXvI/2LpoMH2dmU5KgQUcUlVi+k4xNgAcC7aoi4kPb3vdMOXXy9mdXUJR3QMOZHJuF7ZlThT X-Received: by 2002:a17:906:b24c:b0:869:236c:ac41 with SMTP id ce12-20020a170906b24c00b00869236cac41mr33124697ejb.24.1674577271049; Tue, 24 Jan 2023 08:21:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674577271; cv=none; d=google.com; s=arc-20160816; b=dALKlxpTVoxWozIZOybIibj4hM0qEsuvLv284TEdjxLX19TTZsjHrclUrhj5HBz3yN DpdUvHuqt3qFq5YFVZXdMykTV0kpRGBWxvnFm4ylwethjRf7DX51M/+fEilwnFSe2k/d +c/eDZN9NxvXLEovIW2KIIcBFnf+NgXoMC7cnTnoAISwBCGzoFitfSvi6m/NyoJBLnkv 6DSl4Fyjvf7jXVkCrHsPqhz0ffdlXOhwX/QtkwD8n4flZ/uG+R4VM3r1Z9XKZnrqdGrv sf0qDD6V97zLDR8BgYME2TifECQi7RA6AMzxQOzJ2ufrdyOl0KWfcD6uWTtZw612q7R1 tR7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vPyaQjSFalprBy0AXNcos253eyU8hf3tSNTKaLeAtbU=; b=FS7KAU/Rz2ChEX7pEDOMy2dAOumglK3gX9dVkM+n10x/00o4BINL2j6bGaefJWbsQU p+EkNM+JxJriCThUZyaKy/R3uQCGF9+2hCkD7XAUHQafiIz76GwWqiOJZf/wRVYwrvCG 7UsyzJGMkfh9aeBQFmaZoMRB3zBCGBf9gClDsTdXZMSoEb35cPE778DA/RkaXJ81BXn1 Pi8fx+kehJTvoudcD/kt6aFghxJlmx01KYwie8JW7beiy7M4fgWwdcH1FPApVModz9bN GIAQUh8zhWn7WDjvHb8BY2n22pPp/AMOeB3ugPgxp5SwHZunTuzBUd77pDj54b+u6ABn 9Keg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ex8-20020a170907954800b007c18ffbf16esi2585647ejc.433.2023.01.24.08.20.47; Tue, 24 Jan 2023 08:21:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233580AbjAXQJn (ORCPT + 99 others); Tue, 24 Jan 2023 11:09:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbjAXQJl (ORCPT ); Tue, 24 Jan 2023 11:09:41 -0500 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F57F4ABEC; Tue, 24 Jan 2023 08:09:30 -0800 (PST) Received: by mail-qv1-f41.google.com with SMTP id n2so11979079qvo.1; Tue, 24 Jan 2023 08:09:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=vPyaQjSFalprBy0AXNcos253eyU8hf3tSNTKaLeAtbU=; b=eXJI/NGrUz19C2WlxSZtJURJ2eHilrHrSosVRdtit+1WY6c0HXwV5jygEj6C5ZFhte 42NkGAgv0Q+dIGdtUsR0n8eMGijKV+S8BMtpC0CMHMGtVLKuzNfXRmwmX65SrvDpSSdX ptUeyLRgg0x7z/Wfpua82IG6Ig3VI3YA1KVXuSbgTsryJBmBibYBo/GMtbA0yRTNsmwp VqyjyuqmeSTzK/T2Ojd55XCJVvTPeHjC/ykpZA9kNSx1vwVQMyI26b94HdMbSw6zYbQM LUcUq87860YM7hz1Soj6qV4j52e+nOBgUyWXTz8oC8lxs/nbZXOPStn8X899aumP1GlV qBmw== X-Gm-Message-State: AFqh2kqsVvmYgzdAimFeWokc/w9LQxIySvEyAv1KEvHW6sHrM8K04oxm pch1y5QXvETYDvSDZ/lQJPZMeBM2xHXPf7VP X-Received: by 2002:a0c:8b12:0:b0:535:2264:7433 with SMTP id q18-20020a0c8b12000000b0053522647433mr38105343qva.6.1674576569229; Tue, 24 Jan 2023 08:09:29 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:93a0]) by smtp.gmail.com with ESMTPSA id e22-20020a05620a209600b006cbe3be300esm1676344qka.12.2023.01.24.08.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 08:09:28 -0800 (PST) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@meta.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, tj@kernel.org Subject: [PATCH bpf-next v2 3/4] bpf: Pass const struct bpf_prog * to .check_member Date: Tue, 24 Jan 2023 10:08:01 -0600 Message-Id: <20230124160802.1122124-4-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230124160802.1122124-1-void@manifault.com> References: <20230124160802.1122124-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755921536562356367?= X-GMAIL-MSGID: =?utf-8?q?1755921536562356367?= The .check_member field of struct bpf_struct_ops is currently passed the member's btf_type via const struct btf_type *t, and a const struct btf_member *member. This allows the struct_ops implementation to check whether e.g. an ops is supported, but it would be useful to also enforce that the struct_ops prog being loaded for that member has other qualities, like being sleepable (or not). This patch therefore updates the .check_member() callback to also take a const struct bpf_prog *prog argument. Signed-off-by: David Vernet --- include/linux/bpf.h | 3 ++- kernel/bpf/verifier.c | 2 +- net/ipv4/bpf_tcp_ca.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index ad4bb36d4c10..50123afab9bf 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1422,7 +1422,8 @@ struct bpf_struct_ops { const struct bpf_verifier_ops *verifier_ops; int (*init)(struct btf *btf); int (*check_member)(const struct btf_type *t, - const struct btf_member *member); + const struct btf_member *member, + const struct bpf_prog *prog); int (*init_member)(const struct btf_type *t, const struct btf_member *member, void *kdata, const void *udata); diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2b8f0c0aa0cc..20dd03498e56 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -16732,7 +16732,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) } if (st_ops->check_member) { - int err = st_ops->check_member(t, member); + int err = st_ops->check_member(t, member, prog); if (err) { verbose(env, "attach to unsupported member %s of struct %s\n", diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c index 4517d2bd186a..13fc0c185cd9 100644 --- a/net/ipv4/bpf_tcp_ca.c +++ b/net/ipv4/bpf_tcp_ca.c @@ -248,7 +248,8 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t, } static int bpf_tcp_ca_check_member(const struct btf_type *t, - const struct btf_member *member) + const struct btf_member *member, + const struct bpf_prog *prog) { if (is_unsupported(__btf_member_bit_offset(t, member) / 8)) return -ENOTSUPP;