Skip to contentSkip to conversation

vhost: Fix warnings and bad type handling

PATCH Applied Alan Cox 3 participants 6 messages Nov 17, 2009 – Nov 23, 2009

Subsystems (3)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 vhost: Fix warnings and bad type handling

---

 drivers/vhost/vhost.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/vhost/vhost.c +4 -1
index 97233d5..46b20f7 100644
@@ -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));
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Alan Cox

Thanks!

Quoted 11 lines

---

 drivers/vhost/vhost.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/vhost/vhost.c +0 -0
index 97233d5..46b20f7 100644

drivers/vhost/vhost.c static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) · line 338

Quoted 6 lines
drivers/vhost/vhost.c +2 -1
@@ -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;
                }
Quoted 5 lines
drivers/vhost/vhost.c +2 -0
+		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));
#2 lore raw
In reply to Alan Cox

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.

---

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(-)
drivers/vhost/vhost.c +4 -1
index 97233d5..e7b4dea 100644
@@ -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));
Signature · 1 line
1.6.5.2.143.g8cc62
#3 lore raw
Quoted 8 lines · Michael S. Tsirkin

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.

Quoted 6 lines

---

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

Thanks, applied.

Rusty.

#4 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

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.

Quoted 6 lines

---

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

Thanks, applied.

Rusty.

#5 lore raw
In reply to Alan Cox

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.

---

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(-)
drivers/vhost/vhost.c +4 -1
index 97233d5..e7b4dea 100644
@@ -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));
Signature · 1 line
1.6.5.2.143.g8cc62