From patchwork Thu Jan 26 19:52:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9540025 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 476FC604A0 for ; Thu, 26 Jan 2017 19:53:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DB582832B for ; Thu, 26 Jan 2017 19:53:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3294B28346; Thu, 26 Jan 2017 19:53:13 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86B2B2832B for ; Thu, 26 Jan 2017 19:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753053AbdAZTxL (ORCPT ); Thu, 26 Jan 2017 14:53:11 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48752 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752831AbdAZTxI (ORCPT ); Thu, 26 Jan 2017 14:53:08 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v0QJo4Nx004948; Thu, 26 Jan 2017 11:52:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=subject : to : references : cc : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=facebook; bh=c7LnnDrB7g5CLkHMgz3xFISxFGM1SAtWUrZiIgUjqcs=; b=Ghbmpe5SQ3mwKa7Kpz3KhyCbkFCTBedIJv99wIGvhDukbchGRXyHlYqNtYzWH7+3dKPX EVgTLRqpuCwEvDIL++dvS1CVFe8tpFUGEbpYaDkrB0qaGC493syCe7ZBWDemfscfhAWE BTc/2ekkaAg6XNDluvZsw9ruaM7ETsVbqSI= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 287p7c8dju-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 26 Jan 2017 11:52:23 -0800 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.22) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 26 Jan 2017 14:52:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=c7LnnDrB7g5CLkHMgz3xFISxFGM1SAtWUrZiIgUjqcs=; b=c8yc0gzYBcTLEYRSpj7sLI+Vw9aqgXb6KwcCZ9yi/3P4Zl/X5k0hIJ/XPlHdgL6xfqVS63qgYc0DXeLPDiwE9S3NX8vnto+iM0aopC9XDQKdaKh18sCQ+j+yHmg+X6ruw5zKyfvTyyQ+NrC7cEIJtTo1pPcJQS/cVReOVvBs/rc= Received: from [192.168.1.154] (216.160.245.98) by DM5PR15MB1193.namprd15.prod.outlook.com (10.173.209.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.874.12; Thu, 26 Jan 2017 19:52:19 +0000 Subject: Re: [PATCH 2/5] blk-mq: fix potential race in queue restart and driver tag allocation To: References: <1485460098-16608-1-git-send-email-axboe@fb.com> <1485460098-16608-3-git-send-email-axboe@fb.com> CC: , , , , From: Jens Axboe Message-ID: Date: Thu, 26 Jan 2017 12:52:15 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1485460098-16608-3-git-send-email-axboe@fb.com> X-Originating-IP: [216.160.245.98] X-ClientProxiedBy: CO1PR16CA0002.namprd16.prod.outlook.com (10.166.27.12) To DM5PR15MB1193.namprd15.prod.outlook.com (10.173.209.11) X-MS-Office365-Filtering-Correlation-Id: d8c5fc75-9c9a-442f-6158-08d44624d69d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM5PR15MB1193; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1193; 3:2vQHHuXkkGTLLRJNl1dUDfve8pSSva1Q/whHtb+SwtLRsGtdcBA1odpKkIQWeeSeafIsSEuoayDZuaq2dXNcyD+4082/hoUAvPYjrmYtWyY+laIuDT46uf6mifKurd+4MS4aG4kY7RKFrHOg3B2Cd1Ajj4UvM2rMUXs+zcbWp+iIMaWELigscmbNq7/LiRdj9eBsmc96qSkKwuSPWtWxXTGl5EFCrSlvz3AUzpIxBqCh4F7oYR1CiV/DM8J7iy/9Vwl8Bq600UOkc6ONRt7qOA==; 25:KpBSsXZ3NC1S4m1mbXJe4m/xEkGBDgDdbyT5+xCSP+A8cC0KOlDx2/WiMPz1j5ipYCksVyHgar2C8no0dNK+7qqw9e4+SM2uTiSl5b3geK26sx6u4emt8Pv/WcChHl2nVfFe8zTBr9ANAuQ/lC1OSj6sLaiy3URtVBMbJtzQ8DdoQoH10n99D5oSuht1jq4e15TKpFnSY8rz0LTp6r3A7w52AUqr8jdeQPJXio4vaJte/uQ08bFAe2qmqX5vyfjIOYvWSSWs74tS9qvJ0GMfaNax1zdoqIYHWJHHD6aQqA+s4IOKuxXRRzqWGmzNNsor0GkGNgQZNy9uV02RHJi3mqY83Bvh+Iso9T/DQPFFWGyjLR6G9tA6ngFPWe1pjxlm3f3/ewjZfn9IomU/nxroENV8BSkTZTjNHmIfNN3pkOg0STlZALWYMB1OVI9yE1fzfDo4ZcvID/cy2mv8nW6Q+Q== X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1193; 31:ug6kuXIJi/41bG1xCinR4AoergZ0P89/U/6NQO/RL8SC/CMXaTWN6tEhO1WaPTAMPBbIJfqK2Ua8/xWy6Z1+yeVFDete608l0gGNGeAmAdGlCAc4hvDHunrk/C7rOn7SQmtSx2W6iinw/byDebmjZPkHXiJCDy09RRVwD2VEtkgc2Mjq7+sxKr/uewxjwHLQxhQPfRbJM39ht+g5ijQeIYiSF3dSTImQqwddXGJaUsKys6WlFLn69EKmDx7Dc2Mr; 20:PMaXkxq6NKmbDGUOwfal1uSMNctn/NCo90Jf/SMMSUZ8M5CDoAmL3cGRyBMvL2ljrXIbnQD9r9MX8dY12flsbxZw5taatXqCdiuadf/FMQSyJLmsxT3hFP2cC1egRmNdEE+iEtrnChBYte1iradsudUaUyE76pzGLOIIArDImNW4Vju++9qXtZXVYGaR/Uw0VaX6E+wO8xmyH6gsARr5vvXXDAbRvg/6jVEGjLLv2ObhI9ZXnWPryqklmMzcZ2WuiV12UoFBXbfz3NgnCxbHBH7GcwMw2Ja8mqmqjBtmsEaXt7sXEe+WYWNwuRERGlJHFRWsriV0LZjFLfJLcapUr6XBQzH/i6gUmF3N4O6q8DBf8CW9evO95eS2EIMGhvfOUTzvSRviqBD1ureuV/Af84E8vm3JzfIzc9JlBpAqSTRQHvIj9k06rkzvzsl1tjMgf8LA8O4B4K/ltEI+81IZVC5XFOhVC1Milt6Ka2+G5wnwv7zSYpC0UEx103RnDm/E X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123562025)(20161123560025)(20161123555025)(20161123564025)(6072148); SRVR:DM5PR15MB1193; BCL:0; PCL:0; RULEID:; SRVR:DM5PR15MB1193; X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1193; 4:jW4B0CFJEVQ970euDR++jMUtxeyiG2Pdku+yxnj2/HKl24r+W4+4kNDoByAFHkmwuK64q5XzY9HiFwae6p77Dbsr7R8UJUeA+UFzMR+3ttNddRnOaS/oKweGdKhQO+JKqpQwn8pL5yWJE+6PVKx91nKD++XWJWhC4cFQS7iatlsaEd/2zpyRyuAFeRu6grA6adeM8rVyghqxJtPMwabTLcI4RAJCyFpsAqwAEzEMqNHDrw6EZy3j5S22my7URN+h54NsGeZ7ksP6q156CaFKnFiUOoT6LIL/q8+dJqARgKl3hlZcVs2l+GP90P64iWG4rEs7enkeeSI5AjqoCebfsjjh88LlKq0wEec1EBXpK6P3hY4wp6XL/Agfd7aV3UV+dHmHkSVe7ivkZOmPxoGf1wwzLFEczqISfXP/eAXEipjShqpwXh5+uuJpb4wAns2KPcVgOi0kLUZXfLJujvWj1DxEgD0PgtmJ6H4T+2Z3Mw9qxtGhczou4nshgZ0adiERFeiR1GCYFSeFj958xJwWAUT7bGSATnfA3DZtH6URtfRRqFRKksRXWdUaz5RPd5bmhyQ2TKSxIfXKYKpnpy1V8pDMZjNtM9pGOjcZb4k3qxFS51OVAD+9jh7q8FDIZRNH X-Forefront-PRVS: 019919A9E4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(377454003)(189002)(24454002)(199003)(6116002)(3846002)(23746002)(50466002)(54356999)(65806001)(64126003)(7736002)(305945005)(47776003)(101416001)(66066001)(50986999)(65956001)(106356001)(117156001)(105586002)(76176999)(2351001)(92566002)(42186005)(6486002)(33646002)(31686004)(36756003)(81166006)(8676002)(81156014)(25786008)(8656002)(68736007)(90366009)(230700001)(54906002)(83506001)(38730400001)(229853002)(6666003)(5660300001)(110136003)(65826007)(2950100002)(6916009)(4326007)(189998001)(53936002)(4001350100001)(86362001)(97736004)(31696002)(2906002)(77096006); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR15MB1193; H:[192.168.1.154]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1; DM5PR15MB1193; 23:mXKUVwehr1ntYSLIipDQcojIqXeDmtNlvVdI1?= =?Windows-1252?Q?vju7PNhudnY+1JQaLO6BKyiyWPRideeW/C8uAJjhaGG0zzdYisqHzmHF?= =?Windows-1252?Q?z6OBUZlPpz4hq7rODpHddL/azAcf3hnorjMpNEHsGYLRxDzE51WAPK/R?= =?Windows-1252?Q?nkoDHOHtTc/g55GC8HJnbYmzY5YzKh5iOwQGYzC5MuOD1I0plxS4d6+F?= =?Windows-1252?Q?ZG6xwvoi1BoSZgpKIbAa1geLcmnfTbGMmVsef00mMrN3seBoqy1C6pHL?= =?Windows-1252?Q?G88Dg9tOpxDbhXnlT0WOUNUQxeWN8HAxGOZFCa0CSTXH9vyJmIjdq4Ch?= =?Windows-1252?Q?0ug4J2a44A7xz3o5zP4dUTSF8eBX79xBJXdJoirV5zFo7B+sYNB7d3OJ?= =?Windows-1252?Q?pPtN2FXWvrYXPNpmy2sdjMBCeWsopxid1RvlTpA+MUT+xuXKVylK9KYG?= =?Windows-1252?Q?ys4tkLvR059tQRzVTqBkQrVx4LzgesvXS9g05AJr8maYOsdYTPeCT3r1?= =?Windows-1252?Q?9jqox+8QppDuwuwVo7Xjyr8hOchWNSGAnmg8sCBuIe8GhK1HNZKv7ag5?= =?Windows-1252?Q?GarVslUElr1oM9izFLtgazRB2uFwBnWePL0xZSANyEUcN9Gnm6jSLZrA?= =?Windows-1252?Q?uN1X8/XuiB902lEppBKTYUdzWe2DAbUCcPdw/QhDO6TYBKoNVWFJ5QXK?= =?Windows-1252?Q?omz32PmDoI3DhNd6xJKbAYE3a0FL0IVJL2EWXF22QGWt5mh/7WVqG+vC?= =?Windows-1252?Q?tqizo8/EZOCDyL+PEC/V4XwCe8L8pSbV0f/2m2rqRInEg1Sdb9ZMKNvR?= =?Windows-1252?Q?cPnvhjJjcLeTmfDa7Rr/zemxJR71y4yCJySPLEMHFxtxZz5fqPj7IZCq?= =?Windows-1252?Q?dKfwq8SZq8coLHklwsMKeppsY55rO6nYU1rHmWngLhimUfefK1a5uS/8?= =?Windows-1252?Q?sZvwdy62RBDFx5cApDZ2u5smRj+fSbAT1dJMRwS81ANUy8S3qiWWkSRF?= =?Windows-1252?Q?6ULXt0bgJSytc0+y7+rqFCq5y2XOY+sSn1iZBGxlrqK2z5U14ZaVpWWL?= =?Windows-1252?Q?Jdj+wmtBAPzGcwJW1Z/F5UlnN7W3rC5LNcb4Xo7yt7QdNxwNZir1cHuR?= =?Windows-1252?Q?bfyUNC5bWCyl5nsWViOjhKz1NqGFDoRIX8wst6HK71qzlngMA2BZ6Rqd?= =?Windows-1252?Q?x++icsohGg/nfPoYPHAwTz4OqlrszBGmJrdld8xZqi3if/HCcKvr+lJJ?= =?Windows-1252?Q?dCf8RBOzyZs3Xkbqgpc0U3h3VghJelo5EEq4eT6n5pL9pZwGmGEbKHGm?= =?Windows-1252?Q?akBmPkwup7/mKKztz1Gg3hVtoVevVHvqrSH1qJ9GxJG3KkA2rDgLp8I1?= =?Windows-1252?Q?hrj1jcZRddIPU+CkafiLS7z5pVWmAOM44L8Oso8fAMjw/D4wzk/qO1Qc?= =?Windows-1252?Q?jrXtArGjEp+xU8Tx26+iHocfwA0ymBYch8GJEo1A3WSiMtX67B6RFfVr?= =?Windows-1252?Q?NUZcOoUpgn1v8h1xBvUMPFCcYVsGW8Egy+dHYTWu+odNnQ0Q+hvGCo2e?= =?Windows-1252?Q?m3Qh8sBb2Ar4B0=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR15MB1193; 6:pFVxl8JhoIrHpeb4nXST8gjL0O9hvt3mI/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jUBGpozwEA4xlDLNPPmaqmRqItZXqvL9dRYtTkvedcPBiboiUlPFo2IOQod/CPh8cqXStXJjPoPsvHSDJ78ubZYlXg2ybzil81ocI8rJKZLr23aQis5n1/QXBQ==; 20:5X4fNoaorAhsmCDfK5O2LYiVs7pkcgSdFTS9iOq3kTUkotQEvWoIClk2ERmSabEJA5+X/fXdB5f7RfGR3dYojj8tgwf3iTK2ZzaiDbrUjjqR6WlpVx7nJhrFH2MbPClgiLjvwIZmkc+wm5GiTGNJZ33B41rjHNYjB/OUce8PUs4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2017 19:52:19.3472 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1193 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-26_13:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 01/26/2017 12:48 PM, Jens Axboe wrote: > Once we mark the queue as needing a restart, re-check if we can > get a driver tag. This fixes a theoretical issue where the needed > IO completes _after_ blk_mq_get_driver_tag() fails, but before we > manage to set the restart bit. > > Signed-off-by: Jens Axboe > --- > block/blk-mq.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 223b9b080820..8041ad330289 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -928,7 +928,16 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list) > if (!blk_mq_get_driver_tag(rq, &hctx, false)) { > if (!queued && reorder_tags_to_front(list)) > continue; > + > + /* > + * We failed getting a driver tag. Mark the queue(s) > + * as needing a restart. Retry getting a tag again, > + * in case the needed IO completed right before we > + * marked the queue as needing a restart. > + */ > blk_mq_sched_mark_restart(hctx); > + if (!blk_mq_get_driver_tag(rq, &hctx, false)) > + break; > break; > } > list_del_init(&rq->queuelist); I screwed this up when splitting up the patchset, that last break needs to be removed as well, of course. Updated below: From 9d68cf9232c06a793e305d10b6d655df4beae928 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 26 Jan 2017 12:50:36 -0700 Subject: [PATCH 1/4] blk-mq: fix potential race in queue restart and driver tag allocation Once we mark the queue as needing a restart, re-check if we can get a driver tag. This fixes a theoretical issue where the needed IO completes _after_ blk_mq_get_driver_tag() fails, but before we manage to set the restart bit. Signed-off-by: Jens Axboe Reviewed-by: Omar Sandoval --- block/blk-mq.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 223b9b080820..5cf013d87c2e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -928,8 +928,16 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list) if (!blk_mq_get_driver_tag(rq, &hctx, false)) { if (!queued && reorder_tags_to_front(list)) continue; + + /* + * We failed getting a driver tag. Mark the queue(s) + * as needing a restart. Retry getting a tag again, + * in case the needed IO completed right before we + * marked the queue as needing a restart. + */ blk_mq_sched_mark_restart(hctx); - break; + if (!blk_mq_get_driver_tag(rq, &hctx, false)) + break; } list_del_init(&rq->queuelist);