[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e58349f3-fa36-4635-9b2b-9ff8f2d88038@intel.com>
Date: Tue, 10 Sep 2024 14:15:02 +0300
From: Adrian Hunter <adrian.hunter@...el.com>
To: Paolo Bonzini <pbonzini@...hat.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>, seanjc@...gle.com,
kvm@...r.kernel.org
Cc: kai.huang@...el.com, dmatlack@...gle.com, isaku.yamahata@...il.com,
yan.y.zhao@...el.com, nik.borisov@...e.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 20/21] KVM: TDX: Finalize VM initialization
On 10/09/24 13:33, Paolo Bonzini wrote:
> On 9/4/24 17:37, Adrian Hunter wrote:
>> Isaku was going to lock the mmu. Seems like the change got lost.
>> To protect against racing with KVM_PRE_FAULT_MEMORY,
>> KVM_TDX_INIT_MEM_REGION, tdx_sept_set_private_spte() etc
>> e.g. Rename tdx_td_finalizemr to __tdx_td_finalizemr and add:
>>
>> static int tdx_td_finalizemr(struct kvm *kvm, struct kvm_tdx_cmd *cmd)
>> {
>> int ret;
>>
>> write_lock(&kvm->mmu_lock);
>> ret = __tdx_td_finalizemr(kvm, cmd);
>> write_unlock(&kvm->mmu_lock);
>>
>> return ret;
>> }
>
> kvm->slots_lock is better. In tdx_vcpu_init_mem_region() you can take it before the is_td_finalized() so that there is a lock that is clearly protecting kvm_tdx->finalized between the two. (I also suggest switching to guard() in tdx_vcpu_init_mem_region()).
Doesn't KVM_PRE_FAULT_MEMORY also need to be protected?
>
> Also, I think that in patch 16 (whether merged or not) nr_premapped should not be incremented, once kvm_tdx->finalized has been set?
tdx_sept_set_private_spte() checks is_td_finalized() to decide
whether to call tdx_mem_page_aug() or tdx_mem_page_record_premap_cnt()
Refer patch 14 "KVM: TDX: Implement hooks to propagate changes
of TDP MMU mirror page table" for the addition of
tdx_sept_set_private_spte()
Powered by blists - more mailing lists