Linux KVM/arm64 development list
 help / color / mirror / Atom feed
* [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores
@ 2015-09-04 15:06 Alexander Spyridakis
  2015-09-04 15:54 ` Marc Zyngier
  2015-09-04 15:55 ` Mark Rutland
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Spyridakis @ 2015-09-04 15:06 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: marc.zyngier, christoffer.dall, a.rigo, Alexander Spyridakis

If a guest requests the affinity info for a non-existing vCPU we need to
properly return an error, instead of erroneously reporting an off state.

Signed-off-by: Alexander Spyridakis <a.spyridakis@virtualopensystems.com>
Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
---
 arch/arm/kvm/psci.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
index 4b94b51..ad6f642 100644
--- a/arch/arm/kvm/psci.c
+++ b/arch/arm/kvm/psci.c
@@ -126,7 +126,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
 
 static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
 {
-	int i;
+	int i, matching_cpus = 0;
 	unsigned long mpidr;
 	unsigned long target_affinity;
 	unsigned long target_affinity_mask;
@@ -151,12 +151,16 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
 	 */
 	kvm_for_each_vcpu(i, tmp, kvm) {
 		mpidr = kvm_vcpu_get_mpidr_aff(tmp);
-		if (((mpidr & target_affinity_mask) == target_affinity) &&
-		    !tmp->arch.pause) {
-			return PSCI_0_2_AFFINITY_LEVEL_ON;
+		if ((mpidr & target_affinity_mask) == target_affinity) {
+			matching_cpus++;
+			if (!tmp->arch.pause)
+				return PSCI_0_2_AFFINITY_LEVEL_ON;
 		}
 	}
 
+	if (!matching_cpus)
+		return PSCI_RET_INVALID_PARAMS;
+
 	return PSCI_0_2_AFFINITY_LEVEL_OFF;
 }
 
-- 
2.5.1


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

* Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores
  2015-09-04 15:06 [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores Alexander Spyridakis
@ 2015-09-04 15:54 ` Marc Zyngier
  2015-09-04 16:32   ` Alexander Spyridakis
  2015-09-04 15:55 ` Mark Rutland
  1 sibling, 1 reply; 4+ messages in thread
From: Marc Zyngier @ 2015-09-04 15:54 UTC (permalink / raw)
  To: Alexander Spyridakis, kvmarm, kvm; +Cc: christoffer.dall, a.rigo

On 04/09/15 16:06, Alexander Spyridakis wrote:
> If a guest requests the affinity info for a non-existing vCPU we need to
> properly return an error, instead of erroneously reporting an off state.
> 
> Signed-off-by: Alexander Spyridakis <a.spyridakis@virtualopensystems.com>
> Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>

Seems sound to me. Out of curiosity, how was this found?

Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>

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

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

* Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores
  2015-09-04 15:06 [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores Alexander Spyridakis
  2015-09-04 15:54 ` Marc Zyngier
@ 2015-09-04 15:55 ` Mark Rutland
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Rutland @ 2015-09-04 15:55 UTC (permalink / raw)
  To: Alexander Spyridakis
  Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Marc Zyngier

On Fri, Sep 04, 2015 at 04:06:24PM +0100, Alexander Spyridakis wrote:
> If a guest requests the affinity info for a non-existing vCPU we need to
> properly return an error, instead of erroneously reporting an off state.
> 
> Signed-off-by: Alexander Spyridakis <a.spyridakis@virtualopensystems.com>
> Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>

This looks correct to me per the PSCI 0.2 spec:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Was this spotted by inspection, or do you have some client for which
this is important?

Thanks,
Mark.

> ---
>  arch/arm/kvm/psci.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
> index 4b94b51..ad6f642 100644
> --- a/arch/arm/kvm/psci.c
> +++ b/arch/arm/kvm/psci.c
> @@ -126,7 +126,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
>  
>  static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
>  {
> -	int i;
> +	int i, matching_cpus = 0;
>  	unsigned long mpidr;
>  	unsigned long target_affinity;
>  	unsigned long target_affinity_mask;
> @@ -151,12 +151,16 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
>  	 */
>  	kvm_for_each_vcpu(i, tmp, kvm) {
>  		mpidr = kvm_vcpu_get_mpidr_aff(tmp);
> -		if (((mpidr & target_affinity_mask) == target_affinity) &&
> -		    !tmp->arch.pause) {
> -			return PSCI_0_2_AFFINITY_LEVEL_ON;
> +		if ((mpidr & target_affinity_mask) == target_affinity) {
> +			matching_cpus++;
> +			if (!tmp->arch.pause)
> +				return PSCI_0_2_AFFINITY_LEVEL_ON;
>  		}
>  	}
>  
> +	if (!matching_cpus)
> +		return PSCI_RET_INVALID_PARAMS;
> +
>  	return PSCI_0_2_AFFINITY_LEVEL_OFF;
>  }
>  
> -- 
> 2.5.1
> 
> _______________________________________________
> kvmarm mailing list
> kvmarm@lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
> 

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

* Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores
  2015-09-04 15:54 ` Marc Zyngier
@ 2015-09-04 16:32   ` Alexander Spyridakis
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Spyridakis @ 2015-09-04 16:32 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: kvmarm@lists.cs.columbia.edu, KVM General

On 4 September 2015 at 17:54, Marc Zyngier <marc.zyngier@arm.com> wrote:
> Seems sound to me. Out of curiosity, how was this found?

Hello Mark,

This issue came up when testing some basic bare metal tests with KVM,
which originally were meant for the multi-threading TCG effort
(https://git.virtualopensystems.com/dev/tcg_baremetal_tests.git).
While shutting down the system the test relies on PSCI to find out if
all secondary cores are powered-off by incrementally polling PSCI for
every cpu id. In the case of QEMU/TCG everything was fine, but with
KVM there was no error response for non-existing cores, and so the
system could not shut down properly.

Kind regards.

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

end of thread, other threads:[~2015-09-04 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-04 15:06 [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores Alexander Spyridakis
2015-09-04 15:54 ` Marc Zyngier
2015-09-04 16:32   ` Alexander Spyridakis
2015-09-04 15:55 ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox