Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2753778rwb; Mon, 7 Nov 2022 17:56:51 -0800 (PST) X-Google-Smtp-Source: AMsMyM6RUoxmAz7aMpNokgJiFXrdYAAT/yOF8rK7R5bhJkxamUedzBF1y0OPEimTbQIeXlPxZA/5 X-Received: by 2002:a17:907:3e92:b0:7ad:d4f1:11d8 with SMTP id hs18-20020a1709073e9200b007add4f111d8mr41542853ejc.291.1667872610971; Mon, 07 Nov 2022 17:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667872610; cv=none; d=google.com; s=arc-20160816; b=ckBeHSRHQvhB/YdfGUx/+M0BCKP99t2w722xlR7qOyKjHqZ8Bvy62EsQTlmAaYHTi/ JnLRgsMv3JEfUORt/NtzVUc7FOzdhk81m8Eh7PV13ijSd2YeL4lIfHkUaCGCMxZwvkqj yZKhvtnYDqjH5ZIdu3RjM/0cnhGniwP1O60ZQ3/h79rPOSgL9FQvxBEavzKlo9HwJ9i1 2JM4YAyTHpm4qtvAeSxGElKxkYhNGCXRE3wYnveKxUs6R1lEX9HOdQ2fCM+x2acyOP0Z Wfju/MzG5QhGohEz0m3xZ1Y6kPgpuBx78yrbf1IFxRnMZb7qS+50dgm9rATT0B0GfYr1 D46A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6ZUC/K/qq4lsjAEpOrOv4UwDp2L93NLbYrIOQ63CsCc=; b=dv0C6+jHWgsFKv9MdQK5NLcWwcrhuep5vW7wh2Zdw1ed/5b1b5JhsfZ3GP7lKyR4us ZFUUmDcmRo09XadIhDz5wexZVj4CbyWMiki/+kOl1plPlNIzrLWCWTO0b2imS1jwzE7C d48bscGyGVdVgZOa+wEn7X55JiRJHGgehcCeDqkOVN8ruTFeqlSNuAM+5D2PLXQEnbTh JdstZZrIVuE6dvF05+ufs/GkBQLoRwRVtFaeM/VRvXDly6zYsEwsZAOZRfRiUmeoJUTX V+OfgWGKtBquzcGVBBNb+8XHBkIH7ZPNdWo9pESKMJ00Ru2jqfDnsZN0qW1cc+bcbUEc k3KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ohddt+jc; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ey3-20020a0564022a0300b00456964d3369si381286edb.230.2022.11.07.17.56.29; Mon, 07 Nov 2022 17:56:50 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ohddt+jc; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233106AbiKHBPC (ORCPT + 92 others); Mon, 7 Nov 2022 20:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiKHBO7 (ORCPT ); Mon, 7 Nov 2022 20:14:59 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2466BE016; Mon, 7 Nov 2022 17:14:57 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id t25so34705464ejb.8; Mon, 07 Nov 2022 17:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6ZUC/K/qq4lsjAEpOrOv4UwDp2L93NLbYrIOQ63CsCc=; b=Ohddt+jcUF9W8ZRTqFt5ZEkQPWBh77ov0po6xJ0iyNXsvjJIUgmMADk4+RZR7jugUY A8zdNZoHZgkV0GTJmsyUlYsIHwSweWYBGZlclS1mpRGd/QNM7N36Ol+z2tElSjHYNJkU gG7bmgBXKyuwaEy0p5ETDAE0SrDXDUCusLqs6QFe8XvjY6tNc21Qqq1SxK6Xlxcf2kp4 K/TKD5K2FqXTHm3Ucxj/XkZ44fQXwAu0dJ9PpK6vq9kSZIjD9CSWTyFMtICy4fWow+pQ ODUmZTQdYZAcPh4mLotcG/4tDvf69w4pgHj2XgTL4wGFlNOsQcrF2O+4ETKB0WBETiBp oAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6ZUC/K/qq4lsjAEpOrOv4UwDp2L93NLbYrIOQ63CsCc=; b=UX65CC6gvFaTRI8XeGImcZNiOwX19UAhEHn4+nCJVuahNPA7U8NIupuYOYGMOpGJ+7 3sqcw2ofYDWqPywftyu3Wg02JYrFnLHcksB6pz7B2RjT3KxjbHX4iRFjEysAGRA14B5O sQy1ebHfWKQUwPfpzYpOfHRkuuKzeIVjq7RrjTlELbTyUTrC9S4AwnVsrIPq0h89uKoK GF55eNqcKBDpjO62HByKJD5YiFlZZZwwJgdofTUaZpPLwpOVxi76bSRlHCReDRKYDMJ1 NuiPHUzKKWE3EIbUOyY4Put0M8H+OQ1SEpjglDpy+Kc3Vf11nmqpwAwjBiJ6X5CoaCaZ 5ZKQ== X-Gm-Message-State: ACrzQf2+WCuNf7C0l+wd+qqWGmFEpuz+jxga3w+8/CbG1DeNhx/7vHWA 1h9tT48+AnXkU8MxQg9gnKSpAR+f6ftGr5F14Ok= X-Received: by 2002:a17:906:99c5:b0:73d:70c5:1a4f with SMTP id s5-20020a17090699c500b0073d70c51a4fmr50120270ejn.302.1667870095649; Mon, 07 Nov 2022 17:14:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Mon, 7 Nov 2022 17:14:43 -0800 Message-ID: Subject: Re: [PATCH bpf-next] samples/bpf: Fix sockex3 error: missing BPF prog type To: Rong Tao 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, sdf@google.com, song@kernel.org, yhs@fb.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Fri, Nov 4, 2022 at 11:48 PM Rong Tao wrote: > > From: Rong Tao > > 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. > > Instead of sockex3_user.c parsing section names to get the BPF program fd. > We use the program array map to assign a static index to each BPF program > (get inspired by selftests/bpf progs/test_prog_array_init.c). > Therefore, use SEC("socket") as section name instead of SEC("socket/xxx"), > so that the BPF program is parsed to SOCKET_FILTER type. The "missing BPF > prog type" problem is solved. > > How to reproduce 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 > --- > samples/bpf/sockex3_kern.c | 95 ++++++++++++++++++++++---------------- > samples/bpf/sockex3_user.c | 23 ++++----- > 2 files changed, 64 insertions(+), 54 deletions(-) > > diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c > index b363503357e5..26d916834865 100644 > --- a/samples/bpf/sockex3_kern.c > +++ b/samples/bpf/sockex3_kern.c > @@ -17,47 +17,12 @@ > #define IP_MF 0x2000 > #define IP_OFFSET 0x1FFF > > -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F > - > -struct { > - __uint(type, BPF_MAP_TYPE_PROG_ARRAY); > - __uint(key_size, sizeof(u32)); > - __uint(value_size, sizeof(u32)); > - __uint(max_entries, 8); > -} jmp_table SEC(".maps"); > - > #define PARSE_VLAN 1 > #define PARSE_MPLS 2 > #define PARSE_IP 3 > #define PARSE_IPV6 4 > > -/* Protocol dispatch routine. It tail-calls next BPF program depending > - * on eth proto. Note, we could have used ... > - * > - * bpf_tail_call(skb, &jmp_table, proto); > - * > - * ... but it would need large prog_array and cannot be optimised given > - * the map key is not static. > - */ > -static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto) > -{ > - switch (proto) { > - case ETH_P_8021Q: > - case ETH_P_8021AD: > - bpf_tail_call(skb, &jmp_table, PARSE_VLAN); > - break; > - case ETH_P_MPLS_UC: > - case ETH_P_MPLS_MC: > - bpf_tail_call(skb, &jmp_table, PARSE_MPLS); > - break; > - case ETH_P_IP: > - bpf_tail_call(skb, &jmp_table, PARSE_IP); > - break; > - case ETH_P_IPV6: > - bpf_tail_call(skb, &jmp_table, PARSE_IPV6); > - break; > - } > -} > +#define PROG_SOCKET_FILTER SEC("socket") I dropped this and made SEC("socket") annotations explicit everywhere. Applied to bpf-next, thank. > > struct vlan_hdr { > __be16 h_vlan_TCI; > @@ -74,6 +39,8 @@ struct flow_key_record { > __u32 ip_proto; > }; > [...]