diff mbox

[v9,08/12] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO

Message ID 1397542455-354-9-git-send-email-anup.patel@linaro.org
State New
Headers show

Commit Message

Anup Patel April 15, 2014, 6:14 a.m. UTC
This patch adds emulation of PSCI v0.2 AFFINITY_INFO function call
for KVM ARM/ARM64. This is a VCPU-level function call which will be
used to determine current state of given affinity level.

Signed-off-by: Anup Patel <anup.patel@linaro.org>
Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 arch/arm/kvm/psci.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

Comments

Marc Zyngier April 15, 2014, 10:55 a.m. UTC | #1
On Tue, Apr 15 2014 at  7:14:11 am BST, Anup Patel <anup.patel@linaro.org> wrote:
> This patch adds emulation of PSCI v0.2 AFFINITY_INFO function call
> for KVM ARM/ARM64. This is a VCPU-level function call which will be
> used to determine current state of given affinity level.
>
> Signed-off-by: Anup Patel <anup.patel@linaro.org>
> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
>  arch/arm/kvm/psci.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
> index b964aa4..f6f9290 100644
> --- a/arch/arm/kvm/psci.c
> +++ b/arch/arm/kvm/psci.c
> @@ -27,6 +27,16 @@
>   * as described in ARM document number ARM DEN 0022A.
>   */
>  
> +#define AFFINITY_MASK(level)	~((0x1UL << ((level) * 8)) - 1)

Nit: Use MPIDR_LEVEL_MASK instead of 8.

