[PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff
For now, we have to call some helpers when we need to update the csum, such as bpf_l4_csum_replace, bpf_l3_csum_replace, etc. These helpers are not inlined, which causes poor performance. In fact, we can define our own csum update functions in BPF program instead of bpf_l3_csum_replace, which is totally inlined and efficient. However, we can't do this for bpf_l4_csum_replace for now, as we can't update skb->csum, which can cause skb->csum invalid in the rx path with CHECKSUM_COMPLETE mode. What's more, we can't use the direct data access and have to use skb_store_bytes() with the BPF_F_RECOMPUTE_CSUM flag in some case, such as modifing the vni in the vxlan header and the underlay udp header has no checksum. In the first patch, we make skb->csum readable and writable, and we make skb->ip_summed readable. For now, for tc only. With these 2 fields, we don't need to call bpf helpers for csum update any more. In the second patch, we add some testcases for the read/write testing for skb->csum and skb->ip_summed. If this series is acceptable, we can define the inlined functions for csum update in libbpf in the next step. Menglong Dong (2): bpf: add csum/ip_summed fields to __sk_buff testcases/bpf: add testcases for skb->csum to ctx_skb.c include/linux/skbuff.h| 2 + include/uapi/linux/bpf.h | 2 + net/core/filter.c | 22 ++ tools/include/uapi/linux/bpf.h| 2 + .../testing/selftests/bpf/verifier/ctx_skb.c | 43 +++ 5 files changed, 71 insertions(+) -- 2.39.2
[PATCH bpf-next 1/2] bpf: add csum/ip_summed fields to __sk_buff
For now, we have to call some helpers when we need to update the csum, such as bpf_l4_csum_replace, bpf_l3_csum_replace, etc. These helpers are not inlined, which causes poor performance. In fact, we can define our own csum update functions in BPF program instead of bpf_l3_csum_replace, which is totally inlined and efficient. However, we can't do this for bpf_l4_csum_replace for now, as we can't update skb->csum, which can make skb->csum invalid in the rx path with CHECKSUM_COMPLETE mode. What's more, we can't use the direct data access and have to use skb_store_bytes() with the BPF_F_RECOMPUTE_CSUM flag in some case, such as modifing the vni in the vxlan header and the underlay udp header has no checksum. With the read/write accessing to skb->csum and read accessing to skb->ip_summed, now we can define the inlined csum update functions in libbpf, which are much more efficient. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 2 ++ include/uapi/linux/bpf.h | 2 ++ net/core/filter.c | 22 ++ tools/include/uapi/linux/bpf.h | 2 ++ 4 files changed, 28 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index ea5c8ab3ed00..a0ec404c7009 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1077,8 +1077,10 @@ struct sk_buff { /* if you move pkt_type around you also must adapt those constants */ #ifdef __BIG_ENDIAN_BITFIELD #define PKT_TYPE_MAX (7 << 5) +#define IP_SUMMED_RSH 1 #else #define PKT_TYPE_MAX 7 +#define IP_SUMMED_RSH 5 #endif #define PKT_TYPE_OFFSEToffsetof(struct sk_buff, __pkt_type_offset) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 754e68ca8744..b450e27f5a8d 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6148,6 +6148,8 @@ struct __sk_buff { __u8 tstamp_type; __u32 :24; /* Padding, future use. */ __u64 hwtstamp; + __u32 csum; + __u32 ip_summed; }; struct bpf_tunnel_key { diff --git a/net/core/filter.c b/net/core/filter.c index 24061f29c9dd..23c22d88da1b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -8858,6 +8858,7 @@ static bool tc_cls_act_is_valid_access(int off, int size, case bpf_ctx_range_till(struct __sk_buff, cb[0], cb[4]): case bpf_ctx_range(struct __sk_buff, tstamp): case bpf_ctx_range(struct __sk_buff, queue_mapping): + case bpf_ctx_range(struct __sk_buff, csum): break; default: return false; @@ -8885,6 +8886,8 @@ static bool tc_cls_act_is_valid_access(int off, int size, */ ((struct bpf_prog *)prog)->tstamp_type_access = 1; return size == sizeof(__u8); + case bpf_ctx_range_till(struct __sk_buff, csum, ip_summed): + return size == sizeof(__u32); } return bpf_skb_is_valid_access(off, size, type, prog, info); @@ -9513,6 +9516,25 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, #endif break; + case offsetof(struct __sk_buff, ip_summed): + *target_size = 1; + *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg, + PKT_TYPE_OFFSET); + *insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, IP_SUMMED_RSH); + *insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, 3); + break; + + case offsetof(struct __sk_buff, csum): + if (type == BPF_WRITE) + *insn++ = BPF_EMIT_STORE(BPF_W, si, +bpf_target_off(struct sk_buff, csum, 4, + target_size)); + else + *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg, + bpf_target_off(struct sk_buff, csum, 4, +target_size)); + break; + case offsetof(struct __sk_buff, queue_mapping): if (type == BPF_WRITE) { u32 off = bpf_target_off(struct sk_buff, queue_mapping, 2, target_size); diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 7f24d898efbb..31fd5ee40864 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -6148,6 +6148,8 @@ struct __sk_buff { __u8 tstamp_type; __u32 :24; /* Padding, future use. */ __u64 hwtstamp; + __u32 csum; + __u32 ip_summed; }; struct bpf_tunnel_key { -- 2.39.2
[PATCH bpf-next 2/2] testcases/bpf: add testcases for skb->csum to ctx_skb.c
The testcases for read/write access of skb->csum is added to ctx_skb.c. And the read access testing for skb->ip_summed is also added. Signed-off-by: Menglong Dong --- .../testing/selftests/bpf/verifier/ctx_skb.c | 43 +++ 1 file changed, 43 insertions(+) diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c index 0b394a7f7a2d..f15301686843 100644 --- a/tools/testing/selftests/bpf/verifier/ctx_skb.c +++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c @@ -1193,3 +1193,46 @@ .prog_type = BPF_PROG_TYPE_SK_SKB, .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, +{ + "valid access __sk_buff csum", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct __sk_buff, csum)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, +}, +{ + "valid access __sk_buff ip_summed", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct __sk_buff, ip_summed)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, +}, +{ + "check skb->csum is writeable by CLS/ACT", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct __sk_buff, csum)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .errstr = "invalid bpf_context access", +}, +{ + "check skb->ip_summed is not writeable", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct __sk_buff, csum)), + BPF_EXIT_INSN(), + }, + .result = REJECT, + .errstr = "invalid bpf_context access", +}, -- 2.39.2
Re: [RFC PATCH v3 0/3] Add test to verify probe of devices from discoverable busses
On Thu, Dec 28, 2023 at 05:53:48PM -0600, Bjorn Helgaas wrote: > I have no opinion about the patches themselves, but just a heads-up > that "busses" may be regarded as a misspelling of "buses", e.g., > https://lore.kernel.org/r/20231223184720.25645-1-tintinm2...@gmail.com, > I'm guessing because codespell complains about it. > > Git grep says there are almost as many instances of "busses" as > "buses" in the kernel, so I don't go out of my way to change them. > Just FYI, doesn't matter to me either way. Thanks for the heads up. The online dictionaries seem to agree on "buses", so I'll use that on the next version. Thanks, Nícolas
[PATCH v2 net-next] selftests/net: change shebang to bash to support "source"
The patch set [1] added a general lib.sh in net selftests, and converted several test scripts to source the lib.sh. unicast_extensions.sh (converted in [1]) and pmtu.sh (converted in [2]) have a /bin/sh shebang which may point to various shells in different distributions, but "source" is only available in some of them. For example, "source" is a built-it function in bash, but it cannot be used in dash. Refer to other scripts that were converted together, simply change the shebang to bash to fix the following issues when the default /bin/sh points to other shells. # selftests: net: unicast_extensions.sh # ./unicast_extensions.sh: 31: source: not found # ### # Unicast address extensions tests (behavior of reserved IPv4 addresses) # ### # TEST: assign and ping within 240/4 (1 of 2) (is allowed)[FAIL] # TEST: assign and ping within 240/4 (2 of 2) (is allowed)[FAIL] # TEST: assign and ping within 0/8 (1 of 2) (is allowed) [FAIL] # TEST: assign and ping within 0/8 (2 of 2) (is allowed) [FAIL] # TEST: assign and ping inside 255.255/16 (is allowed)[FAIL] # TEST: assign and ping inside 255.255.255/24 (is allowed)[FAIL] # TEST: route between 240.5.6/24 and 255.1.2/24 (is allowed) [FAIL] # TEST: route between 0.200/16 and 245.99/16 (is allowed) [FAIL] # TEST: assign and ping lowest address (/24) [FAIL] # TEST: assign and ping lowest address (/26) [FAIL] # TEST: routing using lowest address [FAIL] # TEST: assigning 0.0.0.0 (is forbidden) [ OK ] # TEST: assigning 255.255.255.255 (is forbidden) [ OK ] # TEST: assign and ping inside 127/8 (is forbidden) [ OK ] # TEST: assign and ping class D address (is forbidden)[ OK ] # TEST: routing using class D (is forbidden) [ OK ] # TEST: routing using 127/8 (is forbidden)[ OK ] not ok 51 selftests: net: unicast_extensions.sh # exit=1 v1 -> v2: - Fix pmtu.sh which has the same issue as unicast_extensions.sh, suggested by Hangbin - Change the style of the "source" line to be consistent with other tests, suggested by Hangbin Link: https://lore.kernel.org/all/20231202020110.362433-1-liuhang...@gmail.com/ [1] Link: https://lore.kernel.org/all/20231219094856.1740079-1-liuhang...@gmail.com/ [2] Reported-by: kernel test robot Signed-off-by: Yujie Liu --- tools/testing/selftests/net/pmtu.sh | 4 ++-- tools/testing/selftests/net/unicast_extensions.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh index 175d3d1d773b..f10879788f61 100755 --- a/tools/testing/selftests/net/pmtu.sh +++ b/tools/testing/selftests/net/pmtu.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # # Check that route PMTU values match expectations, and that initial device MTU @@ -198,7 +198,7 @@ # - pmtu_ipv6_route_change # Same as above but with IPv6 -source ./lib.sh +source lib.sh PAUSE_ON_FAIL=no VERBOSE=0 diff --git a/tools/testing/selftests/net/unicast_extensions.sh b/tools/testing/selftests/net/unicast_extensions.sh index b7a2cb9e7477..f52aa5f7da52 100755 --- a/tools/testing/selftests/net/unicast_extensions.sh +++ b/tools/testing/selftests/net/unicast_extensions.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # # By Seth Schoen (c) 2021, for the IPv4 Unicast Extensions Project @@ -28,7 +28,7 @@ # These tests provide an easy way to flip the expected result of any # of these behaviors for testing kernel patches that change them. -source ./lib.sh +source lib.sh # nettest can be run from PATH or from same directory as this selftest if ! which nettest >/dev/null; then base-commit: cd4d7263d58ab98fd4dee876776e4da6c328faa3 -- 2.34.1
Re: [PATCH net-next] selftests/net: change the shebang of unicast_extensions.sh to bash
On Tue, Dec 26, 2023 at 08:51:43PM +0800, Hangbin Liu wrote: > On Tue, Dec 26, 2023 at 04:43:18PM +0800, Yujie Liu wrote: > > Hi Hangbin, > > > > On Mon, Dec 25, 2023 at 08:39:09PM +0800, Hangbin Liu wrote: > > > On Mon, Dec 25, 2023 at 03:21:09PM +0800, Yujie Liu wrote: > > > > The patch set [1] added a general lib.sh in net selftests, and converted > > > > several test scripts to source the lib.sh. > > > > > > Oh, I didn't know dash doesn't support "source". Thanks for the fix. > > > Would you please also help fix the pmtu.sh, which has the same issue? > > > > It looks like pmtu.sh was not converted in patch set [1], so it doesn't > > have "source lib.sh" yet. The cover letter of [1] mentions that the > > whole process of conversion will be split into several parts. Not sure > > if pmtu.sh will be converted in the subsequent parts soon? If so, would > > you like to change the shebang of pmtu.sh when converting it later, or > > change it together in this patch? Thanks. > > The pmtu.sh update is in this patch set. > https://lore.kernel.org/all/20231219094856.1740079-1-liuhang...@gmail.com/ > > It would be good to fix these 2 tests together. Sorry for the late reply due to recent holiday. v2 patch has been sent at: https://lore.kernel.org/all/20231229131931.3961150-1-yujie@intel.com/ Please kindly review. Thanks, Yujie > > > > BTW, in addition to pmtu.sh, I noticed that there are several other > > scripts in net selftests which have "/bin/sh" shebang: > > Yes, but the other tests don't use "source". > > > > > linux/tools/testing/selftests/net$ grep -rF '#!/bin/sh' > > openvswitch/openvswitch.sh:#!/bin/sh > > in_netns.sh:#!/bin/sh > > netdevice.sh:#!/bin/sh > > test_bpf.sh:#!/bin/sh > > test_blackhole_dev.sh:#!/bin/sh > > vlan_hw_filter.sh:#!/bin/sh > > run_netsocktests:#!/bin/sh > > pmtu.sh:#!/bin/sh > > bareudp.sh:#!/bin/sh > > l2_tos_ttl_inherit.sh:#!/bin/sh > > veth.sh:#!/bin/sh > > ipv6_flowlabel.sh:#!/bin/sh > > unicast_extensions.sh:#!/bin/sh > > reuseport_addr_any.sh:#!/bin/sh > > run_afpackettests:#!/bin/sh > > ip_local_port_range.sh:#!/bin/sh > > amt.sh:#!/bin/sh > > udpgso.sh:#!/bin/sh > > ip_defrag.sh:#!/bin/sh > > rps_default_mask.sh:#!/bin/sh > > > > > BTW, you can change the "source ./lib.sh" to "source lib.sh" to consistent > > > with other tests. > > > > Sure, will respin a v2 with this change added. > > Thanks > Hangbin
Re: [PATCH v9 00/10] Add iommufd nesting (part 2/2)
On 2023/12/29 11:00, Tian, Kevin wrote: From: Liu, Yi L Sent: Thursday, December 28, 2023 11:06 PM This series is based on the first part which was merged [1], this series is to add the cache invalidation interface or the userspace to invalidate cache after modifying the stage-1 page table. This includes both the iommufd changes and the VT-d driver changes. Complete code can be found in [2], QEMU could can be found in [3]. At last, this is a team work together with Nicolin Chen, Lu Baolu. Thanks them for the help. ^_^. Look forward to your feedbacks. [1] https://lore.kernel.org/linux-iommu/20231026044216.64964-1- yi.l@intel.com/ - merged [2] https://github.com/yiliu1765/iommufd/tree/iommufd_nesting [3] https://github.com/yiliu1765/qemu/tree/zhenzhong/wip/iommufd_nesting_ rfcv1 this looks good to me now, except a few minor comments to patch7. let's see whether Jason may have a chance to look in his holiday and if ok whether he wants to see a new version or just change it while committing. anyhow, I've updated it in below branch. https://github.com/yiliu1765/iommufd/tree/iommufd_nesting -- Regards, Yi Liu
Re: [PATCH v2 net-next] selftests/net: change shebang to bash to support "source"
On 12/29/23 14:19, Yujie Liu wrote: The patch set [1] added a general lib.sh in net selftests, and converted several test scripts to source the lib.sh. unicast_extensions.sh (converted in [1]) and pmtu.sh (converted in [2]) have a /bin/sh shebang which may point to various shells in different distributions, but "source" is only available in some of them. For example, "source" is a built-it function in bash, but it cannot be used in dash. Refer to other scripts that were converted together, simply change the shebang to bash to fix the following issues when the default /bin/sh points to other shells. (snip) Link: https://lore.kernel.org/all/20231202020110.362433-1-liuhang...@gmail.com/ [1] Link: https://lore.kernel.org/all/20231219094856.1740079-1-liuhang...@gmail.com/ [2] Reported-by: kernel test robot Signed-off-by: Yujie Liu I would recommend use of shellcheck in the future, it will catch this particular bug, with following warning: SC3046: In POSIX sh, 'source' in place of '.' is undefined. Being specific, and requiring bash looks fine for me. Reviewed-by: Przemek Kitszel
[PATCH 1/1] userfaultfd: fix move_pages_pte() splitting folio under RCU read lock
While testing the split PMD path with lockdep enabled I've got an "Invalid wait context" error caused by split_huge_page_to_list() trying to lock anon_vma->rwsem while inside RCU read section. The issues is due to move_pages_pte() calling split_folio() under RCU read lock. Fix this by unmapping the PTEs and exiting RCU read section before splitting the folio and then retrying. The same retry pattern is used when locking the folio or anon_vma in this function. Fixes: 94b01c885131 ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Suren Baghdasaryan --- Patch applies over mm-unstable. Please note that the SHA in Fixes tag is unstable. mm/userfaultfd.c | 5 + 1 file changed, 5 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 5e718014e671..71393410e028 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1078,9 +1078,14 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, /* at this point we have src_folio locked */ if (folio_test_large(src_folio)) { + /* split_folio() can block */ + pte_unmap(&orig_src_pte); + pte_unmap(&orig_dst_pte); + src_pte = dst_pte = NULL; err = split_folio(src_folio); if (err) goto out; + goto retry; } if (!src_anon_vma) { -- 2.43.0.472.g3155946c3a-goog
[PATCH 1/2] selftests/mm: add separate UFFDIO_MOVE test for PMD splitting
Add a test for UFFDIO_MOVE ioctl operating on a hugepage which has to be split because destination is marked with MADV_NOHUGEPAGE. With this we cover all 3 cases: normal page move, hugepage move, hugepage splitting before move. Signed-off-by: Suren Baghdasaryan --- Patch applies over mm-unstable. tools/testing/selftests/mm/uffd-unit-tests.c | 17 + 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index d8091523c2df..cce90a10515a 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -1199,6 +1199,16 @@ static void uffd_move_test(uffd_test_args_t *targs) static void uffd_move_pmd_test(uffd_test_args_t *targs) { + if (madvise(area_dst, nr_pages * page_size, MADV_HUGEPAGE)) + err("madvise(MADV_HUGEPAGE) failure"); + uffd_move_test_common(targs, read_pmd_pagesize(), + uffd_move_pmd_handle_fault); +} + +static void uffd_move_pmd_split_test(uffd_test_args_t *targs) +{ + if (madvise(area_dst, nr_pages * page_size, MADV_NOHUGEPAGE)) + err("madvise(MADV_NOHUGEPAGE) failure"); uffd_move_test_common(targs, read_pmd_pagesize(), uffd_move_pmd_handle_fault); } @@ -1330,6 +1340,13 @@ uffd_test_case_t uffd_tests[] = { .uffd_feature_required = UFFD_FEATURE_MOVE, .test_case_ops = &uffd_move_test_pmd_case_ops, }, + { + .name = "move-pmd-split", + .uffd_fn = uffd_move_pmd_split_test, + .mem_targets = MEM_ANON, + .uffd_feature_required = UFFD_FEATURE_MOVE, + .test_case_ops = &uffd_move_test_pmd_case_ops, + }, { .name = "wp-fork", .uffd_fn = uffd_wp_fork_test, -- 2.34.1
Re: [PATCH 1/2] selftests/mm: add separate UFFDIO_MOVE test for PMD splitting
Sorry, I screwed up when sending it out. It's not [1/2], it's supposed to be a stand-alone patch. IOW, don't expect a [2/2] followup :) On Fri, Dec 29, 2023 at 6:56 PM Suren Baghdasaryan wrote: > > Add a test for UFFDIO_MOVE ioctl operating on a hugepage which has to > be split because destination is marked with MADV_NOHUGEPAGE. With this > we cover all 3 cases: normal page move, hugepage move, hugepage splitting > before move. > > Signed-off-by: Suren Baghdasaryan > --- > Patch applies over mm-unstable. > > tools/testing/selftests/mm/uffd-unit-tests.c | 17 + > 1 file changed, 17 insertions(+) > > diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c > b/tools/testing/selftests/mm/uffd-unit-tests.c > index d8091523c2df..cce90a10515a 100644 > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > @@ -1199,6 +1199,16 @@ static void uffd_move_test(uffd_test_args_t *targs) > > static void uffd_move_pmd_test(uffd_test_args_t *targs) > { > + if (madvise(area_dst, nr_pages * page_size, MADV_HUGEPAGE)) > + err("madvise(MADV_HUGEPAGE) failure"); > + uffd_move_test_common(targs, read_pmd_pagesize(), > + uffd_move_pmd_handle_fault); > +} > + > +static void uffd_move_pmd_split_test(uffd_test_args_t *targs) > +{ > + if (madvise(area_dst, nr_pages * page_size, MADV_NOHUGEPAGE)) > + err("madvise(MADV_NOHUGEPAGE) failure"); > uffd_move_test_common(targs, read_pmd_pagesize(), > uffd_move_pmd_handle_fault); > } > @@ -1330,6 +1340,13 @@ uffd_test_case_t uffd_tests[] = { > .uffd_feature_required = UFFD_FEATURE_MOVE, > .test_case_ops = &uffd_move_test_pmd_case_ops, > }, > + { > + .name = "move-pmd-split", > + .uffd_fn = uffd_move_pmd_split_test, > + .mem_targets = MEM_ANON, > + .uffd_feature_required = UFFD_FEATURE_MOVE, > + .test_case_ops = &uffd_move_test_pmd_case_ops, > + }, > { > .name = "wp-fork", > .uffd_fn = uffd_wp_fork_test, > -- > 2.34.1 >
Re: [PATCH v2 net-next] selftests/net: change shebang to bash to support "source"
On Fri, Dec 29, 2023 at 09:19:31PM +0800, Yujie Liu wrote: > The patch set [1] added a general lib.sh in net selftests, and converted > several test scripts to source the lib.sh. > > unicast_extensions.sh (converted in [1]) and pmtu.sh (converted in [2]) > have a /bin/sh shebang which may point to various shells in different > distributions, but "source" is only available in some of them. For > example, "source" is a built-it function in bash, but it cannot be > used in dash. > > Refer to other scripts that were converted together, simply change the > shebang to bash to fix the following issues when the default /bin/sh > points to other shells. > > # selftests: net: unicast_extensions.sh > # ./unicast_extensions.sh: 31: source: not found > # ### > # Unicast address extensions tests (behavior of reserved IPv4 addresses) > # ### > # TEST: assign and ping within 240/4 (1 of 2) (is allowed)[FAIL] > # TEST: assign and ping within 240/4 (2 of 2) (is allowed)[FAIL] > # TEST: assign and ping within 0/8 (1 of 2) (is allowed) [FAIL] > # TEST: assign and ping within 0/8 (2 of 2) (is allowed) [FAIL] > # TEST: assign and ping inside 255.255/16 (is allowed)[FAIL] > # TEST: assign and ping inside 255.255.255/24 (is allowed)[FAIL] > # TEST: route between 240.5.6/24 and 255.1.2/24 (is allowed) [FAIL] > # TEST: route between 0.200/16 and 245.99/16 (is allowed) [FAIL] > # TEST: assign and ping lowest address (/24) [FAIL] > # TEST: assign and ping lowest address (/26) [FAIL] > # TEST: routing using lowest address [FAIL] > # TEST: assigning 0.0.0.0 (is forbidden) [ OK ] > # TEST: assigning 255.255.255.255 (is forbidden) [ OK ] > # TEST: assign and ping inside 127/8 (is forbidden) [ OK ] > # TEST: assign and ping class D address (is forbidden)[ OK ] > # TEST: routing using class D (is forbidden) [ OK ] > # TEST: routing using 127/8 (is forbidden)[ OK ] > not ok 51 selftests: net: unicast_extensions.sh # exit=1 > > v1 -> v2: > - Fix pmtu.sh which has the same issue as unicast_extensions.sh, > suggested by Hangbin > - Change the style of the "source" line to be consistent with other > tests, suggested by Hangbin > > Link: > https://lore.kernel.org/all/20231202020110.362433-1-liuhang...@gmail.com/ [1] > Link: > https://lore.kernel.org/all/20231219094856.1740079-1-liuhang...@gmail.com/ [2] > Reported-by: kernel test robot > Signed-off-by: Yujie Liu > --- > tools/testing/selftests/net/pmtu.sh | 4 ++-- > tools/testing/selftests/net/unicast_extensions.sh | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/net/pmtu.sh > b/tools/testing/selftests/net/pmtu.sh > index 175d3d1d773b..f10879788f61 100755 > --- a/tools/testing/selftests/net/pmtu.sh > +++ b/tools/testing/selftests/net/pmtu.sh > @@ -1,4 +1,4 @@ > -#!/bin/sh > +#!/bin/bash > # SPDX-License-Identifier: GPL-2.0 > # > # Check that route PMTU values match expectations, and that initial device > MTU > @@ -198,7 +198,7 @@ > # - pmtu_ipv6_route_change > #Same as above but with IPv6 > > -source ./lib.sh > +source lib.sh > > PAUSE_ON_FAIL=no > VERBOSE=0 > diff --git a/tools/testing/selftests/net/unicast_extensions.sh > b/tools/testing/selftests/net/unicast_extensions.sh > index b7a2cb9e7477..f52aa5f7da52 100755 > --- a/tools/testing/selftests/net/unicast_extensions.sh > +++ b/tools/testing/selftests/net/unicast_extensions.sh > @@ -1,4 +1,4 @@ > -#!/bin/sh > +#!/bin/bash > # SPDX-License-Identifier: GPL-2.0 > # > # By Seth Schoen (c) 2021, for the IPv4 Unicast Extensions Project > @@ -28,7 +28,7 @@ > # These tests provide an easy way to flip the expected result of any > # of these behaviors for testing kernel patches that change them. > > -source ./lib.sh > +source lib.sh > > # nettest can be run from PATH or from same directory as this selftest > if ! which nettest >/dev/null; then > > base-commit: cd4d7263d58ab98fd4dee876776e4da6c328faa3 > -- > 2.34.1 > Reviewed-by: Hangbin Liu
Re: [PATCH v2 net-next] selftests/net: change shebang to bash to support "source"
On 12/29/23 6:19 PM, Yujie Liu wrote: > The patch set [1] added a general lib.sh in net selftests, and converted > several test scripts to source the lib.sh. > > unicast_extensions.sh (converted in [1]) and pmtu.sh (converted in [2]) > have a /bin/sh shebang which may point to various shells in different > distributions, but "source" is only available in some of them. For > example, "source" is a built-it function in bash, but it cannot be > used in dash. > > Refer to other scripts that were converted together, simply change the > shebang to bash to fix the following issues when the default /bin/sh > points to other shells. > > # selftests: net: unicast_extensions.sh > # ./unicast_extensions.sh: 31: source: not found > # ### > # Unicast address extensions tests (behavior of reserved IPv4 addresses) > # ### > # TEST: assign and ping within 240/4 (1 of 2) (is allowed)[FAIL] > # TEST: assign and ping within 240/4 (2 of 2) (is allowed)[FAIL] > # TEST: assign and ping within 0/8 (1 of 2) (is allowed) [FAIL] > # TEST: assign and ping within 0/8 (2 of 2) (is allowed) [FAIL] > # TEST: assign and ping inside 255.255/16 (is allowed)[FAIL] > # TEST: assign and ping inside 255.255.255/24 (is allowed)[FAIL] > # TEST: route between 240.5.6/24 and 255.1.2/24 (is allowed) [FAIL] > # TEST: route between 0.200/16 and 245.99/16 (is allowed) [FAIL] > # TEST: assign and ping lowest address (/24) [FAIL] > # TEST: assign and ping lowest address (/26) [FAIL] > # TEST: routing using lowest address [FAIL] > # TEST: assigning 0.0.0.0 (is forbidden) [ OK ] > # TEST: assigning 255.255.255.255 (is forbidden) [ OK ] > # TEST: assign and ping inside 127/8 (is forbidden) [ OK ] > # TEST: assign and ping class D address (is forbidden)[ OK ] > # TEST: routing using class D (is forbidden) [ OK ] > # TEST: routing using 127/8 (is forbidden)[ OK ] > not ok 51 selftests: net: unicast_extensions.sh # exit=1 > > v1 -> v2: > - Fix pmtu.sh which has the same issue as unicast_extensions.sh, > suggested by Hangbin > - Change the style of the "source" line to be consistent with other > tests, suggested by Hangbin > > Link: > https://lore.kernel.org/all/20231202020110.362433-1-liuhang...@gmail.com/ [1] > Link: > https://lore.kernel.org/all/20231219094856.1740079-1-liuhang...@gmail.com/ [2] > Reported-by: kernel test robot > Signed-off-by: Yujie Liu Reviewed-by: Muhammad Usama Anjum > --- > tools/testing/selftests/net/pmtu.sh | 4 ++-- > tools/testing/selftests/net/unicast_extensions.sh | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/net/pmtu.sh > b/tools/testing/selftests/net/pmtu.sh > index 175d3d1d773b..f10879788f61 100755 > --- a/tools/testing/selftests/net/pmtu.sh > +++ b/tools/testing/selftests/net/pmtu.sh > @@ -1,4 +1,4 @@ > -#!/bin/sh > +#!/bin/bash > # SPDX-License-Identifier: GPL-2.0 > # > # Check that route PMTU values match expectations, and that initial device > MTU > @@ -198,7 +198,7 @@ > # - pmtu_ipv6_route_change > #Same as above but with IPv6 > > -source ./lib.sh > +source lib.sh > > PAUSE_ON_FAIL=no > VERBOSE=0 > diff --git a/tools/testing/selftests/net/unicast_extensions.sh > b/tools/testing/selftests/net/unicast_extensions.sh > index b7a2cb9e7477..f52aa5f7da52 100755 > --- a/tools/testing/selftests/net/unicast_extensions.sh > +++ b/tools/testing/selftests/net/unicast_extensions.sh > @@ -1,4 +1,4 @@ > -#!/bin/sh > +#!/bin/bash > # SPDX-License-Identifier: GPL-2.0 > # > # By Seth Schoen (c) 2021, for the IPv4 Unicast Extensions Project > @@ -28,7 +28,7 @@ > # These tests provide an easy way to flip the expected result of any > # of these behaviors for testing kernel patches that change them. > > -source ./lib.sh > +source lib.sh > > # nettest can be run from PATH or from same directory as this selftest > if ! which nettest >/dev/null; then > > base-commit: cd4d7263d58ab98fd4dee876776e4da6c328faa3 -- BR, Muhammad Usama Anjum
Re: [PATCH v3 1/2] selftests/vDSO: Fix building errors on LoongArch
On 12/13/23 6:22 AM, Tiezhu Yang wrote: > There exist the following errors when build vDSO selftests on LoongArch: > > # make headers && cd tools/testing/selftests/vDSO && make > ... > error: 'VDSO_VERSION' undeclared (first use in this function) > ... > error: 'VDSO_NAMES' undeclared (first use in this function) > > We can see the following code in arch/loongarch/vdso/vdso.lds.S: > > VERSION > { > LINUX_5.10 { > global: > __vdso_getcpu; > __vdso_clock_getres; > __vdso_clock_gettime; > __vdso_gettimeofday; > __vdso_rt_sigreturn; > local: *; > }; > } > > so VDSO_VERSION should be 6 and VDSO_NAMES should be 1 for LoongArch, > add them to fix the building errors on LoongArch. > > Signed-off-by: Tiezhu Yang Reviewed-by: Muhammad Usama Anjum > --- > tools/testing/selftests/vDSO/vdso_config.h | 6 +- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/vDSO/vdso_config.h > b/tools/testing/selftests/vDSO/vdso_config.h > index cdfed403ba13..7b543e7f04d7 100644 > --- a/tools/testing/selftests/vDSO/vdso_config.h > +++ b/tools/testing/selftests/vDSO/vdso_config.h > @@ -53,15 +53,19 @@ > #if __riscv_xlen == 32 > #define VDSO_32BIT 1 > #endif > +#elif defined(__loongarch__) > +#define VDSO_VERSION 6 > +#define VDSO_NAMES 1 > #endif > > -static const char *versions[6] = { > +static const char *versions[7] = { > "LINUX_2.6", > "LINUX_2.6.15", > "LINUX_2.6.29", > "LINUX_2.6.39", > "LINUX_4", > "LINUX_4.15", > + "LINUX_5.10" > }; > > static const char *names[2][6] = { -- BR, Muhammad Usama Anjum
Re: [PATCH v3 2/2] selftests/vDSO: Fix runtime errors on LoongArch
On 12/13/23 6:23 AM, Tiezhu Yang wrote: > It could not find __vdso_getcpu and __vdso_gettimeofday when test > getcpu and gettimeofday on LoongArch. > > # make headers && cd tools/testing/selftests/vDSO && make > # ./vdso_test_getcpu > Could not find __vdso_getcpu > # ./vdso_test_gettimeofday > Could not find __vdso_gettimeofday > > One simple way is to add LoongArch case to define version and name, > just like commit d942f231afc0 ("selftests/vDSO: Add riscv getcpu & > gettimeofday test"), but it is not the best way. > > Since each architecture has already defined names and versions in > vdso_config.h, it is proper to include vdso_config.h to get version > and name for all archs. > > Signed-off-by: Tiezhu Yang Reviewed-by: Muhammad Usama Anjum Tested on x86, works fine. Tested-by: Muhammad Usama Anjum > --- > .../testing/selftests/vDSO/vdso_test_getcpu.c | 16 +--- > .../selftests/vDSO/vdso_test_gettimeofday.c | 26 +-- > 2 files changed, 13 insertions(+), 29 deletions(-) > > diff --git a/tools/testing/selftests/vDSO/vdso_test_getcpu.c > b/tools/testing/selftests/vDSO/vdso_test_getcpu.c > index 1df5d057d79f..b758f68c6c9c 100644 > --- a/tools/testing/selftests/vDSO/vdso_test_getcpu.c > +++ b/tools/testing/selftests/vDSO/vdso_test_getcpu.c > @@ -13,13 +13,7 @@ > > #include "../kselftest.h" > #include "parse_vdso.h" > - > -#if defined(__riscv) > -const char *version = "LINUX_4.15"; > -#else > -const char *version = "LINUX_2.6"; > -#endif > -const char *name = "__vdso_getcpu"; > +#include "vdso_config.h" > > struct getcpu_cache; > typedef long (*getcpu_t)(unsigned int *, unsigned int *, > @@ -27,6 +21,8 @@ typedef long (*getcpu_t)(unsigned int *, unsigned int *, > > int main(int argc, char **argv) > { > + const char *version = versions[VDSO_VERSION]; > + const char **name = (const char **)&names[VDSO_NAMES]; > unsigned long sysinfo_ehdr; > unsigned int cpu, node; > getcpu_t get_cpu; > @@ -40,9 +36,9 @@ int main(int argc, char **argv) > > vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR)); > > - get_cpu = (getcpu_t)vdso_sym(version, name); > + get_cpu = (getcpu_t)vdso_sym(version, name[4]); > if (!get_cpu) { > - printf("Could not find %s\n", name); > + printf("Could not find %s\n", name[4]); > return KSFT_SKIP; > } > > @@ -50,7 +46,7 @@ int main(int argc, char **argv) > if (ret == 0) { > printf("Running on CPU %u node %u\n", cpu, node); > } else { > - printf("%s failed\n", name); > + printf("%s failed\n", name[4]); > return KSFT_FAIL; > } > > diff --git a/tools/testing/selftests/vDSO/vdso_test_gettimeofday.c > b/tools/testing/selftests/vDSO/vdso_test_gettimeofday.c > index e411f287a426..ee4f1ca56a71 100644 > --- a/tools/testing/selftests/vDSO/vdso_test_gettimeofday.c > +++ b/tools/testing/selftests/vDSO/vdso_test_gettimeofday.c > @@ -18,25 +18,13 @@ > > #include "../kselftest.h" > #include "parse_vdso.h" > - > -/* > - * ARM64's vDSO exports its gettimeofday() implementation with a different > - * name and version from other architectures, so we need to handle it as > - * a special case. > - */ > -#if defined(__aarch64__) > -const char *version = "LINUX_2.6.39"; > -const char *name = "__kernel_gettimeofday"; > -#elif defined(__riscv) > -const char *version = "LINUX_4.15"; > -const char *name = "__vdso_gettimeofday"; > -#else > -const char *version = "LINUX_2.6"; > -const char *name = "__vdso_gettimeofday"; > -#endif > +#include "vdso_config.h" > > int main(int argc, char **argv) > { > + const char *version = versions[VDSO_VERSION]; > + const char **name = (const char **)&names[VDSO_NAMES]; > + > unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR); > if (!sysinfo_ehdr) { > printf("AT_SYSINFO_EHDR is not present!\n"); > @@ -47,10 +35,10 @@ int main(int argc, char **argv) > > /* Find gettimeofday. */ > typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz); > - gtod_t gtod = (gtod_t)vdso_sym(version, name); > + gtod_t gtod = (gtod_t)vdso_sym(version, name[0]); > > if (!gtod) { > - printf("Could not find %s\n", name); > + printf("Could not find %s\n", name[0]); > return KSFT_SKIP; > } > > @@ -61,7 +49,7 @@ int main(int argc, char **argv) > printf("The time is %lld.%06lld\n", > (long long)tv.tv_sec, (long long)tv.tv_usec); > } else { > - printf("%s failed\n", name); > + printf("%s failed\n", name[0]); > return KSFT_FAIL; > } > -- BR, Muhammad Usama Anjum
Re: [PATCH v3 0/2] selftests/vDSO: Fix errors on LoongArch
On 12/27/23 12:55 PM, Tiezhu Yang wrote: > + Andrew Morton > + Mark Brown > > On 12/13/2023 09:22 AM, Tiezhu Yang wrote: >> v3: Rebase on the next branch of linux-kselftest.git, >> modify the patch title and update the commit message >> >> v2: Rebase on 6.5-rc1 and update the commit message >> >> Tiezhu Yang (2): >> selftests/vDSO: Fix building errors on LoongArch >> selftests/vDSO: Fix runtime errors on LoongArch >> >> tools/testing/selftests/vDSO/vdso_config.h | 6 - >> .../testing/selftests/vDSO/vdso_test_getcpu.c | 16 +--- >> .../selftests/vDSO/vdso_test_gettimeofday.c | 26 +-- >> 3 files changed, 18 insertions(+), 30 deletions(-) >> > > Hi Shuah, Andrew and Mark, > > The patches still seem to apply cleanly. > Could you please review and merge them for the upcoming merge window? People may be on vacation. I'm also waiting to hear back on my patches. Lets see when they get back and start picking up patches. > > https://lore.kernel.org/lkml/20231213012300.5640-1-yangtie...@loongson.cn/ > > Thanks, > Tiezhu > > -- BR, Muhammad Usama Anjum
Re: [PATCH v2] selftests: uevent: use shared makefile library
On 12/22/23 1:49 AM, Antonio Terceiro wrote: > This makes the uevent selftests build not write to the source tree > unconditionally, as that breaks out of tree builds when the source tree > is read-only. It also avoids leaving a git repository in a dirty state > after a build. I can see what you are trying to do. The makefile has issues such as lib.mk should be included at the end of the file. Please just clarify this in the message. > > v2: drop spurious extra SPDX-License-Identifier > > Signed-off-by: Antonio Terceiro > --- > tools/testing/selftests/uevent/Makefile | 15 +++ > 1 file changed, 3 insertions(+), 12 deletions(-) > > diff --git a/tools/testing/selftests/uevent/Makefile > b/tools/testing/selftests/uevent/Makefile > index f7baa9aa2932..872969f42694 100644 > --- a/tools/testing/selftests/uevent/Makefile > +++ b/tools/testing/selftests/uevent/Makefile > @@ -1,17 +1,8 @@ > # SPDX-License-Identifier: GPL-2.0 > all: > > -include ../lib.mk > - > -.PHONY: all clean > - > -BINARIES := uevent_filtering > -CFLAGS += -Wl,-no-as-needed -Wall > +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) > > -uevent_filtering: uevent_filtering.c ../kselftest.h ../kselftest_harness.h > - $(CC) $(CFLAGS) $< -o $@ > +TEST_GEN_PROGS = uevent_filtering > > -TEST_PROGS += $(BINARIES) > -EXTRA_CLEAN := $(BINARIES) > - > -all: $(BINARIES) > +include ../lib.mk -- BR, Muhammad Usama Anjum
Re: [PATCH] kunit: Protect string comparisons against NULL
On 12/20/23 8:52 PM, Richard Fitzgerald wrote: > Add NULL checks to KUNIT_BINARY_STR_ASSERTION() so that it will fail > cleanly if either pointer is NULL, instead of causing a NULL pointer > dereference in the strcmp(). > > A test failure could be that a string is unexpectedly NULL. This could > be trapped by KUNIT_ASSERT_NOT_NULL() but that would terminate the test > at that point. It's preferable that the KUNIT_EXPECT_STR*() macros can > handle NULL pointers as a failure. > > Signed-off-by: Richard Fitzgerald Reviewed-by: Muhammad Usama Anjum > --- > include/kunit/test.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index b163b9984b33..c2ce379c329b 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -758,7 +758,7 @@ do { >\ > .right_text = #right, \ > }; \ > \ > - if (likely(strcmp(__left, __right) op 0)) \ > + if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \ > break; \ > \ > \ -- BR, Muhammad Usama Anjum
Re: [PATCH] kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL
On 12/18/23 8:17 PM, Richard Fitzgerald wrote: > suite->log must be checked for NULL before passing it to > string_stream_clear(). This was done in kunit_init_test() but was missing > from kunit_init_suite(). > > Signed-off-by: Richard Fitzgerald > Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using > debugfs") Reviewed-by: Muhammad Usama Anjum > --- > lib/kunit/test.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index e803d998e855..ea7f0913e55a 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -658,7 +658,9 @@ static void kunit_init_suite(struct kunit_suite *suite) > kunit_debugfs_create_suite(suite); > suite->status_comment[0] = '\0'; > suite->suite_init_err = 0; > - string_stream_clear(suite->log); > + > + if (suite->log) > + string_stream_clear(suite->log); > } > > bool kunit_enabled(void) -- BR, Muhammad Usama Anjum