From: Jason Gunthorpe <jgg@nvidia.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
joro@8bytes.org, kevin.tian@intel.com, nicolinc@nvidia.com,
mshavit@google.com, robin.murphy@arm.com, will@kernel.org,
joao.m.martins@oracle.com, jiangkunkun@huawei.com,
zhukeqian1@huawei.com, linuxarm@huawei.com
Subject: Re: [PATCH v2 3/4] iommu/arm-smmu-v3: Add support for dirty tracking in domain alloc
Date: Fri, 8 Mar 2024 10:31:24 -0400 [thread overview]
Message-ID: <20240308143124.GO9179@nvidia.com> (raw)
In-Reply-To: <20240222094923.33104-4-shameerali.kolothum.thodi@huawei.com>
On Thu, Feb 22, 2024 at 09:49:22AM +0000, Shameer Kolothum wrote:
> From: Joao Martins <joao.m.martins@oracle.com>
>
> This provides all the infrastructure to enable dirty tracking if the
> hardware has the capability and domain alloc request for it.
>
> Please note, we still report no support for IOMMU_CAP_DIRTY_TRACKING
> as it will finally be enabled in a subsequent patch.
>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 95 ++++++++++++++++-----
> include/linux/io-pgtable.h | 4 +
> 2 files changed, 77 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index bd30739e3588..058bbb0dbe2e 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -43,6 +43,7 @@ MODULE_PARM_DESC(disable_msipolling,
> "Disable MSI-based polling for CMD_SYNC completion.");
>
> static struct iommu_ops arm_smmu_ops;
> +static struct iommu_dirty_ops arm_smmu_dirty_ops;
>
> enum arm_smmu_msi_index {
> EVTQ_MSI_INDEX,
> @@ -86,7 +87,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = {
>
> static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu);
> static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
> - struct arm_smmu_device *smmu);
> + struct arm_smmu_device *smmu,
> + bool enable_dirty);
> static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master);
> static void arm_smmu_tlb_inv_all_s2(struct arm_smmu_domain *smmu_domain);
>
> @@ -2378,7 +2380,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
> struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> int ret;
>
> - ret = arm_smmu_domain_finalise(smmu_domain, master->smmu);
> + ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, false);
> if (ret) {
> kfree(smmu_domain);
> return ERR_PTR(ret);
> @@ -2445,10 +2447,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
> }
>
> static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
> - struct arm_smmu_device *smmu)
> + struct arm_smmu_device *smmu,
> + bool enable_dirty)
It is possibly a bit more readable if this is a flags and the test is
on IOMMU_HWPT_ALLOC_DIRTY_TRACKING
> {
> int ret;
> - unsigned long ias, oas;
> + unsigned long ias;
Isn't ias unused too?
> @@ -3193,7 +3197,9 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
> const struct iommu_user_data *user_data)
> {
> struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> - const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT;
> + const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT |
> + IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
> + bool enforce_dirty = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
Ah you based this on the nesting series.. Once part 2 is done we
should try to figure out what the order should be..
> +static int arm_smmu_read_and_clear_dirty(struct iommu_domain *domain,
> + unsigned long iova, size_t size,
> + unsigned long flags,
> + struct iommu_dirty_bitmap *dirty)
> +{
> + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> + struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
> +
> + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
> + return -EINVAL;
This is not possible, these ops are only installed on S1 domains.
> + if (WARN_ON_ONCE(!ops || !ops->read_and_clear_dirty))
> + return -ENODEV;
This is not really needed, if this is corrupted then this will have a
tidy crash:
> + return ops->read_and_clear_dirty(ops, iova, size, flags, dirty);
If you are worried then move the WARN_ON into the finalize function to
ensure tha tthe io_pgtable_ops is properly formed after creating it.
> +static int arm_smmu_set_dirty_tracking(struct iommu_domain *domain,
> + bool enabled)
> +{
> + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> + struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
> +
> + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
> + return -EINVAL;
> + if (WARN_ON_ONCE(!ops))
> + return -ENODEV;
Ditto for both of these
Otherwise it looks OK to me
Jason
WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
joro@8bytes.org, kevin.tian@intel.com, nicolinc@nvidia.com,
mshavit@google.com, robin.murphy@arm.com, will@kernel.org,
joao.m.martins@oracle.com, jiangkunkun@huawei.com,
zhukeqian1@huawei.com, linuxarm@huawei.com
Subject: Re: [PATCH v2 3/4] iommu/arm-smmu-v3: Add support for dirty tracking in domain alloc
Date: Fri, 8 Mar 2024 10:31:24 -0400 [thread overview]
Message-ID: <20240308143124.GO9179@nvidia.com> (raw)
In-Reply-To: <20240222094923.33104-4-shameerali.kolothum.thodi@huawei.com>
On Thu, Feb 22, 2024 at 09:49:22AM +0000, Shameer Kolothum wrote:
> From: Joao Martins <joao.m.martins@oracle.com>
>
> This provides all the infrastructure to enable dirty tracking if the
> hardware has the capability and domain alloc request for it.
>
> Please note, we still report no support for IOMMU_CAP_DIRTY_TRACKING
> as it will finally be enabled in a subsequent patch.
>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 95 ++++++++++++++++-----
> include/linux/io-pgtable.h | 4 +
> 2 files changed, 77 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index bd30739e3588..058bbb0dbe2e 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -43,6 +43,7 @@ MODULE_PARM_DESC(disable_msipolling,
> "Disable MSI-based polling for CMD_SYNC completion.");
>
> static struct iommu_ops arm_smmu_ops;
> +static struct iommu_dirty_ops arm_smmu_dirty_ops;
>
> enum arm_smmu_msi_index {
> EVTQ_MSI_INDEX,
> @@ -86,7 +87,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = {
>
> static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu);
> static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
> - struct arm_smmu_device *smmu);
> + struct arm_smmu_device *smmu,
> + bool enable_dirty);
> static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master);
> static void arm_smmu_tlb_inv_all_s2(struct arm_smmu_domain *smmu_domain);
>
> @@ -2378,7 +2380,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
> struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> int ret;
>
> - ret = arm_smmu_domain_finalise(smmu_domain, master->smmu);
> + ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, false);
> if (ret) {
> kfree(smmu_domain);
> return ERR_PTR(ret);
> @@ -2445,10 +2447,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
> }
>
> static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
> - struct arm_smmu_device *smmu)
> + struct arm_smmu_device *smmu,
> + bool enable_dirty)
It is possibly a bit more readable if this is a flags and the test is
on IOMMU_HWPT_ALLOC_DIRTY_TRACKING
> {
> int ret;
> - unsigned long ias, oas;
> + unsigned long ias;
Isn't ias unused too?
> @@ -3193,7 +3197,9 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
> const struct iommu_user_data *user_data)
> {
> struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> - const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT;
> + const u32 paging_flags = IOMMU_HWPT_ALLOC_NEST_PARENT |
> + IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
> + bool enforce_dirty = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
Ah you based this on the nesting series.. Once part 2 is done we
should try to figure out what the order should be..
> +static int arm_smmu_read_and_clear_dirty(struct iommu_domain *domain,
> + unsigned long iova, size_t size,
> + unsigned long flags,
> + struct iommu_dirty_bitmap *dirty)
> +{
> + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> + struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
> +
> + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
> + return -EINVAL;
This is not possible, these ops are only installed on S1 domains.
> + if (WARN_ON_ONCE(!ops || !ops->read_and_clear_dirty))
> + return -ENODEV;
This is not really needed, if this is corrupted then this will have a
tidy crash:
> + return ops->read_and_clear_dirty(ops, iova, size, flags, dirty);
If you are worried then move the WARN_ON into the finalize function to
ensure tha tthe io_pgtable_ops is properly formed after creating it.
> +static int arm_smmu_set_dirty_tracking(struct iommu_domain *domain,
> + bool enabled)
> +{
> + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> + struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
> +
> + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1)
> + return -EINVAL;
> + if (WARN_ON_ONCE(!ops))
> + return -ENODEV;
Ditto for both of these
Otherwise it looks OK to me
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-03-08 14:31 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 9:49 [PATCH v2 0/4] iommu/smmuv3: Add IOMMUFD dirty tracking support for SMMUv3 Shameer Kolothum
2024-02-22 9:49 ` Shameer Kolothum
2024-02-22 9:49 ` [PATCH v2 1/4] iommu/arm-smmu-v3: Add feature detection for HTTU Shameer Kolothum
2024-02-22 9:49 ` Shameer Kolothum
2024-04-23 14:41 ` Ryan Roberts
2024-04-23 14:41 ` Ryan Roberts
2024-04-23 14:52 ` Jason Gunthorpe
2024-04-23 14:52 ` Jason Gunthorpe
2024-04-24 10:04 ` Ryan Roberts
2024-04-24 10:04 ` Ryan Roberts
2024-04-24 12:23 ` Jason Gunthorpe
2024-04-24 12:23 ` Jason Gunthorpe
2024-04-24 12:59 ` Ryan Roberts
2024-04-24 12:59 ` Ryan Roberts
2024-04-24 13:20 ` Shameerali Kolothum Thodi
2024-04-24 13:20 ` Shameerali Kolothum Thodi
2024-04-24 13:32 ` Jason Gunthorpe
2024-04-24 13:32 ` Jason Gunthorpe
2024-04-24 13:43 ` Shameerali Kolothum Thodi
2024-04-24 13:43 ` Shameerali Kolothum Thodi
2024-04-24 14:21 ` Jason Gunthorpe
2024-04-24 14:21 ` Jason Gunthorpe
2024-04-24 8:01 ` Shameerali Kolothum Thodi
2024-04-24 8:01 ` Shameerali Kolothum Thodi
2024-04-24 8:28 ` Ryan Roberts
2024-04-24 8:28 ` Ryan Roberts
2024-02-22 9:49 ` [PATCH v2 2/4] iommu/io-pgtable-arm: Add read_and_clear_dirty() support Shameer Kolothum
2024-02-22 9:49 ` Shameer Kolothum
2024-04-23 15:56 ` Ryan Roberts
2024-04-23 15:56 ` Ryan Roberts
2024-04-24 8:01 ` Shameerali Kolothum Thodi
2024-04-24 8:01 ` Shameerali Kolothum Thodi
2024-04-24 8:36 ` Ryan Roberts
2024-04-24 8:36 ` Ryan Roberts
2024-02-22 9:49 ` [PATCH v2 3/4] iommu/arm-smmu-v3: Add support for dirty tracking in domain alloc Shameer Kolothum
2024-02-22 9:49 ` Shameer Kolothum
2024-02-22 11:04 ` Joao Martins
2024-02-22 11:04 ` Joao Martins
2024-02-22 11:31 ` Shameerali Kolothum Thodi
2024-02-22 11:31 ` Shameerali Kolothum Thodi
2024-02-22 11:37 ` Joao Martins
2024-02-22 11:37 ` Joao Martins
2024-02-22 12:24 ` Shameerali Kolothum Thodi
2024-02-22 12:24 ` Shameerali Kolothum Thodi
2024-02-22 13:11 ` Jason Gunthorpe
2024-02-22 13:11 ` Jason Gunthorpe
2024-02-22 13:23 ` Joao Martins
2024-02-22 13:23 ` Joao Martins
2024-03-08 14:31 ` Jason Gunthorpe [this message]
2024-03-08 14:31 ` Jason Gunthorpe
2024-04-23 16:27 ` Ryan Roberts
2024-04-23 16:27 ` Ryan Roberts
2024-04-23 16:39 ` Jason Gunthorpe
2024-04-23 16:39 ` Jason Gunthorpe
2024-04-23 16:50 ` Ryan Roberts
2024-04-23 16:50 ` Ryan Roberts
2024-04-24 8:27 ` Shameerali Kolothum Thodi
2024-04-24 8:27 ` Shameerali Kolothum Thodi
2024-02-22 9:49 ` [PATCH v2 4/4] iommu/arm-smmu-v3: Enable HTTU for stage1 with io-pgtable mapping Shameer Kolothum
2024-02-22 9:49 ` Shameer Kolothum
2024-03-08 14:32 ` Jason Gunthorpe
2024-03-08 14:32 ` Jason Gunthorpe
2024-04-23 16:45 ` Ryan Roberts
2024-04-23 16:45 ` Ryan Roberts
2024-04-23 17:32 ` Jason Gunthorpe
2024-04-23 17:32 ` Jason Gunthorpe
2024-04-24 7:58 ` Ryan Roberts
2024-04-24 7:58 ` Ryan Roberts
2024-04-24 12:15 ` Jason Gunthorpe
2024-04-24 12:15 ` Jason Gunthorpe
2024-04-24 12:45 ` Ryan Roberts
2024-04-24 12:45 ` Ryan Roberts
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=20240308143124.GO9179@nvidia.com \
--to=jgg@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jiangkunkun@huawei.com \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linuxarm@huawei.com \
--cc=mshavit@google.com \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=will@kernel.org \
--cc=zhukeqian1@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.