Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4936476ioo; Tue, 31 May 2022 15:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztypOCWWdNtAsMM0siDQg1u1/P26fK/u+NDpM0Gqhqj/ymo2La0oTBGvsbwddPOLIYZzw2 X-Received: by 2002:a05:6a00:2345:b0:518:929b:ce8b with SMTP id j5-20020a056a00234500b00518929bce8bmr48793905pfj.5.1654036078089; Tue, 31 May 2022 15:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654036078; cv=none; d=google.com; s=arc-20160816; b=Ysoe5jlrrEIE41znqdqFaRe3Ffj3GMszQU6qKlYNpnft7wQuFmHbWOj1UbZQex5Yxs D3HlSoG4bBW3AtvnWDtBLPrFQ7RTdX8KN0N892lU0aijQNcfcryfI8Op794kIr0wHveT GJcLFzeFQr6NarMDpt75SIkKgfv3pWbypiwHUckMGtWyxkQacSEUK1PoWbKokr6zGcSJ DwMzRNsbiNxiApz97k3fziYujhL0DXIDUe75Mn5YioLYAXPlwRtqF4BXWLGT6muIAWIG pww36hZhRf03nGgCeIkUnKeYB4UwAaPPnPYDpn0rzT1OjTN0rnjr9jmHJ/A3TOcGX7FM N8bg== 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=RSfg53v8okW4qHVT2blNeLMRxMvMCrij8mnAazRb6xY=; b=KQUeN1XVawGkTED7LH6B+7hOxy3EqXEuiwmieHdfjfEmJQfjmjmqZ17F3+TEFtb6Y8 QE0OpdAIab48f8eSx4dgxVry9thzc87EM/WRxLiNS3lTiRdivuB713KCAq5MEkBeR7C5 Bbbv7eCinR5qhq8IeYOFh0buvqDzjbQ+9SdSrMMDbkFVGXRl+CnAcL2/MNwv1H+SA9Ir QGzjTK/8Y99HvEyDgmgK7XrMvrZDvKhJRsmT5u/eu3IwjaAxQJMCZxXGiIQFv85GzZDY zTd1Cz2Yloyg8Wrjua23RrZcID1K2kcD0LiPIUTG0KH8K+sBFaR7i7SIe5ASUGuuOmpc KoUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RUKIqiTi; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a636a08000000b003fc6a2458b6si2967431pgc.350.2022.05.31.15.27.42; Tue, 31 May 2022 15:27:58 -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=@kernel.org header.s=k20201202 header.b=RUKIqiTi; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240321AbiE3O3K (ORCPT + 99 others); Mon, 30 May 2022 10:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241460AbiE3ORh (ORCPT ); Mon, 30 May 2022 10:17:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A5C52B38; Mon, 30 May 2022 06:47:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 080BF60F24; Mon, 30 May 2022 13:47:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DBD9C385B8; Mon, 30 May 2022 13:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918444; bh=x8Opey4gPhl/T9ZY27fZLs+uA+C7ZsiJ2XZJphbacJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUKIqiTiDwP/yX3NA60WoXfRI0pPRb9FosUUtEyUFDqOSfgjUp5CWWeYOz3JYGIFn 44EXVwKPoTqetnDxoNHJwxocuDh9Tr5gYqOk961pi0LZuA0WfdW04ezY/MX9sRN73I /7nqvJY7txN3N1spLnFgeuSV8X1/uewvyQoijbiQPSw/bUQHYF0WuNt9L4PDn0WE76 i4xNFDf3fbyQpNJnMiVc7lKE3rFeVUIheawPpE0r1MlyjExfXJaeX1uqj6wmPAlQvg 0rXcHDh9EYRGYBzJ4Z7/CSENmEnzfFKKZcKp9J/TW6CKbkIQ7sO6dNjhxJ3+2FMjnF BTSMs7JnNBesQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Kirill A. Shutemov" , Dave Hansen , Dan Williams , Thomas Gleixner , Sasha Levin , mingo@redhat.com, bp@alien8.de, x86@kernel.org Subject: [PATCH AUTOSEL 5.4 08/55] ACPICA: Avoid cache flush inside virtual machines Date: Mon, 30 May 2022 09:46:14 -0400 Message-Id: <20220530134701.1935933-8-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530134701.1935933-1-sashal@kernel.org> References: <20220530134701.1935933-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: "Kirill A. Shutemov" [ Upstream commit e2efb6359e620521d1e13f69b2257de8ceaa9475 ] 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 Signed-off-by: Sasha Levin --- 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 9aff97f0de7f..d937c55e717e 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); -- 2.35.1