KVM: arm64: Fix missing ESR_ELx.IL in syndrome injection
v2 cover KVM: arm64: Fix missing ESR_ELx.IL in syndrome injection
Hi folks,
After sashiko caught the missing IL bug [1], I did an audit of all ESR syndrome construction sites in KVM/arm64 as Marc suggested. This series is the result of that audit.
The ARM architecture mandates ESR_ELx.IL=1 for several exception classes regardless of instruction length: EC=Unknown, Instruction Aborts, Data Aborts with ISV=0, and SError. For FPAC (EC=0x1C), IL reflects instruction length, but FPAC can only be generated by A64 instructions, so IL must also be 1.
Patch 1 is the bug sashiko found: inject_undef64() in the pKVM hyp (EL2) path never set IL. Patch 2 makes the same fix to inject_undef64() in the normal host path, where IL was derived from the triggering trap's instruction length. No instruction that reaches undef injection has a 16-bit encoding, so patch 2 has no functional change today. Patch 3 makes the matching fix to inject_abt64(). Unlike undef injection, abort injection is reachable from a 16-bit T32 instruction (a 32-bit EL0 task under an AArch64 EL1 guest), so the old code there injects an abort with IL=0.
Patch 4 fixes the FPAC syndrome constructed during nested ERET emulation, which did not set IL.
Patches 5-6 fix SError injection in the emulated and nested paths, neither of which set IL.
Patch 7 fixes a fake ESR used to exit to the host. The host does not read IL there, so it is not guest-visible.
Changes since v1 [2]:
- Patch 4: keep IL by masking it through from the trapped ERET's ESR instead of OR-ing the bit in. The ERET trap (EC=0x1A) always reports IL=1, so this preserves the source syndrome rather than adding the bit unconditionally (Marc).
- Rebased on v7.1.
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (7):
KVM: arm64: Set ESR_ELx.IL for injected undefined exceptions at EL2
KVM: arm64: Unconditionally set IL for injected undefined exceptions
KVM: arm64: Unconditionally set IL for injected abort exceptions
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
KVM: arm64: Set IL for emulated SError injection
KVM: arm64: Set IL for nested SError injection
KVM: arm64: Set IL in fake ESR for pKVM memory sharing exit
arch/arm64/kvm/emulate-nested.c | 4 ++-- arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 ++- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 +- arch/arm64/kvm/inject_fault.c | 18 +++++------------- 4 files changed, 10 insertions(+), 17 deletions(-)
Signature · 1 line
2.54.0.1189.g8c84645362-goog
PATCH v2 1/7 KVM: arm64: Set ESR_ELx.IL for injected undefined exceptions at EL2
inject_undef64() constructs an ESR with EC=0 (Unknown) but does not set IL. The architecture mandates IL=1 for EC=0 unconditionally (ARM DDI 0487, ESR_ELx.IL description), so the injected syndrome is one that conforming hardware cannot produce.
Set ESR_ELx_IL in the constructed syndrome.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +1 -1
@@ -278,7 +278,7 @@ static void inject_sync64(struct kvm_vcpu *vcpu, u64 esr)*/ static void inject_undef64 (struct kvm_vcpu *vcpu) { -inject_sync64 (vcpu, (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT)); +inject_sync64 (vcpu, (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT) | ESR_ELx_IL); } static u64 read_id_reg(const struct kvm_vcpu *vcpu,
Signature · 1 line
2.54.0.1189.g8c84645362-goog
PATCH v2 2/7 KVM: arm64: Unconditionally set IL for injected undefined exceptions
In reply to Fuad Tabbainject_undef64() derives IL from the triggering trap's instruction length (kvm_vcpu_trap_il_is32bit()), but the IL of the injected exception is fixed by its EC, not by the triggering instruction. The architecture mandates IL=1 for EC=0 (Unknown) unconditionally, so the conditional is wrong. The undef-injection paths are not reached from 16-bit instructions, so there is no functional change today, but the logic should not rely on that.
Set ESR_ELx_IL unconditionally.
--- arch/arm64/kvm/inject_fault.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm64/kvm/inject_fault.c +1 -8
@@ -170,14 +170,7 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)static void inject_undef64 (struct kvm_vcpu *vcpu) { -u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); - -/* -* Build an unknown exception, depending on the instruction -* set. -*/ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; +u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT) | ESR_ELx_IL;kvm_inject_sync (vcpu, esr); }
Signature · 1 line
2.54.0.1189.g8c84645362-goog
[email protected]
AI reviewRe: [PATCH v2 2/7] KVM: arm64: Unconditionally set IL for injected undefined exceptions
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Nested SError exception injection silently drops the ESR_EL2 value. --
commit e7d1337c1e8d6db55c7b9ce2682f4c52e85c3f44
Author: Fuad Tabba <[email protected]>
KVM: arm64: Unconditionally set IL for injected undefined exceptions
This commit simplifies the inject_undef64() exception injection path by unconditionally setting the IL bit, as the architecture mandates IL=1 for EC=0 (Unknown).
Quoted 10 lines
arch/arm64/kvm/inject_fault.c +0
-2@@ -170,14 +170,7 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)static void inject_undef64 (struct kvm_vcpu *vcpu) { -u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); -
arch/arm64/kvm/inject_fault.c void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr) · line 176
Quoted 10 lines
arch/arm64/kvm/inject_fault.c +1
-6-/* -* Build an unknown exception, depending on the instruction -* set. -*/ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; +u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT) | ESR_ELx_IL;kvm_inject_sync (vcpu, esr); }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the exception injection changes, I noticed a pre-existing issue in the nested SError injection path.
In arch/arm64/kvm/emulate-nested.c, kvm_inject_nested_serror() constructs the ESR for the nested SError and passes it down to kvm_inject_nested():
arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_serror() {
...
esr |= FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR);
return kvm_inject_nested(vcpu, esr, except_type_serror);
}However, when this esr reaches kvm_inject_el2_exception(), the value is silently discarded:
arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception() {
...
switch (type) {
case except_type_sync:
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SYNC);
vcpu_write_sys_reg(vcpu, esr_el2, ESR_EL2);
break;
case except_type_irq:
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_IRQ);
break;
case except_type_serror:
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR);
break;
...
}Because the except_type_serror case breaks without writing esr_el2 to ESR_EL2 (unlike the except_type_sync case), the constructed syndrome is completely dropped.
Since enter_exception64() does not dynamically update ESR_ELx, will the guest hypervisor observe a stale ESR_EL2 when handling the injected SError?
Could this cause the guest to misinterpret the error, potentially leading to incorrect functional behavior or a guest panic?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/7] KVM: arm64: Unconditionally set IL for injected undefined exceptions
Quoted 74 lines · On Thu, 18 Jun 2026 at 13:30, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Nested SError exception injection silently drops theESR_EL2value. --commit
e7d1337c1e8d6db55c7b9ce2682f4c52e85c3f44
Author: Fuad Tabba <[email protected]>KVM: arm64: Unconditionally set IL for injected undefined exceptions
This commit simplifies the
inject_undef64()exception injection path by unconditionally setting the IL bit, as the architecture mandates IL=1 for EC=0 (Unknown).Quoted 10 lines
arch/arm64/kvm/inject_fault.c +0
-2@@ -170,14 +170,7 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)static void inject_undef64 (struct kvm_vcpu *vcpu) { -u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); -arch/arm64/kvm/inject_fault.c void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr) · line 176
Quoted 10 lines
arch/arm64/kvm/inject_fault.c +1
-6-/* -* Build an unknown exception, depending on the instruction -* set. -*/ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; +u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT) | ESR_ELx_IL;kvm_inject_sync (vcpu, esr); }[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the exception injection changes, I noticed a pre-existing issue in the nested SError injection path.In
arch/arm64/kvm/emulate-nested.c,kvm_inject_nested_serror()constructs the ESR for the nested SError and passes it down tokvm_inject_nested():arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_serror() { ... esr |= FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); return kvm_inject_nested(vcpu, esr, except_type_serror); }However, when this esr reaches
kvm_inject_el2_exception(), the value is silently discarded:arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception() { ... switch (type) { case except_type_sync: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SYNC); vcpu_write_sys_reg(vcpu, esr_el2, ESR_EL2); break; case except_type_irq: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_IRQ); break; case except_type_serror: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR); break; ... }Because the
except_type_serrorcase breaks without writingesr_el2toESR_EL2(unlike theexcept_type_synccase), the constructed syndrome is completely dropped.
Quoted 5 lines
Since
enter_exception64()does not dynamically updateESR_ELx, will the guest hypervisor observe a staleESR_EL2when handling the injected SError?Could this cause the guest to misinterpret the error, potentially leading to incorrect functional behavior or a guest panic?
IL=1 is correct here. The architecture mandates IL=1 for any Instruction Abort unconditionally, and for any Data Abort where ISV=0 (ARM ARM, ESR_ELx IL bit definition). IL only reflects the faulting instruction length when ISV=1.
This function never sets ISV. The FSC is always EXTABT or SEA_TTW, and FEAT_RAS mandates ISV=0 for any synchronous external abort. The Address Size Fault case (kvm_inject_size_fault overwriting FSC to 0) also has ISV=0 since address size faults are detected during translation table walks with no valid instruction syndrome.
The old code copying IL from the hardware trap ESR was the bug: it produced IL=0 for a 16-bit Thumb instruction, which is wrong for an ISV=0 data abort.
Cheers,
/fuad
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v2 3/7 KVM: arm64: Unconditionally set IL for injected abort exceptions
In reply to Fuad Tabbainject_abt64() derives IL from the triggering trap's instruction length (kvm_vcpu_trap_il_is32bit()), but the IL of the injected abort is fixed by its EC, not by the triggering instruction. The architecture mandates IL=1 for Instruction Aborts unconditionally and for Data Aborts with ISV=0, and this function never sets ISV (the FSC is always EXTABT or SEA_TTW). For a 16-bit T32 trap (a 32-bit EL0 task under an AArch64 EL1 guest) the trap has IL=0, so the abort is injected with the wrong IL.
Set ESR_ELx_IL unconditionally.
--- arch/arm64/kvm/inject_fault.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/arm64/kvm/inject_fault.c +3 -4
@@ -138,11 +138,10 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addrpend_sync_exception (vcpu);/* -* Build an {i,d}abort, depending on the level and the -* instruction set. Report an external synchronous abort. +* Build an {i,d}abort, depending on the level. +* Report an external synchronous abort. */ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; + esr |= ESR_ELx_IL;/* * Here, the guest runs in AArch64 mode when in EL1. If we get
Signature · 1 line
2.54.0.1189.g8c84645362-goog
[email protected]
AI reviewRe: [PATCH v2 3/7] KVM: arm64: Unconditionally set IL for injected abort exceptions
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unconditional IL=1 in inject_abt64() creates invalid ESR state for Address Size faults. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditional IL=1 in inject_abt64() creates invalid ESR state for Address Size faults. --
commit 5d93cc0ddb43cdfa88e555d446e07e55b7334637
Author: Fuad Tabba <[email protected]>
KVM: arm64: Unconditionally set IL for injected abort exceptions
This commit unconditionally sets the ESR_ELx_IL bit to 1 for injected aborts, assuming the FSC is always EXTABT or SEA_TTW.
Quoted 4 lines
arch/arm64/kvm/inject_fault.c +0
-0
[ ... ]
arch/arm64/kvm/inject_fault.c static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr · line 144
Quoted 12 lines
arch/arm64/kvm/inject_fault.c +3
-4@@ -138,11 +138,10 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addrpend_sync_exception (vcpu);/* -* Build an {i,d}abort, depending on the level and the -* instruction set. Report an external synchronous abort. +* Build an {i,d}abort, depending on the level. +* Report an external synchronous abort. */ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; + esr |= ESR_ELx_IL;
[Severity: High]
Does this unconditional setting of IL=1 cause an architecturally invalid syndrome for Address Size faults?
If a guest executing in AArch32 EL0 issues a 16-bit instruction (such as a 16-bit LDR) that triggers a Stage-2 Address Size fault, the IL bit should accurately reflect the size of the trapped instruction (0 for 16-bit).
Looking at kvm_inject_size_fault(), it injects the abort by calling inject_abt64() via the __kvm_inject_sea() call chain, and then modifies the FSC to 0 (Address Size Fault):
arch/arm64/kvm/inject_fault.c:kvm_inject_size_fault() {
...
/* inject_abt64() forces IL=1 earlier in the call chain */
...
esr &= ~GENMASK_ULL(5, 0);
vcpu_write_sys_reg(vcpu, esr, exception_esr_elx(vcpu));
...
}Will KVM now inject the Address Size fault with IL=1 instead of IL=0, potentially causing the guest OS exception handler to incorrectly advance the Program Counter by 4 bytes instead of 2 during fault unwinding?
Quoted 3 lines
arch/arm64/kvm/inject_fault.c +0
-0/* * Here, the guest runs in AArch64 mode when in EL1. If we get
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v2 3/7] KVM: arm64: Unconditionally set IL for injected abort exceptions
Quoted 54 lines · On Thu, 18 Jun 2026 at 13:29, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditional IL=1 ininject_abt64()creates invalid ESR state for Address Size faults. --commit
5d93cc0ddb43cdfa88e555d446e07e55b7334637
Author: Fuad Tabba <[email protected]>KVM: arm64: Unconditionally set IL for injected abort exceptions
This commit unconditionally sets the
ESR_ELx_ILbit to 1 for injected aborts, assuming the FSC is always EXTABT orSEA_TTW.Quoted 4 lines
arch/arm64/kvm/inject_fault.c +0
-0[ ... ]
arch/arm64/kvm/inject_fault.c static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr · line 144
Quoted 12 lines
arch/arm64/kvm/inject_fault.c +3
-4@@ -138,11 +138,10 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addrpend_sync_exception (vcpu);/* -* Build an {i,d}abort, depending on the level and the -* instruction set. Report an external synchronous abort. +* Build an {i,d}abort, depending on the level. +* Report an external synchronous abort. */ -if (kvm_vcpu_trap_il_is32bit (vcpu)) - esr |= ESR_ELx_IL; + esr |= ESR_ELx_IL;[Severity: High]
Does this unconditional setting of IL=1 cause an architecturally invalid syndrome for Address Size faults?If a guest executing in AArch32 EL0 issues a 16-bit instruction (such as a 16-bit LDR) that triggers a Stage-2 Address Size fault, the IL bit should accurately reflect the size of the trapped instruction (0 for 16-bit).
Looking at
kvm_inject_size_fault(), it injects the abort by callinginject_abt64()via the__kvm_inject_sea()call chain, and then modifies the FSC to 0 (Address Size Fault):arch/arm64/kvm/inject_fault.c:kvm_inject_size_fault() { ... /* inject_abt64() forces IL=1 earlier in the call chain */ ... esr &= ~GENMASK_ULL(5, 0); vcpu_write_sys_reg(vcpu, esr, exception_esr_elx(vcpu)); ... }
Quoted 3 lines
Will KVM now inject the Address Size fault with IL=1 instead of IL=0, potentially causing the guest OS exception handler to incorrectly advance the Program Counter by 4 bytes instead of 2 during fault unwinding?
See https://lore.kernel.org/all/CA+EHjTyiyCNV40z82=YTTMrx3BoR5gn5uh-xP80gFxX2PSUMAg@mail.gmail.com/
Quoted 7 lines
arch/arm64/kvm/inject_fault.c static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr · line 147
Quoted 4 lines
arch/arm64/kvm/inject_fault.c +0
-0/* * Here, the guest runs in AArch64 mode when in EL1. If we get --
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v2 4/7 KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
In reply to Fuad TabbaThe FPAC syndrome constructed during nested ERET emulation does not set IL. For FPAC (EC=0x1C), IL reflects the instruction length. ERET and its authenticated variants are always A64 32-bit instructions, so IL must be 1.
--- arch/arm64/kvm/emulate-nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/emulate-nested.c +1 -1
@@ -2776,7 +2776,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)* ERET handling, and the guest will have a little surprise. */ if (kvm_has_pauth (vcpu->kvm,FPACCOMBINE ) && !(spsr &PSR_IL_BIT )) { - esr &= ESR_ELx_ERET_ISS_ERETA; + esr &= (ESR_ELx_ERET_ISS_ERETA | ESR_ELx_IL); esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_FPAC);kvm_inject_nested_sync (vcpu, esr);return ;
Signature · 1 line
2.54.0.1189.g8c84645362-goog
[email protected]
AI reviewRe: [PATCH v2 4/7] KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The constructed FPAC exception syndrome incorrectly maps the ERET ISS encoding directly to the FPAC ISS encoding, resulting in malformed ISS[2:0] bits being injected into the guest. --
commit 27996a8004c4285e2d114067b3fc644f3f649d64
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
This commit sets the IL (Instruction Length) bit for the FPAC syndrome constructed during nested ERET emulation. Since ERET and its authenticated variants are always A64 32-bit instructions, the IL bit must be set to 1.
arch/arm64/kvm/emulate-nested.c void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) · line 2779
Quoted 10 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2776,7 +2776,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)* ERET handling, and the guest will have a little surprise. */ if (kvm_has_pauth (vcpu->kvm,FPACCOMBINE ) && !(spsr &PSR_IL_BIT )) { - esr &= ESR_ELx_ERET_ISS_ERETA; + esr &= (ESR_ELx_ERET_ISS_ERETA | ESR_ELx_IL);
[Severity: High]
This isn't a bug introduced by this patch, but does this mapping of the ERET ISS to the FPAC ISS result in malformed ISS[2:0] bits being injected into the guest?
For an ERET trap (EC=0x1A), ISS[0] indicates the key used (0 for ERETAA, 1 for ERETAB). For an FPAC exception (EC=0x1C), ISS[0] is the Instruction Type (must be 1 for a branch/return instruction), and ISS[2:1] indicates the Authentication Key.
By retaining the ERET ISS[0] bit and clearing the rest, it appears KVM inadvertently maps the ERET key type directly into the FPAC Instruction Type bit, while leaving the FPAC key type (ISS[2:1]) always at 00.
Consequently, wouldn't ERETAA be injected with an FPAC ISS of 0 (wrong instruction type), and ERETAB get an FPAC ISS of 1 (wrong key type)?
Quoted 3 lines
arch/arm64/kvm/emulate-nested.c +0
-0esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_FPAC);kvm_inject_nested_sync (vcpu, esr);return ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v2 4/7] KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
Quoted 36 lines · On Thu, 18 Jun 2026 at 13:28, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The constructed FPAC exception syndrome incorrectly maps the ERET ISS encoding directly to the FPAC ISS encoding, resulting in malformed ISS[2:0] bits being injected into the guest. --commit
27996a8004c4285e2d114067b3fc644f3f649d64
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulationThis commit sets the IL (Instruction Length) bit for the FPAC syndrome constructed during nested ERET emulation. Since ERET and its authenticated variants are always A64 32-bit instructions, the IL bit must be set to 1.
arch/arm64/kvm/emulate-nested.c void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) · line 2779
Quoted 10 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2776,7 +2776,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)* ERET handling, and the guest will have a little surprise. */ if (kvm_has_pauth (vcpu->kvm,FPACCOMBINE ) && !(spsr &PSR_IL_BIT )) { - esr &= ESR_ELx_ERET_ISS_ERETA; + esr &= (ESR_ELx_ERET_ISS_ERETA | ESR_ELx_IL);[Severity: High]
This isn't a bug introduced by this patch, but does this mapping of the ERET ISS to the FPAC ISS result in malformed ISS[2:0] bits being injected into the guest?For an ERET trap (EC=0x1A), ISS[0] indicates the key used (0 for ERETAA, 1 for ERETAB). For an FPAC exception (EC=0x1C), ISS[0] is the Instruction Type (must be 1 for a branch/return instruction), and ISS[2:1] indicates the Authentication Key.
Quoted 6 lines
By retaining the ERET ISS[0] bit and clearing the rest, it appears KVM inadvertently maps the ERET key type directly into the FPAC Instruction Type bit, while leaving the FPAC key type (ISS[2:1]) always at 00.
Consequently, wouldn't ERETAA be injected with an FPAC ISS of 0 (wrong instruction type), and ERETAB get an FPAC ISS of 1 (wrong key type)?
The FPAC (EC=0x1C) ISS encoding is two bits, not three:
ISS[0] (BnA): 0 = A-key, 1 = B-key
ISS[1] (DnI): 0 = Instruction key, 1 = Data key
The mask (ESR_ELx_ERET_ISS_ERETA = 0x1) keeps ISS[0], which has the same A-vs-B semantics in both the ERET and FPAC encodings, and clears ISS[1], giving DnI=0 (Instruction key), which is correct since ERETAA/ERETAB always use instruction keys.
Thanks,
/fuad
Quoted 7 lines
arch/arm64/kvm/emulate-nested.c void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) · line 2782
Quoted 4 lines
arch/arm64/kvm/emulate-nested.c +0
-0esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_FPAC);kvm_inject_nested_sync (vcpu, esr);return ;--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Marc Zyngier
maintainerRe: [PATCH v2 4/7] KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
In reply to [email protected]Quoted 31 lines · On Thu, 18 Jun 2026 13:28:07 +0100, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The constructed FPAC exception syndrome incorrectly maps the ERET ISS encoding directly to the FPAC ISS encoding, resulting in malformed ISS[2:0] bits being injected into the guest. --commit
27996a8004c4285e2d114067b3fc644f3f649d64
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulationThis commit sets the IL (Instruction Length) bit for the FPAC syndrome constructed during nested ERET emulation. Since ERET and its authenticated variants are always A64 32-bit instructions, the IL bit must be set to 1.
arch/arm64/kvm/emulate-nested.c void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) · line 2779
Quoted 10 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2776,7 +2776,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)* ERET handling, and the guest will have a little surprise. */ if (kvm_has_pauth (vcpu->kvm,FPACCOMBINE ) && !(spsr &PSR_IL_BIT )) { - esr &= ESR_ELx_ERET_ISS_ERETA; + esr &= (ESR_ELx_ERET_ISS_ERETA | ESR_ELx_IL);[Severity: High]
This isn't a bug introduced by this patch, but does this mapping of the ERET ISS to the FPAC ISS result in malformed ISS[2:0] bits being injected into the guest?
Quoted 4 lines
For an ERET trap (EC=0x1A), ISS[0] indicates the key used (0 for ERETAA, 1 for ERETAB). For an FPAC exception (EC=0x1C), ISS[0] is the Instruction Type (must be 1 for a branch/return instruction), and ISS[2:1] indicates the Authentication Key.
No. Not at all. ESR_ELx_EC_FPAC (0x1C) defines ISS[0] as BnA. Which matches the definition for ERET. On purpose. See ARM DDI 0487, version M.b, D24-8777.
Quoted 7 lines
By retaining the ERET ISS[0] bit and clearing the rest, it appears KVM inadvertently maps the ERET key type directly into the FPAC Instruction Type bit, while leaving the FPAC key type (ISS[2:1]) always at 00.
Consequently, wouldn't ERETAA be injected with an FPAC ISS of 0 (wrong instruction type), and ERETAB get an FPAC ISS of 1 (wrong key type)?
Yes, and that'd be correct.
I don't know who told Sashiko about the ARM ARM, but it doesn't seem to parse it correctly.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v2 4/7] KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
Quoted 48 lines · Marc Zyngier
Quoted 31 lines · On Thu, 18 Jun 2026 13:28:07 +0100, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The constructed FPAC exception syndrome incorrectly maps the ERET ISS encoding directly to the FPAC ISS encoding, resulting in malformed ISS[2:0] bits being injected into the guest. --commit
27996a8004c4285e2d114067b3fc644f3f649d64
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulationThis commit sets the IL (Instruction Length) bit for the FPAC syndrome constructed during nested ERET emulation. Since ERET and its authenticated variants are always A64 32-bit instructions, the IL bit must be set to 1.
arch/arm64/kvm/emulate-nested.c void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) · line 2779
Quoted 10 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2776,7 +2776,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)* ERET handling, and the guest will have a little surprise. */ if (kvm_has_pauth (vcpu->kvm,FPACCOMBINE ) && !(spsr &PSR_IL_BIT )) { - esr &= ESR_ELx_ERET_ISS_ERETA; + esr &= (ESR_ELx_ERET_ISS_ERETA | ESR_ELx_IL);[Severity: High]
This isn't a bug introduced by this patch, but does this mapping of the ERET ISS to the FPAC ISS result in malformed ISS[2:0] bits being injected into the guest?Quoted 4 lines
For an ERET trap (EC=0x1A), ISS[0] indicates the key used (0 for ERETAA, 1 for ERETAB). For an FPAC exception (EC=0x1C), ISS[0] is the Instruction Type (must be 1 for a branch/return instruction), and ISS[2:1] indicates the Authentication Key.
No. Not at all.
ESR_ELx_EC_FPAC(0x1C) defines ISS[0] as BnA. Which matches the definition for ERET. On purpose. See ARM DDI 0487, version M.b, D24-8777.Quoted 5 lines
By retaining the ERET ISS[0] bit and clearing the rest, it appears KVM inadvertently maps the ERET key type directly into the FPAC Instruction Type bit, while leaving the FPAC key type (ISS[2:1]) always at 00.
Quoted 7 lines
Quoted 2 lines
Consequently, wouldn't ERETAA be injected with an FPAC ISS of 0 (wrong instruction type), and ERETAB get an FPAC ISS of 1 (wrong key type)?
Yes, and that'd be correct.
I don't know who told Sashiko about the ARM ARM, but it doesn't seem to parse it correctly.
The problem is that it _doesn't_ have the ARM ARM, so it hallucinates it. I'll reply to the other ones, and then see if I can write up a PR to review-prompts to fix this.
Cheers,
/fuad
Quoted 5 lines
M.--
Without deviation from the norm, progress is not possible.
PATCH v2 5/7 KVM: arm64: Set IL for emulated SError injection
In reply to Fuad Tabbakvm_inject_serror_esr() constructs an SError syndrome without IL. The architecture mandates IL=1 for SError unconditionally.
--- arch/arm64/kvm/inject_fault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/inject_fault.c +1 -1
@@ -381,7 +381,7 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)*/ if (!serror_is_masked (vcpu)) {pend_serror_exception (vcpu); - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;vcpu_write_sys_reg (vcpu, esr,exception_esr_elx (vcpu));return 1 ; }
Signature · 1 line
2.54.0.1189.g8c84645362-goog
[email protected]
AI reviewRe: [PATCH v2 5/7] KVM: arm64: Set IL for emulated SError injection
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] kvm_inject_nested_sea() passes an Instruction/Data Abort EC instead of an SError EC when FEAT_EASE converts a Synchronous External Abort into an SError.
- [High] The constructed ESR for a nested SError is discarded during injection because kvm_inject_el2_exception() never writes it to the guest's ESR_EL2. --
commit da891cfcd9b452feacd8b631f8c20dae39b009fc
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for emulated SError injection
kvm_inject_serror_esr() constructs an SError syndrome without IL. The architecture mandates IL=1 for SError unconditionally.
arch/arm64/kvm/inject_fault.c int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr) · line 387
Quoted 13 lines
arch/arm64/kvm/inject_fault.c +1
-1@@ -381,7 +381,7 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)*/ if (!serror_is_masked (vcpu)) {pend_serror_exception (vcpu); - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;vcpu_write_sys_reg (vcpu, esr,exception_esr_elx (vcpu));return 1 ; }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this SError injection logic, I noticed an issue in how ESR is constructed for nested SErrors. When SCTLR2_ELx.EASE is set and a Synchronous External Abort is converted to an SError, does kvm_inject_nested_sea() pass an incorrect Exception Class?
In arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_sea():
if (__vcpu_sys_reg(vcpu, SCTLR2_EL2) & SCTLR2_EL1_EASE) return kvm_inject_nested(vcpu, esr, except_type_serror);
The esr variable retains the previously constructed IABT/DABT Exception Class instead of being reconstructed with ESR_ELx_EC_SERROR. Does this present an invalid syndrome to the nested guest hypervisor, since the architecture mandates that ESR_ELx.EC must be 0x2F (SError) when an External abort is treated as an SError?
Also, does this unconditionally update FAR_EL2, which is architecturally incorrect for an SError?
[Severity: High]
This is also a pre-existing issue, but there appears to be a problem where the constructed ESR for a nested SError is discarded during injection. Does kvm_inject_el2_exception() fail to write the esr_el2 argument to ESR_EL2?
In arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception():
case except_type_serror: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR); break;
Unlike the synchronous exception case, the esr_el2 argument isn't written to the guest's ESR_EL2. Since the downstream exception entry path enter_exception64() does not write ESR_ELx, does this result in the nested guest hypervisor receiving an SError with a stale, unmodified ESR_EL2?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v2 5/7] KVM: arm64: Set IL for emulated SError injection
Quoted 5 lines · On Thu, 18 Jun 2026 at 13:32, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High]kvm_inject_nested_sea()passes an Instruction/Data Abort EC instead of an SError EC whenFEAT_EASEconverts a Synchronous External Abort into an SError.
Not a bug. EASE does not convert the exception to an SError. It only changes the vector offset. The EC remains the original abort EC. The non-nested path in inject_abt64() does the same thing. FAR_EL2 is also correct since the exception is still a synchronous abort.
Quoted 1 line
- [High] The constructed ESR for a nested SError is discarded during injection because
kvm_inject_el2_exception()never writes it to the guest'sESR_EL2.
https://lore.kernel.org/all/[email protected]/
Thanks,
/fuad
Quoted 63 lines
--
commit
da891cfcd9b452feacd8b631f8c20dae39b009fc
Author: Fuad Tabba <[email protected]>KVM: arm64: Set IL for emulated SError injection
kvm_inject_serror_esr()constructs an SError syndrome without IL. The architecture mandates IL=1 for SError unconditionally.arch/arm64/kvm/inject_fault.c int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr) · line 387
Quoted 13 lines
arch/arm64/kvm/inject_fault.c +1
-1@@ -381,7 +381,7 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)*/ if (!serror_is_masked (vcpu)) {pend_serror_exception (vcpu); - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;vcpu_write_sys_reg (vcpu, esr,exception_esr_elx (vcpu));return 1 ; }[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this SError injection logic, I noticed an issue in how ESR is constructed for nested SErrors. When SCTLR2_ELx.EASE is set and a Synchronous External Abort is converted to an SError, doeskvm_inject_nested_sea()pass an incorrect Exception Class?In arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_sea():
if (__vcpu_sys_reg(vcpu, SCTLR2_EL2) & SCTLR2_EL1_EASE) return kvm_inject_nested(vcpu, esr, except_type_serror);The esr variable retains the previously constructed IABT/DABT Exception Class instead of being reconstructed with
ESR_ELx_EC_SERROR. Does this present an invalid syndrome to the nested guest hypervisor, since the architecture mandates that ESR_ELx.EC must be0x2F(SError) when an External abort is treated as an SError?Also, does this unconditionally update
FAR_EL2, which is architecturally incorrect for an SError?[Severity: High]
This is also a pre-existing issue, but there appears to be a problem where the constructed ESR for a nested SError is discarded during injection. Doeskvm_inject_el2_exception()fail to write theesr_el2argument toESR_EL2?In arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception():
case except_type_serror: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR); break;Unlike the synchronous exception case, the
esr_el2argument isn't written to the guest'sESR_EL2. Since the downstream exception entry pathenter_exception64()does not writeESR_ELx, does this result in the nested guest hypervisor receiving an SError with a stale, unmodifiedESR_EL2?--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v2 6/7 KVM: arm64: Set IL for nested SError injection
In reply to Fuad Tabbakvm_inject_nested_serror() constructs an SError syndrome without IL. The architecture mandates IL=1 for SError unconditionally.
--- arch/arm64/kvm/emulate-nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/emulate-nested.c +1 -1
@@ -2938,6 +2938,6 @@ int kvm_inject_nested_serror(struct kvm_vcpu *vcpu, u64 esr)* vSError injection. Manually populate EC for an emulated SError * exception. */ - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;return kvm_inject_nested (vcpu, esr, except_type_serror); }
Signature · 1 line
2.54.0.1189.g8c84645362-goog
[email protected]
AI reviewRe: [PATCH v2 6/7] KVM: arm64: Set IL for nested SError injection
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The SError syndrome constructed by kvm_inject_nested_serror() (including the newly added IL bit) is a dead store because the downstream injection logic silently drops the syndrome.
- [High] When a Synchronous External Abort is routed to an SError via FEAT_DoubleFault2 (EASE), KVM incorrectly populates the ESR with an IABT or DABT Exception Class (EC) instead of the architectural SError EC. --
commit 889dc0193654a25a0ce52006ebe91e58fc4c4ed8
Author: Fuad Tabba <[email protected]>
KVM: arm64: Set IL for nested SError injection
This patch modifies kvm_inject_nested_serror() to unconditionally set the IL bit in the SError syndrome, as mandated by the architecture.
arch/arm64/kvm/emulate-nested.c int kvm_inject_nested_serror(struct kvm_vcpu *vcpu, u64 esr) · line 2943
Quoted 12 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2938,6 +2938,6 @@ int kvm_inject_nested_serror(struct kvm_vcpu *vcpu, u64 esr)* vSError injection. Manually populate EC for an emulated SError * exception. */ - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;return kvm_inject_nested (vcpu, esr, except_type_serror); }
[Severity: High]
This isn't a bug introduced by this patch, but does the constructed syndrome value get silently dropped downstream?
Looking at kvm_inject_nested(), it forwards the esr to kvm_inject_el2_exception():
arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception() {
...
case except_type_serror:
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR);
break;
...
}The except_type_serror case doesn't write esr_el2 to ESR_EL2 (unlike the except_type_sync case), and downstream exception entry code doesn't write it either.
The constructed payload appears to be entirely discarded.
Would the nested hypervisor observe a stale ESR_EL2 value when taking the SError, rendering this fix functionally ineffective?
[Severity: High]
This is a pre-existing issue, but when a Synchronous External Abort is routed to an SError via EASE (FEAT_DoubleFault2), does KVM incorrectly populate the ESR with an Abort Exception Class instead of SError?
In kvm_inject_nested_sea(), if SCTLR2_EL1_EASE is set, an SError is requested using an ESR constructed with an Abort EC:
arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_sea() {
...
if (__vcpu_sys_reg(vcpu, SCTLR2_EL2) & SCTLR2_EL1_EASE)
return kvm_inject_nested(vcpu, esr, except_type_serror);
...
}Similarly in arch/arm64/kvm/inject_fault.c:inject_abt64(), the ESR is populated with ESR_ELx_EC_IABT_* or ESR_ELx_EC_DABT_* before being written.
Architecturally, all SError interrupts must have an SError Exception Class, even when representing a routed SEA.
Does supplying an Abort EC violate the architecture and provide the guest with a malformed exception syndrome?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v2 6/7] KVM: arm64: Set IL for nested SError injection
Quoted 6 lines · On Thu, 18 Jun 2026 at 13:33, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The SError syndrome constructed bykvm_inject_nested_serror()(including the newly added IL bit) is a dead store because the downstream injection logic silently drops the syndrome.
- [High] When a Synchronous External Abort is routed to an SError viaFEAT_DoubleFault2(EASE), KVM incorrectly populates the ESR with an IABT or DABT Exception Class (EC) instead of the architectural SError EC.
https://lore.kernel.org/all/CA+EHjTyJUrHZJiM9e2r20_1JLzWQg-+TAr9g720njugLMWTpGw@mail.gmail.com/
Cheers,
/fuad
Quoted 73 lines
--
commit
889dc0193654a25a0ce52006ebe91e58fc4c4ed8
Author: Fuad Tabba <[email protected]>KVM: arm64: Set IL for nested SError injection
This patch modifies
kvm_inject_nested_serror()to unconditionally set the IL bit in the SError syndrome, as mandated by the architecture.arch/arm64/kvm/emulate-nested.c int kvm_inject_nested_serror(struct kvm_vcpu *vcpu, u64 esr) · line 2943
Quoted 12 lines
arch/arm64/kvm/emulate-nested.c +1
-1@@ -2938,6 +2938,6 @@ int kvm_inject_nested_serror(struct kvm_vcpu *vcpu, u64 esr)* vSError injection. Manually populate EC for an emulated SError * exception. */ - esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR); + esr |=FIELD_PREP (ESR_ELx_EC_MASK, ESR_ELx_EC_SERROR) | ESR_ELx_IL;return kvm_inject_nested (vcpu, esr, except_type_serror); }[Severity: High]
This isn't a bug introduced by this patch, but does the constructed syndrome value get silently dropped downstream?Looking at
kvm_inject_nested(), it forwards the esr tokvm_inject_el2_exception():arch/arm64/kvm/emulate-nested.c:kvm_inject_el2_exception() { ... case except_type_serror: kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SERR); break; ... }The
except_type_serrorcase doesn't writeesr_el2toESR_EL2(unlike theexcept_type_synccase), and downstream exception entry code doesn't write it either.The constructed payload appears to be entirely discarded.
Would the nested hypervisor observe a stale
ESR_EL2value when taking the SError, rendering this fix functionally ineffective?[Severity: High]
This is a pre-existing issue, but when a Synchronous External Abort is routed to an SError via EASE (FEAT_DoubleFault2), does KVM incorrectly populate the ESR with an Abort Exception Class instead of SError?In
kvm_inject_nested_sea(), ifSCTLR2_EL1_EASEis set, an SError is requested using an ESR constructed with an Abort EC:arch/arm64/kvm/emulate-nested.c:kvm_inject_nested_sea() { ... if (__vcpu_sys_reg(vcpu, SCTLR2_EL2) & SCTLR2_EL1_EASE) return kvm_inject_nested(vcpu, esr, except_type_serror); ... }Similarly in arch/arm64/kvm/inject_fault.c:inject_abt64(), the ESR is populated with ESR_ELx_EC_IABT_* or ESR_ELx_EC_DABT_* before being written.
Architecturally, all SError interrupts must have an SError Exception Class, even when representing a routed SEA.
Does supplying an Abort EC violate the architecture and provide the guest with a malformed exception syndrome?
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v2 7/7 KVM: arm64: Set IL in fake ESR for pKVM memory sharing exit
In reply to Fuad Tabba__pkvm_memshare_page_req() constructs a fake DABT ESR_EL2 to exit to the host without setting IL. The ESR has ISV=0, so IL must be 1 per the architecture. The host does not read IL on this path, but the constructed syndrome should still be architecturally valid.
Set ESR_ELx_IL.
--- arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/pkvm.c +2 -1
@@ -1054,7 +1054,8 @@ static u64 __pkvm_memshare_page_req(struct kvm_vcpu *vcpu, u64 ipa)/* Fake up a data abort (level 3 translation fault on write) */ vcpu->arch.fault.esr_el2 = (ESR_ELx_EC_DABT_LOW << ESR_ELx_EC_SHIFT) | - ESR_ELx_WNR | ESR_ELx_FSC_FAULT | + ESR_ELx_IL | ESR_ELx_WNR | + ESR_ELx_FSC_FAULT |FIELD_PREP (ESR_ELx_FSC_LEVEL,3 );/* Shuffle the IPA around into the HPFAR */
Signature · 1 line
2.54.0.1189.g8c84645362-goog
Quoted 6 lines · Fuad Tabba
Hi folks,
After sashiko caught the missing IL bug [1], I did an audit of all ESR syndrome construction sites in KVM/arm64 as Marc suggested. This series is the result of that audit.
FWIW, went through all the issues Sashiko raised [1]; the only real bug it found is the one we already fixed [2].
Cheers,
/fuad
[1] https://sashiko.dev/#/patchset/[email protected]
[2] https://lore.kernel.org/all/[email protected]/
Quoted 56 lines
The ARM architecture mandates ESR_ELx.IL=1 for several exception classes regardless of instruction length: EC=Unknown, Instruction Aborts, Data Aborts with ISV=0, and SError. For FPAC (EC=0x1C), IL reflects instruction length, but FPAC can only be generated by A64 instructions, so IL must also be 1.
Patch 1 is the bug sashiko found:
inject_undef64()in the pKVM hyp (EL2) path never set IL. Patch 2 makes the same fix toinject_undef64()in the normal host path, where IL was derived from the triggering trap's instruction length. No instruction that reaches undef injection has a 16-bit encoding, so patch 2 has no functional change today. Patch 3 makes the matching fix toinject_abt64(). Unlike undef injection, abort injection is reachable from a 16-bit T32 instruction (a 32-bit EL0 task under an AArch64 EL1 guest), so the old code there injects an abort with IL=0.
Patch 4 fixes the FPAC syndrome constructed during nested ERET emulation, which did not set IL.
Patches 5-6 fix SError injection in the emulated and nested paths, neither of which set IL.
Patch 7 fixes a fake ESR used to exit to the host. The host does not read IL there, so it is not guest-visible.Changes since v1 [2]:
- Patch 4: keep IL by masking it through from the trapped ERET's ESR instead of OR-ing the bit in. The ERET trap (EC=0x1A) always reports IL=1, so this preserves the source syndrome rather than adding the bit unconditionally (Marc).
- Rebased on v7.1.Cheers,
/fuad[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Fuad Tabba <[email protected]>Fuad Tabba (7):
KVM: arm64: Set ESR_ELx.IL for injected undefined exceptions at EL2
KVM: arm64: Unconditionally set IL for injected undefined exceptions
KVM: arm64: Unconditionally set IL for injected abort exceptions
KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
KVM: arm64: Set IL for emulated SError injection
KVM: arm64: Set IL for nested SError injection
KVM: arm64: Set IL in fake ESR for pKVM memory sharing exitarch/arm64/kvm/emulate-nested.c | 4 ++-- arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 ++- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 2 +- arch/arm64/kvm/inject_fault.c | 18 +++++------------- 4 files changed, 10 insertions(+), 17 deletions(-)--
2.54.0.1189.g8c84645362-goog
Quoted 11 lines · Fuad Tabba
After sashiko caught the missing IL bug [1], I did an audit of all ESR syndrome construction sites in KVM/arm64 as Marc suggested. This series is the result of that audit.
The ARM architecture mandates ESR_ELx.IL=1 for several exception classes regardless of instruction length: EC=Unknown, Instruction Aborts, Data Aborts with ISV=0, and SError. For FPAC (EC=0x1C), IL reflects instruction length, but FPAC can only be generated by A64 instructions, so IL must also be 1.
[...]
Applied to fixes, thanks!
[1/7] KVM: arm64: Set ESR_ELx.IL for injected undefined exceptions at EL2
commit: daa71eca24fdfb43029830bd57ddaddf70c59b23
[2/7] KVM: arm64: Unconditionally set IL for injected undefined exceptions
commit: 1d695dc827957e9570d1b56abac1250d2d13bf0c
[3/7] KVM: arm64: Unconditionally set IL for injected abort exceptions
commit: add40af98b34764ff5603dce297160fde12d784c
[4/7] KVM: arm64: Set IL for injected FPAC exceptions during ERET emulation
commit: a52d6d68ad30374dd794bff300d8538e35ee49a8
[5/7] KVM: arm64: Set IL for emulated SError injection
commit: 7514f1785d526207af8512cc6ccb1c35c5c61767
[6/7] KVM: arm64: Set IL for nested SError injection
commit: a69412287a33c931dca9e48d30c0dbf8cde0ffe6
[7/7] KVM: arm64: Set IL in fake ESR for pKVM memory sharing exit
commit: cbe2278aa3dd6832c544782c6cfed1fbc1f71a42Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.