All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
@ 2018-10-17 16:42 ` Mark Rutland
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Rutland @ 2018-10-17 16:42 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Marc Zyngier, Will Deacon, Robin Murphy, kvmarm

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.

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

diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index c92053bc3f96..8fb31a7cc22c 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -1295,8 +1295,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_reset(void)
@@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
 		cpu_init_hyp_mode(NULL);
 	}
 
+	kvm_arm_init_debug();
+
 	if (vgic_present)
 		kvm_vgic_init_cpu_hardware();
 }
-- 
2.11.0

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

* [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
@ 2018-10-17 16:42 ` Mark Rutland
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Rutland @ 2018-10-17 16:42 UTC (permalink / raw)
  To: linux-arm-kernel

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.

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

diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index c92053bc3f96..8fb31a7cc22c 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -1295,8 +1295,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_reset(void)
@@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
 		cpu_init_hyp_mode(NULL);
 	}
 
+	kvm_arm_init_debug();
+
 	if (vgic_present)
 		kvm_vgic_init_cpu_hardware();
 }
-- 
2.11.0

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

* Re: [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
  2018-10-17 16:42 ` Mark Rutland
@ 2018-10-17 16:51   ` Marc Zyngier
  -1 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2018-10-17 16:51 UTC (permalink / raw)
  To: Mark Rutland, linux-arm-kernel; +Cc: Robin Murphy, Will Deacon, kvmarm

On 17/10/18 17:42, Mark Rutland wrote:
> 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.
> 
> Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Christopher Dall <christoffer.dall@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: kvmarm@lists.cs.columbia.edu
> ---
>  virt/kvm/arm/arm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
> index c92053bc3f96..8fb31a7cc22c 100644
> --- a/virt/kvm/arm/arm.c
> +++ b/virt/kvm/arm/arm.c
> @@ -1295,8 +1295,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_reset(void)
> @@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
>  		cpu_init_hyp_mode(NULL);
>  	}
>  
> +	kvm_arm_init_debug();
> +
>  	if (vgic_present)
>  		kvm_vgic_init_cpu_hardware();
>  }
> 

Urghh. Lovely. Thanks for tracking that one down. I'll queue it
immediately, with a Cc to stable.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
@ 2018-10-17 16:51   ` Marc Zyngier
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2018-10-17 16:51 UTC (permalink / raw)
  To: linux-arm-kernel

On 17/10/18 17:42, Mark Rutland wrote:
> 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.
> 
> Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Christopher Dall <christoffer.dall@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: kvmarm at lists.cs.columbia.edu
> ---
>  virt/kvm/arm/arm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
> index c92053bc3f96..8fb31a7cc22c 100644
> --- a/virt/kvm/arm/arm.c
> +++ b/virt/kvm/arm/arm.c
> @@ -1295,8 +1295,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_reset(void)
> @@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
>  		cpu_init_hyp_mode(NULL);
>  	}
>  
> +	kvm_arm_init_debug();
> +
>  	if (vgic_present)
>  		kvm_vgic_init_cpu_hardware();
>  }
> 

Urghh. Lovely. Thanks for tracking that one down. I'll queue it
immediately, with a Cc to stable.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* Re: [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
  2018-10-17 16:42 ` Mark Rutland
@ 2018-10-17 17:13   ` Robin Murphy
  -1 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2018-10-17 17:13 UTC (permalink / raw)
  To: Mark Rutland, linux-arm-kernel; +Cc: Marc Zyngier, Will Deacon, kvmarm

On 17/10/18 17:42, Mark Rutland wrote:
> 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.

FWIW,

Tested-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Christopher Dall <christoffer.dall@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: kvmarm@lists.cs.columbia.edu
> ---
>   virt/kvm/arm/arm.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
> index c92053bc3f96..8fb31a7cc22c 100644
> --- a/virt/kvm/arm/arm.c
> +++ b/virt/kvm/arm/arm.c
> @@ -1295,8 +1295,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_reset(void)
> @@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
>   		cpu_init_hyp_mode(NULL);
>   	}
>   
> +	kvm_arm_init_debug();
> +
>   	if (vgic_present)
>   		kvm_vgic_init_cpu_hardware();
>   }
> 

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

* [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value
@ 2018-10-17 17:13   ` Robin Murphy
  0 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2018-10-17 17:13 UTC (permalink / raw)
  To: linux-arm-kernel

On 17/10/18 17:42, Mark Rutland wrote:
> 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.

FWIW,

Tested-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Christopher Dall <christoffer.dall@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: kvmarm at lists.cs.columbia.edu
> ---
>   virt/kvm/arm/arm.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
> index c92053bc3f96..8fb31a7cc22c 100644
> --- a/virt/kvm/arm/arm.c
> +++ b/virt/kvm/arm/arm.c
> @@ -1295,8 +1295,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_reset(void)
> @@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void)
>   		cpu_init_hyp_mode(NULL);
>   	}
>   
> +	kvm_arm_init_debug();
> +
>   	if (vgic_present)
>   		kvm_vgic_init_cpu_hardware();
>   }
> 

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

end of thread, other threads:[~2018-10-17 17:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17 16:42 [PATCH] kvm: arm64: fix caching of host MDCR_EL2 value Mark Rutland
2018-10-17 16:42 ` Mark Rutland
2018-10-17 16:51 ` Marc Zyngier
2018-10-17 16:51   ` Marc Zyngier
2018-10-17 17:13 ` Robin Murphy
2018-10-17 17:13   ` Robin Murphy

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.