Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3845012pxy; Mon, 26 Apr 2021 11:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTBjvsh2BDL1KzBq97LWzSBAhRjtCTEE4wNWU5ljR552xE4gHqbbQz2F0zv5dBb0CNfXsg X-Received: by 2002:a05:6402:110b:: with SMTP id u11mr23559893edv.356.1619460325266; Mon, 26 Apr 2021 11:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460325; cv=none; d=google.com; s=arc-20160816; b=aaU82pRJqCW79fZDzi3jf63c3Nq4xBSlKmFnJc24OyR5hK3Y7Gq/kOTeeHfSSe/o2s T3Fz8L7GsgxTTIxfOSNn8sxJsiX0uPhwuJOnejlDJfobZOHDx/L28YIbXskCKcg0SKQi JkSV/9aNimgMKCZ1FUb7k2Yh5Lily1JET7YbvsXv1Nfo6DLRIDPiXFOJjETqs8qn+XsN 90m2E8LbeQoK49jz1RD0XE+0zagYi0HJTDi6eP3ieUa/xHqJOVdO/W5OCjWCY3H+Zzlm p5/2sqS5VkNcCw9saJ9cHuzsuf4aSnCEpCAXWKQsMGeVftgomD4bp6uuH7z4ZLe/jJcb RPEw== 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=JVm26foplE7Ey2gRSXazbjRNdel5zZl7KI5/caJP3ms=; b=nmgwJGpUAJkBzurLJ/McHqQ18jVd9paohWQnVa5wxYJJWGoUTbNFDcJE1AtPsnNVZn GJ7nE1ADltaETC0fem3V/53qBP1tWuc29DetlixC+E2qhV5V3LHDBLkxlQ1TDfbeT+1m cnUNViEUFL2PTSqN5ul/F5oREXe2Cw4sctoTF0rVURsYPvy9OyjwfB9la1J8VVx+ep1r s3eoXqSgWtEwt7plVl/HUAW3TGVG1OcD5bqrJCNCMXL5ziRNHdcJgNRXp7jmm13SsEI8 J5VX856DEP3HxFVycfxOj6EvTZubt9YWNkl6Uo7NIC31lXJCeyixF/12/TEQMOiqK+iV oKZw== 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 u1si446134edy.179.2021.04.26.11.05.01; Mon, 26 Apr 2021 11:05:25 -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 S234944AbhDZSER (ORCPT + 99 others); Mon, 26 Apr 2021 14:04:17 -0400 Received: from mga05.intel.com ([192.55.52.43]:6419 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234279AbhDZSDa (ORCPT ); Mon, 26 Apr 2021 14:03:30 -0400 IronPort-SDR: x47xAY+uSnimq6jHnwkHjI32XzJoNUGqlg37wq0Wt4MN+4X65bRpUmab65YZ3pS7lDrq/phU5x +KvBpT7nft4g== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="281710678" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="281710678" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:47 -0700 IronPort-SDR: dvcm1gFRbCpTm4A7Ju6gGo23W0T2DiLrXFXbmCghwgYPgdNa8RFg5rtYpsYDgby3kVx31Bs0WB +mlYWkXRTwPw== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353367" 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:44 -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 09/32] x86/tdx: Add HLT support for TDX guest Date: Mon, 26 Apr 2021 11:01:36 -0700 Message-Id: <5c11caeada56565b02ca64185be224056f3274c3.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> 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" Per Guest-Host-Communication Interface (GHCI) for Intel Trust Domain Extensions (Intel TDX) specification, sec 3.8, TDVMCALL[Instruction.HLT] provides HLT operation. Use it to implement halt() and safe_halt() paravirtualization calls. The same TDVMCALL is used to handle #VE exception due to EXIT_REASON_HLT. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/tdx.c | 44 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index ccfcb07bfb2c..5169f72b6b3f 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -82,6 +82,27 @@ static void tdg_get_info(void) td_info.attributes = out.rdx; } +static __cpuidle void tdg_halt(void) +{ + u64 ret; + + ret = __tdvmcall(EXIT_REASON_HLT, 0, 0, 0, 0, NULL); + + /* It should never fail */ + BUG_ON(ret); +} + +static __cpuidle void tdg_safe_halt(void) +{ + /* + * Enable interrupts next to the TDVMCALL to avoid + * performance degradation. + */ + asm volatile("sti\n\t"); + + tdg_halt(); +} + unsigned long tdg_get_ve_info(struct ve_info *ve) { u64 ret; @@ -111,13 +132,19 @@ unsigned long tdg_get_ve_info(struct ve_info *ve) int tdg_handle_virtualization_exception(struct pt_regs *regs, struct ve_info *ve) { - /* - * TODO: Add handler support for various #VE exit - * reasons. It will be added by other patches in - * the series. - */ - pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); - return -EFAULT; + switch (ve->exit_reason) { + case EXIT_REASON_HLT: + tdg_halt(); + break; + default: + pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); + return -EFAULT; + } + + /* After successful #VE handling, move the IP */ + regs->ip += ve->instr_len; + + return 0; } void __init tdx_early_init(void) @@ -129,5 +156,8 @@ void __init tdx_early_init(void) tdg_get_info(); + pv_ops.irq.safe_halt = tdg_safe_halt; + pv_ops.irq.halt = tdg_halt; + pr_info("TDX guest is initialized\n"); } -- 2.25.1