[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] nestedsvm: Don't set VMCB(1-2)'s NP_ENABLE and N_CR3 during VMEXIT to L1
- To: Teddy Astie <teddy.astie@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
- Date: Mon, 21 Sep 2026 09:09:43 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SU30me+7oUzPyjyBP7bGt/BtRwrgcEiRGeIVhWCmOoc=; b=Il6fYLt/3++NIUR3KVZ2BEwXpq51j2woLG2zYnQjKJCUewKNUabgGiPelLBwQ2FsxxKUUW+/Wj9umaP/bYDdGea6pFjBlMvZO7VJGZqCgUPsVedGBQlPF5qVFu72MQIDvK5BgiLMCmvZ1WBY+faUMOsvXS9gOn66qb3jg2LzYFYKfBCG19rgKdI0HdYRLcpwX1Ff1DWXw3Y5ZP5ZajQ7m8D2SDpmFxdJ8EfIdKZJx+Q6AX4f8mZb99ZgWpUc6jzt7ey2kgV1E2upRXZo7DQpkVBruz0SKIM18Pq/R0jyMEaxRVoTEs2gKbpv1mJ+KMhZDflRaJAytFTok93qpnYOeg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tvs2/sdIvNt0bb9Wi1LkBdNcwqCteg9DHmbvTyg5TSZVhPt3FZ4zUXIU2Ug5cMacC3V1gboiRzytxFOm3L2ZwSBu7c5igz/kS9o3NJM4WiD2tPm+n6mZxeG+aE+4QJR4dH74SENB19MoiKqCwoRZNKU1el8mbfqlNJXljdA1sXVnkm8mco46FoR6c1iddT44onOi/WmuO42/M5i8HOlROoUPi4+1j2Scalr+RsMXLLJLwgxe2gtcn6shxpjKuWUyU8fPbAHxxU2pka4i94X8/ltYt4s1kaAqBETk/7ZURNpCA/pYmqdofguFHuJHm+x3CxqdXV1xmP30TCZx9RXnZA==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
- Delivery-date: Mon, 21 Sep 2026 08:11:53 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 9/20/26 8:10 PM, Teddy Astie wrote:
Le 18/09/2026 à 14:54, Ross Lagerwall a écrit :
As per the VMRUN pseudocode in APM Vol 3 3.38, the VMCB's NP_ENABLE and
N_CR3 fields are not set during a VMEXIT so don't do this when updating
VMCB(1-2). At the same time, cleanup the somewhat bogus and irrelevant
comments. Not clearing N_CR3 does not introduce a security hole as
stated since L1 can set it regardless and it is never used directly when
running L2.
Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
xen/arch/x86/hvm/svm/nestedsvm.c | 32 +-------------------------------
1 file changed, 1 insertion(+), 31 deletions(-)
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index a8b15d6eae05..c62fca571d75 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -1023,37 +1023,6 @@ nsvm_vmcb_prepare4vmexit(struct vcpu *v, struct
cpu_user_regs *regs)
ns_vmcb->event_inj.raw = 0;
- /* Nested paging mode */
- if ( nestedhvm_paging_mode_hap(v) )
- {
- /* host nested paging + guest nested paging. */
- vmcb_set_np(ns_vmcb, vmcb_get_np(n2vmcb));
- ns_vmcb->_cr3 = n2vmcb->_cr3;
- /* The vmcb->h_cr3 is the shadowed h_cr3. The original
- * unshadowed guest h_cr3 is kept in ns_vmcb->h_cr3,
- * hence we keep the ns_vmcb->h_cr3 value. */
- }
- else if ( paging_mode_hap(v->domain) )
- {
- /* host nested paging + guest shadow paging. */
- vmcb_set_np(ns_vmcb, false);
- /* Throw h_cr3 away. Guest is not allowed to set it or
- * it can break out, otherwise (security hole!) */
- ns_vmcb->_h_cr3 = 0x0;
- /* Stop intercepting #PF (already done above
- * by restoring cached intercepts). */
- ns_vmcb->_cr3 = n2vmcb->_cr3;
- }
- else
- {
- /* host shadow paging + guest shadow paging. */
- vmcb_set_np(ns_vmcb, false);
- ns_vmcb->_h_cr3 = 0x0;
- /* The vmcb->_cr3 is the shadowed cr3. The original
- * unshadowed guest cr3 is kept in ns_vmcb->_cr3,
- * hence we keep the ns_vmcb->_cr3 value. */
- }
-> /* LBR virtualization - keep lbr control as is */
/* NextRIP */
@@ -1083,6 +1052,7 @@ nsvm_vmcb_prepare4vmexit(struct vcpu *v, struct
cpu_user_regs *regs)
/* CRn */
ns_vmcb->_cr4 = n2vmcb->_cr4;
+ ns_vmcb->_cr3 = n2vmcb->_cr3;
ns_vmcb->_cr0 = n2vmcb->_cr0;
I would suggest to group all the CRn (the CR2 part is currently separated).
That can be done separately.
Indeed. The APM says...
"Upon #VMEXIT, the processor performs the following actions in order to return
to the host execution context:"
... so ideally we would rearrange this function to match the order specified
(though it shouldn't make a functional difference).
Ross
|