linux/arch/x86/kvm/mmu
Paolo Bonzini e90ab36691 KVM: x86/mmu: Cope with the SS bit being set in #NPF exit codes
When running Hyper-V from Windows 11, KVM is seeing the SS bit set
in nested page fault error codes produced for shadowed NPT.  The AMD
manual is unclear about when SS is set, including whether it can be set
when SupervisorShadowStackEn (bit 6) is not set in the MISC_CTL field
of the VMCB.

Nevertheless, the unexpected SS bit causes out of bounds accesses in
permission_fault(), seen as either WARNs or UBSAN reports:

  kernel: UBSAN: array-index-out-of-bounds in arch/x86/kvm/mmu.h:225:27
  kernel: index 34 is out of range for type 'u16 [16]'

(in this case, the page fault error code is 34*2=0x44, i.e. SS|U; the
report shows SS|U|W happening as well).  Fix the handling of unknown
error codes by dropping SS and (with a WARN) any bits not among those
that permission_fault() expects to receive.

At the same time, given the uncertainty about when hardware sets SS,
follow the processor's behavior when constructing the fault's error
code, and preserve the SS bit as passed to FNAME(walk_addr_generic).
While the behavior is surprising, there's a possibility that Hyper-V
expects it (Hyper-V does not even enable CET unless it finds MBEC/GMET!),
so retain the information when reflecting the fault to L1 instead of
unconditionally discarding it.

Bisection shows that this started happening with commit 687ee95c1b ("KVM:
nSVM: enable GMET for guests"), even though SHSTK was available to guests
since Linux 6.18.  However, this is not because bit 1 of MISC_CTL (GMET)
somehow enables reporting the SS bit; rather, it's simply that Hyper-V
never uses CET unless GMET is also present.  The WARN is reproducible
even with gmet=0, with some hacking of kvm-unit-tests's cet.c testcase
to ensure that the first access to the shadow stack triggers a page fault.

Reported-by: SimonP <simonp.git@mailbox.org>
Fixes: 8db428fd52 ("KVM: SVM: Enable shadow stack virtualization for SVM")
Cc: stable@vger.kernel.org
Reviewed-by: Sean Christopherson <seanjc@google.com>
Closes: https://lore.kernel.org/all/asUqYEisPp9MJ8mQ@rika.bernkas.tel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-10-12 19:22:54 +02:00
..
mmu_internal.h KVM: x86/mmu: Move kvm_mmu_do_page_fault() from mmu_internal.h => mmu.c 2026-06-24 08:24:05 -04:00
mmu.c KVM: x86/mmu: Bail from shadow walks if the root is invalid or a dummy 2026-09-26 01:15:43 -04:00
mmutrace.h KVM: x86/mmu: Expose number of shadow MMU shadow pages as a stat 2026-06-24 07:52:23 -04:00
page_track.c KVM: x86/mmu: Check write tracking in all address spaces 2026-07-28 18:07:14 +02:00
page_track.h KVM: x86/mmu: Drop @slot param from exported/external page-track APIs 2023-08-31 14:08:18 -04:00
paging_tmpl.h KVM: x86/mmu: Cope with the SS bit being set in #NPF exit codes 2026-10-12 19:22:54 +02:00
spte.c Merge tag 'kvm-riscv-7.3-1' of https://github.com/kvm-riscv/linux into HEAD 2026-08-18 13:09:51 +02:00
spte.h KVM: x86/mmu: use kvm_page_format to test SPTEs 2026-06-25 11:32:00 +02:00
tdp_iter.c KVM: x86/mmu: Support GFN direct bits 2024-12-23 08:31:54 -05:00
tdp_iter.h KVM: x86/mmu: Use CMPXCHG when clearing Accessed bit in TDP MMU 2026-07-29 05:44:07 -07:00
tdp_mmu.c KVM: x86/mmu: Use CMPXCHG when clearing Accessed bit in TDP MMU 2026-07-29 05:44:07 -07:00
tdp_mmu.h KVM: x86/mmu: Rename kvm_tdp_mmu_zap_sp() to better indicate its purpose 2025-08-19 07:40:25 -07:00