From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 05/15] arm64: KVM: Refactor kern_hyp_va/hyp_kern_va to deal with multiple offsets
Date: Tue, 28 Jun 2016 14:42:10 +0200 [thread overview]
Message-ID: <20160628124210.GP26498@cbox> (raw)
In-Reply-To: <1465297115-13091-6-git-send-email-marc.zyngier@arm.com>
On Tue, Jun 07, 2016 at 11:58:25AM +0100, Marc Zyngier wrote:
> As we move towards a selectable HYP VA range, it is obvious that
> we don't want to test a variable to find out if we need to use
> the bottom VA range, the top VA range, or use the address as is
> (for VHE).
>
> Instead, we can expand our current helpers to generate the right
> mask or nop with code patching. We default to using the top VA
> space, with alternatives to switch to the bottom one or to nop
> out the instructions.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> arch/arm64/include/asm/kvm_hyp.h | 27 ++++++++++++--------------
> arch/arm64/include/asm/kvm_mmu.h | 42 +++++++++++++++++++++++++++++++++++++---
> 2 files changed, 51 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
> index 61d01a9..dd4904b 100644
> --- a/arch/arm64/include/asm/kvm_hyp.h
> +++ b/arch/arm64/include/asm/kvm_hyp.h
> @@ -25,24 +25,21 @@
>
> #define __hyp_text __section(.hyp.text) notrace
>
> -static inline unsigned long __kern_hyp_va(unsigned long v)
> -{
> - asm volatile(ALTERNATIVE("and %0, %0, %1",
> - "nop",
> - ARM64_HAS_VIRT_HOST_EXTN)
> - : "+r" (v) : "i" (HYP_PAGE_OFFSET_MASK));
> - return v;
> -}
> -
> -#define kern_hyp_va(v) (typeof(v))(__kern_hyp_va((unsigned long)(v)))
> -
> static inline unsigned long __hyp_kern_va(unsigned long v)
> {
> - asm volatile(ALTERNATIVE("orr %0, %0, %1",
> - "nop",
> + u64 mask;
> +
> + asm volatile(ALTERNATIVE("mov %0, %1",
> + "mov %0, %2",
> + ARM64_HYP_OFFSET_LOW)
> + : "=r" (mask)
> + : "i" (~HYP_PAGE_OFFSET_HIGH_MASK),
> + "i" (~HYP_PAGE_OFFSET_LOW_MASK));
> + asm volatile(ALTERNATIVE("nop",
> + "mov %0, xzr",
> ARM64_HAS_VIRT_HOST_EXTN)
> - : "+r" (v) : "i" (~HYP_PAGE_OFFSET_MASK));
> - return v;
> + : "+r" (mask));
> + return v | mask;
If mask is ~HYP_PAGE_OFFSET_LOW_MASK how can you be sure that setting
bit (VA_BITS - 1) is always the right thing to do to generate a kernel
address?
This is kind of what I asked before only now there's an extra bit not
guaranteed by the architecture to be set for the kernel range, I
think.
> }
>
> #define hyp_kern_va(v) (typeof(v))(__hyp_kern_va((unsigned long)(v)))
> diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
> index e45df1b..889330b 100644
> --- a/arch/arm64/include/asm/kvm_mmu.h
> +++ b/arch/arm64/include/asm/kvm_mmu.h
> @@ -95,13 +95,33 @@
> /*
> * Convert a kernel VA into a HYP VA.
> * reg: VA to be converted.
> + *
> + * This generates the following sequences:
> + * - High mask:
> + * and x0, x0, #HYP_PAGE_OFFSET_HIGH_MASK
> + * nop
> + * - Low mask:
> + * and x0, x0, #HYP_PAGE_OFFSET_HIGH_MASK
> + * and x0, x0, #HYP_PAGE_OFFSET_LOW_MASK
> + * - VHE:
> + * nop
> + * nop
> + *
> + * The "low mask" version works because the mask is a strict subset of
> + * the "high mask", hence performing the first mask for nothing.
> + * Should be completely invisible on any viable CPU.
> */
> .macro kern_hyp_va reg
> -alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
> - and \reg, \reg, #HYP_PAGE_OFFSET_MASK
> +alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
> + and \reg, \reg, #HYP_PAGE_OFFSET_HIGH_MASK
> alternative_else
> nop
> alternative_endif
> +alternative_if_not ARM64_HYP_OFFSET_LOW
> + nop
> +alternative_else
> + and \reg, \reg, #HYP_PAGE_OFFSET_LOW_MASK
> +alternative_endif
> .endm
>
> #else
> @@ -112,7 +132,23 @@ alternative_endif
> #include <asm/mmu_context.h>
> #include <asm/pgtable.h>
>
> -#define KERN_TO_HYP(kva) ((unsigned long)kva & HYP_PAGE_OFFSET_MASK)
> +static inline unsigned long __kern_hyp_va(unsigned long v)
> +{
> + asm volatile(ALTERNATIVE("and %0, %0, %1",
> + "nop",
> + ARM64_HAS_VIRT_HOST_EXTN)
> + : "+r" (v)
> + : "i" (HYP_PAGE_OFFSET_HIGH_MASK));
> + asm volatile(ALTERNATIVE("nop",
> + "and %0, %0, %1",
> + ARM64_HYP_OFFSET_LOW)
> + : "+r" (v)
> + : "i" (HYP_PAGE_OFFSET_LOW_MASK));
how is the second operation a nop for VHE? Is this because
ARM64_HYP_OFFSET_LOW will never be set for VHE?
> + return v;
> +}
> +
> +#define kern_hyp_va(v) (typeof(v))(__kern_hyp_va((unsigned long)(v)))
> +#define KERN_TO_HYP(v) kern_hyp_va(v)
looks like there's room for some unification/cleanup here as well.
>
> /*
> * We currently only support a 40bit IPA.
> --
> 2.1.4
>
Thanks,
-Christoffer
next prev parent reply other threads:[~2016-06-28 12:42 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 10:58 [PATCH 00/15] arm/arm64: KVM: Merge boot and runtime page tables Marc Zyngier
2016-06-07 10:58 ` [PATCH 01/15] arm64: KVM: Merged page tables documentation Marc Zyngier
2016-06-27 13:28 ` Christoffer Dall
2016-06-27 14:06 ` Marc Zyngier
2016-06-28 11:46 ` Christoffer Dall
2016-06-29 9:05 ` Marc Zyngier
2016-06-07 10:58 ` [PATCH 02/15] arm64: KVM: Kill HYP_PAGE_OFFSET Marc Zyngier
2016-06-27 13:47 ` Christoffer Dall
2016-06-27 14:20 ` Marc Zyngier
2016-06-28 12:03 ` Christoffer Dall
2016-06-07 10:58 ` [PATCH 03/15] arm64: Add ARM64_HYP_OFFSET_LOW capability Marc Zyngier
2016-06-07 10:58 ` [PATCH 04/15] arm64: KVM: Define HYP offset masks Marc Zyngier
2016-06-07 10:58 ` [PATCH 05/15] arm64: KVM: Refactor kern_hyp_va/hyp_kern_va to deal with multiple offsets Marc Zyngier
2016-06-28 12:42 ` Christoffer Dall [this message]
2016-06-30 9:22 ` Marc Zyngier
2016-06-30 10:16 ` Marc Zyngier
2016-06-30 10:26 ` Christoffer Dall
2016-06-30 10:42 ` Ard Biesheuvel
2016-06-30 11:02 ` Marc Zyngier
2016-06-30 11:10 ` Ard Biesheuvel
2016-06-30 11:57 ` Marc Zyngier
2016-06-07 10:58 ` [PATCH 06/15] arm/arm64: KVM: Export __hyp_text_start/end symbols Marc Zyngier
2016-06-07 10:58 ` [PATCH 07/15] arm64: KVM: Runtime detection of lower HYP offset Marc Zyngier
2016-06-07 10:58 ` [PATCH 08/15] arm/arm64: KVM: Always have merged page tables Marc Zyngier
2016-06-28 21:43 ` Christoffer Dall
2016-06-30 12:27 ` Marc Zyngier
2016-06-30 13:28 ` Christoffer Dall
2016-06-07 10:58 ` [PATCH 09/15] arm64: KVM: Simplify HYP init/teardown Marc Zyngier
2016-06-28 21:31 ` Christoffer Dall
2016-06-30 12:10 ` Marc Zyngier
2016-06-30 13:31 ` Christoffer Dall
2016-06-07 10:58 ` [PATCH 10/15] arm/arm64: KVM: Drop boot_pgd Marc Zyngier
2016-06-07 10:58 ` [PATCH 11/15] arm/arm64: KVM: Kill free_boot_hyp_pgd Marc Zyngier
2016-06-07 10:58 ` [PATCH 12/15] arm: KVM: Simplify HYP init Marc Zyngier
2016-06-28 21:50 ` Christoffer Dall
2016-06-30 12:31 ` Marc Zyngier
2016-06-30 13:32 ` Christoffer Dall
2016-06-07 10:58 ` [PATCH 13/15] arm: KVM: Allow hyp teardown Marc Zyngier
2016-06-07 10:58 ` [PATCH 14/15] arm/arm64: KVM: Prune unused #defines Marc Zyngier
2016-06-07 10:58 ` [PATCH 15/15] arm/arm64: KVM: Check that IDMAP doesn't intersect with VA range Marc Zyngier
2016-06-28 22:01 ` Christoffer Dall
2016-06-30 12:51 ` Marc Zyngier
2016-06-30 13:27 ` Christoffer Dall
2016-06-27 13:29 ` [PATCH 00/15] arm/arm64: KVM: Merge boot and runtime page tables Christoffer Dall
2016-06-27 14:12 ` Marc Zyngier
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=20160628124210.GP26498@cbox \
--to=christoffer.dall@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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 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).