From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4E4BC07E95 for ; Tue, 13 Jul 2021 06:34:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D1D61183 for ; Tue, 13 Jul 2021 06:34:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233422AbhGMGhk (ORCPT ); Tue, 13 Jul 2021 02:37:40 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:11269 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233374AbhGMGhk (ORCPT ); Tue, 13 Jul 2021 02:37:40 -0400 Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4GP9hM0MtRz1CJNh for ; Tue, 13 Jul 2021 14:29:07 +0800 (CST) Received: from [10.174.178.171] (10.174.178.171) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 13 Jul 2021 14:34:43 +0800 To: From: "luwei (O)" Subject: Ask for help about bpf map Message-ID: <5aebe6f4-ca0d-4f64-8ee6-b68c58675271@huawei.com> Date: Tue, 13 Jul 2021 14:34:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.171] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Hi, List:       I am a beginner about bpf and working on XDP now. I meet a problem and feel difficult to figure it out.       In my following codes, I use two ways to define my_map: in SEC maps and SEC .maps respectively. When I load the xdp_kern.o file, It has different results. The way I load is: ip link set dev ens3 xdp obj xdp1_kern.o sec xdp1.       when I define my_map using SEC maps, it loads successfully but fails to load using SEC .maps, it reports: " [12] TYPEDEF __u32 type_id=13 [13] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none) [14] FUNC_PROTO (anon) return=2 args=(10 ctx) [15] FUNC xdp_prog1 type_id=14 [16] INT char size=1 bits_offset=0 nr_bits=8 encoding=SIGNED [17] ARRAY (anon) type_id=16 index_type_id=4 nr_elems=4 [18] VAR _license type_id=17 linkage=1 [19] DATASEC .maps size=0 vlen=1 size == 0 Prog section 'xdp1' rejected: Permission denied (13)!  - Type:         6  - Instructions: 9 (0 over limit)  - License:      GPL Verifier analysis: 0: (b7) r1 = 0 1: (63) *(u32 *)(r10 -4) = r1 last_idx 1 first_idx 0 regs=2 stack=0 before 0: (b7) r1 = 0 2: (bf) r2 = r10 3: (07) r2 += -4 4: (18) r1 = 0x0 6: (85) call bpf_map_lookup_elem#1 R1 type=inv expected=map_ptr processed 6 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 Error fetching program/map! " I tried to search google, and only found the following page: https://stackoverflow.com/questions/67553794/what-is-variable-attribute-sec-means Does anyone meet the same problem or help to explain this or provide me some suggestions ? Thanks ! === xdp1_kern.c === #define KBUILD_MODNAME "foo" #include #include #include #include #include #include #include #include #include struct {     __uint(type, BPF_MAP_TYPE_HASH);     __uint(max_entries, 1024);     __type(key, int);     __type(value, int); } my_map SEC(".maps"); #if 0 #define PIN_GLOBAL_NS           2 struct bpf_elf_map {         __u32 type;         __u32 size_key;         __u32 size_value;         __u32 max_elem;         __u32 flags;         __u32 id;         __u32 pinning; }; struct bpf_elf_map SEC("maps") my_map = {         .type = BPF_MAP_TYPE_HASH,         .size_key = sizeof(int),         .size_value = sizeof(int),         .pinning        = PIN_GLOBAL_NS,         .max_elem = 65535, }; #endif SEC("xdp1") int xdp_prog1(struct xdp_md *ctx) {     int key = 0;     struct map_elem *val;     val = bpf_map_lookup_elem(&my_map, &key);     if (val) {         return XDP_PASS;     }     return XDP_PASS; } char _license[] SEC("license") = "GPL"; -- Best Regards, Lu Wei