KVM: s390: fix guest fprs memory leak
Subsystems (3)
PATCH 1/2 KVM: s390: fix guest fprs memory leak
This is the backport of 9c7ebb613bff ("KVM: s390: fix guest fprs memory leak") for 4.4-stable.
fprs is never freed, therefore resulting in a memory leak if kvm_vcpu_init() fails or the vcpu is destroyed.
--- arch/s390/kvm/kvm-s390.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +4 -1
@@ -1202,6 +1202,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)if (vcpu->kvm->arch.use_cmma)kvm_s390_vcpu_unsetup_cmma (vcpu); +kfree (vcpu->arch.guest_fpregs.fprs);free_page ((unsigned long )(vcpu->arch.sie_block));kvm_vcpu_uninit (vcpu);
@@ -1516,12 +1517,14 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, rc =kvm_vcpu_init (vcpu, kvm, id);if (rc) - goto out_free_sie_block; + goto out_free_fprs;VM_EVENT (kvm,3 ,"create cpu %d at %p, sie block at %p" , id, vcpu, vcpu->arch.sie_block);trace_kvm_s390_create_vcpu (id, vcpu, vcpu->arch.sie_block);return vcpu; +out_free_fprs: +kfree (vcpu->arch.guest_fpregs.fprs); out_free_sie_block:free_page ((unsigned long )(vcpu->arch.sie_block)); out_free_cpu:
Signature · 1 line
2.3.9
PATCH 2/2 KVM: s390: fix memory overwrites when vx is disabled
This is the backport of 9abc2a08a7d6 (KVM: s390: fix memory overwrites when vx is disabled) for 4.4-stable.
The kernel now always uses vector registers when available, however KVM has special logic if support is really enabled for a guest. If support is disabled, guest_fpregs.fregs will only contain memory for the fpu. The kernel, however, will store vector registers into that area, resulting in crazy memory overwrites.
Simply extending that area is not enough, because the format of the registers also changes. We would have to do additional conversions, making the code even more complex. Therefore let's directly use one place for the vector/fpu registers + fpc (in kvm_run). We just have to convert the data properly when accessing it. This makes current code much easier.
Please note that vector/fpu registers are now always stored to vcpu->run->s.regs.vrs. Although this data is visible to QEMU and used for migration, we only guarantee valid values to user space when KVM_SYNC_VRS is set. As that is only the case when we have vector register support, we are on the safe side.
--- arch/s390/include/asm/kvm_host.h | 1 - arch/s390/kvm/kvm-s390.c | 128 +++++++++++++-------------------------- 2 files changed, 43 insertions(+), 86 deletions(-)
arch/s390/include/asm/kvm_host.h +0 -1
@@ -506,7 +506,6 @@ struct kvm_vcpu_arch {struct kvm_s390_sie_block *sie_block;unsigned int host_acrs[NUM_ACRS ];struct fpu host_fpregs; -struct fpu guest_fpregs;struct kvm_s390_local_interrupt local_int;struct hrtimer ckc_timer;struct kvm_s390_pgm_info pgm;
arch/s390/kvm/kvm-s390.c +43 -85
209 lines not on this page · raw message
Signature · 1 line
2.3.9
Greg KH
maintainerRe: [PATCH 2/2] KVM: s390: fix memory overwrites when vx is disabled
Quoted 2 lines · David Hildenbrand
This is the backport of
9abc2a08a7d6(KVM: s390: fix memory overwrites when vx is disabled) for 4.4-stable.
This backport didn't apply:
Applying kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch to linux-4.4.y Applying patch kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch patching file arch/s390/include/asm/kvm_host.h
patching file arch/s390/kvm/kvm-s390.c
Hunk #8 FAILED at 2246.
Hunk #9 FAILED at 2255.
2 out of 10 hunks FAILED -- rejects in file arch/s390/kvm/kvm-s390.c
Can you try it again?
thanks,
greg k-h
Re: [PATCH 2/2] KVM: s390: fix memory overwrites when vx is disabled
Quoted 14 lines · David Hildenbrand
Quoted 2 lines
This is the backport of
9abc2a08a7d6(KVM: s390: fix memory overwrites when vx is disabled) for 4.4-stable.This backport didn't apply:
Applying kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch to linux-4.4.y Applying patch kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch patching file
arch/s390/include/asm/kvm_host.h
patching filearch/s390/kvm/kvm-s390.c
Hunk #8 FAILED at 2246.
Hunk #9 FAILED at 2255.
2 out of 10 hunks FAILED -- rejects in filearch/s390/kvm/kvm-s390.c
Quoted 6 lines
Can you try it again?
thanks,
greg k-h
Hi Greg,
did you take care of the mentioned precondition?
# v4.4 d9a3a09af54d s390/kvm: remove dependency on struct save_area definition
But as I just received the mail saying this patch has been added to 4.4, I assume that this problems is solved :)
Thanks!
David
Greg KH
maintainerRe: [PATCH 2/2] KVM: s390: fix memory overwrites when vx is disabled
Quoted 18 lines · David Hildenbrand
Quoted 18 lines · David Hildenbrand
Quoted 2 lines
This is the backport of
9abc2a08a7d6(KVM: s390: fix memory overwrites when vx is disabled) for 4.4-stable.This backport didn't apply:
Applying kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch to linux-4.4.y Applying patch kvm-s390-fix-memory-overwrites-when-vx-is-disabled.patch patching file
arch/s390/include/asm/kvm_host.h
patching filearch/s390/kvm/kvm-s390.c
Hunk #8 FAILED at 2246.
Hunk #9 FAILED at 2255.
2 out of 10 hunks FAILED -- rejects in filearch/s390/kvm/kvm-s390.cCan you try it again?
thanks,
Quoted 8 lines
Quoted 2 lines
greg k-h
Hi Greg,
did you take care of the mentioned precondition?
# v4.4 d9a3a09af54d s390/kvm: remove dependency on struct save_area definition
I did not, I missed that as I assumed it was the previous patch here, sorry.
Quoted 2 lines
But as I just received the mail saying this patch has been added to 4.4, I assume that this problems is solved :)
No, that was a mistake, I then deleted it. But, I've added it again now and the dependency so all is fine, sorry for the noise.
greg k-h