From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796343374; b=4xFLlqQltwqWlvNgSj8skrHZqgY8MWOCMrO4jkKWEXnt4qBgF3IXVeEtlG38ISKadqT6 Ly3xo5kPgKiCn7UUo7SGRqpro8MCInsJ61JdBN0zMLIhyEw6EWg7/JDsfcZZtM/e1zpuu nMNHbTVUpNHEK3wqBap8ymbXMxXe0rEzyurl0g7+fqZ28gO/M5VZG9GxODgWtA1LKR3o0 OH/OIDy+4J29Q/qz/HV/YgJzxRBzJPUN0Jr2DHXL2a9KnuzqPGeQMigUmfYj35QwhnxMk 9rmkDfRSKBZhD68TduRQhwH7SEF7igEJhWpnm+MfAVx5DHPTB1gn8jtVpSbdKybaQkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796343374; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bzvtnnGXnT/8oTiyspAf0aVLJjc4K/KiUl7j73JqAk0=; b=dQhTF4b1W41H9smyuZ0OodjujPsnWQGA0jhNHmA6UixLEhmyYH88w/PiT2aT3mEIHkZv gbkKQNKnYWDA97Km+y03dK8idLRMkiNWXXIfQfyHhBWELCKAnnHh9Sg+M5Y7A3F6Z//xN DyCrTFX+bRicxOowwzXeQuCKO9Ua7TiaWfycjJbP86GzIgtxT9P7NFwDGkEFB2HkCYI21 l+DSBbLR2CkeAeCy9BcErb5xPQRsl6g4fIZSlTQWMTdox/4Gi2OF4gvnU2m1PP00i6MaC RK+d9QHKfquyuIcACAyv1zoOzBkxq5IyZParI9qK3Btb7yyCb8dxMI1xyYdypye0vxA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OHCgjHmn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C9C606A322 for ; Fri, 4 Dec 2026 00:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OHCgjHmn Received: by smtp.kernel.org (Postfix) with ESMTPSA id B464A1F000CE; Fri, 4 Dec 2026 00:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796343373; bh=bzvtnnGXnT/8oTiyspAf0aVLJjc4K/KiUl7j73JqAk0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OHCgjHmn7aWgkZtEhCylkCbqrNuRXl0X3yC7cN3emzcTn//csoYTz4ylelZb1cEBe iicoM9eNNC6q8Pc44mFOFHOLEH0bWmAVXcVZs3oyoHhJF1Udt1F8k8MEnllAUybLxO eNN2X1hgIYYLR5VqfUnJ2Fx7+aXRQxkmIfbFp2tOndAuekp+6b7cR7RyLVSRJyNB6Y etBnE6xfvMarUmyKoeVH3a5VRoJUEZjsGaMGvQBStFKLwsGcPb/Huj6hC+Kzq3bTep Oh7XXNQxknZcxKdyH8f+Y+W86l37c5TXiWJRHJOAiP20I9Um0p3/wUb9B7am1/l9uj YDQJFnyz/RIaw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGVubmlzIFJldcOfd2ln?= Cc: kvm@vger.kernel.org In-Reply-To: <20261204-nested-sss-v1-4-57de06f58b2b@reusswig.codes> References: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> <20261204-nested-sss-v1-4-57de06f58b2b@reusswig.codes> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:16:13 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] KVM: x86/mmu: Direct shadow page aliasing leaks EPT SSS permission - [High] KVM: x86/mmu: omit shadow_mmu_writable_mask on SSS SPTEs skips TLB flushes - [High] KVM: x86/mmu: SSS read faults livelock when make_spte() strips bit 60 - [Medium] KVM: x86/mmu: Unconditional second LOCK BTR in __rmap_clear_dirty() -- commit 60a373f236eec5c8d97428ecb5498541f1b762a3 Author: Dennis Reu=C3=9Fwig KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit This commit introduces ACC_EPT_SSS_MASK and updates the x86 MMU to treat EPT bit 60 (supervisor shadow-stack) like the writable bit during SPTE creation, write-protection, dirty logging, and TLB flushing. > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index f89e9f8a6cc2f..d2aa576f97cdf 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c [ ... ] > @@ -697,7 +697,12 @@ static void kvm_mmu_page_set_translation(struct kvm_= mmu_page *sp, int index, > return; > } > =20 > - WARN_ONCE(access !=3D kvm_mmu_page_get_access(sp, index), > + /* > + * role.access cannot hold ACC_EPT_SSS_MASK. Direct SPs that shadow a > + * guest huge page carry the supervisor shadow-stack grant only in > + * their SPTEs, which inherit it on splits. > + */ > + WARN_ONCE((access & ~ACC_EPT_SSS_MASK) !=3D kvm_mmu_page_get_access(sp,= index), > "access mismatch under %s page %llx (expected %u, got %u)\n", > sp->role.passthrough ? "passthrough" : "direct", > sp->gfn, kvm_mmu_page_get_access(sp, index), access); [Severity: High] Can excluding ACC_EPT_SSS_MASK from role.access cause direct shadow pages to alias across SSS=3D1 and SSS=3D0 guest huge pages? When L1 maps the same 2MiB or 1GiB GFN at two L2 GPAs with matching R/W/X/XU bits, one with VMX_EPT_SSS_MASK set and one with it clear, shadow_mmu_get_sp_for_split() passes access to kvm_mmu_child_role(), where role.access =3D access truncates bit 4. Both huge pages then hash to the s= ame (gfn, role.word) key and share a single direct struct kvm_mmu_page. If the SSS=3D1 huge page is split first, shadow_mmu_split_huge_page() popul= ates sp->spt[] with VMX_EPT_SSS_MASK set; splitting the SSS=3D0 huge page reuses that SP, skips the already-present SPTEs, and links them under the SSS=3D0 parent. L2 then gets supervisor shadow-stack write access on an L2 GPA whe= re L1 cleared bit 60. Separately, direct_pte_prefetch_many() reads only sp->role.access, so prefetching sibling 4KiB SPTEs under a direct SP shadowing an SSS=3D1 huge = page silently drops ACC_EPT_SSS_MASK. Storing the SSS permission in union kvm_mmu_page_role (which still has spare padding bits) would keep SSS=3D1 and SSS=3D0 direct SPs distinct and preser= ve the bit during prefetch. [ ... ] > @@ -1424,11 +1429,14 @@ static bool __rmap_clear_dirty(struct kvm *kvm, s= truct kvm_rmap_head *rmap_head, > bool flush =3D false; > =20 > for_each_rmap_spte(rmap_head, &iter, sptep) { > - if (spte_ad_need_write_protect(*sptep)) > + if (spte_ad_need_write_protect(*sptep)) { > flush |=3D test_and_clear_bit(PT_WRITABLE_SHIFT, > (unsigned long *)sptep); > - else > + flush |=3D test_and_clear_bit(SPTE_EPT_SSS_SHIFT, > + (unsigned long *)sptep); > + } else { > flush |=3D spte_clear_dirty(sptep); > + } > } > =20 > return flush; [Severity: Medium] Does this unconditionally issue a second locked atomic RMW on every write-protect-mode SPTE even when VMX_EPT_SSS_MASK is clear? __rmap_clear_dirty() runs under exclusive write_lock(&kvm->mmu_lock) across every 4KiB SPTE in a memslot during dirty-logging setup and dirty-log clearing (kvm_mmu_slot_leaf_clear_dirty() and kvm_mmu_clear_dirty_pt_masked()). Doubling the serializing bit-clear operations per SPTE extends mmu_lock hold time and stalls concurrent vCPU page faults even when EPT SSS is unused. Since VMX_EPT_SSS_MASK is never set by hardware or locklessly in fast_page_fault(), loading spte =3D *sptep once and guarding the second test_and_clear_bit() with is_sss_spte(spte) avoids the extra atomic on non-SSS SPTEs. [ ... ] > diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c > index 5fc27e9733b38..5251d03841815 100644 > --- a/arch/x86/kvm/mmu/spte.c > +++ b/arch/x86/kvm/mmu/spte.c [ ... ] > @@ -249,14 +251,18 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mm= u_page *sp, > if (host_writable) > spte |=3D shadow_host_writable_mask; > else > - pte_access &=3D ~ACC_WRITE_MASK; > + pte_access &=3D ~(ACC_WRITE_MASK | ACC_EPT_SSS_MASK); [Severity: High] Can clearing ACC_EPT_SSS_MASK when !host_writable livelock L2 on supervisor shadow-stack read faults? With EPTP bit 7 set, EPT leaf bit 60 is required for supervisor shadow-stack reads (such as RET or RSTORSSP), which raise an EPT violation with EPT_VIOLATION_SHADOW_STACK set and EPT_VIOLATION_ACC_WRITE clear. __vt_handle_ept_violation() leaves fault->write false, so __kvm_mmu_faultin_pfn() omits FOLL_WRITE and fails to break COW/KSM/zero pages. make_spte() then strips ACC_EPT_SSS_MASK and installs an SPTE witho= ut bit 60, causing L2 to re-fault forever. The same livelock happens on a write-tracked GFN when mmu_try_to_unsync_pages() fails and make_spte() sets wrprot =3D true: both page_fault_handle_page_track() and mmu_set_spte() gate on fault->write, so KVM returns RET_PF_FIXED or RET_PF_SPURIOUS instead of RET_PF_WRITE_PROTECTED. [ ... ] > - if ((!is_last_spte(old_spte, level) || !is_writable_pte(old_spte)) && > - mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefe= tch)) > + if ((!is_last_spte(old_spte, level) || > + !(is_writable_pte(old_spte) || > + (is_shadow_present_pte(old_spte) && is_sss_spte(old_spte)))) && > + mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefe= tch)) { > wrprot =3D true; > - else > - spte |=3D PT_WRITABLE_MASK | shadow_mmu_writable_mask | > - shadow_dirty_mask; > + } else { > + if (pte_access & ACC_WRITE_MASK) > + spte |=3D PT_WRITABLE_MASK | shadow_mmu_writable_mask; > + if (pte_access & ACC_EPT_SSS_MASK) > + spte |=3D VMX_EPT_SSS_MASK; > + > + spte |=3D shadow_dirty_mask; > + } > } [Severity: High] Can omitting shadow_mmu_writable_mask on SSS-only SPTEs cause write-protection to skip a required remote TLB flush? For a read-only supervisor shadow-stack leaf (ACC_EPT_SSS_MASK without ACC_WRITE_MASK), make_spte() sets VMX_EPT_SSS_MASK while leaving shadow_mmu_writable_mask clear. Dirty-logging paths clear VMX_EPT_SSS_MASK under mmu_lock and drop the lock before flushing remote TLBs: CPU0 (dirty logging) CPU1 (pt_protect) kvm_mmu_slot_apply_flags() kvm_mmu_slot_leaf_clear_dirty() write_lock(&kvm->mmu_lock) __rmap_clear_dirty() clear VMX_EPT_SSS_MASK write_unlock(&kvm->mmu_lock) account_shadowed() write_lock(&kvm->mmu_lock) spte_write_protect(..., true) returns false <-- skips TLB flush write_unlock(&kvm->mmu_lock) kvm_flush_remote_tlbs_memslot() Because PT_WRITABLE_MASK, VMX_EPT_SSS_MASK, and shadow_mmu_writable_mask are all clear in that window, spte_write_protect() returns false and account_shadowed() skips kvm_flush_remote_tlbs_gfn(). A remote vCPU can still hold a stale TLB entry with bit 60 set and write directly into a shadowed guest page table via shadow-stack accesses. FNAME(sync_spte) -> leaf_spte_change_needs_tlb_flush() misses the flush in the same window, and check_spte_writable_invariants() does not check that is_sss_spte() entries are MMU-writable and host-writable. Setting shadow_mmu_writable_mask whenever ACC_EPT_SSS_MASK is granted preserves KVM's MMU-writable TLB flush invariant. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-nested-sss= -v1-0-57de06f58b2b@reusswig.codes?part=3D4