qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: fam@euphon.net, pbonzini@redhat.com,
	Amey Narkhede <ameynarkhede03@gmail.com>,
	dmitry.fleytman@gmail.com, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/scsi/vmw_pvscsi.c: Fix wrong usage of gboolean types in PVSCSIState
Date: Tue, 15 Sep 2020 20:00:09 +0100	[thread overview]
Message-ID: <20200915190009.GF2922@work-vm> (raw)
In-Reply-To: <bee146be-e867-6c6f-4007-b61751be1e6c@redhat.com>

* Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
> Hi Amey,
> 
> On 9/14/20 1:44 AM, Amey Narkhede wrote:
> > rings_info_valid, msg_ring_info_valid and use_msg fields of struct
> > PVSCSIState are using gboolean TRUE/FALSE values with the type uint8_t.
> > Change their type to bool along with the usage of initialization macro
> > VMSTATE_BOOL during initialization of vmstate_pvscsi and
> > pvscsi_properties.
> > 
> > Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
> > ---
> >  hw/scsi/vmw_pvscsi.c | 22 +++++++++++-----------
> >  1 file changed, 11 insertions(+), 11 deletions(-)
> > 
> > diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
> > index c071e0c7aa..86f00e3d7e 100644
> > --- a/hw/scsi/vmw_pvscsi.c
> > +++ b/hw/scsi/vmw_pvscsi.c
> > @@ -123,9 +123,9 @@ typedef struct {
> >      /* Collector for current command data */
> >      uint32_t curr_cmd_data[PVSCSI_MAX_CMD_DATA_WORDS];
> > 
> > -    uint8_t rings_info_valid;            /* Whether data rings initialized   */
> > -    uint8_t msg_ring_info_valid;         /* Whether message ring initialized */
> > -    uint8_t use_msg;                     /* Whether to use message ring      */
> > +    bool rings_info_valid;            /* Whether data rings initialized   */
> > +    bool msg_ring_info_valid;         /* Whether message ring initialized */
> > +    bool use_msg;                     /* Whether to use message ring      */
> > 
> >      uint8_t msi_used;                    /* For migration compatibility      */
> >      PVSCSIRingInfo rings;                /* Data transfer rings manager      */
> > @@ -349,8 +349,8 @@ pvscsi_reset_state(PVSCSIState *s)
> >      s->reg_command_status = PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
> >      s->reg_interrupt_status = 0;
> >      pvscsi_ring_cleanup(&s->rings);
> > -    s->rings_info_valid = FALSE;
> > -    s->msg_ring_info_valid = FALSE;
> > +    s->rings_info_valid = false;
> > +    s->msg_ring_info_valid = false;
> >      QTAILQ_INIT(&s->pending_queue);
> >      QTAILQ_INIT(&s->completion_queue);
> >  }
> > @@ -792,7 +792,7 @@ pvscsi_on_cmd_setup_rings(PVSCSIState *s)
> >      pvscsi_dbg_dump_tx_rings_config(rc);
> >      pvscsi_ring_init_data(&s->rings, rc);
> > 
> > -    s->rings_info_valid = TRUE;
> > +    s->rings_info_valid = true;
> >      return PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
> >  }
> > 
> > @@ -874,7 +874,7 @@ pvscsi_on_cmd_setup_msg_ring(PVSCSIState *s)
> >          if (pvscsi_ring_init_msg(&s->rings, rc) < 0) {
> >              return PVSCSI_COMMAND_PROCESSING_FAILED;
> >          }
> > -        s->msg_ring_info_valid = TRUE;
> > +        s->msg_ring_info_valid = true;
> >      }
> >      return sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t);
> >  }
> > @@ -1232,9 +1232,9 @@ static const VMStateDescription vmstate_pvscsi = {
> >          VMSTATE_UINT32(curr_cmd_data_cntr, PVSCSIState),
> >          VMSTATE_UINT32_ARRAY(curr_cmd_data, PVSCSIState,
> >                               ARRAY_SIZE(((PVSCSIState *)NULL)->curr_cmd_data)),
> > -        VMSTATE_UINT8(rings_info_valid, PVSCSIState),
> > -        VMSTATE_UINT8(msg_ring_info_valid, PVSCSIState),
> > -        VMSTATE_UINT8(use_msg, PVSCSIState),
> > +        VMSTATE_BOOL(rings_info_valid, PVSCSIState),
> > +        VMSTATE_BOOL(msg_ring_info_valid, PVSCSIState),
> > +        VMSTATE_BOOL(use_msg, PVSCSIState),
> 
> I believe this change the migration data structure. This
> area is described in "Changing migration data structures"
> in docs/devel/migration.rst.
> 
> If this structure were not affected, your change would be
> a good cleanup. However changing migration can become a
> nightmare, so ... cleaning this is hard.
> 
> Cc'ing Dave (a migration maintainer) as I'm not sure there
> already is a document describing easily this problem.

Well; the migration structures are...very unstructured.
It turns out that VMSTATE_BOOL already reads/writes a raw
byte to the file - so it's the same size as the VMSTATE_UINT8 at least.
Disappointingly get_bool and put_bool in vmstate-types.c don't do any
sanitation either; so you get whatever the raw value is.

glib's FALSE/TRUE is:

#define FALSE   (0)
#define TRUE    (!FALSE)

so that's probably fine;  as long as no one does anything silly like
compare the value with TRUE or true.

Dave

> > 
> >          VMSTATE_UINT64(rings.rs_pa, PVSCSIState),
> >          VMSTATE_UINT32(rings.txr_len_mask, PVSCSIState),
> > @@ -1255,7 +1255,7 @@ static const VMStateDescription vmstate_pvscsi = {
> >  };
> > 
> >  static Property pvscsi_properties[] = {
> > -    DEFINE_PROP_UINT8("use_msg", PVSCSIState, use_msg, 1),
> > +    DEFINE_PROP_BOOL("use_msg", PVSCSIState, use_msg, true),
> >      DEFINE_PROP_BIT("x-old-pci-configuration", PVSCSIState, compat_flags,
> >                      PVSCSI_COMPAT_OLD_PCI_CONFIGURATION_BIT, false),
> >      DEFINE_PROP_BIT("x-disable-pcie", PVSCSIState, compat_flags,
> > --
> > 2.28.0
> > 
> > This is my first qemu patch. Let know if there are any mistakes
> > 
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



      parent reply	other threads:[~2020-09-15 19:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13 23:44 [PATCH] hw/scsi/vmw_pvscsi.c: Fix wrong usage of gboolean types in PVSCSIState Amey Narkhede
2020-09-14  6:32 ` Philippe Mathieu-Daudé
2020-09-14  9:13   ` Amey Narkhede
2020-09-15 19:00   ` Dr. David Alan Gilbert [this message]

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=20200915190009.GF2922@work-vm \
    --to=dgilbert@redhat.com \
    --cc=ameynarkhede03@gmail.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=fam@euphon.net \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).