diff mbox

vhost: replace % with & on data path

Message ID 1448872427-11623-1-git-send-email-mst@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael S. Tsirkin Nov. 30, 2015, 8:34 a.m. UTC
We know vring num is a power of 2, so use &
to mask the high bits.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/vhost.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Joe Perches Nov. 30, 2015, 8:42 a.m. UTC | #1
On Mon, 2015-11-30 at 10:34 +0200, Michael S. Tsirkin wrote:
> We know vring num is a power of 2, so use &
> to mask the high bits.
[]
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
[]
> @@ -1366,10 +1366,12 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
>  	/* Only get avail ring entries after they have been exposed by guest. */
>  	smp_rmb();
>  
> +	}

?

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kernel test robot Nov. 30, 2015, 9 a.m. UTC | #2
Hi Michael,

[auto build test ERROR on: v4.4-rc3]
[also build test ERROR on: next-20151127]

url:    https://github.com/0day-ci/linux/commits/Michael-S-Tsirkin/vhost-replace-with-on-data-path/20151130-163704
config: s390-performance_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=s390 

All errors (new ones prefixed by >>):

   drivers/vhost/vhost.c: In function 'vhost_get_vq_desc':
   drivers/vhost/vhost.c:1345:6: warning: unused variable 'ret' [-Wunused-variable]
     int ret;
         ^
   drivers/vhost/vhost.c:1344:13: warning: unused variable 'ring_head' [-Wunused-variable]
     __virtio16 ring_head;
                ^
   drivers/vhost/vhost.c:1341:24: warning: unused variable 'found' [-Wunused-variable]
     unsigned int i, head, found = 0;
                           ^
   drivers/vhost/vhost.c:1341:18: warning: unused variable 'head' [-Wunused-variable]
     unsigned int i, head, found = 0;
                     ^
   drivers/vhost/vhost.c:1341:15: warning: unused variable 'i' [-Wunused-variable]
     unsigned int i, head, found = 0;
                  ^
   drivers/vhost/vhost.c:1340:20: warning: unused variable 'desc' [-Wunused-variable]
     struct vring_desc desc;
                       ^
   drivers/vhost/vhost.c: At top level:
   drivers/vhost/vhost.c:1373:2: error: expected identifier or '(' before 'if'
     if (unlikely(__get_user(ring_head,
     ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/s390/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
>> arch/s390/include/asm/uaccess.h:250:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:166:42: note: in definition of macro 'unlikely'
    # define unlikely(x) __builtin_expect(!!(x), 0)
                                             ^
   drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
   drivers/vhost/vhost.c:1381:2: warning: data definition has no type or storage class
     head = vhost16_to_cpu(vq, ring_head);
     ^
   drivers/vhost/vhost.c:1381:2: error: type defaults to 'int' in declaration of 'head' [-Werror=implicit-int]
   drivers/vhost/vhost.c:1381:24: error: 'vq' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                           ^
   drivers/vhost/vhost.c:1381:28: error: 'ring_head' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                               ^
   drivers/vhost/vhost.c:1384:2: error: expected identifier or '(' before 'if'
     if (unlikely(head >= vq->num)) {
     ^
   drivers/vhost/vhost.c:1391:2: warning: data definition has no type or storage class
     *out_num = *in_num = 0;
     ^
   drivers/vhost/vhost.c:1391:3: error: type defaults to 'int' in declaration of 'out_num' [-Werror=implicit-int]
     *out_num = *in_num = 0;
      ^
   drivers/vhost/vhost.c:1391:14: error: 'in_num' undeclared here (not in a function)
     *out_num = *in_num = 0;
                 ^
   drivers/vhost/vhost.c:1392:2: error: expected identifier or '(' before 'if'
     if (unlikely(log))
     ^
   drivers/vhost/vhost.c:1395:2: warning: data definition has no type or storage class
     i = head;
     ^
   drivers/vhost/vhost.c:1395:2: error: type defaults to 'int' in declaration of 'i' [-Werror=implicit-int]
   drivers/vhost/vhost.c:1395:2: error: initializer element is not constant
   drivers/vhost/vhost.c:1396:2: error: expected identifier or '(' before 'do'
     do {
     ^
   drivers/vhost/vhost.c:1454:4: error: expected identifier or '(' before 'while'
     } while ((i = next_desc(vq, &desc)) != -1);
       ^
   drivers/vhost/vhost.c:1457:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
     vq->last_avail_idx++;
       ^
   In file included from arch/s390/include/asm/bug.h:69:0,
                    from include/linux/bug.h:4,
                    from include/linux/thread_info.h:11,
                    from include/asm-generic/preempt.h:4,
                    from arch/s390/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/wait.h:8,
                    from include/linux/eventfd.h:12,
                    from drivers/vhost/vhost.c:14:
   include/asm-generic/bug.h:55:27: error: expected identifier or '(' before 'do'
    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                              ^
   drivers/vhost/vhost.c:1461:2: note: in expansion of macro 'BUG_ON'
     BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
     ^
   include/asm-generic/bug.h:55:66: error: expected identifier or '(' before 'while'
    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                                                     ^
   drivers/vhost/vhost.c:1461:2: note: in expansion of macro 'BUG_ON'
     BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
     ^
   drivers/vhost/vhost.c:1462:2: error: expected identifier or '(' before 'return'
     return head;
     ^
   drivers/vhost/vhost.c:1463:1: error: expected identifier or '(' before '}' token
    }
    ^
   drivers/vhost/vhost.c:1235:12: warning: 'get_indirect' defined but not used [-Wunused-function]
    static int get_indirect(struct vhost_virtqueue *vq,
               ^
   drivers/vhost/vhost.c: In function 'vhost_get_vq_desc':
   drivers/vhost/vhost.c:1369:2: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
   cc1: some warnings being treated as errors

vim +250 arch/s390/include/asm/uaccess.h

cfa785e62 arch/s390/include/asm/uaccess.h Heiko Carstens     2014-01-22  234  					 sizeof(*(ptr)));	\
97fa5a664 include/asm-s390/uaccess.h      Al Viro            2006-02-03  235  		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
1047aa772 include/asm-s390/uaccess.h      Martin Schwidefsky 2005-11-07  236  		break;						\
1047aa772 include/asm-s390/uaccess.h      Martin Schwidefsky 2005-11-07  237  	};							\
1047aa772 include/asm-s390/uaccess.h      Martin Schwidefsky 2005-11-07  238  	case 8: {						\
1047aa772 include/asm-s390/uaccess.h      Martin Schwidefsky 2005-11-07  239  		unsigned long long __x;				\
cfa785e62 arch/s390/include/asm/uaccess.h Heiko Carstens     2014-01-22  240  		__gu_err = __get_user_fn(&__x, ptr,		\
cfa785e62 arch/s390/include/asm/uaccess.h Heiko Carstens     2014-01-22  241  					 sizeof(*(ptr)));	\
97fa5a664 include/asm-s390/uaccess.h      Al Viro            2006-02-03  242  		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  243  		break;						\
1047aa772 include/asm-s390/uaccess.h      Martin Schwidefsky 2005-11-07  244  	};							\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  245  	default:						\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  246  		__get_user_bad();				\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  247  		break;						\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  248  	}							\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  249  	__gu_err;						\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16 @250  })
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  251  
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  252  #define get_user(x, ptr)					\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  253  ({								\
dab4079d5 arch/s390/include/asm/uaccess.h Heiko Carstens     2009-06-12  254  	might_fault();						\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  255  	__get_user(x, ptr);					\
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  256  })
^1da177e4 include/asm-s390/uaccess.h      Linus Torvalds     2005-04-16  257  
4f41c2b45 arch/s390/include/asm/uaccess.h Heiko Carstens     2014-01-23  258  int __get_user_bad(void) __attribute__((noreturn));

