All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH stable-4.9] KVM: arm64: Fix caching of host MDCR_EL2 value
@ 2018-11-12  8:27 Marc Zyngier
  2018-11-19 15:16 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Zyngier @ 2018-11-12  8:27 UTC (permalink / raw)
  To: stable
  Cc: Mark Rutland, christoffer.dall, james.morse, robin.murphy,
	will.deacon

From: Mark Rutland <mark.rutland@arm.com>

commit da5a3ce66b8bb51b0ea8a89f42aac153903f90fb upstream.

At boot time, KVM stashes the host MDCR_EL2 value, but only does this
when the kernel is not running in hyp mode (i.e. is non-VHE). In these
cases, the stashed value of MDCR_EL2.HPMN happens to be zero, which can
lead to CONSTRAINED UNPREDICTABLE behaviour.

Since we use this value to derive the MDCR_EL2 value when switching
to/from a guest, after a guest have been run, the performance counters
do not behave as expected. This has been observed to result in accesses
via PMXEVTYPER_EL0 and PMXEVCNTR_EL0 not affecting the relevant
counters, resulting in events not being counted. In these cases, only
the fixed-purpose cycle counter appears to work as expected.

Fix this by always stashing the host MDCR_EL2 value, regardless of VHE.

Cc: Christopher Dall <christoffer.dall@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: stable@vger.kernel.org
Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
Tested-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm/kvm/arm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 20436972537f..a670c70f4def 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -1092,8 +1092,6 @@ static void cpu_init_hyp_mode(void *dummy)
 
 	__cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr);
 	__cpu_init_stage2();
-
-	kvm_arm_init_debug();
 }
 
 static void cpu_hyp_reinit(void)
@@ -1108,6 +1106,8 @@ static void cpu_hyp_reinit(void)
 		if (__hyp_get_vectors() == hyp_default_vectors)
 			cpu_init_hyp_mode(NULL);
 	}
+
+	kvm_arm_init_debug();
 }
 
 static void cpu_hyp_reset(void)
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH stable-4.9] KVM: arm64: Fix caching of host MDCR_EL2 value
  2018-11-12  8:27 [PATCH stable-4.9] KVM: arm64: Fix caching of host MDCR_EL2 value Marc Zyngier
@ 2018-11-19 15:16 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2018-11-19 15:16 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: stable, Mark Rutland, christoffer.dall, james.morse, robin.murphy,
	will.deacon

On Mon, Nov 12, 2018 at 08:27:07AM +0000, Marc Zyngier wrote:
> From: Mark Rutland <mark.rutland@arm.com>
> 
> commit da5a3ce66b8bb51b0ea8a89f42aac153903f90fb upstream.
> 
> At boot time, KVM stashes the host MDCR_EL2 value, but only does this
> when the kernel is not running in hyp mode (i.e. is non-VHE). In these
> cases, the stashed value of MDCR_EL2.HPMN happens to be zero, which can
> lead to CONSTRAINED UNPREDICTABLE behaviour.
> 
> Since we use this value to derive the MDCR_EL2 value when switching
> to/from a guest, after a guest have been run, the performance counters
> do not behave as expected. This has been observed to result in accesses
> via PMXEVTYPER_EL0 and PMXEVCNTR_EL0 not affecting the relevant
> counters, resulting in events not being counted. In these cases, only
> the fixed-purpose cycle counter appears to work as expected.
> 
> Fix this by always stashing the host MDCR_EL2 value, regardless of VHE.
> 
> Cc: Christopher Dall <christoffer.dall@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: stable@vger.kernel.org
> Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
> Tested-by: Robin Murphy <robin.murphy@arm.com>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  arch/arm/kvm/arm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-20  1:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-12  8:27 [PATCH stable-4.9] KVM: arm64: Fix caching of host MDCR_EL2 value Marc Zyngier
2018-11-19 15:16 ` Greg KH

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.