From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B4B0C54EBE for ; Tue, 10 Jan 2023 19:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239665AbjAJTMe (ORCPT ); Tue, 10 Jan 2023 14:12:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239820AbjAJTMZ (ORCPT ); Tue, 10 Jan 2023 14:12:25 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 296364F103; Tue, 10 Jan 2023 11:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673377936; x=1704913936; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=idaSyTc/ks4CE89dkqypMQwFMcAUjyVafAw9EG5/p1Y=; b=SPHSRtPLj9bckQDAopi8zfmjK/c9fRfTq/9QBKhgv5Nj/8vEJJ3vOMA6 Dtd/IbuMDHfo2avI92Vf0Dmdla/FrqeejBhTDr+7ByjzkrRWh3PfcmM6v 0dA1eOf4utWkLgGd50JRMOiJUhkAJmDHbYvEoA0+Dk3f3NlPjxmP5njvf G9koVM5i9dUgPfGx+SfwwJRCg92lwXNNNZ7Rldu2jT4uXXE0EgKwJwAJa y1TkOP4IbVZOBGyhkKeKoh/lfz+rJoOxm+ZHjV79z2+P3IFzJ7Dqcwd43 09in4hRLWEKwTMe11Jx2InohKllfz5Arj7Tn4+mvKA5D9awKkY+fKUP93 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="350458233" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="350458233" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 11:12:14 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="607086563" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="607086563" Received: from svenka7-mobl1.amr.corp.intel.com (HELO [10.209.63.27]) ([10.209.63.27]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 11:12:13 -0800 Message-ID: <56cdb6e6-e25c-aba9-7bb3-323281e65249@intel.com> Date: Tue, 10 Jan 2023 11:12:13 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v8 08/16] x86/virt/tdx: Add placeholder to construct TDMRs to cover all TDX memory regions Content-Language: en-US To: "Huang, Kai" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: "Luck, Tony" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "kirill.shutemov@linux.intel.com" , "Christopherson,, Sean" , "Chatre, Reinette" , "pbonzini@redhat.com" , "linux-mm@kvack.org" , "Yamahata, Isaku" , "tglx@linutronix.de" , "Shahar, Sagi" , "imammedo@redhat.com" , "Gao, Chao" , "Brown, Len" , "peterz@infradead.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" References: <81b814f096513e69e3099ab2b54034deadf8d7fd.camel@intel.com> <92aba287-c839-8841-a9f7-28a2c0b3097a@intel.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 1/9/23 18:23, Huang, Kai wrote: > On Mon, 2023-01-09 at 16:47 -0800, Dave Hansen wrote: >> On 1/9/23 16:40, Huang, Kai wrote: >>> On Fri, 2023-01-06 at 11:24 -0800, Dave Hansen wrote: >> ... >>>> Also, tdmr_sz and max_tdmrs can both be derived from 'sysinfo'. Do they >>>> really need to be stored here? >>> >>> It's not mandatory to keep them here. I did it mainly because I want to avoid >>> passing 'sysinfo' as argument for almost all functions related to constructing >>> TDMRs. >> >> I don't think it hurts readability that much. On the contrary, it makes >> it more clear what data is needed for initialization. > > Sorry one thing I forgot to mention is if we keep 'tdmr_sz' in 'struct > tdmr_info_list', it only needs to be calculated at once when allocating the > buffer. Otherwise, we need to calculate it based on sysinfo- > max_reserved_per_tdmr each time we want to get a TDMR at a given index. What's the problem with recalculating it? It is calculated like this: tdmr_sz = ALIGN(constant1 + constant2 * variable); So, what's the problem? You're concerned about too many multiplications? > To me putting relevant fields (tdmrs, tdmr_sz, max_tdmrs, nr_consumed_tdmrs) > together makes how the TDMR list is organized more clear. But please let me > know if you prefer removing 'tdmr_sz' and 'max_tdmrs'. > > Btw, if we remove 'tdmr_sz' and 'max_tdmrs', even nr_consumed_tdmrs is not > absolutely necessary here. It can be a local variable of init_tdx_module() (as > shown in v7), and the 'struct tdmr_info_list' will only have the 'tdmrs' member > (as you commented in v7): > > https://lore.kernel.org/linux-mm/cc195eb6499cf021b4ce2e937200571915bfe66f.camel@intel.com/T/#mb9826e2bcf8bf6399c13cc5f95a948fe4b3a46d9 > > Please let me know what's your preference? I dunno. My gut says that passing sysinfo around and just deriving the sizes values from that with helpers is the best way. 'struct tdmr_info_list' isn't a horrible idea in and of itself, but I think it's a confusing structure because it's not clear how the pieces fit together when half of it is *required* and the other half is just for some kind of perceived convenience.