From patchwork Wed Jun 28 04:43:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 9813455 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 2637960365 for ; Wed, 28 Jun 2017 04:45:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 190C2282E8 for ; Wed, 28 Jun 2017 04:45:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08444283B4; Wed, 28 Jun 2017 04:45:32 +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, UNPARSEABLE_RELAY 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 7949B282E8 for ; Wed, 28 Jun 2017 04:45:31 +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 1dQ4oc-0007Ha-Eu; Wed, 28 Jun 2017 04:42:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQ4oa-0007HU-86 for xen-devel@lists.xenproject.org; Wed, 28 Jun 2017 04:42:56 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 31/04-01987-FC333595; Wed, 28 Jun 2017 04:42:55 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsXSO6nOVfeccXC kwfMT1hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b0pzEF94QqurbNY2tgfMrfxcjJISQwkUli bjt3FyMXkP2bUeL+6mksEM5GRokdq+axQTjdjBLf5x9kAWlhE9CRmHbgFJgtIuAgsWn/QXYQm 1kgVWLytRtsILawQILE7ofvmEBsFgFViUWn+4DiHBy8Am4ST+dqgIQlBOQkbp7rZIawDSVOP9 zGOIGRZwEjwypGjeLUorLUIl1DS72kosz0jJLcxMwcXUMDY73c1OLixPTUnMSkYr3k/NxNjEC /1zMwMO5g/H3c7xCjJAeTkijv3i9BkUJ8SfkplRmJxRnxRaU5qcWHGDU4OAT61qy+wCjFkpef l6okwfvYKDhSSLAoNT21Ii0zBxiYMKUSHDxKIrx+V4HG8BYXJOYWZ6ZDpE4xKkqJ894G6RMAS WSU5sG1waLhEqOslDAvIwMDgxBPQWpRbmYJqvwrRnEORiVh3haQKTyZeSVw018BLWYCWswyLw BkcUkiQkqqgXH59Rzmt1dXuNrsbzb7O/s/57af8VauFttS049/up+iMWW6153+XQ7f3f7sf3H N8upxNfuZV9M/X2MSvl+R1vTpYnpr50vWtumly35J6fgw8s/K2cCY7v7RKiLK+kH+xjWLhIRj lM/zf5yR8NfuT2Dmx/8f5s/c/KR9PYtPdn298H9pYTMdrVYlluKMREMt5qLiRADadj6FgQIAA A== X-Env-Sender: dongli.zhang@oracle.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1498624972!100137770!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51841 invoked from network); 28 Jun 2017 04:42:54 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Jun 2017 04:42:54 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v5S4gna4010305 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2017 04:42:49 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v5S4gnrG019135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2017 04:42:49 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v5S4gmfr016781; Wed, 28 Jun 2017 04:42:48 GMT Received: from linux.cn.oracle.com (/10.182.69.113) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 27 Jun 2017 21:42:48 -0700 From: Dongli Zhang To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Date: Wed, 28 Jun 2017 12:43:03 +0800 Message-Id: <1498624983-6293-1-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: jgross@suse.com, boris.ostrovsky@oracle.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch partially reverts 3df0e50 ("xen/blkfront: pseudo support for multi hardware queues/rings"). The xen-blkfront queue/ring might hang due to grants allocation failure in the situation when gnttab_free_head is almost empty while many persistent grants are reserved for this queue/ring. As persistent grants management was per-queue since 73716df ("xen/blkfront: make persistent grants pool per-queue"), we should always allocate from persistent grants first. Signed-off-by: Dongli Zhang --- drivers/block/xen-blkfront.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 3945963..d2b759f 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -713,6 +713,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri * existing persistent grants, or if we have to get new grants, * as there are not sufficiently many free. */ + bool new_persistent_gnts = false; struct scatterlist *sg; int num_sg, max_grefs, num_grant; @@ -724,12 +725,13 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri */ max_grefs += INDIRECT_GREFS(max_grefs); - /* - * We have to reserve 'max_grefs' grants because persistent - * grants are shared by all rings. - */ - if (max_grefs > 0) - if (gnttab_alloc_grant_references(max_grefs, &setup.gref_head) < 0) { + /* Check if we have enough persistent grants to allocate a requests */ + if (rinfo->persistent_gnts_c < max_grefs) { + new_persistent_gnts = true; + + if (gnttab_alloc_grant_references( + max_grefs - rinfo->persistent_gnts_c, + &setup.gref_head) < 0) { gnttab_request_free_callback( &rinfo->callback, blkif_restart_queue_callback, @@ -737,6 +739,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri max_grefs); return 1; } + } /* Fill out a communications ring structure. */ id = blkif_ring_get_request(rinfo, req, &ring_req); @@ -837,7 +840,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri if (unlikely(require_extra_req)) rinfo->shadow[extra_id].req = *extra_ring_req; - if (max_grefs > 0) + if (new_persistent_gnts) gnttab_free_grant_references(setup.gref_head); return 0;