From patchwork Fri Dec 8 17:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 175959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5598368vqy; Fri, 8 Dec 2023 09:18:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGxgfKeFxB5vKsE5noTNSVOf64EgyO3aBrEKjkqCOgjBNb7MnfgtB9T/c+u0M9yYyNODYr X-Received: by 2002:a17:90a:8a18:b0:286:54d2:5767 with SMTP id w24-20020a17090a8a1800b0028654d25767mr1545096pjn.0.1702055880223; Fri, 08 Dec 2023 09:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702055880; cv=none; d=google.com; s=arc-20160816; b=dDjwCIBab7odgjL/lWerbz8KGSV96KCAeYOC/xKc2sasFoO0XoJdt2ENPxxKMlT6eG C1OPAsz3yDLdkdUq1aTwoJ/46xQnEWGuvqoN06+GAft1SKBNjQOZNrtFRCHaxc7kANmO zNpbg9fMpX06H/Dj4dOz8bHBb2lqTL7vFtjV67w2ewkelTjoSdWxx/glpoivZsVzR8AZ E67MiyuBQ3xevwlUVRZJXw9hZlwqnFk1AES4Q0iXAOBaYSRgm/FevrDWmiDAqiNl6oUy piMgn2C/IZKU/xiuUFMBOIPwPib4yoyn5dBlfDKDDWVW+AxFL107+vriN2IhxYC3HS7U FaTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=gh09TPzypnck/FA5Ej2jNvr7L9opBLDGxc+LKMUTktY=; fh=EclKCyMvkjLDbhbll74I3WKPleSJXRqhmwGYSWi+Rso=; b=OlW3bXMPfFoyB3QljTDKXuye4v/uYiRdoz+inliHiCy8KI8vn+XnQMiSUX0IcnwXt5 MBp9KGJNEX/m3HmifEh1o5xZQgUueLUdoMkUC7/GsaYay6pqtURrSDMwoCFFx+TSZrdd E4yl6L0byUi6glwegG55LMEY7RfJ5gFc5drSsXQZCs9NPMGCg4UK4eKlqjLN9dOXYOpo w+tGY5Kl+JZ0VMRyKPWNc8kQEYrEUtJYuvwV/T1dpzL3aVYb+H4oyhlQ5gpJ2XMGpk71 881nX4IVAgsFVhvzGsuQQX3Ppk0tGEZnrey4U+RBVfSAuQ/Iy/Dd5dvZz1yPH36NFPTD Qhbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MPEf9gM+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=p6DXvwJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id m5-20020a63ed45000000b005b918d9a3c2si1822948pgk.868.2023.12.08.09.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:18:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MPEf9gM+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=p6DXvwJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 448D5837E64F; Fri, 8 Dec 2023 09:17:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574270AbjLHRRU (ORCPT + 99 others); Fri, 8 Dec 2023 12:17:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233782AbjLHRRQ (ORCPT ); Fri, 8 Dec 2023 12:17:16 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBDC810E3; Fri, 8 Dec 2023 09:17:21 -0800 (PST) Date: Fri, 08 Dec 2023 17:17:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702055840; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gh09TPzypnck/FA5Ej2jNvr7L9opBLDGxc+LKMUTktY=; b=MPEf9gM+JTTx5SqKAdS1nbMlNUvDcF6NpnFhAxqutw91vHRRtB2zu+WPpY2xG1upEO/GTv qipkfUh7TdmvI74P7Z3lVgvGGgCAnphs20F9EUE+XqqBQydQOE61qsm2DMJzEUIU4dunnd eaVwaePTghFy5U3O2BmPpkD+aSIAkRJ7gOm++6+HcD9Vgu9peAA0/2nP/altdlfYyglmXv iku6AOFbsUppZVfZNa9vlry96Q1ueBkhmSmyqMNDm7qcXBZoUNjC/Ewns6IHruO5cZfhGv uEnuuKtp9EZJcS5nXC8nZ6tJeH1AWPPvjxsr3Y1UikHyGSb92TJsaHJaTLmgYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702055840; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gh09TPzypnck/FA5Ej2jNvr7L9opBLDGxc+LKMUTktY=; b=p6DXvwJjoKUDY970d/Xf3TrwJUsHO6KDxogRIHkkUx3GsJcrX0Cw/9nEhbK72ZtAbY6xQ1 v2BULHNshRMWcoCw== From: "tip-bot2 for Kai Huang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/virt/tdx: Handle TDX interaction with sleep and hibernation Cc: Kai Huang , Dave Hansen , "Kirill A. Shutemov" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170205583969.398.4926155283661461906.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:17:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784734946799174344 X-GMAIL-MSGID: 1784734946799174344 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: f3f6aa68640298fb966811b991c7b8efee67e181 Gitweb: https://git.kernel.org/tip/f3f6aa68640298fb966811b991c7b8efee67e181 Author: Kai Huang AuthorDate: Fri, 08 Dec 2023 09:07:36 -08:00 Committer: Dave Hansen CommitterDate: Fri, 08 Dec 2023 09:12:46 -08:00 x86/virt/tdx: Handle TDX interaction with sleep and hibernation TDX is incompatible with hibernation and some ACPI sleep states. Users must disable hibernation to use TDX. Users must also disable TDX if they want to use ACPI S3 sleep. This feels a bit wonky and asymmetric, but it avoids adding any new command-line parameters for now. It can be improved if users hate it too much. Long version: TDX cannot survive from S3 and deeper states. The hardware resets and disables TDX completely when platform goes to S3 and deeper. Both TDX guests and the TDX module get destroyed permanently. The kernel uses S3 to support suspend-to-ram, and S4 or deeper states to support hibernation. The kernel also maintains TDX states to track whether it has been initialized and its metadata resource, etc. After resuming from S3 or hibernation, these TDX states won't be correct anymore. Theoretically, the kernel can do more complicated things like resetting TDX internal states and TDX module metadata before going to S3 or deeper, and re-initialize TDX module after resuming, etc, but there is no way to save/restore TDX guests for now. Until TDX supports full save and restore of TDX guests, there is no big value to handle TDX module in suspend and hibernation alone. To make things simple, just choose to make TDX mutually exclusive with S3 and hibernation. Note the TDX module is initialized at runtime. To avoid having to deal with the fuss of determining TDX state at runtime, just choose TDX vs S3 and hibernation at kernel early boot. It's a bad user experience if the choice of TDX and S3/hibernation is done at runtime anyway, i.e., the user can experience being able to do S3/hibernation but later becoming unable to due to TDX being enabled. Disable TDX in kernel early boot when hibernation support is available. Currently there's no mechanism exposed by the hibernation code to allow other kernel code to disable hibernation once for all. Users that want TDX must disable hibernation, like using hibername=no on the command line. Disable ACPI S3 when TDX is enabled by the BIOS. For now the user needs to disable TDX in the BIOS to use ACPI S3. A new kernel command line can be added in the future if there's a need to let user disable TDX host via kernel command line. Alternatively, the kernel could disable TDX when ACPI S3 is supported and request the user to disable S3 to use TDX. But there's no existing kernel command line to do that, and BIOS doesn't always have an option to disable S3. [ dhansen: subject / changelog tweaks ] Signed-off-by: Kai Huang Signed-off-by: Dave Hansen Reviewed-by: Kirill A. Shutemov Reviewed-by: Dave Hansen Link: https://lore.kernel.org/all/20231208170740.53979-16-dave.hansen%40intel.com --- arch/x86/virt/vmx/tdx/tdx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 48fb1b3..6d030f6 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -1329,6 +1331,15 @@ void __init tdx_init(void) return; } + /* + * At this point, hibernation_available() indicates whether or + * not hibernation support has been permanently disabled. + */ + if (hibernation_available()) { + pr_err("initialization failed: Hibernation support is enabled\n"); + return; + } + err = register_memory_notifier(&tdx_memory_nb); if (err) { pr_err("initialization failed: register_memory_notifier() failed (%d)\n", @@ -1336,6 +1347,11 @@ void __init tdx_init(void) return; } +#if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND) + pr_info("Disable ACPI S3. Turn off TDX in the BIOS to use ACPI S3.\n"); + acpi_suspend_lowlevel = NULL; +#endif + /* * Just use the first TDX KeyID as the 'global KeyID' and * leave the rest for TDX guests.