[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fbebd02d5ee0121811903ed1dd669d3c6ec84689.camel@intel.com>
Date: Tue, 27 Jun 2023 11:46:11 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"Williams, Dan J" <dan.j.williams@...el.com>,
"Raj, Ashok" <ashok.raj@...el.com>,
"Luck, Tony" <tony.luck@...el.com>,
"david@...hat.com" <david@...hat.com>,
"bagasdotme@...il.com" <bagasdotme@...il.com>,
"Hansen, Dave" <dave.hansen@...el.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>,
"mingo@...hat.com" <mingo@...hat.com>,
"Yamahata, Isaku" <isaku.yamahata@...el.com>,
"nik.borisov@...e.com" <nik.borisov@...e.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"hpa@...or.com" <hpa@...or.com>,
"peterz@...radead.org" <peterz@...radead.org>,
"imammedo@...hat.com" <imammedo@...hat.com>,
"Shahar, Sagi" <sagis@...gle.com>, "bp@...en8.de" <bp@...en8.de>,
"Brown, Len" <len.brown@...el.com>,
"Gao, Chao" <chao.gao@...el.com>,
"sathyanarayanan.kuppuswamy@...ux.intel.com"
<sathyanarayanan.kuppuswamy@...ux.intel.com>,
"Huang, Ying" <ying.huang@...el.com>,
"x86@...nel.org" <x86@...nel.org>
Subject: Re: [PATCH v12 08/22] x86/virt/tdx: Get information about TDX module
and TDX-capable memory
On Tue, 2023-06-27 at 14:37 +0300, kirill.shutemov@...ux.intel.com wrote:
> On Tue, Jun 27, 2023 at 10:45:33AM +0000, Huang, Kai wrote:
> > On Tue, 2023-06-27 at 12:51 +0300, kirill.shutemov@...ux.intel.com wrote:
> > > On Tue, Jun 27, 2023 at 02:12:38AM +1200, Kai Huang wrote:
> > > > static int init_tdx_module(void)
> > > > {
> > > > + struct tdsysinfo_struct *sysinfo;
> > > > + struct cmr_info *cmr_array;
> > > > + int ret;
> > > > +
> > > > + /*
> > > > + * Get the TDSYSINFO_STRUCT and CMRs from the TDX module.
> > > > + *
> > > > + * The buffers of the TDSYSINFO_STRUCT and the CMR array passed
> > > > + * to the TDX module must be 1024-bytes and 512-bytes aligned
> > > > + * respectively. Allocate one page to accommodate them both and
> > > > + * also meet those alignment requirements.
> > > > + */
> > > > + sysinfo = (struct tdsysinfo_struct *)__get_free_page(GFP_KERNEL);
> > > > + if (!sysinfo)
> > > > + return -ENOMEM;
> > > > + cmr_array = (struct cmr_info *)((unsigned long)sysinfo + PAGE_SIZE / 2);
> > > > +
> > > > + BUILD_BUG_ON(PAGE_SIZE / 2 < TDSYSINFO_STRUCT_SIZE);
> > > > + BUILD_BUG_ON(PAGE_SIZE / 2 < sizeof(struct cmr_info) * MAX_CMRS);
> > >
> > > This works, but why not just use slab for this? kmalloc has 512 and 1024
> > > pools already and you won't waste memory for rounding up.
> > >
> > > Something like this:
> > >
> > > sysinfo = kmalloc(TDSYSINFO_STRUCT_SIZE, GFP_KERNEL);
> > > if (!sysinfo)
> > > return -ENOMEM;
> > >
> > > cmr_array_size = sizeof(struct cmr_info) * MAX_CMRS;
> > >
> > > /* CMR array has to be 512-aligned */
> > > cmr_array_size = round_up(cmr_array_size, 512);
> >
> > Should we define a macro for 512
> >
> > +#define CMR_INFO_ARRAY_ALIGNMENT 512
> >
> > And get rid of this comment? AFAICT Dave didn't like such comment mentioning
> > 512-bytes aligned if we have a macro for that.
>
> Good idea.
>
> > > cmr_array = kmalloc(cmr_array_size, GFP_KERNEL);
> > > if (!cmr_array) {
> > > kfree(sysinfo);
> > > return -ENOMEM;
> > > }
> > >
> > > ?
> > >
> >
> > I confess the reason I used __get_free_page() was to avoid having to allocate
> > twice, and in case of failure, I need to handle additional memory free. But I
> > can do if you think it's clearer?
>
> Less trickery is always cleaner. Especially if the trick is not justified.
>
>
Alright. I'll change to allocating them separately if no opinion from others.
Powered by blists - more mailing lists