* [PULL 1/2] arm64: kvm: 4.6-rc1: Fix VTCR_EL2 VS setting
2016-04-01 9:07 [PULL 0/2] KVM/ARM Fixes for v4.6-rc2 Christoffer Dall
@ 2016-04-01 9:07 ` Christoffer Dall
2016-04-01 9:07 ` [PULL 2/2] arm64: KVM: Register CPU notifiers when the kernel runs at HYP Christoffer Dall
2016-04-01 10:37 ` [PULL 0/2] KVM/ARM Fixes for v4.6-rc2 Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Christoffer Dall @ 2016-04-01 9:07 UTC (permalink / raw)
To: linux-arm-kernel
From: Suzuki K Poulose <suzuki.poulose@arm.com>
When we detect support for 16bit VMID in ID_AA64MMFR1, we set the
VTCR_EL2_VS field to 1 to make use of 16bit vmids. But, with
commit 3a3604bc5eb4 ("arm64: KVM: Switch to C-based stage2 init")
this is broken and we corrupt VTCR_EL2:T0SZ instead of updating the VS
field. VTCR_EL2_VS was actually defined to the field shift (19) and
not the real value for VS. This patch fixes the issue.
Fixes: commit 3a3604bc5eb4 ("arm64: KVM: Switch to C-based stage2 init")
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
arch/arm64/include/asm/kvm_arm.h | 4 +++-
arch/arm64/include/asm/sysreg.h | 3 +++
arch/arm64/kvm/hyp/s2-setup.c | 6 ++++--
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 0e391db..4150fd8 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -124,7 +124,9 @@
#define VTCR_EL2_SL0_LVL1 (1 << 6)
#define VTCR_EL2_T0SZ_MASK 0x3f
#define VTCR_EL2_T0SZ_40B 24
-#define VTCR_EL2_VS 19
+#define VTCR_EL2_VS_SHIFT 19
+#define VTCR_EL2_VS_8BIT (0 << VTCR_EL2_VS_SHIFT)
+#define VTCR_EL2_VS_16BIT (1 << VTCR_EL2_VS_SHIFT)
/*
* We configure the Stage-2 page tables to always restrict the IPA space to be
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 1a78d6e..1287416 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -141,6 +141,9 @@
#define ID_AA64MMFR1_VMIDBITS_SHIFT 4
#define ID_AA64MMFR1_HADBS_SHIFT 0
+#define ID_AA64MMFR1_VMIDBITS_8 0
+#define ID_AA64MMFR1_VMIDBITS_16 2
+
/* id_aa64mmfr2 */
#define ID_AA64MMFR2_UAO_SHIFT 4
diff --git a/arch/arm64/kvm/hyp/s2-setup.c b/arch/arm64/kvm/hyp/s2-setup.c
index bfc54fd..5a9f3bf 100644
--- a/arch/arm64/kvm/hyp/s2-setup.c
+++ b/arch/arm64/kvm/hyp/s2-setup.c
@@ -36,8 +36,10 @@ void __hyp_text __init_stage2_translation(void)
* Read the VMIDBits bits from ID_AA64MMFR1_EL1 and set the VS
* bit in VTCR_EL2.
*/
- tmp = (read_sysreg(id_aa64mmfr1_el1) >> 4) & 0xf;
- val |= (tmp == 2) ? VTCR_EL2_VS : 0;
+ tmp = (read_sysreg(id_aa64mmfr1_el1) >> ID_AA64MMFR1_VMIDBITS_SHIFT) & 0xf;
+ val |= (tmp == ID_AA64MMFR1_VMIDBITS_16) ?
+ VTCR_EL2_VS_16BIT :
+ VTCR_EL2_VS_8BIT;
write_sysreg(val, vtcr_el2);
}
--
2.1.2.330.g565301e.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PULL 2/2] arm64: KVM: Register CPU notifiers when the kernel runs at HYP
2016-04-01 9:07 [PULL 0/2] KVM/ARM Fixes for v4.6-rc2 Christoffer Dall
2016-04-01 9:07 ` [PULL 1/2] arm64: kvm: 4.6-rc1: Fix VTCR_EL2 VS setting Christoffer Dall
@ 2016-04-01 9:07 ` Christoffer Dall
2016-04-01 10:37 ` [PULL 0/2] KVM/ARM Fixes for v4.6-rc2 Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Christoffer Dall @ 2016-04-01 9:07 UTC (permalink / raw)
To: linux-arm-kernel
From: James Morse <james.morse@arm.com>
When the kernel is running at EL2, it doesn't need init_hyp_mode() to
configure page tables for HYP. This function also registers the CPU
hotplug and lower power notifiers that cause HYP to be re-initialised
after the CPU has been reset.
To avoid losing the register state that controls stage2 translation, move
the registering of these notifiers into init_subsystems(), and add a
is_kernel_in_hyp_mode() path to each callback.
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Fixes: 1e947bad0b6 ("arm64: KVM: Skip HYP setup when already running in HYP")
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
arch/arm/kvm/arm.c | 52 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 19 deletions(-)
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 6accd66..b538431 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -1061,15 +1061,27 @@ static void cpu_init_hyp_mode(void *dummy)
kvm_arm_init_debug();
}
+static void cpu_hyp_reinit(void)
+{
+ if (is_kernel_in_hyp_mode()) {
+ /*
+ * cpu_init_stage2() is safe to call even if the PM
+ * event was cancelled before the CPU was reset.
+ */
+ cpu_init_stage2(NULL);
+ } else {
+ if (__hyp_get_vectors() == hyp_default_vectors)
+ cpu_init_hyp_mode(NULL);
+ }
+}
+
static int hyp_init_cpu_notify(struct notifier_block *self,
unsigned long action, void *cpu)
{
switch (action) {
case CPU_STARTING:
case CPU_STARTING_FROZEN:
- if (__hyp_get_vectors() == hyp_default_vectors)
- cpu_init_hyp_mode(NULL);
- break;
+ cpu_hyp_reinit();
}
return NOTIFY_OK;
@@ -1084,9 +1096,8 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
unsigned long cmd,
void *v)
{
- if (cmd == CPU_PM_EXIT &&
- __hyp_get_vectors() == hyp_default_vectors) {
- cpu_init_hyp_mode(NULL);
+ if (cmd == CPU_PM_EXIT) {
+ cpu_hyp_reinit();
return NOTIFY_OK;
}
@@ -1128,6 +1139,22 @@ static int init_subsystems(void)
int err;
/*
+ * Register CPU Hotplug notifier
+ */
+ cpu_notifier_register_begin();
+ err = __register_cpu_notifier(&hyp_init_cpu_nb);
+ cpu_notifier_register_done();
+ if (err) {
+ kvm_err("Cannot register KVM init CPU notifier (%d)\n", err);
+ return err;
+ }
+
+ /*
+ * Register CPU lower-power notifier
+ */
+ hyp_cpu_pm_init();
+
+ /*
* Init HYP view of VGIC
*/
err = kvm_vgic_hyp_init();
@@ -1270,19 +1297,6 @@ static int init_hyp_mode(void)
free_boot_hyp_pgd();
#endif
- cpu_notifier_register_begin();
-
- err = __register_cpu_notifier(&hyp_init_cpu_nb);
-
- cpu_notifier_register_done();
-
- if (err) {
- kvm_err("Cannot register HYP init CPU notifier (%d)\n", err);
- goto out_err;
- }
-
- hyp_cpu_pm_init();
-
/* set size of VMID supported by CPU */
kvm_vmid_bits = kvm_get_vmid_bits();
kvm_info("%d-bit VMID\n", kvm_vmid_bits);
--
2.1.2.330.g565301e.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PULL 0/2] KVM/ARM Fixes for v4.6-rc2
2016-04-01 9:07 [PULL 0/2] KVM/ARM Fixes for v4.6-rc2 Christoffer Dall
2016-04-01 9:07 ` [PULL 1/2] arm64: kvm: 4.6-rc1: Fix VTCR_EL2 VS setting Christoffer Dall
2016-04-01 9:07 ` [PULL 2/2] arm64: KVM: Register CPU notifiers when the kernel runs at HYP Christoffer Dall
@ 2016-04-01 10:37 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-04-01 10:37 UTC (permalink / raw)
To: linux-arm-kernel
On 01/04/2016 11:07, Christoffer Dall wrote:
> Hi Paolo,
>
> The following changes since commit f55532a0c0b8bb6148f4e07853b876ef73bc69ca:
>
> Linux 4.6-rc1 (2016-03-26 16:03:24 -0700)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvm-arm-for-4.6-rc2
>
> for you to fetch changes up to 5f5560b1c5f3a80e91c6babb2da34a51943bbdec:
>
> arm64: KVM: Register CPU notifiers when the kernel runs at HYP (2016-03-31 10:27:28 +0200)
>
> The pull contains two small patches that fix a bug that corrupts stage-2
> translationson 16-bit VMID equipped systems and fixCPU PM and Hotplug after
> the EL2 init code has been moved to C.
>
> Thanks,
> -Christoffer
>
> ---
>
> James Morse (1):
> arm64: KVM: Register CPU notifiers when the kernel runs at HYP
>
> Suzuki K Poulose (1):
> arm64: kvm: 4.6-rc1: Fix VTCR_EL2 VS setting
>
> arch/arm/kvm/arm.c | 52 +++++++++++++++++++++++++---------------
> arch/arm64/include/asm/kvm_arm.h | 4 +++-
> arch/arm64/include/asm/sysreg.h | 3 +++
> arch/arm64/kvm/hyp/s2-setup.c | 6 +++--
> 4 files changed, 43 insertions(+), 22 deletions(-)
Pulled to kvm/queue, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread