From patchwork Wed Dec 16 00:12:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1416810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CwbDM0Z7Wz9sTL; Wed, 16 Dec 2020 11:12:34 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kpKQg-0002Hk-6T; Wed, 16 Dec 2020 00:12:30 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpKQd-0002HF-CE for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 00:12:27 +0000 Received: from mail-oo1-f70.google.com ([209.85.161.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpKQd-0007Zi-0s for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 00:12:27 +0000 Received: by mail-oo1-f70.google.com with SMTP id l5so7652050ooj.2 for ; Tue, 15 Dec 2020 16:12:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gNTBI6jdfUlb208yujZegpLjtIIsGMZL3eRNkqENAuE=; b=cRbj7+4vgQq2RL2ZfB0tdwIC6D5bVeM53eT5DsHzsAC5n96HW9JYV8MpMvXLcD38yG 4UXsLI5WV7UQIM5OV5sOFQZwNWZlhhtxEJ7Fh1zLbUnD10FqXIRKtsRTFiOieSuTpC/g 1RyG/+w+Hr0OA1ruX7fsmG9GUjZ/l6QViizrf5VNuTeEalAI/1YpMyCNDN9s7rJHNe+i rte/FOQEXSzdQ+e57QVh4H17LX5fGCaMfAhhIl6/U0swcYadV+X9L87EQEsax3e4H6ws FI8IzcwOE6FNcXwTZgAeSndkfAmMijqZvFgMyYajdeH8ZO3PhcL3pifh0rZeNXdkz2cE qP9g== X-Gm-Message-State: AOAM5327blM7tOalDAy3yXckf0d0cqr49K8VtfNkaKbksjkhlzECqPD9 qarDjH/Cv6CYEpMbbZZH/0d+ebf10hHF9JThg/Kwgz60e1aQGNg3MNW0nktHU0uJnQC6J2FROII dYqy84UbifM0l/8+t27mEvSehLd4ECv9fLwyKa/1tTg== X-Received: by 2002:a05:6808:993:: with SMTP id a19mr702702oic.65.1608077545853; Tue, 15 Dec 2020 16:12:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzP7hFQPAC/BePL45p6ZWVNOAF911nqoZNigxNIL/Ojja2UFdIkz1tbnyYPdiQijFBpiOXMIA== X-Received: by 2002:a05:6808:993:: with SMTP id a19mr702698oic.65.1608077545668; Tue, 15 Dec 2020 16:12:25 -0800 (PST) Received: from localhost.localdomain ([38.80.149.171]) by smtp.gmail.com with ESMTPSA id w4sm36219otj.3.2020.12.15.16.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 16:12:25 -0800 (PST) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [b:azure-4.15, f:azure][PATCH 1/2] hv_utils: return error if host timesysnc update is stale Date: Tue, 15 Dec 2020 17:12:22 -0700 Message-Id: <20201216001223.463961-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201216001223.463961-1-kelsey.skunberg@canonical.com> References: <20201216001223.463961-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vineeth Pillai BugLink: https://bugs.launchpad.net/bugs/1896784 If for any reason, host timesync messages were not processed by the guest, hv_ptp_gettime() returns a stale value and the caller (clock_gettime, PTP ioctl etc) has no means to know this now. Return an error so that the caller knows about this. Signed-off-by: Vineeth Pillai Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20200821152523.99364-1-viremana@linux.microsoft.com Signed-off-by: Wei Liu (backported from commit 90b125f4cd2697f949f5877df723a0b710693dd0) [KelseyS: context change] Signed-off-by: Kelsey Skunberg --- drivers/hv/hv_util.c | 46 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index ca4c85672cc1..a395f50b3ca2 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -282,26 +282,52 @@ static struct { spinlock_t lock; } host_ts; -static struct timespec64 hv_get_adj_host_time(void) +static inline u64 reftime_to_ns(u64 reftime) { - struct timespec64 ts; - u64 newtime, reftime; + return (reftime - WLTIMEDELTA) * 100; +} + +/* + * Hard coded threshold for host timesync delay: 600 seconds + */ +static const u64 HOST_TIMESYNC_DELAY_THRESH = 600 * (u64)NSEC_PER_SEC; + +static int hv_get_adj_host_time(struct timespec64 *ts) +{ + u64 newtime, reftime, timediff_adj; unsigned long flags; + int ret = 0; spin_lock_irqsave(&host_ts.lock, flags); reftime = hyperv_cs->read(hyperv_cs); - newtime = host_ts.host_time + (reftime - host_ts.ref_time); - ts = ns_to_timespec64((newtime - WLTIMEDELTA) * 100); + + /* + * We need to let the caller know that last update from host + * is older than the max allowable threshold. clock_gettime() + * and PTP ioctl do not have a documented error that we could + * return for this specific case. Use ESTALE to report this. + */ + timediff_adj = reftime - host_ts.ref_time; + if (timediff_adj * 100 > HOST_TIMESYNC_DELAY_THRESH) { + pr_warn_once("TIMESYNC IC: Stale time stamp, %llu nsecs old\n", + (timediff_adj * 100)); + ret = -ESTALE; + } + + newtime = host_ts.host_time + timediff_adj; + *ts = ns_to_timespec64(reftime_to_ns(newtime)); spin_unlock_irqrestore(&host_ts.lock, flags); - return ts; + return ret; } static void hv_set_host_time(struct work_struct *work) { - struct timespec64 ts = hv_get_adj_host_time(); - do_settimeofday64(&ts); + struct timespec64 ts; + + if (!hv_get_adj_host_time(&ts)) + do_settimeofday64(&ts); } /* @@ -621,9 +647,7 @@ static int hv_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) static int hv_ptp_gettime(struct ptp_clock_info *info, struct timespec64 *ts) { - *ts = hv_get_adj_host_time(); - - return 0; + return hv_get_adj_host_time(ts); } static struct ptp_clock_info ptp_hyperv_info = { From patchwork Wed Dec 16 00:12:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1416808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CwbDL4LJqz9sTK; Wed, 16 Dec 2020 11:12:34 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kpKQg-0002I2-EL; Wed, 16 Dec 2020 00:12:30 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpKQd-0002HL-R2 for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 00:12:27 +0000 Received: from mail-oo1-f69.google.com ([209.85.161.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpKQd-0007Zm-H4 for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 00:12:27 +0000 Received: by mail-oo1-f69.google.com with SMTP id h20so2867632oop.14 for ; Tue, 15 Dec 2020 16:12:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V+j92xuk7pQmiQWl2u+08UkrXMBzz5hoa1qUHCrX0Sw=; b=Zgq05O7kF5LbrOZG1HrAuH0QAA1g3RCdgBgtuVLlQ33HlBJZmPKzgZMh7lOyJqXvPR 9At6nuk+Wv8FLwqLpEaGlePI3n764Nz0ubkBx3oB6/VbCHLklqFiu9tzrfAcqo+ZvldG N2LyhGSP0SyKiGbxcQPu108hHEIQF0SRRzIBIe/Qkc4gzWLA3WjocTaDiP2YN7T/olaU zh7CD53UleAGIxq7yKMAwC1zfSVsDsHjqZSWcvdPSZ96t9hlrgWM4GmoH6r/Ifi9fPsI HOshdl3LcRncj83M5r0leqbxjob+oHG26dZGwdfLP3NsAjcQul2SShrO/mtqCp32N1Zo G+Dw== X-Gm-Message-State: AOAM531XuFj/efmlloPmropc/0LfO8zOPa+abkmaLELdJDD10cixfVRK 0B7CGUD/CVGRw2UPeVxb0u6x/GmCgk2Rq/6wriVWLReExE6h0OmTSeQJXPK59vPNdeY6ncKpzBK HCVVXbOmkl6is9bRlFFUhva8lV8RJcGoUmrwSztfnHw== X-Received: by 2002:aca:58d7:: with SMTP id m206mr762715oib.0.1608077546388; Tue, 15 Dec 2020 16:12:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTBdMqIcE7OTDlbbweU9ABtZJmYaCUJF9tgF3nxOZ1E6ABtzvUX7emm5D5gMmzf/MBSuD4EA== X-Received: by 2002:aca:58d7:: with SMTP id m206mr762709oib.0.1608077546199; Tue, 15 Dec 2020 16:12:26 -0800 (PST) Received: from localhost.localdomain ([38.80.149.171]) by smtp.gmail.com with ESMTPSA id w4sm36219otj.3.2020.12.15.16.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 16:12:25 -0800 (PST) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [b:azure-4.15, f:azure][PATCH 2/2] hv_utils: drain the timesync packets on onchannelcallback Date: Tue, 15 Dec 2020 17:12:23 -0700 Message-Id: <20201216001223.463961-3-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201216001223.463961-1-kelsey.skunberg@canonical.com> References: <20201216001223.463961-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vineeth Pillai 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 Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20200821152849.99517-1-viremana@linux.microsoft.com Signed-off-by: Wei Liu (backported from commit b46b4a8a57c377b72a98c7930a9f6969d2d4784e) [KelseyS: HV_HYP_PAGE_SIZE changed to PAGE_SIZE] Signed-off-by: Kelsey Skunberg --- 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)];