From nobody Wed Nov 5 13:50:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497021482199597.7448920443185; Fri, 9 Jun 2017 08:18:02 -0700 (PDT) Received: from localhost ([::1]:55306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJLfj-00022C-0O for importer@patchew.org; Fri, 09 Jun 2017 11:17:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJLes-0001TZ-9s for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:17:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJLem-00055V-Vx for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:17:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dJLem-00054r-N5 for qemu-devel@nongnu.org; Fri, 09 Jun 2017 11:17:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E421C04B927; Fri, 9 Jun 2017 15:16:56 +0000 (UTC) Received: from localhost (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7826118843; Fri, 9 Jun 2017 15:16:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7E421C04B927 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7E421C04B927 From: Stefan Hajnoczi To: Date: Fri, 9 Jun 2017 16:16:15 +0100 Message-Id: <20170609151615.2589-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 09 Jun 2017 15:16:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] hw/i386: fix nvdimm check error path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Eduardo Habkost , "Michael S. Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit e987c37aee1752177906847630d32477da57e705 ("hw/i386: check if nvdimm is enabled before plugging") introduced a check to reject nvdimm hotplug if -machine pc,nvdimm=3Don was not given. This check executes after pc_dimm_memory_plug() has already completed and does not reverse the effect of this function in the case of failure. Perform the check before calling pc_dimm_memory_plug(). This fixes the following abort: $ qemu -M accel=3Dkvm -m 1G,slots=3D4,maxmem=3D8G \ -object memory-backend-file,id=3Dmem1,share=3Don,mem-path=3Dnvdimm= .dat,size=3D1G (qemu) device_add nvdimm,memdev=3Dmem1 nvdimm is not enabled: missing 'nvdimm' in '-M' (qemu) device_add nvdimm,memdev=3Dmem1 Core dumped The backtrace is: #0 0x00007fffdb5b191f in raise () at /lib64/libc.so.6 #1 0x00007fffdb5b351a in abort () at /lib64/libc.so.6 #2 0x00007fffdb5a9da7 in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007fffdb5a9e52 in () at /lib64/libc.so.6 #4 0x000055555577a5fa in qemu_ram_set_idstr (new_block=3D0x555556747a00,= name=3D, dev=3Ddev@entry=3D0x555556705590) at qemu/exec.c:1= 709 #5 0x0000555555a0fe86 in vmstate_register_ram (mr=3Dmr@entry=3D0x5555567= 3a0e0, dev=3Ddev@entry=3D0x555556705590) at migration/savevm.c:2293 #6 0x0000555555965088 in pc_dimm_memory_plug (dev=3Ddev@entry=3D0x555556= 705590, hpms=3Dhpms@entry=3D0x5555566bb0e0, mr=3Dmr@entry=3D0x555556705630,= align=3D, errp=3Derrp@entry=3D0x7fffffffc660) at hw/mem/pc-dimm.c:110 #7 0x000055555581d89b in pc_dimm_plug (errp=3D0x7fffffffc6c0, dev=3D0x55= 5556705590, hotplug_dev=3D) at qemu/hw/i386/pc.c:1713 #8 0x000055555581d89b in pc_machine_device_plug_cb (hotplug_dev=3D, dev=3D0x555556705590, errp=3D0x7fffffffc6c0) at qemu/hw/i386/pc.= c:2004 #9 0x0000555555914da6 in device_set_realized (obj=3D, val= ue=3D, errp=3D0x7fffffffc7e8) at hw/core/qdev.c:926 Cc: Haozhong Zhang Signed-off-by: Stefan Hajnoczi Reviewed-by: Eduardo Habkost Reviewed-by: Haozhong Zhang --- hw/i386/pc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5b8c6fb..db41cca 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1692,6 +1692,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm); uint64_t align =3D TARGET_PAGE_SIZE; + bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); =20 if (memory_region_get_alignment(mr) && pcmc->enforce_aligned_dimm) { align =3D memory_region_get_alignment(mr); @@ -1703,17 +1704,18 @@ static void pc_dimm_plug(HotplugHandler *hotplug_de= v, goto out; } =20 + if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) { + error_setg(&local_err, + "nvdimm is not enabled: missing 'nvdimm' in '-M'"); + goto out; + } + pc_dimm_memory_plug(dev, &pcms->hotplug_memory, mr, align, &local_err); if (local_err) { goto out; } =20 - if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) { - if (!pcms->acpi_nvdimm_state.is_enabled) { - error_setg(&local_err, - "nvdimm is not enabled: missing 'nvdimm' in '-M'"); - goto out; - } + if (is_nvdimm) { nvdimm_plug(&pcms->acpi_nvdimm_state); } =20 --=20 2.9.4