From nobody Thu May 9 01:37:25 2024 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1705014833; cv=none; d=zohomail.com; s=zohoarc; b=Wlx/UmZr4nS26XRXzCRJHb2G35/6a10XGyzB7KWbT3vJR+dWRCd+Dyqohaj0bRXn9tBBShCHODoKs3+4Art6p5hlafMJaXS0d8Lrr8qDBfzUqoKEjmVy/LimAg98Y5kqmU7A43tJhr73VfjdcsOGAz3w3U5DR6VnmTCAg6ck/C8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705014833; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tQBG4Wv9YHRXR3l5NRi4xR48jlF7kee7EW5QxQr4nfU=; b=dX3Si8PQaNa3P/bBe/zPRxE5C+9aASQ8n3HCNIrDVbn2aI5tQEKUxDCGJsYz1gItKREAjxpyWFXnDMvgETFl/QsU2vegCRbQgXf+OfzytBtkgdlld89o3kNubZOoE8uG4URgpqSFjEsDDiw+sHI3zX77SFYsSgZtY7B9r2MzgZg= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1705014833306725.4989370012945; Thu, 11 Jan 2024 15:13:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.666556.1037283 (Exim 4.92) (envelope-from ) id 1rO4Ez-0006vq-F3; Thu, 11 Jan 2024 23:13:37 +0000 Received: by outflank-mailman (output) from mailman id 666556.1037283; Thu, 11 Jan 2024 23:13:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rO4Ez-0006vh-B5; Thu, 11 Jan 2024 23:13:37 +0000 Received: by outflank-mailman (input) for mailman id 666556; Thu, 11 Jan 2024 23:13:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rO4Ey-0006Rc-1v for xen-devel@lists.xenproject.org; Thu, 11 Jan 2024 23:13:36 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0aa9a961-b0d7-11ee-98f0-6d05b1d4d9a1; Fri, 12 Jan 2024 00:13:35 +0100 (CET) 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" X-Inumbo-ID: 0aa9a961-b0d7-11ee-98f0-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1705014815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Dpm9/S8+MidX9muncwSRV0Kdv7DqGRwPQQ3rsiXm2ss=; b=A2Hq6fhnxWtyZKxgi9k2Mnh38zkg9o/VLmgUH/TQLFNrrjTLdeEWhO3V QFVeP8IJCO+/MWbf4syOpAktBrmrCK6Ucn/O90OHaCXdP/FEk/y2otX6/ +k+gg9eHf/WZqY2/pkSAWXhEe+6G1PeGXW4kUCQmlW/7SmkOJNB4Dwxu6 Y=; X-CSE-ConnectionGUID: uyTfX/LfTRC34w9FxF0y2A== X-CSE-MsgGUID: KuJK4YPoTpmmr6ZKUJK6Ug== Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 129351772 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.159.70 X-Policy: $RELAYED X-ThreatScanner-Verdict: Negative IronPort-Data: A9a23:hiCaa6M1vRya2FnvrR3ml8FynXyQoLVcMsEvi/4bfWQNrUoj3jIBx jQZUG2GM66KM2T9L9l+OY2/8EoBvJTcx4JhGwto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CQ6jefQAOOkVIYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/7rRC9H5qyo5GtB5wVmPpingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0vtmPW9+s tgWFAomNUyc1sym7uqqEMA506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEOHwwNHwsYDUWUrsTILs4kP2lmT/UdDpApUjOjaE2/3LS3Ep6172F3N/9I4bbHpgMwRnCz o7A10fkIDJGBeSY9SKA92jytMzyvwClZY1HQdVU8dY12QbOlwT/EiY+RVa95PW0lEO6c9ZeM FAPvDojq7Ao806mRcW7WAe3yFamlBMBX9tbE8Uh9RqAjKHT5m6xGWwsXjNHLts8u6cLqScCj wHT2YmzXHo27ezTFir1GqqoQS2aJDkpI19FQSE4dyBev8ayjpEd1gOVZ4M2eEKqteEZCQ0c0 hjT83Bi3uRL05JWv5hX62wrlN5Fm3QocuLWzl+ONo5dxlklDLNJnqTxgbQh0d5OLZyCUn6Kt 2Uels6V4YgmVM7VyHXcGrVSRer4u55p1QEwZnY2QvEcG8mFoSb/Lei8HhkiTKuWDir0UWCwO xKC0e+gzJRSIGGrfcdKj3GZUqwXIVzbPY29DJj8N4MeCqWdgSfbpEmCk2bMhTGy+KXt+IljU aqmnTGEVC1KUfU+nWDsF4/wE9YDn0gD+I8afrijpzzP7FZUTCf9pWstWLdWUt0E0Q== IronPort-HdrOrdr: A9a23:SOIL+6yNIcKRI8tNSK7GKrPwFL1zdoMgy1knxilNoRw8SKKlfq eV7Y0mPH7P+VAssR4b+exoVJPtfZqYz+8R3WBzB8bEYOCFghrKEGgK1+KLqFeMJ8S9zJ846U 4JSdkHNDSaNzlHZKjBjzVQa+xQouW6zA== X-Talos-CUID: 9a23:8o3Xem6ci53tkW0aJtss6V8oFPBiVnPh9lyLf1DpJ3ZHEKzPYArF X-Talos-MUID: =?us-ascii?q?9a23=3AhCUvqwwVwFluFiha55BoNTkwbv+aqIezKmNRoK0?= =?us-ascii?q?Bh9GBMDYuCRSgrhfpf4Byfw=3D=3D?= X-IronPort-AV: E=Sophos;i="6.04,187,1695700800"; d="scan'208";a="129351772" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap Subject: [PATCH v2 1/3] x86/vmx: Collect all emtpy VMExit cases together Date: Thu, 11 Jan 2024 23:13:21 +0000 Message-ID: <20240111231323.4043461-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240111231323.4043461-1-andrew.cooper3@citrix.com> References: <20240111231323.4043461-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1705014835238100001 ... rather than having them spread out. Explain consicely why each is empt= y. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: George Dunlap v2: * New. --- xen/arch/x86/hvm/vmx/vmx.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 8ff675883c2b..829c27f1fa33 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -4374,9 +4374,7 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_re= gs *regs) } break; } - case EXIT_REASON_EXTERNAL_INTERRUPT: - /* Already handled above. */ - break; + case EXIT_REASON_TRIPLE_FAULT: hvm_triple_fault(); break; @@ -4539,9 +4537,6 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_re= gs *regs) hvm_inject_hw_exception(X86_EXC_UD, X86_EVENT_NO_EC); break; =20 - case EXIT_REASON_TPR_BELOW_THRESHOLD: - break; - case EXIT_REASON_APIC_ACCESS: if ( !vmx_handle_eoi_write() && !handle_mmio() ) hvm_inject_hw_exception(X86_EXC_GP, 0); @@ -4680,15 +4675,6 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_r= egs *regs) vmx_handle_descriptor_access(exit_reason); break; =20 - case EXIT_REASON_BUS_LOCK: - /* - * Nothing to do: just taking a vmexit should be enough of a pause= to - * prevent a VM from crippling the host with bus locks. Note - * EXIT_REASON_BUS_LOCK will always have bit 26 set in exit_reason= , and - * hence the perf counter is already increased. - */ - break; - case EXIT_REASON_NOTIFY: __vmread(EXIT_QUALIFICATION, &exit_qualification); =20 @@ -4705,6 +4691,11 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_r= egs *regs) =20 break; =20 + case EXIT_REASON_EXTERNAL_INTERRUPT: /* Handled earlier */ + case EXIT_REASON_TPR_BELOW_THRESHOLD: /* Handled later in vmx_intr_ass= ist() */ + case EXIT_REASON_BUS_LOCK: /* Nothing to do (rate-limit onl= y) */ + break; + case EXIT_REASON_VMX_PREEMPTION_TIMER_EXPIRED: case EXIT_REASON_INVPCID: /* fall through */ --=20 2.30.2 From nobody Thu May 9 01:37:25 2024 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1705014830; cv=none; d=zohomail.com; s=zohoarc; b=E8w1TDtMKQgEfvlNRQz8D4J9HZC4X42ec2a7KwhsIq50g8Z+9dvdyLm/XCeWNH0xybcbbk1DS9IktoptNn/xQe9BvuttHSKV7bGJkb6awEjfsnVWR37+A4heH7jwlGddOUEgG+uAInwBnbEcP5VKSrkfIxaMH3L9j9ezbHvHWDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705014830; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tuR9i0BhXx4Q3iGrzsdHeCBosefHqVBXgb/kwo65UlU=; b=Td9JppjEuSFM8O8Tl7HUgn8kIiCytg3cEA9sBE3ow/TE2a8a4PRXHDhxtSrY58WVWSSfkQuoM+rIvwl6BkSnhh6TW7PT9QEUpP8HOXPAJNtMiS5tMv2nHVP/KIPh6Qbg2GY3QXPULu5KhRjmKDmtzOhfLQ0yz6HpWXtrM9baz90= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1705014830298534.9755907598258; Thu, 11 Jan 2024 15:13:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.666555.1037273 (Exim 4.92) (envelope-from ) id 1rO4Ey-0006gX-8h; Thu, 11 Jan 2024 23:13:36 +0000 Received: by outflank-mailman (output) from mailman id 666555.1037273; Thu, 11 Jan 2024 23:13:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rO4Ey-0006gQ-3s; Thu, 11 Jan 2024 23:13:36 +0000 Received: by outflank-mailman (input) for mailman id 666555; Thu, 11 Jan 2024 23:13:34 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rO4Ew-0006Rc-Il for xen-devel@lists.xenproject.org; Thu, 11 Jan 2024 23:13:34 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0a6e6415-b0d7-11ee-98f0-6d05b1d4d9a1; Fri, 12 Jan 2024 00:13:33 +0100 (CET) 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" X-Inumbo-ID: 0a6e6415-b0d7-11ee-98f0-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1705014813; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EE/lRXdi+k5KtqGjtnl0bs1lLF3+iT3WJr+up5HKJ9c=; b=PGleRqkREkuV3Km0cdFtSPSv6MFH0zVnn/XTltfyZ0CHu8iGAZtzJs9C Bq8eZ5fo4C//VBcK7+C3ZkpOcukBiqWDcnoAUq4ScH6WSMUj9ijusfppF vhK/W9IrNzdCfaZoO7lYJNbZlpMwLrLaGTy14uHtnrBZMqwyIPSvL6V4R U=; X-CSE-ConnectionGUID: tTQc7+osRG6vwTF5UyETeQ== X-CSE-MsgGUID: uYXzKoj4SrOJO7q+DE+srg== Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 129228546 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.159.70 X-Policy: $RELAYED X-ThreatScanner-Verdict: Negative IronPort-Data: A9a23:d2lgNaJPpNP3A1ypFE+R6pUlxSXFcZb7ZxGr2PjKsXjdYENS1zEOx mBNXjrTaffYa2L3fohxPIS/p08OuJXRnYVjG1FlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAhk/nOHvylULKs1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpKrfrfwP9TlK6q4m9A5wVnPasjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5rPVhFq r8fMwoiMA6cu8zr/aOWduRV05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGspM0yojx5nYz/7DLoXmuuyi2a5W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cooper To: Xen-devel CC: Andrew Cooper , Reima ISHII , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Tamas K Lengyel , "Takahiro Shinagawa" , George Dunlap Subject: [PATCH v2 2/3] x86/vmx: Fix IRQ handling for EXIT_REASON_INIT Date: Thu, 11 Jan 2024 23:13:22 +0000 Message-ID: <20240111231323.4043461-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240111231323.4043461-1-andrew.cooper3@citrix.com> References: <20240111231323.4043461-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1705014831494100002 When receiving an INIT, a prior bugfix tried to ignore the INIT and continue onwards. Unfortunately it's not safe to return at that point in vmx_vmexit_handler(). Just out of context in the first hunk is a local_irqs_enabled() which is depended-upon by the return-to-guest path, causing the following checklock failure in debug builds: (XEN) Error: INIT received - ignoring (XEN) CHECKLOCK FAILURE: prev irqsafe: 0, curr irqsafe 1 (XEN) Xen BUG at common/spinlock.c:132 (XEN) ----[ Xen-4.19-unstable x86_64 debug=3Dy Tainted: H ]---- ... (XEN) Xen call trace: (XEN) [] R check_lock+0xcd/0xe1 (XEN) [] F _spin_lock+0x1b/0x60 (XEN) [] F pt_update_irq+0x32/0x3bb (XEN) [] F vmx_intr_assist+0x3b/0x51d (XEN) [] F vmx_asm_vmexit_handler+0xf7/0x210 Luckily, this is benign in release builds. Accidentally having IRQs disabl= ed when trying to take an IRQs-on lock isn't a deadlock-vulnerable pattern. Drop the problematic early return. In hindsight, it's wrong to skip other normal VMExit steps. Fixes: b1f11273d5a7 ("x86/vmx: Don't spuriously crash the domain when INIT = is received") Reported-by: Reima ISHII Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Tamas K Lengyel CC: Reima Ishii CC: Takahiro Shinagawa CC: George Dunlap With this patch in place, the INIT is ignored and the guest continues: (XEN) HVM1 restore: CPU 0 (d1) --- Xen Test Framework --- (d1) Environment: HVM 64bit (Long mode 4 levels) (XEN) Error: INIT received - ignoring (d1) Test result: SUCCESS v2: * Leave the printk() early, and skip in the main block. --- xen/arch/x86/hvm/vmx/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 829c27f1fa33..a85394232a23 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -4090,7 +4090,7 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_re= gs *regs) =20 case EXIT_REASON_INIT: printk(XENLOG_ERR "Error: INIT received - ignoring\n"); - return; /* Renter the guest without further processing */ + break; } =20 /* Now enable interrupts so it's safe to take locks. */ @@ -4692,6 +4692,7 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_re= gs *regs) break; =20 case EXIT_REASON_EXTERNAL_INTERRUPT: /* Handled earlier */ + case EXIT_REASON_INIT: /* Handled earlier */ case EXIT_REASON_TPR_BELOW_THRESHOLD: /* Handled later in vmx_intr_ass= ist() */ case EXIT_REASON_BUS_LOCK: /* Nothing to do (rate-limit onl= y) */ break; --=20 2.30.2 From nobody Thu May 9 01:37:25 2024 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1705014836; cv=none; d=zohomail.com; s=zohoarc; b=AcUrU8v/DssfHayc9jSTjmP8t//SoMeYf5gGmVAwMYzjBbVcKz/URDv5hy06wnNdE54h7Y7pNq0IeX0f4UnRZfdMbu05KXvf4DViueNfevL4PFrXmOBan8V8Mfml5y1JKsy9MInpeYMCW2dTKiVZS7gP12WTJ5onLI/vCKnfSZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705014836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1Y8v62+tb035+OLGtY7xGc6mm8HGM/20ZjzRYeFMHdA=; b=Sg5xOCfdP57Kb/b491CJLfMbq/z7x7RLC+kmoJuLtzYp/RyDo5siLtt8D/QCP8Ifj9HWvC502bad5rbG80HPM+6R2vuyi3cVC8CXe9gUED5EN/ECrdhw9Hbp/N3PH00YKuaGSZnN29kZ4yReawEppWeurlZAX7C3S6qPDX1gERE= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1705014836824735.2043433849; Thu, 11 Jan 2024 15:13:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.666557.1037292 (Exim 4.92) (envelope-from ) id 1rO4F0-0007BZ-Ly; Thu, 11 Jan 2024 23:13:38 +0000 Received: by outflank-mailman (output) from mailman id 666557.1037292; Thu, 11 Jan 2024 23:13: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 1rO4F0-0007BM-IK; Thu, 11 Jan 2024 23:13:38 +0000 Received: by outflank-mailman (input) for mailman id 666557; Thu, 11 Jan 2024 23:13:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rO4Ey-0006Rc-RP for xen-devel@lists.xenproject.org; Thu, 11 Jan 2024 23:13:36 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0b1beb35-b0d7-11ee-98f0-6d05b1d4d9a1; Fri, 12 Jan 2024 00:13:35 +0100 (CET) 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" X-Inumbo-ID: 0b1beb35-b0d7-11ee-98f0-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1705014815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4YIR4K6W+nWMY3NLj1Q8Kd8f62sIVMxc9+xWiH9rSVw=; b=iX6Ucla+cmVJDrUaQhWuyHeFjxJzNHcdUZdvxdsx6ojgSInH3NW6gxFR bLYFU4QYLMOapNuunwdnSY06+cY6SLXk7TD2Po8UBsOejs7NZ3ARhCJh3 hxYLkQBX9sNe8tLl9c2vlhPCd4nlV8t0aOQ9JssTnexTjHcBgP+SsuOO7 g=; X-CSE-ConnectionGUID: WH81DfBRRa+ZAEKw+/EGxA== X-CSE-MsgGUID: 9/3zPfAITzu2AejPcLWbGQ== Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 127924843 X-Ironport-Server: esa5.hc3370-68.iphmx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vzTCpVJS9y5V5b5DS3XfwB9rQg2zozw2jeLbiikEz7iOvENCHMEuZZWLdrUgzexPrZyDg5D v4Fb5fao/mheLGWjtbrHX47cglRcClT6WHeoM1LbO+TSjeK60l4Y8I9NYgJItQ/94wMz7egw 51IchMAoLYJrSGdeFrih7EKQO+HYKuTWlpiZnx0bA/5gSJzCWtthY9GH6YKkXAc3LQL5ZZJo zMtIq1s3twnpuz7xgkg IronPort-HdrOrdr: A9a23:EZXpyqlECEcGL79EtVoi7gD+KFzpDfIU3DAbv31ZSRFFG/Fxl6 iV8sjzsiWE8Qr5OUtQ/+xoV5PhfZqxz/JICMwqTNKftWrdyQyVxeNZnOjfKlTbckWUnINgPO VbAsxD4bXLfCBHZK3BgTVQfexO/DD+ytHLudvj X-Talos-CUID: =?us-ascii?q?9a23=3AWNc+W2v0M+/K07eztMcCGbuB6IsaUi2E4Hn6GXW?= =?us-ascii?q?xSlRAZZ6KChi917NNxp8=3D?= X-Talos-MUID: 9a23:M2umaAlYbb9zenPzX9dgdnozc5x626qHKXwfjM8vtsu8PghPMRik2WE= X-IronPort-AV: E=Sophos;i="6.04,187,1695700800"; d="scan'208";a="127924843" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Reima Ishii , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Tamas K Lengyel , "Takahiro Shinagawa" , George Dunlap Subject: [PATCH v2 3/3] x86/vmx: Disallow the use of inactivity states Date: Thu, 11 Jan 2024 23:13:23 +0000 Message-ID: <20240111231323.4043461-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240111231323.4043461-1-andrew.cooper3@citrix.com> References: <20240111231323.4043461-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1705014837302100003 Right now, vvmx will blindly copy L12's ACTIVITY_STATE into the L02 VMCS and enter the vCPU. Luckily for us, nested-virt is explicitly unsupported for security bugs. The inactivity states are HLT, SHUTDOWN and WAIT-FOR-SIPI, and as noted by = the SDM in Vol3 27.7 "Special Features of VM Entry": If VM entry ends with the logical processor in an inactive activity state, the VM entry generates any special bus cycle that is normally generated w= hen that activity state is entered from the active state. Also, Some activity states unconditionally block certain events. I.e. A VMEntry with ACTIVITY=3DSHUTDOWN will initiate a platform reset, whi= le a VMEntry with ACTIVITY=3DWAIT-FOR-SIPI will really block everything other th= an SIPIs. Both of these activity states are for the TXT ACM to use, not for regular hypervisors, and Xen doesn't support dropping the HLT intercept either. There are two paths in Xen which operate on ACTIVITY_STATE. 1) The vmx_{get,set}_nonreg_state() helpers for VM-Fork. As regular VMs can't use any inactivity states, this is just duplicating the 0 from construct_vmcs(). Retain the ability to query activity_state, but crash the domain on any attempt to set an inactivity state. 2) Nested virt, because of ACTIVITY_STATE in vmcs_gstate_field[]. Explicitly hide the inactivity states in the guest's view of MSR_VMX_MIS= C, and remove ACTIVITY_STATE from vmcs_gstate_field[]. In virtual_vmentry(), we should trigger a VMEntry failure for the use of any inactivity states, but there's no support for that in the code at all so leave a TODO for when we finally start working on nested-virt in earnest. Reported-by: Reima Ishii Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Tamas K Lengyel --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Tamas K Lengyel CC: Reima ISHII CC: Takahiro Shinagawa CC: George Dunlap v2: * Retain the ability to query ACTIVITY_STATE in the vmfork helpers, but ve= to attempts to set an inactivity state. Note, entirely untested. --- xen/arch/x86/hvm/vmx/vmx.c | 5 ++++- xen/arch/x86/hvm/vmx/vvmx.c | 9 +++++++-- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index a85394232a23..fd580bd5625f 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1551,7 +1551,10 @@ static void cf_check vmx_set_nonreg_state(struct vcp= u *v, { vmx_vmcs_enter(v); =20 - __vmwrite(GUEST_ACTIVITY_STATE, nrs->vmx.activity_state); + if ( nrs->vmx.activity_state ) + domain_crash(v->domain, "Attempt to set activity_state %#lx\n", + nrs->vmx.activity_state); + __vmwrite(GUEST_INTERRUPTIBILITY_INFO, nrs->vmx.interruptibility_info); __vmwrite(GUEST_PENDING_DBG_EXCEPTIONS, nrs->vmx.pending_dbg); =20 diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index f14053e7637a..ece0aa243a73 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -899,7 +899,10 @@ static const u16 vmcs_gstate_field[] =3D { GUEST_LDTR_AR_BYTES, GUEST_TR_AR_BYTES, GUEST_INTERRUPTIBILITY_INFO, + /* + * ACTIVITY_STATE is handled specially. GUEST_ACTIVITY_STATE, + */ GUEST_SYSENTER_CS, GUEST_PREEMPTION_TIMER, /* natural */ @@ -1200,6 +1203,8 @@ static void virtual_vmentry(struct cpu_user_regs *reg= s) nvcpu->nv_vmentry_pending =3D 0; nvcpu->nv_vmswitch_in_progress =3D 1; =20 + /* TODO: Fail VMentry for GUEST_ACTIVITY_STATE !=3D 0 */ + /* * EFER handling: * hvm_set_efer won't work if CR0.PG =3D 1, so we change the value @@ -2316,8 +2321,8 @@ 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-target feature now */ - data =3D host_data & ~VMX_MISC_CR3_TARGET; + /* Do not support CR3-targets or activity states. */ + data =3D host_data & ~(VMX_MISC_CR3_TARGET | VMX_MISC_ACTIVITY_MAS= K); 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 a9afdffae547..5ec474c79c32 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -277,6 +277,7 @@ extern u32 vmx_secondary_exec_control; #define VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 0x80000000000ULL extern u64 vmx_ept_vpid_cap; =20 +#define VMX_MISC_ACTIVITY_MASK 0x000001c0 #define VMX_MISC_PROC_TRACE 0x00004000 #define VMX_MISC_CR3_TARGET 0x01ff0000 #define VMX_MISC_VMWRITE_ALL 0x20000000 --=20 2.30.2