From patchwork Tue Apr 10 23:02:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10334459 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 0B7846028A for ; Tue, 10 Apr 2018 23:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0386420499 for ; Tue, 10 Apr 2018 23:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E887E28533; Tue, 10 Apr 2018 23:05:38 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 B758A20499 for ; Tue, 10 Apr 2018 23:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755905AbeDJXFg (ORCPT ); Tue, 10 Apr 2018 19:05:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:53524 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755819AbeDJXFd (ORCPT ); Tue, 10 Apr 2018 19:05:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1523401533; x=1554937533; h=from:to:cc:subject:date:message-id:mime-version; bh=Q6O3RqX9c0JKNgUadA2B6UO5n9Pdwjexl0sWiG44frE=; b=GxexHu8uyFqM1wG9LeNx5O4cfLmOCd3LegR9/1FUknZ9m7OHz1z/zeWb krrhPZhW7bLm811rGop5cnUQ4b72xpFyHvGvqt0riUg9izOnB/ZhyTycW pUXh3jXyQxVZqcn5f7OdnnsORJUyO4ZLmLkjcwrj4/t9gWFNsOJR4wMVG ZK+xzYGnijkeddc/LSSrAk5nWSg6D56T70W/2rNLr5QHOH5YyHIez8nzG AyYlWb/Eiokq5YvRHR57WZElGgBCFkYP1L0ui8JiAVZxBVm/ZQv8M9MX/ vJYCAd9a96YpaGGNLLv9L74SydPcUXkjJrYO8U2lb39cNIphIpkRLSAK5 A==; X-IronPort-AV: E=Sophos;i="5.48,433,1517846400"; d="scan'208";a="76403669" Received: from mail-by2nam03lp0055.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([216.32.180.55]) by ob1.hgst.iphmx.com with ESMTP; 11 Apr 2018 07:05:33 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5cAk3gTNBNrUpsrR+WlvOx5r/spQOsvURNZmbFFDJrI=; b=h4OBfH3HdV/y5y77xHtDRb2QTtePUeo6WubAf5DfEO6tL9LpamPBvyQYjX74ToShm1wnw6BZLB3Cr7YfqkMXuX8viylnodJCh9+oKsRSZfAozqcuoCjhGM9z/XflPjsbMiUlmYeuELKpitoYQ8+rcwCS8o/dZ0WZ+anGK3iPW0g= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; Received: from localhost.localdomain (50.225.201.71) by DM5PR04MB1194.namprd04.prod.outlook.com (2603:10b6:3:a1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Tue, 10 Apr 2018 23:05:30 +0000 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Joseph Qi Subject: [PATCH v3] blk-mq: Avoid that submitting a bio concurrently with device removal triggers a crash Date: Tue, 10 Apr 2018 17:02:40 -0600 Message-Id: <20180410230240.27709-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.2 MIME-Version: 1.0 X-Originating-IP: [50.225.201.71] X-ClientProxiedBy: DM5PR11CA0007.namprd11.prod.outlook.com (2603:10b6:3:115::17) To DM5PR04MB1194.namprd04.prod.outlook.com (2603:10b6:3:a1::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DM5PR04MB1194; X-Microsoft-Exchange-Diagnostics: 1; DM5PR04MB1194; 3:wG+eFl79xlkE4iERw+bNEJg6HHON6Jauq+D35wKGuE7GorDsxWb2zOT5Mk8sIbhaprMFdBX5jAZAeqVaDIfA9nbMTUOIm9F8A4lM5h+sUHAT2EULYwecghd7xRITA0BbsdPekjIhKGlDB2jwOq0Dqm33qAmzRiGdYOJ0qfa5I4apAtzfbxA/s3WisaKw3Y02dz+fYveE3EQD2Lzb0aiDEFFnaEoyVnPQnObvBUgfUi9CpWD4GZj3DdlxI2MtF8Dh; 25:YJBWvogUxra45Ll8cGd6+114jSrswoZ6AWmp70bHYiBj8xdirHR/j/djSpi741r2eqiAk1DcJdIOcVNJ9zUnR/VbyS5Euujvy0DmM4vUOaPxIYE2BGNsKbrGkV5acHPCr15z2nRpNKa5/dE7NC3QG1psXUbI8Y8OKUQZoM++B3j28yQsTzcKeusKXRpeV5lqrXBiOC7ro93kF3crPyHg+mpwoonztcS/oC5E9EiaBglL6EeIeksi/GRURvGdxv3ta8hjXS6rl98SYCRTtRYijszylxYSuG8NpGcXmVEi6ftQjeQpfT5Q4j6VNOBdAAqtvCKz214fZx9bJe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LHk+vxaVhiOWAjPmOG5Jch/F64rQ4pPErg71TModsERWJncoLSbCqFe31Q7QSQ7QHcdevvpDMIIizTOTQjp63VKAMoFOwm3ikg/85LId4elnvAh/dmiR5CLbHNTdpZwL76SV44wntVd0OqfhXmNj1jR0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(168385556255192)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231221)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR04MB1194; BCL:0; PCL:0; RULEID:; SRVR:DM5PR04MB1194; X-Forefront-PRVS: 0638FD5066 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39860400002)(366004)(346002)(396003)(376002)(39380400002)(199004)(189003)(97736004)(25786009)(4326008)(50466002)(16586007)(6512007)(48376002)(53936002)(316002)(8936002)(81156014)(6916009)(8676002)(186003)(68736007)(81166006)(6486002)(478600001)(86362001)(5660300001)(51416003)(52116002)(66066001)(26005)(50226002)(16526019)(476003)(486006)(6116002)(3846002)(1076002)(106356001)(2616005)(956004)(59450400001)(2906002)(36756003)(105586002)(47776003)(6506007)(72206003)(54906003)(6666003)(7736002)(305945005)(386003); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR04MB1194; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR04MB1194; 23:C7Ohax2+HCaSDgyf4ePI0M3NBvnRbL6upzX8hM7KH?= =?us-ascii?Q?GOVHKNFkDtr8EG+X3Le/uL0OPSM0kw9W0O0f1HmbBlgYlevzqWlsWbt/3cIp?= =?us-ascii?Q?7H4yuuzoAHvQ+fgzMkND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DZw0957rSeanQYv2eNK+ZAYlhpyrkPH1Loq/sUrONWBzoaSdFbT9o0nMroDWUufJhM+dPxUDBdG5GKViZY8uChl2dfM10xg7Tt8GWt6qnQ4XU8WzD1DypA5+Q24W8dt6l7+rT41cfn8Foiudo=; 24:Ar3yI+y2450WcQ72+lO9ShBNuH819oSUYysiEPm3XBoQIMAigCdVZfK3kOTo6Av2cVLXX7w45EuOF0SZoDOB3NEOZ68+eXpVAyGp/Xr7FMw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR04MB1194; 7:VawP9/ktcJ+4Hx1ok3cLYG7pM/yJj9UxnAUurbp/hEP7pWJm3BX54ulqUTQ4DaJFmjE2KqgUNnCFON2whW+90n026I7vjYgJASRr92L8Vy/TKm5H1/mkUDjcEO/6yMoksE2eGESm0/VCAEEDeXqanfYFk1be1ygX8ox89Fr2Uf0Ndrklgor9SMkoOUlnZ0V0v9wC2ea8b0H0HEg8BTnOhKHlJMSGChRi6DMuWUG3v7NJbv2YUbW6Rio0+IO3Ptlq; 20:2wRrkPwW5HHYoTsf2Ql2lzl7S0SQYWwWzVlFmFRZR0lX7oNlhtx000vA6mkhJ1XvY7t1JDOjcprUFYEQOGtUVE3maM8KvbPRtTE9cAz/RBgJk41WsAZbkQQihSiO0/+H7AmWMTtj47mLAnHFmjYrNbFTLvQhLdbH7H+NDqVl+ws= X-MS-Office365-Filtering-Correlation-Id: b3b6e4c4-9d95-4a68-6c9c-08d59f378eda X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2018 23:05:30.8833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3b6e4c4-9d95-4a68-6c9c-08d59f378eda X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR04MB1194 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 Because blkcg_exit_queue() is now called from inside blk_cleanup_queue() it is no longer safe to access cgroup information during or after the blk_cleanup_queue() call. Hence protect the generic_make_request_checks() call with blk_queue_enter() / blk_queue_exit(). Reported-by: Ming Lei Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller") Signed-off-by: Bart Van Assche Cc: Ming Lei Cc: Joseph Qi Tested-by: Joseph Qi --- Changes compared to v2: converted two ternary expressions into if-statements. Changes compared to v1: guarded the blk_queue_exit() inside the loop with "if (q)". block/blk-core.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 34e2f2227fd9..39308e874ffa 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2386,8 +2386,20 @@ blk_qc_t generic_make_request(struct bio *bio) * yet. */ struct bio_list bio_list_on_stack[2]; + blk_mq_req_flags_t flags = 0; + struct request_queue *q = bio->bi_disk->queue; blk_qc_t ret = BLK_QC_T_NONE; + if (bio->bi_opf & REQ_NOWAIT) + flags = BLK_MQ_REQ_NOWAIT; + if (blk_queue_enter(q, flags) < 0) { + if (!blk_queue_dying(q) && (bio->bi_opf & REQ_NOWAIT)) + bio_wouldblock_error(bio); + else + bio_io_error(bio); + return ret; + } + if (!generic_make_request_checks(bio)) goto out; @@ -2424,11 +2436,22 @@ blk_qc_t generic_make_request(struct bio *bio) bio_list_init(&bio_list_on_stack[0]); current->bio_list = bio_list_on_stack; do { - struct request_queue *q = bio->bi_disk->queue; - blk_mq_req_flags_t flags = bio->bi_opf & REQ_NOWAIT ? - BLK_MQ_REQ_NOWAIT : 0; + bool enter_succeeded = true; + + if (unlikely(q != bio->bi_disk->queue)) { + if (q) + blk_queue_exit(q); + q = bio->bi_disk->queue; + flags = 0; + if (bio->bi_opf & REQ_NOWAIT) + flags = BLK_MQ_REQ_NOWAIT; + if (blk_queue_enter(q, flags) < 0) { + enter_succeeded = false; + q = NULL; + } + } - if (likely(blk_queue_enter(q, flags) == 0)) { + if (enter_succeeded) { struct bio_list lower, same; /* Create a fresh bio_list for all subordinate requests */ @@ -2436,8 +2459,6 @@ blk_qc_t generic_make_request(struct bio *bio) bio_list_init(&bio_list_on_stack[0]); ret = q->make_request_fn(q, bio); - blk_queue_exit(q); - /* sort new bios into those for a lower level * and those for the same level */ @@ -2464,6 +2485,8 @@ blk_qc_t generic_make_request(struct bio *bio) current->bio_list = NULL; /* deactivate */ out: + if (q) + blk_queue_exit(q); return ret; } EXPORT_SYMBOL(generic_make_request);