All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms
@ 2017-03-21 22:31 Andrew Baumann
  2017-03-21 22:51 ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Baumann @ 2017-03-21 22:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S . Tsirkin, Stefan Weil, Andrew Baumann

"long" is 32-bits on win32, but we need to promote it to a 64-bit hwaddr
before negating, or else the top half of the address is truncated

Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
---
 include/hw/virtio/virtio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 15efcf2..a0a8543 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -34,7 +34,7 @@ struct VirtQueue;
 static inline hwaddr vring_align(hwaddr addr,
                                              unsigned long align)
 {
-    return (addr + align - 1) & ~(align - 1);
+    return (addr + align - 1) & ~(hwaddr)(align - 1);
 }
 
 typedef struct VirtQueue VirtQueue;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms
  2017-03-21 22:31 [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms Andrew Baumann
@ 2017-03-21 22:51 ` Eric Blake
  2017-03-21 23:06   ` Andrew Baumann
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2017-03-21 22:51 UTC (permalink / raw)
  To: Andrew Baumann, qemu-devel; +Cc: Stefan Weil, Michael S . Tsirkin

[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]

On 03/21/2017 05:31 PM, Andrew Baumann wrote:
> "long" is 32-bits on win32, but we need to promote it to a 64-bit hwaddr
> before negating, or else the top half of the address is truncated
> 
> Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
> ---
>  include/hw/virtio/virtio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 15efcf2..a0a8543 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -34,7 +34,7 @@ struct VirtQueue;
>  static inline hwaddr vring_align(hwaddr addr,
>                                               unsigned long align)
>  {
> -    return (addr + align - 1) & ~(align - 1);
> +    return (addr + align - 1) & ~(hwaddr)(align - 1);

Why not just use the QEMU_ALIGN_DOWN macro, instead of open-coding it?

(Hmm - a good BiteSized task might be to come up with a Coccinelle
script to help replace all open-coded rounding functions with
appropriate macro calls instead)

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms
  2017-03-21 22:51 ` Eric Blake
@ 2017-03-21 23:06   ` Andrew Baumann
  2017-03-22  6:11     ` Stefan Weil
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Baumann @ 2017-03-21 23:06 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: Stefan Weil, Michael S . Tsirkin

> From: Eric Blake [mailto:eblake@redhat.com]
> Sent: Tuesday, 21 March 2017 15:52
> 
> On 03/21/2017 05:31 PM, Andrew Baumann wrote:
> > "long" is 32-bits on win32, but we need to promote it to a 64-bit hwaddr
> > before negating, or else the top half of the address is truncated
> >
> > Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
> > ---
> >  include/hw/virtio/virtio.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> > index 15efcf2..a0a8543 100644
> > --- a/include/hw/virtio/virtio.h
> > +++ b/include/hw/virtio/virtio.h
> > @@ -34,7 +34,7 @@ struct VirtQueue;
> >  static inline hwaddr vring_align(hwaddr addr,
> >                                               unsigned long align)
> >  {
> > -    return (addr + align - 1) & ~(align - 1);
> > +    return (addr + align - 1) & ~(hwaddr)(align - 1);
> 
> Why not just use the QEMU_ALIGN_DOWN macro, instead of open-coding it?

Well, this code is aligning up, but yes the ALIGN_UP macro looks like it should also avoid the type promotion problem. This patch is just the minimally-invasive change after discovering the bug.

Let me know if you want me to spin another patch with the macro.

Andrew


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms
  2017-03-21 23:06   ` Andrew Baumann
@ 2017-03-22  6:11     ` Stefan Weil
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Weil @ 2017-03-22  6:11 UTC (permalink / raw)
  To: Andrew Baumann, Eric Blake, qemu-devel; +Cc: Michael S . Tsirkin

Am 22.03.2017 um 00:06 schrieb Andrew Baumann:
>> From: Eric Blake [mailto:eblake@redhat.com]
>> Sent: Tuesday, 21 March 2017 15:52
>>
>> On 03/21/2017 05:31 PM, Andrew Baumann wrote:
>>> "long" is 32-bits on win32, but we need to promote it to a 64-bit hwaddr
>>> before negating, or else the top half of the address is truncated
>>>
>>> Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
>>> ---
>>>  include/hw/virtio/virtio.h | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
>>> index 15efcf2..a0a8543 100644
>>> --- a/include/hw/virtio/virtio.h
>>> +++ b/include/hw/virtio/virtio.h
>>> @@ -34,7 +34,7 @@ struct VirtQueue;
>>>  static inline hwaddr vring_align(hwaddr addr,
>>>                                               unsigned long align)
>>>  {
>>> -    return (addr + align - 1) & ~(align - 1);
>>> +    return (addr + align - 1) & ~(hwaddr)(align - 1);
>>
>> Why not just use the QEMU_ALIGN_DOWN macro, instead of open-coding it?
>
> Well, this code is aligning up, but yes the ALIGN_UP macro looks like it should also avoid the type promotion problem. This patch is just the minimally-invasive change after discovering the bug.
>
> Let me know if you want me to spin another patch with the macro.
>
> Andrew

Yes, please use QEMU_ALIGN_UP in an updated patch.
This is a bug fix needed for v2.9.0.

Fixing all other code locations which round up or down
with Coccinelle is a separate task, nothing which is
needed for the next QEMU version.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-22  6:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 22:31 [Qemu-devel] [PATCH] virtio: fix vring_align() on 64-bit win32 platforms Andrew Baumann
2017-03-21 22:51 ` Eric Blake
2017-03-21 23:06   ` Andrew Baumann
2017-03-22  6:11     ` Stefan Weil

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.