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: <20240327225657.GG2444378@ls.amr.corp.intel.com>
Date: Wed, 27 Mar 2024 15:56:57 -0700
From: Isaku Yamahata <isaku.yamahata@...el.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>
Cc: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"Yamahata, Isaku" <isaku.yamahata@...el.com>,
	"Zhang, Tina" <tina.zhang@...el.com>,
	"seanjc@...gle.com" <seanjc@...gle.com>,
	"Yuan, Hang" <hang.yuan@...el.com>,
	"Huang, Kai" <kai.huang@...el.com>, "Chen, Bo2" <chen.bo@...el.com>,
	"sagis@...gle.com" <sagis@...gle.com>,
	"isaku.yamahata@...il.com" <isaku.yamahata@...il.com>,
	"Aktas, Erdem" <erdemaktas@...gle.com>,
	"pbonzini@...hat.com" <pbonzini@...hat.com>,
	"sean.j.christopherson@...el.com" <sean.j.christopherson@...el.com>,
	isaku.yamahata@...ux.intel.com
Subject: Re: [PATCH v19 044/130] KVM: TDX: Do TDX specific vcpu initialization

On Wed, Mar 27, 2024 at 12:27:03AM +0000,
"Edgecombe, Rick P" <rick.p.edgecombe@...el.com> wrote:

> On Mon, 2024-02-26 at 00:25 -0800, isaku.yamahata@...el.com wrote:
> > +/* VMM can pass one 64bit auxiliary data to vcpu via RCX for guest BIOS. */
> > +static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx)
> > +{
> > +       struct kvm_tdx *kvm_tdx = to_kvm_tdx(vcpu->kvm);
> > +       struct vcpu_tdx *tdx = to_tdx(vcpu);
> > +       unsigned long *tdvpx_pa = NULL;
> > +       unsigned long tdvpr_pa;
> 
> 
> I think we could drop theselocal variables and just use tdx->tdvpr_pa and tdx->tdvpx_pa. Then we
> don't have to have the assignments later.

Yes, let me clean it up. The old version acquired spin lock in the middle. Now
we don't have it.


> > +       unsigned long va;
> > +       int ret, i;
> > +       u64 err;
> > +
> > +       if (is_td_vcpu_created(tdx))
> > +               return -EINVAL;
> > +
> > +       /*
> > +        * vcpu_free method frees allocated pages.  Avoid partial setup so
> > +        * that the method can't handle it.
> > +        */
> > +       va = __get_free_page(GFP_KERNEL_ACCOUNT);
> > +       if (!va)
> > +               return -ENOMEM;
> > +       tdvpr_pa = __pa(va);
> > +
> > +       tdvpx_pa = kcalloc(tdx_info->nr_tdvpx_pages, sizeof(*tdx->tdvpx_pa),
> > +                          GFP_KERNEL_ACCOUNT);
> > +       if (!tdvpx_pa) {
> > +               ret = -ENOMEM;
> > +               goto free_tdvpr;
> > +       }
> > +       for (i = 0; i < tdx_info->nr_tdvpx_pages; i++) {
> > +               va = __get_free_page(GFP_KERNEL_ACCOUNT);
> > +               if (!va) {
> > +                       ret = -ENOMEM;
> > +                       goto free_tdvpx;
> > +               }
> > +               tdvpx_pa[i] = __pa(va);
> > +       }
> > +
> > +       err = tdh_vp_create(kvm_tdx->tdr_pa, tdvpr_pa);
> > +       if (KVM_BUG_ON(err, vcpu->kvm)) {
> > +               ret = -EIO;
> > +               pr_tdx_error(TDH_VP_CREATE, err, NULL);
> > +               goto free_tdvpx;
> > +       }
> > +       tdx->tdvpr_pa = tdvpr_pa;
> > +
> > +       tdx->tdvpx_pa = tdvpx_pa;
> 
> Or alternatively let's move these to right before they are used. (in the current branch 
> 
> > +       for (i = 0; i < tdx_info->nr_tdvpx_pages; i++) {
> > +               err = tdh_vp_addcx(tdx->tdvpr_pa, tdvpx_pa[i]);
> > +               if (KVM_BUG_ON(err, vcpu->kvm)) {
> > +                       pr_tdx_error(TDH_VP_ADDCX, err, NULL);
> > +                       for (; i < tdx_info->nr_tdvpx_pages; i++) {
> > +                               free_page((unsigned long)__va(tdvpx_pa[i]));
> > +                               tdvpx_pa[i] = 0;
> > +                       }
> > +                       /* vcpu_free method frees TDVPX and TDR donated to TDX */
> > +                       return -EIO;
> > +               }
> > +       }
> > 
> > 
> In the current branch tdh_vp_init() takes struct vcpu_tdx, so they would be moved right here.
> 
> What do you think?

Yes, I should revise the error recovery path.
-- 
Isaku Yamahata <isaku.yamahata@...el.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