Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Handle !CONFIG_SMC in bpf_smc.c

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

authored by

Alan Maguire and committed by
Martin KaFai Lau
e95e85b8 0c55d481

+30 -4
+4 -2
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
··· 131 131 goto fail; 132 132 133 133 ret = recv(fd, &msg, sizeof(msg), 0); 134 - if (!ASSERT_FALSE(msg.n.nlmsg_type == NLMSG_ERROR || ret < 0 || 135 - !NLMSG_OK(&msg.n, ret), "nl_family response")) 134 + if (msg.n.nlmsg_type == NLMSG_ERROR) 135 + goto fail; 136 + if (!ASSERT_FALSE(ret < 0 || !NLMSG_OK(&msg.n, ret), 137 + "nl_family response")) 136 138 goto fail; 137 139 138 140 nl = (struct nlattr *)GENLMSG_DATA(&msg);
+26 -2
tools/testing/selftests/bpf/progs/bpf_smc.c
··· 8 8 9 9 char _license[] SEC("license") = "GPL"; 10 10 11 + #ifndef SMC_HS_CTRL_NAME_MAX 12 + #define SMC_HS_CTRL_NAME_MAX 16 13 + #endif 14 + 11 15 enum { 12 16 BPF_SMC_LISTEN = 10, 13 17 }; ··· 20 16 struct sock sk; 21 17 struct smc_sock *listen_smc; 22 18 bool use_fallback; 19 + } __attribute__((preserve_access_index)); 20 + 21 + struct smc_hs_ctrl___local { 22 + char name[SMC_HS_CTRL_NAME_MAX]; 23 + int (*syn_option)(struct tcp_sock *); 24 + int (*synack_option)(const struct tcp_sock *, struct inet_request_sock *); 25 + } __attribute__((preserve_access_index)); 26 + 27 + struct netns_smc___local { 28 + struct smc_hs_ctrl___local *hs_ctrl; 29 + } __attribute__((preserve_access_index)); 30 + 31 + struct net___local { 32 + struct netns_smc___local smc; 23 33 } __attribute__((preserve_access_index)); 24 34 25 35 int smc_cnt = 0; ··· 106 88 107 89 task = bpf_get_current_task_btf(); 108 90 /* Prevent from affecting other tests */ 109 - if (!task || !task->nsproxy->net_ns->smc.hs_ctrl) 91 + if (!task) { 110 92 return protocol; 93 + } else { 94 + struct net___local *net = (struct net___local *)task->nsproxy->net_ns; 95 + 96 + if (!bpf_core_field_exists(struct net___local, smc) || !net->smc.hs_ctrl) 97 + return protocol; 98 + } 111 99 112 100 return IPPROTO_SMC; 113 101 } ··· 134 110 } 135 111 136 112 SEC(".struct_ops") 137 - struct smc_hs_ctrl linkcheck = { 113 + struct smc_hs_ctrl___local linkcheck = { 138 114 .name = "linkcheck", 139 115 .syn_option = (void *)bpf_smc_set_tcp_option, 140 116 .synack_option = (void *)bpf_smc_set_tcp_option_cond,