Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp60149pxb; Wed, 22 Sep 2021 15:58:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFmlRvqCnA9UvcYX7RyJUHi+T3rnpvH8/JaJdn9v/w4LKYeWw3yF2kUtr7TrP+ZIGnVMTZ X-Received: by 2002:a17:906:3148:: with SMTP id e8mr1791315eje.240.1632351485311; Wed, 22 Sep 2021 15:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632351485; cv=none; d=google.com; s=arc-20160816; b=vNuGbUlqAtlQxH6hq/VaQY+OarvktGEpu6wOmxFheIyBCWpCc9UymQTQsyb0Dnd1T3 Wef1SjyYH3wmkPN7659X0tNSxNj5bFujwQi7h1UMe6SWczt5MrgrxcjaMpC914aTo6lh tjOjsX+EVjeqb1DFJBruDvc1O2plrowXS+5rGIXHGFex2lvWVVoWhNEWVHP3lrS/hQwL iwmGiNhR/Co43iu+EeW8YrSZyMvJ6W9cNfWFTmHkdWOWK/KxeVzyPKW/DLkeE0Hbl4LM owJaunVsXeJn/RG4bxh6AzbTFNRiVIL8b/lloWU3aGQZQHKDl2nbNczr7Ay6GO9Nev3I sUaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=otOg237FaWjq891iunuIeHu0QEqoqHQj/L+jzoGUMTQ=; b=D1hH1bivDDepUoMn27EXdDFR9Gbw1+/L+4Tat8aqIgmjmTdOuMUKArud0j9zHJWdOC 9CObueBstELpX3Z/YC312tRqAJOo+n4A2m1ZwnWl/56H+usyzwfmydQsPCUiI7jItbvm 13tMaPfBlBUeQ33lCii3aA82U46lxbTRCO5c77sWKQ2knD7uEjtesmrFbnoE1ODmDmgA 4RR1Quv+PhNhph3cM7ruX2OTy+IVf69OMrMpV8uXThWTUOL4aSNnyiYsYtkTVDu6rX4f EBI8hKprkIL+KvduTj1/wYPfGGWSqX+F9nploys0pL3uHWDK1reDCMEkyz8yrv9lI7JJ oSWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p2si3907376ejj.156.2021.09.22.15.57.39; Wed, 22 Sep 2021 15:58:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238455AbhIVW5E (ORCPT + 99 others); Wed, 22 Sep 2021 18:57:04 -0400 Received: from mga01.intel.com ([192.55.52.88]:10398 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238376AbhIVW4Z (ORCPT ); Wed, 22 Sep 2021 18:56:25 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10115"; a="246164391" X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="246164391" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 15:54:54 -0700 X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="653457382" Received: from mnamagi-mobl1.gar.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.34.84]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 15:54:53 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" Cc: Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org Subject: [PATCH v6 10/10] x86/tdx: Handle MWAIT and MONITOR Date: Wed, 22 Sep 2021 15:52:39 -0700 Message-Id: <20210922225239.3501262-11-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210922225239.3501262-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210922225239.3501262-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running as a TDX guest, there are a number of existing, privileged instructions that do not work. If the guest kernel uses these instructions, the hardware generates a #VE. List of unsupported instructions can be found in Intel Trust Domain Extensions (Intel® TDX) Module specification, sec 9.2.2 and in Guest-Host Communication Interface (GHCI) Specification for Intel TDX, sec 2.4.1. To prevent TD guests from using MWAIT/MONITOR instructions, the CPUID flags for these instructions are already disabled by the TDX module.      After the above mentioned preventive measures, if TD guests still execute these instructions, add appropriate warning message (WARN_ONCE()) in #VE handler. This handling behavior is same as KVM (which also treats MWAIT/MONITOR as nops with warning once in unsupported platforms). Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andi Kleen Reviewed-by: Dan Williams --- Changes since v5: * None Changes since v4: * Removed usage of We/You in commit log and comments. Changes since v3: * None Changes since v2: * None arch/x86/kernel/tdx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index aa4719c22c2a..a77d8ffae686 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -369,6 +369,14 @@ int tdx_handle_virtualization_exception(struct pt_regs *regs, return -EFAULT; } break; + case EXIT_REASON_MONITOR_INSTRUCTION: + case EXIT_REASON_MWAIT_INSTRUCTION: + /* + * Something in the kernel used MONITOR or MWAIT despite + * X86_FEATURE_MWAIT being cleared for TDX guests. + */ + WARN_ONCE(1, "TD Guest used unsupported MWAIT/MONITOR instruction\n"); + break; default: pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); return -EFAULT; -- 2.25.1