lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1473d34591bafdebb7a4736ac08a83f6c447acf6.camel@intel.com>
Date:   Thu, 29 Jun 2023 01:03:29 +0000
From:   "Huang, Kai" <kai.huang@...el.com>
To:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "nik.borisov@...e.com" <nik.borisov@...e.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     "Raj, Ashok" <ashok.raj@...el.com>,
        "Hansen, Dave" <dave.hansen@...el.com>,
        "david@...hat.com" <david@...hat.com>,
        "bagasdotme@...il.com" <bagasdotme@...il.com>,
        "Luck, Tony" <tony.luck@...el.com>,
        "ak@...ux.intel.com" <ak@...ux.intel.com>,
        "Wysocki, Rafael J" <rafael.j.wysocki@...el.com>,
        "kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
        "Christopherson,, Sean" <seanjc@...gle.com>,
        "mingo@...hat.com" <mingo@...hat.com>,
        "pbonzini@...hat.com" <pbonzini@...hat.com>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "tglx@...utronix.de" <tglx@...utronix.de>,
        "Yamahata, Isaku" <isaku.yamahata@...el.com>,
        "Chatre, Reinette" <reinette.chatre@...el.com>,
        "hpa@...or.com" <hpa@...or.com>,
        "peterz@...radead.org" <peterz@...radead.org>,
        "Shahar, Sagi" <sagis@...gle.com>,
        "imammedo@...hat.com" <imammedo@...hat.com>,
        "bp@...en8.de" <bp@...en8.de>, "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>,
        "x86@...nel.org" <x86@...nel.org>,
        "Williams, Dan J" <dan.j.williams@...el.com>
Subject: Re: [PATCH v12 18/22] x86/virt/tdx: Keep TDMRs when module
 initialization is successful

On Wed, 2023-06-28 at 12:04 +0300, Nikolay Borisov wrote:
> 
> On 26.06.23 г. 17:12 ч., Kai Huang wrote:
> > On the platforms with the "partial write machine check" erratum, the
> > kexec() needs to convert all TDX private pages back to normal before
> > booting to the new kernel.  Otherwise, the new kernel may get unexpected
> > machine check.
> > 
> > There's no existing infrastructure to track TDX private pages.  Change
> > to keep TDMRs when module initialization is successful so that they can
> > be used to find PAMTs.
> > 
> > With this change, only put_online_mems() and freeing the buffer of the
> > TDSYSINFO_STRUCT and CMR array still need to be done even when module
> > initialization is successful.  Adjust the error handling to explicitly
> > do them when module initialization is successful and unconditionally
> > clean up the rest when initialization fails.
> > 
> > Signed-off-by: Kai Huang <kai.huang@...el.com>
> > ---
> > 
> > v11 -> v12 (new patch):
> >    - Defer keeping TDMRs logic to this patch for better review
> >    - Improved error handling logic (Nikolay/Kirill in patch 15)
> > 
> > ---
> >   arch/x86/virt/vmx/tdx/tdx.c | 84 ++++++++++++++++++-------------------
> >   1 file changed, 42 insertions(+), 42 deletions(-)
> > 
> > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> > index 52b7267ea226..85b24b2e9417 100644
> > --- a/arch/x86/virt/vmx/tdx/tdx.c
> > +++ b/arch/x86/virt/vmx/tdx/tdx.c
> > @@ -49,6 +49,8 @@ static DEFINE_MUTEX(tdx_module_lock);
> >   /* All TDX-usable memory regions.  Protected by mem_hotplug_lock. */
> >   static LIST_HEAD(tdx_memlist);
> >   
> > +static struct tdmr_info_list tdx_tdmr_list;
> > +
> >   /*
> >    * Wrapper of __seamcall() to convert SEAMCALL leaf function error code
> >    * to kernel error code.  @seamcall_ret and @out contain the SEAMCALL
> > @@ -1047,7 +1049,6 @@ static int init_tdmrs(struct tdmr_info_list *tdmr_list)
> >   static int init_tdx_module(void)
> >   {
> >   	struct tdsysinfo_struct *sysinfo;
> > -	struct tdmr_info_list tdmr_list;
> >   	struct cmr_info *cmr_array;
> >   	int ret;
> >   
> > @@ -1088,17 +1089,17 @@ static int init_tdx_module(void)
> >   		goto out_put_tdxmem;
> >   
> >   	/* Allocate enough space for constructing TDMRs */
> > -	ret = alloc_tdmr_list(&tdmr_list, sysinfo);
> > +	ret = alloc_tdmr_list(&tdx_tdmr_list, sysinfo);
> >   	if (ret)
> >   		goto out_free_tdxmem;
> >   
> >   	/* Cover all TDX-usable memory regions in TDMRs */
> > -	ret = construct_tdmrs(&tdx_memlist, &tdmr_list, sysinfo);
> > +	ret = construct_tdmrs(&tdx_memlist, &tdx_tdmr_list, sysinfo);
> 
> nit: Does it make sense to keep passing those global variables are 
> function parameters? Since those functions are static it's unlikely that 
> they are going to be used with any other parameter so might as well use 
> the parameter directly. It makes the code somewhat easier to follow.
> 

I disagree.  To me passing 'struct tdx_tdmr_info *tdmr_list' to
construct_tdmrs() as parameter makes this function clearer:

It takes all TDX memory blocks and sysinfo, generates the TDMRs, and stores them
to the buffer specified in the tdmr_list.  The internal logic doesn't need to
care whether any of of those parameters are static or not. 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