Skip to content

Commit 8bb0841

Browse files
mrutland-armMarc Zyngier
authored andcommitted
KVM: arm64: Extract ESR_ELx.EC only
Since ARMv8.0 the upper 32 bits of ESR_ELx have been RES0, and recently some of the upper bits gained a meaning and can be non-zero. For example, when FEAT_LS64 is implemented, ESR_ELx[36:32] contain ISS2, which for an ST64BV or ST64BV0 can be non-zero. This can be seen in ARM DDI 0487G.b, page D13-3145, section D13.2.37. Generally, we must not rely on RES0 bit remaining zero in future, and when extracting ESR_ELx.EC we must mask out all other bits. All C code uses the ESR_ELx_EC() macro, which masks out the irrelevant bits, and therefore no alterations are required to C code to avoid consuming irrelevant bits. In a couple of places the KVM assembly extracts ESR_ELx.EC using LSR on an X register, and so could in theory consume previously RES0 bits. In both cases this is for comparison with EC values ESR_ELx_EC_HVC32 and ESR_ELx_EC_HVC64, for which the upper bits of ESR_ELx must currently be zero, but this could change in future. This patch adjusts the KVM vectors to use UBFX rather than LSR to extract ESR_ELx.EC, ensuring these are robust to future additions to ESR_ELx. Cc: [email protected] Signed-off-by: Mark Rutland <[email protected]> Cc: Alexandru Elisei <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: James Morse <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Will Deacon <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5a2acbb commit 8bb0841

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

arch/arm64/include/asm/esr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#define ESR_ELx_EC_MAX (0x3F)
6969

7070
#define ESR_ELx_EC_SHIFT (26)
71+
#define ESR_ELx_EC_WIDTH (6)
7172
#define ESR_ELx_EC_MASK (UL(0x3F) << ESR_ELx_EC_SHIFT)
7273
#define ESR_ELx_EC(esr) (((esr) & ESR_ELx_EC_MASK) >> ESR_ELx_EC_SHIFT)
7374

arch/arm64/kvm/hyp/hyp-entry.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
el1_sync: // Guest trapped into EL2
4545

4646
mrs x0, esr_el2
47-
lsr x0, x0, #ESR_ELx_EC_SHIFT
47+
ubfx x0, x0, #ESR_ELx_EC_SHIFT, #ESR_ELx_EC_WIDTH
4848
cmp x0, #ESR_ELx_EC_HVC64
4949
ccmp x0, #ESR_ELx_EC_HVC32, #4, ne
5050
b.ne el1_trap

arch/arm64/kvm/hyp/nvhe/host.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ SYM_FUNC_END(__host_hvc)
141141
.L__vect_start\@:
142142
stp x0, x1, [sp, #-16]!
143143
mrs x0, esr_el2
144-
lsr x0, x0, #ESR_ELx_EC_SHIFT
144+
ubfx x0, x0, #ESR_ELx_EC_SHIFT, #ESR_ELx_EC_WIDTH
145145
cmp x0, #ESR_ELx_EC_HVC64
146146
b.eq __host_hvc
147147
b __host_exit

0 commit comments

Comments
 (0)