vhost: add ioctl to query nregions upper limit
Subsystems (6)
Michael S. Tsirkin
maintainerRFC PATCH 1/1 vhost: add ioctl to query nregions upper limit
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)
include/uapi/linux/vhost.h +16 -1
@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */
@@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. +* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0 +/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64 +/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device.
drivers/vhost/vhost.c +5 -0
@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd; +if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);
Signature · 1 line
MST
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin"…
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments.
include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0
is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see way
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64
^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/
Quoted 20 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +5
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd; +if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);
Michael S. Tsirkin
maintainerQuoted 57 lines · Igor Mammedov
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin"…
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see way
Quoted 5 lines
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/
The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
OTOH if you won't think it's useful, let me know.
Quoted 20 lines
Quoted 20 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +5
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd; +if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);
Quoted 64 lines · On Wed, 24 Jun 2015 16:17:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 57 lines · Igor Mammedov
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see wayQuoted 5 lines
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/
Quoted 4 lines
The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
OTOH if you won't think it's useful, let me know.
this header will be synced into QEMU's tree so that we could use this define there, isn't it? IMHO then _LEGACY is more exact description of macro.
As for 0 return value, -1 is just fine for detecting old kernels (i.e. try and see if it works), so 0 looks unnecessary but it doesn't in any way hurt either. For me limit or -1 is enough to try fix userspace.
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +0
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd;Quoted 8 lines
drivers/vhost/vhost.c long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) · line 927
Quoted 8 lines
drivers/vhost/vhost.c +5
-0+if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin
maintainerQuoted 70 lines · Igor Mammedov
Quoted 67 lines · On Wed, 24 Jun 2015 16:17:46 +0200 "Michael S. Tsirkin"…
Quoted 57 lines · Igor Mammedov
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin"…
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see wayQuoted 5 lines
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
Quoted 6 lines
Quoted 1 line
OTOH if you won't think it's useful, let me know.
this header will be synced into QEMU's tree so that we could use this define there, isn't it? IMHO then
_LEGACYis more exact description of macro.As for 0 return value, -1 is just fine for detecting old kernels (i.e. try and see if it works), so 0 looks unnecessary but it doesn't in any way hurt either. For me limit or -1 is enough to try fix userspace.
OK.
Do you want to try now before I do v2?
Quoted 25 lines
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +0
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd;Quoted 8 lines
drivers/vhost/vhost.c long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) · line 927
Quoted 8 lines
drivers/vhost/vhost.c +5
-0+if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 84 lines · On Wed, 24 Jun 2015 17:08:56 +0200 "Michael S. Tsirkin"…
Quoted 83 lines · Igor Mammedov
Quoted 69 lines · On Wed, 24 Jun 2015 16:17:46 +0200 "Michael S. Tsirkin"…
Quoted 68 lines · Igor Mammedov
Quoted 54 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin"…
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/include/uapi/linux/vhost.hindex ab373191..f71fa6d 100644include/uapi/linux/vhost.h +1
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also
VHOST_GET_MEM_MAX_NREGIONSbelow. */ #defineVHOST_SET_MEM_TABLE_IOW(VHOST_VIRTIO,0x03, structvhost_memory) /* Write logging setup. */include/uapi/linux/vhost.h +1
-0@@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments.
+ * Returns:
+ * 0 < value <=MAX_INT- gives the upper limit,
higher values will fail
+ * 0 - there's no static limit: try and see if it
works
+ * -1 - on failure
+ */include/uapi/linux/vhost.h +3
-0+#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no Quoted 3 lines
static limit:
+ * try and it'll work if you are lucky. */
+#defineVHOST_MEM_MAX_NREGIONS_NONE0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see wayQuoted 5 lines
+/* We support at least as many nregions in
VHOST_SET_MEM_TABLE:
+ * for use on legacy kernels withoutVHOST_GET_MEM_MAX_NREGIONSsupport. */ +#defineVHOST_MEM_MAX_NREGIONS_DEFAULT64Quoted 7 lines
Quoted 2 lines
^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
OTOH if you won't think it's useful, let me know.
this header will be synced into QEMU's tree so that we could use this define there, isn't it? IMHO then
_LEGACYis more exact description of macro.
Quoted 7 lines
Quoted 4 lines
As for 0 return value, -1 is just fine for detecting old kernels (i.e. try and see if it works), so 0 looks unnecessary but it doesn't in any way hurt either. For me limit or -1 is enough to try fix userspace.
OK.
Do you want to try now before I do v2?
I've just tried, idea to check limit is unusable in this case. here is a link to a patch that implements it:
https://github.com/imammedo/qemu/commits/vhost_slot_limit_check
slots count is changing dynamically depending on used devices and more importantly guest OS could change slots count during its runtime when during managing devices it could trigger repartitioning of current memory table as device's memory regions mapped into address space.
That leads to 2 different values of used slots at guest startup time and after guest booted or after hotplug.
I my case guest could be started with max 58 DIMMs coldplugged, but after boot 3 more slots are freed and it's possible to hotadd 3 more DIMMs. That however leads to the guest that can't be migrated to since by QEMU design all hotplugged devices should be present at target's startup time i.e. 60 DIMMs total and that obviously goes above vhost limit at that time.
Other issue with it is that QEMU could report only current limit to mgmt tools, so they can't know for sure how many slots exactly they can allow user to set when creating VM and will have to guess or create a VM with unusable/under provisioned slots.
We have a similar limit check for kvm memslots but that is never exercised path since we rose limit in kernel to 509 (similar issues), over-provisioning it in about 2 times of currently possible userspace consumption.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 14 lines
Quoted 14 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +0
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) long r;int i, fd;Quoted 8 lines
drivers/vhost/vhost.c long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) · line 927
Quoted 8 lines
drivers/vhost/vhost.c +5
-0+if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 84 lines · On Wed, 24 Jun 2015 17:08:56 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 83 lines · Igor Mammedov
Quoted 69 lines · On Wed, 24 Jun 2015 16:17:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 68 lines · Igor Mammedov
Quoted 54 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/include/uapi/linux/vhost.hindex ab373191..f71fa6d 100644include/uapi/linux/vhost.h +1
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also
VHOST_GET_MEM_MAX_NREGIONSbelow. */ #defineVHOST_SET_MEM_TABLE_IOW(VHOST_VIRTIO,0x03, structvhost_memory) /* Write logging setup. */include/uapi/linux/vhost.h +1
-0@@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments.
+ * Returns:
+ * 0 < value <=MAX_INT- gives the upper limit,
higher values will fail
+ * 0 - there's no static limit: try and see if it
works
+ * -1 - on failure
+ */include/uapi/linux/vhost.h +3
-0+#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no Quoted 3 lines
static limit:
+ * try and it'll work if you are lucky. */
+#defineVHOST_MEM_MAX_NREGIONS_NONE0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see wayQuoted 5 lines
+/* We support at least as many nregions in
VHOST_SET_MEM_TABLE:
+ * for use on legacy kernels withoutVHOST_GET_MEM_MAX_NREGIONSsupport. */ +#defineVHOST_MEM_MAX_NREGIONS_DEFAULT64Quoted 7 lines
Quoted 2 lines
^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
OTOH if you won't think it's useful, let me know.
this header will be synced into QEMU's tree so that we could use this define there, isn't it? IMHO then
_LEGACYis more exact description of macro.
Quoted 7 lines
Quoted 4 lines
As for 0 return value, -1 is just fine for detecting old kernels (i.e. try and see if it works), so 0 looks unnecessary but it doesn't in any way hurt either. For me limit or -1 is enough to try fix userspace.
OK.
Do you want to try now before I do v2?
I've just tried, idea to check limit is unusable in this case. here is a link to a patch that implements it:
https://github.com/imammedo/qemu/commits/vhost_slot_limit_check
slots count is changing dynamically depending on used devices and more importantly guest OS could change slots count during its runtime when during managing devices it could trigger repartitioning of current memory table as device's memory regions mapped into address space.
That leads to 2 different values of used slots at guest startup time and after guest booted or after hotplug.
I my case guest could be started with max 58 DIMMs coldplugged, but after boot 3 more slots are freed and it's possible to hotadd 3 more DIMMs. That however leads to the guest that can't be migrated to since by QEMU design all hotplugged devices should be present at target's startup time i.e. 60 DIMMs total and that obviously goes above vhost limit at that time.
Other issue with it is that QEMU could report only current limit to mgmt tools, so they can't know for sure how many slots exactly they can allow user to set when creating VM and will have to guess or create a VM with unusable/under provisioned slots.
We have a similar limit check for kvm memslots but that is never exercised path since we rose limit in kernel to 509 (similar issues), over-provisioning it in about 2 times of currently possible userspace consumption.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 14 lines
Quoted 14 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +0
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) long r;int i, fd;Quoted 8 lines
drivers/vhost/vhost.c long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) · line 927
Quoted 8 lines
drivers/vhost/vhost.c +5
-0+if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin
maintainerQuoted 70 lines · Igor Mammedov
Quoted 67 lines · On Wed, 24 Jun 2015 16:17:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 57 lines · Igor Mammedov
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see wayQuoted 5 lines
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
Quoted 6 lines
Quoted 1 line
OTOH if you won't think it's useful, let me know.
this header will be synced into QEMU's tree so that we could use this define there, isn't it? IMHO then
_LEGACYis more exact description of macro.As for 0 return value, -1 is just fine for detecting old kernels (i.e. try and see if it works), so 0 looks unnecessary but it doesn't in any way hurt either. For me limit or -1 is enough to try fix userspace.
OK.
Do you want to try now before I do v2?
Quoted 25 lines
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +0
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd;Quoted 8 lines
drivers/vhost/vhost.c long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) · line 927
Quoted 8 lines
drivers/vhost/vhost.c +5
-0+if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin
maintainerQuoted 57 lines · Igor Mammedov
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments. include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see way
Quoted 5 lines
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/
The assumption was that userspace detecting old kernels will just use 64, this means we do want a flag to get the old way.
OTOH if you won't think it's useful, let me know.
Quoted 20 lines
Quoted 20 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +5
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd; +if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);
Quoted 41 lines · On Wed, 24 Jun 2015 15:49:27 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Userspace currently simply tries to give vhost as many regions as it happens to have, but you only have the mem table when you have initialized a large part of VM, so graceful failure is very hard to support.
The result is that userspace tends to fail catastrophically.
Instead, add a new ioctl so userspace can find out how much kernel supports, up front. This returns a positive value that we commit to.
Also, document our contract with legacy userspace: when running on an old kernel, you get -1 and you can assume at least 64 slots. Since 0 value's left unused, let's make that mean that the current userspace behaviour (trial and error) is required, just in case we want it back.
Signed-off-by Michael S. Tsirkin <[email protected]>Cc Igor Mammedov <[email protected]>Cc Paolo Bonzini <[email protected]>--- include/uapi/linux/vhost.h | 17 ++++++++++++++++- drivers/vhost/vhost.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)include/uapi/linux/vhost.h +2
-1@@ -80,7 +80,7 @@ struct vhost_memory {* Allows subsequent call to VHOST_OWNER_SET to succeed. */ #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) -/* Set up/modify memory layout */ +/* Set up/modify memory layout: see also VHOST_GET_MEM_MAX_NREGIONS below. */ #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)/* Write logging setup. */ @@ -127,6 +127,21 @@ struct vhost_memory {/* Set eventfd to signal an error */ #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) +/* Query upper limit on nregions in VHOST_SET_MEM_TABLE arguments.
include/uapi/linux/vhost.h struct vhost_memory { · line 140
Quoted 10 lines
include/uapi/linux/vhost.h +10
-0+* Returns: +* 0 < value <= MAX_INT - gives the upper limit, higher values will fail +* 0 - there's no static limit: try and see if it works +* -1 - on failure +*/ +#define VHOST_GET_MEM_MAX_NREGIONS _IO(VHOST_VIRTIO, 0x23) + +/* Returned by VHOST_GET_MEM_MAX_NREGIONS to mean there's no static limit: +* try and it'll work if you are lucky. */ +#define VHOST_MEM_MAX_NREGIONS_NONE 0
is it needed? we always have a limit,
or don't have IOCTL => -1 => old try and see way
include/uapi/linux/vhost.h struct vhost_memory { · line 143
Quoted 3 lines
include/uapi/linux/vhost.h +3
-0+/* We support at least as many nregions in VHOST_SET_MEM_TABLE: +* for use on legacy kernels without VHOST_GET_MEM_MAX_NREGIONS support. */ +#define VHOST_MEM_MAX_NREGIONS_DEFAULT 64
^^^ not used below,
if it's for legacy then perhaps s/DEFAULT/LEGACY/
Quoted 20 lines
include/uapi/linux/vhost.h +1
-0+/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device. drivers/vhost/vhost.c +5
-0@@ -917,6 +917,11 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)long r;int i, fd; +if (ioctl ==VHOST_GET_MEM_MAX_NREGIONS ) { + r =VHOST_MEMORY_MAX_NREGIONS ; + goto done; + } +/* If you are not the owner, you can become one */ if (ioctl ==VHOST_SET_OWNER ) { r =vhost_dev_set_owner (d);