[b:azure-4.15, f:azure][PATCH 2/2] hv_utils: drain the timesync packets on onchannelcallback

Kelsey Skunberg kelsey.skunberg at canonical.com
Wed Dec 16 00:12:23 UTC 2020


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

BugLink: https://bugs.launchpad.net/bugs/1896784

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 at linux.microsoft.com>
Reviewed-by: Michael Kelley <mikelley at microsoft.com>
Link: https://lore.kernel.org/r/20200821152849.99517-1-viremana@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu at kernel.org>
(backported from commit b46b4a8a57c377b72a98c7930a9f6969d2d4784e)
[KelseyS: HV_HYP_PAGE_SIZE changed to PAGE_SIZE]
Signed-off-by: Kelsey Skunberg <kelsey.skunberg at canonical.com>
---
 drivers/hv/hv_util.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index a395f50b3ca2..2c9dabf64184 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -387,10 +387,22 @@ 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,
+					   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




More information about the kernel-team mailing list