Skip to content

Commit f6be563

Browse files
pfedinMarc Zyngier
authored and
Marc Zyngier
committed
arm64: KVM: Get rid of old vcpu_reg()
Using oldstyle vcpu_reg() accessor is proven to be inappropriate and unsafe on ARM64. This patch converts the rest of use cases to new accessors and completely removes vcpu_reg() on ARM64. Signed-off-by: Pavel Fedin <p.fedin@samsung.com> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 2ec5be3 commit f6be563

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

arch/arm/kvm/psci.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
7575
unsigned long context_id;
7676
phys_addr_t target_pc;
7777

78-
cpu_id = *vcpu_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK;
78+
cpu_id = vcpu_get_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK;
7979
if (vcpu_mode_is_32bit(source_vcpu))
8080
cpu_id &= ~((u32) 0);
8181

@@ -94,8 +94,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
9494
return PSCI_RET_INVALID_PARAMS;
9595
}
9696

97-
target_pc = *vcpu_reg(source_vcpu, 2);
98-
context_id = *vcpu_reg(source_vcpu, 3);
97+
target_pc = vcpu_get_reg(source_vcpu, 2);
98+
context_id = vcpu_get_reg(source_vcpu, 3);
9999

100100
kvm_reset_vcpu(vcpu);
101101

@@ -114,7 +114,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
114114
* NOTE: We always update r0 (or x0) because for PSCI v0.1
115115
* the general puspose registers are undefined upon CPU_ON.
116116
*/
117-
*vcpu_reg(vcpu, 0) = context_id;
117+
vcpu_set_reg(vcpu, 0, context_id);
118118
vcpu->arch.power_off = false;
119119
smp_mb(); /* Make sure the above is visible */
120120

@@ -134,8 +134,8 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
134134
struct kvm *kvm = vcpu->kvm;
135135
struct kvm_vcpu *tmp;
136136

137-
target_affinity = *vcpu_reg(vcpu, 1);
138-
lowest_affinity_level = *vcpu_reg(vcpu, 2);
137+
target_affinity = vcpu_get_reg(vcpu, 1);
138+
lowest_affinity_level = vcpu_get_reg(vcpu, 2);
139139

140140
/* Determine target affinity mask */
141141
target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
@@ -209,7 +209,7 @@ int kvm_psci_version(struct kvm_vcpu *vcpu)
209209
static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
210210
{
211211
int ret = 1;
212-
unsigned long psci_fn = *vcpu_reg(vcpu, 0) & ~((u32) 0);
212+
unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
213213
unsigned long val;
214214

215215
switch (psci_fn) {
@@ -273,13 +273,13 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
273273
break;
274274
}
275275

276-
*vcpu_reg(vcpu, 0) = val;
276+
vcpu_set_reg(vcpu, 0, val);
277277
return ret;
278278
}
279279

280280
static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
281281
{
282-
unsigned long psci_fn = *vcpu_reg(vcpu, 0) & ~((u32) 0);
282+
unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
283283
unsigned long val;
284284

285285
switch (psci_fn) {
@@ -295,7 +295,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
295295
break;
296296
}
297297

298-
*vcpu_reg(vcpu, 0) = val;
298+
vcpu_set_reg(vcpu, 0, val);
299299
return 1;
300300
}
301301

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,10 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
100100
}
101101

102102
/*
103-
* vcpu_reg should always be passed a register number coming from a
104-
* read of ESR_EL2. Otherwise, it may give the wrong result on AArch32
105-
* with banked registers.
103+
* vcpu_get_reg and vcpu_set_reg should always be passed a register number
104+
* coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
105+
* AArch32 with banked registers.
106106
*/
107-
static inline unsigned long *vcpu_reg(const struct kvm_vcpu *vcpu, u8 reg_num)
108-
{
109-
return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.regs[reg_num];
110-
}
111-
112107
static inline unsigned long vcpu_get_reg(const struct kvm_vcpu *vcpu,
113108
u8 reg_num)
114109
{

arch/arm64/kvm/handle_exit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
3737
{
3838
int ret;
3939

40-
trace_kvm_hvc_arm64(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
40+
trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0),
4141
kvm_vcpu_hvc_get_imm(vcpu));
4242

4343
ret = kvm_psci_call(vcpu);

0 commit comments

Comments
 (0)