mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Dennis Reußwig" <dennis@reusswig.codes>
To: Sean Christopherson <seanjc@google.com>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org,  "H. Peter Anvin" <hpa@zytor.com>,
	Jon Kohler <jon@nutanix.com>,  Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <shuah@kernel.org>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
	"Chao Gao" <chao.gao@intel.com>,
	"Maxim Levitsky" <mlevitsk@redhat.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Panayotis Katsaloulis" <panayotis@panayotis.com>,
	"Dennis Reußwig" <dennis@reusswig.codes>
Subject: [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57
Date: Fri, 04 Dec 2026 00:49:15 +0100	[thread overview]
Message-ID: <20261204-nested-sss-v1-2-57de06f58b2b@reusswig.codes> (raw)
In-Reply-To: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes>

Bits 60 and 61 of TDP SPTEs hold the type of A/D tracking.  If bit 7 of
the EPTP is set, the CPU uses bit 60 of an EPT leaf as the supervisor
shadow-stack permission (SDM Vol. 3C, 31.3.3.2).  KVM needs to set that
bit in shadow EPT SPTEs to support supervisor shadow-stack control for
nested EPT, so it cannot hold software state.

Move the A/D tracking type to bits 56 and 57, which are unused since
commit be4e45f360a2 ("KVM: x86/mmu: shuffle high bits of SPTEs in
preparation for MBEC").  The CPU ignores bit 56.  Bit 57 is "verify
guest paging" only if the guest-paging verification VM-execution
control is set, which KVM never does; bit 61 was in the same situation
with the sub-page write permission control.  The existing static
asserts against the host-writable, MMU-writable and access-tracking
bits still hold.

No functional change intended.

Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
 arch/x86/kvm/mmu/spte.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h
index e730717824b3..237a0484367a 100644
--- a/arch/x86/kvm/mmu/spte.h
+++ b/arch/x86/kvm/mmu/spte.h
@@ -22,16 +22,19 @@
  * - bits 52, 54: saved X-R bits for access tracking when EPT does not have A/D
  * - bits 53 (EPT only): host writable
  * - bits 55 (EPT only): MMU-writable
- * - bits 56-59: unused
- * - bits 60-61: type of A/D tracking
+ * - bits 56-57: type of A/D tracking
+ * - bits 58-61: unused; bit 60 is the EPT supervisor shadow-stack page bit
+ *   when EPTP[7] is set, so it must not be used for software state
  * - bits 62 (EPT only): saved XU bit for disabled AD
  */
 
 /*
  * TDP SPTES (more specifically, EPT SPTEs) may not have A/D bits, and may also
  * be restricted to using write-protection (for L2 when CPU dirty logging, i.e.
- * PML, is enabled).  Use bits 60 and 61 to hold the type of A/D tracking that
- * is must be employed for a given TDP SPTE.
+ * PML, is enabled).  Use bits 56 and 57 to hold the type of A/D tracking that
+ * is must be employed for a given TDP SPTE.  Bit 57 is "verify guest paging"
+ * only if the guest-paging verification VM-execution control is set, which
+ * KVM never does.
  *
  * Note, the "enabled" mask must be '0', as bits 62:52 are _reserved_ for PAE
  * paging, including NPT PAE.  This scheme works because legacy shadow paging
@@ -39,7 +42,7 @@
  * TDP with CPU dirty logging (PML).  If NPT ever gains PML-like support, it
  * must be restricted to 64-bit KVM.
  */
-#define SPTE_TDP_AD_SHIFT		60
+#define SPTE_TDP_AD_SHIFT		56
 #define SPTE_TDP_AD_MASK		(3ULL << SPTE_TDP_AD_SHIFT)
 #define SPTE_TDP_AD_ENABLED		(0ULL << SPTE_TDP_AD_SHIFT)
 #define SPTE_TDP_AD_DISABLED		(1ULL << SPTE_TDP_AD_SHIFT)

-- 
2.53.0


  parent reply	other threads:[~2026-12-03 23:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS Dennis Reußwig
2026-12-03 23:49 ` Dennis Reußwig [this message]
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
2026-12-03 23:49 ` [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for " Dennis Reußwig
2026-12-03 23:49 ` [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests Dennis Reußwig
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204-nested-sss-v1-2-57de06f58b2b@reusswig.codes \
    --to=dennis@reusswig.codes \
    --cc=bp@alien8.de \
    --cc=chao.gao@intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jon@nutanix.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mlevitsk@redhat.com \
    --cc=panayotis@panayotis.com \
    --cc=pbonzini@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@kernel.org \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®