[bpf-next,v2] selftests/bpf: Fix compilation errors: assign a value to a constant

Message ID tencent_CB281722B3C1BD504C16CDE586CACC2BE706@qq.com
State New
Headers
Series [bpf-next,v2] selftests/bpf: Fix compilation errors: assign a value to a constant |

Commit Message

Rong Tao Feb. 24, 2023, 3:10 p.m. UTC
  From: Rong Tao <rongtao@cestc.cn>

commit bc292ab00f6c("mm: introduce vma->vm_flags wrapper functions")
turns the vm_flags into a const variable.

Added bpf_find_vma test in commit f108662b27c9("selftests/bpf: Add tests
for bpf_find_vma") to assign values to variables that declare const in
find_vma_fail1.c programs, which is an error to the compiler and does not
test BPF verifiers. It is better to replace 'const vm_flags_t vm_flags'
with 'unsigned long vm_start' for testing.

    $ make -C tools/testing/selftests/bpf/ -j8
    ...
    progs/find_vma_fail1.c:16:16: error: cannot assign to non-static data
    member 'vm_flags' with const-qualified type 'const vm_flags_t' (aka
    'const unsigned long')
            vma->vm_flags |= 0x55;
            ~~~~~~~~~~~~~ ^
    ../tools/testing/selftests/bpf/tools/include/vmlinux.h:1898:20:
    note: non-static data member 'vm_flags' declared const here
                    const vm_flags_t vm_flags;
                    ~~~~~~~~~~~`~~~~~~^~~~~~~~

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
v2: Add more useful commit information
v1: https://lore.kernel.org/lkml/tencent_FC8827062142CF5936974B2A30AF6CA3C408@qq.com/
---
 tools/testing/selftests/bpf/progs/find_vma_fail1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

patchwork-bot+netdevbpf@kernel.org Feb. 27, 2023, 7:50 p.m. UTC | #1
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Fri, 24 Feb 2023 23:10:02 +0800 you wrote:
> From: Rong Tao <rongtao@cestc.cn>
> 
> commit bc292ab00f6c("mm: introduce vma->vm_flags wrapper functions")
> turns the vm_flags into a const variable.
> 
> Added bpf_find_vma test in commit f108662b27c9("selftests/bpf: Add tests
> for bpf_find_vma") to assign values to variables that declare const in
> find_vma_fail1.c programs, which is an error to the compiler and does not
> test BPF verifiers. It is better to replace 'const vm_flags_t vm_flags'
> with 'unsigned long vm_start' for testing.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] selftests/bpf: Fix compilation errors: assign a value to a constant
    https://git.kernel.org/bpf/bpf-next/c/11e456cae91e

You are awesome, thank you!
  

Patch

diff --git a/tools/testing/selftests/bpf/progs/find_vma_fail1.c b/tools/testing/selftests/bpf/progs/find_vma_fail1.c
index b3b326b8e2d1..47d5dedff554 100644
--- a/tools/testing/selftests/bpf/progs/find_vma_fail1.c
+++ b/tools/testing/selftests/bpf/progs/find_vma_fail1.c
@@ -13,7 +13,7 @@  static long write_vma(struct task_struct *task, struct vm_area_struct *vma,
 		      struct callback_ctx *data)
 {
 	/* writing to vma, which is illegal */
-	vma->vm_flags |= 0x55;
+	vma->vm_start = 0xffffffffff600000;
 
 	return 0;
 }