From patchwork Wed Jun 21 09:21:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9801277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C3DA760234 for ; Wed, 21 Jun 2017 09:24:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1AC328515 for ; Wed, 21 Jun 2017 09:24:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4F3228546; Wed, 21 Jun 2017 09:24:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 203AD28515 for ; Wed, 21 Jun 2017 09:24:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNbph-0006WA-VJ; Wed, 21 Jun 2017 09:21:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNbpf-0006W2-Td for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 09:21:52 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 99/75-02956-FAA3A495; Wed, 21 Jun 2017 09:21:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXitHSDve46K69 Igys7jS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozXqw+xF/SIVZye3cvawNgu3MXIySEh4C+x evUUVhCbTUBZ4mdnLxuILSIgI3G0fwGQzcXBLLCZUWLmlNvMIAlhAQ+Jm1PngjWwCKhK/L67h gnE5hUwk3i0aSYjxFB5iV1tF8FqhAQUJDqmH4OqEZQ4OfMJC4jNLCAhcfDFC+YJjNyzkKRmIU ktYGRaxahenFpUllqka6aXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iREYDAxAsIN x3gn/Q4ySHExKorwXZL0ihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnwtlgC5QSLUtNTK9Iyc4Bh CZOW4OBREuFdZg6U5i0uSMwtzkyHSJ1iVJQS52UCBrOQAEgiozQPrg0WC5cYZaWEeRmBDhHiK Ugtys0sQZV/xSjOwagkzPsHZDtPZl4J3PRXQIuZgBa/OOIBsrgkESEl1cA4i79zjePWQp4eY7 WoE/Fr2Yw9nQpXnuBvzV51OunzS5WOy/Prak6fPNh+p0DQyHNbo/EVtXcnKl5arr/h0BIa2BR bHdI7KUpsesaW1+Jr/G5IWdnIrk67OqO93qEsiS3GQqmybWlZxXVumcWFNi82N0ys0ev1/sS+ pDNBfE3Ng6gicZej+5RYijMSDbWYi4oTAQj4+86AAgAA X-Env-Sender: prvs=3381a6b98=wei.liu2@citrix.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1498036909!68276169!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18463 invoked from network); 21 Jun 2017 09:21:50 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jun 2017 09:21:50 -0000 X-IronPort-AV: E=Sophos;i="5.39,368,1493683200"; d="scan'208";a="437274822" From: Wei Liu To: Date: Wed, 21 Jun 2017 10:21:22 +0100 Message-ID: <20170621092122.694-1-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Cc: Xen-devel , Paul Durrant , jean-louis@dupond.be, David Miller , Wei Liu Subject: [Xen-devel] [PATCH net] xen-netback: correctly schedule rate-limited queues X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a flag to indicate if a queue is rate-limited. Test the flag in NAPI poll handler and avoid rescheduling the queue if true, otherwise we risk locking up the host. The rescheduling will be done in the timer callback function. Reported-by: Jean-Louis Dupond Signed-off-by: Wei Liu Tested-by: Jean-Louis Dupond Reviewed-by: Paul Durrant --- drivers/net/xen-netback/common.h | 1 + drivers/net/xen-netback/interface.c | 6 +++++- drivers/net/xen-netback/netback.c | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h index 530586be05b4..5b1d2e8402d9 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h @@ -199,6 +199,7 @@ struct xenvif_queue { /* Per-queue data for xenvif */ unsigned long remaining_credit; struct timer_list credit_timeout; u64 credit_window_start; + bool rate_limited; /* Statistics */ struct xenvif_stats stats; diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index 8397f6c92451..e322a862ddfe 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -106,7 +106,11 @@ static int xenvif_poll(struct napi_struct *napi, int budget) if (work_done < budget) { napi_complete_done(napi, work_done); - xenvif_napi_schedule_or_enable_events(queue); + /* If the queue is rate-limited, it shall be + * rescheduled in the timer callback. + */ + if (likely(!queue->rate_limited)) + xenvif_napi_schedule_or_enable_events(queue); } return work_done; diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index 602d408fa25e..5042ff8d449a 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c @@ -180,6 +180,7 @@ static void tx_add_credit(struct xenvif_queue *queue) max_credit = ULONG_MAX; /* wrapped: clamp to ULONG_MAX */ queue->remaining_credit = min(max_credit, max_burst); + queue->rate_limited = false; } void xenvif_tx_credit_callback(unsigned long data) @@ -686,8 +687,10 @@ static bool tx_credit_exceeded(struct xenvif_queue *queue, unsigned size) msecs_to_jiffies(queue->credit_usec / 1000); /* Timer could already be pending in rare cases. */ - if (timer_pending(&queue->credit_timeout)) + if (timer_pending(&queue->credit_timeout)) { + queue->rate_limited = true; return true; + } /* Passed the point where we can replenish credit? */ if (time_after_eq64(now, next_credit)) { @@ -702,6 +705,7 @@ static bool tx_credit_exceeded(struct xenvif_queue *queue, unsigned size) mod_timer(&queue->credit_timeout, next_credit); queue->credit_window_start = next_credit; + queue->rate_limited = true; return true; }