From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484603; cv=none; d=zohomail.com; s=zohoarc; b=e8XUoxdBfEBwIGDO8hj5j9RhQKECZWHqtFF6sS1MIow49e9+/MpIaQaCK+2EKfhGMCtBqMFSecjivcillnDqjHb8ZMyA9vYQ7nsT2WwZ/dzVuRNUV6QMQNKibuzpU1kJ6iYdbTe5tGYvtCoesiid+JBbBCg7XhhfDjjBE6WdNew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484603; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=t9PkhQUDB8JuhjSbOPN2bvdjEcF2wLsH4GMRziMp5uI=; b=FLBaT1BALLu6bNaETiPxc2AktK6TI6D0GPiTPs58WPL/Wn7nMOQZg8zyNLCH5lsW2qGMSLhjlYAQmvDkU3gSuIoazCpCkrt8eSkMXAcNbdBAjWGfDhHfDhRKJiFwMpGWKGcmdu/t5zP32LicliyDgGtkhgdfQLmBI93t9jNjyOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601484603702844.2320873567251; Wed, 30 Sep 2020 09:50:03 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-J2G64uhNNAOR2vsFm758AQ-1; Wed, 30 Sep 2020 12:49:58 -0400 Received: by mail-wm1-f69.google.com with SMTP id x6so68634wmi.1 for ; Wed, 30 Sep 2020 09:49:58 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id m18sm4062428wmg.32.2020.09.30.09.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:49:56 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t9PkhQUDB8JuhjSbOPN2bvdjEcF2wLsH4GMRziMp5uI=; b=DST5CtS7FNfqAR8CPPijDa3fTArg0gsJPi9rmU+CYAlNHi96xW3nUL3IEaX0Okq1Rl7uKM snDg80W9E+zPfnINj+1R84CyfJKEVRUvQl0G5e4kqxvpnHpuYKmNNu3AsflvLMotExu48j uEQN3TGOJdgsCnVmoVIvsvg8NqVRmOs= X-MC-Unique: J2G64uhNNAOR2vsFm758AQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t9PkhQUDB8JuhjSbOPN2bvdjEcF2wLsH4GMRziMp5uI=; b=lOClFscOWdB8w/UkzLyH/8JZQG1y47YtrD7l4lrxMvu055M+V80ruYDVzGDpzIheDR aQEH4yVwgBXUQ/b9i6vhJibzAFR19Zv6Z1YflBbtAOP4/aXTue4W5DUkyGAB2HBDjpuf G5cTGTka5iVpJWDU+v6rK7rz0Q0rA+JQF2aN8s+AXGJqfSHPZuChRjXtFKmvssyTWKk8 USGcBLJ88Lxz85qsgKsQHgUcZdxkejuZJwjIfjSljjjqhLj7g0Ogb2w4kdzvWbushaig AeNaqCzGpjT1NeLMF3LiYLBOHWAqigjJ+YoGDr7+v2f1F9UayYym5vLQMp5KQB/EumIq I0Og== X-Gm-Message-State: AOAM5305+tAk5k90Awr2oBE9PepXxZNFlZRGLMgoK3JK11ajPfQBNJF3 RNBlOqi8JV+8iIfta3+IdwilO41SkHIT27sFEAoKkfXl1mivavMNPDluLkrnCB6GTfwgf5tv+Wf jdzq01jQ8OjoNJA== X-Received: by 2002:a7b:cb07:: with SMTP id u7mr3874747wmj.57.1601484597005; Wed, 30 Sep 2020 09:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr+ox58eHgr/ILmlGB8SkqVhKIHFrE3cjygC8QQU/qJFwgMJvYj8KmrspHkiXM219VdOR7Bw== X-Received: by 2002:a7b:cb07:: with SMTP id u7mr3874713wmj.57.1601484596741; Wed, 30 Sep 2020 09:49:56 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Date: Wed, 30 Sep 2020 18:49:39 +0200 Message-Id: <20200930164949.1425294-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) In commit f68c01470b we restricted the query-uuid command to machine code, but it is incorrect, as it is also used by the tools. Therefore move this command again, but to block.json, which is shared by machine code and tools. Fixes: f68c01470b ("qapi: Restrict query-uuid command to machine code") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- qapi/block.json | 30 ++++++++++++++++++++++++++++++ qapi/machine.json | 30 ------------------------------ block/iscsi.c | 2 +- stubs/uuid.c | 2 +- stubs/meson.build | 4 +++- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/qapi/block.json b/qapi/block.json index a009f7d3a2..4ae1716b56 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -11,6 +11,36 @@ # =3D=3D Additional block stuff (VM related) ## =20 +## +# @UuidInfo: +# +# Guest UUID information (Universally Unique Identifier). +# +# @UUID: the UUID of the guest +# +# Since: 0.14.0 +# +# Notes: If no UUID was specified for the guest, a null UUID is returned. +## +{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} } + +## +# @query-uuid: +# +# Query the guest UUID information. +# +# Returns: The @UuidInfo for the guest +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-uuid" } +# <- { "return": { "UUID": "550e8400-e29b-41d4-a716-446655440000" } } +# +## +{ 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true } + ## # @BiosAtaTranslation: # diff --git a/qapi/machine.json b/qapi/machine.json index 756dacb06f..72f014bb5b 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -402,36 +402,6 @@ ## { 'command': 'query-target', 'returns': 'TargetInfo' } =20 -## -# @UuidInfo: -# -# Guest UUID information (Universally Unique Identifier). -# -# @UUID: the UUID of the guest -# -# Since: 0.14.0 -# -# Notes: If no UUID was specified for the guest, a null UUID is returned. -## -{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} } - -## -# @query-uuid: -# -# Query the guest UUID information. -# -# Returns: The @UuidInfo for the guest -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-uuid" } -# <- { "return": { "UUID": "550e8400-e29b-41d4-a716-446655440000" } } -# -## -{ 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true } - ## # @GuidInfo: # diff --git a/block/iscsi.c b/block/iscsi.c index e30a7e3606..1effea25ed 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -42,7 +42,7 @@ #include "qemu/uuid.h" #include "sysemu/replay.h" #include "qapi/error.h" -#include "qapi/qapi-commands-machine.h" +#include "qapi/qapi-commands-block.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" #include "crypto/secret.h" diff --git a/stubs/uuid.c b/stubs/uuid.c index e5112eb3f6..d6bfb442e0 100644 --- a/stubs/uuid.c +++ b/stubs/uuid.c @@ -1,5 +1,5 @@ #include "qemu/osdep.h" -#include "qapi/qapi-commands-machine.h" +#include "qapi/qapi-commands-block.h" #include "qemu/uuid.h" =20 UuidInfo *qmp_query_uuid(Error **errp) diff --git a/stubs/meson.build b/stubs/meson.build index e0b322bc28..2e231590e1 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -39,7 +39,9 @@ stub_ss.add(files('target-get-monitor-def.c')) stub_ss.add(files('target-monitor-defs.c')) stub_ss.add(files('tpm.c')) stub_ss.add(files('trace-control.c')) -stub_ss.add(files('uuid.c')) +if have_block + stub_ss.add(files('uuid.c')) +endif stub_ss.add(files('vmgenid.c')) stub_ss.add(files('vmstate.c')) stub_ss.add(files('vm-stop.c')) --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484612; cv=none; d=zohomail.com; s=zohoarc; b=P2M4rXg/qG+yz7PTGpXD2XP095tIQz9oflnBt7KzuQkWuqRyVtvJC+Bp7otX170HLotjQ5qtE6LNnKubRcNQmL2SSMbQoMKqnyXe3DFChk+9KIoHna+AntlEVnjept+M4xseuYJO3rQsum6uHRFO0gQmyyZgek9YYtr754i5LTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484612; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Dl78dpgTJZ8P1IU2c4DK1V5IhL26LnKDU3IyXovKRpw=; b=Eb+atIBDPomjSEpQshvBS8P60HGWU1z3dVZ4UnUU/zDTbf9aeSSqa/B6IkfeN0FGRjCfxef7+3xmZaZTazcroqmTFDBfrwt5aQ6yWVFLjmJCxdLyjndOVcrUWJLxWoh5GFh0k4mwAJvKD77wYnT7mPmxHiedZRWy5eEf15iVA/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484612032148.94301349218904; Wed, 30 Sep 2020 09:50:12 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-VdY1RcgeNuuKbYGSH5uhlw-1; Wed, 30 Sep 2020 12:50:03 -0400 Received: by mail-wm1-f70.google.com with SMTP id y6so56430wmi.7 for ; Wed, 30 Sep 2020 09:50:03 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id u12sm4001266wrt.81.2020.09.30.09.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dl78dpgTJZ8P1IU2c4DK1V5IhL26LnKDU3IyXovKRpw=; b=OeFGm3fSxNBhdNujQB7wfgG/Tpd0RYxZcDoDpfrpO6GGnmqBsALYEzFGmV4xAEtaQZZRrc 7ZAFZOS/gMvG6wOCm5npz7jr8Pjz5Om4i6VWuzxFOqGRfS+qRCCnAbGm1WQ+17P55IRi5K 1D/5gp3ZuS4WMU9CQ4tiI/ZP28SxHmc= X-MC-Unique: VdY1RcgeNuuKbYGSH5uhlw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dl78dpgTJZ8P1IU2c4DK1V5IhL26LnKDU3IyXovKRpw=; b=niBZTHxx4Gu+cDi9kCSq4bctolqNWaZaHGGO42ueUnl2Lb8lgo5bmCdwNBbyrBqZvE UfzzkTZif8ms+Z+nu/mJBHZZ4ZEbS38xlC+xC4s4dNHhwSrGT0Ivrzcku+wQPpNAxN7a RODFjKWcsF35NqTpSGQzf9AJxlULJPMZfuHlyio0bx4CEuMOakP5+91AMk6pxqDUm+Yl Bu5fGGypNH9XIQ34zK21gfbUO6cbA7nQ1z0u3GhgwTCulggaIyG8SQxAek4XWo/xEghX VHjNmLd8ZiRFFi6cAUCEf9TFi+GjhRU+PAym9eBJuKoCkTunFNaVmKAiiHz/Ramvyivn od+A== X-Gm-Message-State: AOAM532jSeRp1tZU5ve55lNk9v9csvfUhXnBzK3jw01e+QqIrmx9jbGU 2OUraRHtWznalForOuA54nUQYVBCnIF/zjx3X1DRs95/Lwpr6Z/Ij0SzecINKGCYJR4k0l3Y85f E5MvY3qHowKRkGw== X-Received: by 2002:adf:e989:: with SMTP id h9mr4427116wrm.38.1601484602505; Wed, 30 Sep 2020 09:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt+AAkhoSapD0U322SGxeUJSceXYggA4RujouPo6flOPJ8NY2arJl7TWHL+kJM6S21FBhBtQ== X-Received: by 2002:adf:e989:: with SMTP id h9mr4427080wrm.38.1601484602158; Wed, 30 Sep 2020 09:50:02 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 02/11] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler Date: Wed, 30 Sep 2020 18:49:40 +0200 Message-Id: <20200930164949.1425294-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The MACAddr structure contains an array of uint8_t. Previously if a value was out of the [0..255] range, it was silently casted and no input validation was done. Replace strtol() by qemu_strtol() -- so checkpatch.pl won't complain if we move this code later -- and return EINVAL if the input is invalid. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- hw/core/qdev-properties.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 343c824da0..080ba319a1 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "net/net.h" #include "hw/qdev-properties.h" #include "qapi/error.h" @@ -524,7 +525,8 @@ static void set_mac(Object *obj, Visitor *v, const char= *name, void *opaque, Property *prop =3D opaque; MACAddr *mac =3D qdev_get_prop_ptr(dev, prop); int i, pos; - char *str, *p; + char *str; + const char *p; =20 if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); @@ -536,6 +538,8 @@ static void set_mac(Object *obj, Visitor *v, const char= *name, void *opaque, } =20 for (i =3D 0, pos =3D 0; i < 6; i++, pos +=3D 3) { + long val; + if (!qemu_isxdigit(str[pos])) { goto inval; } @@ -551,7 +555,10 @@ static void set_mac(Object *obj, Visitor *v, const cha= r *name, void *opaque, goto inval; } } - mac->a[i] =3D strtol(str+pos, &p, 16); + if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) { + goto inval; + } + mac->a[i] =3D val; } g_free(str); return; --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484612; cv=none; d=zohomail.com; s=zohoarc; b=If39HEnsklnmT7l/XulshMDDFQhN0mWioUXvAKB/WAi/J653gYAsEcJw4hDp/FSz1OHAyVfT0b77V6d3Nt8qXkMcsV87DbXUiuKFlbWlJGYsRsYVkkQCPWypVvpIOS6Zhipr8/zpVs5AXAKs19AlLpFwDFAwahtAbrREGONlEaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484612; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=AEjJONFrTBimyHKi2i/2D3r46cwVifpdF+Aae2zJhkU=; b=Te7kWwCfogIjA1cbw00Bg8fdnylL9HlMge/VMoJ3cXaPeZfEOZ7Pqqf01RsTrPtckSuHleTZ9GFnjJ3Wo1WUnjthHf3DF9OIT26qYjPzfceARUcSMO5Ptt1XCaCRsN0dhVgY4bTBAhhirBpDtMG0uISC3l6mJwINbGSz80A9by4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484612674766.1544038397938; Wed, 30 Sep 2020 09:50:12 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-511-L1AcqBakMFWAPIC1ROxE1A-1; Wed, 30 Sep 2020 12:50:09 -0400 Received: by mail-wr1-f72.google.com with SMTP id d9so823589wrv.16 for ; Wed, 30 Sep 2020 09:50:08 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id b188sm3867646wmb.2.2020.09.30.09.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:06 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEjJONFrTBimyHKi2i/2D3r46cwVifpdF+Aae2zJhkU=; b=OCfmoYcFtj9+sxPD6HissYFVUHWL06t/Mi23jMm3Y64oxsFls0xoMLSxTYbBOOHE5MzpKc X0dFWDLZSgAEZMflCm7jN3lVGMwtDeeU3LuryYBqLZSy1WtkeQpMGMu3Al9DudaQBZ7wc6 FAviSkt5qAJwuNtzkTobA+vvu3/avzw= X-MC-Unique: L1AcqBakMFWAPIC1ROxE1A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AEjJONFrTBimyHKi2i/2D3r46cwVifpdF+Aae2zJhkU=; b=ceyThlFPZY23NiWOdRX3VIv7iHJqUXBfFdmvkntIqkwkRTYp4iVkNnl8X0CQlK6pfK pvhjn8+RE/YPACDu9l3xIUVctXrDBwHPWK7PJ46v5LBMz3SHU/2vgeCGWz7tdKpE+CDW uaKi4tSQoJqyLeSc2otznu0Kgx+O/NkTAcPAYUSqBpH9lnKmXnZosQA+sbfw2kOT9oWI I1oUW3g0T7oPyCnv2KDmFhUKwrJIR4FAy8ha6R5m6+6Et9VBmkoczjvz/lbJl5cQRQWo UIM1Q8mZsvaC2tpsTzQVVTcFycGIEtpEyyxgNOwNQQwQL5x4pTcTNSsH/gNXMovymdN6 1bCQ== X-Gm-Message-State: AOAM530klzAzsvS4jEDn9/piGZnxJ8IOqHwkgLqM55rtKv3NCM8d/Kkr BuMB0Bw+N9XvQ9zyzqOfhpaIll1YRYC2Nk4HGCTq54jVeb1xi9OCnFhkUzYlLKNnVckkZUxn/hU XLqfl59MT7oSfcQ== X-Received: by 2002:a1c:6a08:: with SMTP id f8mr4121739wmc.151.1601484607737; Wed, 30 Sep 2020 09:50:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwynqRkbqXGunLbcXXsuq4/kf0mah5iSCwc05KRFVcDGC/tNwtcfpL+8lz9Cc3EmsmQpYveTQ== X-Received: by 2002:a1c:6a08:: with SMTP id f8mr4121721wmc.151.1601484607506; Wed, 30 Sep 2020 09:50:07 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr() Date: Wed, 30 Sep 2020 18:49:41 +0200 Message-Id: <20200930164949.1425294-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Replace strtoul() by qemu_strtoul() so checkpatch.pl won't complain if we move this code later. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- hw/core/qdev-properties.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 080ba319a1..a1190a5db9 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -951,7 +951,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *= v, const char *name, Property *prop =3D opaque; PCIHostDeviceAddress *addr =3D qdev_get_prop_ptr(dev, prop); char *str, *p; - char *e; + const char *e; unsigned long val; unsigned long dom =3D 0, bus =3D 0; unsigned int slot =3D 0, func =3D 0; @@ -966,23 +966,23 @@ static void set_pci_host_devaddr(Object *obj, Visitor= *v, const char *name, } =20 p =3D str; - val =3D strtoul(p, &e, 16); - if (e =3D=3D p || *e !=3D ':') { + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e =3D=3D p) { + goto inval; + } + if (*e !=3D ':') { goto inval; } bus =3D val; =20 - p =3D e + 1; - val =3D strtoul(p, &e, 16); - if (e =3D=3D p) { + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p) { goto inval; } if (*e =3D=3D ':') { dom =3D bus; bus =3D val; - p =3D e + 1; - val =3D strtoul(p, &e, 16); - if (e =3D=3D p) { + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p)= { goto inval; } } @@ -991,14 +991,13 @@ static void set_pci_host_devaddr(Object *obj, Visitor= *v, const char *name, if (*e !=3D '.') { goto inval; } - p =3D e + 1; - val =3D strtoul(p, &e, 10); - if (e =3D=3D p) { + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e =3D=3D p) { goto inval; } func =3D val; =20 - if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) { + if (bus > 0xff) { goto inval; } =20 --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484619; cv=none; d=zohomail.com; s=zohoarc; b=XjB7PMODTVG/V5nmU+3Z9sDdsnzEmZBwTV6VD5T97z/sr+kPQR1lG9nVMgj2Nafrw5F2xNCf6q8J9qLvFXJLW+keqogvlhYITiuBBhkQ7sGQXeeK0mcgMzLE0XQ3l9FpN3ojaYj1UbUOsHYxMvmyFNfugH5NxhmpyoIDHZ6eJJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=zXLYVmcZORAN1WI9rIV4a3OMV4bhJ5fCBxobebcKs5M=; b=EbxJiEg9hjGK9s6Y7S45vIs7zgT5wZ6o8rzf0S9S7PF2pN5i2CYxsRctAHPAjcKqxKR2RVje7IRaUEIGo9/j4m1q8spbw6J/xABSc8GZcr8Nec5IqaSHLE0s6h+NpFYJFWubxecH3TruQkl29mvU4cKvc+P8sbg/1ZPjjzszwRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484619807249.04348663052667; Wed, 30 Sep 2020 09:50:19 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-dp6iYjYfNE-tVcLjIcjXwQ-1; Wed, 30 Sep 2020 12:50:14 -0400 Received: by mail-wr1-f72.google.com with SMTP id d13so814356wrr.23 for ; Wed, 30 Sep 2020 09:50:14 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id v2sm4040504wme.19.2020.09.30.09.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:12 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zXLYVmcZORAN1WI9rIV4a3OMV4bhJ5fCBxobebcKs5M=; b=iNImFuIWJBVGW4OBgj3fotfvOuAQAFCpulStaCWkUmRdcueeyEduSxvYtw8Ru0qNEQEzCz I6LdH1909Rb+eX2nxTGGYJCdhugvUdVhXTX67QdKr/N+xP8gmcZ2mXiCMOSYSNFlenDMgf cQfK4Ftw44p7GBjh+Z/WFvhB+ipm57E= X-MC-Unique: dp6iYjYfNE-tVcLjIcjXwQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zXLYVmcZORAN1WI9rIV4a3OMV4bhJ5fCBxobebcKs5M=; b=DHy50W2rC/5ELkNoWrI67KXYk1xsr5eNCntOBSrwrkRouwE/PKa89A5R0I69nX9VmX swL+n1dnj3jJ981eS9vQomGc+nY88dffrbdSoJU5XjZ81+VQxinuALkyNEKaMT5zHdCi hS0vPGV+ctiaS2uSDDb7RxAFl9IMb0w6J1qysPPBy/nCOA1PMxDMDuBCLAoi7wIk0mXP x7V1KvnNFpeBZqgyCZIhBbxt+uO3QBWsqf3EEO40qIa0TDQP9GEXVP6NBst2Fb4uwvPr YRkjZJ9hM9j8wJPOMvAxZh2OQaZf/nbPIo0clchcGHcg0lRJtUiCkp+/wFy+VeH4W4xD oUEQ== X-Gm-Message-State: AOAM533H6IBv/RDtgp3EOws+X2nGsdENE9C7HEH9oAb1Np0j/gYq3F2Q JuZRtcjlX15zWXuJzL3/8FHQiIq3f7SQlL8bkp/cJ72vtfq8qr45gVYxweGkf+96LDG8H35GU/4 rB1j1Oc5pgqEMEQ== X-Received: by 2002:a1c:59c2:: with SMTP id n185mr3938721wmb.43.1601484613367; Wed, 30 Sep 2020 09:50:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9t/R0crJ5TioAioJD4m7jku3Gfqpg0Q8CECC1TjraYneMkxr7YZqz8+8/jjFJLXK3cxZWUQ== X-Received: by 2002:a1c:59c2:: with SMTP id n185mr3938695wmb.43.1601484613132; Wed, 30 Sep 2020 09:50:13 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 04/11] hw/core/qdev-properties: Fix code style Date: Wed, 30 Sep 2020 18:49:42 +0200 Message-Id: <20200930164949.1425294-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We will soon move this code, fix its style to avoid checkpatch.pl to complain. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- hw/core/qdev-properties.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index a1190a5db9..071fd5864a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -543,15 +543,15 @@ static void set_mac(Object *obj, Visitor *v, const ch= ar *name, void *opaque, if (!qemu_isxdigit(str[pos])) { goto inval; } - if (!qemu_isxdigit(str[pos+1])) { + if (!qemu_isxdigit(str[pos + 1])) { goto inval; } if (i =3D=3D 5) { - if (str[pos+2] !=3D '\0') { + if (str[pos + 2] !=3D '\0') { goto inval; } } else { - if (str[pos+2] !=3D ':' && str[pos+2] !=3D '-') { + if (str[pos + 2] !=3D ':' && str[pos + 2] !=3D '-') { goto inval; } } @@ -898,8 +898,8 @@ static void set_blocksize(Object *obj, Visitor *v, cons= t char *name, /* We rely on power-of-2 blocksizes for bitmasks */ if ((value & (value - 1)) !=3D 0) { error_setg(errp, - "Property %s.%s doesn't take value '%" PRId64 "', it's n= ot a power of 2", - dev->id ?: "", name, (int64_t)value); + "Property %s.%s doesn't take value '%" PRId64 "', " + "it's not a power of 2", dev->id ?: "", name, (int64_t)v= alue); return; } =20 --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484625; cv=none; d=zohomail.com; s=zohoarc; b=D13TRegNQWaPcr7IV1g7gqVuUeMOAFVi2HueQAbBiIVF4zAj5pHf/xPeiJyQhM3G+r2fN11cms//1R7KSCgdFQb2mxHT9OgfcJrx80mYQpisPB44zFcgEf+kKCVhRoo9qBrA9uKRUQj/u78625Sx2bRY7a5ypBWhEniqzF7rzFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484625; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=JnF87mYv9nAoTiMqtlszBIcwjhpYBnj/f8wWUylyEBo=; b=WVbnlUkx04DC05IR8iyNd7DbzWs3Be3DCQhkFxKdcyZ0WVuAl17Hv5K2GvCMqJMTYl8DVHDZIdk1xIisklM19+An5wADTWpwMAa7grBMCLRHnudhlTHeEfWqZut/2vz1IW+oofyZ+PnRzsLcyzBGxoHlj+L43WS5yQ/ZQlVx1l4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484625249780.08728055762; Wed, 30 Sep 2020 09:50:25 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-vVuqG983NEWFKzdrP9o-yw-1; Wed, 30 Sep 2020 12:50:20 -0400 Received: by mail-wr1-f69.google.com with SMTP id a10so810226wrw.22 for ; Wed, 30 Sep 2020 09:50:19 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id y1sm3951468wmi.36.2020.09.30.09.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:17 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JnF87mYv9nAoTiMqtlszBIcwjhpYBnj/f8wWUylyEBo=; b=Cpq+ZtkqOe3aw2AoQqdOykdoaFyBbSpD+bNthNppVjTRE8lcuKPGL7OBLBQV0BE+/IQOVM Twm4ni/SwMu0oMSNBLDVNHDjn7kXHiVDf8bV6tgi7+My9sso8hmspbn3TTuyBPweBy+sbZ BjmJbMydrBWwFubgR1e9M7PZT7WDhUk= X-MC-Unique: vVuqG983NEWFKzdrP9o-yw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JnF87mYv9nAoTiMqtlszBIcwjhpYBnj/f8wWUylyEBo=; b=pbyFnFwDYWwa2i0TUj8V1KP3fHqflglRS2A0L883UAZ3CklCC/vnuxsaOXZfXQqLAk AST9G6aC72SAFmrUXUR5vbmr1KzjmXE+z2oANewAXbSAuqvv6rMNuJ6KAyvP274l6jmu DezkZAY3fudHNOWpHSjQ5bnOMtiv7vk2RaU4vP+n4Mkl1hqadXSHzOtwYnJY2b1zGHpz B+HLLlQJZRwzPLqT4whSt7DBmOPoSuhyVik/vu75nPW4206BcXQSdqzb/bpIXYtcEE+A wBI92Az7dWVsdrpclryCGiYlgEVhOzpraY7Y6xAqpse2CCa+jT4maX3FGhwJZzkTKjdD vROg== X-Gm-Message-State: AOAM530ZbGxVgfrglw2sU6vvJW0wPuPujebKqwPz5Xo1QxXtSSCubQuy 5gdRKbP74yGULFu+Hd2Dku/sv8Mchc0CeaqLl0Dy+OEcvFRX6GTEr28tE5XgY5YZGKVYCHodCGO 5CwXOpS0xsIBdTQ== X-Received: by 2002:a5d:4cc1:: with SMTP id c1mr4164931wrt.122.1601484618804; Wed, 30 Sep 2020 09:50:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7NiQM0mxDOzxHSfAyhi8ASwWDi0eN5yG6RQuak95CeGWRLYJFGw3mi2qS/uUXhISKB0mjdA== X-Received: by 2002:a5d:4cc1:: with SMTP id c1mr4164898wrt.122.1601484618525; Wed, 30 Sep 2020 09:50:18 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 05/11] hw/core/qdev-properties: Export enum-related functions Date: Wed, 30 Sep 2020 18:49:43 +0200 Message-Id: <20200930164949.1425294-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We are going to split this file and reuse these static functions. Add the local "qdev-prop-internal.h" header declaring them. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- hw/core/qdev-prop-internal.h | 19 ++++++++++++ hw/core/qdev-properties.c | 58 +++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 hw/core/qdev-prop-internal.h diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h new file mode 100644 index 0000000000..2a8c9a306a --- /dev/null +++ b/hw/core/qdev-prop-internal.h @@ -0,0 +1,19 @@ +/* + * qdev property parsing + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_CORE_QDEV_PROP_INTERNAL_H +#define HW_CORE_QDEV_PROP_INTERNAL_H + +void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp); +void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp); + +void qdev_propinfo_set_default_value_enum(ObjectProperty *op, + const Property *prop); + +#endif diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 071fd5864a..76417d0936 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -18,6 +18,7 @@ #include "qemu/uuid.h" #include "qemu/units.h" #include "qemu/cutils.h" +#include "qdev-prop-internal.h" =20 void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -53,8 +54,8 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) return ptr; } =20 -static void get_enum(Object *obj, Visitor *v, const char *name, void *opaq= ue, - Error **errp) +void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; @@ -63,8 +64,8 @@ static void get_enum(Object *obj, Visitor *v, const char = *name, void *opaque, visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); } =20 -static void set_enum(Object *obj, Visitor *v, const char *name, void *opaq= ue, - Error **errp) +void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; @@ -78,7 +79,8 @@ static void set_enum(Object *obj, Visitor *v, const char = *name, void *opaque, visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); } =20 -static void set_default_value_enum(ObjectProperty *op, const Property *pro= p) +void qdev_propinfo_set_default_value_enum(ObjectProperty *op, + const Property *prop) { object_property_set_default_str(op, qapi_enum_lookup(prop->info->enum_table, prop->defval.i)); @@ -669,9 +671,9 @@ const PropertyInfo qdev_prop_on_off_auto =3D { .name =3D "OnOffAuto", .description =3D "on/off/auto", .enum_table =3D &OnOffAuto_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- lost tick policy --- */ @@ -681,9 +683,9 @@ QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) !=3D sizeof(in= t)); const PropertyInfo qdev_prop_losttickpolicy =3D { .name =3D "LostTickPolicy", .enum_table =3D &LostTickPolicy_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- Block device error handling policy --- */ @@ -695,9 +697,9 @@ const PropertyInfo qdev_prop_blockdev_on_error =3D { .description =3D "Error handling policy, " "report/ignore/enospc/stop/auto", .enum_table =3D &BlockdevOnError_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- BIOS CHS translation */ @@ -709,9 +711,9 @@ const PropertyInfo qdev_prop_bios_chs_trans =3D { .description =3D "Logical CHS translation algorithm, " "auto/none/lba/large/rechs", .enum_table =3D &BiosAtaTranslation_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- FDC default drive types */ @@ -721,9 +723,9 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { .description =3D "FDC drive type, " "144/288/120/none/auto", .enum_table =3D &FloppyDriveType_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- MultiFDCompression --- */ @@ -733,9 +735,9 @@ const PropertyInfo qdev_prop_multifd_compression =3D { .description =3D "multifd_compression values, " "none/zlib/zstd", .enum_table =3D &MultiFDCompression_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- pci address --- */ @@ -1416,9 +1418,9 @@ const PropertyInfo qdev_prop_off_auto_pcibar =3D { .name =3D "OffAutoPCIBAR", .description =3D "off/auto/bar0/bar1/bar2/bar3/bar4/bar5", .enum_table =3D &OffAutoPCIBAR_lookup, - .get =3D get_enum, - .set =3D set_enum, - .set_default_value =3D set_default_value_enum, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- PCIELinkSpeed 2_5/5/8/16 -- */ @@ -1495,7 +1497,7 @@ const PropertyInfo qdev_prop_pcie_link_speed =3D { .enum_table =3D &PCIELinkSpeed_lookup, .get =3D get_prop_pcielinkspeed, .set =3D set_prop_pcielinkspeed, - .set_default_value =3D set_default_value_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */ @@ -1590,5 +1592,5 @@ const PropertyInfo qdev_prop_pcie_link_width =3D { .enum_table =3D &PCIELinkWidth_lookup, .get =3D get_prop_pcielinkwidth, .set =3D set_prop_pcielinkwidth, - .set_default_value =3D set_default_value_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, }; --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484633; cv=none; d=zohomail.com; s=zohoarc; b=a7cTcTVVXjyNYssjub6k3FFt5gALv0jKx0MYnk+4nMhxhNbADGDllKJclFJSO7L/FhhUPIof4H1ibolQVG9f48h/PAQCSSDgUxBHSsv6sOa6BzbttraeoDmoyHHBPjAnGbJ4GDdfjmG0NeNg2oVNiNwM9whlmei1+o5EyQ1K6r4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484633; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=C6Fm2xUD2RWK8sXQLgIXMwM+hS3JLybHuCGcigeuHtk=; b=JoG4qQ0PB0Cf2fRRJApO0H/7b+fYaXQGeSJYmw7fmQjJ79l0x2C5I5e3UR63eIZ9lhXW1gCDEzFbAbVVp/ixpCEkLWlGqtyNuBsH99N3fmO1+3i3D1Lht7dVF92Sx4d36NJZ0kxC6bI1T5przLuVuRXKBryMjcioeYdfRnrFJx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601484633554694.4849154826356; Wed, 30 Sep 2020 09:50:33 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-dDAXEZEaNF6Ie1eR53evDA-1; Wed, 30 Sep 2020 12:50:29 -0400 Received: by mail-wr1-f71.google.com with SMTP id j7so828467wro.14 for ; Wed, 30 Sep 2020 09:50:28 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id a15sm4405097wrn.3.2020.09.30.09.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C6Fm2xUD2RWK8sXQLgIXMwM+hS3JLybHuCGcigeuHtk=; b=IZbkrdz4gBs9j1ooP6feQkbSjT6bWtt31eirOWVYOMfsWEB7LPeX6jQi4+zBIegVRmlXDV x0gge494zgZfjEi2uGb5dc30Yobc4SMhFuxTzQr8Vf+AdmNwytK+88s82LByOu/gLR18N1 I3TW7xbP9D+HKHbjxGSE+IiXEePXVeo= X-MC-Unique: dDAXEZEaNF6Ie1eR53evDA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C6Fm2xUD2RWK8sXQLgIXMwM+hS3JLybHuCGcigeuHtk=; b=h9hb0vWSwHqNsY204eM+KIZCZzc8h73DLEi3J0f7YGD1AWA2uJcptkdJ8hg+ND5P/4 I8KNeSPK9ym657L1Jtb2RvQsQvz3A6bmBIOaqQ+a1rMB70HPZb2ZKy7TgIEkM4X6Q+o1 Kbl0jlfj/DVdvZfOpu9FcjNWY90mMJhZ50NtjE4gQDzB36kSqGu3T6W7pCrGvtLM/JFq Lgn0NYAt120Yhz+ZxbutuBcuZ2lCWGLThs+gyzG2qOBXy8LhV9e1a7VmmFfNwMp96LUm b8Dkd6AiIInHuXqE9wYC45wKYxq+k/BDZ+Z1M2G4eXc3PJuTALq6YYcXxPoIB2mmTZk7 0jAg== X-Gm-Message-State: AOAM532CuuFuN5+bf9mNFroa/qjDqBvg7RRxsyojKzxKJTB9hmSWigS2 VIt685ioF/GEBlAUoOhbhsWpyjTYITLN9wp3zJQg3ehBC6G9rQKiIdzEQOnA2M/1fRrHSN99V0y Tds1I06QnLGgYsg== X-Received: by 2002:a1c:96cf:: with SMTP id y198mr4218422wmd.104.1601484624054; Wed, 30 Sep 2020 09:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZwYKXrf/pCor3fL0qkRpuOATDY1ZY0R/nDzSeJ/dAFin5woJ3Ks49fKghYaGUVgJYglJlcg== X-Received: by 2002:a1c:96cf:: with SMTP id y198mr4218397wmd.104.1601484623802; Wed, 30 Sep 2020 09:50:23 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 06/11] hw/core/qdev-properties: Export qdev_prop_enum Date: Wed, 30 Sep 2020 18:49:44 +0200 Message-Id: <20200930164949.1425294-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- include/hw/qdev-properties.h | 1 + hw/core/qdev-properties.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 528310bb22..4437450065 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -8,6 +8,7 @@ extern const PropertyInfo qdev_prop_bit; extern const PropertyInfo qdev_prop_bit64; extern const PropertyInfo qdev_prop_bool; +extern const PropertyInfo qdev_prop_enum; extern const PropertyInfo qdev_prop_uint8; extern const PropertyInfo qdev_prop_uint16; extern const PropertyInfo qdev_prop_uint32; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 76417d0936..31dfe441e2 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -86,6 +86,13 @@ void qdev_propinfo_set_default_value_enum(ObjectProperty= *op, qapi_enum_lookup(prop->info->enum_table, prop->defval.i)); } =20 +const PropertyInfo qdev_prop_enum =3D { + .name =3D "enum", + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + /* Bit */ =20 static uint32_t qdev_get_prop_mask(Property *prop) --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484638; cv=none; d=zohomail.com; s=zohoarc; b=V6orXv1pa9226kBdTd44fqmzgHNf9NVgFr+LGTGWf68VXsVYSNzUQ1b4t14AHhJAhg6ln7GqnEAPLGYuXOrIoL0+bCu1etnUn7OuQAvPFmfp8mLeSHii7ydMo1S411h8Qr2uY4FKLZaZNM9ghi4kQGsCuf/evoRkZzUfArxYa1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484638; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ex4gpJ0pAFE1dfNikKPuxcXqvVmymiM2aiqFym1Iy/Y=; b=hTZEDrdoNO7S6jOme0nxiu5zB28IHitZVyvCrixkjGTwPE7INBNhg5WET0JofTb1NfYKZM9dQBQCPd1Jg2I7sye4Wi5gVfQyaJFUjWTNk91irYdTYep15NPJ/utG6hlazUuGlCq+3vB2gYdjIKJApcK2oTASDUxLcPbFX24ozJg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601484638234593.9397916079694; Wed, 30 Sep 2020 09:50:38 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-3E1ck-EENzW0dp0lez4ryQ-1; Wed, 30 Sep 2020 12:50:31 -0400 Received: by mail-wr1-f69.google.com with SMTP id l9so817013wrq.20 for ; Wed, 30 Sep 2020 09:50:30 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id l19sm3842702wmi.8.2020.09.30.09.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:28 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ex4gpJ0pAFE1dfNikKPuxcXqvVmymiM2aiqFym1Iy/Y=; b=fzHzhtoulxwssc742+zu7HpOQ5UIaL5za750vytoKpr+jc8lxuEeLXcMrSWEesubck0fmO x4E6OF9Hr2TK1bXnsrAJ/dyhwELarL6pYQrQvnwWDtJTS6nmt5xZ9k5I6NQ/DODShRht9K CGin5QBAjKuMpDn0fbJc41Kw+LmQUzQ= X-MC-Unique: 3E1ck-EENzW0dp0lez4ryQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ex4gpJ0pAFE1dfNikKPuxcXqvVmymiM2aiqFym1Iy/Y=; b=lGR3or3pXA3rRctBC8yPbHmwk7BcJTJTKeEBxH9i0A9Uz6joUUes3cXKlqEFQ1MTjF 7EH1b0u6PxGKfpbmAGJIzQzCnsvpoxUNx7xE52pqmWvObIbjpDwmCYMQfcTYr4Olm+oW 1EHNn/RmXhgxx21JbVxB+jrzllDm9+K+7jSKSFCNSrNA8/sb1PqVrTBAKccWPTPMON4C BYEbBfM7E7Dt04eiWY1vtjL8NwUwbJZ89VF0VYz6mJ9K9+F1l9IpLcAbAGXPnjqvtfWG LrXQvrAAkkOdxwxsZfn0xuuc715n0CJKMUPUglXXGC+fUIU+REMKRYkCcBN9wkc4JsEM e5HA== X-Gm-Message-State: AOAM530XtnrjhozkysNAPIWPRfEI2Eh9U8MXLMAKccH1rJfj9wFQMC2h BIKgBiZlw/JnhNTMC99z7K5vMqltdKSM0oi3zMv7mw/DZtF/seMxHoHSDIwlmn2FHzhYiy8KyUK cCVmhzywO/yOIDg== X-Received: by 2002:a5d:4591:: with SMTP id p17mr4087802wrq.408.1601484629281; Wed, 30 Sep 2020 09:50:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaxdidazBw5vpOugL9EXkBK5RJseRGSh4EGDFBeaOMYTSn9rB+tfKYUFxKWLnmit7u398T8g== X-Received: by 2002:a5d:4591:: with SMTP id p17mr4087771wrq.408.1601484629067; Wed, 30 Sep 2020 09:50:29 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 07/11] hw/core/qdev-properties: Export some integer-related functions Date: Wed, 30 Sep 2020 18:49:45 +0200 Message-Id: <20200930164949.1425294-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We are going to split this file and reuse these static functions. Declare them in the local "qdev-prop-internal.h" header. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- v3: Also export qdev_propinfo_get_size32 introduced in commits 914e74cda9 ("qdev-properties: add size32 property type") and 031ffd9a61 ("qdev-properties: add getter for size32 and blocksize"). --- hw/core/qdev-prop-internal.h | 11 +++++++++ hw/core/qdev-properties.c | 46 +++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h index 2a8c9a306a..9cf5cc1d51 100644 --- a/hw/core/qdev-prop-internal.h +++ b/hw/core/qdev-prop-internal.h @@ -15,5 +15,16 @@ void qdev_propinfo_set_enum(Object *obj, Visitor *v, con= st char *name, =20 void qdev_propinfo_set_default_value_enum(ObjectProperty *op, const Property *prop); +void qdev_propinfo_set_default_value_int(ObjectProperty *op, + const Property *prop); +void qdev_propinfo_set_default_value_uint(ObjectProperty *op, + const Property *prop); + +void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp); +void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp); +void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp); =20 #endif diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 31dfe441e2..37e309077a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -271,12 +271,14 @@ static void set_uint8(Object *obj, Visitor *v, const = char *name, void *opaque, visit_type_uint8(v, name, ptr, errp); } =20 -static void set_default_value_int(ObjectProperty *op, const Property *prop) +void qdev_propinfo_set_default_value_int(ObjectProperty *op, + const Property *prop) { object_property_set_default_int(op, prop->defval.i); } =20 -static void set_default_value_uint(ObjectProperty *op, const Property *pro= p) +void qdev_propinfo_set_default_value_uint(ObjectProperty *op, + const Property *prop) { object_property_set_default_uint(op, prop->defval.u); } @@ -285,13 +287,13 @@ const PropertyInfo qdev_prop_uint8 =3D { .name =3D "uint8", .get =3D get_uint8, .set =3D set_uint8, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- 16bit integer --- */ =20 -static void get_uint16(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) +void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; @@ -317,9 +319,9 @@ static void set_uint16(Object *obj, Visitor *v, const c= har *name, =20 const PropertyInfo qdev_prop_uint16 =3D { .name =3D "uint16", - .get =3D get_uint16, + .get =3D qdev_propinfo_get_uint16, .set =3D set_uint16, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- 32bit integer --- */ @@ -349,8 +351,8 @@ static void set_uint32(Object *obj, Visitor *v, const c= har *name, visit_type_uint32(v, name, ptr, errp); } =20 -static void get_int32(Object *obj, Visitor *v, const char *name, void *opa= que, - Error **errp) +void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; @@ -378,14 +380,14 @@ const PropertyInfo qdev_prop_uint32 =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_uint32, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 const PropertyInfo qdev_prop_int32 =3D { .name =3D "int32", - .get =3D get_int32, + .get =3D qdev_propinfo_get_int32, .set =3D set_int32, - .set_default_value =3D set_default_value_int, + .set_default_value =3D qdev_propinfo_set_default_value_int, }; =20 /* --- 64bit integer --- */ @@ -444,14 +446,14 @@ const PropertyInfo qdev_prop_uint64 =3D { .name =3D "uint64", .get =3D get_uint64, .set =3D set_uint64, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 const PropertyInfo qdev_prop_int64 =3D { .name =3D "int64", .get =3D get_int64, .set =3D set_int64, - .set_default_value =3D set_default_value_int, + .set_default_value =3D qdev_propinfo_set_default_value_int, }; =20 /* --- string --- */ @@ -820,8 +822,8 @@ const PropertyInfo qdev_prop_pci_devfn =3D { =20 /* --- 32bit unsigned int 'size' type --- */ =20 -static void get_size32(Object *obj, Visitor *v, const char *name, void *op= aque, - Error **errp) +void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; @@ -861,9 +863,9 @@ static void set_size32(Object *obj, Visitor *v, const c= har *name, void *opaque, =20 const PropertyInfo qdev_prop_size32 =3D { .name =3D "size", - .get =3D get_size32, + .get =3D qdev_propinfo_get_size32, .set =3D set_size32, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- blocksize --- */ @@ -919,9 +921,9 @@ const PropertyInfo qdev_prop_blocksize =3D { .name =3D "size", .description =3D "A power of two between " MIN_BLOCK_SIZE_STR " and " MAX_BLOCK_SIZE_STR, - .get =3D get_size32, + .get =3D qdev_propinfo_get_size32, .set =3D set_blocksize, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- pci host address --- */ @@ -1190,7 +1192,7 @@ const PropertyInfo qdev_prop_arraylen =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_prop_arraylen, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- public helpers --- */ @@ -1401,7 +1403,7 @@ const PropertyInfo qdev_prop_size =3D { .name =3D "size", .get =3D get_size, .set =3D set_size, - .set_default_value =3D set_default_value_uint, + .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 /* --- object link property --- */ --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484642; cv=none; d=zohomail.com; s=zohoarc; b=OxsFV/ZzL0J6xUSuYME9me5X5me5+W7NmkYRBZrnt/764XwjkaSbW1phvaV+Ygv7vLvEmD4pfU/GG1L6dRfcaSnb115ASq+51/yJhBE8UXgqncn9eLRPeq3aWkwnMjUkBRN1GntzuDnPYLoT3YW7rZdSAd62X6+KPS3SRyoVm8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=IH1Y+lGzySf//AXyG6WjJKYyISNsRIiloaORu9fBW48=; b=VGP3N+vduWqX2X2NJjQwnuIGfV8nQ/dyj+0mrLPj7nWeHdi2/1GWa77cQOqyFqvea4GsYb1NkRCHUYsGHxvc111yOm5mCQQKR8sE574eInAA8mdZV2iLVZQvJB9LStByCKLQfpRb+kK86BGd7KtIb1D5EVdXvqE5nFKWY1jgmjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484642663299.5780017087982; Wed, 30 Sep 2020 09:50:42 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-nvckgTv1O7KuXF_9ibsbeg-1; Wed, 30 Sep 2020 12:50:37 -0400 Received: by mail-wm1-f72.google.com with SMTP id 73so60973wma.5 for ; Wed, 30 Sep 2020 09:50:37 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id z1sm3885958wmk.45.2020.09.30.09.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:33 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IH1Y+lGzySf//AXyG6WjJKYyISNsRIiloaORu9fBW48=; b=Kit4xc7iHkVuhWipY8QuZ5GDXyMDXRGqqXdIkIoHOxJ9wyzydaOfc7RSB2o9v11HgCNfqW KpXltxn5nhyV3zCscdN/wBUwDQWAVN5gXAz7uVVJZkydU1tL3hRzmrB9dr9wTLXyYEqO+w ylo9NHYBfxQA2g7S40schZGnTsN/8fA= X-MC-Unique: nvckgTv1O7KuXF_9ibsbeg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IH1Y+lGzySf//AXyG6WjJKYyISNsRIiloaORu9fBW48=; b=XxFEdYWSf3k5ssLZ+JURI9P9Yat+HgaH2RiOs/w/ImUrxr38fiCbMH+kK33/XCcqG/ Sno4UEG902h8234hoJAJz8gt82vQKYJnIqyoXHJmlrSCJGNfilK2dY4B+ON2B/VDFo0a dZMsnHPMwoiNMqK4uJGC9gNmSBcfQ9Pz7oJL8og+ly/WuuxdTx9rWjvyjHizWlPNsePl LXH1TpJcURU5lseLvUDTZ62grhl8kXsiozqKYAUtO3U5Tzzrhx8RFmGlZtostNYWu1K9 MDt9jV43ze/DjMX/sLNBfdowBCkA4o8Od36kC6NzwOG0f9lfSt4B83ZObxotM4RkOa1r X7bA== X-Gm-Message-State: AOAM530InDnVPEYKpbBXFnRvlgJkboYUwgS5d+Txf8fjTMYpvTeuJaay 5uH6DvEXJGfAeaXihk5+QnNFk+xjK1fjoXmFnfirBsZzD2qrKFZgj73m90L3NycqiPMjxyH8+no Hx8hE/JH4e9tqIw== X-Received: by 2002:a1c:a515:: with SMTP id o21mr2686573wme.75.1601484635335; Wed, 30 Sep 2020 09:50:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznTQ5tHY2LEURDng7l6x7ZBFNfIGeJ8HNoR9+adXwfX93CkjMyujmOmaLMzwV/x4X/ZMYvDw== X-Received: by 2002:a1c:a515:: with SMTP id o21mr2686535wme.75.1601484634815; Wed, 30 Sep 2020 09:50:34 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 08/11] hw/core/qdev-properties: Extract system-mode specific properties Date: Wed, 30 Sep 2020 18:49:46 +0200 Message-Id: <20200930164949.1425294-9-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Move properties specific to machines into a separate file. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- v3: Also move Reserved Region introduced in commit f78069253c ("qdev: Introduce DEFINE_PROP_RESERVED_REGION"). --- hw/core/qdev-properties-system.c | 687 ++++++++++++++++++++++++++++++- hw/core/qdev-properties.c | 674 ------------------------------ 2 files changed, 679 insertions(+), 682 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index b29daf4fb5..49bdd12581 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -11,19 +11,25 @@ */ =20 #include "qemu/osdep.h" -#include "audio/audio.h" -#include "net/net.h" #include "hw/qdev-properties.h" #include "qapi/error.h" +#include "qapi/visitor.h" +#include "qapi/qapi-types-block.h" +#include "qapi/qapi-types-machine.h" +#include "qapi/qapi-types-migration.h" #include "qapi/qmp/qerror.h" +#include "qemu/ctype.h" +#include "qemu/cutils.h" +#include "qemu/units.h" +#include "qemu/error-report.h" +#include "qdev-prop-internal.h" + +#include "audio/audio.h" +#include "chardev/char-fe.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" -#include "hw/block/block.h" -#include "net/hub.h" -#include "qapi/visitor.h" -#include "chardev/char-fe.h" -#include "sysemu/iothread.h" -#include "sysemu/tpm_backend.h" +#include "net/net.h" +#include "hw/pci/pci.h" =20 static bool check_prop_still_unset(DeviceState *dev, const char *name, const void *old_val, const char *new_va= l, @@ -280,6 +286,96 @@ const PropertyInfo qdev_prop_chr =3D { .release =3D release_chr, }; =20 +/* --- mac address --- */ + +/* + * accepted syntax versions: + * 01:02:03:04:05:06 + * 01-02-03-04-05-06 + */ +static void get_mac(Object *obj, Visitor *v, const char *name, void *opaqu= e, + Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + MACAddr *mac =3D qdev_get_prop_ptr(dev, prop); + char buffer[2 * 6 + 5 + 1]; + char *p =3D buffer; + + snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x", + mac->a[0], mac->a[1], mac->a[2], + mac->a[3], mac->a[4], mac->a[5]); + + visit_type_str(v, name, &p, errp); +} + +static void set_mac(Object *obj, Visitor *v, const char *name, void *opaqu= e, + Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + MACAddr *mac =3D qdev_get_prop_ptr(dev, prop); + int i, pos; + char *str; + const char *p; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_str(v, name, &str, errp)) { + return; + } + + for (i =3D 0, pos =3D 0; i < 6; i++, pos +=3D 3) { + long val; + + if (!qemu_isxdigit(str[pos])) { + goto inval; + } + if (!qemu_isxdigit(str[pos + 1])) { + goto inval; + } + if (i =3D=3D 5) { + if (str[pos + 2] !=3D '\0') { + goto inval; + } + } else { + if (str[pos + 2] !=3D ':' && str[pos + 2] !=3D '-') { + goto inval; + } + } + if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) { + goto inval; + } + mac->a[i] =3D val; + } + g_free(str); + return; + +inval: + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + g_free(str); +} + +const PropertyInfo qdev_prop_macaddr =3D { + .name =3D "str", + .description =3D "Ethernet 6-byte MAC Address, example: 52:54:00:12:34= :56", + .get =3D get_mac, + .set =3D set_mac, +}; + +void qdev_prop_set_macaddr(DeviceState *dev, const char *name, + const uint8_t *value) +{ + char str[2 * 6 + 5 + 1]; + snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x", + value[0], value[1], value[2], value[3], value[4], value[5]); + + object_property_set_str(OBJECT(dev), name, str, &error_abort); +} + /* --- netdev device --- */ static void get_netdev(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -465,3 +561,578 @@ void qdev_set_nic_properties(DeviceState *dev, NICInf= o *nd) } nd->instantiated =3D 1; } + +/* --- lost tick policy --- */ + +QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) !=3D sizeof(int)); + +const PropertyInfo qdev_prop_losttickpolicy =3D { + .name =3D "LostTickPolicy", + .enum_table =3D &LostTickPolicy_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- blocksize --- */ + +/* lower limit is sector size */ +#define MIN_BLOCK_SIZE 512 +#define MIN_BLOCK_SIZE_STR "512 B" +/* + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses,= and + * matches qcow2 cluster size limit + */ +#define MAX_BLOCK_SIZE (2 * MiB) +#define MAX_BLOCK_SIZE_STR "2 MiB" + +static void set_blocksize(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + uint32_t *ptr =3D qdev_get_prop_ptr(dev, prop); + uint64_t value; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_size(v, name, &value, errp)) { + return; + } + /* value of 0 means "unset" */ + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { + error_setg(errp, + "Property %s.%s doesn't take value %" PRIu64 + " (minimum: " MIN_BLOCK_SIZE_STR + ", maximum: " MAX_BLOCK_SIZE_STR ")", + dev->id ? : "", name, value); + return; + } + + /* We rely on power-of-2 blocksizes for bitmasks */ + if ((value & (value - 1)) !=3D 0) { + error_setg(errp, + "Property %s.%s doesn't take value '%" PRId64 "', " + "it's not a power of 2", dev->id ?: "", name, (int64_t)v= alue); + return; + } + + *ptr =3D value; +} + +const PropertyInfo qdev_prop_blocksize =3D { + .name =3D "size", + .description =3D "A power of two between " MIN_BLOCK_SIZE_STR + " and " MAX_BLOCK_SIZE_STR, + .get =3D qdev_propinfo_get_size32, + .set =3D set_blocksize, + .set_default_value =3D qdev_propinfo_set_default_value_uint, +}; + +/* --- Block device error handling policy --- */ + +QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) !=3D sizeof(int)); + +const PropertyInfo qdev_prop_blockdev_on_error =3D { + .name =3D "BlockdevOnError", + .description =3D "Error handling policy, " + "report/ignore/enospc/stop/auto", + .enum_table =3D &BlockdevOnError_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- BIOS CHS translation */ + +QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) !=3D sizeof(int)); + +const PropertyInfo qdev_prop_bios_chs_trans =3D { + .name =3D "BiosAtaTranslation", + .description =3D "Logical CHS translation algorithm, " + "auto/none/lba/large/rechs", + .enum_table =3D &BiosAtaTranslation_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- FDC default drive types */ + +const PropertyInfo qdev_prop_fdc_drive_type =3D { + .name =3D "FdcDriveType", + .description =3D "FDC drive type, " + "144/288/120/none/auto", + .enum_table =3D &FloppyDriveType_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- MultiFDCompression --- */ + +const PropertyInfo qdev_prop_multifd_compression =3D { + .name =3D "MultiFDCompression", + .description =3D "multifd_compression values, " + "none/zlib/zstd", + .enum_table =3D &MultiFDCompression_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- Reserved Region --- */ + +/* + * Accepted syntax: + * :: + * where low/high addresses are uint64_t in hexadecimal + * and type is a non-negative decimal integer + */ +static void get_reserved_region(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); + char buffer[64]; + char *p =3D buffer; + int rc; + + rc =3D snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u", + rr->low, rr->high, rr->type); + assert(rc < sizeof(buffer)); + + visit_type_str(v, name, &p, errp); +} + +static void set_reserved_region(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); + Error *local_err =3D NULL; + const char *endptr; + char *str; + int ret; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + ret =3D qemu_strtou64(str, &endptr, 16, &rr->low); + if (ret) { + error_setg(errp, "start address of '%s'" + " must be a hexadecimal integer", name); + goto out; + } + if (*endptr !=3D ':') { + goto separator_error; + } + + ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &rr->high); + if (ret) { + error_setg(errp, "end address of '%s'" + " must be a hexadecimal integer", name); + goto out; + } + if (*endptr !=3D ':') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &rr->type); + if (ret) { + error_setg(errp, "type of '%s'" + " must be a non-negative decimal integer", name); + } + goto out; + +separator_error: + error_setg(errp, "reserved region fields must be separated with ':'"); +out: + g_free(str); + return; +} + +const PropertyInfo qdev_prop_reserved_region =3D { + .name =3D "reserved_region", + .description =3D "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0", + .get =3D get_reserved_region, + .set =3D set_reserved_region, +}; + +/* --- pci address --- */ + +/* + * bus-local address, i.e. "$slot" or "$slot.$fn" + */ +static void set_pci_devfn(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + int32_t value, *ptr =3D qdev_get_prop_ptr(dev, prop); + unsigned int slot, fn, n; + char *str; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_str(v, name, &str, NULL)) { + if (!visit_type_int32(v, name, &value, errp)) { + return; + } + if (value < -1 || value > 255) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "pci_devfn"); + return; + } + *ptr =3D value; + return; + } + + if (sscanf(str, "%x.%x%n", &slot, &fn, &n) !=3D 2) { + fn =3D 0; + if (sscanf(str, "%x%n", &slot, &n) !=3D 1) { + goto invalid; + } + } + if (str[n] !=3D '\0' || fn > 7 || slot > 31) { + goto invalid; + } + *ptr =3D slot << 3 | fn; + g_free(str); + return; + +invalid: + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + g_free(str); +} + +static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, + size_t len) +{ + int32_t *ptr =3D qdev_get_prop_ptr(dev, prop); + + if (*ptr =3D=3D -1) { + return snprintf(dest, len, ""); + } else { + return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7); + } +} + +const PropertyInfo qdev_prop_pci_devfn =3D { + .name =3D "int32", + .description =3D "Slot and optional function number, example: 06.0 or = 06", + .print =3D print_pci_devfn, + .get =3D qdev_propinfo_get_int32, + .set =3D set_pci_devfn, + .set_default_value =3D qdev_propinfo_set_default_value_int, +}; + +/* --- pci host address --- */ + +static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIHostDeviceAddress *addr =3D qdev_get_prop_ptr(dev, prop); + char buffer[] =3D "ffff:ff:ff.f"; + char *p =3D buffer; + int rc =3D 0; + + /* + * Catch "invalid" device reference from vfio-pci and allow the + * default buffer representing the non-existent device to be used. + */ + if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) { + rc =3D snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d", + addr->domain, addr->bus, addr->slot, addr->function); + assert(rc =3D=3D sizeof(buffer) - 1); + } + + visit_type_str(v, name, &p, errp); +} + +/* + * Parse [:]:. + * if is not supplied, it's assumed to be 0. + */ +static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIHostDeviceAddress *addr =3D qdev_get_prop_ptr(dev, prop); + char *str, *p; + const char *e; + unsigned long val; + unsigned long dom =3D 0, bus =3D 0; + unsigned int slot =3D 0, func =3D 0; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_str(v, name, &str, errp)) { + return; + } + + p =3D str; + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e =3D=3D p) { + goto inval; + } + if (*e !=3D ':') { + goto inval; + } + bus =3D val; + + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p) { + goto inval; + } + if (*e =3D=3D ':') { + dom =3D bus; + bus =3D val; + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p)= { + goto inval; + } + } + slot =3D val; + + if (*e !=3D '.') { + goto inval; + } + p =3D (char *)e + 1; + if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e =3D=3D p) { + goto inval; + } + func =3D val; + + if (bus > 0xff) { + goto inval; + } + + if (*e) { + goto inval; + } + + addr->domain =3D dom; + addr->bus =3D bus; + addr->slot =3D slot; + addr->function =3D func; + + g_free(str); + return; + +inval: + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + g_free(str); +} + +const PropertyInfo qdev_prop_pci_host_devaddr =3D { + .name =3D "str", + .description =3D "Address (bus/device/function) of " + "the host device, example: 04:10.0", + .get =3D get_pci_host_devaddr, + .set =3D set_pci_host_devaddr, +}; + +/* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */ + +const PropertyInfo qdev_prop_off_auto_pcibar =3D { + .name =3D "OffAutoPCIBAR", + .description =3D "off/auto/bar0/bar1/bar2/bar3/bar4/bar5", + .enum_table =3D &OffAutoPCIBAR_lookup, + .get =3D qdev_propinfo_get_enum, + .set =3D qdev_propinfo_set_enum, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- PCIELinkSpeed 2_5/5/8/16 -- */ + +static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIExpLinkSpeed *p =3D qdev_get_prop_ptr(dev, prop); + int speed; + + switch (*p) { + case QEMU_PCI_EXP_LNK_2_5GT: + speed =3D PCIE_LINK_SPEED_2_5; + break; + case QEMU_PCI_EXP_LNK_5GT: + speed =3D PCIE_LINK_SPEED_5; + break; + case QEMU_PCI_EXP_LNK_8GT: + speed =3D PCIE_LINK_SPEED_8; + break; + case QEMU_PCI_EXP_LNK_16GT: + speed =3D PCIE_LINK_SPEED_16; + break; + default: + /* Unreachable */ + abort(); + } + + visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp); +} + +static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIExpLinkSpeed *p =3D qdev_get_prop_ptr(dev, prop); + int speed; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table, + errp)) { + return; + } + + switch (speed) { + case PCIE_LINK_SPEED_2_5: + *p =3D QEMU_PCI_EXP_LNK_2_5GT; + break; + case PCIE_LINK_SPEED_5: + *p =3D QEMU_PCI_EXP_LNK_5GT; + break; + case PCIE_LINK_SPEED_8: + *p =3D QEMU_PCI_EXP_LNK_8GT; + break; + case PCIE_LINK_SPEED_16: + *p =3D QEMU_PCI_EXP_LNK_16GT; + break; + default: + /* Unreachable */ + abort(); + } +} + +const PropertyInfo qdev_prop_pcie_link_speed =3D { + .name =3D "PCIELinkSpeed", + .description =3D "2_5/5/8/16", + .enum_table =3D &PCIELinkSpeed_lookup, + .get =3D get_prop_pcielinkspeed, + .set =3D set_prop_pcielinkspeed, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + +/* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */ + +static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIExpLinkWidth *p =3D qdev_get_prop_ptr(dev, prop); + int width; + + switch (*p) { + case QEMU_PCI_EXP_LNK_X1: + width =3D PCIE_LINK_WIDTH_1; + break; + case QEMU_PCI_EXP_LNK_X2: + width =3D PCIE_LINK_WIDTH_2; + break; + case QEMU_PCI_EXP_LNK_X4: + width =3D PCIE_LINK_WIDTH_4; + break; + case QEMU_PCI_EXP_LNK_X8: + width =3D PCIE_LINK_WIDTH_8; + break; + case QEMU_PCI_EXP_LNK_X12: + width =3D PCIE_LINK_WIDTH_12; + break; + case QEMU_PCI_EXP_LNK_X16: + width =3D PCIE_LINK_WIDTH_16; + break; + case QEMU_PCI_EXP_LNK_X32: + width =3D PCIE_LINK_WIDTH_32; + break; + default: + /* Unreachable */ + abort(); + } + + visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp); +} + +static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + Property *prop =3D opaque; + PCIExpLinkWidth *p =3D qdev_get_prop_ptr(dev, prop); + int width; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table, + errp)) { + return; + } + + switch (width) { + case PCIE_LINK_WIDTH_1: + *p =3D QEMU_PCI_EXP_LNK_X1; + break; + case PCIE_LINK_WIDTH_2: + *p =3D QEMU_PCI_EXP_LNK_X2; + break; + case PCIE_LINK_WIDTH_4: + *p =3D QEMU_PCI_EXP_LNK_X4; + break; + case PCIE_LINK_WIDTH_8: + *p =3D QEMU_PCI_EXP_LNK_X8; + break; + case PCIE_LINK_WIDTH_12: + *p =3D QEMU_PCI_EXP_LNK_X12; + break; + case PCIE_LINK_WIDTH_16: + *p =3D QEMU_PCI_EXP_LNK_X16; + break; + case PCIE_LINK_WIDTH_32: + *p =3D QEMU_PCI_EXP_LNK_X32; + break; + default: + /* Unreachable */ + abort(); + } +} + +const PropertyInfo qdev_prop_pcie_link_width =3D { + .name =3D "PCIELinkWidth", + .description =3D "1/2/4/8/12/16/32", + .enum_table =3D &PCIELinkWidth_lookup, + .get =3D get_prop_pcielinkwidth, + .set =3D set_prop_pcielinkwidth, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 37e309077a..509cbf155d 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1,20 +1,11 @@ #include "qemu/osdep.h" -#include "qemu/cutils.h" -#include "net/net.h" #include "hw/qdev-properties.h" #include "qapi/error.h" -#include "hw/pci/pci.h" -#include "qapi/qapi-types-block.h" -#include "qapi/qapi-types-machine.h" #include "qapi/qapi-types-misc.h" #include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/error-report.h" -#include "qapi/qapi-types-migration.h" -#include "hw/block/block.h" -#include "net/hub.h" #include "qapi/visitor.h" -#include "chardev/char.h" #include "qemu/uuid.h" #include "qemu/units.h" #include "qemu/cutils.h" @@ -506,174 +497,6 @@ const PropertyInfo qdev_prop_string =3D { .set =3D set_string, }; =20 -/* --- mac address --- */ - -/* - * accepted syntax versions: - * 01:02:03:04:05:06 - * 01-02-03-04-05-06 - */ -static void get_mac(Object *obj, Visitor *v, const char *name, void *opaqu= e, - Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - MACAddr *mac =3D qdev_get_prop_ptr(dev, prop); - char buffer[2 * 6 + 5 + 1]; - char *p =3D buffer; - - snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x", - mac->a[0], mac->a[1], mac->a[2], - mac->a[3], mac->a[4], mac->a[5]); - - visit_type_str(v, name, &p, errp); -} - -static void set_mac(Object *obj, Visitor *v, const char *name, void *opaqu= e, - Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - MACAddr *mac =3D qdev_get_prop_ptr(dev, prop); - int i, pos; - char *str; - const char *p; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_str(v, name, &str, errp)) { - return; - } - - for (i =3D 0, pos =3D 0; i < 6; i++, pos +=3D 3) { - long val; - - if (!qemu_isxdigit(str[pos])) { - goto inval; - } - if (!qemu_isxdigit(str[pos + 1])) { - goto inval; - } - if (i =3D=3D 5) { - if (str[pos + 2] !=3D '\0') { - goto inval; - } - } else { - if (str[pos + 2] !=3D ':' && str[pos + 2] !=3D '-') { - goto inval; - } - } - if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) { - goto inval; - } - mac->a[i] =3D val; - } - g_free(str); - return; - -inval: - error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); - g_free(str); -} - -const PropertyInfo qdev_prop_macaddr =3D { - .name =3D "str", - .description =3D "Ethernet 6-byte MAC Address, example: 52:54:00:12:34= :56", - .get =3D get_mac, - .set =3D set_mac, -}; - -/* --- Reserved Region --- */ - -/* - * Accepted syntax: - * :: - * where low/high addresses are uint64_t in hexadecimal - * and type is a non-negative decimal integer - */ -static void get_reserved_region(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); - char buffer[64]; - char *p =3D buffer; - int rc; - - rc =3D snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u", - rr->low, rr->high, rr->type); - assert(rc < sizeof(buffer)); - - visit_type_str(v, name, &p, errp); -} - -static void set_reserved_region(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - ReservedRegion *rr =3D qdev_get_prop_ptr(dev, prop); - Error *local_err =3D NULL; - const char *endptr; - char *str; - int ret; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - visit_type_str(v, name, &str, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - ret =3D qemu_strtou64(str, &endptr, 16, &rr->low); - if (ret) { - error_setg(errp, "start address of '%s'" - " must be a hexadecimal integer", name); - goto out; - } - if (*endptr !=3D ':') { - goto separator_error; - } - - ret =3D qemu_strtou64(endptr + 1, &endptr, 16, &rr->high); - if (ret) { - error_setg(errp, "end address of '%s'" - " must be a hexadecimal integer", name); - goto out; - } - if (*endptr !=3D ':') { - goto separator_error; - } - - ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &rr->type); - if (ret) { - error_setg(errp, "type of '%s'" - " must be a non-negative decimal integer", name); - } - goto out; - -separator_error: - error_setg(errp, "reserved region fields must be separated with ':'"); -out: - g_free(str); - return; -} - -const PropertyInfo qdev_prop_reserved_region =3D { - .name =3D "reserved_region", - .description =3D "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0", - .get =3D get_reserved_region, - .set =3D set_reserved_region, -}; - /* --- on/off/auto --- */ =20 const PropertyInfo qdev_prop_on_off_auto =3D { @@ -685,141 +508,6 @@ const PropertyInfo qdev_prop_on_off_auto =3D { .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 -/* --- lost tick policy --- */ - -QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) !=3D sizeof(int)); - -const PropertyInfo qdev_prop_losttickpolicy =3D { - .name =3D "LostTickPolicy", - .enum_table =3D &LostTickPolicy_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- Block device error handling policy --- */ - -QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) !=3D sizeof(int)); - -const PropertyInfo qdev_prop_blockdev_on_error =3D { - .name =3D "BlockdevOnError", - .description =3D "Error handling policy, " - "report/ignore/enospc/stop/auto", - .enum_table =3D &BlockdevOnError_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- BIOS CHS translation */ - -QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) !=3D sizeof(int)); - -const PropertyInfo qdev_prop_bios_chs_trans =3D { - .name =3D "BiosAtaTranslation", - .description =3D "Logical CHS translation algorithm, " - "auto/none/lba/large/rechs", - .enum_table =3D &BiosAtaTranslation_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- FDC default drive types */ - -const PropertyInfo qdev_prop_fdc_drive_type =3D { - .name =3D "FdcDriveType", - .description =3D "FDC drive type, " - "144/288/120/none/auto", - .enum_table =3D &FloppyDriveType_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- MultiFDCompression --- */ - -const PropertyInfo qdev_prop_multifd_compression =3D { - .name =3D "MultiFDCompression", - .description =3D "multifd_compression values, " - "none/zlib/zstd", - .enum_table =3D &MultiFDCompression_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- pci address --- */ - -/* - * bus-local address, i.e. "$slot" or "$slot.$fn" - */ -static void set_pci_devfn(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - int32_t value, *ptr =3D qdev_get_prop_ptr(dev, prop); - unsigned int slot, fn, n; - char *str; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_str(v, name, &str, NULL)) { - if (!visit_type_int32(v, name, &value, errp)) { - return; - } - if (value < -1 || value > 255) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "pci_devfn"); - return; - } - *ptr =3D value; - return; - } - - if (sscanf(str, "%x.%x%n", &slot, &fn, &n) !=3D 2) { - fn =3D 0; - if (sscanf(str, "%x%n", &slot, &n) !=3D 1) { - goto invalid; - } - } - if (str[n] !=3D '\0' || fn > 7 || slot > 31) { - goto invalid; - } - *ptr =3D slot << 3 | fn; - g_free(str); - return; - -invalid: - error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); - g_free(str); -} - -static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, - size_t len) -{ - int32_t *ptr =3D qdev_get_prop_ptr(dev, prop); - - if (*ptr =3D=3D -1) { - return snprintf(dest, len, ""); - } else { - return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7); - } -} - -const PropertyInfo qdev_prop_pci_devfn =3D { - .name =3D "int32", - .description =3D "Slot and optional function number, example: 06.0 or = 06", - .print =3D print_pci_devfn, - .get =3D get_int32, - .set =3D set_pci_devfn, - .set_default_value =3D set_default_value_int, -}; - /* --- 32bit unsigned int 'size' type --- */ =20 void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name, @@ -868,175 +556,6 @@ const PropertyInfo qdev_prop_size32 =3D { .set_default_value =3D qdev_propinfo_set_default_value_uint, }; =20 -/* --- blocksize --- */ - -/* lower limit is sector size */ -#define MIN_BLOCK_SIZE 512 -#define MIN_BLOCK_SIZE_STR "512 B" -/* - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses,= and - * matches qcow2 cluster size limit - */ -#define MAX_BLOCK_SIZE (2 * MiB) -#define MAX_BLOCK_SIZE_STR "2 MiB" - -static void set_blocksize(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - uint32_t *ptr =3D qdev_get_prop_ptr(dev, prop); - uint64_t value; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_size(v, name, &value, errp)) { - return; - } - /* value of 0 means "unset" */ - if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { - error_setg(errp, - "Property %s.%s doesn't take value %" PRIu64 - " (minimum: " MIN_BLOCK_SIZE_STR - ", maximum: " MAX_BLOCK_SIZE_STR ")", - dev->id ? : "", name, value); - return; - } - - /* We rely on power-of-2 blocksizes for bitmasks */ - if ((value & (value - 1)) !=3D 0) { - error_setg(errp, - "Property %s.%s doesn't take value '%" PRId64 "', " - "it's not a power of 2", dev->id ?: "", name, (int64_t)v= alue); - return; - } - - *ptr =3D value; -} - -const PropertyInfo qdev_prop_blocksize =3D { - .name =3D "size", - .description =3D "A power of two between " MIN_BLOCK_SIZE_STR - " and " MAX_BLOCK_SIZE_STR, - .get =3D qdev_propinfo_get_size32, - .set =3D set_blocksize, - .set_default_value =3D qdev_propinfo_set_default_value_uint, -}; - -/* --- pci host address --- */ - -static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIHostDeviceAddress *addr =3D qdev_get_prop_ptr(dev, prop); - char buffer[] =3D "ffff:ff:ff.f"; - char *p =3D buffer; - int rc =3D 0; - - /* - * Catch "invalid" device reference from vfio-pci and allow the - * default buffer representing the non-existent device to be used. - */ - if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) { - rc =3D snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d", - addr->domain, addr->bus, addr->slot, addr->function); - assert(rc =3D=3D sizeof(buffer) - 1); - } - - visit_type_str(v, name, &p, errp); -} - -/* - * Parse [:]:. - * if is not supplied, it's assumed to be 0. - */ -static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIHostDeviceAddress *addr =3D qdev_get_prop_ptr(dev, prop); - char *str, *p; - const char *e; - unsigned long val; - unsigned long dom =3D 0, bus =3D 0; - unsigned int slot =3D 0, func =3D 0; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_str(v, name, &str, errp)) { - return; - } - - p =3D str; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e =3D=3D p) { - goto inval; - } - if (*e !=3D ':') { - goto inval; - } - bus =3D val; - - p =3D (char *)e + 1; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p) { - goto inval; - } - if (*e =3D=3D ':') { - dom =3D bus; - bus =3D val; - p =3D (char *)e + 1; - if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e =3D=3D p)= { - goto inval; - } - } - slot =3D val; - - if (*e !=3D '.') { - goto inval; - } - p =3D (char *)e + 1; - if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e =3D=3D p) { - goto inval; - } - func =3D val; - - if (bus > 0xff) { - goto inval; - } - - if (*e) { - goto inval; - } - - addr->domain =3D dom; - addr->bus =3D bus; - addr->slot =3D slot; - addr->function =3D func; - - g_free(str); - return; - -inval: - error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); - g_free(str); -} - -const PropertyInfo qdev_prop_pci_host_devaddr =3D { - .name =3D "str", - .description =3D "Address (bus/device/function) of " - "the host device, example: 04:10.0", - .get =3D get_pci_host_devaddr, - .set =3D set_pci_host_devaddr, -}; - /* --- UUID --- */ =20 static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaq= ue, @@ -1286,16 +805,6 @@ void qdev_prop_set_string(DeviceState *dev, const cha= r *name, const char *value) object_property_set_str(OBJECT(dev), name, value, &error_abort); } =20 -void qdev_prop_set_macaddr(DeviceState *dev, const char *name, - const uint8_t *value) -{ - char str[2 * 6 + 5 + 1]; - snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x", - value[0], value[1], value[2], value[3], value[4], value[5]); - - object_property_set_str(OBJECT(dev), name, str, &error_abort); -} - void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) { Property *prop; @@ -1420,186 +929,3 @@ const PropertyInfo qdev_prop_link =3D { .name =3D "link", .create =3D create_link_property, }; - -/* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */ - -const PropertyInfo qdev_prop_off_auto_pcibar =3D { - .name =3D "OffAutoPCIBAR", - .description =3D "off/auto/bar0/bar1/bar2/bar3/bar4/bar5", - .enum_table =3D &OffAutoPCIBAR_lookup, - .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- PCIELinkSpeed 2_5/5/8/16 -- */ - -static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *na= me, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIExpLinkSpeed *p =3D qdev_get_prop_ptr(dev, prop); - int speed; - - switch (*p) { - case QEMU_PCI_EXP_LNK_2_5GT: - speed =3D PCIE_LINK_SPEED_2_5; - break; - case QEMU_PCI_EXP_LNK_5GT: - speed =3D PCIE_LINK_SPEED_5; - break; - case QEMU_PCI_EXP_LNK_8GT: - speed =3D PCIE_LINK_SPEED_8; - break; - case QEMU_PCI_EXP_LNK_16GT: - speed =3D PCIE_LINK_SPEED_16; - break; - default: - /* Unreachable */ - abort(); - } - - visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp); -} - -static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *na= me, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIExpLinkSpeed *p =3D qdev_get_prop_ptr(dev, prop); - int speed; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table, - errp)) { - return; - } - - switch (speed) { - case PCIE_LINK_SPEED_2_5: - *p =3D QEMU_PCI_EXP_LNK_2_5GT; - break; - case PCIE_LINK_SPEED_5: - *p =3D QEMU_PCI_EXP_LNK_5GT; - break; - case PCIE_LINK_SPEED_8: - *p =3D QEMU_PCI_EXP_LNK_8GT; - break; - case PCIE_LINK_SPEED_16: - *p =3D QEMU_PCI_EXP_LNK_16GT; - break; - default: - /* Unreachable */ - abort(); - } -} - -const PropertyInfo qdev_prop_pcie_link_speed =3D { - .name =3D "PCIELinkSpeed", - .description =3D "2_5/5/8/16", - .enum_table =3D &PCIELinkSpeed_lookup, - .get =3D get_prop_pcielinkspeed, - .set =3D set_prop_pcielinkspeed, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; - -/* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */ - -static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *na= me, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIExpLinkWidth *p =3D qdev_get_prop_ptr(dev, prop); - int width; - - switch (*p) { - case QEMU_PCI_EXP_LNK_X1: - width =3D PCIE_LINK_WIDTH_1; - break; - case QEMU_PCI_EXP_LNK_X2: - width =3D PCIE_LINK_WIDTH_2; - break; - case QEMU_PCI_EXP_LNK_X4: - width =3D PCIE_LINK_WIDTH_4; - break; - case QEMU_PCI_EXP_LNK_X8: - width =3D PCIE_LINK_WIDTH_8; - break; - case QEMU_PCI_EXP_LNK_X12: - width =3D PCIE_LINK_WIDTH_12; - break; - case QEMU_PCI_EXP_LNK_X16: - width =3D PCIE_LINK_WIDTH_16; - break; - case QEMU_PCI_EXP_LNK_X32: - width =3D PCIE_LINK_WIDTH_32; - break; - default: - /* Unreachable */ - abort(); - } - - visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp); -} - -static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *na= me, - void *opaque, Error **errp) -{ - DeviceState *dev =3D DEVICE(obj); - Property *prop =3D opaque; - PCIExpLinkWidth *p =3D qdev_get_prop_ptr(dev, prop); - int width; - - if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); - return; - } - - if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table, - errp)) { - return; - } - - switch (width) { - case PCIE_LINK_WIDTH_1: - *p =3D QEMU_PCI_EXP_LNK_X1; - break; - case PCIE_LINK_WIDTH_2: - *p =3D QEMU_PCI_EXP_LNK_X2; - break; - case PCIE_LINK_WIDTH_4: - *p =3D QEMU_PCI_EXP_LNK_X4; - break; - case PCIE_LINK_WIDTH_8: - *p =3D QEMU_PCI_EXP_LNK_X8; - break; - case PCIE_LINK_WIDTH_12: - *p =3D QEMU_PCI_EXP_LNK_X12; - break; - case PCIE_LINK_WIDTH_16: - *p =3D QEMU_PCI_EXP_LNK_X16; - break; - case PCIE_LINK_WIDTH_32: - *p =3D QEMU_PCI_EXP_LNK_X32; - break; - default: - /* Unreachable */ - abort(); - } -} - -const PropertyInfo qdev_prop_pcie_link_width =3D { - .name =3D "PCIELinkWidth", - .description =3D "1/2/4/8/12/16/32", - .enum_table =3D &PCIELinkWidth_lookup, - .get =3D get_prop_pcielinkwidth, - .set =3D set_prop_pcielinkwidth, - .set_default_value =3D qdev_propinfo_set_default_value_enum, -}; --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484647; cv=none; d=zohomail.com; s=zohoarc; b=dU7nNFDbGF4c5Wsd0i7/QlEJGjnFDuCOqxYEHlOdiZ23SgDCwMpDz7whzTyR/OKsnY7P8sh1yOUgD4y+bcTUnyIw5B0s8NOrsI8ygNcji7OIshpt1AsyXLJ6noyb1m0N5XrhGWzzT1yquVX7S+hleqhlRcOcvuTQKxEh5h0422Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484647; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=jKQQNYZ2SLgmhNgWo9hIOt2yqMJ/mPmoThVu67DVxco=; b=A/SBdsNxA3D402hIf601hmTxvi2naf0uP/eZHwG7al1WZf0/mHTytQ8yNBIlUCPbtJBUBix4LZ+9nxlJc0bBJI6YFGAoWBm2jH7FFz8BdESvpqRSXtOxuW3qWZH/UIeedGxULC08uAqCQ2Zr4qrGVha8xNE5vtYVphLjEmDjieA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601484647798188.90938460609868; Wed, 30 Sep 2020 09:50:47 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-5GZxn8MfMa6zYXYtAyH8BA-1; Wed, 30 Sep 2020 12:50:42 -0400 Received: by mail-wm1-f72.google.com with SMTP id y18so60059wma.4 for ; Wed, 30 Sep 2020 09:50:42 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id v4sm3563456wml.46.2020.09.30.09.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jKQQNYZ2SLgmhNgWo9hIOt2yqMJ/mPmoThVu67DVxco=; b=ZnVP0b1fKSHfsdk+Ls6eICcxh62wyUZAEFSAUTmGstZSKvnYV5CNc5Hg/zD+xG3+o5b3QE Skiv61VKwAxlnKL1NYc3+qWcjVCPz3zw58w079tbDRK7ZzNmrJxrzyRb0mrr8dmu2EnWCc 0i/kWY9K61A6XB4A6GmjSdNmAgfp7KQ= X-MC-Unique: 5GZxn8MfMa6zYXYtAyH8BA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jKQQNYZ2SLgmhNgWo9hIOt2yqMJ/mPmoThVu67DVxco=; b=qfU2odMXg1yk2Uw+05IBfACLq+JJA27RuhXs4Kh8dyanX7/r1TqomxdsGIrJw4AS+o LdW9kjIKZCPcT+aHgaL6z3/m3Nt3pITXrJp7+0hQqj+bgWNpR3rqJjEuTSb+vs04K7P0 rbbyqDkOqxPdjrV4DtXaBytXNhigefz/ZNOcyxv1DBKJBfpU3H/rTb+jw7aM+IoIy+8q e1mSGZS4M/WsGcAWCqgkWS/Il5f6Eloh9NAzToBk/6pgO8ZIIBcGC6gIs89KJ1iMiEHv aZxVYuwOA7MW4N/XGpRv/GJgs1JUQsAK/s5b0mLwltkS5GDAI1pdIJVzINWEmuLUS59A KjxA== X-Gm-Message-State: AOAM530/GRe1RcRyU1ZvQMlKvWpo+DZbBdCONiq6E42OYtye6KqK7P0t WNAeMq/jScAUI1iUwx6pViNDdTLYUh6U+5lsyFF0OC/oPgVyw1zDqx/N2qxbsgDwvmkevPDSQXf p13fQT9kgbLut7A== X-Received: by 2002:a5d:444e:: with SMTP id x14mr3965089wrr.235.1601484640896; Wed, 30 Sep 2020 09:50:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnLfectrjk5rOG39NVLnIV5g6+m0NSAZsv7bRIwZo2gPt9mWfr/uMfChTftCeAlsvEum05fw== X-Received: by 2002:a5d:444e:: with SMTP id x14mr3965059wrr.235.1601484640690; Wed, 30 Sep 2020 09:50:40 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 09/11] hw/core: Add qdev stub for user-mode Date: Wed, 30 Sep 2020 18:49:47 +0200 Message-Id: <20200930164949.1425294-10-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) While user-mode does not use peripherals (devices), it uses a CPU which is a device. In the next commit we will reduce the QAPI generated code for user-mode. Since qdev.c calls qapi_event_send_device_deleted() in device_finalize, let's add a stub for it. Suggested-by: Paolo Bonzini Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- v3: Meson rebase --- stubs/qdev-system.c | 24 ++++++++++++++++++++++++ stubs/meson.build | 1 + 2 files changed, 25 insertions(+) create mode 100644 stubs/qdev-system.c diff --git a/stubs/qdev-system.c b/stubs/qdev-system.c new file mode 100644 index 0000000000..2b4b54f621 --- /dev/null +++ b/stubs/qdev-system.c @@ -0,0 +1,24 @@ +/* + * QAPI qdev stubs + * + * Copyright (c) 2020 Red Hat, Inc. + * + * Author: + * Philippe Mathieu-Daud=C3=A9 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/qapi-events-qdev.h" + +void qapi_event_send_device_deleted(bool has_device, + const char *device, const char *path) +{ + /* + * Called in user-mode in fork() when a CPUState is qdev::finalize()'d. + * Simply ignore the QAPI event there. + */ +} diff --git a/stubs/meson.build b/stubs/meson.build index 2e231590e1..71d42c34d6 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -25,6 +25,7 @@ stub_ss.add(files('monitor.c')) stub_ss.add(files('monitor-core.c')) stub_ss.add(files('pci-bus.c')) stub_ss.add(files('pci-host-piix.c')) +stub_ss.add(files('qdev-system.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) stub_ss.add(files('qtest.c')) --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484653; cv=none; d=zohomail.com; s=zohoarc; b=Fh/R1m+U8ZCO7b12t3vOIAhPmhsDG+rfsepAPTnT0ahHa+h2wkcul6EvfcBYkHSNpxuolySlVVIZITFWWIDrsdMTMzBosplorxNGEh1InnG9v8bQxihXqu91FHTJR8eP0IH6T8QpYn1nNgtxNXi3iGGNQUEeytiYoH3Z999kf9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484653; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=FD/Sn/zEqk9dQKIbQoXOYve2d137UlETatSPRZNX5Dk=; b=GsfQ4uzfnhomrsWgXMtSFEB7fBK9/V32wTJVG8qeH0xGQnviq/V4xK22LCZZYtDtwEAgpccUe4jnOaYRiEn1r/VOJJOozspq33MGwa6g3h9ACRIkbLMhQd1lB5Jwm6MPCzXHmi0ClD3w/89g1R5np2hFIyfi0R30OEoH6mayba4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601484652996614.5752879401342; Wed, 30 Sep 2020 09:50:52 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-41Bq5SezMTGJ8jTMplxQ9w-1; Wed, 30 Sep 2020 12:50:48 -0400 Received: by mail-wr1-f72.google.com with SMTP id j7so828842wro.14 for ; Wed, 30 Sep 2020 09:50:47 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id o16sm3781269wrp.52.2020.09.30.09.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:45 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FD/Sn/zEqk9dQKIbQoXOYve2d137UlETatSPRZNX5Dk=; b=Ke7CGG2vYGwFU++kOcUQFupNS04LiXxSNToHXdgKrap/M2BkrwiJ9gYuz4lNhmFmkpUwa9 lb7fg7YN+DbaFXffapCftSS2BNabbAHXDnu5J2xFV53XpBUyQL9vtk287MbwdqDst+wHZv qqScLfCfOOa7hYduWZNAGTbn2jqnoZw= X-MC-Unique: 41Bq5SezMTGJ8jTMplxQ9w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FD/Sn/zEqk9dQKIbQoXOYve2d137UlETatSPRZNX5Dk=; b=VQq0C6Xc2lFGN1T33V5w98hJtRMSqbvjvbkS2UGQoH5ni2KWYCT7uPSLXfGSWbC2uN XpUjjSB0ysufi7SZQgSDCMMSoe9IZ7/0yK/+oWMC5BNHIsZ+ZHp4LD1M5D2d0SzRu9E0 SqatEg6D1kMfYZq0kaUubEwLSV1Aa2LCHNtn9uHvsTlpKDyhsb+WdlRukMGM1nKqNGvW 0dXxpCsJ0K2YIC7JOCBy/KMk/WWN75TlcyXu83WHykTYgYSKZldZ094vKBMYZ1AmHSLK LiatjJt4y0nhSPAB3bfc6CFhvWEQgpoAeLq+n5D5chzpvJ+zGS5USsdg0xsGmbHGdGsM 43Hg== X-Gm-Message-State: AOAM532RrQ4NpVpTY2O0U/KeWR1AijmRES2ISOseUy7rQO0nZnSbJDKv FJNvfPr2m3j4Uu3fN1xziQS3iLtD4hvphgrmculTTVUJDmFocyNtKLeagK/A3HeZ3SlE+0EAAwo SSIhvos4xBrZ4OA== X-Received: by 2002:adf:f0c7:: with SMTP id x7mr4010749wro.315.1601484646500; Wed, 30 Sep 2020 09:50:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHoKmzKfrCAZuzq+wwimEabmMc7cpUzoabhj+YUeLa5g0x+0zXj3Wn0hpiCmUIECSRiZA1DA== X-Received: by 2002:adf:f0c7:: with SMTP id x7mr4010725wro.315.1601484646259; Wed, 30 Sep 2020 09:50:46 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets Date: Wed, 30 Sep 2020 18:49:48 +0200 Message-Id: <20200930164949.1425294-11-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Only qemu-system-FOO and qemu-storage-daemon provide QMP monitors, therefore such declarations and definitions are irrelevant for user-mode emulation. Restricting the x86-specific commands to machine-target.json pulls less QAPI-generated code into user-mode. Add a stub to satisfy linking in user-mode: /usr/bin/ld: libqemu-i386-linux-user.fa.p/target_i386_cpu.c.o: in functio= n `x86_cpu_get_feature_words': target/i386/cpu.c:4643: undefined reference to `visit_type_X86CPUFeatureW= ordInfoList' collect2: error: ld returned 1 exit status make: *** [Makefile.ninja:1125: qemu-i386] Error 1 Acked-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. --- v3: Reworded + Meson rebase --- qapi/machine-target.json | 45 ++++++++++++++++++++++++++++++++++++++ qapi/machine.json | 42 ----------------------------------- target/i386/cpu.c | 2 +- target/i386/feature-stub.c | 23 +++++++++++++++++++ target/i386/meson.build | 1 + 5 files changed, 70 insertions(+), 43 deletions(-) create mode 100644 target/i386/feature-stub.c diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 698850cc78..b4d769a53b 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -4,6 +4,51 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. =20 +## +# @X86CPURegister32: +# +# A X86 32-bit register +# +# Since: 1.5 +## +{ 'enum': 'X86CPURegister32', + 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ], + 'if': 'defined(TARGET_I386)' } + +## +# @X86CPUFeatureWordInfo: +# +# Information about a X86 CPU feature word +# +# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature= word +# +# @cpuid-input-ecx: Input ECX value for CPUID instruction for that +# feature word +# +# @cpuid-register: Output register containing the feature bits +# +# @features: value of output register, containing the feature bits +# +# Since: 1.5 +## +{ 'struct': 'X86CPUFeatureWordInfo', + 'data': { 'cpuid-input-eax': 'int', + '*cpuid-input-ecx': 'int', + 'cpuid-register': 'X86CPURegister32', + 'features': 'int' }, + 'if': 'defined(TARGET_I386)' } + +## +# @DummyForceArrays: +# +# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally +# +# Since: 2.5 +## +{ 'struct': 'DummyForceArrays', + 'data': { 'unused': ['X86CPUFeatureWordInfo'] }, + 'if': 'defined(TARGET_I386)' } + ## # @CpuModelInfo: # diff --git a/qapi/machine.json b/qapi/machine.json index 72f014bb5b..cb878acdac 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -544,48 +544,6 @@ 'dst': 'uint16', 'val': 'uint8' }} =20 -## -# @X86CPURegister32: -# -# A X86 32-bit register -# -# Since: 1.5 -## -{ 'enum': 'X86CPURegister32', - 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } - -## -# @X86CPUFeatureWordInfo: -# -# Information about a X86 CPU feature word -# -# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature= word -# -# @cpuid-input-ecx: Input ECX value for CPUID instruction for that -# feature word -# -# @cpuid-register: Output register containing the feature bits -# -# @features: value of output register, containing the feature bits -# -# Since: 1.5 -## -{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', - 'features': 'int' } } - -## -# @DummyForceArrays: -# -# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally -# -# Since: 2.5 -## -{ 'struct': 'DummyForceArrays', - 'data': { 'unused': ['X86CPUFeatureWordInfo'] } } - ## # @NumaCpuOptions: # diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3ffd877dd5..d45fa217cc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -38,7 +38,7 @@ #include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/error.h" -#include "qapi/qapi-visit-machine.h" +#include "qapi/qapi-visit-machine-target.h" #include "qapi/qapi-visit-run-state.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" diff --git a/target/i386/feature-stub.c b/target/i386/feature-stub.c new file mode 100644 index 0000000000..787c3c7fa1 --- /dev/null +++ b/target/i386/feature-stub.c @@ -0,0 +1,23 @@ +/* + * QAPI x86 CPU features stub + * + * Copyright (c) 2020 Red Hat, Inc. + * + * Author: + * Philippe Mathieu-Daud=C3=A9 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-visit-machine-target.h" + +bool visit_type_X86CPUFeatureWordInfoList(Visitor *v, const char *name, + X86CPUFeatureWordInfoList **obj, + Error **errp) +{ + g_assert_not_reached(); +} diff --git a/target/i386/meson.build b/target/i386/meson.build index e0b71ade56..0c5d9e6caf 100644 --- a/target/i386/meson.build +++ b/target/i386/meson.build @@ -5,6 +5,7 @@ i386_ss.add(files( 'helper.c', 'xsave_helper.c', )) +i386_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('feature-stub.c')) i386_ss.add(when: 'CONFIG_TCG', if_true: files( 'bpt_helper.c', 'cc_helper.c', --=20 2.26.2 From nobody Sun Feb 8 20:35:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601484656; cv=none; d=zohomail.com; s=zohoarc; b=kd3AqKTmyTmAfUR2SZIZSZNL13nIU0jdecHfmIS7IXDd5dS7Zot6H/gjxTKI1ZsF9eIirFWn1+FUF2n2GZ3N7QnMEcfZhbDZrYZ7Ozrl9WZoBibQQppFrx57M9OSjs8JHjDEHPJjO5adDIQjvAQYH6RGxBgId+erqeRObNjfA6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601484656; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=p5T4b3uR4sPUBIFjdhNd72M+5jlOJeIdLDswdJQ0sTY=; b=Duk1E7iI5Rg8XbEGV7EbSJN8D+/kWZDgf4cPgcZhQQEsekHKku0MsiiTuxwpt4lLr6P9ov7RBjIMQI+nSw6iByl0NUxzYVt5RcSHNMBuyW12pSos3y5VHHsyZlqZluom9mAqViSChXvDd8bkKooSruFFZDGCZPjtBW11HJh20rA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601484656420902.7400056744939; Wed, 30 Sep 2020 09:50:56 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-5JplZResOha-VKsQw7smRQ-1; Wed, 30 Sep 2020 12:50:53 -0400 Received: by mail-wm1-f72.google.com with SMTP id b14so62998wmj.3 for ; Wed, 30 Sep 2020 09:50:52 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id t4sm4250032wrr.26.2020.09.30.09.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 09:50:51 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601484655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p5T4b3uR4sPUBIFjdhNd72M+5jlOJeIdLDswdJQ0sTY=; b=gu8CisHykX+emQxAml9sN63b2v25Fr0JzG5aGUS0AeQG/fWTovMhC4AefHYVCWKbcmwezA cNwvPchzVoQ/CZSaODQn53YU/HSLzf1xgzin30HvPDOVIEK8NUlHEaVXz2JbMmpU/squi2 t74oMfI5/U1OD+Sap9Pn23Tj3MwBZPc= X-MC-Unique: 5JplZResOha-VKsQw7smRQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p5T4b3uR4sPUBIFjdhNd72M+5jlOJeIdLDswdJQ0sTY=; b=onAoueWta9BtW40IeBRbTGO5MUwTm+snJVWCL3u43/PutoXI4U/6oHDODuGYY/Mhzw NGLTpQ9G5vUYBAbN4nObF9lLU3PJRhDATNSBhM9ZGZ+ylNPhDi6QpVB0txZjFV9UwBnf SyGylkBVWareiws+QEJNvp2vTU0Nan87y6OxcI1yCI6lz1hQNhgaykH466gIdtMBc7Oj UYKAT0P/RsFs153OXVhHbheuD0tu7Fnd+WzLBTuQNf9eKTrupatNQ7Ftuu03vz6iKMjY z9khiGxEEBkJ4erehc300j0xgLj8gFNaaaRCec4iiQXjFY0hpmpW/7khdMbAPeOKsAdm mMkA== X-Gm-Message-State: AOAM531TSaplcviqO+7byL75M3sB5ffEl3yU34xtEqsqlefLdacC81dy O+KUv0nuOyL/gNxs36EWy16gwpLCVNxRxRmmQ2xqLKv2cWLl6cic9juTiEbx6+yN5lKwIFVuJxs JOMMQcsoome6cRg== X-Received: by 2002:adf:fd12:: with SMTP id e18mr4250009wrr.96.1601484651954; Wed, 30 Sep 2020 09:50:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuTX+OJeaabPNkTWh+q+FjuxodYFwPUOAG87v3IdLMLDqovciEEHHgoWcyYIPkOeVRu0X9fw== X-Received: by 2002:adf:fd12:: with SMTP id e18mr4249995wrr.96.1601484651786; Wed, 30 Sep 2020 09:50:51 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Laurent Vivier Cc: Ronnie Sahlberg , Eric Blake , Kevin Wolf , Marcel Apfelbaum , Richard Henderson , Michael Roth , Eduardo Habkost , Peter Lieven , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Paolo Bonzini , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 11/11] qapi: Restrict code generated for user-mode Date: Wed, 30 Sep 2020 18:49:49 +0200 Message-Id: <20200930164949.1425294-12-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930164949.1425294-1-philmd@redhat.com> References: <20200930164949.1425294-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) A lot of QAPI generated code is never used by user-mode. Split out qapi_system_modules and qapi_system_or_tools_modules from the qapi_all_modules array. We now have 3 groups: - always used - use by system-mode or tools (usually by the block layer) - only used by system-mode Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by. Reviewed-by: Richard Henderson --- Resetting due to Meson update: Reviewed-by: Richard Henderson --- qapi/meson.build | 51 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/qapi/meson.build b/qapi/meson.build index 7c4a89a882..ba9677ba97 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -14,39 +14,60 @@ util_ss.add(files( )) =20 qapi_all_modules =3D [ + 'common', + 'introspect', + 'misc', +] + +qapi_system_modules =3D [ 'acpi', 'audio', + 'dump', + 'machine-target', + 'machine', + 'migration', + 'misc-target', + 'net', + 'pci', + 'qdev', + 'rdma', + 'rocker', + 'tpm', + 'trace', +] + +# system or tools +qapi_block_modules =3D [ 'authz', 'block-core', 'block', 'char', - 'common', 'control', 'crypto', - 'dump', 'error', - 'introspect', 'job', - 'machine', - 'machine-target', - 'migration', - 'misc', - 'misc-target', - 'net', 'pragma', - 'qdev', - 'pci', 'qom', - 'rdma', - 'rocker', 'run-state', 'sockets', - 'tpm', - 'trace', 'transaction', 'ui', ] =20 +if have_system + qapi_all_modules +=3D qapi_system_modules +elif have_user + # Temporary kludge because X86CPUFeatureWordInfo is not + # restricted to system-mode. This should be removed (along + # with target/i386/feature-stub.c) once target/i386/cpu.c + # has been cleaned. + qapi_all_modules +=3D ['machine-target'] +endif + +if have_block + qapi_all_modules +=3D qapi_block_modules +endif + qapi_storage_daemon_modules =3D [ 'block-core', 'char', --=20 2.26.2