From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8CF5C433F5 for ; Tue, 5 Oct 2021 20:42:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D22EE613D5 for ; Tue, 5 Oct 2021 20:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236763AbhJEUoS (ORCPT ); Tue, 5 Oct 2021 16:44:18 -0400 Received: from mga07.intel.com ([134.134.136.100]:11176 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236188AbhJEUn5 (ORCPT ); Tue, 5 Oct 2021 16:43:57 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10128"; a="289354616" X-IronPort-AV: E=Sophos;i="5.85,349,1624345200"; d="scan'208";a="289354616" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 13:42:04 -0700 X-IronPort-AV: E=Sophos;i="5.85,349,1624345200"; d="scan'208";a="523979726" Received: from alyee-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.5.222]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 13:42:04 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf , "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 v7 10/10] x86/tdx: Handle MWAIT and MONITOR Date: Tue, 5 Oct 2021 13:41:36 -0700 Message-Id: <20211005204136.1812078-11-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211005204136.1812078-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20211005204136.1812078-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 titled "Instructions that Cause a #VE Unconditionally" and in Guest-Host Communication Interface (GHCI) Specification for Intel TDX, sec titled "#VE Injected due to disallowed instructions". 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 v6: * Added section title to spec reference in commit log. 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 851ad143da03..a66520405109 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -364,6 +364,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