tools/virtio: fix the build and the posix_memalign() checks
cover tools/virtio: fix the build and the posix_memalign() checks
Working on other tools, I came across the fact that posix_memalign()'s return is not the standard negative error. Scanning the git repo, I came across the virtio issue with the return. Testing turned out the be broke as well, so there's a patch to fix testing prior to fixing the caller.
Liam R. Howlett (Google) (2):
tools/virtio: add a shim for linux/device-id/virtio.h tools/virtio: check posix_memalign() for failure
tools/virtio/linux/device-id/virtio.h | 2 ++ tools/virtio/linux/kernel.h | 3 ++- tools/virtio/vhost_net_test.c | 2 +- tools/virtio/virtio_test.c | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 tools/virtio/linux/device-id/virtio.h
Signature · 1 line
2.47.3
PATCH 1/2 tools/virtio: add a shim for linux/device-id/virtio.h
include/linux/virtio.h takes struct virtio_device_id from <linux/device-id/virtio.h>, which the tools build cannot find.
Add a shim for it beside the others, pointing at the real header.
--- tools/virtio/linux/device-id/virtio.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tools/virtio/linux/device-id/virtio.h
tools/virtio/linux/device-id/virtio.h new file +2 -0
@@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <../../include/linux/device-id/virtio.h>
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/2] tools/virtio: add a shim for linux/device-id/virtio.h
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
include/linux/virtio.htakes structvirtio_device_idfrom <linux/device-id/virtio.h>, which the tools build cannot find.Add a shim for it beside the others, pointing at the real header.
Fixes ecca1d63c1ea ("Replace <linux/mod_devicetable.h> by more specific <linux/device-id/*.h> (headers)")Signed-off-by Liam R. Howlett (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 tools/virtio: check posix_memalign() for failure
In reply to Liam R. Howlett (Google)posix_memalign() returns zero or a positive error number and does not set errno. virtio_test and vhost_net_test assert that the return is not negative, which will always be true, and the userspace __get_free_page() ignores it, so a failed allocation continues without setting the pointer
Assert a zero return in the tests, and return 0 from __get_free_page() on failure, as the kernel's does.
--- tools/virtio/linux/kernel.h | 3 ++- tools/virtio/vhost_net_test.c | 2 +- tools/virtio/virtio_test.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
tools/virtio/linux/kernel.h +2 -1
@@ -106,7 +106,8 @@ static inline unsigned long __get_free_page(gfp_t gfp) {void *p; -posix_memalign (&p,PAGE_SIZE ,PAGE_SIZE ); +if (posix_memalign (&p,PAGE_SIZE ,PAGE_SIZE )) +return 0 ;return (unsigned long )p; }
tools/virtio/vhost_net_test.c +1 -1
@@ -197,7 +197,7 @@ static void vq_info_add(struct vdev_info *dev, int idx, int num, int fd) info->idx = idx; info->kick =eventfd (0 ,EFD_NONBLOCK ); r =posix_memalign (&info->ring,4096 ,vring_size (num,4096 )); -assert (r >=0 ); +assert (!r);vq_reset (info, num, &dev->vdev);vhost_vq_setup (dev, info);
tools/virtio/virtio_test.c +1 -1
@@ -116,7 +116,7 @@ static void vq_info_add(struct vdev_info *dev, int num) info->kick =eventfd (0 ,EFD_NONBLOCK ); info->call =eventfd (0 ,EFD_NONBLOCK ); r =posix_memalign (&info->ring,4096 ,vring_size (num,4096 )); -assert (r >=0 ); +assert (!r);vq_reset (info, num, &dev->vdev);vhost_vq_setup (dev, info); dev->fds[info->idx].fd = info->call;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/2] tools/virtio: check posix_memalign() for failure
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
posix_memalign()returns zero or a positive error number and does not set errno.virtio_testandvhost_net_testassert that the return is not negative, which will always be true, and the userspace__get_free_page()ignores it, so a failed allocation continues without setting the pointerAssert a zero return in the tests, and return 0 from
__get_free_page()on failure, as the kernel's does.Signed-off-by Liam R. Howlett (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] tools/virtio: check posix_memalign() for failure
In reply to Liam R. Howlett (Google)Quoted 9 lines · Liam R. Howlett (Google)
posix_memalign()returns zero or a positive error number and does not set errno.virtio_testandvhost_net_testassert that the return is not negative, which will always be true, and the userspace__get_free_page()ignores it, so a failed allocation continues without setting the pointerAssert a zero return in the tests, and return 0 from
__get_free_page()on failure, as the kernel's does.
Thanks!
Quoted 51 lines
Signed-off-by Liam R. Howlett (Google) <[email protected]>--- tools/virtio/linux/kernel.h | 3 ++- tools/virtio/vhost_net_test.c | 2 +- tools/virtio/virtio_test.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)tools/virtio/linux/kernel.h +2
-1@@ -106,7 +106,8 @@ static inline unsigned long __get_free_page(gfp_t gfp) {void *p; -posix_memalign (&p,PAGE_SIZE ,PAGE_SIZE ); +if (posix_memalign (&p,PAGE_SIZE ,PAGE_SIZE )) +return 0 ;return (unsigned long )p; }tools/virtio/vhost_net_test.c +1
-1@@ -197,7 +197,7 @@ static void vq_info_add(struct vdev_info *dev, int idx, int num, int fd) info->idx = idx; info->kick =eventfd (0 ,EFD_NONBLOCK ); r =posix_memalign (&info->ring,4096 ,vring_size (num,4096 )); -assert (r >=0 ); +assert (!r);vq_reset (info, num, &dev->vdev);vhost_vq_setup (dev, info);tools/virtio/virtio_test.c +1
-2@@ -116,7 +116,7 @@ static void vq_info_add(struct vdev_info *dev, int num) info->kick =eventfd (0 ,EFD_NONBLOCK ); info->call =eventfd (0 ,EFD_NONBLOCK ); r =posix_memalign (&info->ring,4096 ,vring_size (num,4096 )); -assert (r >=0 ); +assert (!r);vq_reset (info, num, &dev->vdev);vhost_vq_setup (dev, info); dev->fds[info->idx].fd = info->call; --2.47.3