hv: do not lose pending heartbeat vmbus packets
PATCH 1/1 hv: do not lose pending heartbeat vmbus packets
From: Long Li <[email protected]>
The host keeps sending heartbeat packets independent of guest responding to them. In some situations, there might be multiple heartbeat packets pending in the ring buffer. Don't lose them, read them all.
--- drivers/hv/hv_util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/hv/hv_util.c +7 -3
@@ -283,10 +283,14 @@ static void heartbeat_onchannelcallback(void *context)u8 *hbeat_txf_buf = util_heartbeat.recv_buffer;struct icmsg_negotiate *negop =NULL ; -vmbus_recvpacket (channel, hbeat_txf_buf, -PAGE_SIZE , &recvlen, &requestid); +while (1 ) { + +vmbus_recvpacket (channel, hbeat_txf_buf, +PAGE_SIZE , &recvlen, &requestid); + +if (!recvlen) +break ; -if (recvlen >0 ) { icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[sizeof (struct vmbuspipe_hdr )];
Signature · 1 line
1.8.5.6
Haiyang Zhang
maintainerQuoted 9 lines
-----Original Message-----
From: Long Li [mailto:[email protected]]
Sent: Monday, September 12, 2016 11:31 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; Long Li <[email protected]>
Subject: [PATCH] hv: do not lose pending heartbeat vmbus packets
Quoted 7 lines
From: Long Li <[email protected]>
The host keeps sending heartbeat packets independent of guest responding to them. In some situations, there might be multiple heartbeat packets pending in the ring buffer. Don't lose them, read them all.
Signed-off-by Long Li <[email protected]>
Please also apply it to "stable".
Quoted 5 lines · Long Li
From: Long Li <[email protected]>
The host keeps sending heartbeat packets independent of guest responding to them. In some situations, there might be multiple heartbeat packets pending in the ring buffer. Don't lose them, read them all.
Signed-off-by Long Li <[email protected]>
Long, K. Y.,
it seems this patch didn't make it to char-misc tree and it looks like an important fix. A couple of nitpicks below,
Quoted 9 lines
--- drivers/hv/hv_util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/hv/hv_util.c +0
-0
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void *context) · line 289
Quoted 9 lines
drivers/hv/hv_util.c +4
-2@@ -283,10 +283,14 @@ static void heartbeat_onchannelcallback(void *context)u8 *hbeat_txf_buf = util_heartbeat.recv_buffer;struct icmsg_negotiate *negop =NULL ; -vmbus_recvpacket (channel, hbeat_txf_buf, -PAGE_SIZE , &recvlen, &requestid); +while (1 ) { + +vmbus_recvpacket (channel, hbeat_txf_buf, +PAGE_SIZE , &recvlen, &requestid);
We should check vmbus_recvpacket() return value as
well. E.g. hv_ringbuffer_read() may return -EAGAIN in case we didn't receive the whole packet (and we do this check in other drivers, see storvsc_on_channel_callback() for example).
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void *context) · line 291
Quoted 2 lines
drivers/hv/hv_util.c +2
-0+ +if (!recvlen)
so this should be 'if (ret || !recvlen)'
Quoted 5 lines
drivers/hv/hv_util.c +1
-1+break ; -if (recvlen >0 ) { icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[sizeof (struct vmbuspipe_hdr )];
Signature · 1 line
Vitaly
Quoted 38 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Thursday, September 29, 2016 2:22 AM
To: KY Srinivasan <[email protected]>; Long Li <[email protected]>
Cc: Haiyang Zhang <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] hv: do not lose pending heartbeat vmbus packetsQuoted 3 lines · Long Li
From: Long Li <[email protected]>
The host keeps sending heartbeat packets independent of guest
responding to them. In some situations, there might be multiple heartbeat packets pending in the ring buffer. Don't lose them, read them all.
Quoted 2 lines
Signed-off-by Long Li <[email protected]>Long, K. Y.,
it seems this patch didn't make it to char-misc tree and it looks like an important fix. A couple of nitpicks below,
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void
Quoted 9 lines
--- drivers/hv/hv_util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/hv/hv_util.c index renamed from drivers/hv/hv_util.c +0
-0d5acaa2..9dc6372 100644
drivers/hv/hv_util.c +0
-0@@ -283,10 +283,14 @@ static void heartbeat_onchannelcallback(void*context)
Quoted 3 lines
drivers/hv/hv_util.c +0
-0u8 *hbeat_txf_buf = util_heartbeat.recv_buffer;struct icmsg_negotiate *negop =NULL ;
Quoted 11 lines
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void *context) · line 289
Quoted 6 lines
drivers/hv/hv_util.c +4
-2-vmbus_recvpacket (channel, hbeat_txf_buf, -PAGE_SIZE , &recvlen, &requestid); +while (1 ) { + +vmbus_recvpacket (channel, hbeat_txf_buf, +PAGE_SIZE , &recvlen, &requestid);We should check
vmbus_recvpacket()return value as well. E.g.hv_ringbuffer_read()may return-EAGAINin case we didn't receive the whole packet (and we do this check in other drivers, seestorvsc_on_channel_callback()for example).
I agree with you, we should check for -EAGAIN. This should also be done in storvsc_on_channel_callback.
I think the chance of hv_ringbuffer_read() returning -EAGAIN is almost zero. Because read_index and write_index are updated after the whole packet is written to the ring buffer, and protected by memory barriers. So getting a partial read is impossible, unless the host is doing something wrong.
Checking for recvlen is safe, because it's always set to 0 at the beginning of hv_ringbuffer_read().
Anyway, we should check for -EAGAIN for all hyperv drivers on read. I think this is a separate issue on how we deal with a buggy host. Will send another set of patches .
Quoted 14 lines
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void · line 291
Quoted 3 lines
drivers/hv/hv_util.c +2
-0+ +if (!recvlen)so this should be 'if (ret || !recvlen)'
drivers/hv/hv_util.c static void heartbeat_onchannelcallback(void *context) · line 295
Quoted 5 lines
drivers/hv/hv_util.c +1
-1+break ; -if (recvlen >0 ) { icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[sizeof (struct vmbuspipe_hdr )];--
Vitaly