mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "Hansen, Dave" <dave.hansen@intel.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"nik.borisov@suse.com" <nik.borisov@suse.com>
Cc: "Gao, Chao" <chao.gao@intel.com>,
	"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"binbin.wu@linux.intel.com" <binbin.wu@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Hunter, Adrian" <adrian.hunter@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>
Subject: Re: [PATCH v3 3/8] x86/virt/tdx: Prepare to support reading other global metadata fields
Date: Fri, 30 Aug 2024 11:09:31 +0000	[thread overview]
Message-ID: <fd965db365b08bd88179318bef30c5de15542699.camel@intel.com> (raw)
In-Reply-To: <de4e1842-1ca2-44aa-b028-359008b591fd@suse.com>


> > -static int read_sys_metadata_field16(u64 field_id, u16 *val)
> > +static int __read_sys_metadata_field(u64 field_id, void *val, int size)
> 
> The type of 'size' should be size_t.

OK will do.

> 
> >   {
> >   	u64 tmp;
> >   	int ret;
> >   
> > -	BUILD_BUG_ON(MD_FIELD_ID_ELE_SIZE_CODE(field_id) !=
> > -			MD_FIELD_ID_ELE_SIZE_16BIT);
> > -
> > -	ret = read_sys_metadata_field(field_id, &tmp);
> > +	ret = tdh_sys_rd(field_id, &tmp);
> >   	if (ret)
> >   		return ret;
> >   
> > -	*val = tmp;
> > +	memcpy(val, &tmp, size);
> >   
> >   	return 0;
> >   }
> >   
> > +/* Wrapper to read one global metadata to u8/u16/u32/u64 */
> > +#define read_sys_metadata_field(_field_id, _val)					\
> > +	({										\
> > +		BUILD_BUG_ON(MD_FIELD_ELE_SIZE(_field_id) != sizeof(typeof(*(_val))));	\
> > +		__read_sys_metadata_field(_field_id, _val, sizeof(typeof(*(_val))));	\
> > +	})
> > +
> >   /*
> > - * Assumes locally defined @ret and @sysinfo_tdmr to convey the error
> > - * code and the 'struct tdx_sys_info_tdmr' instance to fill out.
> > + * Read one global metadata field to a member of a structure instance,
> > + * assuming locally defined @ret to convey the error code.
> >    */
> > -#define TD_SYSINFO_MAP(_field_id, _member)						\
> > -	({										\
> > -		if (!ret)								\
> > -			ret = read_sys_metadata_field16(MD_FIELD_ID_##_field_id,	\
> > -					&sysinfo_tdmr->_member);			\
> > +#define TD_SYSINFO_MAP(_field_id, _stbuf, _member)				\
> > +	({									\
> > +		if (!ret)							\
> > +			ret = read_sys_metadata_field(MD_FIELD_ID_##_field_id,	\
> > +					&_stbuf->_member);			\
> >   	})
> >   
> >   static int get_tdx_sys_info_tdmr(struct tdx_sys_info_tdmr *sysinfo_tdmr)
> >   {
> >   	int ret = 0;
> >   
> > -	TD_SYSINFO_MAP(MAX_TDMRS,	      max_tdmrs);
> > -	TD_SYSINFO_MAP(MAX_RESERVED_PER_TDMR, max_reserved_per_tdmr);
> > -	TD_SYSINFO_MAP(PAMT_4K_ENTRY_SIZE,    pamt_entry_size[TDX_PS_4K]);
> > -	TD_SYSINFO_MAP(PAMT_2M_ENTRY_SIZE,    pamt_entry_size[TDX_PS_2M]);
> > -	TD_SYSINFO_MAP(PAMT_1G_ENTRY_SIZE,    pamt_entry_size[TDX_PS_1G]);
> > +#define TD_SYSINFO_MAP_TDMR_INFO(_field_id, _member)	\
> > +	TD_SYSINFO_MAP(_field_id, sysinfo_tdmr, _member)
> 
> nit: I guess its a personal preference but honestly I think the amount 
> of macro indirection (3 levels) here is crazy, despite each being rather 
> simple. Just use TD_SYSINFO_MAP directly, saving the typing of 
> "sysinfo_tdmr" doesn't seem like a big deal.

We have a different interpretation of "crazy" :-)

> 
> You can probably take it even a bit further and simply opencode 
> read_sys_metadata_field macro inside TD_SYSINFO_MAP and be left with 
> just it, no ? No other patch in this series uses read_sys_metadata_field 
> stand alone, if anything factoring it out could be deferred until the 
> first users gets introduced.

Joke aside, anyway, with what Adrian suggested we just need the
TD_SYSINFO_MAP() but don't need those wrappers anymore.  I'll go with this if
no one says differently.

> 
> > +
> > +	TD_SYSINFO_MAP_TDMR_INFO(MAX_TDMRS,	        max_tdmrs);
> > +	TD_SYSINFO_MAP_TDMR_INFO(MAX_RESERVED_PER_TDMR, max_reserved_per_tdmr);
> > +	TD_SYSINFO_MAP_TDMR_INFO(PAMT_4K_ENTRY_SIZE,    pamt_entry_size[TDX_PS_4K]);
> > +	TD_SYSINFO_MAP_TDMR_INFO(PAMT_2M_ENTRY_SIZE,    pamt_entry_size[TDX_PS_2M]);
> > +	TD_SYSINFO_MAP_TDMR_INFO(PAMT_1G_ENTRY_SIZE,    pamt_entry_size[TDX_PS_1G]);
> >   
> >   	return ret;
> >   }
> > diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
> > index 148f9b4d1140..7458f6717873 100644
> > --- a/arch/x86/virt/vmx/tdx/tdx.h
> > +++ b/arch/x86/virt/vmx/tdx/tdx.h
> > @@ -53,7 +53,8 @@
> >   #define MD_FIELD_ID_ELE_SIZE_CODE(_field_id)	\
> >   		(((_field_id) & GENMASK_ULL(33, 32)) >> 32)
> >   
> > -#define MD_FIELD_ID_ELE_SIZE_16BIT	1
> > +#define MD_FIELD_ELE_SIZE(_field_id)	\
> 
> That ELE seems a bit ambiguous, ELEM seems more natural and is in line 
> with other macros in the kernel.

OK will do.  Thanks for the review!



  reply	other threads:[~2024-08-30 11:09 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27  7:14 [PATCH v3 0/8] TDX host: metadata reading tweaks, bug fix and info dump Kai Huang
2024-08-27  7:14 ` [PATCH v3 1/8] x86/virt/tdx: Rename 'struct tdx_tdmr_sysinfo' to reflect the spec better Kai Huang
2024-08-27 13:10   ` Adrian Hunter
2024-08-27 22:20     ` Huang, Kai
2024-09-24 11:39       ` Huang, Kai
2024-08-30 22:05   ` Dan Williams
2024-08-27  7:14 ` [PATCH v3 2/8] x86/virt/tdx: Remove 'struct field_mapping' and implement TD_SYSINFO_MAP() macro Kai Huang
2024-08-29  7:20   ` Adrian Hunter
2024-08-30 10:52     ` Huang, Kai
2024-09-06 21:30     ` Dan Williams
2024-09-09  9:59       ` Huang, Kai
2024-09-06 20:21   ` Dan Williams
2024-09-09  9:59     ` Huang, Kai
2024-08-27  7:14 ` [PATCH v3 3/8] x86/virt/tdx: Prepare to support reading other global metadata fields Kai Huang
2024-08-30  6:43   ` Adrian Hunter
2024-08-30 11:02     ` Huang, Kai
2024-08-30  9:05   ` Nikolay Borisov
2024-08-30 11:09     ` Huang, Kai [this message]
2024-09-06 21:34   ` Dan Williams
2024-09-09 12:28     ` Huang, Kai
2024-08-27  7:14 ` [PATCH v3 4/8] x86/virt/tdx: Refine a comment to reflect the latest TDX spec Kai Huang
2024-08-30  6:45   ` Adrian Hunter
2024-08-30  9:14   ` Nikolay Borisov
2024-08-27  7:14 ` [PATCH v3 5/8] x86/virt/tdx: Start to track all global metadata in one structure Kai Huang
2024-08-30  7:02   ` Adrian Hunter
2024-08-30 11:10     ` Huang, Kai
2024-08-30 11:01   ` Nikolay Borisov
2024-08-30 11:57     ` Huang, Kai
2024-08-27  7:14 ` [PATCH v3 6/8] x86/virt/tdx: Print TDX module basic information Kai Huang
2024-09-06 22:46   ` Dan Williams
2024-09-09 10:18     ` Huang, Kai
2024-08-27  7:14 ` [PATCH v3 7/8] x86/virt/tdx: Reduce TDMR's reserved areas by using CMRs to find memory holes Kai Huang
2024-08-30 10:50   ` Adrian Hunter
2024-08-30 11:52     ` Huang, Kai
2024-08-30 12:02       ` Adrian Hunter
2024-08-30 12:27   ` Nikolay Borisov
2024-09-06 23:31   ` Dan Williams
2024-09-09 10:30     ` Huang, Kai
2024-08-27  7:14 ` [PATCH v3 8/8] x86/virt/tdx: Don't initialize module that doesn't support NO_RBP_MOD feature Kai Huang
2024-08-30 11:01   ` Adrian Hunter
2024-09-06 23:36   ` Dan Williams
2024-09-09 10:21     ` Huang, Kai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd965db365b08bd88179318bef30c5de15542699.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=chao.gao@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®