Message ID | tencent_7DD02046A8398BE3324F85E0F56ED41EB105@qq.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1248979wru; Sat, 29 Oct 2022 01:35:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ljRdWVU5EQcOCc6uqCL+dGd019+zkc+M74G+cG19HjVXgO+T9VpcIfj6waE7vasDwoj// X-Received: by 2002:a63:ce02:0:b0:46f:38ad:e5b1 with SMTP id y2-20020a63ce02000000b0046f38ade5b1mr3239515pgf.75.1667032527767; Sat, 29 Oct 2022 01:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667032527; cv=none; d=google.com; s=arc-20160816; b=f13UPOSofGGzwdmefkYz1SFPD0sfnjgEl5r7xJensB+BQ4DiXbRAVT4rH6jCpTp8RG hbVVDtrhm7GKRrc3QubJBDOgoi6kO6+OlTu2y+Bd0z2iW9mFBvCWfdUjTJs/0L6jix9C VUVUBYOUXwtOm+tXhPUUCof1EUlmAjxLTIc60HvmDjtd+3upP8Nvmg6HKIbPxdBTfb4L bha6XgF+Z8PLvvUGc07OLA2dLH9LF/HMDZQg3uQid8C+EgXixb/cPmP1WChFbLqq95F1 x0ViVEeZDcWw1i9fjT6yEbcctvdk9PfV73f6I3TPlTALmfRHMqqO0PvmncxldysRQbbw J/aA== 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:date:subject:cc:to:from:message-id :dkim-signature; bh=+DzGGmzgC+pXMjNXZtuoYW7aaeiptNxaQfitvxP5P1g=; b=T4RoaZiRyLlOUC0+FQOAxsYyeDSIkE5WigSVaKZvV6U8o52ZitEELhqRexplsR3dtY u4OsPnaAF03ybLCo5lhYj/11Wif9fhSj6q4tSuBMABLtZFCoCE0N0gekrRtbcmY4apAD l4VEczXYOjnT3kJ6fy3qZDyjQhfrnLMAEgA7nLzaGu/iZellOwfwXSRQQq8xFnDRBzlD Wrha34NTwTdPV59ltndqAiql3seXCJ/CQz/UU+l91oRLZro1WlG3yfNFV0d3qnBodLoo PQt5OiJ403S3BBujWt4oMeRfjnfLZXnWYGsTUUdR8Xdml55DHkjeYR+nuigUql08+N7n hHbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=FYYuTW8R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j19-20020a170902f25300b0017f7de32cb0si1160789plc.85.2022.10.29.01.35.14; Sat, 29 Oct 2022 01:35:27 -0700 (PDT) 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; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=FYYuTW8R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbiJ2Hx1 (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Sat, 29 Oct 2022 03:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbiJ2HxX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 29 Oct 2022 03:53:23 -0400 X-Greylist: delayed 17127 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 29 Oct 2022 00:53:20 PDT Received: from out203-205-251-73.mail.qq.com (out203-205-251-73.mail.qq.com [203.205.251.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7030072872; Sat, 29 Oct 2022 00:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667029998; bh=+DzGGmzgC+pXMjNXZtuoYW7aaeiptNxaQfitvxP5P1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FYYuTW8Rx4q7D+sLngTrGEU0lDL/uPlA1pWUdhwPnHWsW8f0TL9rOLEbJ9LmZgPvy IvO8nmWDHK8XpkmvNpJIN4e73kPygjt7eaUPk3cVFbnUtFR3Y3beyW4Bw3FUAD6IFU vB6hhLYC5aydu2mCZlwOf98q8eM3Lf8noUrkRjCU= Received: from localhost.localdomain ([111.199.189.86]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id D4E04CEB; Sat, 29 Oct 2022 15:53:14 +0800 X-QQ-mid: xmsmtpt1667029994t99qqcvlu Message-ID: <tencent_7DD02046A8398BE3324F85E0F56ED41EB105@qq.com> X-QQ-XMAILINFO: MyIXMys/8kCtEqSkamGclXo01fwlP9MOoZDqUX1NWl3bDUhmuEGRou3hroWzZe fO0zJSGcZRxO4A+m7kerwdTwJSAUcu2pYdv5RCJxjLsxRSH43nvVnb8DmU8bAg1pgf8FG0FRFA0b H0E9RiE01svpNHEnVoVwJsYR5OLWjfoE1wEJRjG7lRKcNAb2oUt/s6Kehv1zAK6QdupLKl8DVQ0W kO4xShdrhmbIT4cCLKz4TfFDtGF/lJnmW1dXZ3eX+DnPstLUgQVteesFY2MVEPF8lR49BdYBMrpr voJoMpTGjsHk7lkfpTusbKrd3hB8PBTIXjDbkPis/PTnbJTX6IMOSO8UUVY1LJ6uXwW2Fdl72uuj XVEE1Iu3KVB4w5c4e04Kp8CQxX7FYReIhTuD2LNCU7+91OtQzk77K1uUjpZMYHB6zz4ahGsyDM0T mwPx5AEy1yhiS2sPXxJK0cTW/ipMSG1eTRAxIIFtsbI9BtvZieBPSBY2Gm4lqeZek34O5YEH32tn Ts1IxoazaO5pg+9UGCC9+75GaTe+UV7Ef6LtCihjtfTlapqihjcipd1f0yr6OLnftEwlnzUAPSed Gz8auusMeJLJ3P/RTLeQVtrmiTsBhZW14QpOkoPOOGALX+uKq4u3FyYjBEAb2w3Qqp7C05aDv9kr MzoqY1RnwOqEK2YzpL01nFtlRlr0Os3uQmX0AInQMPlxldN4gqNozW/2QbYEhFeoQeqYSajt4zZz YA8FEUjfkEu7XVzs4Iqu8Rv2ZI4Q9uyYEZG96aYKkL4ISIrzniPZMtIHVY0ABDJVy4Q7bfaCR+O/ FCZSZ89A8a2HJojr4/wcBZ0ax3bWLlNCRcYH/W5C8aMOob9kjtN5gPqAZZHn06JPpyLwKYnbdQbZ qqPlJYozQZs+nABXfwmccEhoson0dZqOHvkYNZOQXUnFHbMxQPuNqPq2BocDqbfSOgHKUyy02gSB 3c0X7gUx/NxZXnGXhPk9y+lw1gjcA/frEoASpuA/zeO6Q7wpC5mvG29f4Z6kkwQsk5oIPK2zE= From: Rong Tao <rtoax@foxmail.com> To: andrii.nakryiko@gmail.com Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, rongtao@cestc.cn, rtoax@foxmail.com, sdf@google.com, song@kernel.org, yhs@fb.com Subject: [PATCH bpf-next] samples/bpf: Fix sockex3: missing BPF prog type Date: Sat, 29 Oct 2022 15:53:12 +0800 X-OQ-MSGID: <20221029075312.45206-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <CAEf4Bza_6qND8iOuiur+xX0cBVkKJfKoJAOjihnVYRjoB3tWqw@mail.gmail.com> References: <CAEf4Bza_6qND8iOuiur+xX0cBVkKJfKoJAOjihnVYRjoB3tWqw@mail.gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SORTED_RECIPS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747848015234667972?= X-GMAIL-MSGID: =?utf-8?q?1748010299771388444?= |
Series |
[bpf-next] samples/bpf: Fix sockex3: missing BPF prog type
|
|
Commit Message
Rong Tao
Oct. 29, 2022, 7:53 a.m. UTC
From: Rong Tao <rongtao@cestc.cn> since commit 450b167fb9be("libbpf: clean up SEC() handling"), sec_def_matches() does not recognize "socket/xxx" as "socket", therefore, the BPF program type is not recognized, set "socket/xxx" to SOCKET_FILTER solves this error. $ cd samples/bpf $ sudo ./sockex3 libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3' libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22 libbpf: failed to load object './sockex3_kern.o' ERROR: loading BPF object file failed Signed-off-by: Rong Tao <rongtao@cestc.cn> --- samples/bpf/sockex3_user.c | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Sat, Oct 29, 2022 at 12:53 AM Rong Tao <rtoax@foxmail.com> wrote: > > From: Rong Tao <rongtao@cestc.cn> > > since commit 450b167fb9be("libbpf: clean up SEC() handling"), > sec_def_matches() does not recognize "socket/xxx" as "socket", therefore, > the BPF program type is not recognized, set "socket/xxx" to SOCKET_FILTER > solves this error. > > $ cd samples/bpf > $ sudo ./sockex3 > libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3' > libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22 > libbpf: failed to load object './sockex3_kern.o' > ERROR: loading BPF object file failed > > Signed-off-by: Rong Tao <rongtao@cestc.cn> > --- You need to do changes like this: diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c index b363503357e5..db6a93e7ec53 100644 --- a/samples/bpf/sockex3_kern.c +++ b/samples/bpf/sockex3_kern.c @@ -17,7 +17,7 @@ #define IP_MF 0x2000 #define IP_OFFSET 0x1FFF -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F +#define PROG(F) SEC("socket_filter") int bpf_func_##F struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); @@ -279,7 +279,7 @@ PROG(PARSE_MPLS)(struct __sk_buff *skb) return 0; } -SEC("socket/0") +SEC("socket_filter") int main_prog(struct __sk_buff *skb) { __u32 nhoff = ETH_HLEN; Why fixing up after the fact at runtime, if you can just make those BPF programs conform to libbpf rules? > samples/bpf/sockex3_user.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c > index cd6fa79df900..dc79c17ad195 100644 > --- a/samples/bpf/sockex3_user.c > +++ b/samples/bpf/sockex3_user.c > @@ -39,6 +39,9 @@ int main(int argc, char **argv) > return 0; > } > > + bpf_object__for_each_program(prog, obj) > + bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER); > + > /* load BPF program */ > if (bpf_object__load(obj)) { > fprintf(stderr, "ERROR: loading BPF object file failed\n"); > -- > 2.31.1 >
We can not just remove the number of program like: -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F +#define PROG(F) SEC("socket_filter") int bpf_func_##F because "sockex3" use the _NUMBER_ as index(see map "jmp_table"), if we apply the following patch, it's still not recognize "socket_filter/xxx" as "socket_filter", still have "missing BPF prog type" error: diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c index b363503357e5..ab5a7bde66d0 100644 --- a/samples/bpf/sockex3_kern.c +++ b/samples/bpf/sockex3_kern.c @@ -17,7 +17,7 @@ #define IP_MF 0x2000 #define IP_OFFSET 0x1FFF -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F +#define PROG(F) SEC("socket_filter/"__stringify(F)) int bpf_func_##F struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); @@ -279,7 +279,7 @@ PROG(PARSE_MPLS)(struct __sk_buff *skb) return 0; } -SEC("socket/0") +SEC("socket_filter/0") int main_prog(struct __sk_buff *skb) { __u32 nhoff = ETH_HLEN; diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c index cd6fa79df900..63fc9a8077b1 100644 --- a/samples/bpf/sockex3_user.c +++ b/samples/bpf/sockex3_user.c @@ -56,7 +56,7 @@ int main(int argc, char **argv) fd = bpf_program__fd(prog); section = bpf_program__section_name(prog); - if (sscanf(section, "socket/%d", &key) != 1) { + if (sscanf(section, "socket_filter/%d", &key) != 1) { fprintf(stderr, "ERROR: finding prog failed\n"); goto cleanup; } For a reason, in sockex3_kern.c only have five PROGs, list all five: #define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F PROG(PARSE_IP)(struct __sk_buff *skb) PROG(PARSE_IPV6)(struct __sk_buff *skb) PROG(PARSE_VLAN)(struct __sk_buff *skb) PROG(PARSE_MPLS)(struct __sk_buff *skb) SEC("socket/0") int main_prog(struct __sk_buff *skb) As you can see, all those PROGs are BPF_PROG_TYPE_SOCKET_FILTER, so we can use the follow patch specify bpf program type as SOCKET_FILTER: https://lore.kernel.org/lkml/tencent_7DD02046A8398BE3324F85E0F56ED41EB105@qq.com/ diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c index cd6fa79df900..dc79c17ad195 100644 --- a/samples/bpf/sockex3_user.c +++ b/samples/bpf/sockex3_user.c @@ -39,6 +39,9 @@ int main(int argc, char **argv) return 0; } + bpf_object__for_each_program(prog, obj) + bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER); + /* load BPF program */ if (bpf_object__load(obj)) { fprintf(stderr, "ERROR: loading BPF object file failed\n"); This patch above totally solved the compile error.
On Thu, Nov 3, 2022 at 8:17 PM Rong Tao <rtoax@foxmail.com> wrote: > > We can not just remove the number of program like: > > -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F > +#define PROG(F) SEC("socket_filter") int bpf_func_##F > > because "sockex3" use the _NUMBER_ as index(see map "jmp_table"), if we > apply the following patch, it's still not recognize "socket_filter/xxx" > as "socket_filter", still have "missing BPF prog type" error: Ok, let's keep unwinding this. This is an old and manual way to set up tail call map. Libbpf supports declarative way to do, so sockex3_user.c won't have to do anything at all. See progs/test_prog_array_init.c for an example. Let's convert samples to use this as well. This programmatic setting of program type works, there is no doubt about this. But it's a signal that something is not exactly how it should be. So let's use this as an opportunity to modernize samples, instead of adding workarounds. I hope you sympathize with this goal. > > diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c > index b363503357e5..ab5a7bde66d0 100644 > --- a/samples/bpf/sockex3_kern.c > +++ b/samples/bpf/sockex3_kern.c > @@ -17,7 +17,7 @@ > #define IP_MF 0x2000 > #define IP_OFFSET 0x1FFF > [...]
diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c index cd6fa79df900..dc79c17ad195 100644 --- a/samples/bpf/sockex3_user.c +++ b/samples/bpf/sockex3_user.c @@ -39,6 +39,9 @@ int main(int argc, char **argv) return 0; } + bpf_object__for_each_program(prog, obj) + bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER); + /* load BPF program */ if (bpf_object__load(obj)) { fprintf(stderr, "ERROR: loading BPF object file failed\n");