Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19148696rwd; Wed, 28 Jun 2023 05:52:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ENeuzMF1qod4JRTpocryhIOK83yhj7vkLrIYdtmgxarhllOfqNqaAUgYesrJy2hVpFWSq X-Received: by 2002:a17:907:75ea:b0:991:d5ad:f1a7 with SMTP id jz10-20020a17090775ea00b00991d5adf1a7mr6021906ejc.51.1687956722012; Wed, 28 Jun 2023 05:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687956721; cv=none; d=google.com; s=arc-20160816; b=jjzs4yvBID027urI0kJ/3s8O20ePM6CpXn5oGs9uI61ncelDKZSk6L9TbAxXj75fK8 ElePQfIL1uABO87nYZNlKqmgYVXSbQXdu/7U800BIfW8wl0XQpHSODwsPr1+qMyuJ8Ov Mn+aR5PpGAS2D8AAMOFCFDosCZfre6mFDWmXQoPLE9jIITmr4tnZXv3sbc3ZsK3fjowC K0vnEHZvDjPu5RIeBR0d2GsmYJVTGeQyIWQ+eDc0ZMedNCJc1Jf7IW/NyeiDdk9lJbR0 JYolqyTQ0AhqACj/y6JD8ZkqvuxADagG+8pgoC/m2t1poIxiN9jBCjIJcPcnvFHJYw/7 WhzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=T68PK/B00rfTRMrkC72ab7DQ6gdYUqTPcN3zzhtG7eg=; fh=U3TJmJHrqmoyVzdr5WTQxA/qFKy1nY/GQSZ6ivpgig8=; b=Rx73o09NZytYm5fP2wHEaJN9m5Lj3z6BgIa0p6mNPWfR6zrHJS/tOe3SbodjJLAIFS ajHL9w1SGuODccraKu07QcZd9WCRz0N2oFLB2RZwjybP7hJsSdp8kfomAgMH3KOGEhIp PysQjwkXCJdzE81glSov1LeQxUJhT5wOnGLObs0e30O8Pd5aSoSWsZ/514PUV/DODwkp gcpi84wC9RHR4BkNpMOyv06AU9oxKg1OCwEKJzGU+LsicD0xKz9M66oxS9e/el5FPDtE ahabU+YdU0xMQ8pPcBhy6AbnrKjwnDmbMf5Ce8742cjBUec1oib+cbrnnxigxC82QFQx NOSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FHJM0pns; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a170906474900b0099257ea4ef6si1173165ejs.726.2023.06.28.05.51.38; Wed, 28 Jun 2023 05:52:01 -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=@intel.com header.s=Intel header.b=FHJM0pns; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjF1MaJ (ORCPT + 99 others); Wed, 28 Jun 2023 08:30:09 -0400 Received: from mga09.intel.com ([134.134.136.24]:1966 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbjF1MaI (ORCPT ); Wed, 28 Jun 2023 08:30:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687955408; x=1719491408; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=SAzJtHLtNMNNef0gGslBTtW/PqahrrYxc8mh0SENA4Y=; b=FHJM0pnspdOa8To96VAnSckyu73wYxa2020s5WKltzL/6f5ghCiBX9XE Dl8ISw5qUDaoa3hpOii/5MSE4C6TIQBc/GeuRuT98C/T50b+1xIGRazDI FBBXWj80sEx0e1Nq74WE0cKJ2IPDlCoihzPLSRYNkYf028tYZAd8662Ol YOTCkl4bK3S4qebGX7lC47Vy3zKSYorc9t3QxI1YvlCFWdDK11VpLBdrF ndM63LrS3rC40hLGL/lFzVuqvAygPs/kUNehckL70TpYoOsEJPTg6Enqp JYoPAxzVxVxAvHG3xr5uoceNL+0atNFq7qa0vLfQgY5at2Eo6sTW5rR5K A==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="364380459" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="364380459" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 05:30:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="720229784" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="720229784" Received: from rajritu-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.47.187]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 05:30:00 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id E19531095C8; Wed, 28 Jun 2023 15:29:57 +0300 (+03) Date: Wed, 28 Jun 2023 15:29:57 +0300 From: kirill.shutemov@linux.intel.com To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v12 19/22] x86/kexec(): Reset TDX private memory on platforms with TDX erratum Message-ID: <20230628122957.sl7wzenjby3o2xsw@box.shutemov.name> References: <28aece770321e307d58df77eddee2d3fa851d15a.1687784645.git.kai.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28aece770321e307d58df77eddee2d3fa851d15a.1687784645.git.kai.huang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 02:12:49AM +1200, Kai Huang wrote: > @@ -1113,6 +1115,17 @@ static int init_tdx_module(void) > */ > wbinvd_on_all_cpus(); > > + /* > + * Starting from this point the system may have TDX private > + * memory. Make it globally visible so tdx_reset_memory() only > + * reads TDMRs/PAMTs when they are stable. > + * > + * Note using atomic_inc_return() to provide the explicit memory > + * ordering isn't mandatory here as the WBINVD above already > + * does that. Compiler barrier isn't needed here either. > + */ > + atomic_inc_return(&tdx_may_has_private_mem); Why do we need atomics at all here? Writers seems serialized with tdx_module_lock and reader accesses the variable when all CPUs, but one is down and cannot race. Hm? -- Kiryl Shutsemau / Kirill A. Shutemov