public inbox for kvm@vger.kernel.org
 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>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>
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 2/8] x86/virt/tdx: Remove 'struct field_mapping' and implement TD_SYSINFO_MAP() macro
Date: Mon, 9 Sep 2024 09:59:16 +0000	[thread overview]
Message-ID: <2921b03e0e0f3d0e03b8cc705f0953a67da37526.camel@intel.com> (raw)
In-Reply-To: <66db6465cd956_22a22943d@dwillia2-xfh.jf.intel.com.notmuch>

On Fri, 2024-09-06 at 13:21 -0700, Dan Williams wrote:
> I think the subject buries the lead on what this patch does which is
> more like:
> 
> x86/virt/tdx: Rework TD_SYSINFO_MAP to support build-time verification

Yes this looks better.  Thanks.

> 
> Kai Huang wrote:
> > TL;DR: Remove the 'struct field_mapping' structure and use another way
> 
> I would drop the TL;DR: and just make the changelog more concise,
> because as it stands now it requires the reader to fully appreciate the
> direction of the v1 approach which this new proposal abandons:
> 
> Something like:
> 
>     Dan noticed [1] that read_sys_metadata_field16() has a runtime warning
>     to validate that the metadata field size matches the passed in buffer
>     size. In turns out that all the information to perform that validation
>     is available at build time. Rework TD_SYSINFO_MAP() to stop providing
>     runtime data to read_sys_metadata_field16() and instead just pass typed
>     fields to read_sys_metadata_field16() and let the compiler catch any
>     mismatches.
>     
>     The new TD_SYSINFO_MAP() has a couple quirks for readability.  It
>     requires the function that uses it to define a local variable @ret to
>     carry the error code and set the initial value to 0.  It also hard-codes
>     the variable name of the structure pointer used in the function, but it
>     is less code, build-time verfiable, and the same readability as the
>     former 'struct field_mapping' approach.
>     
>     Link: http://lore.kernel.org/66b16121c48f4_4fc729424@dwillia2-xfh.jf.intel.com.notmuch [1]

Thanks.  Will do.

Btw, Adrian suggested to rename TD_SYSINFO_MAP() to READ_SYS_INFO(), which is
reasonable to me, so I will also add "rename TD_SYSINFO_MAP() to
READ_SYS_INFO()" to your above text.  Please let know if you have any comments.

> 
> [..]
> > Link: https://lore.kernel.org/kvm/a107b067-861d-43f4-86b5-29271cb93dad@intel.com/T/#m7cfb3c146214d94b24e978eeb8708d92c0b14ac6 [1]
> 
> The expectation for lore links is to capture the message-id. Note the
> differences with the "Link:" format above.

Oh I did not know this.  What's the difference between message-id and a normal
link that I got by "google <patch name> + open that lore link"?

> 
> > v2 -> v3:
> >  - Remove 'struct field_mapping' and reimplement TD_SYSINFO_MAP().
> > 
> > ---
> >  arch/x86/virt/vmx/tdx/tdx.c | 57 ++++++++++++++-----------------------
> >  1 file changed, 21 insertions(+), 36 deletions(-)
> > 
> > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> > index e979bf442929..7e75c1b10838 100644
> > --- a/arch/x86/virt/vmx/tdx/tdx.c
> > +++ b/arch/x86/virt/vmx/tdx/tdx.c
> > @@ -270,60 +270,45 @@ static int read_sys_metadata_field(u64 field_id, u64 *data)
> >  	return 0;
> >  }
> >  
> > -static int read_sys_metadata_field16(u64 field_id,
> > -				     int offset,
> > -				     struct tdx_sys_info_tdmr *ts)
> > +static int read_sys_metadata_field16(u64 field_id, u16 *val)
> >  {
> > -	u16 *ts_member = ((void *)ts) + offset;
> >  	u64 tmp;
> >  	int ret;
> >  
> > -	if (WARN_ON_ONCE(MD_FIELD_ID_ELE_SIZE_CODE(field_id) !=
> > -			MD_FIELD_ID_ELE_SIZE_16BIT))
> > -		return -EINVAL;
> > +	BUILD_BUG_ON(MD_FIELD_ID_ELE_SIZE_CODE(field_id) !=
> > +			MD_FIELD_ID_ELE_SIZE_16BIT);
> 
> Perhaps just move this to TD_SYSINFO_MAP() directly?

Sure will do.  It gets moved to TD_SYSINFO_MAP() in the next patch anyway.

> 
> Something like:
> 
> #define TD_SYSINFO_MAP(_field_id, _member, _size)					\
> 	({										\
> 		BUILD_BUG_ON(MD_FIELD_ID_ELE_SIZE_CODE(field_id) !=			\
> 				MD_FIELD_ID_ELE_SIZE_##_size##BIT);			\
> 		if (!ret)								\
> 			ret = read_sys_metadata_field##_size(MD_FIELD_ID_##_field_id,	\
> 					&sysinfo_tdmr->_member);			\
> 	})

Will do.

Btw this patch doesn't extend to support other sizes but only 16-bits, so I'll
defer the support of "_size" to the next patch.

  reply	other threads:[~2024-09-09  9:59 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 [this message]
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
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=2921b03e0e0f3d0e03b8cc705f0953a67da37526.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=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