]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/test_bpf.c
bpf: fix selftests/bpf test_kmod.sh failure when CONFIG_BPF_JIT_ALWAYS_ON=y
[mirror_ubuntu-bionic-kernel.git] / lib / test_bpf.c
index f369889e521d7e7f1e237236651532e6a862e0f5..8076e693f86e4011b9f7aec8cfd5a0dd98004f73 100644 (file)
@@ -83,6 +83,7 @@ struct bpf_test {
                __u32 result;
        } test[MAX_SUBTESTS];
        int (*fill_helper)(struct bpf_test *self);
+       int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
        __u8 frag_data[MAX_DATA];
        int stack_depth; /* for eBPF only, since tests don't call verifier */
 };
@@ -2022,7 +2023,9 @@ static struct bpf_test tests[] = {
                },
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
-               { }
+               { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {
                "check: div_k_0",
@@ -2032,7 +2035,9 @@ static struct bpf_test tests[] = {
                },
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
-               { }
+               { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {
                "check: unknown insn",
@@ -2043,7 +2048,9 @@ static struct bpf_test tests[] = {
                },
                CLASSIC | FLAG_EXPECTED_FAIL,
                { },
-               { }
+               { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {
                "check: out of range spill/fill",
@@ -2053,7 +2060,9 @@ static struct bpf_test tests[] = {
                },
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
-               { }
+               { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {
                "JUMPS + HOLES",
@@ -2145,6 +2154,8 @@ static struct bpf_test tests[] = {
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
                { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {
                "check: LDX + RET X",
@@ -2155,6 +2166,8 @@ static struct bpf_test tests[] = {
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
                { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {       /* Mainly checking JIT here. */
                "M[]: alt STX + LDX",
@@ -2329,6 +2342,8 @@ static struct bpf_test tests[] = {
                CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
                { },
                { },
+               .fill_helper = NULL,
+               .expected_errcode = -EINVAL,
        },
        {       /* Passes checker but fails during runtime. */
                "LD [SKF_AD_OFF-1]",
@@ -5391,6 +5406,7 @@ static struct bpf_test tests[] = {
                { },
                { },
                .fill_helper = bpf_fill_maxinsns4,
+               .expected_errcode = -EINVAL,
        },
        {       /* Mainly checking JIT here. */
                "BPF_MAXINSNS: Very long jump",
@@ -5446,10 +5462,15 @@ static struct bpf_test tests[] = {
        {
                "BPF_MAXINSNS: Jump, gap, jump, ...",
                { },
+#ifdef CONFIG_BPF_JIT_ALWAYS_ON
+               CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
+#else
                CLASSIC | FLAG_NO_DATA,
+#endif
                { },
                { { 0, 0xababcbac } },
                .fill_helper = bpf_fill_maxinsns11,
+               .expected_errcode = -ENOTSUPP,
        },
        {
                "BPF_MAXINSNS: ld_abs+get_processor_id",
@@ -6236,7 +6257,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
 
                *err = bpf_prog_create(&fp, &fprog);
                if (tests[which].aux & FLAG_EXPECTED_FAIL) {
-                       if (*err == -EINVAL) {
+                       if (*err == tests[which].expected_errcode) {
                                pr_cont("PASS\n");
                                /* Verifier rejected filter as expected. */
                                *err = 0;