Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp314616pxj; Tue, 1 Jun 2021 23:14:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyEiZDU7VR6VUf858H5p1YzcYee6dYJqMlHlxLGtIRIfRUbevtsc51Cw5MFPcDDABpnLwr X-Received: by 2002:a17:906:4308:: with SMTP id j8mr25991899ejm.315.1622614462222; Tue, 01 Jun 2021 23:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622614462; cv=none; d=google.com; s=arc-20160816; b=EyB8djD/uCDMl5BAba7I8TfqekrYwchd2nfta4SuqF9DJS3x+zwiKRqsX0R4SSu8Bk dSKgV8n3lfu8CTx2J8hmJY0zytXjyhkwhTK3Rnbzi7dSntb7XR93n0fGunhxOo66/IER ECBmO6XlTTV736ndKlLRYLP759tX+7saacpwuZQRnb7H6/sMglJxUrBAPhaiiII9Tn6C 6NbOZuVacrGldzvPyntArgXJ98ZplwTfmLlrKJBkrzPY797KwgObr6WNh0mAvXD43wFX R/HfDkwy5TYUPPlcgwE6qY5/YResZ15NzXnXtA+/Oqkfz+RsqYLnZsSLpPK3SPrWKLlT LLJw== 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=If+pbqjbZBzt0vitS+jeV5ByUJVdMxMPDzL54HNb/Fg=; b=ULV30L8UX5UAZYB4WAzwuxshis7v6OEgti8Q+hGSZed3hSdOzdohUHYhnBaZUS9k5V 8WgHO73gYDsOdLS67JtuPTV4rkocwleiYKW9vTWLmCFoDDANUMFVoVlWvF0jdtjkwvi2 60Y4AFSHgsqEIWm3Vv5MqkpgIAnh7vLjEcjy56w9jZf87E8XMjywvn91ayIH5mCV+5fP fOluOKpn1orpkWjDGtvn3RgcfEADeDlaLelYwqR/ica9QDdIPI8mLRZxgOP7F3N4KUJn /inbKmrdnolVzgdkTOi61mtnAw9slDqGAZEsTUtVek0fe+JwyKqJnRy6C1uPRaZmxiiD ZSiw== 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 v16si5092487ejg.147.2021.06.01.23.13.53; Tue, 01 Jun 2021 23:14:22 -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 S231200AbhFBCYT (ORCPT + 99 others); Tue, 1 Jun 2021 22:24:19 -0400 Received: from mga18.intel.com ([134.134.136.126]:39490 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbhFBCXh (ORCPT ); Tue, 1 Jun 2021 22:23:37 -0400 IronPort-SDR: Ls+1Q0CF/i5s5ufBO0oLLJ//o4c5BdVoIkE7YufQ+5qd99swLNLNpMNpYjh/uq+ZdD1io2HAUU g0BLzFlE09Tw== X-IronPort-AV: E=McAfee;i="6200,9189,10002"; a="191037611" X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="191037611" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:52 -0700 IronPort-SDR: /50QWJuamk2Af5O7nXslCfbtggWuype9jayEaMohCzwo8sjQFjQvX2IDm6z81ShHCc48aAY6hp Hl1Y+CSZfxpg== X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="633069250" Received: from mjdelaro-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.3.23]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:51 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH v1 11/11] x86/tdx: Handle CPUID via #VE Date: Tue, 1 Jun 2021 19:21:36 -0700 Message-Id: <20210602022136.2186759-12-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" TDX has three classes of CPUID leaves: some CPUID leaves are always handled by the CPU, others are handled by the TDX module, and some others are handled by the VMM. Since the VMM cannot directly intercept the instruction these are reflected with a #VE exception to the guest, which then converts it into a hypercall to the VMM, or handled directly. The TDX module EAS has a full list of CPUID leaves which are handled natively or by the TDX module in 16.2. Only unknown CPUIDs are handled by the #VE method. In practice this typically only applies to the hypervisor specific CPUIDs unknown to the native CPU. Therefore there is no risk of causing this in early CPUID code which runs before the #VE handler is set up because it will never access those exotic CPUID leaves. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/tdx.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index af7acea500ab..17725646eb30 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -164,6 +164,22 @@ static int tdg_write_msr_safe(unsigned int msr, unsigned int low, return ret ? -EIO : 0; } +static void tdg_handle_cpuid(struct pt_regs *regs) +{ + u64 ret; + struct tdx_hypercall_output out = {0}; + + ret = __tdx_hypercall(EXIT_REASON_CPUID, regs->ax, + regs->cx, 0, 0, &out); + + WARN_ON(ret); + + regs->ax = out.r12; + regs->bx = out.r13; + regs->cx = out.r14; + regs->dx = out.r15; +} + unsigned long tdg_get_ve_info(struct ve_info *ve) { u64 ret; @@ -207,6 +223,9 @@ int tdg_handle_virtualization_exception(struct pt_regs *regs, case EXIT_REASON_MSR_WRITE: ret = tdg_write_msr_safe(regs->cx, regs->ax, regs->dx); break; + case EXIT_REASON_CPUID: + tdg_handle_cpuid(regs); + break; default: pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); return -EFAULT; -- 2.25.1