]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
bpf: test_maps: cleanup sockmaps when test ends
authorPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Tue, 23 Jan 2018 04:30:44 +0000 (13:30 +0900)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 6 Jun 2018 17:44:25 +0000 (13:44 -0400)
BugLink: http://bugs.launchpad.net/bugs/1774063
[ Upstream commit 783687810e986a15ffbf86c516a1a48ff37f38f7 ]

Bug: BPF programs and maps related to sockmaps test exist
in memory even after test_maps ends.

This patch fixes it as a short term workaround (sockmap
kernel side needs real fixing) by empyting sockmaps when
test ends.

Fixes: 6f6d33f3b3d0f ("bpf: selftests add sockmap tests")
Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
[ daniel: Note on workaround. ]
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
tools/testing/selftests/bpf/test_maps.c

index 040356ecc862b6f87a7ff841c19b98afd3098fb3..5fb1355f80fc2f64f955fa1299a7d2705a5947bc 100644 (file)
@@ -463,7 +463,7 @@ static void test_devmap(int task, void *data)
 #define SOCKMAP_VERDICT_PROG "./sockmap_verdict_prog.o"
 static void test_sockmap(int tasks, void *data)
 {
-       int one = 1, map_fd_rx, map_fd_tx, map_fd_break, s, sc, rc;
+       int one = 1, map_fd_rx = 0, map_fd_tx = 0, map_fd_break, s, sc, rc;
        struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break;
        int ports[] = {50200, 50201, 50202, 50204};
        int err, i, fd, udp, sfd[6] = {0xdeadbeef};
@@ -868,9 +868,12 @@ static void test_sockmap(int tasks, void *data)
                goto out_sockmap;
        }
 
-       /* Test map close sockets */
-       for (i = 0; i < 6; i++)
+       /* Test map close sockets and empty maps */
+       for (i = 0; i < 6; i++) {
+               bpf_map_delete_elem(map_fd_tx, &i);
+               bpf_map_delete_elem(map_fd_rx, &i);
                close(sfd[i]);
+       }
        close(fd);
        close(map_fd_rx);
        bpf_object__close(obj);
@@ -881,8 +884,13 @@ out:
        printf("Failed to create sockmap '%i:%s'!\n", i, strerror(errno));
        exit(1);
 out_sockmap:
-       for (i = 0; i < 6; i++)
+       for (i = 0; i < 6; i++) {
+               if (map_fd_tx)
+                       bpf_map_delete_elem(map_fd_tx, &i);
+               if (map_fd_rx)
+                       bpf_map_delete_elem(map_fd_rx, &i);
                close(sfd[i]);
+       }
        close(fd);
        exit(1);
 }