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,
robin.murphy@arm.com, will@kernel.org, joro@8bytes.org,
ryan.roberts@arm.com, kevin.tian@intel.com, nicolinc@nvidia.com,
mshavit@google.com, eric.auger@redhat.com,
joao.m.martins@oracle.com, jiangkunkun@huawei.com,
zhukeqian1@huawei.com, linuxarm@huawei.com
Subject: Re: [PATCH v3 2/4] iommu/io-pgtable-arm: Add read_and_clear_dirty() support
Date: Sun, 12 May 2024 09:51:15 -0300 [thread overview]
Message-ID: <ZkC7Q5bynT+WAO3t@nvidia.com> (raw)
In-Reply-To: <20240430134308.1604-3-shameerali.kolothum.thodi@huawei.com>
On Tue, Apr 30, 2024 at 02:43:06PM +0100, Shameer Kolothum wrote:
> +static int io_pgtable_visit_dirty(struct arm_lpae_io_pgtable *data,
> + struct io_pgtable_walk_data *walk_data,
> + arm_lpae_iopte *ptep, int lvl)
> +{
> + struct io_pgtable *iop = &data->iop;
> + arm_lpae_iopte pte = READ_ONCE(*ptep);
> +
> + if (WARN_ON(!pte))
> + return -EINVAL;
This seems poorly placed, why would pte ever be zero?
> + if (iopte_leaf(pte, lvl, iop->fmt)) {
> + size_t size = ARM_LPAE_BLOCK_SIZE(lvl, data);
> +
> + if (iopte_hw_dirty(pte)) {
> + iommu_dirty_bitmap_record(walk_data->dirty,
> + walk_data->addr, size);
> + if (!(walk_data->flags & IOMMU_DIRTY_NO_CLEAR))
> + set_bit(ARM_LPAE_PTE_AP_RDONLY_BIT,
> + (unsigned long *)ptep);
> + }
> + walk_data->addr += size;
> + return 0;
> + }
> +
> + ptep = iopte_deref(pte, data);
This would be a better spot, if the pte doesn't indicate a next level
table then something has gone wrong, otherwise the returned pointer
has to be valid.
Something like this maybe?
static inline bool iopte_table(arm_lpae_iopte pte, int lvl,
enum io_pgtable_fmt fmt)
{
if (lvl == (ARM_LPAE_MAX_LEVELS - 1))
return false;
return iopte_type(pte) == ARM_LPAE_PTE_TYPE_TABLE;
}
> + return __arm_lpae_iopte_walk_dirty(data, walk_data, ptep, lvl + 1);
> +}
> +
> +static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data,
> + struct io_pgtable_walk_data *walk_data,
> + arm_lpae_iopte *ptep,
> + int lvl)
> +{
> + u32 idx;
> + int max_entries, ret;
> +
> + if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS))
> + return -EINVAL;
And if the above ipte_deref() could check for a valid next level (with
no valid level at MAX_LEVELS) then this can never happen either and
can be removed.
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,
robin.murphy@arm.com, will@kernel.org, joro@8bytes.org,
ryan.roberts@arm.com, kevin.tian@intel.com, nicolinc@nvidia.com,
mshavit@google.com, eric.auger@redhat.com,
joao.m.martins@oracle.com, jiangkunkun@huawei.com,
zhukeqian1@huawei.com, linuxarm@huawei.com
Subject: Re: [PATCH v3 2/4] iommu/io-pgtable-arm: Add read_and_clear_dirty() support
Date: Sun, 12 May 2024 09:51:15 -0300 [thread overview]
Message-ID: <ZkC7Q5bynT+WAO3t@nvidia.com> (raw)
In-Reply-To: <20240430134308.1604-3-shameerali.kolothum.thodi@huawei.com>
On Tue, Apr 30, 2024 at 02:43:06PM +0100, Shameer Kolothum wrote:
> +static int io_pgtable_visit_dirty(struct arm_lpae_io_pgtable *data,
> + struct io_pgtable_walk_data *walk_data,
> + arm_lpae_iopte *ptep, int lvl)
> +{
> + struct io_pgtable *iop = &data->iop;
> + arm_lpae_iopte pte = READ_ONCE(*ptep);
> +
> + if (WARN_ON(!pte))
> + return -EINVAL;
This seems poorly placed, why would pte ever be zero?
> + if (iopte_leaf(pte, lvl, iop->fmt)) {
> + size_t size = ARM_LPAE_BLOCK_SIZE(lvl, data);
> +
> + if (iopte_hw_dirty(pte)) {
> + iommu_dirty_bitmap_record(walk_data->dirty,
> + walk_data->addr, size);
> + if (!(walk_data->flags & IOMMU_DIRTY_NO_CLEAR))
> + set_bit(ARM_LPAE_PTE_AP_RDONLY_BIT,
> + (unsigned long *)ptep);
> + }
> + walk_data->addr += size;
> + return 0;
> + }
> +
> + ptep = iopte_deref(pte, data);
This would be a better spot, if the pte doesn't indicate a next level
table then something has gone wrong, otherwise the returned pointer
has to be valid.
Something like this maybe?
static inline bool iopte_table(arm_lpae_iopte pte, int lvl,
enum io_pgtable_fmt fmt)
{
if (lvl == (ARM_LPAE_MAX_LEVELS - 1))
return false;
return iopte_type(pte) == ARM_LPAE_PTE_TYPE_TABLE;
}
> + return __arm_lpae_iopte_walk_dirty(data, walk_data, ptep, lvl + 1);
> +}
> +
> +static int __arm_lpae_iopte_walk_dirty(struct arm_lpae_io_pgtable *data,
> + struct io_pgtable_walk_data *walk_data,
> + arm_lpae_iopte *ptep,
> + int lvl)
> +{
> + u32 idx;
> + int max_entries, ret;
> +
> + if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS))
> + return -EINVAL;
And if the above ipte_deref() could check for a valid next level (with
no valid level at MAX_LEVELS) then this can never happen either and
can be removed.
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-05-12 12:51 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 13:43 [PATCH v3 0/4] iommu/smmuv3: Add IOMMUFD dirty tracking support for SMMUv3 Shameer Kolothum
2024-04-30 13:43 ` Shameer Kolothum
2024-04-30 13:43 ` [PATCH v3 1/4] iommu/arm-smmu-v3: Add feature detection for HTTU Shameer Kolothum
2024-04-30 13:43 ` Shameer Kolothum
2024-05-22 7:02 ` Tian, Kevin
2024-05-22 7:02 ` Tian, Kevin
2024-04-30 13:43 ` [PATCH v3 2/4] iommu/io-pgtable-arm: Add read_and_clear_dirty() support Shameer Kolothum
2024-04-30 13:43 ` Shameer Kolothum
2024-04-30 14:51 ` Ryan Roberts
2024-04-30 14:51 ` Ryan Roberts
2024-05-12 12:51 ` Jason Gunthorpe [this message]
2024-05-12 12:51 ` Jason Gunthorpe
2024-05-22 7:12 ` Tian, Kevin
2024-05-22 7:12 ` Tian, Kevin
2024-05-22 12:37 ` Jason Gunthorpe
2024-05-22 12:37 ` Jason Gunthorpe
2024-05-22 14:03 ` Shameerali Kolothum Thodi
2024-05-22 14:03 ` Shameerali Kolothum Thodi
2024-05-22 14:37 ` Joao Martins
2024-05-22 14:37 ` Joao Martins
2024-05-22 16:56 ` Jason Gunthorpe
2024-05-22 16:56 ` Jason Gunthorpe
2024-05-22 17:10 ` Joao Martins
2024-05-22 17:10 ` Joao Martins
2024-05-22 17:50 ` Jason Gunthorpe
2024-05-22 17:50 ` Jason Gunthorpe
2024-05-22 18:15 ` Joao Martins
2024-05-22 18:15 ` Joao Martins
2024-05-22 18:39 ` Joao Martins
2024-05-22 18:39 ` Joao Martins
2024-05-23 3:30 ` Tian, Kevin
2024-05-23 3:30 ` Tian, Kevin
2024-05-24 11:30 ` Joao Martins
2024-05-24 11:30 ` Joao Martins
2024-05-24 14:07 ` Jason Gunthorpe
2024-05-24 14:07 ` Jason Gunthorpe
2024-05-27 1:21 ` Tian, Kevin
2024-05-27 1:21 ` Tian, Kevin
2024-05-27 9:50 ` Joao Martins
2024-05-27 9:50 ` Joao Martins
2024-06-01 18:55 ` Jason Gunthorpe
2024-06-01 18:55 ` Jason Gunthorpe
2024-06-03 18:50 ` Joao Martins
2024-06-03 18:50 ` Joao Martins
2024-04-30 13:43 ` [PATCH v3 3/4] iommu/arm-smmu-v3: Add support for dirty tracking in domain alloc Shameer Kolothum
2024-04-30 13:43 ` Shameer Kolothum
2024-04-30 15:05 ` Ryan Roberts
2024-04-30 15:05 ` Ryan Roberts
2024-05-12 12:57 ` Jason Gunthorpe
2024-05-12 12:57 ` Jason Gunthorpe
2024-05-22 7:16 ` Tian, Kevin
2024-05-22 7:16 ` Tian, Kevin
2024-05-22 12:38 ` Jason Gunthorpe
2024-05-22 12:38 ` Jason Gunthorpe
2024-05-22 14:30 ` Shameerali Kolothum Thodi
2024-05-22 14:30 ` Shameerali Kolothum Thodi
2024-05-22 23:49 ` Tian, Kevin
2024-05-22 23:49 ` Tian, Kevin
2024-04-30 13:43 ` [PATCH v3 4/4] iommu/arm-smmu-v3: Enable HTTU for stage1 with io-pgtable mapping Shameer Kolothum
2024-04-30 13:43 ` Shameer Kolothum
2024-05-12 12:08 ` Jason Gunthorpe
2024-05-12 12:08 ` Jason Gunthorpe
2024-05-22 7:19 ` Tian, Kevin
2024-05-22 7:19 ` Tian, Kevin
2024-05-22 12:39 ` Jason Gunthorpe
2024-05-22 12:39 ` Jason Gunthorpe
2024-05-22 23:52 ` Tian, Kevin
2024-05-22 23:52 ` Tian, Kevin
2024-05-22 13:26 ` Shameerali Kolothum Thodi
2024-05-22 13:26 ` Shameerali Kolothum Thodi
2024-05-22 13:41 ` Jason Gunthorpe
2024-05-22 13:41 ` Jason Gunthorpe
2024-05-12 12:58 ` [PATCH v3 0/4] iommu/smmuv3: Add IOMMUFD dirty tracking support for SMMUv3 Jason Gunthorpe
2024-05-12 12:58 ` Jason Gunthorpe
2024-05-22 13:28 ` Shameerali Kolothum Thodi
2024-05-22 13:28 ` Shameerali Kolothum Thodi
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=ZkC7Q5bynT+WAO3t@nvidia.com \
--to=jgg@nvidia.com \
--cc=eric.auger@redhat.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=ryan.roberts@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.