> +
> +static unsigned long psci_affinity_mask(unsigned long affinity_level)
> +{
> +	if (affinity_level <= 3)
> +		return MPIDR_HWID_BITMASK & AFFINITY_MASK(affinity_level);
> +
> +	return 0;
> +}
> +
>  static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu)
>  {
>  	vcpu->arch.pause = true;
> @@ -85,6 +95,42 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
>  	return PSCI_RET_SUCCESS;
>  }
>  
> +static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
> +{
> +	int i;
> +	unsigned long mpidr;
> +	unsigned long target_affinity;
> +	unsigned long target_affinity_mask;
> +	unsigned long lowest_affinity_level;
> +	struct kvm *kvm = vcpu->kvm;
> +	struct kvm_vcpu *tmp;
> +
> +	target_affinity = *vcpu_reg(vcpu, 1);
> +	lowest_affinity_level = *vcpu_reg(vcpu, 2);
> +
> +	/* Determine target affinity mask */
> +	target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
> +	if (!target_affinity_mask)
> +		return PSCI_RET_INVALID_PARAMS;
> +
> +	/* Ignore other bits of target affinity */
> +	target_affinity &= target_affinity_mask;
> +
> +	/*
> +	 * If one or more VCPU matching target affinity are running
> +	 * then return 0 (ON) else return 1 (OFF)

Would be good to define symbolic values for these (and for ON_PENDING as
well).

> +	 */
> +	kvm_for_each_vcpu(i, tmp, kvm) {
> +		mpidr = kvm_vcpu_get_mpidr(tmp);
> +		if (((mpidr & target_affinity_mask) == target_affinity) &&
> +		    !tmp->arch.pause) {
> +			return 0;
> +		}
> +	}
> +
> +	return 1;
> +}
> +
>  static inline void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type)
>  {
>  	memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
> @@ -132,6 +178,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
>  	case PSCI_0_2_FN64_CPU_ON:
>  		val = kvm_psci_vcpu_on(vcpu);
>  		break;
> +	case PSCI_0_2_FN_AFFINITY_INFO:
> +	case PSCI_0_2_FN64_AFFINITY_INFO:
> +		val = kvm_psci_vcpu_affinity_info(vcpu);
> +		break;
>  	case PSCI_0_2_FN_SYSTEM_OFF:
>  		kvm_psci_system_off(vcpu);
>  		val = PSCI_RET_SUCCESS;
> @@ -143,12 +193,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
>  		ret = 0;
>  		break;
>  	case PSCI_0_2_FN_CPU_SUSPEND:
> -	case PSCI_0_2_FN_AFFINITY_INFO:
>  	case PSCI_0_2_FN_MIGRATE:
>  	case PSCI_0_2_FN_MIGRATE_INFO_TYPE:
>  	case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
>  	case PSCI_0_2_FN64_CPU_SUSPEND:
> -	case PSCI_0_2_FN64_AFFINITY_INFO:
>  	case PSCI_0_2_FN64_MIGRATE:
>  	case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:
>  		val = PSCI_RET_NOT_SUPPORTED;
Anup Patel April 15, 2014, 11:15 a.m. UTC | #2
On Tue, Apr 15, 2014 at 4:25 PM, Marc Zyngier <marc.zyngier@arm.com> wrote:
> On Tue, Apr 15 2014 at  7:14:11 am BST, Anup Patel <anup.patel@linaro.org> wrote:
>> This patch adds emulation of PSCI v0.2 AFFINITY_INFO function call
>> for KVM ARM/ARM64. This is a VCPU-level function call which will be
>> used to determine current state of given affinity level.
>>
>> Signed-off-by: Anup Patel <anup.patel@linaro.org>
>> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
>> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
>> ---
>>  arch/arm/kvm/psci.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 50 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
>> index b964aa4..f6f9290 100644
>> --- a/arch/arm/kvm/psci.c
>> +++ b/arch/arm/kvm/psci.c
>> @@ -27,6 +27,16 @@
>>   * as described in ARM document number ARM DEN 0022A.
>>   */
>>
>> +#define AFFINITY_MASK(level) ~((0x1UL << ((level) * 8)) - 1)
>
> Nit: Use MPIDR_LEVEL_MASK instead of 8.

OK, will use MPIDR_LEVEL_MASK here.

>
>> +
>> +static unsigned long psci_affinity_mask(unsigned long affinity_level)
>> +{
>> +     if (affinity_level <= 3)
>> +             return MPIDR_HWID_BITMASK & AFFINITY_MASK(affinity_level);
>> +
>> +     return 0;
>> +}
>> +
>>  static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu)
>>  {
>>       vcpu->arch.pause = true;
>> @@ -85,6 +95,42 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
>>       return PSCI_RET_SUCCESS;
>>  }
>>
>> +static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
>> +{
>> +     int i;
>> +     unsigned long mpidr;
>> +     unsigned long target_affinity;
>> +     unsigned long target_affinity_mask;
>> +     unsigned long lowest_affinity_level;
>> +     struct kvm *kvm = vcpu->kvm;
>> +     struct kvm_vcpu *tmp;
>> +
>> +     target_affinity = *vcpu_reg(vcpu, 1);
>> +     lowest_affinity_level = *vcpu_reg(vcpu, 2);
>> +
>> +     /* Determine target affinity mask */
>> +     target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
>> +     if (!target_affinity_mask)
>> +             return PSCI_RET_INVALID_PARAMS;
>> +
>> +     /* Ignore other bits of target affinity */
>> +     target_affinity &= target_affinity_mask;
>> +
>> +     /*
>> +      * If one or more VCPU matching target affinity are running
>> +      * then return 0 (ON) else return 1 (OFF)
>
> Would be good to define symbolic values for these (and for ON_PENDING as
> well).

Sure, I will add them to uapi/linux/psci.h

>
>> +      */
>> +     kvm_for_each_vcpu(i, tmp, kvm) {
>> +             mpidr = kvm_vcpu_get_mpidr(tmp);
>> +             if (((mpidr & target_affinity_mask) == target_affinity) &&
>> +                 !tmp->arch.pause) {
>> +                     return 0;
>> +             }
>> +     }
>> +
>> +     return 1;
>> +}
>> +
>>  static inline void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type)
>>  {
>>       memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
>> @@ -132,6 +178,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
>>       case PSCI_0_2_FN64_CPU_ON:
>>               val = kvm_psci_vcpu_on(vcpu);
>>               break;
>> +     case PSCI_0_2_FN_AFFINITY_INFO:
>> +     case PSCI_0_2_FN64_AFFINITY_INFO:
>> +             val = kvm_psci_vcpu_affinity_info(vcpu);
>> +             break;
>>       case PSCI_0_2_FN_SYSTEM_OFF:
>>               kvm_psci_system_off(vcpu);
>>               val = PSCI_RET_SUCCESS;
>> @@ -143,12 +193,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
>>               ret = 0;
>>               break;
>>       case PSCI_0_2_FN_CPU_SUSPEND:
>> -     case PSCI_0_2_FN_AFFINITY_INFO:
>>       case PSCI_0_2_FN_MIGRATE:
>>       case PSCI_0_2_FN_MIGRATE_INFO_TYPE:
>>       case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
>>       case PSCI_0_2_FN64_CPU_SUSPEND:
>> -     case PSCI_0_2_FN64_AFFINITY_INFO:
>>       case PSCI_0_2_FN64_MIGRATE:
>>       case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:
>>               val = PSCI_RET_NOT_SUPPORTED;
>
> --
> Jazz is not dead. It just smells funny.
> _______________________________________________
> kvmarm mailing list
> kvmarm@lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

--
Anup
diff mbox

Patch

diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
index b964aa4..f6f9290 100644
--- a/arch/arm/kvm/psci.c
+++ b/arch/arm/kvm/psci.c
@@ -27,6 +27,16 @@ 
  * as described in ARM document number ARM DEN 0022A.
  */
 
+#define AFFINITY_MASK(level)	~((0x1UL << ((level) * 8)) - 1)
+
+static unsigned long psci_affinity_mask(unsigned long affinity_level)
+{
+	if (affinity_level <= 3)
+		return MPIDR_HWID_BITMASK & AFFINITY_MASK(affinity_level);
+
+	return 0;
+}
+
 static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu)
 {
 	vcpu->arch.pause = true;
@@ -85,6 +95,42 @@  static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
 	return PSCI_RET_SUCCESS;
 }
 
