From: Nicolin Chen <nicolinc@nvidia.com>
To: Joao Martins <joao.m.martins@oracle.com>
Cc: <iommu@lists.linux.dev>, Jason Gunthorpe <jgg@nvidia.com>,
Kevin Tian <kevin.tian@intel.com>,
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>,
Lu Baolu <baolu.lu@linux.intel.com>, Yi Liu <yi.l.liu@intel.com>,
Yi Y Sun <yi.y.sun@intel.com>, Joerg Roedel <joro@8bytes.org>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
Alex Williamson <alex.williamson@redhat.com>,
<kvm@vger.kernel.org>
Subject: Re: [PATCH v5 16/18] iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP
Date: Mon, 23 Oct 2023 13:37:28 -0700 [thread overview]
Message-ID: <ZTbZiKhkrSaxpqNU@Asurada-Nvidia> (raw)
In-Reply-To: <0a641e15-a6e4-4113-932d-ba2caa236653@oracle.com>
On Mon, Oct 23, 2023 at 09:15:32PM +0100, Joao Martins wrote:
> External email: Use caution opening links or attachments
>
>
> 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.
Yea, the crash seems to be caused by this. Possibly some memory
debugging feature that I turned on caught this?
I tried a test fix and the crash is gone (attaching at EOM).
However, I still see other failures:
# # RUN iommufd_dirty_tracking.domain_dirty128M.get_dirty_bitmap ...
# # iommufd_utils.h:292:get_dirty_bitmap:Expected nr (32768) == out_dirty (13648)
# # get_dirty_bitmap: Test terminated by assertion
# # FAIL iommufd_dirty_tracking.domain_dirty128M.get_dirty_bitmap
# not ok 147 iommufd_dirty_tracking.domain_dirty128M.get_dirty_bitmap
# # RUN iommufd_dirty_tracking.domain_dirty256M.enforce_dirty ...
# # OK iommufd_dirty_tracking.domain_dirty256M.enforce_dirty
# ok 148 iommufd_dirty_tracking.domain_dirty256M.enforce_dirty
# # RUN iommufd_dirty_tracking.domain_dirty256M.set_dirty_tracking ...
# # OK iommufd_dirty_tracking.domain_dirty256M.set_dirty_tracking
# ok 149 iommufd_dirty_tracking.domain_dirty256M.set_dirty_tracking
# # RUN iommufd_dirty_tracking.domain_dirty256M.device_dirty_capability ...
# # OK iommufd_dirty_tracking.domain_dirty256M.device_dirty_capability
# ok 150 iommufd_dirty_tracking.domain_dirty256M.device_dirty_capability
# # RUN iommufd_dirty_tracking.domain_dirty256M.get_dirty_bitmap ...
# # iommufd_utils.h:292:get_dirty_bitmap:Expected nr (65536) == out_dirty (8923)
Maybe page_size isn't the right size?
-------------attaching copy_from_user------------
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 8a2c7df85441..daa198809d61 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -1103,8 +1103,9 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
struct iommufd_hw_pagetable *hwpt;
struct mock_iommu_domain *mock;
int rc, count = 0;
+ void *tmp;
- if (iova % page_size || length % page_size ||
+ if (iova % page_size || length % page_size || !uptr ||
(uintptr_t)uptr % page_size)
return -EINVAL;
@@ -1117,11 +1118,22 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
goto out_put;
}
+ tmp = kvzalloc(page_size, GFP_KERNEL_ACCOUNT);
+ if (!tmp) {
+ rc = -ENOMEM;
+ 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))
+ if (copy_from_user(tmp, uptr, page_size)) {
+ rc = -EFAULT;
+ goto out_free;
+ }
+
+ if (!test_bit(i, (unsigned long *)tmp))
continue;
ent = xa_load(&mock->pfns, cur / page_size);
@@ -1138,6 +1150,8 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
cmd->dirty.out_nr_dirty = count;
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+out_free:
+ kvfree(tmp);
out_put:
iommufd_put_object(&hwpt->obj);
return rc;
next prev parent reply other threads:[~2023-10-23 20:37 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 22:27 [PATCH v5 00/18] IOMMUFD Dirty Tracking Joao Martins
2023-10-20 22:27 ` [PATCH v5 01/18] vfio/iova_bitmap: Export more API symbols Joao Martins
2023-10-20 22:27 ` [PATCH v5 02/18] vfio: Move iova_bitmap into iommufd Joao Martins
2023-10-20 22:27 ` [PATCH v5 03/18] iommufd/iova_bitmap: Move symbols to IOMMUFD namespace Joao Martins
2023-10-20 22:27 ` [PATCH v5 04/18] iommu: Add iommu_domain ops for dirty tracking Joao Martins
2023-10-20 22:27 ` [PATCH v5 05/18] iommufd: Add a flag to enforce dirty tracking on attach Joao Martins
2023-10-20 22:27 ` [PATCH v5 06/18] iommufd: Add IOMMU_HWPT_SET_DIRTY_TRACKING Joao Martins
2023-10-20 22:27 ` [PATCH v5 07/18] iommufd: Add IOMMU_HWPT_GET_DIRTY_BITMAP Joao Martins
2023-10-23 9:09 ` Arnd Bergmann
2023-10-23 9:28 ` Joao Martins
2023-10-23 12:10 ` Jason Gunthorpe
2023-10-23 12:41 ` Arnd Bergmann
2023-10-23 15:56 ` Joao Martins
2023-10-23 16:16 ` Jason Gunthorpe
2023-10-23 16:31 ` Joao Martins
2023-10-23 16:34 ` Jason Gunthorpe
2023-10-23 17:55 ` Joao Martins
2023-10-23 18:08 ` Jason Gunthorpe
2023-10-20 22:27 ` [PATCH v5 08/18] iommufd: Add capabilities to IOMMU_GET_HW_INFO Joao Martins
2023-10-20 22:27 ` [PATCH v5 09/18] iommufd: Add a flag to skip clearing of IOPTE dirty Joao Martins
2023-10-20 22:27 ` [PATCH v5 10/18] iommu/amd: Add domain_alloc_user based domain allocation Joao Martins
2023-10-20 22:27 ` [PATCH v5 11/18] iommu/amd: Access/Dirty bit support in IOPTEs Joao Martins
2023-10-20 22:27 ` [PATCH v5 12/18] iommu/intel: Access/Dirty bit support for SL domains Joao Martins
2023-10-24 12:34 ` Yi Liu
2023-10-24 12:42 ` Joao Martins
2023-10-24 12:52 ` Joao Martins
2023-10-24 13:51 ` Yi Liu
2023-10-20 22:27 ` [PATCH v5 13/18] iommufd/selftest: Expand mock_domain with dev_flags Joao Martins
2023-10-20 22:28 ` [PATCH v5 14/18] iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING Joao Martins
2023-10-20 22:28 ` [PATCH v5 15/18] iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING Joao Martins
2023-10-20 22:28 ` [PATCH v5 16/18] iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP Joao Martins
2023-10-23 20:08 ` Nicolin Chen
2023-10-23 20:15 ` Joao Martins
2023-10-23 20:37 ` Nicolin Chen [this message]
2023-10-23 20:50 ` Joao Martins
2023-10-23 21:46 ` Joao Martins
2023-10-23 21:56 ` Nicolin Chen
2023-10-20 22:28 ` [PATCH v5 17/18] iommufd/selftest: Test out_capabilities in IOMMU_GET_HW_INFO Joao Martins
2023-10-20 22:28 ` [PATCH v5 18/18] iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag Joao Martins
2023-10-21 16:23 ` [PATCH v5 00/18] IOMMUFD Dirty Tracking Jason Gunthorpe
2023-10-23 1:36 ` Nicolin Chen
2023-10-23 9:15 ` Joao Martins
2023-10-23 11:49 ` Joao Martins
2023-10-23 13:24 ` Jason Gunthorpe
2023-10-23 18:12 ` Nicolin Chen
2023-10-23 18:21 ` Joao Martins
2023-10-23 18:32 ` Nicolin Chen
2023-10-23 18:52 ` Joao Martins
2023-10-23 18:10 ` Nicolin Chen
2023-10-23 18:20 ` Joao Martins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZTbZiKhkrSaxpqNU@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@intel.com \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox