From patchwork Fri May 31 08:52:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2640931 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 153BF4020A for ; Fri, 31 May 2013 08:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754566Ab3EaIwf (ORCPT ); Fri, 31 May 2013 04:52:35 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:44724 "EHLO e28smtp07.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754539Ab3EaIwb (ORCPT ); Fri, 31 May 2013 04:52:31 -0400 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 31 May 2013 14:16:13 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 31 May 2013 14:16:11 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 90BB7394004E for ; Fri, 31 May 2013 14:22:25 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4V8qFa356688870 for ; Fri, 31 May 2013 14:22:16 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4V8qM6E017938 for ; Fri, 31 May 2013 18:52:23 +1000 Received: from localhost.localdomain (dhcp-9-111-29-91.cn.ibm.com [9.111.29.91]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r4V8qIuo017775; Fri, 31 May 2013 18:52:19 +1000 Message-ID: <51A864C2.8090904@linux.vnet.ibm.com> Date: Fri, 31 May 2013 16:52:18 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Paolo Bonzini CC: Jordan Justen , qemu-devel , "Justen, Jordan L" , Luiz Capitulino , Gleb Natapov , KVM Subject: [PATCH uq/master] fix double free the memslot in kvm_set_phys_mem References: <20130530114604.4b12cb22@redhat.com> <51A77838.4060707@redhat.com> <20130530120832.5abe1c65@redhat.com> <51A8485A.4000605@linux.vnet.ibm.com> <51A85DE8.2090600@redhat.com> In-Reply-To: <51A85DE8.2090600@redhat.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13053108-8878-0000-0000-0000075540C9 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Luiz Capitulino reported that guest refused to boot and qemu complained with: kvm_set_phys_mem: error unregistering overlapping slot: Invalid argument It is caused by commit 235e8982ad that did double free for the memslot so that the second one raises the -EINVAL error Fix it by reset memory size only if it is needed Reported-by: Luiz Capitulino Signed-off-by: Xiao Guangrong Reviewed-by: Paolo Bonzini Tested-by: Luiz Capitulino Tested-by: Richard W.M. Jones Reviewed-by: Jordan Justen --- kvm-all.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 8e7bbf8..405480e 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -206,7 +206,8 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot) if (s->migration_log) { mem.flags |= KVM_MEM_LOG_DIRTY_PAGES; } - if (mem.flags & KVM_MEM_READONLY) { + + if (slot->memory_size && mem.flags & KVM_MEM_READONLY) { /* Set the slot size to 0 before setting the slot to the desired * value. This is needed based on KVM commit 75d61fbc. */ mem.memory_size = 0;