* [PATCH] hv: do not lose pending heartbeat vmbus packets
@ 2016-09-13 3:31 Long Li
2016-09-19 17:15 ` Haiyang Zhang
2016-09-29 9:22 ` Vitaly Kuznetsov
0 siblings, 2 replies; 4+ messages in thread
From: Long Li @ 2016-09-13 3:31 UTC (permalink / raw)
To: K. Y. Srinivasan, Haiyang Zhang; +Cc: devel, linux-kernel, Long Li
From: Long Li <longli@microsoft.com>
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 <longli@microsoft.com>
---
drivers/hv/hv_util.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index d5acaa2..9dc6372 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -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)];
--
1.8.5.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] hv: do not lose pending heartbeat vmbus packets
2016-09-13 3:31 [PATCH] hv: do not lose pending heartbeat vmbus packets Long Li
@ 2016-09-19 17:15 ` Haiyang Zhang
2016-09-29 9:22 ` Vitaly Kuznetsov
1 sibling, 0 replies; 4+ messages in thread
From: Haiyang Zhang @ 2016-09-19 17:15 UTC (permalink / raw)
To: Long Li, KY Srinivasan
Cc: devel@linuxdriverproject.org, linux-kernel@vger.kernel.org,
Long Li
> -----Original Message-----
> From: Long Li [mailto:longli@exchange.microsoft.com]
> Sent: Monday, September 12, 2016 11:31 PM
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>
> Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org; Long Li
> <longli@microsoft.com>
> Subject: [PATCH] hv: do not lose pending heartbeat vmbus packets
>
> From: Long Li <longli@microsoft.com>
>
> 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 <longli@microsoft.com>
Please also apply it to "stable".
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hv: do not lose pending heartbeat vmbus packets
2016-09-13 3:31 [PATCH] hv: do not lose pending heartbeat vmbus packets Long Li
2016-09-19 17:15 ` Haiyang Zhang
@ 2016-09-29 9:22 ` Vitaly Kuznetsov
2016-09-30 18:31 ` Long Li
1 sibling, 1 reply; 4+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-29 9:22 UTC (permalink / raw)
To: K. Y. Srinivasan, Long Li; +Cc: Haiyang Zhang, devel, linux-kernel
Long Li <longli@exchange.microsoft.com> writes:
> From: Long Li <longli@microsoft.com>
>
> 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 <longli@microsoft.com>
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 | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
> index d5acaa2..9dc6372 100644
> --- a/drivers/hv/hv_util.c
> +++ b/drivers/hv/hv_util.c
> @@ -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).
> +
> + if (!recvlen)
so this should be 'if (ret || !recvlen)'
> + break;
>
> - if (recvlen > 0) {
> icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[
> sizeof(struct vmbuspipe_hdr)];
--
Vitaly
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] hv: do not lose pending heartbeat vmbus packets
2016-09-29 9:22 ` Vitaly Kuznetsov
@ 2016-09-30 18:31 ` Long Li
0 siblings, 0 replies; 4+ messages in thread
From: Long Li @ 2016-09-30 18:31 UTC (permalink / raw)
To: Vitaly Kuznetsov, KY Srinivasan
Cc: Haiyang Zhang, devel@linuxdriverproject.org,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com]
> Sent: Thursday, September 29, 2016 2:22 AM
> To: KY Srinivasan <kys@microsoft.com>; Long Li <longli@microsoft.com>
> Cc: Haiyang Zhang <haiyangz@microsoft.com>;
> devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] hv: do not lose pending heartbeat vmbus packets
>
> Long Li <longli@exchange.microsoft.com> writes:
>
> > From: Long Li <longli@microsoft.com>
> >
> > 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 <longli@microsoft.com>
>
> 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 | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index
> > d5acaa2..9dc6372 100644
> > --- a/drivers/hv/hv_util.c
> > +++ b/drivers/hv/hv_util.c
> > @@ -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).
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 .
>
> > +
> > + if (!recvlen)
>
> so this should be 'if (ret || !recvlen)'
>
> > + break;
> >
> > - if (recvlen > 0) {
> > icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[
> > sizeof(struct vmbuspipe_hdr)];
>
> --
> Vitaly
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-30 21:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-13 3:31 [PATCH] hv: do not lose pending heartbeat vmbus packets Long Li
2016-09-19 17:15 ` Haiyang Zhang
2016-09-29 9:22 ` Vitaly Kuznetsov
2016-09-30 18:31 ` Long Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox