From: "Michael S. Tsirkin" <mst@redhat.com>
To: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, David Miller <davem@davemloft.net>,
cornelia.huck@de.ibm.com, rusty@au1.ibm.com, nab@linux-iscsi.org,
pbonzini@redhat.com, thuth@linux.vnet.ibm.com,
Rusty Russell <rusty@rustcorp.com.au>,
Brian Swetland <swetland@google.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Pawel Moll <pawel.moll@arm.com>, Ohad Ben-Cohen <ohad@wizery.com>,
Amit Shah <amit.shah@redhat.com>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux390@de.ibm.com, Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Ashutosh Dixit <ashutosh.dixit@intel.com>,
Sudeep Dutt <sudeep.dutt@intel.com>,
Siva Yerramreddy <yshivakrishna@gmail.com>,
Joel Stanley <joel@jms.id.au>,
virtualization@lists.linux-foundation.org,
lguest@lists.ozlabs.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH v5 01/45] virtio: use u32, not bitmap for struct virtio_device's features
Date: Thu, 27 Nov 2014 18:28:04 +0200 [thread overview]
Message-ID: <20141127162804.GB27124@redhat.com> (raw)
In-Reply-To: <20141127171542.3dbb2bc2@thinkpad-w530>
On Thu, Nov 27, 2014 at 05:15:42PM +0100, David Hildenbrand wrote:
> > From: Rusty Russell <rusty@rustcorp.com.au>
> >
> > It seemed like a good idea, but it's actually a pain when we get more
> > than 32 feature bits. Just change it to a u32 for now.
> >
> > Cc: Brian Swetland <swetland@google.com>
> > Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > Acked-by: Pawel Moll <pawel.moll@arm.com>
> > Acked-by: Ohad Ben-Cohen <ohad@wizery.com>
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
>
> Wouldn't it be easier to turn
> test_bit(i, dev->features)
>
> into a simple makro like
> #define test_bit(i, features) (features & (1 << i))
>
> Similar one for clear_bit and set_bit.
I don't really see why it's easier.
These wrappers resulted in a ton of code
converting from bit numbers to set_bit calls
and back.
E.g. with plan integer you can do (a|b|c)
to get a set with 3 bits.
>
> if names collide with existing functions, we could simply rename them to:
>
> set_feature_bit() ...
> clear_feature_bit() ...
In fact that's why we have BIT macro.
vdev->features & BIT_ULL(x) is only longer by 1
character than test_feature_bit(vdev, x), and
it's much clearer than a non standard wrapper.
vdev->features & (1ULL << x) is longer by 3 chars.
I guess this is a suggestion to use BIT / BIT_ULL more.
Good point.
> > diff --git a/drivers/misc/mic/card/mic_virtio.c b/drivers/misc/mic/card/mic_virtio.c
> > index e647947..0acd564 100644
> > --- a/drivers/misc/mic/card/mic_virtio.c
> > +++ b/drivers/misc/mic/card/mic_virtio.c
> > @@ -101,7 +101,7 @@ static void mic_finalize_features(struct virtio_device *vdev)
> > bits = min_t(unsigned, feature_len,
> > sizeof(vdev->features)) * 8;
> > for (i = 0; i < bits; i++) {
> > - if (test_bit(i, vdev->features))
> > + if (vdev->features & BIT(bits))
>
> Hm, shouldn't that also be "if (vdev->features & (1 << i))"?
Ouch. you are right of course. Will fix.
> > iowrite8(ioread8(&out_features[i / 8]) | (1 << (i % 8)),
> > &out_features[i / 8]);
> > }
>
> > out_free:
> > kfree(features);
> > kfree(ccw);
> > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> > index df598dd..7814b1f 100644
> > --- a/drivers/virtio/virtio.c
> > +++ b/drivers/virtio/virtio.c
> > @@ -49,9 +49,9 @@ static ssize_t features_show(struct device *_d,
> >
> > /* We actually represent this as a bitstring, as it could be
> > * arbitrary length in future. */
> > - for (i = 0; i < ARRAY_SIZE(dev->features)*BITS_PER_LONG; i++)
> > + for (i = 0; i < sizeof(dev->features)*8; i++)
>
> ... sizeof(dev->features) * 8; ...
>
> Do we have a define for 8 ?
We do: BITS_PER_BYTE.
> > len += sprintf(buf+len, "%c",
> > - test_bit(i, dev->features) ? '1' : '0');
> > + dev->features & (1ULL << i) ? '1' : '0');
> > len += sprintf(buf+len, "\n");
> > return len;
> > }
> > @@ -168,18 +168,18 @@ static int virtio_dev_probe(struct device *_d)
> > device_features = dev->config->get_features(dev);
> >
>
> [...]
>
> > @@ -483,7 +483,7 @@ int main(int argc, char *argv[])
> >
> > /* Set up host side. */
> > vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN);
> > - vringh_init_user(&vrh, vdev.features[0], RINGSIZE, true,
> > + vringh_init_user(&vrh, vdev.features, RINGSIZE, true,
> > vrh.vring.desc, vrh.vring.avail, vrh.vring.used);
> >
> > /* No descriptor to get yet... */
> > @@ -652,13 +652,13 @@ int main(int argc, char *argv[])
> > }
> >
> > /* Test weird (but legal!) indirect. */
> > - if (vdev.features[0] & (1 << VIRTIO_RING_F_INDIRECT_DESC)) {
> > + if (vdev.features & (1 << VIRTIO_RING_F_INDIRECT_DESC)) {
> > char *data = __user_addr_max - USER_MEM/4;
> > struct vring_desc *d = __user_addr_max - USER_MEM/2;
> > struct vring vring;
> >
> > /* Force creation of direct, which we modify. */
> > - vdev.features[0] &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC);
> > + vdev.features &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC);
>
> That could then be something like
>
> clear_feature_bit(VIRTIO_RING_F_INDIRECT_DESC, vdev.features);
>
> (I would prefer such makros over repeating bit actions)
That's the whole reason for the patch.
I guess you disagree with it, but it's much easier
to deal with simple integers.
> > vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true,
> > __user_addr_min,
> > never_notify_host,
>
>
> But on the whole this looks good to me.
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: rusty@au1.ibm.com, Heiko Carstens <heiko.carstens@de.ibm.com>,
Sudeep Dutt <sudeep.dutt@intel.com>,
virtualization@lists.linux-foundation.org,
linux-s390@vger.kernel.org, lguest@lists.ozlabs.org,
Arnd Bergmann <arnd@arndb.de>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Joel Stanley <joel@jms.id.au>, Pawel Moll <pawel.moll@arm.com>,
Siva Yerramreddy <yshivakrishna@gmail.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
pbonzini@redhat.com, thuth@linux.vnet.ibm.com,
Brian Swetland <swetland@google.com>,
linux-kernel@vger.kernel.org,
Ashutosh Dixit <ashutosh.dixit@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Amit Shah <amit.shah@redhat.com>,
linux390@de.ibm.com, David Miller <davem@davemloft.net>
Subject: Re: [PATCH v5 01/45] virtio: use u32, not bitmap for struct virtio_device's features
Date: Thu, 27 Nov 2014 18:28:04 +0200 [thread overview]
Message-ID: <20141127162804.GB27124@redhat.com> (raw)
In-Reply-To: <20141127171542.3dbb2bc2@thinkpad-w530>
On Thu, Nov 27, 2014 at 05:15:42PM +0100, David Hildenbrand wrote:
> > From: Rusty Russell <rusty@rustcorp.com.au>
> >
> > It seemed like a good idea, but it's actually a pain when we get more
> > than 32 feature bits. Just change it to a u32 for now.
> >
> > Cc: Brian Swetland <swetland@google.com>
> > Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > Acked-by: Pawel Moll <pawel.moll@arm.com>
> > Acked-by: Ohad Ben-Cohen <ohad@wizery.com>
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
>
> Wouldn't it be easier to turn
> test_bit(i, dev->features)
>
> into a simple makro like
> #define test_bit(i, features) (features & (1 << i))
>
> Similar one for clear_bit and set_bit.
I don't really see why it's easier.
These wrappers resulted in a ton of code
converting from bit numbers to set_bit calls
and back.
E.g. with plan integer you can do (a|b|c)
to get a set with 3 bits.
>
> if names collide with existing functions, we could simply rename them to:
>
> set_feature_bit() ...
> clear_feature_bit() ...
In fact that's why we have BIT macro.
vdev->features & BIT_ULL(x) is only longer by 1
character than test_feature_bit(vdev, x), and
it's much clearer than a non standard wrapper.
vdev->features & (1ULL << x) is longer by 3 chars.
I guess this is a suggestion to use BIT / BIT_ULL more.
Good point.
> > diff --git a/drivers/misc/mic/card/mic_virtio.c b/drivers/misc/mic/card/mic_virtio.c
> > index e647947..0acd564 100644
> > --- a/drivers/misc/mic/card/mic_virtio.c
> > +++ b/drivers/misc/mic/card/mic_virtio.c
> > @@ -101,7 +101,7 @@ static void mic_finalize_features(struct virtio_device *vdev)
> > bits = min_t(unsigned, feature_len,
> > sizeof(vdev->features)) * 8;
> > for (i = 0; i < bits; i++) {
> > - if (test_bit(i, vdev->features))
> > + if (vdev->features & BIT(bits))
>
> Hm, shouldn't that also be "if (vdev->features & (1 << i))"?
Ouch. you are right of course. Will fix.
> > iowrite8(ioread8(&out_features[i / 8]) | (1 << (i % 8)),
> > &out_features[i / 8]);
> > }
>
> > out_free:
> > kfree(features);
> > kfree(ccw);
> > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> > index df598dd..7814b1f 100644
> > --- a/drivers/virtio/virtio.c
> > +++ b/drivers/virtio/virtio.c
> > @@ -49,9 +49,9 @@ static ssize_t features_show(struct device *_d,
> >
> > /* We actually represent this as a bitstring, as it could be
> > * arbitrary length in future. */
> > - for (i = 0; i < ARRAY_SIZE(dev->features)*BITS_PER_LONG; i++)
> > + for (i = 0; i < sizeof(dev->features)*8; i++)
>
> ... sizeof(dev->features) * 8; ...
>
> Do we have a define for 8 ?
We do: BITS_PER_BYTE.
> > len += sprintf(buf+len, "%c",
> > - test_bit(i, dev->features) ? '1' : '0');
> > + dev->features & (1ULL << i) ? '1' : '0');
> > len += sprintf(buf+len, "\n");
> > return len;
> > }
> > @@ -168,18 +168,18 @@ static int virtio_dev_probe(struct device *_d)
> > device_features = dev->config->get_features(dev);
> >
>
> [...]
>
> > @@ -483,7 +483,7 @@ int main(int argc, char *argv[])
> >
> > /* Set up host side. */
> > vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN);
> > - vringh_init_user(&vrh, vdev.features[0], RINGSIZE, true,
> > + vringh_init_user(&vrh, vdev.features, RINGSIZE, true,
> > vrh.vring.desc, vrh.vring.avail, vrh.vring.used);
> >
> > /* No descriptor to get yet... */
> > @@ -652,13 +652,13 @@ int main(int argc, char *argv[])
> > }
> >
> > /* Test weird (but legal!) indirect. */
> > - if (vdev.features[0] & (1 << VIRTIO_RING_F_INDIRECT_DESC)) {
> > + if (vdev.features & (1 << VIRTIO_RING_F_INDIRECT_DESC)) {
> > char *data = __user_addr_max - USER_MEM/4;
> > struct vring_desc *d = __user_addr_max - USER_MEM/2;
> > struct vring vring;
> >
> > /* Force creation of direct, which we modify. */
> > - vdev.features[0] &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC);
> > + vdev.features &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC);
>
> That could then be something like
>
> clear_feature_bit(VIRTIO_RING_F_INDIRECT_DESC, vdev.features);
>
> (I would prefer such makros over repeating bit actions)
That's the whole reason for the patch.
I guess you disagree with it, but it's much easier
to deal with simple integers.
> > vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true,
> > __user_addr_min,
> > never_notify_host,
>
>
> But on the whole this looks good to me.
next prev parent reply other threads:[~2014-11-27 16:28 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 12:29 [PATCH v5 00/45] linux: towards virtio-1 guest support Michael S. Tsirkin
2014-11-27 12:29 ` [PATCH v5 01/45] virtio: use u32, not bitmap for struct virtio_device's features Michael S. Tsirkin
2014-11-27 12:29 ` Michael S. Tsirkin
2014-11-27 16:15 ` David Hildenbrand
2014-11-27 16:15 ` David Hildenbrand
2014-11-27 16:28 ` Michael S. Tsirkin [this message]
2014-11-27 16:28 ` Michael S. Tsirkin
2014-11-27 16:34 ` David Hildenbrand
2014-11-27 16:34 ` David Hildenbrand
2014-11-27 12:30 ` [PATCH v5 02/45] mic_virtio: robust feature array size calculation Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 03/45] virtio: add support for 64 bit features Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 04/45] virtio: assert 32 bit features in transports Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 05/45] virtio_ccw: add support for 64 bit features Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 06/45] virtio: add virtio 1.0 feature bit Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 07/45] virtio: memory access APIs Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 08/45] virtio_ring: switch to new " Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 09/45] virtio_config: endian conversion for v1.0 Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:30 ` [PATCH v5 10/45] virtio: allow transports to get avail/used addresses Michael S. Tsirkin
2014-11-27 12:30 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 11/45] virtio: set FEATURES_OK Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 12/45] virtio: simplify feature bit handling Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 13/45] virtio: add legacy feature table support Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 14/45] virtio_net: v1.0 endianness Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 15/45] virtio_blk: v1.0 support Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 16/45] KVM: s390: Set virtio-ccw transport revision Michael S. Tsirkin
2014-11-27 16:01 ` David Hildenbrand
2014-11-27 12:31 ` [PATCH v5 17/45] KVM: s390: virtio-ccw revision 1 SET_VQ Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 18/45] KVM: s390 allow virtio_ccw status writes to fail Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 19/45] KVM: s390: enable virtio-ccw revision 1 Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 20/45] virtio_blk: make serial attribute static Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 21/45] virtio_blk: fix race at module removal Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:31 ` [PATCH v5 22/45] virtio_net: pass vi around Michael S. Tsirkin
2014-11-27 12:31 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 23/45] virtio_net: get rid of virtio_net_hdr/skb_vnet_hdr Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 24/45] virtio_net: stricter short buffer length checks Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 25/45] virtio_net: bigger header when VERSION_1 is set Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 26/45] virtio_net: enable v1.0 support Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 27/45] vhost: make features 64 bit Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 28/45] vhost: add memory access wrappers Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 29/45] vhost/net: force len for TX to host endian Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 30/45] vhost: virtio 1.0 endian-ness support Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 31/45] vhost/net: virtio 1.0 byte swap Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 32/45] vhost/net: larger header for virtio 1.0 Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 33/45] virtio_net: disable mac write " Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 34/45] vhost/net: enable " Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:32 ` [PATCH v5 35/45] vhost/net: suppress compiler warning Michael S. Tsirkin
2014-11-27 12:32 ` Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 36/45] tun: move internal flag defines out of uapi Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 37/45] tun: drop most type defines Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 38/45] tun: add VNET_LE flag Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 39/45] tun: TUN_VNET_LE support, fix sparse warnings for virtio headers Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 40/45] macvtap: TUN_VNET_HDR support Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 41/45] virtio_scsi: v1.0 support Michael S. Tsirkin
2014-11-27 12:33 ` Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 42/45] virtio_scsi: move to uapi Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 43/45] virtio_scsi: export to userspace Michael S. Tsirkin
2014-11-27 12:33 ` Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 44/45] vhost/scsi: partial virtio 1.0 support Michael S. Tsirkin
2014-11-27 12:33 ` Michael S. Tsirkin
2014-11-27 12:33 ` [PATCH v5 45/45] af_packet: virtio 1.0 stubs Michael S. Tsirkin
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=20141127162804.GB27124@redhat.com \
--to=mst@redhat.com \
--cc=amit.shah@redhat.com \
--cc=arnd@arndb.de \
--cc=ashutosh.dixit@intel.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dahi@linux.vnet.ibm.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=heiko.carstens@de.ibm.com \
--cc=joel@jms.id.au \
--cc=lguest@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux390@de.ibm.com \
--cc=nab@linux-iscsi.org \
--cc=ohad@wizery.com \
--cc=pawel.moll@arm.com \
--cc=pbonzini@redhat.com \
--cc=rusty@au1.ibm.com \
--cc=rusty@rustcorp.com.au \
--cc=schwidefsky@de.ibm.com \
--cc=sudeep.dutt@intel.com \
--cc=swetland@google.com \
--cc=thuth@linux.vnet.ibm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=yshivakrishna@gmail.com \
/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.