From patchwork Tue Dec 13 16:31:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13072202 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 ABA63C4332F for ; Tue, 13 Dec 2022 16:32:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.460894.718919 (Exim 4.92) (envelope-from ) id 1p58Cg-0000HB-Ts; Tue, 13 Dec 2022 16:32:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 460894.718919; Tue, 13 Dec 2022 16:32:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p58Cg-0000H0-QZ; Tue, 13 Dec 2022 16:32:26 +0000 Received: by outflank-mailman (input) for mailman id 460894; Tue, 13 Dec 2022 16:32:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p58Cf-0008Sb-Bb for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 16:32:25 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7d50a4c-7b03-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 17:32:23 +0100 (CET) Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 13 Dec 2022 11:32:20 -0500 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by CO3PR03MB6791.namprd03.prod.outlook.com (2603:10b6:303:175::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 16:32:14 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1%9]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 16:32:14 +0000 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: b7d50a4c-7b03-11ed-8fd2-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1670949143; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=sJ93Kqcs+vf82vQOcu7gbTEFhxiM3Uy2ge4FFxcQ4GQ=; b=dOrrVZq0xko4JLK2F7MmLglkrbvqIbLKJuSGN0SbaNSNnhUraS3mKTUf omxyT+kZHCAoeX/89vm5wptcszsdmu5EJ081pFQfTfhJG0XuP8suUWpl4 WYwIM/HdSs8V+jxZsuxVgMypi6wzz2Ul3j1f7rW7Cf2ANNAFfvg1kR2f1 c=; X-IronPort-RemoteIP: 104.47.57.177 X-IronPort-MID: 88160268 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:B/O6hq79OW+qLs9KRly+pQxRtO3GchMFZxGqfqrLsTDasY5as4F+v m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KojKxEE5nFfhSVhE+Lo7+T8SgruOeXSI7 X-IronPort-AV: E=Sophos;i="5.96,241,1665460800"; d="scan'208";a="88160268" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=huuHqqWJbw/1Gq98HymnQ8vU0U61OEK6OXynt1AS2XOq0X/lfc1fg7R5CBI4kmCY4eDL7racnyhcBexCQ8QEDhyfAff+pDGmgsAHzBZPmORVU3DNb4KPV3skWrpVr3vtiVnvZ2psiZ4zDGwJF325lP5qwTjA1Ok2pUCeWqunkC/TzelLvSzUrKmPIciX+D/FsU42AbbnheEZquPujtqczHh8sTlAsbyCqWR4jzhyT1k+YRVMmhgCxJcC+k9sWoc+yfdiJMEP4sROPKkaPucbRzyI2Rjtx8+1oStyFw5kIzg2L0S8979qsKGM90Ad1vYgpM7yv4Jgi1ChF2m4m8Iaew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=2iXDq00v+qB0BlrrSzP2Ii0oJyOF3yLc5fy3YIt0O2M=; b=CaH0BI8X44qCAO6PLWk54PG7TkCstLiKUlhahNFOq/53T59laRx4Hr2TFP91FCw7zjZrb+kmBhPfwBF2IBRG0Cv8H5Zkyl+zB8eENDRdZAnKBvXrShVkjtLgeToz0Hhwvfe3PWPcf3q7pR32bsCiXn+XYC7BG9wGX7Evdo5diNZY/gsXn+ivF05W/T5q3fClTJ+LIyPhm/2eIOkcPn7LHo904HjaJMcVE6qbYOvvPZawb7SnHejTLvuF3fgJ6bCZPXf1CAj8QRmOytvpNwWN3KGxS3MQJBaswyjTzXPStaBr/HiQK5+Hb4MjcvmR7sUedDJjG5UBa6z1FO0+wkNP7A== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2iXDq00v+qB0BlrrSzP2Ii0oJyOF3yLc5fy3YIt0O2M=; b=tBFr9CJaSaSlS3o+UI59rvtsN9P4h3ScOvBlGShFFliDSzyRjxnOfZxrXID5Bl9zBGCeZQPKZD8gJ+sXw1a41ghOCjp6y1/QWXRjMbh/RwmQKfuPkeuNdGZTo8KmZoFeHozPJ4DXdcxPNqgO3dR9M4Nyvf9r+E+ocK0rDKixqpA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jun Nakajima , Kevin Tian , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v4 1/3] x86/vmx: implement VMExit based guest Bus Lock detection Date: Tue, 13 Dec 2022 17:31:02 +0100 Message-Id: <20221213163104.19066-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221213163104.19066-1-roger.pau@citrix.com> References: <20221213163104.19066-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P123CA0414.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::23) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|CO3PR03MB6791:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cfd1f5e-a44f-4da9-2e54-08dadd2797a3 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PQaYFccMUNJSh64LURevxmH/09jhoW8ca/Hj++ePOsUIS4S2xSxrWUNiGvoj/hUc5pUgp/Fb1imBTWKklj1LXEo5W5PwjSWl0NbSMJVgqJ0dGxENR5tih4TQEaOvyRBjKYGtzMCVteoUVykdU1v2a8eEXQzBT61wo/T+tLX7cximLtnDAEpyWm5miRX4S2h8ItGmsPy0UJ+U94cznvpWAS8IsDwB6kFfrD0bgoSqV9mR+go36eLS8nN9E5whmxv3BJIWIrpNy8q3DUq+yKj6v679BKb2O6JaAmZ5CTbJ/mgu4aSmC5Q2qB1/xc8JSpL+K5hKxF4GiJ6AEVFfJacB8jvAPFHedttONf9NfjfM/QcuQylE3EbPVs7ngqJ050GnzNF98nnC73KPx4PlzEu2btF0LgiCQTL/362COG5lw3z6WEHP//N+ls9m4fIj2Cd9vz8EgyED7OhKEduWnKF7OtGOYVkIc5GfeTqknza8Dpy3n+t+DOGIOCrTHjYGk7LMzeQGyGdoB8u2taR9FOBFeIkz87Xj6plH7M8zxnRzAXMlhvUtPSM+a8l/n0m/jQWD0ikJ+o+DtcyGYo3ynVszZ5E4UgIaV7A/ekvE1U/xJIFPUDP6YopHe7lMGY+4dxHcN55h+SB1vT/8xGZREUXTYDNVWC+EpHtPpoTd8EakuGuAnESUM1fClf3xMRDi3Vui X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6360.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199015)(38100700002)(82960400001)(5660300002)(86362001)(478600001)(2906002)(6486002)(41300700001)(6666004)(83380400001)(66946007)(6916009)(6506007)(66476007)(316002)(8936002)(4326008)(54906003)(186003)(6512007)(26005)(1076003)(8676002)(66556008)(2616005)(36756003)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-Chunk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?q?IWZHzX1ttQh/leJ0LBAW9DaNsNmViHpEDwQbpLiNjKhb5z/rEi3PQQe7lmXSVVDfE?= =?utf-8?q?iWhax6KvkOLgRknJlUm+hL2y2wObVwvj/hcYQ6bkiS5r2pSskVywGSMrpnxl0yZ0K?= =?utf-8?q?qbOt36zDLWbPG8vdnC8M5SiMmoQKHYNe1rQhckMmbUZNsNY49xb3WwPkFtXeJfx+d?= =?utf-8?q?3qyfVM28Uc+gg3S9otv1hbdmbQYQ1E7T7AMbEBY6UKjmBzihN+rV/wVjC/v+T7qAS?= =?utf-8?q?oSJ4szKVJiOAcelbhQeDAX47piCYCc2D1PLwkq3Mb1Yir9gBLLwezADkcAvDqNESj?= =?utf-8?q?xD21Z0TZlPc7D/xYt/FFNlxD1rGtbrVr32D3OADkyDDWATm1AhG9zR4HCc4hdBE9D?= =?utf-8?q?y91ciF0puc/BfpFx5MX8Zo2/Hqo8pkGyXK8iV0862m5vw2iZGsce1nbOnEwsIq5U8?= =?utf-8?q?ae9n3m87U0I66vS7Gs5x6wsCDazTag3vRUA3fv23iHGeiO3CnUrI09H7tffmkhmE9?= =?utf-8?q?TPdnPElSquCEM2llUGokwkpIKSTvKkI9Na8dYFgPXYxXT9XmnYy/x05IgEyYRLNhE?= =?utf-8?q?CLmXLpK7L+XbXL1HzmCuITb7CvlUt8s+zZeUeIR5mgEH6faZUt3+6DRoN/sOizAjG?= =?utf-8?q?vGLTXqw9105vlM+9lUwuy8DoUvNsYojdTucAA15xS3Tu7JN4FjdVx2GFEuqOWrZWZ?= =?utf-8?q?nr6eH81uDYCDHpyABIcCDd5s9r8ygjTUeg=3D=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cfd1f5e-a44f-4da9-2e54-08dadd2797a3 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 16:32:14.6206 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CEKxYMYLPkcGx5vr+HG3M08d8ax3rQXU66XGeI822BCNJbCSiPSR3sK1PPgevBGRyufa5kxUXHJRSgARy95qpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO3PR03MB6791 Add support for enabling guest Bus Lock Detection on Intel systems. Such detection works by triggering a vmexit, which ought to be enough of a pause to prevent a guest from abusing of the Bus Lock. Add an extra Xen perf counter to track the number of Bus Locks detected. This is done because Bus Locks can also be reported by setting the bit 26 in the exit reason field, so also account for those. Note EXIT_REASON_BUS_LOCK VMExits will always have bit 26 set in exit_reason, and hence the performance counter doesn't need to be increased for EXIT_REASON_BUS_LOCK handling. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monné Reviewed-by: Kevin Tian --- Changes since v3: - Style fixes. - Fix usage of exit_reason by nested handlers. Changes since v2: - Subject/commit log adjustments. - Simply logic given bit 26 will always be set. Changes since v1: - Adjust commit message. --- xen/arch/x86/hvm/vmx/vmcs.c | 4 +++- xen/arch/x86/hvm/vmx/vmx.c | 15 +++++++++++++++ xen/arch/x86/hvm/vmx/vvmx.c | 3 ++- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 3 +++ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 2 ++ xen/arch/x86/include/asm/perfc_defn.h | 4 +++- 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 84dbb88d33..a0d5e8d6ab 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -209,6 +209,7 @@ static void __init vmx_display_features(void) P(cpu_has_vmx_virt_exceptions, "Virtualisation Exceptions"); P(cpu_has_vmx_pml, "Page Modification Logging"); P(cpu_has_vmx_tsc_scaling, "TSC Scaling"); + P(cpu_has_vmx_bus_lock_detection, "Bus Lock Detection"); #undef P if ( !printed ) @@ -318,7 +319,8 @@ static int vmx_init_vmcs_config(bool bsp) SECONDARY_EXEC_ENABLE_VM_FUNCTIONS | SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS | SECONDARY_EXEC_XSAVES | - SECONDARY_EXEC_TSC_SCALING); + SECONDARY_EXEC_TSC_SCALING | + SECONDARY_EXEC_BUS_LOCK_DETECTION); if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL ) opt |= SECONDARY_EXEC_ENABLE_VMCS_SHADOWING; if ( opt_vpid_enabled ) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 7c81b80710..3898f92f85 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -4081,6 +4081,12 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) return; } + if ( unlikely(exit_reason & VMX_EXIT_REASONS_BUS_LOCK) ) + { + perfc_incr(buslock); + exit_reason &= ~VMX_EXIT_REASONS_BUS_LOCK; + } + /* XXX: This looks ugly, but we need a mechanism to ensure * any pending vmresume has really happened */ @@ -4590,6 +4596,15 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) vmx_handle_descriptor_access(exit_reason); break; + 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_VMX_PREEMPTION_TIMER_EXPIRED: case EXIT_REASON_INVPCID: /* fall through */ diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 5f54451475..2095c1e612 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -2405,7 +2405,7 @@ void nvmx_idtv_handling(void) * be reinjected, otherwise, pass to L1. */ __vmread(VM_EXIT_REASON, &reason); - if ( reason != EXIT_REASON_EPT_VIOLATION ? + if ( (uint16_t)reason != EXIT_REASON_EPT_VIOLATION ? !(nvmx->intr.intr_info & INTR_INFO_VALID_MASK) : !nvcpu->nv_vmexit_pending ) { @@ -2486,6 +2486,7 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs, case EXIT_REASON_EPT_VIOLATION: case EXIT_REASON_EPT_MISCONFIG: case EXIT_REASON_EXTERNAL_INTERRUPT: + case EXIT_REASON_BUS_LOCK: /* pass to L0 handler */ break; case VMX_EXIT_REASONS_FAILED_VMENTRY: diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index 75f9928abf..f3df5113d4 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -267,6 +267,7 @@ extern u32 vmx_vmentry_control; #define SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS 0x00040000 #define SECONDARY_EXEC_XSAVES 0x00100000 #define SECONDARY_EXEC_TSC_SCALING 0x02000000 +#define SECONDARY_EXEC_BUS_LOCK_DETECTION 0x40000000 extern u32 vmx_secondary_exec_control; #define VMX_EPT_EXEC_ONLY_SUPPORTED 0x00000001 @@ -346,6 +347,8 @@ extern u64 vmx_ept_vpid_cap; (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES) #define cpu_has_vmx_tsc_scaling \ (vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING) +#define cpu_has_vmx_bus_lock_detection \ + (vmx_secondary_exec_control & SECONDARY_EXEC_BUS_LOCK_DETECTION) #define VMCS_RID_TYPE_MASK 0x80000000 diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index 8eedf59155..03995701a1 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -159,6 +159,7 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) * Exit Reasons */ #define VMX_EXIT_REASONS_FAILED_VMENTRY 0x80000000 +#define VMX_EXIT_REASONS_BUS_LOCK (1u << 26) #define EXIT_REASON_EXCEPTION_NMI 0 #define EXIT_REASON_EXTERNAL_INTERRUPT 1 @@ -219,6 +220,7 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) #define EXIT_REASON_PML_FULL 62 #define EXIT_REASON_XSAVES 63 #define EXIT_REASON_XRSTORS 64 +#define EXIT_REASON_BUS_LOCK 74 /* Remember to also update VMX_PERF_EXIT_REASON_SIZE! */ /* diff --git a/xen/arch/x86/include/asm/perfc_defn.h b/xen/arch/x86/include/asm/perfc_defn.h index 509afc516b..6fce21e85a 100644 --- a/xen/arch/x86/include/asm/perfc_defn.h +++ b/xen/arch/x86/include/asm/perfc_defn.h @@ -6,7 +6,7 @@ PERFCOUNTER_ARRAY(exceptions, "exceptions", 32) #ifdef CONFIG_HVM -#define VMX_PERF_EXIT_REASON_SIZE 65 +#define VMX_PERF_EXIT_REASON_SIZE 75 #define VMEXIT_NPF_PERFC 143 #define SVM_PERF_EXIT_REASON_SIZE (VMEXIT_NPF_PERFC + 1) PERFCOUNTER_ARRAY(vmexits, "vmexits", @@ -128,4 +128,6 @@ PERFCOUNTER(pauseloop_exits, "vmexits from Pause-Loop Detection") PERFCOUNTER(iommu_pt_shatters, "IOMMU page table shatters") PERFCOUNTER(iommu_pt_coalesces, "IOMMU page table coalesces") +PERFCOUNTER(buslock, "Bus Locks Detected") + /*#endif*/ /* __XEN_PERFC_DEFN_H__ */ From patchwork Tue Dec 13 16:31:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13072203 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 1D8AFC10F1B for ; Tue, 13 Dec 2022 16:32:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.460895.718930 (Exim 4.92) (envelope-from ) id 1p58Ci-0000Wu-8y; Tue, 13 Dec 2022 16:32:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 460895.718930; Tue, 13 Dec 2022 16:32:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p58Ci-0000Wn-5K; Tue, 13 Dec 2022 16:32:28 +0000 Received: by outflank-mailman (input) for mailman id 460895; Tue, 13 Dec 2022 16:32:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p58Cg-0008Sb-B5 for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 16:32:26 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b96f8bb1-7b03-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 17:32:24 +0100 (CET) Received: from mail-dm6nam11lp2175.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.175]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 13 Dec 2022 11:32:22 -0500 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by CO3PR03MB6791.namprd03.prod.outlook.com (2603:10b6:303:175::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 16:32:20 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1%9]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 16:32:20 +0000 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: b96f8bb1-7b03-11ed-8fd2-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1670949145; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=kFQ6UCqPmnuqJ9WmouCTU+CbLPqWzGus9jI8R/AS+bQ=; b=BZieA+n6C1yUvjA0EhDgYFK+haU9ve24Dy846lEmJWKnhHmdnYw9ZQra jrAh6ObNlvJABjN72fboxy5yV1rDKkwIXl9/6xSADsuD8EVypG8HpgPiB bbJt19Ln2sWrAKx9wRk1y+GnZ2rSiSN/tLxamPz6hQw004ePksFSPKAp6 c=; X-IronPort-RemoteIP: 104.47.57.175 X-IronPort-MID: 88160297 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:GDoIMqn/uYSQJvTWtQFFIk/o5gxUJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xJKWmDTMvjbZWSkKYt2O4ng/BkFu8CGndJgT1Nr+H0xEyMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icf3grHmeIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aqaVA8w5ARkP6kR5QSGzRH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 c06KBQObk3TvsuRmYOHEMJBguAkPvC+aevzulk4pd3YJdAPZMmaBonvu5pf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVM3ieewWDbWUoXiqcF9hEGXq 3iA523kKhobKMae2XyO9XfEaurnzXOiBtpIReLQGvhC2WS8nVE5NjgqbwHk+cOAjUyvcIxhA hlBksYphe1onKCxdfHtUhv9rHOasxo0X9tLD/Z8+AyL0rDT4QuSGi4DVDEpQN47sokwTD8j1 F6MlvvoAyBitPueTnf13rSZszK0fzQUJGkqZCkYQA9D6N7myKkxhB/SStdoEIauk8b4Xzr3x liisywWl7gVy8kR2M2GEUvvhjutot3FS1Az7wCOB2a9tFomOciiepCi7kXd4bBYNoGFQ1Kdv X8C3c+D8OQJCpLLnyuIKAkQIIyUCz++GGW0qTZS81MJrlxBJ1bLkVhs3QxD IronPort-HdrOrdr: A9a23:rYUF2aqRXin5aHoiD/eFFXkaV5rveYIsimQD101hICG9Evb0qy nOpoV/6faQslwssR4b9uxoVJPvfZq+z+8W3WByB9eftWDd0QPFEGgL1+DfKlbbak7DH4BmtJ uJc8JFeafN5VoRt7eG3OFveexQvOVu88qT9JjjJ28Gd3APV0n5hT0JcjpyFCdNNW57LKt8Lr WwzOxdqQGtfHwGB/7LfUXsD4D41rv2fIuNW29+OyIa X-IronPort-AV: E=Sophos;i="5.96,241,1665460800"; d="scan'208";a="88160297" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fG1VzlQN9LwuLlw9M/WlTSdHPF59H9BQAmJW4cYH/qIrLTqvzgISFyINU+bO54JSdHb1NVpbzl4THRaUDP4SDfTovWkT8DcAqQgNs2eNi/8gz5JqvV3ZiYeOh6iABplaZesHJgFeHZ3CkGmtkXdgcNGvrR/UBjxGB69/vqDSuZIBDG71vuGfNYRHBlHaGf4+yKByGPEUd69FTb1rwTtAaN8nA7NQ+pq66PYqElg1A2aHC+6DOeU0iJc5Y2JfOr9aK6PSgrxeshwII1C5paCKG3Lp0u6QpREuWvBqg+WebpxCdrlgX30TdDRZWXfPFHNTOu2RzmhoZV4TEEdmUDEX6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=+pOZwwS0tJfftDQXUS/cr3DkGL4CfPBmraxxIz5hRpk=; b=H38MuZJZXVRER+a2MqtY1nW5mXJewGGgAQuVJHVbdNfxcGGevBY7CYPHI2/GjfiXePlFAtKEDQFDqEnsmVMjgi7LnsUV/VX2C8KMj01uAgmK5T2byJbbQssEQ7AYfCP/te+0LlwOAOxSI1fL0kTsP/6k+MuwnengQ10j0ag8nYrtB2d22NY0qQjl8QopCnxXEenEgIIkbQT6myQKS/JDgBJ2Cm0lSxd1iDLt2HsdveWvMC0206DRd6ai+6vVNVc5Lr0g+sgzUelRrbe50+XfUPDMypPaeONG8Tv8Ak7i9bcoTzrIGH6qYOTgigtq53eKWFxApcxiP5uKECAo4vSP3A== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+pOZwwS0tJfftDQXUS/cr3DkGL4CfPBmraxxIz5hRpk=; b=NncEd5VGMjgmAM5DBqh19h402gVwBTwB17LIUyXdvy/68XioqHweex/QYWJPowRQILkoIk2Asw89JPE6EyLEA2CaT7OkTjknw6ye6MZCieaVGrvgA+q2CYwZKZd+YeyBs1BY1PP4169aHQ3p+eQATTW6aRmBSMehwyfIYSuNhls= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jun Nakajima , Kevin Tian , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v4 2/3] x86/vmx: introduce helper to set VMX_INTR_SHADOW_NMI Date: Tue, 13 Dec 2022 17:31:03 +0100 Message-Id: <20221213163104.19066-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221213163104.19066-1-roger.pau@citrix.com> References: <20221213163104.19066-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P123CA0125.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:192::22) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|CO3PR03MB6791:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fe188e2-06ed-478d-a611-08dadd279af2 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LeSFaoEnyywJ1vmy26yWSm1EnGtuokBua718gL6RRYoi55Yby7yezxlSJdT8ng+Bw/tEj6dUm4mcvPGIYde42xPa9C2NWvK+Y411F7bo5pomv/NthOuiQ0LWtBPgEv0LBDuh3Mz7cuyMMKIOlFn00RByxoDsNmw3T0z/I8BznAYEkbdMO978i92qqVZiJu5go+STyYdAHkgH2CEbZ2XAtvCfKzqZBvucDGDJNHlqcnaOY3jafw5A+R9qOJ44RysLVc8Tllgb3gC2aEpFEce9M7/zO46fFCBSjL5ZbjkqDtywjMvlZlFj0HdFnqv6ieHwyhyUKvbhYoU+KAtRCR4ze+WEFPBob9W8jAljXDlM3J+TeY7TFL1ITHI+E8kEkGL2maH8JLNbFO0T9y+wXzJvEhPKgvRTKSMDlIVUJL8Wa8j+zlFkpxKxrCezYDcp/eO38+Y6mWGZrgV+fxJQjat9mJLpubzF8bLTAQliMiwfyKUW9Hhg1dMl6UOHjlVJWDH7cv72JEmkRSnd3ITKXrf1r+Nj/LFn7raTAaBLV4JNTzfdXIXo1MHE53Yj6UM+Ohp3n9YkJGWxamx5jSO7Fzmw5nD6LzHaHFFSjljjnQyTKZshlG0BJISc1gb2gNQ86XlBBNhd8JUOZifGIQ/k+IyzUg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6360.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199015)(38100700002)(82960400001)(5660300002)(86362001)(478600001)(2906002)(6486002)(41300700001)(6666004)(83380400001)(66946007)(6916009)(6506007)(66476007)(316002)(8936002)(4326008)(54906003)(186003)(6512007)(26005)(1076003)(8676002)(66556008)(2616005)(66899015)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?eK4mGgdCdvyWl2a6MH+If2rU1gF5?= =?utf-8?q?WdTz2poR0pAzVi1RC99/B8dvljmC0KeRyMOr3pvLsRtZWHjF/Id6ADLoeD24S+RGW?= =?utf-8?q?oKz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dAvluCxA58CIb9anbMal2l2I0yHKkDe+p2BDQ9FVJKK1oMWiJcqnBBdaYorabMR?= =?utf-8?q?lix1zu8oeRrkmXOw11yujpE7LslaLGTIrcRjOrQmasyH9k69oitpusp7pIxELRJbq?= =?utf-8?q?eHXxEheUh18jX2qlNUr2fYjl5+kP53HSYS/wJas/PLyzfjHpLJpEbe19S8rwwIkBX?= =?utf-8?q?IeU9GAVmtNiwK68ELbk0iSLGypDDIuwO7UJHsTCXOh9Bh4Gu3Es5ixkKE9rltJZkJ?= =?utf-8?q?hG8UKjk0ndo6n620k4ZZ0glFbA/vlzMnYebpPLHK5Aht/63YAR6/LsXmw2rGbYGDq?= =?utf-8?q?KkkDx9AyLTiQ/CLoajbiP29BPxZot2e1my+Vq53SRlEfvbzHDE8T8Q/y36c3XFoVz?= =?utf-8?q?KG7y73zela6z21/KZlg9EhSIQ75HwmqeBx/+tlDy62fNYrh28/BFfo8rIb+WWvZ5X?= =?utf-8?q?+FTb2bFPyi2I5MoEdp9yjgtTd8fJwZjYxoehZXZA3NK2XnDNtoMmrR0I5rVYnRVDa?= =?utf-8?q?ipxsaVMSlwWvoeyjOW1VakpECwfmG2kTXMXaRu8tU8WP0zkEuOAttBxzwxZzoDjYb?= =?utf-8?q?WNfsfnWVJphp7263JTOlG/wPraAQpKoy0w=3D=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fe188e2-06ed-478d-a611-08dadd279af2 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 16:32:20.1773 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: beDoLpPcgWhu9OR4AMudKyoebG8FVtmmT98Dz7W4vI785c80WBgImFTtQr7X9amGKBFNzl/QK5mK5ZYWCTNhnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO3PR03MB6791 Introduce a small helper to OR VMX_INTR_SHADOW_NMI in GUEST_INTERRUPTIBILITY_INFO in order to help dealing with the NMI unblocked by IRET case. Replace the existing usage in handling EXIT_REASON_EXCEPTION_NMI and also add such handling to EPT violations and page-modification log-full events. Reported-by: Andrew Cooper Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- Changes since v3: - Expand comment. --- xen/arch/x86/hvm/vmx/vmx.c | 28 +++++++++++++++++++------- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 3 +++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 3898f92f85..dabf4a3552 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3964,6 +3964,15 @@ static int vmx_handle_apic_write(void) return vlapic_apicv_write(current, exit_qualification & 0xfff); } +static void undo_nmis_unblocked_by_iret(void) +{ + unsigned long guest_info; + + __vmread(GUEST_INTERRUPTIBILITY_INFO, &guest_info); + __vmwrite(GUEST_INTERRUPTIBILITY_INFO, + guest_info | VMX_INTR_SHADOW_NMI); +} + void vmx_vmexit_handler(struct cpu_user_regs *regs) { unsigned long exit_qualification, exit_reason, idtv_info, intr_info = 0; @@ -4164,13 +4173,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) if ( unlikely(intr_info & INTR_INFO_NMI_UNBLOCKED_BY_IRET) && !(idtv_info & INTR_INFO_VALID_MASK) && (vector != TRAP_double_fault) ) - { - unsigned long guest_info; - - __vmread(GUEST_INTERRUPTIBILITY_INFO, &guest_info); - __vmwrite(GUEST_INTERRUPTIBILITY_INFO, - guest_info | VMX_INTR_SHADOW_NMI); - } + undo_nmis_unblocked_by_iret(); perfc_incra(cause_vector, vector); @@ -4536,6 +4539,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) __vmread(GUEST_PHYSICAL_ADDRESS, &gpa); __vmread(EXIT_QUALIFICATION, &exit_qualification); + + if ( unlikely(exit_qualification & INTR_INFO_NMI_UNBLOCKED_BY_IRET) && + !(idtv_info & INTR_INFO_VALID_MASK) ) + undo_nmis_unblocked_by_iret(); + ept_handle_violation(exit_qualification, gpa); break; } @@ -4580,6 +4588,12 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) break; case EXIT_REASON_PML_FULL: + __vmread(EXIT_QUALIFICATION, &exit_qualification); + + if ( unlikely(exit_qualification & INTR_INFO_NMI_UNBLOCKED_BY_IRET) && + !(idtv_info & INTR_INFO_VALID_MASK) ) + undo_nmis_unblocked_by_iret(); + vmx_vcpu_flush_pml_buffer(v); break; diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index 03995701a1..eae39365aa 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -225,6 +225,9 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) /* * Interruption-information format + * + * Note INTR_INFO_NMI_UNBLOCKED_BY_IRET is also used with Exit Qualification + * field for EPT violations, PML full and SPP-related event vmexits. */ #define INTR_INFO_VECTOR_MASK 0xff /* 7:0 */ #define INTR_INFO_INTR_TYPE_MASK 0x700 /* 10:8 */ From patchwork Tue Dec 13 16:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13072205 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 70214C10F1D for ; Tue, 13 Dec 2022 16:32:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.460896.718941 (Exim 4.92) (envelope-from ) id 1p58Cr-0000uc-Kp; Tue, 13 Dec 2022 16:32:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 460896.718941; Tue, 13 Dec 2022 16:32: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 1p58Cr-0000uT-H3; Tue, 13 Dec 2022 16:32:37 +0000 Received: by outflank-mailman (input) for mailman id 460896; Tue, 13 Dec 2022 16:32:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p58Cp-0008Sb-VQ for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 16:32:36 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bddf442b-7b03-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 17:32:33 +0100 (CET) Received: from mail-dm6nam11lp2169.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.169]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 13 Dec 2022 11:32:30 -0500 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by CO3PR03MB6791.namprd03.prod.outlook.com (2603:10b6:303:175::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 16:32:26 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::740b:4e0a:7de4:5ab1%9]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 16:32:26 +0000 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: bddf442b-7b03-11ed-8fd2-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1670949153; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=sMuxSnFpNQrAkbbLtQpLS0YoQ8ak+oc74VRZ4eqVs+c=; b=g4/VOi0DJm2RfEvNLG9UkpoIfM/rA1pJsrdVACFNcw91dfq3STde5kFS HB53k4vZq3iXpk16lLGlEt6TdOppXG/0cz6zVmML5PvpYheJSEIFJNTFi 3WPUXtsEnmBDueSZY2fw82Ci0GwDERY0OPOqxA3j2CYiNhTvBY21/z8rO I=; X-IronPort-RemoteIP: 104.47.57.169 X-IronPort-MID: 88555885 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:e3M/Iaubevy4kw3wfLubK0HIzefnVKtfMUV32f8akzHdYApBsoF/q tZmKW/TOPqIN2vxco9za4638k8OvMLWyN5mGgJk+SBnES4W+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg0HVU/IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4bKj5lv0gnRkPaoR5QWHzCFPZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwN2EfSgCJm/2Pm7+cVeA9v8sEFMbqBdZK0p1g5Wmx4fcOZ7nmGvyPyfoGmTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0osj/60bou9lt+iHK25mm6Co W3L5SLhCwwyP92D0zuVtHmrg4cjmAurCN9PSe3oq5aGhnXUxFIIFAM2XGKH/6GHtFa7BfsDG WY9r39GQa8asRbDosPGdw21pjuIswARX/JUEvYm80edx6zM+QGbC2MYCDlbZ7QOtsU7WDgr3 V+hhM7yCHpkt7j9YXCA8raZqxuiNC5TKnUNDQcfVhcM6dTnpIA1jzrMQ8xlHarzicf6cRnvx xiaoS54gK8c5eYJyqP9+1nEijCto5HhTwgp6wGRVWWghit6aZCkYcq06FHdxfdGMIudCFKGu RA5d9O26ekPCdSBkXKLSeBURbWxva/bYXvbnEJlGIQn+3K14Xm/cItM4TZ4YkB0LsIDfjyva 0jW0e9M2KJu0LKRRfcfS+qM5w4ClMAMyfyNuijoU+dz IronPort-HdrOrdr: A9a23:GDlBVKEzl45v1kSNpLqENMeALOsnbusQ8zAXPiFKOGdom6mj/P xG88506faZslsssTIb6LS90dC7IE80rKQU3WBzB8bBYOCFghrREGgK1+KLqQEIfReOk9K1vp 0OT0ERMrHN5BdB/KHHCaSDYrAd6cjC2pqBwc3Zy25pTQlsYa0l1QFkEQyWe3cGJzWuQaBJba ah2g== X-IronPort-AV: E=Sophos;i="5.96,241,1665460800"; d="scan'208";a="88555885" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gAaWQ9K/uLG4tD/iYgsrQ6QAXsPeXvJO7XKGD/9zYaeu5hPRFfja7NacxtYXfZUyJerEGSRnCsHHMw+mqaBz0KNcN5D+KjIKW6ep31e49uTUw+PwOEj6dHTiRyYGyC7lMr8YhE5B6W+7x1eIFlUeW2use6IhFyDLcvPAVaphNTyZwhihxdzd5MquBL6Tn4lOuytKxAAyzoCgZfOdVIc8WF0XCtJjOvNUuV8JZWU/HQyx0rxi6Oj2MpWgtGUJTFjswSZl/hPESebtiU/el4Pz7YfA6cOFIFJW14U9XykL0z2Gduj1bq0fbTHbc86Li3Vh5Z8gOeo3ic1lZHzb+06XLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Rd68Qyv0Xcs0YjD78x9OxU/cmhG5hpGT4Fa+ZPnIUaU=; b=FrJbQs3UHdNOdSrWScuDO1/hkvJSyt6xANtwlMfevjlvMQvX/MWVGAoAsVfysiEJK2AqLDvIpAFO3kNTLTajlOOav61MtqjbrbXRglGLkc308OiKmGgLcvFIOladNBkpMaQcLNiORe3FhykwpP//W3HSgPZQm6bBJPcvWzVIr7kOICJV/bzBzrnfPppnXB32x0OS8yJQGkzlY6beyJ1ivkNqA/BmogwTCCHgGY4F1Bi15UEdLIYK9smPHnbAOBg1JKp2oQgROEKWDek2xB23/GM3rhjdCYxfH2Q64MIkyzYVkR+Ksml/pSKWH+G7XsKPJUiRJ5qaaRnPEVELP/Oguw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rd68Qyv0Xcs0YjD78x9OxU/cmhG5hpGT4Fa+ZPnIUaU=; b=BHY4FmENRs/YCV6kdSpCjmp7wWLVTFp3MOowaiBWwmLiJIMxFUkjI9U4mGzt+olBGU6MWHhZiIY9Ml6sKjYK3QTzvPvPHSGFNiScJt4xdGNbMn/PkPKKdRcBDWie24r4tbcgwnNezh2THZXE34762JZFYUrXtS6eI3SeYvdyUtE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Jun Nakajima , Kevin Tian Subject: [PATCH v4 3/3] x86/vmx: implement Notify VM Exit Date: Tue, 13 Dec 2022 17:31:04 +0100 Message-Id: <20221213163104.19066-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221213163104.19066-1-roger.pau@citrix.com> References: <20221213163104.19066-1-roger.pau@citrix.com> X-ClientProxiedBy: LO2P265CA0146.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::14) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|CO3PR03MB6791:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c00f314-15d2-4509-cab1-08dadd279ea8 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9uX97OJgu2pA8uMKGN7UlFn6B9aSnaZ4OZWYUb3iRE7Z7wYWTn+4jQVUL/BPjAsyENURFBaQ2jZFBMuIggwkvi3WGKngvk1fV44Jm916vNpCjCxCPoGFhAJGZ2fVqLroOLw0wqfSPzdmNQp1n/z5OChdSiZsSCTg7Qxb4Zk84d8RnCeGj+wfAQfKvqklamtxM9fT/wcWzkEz/tng37tTFcLUSxjubMHYzqWGGbYVlsG5MXvkIVXf53AIr6ifngw+gG3ZO6VqsflcSgKd2IdnU8ET3eVqOcCHTgmqON3DlZK55Ftv8y07NKo/4C3SVQ8qx7yiKWqA/tlhHYK63/fDEzrPJah4Y9edr8Q5s+rB/4Tf8bbCppnzg0qYZJ9TzvvEGUGZ4cjfsIrEFiF0plFnD/gIrqPI3MMjr+s6C5RvWl3xRYGqIG60OgfdhCEbtUpS8NC2FTW1cAzL0Bs3jesrNUvUiH5regbtMw4wWB7UXDEKNjrOHNVGy8aSjb2khIgWbPL9H8HECh/QcJ8EXUVD0v4QKCJzpPuobPElHZh5pFBgHX0v0Hmk9kk6F2uI7Fjiqv5DL9cr3jhxZPn/26wGLopHgJmweiOY/bhYpCBr1DGJjzc5wRqEH79woPIoI5Ox0mWypQ8L9mZkwnG2UZ75Qw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6360.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199015)(38100700002)(7416002)(82960400001)(5660300002)(86362001)(478600001)(2906002)(6486002)(41300700001)(6666004)(83380400001)(66946007)(6916009)(6506007)(66476007)(316002)(8936002)(4326008)(54906003)(186003)(6512007)(26005)(1076003)(8676002)(66556008)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oL1EG6lrX/706rjr7V1GbExVExlm?= =?utf-8?q?oouXrARH/Mdb0JC6HAGvkqiAnhnxUoDzLScwJkDtf84dDYnC8eyqkGSyk17A1ZR8A?= =?utf-8?q?mq44MfgGwiqbqpJaxHpxrPoNWTa3VOD5j5rrPebtGkwWXVMqFwZY26i/ZU2WVRxbi?= =?utf-8?q?yxb9TRIswHcCAcQ7dk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OJSLr8dWjESOt433uLjKsxjWHuEdTHkydRbpdQyxCrF4C2I?= =?utf-8?q?I4ze+IrZ09Eu1on0tHU2D2PNraCkNBO+8dHFlE5cT5wOYvfH8ykbbqjd9rgpczPZn?= =?utf-8?q?KUTnZ8n+PHDa43hGjYuBhOGs3HZVcaLeUndSdn+MOPymxmEtTz052lq8hEyI4X7qu?= =?utf-8?q?WufCouwG2dRk7Z4kSHmzBvcgBDzUIN/lPapTNkbIiMOr8W4386ce3apOdZ2fB8CIS?= =?utf-8?q?S5YsetKkEhJpo6a5kz1iJcCJl7ufLJNslxU8ZYNhltPGiWvrAgojNlq7eOXZwuceE?= =?utf-8?q?2f1tDwBpdURgjwNBPopIOBJt6x5XZG8JN58NZIP8i/Qk/rT1519OSmagU1JPfsJus?= =?utf-8?q?x3xNC/k66jEbXlifl66toe7HGgNSp7KReHQyuO011EJTsK9F3AbtSg2YKQLel1H/e?= =?utf-8?q?zz0DPGzx36bZEGOKHQCfGh/0EIkjenovVaTKEn92/QH8aSffGjttRh3gBIaQWqPRe?= =?utf-8?q?v3EsU2LnOhuYLHrX4B122Kr+mCiMHMsABQ=3D=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c00f314-15d2-4509-cab1-08dadd279ea8 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 16:32:26.4327 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: akwhcQSgkspBXIBb49+xI/k3y5c6/HsDwGcegpE/B8qbyHuoyc5SHKsOqEgqnMIPmKFadMnPPD9L2E0AiO5qGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO3PR03MB6791 Under certain conditions guests can get the CPU stuck in an unbounded loop without the possibility of an interrupt window to occur on instruction boundary. This was the case with the scenarios described in XSA-156. Make use of the Notify VM Exit mechanism, that will trigger a VM Exit if no interrupt window occurs for a specified amount of time. Note that using the Notify VM Exit avoids having to trap #AC and #DB exceptions, as Xen is guaranteed to get a VM Exit even if the guest puts the CPU in a loop without an interrupt window, as such disable the intercepts if the feature is available and enabled. Setting the notify VM exit window to 0 is safe because there's a threshold added by the hardware in order to have a sane window value. Note the handling of EXIT_REASON_NOTIFY in the nested virtualization case is passed to L0, and hence a nested guest being able to trigger a notify VM exit with an invalid context would be able to crash the L1 hypervisor (by L0 destroying the domain). Since we don't expose VM Notify support to L1 it should already enable the required protections in order to prevent VM Notify from triggering in the first place. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monné Reviewed-by: Kevin Tian --- Changes since v3: - Handle the exit reason in nvmx_n2_vmexit_handler(). - Use unlikely. - Expand commit message. Changes since v2: - Move up the logic to set the exception bitmap in construct_vmcs(). - Change perfcounter description. Changes since v1: - Properly update debug state when using notify VM exit. - Reword commit message. --- docs/misc/xen-command-line.pandoc | 11 +++++++++ xen/arch/x86/hvm/vmx/vmcs.c | 17 +++++++++++++ xen/arch/x86/hvm/vmx/vmx.c | 32 +++++++++++++++++++++++-- xen/arch/x86/hvm/vmx/vvmx.c | 1 + xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 4 ++++ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 6 +++++ xen/arch/x86/include/asm/perfc_defn.h | 3 ++- 7 files changed, 71 insertions(+), 3 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index b7ee97be76..923910f553 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2636,6 +2636,17 @@ guest will notify Xen that it has failed to acquire a spinlock. , and must be integers. The values will be encoded in guest CPUID 0x40000002 if viridian enlightenments are enabled. +### vm-notify-window (Intel) +> `= ` + +> Default: `0` + +Specify the value of the VM Notify window used to detect locked VMs. Set to -1 +to disable the feature. Value is in units of crystal clock cycles. + +Note the hardware might add a threshold to the provided value in order to make +it safe, and hence using 0 is fine. + ### vpid (Intel) > `= ` diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index a0d5e8d6ab..3d7c471a3f 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -67,6 +67,9 @@ integer_param("ple_gap", ple_gap); static unsigned int __read_mostly ple_window = 4096; integer_param("ple_window", ple_window); +static unsigned int __ro_after_init vm_notify_window; +integer_param("vm-notify-window", vm_notify_window); + static bool __read_mostly opt_ept_pml = true; static s8 __read_mostly opt_ept_ad = -1; int8_t __read_mostly opt_ept_exec_sp = -1; @@ -210,6 +213,7 @@ static void __init vmx_display_features(void) P(cpu_has_vmx_pml, "Page Modification Logging"); P(cpu_has_vmx_tsc_scaling, "TSC Scaling"); P(cpu_has_vmx_bus_lock_detection, "Bus Lock Detection"); + P(cpu_has_vmx_notify_vm_exiting, "Notify VM Exit"); #undef P if ( !printed ) @@ -329,6 +333,8 @@ static int vmx_init_vmcs_config(bool bsp) opt |= SECONDARY_EXEC_UNRESTRICTED_GUEST; if ( opt_ept_pml ) opt |= SECONDARY_EXEC_ENABLE_PML; + if ( vm_notify_window != ~0u ) + opt |= SECONDARY_EXEC_NOTIFY_VM_EXITING; /* * "APIC Register Virtualization" and "Virtual Interrupt Delivery" @@ -1290,6 +1296,17 @@ static int construct_vmcs(struct vcpu *v) v->arch.hvm.vmx.exception_bitmap = HVM_TRAP_MASK | (paging_mode_hap(d) ? 0 : (1U << TRAP_page_fault)) | (v->arch.fully_eager_fpu ? 0 : (1U << TRAP_no_device)); + if ( cpu_has_vmx_notify_vm_exiting ) + { + __vmwrite(NOTIFY_WINDOW, vm_notify_window); + /* + * Disable #AC and #DB interception: by using VM Notify Xen is + * guaranteed to get a VM exit even if the guest manages to lock the + * CPU. + */ + v->arch.hvm.vmx.exception_bitmap &= ~((1U << TRAP_debug) | + (1U << TRAP_alignment_check)); + } vmx_update_exception_bitmap(v); v->arch.hvm.guest_cr[0] = X86_CR0_PE | X86_CR0_ET; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index dabf4a3552..b11578777a 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1428,10 +1428,19 @@ static void cf_check vmx_update_host_cr3(struct vcpu *v) void vmx_update_debug_state(struct vcpu *v) { + unsigned int mask = 1u << TRAP_int3; + + if ( !cpu_has_monitor_trap_flag && cpu_has_vmx_notify_vm_exiting ) + /* + * Only allow toggling TRAP_debug if notify VM exit is enabled, as + * unconditionally setting TRAP_debug is part of the XSA-156 fix. + */ + mask |= 1u << TRAP_debug; + if ( v->arch.hvm.debug_state_latch ) - v->arch.hvm.vmx.exception_bitmap |= 1U << TRAP_int3; + v->arch.hvm.vmx.exception_bitmap |= mask; else - v->arch.hvm.vmx.exception_bitmap &= ~(1U << TRAP_int3); + v->arch.hvm.vmx.exception_bitmap &= ~mask; vmx_vmcs_enter(v); vmx_update_exception_bitmap(v); @@ -4180,6 +4189,9 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) switch ( vector ) { case TRAP_debug: + if ( cpu_has_monitor_trap_flag && cpu_has_vmx_notify_vm_exiting ) + goto exit_and_crash; + /* * Updates DR6 where debugger can peek (See 3B 23.2.1, * Table 23-1, "Exit Qualification for Debug Exceptions"). @@ -4619,6 +4631,22 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) */ break; + case EXIT_REASON_NOTIFY: + __vmread(EXIT_QUALIFICATION, &exit_qualification); + + if ( unlikely(exit_qualification & NOTIFY_VM_CONTEXT_INVALID) ) + { + perfc_incr(vmnotify_crash); + gprintk(XENLOG_ERR, "invalid VM context after notify vmexit\n"); + domain_crash(v->domain); + break; + } + + if ( unlikely(exit_qualification & INTR_INFO_NMI_UNBLOCKED_BY_IRET) ) + undo_nmis_unblocked_by_iret(); + + break; + case EXIT_REASON_VMX_PREEMPTION_TIMER_EXPIRED: case EXIT_REASON_INVPCID: /* fall through */ diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 2095c1e612..f8fe8d0c14 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -2487,6 +2487,7 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs, case EXIT_REASON_EPT_MISCONFIG: case EXIT_REASON_EXTERNAL_INTERRUPT: case EXIT_REASON_BUS_LOCK: + case EXIT_REASON_NOTIFY: /* pass to L0 handler */ break; case VMX_EXIT_REASONS_FAILED_VMENTRY: diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index f3df5113d4..78404e42b3 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -268,6 +268,7 @@ extern u32 vmx_vmentry_control; #define SECONDARY_EXEC_XSAVES 0x00100000 #define SECONDARY_EXEC_TSC_SCALING 0x02000000 #define SECONDARY_EXEC_BUS_LOCK_DETECTION 0x40000000 +#define SECONDARY_EXEC_NOTIFY_VM_EXITING 0x80000000 extern u32 vmx_secondary_exec_control; #define VMX_EPT_EXEC_ONLY_SUPPORTED 0x00000001 @@ -349,6 +350,8 @@ extern u64 vmx_ept_vpid_cap; (vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING) #define cpu_has_vmx_bus_lock_detection \ (vmx_secondary_exec_control & SECONDARY_EXEC_BUS_LOCK_DETECTION) +#define cpu_has_vmx_notify_vm_exiting \ + (vmx_secondary_exec_control & SECONDARY_EXEC_NOTIFY_VM_EXITING) #define VMCS_RID_TYPE_MASK 0x80000000 @@ -456,6 +459,7 @@ enum vmcs_field { SECONDARY_VM_EXEC_CONTROL = 0x0000401e, PLE_GAP = 0x00004020, PLE_WINDOW = 0x00004022, + NOTIFY_WINDOW = 0x00004024, VM_INSTRUCTION_ERROR = 0x00004400, VM_EXIT_REASON = 0x00004402, VM_EXIT_INTR_INFO = 0x00004404, diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index eae39365aa..8e1e42ac47 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -221,6 +221,7 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) #define EXIT_REASON_XSAVES 63 #define EXIT_REASON_XRSTORS 64 #define EXIT_REASON_BUS_LOCK 74 +#define EXIT_REASON_NOTIFY 75 /* Remember to also update VMX_PERF_EXIT_REASON_SIZE! */ /* @@ -236,6 +237,11 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) #define INTR_INFO_VALID_MASK 0x80000000 /* 31 */ #define INTR_INFO_RESVD_BITS_MASK 0x7ffff000 +/* + * Exit Qualifications for NOTIFY VM EXIT + */ +#define NOTIFY_VM_CONTEXT_INVALID 1u + /* * Exit Qualifications for MOV for Control Register Access */ diff --git a/xen/arch/x86/include/asm/perfc_defn.h b/xen/arch/x86/include/asm/perfc_defn.h index 6fce21e85a..487e20dc97 100644 --- a/xen/arch/x86/include/asm/perfc_defn.h +++ b/xen/arch/x86/include/asm/perfc_defn.h @@ -6,7 +6,7 @@ PERFCOUNTER_ARRAY(exceptions, "exceptions", 32) #ifdef CONFIG_HVM -#define VMX_PERF_EXIT_REASON_SIZE 75 +#define VMX_PERF_EXIT_REASON_SIZE 76 #define VMEXIT_NPF_PERFC 143 #define SVM_PERF_EXIT_REASON_SIZE (VMEXIT_NPF_PERFC + 1) PERFCOUNTER_ARRAY(vmexits, "vmexits", @@ -129,5 +129,6 @@ PERFCOUNTER(iommu_pt_shatters, "IOMMU page table shatters") PERFCOUNTER(iommu_pt_coalesces, "IOMMU page table coalesces") PERFCOUNTER(buslock, "Bus Locks Detected") +PERFCOUNTER(vmnotify_crash, "domain crashes by Notify VM Exit") /*#endif*/ /* __XEN_PERFC_DEFN_H__ */