Drivers: hv: balloon: account for vmbus packet header in max_pkt_size
Subsystems (2)
PATCH 1/1 Drivers: hv: balloon: account for vmbus packet header in max_pkt_size
Commit adae1e931acd ("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer") introduced a notion of maximum packet size in vmbus channel and used that size to initialize a buffer holding all incoming packet along with their vmbus packet header. hv_balloon uses the default maximum packet size VMBUS_DEFAULT_MAX_PKT_SIZE which matches its maximum message size, however vmbus_open expects this size to also include vmbus packet header. This leads to 4096 bytes dm_unballoon_request messages being truncated to 4080 bytes. When the driver tries to read next packet it starts from a wrong read_index, receives garbage and prints a lot of "Unhandled message: type:
<garbage>" in dmesg.
Allocate the buffer with HV_HYP_PAGE_SIZE more bytes to make room for the header.
---
The patch was "[PATCH v2] hv: account for packet descriptor in maximum packet size". As pointed out by Michael Kelley [1], other hv drivers already overallocate a lot, and hv_balloon is hopefully the only remaining affected driver. It's better to just fix hv_balloon. Patch summary is changed to reflect this new (much smaller) scope.
drivers/hv/hv_balloon.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hv/hv_balloon.c +7 -0
@@ -1660,6 +1660,13 @@ static int balloon_connect_vsp(struct hv_device *dev)unsigned long t;int ret; +/* +* max_pkt_size should be large enough for one vmbus packet header plus +* our receive buffer size. Hyper-V sends messages up to +* HV_HYP_PAGE_SIZE bytes long on balloon channel. +*/ + dev->channel->max_pkt_size =HV_HYP_PAGE_SIZE *2 ; + ret =vmbus_open (dev->channel, dm_ring_size, dm_ring_size,NULL ,0 , balloon_onchannelcallback, dev);if (ret)
Signature · 1 line
2.34.1
From: Yanming Liu <[email protected]> Sent: Wednesday, January 19, 2022 12:21 PM
Quoted 53 lines
Commit
adae1e931acd("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer") introduced a notion of maximum packet size in vmbus channel and used that size to initialize a buffer holding all incoming packet along with their vmbus packet header.hv_balloonuses the default maximum packet sizeVMBUS_DEFAULT_MAX_PKT_SIZEwhich matches its maximum message size, howevervmbus_openexpects this size to also include vmbus packet header. This leads to 4096 bytesdm_unballoon_requestmessages being truncated to 4080 bytes. When the driver tries to read next packet it starts from a wrongread_index, receives garbage and prints a lot of "Unhandled message: type:
<garbage>" in dmesg.Allocate the buffer with
HV_HYP_PAGE_SIZEmore bytes to make room for the header.Fixes adae1e931acd ("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of thering buffer")
Suggested-by Michael Kelley (LINUX) <[email protected]>Suggested-by Andrea Parri (Microsoft) <[email protected]>Signed-off-by Yanming Liu <[email protected]>---
The patch was "[PATCH v2] hv: account for packet descriptor in maximum packet size". As pointed out by Michael Kelley [1], other hv drivers already overallocate a lot, andhv_balloonis hopefully the only remaining affected driver. It's better to just fixhv_balloon. Patch summary is changed to reflect this new (much smaller) scope.drivers/hv/hv_balloon.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/hv/hv_balloon.c +7
-1@@ -1660,6 +1660,13 @@ static int balloon_connect_vsp(struct hv_device *dev)unsigned long t;int ret; +/* +* max_pkt_size should be large enough for one vmbus packet header plus +* our receive buffer size. Hyper-V sends messages up to +* HV_HYP_PAGE_SIZE bytes long on balloon channel. +*/ + dev->channel->max_pkt_size =HV_HYP_PAGE_SIZE *2 ; + ret =vmbus_open (dev->channel, dm_ring_size, dm_ring_size,NULL ,0 , balloon_onchannelcallback, dev);if (ret) --
Quoted 1 line
2.34.1
Quoted 19 lines · Yanming Liu
Commit
adae1e931acd("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer") introduced a notion of maximum packet size in vmbus channel and used that size to initialize a buffer holding all incoming packet along with their vmbus packet header.hv_balloonuses the default maximum packet sizeVMBUS_DEFAULT_MAX_PKT_SIZEwhich matches its maximum message size, howevervmbus_openexpects this size to also include vmbus packet header. This leads to 4096 bytesdm_unballoon_requestmessages being truncated to 4080 bytes. When the driver tries to read next packet it starts from a wrongread_index, receives garbage and prints a lot of "Unhandled message: type:
<garbage>" in dmesg.Allocate the buffer with
HV_HYP_PAGE_SIZEmore bytes to make room for the header.Fixes adae1e931acd ("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer")Suggested-by Michael Kelley (LINUX) <[email protected]>Suggested-by Andrea Parri (Microsoft) <[email protected]>Signed-off-by Yanming Liu <[email protected]>
Quoted 6 lines
---
The patch was "[PATCH v2] hv: account for packet descriptor in maximum packet size". As pointed out by Michael Kelley [1], other hv drivers already overallocate a lot, andhv_balloonis hopefully the only remaining affected driver. It's better to just fixhv_balloon. Patch summary is changed to reflect this new (much smaller) scope.
hopefully - adeguately describing what/how we "know" (here), it remarks us that our estimates are empirical (and that people may have different opinions about "safe" estimates ;-))
Thanks,
Andrea
Quoted 26 lines
drivers/hv/hv_balloon.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/hv/hv_balloon.c +7
-0@@ -1660,6 +1660,13 @@ static int balloon_connect_vsp(struct hv_device *dev)unsigned long t;int ret; +/* +* max_pkt_size should be large enough for one vmbus packet header plus +* our receive buffer size. Hyper-V sends messages up to +* HV_HYP_PAGE_SIZE bytes long on balloon channel. +*/ + dev->channel->max_pkt_size =HV_HYP_PAGE_SIZE *2 ; + ret =vmbus_open (dev->channel, dm_ring_size, dm_ring_size,NULL ,0 , balloon_onchannelcallback, dev);if (ret)Signature · 1 line
2.34.1
Quoted 12 lines · Yanming Liu
Commit
adae1e931acd("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer") introduced a notion of maximum packet size in vmbus channel and used that size to initialize a buffer holding all incoming packet along with their vmbus packet header.hv_balloonuses the default maximum packet sizeVMBUS_DEFAULT_MAX_PKT_SIZEwhich matches its maximum message size, howevervmbus_openexpects this size to also include vmbus packet header. This leads to 4096 bytesdm_unballoon_requestmessages being truncated to 4080 bytes. When the driver tries to read next packet it starts from a wrongread_index, receives garbage and prints a lot of "Unhandled message: type:
<garbage>" in dmesg.
Quoted 7 lines
Allocate the buffer with
HV_HYP_PAGE_SIZEmore bytes to make room for the header.Fixes adae1e931acd ("Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer")Suggested-by Michael Kelley (LINUX) <[email protected]>Suggested-by Andrea Parri (Microsoft) <[email protected]>Signed-off-by Yanming Liu <[email protected]>
Applied to hyperv-fixes. Thanks.