Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3845601pxy; Mon, 26 Apr 2021 11:06:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/R0yM9SEAhX3Alz45DiC4cDV8DoFKmXgljx00htv6Tl9nmZlxRiq5/ulpU23ootNwEey7 X-Received: by 2002:a17:906:bcc2:: with SMTP id lw2mr19605392ejb.470.1619460370399; Mon, 26 Apr 2021 11:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460370; cv=none; d=google.com; s=arc-20160816; b=XpsXyZOqrChXTWJnVzQtNnB0mQ1hfb/ePfGAMvMwUrUZq+zREFBb+/qRvCzUkC6NLU 2vBr5L0KjMwm+FMZjslTzq/cMQk/nIL6XA3p48AXjI7OlIed3u2fv3Ml+e2aNUREqyxw iSTTFhbQI/1T1tMLMogo0ODadx4IMaXajaHyJ4Y1gPoNZMo1vqzN6b/Z13wGrEnHlBsc +TENjtytXPpnwgj70jyVeLOugDhjBXXMoN+EMW8O3q8TM30xeYpmFo/S4UMJ5ukQRpx1 BJ9HiJ/Q1KRwsH5zT7abdlZyoiVq+YgRTzfEF8S4AF+aso3zu8fF6hzPCbV2Y9XC1X3E 1vSg== 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 :ironport-sdr:ironport-sdr; bh=Y+kGFTDzhyRQTQXmjkYXe9iEDWH6mTdJGsNvbFvz9tQ=; b=IxmKPXg0sYhrWyQKdidWkPwUVqJ1qQdS8iMkFqPJjtDFZ+fYipao2hEbMtUUPfyYmM AvAH4VO2q8WgVegmOMb/ScD0rpBJEECrO4litAJg/Cv4LMN4IJCwU8/y2WOE/NROikwF JQuL9ZOeL5r27e/ZQ4ql5P9H4bDG/bvm758w2bmPLmU9/fVDIYqCqR39sEK5mVZ8zWrz C6VTReAU0u+89VE9bABuZpWJdmKyzJw0Cpaisdm/ts/hDVuctlCr7PmloiwmAl77klxW jhqwYMUx+PQziVfeVbOWgbyUDk4ea7EKjNbR05bT1BHvUuB/asZSo33sv0snH/y8ppV7 qd2A== 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 nb11si1101069ejc.133.2021.04.26.11.05.44; Mon, 26 Apr 2021 11:06:10 -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 S234929AbhDZSEh (ORCPT + 99 others); Mon, 26 Apr 2021 14:04:37 -0400 Received: from mga04.intel.com ([192.55.52.120]:22343 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234148AbhDZSDe (ORCPT ); Mon, 26 Apr 2021 14:03:34 -0400 IronPort-SDR: kbUIcSiUQuDuo4K3U5xpw1d2AWSF/mlYNC9lgwzLFm9aY6bEZKAFUedXxlMGbmlFmR5943Z5lP P6gEsoIb/UpA== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="194263258" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="194263258" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:50 -0700 IronPort-SDR: TZoklZsXDchjOM4p2zZP7e3bYTlApnrnKHxrPMqoDZMFUplpEIZNxZjDe13rn6YqcZGnsZZibw OgIHWi4lETWQ== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353400" Received: from ssumanpx-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.254.34.197]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:49 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Dan Williams , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Kuppuswamy Sathyanarayanan Subject: [RFC v2 16/32] x86/tdx: Handle MWAIT, MONITOR and WBINVD Date: Mon, 26 Apr 2021 11:01:43 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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. You can find the list of unsupported instructions 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 guest from using MWAIT/MONITOR instructions, support for these instructions are already disabled by TDX module (SEAM). So CPUID flags for these instructions should be in disabled state. After the above mentioned preventive measures, if TD guests still execute these instructions, add appropriate warning messages in #VE handler. For WBIND instruction, since it's related to memory writeback and cache flushes, it's mainly used in context of IO devices. Since TDX 1.0 does not support non-virtual I/O devices, skipping it should not cause any fatal issues. But to let users know about its usage, use WARN() to report about it.. For MWAIT/MONITOR instruction, since its unsupported use WARN() to report unsupported usage. Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andi Kleen --- arch/x86/kernel/tdx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 3fe617978fc4..294dda5bf3f6 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -371,6 +371,21 @@ int tdg_handle_virtualization_exception(struct pt_regs *regs, case EXIT_REASON_EPT_VIOLATION: ve->instr_len = tdg_handle_mmio(regs, ve); break; + case EXIT_REASON_WBINVD: + /* + * WBINVD is not supported inside TDX guests. All in- + * kernel uses should have been disabled. + */ + WARN_ONCE(1, "TD Guest used unsupported WBINVD instruction\n"); + 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