:::::: The code at line 250 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Nov. 30, 2015, 9:05 a.m. UTC | #3
Hi Michael,

[auto build test ERROR on: v4.4-rc3]
[also build test ERROR on: next-20151127]

url:    https://github.com/0day-ci/linux/commits/Michael-S-Tsirkin/vhost-replace-with-on-data-path/20151130-163704
config: i386-randconfig-s1-201548 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   drivers/vhost/vhost.c: In function 'vhost_get_vq_desc':
>> drivers/vhost/vhost.c:1345:6: warning: unused variable 'ret' [-Wunused-variable]
     int ret;
         ^
>> drivers/vhost/vhost.c:1344:13: warning: unused variable 'ring_head' [-Wunused-variable]
     __virtio16 ring_head;
                ^
>> drivers/vhost/vhost.c:1341:24: warning: unused variable 'found' [-Wunused-variable]
     unsigned int i, head, found = 0;
                           ^
>> drivers/vhost/vhost.c:1341:18: warning: unused variable 'head' [-Wunused-variable]
     unsigned int i, head, found = 0;
                     ^
>> drivers/vhost/vhost.c:1341:15: warning: unused variable 'i' [-Wunused-variable]
     unsigned int i, head, found = 0;
                  ^
>> drivers/vhost/vhost.c:1340:20: warning: unused variable 'desc' [-Wunused-variable]
     struct vring_desc desc;
                       ^
   drivers/vhost/vhost.c: At top level:
