Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp445168iog; Mon, 13 Jun 2022 06:08:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8N7kMbiKwDA5N3R3XLGRaryDnmUnehMANgBvBLJDMXEiFPyOKj1tZSQYHH5v4QMfkkOye X-Received: by 2002:a63:8349:0:b0:403:fee8:7b8f with SMTP id h70-20020a638349000000b00403fee87b8fmr14350433pge.434.1655125682747; Mon, 13 Jun 2022 06:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125682; cv=none; d=google.com; s=arc-20160816; b=kdoUer0kTSGbs6+mmcg1x03LD9AmBmkcYb0swAfK554kANhAVb1Urdn4A3lcve/J/L IYtmE17FNzVEBEeKjYvA4dwzeDtTzX+cFrO1k+UmJUZ5lrBEpFBzqlpy04c9r2LljGPQ d8zyGVvE3yKLR1S+2/x6DdumrEr9Y7UMVEnBxiqvGqanJKFtJZTM6gEpyDUdz/y6YiPb 22CIJ2K0etnEXGPLIkBvbptvprf1OSqer7tXPLdpsNN9cOc+y4/XpDD2RR1g42k4NeeW 76g68ZMI7MVJVqMfDYZDzmDIhz9N7XxjjCpHqddqiXXl1AP4YMce6Hq347CP3JYx04Kp B5eQ== 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=SWbblIxbViHW1c2Vo13iDKc9FEzKqha7oggCD077VLo=; b=cSdbhN3wwwrjf0lFqHIiX3j+ECfQjtHoluzt/gPvVkl0fsdnGKLOD2YHquwNmpwf9S zwCU5BGP/+sFlx16CfELil2PhJBTtXkbWurd0UljfB/qVSX5PjpxRGOYOXbMTEqWpf6H U8GZTWcWOwpMka6BiczD+R1tPDmV5EjnM596+a+SseAiT50Ih8uJYI+LiqxVJjoVaQnc dLgiIPLL5aVENQNR2wVIehxx0bYFodVO3bqVmUTdTMTWa5mZPk+tWi7ujlgBiJB1DoBe a/V3Y2wFUzH8wqYqNfE5S7RoUz3vg6h7Z7KFnAUx4SopjMWP0B5oBqujx6kkLZUqxdcl eohA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UpPvOt4J; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 76-20020a63064f000000b003fe19299386si9608457pgg.756.2022.06.13.06.07.49; Mon, 13 Jun 2022 06:08:02 -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=@linuxfoundation.org header.s=korg header.b=UpPvOt4J; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344931AbiFMKf3 (ORCPT + 99 others); Mon, 13 Jun 2022 06:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244206AbiFMKck (ORCPT ); Mon, 13 Jun 2022 06:32:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C14627CE4; Mon, 13 Jun 2022 03:21:50 -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 3290060AEB; Mon, 13 Jun 2022 10:21:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 399EFC34114; Mon, 13 Jun 2022 10:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115709; bh=l+AybNHC05BqQuQ3Dkj3uvVIIyZwvXV3Ggmj5WIMdqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpPvOt4JHAsSGHkN2EMhzMFGLbihYuLn4me17vzF/oACwJhuyymngL4dyKCMuPMqv 7/OY9hOB10HfdHnq5GytLY4epfRcjrJXU5kPsRCcJ51mm3zxdlWApzYBpqcAg2VsUC dwB7F33H2GDJGZ9QoLkaMlE+T11Z9sPIbMzJLxXY= 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 4.14 013/218] ACPICA: Avoid cache flush inside virtual machines Date: Mon, 13 Jun 2022 12:07:51 +0200 Message-Id: <20220613094911.494259234@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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=-8.3 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 1b010a859b8b..6de59a4f723c 100644 --- a/arch/x86/include/asm/acenv.h +++ b/arch/x86/include/asm/acenv.h @@ -16,7 +16,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