Skip to content

Commit 0b12620

Browse files
Alexandru Eliseictmarinas
authored andcommitted
KVM: arm64: Treat ESR_EL2 as a 64-bit register
ESR_EL2 was defined as a 32-bit register in the initial release of the ARM Architecture Manual for Armv8-A, and was later extended to 64 bits, with bits [63:32] RES0. ARMv8.7 introduced FEAT_LS64, which makes use of bits [36:32]. KVM treats ESR_EL1 as a 64-bit register when saving and restoring the guest context, but ESR_EL2 is handled as a 32-bit register. Start treating ESR_EL2 as a 64-bit register to allow KVM to make use of the most significant 32 bits in the future. The type chosen to represent ESR_EL2 is u64, as that is consistent with the notation KVM overwhelmingly uses today (u32), and how the rest of the registers are declared. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20220425114444.368693-5-alexandru.elisei@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 8d56e5c commit 0b12620

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu)
235235
return mode != PSR_MODE_EL0t;
236236
}
237237

238-
static __always_inline u32 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
238+
static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
239239
{
240240
return vcpu->arch.fault.esr_el2;
241241
}
242242

243243
static __always_inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu)
244244
{
245-
u32 esr = kvm_vcpu_get_esr(vcpu);
245+
u64 esr = kvm_vcpu_get_esr(vcpu);
246246

247247
if (esr & ESR_ELx_CV)
248248
return (esr & ESR_ELx_COND_MASK) >> ESR_ELx_COND_SHIFT;
@@ -373,7 +373,7 @@ static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu)
373373

374374
static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
375375
{
376-
u32 esr = kvm_vcpu_get_esr(vcpu);
376+
u64 esr = kvm_vcpu_get_esr(vcpu);
377377
return ESR_ELx_SYS64_ISS_RT(esr);
378378
}
379379

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct kvm_arch {
153153
};
154154

