2009-11-17 15:58:43

by Alan

[permalink] [raw]
Subject: [PATCH] vhost: Fix warnings and bad type handling

Signed-off-by: Alan Cox <[email protected]>
---

drivers/vhost/vhost.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)


diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 97233d5..46b20f7 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -334,7 +334,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
r = -EINVAL;
break;
}
- r = init_used(vq, (struct vring_used __user *)a.used_user_addr);
+ /* For 32bit we will ignore the top 32bits of the user
+ data */
+ r = init_used(vq, (struct vring_used __user *)(unsigned long)
+ a.used_user_addr);
if (r)
break;
vq->log_used = !!(a.flags & (0x1 << VHOST_VRING_F_LOG));


2009-11-22 09:39:03

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH] vhost: Fix warnings and bad type handling

On Tue, Nov 17, 2009 at 03:42:15PM +0000, Alan Cox wrote:
> Signed-off-by: Alan Cox <[email protected]>

Thanks!
Acked-by: Michael S. Tsirkin <[email protected]>

> ---
>
> drivers/vhost/vhost.c | 5 ++++-
> 1 files changed, 4 insertions(+), 1 deletions(-)
>
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 97233d5..46b20f7 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -334,7 +334,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
> r = -EINVAL;
> break;
> }
> - r = init_used(vq, (struct vring_used __user *)a.used_user_addr);
> + /* For 32bit we will ignore the top 32bits of the user
> + data */

I am not sure this comment is helpful here: we actually verify that the
top 32 bits are set to 0, a couple of lines above this:

if ((u64)(unsigned long)a.desc_user_addr != a.desc_user_addr ||
(u64)(unsigned long)a.used_user_addr != a.used_user_addr ||
(u64)(unsigned long)a.avail_user_addr != a.avail_user_addr) {
r = -EFAULT;
break;
}


> + r = init_used(vq, (struct vring_used __user *)(unsigned long)
> + a.used_user_addr);
> if (r)
> break;
> vq->log_used = !!(a.flags & (0x1 << VHOST_VRING_F_LOG));

2009-11-22 10:30:57

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH] vhost: Fix warnings and bad type handling


From: Alan Cox <[email protected]>
Subject: [PATCH] vhost: fix warnings on 32 bit systems

Fix compiler warning about discarding top 32 bit
of data on 32 bit systems, and document that
dicarded bits must be 0.

Signed-off-by: Alan Cox <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
---

So I think the below slightly tweaked version of
Alan's patch is a bit better. OK?

drivers/vhost/vhost.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 97233d5..e7b4dea 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -322,6 +322,8 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
r = -EOPNOTSUPP;
break;
}
+ /* For 32bit, verify that the top 32bits of the user
+ data are set to zero. */
if ((u64)(unsigned long)a.desc_user_addr != a.desc_user_addr ||
(u64)(unsigned long)a.used_user_addr != a.used_user_addr ||
(u64)(unsigned long)a.avail_user_addr != a.avail_user_addr) {
@@ -334,7 +336,8 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
r = -EINVAL;
break;
}
- r = init_used(vq, (struct vring_used __user *)a.used_user_addr);
+ r = init_used(vq, (struct vring_used __user *)(unsigned long)
+ a.used_user_addr);
if (r)
break;
vq->log_used = !!(a.flags & (0x1 << VHOST_VRING_F_LOG));
--
1.6.5.2.143.g8cc62

2009-11-23 02:01:46

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH] vhost: Fix warnings and bad type handling

On Sun, 22 Nov 2009 08:58:01 pm Michael S. Tsirkin wrote:
>
> From: Alan Cox <[email protected]>
> Subject: [PATCH] vhost: fix warnings on 32 bit systems
>
> Fix compiler warning about discarding top 32 bit
> of data on 32 bit systems, and document that
> dicarded bits must be 0.
>
> Signed-off-by: Alan Cox <[email protected]>
> Signed-off-by: Michael S. Tsirkin <[email protected]>
> ---
>
> So I think the below slightly tweaked version of
> Alan's patch is a bit better. OK?

Thanks, applied.

Rusty.