From patchwork Thu Jan 26 22:11:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 48932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp520894wrn; Thu, 26 Jan 2023 14:33:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXvj6+P0Q5PSBf3HhkE0zpjvjiOqHiA9GNVMA8ebgzsMyKbCcxw1jVNWG6usnkPvhd1EHWUj X-Received: by 2002:a17:90a:7182:b0:229:19f7:a60d with SMTP id i2-20020a17090a718200b0022919f7a60dmr40717094pjk.0.1674772429420; Thu, 26 Jan 2023 14:33:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674772429; cv=none; d=google.com; s=arc-20160816; b=kiDxlGebNuj0shhKMcEXMFKgwjPGtSUqwNf3/TNtkBEYUdUPNabSzJe+2mcECQxuXO zpc5frEnYjvWSxyzYV0o37LulwKYAr/TNmnZICHOw8vvlRXoaWQKglT/iajub1gOaPbc oh9cIo+2Z9DXTZKXmXYexk6RTxkSiCxQUAWwjbVypX790mz3Ar9NcjKbPI3074C9cmW2 BRNWNSpjAufug3PxSwZgKQgn4It1O6DKT4ElE73bxJvY+caNin8f3iwfGO9wUcUXr17s 3qC7nklqrdE/k4iG7TkfPs/ob8iymo/pz+gB6LbUsI7WmJjYqngT25e6EXpGW2iKRgq6 KyhA== 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 :dkim-signature; bh=j3CCUQr0NXRyoeU7P5EaGtdWz4ZoU3xGLGz0mBhPzAc=; b=EVy/2z9yqvx8N2uUS3QHDsliLEUMyAQ7iP2DNTTVKGTW7KQDzEdHyRiyWWZxn6kVf4 AWkGT8IT8rOTilbb0DdJhRDGGhqtNJo15AqO1oXuF601nMLDMjB/TtlEbclT/G5yOoju eJIBGU4UL5Mk3oLANXoE08DjWSRVb4O8T9Pb5tR5dy4B6lDaz7pUM5keJgnbkiuTKdrs ZvIZndIMRrF8CNmHdGg71fo1t2rCRfw4VtyYgYQbh8LFnqUHMCGkoWsy1XRQ4vhvBlfJ Ht671Nk9LAjZC584voWC3e3OmZBJyH294behjDa+KdkuKQX3EE/sAWQAM/HkzqGh1OcH dbvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=avoJ0qGf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 30-20020a17090a199e00b0022c3e9115e3si1182490pji.172.2023.01.26.14.33.37; Thu, 26 Jan 2023 14:33:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=avoJ0qGf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbjAZWai (ORCPT + 99 others); Thu, 26 Jan 2023 17:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232362AbjAZWaZ (ORCPT ); Thu, 26 Jan 2023 17:30:25 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B61EAF759 for ; Thu, 26 Jan 2023 14:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674772224; x=1706308224; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4RnpvG851CQ2J01HFmizOyd6RFXJQ68QAxBEP3YWKQ4=; b=avoJ0qGfZyKcQ9tHDtyTxLr7SCaaqlf1YAlyhEkjwFWZNW+EP0yD7zpi fJhn+9TYW+Y5w1/kDlvNKuLp6loRKMJ2Hit92MwETgEDuEpIyTRcEtUu6 qL+jtdrlnlzIO+6k4PwJ1p/Doju93J7ri5qG022JC15Vk6vQpddWsdIjT qdI6GP5rgVsTtEucUZCTJ7OHxmrBZNvKjkIk2Eh2t4I/FkD3pfGXk+x9e RzHZ7IMEFb3Ex3OFhzOK9hQGC6P4FFeFU70nspG5GH28MICNfGDFiMguC 4v2zuAr1CW1VgvnZ4aJJftPxww6u903Bbls+HJClMaAUAHy8+vikKAXc6 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="389342099" X-IronPort-AV: E=Sophos;i="5.97,249,1669104000"; d="scan'208";a="389342099" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2023 14:12:13 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="751770953" X-IronPort-AV: E=Sophos;i="5.97,249,1669104000"; d="scan'208";a="751770953" Received: from smadjatx-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.210.179]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2023 14:12:10 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 7019310DBF3; Fri, 27 Jan 2023 01:12:03 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Borislav Petkov , Andy Lutomirski Cc: Kuppuswamy Sathyanarayanan , Thomas Gleixner , Elena Reshetova , x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2, RESEND 5/7] x86/tdx: Use ReportFatalError to report missing SEPT_VE_DISABLE Date: Fri, 27 Jan 2023 01:11:57 +0300 Message-Id: <20230126221159.8635-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230126221159.8635-1-kirill.shutemov@linux.intel.com> References: <20230126221159.8635-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756126175100221928?= X-GMAIL-MSGID: =?utf-8?q?1756126175100221928?= Linux TDX guests require that the SEPT_VE_DISABLE "attribute" be set. If it is not set, the kernel is theoretically required to handle exceptions anywhere that kernel memory is accessed, including places like NMI handlers and in the syscall entry gap. Rather than even try to handle these exceptions, the kernel refuses to run if SEPT_VE_DISABLE is unset. However, the SEPT_VE_DISABLE detection and refusal code happens very early in boot, even before earlyprintk runs. Calling panic() will effectively just hang the system. Instead, call a TDX-specific panic() function. This makes a very simple TDVMCALL which gets a short error string out to the hypervisor without any console infrastructure. Use TDG.VP.VMCALL to report the error. The hypercall can encode message up to 64 bytes in eight registers. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 669d9e4f2901..56accf653709 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -22,6 +22,7 @@ /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 +#define TDVMCALL_REPORT_FATAL_ERROR 0x10003 /* MMIO direction */ #define EPT_READ 0 @@ -140,6 +141,41 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport) } EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); +static void __noreturn tdx_panic(const char *msg) +{ + struct tdx_hypercall_args args = { + .r10 = TDX_HYPERCALL_STANDARD, + .r11 = TDVMCALL_REPORT_FATAL_ERROR, + .r12 = 0, /* Error code: 0 is Panic */ + }; + union { + /* Define register order according to the GHCI */ + struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; }; + + char str[64]; + } message; + + /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */ + strncpy(message.str, msg, 64); + + args.r8 = message.r8; + args.r9 = message.r9; + args.r14 = message.r14; + args.r15 = message.r15; + args.rdi = message.rdi; + args.rsi = message.rsi; + args.rbx = message.rbx; + args.rdx = message.rdx; + + /* + * Keep calling the hypercall in case VMM did not terminated + * the TD as it must. + */ + while (1) { + __tdx_hypercall(&args, 0); + } +} + static void tdx_parse_tdinfo(u64 *cc_mask) { struct tdx_module_output out; @@ -172,7 +208,7 @@ static void tdx_parse_tdinfo(u64 *cc_mask) */ td_attr = out.rdx; if (!(td_attr & ATTR_SEPT_VE_DISABLE)) - panic("TD misconfiguration: SEPT_VE_DISABLE attibute must be set.\n"); + tdx_panic("TD misconfiguration: SEPT_VE_DISABLE attribute must be set."); } /*