stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.4.y] hv_utils: drain the timesync packets on onchannelcallback
@ 2024-06-17 23:25 Dexuan Cui
  2024-06-19  9:30 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Dexuan Cui @ 2024-06-17 23:25 UTC (permalink / raw)
  To: stable, mhklinux; +Cc: Vineeth Pillai, Wei Liu, Dexuan Cui

From: Vineeth Pillai <viremana@linux.microsoft.com>

commit b46b4a8a57c377b72a98c7930a9f6969d2d4784e

There could be instances where a system stall prevents the timesync
packets to be consumed. And this might lead to more than one packet
pending in the ring buffer. Current code empties one packet per callback
and it might be a stale one. So drain all the packets from ring buffer
on each callback.

Signed-off-by: Vineeth Pillai <viremana@linux.microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20200821152849.99517-1-viremana@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>

The old code in the upstream commit uses HV_HYP_PAGE_SIZE, but
the old code in 5.4.y sitll uses PAGE_SIZE. Fixed this manually for 5.4.y.
Note: 5.4.y already has the define HV_HYP_PAGE_SIZE, so the new code in
in the upstream commit works for 5.4.y.

If there are multiple messages in the host-to-guest ringbuffer of the TimeSync
device, 5.4.y only handles 1 message, and later the host puts new messages
into the ringbuffer without signaling the guest because the ringbuffer is not
empty, causing a "hung" ringbuffer. Backported the mainline fix for this issue.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/hv_util.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 1671f6f9ea80..48f9b1fbcbda 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -283,10 +283,23 @@ static void timesync_onchannelcallback(void *context)
 	struct ictimesync_ref_data *refdata;
 	u8 *time_txf_buf = util_timesynch.recv_buffer;
 
-	vmbus_recvpacket(channel, time_txf_buf,
-			 PAGE_SIZE, &recvlen, &requestid);
+	/*
+	 * Drain the ring buffer and use the last packet to update
+	 * host_ts
+	 */
+	while (1) {
+		int ret = vmbus_recvpacket(channel, time_txf_buf,
+					   HV_HYP_PAGE_SIZE, &recvlen,
+					   &requestid);
+		if (ret) {
+			pr_warn_once("TimeSync IC pkt recv failed (Err: %d)\n",
+				     ret);
+			break;
+		}
+
+		if (!recvlen)
+			break;
 
-	if (recvlen > 0) {
 		icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[
 				sizeof(struct vmbuspipe_hdr)];
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5.4.y] hv_utils: drain the timesync packets on onchannelcallback
  2024-06-17 23:25 [PATCH 5.4.y] hv_utils: drain the timesync packets on onchannelcallback Dexuan Cui
@ 2024-06-19  9:30 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-06-19  9:30 UTC (permalink / raw)
  To: Dexuan Cui; +Cc: stable, mhklinux, Vineeth Pillai, Wei Liu

On Mon, Jun 17, 2024 at 04:25:07PM -0700, Dexuan Cui wrote:
> From: Vineeth Pillai <viremana@linux.microsoft.com>
> 
> commit b46b4a8a57c377b72a98c7930a9f6969d2d4784e
> 
> There could be instances where a system stall prevents the timesync
> packets to be consumed. And this might lead to more than one packet
> pending in the ring buffer. Current code empties one packet per callback
> and it might be a stale one. So drain all the packets from ring buffer
> on each callback.
> 
> Signed-off-by: Vineeth Pillai <viremana@linux.microsoft.com>
> Reviewed-by: Michael Kelley <mikelley@microsoft.com>
> Link: https://lore.kernel.org/r/20200821152849.99517-1-viremana@linux.microsoft.com
> Signed-off-by: Wei Liu <wei.liu@kernel.org>
> 
> The old code in the upstream commit uses HV_HYP_PAGE_SIZE, but
> the old code in 5.4.y sitll uses PAGE_SIZE. Fixed this manually for 5.4.y.
> Note: 5.4.y already has the define HV_HYP_PAGE_SIZE, so the new code in
> in the upstream commit works for 5.4.y.
> 
> If there are multiple messages in the host-to-guest ringbuffer of the TimeSync
> device, 5.4.y only handles 1 message, and later the host puts new messages
> into the ringbuffer without signaling the guest because the ringbuffer is not
> empty, causing a "hung" ringbuffer. Backported the mainline fix for this issue.
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Both now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-19  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-17 23:25 [PATCH 5.4.y] hv_utils: drain the timesync packets on onchannelcallback Dexuan Cui
2024-06-19  9:30 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).