All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 11/17] object: use more specific property type names
Date: Wed, 31 May 2017 15:18:58 +0200	[thread overview]
Message-ID: <87inkh88ql.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAJ+F1CK5OgaH6SRcPnhPxrHOWHq3YE28o3y_+tPwJsYkT5PsSQ@mail.gmail.com> (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Tue, 30 May 2017 13:58:09 +0000")

Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Wed, May 17, 2017 at 12:50 PM Markus Armbruster <armbru@redhat.com>
> wrote:
>
>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>>
>> > Use the actual unsigned integer type name (this should't break since
>> > property type aren't directly accessed from outside it seems).
>>
>> I'm not sure I understand the parenthesis.  Do you mean changing the
>> type names is safe because they're used only in a certain way?  Which
>> way?
>>
>
> It looks like prop->type is only used internally by qom/object.c and not
> exposed to QMP or other internal APIs, it would be nice if someone more
> familiar with it could confirm.

I see.  I can have a look once I'm done catching up with your replies.

>> How did you find the names that need fixing?
>
> Mostly by grepping and reviewing the code, I don't have a better approach..

Can't think of a better way offhand.  If something comes to me, I'll let
you know.  Thanks for going the extra mile!

>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> >  backends/cryptodev.c |  2 +-
>> >  hw/pci-host/piix.c   |  8 ++++----
>> >  hw/pci-host/q35.c    | 10 +++++-----
>> >  hw/ppc/pnv.c         |  2 +-
>> >  net/dump.c           |  2 +-
>> >  net/filter-buffer.c  |  2 +-
>> >  6 files changed, 13 insertions(+), 13 deletions(-)
>> >
>> > diff --git a/backends/cryptodev.c b/backends/cryptodev.c
>> > index 832f056266..1764c179fe 100644
>> > --- a/backends/cryptodev.c
>> > +++ b/backends/cryptodev.c
>> > @@ -222,7 +222,7 @@ cryptodev_backend_can_be_deleted(UserCreatable *uc, Error **errp)
>> >
>> >  static void cryptodev_backend_instance_init(Object *obj)
>> >  {
>> > -    object_property_add(obj, "queues", "int",
>> > +    object_property_add(obj, "queues", "uint32",
>> >                            cryptodev_backend_get_queues,
>> >                            cryptodev_backend_set_queues,
>> >                            NULL, NULL, NULL);
>>
>> Correct, because the callbacks access struct CryptoDevBackendPeers
>> member queues, which is uint32_t.
>>
>> The callbacks pass a local variable instead of the struct member to the
>> visitor.  Problematic, because it weakens the type checking we get from
>> the compiler.  Let's tighten it up:
>>
>>    static void
>>    cryptodev_backend_get_queues(Object *obj, Visitor *v, const char *name,
>>                                 void *opaque, Error **errp)
>>    {
>>        CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
>>   -    uint32_t value = backend->conf.peers.queues;
>>
>>   -    visit_type_uint32(v, name, &value, errp);
>>   +    visit_type_uint32(v, name, &backend->conf.peers.queues, errp);
>>    }
>>
>>    static void
>>    cryptodev_backend_set_queues(Object *obj, Visitor *v, const char *name,
>>                                 void *opaque, Error **errp)
>>    {
>>        CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
>>        Error *local_err = NULL;
>>   -    uint32_t value;
>>
>>   -    visit_type_uint32(v, name, &value, &local_err);
>>   +    visit_type_uint32(v, name, &backend->conf.peers.queues, &local_err);
>>        if (local_err) {
>>            goto out;
>>        }
>>   -    if (!value) {
>>   +    if (!backend->conf.peers.queues) {
>>            error_setg(&local_err, "Property '%s.%s' doesn't take value '%"
>>   -                   PRIu32 "'", object_get_typename(obj), name, value);
>>   +                   PRIu32 "'", object_get_typename(obj), name,
>>   +                   backend->conf.peers.queues);
>>   -        goto out;
>>        }
>>   -    backend->conf.peers.queues = value;
>>   -out:
>>        error_propagate(errp, local_err);
>>    }
>>
>> If we need to preserve backend->conf.peers.queue on an attempt to set it
>> to zero, things get a bit more complicated.  But having the compiler
>> enforce the visitor matches the member type exactly is worth it, in my
>> opinion.
>>
>> Separate patch, not necessarily in this series.
>>
>> > diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
>> > index f9218aa952..9aed6225bf 100644
>> > --- a/hw/pci-host/piix.c
>> > +++ b/hw/pci-host/piix.c
>> > @@ -279,19 +279,19 @@ static void i440fx_pcihost_initfn(Object *obj)
>> >      memory_region_init_io(&s->data_mem, obj, &pci_host_data_le_ops, s,
>> >                            "pci-conf-data", 4);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32",
>> >                          i440fx_pcihost_get_pci_hole_start,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "uint32",
>> >                          i440fx_pcihost_get_pci_hole_end,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "uint64",
>> >                          i440fx_pcihost_get_pci_hole64_start,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "uint64",
>> >                          i440fx_pcihost_get_pci_hole64_end,
>> >                          NULL, NULL, NULL, NULL);
>> >  }
>>
>> These look good.  The underlying values are 64 bits, but the 32 bit
>> callbacks assert they fit into 32.
>>
>> > diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
>> > index 344f77b10c..5438be8253 100644
>> > --- a/hw/pci-host/q35.c
>> > +++ b/hw/pci-host/q35.c
>> > @@ -176,23 +176,23 @@ static void q35_host_initfn(Object *obj)
>> >      qdev_prop_set_uint32(DEVICE(&s->mch), "addr", PCI_DEVFN(0, 0));
>> >      qdev_prop_set_bit(DEVICE(&s->mch), "multifunction", false);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32",
>> >                          q35_host_get_pci_hole_start,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_END, "uint32",
>> >                          q35_host_get_pci_hole_end,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_START, "uint64",
>> >                          q35_host_get_pci_hole64_start,
>> >                          NULL, NULL, NULL, NULL);
>> >
>> > -    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "int",
>> > +    object_property_add(obj, PCI_HOST_PROP_PCI_HOLE64_END, "uint64",
>> >                          q35_host_get_pci_hole64_end,
>> >                          NULL, NULL, NULL, NULL);
>>
>> Likewise.
>>
>> >
>> > -    object_property_add(obj, PCIE_HOST_MCFG_SIZE, "int",
>> > +    object_property_add(obj, PCIE_HOST_MCFG_SIZE, "uint32",
>> >                          q35_host_get_mmcfg_size,
>> >                          NULL, NULL, NULL, NULL);
>>
>> This one leads to a bug, I think:
>>
>>    static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, const char
>> *name,
>>                                        void *opaque, Error **errp)
>>    {
>>        PCIExpressHost *e = PCIE_HOST_BRIDGE(obj);
>>        uint32_t value = e->size;
>>
>>        visit_type_uint32(v, name, &value, errp);
>>    }
>>
>> e->size is hwaddr, i.e. uint64_t.  We silently truncate.
>>
>> Demonstrates that the detour through a separate variable breeds bugs and
>> should be avoided.
>>
>> Suggested fix:
>>
>>    static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, const char
>> *name,
>>                                        void *opaque, Error **errp)
>>    {
>>        PCIExpressHost *e = PCIE_HOST_BRIDGE(obj);
>>   -    uint32_t value = e->size;
>>
>>   -    visit_type_uint64(v, name, &value, errp);
>>   +    visit_type_uint64(v, name, &e->size, errp);
>>    }
>>
>> You then have to change the type name to "uint64" instead of "uint32",
>> of course.
>>
>
> Ok, although this bug exist before the type name change, right? I'll make
> it a seperate patch

