On Mon, Oct 23, 2023 at 07:21:09PM +0100, Joao Martins wrote: > External email: Use caution opening links or attachments > > > On 23/10/2023 19:12, Nicolin Chen wrote: > > On Mon, Oct 23, 2023 at 12:49:55PM +0100, Joao Martins wrote: > >> Here's an example down that avoids the kernel header dependency; imported from > >> the arch-independent non-atomic bitops > >> (include/asm-generic/bitops/generic-non-atomic.h) > >> > >> diff --git a/tools/testing/selftests/iommu/iommufd.c > >> b/tools/testing/selftests/iommu/iommufd.c > >> index 96837369a0aa..026ff9f5c1f3 100644 > >> --- a/tools/testing/selftests/iommu/iommufd.c > >> +++ b/tools/testing/selftests/iommu/iommufd.c > >> @@ -12,7 +12,6 @@ > >> static unsigned long HUGEPAGE_SIZE; > >> > >> #define MOCK_PAGE_SIZE (PAGE_SIZE / 2) > >> -#define BITS_PER_BYTE 8 > >> > >> static unsigned long get_huge_page_size(void) > >> { > >> diff --git a/tools/testing/selftests/iommu/iommufd_utils.h > >> b/tools/testing/selftests/iommu/iommufd_utils.h > >> index 390563ff7935..6bbcab7fd6ab 100644 > >> --- a/tools/testing/selftests/iommu/iommufd_utils.h > >> +++ b/tools/testing/selftests/iommu/iommufd_utils.h > >> @@ -9,8 +9,6 @@ > >> #include <sys/ioctl.h> > >> #include <stdint.h> > >> #include <assert.h> > >> -#include <linux/bitmap.h> > >> -#include <linux/bitops.h> > >> > >> #include "../kselftest_harness.h" > >> #include "../../../../drivers/iommu/iommufd/iommufd_test.h" > >> @@ -18,6 +16,24 @@ > >> /* Hack to make assertions more readable */ > >> #define _IOMMU_TEST_CMD(x) IOMMU_TEST_CMD > >> > >> +/* Imported from include/asm-generic/bitops/generic-non-atomic.h */ > >> +#define BITS_PER_BYTE 8 > >> +#define BITS_PER_LONG __BITS_PER_LONG > >> +#define BIT_MASK(nr) (1UL << ((nr) % __BITS_PER_LONG)) > >> +#define BIT_WORD(nr) ((nr) / __BITS_PER_LONG) > >> + > >> +static inline void set_bit(unsigned int nr, unsigned long *addr) > > > > The whole piece could fix the break, except this one. We'd need > > __set_bit instead of set_bit. > > > > I changed it set_bit in the caller of course Can you confirm the test results too? I am seeing test failing and BUG_ON since this commit: 1d2ac3b64486 (HEAD) iommufd/selftest: Test out_capabilities in IOMMU_GET_HW_INFO -----logs----- # ok 133 iommufd_dirty_tracking.domain_dirty128k.set_dirty_tracking # # RUN iommufd_dirty_tracking.domain_dirty128k.device_dirty_capability ... # # iommufd.c:1577:device_dirty_capability:Expected IOMMU_HW_CAP_DIRTY_TRACKING (1) == caps & IOMMU_HW_CAP_DIRTY_TRACKING (0) # # device_dirty_capability: Test terminated by assertion ..... # # FAILED: 151 / 161 tests passed. -----bug_on----- [ 29.209521] BUG: unable to handle page fault for address: 000056258adc0000 [ 29.209771] #PF: supervisor read access in kernel mode [ 29.209965] #PF: error_code(0x0001) - permissions violation [ 29.210155] PGD 112975067 P4D 112975067 PUD 112976067 PMD 10e5a8067 PTE 800000010973b067 [ 29.210446] Oops: 0001 [#1] SMP [ 29.210594] CPU: 1 PID: 857 Comm: iommufd Not tainted 6.6.0-rc2+ #1823 [ 29.210842] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 [ 29.211267] RIP: 0010:iommufd_test+0xb7a/0x1120 [iommufd] [ 29.211480] Code: 82 a8 00 00 00 4c 8b 7d 90 c7 45 98 00 00 00 00 4d 89 cd 4c 89 5d 88 4c 89 75 80 48 89 45 a8 4c 89 95 78 ff ff ff 48 8b 45 b8 <48> 0f a3 18 73 5e 48 8b 4d a8 31 d2 4c 89 e8 49 f7 f4 48 89 c6 48 [ 29.212131] RSP: 0018:ffffc900029f7d70 EFLAGS: 00010206 [ 29.212348] RAX: 000056258adc0000 RBX: 0000000000000000 RCX: ffff888104296498 [ 29.212638] RDX: 0000000000000000 RSI: 0000000094904f49 RDI: ffff888103fa23c8 [ 29.212928] RBP: ffffc900029f7e00 R08: 0000000000020000 R09: 0000000001000000 [ 29.213214] R10: ffffc900029f7e10 R11: ffffc900029f7e30 R12: 0000000000000800 [ 29.213501] R13: 0000000001000000 R14: ffff888104296400 R15: 0000000000000040 [ 29.213786] FS: 00007f485e907740(0000) GS:ffff8881ba440000(0000) knlGS:0000000000000000 [ 29.214072] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 29.214310] CR2: 000056258adc0000 CR3: 0000000112974001 CR4: 00000000003706a0 [ 29.214592] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 29.214882] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 29.215171] Call Trace: [ 29.215265] <TASK> [ 29.215358] ? show_regs+0x5c/0x70 [ 29.215496] ? __die+0x1f/0x60 [ 29.215638] ? page_fault_oops+0x15d/0x440 [ 29.215779] ? exc_page_fault+0x4ca/0x9e0 [ 29.215923] ? lock_acquire+0xb8/0x2a0 [ 29.216064] ? asm_exc_page_fault+0x27/0x30 [ 29.216207] ? iommufd_test+0xb7a/0x1120 [iommufd] [ 29.216435] ? should_fail_usercopy+0x15/0x20 [ 29.216577] iommufd_fops_ioctl+0x10d/0x190 [iommufd] [ 29.216725] __x64_sys_ioctl+0x412/0x9b0 [ 29.216823] do_syscall_64+0x3c/0x80 [ 29.216919] entry_SYSCALL_64_after_hwframe+0x46/0xb0 [ 29.217050] RIP: 0033:0x7f485ea0d04f [ 29.217147] Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 18 48 8b 44 24 18 64 48 2b 04 25 28 00 00 [ 29.217593] RSP: 002b:00007ffddef77ca0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 29.217785] RAX: ffffffffffffffda RBX: 0000562588e29d60 RCX: 00007f485ea0d04f [ 29.217982] RDX: 00007ffddef77d30 RSI: 0000000000003ba0 RDI: 0000000000000005 [ 29.218177] RBP: 0000562588e29038 R08: 4000000000000000 R09: 0000000000000008 [ 29.218372] R10: 0000000000000001 R11: 0000000000000246 R12: 000056258adc0000 [ 29.218567] R13: 0000000000000000 R14: 0000000000000040 R15: 0000562588e29d60 [ 29.218772] </TASK> [ 29.218835] Modules linked in: iommufd ib_umad rdma_ucm rdma_cm ib_ipoib iw_cm ib_cm mlx5_ib ib_uverbs ib_core mlx5_core [ 29.219117] CR2: 000056258adc0000 [ 29.219216] ---[ end trace 0000000000000000 ]---