]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Handle !CONFIG_SMC in bpf_smc.c
authorAlan Maguire <alan.maguire@oracle.com>
Tue, 10 Mar 2026 11:13:29 +0000 (11:13 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Wed, 11 Mar 2026 00:40:15 +0000 (17:40 -0700)
Currently BPF selftests will fail to compile if CONFIG_SMC
is not set.

Use BPF CO-RE to work around the case where CONFIG_SMC is
not set; use ___local variants of relevant structures and
utilize bpf_core_field_exists() for net->smc.

The test continues to pass where

  CONFIG_SMC=y
  CONFIG_SMC_HS_CTRL_BPF=y

but these changes allow the selftests to build in the absence
of CONFIG_SMC=y.

Also ensure that we get a pure skip rather than a skip+fail
by removing the SMC is unsupported part from the ASSERT_FALSE()
in get_smc_nl_family(); doing this means we get a skip without
a fail when CONFIG_SMC is not set:

$ sudo ./test_progs -t bpf_smc
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes: beb3c67297d9 ("bpf/selftests: Add selftest for bpf_smc_hs_ctrl")
Reported-by: Colm Harrington <colm.harrington@oracle.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Tested-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://patch.msgid.link/20260310111330.601765-1-alan.maguire@oracle.com
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
tools/testing/selftests/bpf/progs/bpf_smc.c

index de22734abc4d2bdd7ddff55a0f7e2b8af43857a1..40d38280c091e314f2e8f3756bcc616ecc95eed0 100644 (file)
@@ -131,8 +131,10 @@ static bool get_smc_nl_family_id(void)
                goto fail;
 
        ret = recv(fd, &msg, sizeof(msg), 0);
-       if (!ASSERT_FALSE(msg.n.nlmsg_type == NLMSG_ERROR || ret < 0 ||
-                         !NLMSG_OK(&msg.n, ret), "nl_family response"))
+       if (msg.n.nlmsg_type == NLMSG_ERROR)
+               goto fail;
+       if (!ASSERT_FALSE(ret < 0 || !NLMSG_OK(&msg.n, ret),
+                         "nl_family response"))
                goto fail;
 
        nl = (struct nlattr *)GENLMSG_DATA(&msg);
index 70d8b08f591405727a727de216b625c98f9a8a66..6263a45bf0066a582abf6cd84da4bba352811b47 100644 (file)
@@ -8,6 +8,10 @@
 
 char _license[] SEC("license") = "GPL";
 
+#ifndef SMC_HS_CTRL_NAME_MAX
+#define SMC_HS_CTRL_NAME_MAX 16
+#endif
+
 enum {
        BPF_SMC_LISTEN  = 10,
 };
@@ -18,6 +22,20 @@ struct smc_sock___local {
        bool use_fallback;
 } __attribute__((preserve_access_index));
 
+struct smc_hs_ctrl___local {
+       char name[SMC_HS_CTRL_NAME_MAX];
+       int (*syn_option)(struct tcp_sock *);
+       int (*synack_option)(const struct tcp_sock  *, struct inet_request_sock *);
+} __attribute__((preserve_access_index));
+
+struct netns_smc___local {
+       struct smc_hs_ctrl___local *hs_ctrl;
+} __attribute__((preserve_access_index));
+
+struct net___local {
+       struct netns_smc___local smc;
+} __attribute__((preserve_access_index));
+
 int smc_cnt = 0;
 int fallback_cnt = 0;
 
@@ -88,8 +106,14 @@ int BPF_PROG(smc_run, int family, int type, int protocol)
 
        task = bpf_get_current_task_btf();
        /* Prevent from affecting other tests */
-       if (!task || !task->nsproxy->net_ns->smc.hs_ctrl)
+       if (!task) {
                return protocol;
+       } else {
+               struct net___local *net = (struct net___local *)task->nsproxy->net_ns;
+
+               if (!bpf_core_field_exists(struct net___local, smc) || !net->smc.hs_ctrl)
+                       return protocol;
+       }
 
        return IPPROTO_SMC;
 }
@@ -110,7 +134,7 @@ int BPF_PROG(bpf_smc_set_tcp_option, struct tcp_sock *tp)
 }
 
 SEC(".struct_ops")
-struct smc_hs_ctrl  linkcheck = {
+struct smc_hs_ctrl___local  linkcheck = {
        .name           = "linkcheck",
        .syn_option     = (void *)bpf_smc_set_tcp_option,
        .synack_option  = (void *)bpf_smc_set_tcp_option_cond,