Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2142834iof; Tue, 7 Jun 2022 21:10:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwElX3LZvf5RtCfv5U3rpIZtHgV4wdCrIYYW4jTitzp2ppbZzmHO5lIupBoDMQUkJYkNOhE X-Received: by 2002:a63:42:0:b0:3fa:b4d7:eeb5 with SMTP id 63-20020a630042000000b003fab4d7eeb5mr27375791pga.71.1654661447324; Tue, 07 Jun 2022 21:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661447; cv=none; d=google.com; s=arc-20160816; b=re0yiqfa25p4JZyKDJHLCu7kBHYDZdnOS77wc7UDXo6ll29tO2Y/qVm39Rq95HWEcL q4oWxUxYEvuYW6JhW3A52P7rQyCg01A18txg1z/fZbr9h/ckxjZNriJdjjc9xm+pLlvL rmxidYi5jstNKA9gD9Ir+XEvOX38Q4zkvPlMkGfmwLl0FZqD8R4oNYRBtHKlMJ4ShRcR nCVnL2Abf6OFo/xff9Al+dfojfGaLRKLuPzYJIUNCjjFToGOhas4hEPts7Ev53QHcOfJ hNSlt3IQZ+YRrMeB3DLGQR7ibYAJdufnOXgJjAzmL9ZyE4c/GAuiPcRPJ0Y7MSJ94LJM cILg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jdwUAkPybh634ejosPiIlEFfpi1PT9UP0Yg9pZ2zHm8=; b=k6pRIaAifP2JagPZ80/9Wcq184T6QRjUV5hOQuLzGsUWv35IfWgcZq/3vFitJdNeOq jMQlW7FCOLFaPJYpZOYnvnm6H2lBLzu4s1FGtB3i5dBZyL9Hmpj6slCuTQWoBCr087IM lGVPtzIPWxcKz2qBFNw8fqEcgCDIMpGa7HEEGsRY4zYVAcqFZrbinOhphHWDE9t/7M7i djnypbqfhqCp1a4dVG7wJM2x/55jxpOmax/uJrfiCEZUugkiWPvahTYb30r5s20oPckg A0wnEWxIP1zkfbY6ZoBULQpaH7yAdTY7mdVYJc4EILnWarSMhT2puhsB7INyCSekA1hd 9zzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O4XeK5cj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x8-20020a1709027c0800b00153b2d16586si9578517pll.398.2022.06.07.21.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:10:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O4XeK5cj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 705442823F7; Tue, 7 Jun 2022 20:42:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346113AbiFGRWG (ORCPT + 99 others); Tue, 7 Jun 2022 13:22:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345837AbiFGRTd (ORCPT ); Tue, 7 Jun 2022 13:19:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4BD6106341; Tue, 7 Jun 2022 10:19:27 -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 01450618CB; Tue, 7 Jun 2022 17:19:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10889C385A5; Tue, 7 Jun 2022 17:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622366; bh=RsqfcE3Vlaza98kvhQkeITROjqKHS5OvbTROZhct/dA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4XeK5cjURdrKv9ND1WmZqqyW7KZK8qeeUupTGohPWraVlSQ0zdEyud/nV0hiea1D IZj1VOZLru+PLhOm0xWwXDv/fgPJaqRa80x7VEIAuthkUAbbqiTYlUJYzMqXhWN+yG rf7sWBY4+x1ZWshV+2UYF1rMk7HjjBdWExr7nFGQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen , Dan Williams , Thomas Gleixner , Sasha Levin Subject: [PATCH 5.10 034/452] ACPICA: Avoid cache flush inside virtual machines Date: Tue, 7 Jun 2022 18:58:11 +0200 Message-Id: <20220607164909.565483546@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 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