selftests/bpf: Fix erroneous bitmask operation
[platform/kernel/linux-rpi.git] / tools / testing / selftests / bpf / progs / test_map_init.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Tessares SA <http://www.tessares.net> */
3
4 #include "vmlinux.h"
5 #include <bpf/bpf_helpers.h>
6
7 __u64 inKey = 0;
8 __u64 inValue = 0;
9 __u32 inPid = 0;
10
11 struct {
12         __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
13         __uint(max_entries, 2);
14         __type(key, __u64);
15         __type(value, __u64);
16 } hashmap1 SEC(".maps");
17
18
19 SEC("tp/syscalls/sys_enter_getpgid")
20 int sysenter_getpgid(const void *ctx)
21 {
22         /* Just do it for once, when called from our own test prog. This
23          * ensures the map value is only updated for a single CPU.
24          */
25         int cur_pid = bpf_get_current_pid_tgid() >> 32;
26
27         if (cur_pid == inPid)
28                 bpf_map_update_elem(&hashmap1, &inKey, &inValue, BPF_NOEXIST);
29
30         return 0;
31 }
32
33 char _license[] SEC("license") = "GPL";