Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5FD36C43602 for ; Wed, 8 Jul 2026 07:07:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1356632.1611202 (Exim 4.92) (envelope-from ) id 1whMNe-0000iL-EE; Wed, 08 Jul 2026 07:07:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1356632.1611202; Wed, 08 Jul 2026 07:07:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1whMNe-0000iD-A0; Wed, 08 Jul 2026 07:07:38 +0000 Received: by outflank-mailman (input) for mailman id 1356632; Wed, 08 Jul 2026 07:07:37 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1whMNd-0000go-5m for xen-devel@lists.xenproject.org; Wed, 08 Jul 2026 07:07:37 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1whMNb-00GZJo-Ub for xen-devel@lists.xenproject.org; Wed, 08 Jul 2026 09:07:35 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a4df737-5cb7-0a2a0a5109dd-0a2a4502c76c-0 for ; Wed, 08 Jul 2026 09:07:35 +0200 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a4df737-5a27-0a2a45020019-d1558033ddc9-3 for ; Wed, 08 Jul 2026 09:07:35 +0200 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-493c2c0b9a8so2353635e9.1 for ; Wed, 08 Jul 2026 00:07:35 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493e0f51193sm116283825e9.12.2026.07.08.00.07.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jul 2026 00:07:34 -0700 (PDT) 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=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1783494455; x=1784099255; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IlgP6o8P3+QTU56avtjZ6NtN6wrlyE7EMZj2/RyLlxA=; b=CDLsEHaIjZoh/XTStGfjSV1eMz5lMLBoVaZQV0fBHU1RF7boX5yyngrAHdT0lzAoJ9 rdcQJdoC4qTst94wkY1rjxmvjZwLKIryO06PEHP4NWw1htQdYdbCAwcUY6euGfhQNoMt M7U2zLNk+T3t8m/WLGebcxiCOYsO6sYLb42XKtUtMSsREoqRLMa5TtEIGL9zF35NxNop 7SbzdkLjvmrhXnpbpgQg/JDMwHcDsiNxGIcoR9Hc0BsffLMVIuaspKCCLdcTqoXn4Oes aQB08LUGsEHA5gsZWfwi1GmWhPLCgXfJUhatfREE7i7q0zg5E1nuBG4S36aLX3CKrj8J J8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783494455; x=1784099255; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IlgP6o8P3+QTU56avtjZ6NtN6wrlyE7EMZj2/RyLlxA=; b=PybGLOWWwbU5zkeV0lSpN2yVnB5xKmFqSPhCouhke+idHNJezMlj/o+TcdNGQ/eoJr ecYl9aj/Ig2Ps3guIR+MICY5hy/NGGk07EISCsXZhIKnQnZy50ZKiLFUQjPIpSqb9FI9 nuTHqOB5k85SmBwBpBBNz3isanmcQKYK3br79X41q+r0sQxweY3TwHwOz2CARP/016+x DFJ70VpqzVBJFp4jamDsiWGvC73gBA9VILfs0U32VD2RtkeeB458wDDWzLoh9+OmbLrj hUixPTjRAcImkENw27S+CXebTY30WA7uP2oGTBXm+E2fJ5FsHkcSfdpvr1vuxtwjNpUK 9tiQ== X-Forwarded-Encrypted: i=1; AHgh+Rr1+16fqISmHBcDy5rRU48Lo7oJquepCRKq7/+BGX7PoDq9gcxSa9OwjVoqmwDEJIo9Jjm1D7y+T2E=@lists.xenproject.org X-Gm-Message-State: AOJu0YxacE09JbBRz83L/k3Re5SAX2qiz2sEuwo6t6iJhrrhsm5Y6c0A vgcZ4x8l29tA4Fq2LthruE2R0C2IrHrbNW2Mt73RgbMsGFEftRddQCKb2oIxsxXhgA== X-Gm-Gg: AfdE7ckZgQur+oHh6e8/w9Ak0dQULAzeRsssMfSDXbizszqQ79XBr8OXCZ3jc0rU+k0 u7XVLhiyIPgk14qxi+rCC01/h1zlddqeDL9Zipa1xvV8UaLjdEwkXOlZ8v9Wi6tc0j2YD4htVZ8 F2Ns+V59/Jud+Q0afHlysO18cjXLHPsE84sovSWAMZbmqjbkVuEw6B7HoKlAFolJZIgyI6zQBlt TDAK/C6BAD9IBsZbftMjFLIgk0EK35S051A0XgdD9CuH8I+fY3C6/FmMlJ3Oh/J091x26I5fSxl m0x08DoCZ6l5+HubAdBI+CzEl6cMEp/m/5bJ+RNmm9oCSO1dvTp8RpsYbxLqeyPHT/yN38yNiAH 7JOrlr0SkB7A6ud2Bvg/0lcXaoz6EUpi6/gN9wVP1b80JGs4tSYYH0xHzXUBloUQ0VRiLOaBFNr vXKFMQXLeUCV+duz4OWepKxSoCimGCER72aMDI70VljZSrTr0QaKIw3+ZLRRFVxfxiMgTVaxBmP +R4 X-Received: by 2002:a05:600d:8444:10b0:493:de4b:de17 with SMTP id 5b1f17b1804b1-493e68c5ee4mr8020315e9.14.1783494454996; Wed, 08 Jul 2026 00:07:34 -0700 (PDT) Message-ID: <7b6e99b4-f2be-4bbe-b29f-98a02b0a231f@suse.com> Date: Wed, 8 Jul 2026 09:07:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/vmx: Fix cascade crash in vmx_vmentry_failure() To: Andrew Cooper Cc: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie , Xen-devel References: <20260707193521.1423908-1-andrew.cooper3@citrix.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUS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/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <20260707193521.1423908-1-andrew.cooper3@citrix.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-720697/1783494455-4F51C7C5-46867C5E/0/0 X-purgate-type: clean X-purgate-size: 7159 On 07.07.2026 21:35, Andrew Cooper wrote: > The VMEntry failure handling does not distinguish VMFail Valid vs Invalid. In > the latter case, vmx_vmentry_failure() will hit a BUG() when trying to look up > VM_INSTRUCTION_ERROR. That's the BUG() in __vmread(), I expect? I suppose this is also connected to ... > Slightly RFC - it's fairly hard to these these. It came from code inspection > rather than encountering a VMFailInvalid case in practice. ... this. (Presumably the first "these" also was meant to be "observe" or "hit" or some such.) What I'm having difficulty with is seeing how we would make it as far: If said __vmread() hit its BUG(), wouldn't all earlier VMCS accesses (reads or writes) have hit that, too? I.e. would this be guarding us merely against a pretty narrow window where memory corruption might occur? And wouldn't that then be as little or as much of a reason for crashing as any other failed VM{READ,WRITE}? > --- a/xen/arch/x86/hvm/vmx/entry.S > +++ b/xen/arch/x86/hvm/vmx/entry.S > @@ -154,21 +154,7 @@ UNLIKELY_END(realmode) > > .Lvmx_launch: > vmlaunch > - > -.Lvmx_vmentry_fail: > - sti > - PUSH_AND_CLEAR_GPRS > - > - /* > - * SPEC_CTRL_ENTRY notes > - * > - * If we end up here, no guest code has executed. The MSR lists have > - * not been processed, so we still have Xen's choice of MSR_SPEC_CTRL > - * in context, and the RSB is unchanged. > - */ > - > - call vmx_vmentry_failure > - jmp .Lvmx_process_softirqs > + jmp .Lvmx_vmentry_fail > > LABEL(vmx_asm_do_vmentry) > GET_CURRENT(bx) > @@ -189,3 +175,30 @@ LABEL(vmx_asm_do_vmentry) > call do_softirq > jmp .Lvmx_do_vmentry > END(vmx_asm_vmexit_handler) > + > + .section .text.cold, "ax", @progbits > + > +FUNC(vmx_asm_vmexit_handler.cold) Is this doing what you want when CC_SPLIT_SECTIONS=y (and assuming my patch to extend this to assembly code would finally land)? > +.Lvmx_vmentry_fail: > + /* > + * SPEC_CTRL_ENTRY notes > + * > + * If we end up here, no guest code has executed. The MSR lists have > + * not been processed, so we still have Xen's choice of MSR_SPEC_CTRL > + * in context, and the RSB is unchanged. How do we know the MSR lists haven't been processed? VM entry can fail because of that processing. Afaict we only know this in the "VMfail invalid" case. For SPEC_CTRL (in the "VMfail valid" case) this means we only have Xen's choice still in context if that's the last entry on the list. > + * The guest registers are live, and the on-stack copy is up-to-date. > + * PUSH_AND_CLEAR_GPRS clobbers flags and can't reasonably be made not > + * to. The Carry flag (VMFail Invalid vs Valid) needs preserving. Define "reasonably". What about (with my CET-SS part included) .macro PUSH_AND_CLEAR_GPRS ssp=IS_ENABLED(CONFIG_XEN_SHSTK) push %rdi mov $0, %edi push %rsi mov %edi, %esi push %rdx mov %edi, %edx push %rcx mov %edi, %ecx push %rax mov %edi, %eax .if \ssp rdsspq %rcx .endif push %r8 mov %edi, %r8d push %r9 mov %edi, %r9d push %r10 mov %edi, %r10d push %r11 mov %edi, %r11d push %rbx mov %edi, %ebx push %rbp #ifdef CONFIG_FRAME_POINTER /* Indicate special exception stack frame by inverting the frame pointer. */ mov %rsp, %rbp not %rbp #else mov %edi, %ebp #endif push %r12 mov %edi, %r12d push %r13 mov %edi, %r13d push %r14 mov %edi, %r14d push %r15 mov %edi, %r15d #ifdef CONFIG_XEN_SHSTK push %rcx #endif .endm ? Whether we'd accept the slightly longer form everywhere, or whether we'd prefer to add a parameter is TBD. > + * We could opencode PUSH_AND_CLEAR_GPRS but that's fragile to stack > + * layout changes. Instead, use a spare byte in the cpuinfo block. > + */ > + setnc STK_REL(CPUINFO_vmx_vmfail_valid, CPUINFO_error_code)(%rsp) > + > + PUSH_AND_CLEAR_GPRS > + sti Any reason you have re-ordered these two? Can't STI still be the very first insn after the label? (Of course, if - as per above - SPEC_CTRL would first need restoring, that would likely need to be ahead of STI.) > --- a/xen/arch/x86/hvm/vmx/vmcs.c > +++ b/xen/arch/x86/hvm/vmx/vmcs.c > @@ -1833,18 +1833,53 @@ void vmx_destroy_vmcs(struct vcpu *v) > free_xenheap_page(v->arch.hvm.vmx.msr_bitmap); > } > > -void vmx_vmentry_failure(void) > +static const char *vmx_error_str(unsigned int error) > +{ > + switch ( error ) > + { > + case VMX_INSN_VMLAUNCH_NONCLEAR_VMCS: > + return "VMLAUNCH with non-clear VMCS"; > + > + case VMX_INSN_VMRESUME_NONLAUNCHED_VMCS: > + return "VMRESUME with non-launched VMCS"; > + > + case VMX_INSN_VMRESUME_AFTER_VMXOFF: > + return "VMRESUME after VMXOFF"; > + > + case VMX_INSN_INVALID_CONTROL_STATE: > + return "Invalid control state"; > + > + case VMX_INSN_INVALID_HOST_STATE: > + return "Invalid host state"; > + > + case VMX_INSN_VMENTRY_BLOCKED_BY_MOV_SS: > + return "Blocked by MOV-SS"; > + > + default: > + return "Unknown"; > + } > +} > + > +void asmlinkage __cold vmx_vmentry_failure(void) > { > struct vcpu *curr = current; > - unsigned long error; > + bool valid = get_cpu_info()->vmx_vmfail_valid; > > - __vmread(VM_INSTRUCTION_ERROR, &error); > - gprintk(XENLOG_ERR, "VM%s error: %#lx\n", > - curr->arch.hvm.vmx.launched ? "RESUME" : "LAUNCH", error); > + gprintk(XENLOG_ERR, "VM%s Failure, VMCS %svalid\n", > + curr->arch.hvm.vmx.launched ? "RESUME" : "LAUNCH", > + valid ? "" : "not "); > > - if ( error == VMX_INSN_INVALID_CONTROL_STATE || > - error == VMX_INSN_INVALID_HOST_STATE ) > - vmcs_dump_vcpu(curr); > + if ( valid ) > + { > + unsigned int error = vmread(VM_INSTRUCTION_ERROR); > + > + gprintk(XENLOG_ERR, " Instruction Error %u, %s\n", > + error, vmx_error_str(error)); With this being the only call to vmx_error_str(), would that better also be __cold (despite the compiler almost certainly inlining it, unless __cold triggered some special inlining decisions)? > --- a/xen/arch/x86/include/asm/current.h > +++ b/xen/arch/x86/include/asm/current.h > @@ -80,6 +80,9 @@ struct cpu_info { > */ > bool use_pv_cr3; > > + /* Scratch space for the VT-x logic. See users. */ > + uint8_t vmx_vmfail_valid; Any reason this isn't bool? No use of the field wants it differently afaics. Should we - mostly for doc purposes - also wrap this in #ifdef CONFIG_VMX? Jan