From: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
To: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
Cc: laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
brian.starkey-5wv7dgnIgG8@public.gmane.org
Subject: Re: [PATCH 3/5] iommu/arm-smmu: Invalidate TLBs properly
Date: Mon, 7 Dec 2015 13:34:36 +0000 [thread overview]
Message-ID: <20151207133435.GE23430@arm.com> (raw)
In-Reply-To: <5665850F.1060406-5wv7dgnIgG8@public.gmane.org>
On Mon, Dec 07, 2015 at 01:09:35PM +0000, Robin Murphy wrote:
> On 07/12/15 11:09, Will Deacon wrote:
> >On Fri, Dec 04, 2015 at 05:53:00PM +0000, Robin Murphy wrote:
> >>When invalidating an IOVA range potentially spanning multiple pages,
> >>such as when removing an entire intermediate-level table, we currently
> >>only issue an invalidation for the first IOVA of that range. Since the
> >>architecture specifies that address-based TLB maintenance operations
> >>target a single entry, an SMMU could feasibly retain live entries for
> >>subsequent pages within that unmapped range, which is not good.
> >>
> >>Make sure we hit every possible entry by iterating over the whole range
> >>at the granularity provided by the pagetable implementation.
> >>
> >>Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> >>---
> >> drivers/iommu/arm-smmu.c | 19 ++++++++++++++++---
> >> 1 file changed, 16 insertions(+), 3 deletions(-)
> >
> >Can you do something similar for arm-smmu-v3.c as well, please?
>
> Something like this? (untested as I don't have a v3 model set up):
>
> ------>8------
> From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> Date: Mon, 7 Dec 2015 12:52:56 +0000
> Subject: [PATCH] iommu/arm-smmu: Fix TLB invalidation
>
> SMMUv3 operates under the same rules as SMMUv2 and the CPU
> architectures, so when invalidating an IOVA range we have to hit
> every address for which a TLB entry might exist.
>
> To fix this, issue commands for the whole range rather than just the
> initial address; as a minor optimisation, try to avoid flooding the
> queue by falling back to 'invalidate all' if the range is large.
>
> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> ---
> drivers/iommu/arm-smmu-v3.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index c302b65..afa0b41 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -1346,6 +1346,10 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned
> long iova, size_t size,
> },
> };
>
> + /* If we'd fill the whole queue or more, don't even bother... */
> + if (granule << smmu->cmdq.q.max_n_shift >= size / (CMDQ_ENT_DWORDS << 3))
> + return arm_smmu_tlb_inv_context(cookie);
Let's not bother with this heuristic for now. It's not at all clear where
the trade off is between CPU time and I/O latency and this check doesn't
take into account the current state of the command queue and/or how quickly
it drains anyway.
> if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
> cmd.opcode = CMDQ_OP_TLBI_NH_VA;
> cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid;
> @@ -1354,7 +1358,10 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned
> long iova, size_t size,
> cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
> }
>
> - arm_smmu_cmdq_issue_cmd(smmu, &cmd);
> + do {
> + arm_smmu_cmdq_issue_cmd(smmu, &cmd);
> + cmd.tlbi.addr += granule;
> + } while (size -= granule);
This bit looks fine to me, thanks.
Will
WARNING: multiple messages have this Message-ID (diff)
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] iommu/arm-smmu: Invalidate TLBs properly
Date: Mon, 7 Dec 2015 13:34:36 +0000 [thread overview]
Message-ID: <20151207133435.GE23430@arm.com> (raw)
In-Reply-To: <5665850F.1060406@arm.com>
On Mon, Dec 07, 2015 at 01:09:35PM +0000, Robin Murphy wrote:
> On 07/12/15 11:09, Will Deacon wrote:
> >On Fri, Dec 04, 2015 at 05:53:00PM +0000, Robin Murphy wrote:
> >>When invalidating an IOVA range potentially spanning multiple pages,
> >>such as when removing an entire intermediate-level table, we currently
> >>only issue an invalidation for the first IOVA of that range. Since the
> >>architecture specifies that address-based TLB maintenance operations
> >>target a single entry, an SMMU could feasibly retain live entries for
> >>subsequent pages within that unmapped range, which is not good.
> >>
> >>Make sure we hit every possible entry by iterating over the whole range
> >>at the granularity provided by the pagetable implementation.
> >>
> >>Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> >>---
> >> drivers/iommu/arm-smmu.c | 19 ++++++++++++++++---
> >> 1 file changed, 16 insertions(+), 3 deletions(-)
> >
> >Can you do something similar for arm-smmu-v3.c as well, please?
>
> Something like this? (untested as I don't have a v3 model set up):
>
> ------>8------
> From: Robin Murphy <robin.murphy@arm.com>
> Date: Mon, 7 Dec 2015 12:52:56 +0000
> Subject: [PATCH] iommu/arm-smmu: Fix TLB invalidation
>
> SMMUv3 operates under the same rules as SMMUv2 and the CPU
> architectures, so when invalidating an IOVA range we have to hit
> every address for which a TLB entry might exist.
>
> To fix this, issue commands for the whole range rather than just the
> initial address; as a minor optimisation, try to avoid flooding the
> queue by falling back to 'invalidate all' if the range is large.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
> drivers/iommu/arm-smmu-v3.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index c302b65..afa0b41 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -1346,6 +1346,10 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned
> long iova, size_t size,
> },
> };
>
> + /* If we'd fill the whole queue or more, don't even bother... */
> + if (granule << smmu->cmdq.q.max_n_shift >= size / (CMDQ_ENT_DWORDS << 3))
> + return arm_smmu_tlb_inv_context(cookie);
Let's not bother with this heuristic for now. It's not at all clear where
the trade off is between CPU time and I/O latency and this check doesn't
take into account the current state of the command queue and/or how quickly
it drains anyway.
> if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
> cmd.opcode = CMDQ_OP_TLBI_NH_VA;
> cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid;
> @@ -1354,7 +1358,10 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned
> long iova, size_t size,
> cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
> }
>
> - arm_smmu_cmdq_issue_cmd(smmu, &cmd);
> + do {
> + arm_smmu_cmdq_issue_cmd(smmu, &cmd);
> + cmd.tlbi.addr += granule;
> + } while (size -= granule);
This bit looks fine to me, thanks.
Will
next prev parent reply other threads:[~2015-12-07 13:34 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-04 17:52 [PATCH 0/5] io-pgtable fixes + ARM short-descriptor format Robin Murphy
2015-12-04 17:52 ` Robin Murphy
[not found] ` <cover.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-04 17:52 ` [PATCH 1/5] iommu/io-pgtable-arm: Avoid dereferencing bogus PTEs Robin Murphy
2015-12-04 17:52 ` Robin Murphy
[not found] ` <ad5898fd59575d0e2a8dccabafde71650f44e2a8.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-13 21:41 ` Laurent Pinchart
2015-12-13 21:41 ` Laurent Pinchart
2015-12-14 15:33 ` Robin Murphy
2015-12-14 15:33 ` Robin Murphy
2015-12-04 17:52 ` [PATCH 2/5] iommu/io-pgtable: Indicate granule for TLB maintenance Robin Murphy
2015-12-04 17:52 ` Robin Murphy
[not found] ` <67223d4b1ff57f3f46e8c3102e663a063a50a7f7.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-07 11:08 ` Will Deacon
2015-12-07 11:08 ` Will Deacon
[not found] ` <20151207110804.GA23430-5wv7dgnIgG8@public.gmane.org>
2015-12-07 12:09 ` Robin Murphy
2015-12-07 12:09 ` Robin Murphy
[not found] ` <56657714.50504-5wv7dgnIgG8@public.gmane.org>
2015-12-07 13:48 ` Will Deacon
2015-12-07 13:48 ` Will Deacon
2015-12-07 18:18 ` [PATCH v2] " Robin Murphy
2015-12-07 18:18 ` Robin Murphy
2015-12-04 17:53 ` [PATCH 3/5] iommu/arm-smmu: Invalidate TLBs properly Robin Murphy
2015-12-04 17:53 ` Robin Murphy
[not found] ` <2acaea8656f14a4421d7d466dd242fe5a3d0f6f6.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-07 11:09 ` Will Deacon
2015-12-07 11:09 ` Will Deacon
[not found] ` <20151207110939.GB23430-5wv7dgnIgG8@public.gmane.org>
2015-12-07 13:09 ` Robin Murphy
2015-12-07 13:09 ` Robin Murphy
[not found] ` <5665850F.1060406-5wv7dgnIgG8@public.gmane.org>
2015-12-07 13:34 ` Will Deacon [this message]
2015-12-07 13:34 ` Will Deacon
2015-12-07 18:18 ` [PATCH v2] " Robin Murphy
2015-12-07 18:18 ` Robin Murphy
[not found] ` <ac2d6aedf473cf01eb1df48a1f81614f0f74b0b1.1449501523.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-07 18:28 ` Will Deacon
2015-12-07 18:28 ` Will Deacon
2015-12-04 17:53 ` [PATCH 4/5] iommu/io-pgtable: Make io_pgtable_ops_to_pgtable() macro common Robin Murphy
2015-12-04 17:53 ` Robin Murphy
[not found] ` <ef5954ba727840a020b62b0135a1ce9f4a10fb2c.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-13 21:52 ` Laurent Pinchart
2015-12-13 21:52 ` Laurent Pinchart
2015-12-04 17:53 ` [PATCH 5/5] iommu/io-pgtable: Add ARMv7 short descriptor support Robin Murphy
2015-12-04 17:53 ` Robin Murphy
[not found] ` <3c72de1e8caa28cbfd423de41c6cba812db4e7db.1449246988.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-12-08 8:58 ` Yong Wu
2015-12-08 8:58 ` Yong Wu
2015-12-17 20:12 ` Robin Murphy
2015-12-17 20:12 ` Robin Murphy
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=20151207133435.GE23430@arm.com \
--to=will.deacon-5wv7dgnigg8@public.gmane.org \
--cc=brian.starkey-5wv7dgnIgG8@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=robin.murphy-5wv7dgnIgG8@public.gmane.org \
/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.