]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Widen x86_exception's error_code to 64 bits
authorKevin Cheng <chengkev@google.com>
Fri, 22 May 2026 23:26:57 +0000 (16:26 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 26 May 2026 19:31:11 +0000 (12:31 -0700)
Widen the error_code field in struct x86_exception from u16 to u64 to
accommodate AMD's NPF error code, which defines information bits above
bit 31, e.g. PFERR_GUEST_FINAL_MASK (bit 32), and PFERR_GUEST_PAGE_MASK
(bit 33).

Retain the u16 type for the local errcode variable in walk_addr_generic
as the walker synthesizes conventional #PF error codes that are
architecturally limited to bits 15:0.

Signed-off-by: Kevin Cheng <chengkev@google.com>
Link: https://patch.msgid.link/20260522232701.3671446-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/kvm_emulate.h
arch/x86/kvm/mmu/paging_tmpl.h

index 72aece9ef575e0604e2adb3556794ed6844bea70..f5df31a52996af076b4c6f83ba183ddbcd67920c 100644 (file)
@@ -22,7 +22,7 @@ enum x86_intercept_stage;
 struct x86_exception {
        u8 vector;
        bool error_code_valid;
-       u16 error_code;
+       u64 error_code;
        bool nested_page_fault;
        union {
                u64 address; /* cr2 or nested page fault gpa */
index 07100bbfc270178dcc48aa0db7a63b4f563c550e..51f8b45223143b7c9ff62c3e61de4ba6b92b097b 100644 (file)
@@ -328,6 +328,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
        const int write_fault = access & PFERR_WRITE_MASK;
        const int user_fault  = access & PFERR_USER_MASK;
        const int fetch_fault = access & PFERR_FETCH_MASK;
+       /*
+        * Note! Track the error_code that's common to legacy shadow paging
+        * and NPT shadow paging as a u16 to guard against unintentionally
+        * setting any of bits 63:16.  Architecturally, the #PF error code is
+        * 32 bits, and Intel CPUs don't support settings bits 31:16.
+        */
        u16 errcode = 0;
        gpa_t real_gpa;
        gfn_t gfn;