Re: [PATCH 19/21] KVM: TDX: Add an ioctl to create initial guest memory
From: Edgecombe, Rick P
Date: Wed Sep 04 2024 - 10:02:52 EST
On Wed, 2024-09-04 at 12:53 +0800, Yan Zhao wrote:
> > + if (!kvm_mem_is_private(kvm, gfn)) {
> > + ret = -EFAULT;
> > + goto out_put_page;
> > + }
> > +
> > + ret = kvm_tdp_map_page(vcpu, gpa, error_code, &level);
> > + if (ret < 0)
> > + goto out_put_page;
> > +
> > + read_lock(&kvm->mmu_lock);
> Although mirrored root can't be zapped with shared lock currently, is it
> better to hold write_lock() here?
>
> It should bring no extra overhead in a normal condition when the
> tdx_gmem_post_populate() is called.
I think we should hold the weakest lock we can. Otherwise someday someone could
run into it and think the write_lock() is required. It will add confusion.
What was the benefit of a write lock? Just in case we got it wrong?