Skip to content

Commit e10ecb4

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Enforce reserved bits for PSCI target affinities
According to the PSCI specification, ARM DEN 0022D, 5.1.4 "CPU_ON", the CPU_ON function takes a target_cpu argument that is bit-compatible with the affinity fields in MPIDR_EL1. All other bits in the argument are RES0. Note that the same constraints apply to the target_affinity argument for the AFFINITY_INFO call. Enforce the spec by returning INVALID_PARAMS if a guest incorrectly sets a RES0 bit. Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6826c68 commit e10ecb4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

arch/arm64/kvm/psci.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu)
5959
kvm_vcpu_kick(vcpu);
6060
}
6161

62+
static inline bool kvm_psci_valid_affinity(struct kvm_vcpu *vcpu,
63+
unsigned long affinity)
64+
{
65+
return !(affinity & ~MPIDR_HWID_BITMASK);
66+
}
67+
6268
static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
6369
{
6470
struct vcpu_reset_state *reset_state;
6571
struct kvm *kvm = source_vcpu->kvm;
6672
struct kvm_vcpu *vcpu = NULL;
6773
unsigned long cpu_id;
6874

69-
cpu_id = smccc_get_arg1(source_vcpu) & MPIDR_HWID_BITMASK;
70-
if (vcpu_mode_is_32bit(source_vcpu))
71-
cpu_id &= ~((u32) 0);
75+
cpu_id = smccc_get_arg1(source_vcpu);
76+
if (!kvm_psci_valid_affinity(source_vcpu, cpu_id))
77+
return PSCI_RET_INVALID_PARAMS;
7278

7379
vcpu = kvm_mpidr_to_vcpu(kvm, cpu_id);
7480

@@ -126,6 +132,9 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
126132
target_affinity = smccc_get_arg1(vcpu);
127133
lowest_affinity_level = smccc_get_arg2(vcpu);
128134

135+
if (!kvm_psci_valid_affinity(vcpu, target_affinity))
136+
return PSCI_RET_INVALID_PARAMS;
137+
129138
/* Determine target affinity mask */
130139
target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
131140
if (!target_affinity_mask)

0 commit comments

Comments
 (0)