From: Joao Martins <joao.m.martins@oracle.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: robin.murphy@arm.com, will@kernel.org, joro@8bytes.org,
jgg@nvidia.com, kevin.tian@intel.com, nicolinc@nvidia.com,
mshavit@google.com, eric.auger@redhat.com,
jiangkunkun@huawei.com, zhukeqian1@huawei.com,
linuxarm@huawei.com, iommu@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 5/5] iommu/arm-smmu-v3: Enforce dirty tracking in domain attach/alloc
Date: Thu, 14 Dec 2023 16:29:03 +0000 [thread overview]
Message-ID: <b2911a1a-9dc1-477c-b003-cb078563f08e@oracle.com> (raw)
In-Reply-To: <20231128094940.1344-6-shameerali.kolothum.thodi@huawei.com>
On 28/11/2023 09:49, Shameer Kolothum wrote:
> From: Joao Martins <joao.m.martins@oracle.com>
>
> SMMUv3 implements all requirements of revoking device
> attachment if smmu does not support dirty tracking.
>
> Finally handle the IOMMU_CAP_DIRTY in iommu_capable for
> IOMMUFD_DEVICE_GET_HW_INFO.
>
> 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 | 22 ++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 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 c5eabdc29ba5..2c100f2136bc 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -2244,6 +2244,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
> case IOMMU_CAP_NOEXEC:
> case IOMMU_CAP_DEFERRED_FLUSH:
> return true;
> + case IOMMU_CAP_DIRTY_TRACKING:
> + return arm_smmu_dbm_capable(master->smmu);
> default:
> return false;
> }
> @@ -2701,6 +2703,9 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
> master = dev_iommu_priv_get(dev);
> smmu = master->smmu;
>
> + if (domain->dirty_ops && !arm_smmu_dbm_capable(smmu))
> + return -EINVAL;
> +
> mutex_lock(&smmu_domain->init_mutex);
>
> if (!smmu_domain->smmu) {
> @@ -3077,7 +3082,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;
> struct arm_smmu_domain *smmu_domain;
> int ret;
>
> @@ -3090,6 +3097,10 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
> if (user_data)
> return ERR_PTR(-EINVAL);
>
> + if (enforce_dirty &&
> + !device_iommu_capable(dev, IOMMU_CAP_DIRTY_TRACKING))
> + return ERR_PTR(-EOPNOTSUPP);
> +
> smmu_domain = arm_smmu_domain_alloc();
> if (!smmu_domain)
> return ERR_PTR(-ENOMEM);
> @@ -3104,6 +3115,9 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
>
> smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED;
> smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops;
> + if (enforce_dirty)
> + smmu_domain->domain.dirty_ops = &arm_smmu_dirty_ops;
> +
> ret = arm_smmu_domain_finalise(smmu_domain, master->smmu);
> if (ret)
> goto err_free;
Perhaps it would be better to limit the blast radius of the always-on mode, to
just enable it in the context descriptor depending on passing the
HWPT_ALLOC_DIRTY_TRACKING flag instead of enabling for everybody.
Something like this in arm_smmu_domain_finalise():
if (arm_smmu_dbm_capable(smmu) && smmu_domain->domain.dirty_ops &&
smmu_domain->stage == ARM_SMMU_DOMAIN_S1)
pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_ARM_HD;
For bisectability perhaps the second patch of this series should be the last,
while bringing the implementation of arm_smmu_dbm_capable() to this patch.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2023-12-14 16:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 9:49 [PATCH 0/5] iommu/smmuv3: Add IOMMUFD dirty tracking support for SMMUv3 Shameer Kolothum
2023-11-28 9:49 ` [PATCH 1/5] iommu/arm-smmu-v3: Add feature detection for HTTU Shameer Kolothum
2023-11-29 19:49 ` Jason Gunthorpe
2023-11-28 9:49 ` [PATCH 2/5] iommu/arm-smmu-v3: Enable HTTU for stage1 with io-pgtable mapping Shameer Kolothum
2023-11-29 19:30 ` Jason Gunthorpe
2023-11-30 9:17 ` Shameerali Kolothum Thodi
2023-11-28 9:49 ` [PATCH 3/5] iommu/arm-smmu-v3: Add read_and_clear_dirty() support Shameer Kolothum
2023-11-29 19:35 ` Jason Gunthorpe
2023-11-30 9:05 ` Shameerali Kolothum Thodi
2023-11-28 9:49 ` [PATCH 4/5] iommu/arm-smmu-v3: Add set_dirty_tracking() support Shameer Kolothum
2023-11-29 19:42 ` Jason Gunthorpe
2023-11-30 8:56 ` Shameerali Kolothum Thodi
2023-11-30 12:54 ` Jason Gunthorpe
2023-11-30 14:04 ` Shameerali Kolothum Thodi
2023-12-14 16:23 ` Joao Martins
2023-11-28 9:49 ` [PATCH 5/5] iommu/arm-smmu-v3: Enforce dirty tracking in domain attach/alloc Shameer Kolothum
2023-11-29 19:48 ` Jason Gunthorpe
2023-11-30 9:01 ` Shameerali Kolothum Thodi
2023-12-14 16:29 ` Joao Martins [this message]
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=b2911a1a-9dc1-477c-b003-cb078563f08e@oracle.com \
--to=joao.m.martins@oracle.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jiangkunkun@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).