From: Marc Zyngier <marc.zyngier@arm.com> To: Christoffer Dall <christoffer.dall@linaro.org> Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH v2 07/18] arm64: KVM: Refactor kern_hyp_va to deal with multiple offsets Date: Thu, 30 Jun 2016 18:40:40 +0100 [thread overview] Message-ID: <1467308451-13365-8-git-send-email-marc.zyngier@arm.com> (raw) In-Reply-To: <1467308451-13365-1-git-send-email-marc.zyngier@arm.com> 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 helper 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 | 11 ----------- arch/arm64/include/asm/kvm_mmu.h | 42 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 1d81f9a..cff5105 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -25,17 +25,6 @@ #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))) - #define read_sysreg_elx(r,nvh,vh) \ ({ \ u64 reg; \ diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 5e54323..2970537 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -90,13 +90,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 @@ -107,7 +127,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)); + return v; +} + +#define kern_hyp_va(v) (typeof(v))(__kern_hyp_va((unsigned long)(v))) +#define KERN_TO_HYP(v) kern_hyp_va(v) /* * We currently only support a 40bit IPA. -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: marc.zyngier@arm.com (Marc Zyngier) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 07/18] arm64: KVM: Refactor kern_hyp_va to deal with multiple offsets Date: Thu, 30 Jun 2016 18:40:40 +0100 [thread overview] Message-ID: <1467308451-13365-8-git-send-email-marc.zyngier@arm.com> (raw) In-Reply-To: <1467308451-13365-1-git-send-email-marc.zyngier@arm.com> 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 helper 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 | 11 ----------- arch/arm64/include/asm/kvm_mmu.h | 42 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 1d81f9a..cff5105 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -25,17 +25,6 @@ #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))) - #define read_sysreg_elx(r,nvh,vh) \ ({ \ u64 reg; \ diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 5e54323..2970537 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -90,13 +90,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 @@ -107,7 +127,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)); + return v; +} + +#define kern_hyp_va(v) (typeof(v))(__kern_hyp_va((unsigned long)(v))) +#define KERN_TO_HYP(v) kern_hyp_va(v) /* * We currently only support a 40bit IPA. -- 2.1.4
next prev parent reply other threads:[~2016-06-30 17:40 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-06-30 17:40 [PATCH v2 00/18] arm/arm64: KVM: Merge boot and runtime page tables Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 01/18] arm64: KVM: Merged page tables documentation Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 02/18] arm64: KVM: Always reference __hyp_panic_string via its kernel VA Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 03/18] arm/arm64: KVM: Remove hyp_kern_va helper Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 04/18] arm64: KVM: Kill HYP_PAGE_OFFSET Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 05/18] arm64: Add ARM64_HYP_OFFSET_LOW capability Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 06/18] arm64: KVM: Define HYP offset masks Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier [this message] 2016-06-30 17:40 ` [PATCH v2 07/18] arm64: KVM: Refactor kern_hyp_va to deal with multiple offsets Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 08/18] arm/arm64: KVM: Export __hyp_text_start/end symbols Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 09/18] arm64: KVM: Runtime detection of lower HYP offset Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 10/18] arm/arm64: KVM: Always have merged page tables Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 11/18] arm64: KVM: Simplify HYP init/teardown Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 12/18] arm/arm64: KVM: Drop boot_pgd Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 13/18] arm/arm64: KVM: Kill free_boot_hyp_pgd Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 14/18] arm: KVM: Simplify HYP init Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 15/18] arm: KVM: Allow hyp teardown Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 16/18] arm/arm64: KVM: Prune unused #defines Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 17/18] arm/arm64: KVM: Check that IDMAP doesn't intersect with VA range Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-06-30 17:40 ` [PATCH v2 18/18] arm/arm64: Get rid of KERN_TO_HYP Marc Zyngier 2016-06-30 17:40 ` Marc Zyngier 2016-07-03 21:44 ` [PATCH v2 00/18] arm/arm64: KVM: Merge boot and runtime page tables Christoffer Dall 2016-07-03 21:44 ` 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=1467308451-13365-8-git-send-email-marc.zyngier@arm.com \ --to=marc.zyngier@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 \ /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: linkBe 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.