>> drivers/vhost/vhost.c:1373:2: error: expected identifier or '(' before 'if'
     if (unlikely(__get_user(ring_head,
     ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
>> arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:137:45: note: in definition of macro 'unlikely'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
>> drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
>> arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:137:53: note: in definition of macro 'unlikely'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                        ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
>> drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
>> include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
>> drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
>> drivers/vhost/vhost.c:1381:2: warning: data definition has no type or storage class
     head = vhost16_to_cpu(vq, ring_head);
     ^
>> drivers/vhost/vhost.c:1381:2: error: type defaults to 'int' in declaration of 'head' [-Werror=implicit-int]
>> drivers/vhost/vhost.c:1381:24: error: 'vq' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                           ^
>> drivers/vhost/vhost.c:1381:28: error: 'ring_head' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                               ^
   drivers/vhost/vhost.c:1384:2: error: expected identifier or '(' before 'if'
     if (unlikely(head >= vq->num)) {
     ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
>> include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1384:6: note: in expansion of macro 'unlikely'
     if (unlikely(head >= vq->num)) {
         ^
   drivers/vhost/vhost.c:1391:2: warning: data definition has no type or storage class
     *out_num = *in_num = 0;
     ^
>> drivers/vhost/vhost.c:1391:3: error: type defaults to 'int' in declaration of 'out_num' [-Werror=implicit-int]
     *out_num = *in_num = 0;
      ^
>> drivers/vhost/vhost.c:1391:14: error: 'in_num' undeclared here (not in a function)
     *out_num = *in_num = 0;
                 ^
   drivers/vhost/vhost.c:1392:2: error: expected identifier or '(' before 'if'
     if (unlikely(log))
     ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:

vim +1373 drivers/vhost/vhost.c

d5675bd2 Michael S. Tsirkin 2010-06-24  1334   * returned on error. */
47283bef Michael S. Tsirkin 2014-06-05  1335  int vhost_get_vq_desc(struct vhost_virtqueue *vq,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1336  		      struct iovec iov[], unsigned int iov_size,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1337  		      unsigned int *out_num, unsigned int *in_num,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1338  		      struct vhost_log *log, unsigned int *log_num)
3a4d5c94 Michael S. Tsirkin 2010-01-14  1339  {
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1340  	struct vring_desc desc;
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1341  	unsigned int i, head, found = 0;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1342  	u16 last_avail_idx;
3b1bbe89 Michael S. Tsirkin 2014-10-24  1343  	__virtio16 avail_idx;
3b1bbe89 Michael S. Tsirkin 2014-10-24 @1344  	__virtio16 ring_head;
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1345  	int ret;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1346  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1347  	/* Check it isn't doing very strange things with descriptor numbers. */
3a4d5c94 Michael S. Tsirkin 2010-01-14  1348  	last_avail_idx = vq->last_avail_idx;
3b1bbe89 Michael S. Tsirkin 2014-10-24  1349  	if (unlikely(__get_user(avail_idx, &vq->avail->idx))) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1350  		vq_err(vq, "Failed to access avail idx at %p\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1351  		       &vq->avail->idx);
d5675bd2 Michael S. Tsirkin 2010-06-24  1352  		return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1353  	}
3b1bbe89 Michael S. Tsirkin 2014-10-24  1354  	vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
3a4d5c94 Michael S. Tsirkin 2010-01-14  1355  
7b3384fc Michael S. Tsirkin 2010-07-01  1356  	if (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1357  		vq_err(vq, "Guest moved used index from %u to %u",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1358  		       last_avail_idx, vq->avail_idx);
d5675bd2 Michael S. Tsirkin 2010-06-24  1359  		return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1360  	}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1361  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1362  	/* If there's nothing new since last we looked, return invalid. */
3a4d5c94 Michael S. Tsirkin 2010-01-14  1363  	if (vq->avail_idx == last_avail_idx)
3a4d5c94 Michael S. Tsirkin 2010-01-14  1364  		return vq->num;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1365  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1366  	/* Only get avail ring entries after they have been exposed by guest. */
5659338c Michael S. Tsirkin 2010-02-01  1367  	smp_rmb();
3a4d5c94 Michael S. Tsirkin 2010-01-14  1368  
07a08023 Michael S. Tsirkin 2015-11-30 @1369  	}
07a08023 Michael S. Tsirkin 2015-11-30  1370  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1371  	/* Grab the next descriptor number they're advertising, and increment
3a4d5c94 Michael S. Tsirkin 2010-01-14  1372  	 * the index we've seen. */
3b1bbe89 Michael S. Tsirkin 2014-10-24 @1373  	if (unlikely(__get_user(ring_head,
07a08023 Michael S. Tsirkin 2015-11-30  1374  				&vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1375  		vq_err(vq, "Failed to read head: idx %d address %p\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1376  		       last_avail_idx,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1377  		       &vq->avail->ring[last_avail_idx % vq->num]);
d5675bd2 Michael S. Tsirkin 2010-06-24  1378  		return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1379  	}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1380  
3b1bbe89 Michael S. Tsirkin 2014-10-24 @1381  	head = vhost16_to_cpu(vq, ring_head);
3b1bbe89 Michael S. Tsirkin 2014-10-24  1382  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1383  	/* If their number is silly, that's an error. */
7b3384fc Michael S. Tsirkin 2010-07-01 @1384  	if (unlikely(head >= vq->num)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1385  		vq_err(vq, "Guest says index %u > %u is available",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1386  		       head, vq->num);
d5675bd2 Michael S. Tsirkin 2010-06-24  1387  		return -EINVAL;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1388  	}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1389  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1390  	/* When we start there are none of either input nor output. */
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1391  	*out_num = *in_num = 0;
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1392  	if (unlikely(log))
3a4d5c94 Michael S. Tsirkin 2010-01-14  1393  		*log_num = 0;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1394  
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1395  	i = head;
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1396  	do {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1397  		unsigned iov_count = *in_num + *out_num;
7b3384fc Michael S. Tsirkin 2010-07-01  1398  		if (unlikely(i >= vq->num)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1399  			vq_err(vq, "Desc index is %u > %u, head = %u",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1400  			       i, vq->num, head);
d5675bd2 Michael S. Tsirkin 2010-06-24  1401  			return -EINVAL;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1402  		}
7b3384fc Michael S. Tsirkin 2010-07-01  1403  		if (unlikely(++found > vq->num)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1404  			vq_err(vq, "Loop detected: last one at %u "
3a4d5c94 Michael S. Tsirkin 2010-01-14  1405  			       "vq size %u head %u\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1406  			       i, vq->num, head);
d5675bd2 Michael S. Tsirkin 2010-06-24  1407  			return -EINVAL;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1408  		}
fcc042a2 Michael S. Tsirkin 2011-03-06  1409  		ret = __copy_from_user(&desc, vq->desc + i, sizeof desc);
7b3384fc Michael S. Tsirkin 2010-07-01  1410  		if (unlikely(ret)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1411  			vq_err(vq, "Failed to get descriptor: idx %d addr %p\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1412  			       i, vq->desc + i);
d5675bd2 Michael S. Tsirkin 2010-06-24  1413  			return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1414  		}
3b1bbe89 Michael S. Tsirkin 2014-10-24  1415  		if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_INDIRECT)) {
47283bef Michael S. Tsirkin 2014-06-05  1416  			ret = get_indirect(vq, iov, iov_size,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1417  					   out_num, in_num,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1418  					   log, log_num, &desc);
7b3384fc Michael S. Tsirkin 2010-07-01  1419  			if (unlikely(ret < 0)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1420  				vq_err(vq, "Failure detected "
3a4d5c94 Michael S. Tsirkin 2010-01-14  1421  				       "in indirect descriptor at idx %d\n", i);
d5675bd2 Michael S. Tsirkin 2010-06-24  1422  				return ret;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1423  			}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1424  			continue;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1425  		}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1426  
3b1bbe89 Michael S. Tsirkin 2014-10-24  1427  		ret = translate_desc(vq, vhost64_to_cpu(vq, desc.addr),
3b1bbe89 Michael S. Tsirkin 2014-10-24  1428  				     vhost32_to_cpu(vq, desc.len), iov + iov_count,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1429  				     iov_size - iov_count);
7b3384fc Michael S. Tsirkin 2010-07-01  1430  		if (unlikely(ret < 0)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1431  			vq_err(vq, "Translation failure %d descriptor idx %d\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1432  			       ret, i);
d5675bd2 Michael S. Tsirkin 2010-06-24  1433  			return ret;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1434  		}
3b1bbe89 Michael S. Tsirkin 2014-10-24  1435  		if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1436  			/* If this is an input descriptor,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1437  			 * increment that count. */
3a4d5c94 Michael S. Tsirkin 2010-01-14  1438  			*in_num += ret;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1439  			if (unlikely(log)) {
3b1bbe89 Michael S. Tsirkin 2014-10-24  1440  				log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
3b1bbe89 Michael S. Tsirkin 2014-10-24  1441  				log[*log_num].len = vhost32_to_cpu(vq, desc.len);
3a4d5c94 Michael S. Tsirkin 2010-01-14  1442  				++*log_num;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1443  			}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1444  		} else {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1445  			/* If it's an output descriptor, they're all supposed
3a4d5c94 Michael S. Tsirkin 2010-01-14  1446  			 * to come before any input descriptors. */
7b3384fc Michael S. Tsirkin 2010-07-01  1447  			if (unlikely(*in_num)) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1448  				vq_err(vq, "Descriptor has out after in: "
3a4d5c94 Michael S. Tsirkin 2010-01-14  1449  				       "idx %d\n", i);
d5675bd2 Michael S. Tsirkin 2010-06-24  1450  				return -EINVAL;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1451  			}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1452  			*out_num += ret;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1453  		}
3b1bbe89 Michael S. Tsirkin 2014-10-24 @1454  	} while ((i = next_desc(vq, &desc)) != -1);
3a4d5c94 Michael S. Tsirkin 2010-01-14  1455  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1456  	/* On success, increment avail index. */
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1457  	vq->last_avail_idx++;
8ea8cf89 Michael S. Tsirkin 2011-05-20  1458  
8ea8cf89 Michael S. Tsirkin 2011-05-20  1459  	/* Assume notifications from guest are disabled at this point,
8ea8cf89 Michael S. Tsirkin 2011-05-20  1460  	 * if they aren't we would need to update avail_event index. */
8ea8cf89 Michael S. Tsirkin 2011-05-20 @1461  	BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1462  	return head;
3a4d5c94 Michael S. Tsirkin 2010-01-14 @1463  }
6ac1afbf Asias He           2013-05-06  1464  EXPORT_SYMBOL_GPL(vhost_get_vq_desc);
3a4d5c94 Michael S. Tsirkin 2010-01-14  1465  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1466  /* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */

:::::: The code at line 1373 was first introduced by commit
:::::: 3b1bbe89351a8003857aeb5cbef3595f5d0ee609 vhost: virtio 1.0 endian-ness support

:::::: TO: Michael S. Tsirkin <mst@redhat.com>
:::::: CC: Michael S. Tsirkin <mst@redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Michael S. Tsirkin Nov. 30, 2015, 9:11 a.m. UTC | #4
On Mon, Nov 30, 2015 at 10:34:07AM +0200, Michael S. Tsirkin wrote:
> We know vring num is a power of 2, so use &
> to mask the high bits.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/vhost/vhost.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 080422f..85f0f0a 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1366,10 +1366,12 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
>  	/* Only get avail ring entries after they have been exposed by guest. */
>  	smp_rmb();
>  
> +	}
> +

Oops. This sneaked in from an unrelated patch.
Pls ignore, will repost.

>  	/* Grab the next descriptor number they're advertising, and increment
>  	 * the index we've seen. */
>  	if (unlikely(__get_user(ring_head,
> -				&vq->avail->ring[last_avail_idx % vq->num]))) {
> +				&vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
>  		vq_err(vq, "Failed to read head: idx %d address %p\n",
>  		       last_avail_idx,
>  		       &vq->avail->ring[last_avail_idx % vq->num]);
> @@ -1489,7 +1491,7 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,
>  	u16 old, new;
>  	int start;
>  
> -	start = vq->last_used_idx % vq->num;
> +	start = vq->last_used_idx & (vq->num - 1);
>  	used = vq->used->ring + start;
>  	if (count == 1) {
>  		if (__put_user(heads[0].id, &used->id)) {
> @@ -1531,7 +1533,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
>  {
>  	int start, n, r;
>  
> -	start = vq->last_used_idx % vq->num;
> +	start = vq->last_used_idx & (vq->num - 1);
>  	n = vq->num - start;
>  	if (n < count) {
>  		r = __vhost_add_used_n(vq, heads, n);
> -- 
> MST
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kernel test robot Nov. 30, 2015, 9:18 a.m. UTC | #5
Hi Michael,

[auto build test ERROR on: v4.4-rc3]
[also build test ERROR on: next-20151127]

url:    https://github.com/0day-ci/linux/commits/Michael-S-Tsirkin/vhost-replace-with-on-data-path/20151130-163704
config: x86_64-randconfig-s0-11301655 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/vhost/vhost.c: In function 'vhost_get_vq_desc':
   drivers/vhost/vhost.c:1345:6: warning: unused variable 'ret' [-Wunused-variable]
     int ret;
         ^
   drivers/vhost/vhost.c:1344:13: warning: unused variable 'ring_head' [-Wunused-variable]
     __virtio16 ring_head;
                ^
   drivers/vhost/vhost.c:1341:24: warning: unused variable 'found' [-Wunused-variable]
     unsigned int i, head, found = 0;
                           ^
   drivers/vhost/vhost.c:1341:18: warning: unused variable 'head' [-Wunused-variable]
     unsigned int i, head, found = 0;
                     ^
   drivers/vhost/vhost.c:1341:15: warning: unused variable 'i' [-Wunused-variable]
     unsigned int i, head, found = 0;
                  ^
   drivers/vhost/vhost.c:1340:20: warning: unused variable 'desc' [-Wunused-variable]
     struct vring_desc desc;
                       ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
   drivers/vhost/vhost.c: At top level:
>> include/linux/compiler.h:147:2: error: expected identifier or '(' before 'if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
     ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
   drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
   arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
   drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
   drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
   arch/x86/include/asm/uaccess.h:414:2: error: expected identifier or '(' before ')' token
    })
     ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   arch/x86/include/asm/uaccess.h:479:2: note: in expansion of macro '__get_user_nocheck'
     __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
     ^
   drivers/vhost/vhost.c:1373:15: note: in expansion of macro '__get_user'
     if (unlikely(__get_user(ring_head,
                  ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1373:6: note: in expansion of macro 'unlikely'
     if (unlikely(__get_user(ring_head,
         ^
   include/linux/compiler.h:161:3: error: expected identifier or '(' before ')' token
     }))
      ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
>> drivers/vhost/vhost.c:1373:2: note: in expansion of macro 'if'
     if (unlikely(__get_user(ring_head,
     ^
   drivers/vhost/vhost.c:1381:2: warning: data definition has no type or storage class
     head = vhost16_to_cpu(vq, ring_head);
     ^
   drivers/vhost/vhost.c:1381:2: error: type defaults to 'int' in declaration of 'head' [-Werror=implicit-int]
   drivers/vhost/vhost.c:1381:24: error: 'vq' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                           ^
   drivers/vhost/vhost.c:1381:28: error: 'ring_head' undeclared here (not in a function)
     head = vhost16_to_cpu(vq, ring_head);
                               ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
>> include/linux/compiler.h:147:2: error: expected identifier or '(' before 'if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
     ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
   drivers/vhost/vhost.c:1384:2: note: in expansion of macro 'if'
     if (unlikely(head >= vq->num)) {
     ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
   drivers/vhost/vhost.c:1384:2: note: in expansion of macro 'if'
     if (unlikely(head >= vq->num)) {
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1384:6: note: in expansion of macro 'unlikely'
     if (unlikely(head >= vq->num)) {
         ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
   drivers/vhost/vhost.c:1384:2: note: in expansion of macro 'if'
     if (unlikely(head >= vq->num)) {
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1384:6: note: in expansion of macro 'unlikely'
     if (unlikely(head >= vq->num)) {
         ^
   include/linux/compiler.h:161:3: error: expected identifier or '(' before ')' token
     }))
      ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
   drivers/vhost/vhost.c:1384:2: note: in expansion of macro 'if'
     if (unlikely(head >= vq->num)) {
     ^
   drivers/vhost/vhost.c:1391:2: warning: data definition has no type or storage class
     *out_num = *in_num = 0;
     ^
   drivers/vhost/vhost.c:1391:3: error: type defaults to 'int' in declaration of 'out_num' [-Werror=implicit-int]
     *out_num = *in_num = 0;
      ^
   drivers/vhost/vhost.c:1391:14: error: 'in_num' undeclared here (not in a function)
     *out_num = *in_num = 0;
                 ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/asm-generic/fcntl.h:4,
                    from arch/x86/include/uapi/asm/fcntl.h:1,
                    from include/uapi/linux/fcntl.h:4,
                    from include/linux/fcntl.h:4,
                    from include/linux/eventfd.h:11,
                    from drivers/vhost/vhost.c:14:
>> include/linux/compiler.h:147:2: error: expected identifier or '(' before 'if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
     ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
   drivers/vhost/vhost.c:1392:2: note: in expansion of macro 'if'
     if (unlikely(log))
     ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
   drivers/vhost/vhost.c:1392:2: note: in expansion of macro 'if'
     if (unlikely(log))
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1392:6: note: in expansion of macro 'unlikely'
     if (unlikely(log))
         ^
   include/linux/compiler.h:126:4: error: expected identifier or '(' before ')' token
      })
       ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
   drivers/vhost/vhost.c:1392:2: note: in expansion of macro 'if'
     if (unlikely(log))
     ^
   include/linux/compiler.h:137:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^
   drivers/vhost/vhost.c:1392:6: note: in expansion of macro 'unlikely'
     if (unlikely(log))
         ^
   include/linux/compiler.h:161:3: error: expected identifier or '(' before ')' token
     }))
      ^
   include/linux/compiler.h:145:23: note: in expansion of macro '__trace_if'
    #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
                          ^
   drivers/vhost/vhost.c:1392:2: note: in expansion of macro 'if'
     if (unlikely(log))
     ^
   drivers/vhost/vhost.c:1395:2: warning: data definition has no type or storage class
     i = head;
     ^
   drivers/vhost/vhost.c:1395:2: error: type defaults to 'int' in declaration of 'i' [-Werror=implicit-int]
   drivers/vhost/vhost.c:1395:6: error: initializer element is not constant
     i = head;
         ^
   drivers/vhost/vhost.c:1396:2: error: expected identifier or '(' before 'do'
     do {
     ^
   drivers/vhost/vhost.c:1454:4: error: expected identifier or '(' before 'while'
     } while ((i = next_desc(vq, &desc)) != -1);
       ^
   drivers/vhost/vhost.c:1457:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
     vq->last_avail_idx++;
       ^
   In file included from arch/x86/include/asm/bug.h:35:0,
                    from include/linux/bug.h:4,
                    from include/linux/thread_info.h:11,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:59,
                    from include/linux/spinlock.h:50,
                    from include/linux/wait.h:8,
                    from include/linux/eventfd.h:12,
                    from drivers/vhost/vhost.c:14:
   include/asm-generic/bug.h:55:27: error: expected identifier or '(' before 'do'
    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                              ^
   drivers/vhost/vhost.c:1461:2: note: in expansion of macro 'BUG_ON'
     BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
     ^
   include/asm-generic/bug.h:55:66: error: expected identifier or '(' before 'while'
    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                                                     ^
   drivers/vhost/vhost.c:1461:2: note: in expansion of macro 'BUG_ON'
     BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
     ^
   drivers/vhost/vhost.c:1462:2: error: expected identifier or '(' before 'return'
     return head;
     ^
   drivers/vhost/vhost.c:1463:1: error: expected identifier or '(' before '}' token
    }
    ^
   drivers/vhost/vhost.c:1235:12: warning: 'get_indirect' defined but not used [-Wunused-function]
    static int get_indirect(struct vhost_virtqueue *vq,
               ^
   drivers/vhost/vhost.c: In function 'vhost_get_vq_desc':
   drivers/vhost/vhost.c:1369:2: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
   cc1: some warnings being treated as errors

vim +/if +1373 drivers/vhost/vhost.c

3a4d5c94 Michael S. Tsirkin 2010-01-14  1357  		vq_err(vq, "Guest moved used index from %u to %u",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1358  		       last_avail_idx, vq->avail_idx);
d5675bd2 Michael S. Tsirkin 2010-06-24  1359  		return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1360  	}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1361  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1362  	/* If there's nothing new since last we looked, return invalid. */
3a4d5c94 Michael S. Tsirkin 2010-01-14  1363  	if (vq->avail_idx == last_avail_idx)
3a4d5c94 Michael S. Tsirkin 2010-01-14  1364  		return vq->num;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1365  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1366  	/* Only get avail ring entries after they have been exposed by guest. */
5659338c Michael S. Tsirkin 2010-02-01  1367  	smp_rmb();
3a4d5c94 Michael S. Tsirkin 2010-01-14  1368  
07a08023 Michael S. Tsirkin 2015-11-30  1369  	}
07a08023 Michael S. Tsirkin 2015-11-30  1370  
3a4d5c94 Michael S. Tsirkin 2010-01-14  1371  	/* Grab the next descriptor number they're advertising, and increment
3a4d5c94 Michael S. Tsirkin 2010-01-14  1372  	 * the index we've seen. */
3b1bbe89 Michael S. Tsirkin 2014-10-24 @1373  	if (unlikely(__get_user(ring_head,
07a08023 Michael S. Tsirkin 2015-11-30  1374  				&vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
3a4d5c94 Michael S. Tsirkin 2010-01-14  1375  		vq_err(vq, "Failed to read head: idx %d address %p\n",
3a4d5c94 Michael S. Tsirkin 2010-01-14  1376  		       last_avail_idx,
3a4d5c94 Michael S. Tsirkin 2010-01-14  1377  		       &vq->avail->ring[last_avail_idx % vq->num]);
d5675bd2 Michael S. Tsirkin 2010-06-24  1378  		return -EFAULT;
3a4d5c94 Michael S. Tsirkin 2010-01-14  1379  	}
3a4d5c94 Michael S. Tsirkin 2010-01-14  1380  
3b1bbe89 Michael S. Tsirkin 2014-10-24  1381  	head = vhost16_to_cpu(vq, ring_head);

:::::: The code at line 1373 was first introduced by commit
:::::: 3b1bbe89351a8003857aeb5cbef3595f5d0ee609 vhost: virtio 1.0 endian-ness support

:::::: TO: Michael S. Tsirkin <mst@redhat.com>
:::::: CC: Michael S. Tsirkin <mst@redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Michael S. Tsirkin Nov. 30, 2015, 9:21 a.m. UTC | #6
On Mon, Nov 30, 2015 at 12:42:49AM -0800, Joe Perches wrote:
> On Mon, 2015-11-30 at 10:34 +0200, Michael S. Tsirkin wrote:
> > We know vring num is a power of 2, so use &
> > to mask the high bits.
> []
> > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> []
> > @@ -1366,10 +1366,12 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
> >  	/* Only get avail ring entries after they have been exposed by guest. */
> >  	smp_rmb();
> >  
> > +	}
> 
> ?

Yes, I noticed this - I moved this chunk from the next patch
in my tree by mistake.

Will fix, thanks!
David Miller Nov. 30, 2015, 4:13 p.m. UTC | #7
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Mon, 30 Nov 2015 10:34:07 +0200

> We know vring num is a power of 2, so use &
> to mask the high bits.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/vhost/vhost.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 080422f..85f0f0a 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1366,10 +1366,12 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
>  	/* Only get avail ring entries after they have been exposed by guest. */
>  	smp_rmb();
>  
> +	}
> +

!!!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 080422f..85f0f0a 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1366,10 +1366,12 @@  int vhost_get_vq_desc(struct vhost_virtqueue *vq,
 	/* Only get avail ring entries after they have been exposed by guest. */
 	smp_rmb();
 
+	}
+
 	/* Grab the next descriptor number they're advertising, and increment
 	 * the index we've seen. */
 	if (unlikely(__get_user(ring_head,
-				&vq->avail->ring[last_avail_idx % vq->num]))) {
+				&vq->avail->ring[last_avail_idx & (vq->num - 1)]))) {
 		vq_err(vq, "Failed to read head: idx %d address %p\n",
 		       last_avail_idx,
 		       &vq->avail->ring[last_avail_idx % vq->num]);
@@ -1489,7 +1491,7 @@  static int __vhost_add_used_n(struct vhost_virtqueue *vq,
 	u16 old, new;
 	int start;
 
-	start = vq->last_used_idx % vq->num;
+	start = vq->last_used_idx & (vq->num - 1);
 	used = vq->used->ring + start;
 	if (count == 1) {
 		if (__put_user(heads[0].id, &used->id)) {
@@ -1531,7 +1533,7 @@  int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
 {
 	int start, n, r;
 
-	start = vq->last_used_idx % vq->num;
+	start = vq->last_used_idx & (vq->num - 1);
 	n = vq->num - start;
 	if (n < count) {
 		r = __vhost_add_used_n(vq, heads, n);