From: Christoffer Dall <cdall@linaro.org>
To: Marc Zyngier <marc.zyngier@arm.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH 03/10] arm: KVM: Add optimized PIPT icache flushing
Date: Mon, 16 Oct 2017 22:07:52 +0200 [thread overview]
Message-ID: <20171016200752.GF1845@lvm> (raw)
In-Reply-To: <20171009152032.27804-4-marc.zyngier@arm.com>
On Mon, Oct 09, 2017 at 04:20:25PM +0100, Marc Zyngier wrote:
> Calling __cpuc_coherent_user_range to invalidate the icache on
> a PIPT icache machine has some pointless overhead, as it starts
> by cleaning the dcache to the PoU, while we're guaranteed to
> have already cleaned it to the PoC.
>
> As KVM is the only user of such a feature, let's implement some
> ad-hoc cache flushing in kvm_mmu.h. Should it become useful to
> other subsystems, it can be moved to a more global location.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> arch/arm/include/asm/kvm_hyp.h | 2 ++
> arch/arm/include/asm/kvm_mmu.h | 24 ++++++++++++++++++++++--
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/include/asm/kvm_hyp.h b/arch/arm/include/asm/kvm_hyp.h
> index 14b5903f0224..ad541f9ecc78 100644
> --- a/arch/arm/include/asm/kvm_hyp.h
> +++ b/arch/arm/include/asm/kvm_hyp.h
> @@ -69,6 +69,8 @@
> #define HIFAR __ACCESS_CP15(c6, 4, c0, 2)
> #define HPFAR __ACCESS_CP15(c6, 4, c0, 4)
> #define ICIALLUIS __ACCESS_CP15(c7, 0, c1, 0)
> +#define BPIALLIS __ACCESS_CP15(c7, 0, c1, 6)
> +#define ICIMVAU __ACCESS_CP15(c7, 0, c5, 1)
> #define ATS1CPR __ACCESS_CP15(c7, 0, c8, 0)
> #define TLBIALLIS __ACCESS_CP15(c8, 0, c3, 0)
> #define TLBIALL __ACCESS_CP15(c8, 0, c7, 0)
> diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
> index f553aa62d0c3..6773dcf21bff 100644
> --- a/arch/arm/include/asm/kvm_mmu.h
> +++ b/arch/arm/include/asm/kvm_mmu.h
> @@ -37,6 +37,8 @@
>
> #include <linux/highmem.h>
> #include <asm/cacheflush.h>
> +#include <asm/cputype.h>
> +#include <asm/kvm_hyp.h>
> #include <asm/pgalloc.h>
> #include <asm/stage2_pgtable.h>
>
> @@ -157,6 +159,8 @@ static inline void __coherent_icache_guest_page(struct kvm_vcpu *vcpu,
> kvm_pfn_t pfn,
> unsigned long size)
> {
> + u32 iclsz;
> +
> /*
> * If we are going to insert an instruction page and the icache is
> * either VIPT or PIPT, there is a potential problem where the host
> @@ -182,17 +186,33 @@ static inline void __coherent_icache_guest_page(struct kvm_vcpu *vcpu,
> }
>
> /* PIPT cache. As for the d-side, use a temporary kernel mapping. */
> + iclsz = 4 << (read_cpuid(CPUID_CACHETYPE) & 0xf);
> +
nit: the 4 here is a bit cryptic, could we say something like (perhaps
slightly over-explained):
/*
* CTR IminLine contains Log2 of the number of words in the cache line,
* so we can get the number of words as 2 << (IminLine - 1). To get the
* number of bytes, we multiply by 4 (the number of bytes in a 32-bit
* word), and get 4 << (IminLine).
*/
> while (size) {
> void *va = kmap_atomic_pfn(pfn);
> + void *end = va + PAGE_SIZE;
> + void *addr = va;
> +
> + do {
> + write_sysreg(addr, ICIMVAU);
Maybe an oddball place to ask this, but I don't recall why we need PoU
everywhere, would PoC potentially be enough?
> + addr += iclsz;
> + } while (addr < end);
>
> - __cpuc_coherent_user_range((unsigned long)va,
> - (unsigned long)va + PAGE_SIZE);
> + dsb(ishst);
> + isb();
Do we really need this in every iteration of the loop?
>
> size -= PAGE_SIZE;
> pfn++;
>
> kunmap_atomic(va);
> }
> +
> + /* Check if we need to invalidate the BTB */
> + if ((read_cpuid_ext(CPUID_EXT_MMFR1) >> 24) != 4) {
Either I'm having a bad day or you meant to shift this 28, not 24?
> + write_sysreg(0, BPIALLIS);
> + dsb(ishst);
> + isb();
> + }
> }
>
> static inline void __kvm_flush_dcache_pte(pte_t pte)
> --
> 2.14.1
>
Thanks,
-Christoffer
WARNING: multiple messages have this Message-ID (diff)
From: cdall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/10] arm: KVM: Add optimized PIPT icache flushing
Date: Mon, 16 Oct 2017 22:07:52 +0200 [thread overview]
Message-ID: <20171016200752.GF1845@lvm> (raw)
In-Reply-To: <20171009152032.27804-4-marc.zyngier@arm.com>
On Mon, Oct 09, 2017 at 04:20:25PM +0100, Marc Zyngier wrote:
> Calling __cpuc_coherent_user_range to invalidate the icache on
> a PIPT icache machine has some pointless overhead, as it starts
> by cleaning the dcache to the PoU, while we're guaranteed to
> have already cleaned it to the PoC.
>
> As KVM is the only user of such a feature, let's implement some
> ad-hoc cache flushing in kvm_mmu.h. Should it become useful to
> other subsystems, it can be moved to a more global location.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> arch/arm/include/asm/kvm_hyp.h | 2 ++
> arch/arm/include/asm/kvm_mmu.h | 24 ++++++++++++++++++++++--
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/include/asm/kvm_hyp.h b/arch/arm/include/asm/kvm_hyp.h
> index 14b5903f0224..ad541f9ecc78 100644
> --- a/arch/arm/include/asm/kvm_hyp.h
> +++ b/arch/arm/include/asm/kvm_hyp.h
> @@ -69,6 +69,8 @@
> #define HIFAR __ACCESS_CP15(c6, 4, c0, 2)
> #define HPFAR __ACCESS_CP15(c6, 4, c0, 4)
> #define ICIALLUIS __ACCESS_CP15(c7, 0, c1, 0)
> +#define BPIALLIS __ACCESS_CP15(c7, 0, c1, 6)
> +#define ICIMVAU __ACCESS_CP15(c7, 0, c5, 1)
> #define ATS1CPR __ACCESS_CP15(c7, 0, c8, 0)
> #define TLBIALLIS __ACCESS_CP15(c8, 0, c3, 0)
> #define TLBIALL __ACCESS_CP15(c8, 0, c7, 0)
> diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
> index f553aa62d0c3..6773dcf21bff 100644
> --- a/arch/arm/include/asm/kvm_mmu.h
> +++ b/arch/arm/include/asm/kvm_mmu.h
> @@ -37,6 +37,8 @@
>
> #include <linux/highmem.h>
> #include <asm/cacheflush.h>
> +#include <asm/cputype.h>
> +#include <asm/kvm_hyp.h>
> #include <asm/pgalloc.h>
> #include <asm/stage2_pgtable.h>
>
> @@ -157,6 +159,8 @@ static inline void __coherent_icache_guest_page(struct kvm_vcpu *vcpu,
> kvm_pfn_t pfn,
> unsigned long size)
> {
> + u32 iclsz;
> +
> /*
> * If we are going to insert an instruction page and the icache is
> * either VIPT or PIPT, there is a potential problem where the host
> @@ -182,17 +186,33 @@ static inline void __coherent_icache_guest_page(struct kvm_vcpu *vcpu,
> }
>
> /* PIPT cache. As for the d-side, use a temporary kernel mapping. */
> + iclsz = 4 << (read_cpuid(CPUID_CACHETYPE) & 0xf);
> +
nit: the 4 here is a bit cryptic, could we say something like (perhaps
slightly over-explained):
/*
* CTR IminLine contains Log2 of the number of words in the cache line,
* so we can get the number of words as 2 << (IminLine - 1). To get the
* number of bytes, we multiply by 4 (the number of bytes in a 32-bit
* word), and get 4 << (IminLine).
*/
> while (size) {
> void *va = kmap_atomic_pfn(pfn);
> + void *end = va + PAGE_SIZE;
> + void *addr = va;
> +
> + do {
> + write_sysreg(addr, ICIMVAU);
Maybe an oddball place to ask this, but I don't recall why we need PoU
everywhere, would PoC potentially be enough?
> + addr += iclsz;
> + } while (addr < end);
>
> - __cpuc_coherent_user_range((unsigned long)va,
> - (unsigned long)va + PAGE_SIZE);
> + dsb(ishst);
> + isb();
Do we really need this in every iteration of the loop?
>
> size -= PAGE_SIZE;
> pfn++;
>
> kunmap_atomic(va);
> }
> +
> + /* Check if we need to invalidate the BTB */
> + if ((read_cpuid_ext(CPUID_EXT_MMFR1) >> 24) != 4) {
Either I'm having a bad day or you meant to shift this 28, not 24?
> + write_sysreg(0, BPIALLIS);
> + dsb(ishst);
> + isb();
> + }
> }
>
> static inline void __kvm_flush_dcache_pte(pte_t pte)
> --
> 2.14.1
>
Thanks,
-Christoffer
next prev parent reply other threads:[~2017-10-16 20:07 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-09 15:20 [PATCH 00/10] arm/arm64: KVM: limit icache invalidation to prefetch aborts Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-09 15:20 ` [PATCH 01/10] KVM: arm/arm64: Split dcache/icache flushing Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:07 ` Christoffer Dall
2017-10-16 20:07 ` Christoffer Dall
2017-10-17 8:57 ` Marc Zyngier
2017-10-17 8:57 ` Marc Zyngier
2017-10-17 14:28 ` Christoffer Dall
2017-10-17 14:28 ` Christoffer Dall
2017-10-17 14:41 ` Marc Zyngier
2017-10-17 14:41 ` Marc Zyngier
2017-10-16 21:35 ` Roy Franz (Cavium)
2017-10-16 21:35 ` Roy Franz (Cavium)
2017-10-17 6:44 ` Christoffer Dall
2017-10-17 6:44 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 02/10] arm64: KVM: Add invalidate_icache_range helper Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:08 ` Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-19 16:47 ` Will Deacon
2017-10-19 16:47 ` Will Deacon
2017-10-20 13:41 ` Marc Zyngier
2017-10-20 13:41 ` Marc Zyngier
2017-10-09 15:20 ` [PATCH 03/10] arm: KVM: Add optimized PIPT icache flushing Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:07 ` Christoffer Dall [this message]
2017-10-16 20:07 ` Christoffer Dall
2017-10-17 9:26 ` Marc Zyngier
2017-10-17 9:26 ` Marc Zyngier
2017-10-17 14:34 ` Christoffer Dall
2017-10-17 14:34 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 04/10] arm64: KVM: PTE/PMD S2 XN bit definition Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:07 ` Christoffer Dall
2017-10-16 20:07 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 05/10] KVM: arm/arm64: Limit icache invalidation to prefetch aborts Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:08 ` Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 06/10] KVM: arm/arm64: Only clean the dcache on translation fault Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:08 ` Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-17 9:34 ` Marc Zyngier
2017-10-17 9:34 ` Marc Zyngier
2017-10-17 14:36 ` Christoffer Dall
2017-10-17 14:36 ` Christoffer Dall
2017-10-17 14:52 ` Marc Zyngier
2017-10-17 14:52 ` Marc Zyngier
2017-10-09 15:20 ` [PATCH 07/10] KVM: arm/arm64: Preserve Exec permission across R/W permission faults Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:08 ` Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-17 11:22 ` Marc Zyngier
2017-10-17 11:22 ` Marc Zyngier
2017-10-17 14:46 ` Christoffer Dall
2017-10-17 14:46 ` Christoffer Dall
2017-10-17 15:04 ` Marc Zyngier
2017-10-17 15:04 ` Marc Zyngier
2017-10-09 15:20 ` [PATCH 08/10] KVM: arm/arm64: Drop vcpu parameter from coherent_{d,i}cache_guest_page Marc Zyngier
2017-10-09 15:20 ` [PATCH 08/10] KVM: arm/arm64: Drop vcpu parameter from coherent_{d, i}cache_guest_page Marc Zyngier
2017-10-16 20:08 ` [PATCH 08/10] KVM: arm/arm64: Drop vcpu parameter from coherent_{d,i}cache_guest_page Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 09/10] KVM: arm/arm64: Detangle kvm_mmu.h from kvm_hyp.h Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:08 ` Christoffer Dall
2017-10-16 20:08 ` Christoffer Dall
2017-10-09 15:20 ` [PATCH 10/10] arm: KVM: Use common implementation for all flushes to PoC Marc Zyngier
2017-10-09 15:20 ` Marc Zyngier
2017-10-16 20:06 ` Christoffer Dall
2017-10-16 20:06 ` Christoffer Dall
2017-10-17 12:40 ` Marc Zyngier
2017-10-17 12:40 ` Marc Zyngier
2017-10-17 14:48 ` Christoffer Dall
2017-10-17 14:48 ` Christoffer Dall
2017-10-16 20:59 ` [PATCH 00/10] arm/arm64: KVM: limit icache invalidation to prefetch aborts Christoffer Dall
2017-10-16 20:59 ` Christoffer Dall
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=20171016200752.GF1845@lvm \
--to=cdall@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marc.zyngier@arm.com \
--cc=will.deacon@arm.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.