+static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
+{
+	int i;
+	unsigned long mpidr;
+	unsigned long target_affinity;
+	unsigned long target_affinity_mask;
+	unsigned long lowest_affinity_level;
+	struct kvm *kvm = vcpu->kvm;
+	struct kvm_vcpu *tmp;
+
+	target_affinity = *vcpu_reg(vcpu, 1);
+	lowest_affinity_level = *vcpu_reg(vcpu, 2);
+
+	/* Determine target affinity mask */
+	target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
+	if (!target_affinity_mask)
+		return PSCI_RET_INVALID_PARAMS;
+
+	/* Ignore other bits of target affinity */
+	target_affinity &= target_affinity_mask;
+
+	/*
+	 * If one or more VCPU matching target affinity are running
+	 * then return 0 (ON) else return 1 (OFF)
+	 */
+	kvm_for_each_vcpu(i, tmp, kvm) {
+		mpidr = kvm_vcpu_get_mpidr(tmp);
+		if (((mpidr & target_affinity_mask) == target_affinity) &&
+		    !tmp->arch.pause) {
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
 static inline void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type)
 {
 	memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
@@ -132,6 +178,10 @@  static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
 	case PSCI_0_2_FN64_CPU_ON:
 		val = kvm_psci_vcpu_on(vcpu);
 		break;
+	case PSCI_0_2_FN_AFFINITY_INFO:
+	case PSCI_0_2_FN64_AFFINITY_INFO:
+		val = kvm_psci_vcpu_affinity_info(vcpu);
+		break;
 	case PSCI_0_2_FN_SYSTEM_OFF:
 		kvm_psci_system_off(vcpu);
 		val = PSCI_RET_SUCCESS;
@@ -143,12 +193,10 @@  static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
 		ret = 0;
 		break;
 	case PSCI_0_2_FN_CPU_SUSPEND:
-	case PSCI_0_2_FN_AFFINITY_INFO:
 	case PSCI_0_2_FN_MIGRATE:
 	case PSCI_0_2_FN_MIGRATE_INFO_TYPE:
 	case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
 	case PSCI_0_2_FN64_CPU_SUSPEND:
-	case PSCI_0_2_FN64_AFFINITY_INFO:
 	case PSCI_0_2_FN64_MIGRATE:
 	case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:
 		val = PSCI_RET_NOT_SUPPORTED;