155155
struct kvm_vcpu_fault_info {
156-
u32 esr_el2; /* Hyp Syndrom Register */
156+
u64 esr_el2; /* Hyp Syndrom Register */
157157
u64 far_el2; /* Hyp Fault Address Register */
158158
u64 hpfar_el2; /* Hyp IPA Fault Address Register */
159159
u64 disr_el1; /* Deferred [SError] Status Register */

arch/arm64/include/asm/kvm_ras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Was this synchronous external abort a RAS notification?
1515
* Returns '0' for errors handled by some RAS subsystem, or -ENOENT.
1616
*/
17-
static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr)
17+
static inline int kvm_handle_guest_sea(phys_addr_t addr, u64 esr)
1818
{
1919
/* apei_claim_sea(NULL) expects to mask interrupts itself */
2020
lockdep_assert_irqs_enabled();

arch/arm64/kvm/handle_exit.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
typedef int (*exit_handle_fn)(struct kvm_vcpu *);
2828

29-
static void kvm_handle_guest_serror(struct kvm_vcpu *vcpu, u32 esr)
29+
static void kvm_handle_guest_serror(struct kvm_vcpu *vcpu, u64 esr)
3030
{
3131
if (!arm64_is_ras_serror(esr) || arm64_is_fatal_ras_serror(NULL, esr))
3232
kvm_inject_vabt(vcpu);
@@ -117,10 +117,10 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
117117
static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
118118
{
119119
struct kvm_run *run = vcpu->run;
120-
u32 esr = kvm_vcpu_get_esr(vcpu);
120+
u64 esr = kvm_vcpu_get_esr(vcpu);
121121

122122
run->exit_reason = KVM_EXIT_DEBUG;
123-
run->debug.arch.hsr = esr;
123+
run->debug.arch.hsr = lower_32_bits(esr);
124124

125125
if (ESR_ELx_EC(esr) == ESR_ELx_EC_WATCHPT_LOW)
126126
run->debug.arch.far = vcpu->arch.fault.far_el2;
@@ -130,9 +130,9 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
130130

131131
static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)
132132
{
133-
u32 esr = kvm_vcpu_get_esr(vcpu);
133+
u64 esr = kvm_vcpu_get_esr(vcpu);
134134

135-
kvm_pr_unimpl("Unknown exception class: esr: %#08x -- %s\n",
135+
kvm_pr_unimpl("Unknown exception class: esr: %#016llx -- %s\n",
136136
esr, esr_get_class_string(esr));
137137

138138
kvm_inject_undefined(vcpu);
@@ -187,7 +187,7 @@ static exit_handle_fn arm_exit_handlers[] = {
187187

188188
static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
189189
{
190-
u32 esr = kvm_vcpu_get_esr(vcpu);
190+
u64 esr = kvm_vcpu_get_esr(vcpu);
191191
u8 esr_ec = ESR_ELx_EC(esr);
192192

193193
return arm_exit_handlers[esr_ec];
@@ -334,6 +334,6 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
334334
*/
335335
kvm_err("Hyp Offset: 0x%llx\n", hyp_offset);
336336

337-
panic("HYP panic:\nPS:%08llx PC:%016llx ESR:%08llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%016lx\n",
337+
panic("HYP panic:\nPS:%08llx PC:%016llx ESR:%016llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%016lx\n",
338338
spsr, elr_virt, esr, far, hpfar, par, vcpu);
339339
}

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static inline bool handle_tx2_tvm(struct kvm_vcpu *vcpu)
266266
return true;
267267
}
268268

269-
static inline bool esr_is_ptrauth_trap(u32 esr)
269+
static inline bool esr_is_ptrauth_trap(u64 esr)
270270
{
271271
switch (esr_sys64_to_sysreg(esr)) {
272272
case SYS_APIAKEYLO_EL1:

arch/arm64/kvm/hyp/nvhe/sys_regs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ u64 id_aa64mmfr2_el1_sys_val;
3333
*/
3434
static void inject_undef64(struct kvm_vcpu *vcpu)
3535
{
36-
u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
36+
u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
3737

3838
*vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
3939
*vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);

arch/arm64/kvm/hyp/vgic-v3-sr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int __vgic_v3_bpr_min(void)
473473

474474
static int __vgic_v3_get_group(struct kvm_vcpu *vcpu)
475475
{
476-
u32 esr = kvm_vcpu_get_esr(vcpu);
476+
u64 esr = kvm_vcpu_get_esr(vcpu);
477477
u8 crm = (esr & ESR_ELx_SYS64_ISS_CRM_MASK) >> ESR_ELx_SYS64_ISS_CRM_SHIFT;
478478

479479
return crm != 8;
@@ -1016,7 +1016,7 @@ static void __vgic_v3_write_ctlr(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
10161016
int __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
10171017
{
10181018
int rt;
1019-
u32 esr;
1019+
u64 esr;
10201020
u32 vmcr;
10211021
void (*fn)(struct kvm_vcpu *, u32, int);
10221022
bool is_read;

arch/arm64/kvm/inject_fault.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr
1818
{
1919
unsigned long cpsr = *vcpu_cpsr(vcpu);
2020
bool is_aarch32 = vcpu_mode_is_32bit(vcpu);
21-
u32 esr = 0;
21+
u64 esr = 0;
2222

2323
vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 |
2424
KVM_ARM64_EXCEPT_AA64_ELx_SYNC |
@@ -50,7 +50,7 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr
5050

5151
static void inject_undef64(struct kvm_vcpu *vcpu)
5252
{
53-
u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
53+
u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
5454

5555
vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 |
5656
KVM_ARM64_EXCEPT_AA64_ELx_SYNC |

arch/arm64/kvm/sys_regs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ static int kvm_handle_cp_64(struct kvm_vcpu *vcpu,
23042304
size_t nr_global)
23052305
{
23062306
struct sys_reg_params params;
2307-
u32 esr = kvm_vcpu_get_esr(vcpu);
2307+
u64 esr = kvm_vcpu_get_esr(vcpu);
23082308
int Rt = kvm_vcpu_sys_get_rt(vcpu);
23092309
int Rt2 = (esr >> 10) & 0x1f;
23102310

@@ -2354,7 +2354,7 @@ static int kvm_handle_cp_32(struct kvm_vcpu *vcpu,
23542354
size_t nr_global)
23552355
{
23562356
struct sys_reg_params params;
2357-
u32 esr = kvm_vcpu_get_esr(vcpu);
2357+
u64 esr = kvm_vcpu_get_esr(vcpu);
23582358
int Rt = kvm_vcpu_sys_get_rt(vcpu);
23592359

23602360
params.CRm = (esr >> 1) & 0xf;

0 commit comments

Comments
 (0)