On 23/10/2023 21:08, Nicolin Chen wrote: > On Fri, Oct 20, 2023 at 11:28:02PM +0100, Joao Martins wrote: > >> +static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, >> + unsigned int mockpt_id, unsigned long iova, >> + size_t length, unsigned long page_size, >> + void __user *uptr, u32 flags) >> +{ >> + unsigned long i, max = length / page_size; >> + struct iommu_test_cmd *cmd = ucmd->cmd; >> + struct iommufd_hw_pagetable *hwpt; >> + struct mock_iommu_domain *mock; >> + int rc, count = 0; >> + >> + if (iova % page_size || length % page_size || >> + (uintptr_t)uptr % page_size) >> + return -EINVAL; >> + >> + hwpt = get_md_pagetable(ucmd, mockpt_id, &mock); >> + if (IS_ERR(hwpt)) >> + return PTR_ERR(hwpt); >> + >> + if (!(mock->flags & MOCK_DIRTY_TRACK)) { >> + rc = -EINVAL; >> + goto out_put; >> + } >> + >> + for (i = 0; i < max; i++) { >> + unsigned long cur = iova + i * page_size; >> + void *ent, *old; >> + >> + if (!test_bit(i, (unsigned long *) uptr)) >> + continue; > > Is it okay to test_bit on a user pointer/page? Should we call > get_user_pages or so? > Arggh, let me fix that. This is where it is failing the selftest for you? If so, I should paste a snippet for you to test.