Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp574669pxr; Mon, 11 Apr 2022 01:18:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9vaKUrB2AquQqkjTsNROUtCeoMgTVQT0F0NcRLZ+LVh9NeaSZmp5Ba52mzSoJfZ31ickx X-Received: by 2002:aa7:98c2:0:b0:505:c55b:eacf with SMTP id e2-20020aa798c2000000b00505c55beacfmr3486180pfm.33.1649665130530; Mon, 11 Apr 2022 01:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649665130; cv=none; d=google.com; s=arc-20160816; b=Etz1lsNJ+QqpF33gbEs+nLv8eL0j78a3ZSXD3utCf6r1lTYVAKHjlJr29O911VYNH7 ZAwJlmSI0i4fSz8ZlmnLouPQEWsVWCYGHtXQ3SxJG60USf0ow4deXB1RZwu2wBG8W+pn gaYlORij0nozfLywVJ5ay+hA1UyQ8JJKgkbcNC4UYR5stnasEoWw2LVshMScKu3NP6tf evlfsaLAycvBfCeWDQGrRUC9KIrveq14AbeB58sWDUmY2aVqfwu8nNgogVLNDNZPnb4Q 3yw9SqLdN95qFmLDkyjoVt4p1jq10eq3owj3hmoQXfr7KIYScXriHUrz2sITTgkYyRlk ebdg== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=TDRE3JIcr2hY/DHw9IOdrcLFKUf37UqkwqHPl09hq0Q=; b=Rky4Oi/Nrbg9rb6aieF5OD6WauOj+Ml1fil9M8VPCkmJuKB+nE35wOXhpmc9FvToUH dKO1T6Rdfww/zMEFZfLzy0bvrbuCPC9XZGuP9P41CrWVhPf9MafNEiNTdIJPsA6uAy5q NY5Qu9RMM3sY2EMoJfZpsV0cnJzky2l5IIfVb8OtPxjeNigRT1rslJPbt7OQZsVuH/8b zbf6QdKjMyX7F4jYXIWr6BlZg/7HW8C8S6DLyAte9iAU5KMGvnWKfRSA3WrpVJXpjKpK Xj/mdNEr/cAC20oxQgC7nexj1AYlHk77qCoP0gf3O1hFNEvOqdRaAmaPZT2NuD8ZXOT+ 6Frg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ST2whTrR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b24-20020a170902b61800b00156d87887eesi7693478pls.83.2022.04.11.01.18.36; Mon, 11 Apr 2022 01:18:50 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=ST2whTrR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240247AbiDIB33 (ORCPT + 99 others); Fri, 8 Apr 2022 21:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237791AbiDIB30 (ORCPT ); Fri, 8 Apr 2022 21:29:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C799101F0B; Fri, 8 Apr 2022 18:27:21 -0700 (PDT) Date: Sat, 09 Apr 2022 01:27:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649467640; 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: in-reply-to:in-reply-to:references:references; bh=TDRE3JIcr2hY/DHw9IOdrcLFKUf37UqkwqHPl09hq0Q=; b=ST2whTrRPmaJ8SYEZocSOTvu98KXLlXvdOPHeMgtka48R/rkB6LRXSMAI0f2Jo9rzHw7iO yXads78h7dRzjAE+YqLm1siDC7Y4Y30it33yPBVx71hCgN8dbKvYUyCxvjBHeddDK2pmgF r7HaV4ntzQ6I+7en3l6GhEDH5g3nqQIW32SmVQfTK9L5W8O95VvEPH4lJURjHArpTx/joR Cfr4MP0JoSHUaeirrIShI2l7bkltre8z1ALgzUwnQE5pWVjTgVc/j3u9qy30ewn9vEKx0B 6a3GlMeAFguhOmMvqd4U1gKdancrwBws1KMVykLb4OKMhDDS8xKTf1SsXlvUGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649467640; 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: in-reply-to:in-reply-to:references:references; bh=TDRE3JIcr2hY/DHw9IOdrcLFKUf37UqkwqHPl09hq0Q=; b=brF7Pbjr/zLF4bazd4xiUqbYkjUlhwVbBxLIvW5MrbkW/YlDQiw/2oJICsC5CgmphYPr1O i2VPl07+H0uf8wBQ== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] ACPICA: Avoid cache flush inside virtual machines Cc: "Kirill A. Shutemov" , Dave Hansen , Dan Williams , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405232939.73860-30-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-30-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <164946763897.4207.11572808641505094885.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: e2efb6359e620521d1e13f69b2257de8ceaa9475 Gitweb: https://git.kernel.org/tip/e2efb6359e620521d1e13f69b2257de8ceaa9475 Author: Kirill A. Shutemov AuthorDate: Wed, 06 Apr 2022 02:29:38 +03:00 Committer: Dave Hansen CommitterDate: Thu, 07 Apr 2022 08:27:54 -07:00 ACPICA: Avoid cache flush inside virtual machines While running inside virtual machine, the kernel can bypass cache flushing. Changing sleep state in a virtual machine doesn't affect the host system sleep state and cannot lead to data loss. Before entering sleep states, the ACPI code flushes caches to prevent data loss using the WBINVD instruction. This mechanism is required on bare metal. But, any use WBINVD inside of a guest is worthless. Changing sleep state in a virtual machine doesn't affect the host system sleep state and cannot lead to data loss, so most hypervisors simply ignore it. Despite this, the ACPI code calls WBINVD unconditionally anyway. It's useless, but also normally harmless. In TDX guests, though, WBINVD stops being harmless; it triggers a virtualization exception (#VE). If the ACPI cache-flushing WBINVD were left in place, TDX guests would need handling to recover from the exception. Avoid using WBINVD whenever running under a hypervisor. This both removes the useless WBINVDs and saves TDX from implementing WBINVD handling. Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Dave Hansen Reviewed-by: Dan Williams Reviewed-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20220405232939.73860-30-kirill.shutemov@linux.intel.com --- arch/x86/include/asm/acenv.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/acenv.h b/arch/x86/include/asm/acenv.h index 9aff97f..d937c55 100644 --- a/arch/x86/include/asm/acenv.h +++ b/arch/x86/include/asm/acenv.h @@ -13,7 +13,19 @@ /* Asm macros */ -#define ACPI_FLUSH_CPU_CACHE() wbinvd() +/* + * ACPI_FLUSH_CPU_CACHE() flushes caches on entering sleep states. + * It is required to prevent data loss. + * + * While running inside virtual machine, the kernel can bypass cache flushing. + * Changing sleep state in a virtual machine doesn't affect the host system + * sleep state and cannot lead to data loss. + */ +#define ACPI_FLUSH_CPU_CACHE() \ +do { \ + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) \ + wbinvd(); \ +} while (0) int __acpi_acquire_global_lock(unsigned int *lock); int __acpi_release_global_lock(unsigned int *lock);