All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Andre Przywara <andre.przywara@arm.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	kvmarm@lists.cs.columbia.edu,
	Shaokun Zhang <zhangshaokun@hisilicon.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	linux-arm-kernel@lists.infradead.org,
	Zenghui Yu <yuzenghui@huawei.com>,
	Colin Ian King <colin.king@canonical.com>,
	Dave Martin <Dave.Martin@arm.com>
Subject: [PATCH 03/27] arm64: KVM: Allow for direct call of HYP functions when using VHE
Date: Fri, 22 Feb 2019 16:25:41 +0000	[thread overview]
Message-ID: <20190222162605.5054-4-marc.zyngier@arm.com> (raw)
In-Reply-To: <20190222162605.5054-1-marc.zyngier@arm.com>

When running VHE, there is no need to jump via some stub to perform
a "HYP" function call, as there is a single address space.

Let's thus change kvm_call_hyp() and co to perform a direct call
in this case. Although this results in a bit of code expansion,
it allows the compiler to check for type compatibility, something
that we are missing so far.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
---
 arch/arm64/include/asm/kvm_host.h | 32 +++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index e54cb7c88a4e..8b7702bdb219 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -370,8 +370,36 @@ void kvm_arm_halt_guest(struct kvm *kvm);
 void kvm_arm_resume_guest(struct kvm *kvm);
 
 u64 __kvm_call_hyp(void *hypfn, ...);
