From nobody Mon Nov 23 22:28:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794294645; cv=none; d=zohomail.com; s=zohoarc; b=LldpOqtyTFSK8ileaApT6nzCWuPKBXgQxl/nGRoCxEwpbmle1kr+eTJsaaQX9KNa7Dd8ZclKXCKdW4ksMZ8ZwNCHnLMEb1Ub69oOju+LpzeiBizdsS1eSc4AYUjm+vDmYHk2t+lxgmoNT28awVESfeBncIsaXlWuI00ijak4aUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794294645; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0lqZDBduZu05Iia47gN/7mGdgXvDzEOEnsPvIYGH5T4=; b=FAmUj3Eqhl7SMfqiVh0qgGxN7OcNcxgTiJTBzDJW7ZbZ2DbQFyQ5EW9SnPB8iflN3RLnITCpGkYEqBK7zt5eTCx1yEeGpylGHuhp1V1PgsxL9tZzRscLo2KUPgs6ArsDU5a1YqdcUejceT4RM5FmMFylLa8FwboEmybK1FacxAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794294645401398.4546614273888; Mon, 9 Nov 2026 23:10:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1480674.1684441 (Exim 4.92) (envelope-from ) id 1xQfzg-0006IR-8D; Tue, 10 Nov 2026 07:10:12 +0000 Received: by outflank-mailman (output) from mailman id 1480674.1684441; Tue, 10 Nov 2026 07:10:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQfzg-0006IK-5i; Tue, 10 Nov 2026 07:10:12 +0000 Received: by outflank-mailman (input) for mailman id 1480674; Tue, 10 Nov 2026 06:35:04 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQfRg-0001fP-3B for xen-devel@lists.xenproject.org; Tue, 10 Nov 2026 06:35:04 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQfRf-00Gp7q-96 for xen-devel@lists.xenproject.org; Tue, 10 Nov 2026 07:35:03 +0100 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af2bb15-bab6-0a2a0a5309dd-0a2a4509d526-6 for ; Tue, 10 Nov 2026 07:35:03 +0100 Received: from [209.85.216.44] (helo=mail-pj1-f44.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af2bb15-be1a-0a2a45090019-d155d82cd46f-3 for ; Tue, 10 Nov 2026 07:35:02 +0100 Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3b0d09df973so1277588a91.0 for ; Mon, 09 Nov 2026 22:35:02 -0800 (PST) Received: from cs-arch-srv04.cmpt.sfu.ca (cs-arch-srv04.cmpt.sfu.ca. [142.58.10.48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b16708f533sm2560410a91.2.2026.11.09.22.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 22:35:00 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794292501; x=1794897301; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=0lqZDBduZu05Iia47gN/7mGdgXvDzEOEnsPvIYGH5T4=; b=EufH1KwbL1huH2eRS+OxaZbwYasvTK2K+vvdvcoP33aCwQn7/NGqxM02l1jLiAlMHu aj89ePLnp4k10DBAYa3sZlMqB5ACy9hATtDjUKNWs4CHJk4J+F2fUK6PipnDOuVR6YV8 HXsrbkT5NEFjvcy6KB0VMZmDz2p8UZyUZftmgKRJnYnTInnX8ZYdfH+afy9k3L00ckNu Auz0AGXCCz1y9RMXSmmhQUGsFsYGmspq6iuPrVSNuGs5ef/eacuB6V1KEy9u2KlZYfxp xytmRSHA9Kwk1HGJfNCTxXSjCYb+Sr9AuBeo5OBM/UvnbL2xg5HOTOOiyOhkUmjYFj5+ d5DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794292501; x=1794897301; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0lqZDBduZu05Iia47gN/7mGdgXvDzEOEnsPvIYGH5T4=; b=qGTtuZZcLXnzLQj67kbGLm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EdRBTHHfd6mb+KvF6n43fWlNvawJE240rv03iIQHULE1zPcJdkDXlJSb0YOjL1Zzy/kS S5YrIy9jqk7WH8EgOpyHOW6ryVnSkkLv3V5gNkdKQg9ntTC1nX8lyxMUvVcmb0Qm7YWJCxRv2ZB gW2hykShmbHA== X-Received: by 2002:a17:90b:1a8e:b0:3a8:5cab:1009 with SMTP id 98e67ed59e1d1-3b166fb76a8mr1996164a91.46.1794292500677; Mon, 09 Nov 2026 22:35:00 -0800 (PST) From: Mahmoud Abumandour To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Mahmoud Abumandour Subject: [PATCH] x86/nestedhvm: process the MSR-load and MSR-store areas of L1's VMCS Date: Mon, 9 Nov 2026 22:33:34 -0800 Message-Id: <20261110063334.2029620-1-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1794292502-FC212034-AC172E0D/0/0 X-purgate-type: clean X-purgate-size: 10587 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794294647736158500 Content-Type: text/plain; charset="utf-8" Nothing in vvmx.c reads the VM-entry MSR-load, VM-exit MSR-store or VM-exit MSR-load area of L1's VMCS, so L2 runs with the listed MSRs as the previous L2 or L1 left them, and L1 gets neither L2's values stored nor its own loaded back. Process each area where the SDM does, with the SDM's checks, an entry as a WRMSR or RDMSR at CPL 0 that L1 does not intercept. A bad VM-entry entry fails the VM entry with exit reason 34 and leaves the VMCS unlaunched, a bad VM-exit entry is a VMX abort, which crashes the domain, and IA32_VMX_MISC now recommends the 512 entries an area may hold. Fixes: 9390642b7fa5 ("Nested VMX: Switch shadow/virtual VMCS between n1/n2 = guests.") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Mahmoud Abumandour --- Found by a fuzzer for VMX isolation. A VMX abort crashes the domain as vvmx.c does elsewhere when nested VMX cannot continue. Alternatives: hvm_triple_fault(), which applies the domain's triple-fault action (reboot by default), as KVM does, or hvm_vcpu_down() on the aborting vCPU alone with the VMX-abort indicator written, which is closest to the SDM but needs more code. Happy to switch to either. xen/arch/x86/hvm/vmx/vvmx.c | 135 ++++++++++++++++++++---- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 1 + 2 files changed, 117 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 3309432873..af93beacb1 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -23,6 +23,8 @@ static DEFINE_PER_CPU(u64 *, vvmcs_buf); =20 static void nvmx_purge_vvmcs(struct vcpu *v); +static int set_vvmcs_launched(struct list_head *launched_list, + unsigned long vvmcs_mfn); =20 static bool nvmx_vcpu_in_vmx(const struct vcpu *v) { @@ -1212,11 +1214,67 @@ static void nvmx_clear_vmcs_pointer(struct vcpu *v,= struct vmcs_struct *vvmcs) __vmwrite(VMWRITE_BITMAP, 0); } =20 -static void virtual_vmentry(struct cpu_user_regs *regs) +/* The longest MSR list that IA32_VMX_MISC recommends to L1. */ +#define NVMX_MAX_MSRS 512 + +/* A nonempty MSR area must be 16-byte aligned and within MAXPHYADDR. */ +static bool msr_area_valid(const struct vcpu *v, unsigned int addr_field, + unsigned int count_field) +{ + uint64_t addr =3D get_vvmcs(v, addr_field); + uint64_t count =3D get_vvmcs(v, count_field); + unsigned int width =3D v->domain->arch.cpuid->extd.maxphysaddr; + + return !count || + (!(addr & 0xf) && !(addr >> width) && + !((addr + count * sizeof(struct vmx_msr_entry) - 1) >> width)); +} + +/* + * Load or store an MSR area of L1's VMCS, each entry as an unintercepted + * WRMSR or RDMSR. Returns 0, or the 1-based index of the failing entry. + */ +static unsigned int process_msr_area(struct vcpu *v, unsigned int addr_fie= ld, + unsigned int count_field) +{ + paddr_t addr =3D get_vvmcs(v, addr_field); + unsigned int i, count =3D get_vvmcs(v, count_field); + struct vmx_msr_entry ent; + + for ( i =3D 0; i < count; i++, addr +=3D sizeof(ent) ) + { + if ( i =3D=3D NVMX_MAX_MSRS || + hvm_copy_from_guest_phys(&ent, addr, + sizeof(ent)) !=3D HVMTRANS_okay || + ent.mbz || + (ent.index >=3D MSR_X2APIC_FIRST && ent.index <=3D MSR_X2APIC= _LAST) ) + return i + 1; + + if ( addr_field =3D=3D VM_EXIT_MSR_STORE_ADDR ) + { + if ( hvm_msr_read_intercept(ent.index, &ent.data) !=3D X86EMUL= _OKAY || + hvm_copy_to_guest_phys(addr + offsetof(struct vmx_msr_ent= ry, + data), + &ent.data, sizeof(ent.data), + v) !=3D HVMTRANS_okay ) + return i + 1; + } + else if ( ent.index =3D=3D MSR_FS_BASE || ent.index =3D=3D MSR_GS_= BASE || + hvm_msr_write_intercept(ent.index, ent.data, + false) !=3D X86EMUL_OKAY ) + return i + 1; + } + + return 0; +} + +/* Returns 0, or the 1-based index of the failing MSR-load entry. */ +static unsigned int virtual_vmentry(struct cpu_user_regs *regs) { struct vcpu *v =3D current; struct nestedvcpu *nvcpu =3D &vcpu_nestedhvm(v); unsigned long lm_l1, lm_l2; + unsigned int msr_fail; =20 vmx_vmcs_switch(v->arch.hvm.vmx.vmcs_pa, nvcpu->nv_n2vmcx_pa); =20 @@ -1277,6 +1335,15 @@ static void virtual_vmentry(struct cpu_user_regs *re= gs) } } =20 + /* MSRs load last, and only a successful entry launches the VMCS. */ + msr_fail =3D process_msr_area(v, VM_ENTRY_MSR_LOAD_ADDR, + VM_ENTRY_MSR_LOAD_COUNT); + if ( !msr_fail && + set_vvmcs_launched(&vcpu_2_nvmx(v).launched_list, + PFN_DOWN(v->arch.hvm.vmx.vmcs_shadow_maddr)) <= 0 ) + domain_crash(v->domain); + + return msr_fail; } =20 static void sync_vvmcs_guest_state(struct vcpu *v, struct cpu_user_regs *r= egs) @@ -1454,19 +1521,37 @@ static void nvmx_update_apicv(struct vcpu *v) } } =20 -static void virtual_vmexit(struct cpu_user_regs *regs) +/* + * A VM exit, or with msr_fail a VM entry that failed loading MSRs, which + * records only the exit reason and qualification and saves nothing. + */ +static void virtual_vmexit(struct cpu_user_regs *regs, unsigned int msr_fa= il) { struct vcpu *v =3D current; struct nestedvcpu *nvcpu =3D &vcpu_nestedhvm(v); - unsigned long lm_l1, lm_l2; + unsigned long lm_l1, lm_l2, intr_info =3D 0; =20 - sync_vvmcs_ro(v); - sync_vvmcs_guest_state(v, regs); - sync_exception_state(v); + if ( msr_fail ) + { + intr_info =3D get_vvmcs(v, VM_ENTRY_INTR_INFO); + set_vvmcs(v, VM_EXIT_REASON, + VMX_EXIT_REASONS_FAILED_VMENTRY | EXIT_REASON_MSR_LOADIN= G); + set_vvmcs(v, EXIT_QUALIFICATION, msr_fail); + } + else + { + sync_vvmcs_ro(v); + sync_vvmcs_guest_state(v, regs); + sync_exception_state(v); =20 - if ( nvmx_ept_enabled(v) && hvm_pae_enabled(v) && - !hvm_long_mode_active(v) ) - shadow_to_vvmcs_bulk(v, ARRAY_SIZE(gpdpte_fields), gpdpte_fields); + if ( nvmx_ept_enabled(v) && hvm_pae_enabled(v) && + !hvm_long_mode_active(v) ) + shadow_to_vvmcs_bulk(v, ARRAY_SIZE(gpdpte_fields), gpdpte_fiel= ds); + + if ( process_msr_area(v, VM_EXIT_MSR_STORE_ADDR, + VM_EXIT_MSR_STORE_COUNT) ) + domain_crash(v->domain, "%pv VMX abort: storing MSRs failed\n"= , v); + } =20 /* This will clear current pCPU bit in p2m->dirty_cpumask */ np2m_schedule(NP2M_SCHEDLE_OUT); @@ -1490,6 +1575,9 @@ static void virtual_vmexit(struct cpu_user_regs *regs) vmx_update_exception_bitmap(v); =20 load_vvmcs_host_state(v); + /* A failed VM entry keeps its interruption information. */ + if ( msr_fail ) + set_vvmcs(v, VM_ENTRY_INTR_INFO, intr_info); =20 if ( lm_l1 !=3D lm_l2 ) paging_update_paging_modes(v); @@ -1499,6 +1587,9 @@ static void virtual_vmexit(struct cpu_user_regs *regs) /* VM exit clears all bits except bit 1 */ regs->rflags =3D X86_EFLAGS_MBS; =20 + if ( process_msr_area(v, VM_EXIT_MSR_LOAD_ADDR, VM_EXIT_MSR_LOAD_COUNT= ) ) + domain_crash(v->domain, "%pv VMX abort: loading MSRs failed\n", v); + if ( cpu_has_vmx_virtual_intr_delivery ) nvmx_update_apicv(v); =20 @@ -1553,9 +1644,14 @@ void asmlinkage nvmx_switch_guest(void) return; =20 if ( nestedhvm_vcpu_in_guestmode(v) && nvcpu->nv_vmexit_pending ) - virtual_vmexit(regs); + virtual_vmexit(regs, 0); else if ( !nestedhvm_vcpu_in_guestmode(v) && nvcpu->nv_vmentry_pending= ) - virtual_vmentry(regs); + { + unsigned int msr_fail =3D virtual_vmentry(regs); + + if ( msr_fail ) + virtual_vmexit(regs, msr_fail); + } } =20 /* @@ -1704,6 +1800,11 @@ static enum vmx_insn_errno nvmx_vmresume(struct vcpu= *v) goto invalid_control_state; } =20 + if ( !msr_area_valid(v, VM_EXIT_MSR_STORE_ADDR, VM_EXIT_MSR_STORE_COUN= T) || + !msr_area_valid(v, VM_EXIT_MSR_LOAD_ADDR, VM_EXIT_MSR_LOAD_COUNT)= || + !msr_area_valid(v, VM_ENTRY_MSR_LOAD_ADDR, VM_ENTRY_MSR_LOAD_COUN= T) ) + goto invalid_control_state; + nvcpu->nv_vmentry_pending =3D 1; =20 return VMX_INSN_SUCCEED; @@ -1777,15 +1878,10 @@ static int nvmx_handle_vmlaunch(struct cpu_user_reg= s *regs) return X86EMUL_OKAY; } else { + /* virtual_vmentry() launches the VMCS. */ rc =3D nvmx_vmresume(v); if ( rc ) vmfail_valid(regs, rc); - else - { - if ( set_vvmcs_launched(&nvmx->launched_list, - PFN_DOWN(v->arch.hvm.vmx.vmcs_shadow_m= addr)) < 0 ) - return X86EMUL_UNHANDLEABLE; - } rc =3D X86EMUL_OKAY; } return rc; @@ -2354,8 +2450,9 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 *ms= r_content) data =3D hvm_cr4_guest_valid_bits(d); break; case MSR_IA32_VMX_MISC: - /* Do not support CR3-targets or activity states. */ - data =3D host_data & ~(VMX_MISC_CR3_TARGET | VMX_MISC_ACTIVITY_MAS= K); + /* No CR3-targets or activity states; MSR lists of NVMX_MAX_MSRS. = */ + data =3D host_data & ~(VMX_MISC_CR3_TARGET | VMX_MISC_ACTIVITY_MAS= K | + VMX_MISC_MAX_MSRS); break; case MSR_IA32_VMX_EPT_VPID_CAP: data =3D nept_get_ept_vpid_cap(); diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include= /asm/hvm/vmx/vmcs.h index d0716e97d2..24b502382f 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -304,6 +304,7 @@ void vmx_vmcs_reload(struct vcpu *v); #define VMX_MISC_ACTIVITY_MASK 0x000001c0 #define VMX_MISC_PROC_TRACE 0x00004000 #define VMX_MISC_CR3_TARGET 0x01ff0000 +#define VMX_MISC_MAX_MSRS 0x0e000000 #define VMX_MISC_VMWRITE_ALL 0x20000000 =20 #define VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL --=20 2.25.1