From patchwork Wed Jan 25 05:03:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp102300wrn; Tue, 24 Jan 2023 21:13:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXtxTm4oqTbkbHSxmWnEPgC2+H5uyhUnL56/m7PCbAUtFZskMuh+j7ZahQOdbAVsuLA5nm0e X-Received: by 2002:a05:6a20:a89d:b0:af:7320:664c with SMTP id ca29-20020a056a20a89d00b000af7320664cmr28328700pzb.23.1674623612455; Tue, 24 Jan 2023 21:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674623612; cv=none; d=google.com; s=arc-20160816; b=BcPh2wEKzYLCqPzMduWlxo7nfdAFrzorzGNnXDC4t7NlnLta9rMASRBdZt4ZTXDYf8 5iPZTq1qYWHgEa9aly31AiKCvAVcUHSDqBGpOKGSwE5wUU9lPMvXYesTTy5yLQRNZmhv UqNub4+DvyuPwRIF3xKTNgeIM9EuikHa9vb6q+hcOnN8N0R9MQklLOMN9iUqXUsDygyt 684ZZOSQ+PBLvrpUURQi0jSMdRJM4FOLOrUOPNYcOQt7dIr3uyw1MbirBjDnANfyFHbk WQbo8M1ZhzgoVPBwz4sNIFh8O6HQ241Tq4z7DQM2+4TbRuqCnyICaZnsg96mtjOGAMqX BWPQ== 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=avmtjVdlSz7PFCfVWvw/WMVdK3jKu8qVhkizbZMouYn+mFbEyf4IWe99SfG9DAL4u4 eggBjPkSlcdyOfnV+Yqv2x+uuUQd5E29pNZKlUsA1Qq7a4C2LI16zUCKAwUyK5ihPqc3 ZGdNcnDI81gycBl2HtzCqM22gaDXjw4rEnDxHYDvp7iH6keHkpw1SjBqERFd/ChFxXpj xZ5ZEl6hWJgOrAksjvx8hYePDw/ipJI+fh07WAQuHlTopybGiIifJf42mAsMyVoObkQc wbvxcCFbxxc0L21nn4JeP85rlHbW8lYG/64dcZFwaxQhDA4Yw7A+5Vux6O6N1VOOsC0w 9JjA== 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 x21-20020a656ab5000000b00478d30cde9csi4174908pgu.832.2023.01.24.21.13.20; Tue, 24 Jan 2023 21:13:32 -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 S234313AbjAYFEW (ORCPT + 99 others); Wed, 25 Jan 2023 00:04:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234083AbjAYFEO (ORCPT ); Wed, 25 Jan 2023 00:04:14 -0500 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F8D474F4; Tue, 24 Jan 2023 21:04:13 -0800 (PST) Received: by mail-pg1-f171.google.com with SMTP id q9so12684580pgq.5; Tue, 24 Jan 2023 21:04:13 -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=7ERx4DmrZjRzcasQoO3UM8jXd4neDD4F52KG1zFLNTpBayr44dSWqd62m4yThf+MHu akdk+n4OXJYAz0lAKxEy/07ECjhGYHjtTL+n0PiGDmFj2zlsjmg25CzfQqgbvfMOnCKc daWt/VRfXPORJ/cuBgzXEsA4P03rpYZwI1OJ6/v3+Tcgj2C/tqQcURBoCOZrCULOjQVM uOqGXu7grpiY7mxYjTWQbptkjgs2fylRlPwoJQD1n38NUh8OQGmrWqTa7dL3NKqoA/de rh16T6a7+JYDR9x/5eClmL4LeuXj9ppLF1KPUgyvNkKT+dSHQlh2c5THRqAsWqgfURir ZxHg== X-Gm-Message-State: AFqh2kovHS61dxrp6NZks6ZjI/diGl2NEFOmD+4j5aHwZH2l9Bkk0DPE PhCVVphKckCwpTkRvQhFc5AR9JWNumA48zO0 X-Received: by 2002:aa7:982b:0:b0:58b:4ae0:c761 with SMTP id q11-20020aa7982b000000b0058b4ae0c761mr31031791pfl.34.1674623052636; Tue, 24 Jan 2023 21:04:12 -0800 (PST) Received: from localhost ([2620:10d:c090:400::5:d24a]) by smtp.gmail.com with ESMTPSA id z25-20020aa79499000000b005775c52dbc4sm2492216pfk.167.2023.01.24.21.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 21:04:12 -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 v3 3/4] bpf: Pass const struct bpf_prog * to .check_member Date: Tue, 24 Jan 2023 23:03:58 -0600 Message-Id: <20230125050359.339273-4-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125050359.339273-1-void@manifault.com> References: <20230125050359.339273-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?1755970129314113508?= X-GMAIL-MSGID: =?utf-8?q?1755970129314113508?= 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;