From patchwork Mon Mar 20 16:13:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 741072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vn1H619YVz9s3l for ; Tue, 21 Mar 2017 03:14:26 +1100 (AEDT) Received: from localhost ([::1]:33880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzwt-0000GK-ME for incoming@patchwork.ozlabs.org; Mon, 20 Mar 2017 12:14:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzwM-0000Dp-L2 for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpzwJ-0004lI-IR for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54858) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpzwJ-0004kp-AK for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63AED80462; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63AED80462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 63AED80462 Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2966AE4B82; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9C4B6113864D; Mon, 20 Mar 2017 17:13:44 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 17:13:44 +0100 Message-Id: <1490026424-11330-3-git-send-email-armbru@redhat.com> In-Reply-To: <1490026424-11330-1-git-send-email-armbru@redhat.com> References: <1490026424-11330-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 20 Mar 2017 16:13:47 +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 for-2.9 2/2] Revert "hostmem: fix QEMU crash by 'info memdev'" 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: Xiao Guangrong , ehabkost@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , imammedo@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This reverts commit 1454d33f0507cb54d62ed80f494884157c9e7130. The string input visitor regression fixed in the previous commit made visit_type_uint16List() fail on empty input. query_memdev() calls it via object_property_get_uint16List(). Because it doesn't expect it to fail, it passes &error_abort, and duly crashes. Commit 1454d33 "fixes" this crash by making host_memory_backend_get_host_nodes() return a list containing just MAX_NODES instead of the empty list. Papers over the regression, and leads to bogus "info memdev" output, as shown below; revert. I suspect that if we had bisected the crash back then, we would have found and fixed the actual bug instead of papering over it. To reproduce, run HMP command "info memdev" with $ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -object memory-backend-ram,id=mem1,size=4k With this commit, "info memdev" prints memory backend: mem1 size: 4096 merge: true dump: true prealloc: false policy: default host nodes: exactly like before commit 74f24cb. Between commit 1454d33 and this commit, it prints memory backend: mem1 size: 4096 merge: true dump: true prealloc: false policy: default host nodes: 128 The last line is bogus. Between commit 74f24cb and 1454d33, it crashes like this: Unexpected error in parse_str() at /work/armbru/tmp/qemu/qapi/string-input-visitor.c:126: Parameter 'null' expects an int64 value or range Aborted (core dumped) Cc: Xiao Guangrong Cc: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Michael Roth --- backends/hostmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 162c218..89feb9e 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -64,14 +64,6 @@ out: error_propagate(errp, local_err); } -static uint16List **host_memory_append_node(uint16List **node, - unsigned long value) -{ - *node = g_malloc0(sizeof(**node)); - (*node)->value = value; - return &(*node)->next; -} - static void host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -82,23 +74,25 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, unsigned long value; value = find_first_bit(backend->host_nodes, MAX_NODES); - - node = host_memory_append_node(node, value); - if (value == MAX_NODES) { - goto out; + return; } + *node = g_malloc0(sizeof(**node)); + (*node)->value = value; + node = &(*node)->next; + do { value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1); if (value == MAX_NODES) { break; } - node = host_memory_append_node(node, value); + *node = g_malloc0(sizeof(**node)); + (*node)->value = value; + node = &(*node)->next; } while (true); -out: visit_type_uint16List(v, name, &host_nodes, errp); }