-#define kvm_call_hyp(f, ...) __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__)
-#define kvm_call_hyp_ret(f, ...) kvm_call_hyp(f, ##__VA_ARGS__)
+
+/*
+ * The couple of isb() below are there to guarantee the same behaviour
+ * on VHE as on !VHE, where the eret to EL1 acts as a context
+ * synchronization event.
+ */
+#define kvm_call_hyp(f, ...)						\
+	do {								\
+		if (has_vhe()) {					\
+			f(__VA_ARGS__);					\
+			isb();						\
+		} else {						\
+			__kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \
+		}							\
+	} while(0)
+
+#define kvm_call_hyp_ret(f, ...)					\
+	({								\
+		typeof(f(__VA_ARGS__)) ret;				\
+									\
+		if (has_vhe()) {					\
+			ret = f(__VA_ARGS__);				\
+			isb();						\
+		} else {						\
+			ret = __kvm_call_hyp(kvm_ksym_ref(f),		\
+					     ##__VA_ARGS__);		\
+		}							\
+									\
+		ret;							\
+	})
 
 void force_vm_exit(const cpumask_t *mask);
 void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
-- 
2.20.1

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <marc.zyngier@arm.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Cc: Julien Thierry <julien.thierry@arm.com>,
	kvm@vger.kernel.org, Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Andre Przywara <andre.przywara@arm.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Christoffer Dall <christoffer.dall@arm.com>,
	kvmarm@lists.cs.columbia.edu,
	Shaokun Zhang <zhangshaokun@hisilicon.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	James Morse <james.morse@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	Zenghui Yu <yuzenghui@huawei.com>,
	Colin Ian King <colin.king@canonical.com>,
	Dave Martin <Dave.Martin@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>
Subject: [PATCH 03/27] arm64: KVM: Allow for direct call of HYP functions when using VHE
Date: Fri, 22 Feb 2019 16:25:41 +0000	[thread overview]
Message-ID: <20190222162605.5054-4-marc.zyngier@arm.com> (raw)
In-Reply-To: <20190222162605.5054-1-marc.zyngier@arm.com>

When running VHE, there is no need to jump via some stub to perform
a "HYP" function call, as there is a single address space.

Let's thus change kvm_call_hyp() and co to perform a direct call
in this case. Although this results in a bit of code expansion,
it allows the compiler to check for type compatibility, something
that we are missing so far.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
---
 arch/arm64/include/asm/kvm_host.h | 32 +++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index e54cb7c88a4e..8b7702bdb219 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -370,8 +370,36 @@ void kvm_arm_halt_guest(struct kvm *kvm);
 void kvm_arm_resume_guest(struct kvm *kvm);
 
 u64 __kvm_call_hyp(void *hypfn, ...);
-#define kvm_call_hyp(f, ...) __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__)
-#define kvm_call_hyp_ret(f, ...) kvm_call_hyp(f, ##__VA_ARGS__)
+
+/*
+ * The couple of isb() below are there to guarantee the same behaviour
+ * on VHE as on !VHE, where the eret to EL1 acts as a context
+ * synchronization event.
+ */
+#define kvm_call_hyp(f, ...)						\
+	do {								\
+		if (has_vhe()) {					\
+			f(__VA_ARGS__);					\
+			isb();						\
+		} else {						\
+			__kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \
+		}							\
+	} while(0)
+
+#define kvm_call_hyp_ret(f, ...)					\
+	({								\
+		typeof(f(__VA_ARGS__)) ret;				\
+									\
+		if (has_vhe()) {					\
+			ret = f(__VA_ARGS__);				\
+			isb();						\
+		} else {						\
+			ret = __kvm_call_hyp(kvm_ksym_ref(f),		\
+					     ##__VA_ARGS__);		\
+		}							\
+									\
+		ret;							\
+	})
 
 void force_vm_exit(const cpumask_t *mask);
 void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-02-22 16:25 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 16:25 [GIT PULL] KVM/arm updates for Linux v5.1 Marc Zyngier
2019-02-22 16:25 ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 01/27] clocksource/arm_arch_timer: Store physical timer IRQ number for KVM on VHE Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 02/27] arm/arm64: KVM: Introduce kvm_call_hyp_ret() Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` Marc Zyngier [this message]
2019-02-22 16:25   ` [PATCH 03/27] arm64: KVM: Allow for direct call of HYP functions when using VHE Marc Zyngier
2019-02-22 16:25 ` [PATCH 04/27] arm64: KVM: Drop VHE-specific HYP call stub Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 05/27] ARM: KVM: Teach some form of type-safety to kvm_call_hyp Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 06/27] arm/arm64: KVM: Statically configure the host's view of MPIDR Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 07/27] KVM: arm/arm64: Factor out VMID into struct kvm_vmid Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 08/27] KVM: arm/arm64: Simplify bg_timer programming Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 09/27] KVM: arm64: Fix ICH_ELRSR_EL2 sysreg naming Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 10/27] KVM: arm64: Reuse sys_reg() macro when searching the trap table Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 11/27] KVM: arm/arm64: consolidate arch timer trap handlers Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 12/27] KVM: arm/arm64: timer: Rework data structures for multiple timers Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 13/27] KVM: arm/arm64: arch_timer: Assign the phys timer on VHE systems Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 14/27] KVM: arm/arm64: Rework the timer code to use a timer_map Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 15/27] KVM: arm/arm64: Move kvm_is_write_fault to header file Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 16/27] arm64: KVM: Expose sanitised cache type register to guest Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 17/27] arm64: KVM: Describe data or unified caches as having 1 set and 1 way Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 18/27] KVM: arm/arm64: arch_timer: Mark physical interrupt active when a virtual interrupt is pending Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 19/27] KVM: arm/arm64: Fix TRACE_INCLUDE_PATH Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 20/27] KVM: arm/arm64: Remove -I. header search paths Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:25 ` [PATCH 21/27] KVM: arm/arm64: Prefix header search paths with $(srctree)/ Marc Zyngier
2019-02-22 16:25   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 22/27] KVM: arm/arm64: Update MAINTAINERS entries Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 23/27] KVM: arm/arm64: fix spelling mistake: "auxilary" -> "auxiliary" Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 24/27] KVM: arm64: Fix comment for KVM_PHYS_SHIFT Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 25/27] KVM: arm/arm64: Remove unused gpa_end variable Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 26/27] KVM: arm/arm64: Remove unused timer variable Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:26 ` [PATCH 27/27] arm64: KVM: Fix architecturally invalid reset value for FPEXC32_EL2 Marc Zyngier
2019-02-22 16:26   ` Marc Zyngier
2019-02-22 16:45 ` [GIT PULL] KVM/arm updates for Linux v5.1 Paolo Bonzini
2019-02-22 16:45   ` Paolo Bonzini

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=20190222162605.5054-4-marc.zyngier@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=Dave.Martin@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=colin.king@canonical.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=yamada.masahiro@socionext.com \
    --cc=yuzenghui@huawei.com \
    --cc=zhangshaokun@hisilicon.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.