public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Joao Martins <joao.m.martins@oracle.com>
Cc: iommu@lists.linux.dev, 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>, Nicolin Chen <nicolinc@nvidia.com>,
	Joerg Roedel <joro@8bytes.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 10/19] iommufd: Add IOMMU_HWPT_GET_DIRTY_IOVA
Date: Fri, 13 Oct 2023 13:22:17 -0300	[thread overview]
Message-ID: <20231013162217.GF3952@nvidia.com> (raw)
In-Reply-To: <20230923012511.10379-11-joao.m.martins@oracle.com>

On Sat, Sep 23, 2023 at 02:25:02AM +0100, Joao Martins wrote:

> +int iommufd_check_iova_range(struct iommufd_ioas *ioas,
> +			     struct iommufd_dirty_data *bitmap)
> +{
> +	unsigned long pgshift, npages;
> +	size_t iommu_pgsize;
> +	int rc = -EINVAL;
> +
> +	pgshift = __ffs(bitmap->page_size);
> +	npages = bitmap->length >> pgshift;
> +
> +	if (!npages || (npages > ULONG_MAX))
> +		return rc;
> +
> +	iommu_pgsize = 1 << __ffs(ioas->iopt.iova_alignment);

iova_alignment is not a bitmask, it is the alignment itself, so is
redundant.

> +	/* allow only smallest supported pgsize */
> +	if (bitmap->page_size != iommu_pgsize)
> +		return rc;

!= is smallest?

Why are we restricting this anyhow? I thought the iova bitmap stuff
did all the adaptation automatically?

I can sort of see restricting the start/stop iova


> +	if (bitmap->iova & (iommu_pgsize - 1))
> +		return rc;
> +
> +	if (!bitmap->length || bitmap->length & (iommu_pgsize - 1))
> +		return rc;
> +
> +	return 0;
> +}

> --- a/drivers/iommu/iommufd/main.c
> +++ b/drivers/iommu/iommufd/main.c
> @@ -316,6 +316,7 @@ union ucmd_buffer {
>  	struct iommu_option option;
>  	struct iommu_vfio_ioas vfio_ioas;
>  	struct iommu_hwpt_set_dirty set_dirty;
> +	struct iommu_hwpt_get_dirty_iova get_dirty_iova;
>  #ifdef CONFIG_IOMMUFD_TEST
>  	struct iommu_test_cmd test;
>  #endif
> @@ -361,6 +362,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = {
>  		 __reserved),
>  	IOCTL_OP(IOMMU_HWPT_SET_DIRTY, iommufd_hwpt_set_dirty,
>  		 struct iommu_hwpt_set_dirty, __reserved),
> +	IOCTL_OP(IOMMU_HWPT_GET_DIRTY_IOVA, iommufd_hwpt_get_dirty_iova,
> +		 struct iommu_hwpt_get_dirty_iova, bitmap.data),

Also keep sorted

>  #ifdef CONFIG_IOMMUFD_TEST
>  	IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last),
>  #endif
> diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
> index 37079e72d243..b35b7d0c4be0 100644
> --- a/include/uapi/linux/iommufd.h
> +++ b/include/uapi/linux/iommufd.h
> @@ -48,6 +48,7 @@ enum {
>  	IOMMUFD_CMD_HWPT_ALLOC,
>  	IOMMUFD_CMD_GET_HW_INFO,
>  	IOMMUFD_CMD_HWPT_SET_DIRTY,
> +	IOMMUFD_CMD_HWPT_GET_DIRTY_IOVA,
>  };
>  
>  /**
> @@ -481,4 +482,39 @@ struct iommu_hwpt_set_dirty {
>  	__u32 __reserved;
>  };
>  #define IOMMU_HWPT_SET_DIRTY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_SET_DIRTY)
> +
> +/**
> + * struct iommufd_dirty_bitmap - Dirty IOVA tracking bitmap
> + * @iova: base IOVA of the bitmap
> + * @length: IOVA size
> + * @page_size: page size granularity of each bit in the bitmap
> + * @data: bitmap where to set the dirty bits. The bitmap bits each
> + * represent a page_size which you deviate from an arbitrary iova.
> + * Checking a given IOVA is dirty:
> + *
> + *  data[(iova / page_size) / 64] & (1ULL << (iova % 64))
> + */
> +struct iommufd_dirty_data {
> +	__aligned_u64 iova;
> +	__aligned_u64 length;
> +	__aligned_u64 page_size;
> +	__aligned_u64 *data;
> +};

Is there a reason to add this struct? Does something else use it?

