usb: allow max 8192 bytes for desc
PATCH 1/1 usb: allow max 8192 bytes for desc
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (dev-video.c is ready)
Allocating memory dynamically by g_malloc of the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.
--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/desc.c +1 -1
@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ]; +uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;
Signature · 1 line
2.25.1
Quoted 18 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-0
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 8 lines
hw/usb/desc.c +1
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ]; +uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;
Quoted 19 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-0
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 8 lines
hw/usb/desc.c +1
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ]; +uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;
I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
thanks
-- PMM
Quoted 24 lines · Peter Maydell
Quoted 23 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ];
Quoted 8 lines
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 4 lines
hw/usb/desc.c +1
-0+uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
IIUC, querying USB device descriptors is not a hot path, so using heap allocation feels sufficient.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 34 lines · Daniel P. Berrangé
Quoted 24 lines · Peter Maydell
Quoted 23 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ];Quoted 8 lines
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 4 lines
hw/usb/desc.c +1
-0+uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
Quoted 3 lines
IIUC, querying USB device descriptors is not a hot path, so using heap allocation feels sufficient.
Yes, I tested this a lot, and found that it's an unlikely code path:
1, during guest startup, guest tries to probe device.
2, run 'lsusb' command in guest(or other similar commands).
The original patch and context link:
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Quoted 4 lines
Regards,
Daniel
Signature · 1 line
zhenwei pi
Quoted 40 lines · zhenwei pi
Quoted 34 lines · Daniel P. Berrangé
Quoted 24 lines · Peter Maydell
Quoted 23 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ];Quoted 8 lines
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 4 lines
hw/usb/desc.c +1
-0+uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
Quoted 3 lines
IIUC, querying USB device descriptors is not a hot path, so using heap allocation feels sufficient.
Quoted 6 lines
Yes, I tested this a lot, and found that it's an unlikely code path:
1, during guest startup, guest tries to probe device.
2, run 'lsusb' command in guest(or other similar commands).The original patch and context link:
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Yes, the orignal patch is better I think.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 48 lines · Daniel P. Berrangé
Quoted 40 lines · zhenwei pi
Quoted 34 lines · Daniel P. Berrangé
Quoted 24 lines · Peter Maydell
Quoted 23 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>--- hw/usb/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +0
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev; -uint8_t buf[256 ];Quoted 8 lines
hw/usb/desc.c int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, · line 638
Quoted 4 lines
hw/usb/desc.c +1
-0+uint8_t buf[8192 ];uint8_t type = value >>8 ;uint8_t index = value &0xff ;int flags, ret =-1 ;I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
Quoted 3 lines
IIUC, querying USB device descriptors is not a hot path, so using heap allocation feels sufficient.
Quoted 6 lines
Yes, I tested this a lot, and found that it's an unlikely code path:
1, during guest startup, guest tries to probe device.
2, run 'lsusb' command in guest(or other similar commands).The original patch and context link:
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Quoted 7 lines
Yes, the orignal patch is better I think.
Regards,
Daniel
By the way, could you please review the v2 version of "camera subsystem"?
https://patchwork.kernel.org/project/qemu-devel/cover/[email protected]/
Signature · 1 line
zhenwei pi
Quoted 37 lines · zhenwei pi
Quoted 36 lines · Daniel P. Berrangé
Quoted 34 lines · Peter Maydell
Quoted 27 lines · zhenwei pi
A device of USB video class usually uses larger desc structure, so use larger buffer to avoid failure. (
dev-video.cis ready)Allocating memory dynamically by
g_mallocof the orignal version of this change, Philippe suggested just using the stack. Test the two versions of qemu binary, the size of stack gets no change.CC Philippe Mathieu-Daudé <[email protected]>Signed-off-by zhenwei pi <[email protected]>---
hw/usb/desc.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/usb/desc.c +1
-1@@ -632,7 +632,7 @@ int usb_desc_get_descriptor(USBDevice *dev,USBPacket *p, bool msos = (dev->flags & (1 << USB_DEV_FLAG_MSOS_DESC_IN_USE)); const USBDesc *desc = usb_device_get_usb_desc(dev); const USBDescDevice *other_dev; - uint8_t buf[256]; + uint8_t buf[8192]; uint8_t type = value >> 8; uint8_t index = value & 0xff;Quoted 1 line
int flags, ret = -1;
I think 8K is too large to be allocating as an array on the stack, so if we need this buffer to be larger we should switch to some other allocation strategy for it.
Quoted 6 lines
Quoted 3 lines
IIUC, querying USB device descriptors is not a hot path, so using heap allocation feels sufficient.
Yes, I tested this a lot, and found that it's an unlikely code path:
1, during guest startup, guest tries to probe device.
2, run 'lsusb' command in guest(or other similar commands).
Sorry, I thought this was a hot path without looking at the code.
Quoted 8 lines
The original patch and context link:
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/Quoted 4 lines
Regards,
Daniel