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

Janosch Frank <[email protected]> Mon, 3 Aug 2026 17:06:50 +0200
Newsgroups org.kernel.vger.linux-s390,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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 <[email protected]>
> Reviewed-by: Steffen Eiden <[email protected]>

Reviewed-by: Janosch Frank <[email protected]>