]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftest/bpf: Add test for vsock removal from sockmap on close()
authorMichal Luczaj <mhal@rbox.co>
Mon, 18 Nov 2024 21:03:44 +0000 (22:03 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 25 Nov 2024 22:19:14 +0000 (14:19 -0800)
Make sure the proto::close callback gets invoked on vsock release.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20241118-vsock-bpf-poll-close-v1-4-f1b9669cacdc@rbox.co
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

index 6a9aab2d051acd731532a7e639a53772f509071e..fdff0652d7ef5cdd4892af8c2c83cbf18cbf163f 100644 (file)
@@ -108,6 +108,35 @@ out:
        close(s);
 }
 
+static void test_sockmap_vsock_delete_on_close(void)
+{
+       int err, c, p, map;
+       const int zero = 0;
+
+       err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
+       if (!ASSERT_OK(err, "create_pair(AF_VSOCK)"))
+               return;
+
+       map = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(int),
+                            sizeof(int), 1, NULL);
+       if (!ASSERT_GE(map, 0, "bpf_map_create")) {
+               close(c);
+               goto out;
+       }
+
+       err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
+       close(c);
+       if (!ASSERT_OK(err, "bpf_map_update"))
+               goto out;
+
+       err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST);
+       ASSERT_OK(err, "after close(), bpf_map_update");
+
+out:
+       close(p);
+       close(map);
+}
+
 static void test_skmsg_helpers(enum bpf_map_type map_type)
 {
        struct test_skmsg_load_helpers *skel;
@@ -987,6 +1016,8 @@ void test_sockmap_basic(void)
                test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKMAP);
        if (test__start_subtest("sockhash create_update_free"))
                test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKHASH);
+       if (test__start_subtest("sockmap vsock delete on close"))
+               test_sockmap_vsock_delete_on_close();
        if (test__start_subtest("sockmap sk_msg load helpers"))
                test_skmsg_helpers(BPF_MAP_TYPE_SOCKMAP);
        if (test__start_subtest("sockhash sk_msg load helpers"))