From patchwork Wed Jan 25 16:47:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48210 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp373286wrn; Wed, 25 Jan 2023 08:48:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsZiTYGD6TB02QaMSSl9wZukxASBGz1KPC8msYZKE1hX7HcMNL1Bld3GXT3LAUeei+Aj3qD X-Received: by 2002:a17:903:2c7:b0:189:f7c2:7245 with SMTP id s7-20020a17090302c700b00189f7c27245mr36333927plk.45.1674665294747; Wed, 25 Jan 2023 08:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665294; cv=none; d=google.com; s=arc-20160816; b=yezO4TARhRjNB355rpScJsM0Htx/+fb9fZkdtXwDlOXSt6T94RFmX4wJ2akBP/Lm24 iwhjD4N3k42YhSgu6ImJ1IilUs7J/YAPcK0uBFOvrW9E/fNwgv9ZaCMA26zXWkFZwtUh n8A5mpuJaBLNxxeF/dRGNMGEOhqVFWl6pzV2Ypcm1ElEaaMTNcgsT+MmfJWmdwgZiNRM qgri8tkyo2GHXWAi9/KAMUvUlAl600FHVc2ueaocY5uAsLFgmEAT5GHh3sygGru+2dXO CqedCWQ860d+rLC+jXKoLJC8GepBzwLC+mCdKRaG7d/pXWtWgusHa7myBx0XEvHXlHiw /W8g== 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=GXEvYhVDnMHXNpqr41k3IdTNthtzRVxr3+zGczCqXyE=; b=QzXtn/K+7/hqW6Aofep9l4sT4hc+2wIJAHCVw1RQcgrWFXzRBIHsrAGSPT901htuoO KikcoPln26WoqPCJwddFCbuEmYOs3BNA0eA8IzOFv0oZJ8UZoU6eaIZfXR6Vrjn/K8ki DX730zRsnWac0YZ/OYY+iGaLUM+/LA8JRUXC1fr9MOCHVzepYUs2bKBjp/frB5oCc/8i nxr1l0T4zq9xuxiVWZAXBoiDDo9Du84RiGN6jphcJolYURYgIXEqFnX6EHEP7ChNBAAo IAF2qfyYqPQdpDaCWF10MDqAe6X6Q0VgaPApnTWWnhA25aBVogktDvVvTQHPbR1BOmb9 tlNA== 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 p16-20020a170902a41000b0019497c8ff7asi5677227plq.284.2023.01.25.08.48.02; Wed, 25 Jan 2023 08:48:14 -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 S235681AbjAYQrr (ORCPT + 99 others); Wed, 25 Jan 2023 11:47:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235644AbjAYQrp (ORCPT ); Wed, 25 Jan 2023 11:47:45 -0500 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AEA10D7; Wed, 25 Jan 2023 08:47:43 -0800 (PST) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-4fd37a1551cso247167597b3.13; Wed, 25 Jan 2023 08:47:43 -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=GXEvYhVDnMHXNpqr41k3IdTNthtzRVxr3+zGczCqXyE=; b=Vj3mRByIac6HCB6wepeCufmGmkpQgfJ8Ux/SDBiG7mf3mTYoqxZWIUw6OZ0s0Lhfdw 1enWOm8xgxxejiYHxKyJ2lrfp2mrQ0cVM6LbsPJrEZVNVJNZGEvqJ4CoRVzKxu0We2TL qtqVh4yxeRVefvYO+8TAR3h11DrDrH4cLOxdaskojjaDBrtE+x1yko+PGZGoCeKeJ6Xq iBqW8AcyhGE9t0NhLEDv4Oku8mZUfpU1oyjqzbj0h176hjMeWYfYgDua6GIgr8kRbKMw lKMjp2yMCMX6npBqvjFd7zJJOz6Qr3IZ5lRI3Nu/d5UX2XebZHGoJ2+Vc7U17lzWdcR2 YhjA== X-Gm-Message-State: AFqh2krZjlPq0jPkjnL0wFBtSs4J0sYgEux3Ws+Wt0fJfyqCIk0ww3i3 Olu2/XpY1czljoZZBASHCYWhVACWIezYbhgr X-Received: by 2002:a81:1353:0:b0:502:9f7e:3117 with SMTP id 80-20020a811353000000b005029f7e3117mr13066092ywt.10.1674665262446; Wed, 25 Jan 2023 08:47:42 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:113e]) by smtp.gmail.com with ESMTPSA id q15-20020a05620a038f00b007090f7a4f2asm3769263qkm.82.2023.01.25.08.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 08:47:42 -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 v4 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable Date: Wed, 25 Jan 2023 10:47:32 -0600 Message-Id: <20230125164735.785732-2-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125164735.785732-1-void@manifault.com> References: <20230125164735.785732-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 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?1756013835966948683?= X-GMAIL-MSGID: =?utf-8?q?1756013835966948683?= BPF struct_ops programs currently cannot be marked as sleepable. This need not be the case -- struct_ops programs can be sleepable, and e.g. invoke kfuncs that export the KF_SLEEPABLE flag. So as to allow future struct_ops programs to invoke such kfuncs, this patch updates the verifier to allow struct_ops programs to be sleepable. A follow-on patch will add support to libbpf for specifying struct_ops.s as a sleepable struct_ops program, and then another patch will add testcases to the dummy_st_ops selftest suite which test sleepable struct_ops behavior. Signed-off-by: David Vernet --- kernel/bpf/verifier.c | 5 +++-- tools/testing/selftests/bpf/verifier/sleepable.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index bb38b01b738f..c8907df49f81 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17114,7 +17114,8 @@ static bool can_be_sleepable(struct bpf_prog *prog) } } return prog->type == BPF_PROG_TYPE_LSM || - prog->type == BPF_PROG_TYPE_KPROBE; /* only for uprobes */ + prog->type == BPF_PROG_TYPE_KPROBE /* only for uprobes */ || + prog->type == BPF_PROG_TYPE_STRUCT_OPS; } static int check_attach_btf_id(struct bpf_verifier_env *env) @@ -17136,7 +17137,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) } if (prog->aux->sleepable && !can_be_sleepable(prog)) { - verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable\n"); + verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable\n"); return -EINVAL; } diff --git a/tools/testing/selftests/bpf/verifier/sleepable.c b/tools/testing/selftests/bpf/verifier/sleepable.c index bea0daef908a..1f0d2bdc673f 100644 --- a/tools/testing/selftests/bpf/verifier/sleepable.c +++ b/tools/testing/selftests/bpf/verifier/sleepable.c @@ -85,7 +85,7 @@ .expected_attach_type = BPF_TRACE_RAW_TP, .kfunc = "sched_switch", .result = REJECT, - .errstr = "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable", + .errstr = "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable", .flags = BPF_F_SLEEPABLE, .runs = -1, }, From patchwork Wed Jan 25 16:47:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48211 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp373416wrn; Wed, 25 Jan 2023 08:48:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXs9//JLMDnpj/rJnVlm8NaCpc60zGryPMV50hBc/XwncMWLgO2ZEsGpBgpaJR8rmpD8v4aj X-Received: by 2002:a17:90a:4fa4:b0:226:f7d7:50f4 with SMTP id q33-20020a17090a4fa400b00226f7d750f4mr57460859pjh.21.1674665316049; Wed, 25 Jan 2023 08:48:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665316; cv=none; d=google.com; s=arc-20160816; b=IdkbrDvZuggLKa/jnmZ/k9PDBSURYHcL/jj8JzVBaghH+tfZ1p/RmByhuj0fBO7CmE /BWoS+UhPZBuCzFyiLLbADi7zWhfMbr8FBqWIwJ7qrtIBE/bI+v1s7tF+ZuGTprSGQI4 kfjt5QB9Ds+0rBEqGEXUI+b1quxGrz4+yFO9XwJwt4RvjTXQq7RDvKw87wg/VsHaVwi1 pVXO6af40m0JaXbPI3NcrHrt9adH6jKTycutBzDMIf+tAD2sFpqGIpsdPmlQeTSNJg6F x91mUcsDDq+OKVJY+85itW2FFxFaIKhYGyExa9krd7SrnMxFaFb9kQi3micTvHdBddFx Kmkw== 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=/fu5eVF7dMpmGGWY5c48C3xPPttDeaZkjkMTCdf0Gr0=; b=UlCmU2T6Z4dQ/iLdQlpCn5cZPgAp+DDaBr976VcXtUgErrEgOAcxG4n5+AgoLEG4P6 Y7OgKID+PqQIlLvjuAeKgolVYRRO6PXyR2/ZMRWeHCloQ9nkrMBL8pfkAMGiqlNFs7rz iCpPTZ+/yh6k4XzL2vlfB78ozUzMFQbG8b9dURTesr5TxE2c2u2nde2kbjtNAOYp2hie 49eYIlCyoWC4YMwPupqTdQeJzz1mpVQQ+9Wb77M8HvlhoyORrmp9+7z3nu5ZsIG1/EUx D4R1+fGBeuKaIkzmN/PIrUfTuYoP9vnmBf2m5BmoPIV4BxNGkPMU5BrLQN6/ZGTTrG3b S2MA== 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 r22-20020a17090aa09600b00213ff43fdf1si2325418pjp.185.2023.01.25.08.48.24; Wed, 25 Jan 2023 08:48:36 -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 S235718AbjAYQru (ORCPT + 99 others); Wed, 25 Jan 2023 11:47:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235653AbjAYQrp (ORCPT ); Wed, 25 Jan 2023 11:47:45 -0500 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0691540D8; Wed, 25 Jan 2023 08:47:45 -0800 (PST) Received: by mail-qt1-f173.google.com with SMTP id s4so16449992qtx.6; Wed, 25 Jan 2023 08:47:44 -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=/fu5eVF7dMpmGGWY5c48C3xPPttDeaZkjkMTCdf0Gr0=; b=wNpoY2n+4DsfrQ9AjqljcGc3+4BZxaC+YvoNLxjQ3X+ePDRJNT5wgwJ7pn7I0p3BWr tCXhLfYI5RaHiS2TVhAouwR0CGPs7IY1SpFoiQhXfHoMWSZ8nBnFbJ8kl5rPaw3rsI8X q87bi2SP+rDfR10Vi/2JamBE0oxzxqTvJizPt7gdP5IpqJZbUwyxSXDr5SylY1yc2T0W tOa7tadoiykz2t4YY3cbhCeF4prwzar8HdZk2/xdyBMzii7RkB5c6Vi622UamBQ7Q8f+ VNS5tZYRpYJaLlP+KcOk1YJJvU2WvSUlzdLxR3hZphhq0dH7tno2oKfViQY+A3i97nEn pXDg== X-Gm-Message-State: AO0yUKVqMHBWuH2AzmxMNNQFMnkaBzUz3ZRs8f6wc5Fh4kAVhPODJk7V 7JyC9Ax1wAuOox30MYBYU4+uqf2XIFSeuWnE X-Received: by 2002:ac8:5c0f:0:b0:3b6:38cf:1277 with SMTP id i15-20020ac85c0f000000b003b638cf1277mr5384935qti.64.1674665263814; Wed, 25 Jan 2023 08:47:43 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:113e]) by smtp.gmail.com with ESMTPSA id j129-20020a378787000000b00706a1551428sm3859774qkd.6.2023.01.25.08.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 08:47:43 -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 v4 2/4] libbpf: Support sleepable struct_ops.s section Date: Wed, 25 Jan 2023 10:47:33 -0600 Message-Id: <20230125164735.785732-3-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125164735.785732-1-void@manifault.com> References: <20230125164735.785732-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1756013858473981892?= X-GMAIL-MSGID: =?utf-8?q?1756013858473981892?= In a prior change, the verifier was updated to support sleepable BPF_PROG_TYPE_STRUCT_OPS programs. A caller could set the program as sleepable with bpf_program__set_flags(), but it would be more ergonomic and more in-line with other sleepable program types if we supported suffixing a struct_ops section name with .s to indicate that it's sleepable. Signed-off-by: David Vernet --- tools/lib/bpf/libbpf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 27d9faa80471..eed5cec6f510 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8605,6 +8605,7 @@ static const struct bpf_sec_def section_defs[] = { SEC_DEF("cgroup/setsockopt", CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT, SEC_ATTACHABLE), SEC_DEF("cgroup/dev", CGROUP_DEVICE, BPF_CGROUP_DEVICE, SEC_ATTACHABLE_OPT), SEC_DEF("struct_ops+", STRUCT_OPS, 0, SEC_NONE), + SEC_DEF("struct_ops.s+", STRUCT_OPS, 0, SEC_SLEEPABLE), SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE), }; From patchwork Wed Jan 25 16:47:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48212 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp374333wrn; Wed, 25 Jan 2023 08:50:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXuTaNJX4gqTF7O8qY37YfqwIboFCxeWfv+ZU8KdZ4ts8GK4G3atHDzOJUnUb1gxre+J+WMX X-Received: by 2002:a05:6402:e9f:b0:49a:f52f:eed0 with SMTP id h31-20020a0564020e9f00b0049af52feed0mr34496634eda.13.1674665449417; Wed, 25 Jan 2023 08:50:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665449; cv=none; d=google.com; s=arc-20160816; b=EOiWIRmAJfigGQCWvcSD12qpxXgnxjA77BODVfIXs+YJLh0STfwrKMRH5FHA7AxpHY G99ISFUY6KB4iQ5YPkwutOaMvm104/S013ruYUz3pi8ZamzxXpVDMGF3g5RZBmX1dAI/ P+MEFqEs2RJHYkk2Jy5be2OydIDXRrgZUCpkTqSv4s16lOIFRAXq5BqldH75QDdjxGZf Rkig+TFIhpNe+wkqU0BpjTuE56b2pX9wcaO86pLrSnAdvG5teRahS5qrt0vTNh3U2Jt8 +JelZMxzSZR6RnQHCF9aTDyFYR+4KubzDgSN/8yrh9vM5mR8kSv5DMdVVMzlxUXxyzbM zA+Q== 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=pGxzySYtoUdE+E5gljdC4XUw0xMv3aIF1+OGStefhxI=; b=wW9EbZeJs7RksLHeGgD9H4TI/IWdacv56NSDFajvxm/+qPnr3jdIf1ODmzAnWDcFmv yL+amd7JUbch0VxOpQUevrm1p72UfmLYWkaSWP+6EJf/ic+o2YgVL9xf2W+TE1wtjdAR lfnK8b8/BT5Q7+CMbz1RcWkwJY1PTZJnvXLr8oKiqOH5PWjZ02TBj+kzc//JD5qRc3Vm +q4BgJJiLMlk7jXGqEx3iJOuANK3F5BeN2+3DNN1XIyO1jlGcoN7zWHqNpOLmIPKbQBv z7ztn7qZKbL4Pnc8+r4I1j9ke6H1pNvEm+yhhLTfk9eH6b4FFzaha9tIZ4ZG9X6AHIca g1vQ== 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 v17-20020aa7d811000000b0046b55a18bc4si3964143edq.436.2023.01.25.08.50.25; Wed, 25 Jan 2023 08:50:49 -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 S235818AbjAYQr5 (ORCPT + 99 others); Wed, 25 Jan 2023 11:47:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235688AbjAYQrr (ORCPT ); Wed, 25 Jan 2023 11:47:47 -0500 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F3972A0; Wed, 25 Jan 2023 08:47:46 -0800 (PST) Received: by mail-qt1-f175.google.com with SMTP id z9so16453395qtv.5; Wed, 25 Jan 2023 08:47:46 -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=pGxzySYtoUdE+E5gljdC4XUw0xMv3aIF1+OGStefhxI=; b=cBXJUAyFUbLK2KQ99yMT0mdq2UYnLq6U2vNGZsYn0NYhlODqrLb1r+GAVZPhdiolhx 0btzhW63NWFWFKwmBcV8ytU/u/zSzeYVOTV/Hgym9JRIqZcUd6bwkflczZdrIt87fre+ EdvhbduqzmMjid3NZWZpLXzJNaEnLNKw+8fHBa570B6ExA98xNZo36Fo17oXhodSR+by gdc/VOalRrrnGhPJGcuCSQ4N0g58GY7tKR3O+vYRMawjbNiI5UYsPBGofm7enRUoTEWe 0aq3hvikUvTpfjMxSht3e1xy+SMbvt7Cdh//eDNoTXzw8PVKUkrYQ8KV89BExHL1LojH r6Sw== X-Gm-Message-State: AO0yUKV05faV/lCBxFQsdE/0yBh1EvTP8z6VavH7/5xU+jaDOoB2BVrV Db0NmiGLhWOtyEAWQqiLUTYsylBGkc1PcM5Q X-Received: by 2002:ac8:5c09:0:b0:3b6:377d:4330 with SMTP id i9-20020ac85c09000000b003b6377d4330mr4986515qti.29.1674665265146; Wed, 25 Jan 2023 08:47:45 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:113e]) by smtp.gmail.com with ESMTPSA id e127-20020a376985000000b006f9ddaaf01esm3736686qkc.102.2023.01.25.08.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 08:47:44 -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 v4 3/4] bpf: Pass const struct bpf_prog * to .check_member Date: Wed, 25 Jan 2023 10:47:34 -0600 Message-Id: <20230125164735.785732-4-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125164735.785732-1-void@manifault.com> References: <20230125164735.785732-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 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?1756013998248254476?= X-GMAIL-MSGID: =?utf-8?q?1756013998248254476?= 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 1bec48d9e5d9..0d868ef1b973 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 c8907df49f81..6bd097e0d45f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -16792,7 +16792,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; From patchwork Wed Jan 25 16:47:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48213 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp376521wrn; Wed, 25 Jan 2023 08:55:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXs/yUnxioozeG2u4HL4xwqdsGdGFcDb9Jf+1k3QpqVKjpgxfW17H1Z+JcvAAe9Vo8M+jpwj X-Received: by 2002:a05:6402:501e:b0:472:1436:73ab with SMTP id p30-20020a056402501e00b00472143673abmr39069313eda.28.1674665755427; Wed, 25 Jan 2023 08:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665755; cv=none; d=google.com; s=arc-20160816; b=huj1hwDrbDuVbEjofdEgCdxjqIkJKY2WVR7/Pj71O5iqxzlmkE+f+hX8QFu4Oyym0i 7MDerdETfKCefmUA1vi51RrMMkN72UWVd8nSuKhZy1KFtTOTTbwmvKvrndEE7TCt91Sv B+HYdie1Wasm/PxveJ5z2oTAM2r4twFpwx/o9MsFdMxx7rU6b0/x0oCjurPA4q56YUo9 JW9+01sxd+0CUww6eP1MwwxEtTVHn8Ui/EsQ2KYh4+Yz9AkzcGOQa2HIFYyNPjGJ3n9s DElah3ZfgmtoBKi/aBXffMbsjUwTSOEcRl1wsCblbYeKSNg7EooQfjgTi2Q5+D17w+/k j0dQ== 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=jin40lfggyQ0e+XmjWmUlagBMngNuJsNbxMgU6ErLIQ=; b=HrX73ztTwYzQtv2h6nxn2qhakf9LswzO3vPFnuun6PSnpzWugFj3n8nCaz5etIbnzC ZI1tEyLIiQLXi5e6qaQZWMFZ21crWzVeAMi0VosUd2cpnQcVAAppsLLFMg/9uP1PCwFQ 0KrwwPQNDFbY3GDM4nIGXVv4C9ckn7J9rgaREM+WN8o3B/M9Y091EEomn+ljDBvZpdYS /IiwZOCKkuV9FZwvxz9xIRzdIvxCp1BuPPfxMOkGlY+Nv1mBBc3eyLh39q+ed2+0/gUK naUIofrM7VWQIawbF16bK5nmnPXpxybwWRQtIez7p8Nb1O7BnS9+U0nqN5kdAxsUZWPu vluw== 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 t29-20020a50d71d000000b0049e40bd2a0csi7055448edi.22.2023.01.25.08.55.30; Wed, 25 Jan 2023 08:55:55 -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 S235791AbjAYQsB (ORCPT + 99 others); Wed, 25 Jan 2023 11:48:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235772AbjAYQry (ORCPT ); Wed, 25 Jan 2023 11:47:54 -0500 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D7FA5C1; Wed, 25 Jan 2023 08:47:47 -0800 (PST) Received: by mail-yb1-f180.google.com with SMTP id m199so7997685ybm.4; Wed, 25 Jan 2023 08:47:47 -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=jin40lfggyQ0e+XmjWmUlagBMngNuJsNbxMgU6ErLIQ=; b=AODcPH4v6rSSAPj4G/tniCx2QyMQOoWhqBhcfaJFFQ73WdkXlXmKhXG2TzbR0UE+PB ykib7s76KIxzqsrcPQAs39M0DxABFUWliZByNqpAqrisvFfaHSdJesy7ZNsltHI9XiI8 sfvzxefuCHTnd8RuAQZskHuaSTUrChi8VgqAtTZ1FQdGp9EgCRxZaOzNZpaZxEZ/Juld l1iIahc5/OEFEhJuErxa13RNdgfZIls5z8PgbUHhJiq1boiO3DEDL8k7Q3x1EzhO7gA7 tZU3Ze+QXobfNHLH7wIUf/0jWZc6NU478L4XZS9ktWIOWHwHHvv22WAKZoviAQESAAL0 fR1g== X-Gm-Message-State: AFqh2krJO+9n+73rYvVP88dbEruuWTqFJmRzgPRpQxD88GPGCE3jGFJk 5amIbe+AlBJ8+TfcasTmaRmyHc7Knm5yAMdY X-Received: by 2002:a25:a2c2:0:b0:801:6611:ca81 with SMTP id c2-20020a25a2c2000000b008016611ca81mr13130580ybn.16.1674665266478; Wed, 25 Jan 2023 08:47:46 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:113e]) by smtp.gmail.com with ESMTPSA id b5-20020a378005000000b00704a2a40cf2sm3760465qkd.38.2023.01.25.08.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 08:47:46 -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 v4 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior Date: Wed, 25 Jan 2023 10:47:35 -0600 Message-Id: <20230125164735.785732-5-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125164735.785732-1-void@manifault.com> References: <20230125164735.785732-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 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?1756014319257225447?= X-GMAIL-MSGID: =?utf-8?q?1756014319257225447?= In a set of prior changes, we added the ability for struct_ops programs to be sleepable. This patch enhances the dummy_st_ops selftest suite to validate this behavior by adding a new sleepable struct_ops entry to dummy_st_ops. Signed-off-by: David Vernet --- include/linux/bpf.h | 1 + net/bpf/bpf_dummy_struct_ops.c | 18 +++++++ .../selftests/bpf/prog_tests/dummy_st_ops.c | 52 ++++++++++++++----- .../selftests/bpf/progs/dummy_st_ops_fail.c | 27 ++++++++++ ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++---- 5 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c rename tools/testing/selftests/bpf/progs/{dummy_st_ops.c => dummy_st_ops_success.c} (72%) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 0d868ef1b973..14a0264fac57 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1474,6 +1474,7 @@ struct bpf_dummy_ops { int (*test_1)(struct bpf_dummy_ops_state *cb); int (*test_2)(struct bpf_dummy_ops_state *cb, int a1, unsigned short a2, char a3, unsigned long a4); + int (*test_sleepable)(struct bpf_dummy_ops_state *cb); }; int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index 1ac4467928a9..ff4f89a2b02a 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c @@ -154,6 +154,23 @@ static bool bpf_dummy_ops_is_valid_access(int off, int size, return bpf_tracing_btf_ctx_access(off, size, type, prog, info); } +static int bpf_dummy_ops_check_member(const struct btf_type *t, + const struct btf_member *member, + const struct bpf_prog *prog) +{ + u32 moff = __btf_member_bit_offset(t, member) / 8; + + switch (moff) { + case offsetof(struct bpf_dummy_ops, test_sleepable): + break; + default: + if (prog->aux->sleepable) + return -EINVAL; + } + + return 0; +} + static int bpf_dummy_ops_btf_struct_access(struct bpf_verifier_log *log, const struct bpf_reg_state *reg, int off, int size, enum bpf_access_type atype, @@ -208,6 +225,7 @@ static void bpf_dummy_unreg(void *kdata) struct bpf_struct_ops bpf_bpf_dummy_ops = { .verifier_ops = &bpf_dummy_verifier_ops, .init = bpf_dummy_init, + .check_member = bpf_dummy_ops_check_member, .init_member = bpf_dummy_init_member, .reg = bpf_dummy_reg, .unreg = bpf_dummy_unreg, diff --git a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c index c11832657d2b..f43fcb13d2c4 100644 --- a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +++ b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */ #include -#include "dummy_st_ops.skel.h" +#include "dummy_st_ops_success.skel.h" +#include "dummy_st_ops_fail.skel.h" #include "trace_dummy_st_ops.skel.h" /* Need to keep consistent with definition in include/linux/bpf.h */ @@ -11,17 +12,17 @@ struct bpf_dummy_ops_state { static void test_dummy_st_ops_attach(void) { - struct dummy_st_ops *skel; + struct dummy_st_ops_success *skel; struct bpf_link *link; - skel = dummy_st_ops__open_and_load(); + skel = dummy_st_ops_success__open_and_load(); if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) return; link = bpf_map__attach_struct_ops(skel->maps.dummy_1); ASSERT_EQ(libbpf_get_error(link), -EOPNOTSUPP, "dummy_st_ops_attach"); - dummy_st_ops__destroy(skel); + dummy_st_ops_success__destroy(skel); } static void test_dummy_init_ret_value(void) @@ -31,10 +32,10 @@ static void test_dummy_init_ret_value(void) .ctx_in = args, .ctx_size_in = sizeof(args), ); - struct dummy_st_ops *skel; + struct dummy_st_ops_success *skel; int fd, err; - skel = dummy_st_ops__open_and_load(); + skel = dummy_st_ops_success__open_and_load(); if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) return; @@ -43,7 +44,7 @@ static void test_dummy_init_ret_value(void) ASSERT_OK(err, "test_run"); ASSERT_EQ(attr.retval, 0xf2f3f4f5, "test_ret"); - dummy_st_ops__destroy(skel); + dummy_st_ops_success__destroy(skel); } static void test_dummy_init_ptr_arg(void) @@ -58,10 +59,10 @@ static void test_dummy_init_ptr_arg(void) .ctx_size_in = sizeof(args), ); struct trace_dummy_st_ops *trace_skel; - struct dummy_st_ops *skel; + struct dummy_st_ops_success *skel; int fd, err; - skel = dummy_st_ops__open_and_load(); + skel = dummy_st_ops_success__open_and_load(); if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) return; @@ -91,7 +92,7 @@ static void test_dummy_init_ptr_arg(void) ASSERT_EQ(trace_skel->bss->val, exp_retval, "fentry_val"); done: - dummy_st_ops__destroy(skel); + dummy_st_ops_success__destroy(skel); trace_dummy_st_ops__destroy(trace_skel); } @@ -102,12 +103,12 @@ static void test_dummy_multiple_args(void) .ctx_in = args, .ctx_size_in = sizeof(args), ); - struct dummy_st_ops *skel; + struct dummy_st_ops_success *skel; int fd, err; size_t i; char name[8]; - skel = dummy_st_ops__open_and_load(); + skel = dummy_st_ops_success__open_and_load(); if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) return; @@ -119,7 +120,28 @@ static void test_dummy_multiple_args(void) ASSERT_EQ(skel->bss->test_2_args[i], args[i], name); } - dummy_st_ops__destroy(skel); + dummy_st_ops_success__destroy(skel); +} + +static void test_dummy_sleepable(void) +{ + __u64 args[1] = {0}; + LIBBPF_OPTS(bpf_test_run_opts, attr, + .ctx_in = args, + .ctx_size_in = sizeof(args), + ); + struct dummy_st_ops_success *skel; + int fd, err; + + skel = dummy_st_ops_success__open_and_load(); + if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) + return; + + fd = bpf_program__fd(skel->progs.test_sleepable); + err = bpf_prog_test_run_opts(fd, &attr); + ASSERT_OK(err, "test_run"); + + dummy_st_ops_success__destroy(skel); } void test_dummy_st_ops(void) @@ -132,4 +154,8 @@ void test_dummy_st_ops(void) test_dummy_init_ptr_arg(); if (test__start_subtest("dummy_multiple_args")) test_dummy_multiple_args(); + if (test__start_subtest("dummy_sleepable")) + test_dummy_sleepable(); + + RUN_TESTS(dummy_st_ops_fail); } diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c new file mode 100644 index 000000000000..0bf969a0b5ed --- /dev/null +++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ + +#include "vmlinux.h" +#include +#include + +#include "bpf_misc.h" + +char _license[] SEC("license") = "GPL"; + +SEC("struct_ops.s/test_2") +__failure __msg("attach to unsupported member test_2 of struct bpf_dummy_ops") +int BPF_PROG(test_unsupported_field_sleepable, + struct bpf_dummy_ops_state *state, int a1, unsigned short a2, + char a3, unsigned long a4) +{ + /* Tries to mark an unsleepable field in struct bpf_dummy_ops as sleepable. */ + return 0; +} + +SEC(".struct_ops") +struct bpf_dummy_ops dummy_1 = { + .test_1 = NULL, + .test_2 = (void *)test_unsupported_field_sleepable, + .test_sleepable = (void *)NULL, +}; diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c similarity index 72% rename from tools/testing/selftests/bpf/progs/dummy_st_ops.c rename to tools/testing/selftests/bpf/progs/dummy_st_ops_success.c index ead87edb75e2..1efa746c25dc 100644 --- a/tools/testing/selftests/bpf/progs/dummy_st_ops.c +++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c @@ -1,19 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */ -#include +#include "vmlinux.h" #include #include -struct bpf_dummy_ops_state { - int val; -} __attribute__((preserve_access_index)); - -struct bpf_dummy_ops { - int (*test_1)(struct bpf_dummy_ops_state *state); - int (*test_2)(struct bpf_dummy_ops_state *state, int a1, unsigned short a2, - char a3, unsigned long a4); -}; - char _license[] SEC("license") = "GPL"; SEC("struct_ops/test_1") @@ -43,8 +33,15 @@ int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a return 0; } +SEC("struct_ops.s/test_sleepable") +int BPF_PROG(test_sleepable, struct bpf_dummy_ops_state *state) +{ + return 0; +} + SEC(".struct_ops") struct bpf_dummy_ops dummy_1 = { .test_1 = (void *)test_1, .test_2 = (void *)test_2, + .test_sleepable = (void *)test_sleepable, };