From patchwork Wed Jan 25 05:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp101549wrn; Tue, 24 Jan 2023 21:10:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXspCcd/fzIyK6Yu6XpMYk5IYduMdp/CpBE2YrYSUx4g2kxEWy8wOwikt8FG7kA/RI7jDf/1 X-Received: by 2002:a17:902:7c0c:b0:194:6265:ba5f with SMTP id x12-20020a1709027c0c00b001946265ba5fmr29555778pll.8.1674623441931; Tue, 24 Jan 2023 21:10:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674623441; cv=none; d=google.com; s=arc-20160816; b=mjgWBnGAUnwxEezymtUnVmDiSEfPdj1k3NGO0oAgtboTQoniAg1LjFrNEwSUuQOSWo 0/wi3cmqOsts/K6eFJ/43vEEsG+QzgQhZjcaOb9LzgcaMppDWDEO+RBezDcngbMh/tm0 Z8gxAyVL4HVLXJwr6LdPayahswmbvbLwaDLjZv7/hggIhJH8iSEDZnNKNXLLELmMrPLR nsVHusA8YY7JV7HNKXawFUUBTDxCJtbg0/d0bCJNvHBB7SsVMEuiHSAKTHYFUGB0Bkyw d3FkqyHzVUfehHfXFhHJzh5+nRHKvPkyUwTnnPyf2a1TuQX8akiq8GxV4g+IiClE0lSW 2UVg== 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=geJZ0n/Osgu93pxX9vL5o3+bzLvg1dQW9V/BZwV5zXs=; b=aCXfk9i0gRNDiYPp8U/DzNpv5BkYweFTdp82H7VHdqrpdLvwhPi+D8/cldEXVUo2nW aRHkKC2jo/lkFYNAew15Zt23kCGqep6HNf0+EMWsqbZfNfwVwpemyaUzbffkXWv25QRs jkXjVrMKKIAENfEg4KEcI3GTzW9lk0HeDYRwvfjHJRleq+mmYavKiM/2OeHk76ZgVB5e LIHq/XTsUWNq+e1cOUe1pyLrPKIxkc4AUvJepcrF07tcf1oGGuZxtrtGcGps+snyDe2t JGGL/IFHNPIQdR5mC7URTLAc9chiCNj/9YQEk80eA4NFHW8K9uZUuEiQXRO27gUw4DhY ORxQ== 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 t126-20020a625f84000000b0053652e1c0b6si4396196pfb.12.2023.01.24.21.10.29; Tue, 24 Jan 2023 21:10:41 -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 S234182AbjAYFES (ORCPT + 99 others); Wed, 25 Jan 2023 00:04:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232745AbjAYFEM (ORCPT ); Wed, 25 Jan 2023 00:04:12 -0500 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23FFA474F4; Tue, 24 Jan 2023 21:04:09 -0800 (PST) Received: by mail-pl1-f171.google.com with SMTP id d9so16832255pll.9; Tue, 24 Jan 2023 21:04:09 -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=geJZ0n/Osgu93pxX9vL5o3+bzLvg1dQW9V/BZwV5zXs=; b=SdK8le0Oc3RV2VGyiqC5X5/c8O3ivrOV9JuDGc5CCgChhAgTX/kU4ADFuksHJMoHHo uZn16fni36zg9024Cfg+IxHK/itIi+Nj99WUA/neTRaZHTIALixkhuxtfgWwe+wOgtHu zQ0v+J6j6rbmCYwWnlNXLHrbDeYW6LAooJuTibHDMvGUXZQ25ix9CS2SH16G8OHuW3jT 6shwAJQ0apAbMqIaJLDPBkcnv24MmRr+7DXqL59pCeWFnscjt5OjP8NbKl8hDISzGjXi 4mpQ5xIrcdv7H8CVUQEr+eE/kc+Z6XsUXH9qOzsGPMTx3Ftnum60YVnLms+WEMWinfui LcBQ== X-Gm-Message-State: AFqh2kqsCgzIfDQ86gD8UMUkxxaXyf12qfwQe6I3cpYdihiHt1Iy53mc tdN+GFJtbB1JTjclYfOa3fXwAoW1qrsQ2IXN X-Received: by 2002:a05:6a20:c120:b0:b8:8027:13a5 with SMTP id bh32-20020a056a20c12000b000b8802713a5mr31697542pzb.33.1674623048109; Tue, 24 Jan 2023 21:04:08 -0800 (PST) Received: from localhost ([2620:10d:c090:400::5:d24a]) by smtp.gmail.com with ESMTPSA id u71-20020a63794a000000b004d346876d37sm2301166pgc.45.2023.01.24.21.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 21:04:07 -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 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable Date: Tue, 24 Jan 2023 23:03:56 -0600 Message-Id: <20230125050359.339273-2-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?1755969950084290251?= X-GMAIL-MSGID: =?utf-8?q?1755969950084290251?= 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 800488289297..2b8f0c0aa0cc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17054,7 +17054,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) @@ -17076,7 +17077,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 05:03:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp100578wrn; Tue, 24 Jan 2023 21:07:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLBAVkWtGVYiQXIEe9soxU0mkjWPGGBdNoY8lWxkjW4Vv1kRuXa20bvqvBwQHdyB3hXDdy X-Received: by 2002:a05:6a20:4a1d:b0:b8:a0e1:2750 with SMTP id fr29-20020a056a204a1d00b000b8a0e12750mr27099290pzb.4.1674623259948; Tue, 24 Jan 2023 21:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674623259; cv=none; d=google.com; s=arc-20160816; b=l09AptRxTNh/8frVaCqCOBNew1k8LYxsmffidIkw+Zic+ojoLnitXy1hNbVm0BInQA O579PvPGSK8yuPit5iDpfhjqIDcClq5VVgS3YM/cK82M7jpRUujYP5TMBCku1pIglUrR FuZQB809ZlEkdQkfXmtQ4q/44DDgrsZ+k8p1VJdvaf+wJAja0boXv428Y5Ja/PW5j7E1 +xtkiVHhsj3vb1w93As9znYE1klUpWsO4NiUmE/gAjYvoGqI4V9EYv5UJPfo/ICe6Pss FXs8GTBospqh6BIl/seJUHMwmCEuzjRLswh5vmdreMHCO7LApaoNxnNk61P4ZR+7QWvr zfeA== 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=Gi5Iq4stK2jEWp0+v7tCR4wFLwWaRDlyMao5ymVjrpkZWnDlyPF4Ofecgt3yBTiCVX /by9gHUGvN94WunRQSPO7JVGITf8bUZaM/IPLu0gD14AGJmQz1L1KDUgu7fnlfSgYWlq Vk0marNnO14uZ+VK3SEvIDXVmpCMf1BbZ2xa9vIbDgUWye2zxdixoOLJyZxPK0sG+C9w 6AwGHeYVEqssEQrKOcIhjZ+skgn7v9WtZwKDlMrK7n0jXLYB1JOdrKgimVujGxm1HyQH Z0sglLDVWVDOFYXRJSgcC962lo/JFtSqIsuL2fxXkgj7FxAcDUhLBMQFRqXxthhnpzfC uiHw== 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 r2-20020a63a002000000b0047780dc6a58si4043173pge.500.2023.01.24.21.07.27; Tue, 24 Jan 2023 21:07:39 -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 S234100AbjAYFEP (ORCPT + 99 others); Wed, 25 Jan 2023 00:04:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231563AbjAYFEM (ORCPT ); Wed, 25 Jan 2023 00:04:12 -0500 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF67474EA; Tue, 24 Jan 2023 21:04:11 -0800 (PST) Received: by mail-pl1-f171.google.com with SMTP id 5so11542965plo.3; Tue, 24 Jan 2023 21:04:11 -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=kIi6vNhFdCUBiYn0YOepitNgdaTLqRijrHYZZC28pri4S/wFsF0Oa3UO1xksD1n3/B EqxEWRJ5tILyqoYNvMlIadQ/xJihozoul7Z1s5yvI9TsQimHDKs2ZztFhDdWipEE9Qij 6PD5K+j055fw5X7ScWvsbVU0Mg5X5knE8kJRbE4vL/xo4PbqF9duvgbHXOjCJ2NFHqTU d50UmXWoEPwjL9kAzGiIRVQI7ZcjRyStEfiPPEUn3hLe1N7eOAOk6h3FZHtKpOH2qspI rJ+gNmxLKfo52tWwUufE5u/vyFicnckAL85FRwRE+CltHBOfRrVBClgFKRgcjD3YMrQn BwIg== X-Gm-Message-State: AFqh2krFS3xZVg/UjxTy5zreSbTXOXdVQzUWg5XIym/tmy9dmOc6OKQM 7AInlZ66GekIXu4vh1PcnriqZ+qTcDh+UkbS X-Received: by 2002:a17:902:ce8f:b0:195:f3e6:ab9f with SMTP id f15-20020a170902ce8f00b00195f3e6ab9fmr21115616plg.51.1674623050295; Tue, 24 Jan 2023 21:04:10 -0800 (PST) Received: from localhost ([2620:10d:c090:400::5:d24a]) by smtp.gmail.com with ESMTPSA id m9-20020a170902bb8900b001931c37da2dsm2578963pls.20.2023.01.24.21.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 21:04:09 -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 2/4] libbpf: Support sleepable struct_ops.s section Date: Tue, 24 Jan 2023 23:03:57 -0600 Message-Id: <20230125050359.339273-3-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?1755969759366247314?= X-GMAIL-MSGID: =?utf-8?q?1755969759366247314?= 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 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; From patchwork Wed Jan 25 05:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 48017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp102190wrn; Tue, 24 Jan 2023 21:13:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXttFx/UBcuKd7/eSI6z0xEaq4szfD9MaFBAzfqPcpnnVLyu3XJ+raYMOLOIeW/qY2GKP+ZN X-Received: by 2002:a17:903:32c9:b0:195:e2d7:d511 with SMTP id i9-20020a17090332c900b00195e2d7d511mr23987416plr.6.1674623586565; Tue, 24 Jan 2023 21:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674623586; cv=none; d=google.com; s=arc-20160816; b=Ayly8HQ4Os43Y3dAsHZu+B5yf70VNyH1TUztkkP0oXwi/hcMEyHsXW939DP9WJYrcW wVGuQTIZXxWPG1Nku5JApqaTF7ysep0GMvjY11zsvxcZ3lfgmljZYCKQSF0UhFCG4xa3 ARvgl+1nSLXsj6/D8oJMaMHzGMwihDbXEPkgssPM6YA7C9ZSNn8zE43y2KYKClQAqb7C Gmyr7pfE+TEj29RM+hwZ8ObmbhtdRpVO/g3Q45AzDpNqvAvhZs1ahdzAx37oR6sdwv7g yv4FPAOacz8he28nkFk5m1le8oBgmx7wN0mbq5nFlR0sybRCqZ+WVWFKdBukhvEntchs ET/w== 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=rova6ngLsYq2rnb5PiS/P21X822PIKJ9gJ36rqMX2HQ=; b=e3atiHoX4D1yU7f+VUSeyfCguMkgV33GIAufFhQ3YkwQoqAXSmb6xPqelqkaEf7Fgn lt3bQP/KcVUk4h2sMimpClDY+EbM7Y3L57K/yX8nV4dGSQwYHHkvGWQQhhT0iFJFtfnf tttCdKu/OZlL0Td94BADFAWo+HkVHoxjBsM6OMOEPYlVfAGrZvhtwkmFTIzb6jvGj0G7 i3V7Uf1VW3b1/KPPZrsRoM2hYDtGQ7GcSPTBlTWTP+Ym2Wsyh4EJbYwR2lluEPn4lM45 TcRRNF46XPH8oV3iIzCVjGm15j911z9jUlldDuLKNsA+LvGWeGS94HwKc9vZnwfdWd27 71Uw== 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 p7-20020a1709028a8700b001944b1285e6si4404691plo.193.2023.01.24.21.12.52; Tue, 24 Jan 2023 21:13:06 -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 S234163AbjAYFE0 (ORCPT + 99 others); Wed, 25 Jan 2023 00:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234144AbjAYFES (ORCPT ); Wed, 25 Jan 2023 00:04:18 -0500 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08E14FC2E; Tue, 24 Jan 2023 21:04:15 -0800 (PST) Received: by mail-pj1-f47.google.com with SMTP id h5-20020a17090a9c0500b0022bb85eb35dso869299pjp.3; Tue, 24 Jan 2023 21:04:15 -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=rova6ngLsYq2rnb5PiS/P21X822PIKJ9gJ36rqMX2HQ=; b=4+CfiGFiIcjz3v+JUl/Tgfc4VTiOWoB6taOYmw6h+6fidDQOwqorNjR5sy5Seok4EO Pw4c70aa6ENBnNk5s498rKrU+fkTUdsR3mhJD4UxFObm+RR56sNp6JNxNvRn36uacOtZ kEHgN8/cwKxnlRtkrik2LiXik7dbwvKJByTAno/Ij3+Lz6rDiY4e+qF0gz/DTv3OiZSg C/ImDicciAMlZUrCGckWCD1DKnH8qdaQ3sAwHnQwcwJOT1ZKvzZuQnbncqmX2fxLF4mH C5Rp6lXW8aGeYuPdTmgzNJZx4zJ10HTOxx0EtvGtig/wrmoh51o+uW4H+8ccpMKuYB0h Djyg== X-Gm-Message-State: AFqh2kpd8IPBestdRtYP0IaRBOQFLKgaCAeCCti61rUIcHHRNIVQSHdi d8kf/OxxgNPRlbXxoeR674eltjfW62SQFNOb X-Received: by 2002:a17:90a:1a5c:b0:22b:b76b:5043 with SMTP id 28-20020a17090a1a5c00b0022bb76b5043mr17760297pjl.9.1674623054737; Tue, 24 Jan 2023 21:04:14 -0800 (PST) Received: from localhost ([2620:10d:c090:400::5:d24a]) by smtp.gmail.com with ESMTPSA id o9-20020a17090a744900b00229f74a4323sm464229pjk.34.2023.01.24.21.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 21:04:14 -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 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior Date: Tue, 24 Jan 2023 23:03:59 -0600 Message-Id: <20230125050359.339273-5-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_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?1755970101938210256?= X-GMAIL-MSGID: =?utf-8?q?1755970101938210256?= 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 | 54 ++++++++++++++----- .../selftests/bpf/progs/dummy_st_ops_fail.c | 27 ++++++++++ ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++---- 5 files changed, 94 insertions(+), 25 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 50123afab9bf..d92a6e0fde97 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..135514fad83a 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,10 +120,31 @@ 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); } -void test_dummy_st_ops(void) +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_success(void) { if (test__start_subtest("dummy_st_ops_attach")) test_dummy_st_ops_attach(); @@ -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, };