vhost: remove assertion to prevent crash
PATCH v5 1/4 vhost: remove assertion to prevent crash
Start QEMU with more DIMM devices than limit but without any vhost backends and then hotplug a vhost user backend, the VM will be crashed.
Instead of asserting in vhost_user_set_mem_table(), error number is used to gracefully prevent device to start. This fixes the crash issue.
--- hw/virtio/vhost-user.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost-user.c +4 -1
@@ -317,11 +317,14 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, &offset); fd =memory_region_get_fd (mr);if (fd >0 ) { +if (fd_num ==VHOST_MEMORY_MAX_NREGIONS ) { +error_report ("Failed preparing vhost-user memory table msg" ); +return -1 ; + } msg.payload.memory.regions[fd_num].userspace_addr = reg->userspace_addr; msg.payload.memory.regions[fd_num].memory_size = reg->memory_size; msg.payload.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset = offset; -assert (fd_num <VHOST_MEMORY_MAX_NREGIONS ); fds[fd_num++] = fd; } }
Signature · 1 line
1.8.3.1
Quoted 6 lines · On Wed, 10 Jan 2018 00:39:35 +0800 Jay Zhou <[email protected]> wrote:
Start QEMU with more DIMM devices than limit but without any vhost backends and then hotplug a vhost user backend, the VM will be crashed.
Instead of asserting invhost_user_set_mem_table(), error number is used to gracefully prevent device to start. This fixes the crash issue.
I'd rewrite commit message as following:
--
QEMU will assert on vhsot-user backed virtio device hotplug if QEMU is using more RAM regions than VHOST_MEMORY_MAX_NREGIONS (for example if it were started with a lot of DIMM devices).
Fix it by returning error instead of asserting and let callers of vhost_set_mem_table() handle error condition gracefully.
--
Quoted 28 lines
Signed-off-by Igor Mammedov <[email protected]>Signed-off-by Jay Zhou <[email protected]>--- hw/virtio/vhost-user.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/virtio/vhost-user.c +4
-1@@ -317,11 +317,14 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, &offset); fd =memory_region_get_fd (mr);if (fd >0 ) { +if (fd_num ==VHOST_MEMORY_MAX_NREGIONS ) { +error_report ("Failed preparing vhost-user memory table msg" ); +return -1 ; + } msg.payload.memory.regions[fd_num].userspace_addr = reg->userspace_addr; msg.payload.memory.regions[fd_num].memory_size = reg->memory_size; msg.payload.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset = offset; -assert (fd_num <VHOST_MEMORY_MAX_NREGIONS ); fds[fd_num++] = fd; } }
Hi Igor,
Quoted 27 lines
-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Wednesday, January 10, 2018 9:31 PM
To: Zhoujian (jay) <[email protected]>
Cc: [email protected]; Huangweidong (C) <[email protected]>; [email protected]; wangxin (U) <[email protected]>; qemu- [email protected]; Gonglei (Arei) <[email protected]>; Liuzhe (Ahriy, Euler) <[email protected]>
Subject: Re: [Qemu-devel] [PATCH v5 1/4] vhost: remove assertion to prevent crashQuoted 6 lines · On Wed, 10 Jan 2018 00:39:35 +0800 Jay Zhou <[email protected]> wrote:
Start QEMU with more DIMM devices than limit but without any vhost backends and then hotplug a vhost user backend, the VM will be crashed.
Instead of asserting invhost_user_set_mem_table(), error number is used to gracefully prevent device to start. This fixes the crash issue.I'd rewrite commit message as following:
--
QEMU will assert on vhsot-user backed virtio device hotplug if QEMU is using more RAM regions thanVHOST_MEMORY_MAX_NREGIONS(for example if it were started with a lot of DIMM devices).
Quoted 3 lines
Fix it by returning error instead of asserting and let callers of
vhost_set_mem_table()handle error condition gracefully. --
s/vhsot-user/vhost-user, otherwise much better than mine, will use it in the next version, thanks!
Jay
Quoted 33 lines
hw/virtio/vhost-user.c static int vhost_user_set_mem_table(struct vhost_dev
Quoted 13 lines
Signed-off-by Igor Mammedov <[email protected]>Signed-off-by Jay Zhou <[email protected]>--- hw/virtio/vhost-user.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/virtio/vhost-user.c index renamed from hw/virtio/vhost-user.c +0
-0093675e..8500562 100644
hw/virtio/vhost-user.c +0
-0@@ -317,11 +317,14 @@ static int vhost_user_set_mem_table(struct vhost_dev*dev,
hw/virtio/vhost-user.c static int vhost_user_set_mem_table(struct vhost_dev *dev,
Quoted 5 lines
hw/virtio/vhost-user.c +2
-0&offset); fd =memory_region_get_fd (mr);if (fd >0 ) { +if (fd_num ==VHOST_MEMORY_MAX_NREGIONS ) { + error_report("Failed preparing vhost-user memory tablemsg");
Quoted 13 lines
hw/virtio/vhost-user.c +2
-1+return -1 ; + } msg.payload.memory.regions[fd_num].userspace_addr = reg- userspace_addr; msg.payload.memory.regions[fd_num].memory_size = reg- memory_size; msg.payload.memory.regions[fd_num].guest_phys_addr = reg- guest_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset = offset; -assert (fd_num <VHOST_MEMORY_MAX_NREGIONS );fds[fd_num++] = fd; } }