Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1751919pxm; Thu, 24 Feb 2022 08:42:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxxAILqVyeSRNI0dN+jXU9d8EIMlPhviEx38L3f1OjntEyvY2zdK5lTSMY4KP8BD87gLRI X-Received: by 2002:a17:90a:a44:b0:1bc:275c:796e with SMTP id o62-20020a17090a0a4400b001bc275c796emr3631916pjo.3.1645720969402; Thu, 24 Feb 2022 08:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645720969; cv=none; d=google.com; s=arc-20160816; b=pXr4Ci1brdMBPXDuDz10TUZo8PAzaFnkG9iPfVlQfgFOW9BNaHRf/EF2O1Wmr/2fyx M+9wWzXretXCrTPhCzJlvF26P74geBT7/fGceExP64ksU6pmfS/kKKW5ihgmnH8DV5An 0GgPreUE5QnekQNv9Y5HioNMhx8ZsjJq8lWuOX9/n3F0S7U8V5XlVz4LiqL2NomxsrTl 0fJxgLZngZGXxg1RBrDNhW+TZUgClA4IQR00YuOk8QNz2D9Bb4thDnGDaoOKayFbzSo1 vXgtQw3aUFhBS6/kQZ/f/P3BA2o1n2/EDbFwHd1w/MAkMMBOf9R6LILmu9NP+cxfjgiF A3lQ== 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=pUt/FeY/aF81FHa7c08LpkB7+69FdUbpbipoHAouTqI=; b=rkl3gsD0x6G6HiX4AXu9DvVnQSA3HL4EoSteBjogLQawYJa5drjqWnZFqcYKE950VH 4E4zleqQvho7xbWecg3UWY8puRKnfEXFSEeKQeK8RQB6b6+UCtuk05I646AtBT2/H1DH mFe4FExjUQK6knNCXCNZDRHoOqTL/fbkMwEK/eid4nefwMMps6EWS4rFtBMXxBoNQN/p gxVrXfTiJ4Rz87FyDHmME3zgifDeBuWJchqJAFGtoaIMlr3p3SWJyxsDlvgoiVyH5FmX hpAjERdsU2QcJSmvA4IyoqYlrGjr3IXGnP5s9Z977QXvUVIVU1LmYcx12lq71N2T4RJ9 09Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lXuCa+iw; 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=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j190si2686589pge.526.2022.02.24.08.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:42:49 -0800 (PST) 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=@intel.com header.s=Intel header.b=lXuCa+iw; 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=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0C5E1AF8FE; Thu, 24 Feb 2022 08:22:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236859AbiBXP6W (ORCPT + 99 others); Thu, 24 Feb 2022 10:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236723AbiBXP5Q (ORCPT ); Thu, 24 Feb 2022 10:57:16 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1983422BC8 for ; Thu, 24 Feb 2022 07:56:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645718201; x=1677254201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aMt9dMQFnuWJAh9cVzkqMUEeYOnZHiNvm0HEf2p9qHU=; b=lXuCa+iwUVti7N3VDEAB9CS6A1zl4MUIdYHZdwssyjhGO/Xox1UGHF6D 0sgbUD6VHmm8WIa+zIfzo2426FN5fIAgMB9s3JhWBifYallPs+XRyvICs ewAogf3nJTsXYQ1pDDRUdDg5MaNfgD1fAXi2uMiajoc2YUcxvk7ucazKM xzh3DWv83QDRK2DngM2F5A6x4l1BlxIuKS9uYwc3M1PAu+OgmRgjxneHi EOJ2ToiPq1jUnpKo6GDfEiYMkfVL7+43UuMlbQUtDLWE89On95DgGZ4Wb uMlQFkJGkREG+nThCYoxB2XkssUUQp5XeN2Ptxhv6sZRpb/aCvXNGcMLn w==; X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="312983041" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="312983041" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 07:56:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="506362116" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 24 Feb 2022 07:56:32 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id B1E38C7E; Thu, 24 Feb 2022 17:56:35 +0200 (EET) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv4 29/30] ACPICA: Avoid cache flush on TDX guest Date: Thu, 24 Feb 2022 18:56:29 +0300 Message-Id: <20220224155630.52734-30-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> References: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 ACPI_FLUSH_CPU_CACHE() flushes caches on entering sleep states. It is required to prevent data loss. While running inside TDX guest, 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. The approach can be generalized to all guest kernels, but, to be cautious, let's limit it to TDX for now. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/acenv.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/acenv.h b/arch/x86/include/asm/acenv.h index 9aff97f0de7f..d19deca6dd27 100644 --- a/arch/x86/include/asm/acenv.h +++ b/arch/x86/include/asm/acenv.h @@ -13,7 +13,21 @@ /* 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 TDX guest, 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. + * + * TODO: Is it safe to generalize this from TDX guests to all guest kernels? + */ +#define ACPI_FLUSH_CPU_CACHE() \ +do { \ + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) \ + wbinvd(); \ +} while (0) int __acpi_acquire_global_lock(unsigned int *lock); int __acpi_release_global_lock(unsigned int *lock); -- 2.34.1