On 5/27/26 11:48, Xiaoyao Li wrote:
> On 5/14/2026 4:47 AM, Peter Xu wrote:
>> On Mon, May 04, 2026 at 04:30:19PM +0400, Marc-André Lureau wrote:
>>> In TDX guests, virtio-mem plug/unplug/re-plug fails because
>>> kvm_set_phys_mem() unconditionally sets KVM memory attributes to
>>> PRIVATE for all guest_memfd regions. On re-plug, the PRIVATE->PRIVATE
>>> transition is a no-op, so KVM doesn't re-AUG pages and the guest's
>>> TDG.MEM.PAGE.ACCEPT fails.
>>
>> Know little on TDX, please bare with me..
>>
>> I saw KVM does a seamcall to ADD or AUG whenever a new EPT pte is set, via
>> this path:
>>
>>          __tdp_mmu_set_spte_atomic
>>          set_external_spte_present
>>          tdx_sept_set_private_spte <------
>>
>> On unplug, I'm expecting with your prior patches, gmem pages will be
>> truncated properly, so they'll be all gone.
>>
>> Then, qemu does replug -> guest gets that event, start access page -> EPT
>> violation, KVM resolving page fault with __tdp_mmu_set_spte_atomic() (per
>> above) and a new page -> triggering AUG (not ADD, since it's post-boot).
>>
>> Could you elaborate here why AUG is missing in the first place?
> 
> Peter, you analysis is correct.
> 
> The reason why plug -> unplug -> re-plug fails, is QEMU fails to discard the
> private memory so that KVM doesn't zap the private mapping. When re-plug and
> guest re-accepts, KVM doesn't get involved. Not discard the private memory on
> unplug leads to another issue that the private memory is still accessible to 
> the
> guest.
> 
> But patch 11 fixes this. Patch 11 should be enough and we don't need this 
> patch.
> For guest kernel side, we need to ensure the guest kernel accepts the new
> plugged memory, and no "start-shared" trick is required.
> 
> BTW, "start-shared" memory for coco is not something good. It violates the
> contract that all the memory for Coco VM is initial private (accepted or
> unaccepted) from EFI spec. We probably should avoid introducing exception 
> unless
> we have to.
> 

Sorry, I have to double check: you are saying we do not need this patch, and
instead the guest has to do the right thing after plugging memory?

-- 
Cheers,

David

Reply via email to