From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341792; b=gwbyizV2OxQsbCZWTI+GUUVLVIv83jAoeU4F2UKF9cGm4D+4Pdw9BQdLfG2Cw2vqcQuo 5ovZ+yfAFJ2TmpdhGx4Hr6SjOwdJnbHIBJTySsDoZZUp3kvjqOHnxeK5Yoo8wE25i59IT 6Z/f2tqDCKdzRt046YF38gpYcLTsDcbB+/LXrOlB0CdCtwXpyDGHJRtn1bQMg6T87FU/r n+awPHmRrvpfGvMUVZXaZ16G0DxNEbEAYG3mnxQAaGDxCQLbGxHFtP+1Jv5+KAjNMq8b6 2H1IFISTDHUrRjUVz4D/q+VsMIEQ05/COlwEaPTtqyJP0kMmnZfm7txzwLDX89FtjoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341792; h=DMARC-Filter:DKIM-Signature:X-Pm-Submission-Id:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=rwBVbIHXKpIcQGdCDadGW9EeHFoT1ypQX7SzrG7xpRA=; b=3WbPIYXruULp/KiTzBHe9KER/u+Of2cyVj/iu26y1ysQko2TxpQ0RrkSC3MqYRmt/vov JtdUrY2WAp4GxMBNYrtMc7N2FtDxDoW0haZGp7fCq0clt/ZCkOGeecW4R+IWhHe+CQuUj HWdDsxVSCDvoxOv4f9DhwyFktOCdUwQp3I//0Brmos2ElHVZBUAZZach9k66I2q4D4WVw 4ufgH30OnSB/Qm0XOG+TphV1QghZuU+JK5FtCTKBS3fUZETKs2oTDLgxUpJ18BXhZ+L2x NYj0/3aTyuFzdQw18/QAdHwpgsKJqkelwr/F1PhMg/pZyRiE4IMDJHvvstZa8mm5JuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=reusswig.codes; spf=pass smtp.mailfrom=reusswig.codes; dkim=pass header.d=reusswig.codes header.i=@reusswig.codes header.a=rsa-sha256 header.s=protonmail3 header.b=TkqpZ1o4; arc=none smtp.remote-ip=185.70.43.171 Received: from mail-43171.protonmail.ch (mail-43171.protonmail.ch [185.70.43.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DF65606A337; Thu, 3 Dec 2026 23:49:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DF65606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=reusswig.codes Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=reusswig.codes Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=reusswig.codes header.i=@reusswig.codes header.a=rsa-sha256 header.s=protonmail3 header.b=TkqpZ1o4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=reusswig.codes; s=protonmail3; t=1796341788; x=1796600988; bh=rwBVbIHXKpIcQGdCDadGW9EeHFoT1ypQX7SzrG7xpRA=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=TkqpZ1o4pu59mPYqgwXMJP34jaDDUwLWhYErq3HynjjzfDjbt5wUiq1e0q6Yr6Xc1 hbQNP39kADfxGB8O6G3xey4cTfYX32EZAwNW6/RP7+9nVbBY8C6kXK/L94fGwEDelu k9OhXgumgTbmAacbKxaKjL0w0F77ylIP44VZouVvd+AsFxwv61kynW8Hqww823bUg+ 8Kh/6+xMhOyB6YchPQMlqNZLRbm1LufbvP1NNDN30vC4z+tILK/T6rl6ljN9zRcDn2 AEd378LsIPw0++aVYx0ZyD7cP37xcELT0WyzLmv1eGnUjKLgSX/AR8g5a5SyWeSoDt 84RiZsZRaZVng== X-Pm-Submission-Id: 4jgWZL6SnPz2ScNb From: =?utf-8?q?Dennis_Reu=C3=9Fwig?= Date: Fri, 04 Dec 2026 00:49:18 +0100 Subject: [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20261204-nested-sss-v1-5-57de06f58b2b@reusswig.codes> References: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> In-Reply-To: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jon Kohler , Jonathan Corbet , Shuah Khan , Randy Dunlap , Shuah Khan Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Chao Gao , Maxim Levitsky , Vitaly Kuznetsov , Panayotis Katsaloulis , =?utf-8?q?Dennis_Reu=C3=9Fwig?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=15682; i=dennis@reusswig.codes; h=from:subject:message-id; bh=0P6YsajGvncM0t0HOJDNYvYpmnA9btS5tP6kOPcSUTo=; b=owEBbQKS/ZANAwAIAWBucoRlTGuCAcsmYgBrEgAMlPEcaaRaWMiY3P1NuASs2ea3cKzZs6sPr ANSEkxrsVKJAjMEAAEIAB0WIQS59eJ1vy/tsv/LkIBgbnKEZUxrggUCaxIADAAKCRBgbnKEZUxr griED/4n/dGEmGIeOA1PQfJnx+/g3j1tOIsqb8wJrwJQfUp3wW+tFoWpY+Nk08Z9kJxWkiM+OaE QvUoa8oeN7o5iKH/mgwrAzBKNISk3HQorSFpiF32RcoidtOYoOOY2ViTaJ255fe16bbqihcXMaO VkHnbYDa8T2/hYsVCXCY9nqGby480R+tAcnrQOPN7uiKEsGSZRBlPU7GqsMy7zp4BKIy2zWSyGF Z5qa6mr6x7BYud6SWh6/zzTHk8X6aKLH1lura/SG6ZNUSnDxJ6scUw2yxcXx7MwmR4Hm/weJ7xc 9RfftMCzwlvm3qEo9xoF26+SxjJGNHCE6eONJeW1rsI8uJNIJC6qW4+QkYK3S/nggpbt6ot3tLD 7wyvPQuxORXauIo79q2U1YrQ/oJJAsK2QaEpyr1lw5Qqg8dpqJBJfJyJhDmS2r3ToJnTWW6lnCv GQ0bZEGRD+icIQPU/s4jK+a3SzROOxmdELjJDRe+qdu3QlTV/yB/iVi/kALrstka/oCSrQS8AqH tS8dvXBzZnOaHi62xfrR3pyYH+qpuFHKhn7T8AdvwPKzS5augoefgfkL5xZZCubVn7xIti2zqiZ EEnFrTi15SjrXVLIZ0an8BBX+LiCUwsR+rX3FY4uM9ZhBNah616FWKASiK7stlT/XBD6fU0bFRL F4txwJ9OgXz76gw== X-Developer-Key: i=dennis@reusswig.codes; a=openpgp; fpr=D8E955E3BCD7A0A0DEDE55D1B92D668A3A02E8CA If bit 7 of L1's EPTP is set, supervisor shadow-stack accesses of L2 are allowed if every entry of the walk is readable, every non-leaf entry is writable and the leaf sets bit 60; the write bit of the leaf does not matter (SDM Vol. 3C, 31.3.3.2). User shadow-stack accesses and the accesses to the guest paging structures follow the normal rules. Implement this in the nested EPT MMU: - add role.ept_sss, so that shadow pages for EPTP bit 7 set and clear are not shared, and set bit 7 in the EPTP of such roots so that the CPU enforces bit 60 of the shadow SPTEs; - in FNAME(walk_addr_generic), check supervisor shadow-stack accesses against bit 60 and set the Dirty flag for them like for writes, and pass the permission to the SPTEs in FNAME(fetch), FNAME(prefetch_gpte) and FNAME(sync_spte); - report bit 13 (shadow-stack access) and bit 14 (bit 60 of the leaf) in the exit qualification of EPT violations reflected to L1. The role grows to 22 bits. Update the comment that bounds the number of shadow pages per gfn: it was already one bit low (21 - 2 - 2 - 2 = 15, not 14) and named execonly, which is in the extended role. L1 cannot set EPTP bit 7 yet, because nested_vmx_check_eptp() rejects it; the next patch allows it. Signed-off-by: Dennis Reußwig --- Documentation/virt/kvm/x86/mmu.rst | 4 ++ arch/x86/include/asm/kvm_host.h | 18 +++++--- arch/x86/include/asm/vmx.h | 2 + arch/x86/kvm/mmu.h | 2 +- arch/x86/kvm/mmu/mmu.c | 12 +++-- arch/x86/kvm/mmu/paging_tmpl.h | 90 +++++++++++++++++++++++++++++++++++--- arch/x86/kvm/vmx/nested.c | 1 + arch/x86/kvm/vmx/vmx.c | 4 ++ 8 files changed, 119 insertions(+), 14 deletions(-) diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst index 666aa179601a..4067b483876e 100644 --- a/Documentation/virt/kvm/x86/mmu.rst +++ b/Documentation/virt/kvm/x86/mmu.rst @@ -206,6 +206,10 @@ Shadow pages contain the following information: The page is not backed by a guest page table, but its first entry points to one. This is set if NPT uses 5-level page tables (host CR4.LA57=1) and is shadowing L1's 4-level NPT (L1 CR4.LA57=0). + role.ept_sss: + Is 1 if the page shadows L1 EPT with supervisor shadow-stack control + (EPTP bit 7). Bit 60 of a leaf SPTE then grants L2 supervisor + shadow-stack accesses, and KVM treats it like a write permission. mmu_valid_gen: The MMU generation of this page, used to fast zap of all MMU pages within a VM without blocking vCPUs too long. Specifically, KVM updates the per-VM diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3efef3415f8e..43e582507e39 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -319,14 +319,14 @@ extern struct kvm_host_values kvm_host; * the number of unique SPs that can theoretically be created is 2^n, where n * is the number of bits that are used to compute the role. * - * But, even though there are 21 bits in the mask below, not all combinations + * But, even though there are 22 bits in the mask below, not all combinations * of modes and flags are possible: * * - invalid shadow pages are not accounted, mirror pages are not shadowed, - * so the bits are effectively 19. + * so the bits are effectively 20. * * - quadrant will only be used if has_4_byte_gpte=1 (non-PAE paging); - * execonly and ad_disabled are only used for nested EPT which has + * ad_disabled and ept_sss are only used for nested EPT which has * has_4_byte_gpte=0. Therefore, 2 bits are always unused. * * - the 4 bits of level are effectively limited to the values 2/3/4/5, @@ -338,7 +338,7 @@ extern struct kvm_host_values kvm_host; * therefore these two bits only give rise to 3 possibilities. * * Therefore, the maximum number of possible upper-level shadow pages for a - * single gfn is a bit less than 2^14. + * single gfn is a bit less than 2^16. */ union kvm_mmu_page_role { u32 word; @@ -366,7 +366,15 @@ union kvm_mmu_page_role { */ unsigned cr4_smep:1; - unsigned:3; + /* + * Nested EPT with supervisor shadow-stack control (EPTP bit 7). + * EPT bit 60 of a leaf SPTE grants supervisor shadow-stack + * accesses only if the EPTP sets bit 7, so SPTEs built for one + * setting are not valid for the other. + */ + unsigned ept_sss:1; + + unsigned:2; /* * This is left at the top of the word so that diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 79646365369f..df6feba112f7 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -559,6 +559,7 @@ enum vmcs_field { #define VMX_EPTP_PWL_4 0x18ull #define VMX_EPTP_PWL_5 0x20ull #define VMX_EPTP_AD_ENABLE_BIT (1ull << 6) +#define VMX_EPTP_SSS_BIT (1ull << 7) /* The EPTP memtype is encoded in bits 2:0, i.e. doesn't need to be shifted. */ #define VMX_EPTP_MT_MASK 0x7ull #define VMX_EPTP_MT_WB X86_MEMTYPE_WB @@ -632,6 +633,7 @@ enum vm_entry_failure_code { #define EPT_VIOLATION_GVA_WRITABLE BIT(10) #define EPT_VIOLATION_GVA_NX BIT(11) #define EPT_VIOLATION_SHADOW_STACK BIT(13) +#define EPT_VIOLATION_SSS_PAGE BIT(14) #define EPT_VIOLATION_RWX_TO_PROT(__epte) (((__epte) & VMX_EPT_RWX_MASK) << 3) #define EPT_VIOLATION_USER_EXEC_TO_PROT(__epte) (((__epte) & VMX_EPT_USER_EXECUTABLE_MASK) >> 4) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 3d4de461e948..09f6f48ebc5f 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -151,7 +151,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr4, u64 efer, gpa_t nested_cr3, u64 misc_ctl); void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly, int huge_page_level, bool accessed_dirty, - bool mbec, gpa_t new_eptp); + bool mbec, bool sss, gpa_t new_eptp); int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code, void *insn, int insn_len); diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index d2aa576f97cd..39637dca870f 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -246,6 +246,11 @@ static inline bool has_pferr_fetch(struct kvm_pagewalk *w) return w->cpu_role.ext.has_pferr_fetch; } +static inline bool is_ept_sss(struct kvm_pagewalk *w) +{ + return w->cpu_role.base.ept_sss; +} + static inline bool is_cr0_pg(struct kvm_pagewalk *w) { return w->cpu_role.base.level > 0; @@ -6217,7 +6222,7 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_init_shadow_npt_mmu); static union kvm_cpu_role kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty, - bool execonly, u8 level, bool mbec) + bool execonly, u8 level, bool mbec, bool sss) { union kvm_cpu_role role = {0}; @@ -6228,6 +6233,7 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty, WARN_ON_ONCE(is_smm(vcpu)); role.base.level = level; role.base.cr4_smep = mbec; + role.base.ept_sss = sss; role.base.has_4_byte_gpte = false; role.base.direct = false; role.base.ad_disabled = !accessed_dirty; @@ -6243,13 +6249,13 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty, void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly, int huge_page_level, bool accessed_dirty, - bool mbec, gpa_t new_eptp) + bool mbec, bool sss, gpa_t new_eptp) { struct kvm_mmu *context = &vcpu->arch.guest_mmu; u8 level = vmx_eptp_page_walk_level(new_eptp); union kvm_cpu_role new_mode = kvm_calc_shadow_ept_root_page_role(vcpu, accessed_dirty, - execonly, level, mbec); + execonly, level, mbec, sss); struct kvm_pagewalk *ngpa_walk = &vcpu->arch.ngpa_walk; diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 939a10fc1110..02421e74ec36 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -88,6 +88,8 @@ struct guest_walker { bool pte_writable[PT_MAX_FULL_LEVELS]; unsigned int pt_access[PT_MAX_FULL_LEVELS]; unsigned int pte_access; + /* ACC_EPT_SSS_MASK if the leaf grants supervisor shadow-stack accesses. */ + unsigned int sss_access; gfn_t gfn; struct x86_exception fault; }; @@ -124,6 +126,55 @@ static inline void FNAME(protect_clean_gpte)(struct kvm_pagewalk *w, unsigned *a *access &= mask; } +/* + * Supervisor shadow-stack accesses through nested EPT with EPTP bit 7 set are + * governed by bit 60 of the leaf instead of its write bit: the access is + * allowed if the leaf sets bit 60, every entry is readable and every non-leaf + * entry is writable (SDM Vol. 3C 31.3.3.2). User shadow-stack accesses keep + * the normal rules. For EPT, PFERR_USER_MASK reports a user-mode linear + * address (advanced VM-exit information). The CPU also reports the guest + * paging-structure accesses of a shadow-stack access as shadow-stack + * accesses; those are ordinary reads and writes of the paging structure. + */ +static inline bool FNAME(is_sss_access)(struct kvm_pagewalk *w, u64 access) +{ +#if PTTYPE == PTTYPE_EPT + return is_ept_sss(w) && (access & PFERR_SS_MASK) && + !(access & (PFERR_USER_MASK | PFERR_GUEST_PAGE_MASK)); +#else + return false; +#endif +} + +/* + * Return ACC_EPT_SSS_MASK if @gpte grants supervisor shadow-stack accesses. + * @pt_access holds the ACC_* permissions of the non-leaf entries above it. + * Bit 60 also allows shadow-stack writes, so it is withheld from leaves whose + * Dirty flag is clear unless @dirty: the first shadow-stack access then + * faults and the walker sets the Dirty flag, as for writes. + */ +static inline unsigned int FNAME(gpte_sss_access)(struct kvm_pagewalk *w, + unsigned int pt_access, + pt_element_t gpte, bool dirty) +{ +#if PTTYPE == PTTYPE_EPT + if (!is_ept_sss(w) || !(gpte & VMX_EPT_SSS_MASK) || + !(gpte & VMX_EPT_READABLE_MASK)) + return 0; + + if ((pt_access & (ACC_READ_MASK | ACC_WRITE_MASK)) != + (ACC_READ_MASK | ACC_WRITE_MASK)) + return 0; + + if (!dirty && PT_HAVE_ACCESSED_DIRTY(w) && !(gpte & PT_GUEST_DIRTY_MASK)) + return 0; + + return ACC_EPT_SSS_MASK; +#else + return 0; +#endif +} + static inline int FNAME(is_present_gpte)(struct kvm_pagewalk *w, unsigned long pte) { @@ -329,6 +380,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, u64 walk_nx_mask = 0; const int write_fault = access & PFERR_WRITE_MASK; const int fetch_fault = access & PFERR_FETCH_MASK; + /* + * Supervisor shadow-stack accesses under EPTP bit 7 can write the page, + * so they set the Dirty flag even when they only read the shadow stack. + */ + const bool sss_fault = FNAME(is_sss_access)(w, access); + const bool dirty_fault = write_fault || sss_fault; /* * Note! Track the error_code that's common to legacy shadow paging * and NPT shadow paging as a u16 to guard against unintentionally @@ -452,7 +509,13 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, /* Convert to ACC_*_MASK flags for struct guest_walker. */ walker->pte_access = FNAME(gpte_access)(pte_access ^ walk_nx_mask); - errcode = permission_fault(vcpu, w, walker->pte_access, pte_pkey, access); + walker->sss_access = FNAME(gpte_sss_access)(w, + walker->pt_access[walker->level - 1], + pte, true); + if (sss_fault) + errcode = walker->sss_access ? 0 : PFERR_PRESENT_MASK; + else + errcode = permission_fault(vcpu, w, walker->pte_access, pte_pkey, access); if (unlikely(errcode)) goto error; @@ -472,9 +535,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, walker->gfn = real_gpa >> PAGE_SHIFT; - if (!write_fault) + if (!dirty_fault) { FNAME(protect_clean_gpte)(w, &walker->pte_access, pte); - else + walker->sss_access = FNAME(gpte_sss_access)(w, + walker->pt_access[walker->level - 1], + pte, false); + } else { /* * On a write fault, fold the dirty bit into accessed_dirty. * For modes without A/D bits support accessed_dirty will be @@ -482,10 +548,11 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, */ accessed_dirty &= pte >> (PT_GUEST_DIRTY_SHIFT - PT_GUEST_ACCESSED_SHIFT); + } if (unlikely(!accessed_dirty)) { ret = FNAME(update_accessed_dirty_bits)(vcpu, w, walker, - addr, write_fault); + addr, dirty_fault); if (unlikely(ret < 0)) goto error; else if (ret) { @@ -556,6 +623,14 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, if (is_cr4_smep(w)) walker->fault.exit_qualification |= EPT_VIOLATION_USER_EXEC_TO_PROT(pte_access); + if (access & PFERR_SS_MASK) + walker->fault.exit_qualification |= EPT_VIOLATION_SHADOW_STACK; + /* + * Bit 14 mirrors bit 60 of the leaf; it is undefined if the walk + * stopped earlier, so report the last entry read either way. + */ + if (is_ept_sss(w) && (pte & VMX_EPT_SSS_MASK)) + walker->fault.exit_qualification |= EPT_VIOLATION_SSS_PAGE; } #endif walker->fault.address = addr; @@ -591,6 +666,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, gfn = gpte_to_gfn(gpte); pte_access = sp->role.access & FNAME(gpte_access)(gpte); FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte); + pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access, + gpte, false); return kvm_mmu_prefetch_sptes(vcpu, gfn, spte, 1, pte_access); } @@ -789,7 +866,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, if (KVM_BUG_ON(it.level != fault->goal_level, vcpu->kvm)) return -EIO; - ret = mmu_set_spte(vcpu, fault->slot, it.sptep, gw->pte_access, + ret = mmu_set_spte(vcpu, fault->slot, it.sptep, + gw->pte_access | gw->sss_access, base_gfn, fault->pfn, fault); if (ret == RET_PF_SPURIOUS) return ret; @@ -973,6 +1051,8 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int pte_access = sp->role.access; pte_access &= FNAME(gpte_access)(gpte); FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte); + pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access, + gpte, false); if (sync_mmio_spte(vcpu, &sp->spt[i], gfn, pte_access)) return 0; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index a7c8bbdfe4ca..dc7199855497 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -519,6 +519,7 @@ static void nested_ept_new_eptp(struct kvm_vcpu *vcpu) kvm_init_shadow_ept_mmu(vcpu, execonly, ept_lpage_level, nested_ept_ad_enabled(vcpu), nested_ept_mbec_enabled(vcpu), + nested_ept_get_eptp(vcpu) & VMX_EPTP_SSS_BIT, nested_ept_get_eptp(vcpu)); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 68fa251dda60..57aa8b3be509 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3361,6 +3361,10 @@ static u64 construct_eptp(hpa_t root_hpa) if (enable_ept_ad_bits && !root->role.ad_disabled) eptp |= VMX_EPTP_AD_ENABLE_BIT; + /* Only nested EPT roots for an L1 EPTP with bit 7 set. */ + if (root->role.ept_sss) + eptp |= VMX_EPTP_SSS_BIT; + return eptp; } -- 2.53.0