Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1294968rwd; Thu, 8 Jun 2023 15:51:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4llh7JO8Kxp7NY08mM/bsWZio/u/XcJeZQn6lLZFJrQqToIgSlHdY0h48BSchRe+FpWJqQ X-Received: by 2002:a17:902:edc2:b0:1b1:a2c3:29c0 with SMTP id q2-20020a170902edc200b001b1a2c329c0mr5798821plk.24.1686264666690; Thu, 08 Jun 2023 15:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686264666; cv=none; d=google.com; s=arc-20160816; b=xR7KieHjj61ZkFqTOgeJ15+sgocP9OaKxXNUQ+JA1w2etkyNoQft0Gxk1XUNxC33Rl dTjGnklFeExn979M2CcMmumR1DsM5gb2PwmtNkasltCp1tVUTpapNxLfZSvV0d4dAJ8C dnaFpyEHyIA2SpV5CDvJs+4N8lZj+lSRrKlCTEOSuD3ZtdNSqWKM1uTGbG5wwImToA97 lXkR3tlaBHxqJkinPa9PurqO5RyV0SEZdWCx078I2PBEgkqw6saeBVNIo180qYgUZn8R P7fAWHYnjLKS+lBj/kEuxPp+nmkgR47Zq/7vn1hmjg5l3oedcHfYoRO+4Rjx2bx6wut5 1RgQ== 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=EOsm2MwiOHSdVaG2w8eE4V4EjIcvyWW9dgXoHxRbE0I=; b=Dnxv1SwyKJ6NwzfdkFEMAwcg4hbPHicf0C7fiz3tzpFPoZsH0XPtUm+RzH4TJOVHp9 3PNPvNagJSk/MFc9Xy17hPnLvjVH9G6AkkXcV4rc7QxXSTPXPXhkKH6rnWu7O/8Ih1YN RMBAyItiFRMhjJhiEwk/NMqtFejujmQRuARfcsLiFAAs43Q6+1J3r4yM0oNrCNNt/Wkj j7GQ5jIPbzJEWodXS2N27RsQy/AZ1Ujw2bur7C+rusnathjcIKIM57oDVHNQasxSq2L/ yqGXeASU4BR2ddEKTi0kRLQGLSO+kyuR4+lR+CMdCW8x6mlyP+mtRxp3/cVdUL4knnRc OfxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=akyy+RFi; 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 lk8-20020a17090308c800b001b042e93c11si1658305plb.262.2023.06.08.15.50.54; Thu, 08 Jun 2023 15:51:06 -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=akyy+RFi; 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 S234505AbjFHWlH (ORCPT + 99 others); Thu, 8 Jun 2023 18:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjFHWlF (ORCPT ); Thu, 8 Jun 2023 18:41:05 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E28A2D42; Thu, 8 Jun 2023 15:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686264064; x=1717800064; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=HWH/BChFipfANutgTqAIw2nFszN1k9sN0DS13QIpLeQ=; b=akyy+RFim9+mtE5bfROSFyn6QK/j9BKBDmBRhRowT7dskFtoOeXsmuq9 sA7ekxMXeiLarN4UyloXkI7O/jS9GSz98LdGHZbFT6Gc0GqL1VJuF9HzE mVg6Bk/6b2ZbegCKVAGTNL8M9S/Wt+dt6KUQOBfaHLuePxpC4XWYTJhwB 5brOVs5XubiXoBkRvaBempLK8T9x7FbAq1fgrI1oihHqfBJmMumgl9ILO fiA/E2oTnkz3ctWB26gtwRsskzcCIsrOA21selV0fOby82/D5v4AWZzwV m3ZtpJZMk+cE6r043+26WFoVGxVjrcVUCtvhfsA0dWvXD5z3n0bceC9sF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="421040869" X-IronPort-AV: E=Sophos;i="6.00,227,1681196400"; d="scan'208";a="421040869" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 15:41:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="775264650" X-IronPort-AV: E=Sophos;i="6.00,227,1681196400"; d="scan'208";a="775264650" Received: from fgorter-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.59.89]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 15:40:58 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 0BC00104C0F; Fri, 9 Jun 2023 01:40:56 +0300 (+03) Date: Fri, 9 Jun 2023 01:40:56 +0300 From: kirill.shutemov@linux.intel.com To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, dave.hansen@intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v11 09/20] x86/virt/tdx: Use all system memory when initializing TDX module as TDX memory Message-ID: <20230608224056.2j524gnkrdjtirti@box> References: <468533166590ff5ed11730350c4af8cdb0b99165.1685887183.git.kai.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <468533166590ff5ed11730350c4af8cdb0b99165.1685887183.git.kai.huang@intel.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Mon, Jun 05, 2023 at 02:27:22AM +1200, Kai Huang wrote: > As a step of initializing the TDX module, the kernel needs to tell the > TDX module which memory regions can be used by the TDX module as TDX > guest memory. > > TDX reports a list of "Convertible Memory Region" (CMR) to tell the > kernel which memory is TDX compatible. The kernel needs to build a list > of memory regions (out of CMRs) as "TDX-usable" memory and pass them to > the TDX module. Once this is done, those "TDX-usable" memory regions > are fixed during module's lifetime. > > To keep things simple, assume that all TDX-protected memory will come > from the page allocator. Make sure all pages in the page allocator > *are* TDX-usable memory. > > As TDX-usable memory is a fixed configuration, take a snapshot of the > memory configuration from memblocks at the time of module initialization > (memblocks are modified on memory hotplug). This snapshot is used to > enable TDX support for *this* memory configuration only. Use a memory > hotplug notifier to ensure that no other RAM can be added outside of > this configuration. > > This approach requires all memblock memory regions at the time of module > initialization to be TDX convertible memory to work, otherwise module > initialization will fail in a later SEAMCALL when passing those regions > to the module. This approach works when all boot-time "system RAM" is > TDX convertible memory, and no non-TDX-convertible memory is hot-added > to the core-mm before module initialization. > > For instance, on the first generation of TDX machines, both CXL memory > and NVDIMM are not TDX convertible memory. Using kmem driver to hot-add > any CXL memory or NVDIMM to the core-mm before module initialization > will result in failure to initialize the module. The SEAMCALL error > code will be available in the dmesg to help user to understand the > failure. > > Signed-off-by: Kai Huang > Reviewed-by: "Huang, Ying" > Reviewed-by: Isaku Yamahata Reviewed-by: Kirill A. Shutemov -- Kiryl Shutsemau / Kirill A. Shutemov