Re: [PATCH v8 13/13] KVM: s390: Fix cleanup in kvm_s390_pv_create_cpu()

From: Janosch Frank

Date: Mon Aug 03 2026 - 12:38:02 EST


On 8/3/26 14:40, Claudio Imbrenda wrote:
If creating a protected vCPU in kvm_s390_pv_create_cpu() fails,
kvm_s390_pv_destroy_cpu() was called, which checks whether the vCPU has
a PV handle and exits doing nothing otherwise. At that point, due to
not having created the protected vCPU, the PV handle will not be set,
and kvm_s390_pv_destroy_cpu() will do nothing, thus leaking the
allocated memory.

There are times when the creation fails and we still get a handle to destroy the cpu again. But you're describing the case where the destroy bit and handle are not set so that's fine.


Fix by factoring out the code to free and reset a PV vCPU; call it from
kvm_s390_pv_destroy_cpu() and kvm_s390_pv_create_cpu().

Opportunistically fix the return value of kvm_s390_pv_destroy_cpu() in
case of errors: return -EIO instead if EIO.

Fixes: d4074324b07a ("KVM: s390: pv: avoid double free of sida page")
Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>
Reviewed-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>

Reviewed-by: Janosch Frank <frankja@xxxxxxxxxxxxx>