Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3846698pxy; Mon, 26 Apr 2021 11:07:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/3QWwHTqZdBWN7m/O70zIEEzsAYwsECkxYUQpbMoehZOPARqelyGgqIF10TL1v2gTI0aK X-Received: by 2002:aa7:db14:: with SMTP id t20mr22098444eds.311.1619460451813; Mon, 26 Apr 2021 11:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460451; cv=none; d=google.com; s=arc-20160816; b=HILhD73f/UD6OmbV+iIQYiAiDd1CRYa4uEvu9+fjdE3MDuvybIG97vhC1X7BhC2jH3 eY76FI/ZOu/8FRWdmiyfWZe/irRnOQjow6/eCOYFVHN/X4WhHHH2YJObvfPOZAW3eDyL VBcPBTg5zTlIj4EYxx4tZDEG3lWrcX+byH7NA3t8/Cz10bdFW6XNIg8XRWh9mRGAacEr iu1FcRoW/Dg2FBlpb0COy5WVFWAHhb0kC/EVNWDWngsh259D9ZYx0bZyE9smU09YWIFn y6x0lQpKjKKAbbL7qkkv7IG/BkYAaKEntKB2Veph2hy7tKskbkA/1uPq6b0uT1B0/1X3 i0zg== 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=pySR6fd824AixLeaEM0dIMHoGjtpkofSc94PvrTUe1g=; b=mAO7BOA7RRFLq1M7nV4gd1PCmWTxKdljHXKWcrXaTHzYZrVC44fgHFEo9QNOcE2IJD t1VspvxNfhNj79KWhWUvZz2Senc5eAO40TnIr4tExOKJNqo9G4yugUgNOnAMZOfm8v+s oVgBlbYoJvs/qWKkwnIGyfnNFWaX7x8yF7nf58z/u6Yl42kxEIoEGHtxL1uB/NCl8ruA 9Fr9/ypdnnr7a/2apZSA4+spdPQ3gwW4+I0MnBwm8LfXDNIckOwIDd8sTPts6s4rVTHg hvhGAKMim2l1zyteBAt1YSnLSFb6Bra5UqGojH27gjwm/4AIFN6Gw5kgqJCXLoSyXfS9 FEvw== 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 d23si7216008eja.469.2021.04.26.11.07.06; Mon, 26 Apr 2021 11:07:31 -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 S233971AbhDZSE1 (ORCPT + 99 others); Mon, 26 Apr 2021 14:04:27 -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 S234288AbhDZSDc (ORCPT ); Mon, 26 Apr 2021 14:03:32 -0400 IronPort-SDR: EIwMIS/QHzEQA/86PIg7vL+c4SqLU8FuWqvjmaw1nUfRYlhMvKMjjkDatER7odkec50BVdyuje QogY7eHhpYcQ== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="194263253" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="194263253" 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:49 -0700 IronPort-SDR: 3jWZ8EtxzHZBiFbjW+9c8U3Cl0QWi4h0JH9PK35KjuaU5Aus0UbfLOb+x2jHdXqNGrGd3Lf4u9 gYxkZ3J0UOWw== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353380" 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:47 -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 12/32] x86/tdx: Handle CPUID via #VE Date: Mon, 26 Apr 2021 11:01:39 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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 TDCALL 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 5b16707b3577..e42e260df245 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -174,6 +174,21 @@ 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 tdvmcall_output out = {0}; + + ret = __tdvmcall(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; @@ -220,6 +235,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