Yes, please.

[...]

  reply	other threads:[~2017-05-31 13:19 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09 17:35 [Qemu-devel] [PATCH 00/17] qobject/qapi: add uint type Marc-André Lureau
2017-05-09 17:35 ` [Qemu-devel] [PATCH 01/17] qdev: remove PropertyInfo.qtype field Marc-André Lureau
2017-05-09 18:40   ` Eric Blake
2017-05-11 11:59     ` Markus Armbruster
2017-05-11 12:07       ` Paolo Bonzini
2017-05-09 17:35 ` [Qemu-devel] [PATCH 02/17] object: fix potential leak in getters Marc-André Lureau
2017-05-09 18:44   ` Eric Blake
2017-05-09 17:35 ` [Qemu-devel] [PATCH 03/17] tests: remove alt num-int cases Marc-André Lureau
2017-05-09 18:51   ` Eric Blake
2017-05-11 12:34     ` Markus Armbruster
2017-05-22 17:03   ` Markus Armbruster
2017-05-30  3:40     ` Fam Zheng
2017-05-30 14:17       ` Eric Blake
2017-05-09 17:35 ` [Qemu-devel] [PATCH 04/17] qapi: merge QInt and QFloat in QNum Marc-André Lureau
2017-05-11 14:29   ` Markus Armbruster
2017-05-11 15:09     ` Eric Blake
2017-05-30  7:32     ` Marc-André Lureau
2017-05-30 14:19       ` Eric Blake
2017-05-30 14:23       ` Markus Armbruster
2017-05-30 15:36         ` Marc-André Lureau
2017-06-02  6:30           ` Markus Armbruster
2017-06-02 11:18             ` Marc-André Lureau
2017-05-12  6:30   ` Markus Armbruster
2017-05-12 13:00     ` Luiz Capitulino
2017-05-15  7:00       ` Markus Armbruster
2017-05-12  7:37   ` Markus Armbruster
2017-05-12 13:03     ` Luiz Capitulino
2017-05-15  6:35       ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 05/17] qapi: remove promote_int Marc-André Lureau
2017-05-11 17:30   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 06/17] qnum: add uint type Marc-André Lureau
2017-05-15  7:27   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 07/17] json: learn to parse uint64 numbers Marc-André Lureau
2017-05-15 13:59   ` Markus Armbruster
2017-05-30 11:35     ` Marc-André Lureau
2017-05-30 14:22       ` Eric Blake
2017-05-31  7:38         ` Marc-André Lureau
2017-05-31 10:08       ` Markus Armbruster
2017-05-31 10:53         ` Marc-André Lureau
2017-05-09 17:35 ` [Qemu-devel] [PATCH 08/17] qapi: update the qobject visitor to use QUInt Marc-André Lureau
2017-05-16 17:31   ` Markus Armbruster
2017-05-17 16:26     ` Markus Armbruster
2017-05-30 12:28     ` Marc-André Lureau
2017-05-31 13:10       ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 09/17] qnum: fix get_int() with values > INT64_MAX Marc-André Lureau
2017-05-16 17:35   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 10/17] object: add uint property setter/getter Marc-André Lureau
2017-05-16 17:41   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 11/17] object: use more specific property type names Marc-André Lureau
2017-05-17  8:49   ` Markus Armbruster
2017-05-30 13:58     ` Marc-André Lureau
2017-05-31 13:18       ` Markus Armbruster [this message]
2017-05-09 17:35 ` [Qemu-devel] [PATCH 12/17] qdev: use int and uint properties as appropriate Marc-André Lureau
2017-05-17 11:09   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 13/17] qdev: use appropriate getter/setters type Marc-André Lureau
2017-05-17 17:42   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 14/17] acpi: fix s3/s4 disabled type Marc-André Lureau
2017-05-13 20:49   ` Philippe Mathieu-Daudé
2017-05-18 12:57   ` Markus Armbruster
2017-05-31 11:10     ` Marc-André Lureau
2017-05-31 13:23       ` Markus Armbruster
2017-05-31 13:26         ` Marc-André Lureau
2017-05-09 17:35 ` [Qemu-devel] [PATCH 15/17] Use uint property getter/setter where appropriate Marc-André Lureau
2017-05-18 15:20   ` Markus Armbruster
2017-05-31 12:22     ` Marc-André Lureau
2017-05-09 17:35 ` [Qemu-devel] [PATCH 16/17] RFC: qdict: add uint Marc-André Lureau
2017-05-18 15:27   ` Markus Armbruster
2017-05-09 17:35 ` [Qemu-devel] [PATCH 17/17] qobject: move dump_qobject() from block/ to qobject/ Marc-André Lureau
2017-05-13 21:41 ` [Qemu-devel] [PATCH 00/17] qobject/qapi: add uint type no-reply
2017-05-18 15:39 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87inkh88ql.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.