From: "Daniel P. Berrange" <berrange@redhat.com>
To: Felipe Franciosi <felipe@nutanix.com>
Cc: Marc-Andre Lureau <marcandre.lureau@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] io: Fix double shift usages on QIOChannel features
Date: Tue, 27 Sep 2016 19:04:48 +0100 [thread overview]
Message-ID: <20160927180448.GU3967@redhat.com> (raw)
In-Reply-To: <90EEF36E-117B-4103-B078-1F039A632298@nutanix.com>
On Tue, Sep 27, 2016 at 05:57:12PM +0000, Felipe Franciosi wrote:
> Hi Daniel,
>
> > On 27 Sep 2016, at 18:23, Daniel P. Berrange <berrange@redhat.com> wrote:
> >
> > On Tue, Sep 27, 2016 at 09:49:18AM -0700, Felipe Franciosi wrote:
> >> When QIOChannels were introduced in 666a3af9, the feature bits were
> >> defined shifted. However, when using them, the code was shifting them
> >> again. The incorrect use was consistent until 74b6ce43, where
> >> QIO_CHANNEL_FEATURE_LISTEN was defined shifted but tested unshifted.
> >
> > I'm more inclined to actually change the header file, so that they
> > are defined unshifted, and fix the single place that tests
> > unshifted. They are defined in an enum, so it was kind of odd to
> > use shifted values in the first place.
>
> It's not uncommon to specify shifted features/flags on enums:
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/nl80211.h#n2661
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/nvme.h#n322
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/blk-mq.h#n194
> I actually prefer defining them shifted, as proposed in my patch.
> And perhaps adding a qio_channel_set_feature() to completely
> abstract their usage. But I don't have strong preferences towards
> this and can change it if you really want me to.
I'd really prefer them to be defined unshifted, just using the
enum default value assignment.
> >> This patch fixes all uses of QIOChannel features. They are defined
> >> shifted and therefore set unshifted. It also makes all feature tests to
> >> use the qio_channel_has_feature() function.
> >
> > Switching to use of qio_channel_has_feature() is a useful, but
> > independant fix, so should be a separate commit really.
>
> Sure I can separate that in another patch. Should I also
> add a qio_channel_set_feature()? I think that's a good idea.
Yep, a set feature helper sounds like a reasonable addition.
> >
> >> {
> >> - return ioc->features & (1 << feature);
> >> + return ioc->features & feature;
> >> }
> >
> > This is logically wrong - 'feature' can now contain multiple
> > bits, but this is returning true if any single one of them
> > is present, rather than if all are present. IMHO this is an
> > example of why we should define them unshifted.
>
> This looks correct to me. It's only wrong if we change
> the definition to be unshifted, which I believe is still
> on the table. :)
You've got it reversed - with the definitions shifted
you can do
qio_channel_has_feature(ioc, A | B)
and it'll return true, even if only A is set. So if we
were to keep the definitions shifted, then you'd actually
need to have
- return ioc->features & (1 << feature);
+ (return ioc->features & feature) == feature;
but as above, I'd prefer to just have it unshifted.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
next prev parent reply other threads:[~2016-09-27 18:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-27 16:49 [Qemu-devel] [PATCH] io: Fix double shift usages on QIOChannel features Felipe Franciosi
2016-09-27 16:53 ` no-reply
2016-09-27 17:12 ` Marc-André Lureau
2016-09-28 10:55 ` Felipe Franciosi
2016-09-28 10:58 ` Marc-André Lureau
2016-09-28 11:06 ` Marc-André Lureau
2016-09-28 11:00 ` Daniel P. Berrange
2016-09-27 17:23 ` Daniel P. Berrange
2016-09-27 17:57 ` Felipe Franciosi
2016-09-27 18:04 ` Daniel P. Berrange [this message]
2016-09-27 18:16 ` Felipe Franciosi
2016-09-27 18:35 ` Felipe Franciosi
2016-09-28 9:21 ` Daniel P. Berrange
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=20160927180448.GU3967@redhat.com \
--to=berrange@redhat.com \
--cc=felipe@nutanix.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@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).