Re: [PATCH v4 6/7] KVM: SEV: Perform RMP optimizations on SNP guest shutdown

From: Kalra, Ashish

Date: Tue May 05 2026 - 16:34:38 EST


Hello Ackerley,

On 5/1/2026 2:12 PM, Ackerley Tng wrote:
> Ashish Kalra <Ashish.Kalra@xxxxxxx> writes:
>
>>
>> [...snip...]
>>
>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
>> index 3f9c1aa39a0a..e0f4f8ebef68 100644
>> --- a/arch/x86/kvm/svm/sev.c
>> +++ b/arch/x86/kvm/svm/sev.c
>> @@ -2942,6 +2942,8 @@ void sev_vm_destroy(struct kvm *kvm)
>> if (sev_snp_guest(kvm)) {
>> snp_guest_req_cleanup(kvm);
>>
>> + snp_rmpopt_all_physmem();
>> +
>
> I see this is what you suggested in [1]. The time-based batching you
> suggeested works because adding to the workqueue when there's already a
> job just does nothing. Thanks!
>
> I think optimizing when the VM is destroyed makes sense, in most cases
> for SNP VMs, we don't expect large 1G blocks of memory to be shared
> anyway, so even if we try to RMPOPT on every conversion to private, most
> of those tries would be optimizing nothing.
>

Yes.

Thanks,
Ashish

> I guess the remaining optimization would be to update based on only the
> range of pfns where guest_memfd has private memory, but that could be
> done in another patch series.
>
> Reviewed-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
>
> [1] https://lore.kernel.org/all/31040bb7-653a-40f9-8899-40bc852f7e1f@xxxxxxx/
>
>> /*
>> * Decomission handles unbinding of the ASID. If it fails for
>> * some unexpected reason, just leak the ASID.
>> --
>> 2.43.0