xref: /linux/tools/testing/selftests/bpf/progs/uptr_update_failure.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3 
4 #include <vmlinux.h>
5 #include <bpf/bpf_helpers.h>
6 #include "uptr_test_common.h"
7 
8 struct {
9 	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
10 	__uint(map_flags, BPF_F_NO_PREALLOC);
11 	__type(key, int);
12 	__type(value, struct value_lock_type);
13 } datamap SEC(".maps");
14 
15 /* load test only. not used */
16 SEC("syscall")
17 int not_used(void *ctx)
18 {
19 	struct value_lock_type *ptr;
20 	struct task_struct *task;
21 	struct user_data *udata;
22 
23 	task = bpf_get_current_task_btf();
24 	ptr = bpf_task_storage_get(&datamap, task, 0, 0);
25 	if (!ptr)
26 		return 0;
27 
28 	bpf_spin_lock(&ptr->lock);
29 
30 	udata = ptr->udata;
31 	if (!udata) {
32 		bpf_spin_unlock(&ptr->lock);
33 		return 0;
34 	}
35 	udata->result = MAGIC_VALUE + udata->a + udata->b;
36 
37 	bpf_spin_unlock(&ptr->lock);
38 
39 	return 0;
40 }
41 
42 char _license[] SEC("license") = "GPL";
43