> +/**
> + * struct iommu_hwpt_get_dirty_iova - ioctl(IOMMU_HWPT_GET_DIRTY_IOVA)
> + * @size: sizeof(struct iommu_hwpt_get_dirty_iova)
> + * @hwpt_id: HW pagetable ID that represents the IOMMU domain.
> + * @flags: Flags to control dirty tracking status.
> + * @bitmap: Bitmap of the range of IOVA to read out
> + */
> +struct iommu_hwpt_get_dirty_iova {
> +	__u32 size;
> +	__u32 hwpt_id;
> +	__u32 flags;
> +	__u32 __reserved;
> +	struct iommufd_dirty_data bitmap;

vs inlining here?

I see you are passing it around the internal API, but that could
easily pass the whole command too

Jason

  reply	other threads:[~2023-10-13 16:22 UTC|newest]

Thread overview: 140+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23  1:24 [PATCH v3 00/19] IOMMUFD Dirty Tracking Joao Martins
2023-09-23  1:24 ` [PATCH v3 01/19] vfio/iova_bitmap: Export more API symbols Joao Martins
2023-10-13 15:43   ` Jason Gunthorpe
2023-10-13 15:57     ` Joao Martins
2023-10-13 16:03       ` Jason Gunthorpe
2023-10-13 16:22         ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 02/19] vfio: Move iova_bitmap into iommu core Joao Martins
2023-10-13 15:48   ` Jason Gunthorpe
2023-10-13 16:00     ` Joao Martins
2023-10-13 16:04       ` Jason Gunthorpe
2023-10-13 16:23         ` Joao Martins
2023-10-13 17:10       ` Joao Martins
2023-10-13 17:16         ` Jason Gunthorpe
2023-10-13 17:23           ` Joao Martins
2023-10-13 17:28             ` Jason Gunthorpe
2023-10-13 17:32               ` Joao Martins
2023-10-13 20:41             ` Alex Williamson
2023-10-13 21:20               ` Joao Martins
2023-10-13 21:51                 ` Alex Williamson
2023-10-14  0:02                   ` Jason Gunthorpe
2023-10-16 16:25                     ` Joao Martins
2023-10-16 16:34                       ` Jason Gunthorpe
2023-10-16 17:52                         ` Joao Martins
2023-10-16 18:05                           ` Jason Gunthorpe
2023-10-16 18:15                             ` Joao Martins
2023-10-16 18:20                               ` Jason Gunthorpe
2023-10-16 18:37                                 ` Joao Martins
2023-10-16 18:50                                   ` Joao Martins
2023-10-17 12:58                                     ` Jason Gunthorpe
2023-10-17 15:20                                       ` Joao Martins
2023-10-17 15:23                                         ` Jason Gunthorpe
2023-10-17 15:44                                           ` Joao Martins
2023-10-18 10:19                             ` Joao Martins
2023-10-18 12:03                               ` Jason Gunthorpe
2023-10-18 12:48                                 ` Joao Martins
2023-10-18 14:23                                   ` Jason Gunthorpe
2023-10-18 15:34                                     ` Joao Martins
2023-10-18 15:43                                       ` Jason Gunthorpe
2023-09-23  1:24 ` [PATCH v3 03/19] iommu: Add iommu_domain ops for dirty tracking Joao Martins
2023-10-13 16:05   ` Jason Gunthorpe
2023-10-13 16:27     ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 04/19] iommufd: Add a flag to enforce dirty tracking on attach Joao Martins
2023-10-13 15:52   ` Jason Gunthorpe
2023-10-13 16:14     ` Joao Martins
2023-10-13 16:16       ` Jason Gunthorpe
2023-10-13 16:29         ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 05/19] iommufd/selftest: Expand mock_domain with dev_flags Joao Martins
2023-10-13 16:02   ` Jason Gunthorpe
2023-10-13 16:21     ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 06/19] iommufd/selftest: Test IOMMU_HWPT_ALLOC_ENFORCE_DIRTY Joao Martins
2023-09-23  1:24 ` [PATCH v3 07/19] iommufd: Dirty tracking data support Joao Martins
2023-09-23  1:40   ` Joao Martins
2023-10-17 12:06     ` Joao Martins
2023-10-17 15:29       ` Jason Gunthorpe
2023-10-17 15:51         ` Joao Martins
2023-10-17 16:01           ` Jason Gunthorpe
2023-10-17 16:51             ` Joao Martins
2023-10-17 17:13               ` Jason Gunthorpe
2023-10-17 17:30                 ` Joao Martins
2023-10-17 18:14                   ` Joao Martins
2023-09-23  1:25 ` [PATCH v3 08/19] iommufd: Add IOMMU_HWPT_SET_DIRTY Joao Martins
2023-10-13 16:13   ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 09/19] iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY Joao Martins
2023-09-23  1:25 ` [PATCH v3 10/19] iommufd: Add IOMMU_HWPT_GET_DIRTY_IOVA Joao Martins
2023-10-13 16:22   ` Jason Gunthorpe [this message]
2023-10-13 16:58     ` Joao Martins
2023-10-13 17:03       ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 11/19] iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_IOVA Joao Martins
2023-09-23  1:25 ` [PATCH v3 12/19] iommufd: Add capabilities to IOMMU_GET_HW_INFO Joao Martins
2023-09-23  1:25 ` [PATCH v3 13/19] iommufd/selftest: Test out_capabilities in IOMMU_GET_HW_INFO Joao Martins
2023-09-23  1:25 ` [PATCH v3 14/19] iommufd: Add a flag to skip clearing of IOPTE dirty Joao Martins
2023-09-23  1:25 ` [PATCH v3 15/19] iommufd/selftest: Test IOMMU_GET_DIRTY_IOVA_NO_CLEAR flag Joao Martins
2023-09-23  1:25 ` [PATCH v3 16/19] iommu/amd: Add domain_alloc_user based domain allocation Joao Martins
2023-10-17  2:00   ` Suthikulpanit, Suravee
2023-10-17  9:07     ` Joao Martins
2023-10-17 13:10       ` Jason Gunthorpe
2023-10-17 14:14         ` Joao Martins
2023-10-17 14:37           ` Joao Martins
2023-10-17 15:32             ` Jason Gunthorpe
2023-10-18  8:29             ` Vasant Hegde
2023-09-23  1:25 ` [PATCH v3 17/19] iommu/amd: Access/Dirty bit support in IOPTEs Joao Martins
2023-10-04 17:01   ` Joao Martins
2023-10-17  8:18   ` Suthikulpanit, Suravee
2023-10-17  9:54     ` Joao Martins
2023-10-17 18:32       ` Joao Martins
2023-10-17 18:49         ` Jason Gunthorpe
2023-10-17 19:03           ` Joao Martins
2023-10-17 22:04             ` Joao Martins
2023-10-18 11:47               ` Suthikulpanit, Suravee
2023-10-18 20:40             ` Joao Martins
2023-10-18 11:46       ` Suthikulpanit, Suravee
2023-10-18 13:04       ` Suthikulpanit, Suravee
2023-10-18 13:17         ` Joao Martins
2023-10-18 13:31           ` Joao Martins
2023-10-18 15:50         ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 18/19] iommu/amd: Print access/dirty bits if supported Joao Martins
2023-10-17  3:48   ` Suthikulpanit, Suravee
2023-10-17  9:07     ` Joao Martins
2023-10-18  8:32   ` Vasant Hegde
2023-10-18  8:53     ` Joao Martins
2023-10-18  9:03       ` Vasant Hegde
2023-10-18  9:05         ` Joao Martins
2023-10-18 15:52         ` Jason Gunthorpe
2023-10-18 15:55           ` Joao Martins
2023-09-23  1:25 ` [PATCH v3 19/19] iommu/intel: Access/Dirty bit support for SL domains Joao Martins
2023-09-25  7:01   ` Baolu Lu
2023-09-25  9:08     ` Joao Martins
2023-10-16  2:26       ` Baolu Lu
2023-10-16  0:51   ` Baolu Lu
2023-10-16 10:42     ` Joao Martins
2023-10-16 12:41       ` Baolu Lu
2023-10-16  1:37   ` Baolu Lu
2023-10-16 10:57     ` Joao Martins
2023-10-16 11:42       ` Jason Gunthorpe
2023-10-16 12:58         ` Baolu Lu
2023-10-16 12:59           ` Jason Gunthorpe
2023-10-16 13:01             ` Baolu Lu
2023-10-17 10:51               ` Joao Martins
2023-10-17 12:41                 ` Baolu Lu
2023-10-17 14:16                   ` Joao Martins
2023-10-17 14:25                     ` Joao Martins
2023-10-18  2:06                       ` Baolu Lu
2023-10-16  2:07   ` Baolu Lu
2023-10-16 11:26     ` Joao Martins
2023-10-16 16:00       ` Joao Martins
2023-10-17  2:08         ` Baolu Lu
2023-10-17 11:22           ` Joao Martins
2023-10-17 12:49             ` Baolu Lu
2023-10-17 14:19               ` Joao Martins
2023-10-17 13:10             ` Jason Gunthorpe
2023-10-17 14:11               ` Joao Martins
2023-10-17 15:31                 ` Jason Gunthorpe
2023-10-17 15:54                   ` Joao Martins
2023-10-16  2:21   ` Baolu Lu
2023-10-16 11:39     ` Joao Martins
2023-10-16 13:06       ` Baolu Lu
2023-09-26  8:58 ` [PATCH v3 00/19] IOMMUFD Dirty Tracking Shameerali Kolothum Thodi
2023-10-13 16:29 ` Jason Gunthorpe
2023-10-13 18:11   ` Joao Martins
2023-10-14  7:53     ` Baolu Lu

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=20231013162217.GF3952@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joao.m.martins@oracle.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --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 \
    /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