[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <19b612683cf190ab2eda55f83bee554e40c2233c.camel@intel.com>
Date: Mon, 12 Jun 2023 02:52:13 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
"Hansen, Dave" <dave.hansen@...el.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"Luck, Tony" <tony.luck@...el.com>,
"david@...hat.com" <david@...hat.com>,
"bagasdotme@...il.com" <bagasdotme@...il.com>,
"ak@...ux.intel.com" <ak@...ux.intel.com>,
"Wysocki, Rafael J" <rafael.j.wysocki@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"Chatre, Reinette" <reinette.chatre@...el.com>,
"Christopherson,, Sean" <seanjc@...gle.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"Yamahata, Isaku" <isaku.yamahata@...el.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"peterz@...radead.org" <peterz@...radead.org>,
"Shahar, Sagi" <sagis@...gle.com>,
"imammedo@...hat.com" <imammedo@...hat.com>,
"Gao, Chao" <chao.gao@...el.com>,
"Brown, Len" <len.brown@...el.com>,
"sathyanarayanan.kuppuswamy@...ux.intel.com"
<sathyanarayanan.kuppuswamy@...ux.intel.com>,
"Huang, Ying" <ying.huang@...el.com>,
"Williams, Dan J" <dan.j.williams@...el.com>
Subject: Re: [PATCH v11 12/20] x86/virt/tdx: Allocate and set up PAMTs for
TDMRs
On Thu, 2023-06-08 at 16:43 -0700, Dave Hansen wrote:
> On 6/8/23 16:24, kirill.shutemov@...ux.intel.com wrote:
> > > ret = -EINVAL;
> > > + if (ret)
> > > + tdmrs_free_pamt_all(&tdx_tdmr_list);
> > > + else
> > > + pr_info("%lu KBs allocated for PAMT.\n",
> > > + tdmrs_count_pamt_pages(&tdx_tdmr_list) * 4);
> > "* 4"? This is very cryptic. procfs uses "<< (PAGE_SHIFT - 10)" which
> > slightly less magic to me. And just make the helper that returns kilobytes
> > to begin with, if it is the only caller.
>
> Let's look at where this data comes from:
>
> +static unsigned long tdmrs_count_pamt_pages(struct tdmr_info_list
> *tdmr_list)
> +{
> + unsigned long pamt_npages = 0;
> + int i;
> +
> + for (i = 0; i < tdmr_list->nr_consumed_tdmrs; i++) {
> + unsigned long pfn, npages;
> +
> + tdmr_get_pamt(tdmr_entry(tdmr_list, i), &pfn, &npages);
> + pamt_npages += npages;
> + }
>
> OK, so tdmr_get_pamt() is getting it in pages. How is it *stored*?
>
> +static void tdmr_get_pamt(struct tdmr_info *tdmr, unsigned long *pamt_pfn,
> + unsigned long *pamt_npages)
> +{
> ...
> + pamt_sz = tdmr->pamt_4k_size + tdmr->pamt_2m_size + tdmr->pamt_1g_size;
> ++ *pamt_pfn = PHYS_PFN(pamt_base);
> + *pamt_npages = pamt_sz >> PAGE_SHIFT;
> +}
>
> Oh, it's actually stored in bytes. So to print it out you actually
> convert it from bytes->pages->kbytes. Not the best.
>
> If tdmr_get_pamt() just returned 'pamt_size_bytes', you could do one
> conversion at:
>
> free_contig_range(pamt_pfn, pamt_size_bytes >> PAGE_SIZE);
I thought making tdmr_get_pamt() return pamt_pfn and pamt_npages would be more
clear that PAMTs must be in 4K granularity, but I guess it doesn't matter
anyway.
If we return bytes for PAMT size, I think we should also return physical address
instead of PFN for PAMT start?
I'll change tdmr_get_pamt() to return physical address and bytes for PAMT
location and size respectively. Please let me know if you have any comments.
>
> and since tdmrs_count_pamt_pages() has only one caller you can just make
> it: tdmrs_count_pamt_kb(). The print becomes:
>
> pr_info("%lu KBs allocated for PAMT.\n",
> tdmrs_count_pamt_kb(&tdx_tdmr_list) * 4);
>
> and tdmrs_count_pamt_kb() does something super fancy like:
>
> return pamt_size_bytes / 1024;
>
> which makes total complete obvious sense and needs zero explanation.
Will do.
Thanks for the feedback.
Powered by blists - more mailing lists