From patchwork Tue Apr 10 20:45:54 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: 10333831 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 B4F006053F for ; Tue, 10 Apr 2018 20:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A458928408 for ; Tue, 10 Apr 2018 20:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 989DF2841C; Tue, 10 Apr 2018 20:48:14 +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 D11D528408 for ; Tue, 10 Apr 2018 20:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751884AbeDJUsN (ORCPT ); Tue, 10 Apr 2018 16:48:13 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:37104 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751624AbeDJUsL (ORCPT ); Tue, 10 Apr 2018 16:48:11 -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=1523393292; x=1554929292; h=from:to:cc:subject:date:message-id:mime-version; bh=3XXnuy/P9yGH3zx2HsgE8rU+7zd1MJSAAC24EGjSvx8=; b=kR9pG1gwoiMpuDRyHsEvbWLJ83QWUGMgk4h1LFEY6pu8r86vbdiWj+7r dEWJJb1BRfmFogemelZ9wX7OC3cmDo3AA1nzL85ik5/FiQtrMwoDJsj62 AVoaD4LitIbIgybXDaY2nFqmuXF/aZPNWVyqkGC010qQsehw90jGOgwn9 ygBFRmE+S4w03MueHG+BMJw6S7a5ysnkatK5Y/fc7u8xnZqwz9gmf0jpz 6894Rfq+tZRwr7b6NK01qaIovxSgOVWiIeUuj9Hv0DPple+D6fAgpgsd1 sD49zRq0FkIiZpH1HLiTcGRV305kaETNpsKgvpwa0TmFpCp3yx8x/UrEl A==; X-IronPort-AV: E=Sophos;i="5.48,433,1517846400"; d="scan'208";a="75542783" Received: from mail-sn1nam01lp0116.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.116]) by ob1.hgst.iphmx.com with ESMTP; 11 Apr 2018 04:48:11 +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=n7AylCTlRyucLgLvR/5ttazul6eWkpUP5xZpIfbukW4=; b=jFBU1BRX6lVcVBU5Ww8/Vzrx+CyxHKM1HPtSVL/izvjGA/JRHiBoEZXhPiLNgO+TwbHS1hbxs6XbJl7awBZ91pSr2EsZ3jRE68I9/U1Ig+qgC++gxE5XvJu9nUp+2mw0kFDfYuW9clwLnYGMpKkIUHGMe83uskJ6ySxxGxhplek= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; Received: from localhost.localdomain (50.225.201.71) by DM5PR04MB1195.namprd04.prod.outlook.com (2603:10b6:3:a3::15) 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 20:48:08 +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 v2] blk-mq: Avoid that submitting a bio concurrently with device removal triggers a crash Date: Tue, 10 Apr 2018 14:45:54 -0600 Message-Id: <20180410204554.28914-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: CY4PR04CA0046.namprd04.prod.outlook.com (2603:10b6:903:c6::32) To DM5PR04MB1195.namprd04.prod.outlook.com (2603:10b6:3:a3::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DM5PR04MB1195; X-Microsoft-Exchange-Diagnostics: 1; DM5PR04MB1195; 3:L1C5N5+DgWdceixRzlQbs7uHpzcXlE6uzwQY7xtcs52ETcgpVI+H0kG1FEX9UivFfYFlKePm4DUZ6bn5LwDzhZ0PPFPFxmQJT2tE8MfOHvyUJspOnx8jA+W3MNxSGLv6xzjkH7UqbbpVEgWaMoRGdz4RZLta4IBpQiTalgmVtnsOiMs2sQdqx1SW0+MlOniHBYP2csKQseS/r0sKKNsKtfA2H9NmXvunF4F78NV/0D3yZ/BmJG4+4qWqsusC2GDe; 25:s4ZlgG6mNN9KVpwJ04eihpUSiZwIgUWmaRMQPUyUXwnAN5OBajqzzBgQo2NsaZyonFfgugOHcL1rUEaYkWAlF2BSbQS2p3k54R66EwEkZ6s359a3x4YRJU0LrY0kTTW3cm91Qv/xD6OX6HA/HD3cje6NMis5iHct7gO/CkFIt1D8rPc+kMLq3YWZKRaOMXggoMpWroXEn2nVUIsJda9BZ4MG1ZXK7IUP60VM75pJ8iE+05VyMofTpxr0CthM9qnb8ose3P4pFI0sQSJV/Ar96yUTXM2QMltifP/TRKcdiq469aDuPUnnPNbzhZaYG+oaDG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kQ634PIUflMzTx9/FXQ9pOQUY4plYMNfAAlErn+71SmyiDRbFn6RIKby9mJFzTPL1vSxzoCktRG3vzY/0FqpY2v22GMsF/vxwcCmDL6xo0/LPuVZNoVhAbc+54T7oU8LJGDmhtyDfQFw+71hmTo8ZYdAqPQ= 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)(93006095)(93001095)(3002001)(10201501046)(3231221)(944501327)(52105095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:DM5PR04MB1195; BCL:0; PCL:0; RULEID:; SRVR:DM5PR04MB1195; X-Forefront-PRVS: 0638FD5066 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39860400002)(366004)(396003)(346002)(376002)(39380400002)(189003)(199004)(105586002)(50226002)(68736007)(51416003)(2906002)(316002)(48376002)(8676002)(97736004)(6506007)(8936002)(59450400001)(386003)(6116002)(47776003)(50466002)(81166006)(54906003)(36756003)(16586007)(16526019)(81156014)(4326008)(25786009)(186003)(6512007)(5660300001)(3846002)(486006)(6666003)(6916009)(1076002)(106356001)(305945005)(53936002)(66066001)(7736002)(72206003)(52116002)(476003)(2616005)(6486002)(86362001)(26005)(956004)(478600001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR04MB1195; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR04MB1195; 23:qHuvmVETzazu+G7el156o/JwzCBtWXUmVoLWx53zV?= =?us-ascii?Q?f9KflLjDHTHFVquf0RdA7c4DRqb0EtuVBbpof4OhmJScuoJWu6OqhNAGRU+L?= =?us-ascii?Q?nJlB15EZNo1qZ7lKsBy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M1QJJXfb1zGOT2Nz4C0oqz/CW4G1vNVy+mMetxtyXI4M4e7uBpsaxc+4nBYDLU+hANcwnzaDWLdZ3GX7bHWleE34nz+BZh7+HZCYq5to1R+LkxySOmcpq0cA1BGLOCoPYKtfCg=; 24:mGpf8OyYhgf9QKY9807eTywss8MXG2wa2Mnv/6/c7myn3XVTqBgjpfBVf2HMt1ap5bNfacdH3mEbZajhmTC9FzN0GlA4WxhmHaXZcVVg+DE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR04MB1195; 7:sZSK8Sw/9b0kkJ8kgfckiSVI3RXVCToE84TlqD1OvPm7P2cZ1ar9Rv0zgfadhwwPaIeS/P4N0rpAp0cSSXm+Lj5bi7G+GnlbRTyIlPZODGoMIqSOJ2hu9ApfDqtlarNKVPS0BV+do6wh7AOotg6DVw5pspOgpRNBUUBcu6WCzzszvNgAYq2/E+zdyRO8gLtFdso6O7hDdqARcguOLuYdyIjOpMeZ8F0YNXgf//pCn5UAXjiYpRjqcFA9q82gtYFo; 20:dvit1xmbsJW4mi+ji1d23P0FVk1eyxJtaQuq53nQN5pVTrXq5oZ/7QdUJ7eSFtRibhTPbaasGRxQlQoFlZNbF/4dMRlm11V3okzJIrRnAI9g6R8iMseYU6jjGg40obe3GR3fSg+shuhq+wYSCdHPBSoLTw5JrfgetDQY1SNyJo0= X-MS-Office365-Filtering-Correlation-Id: 0b7eb444-14ed-43b2-0447-08d59f245e11 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2018 20:48:08.6730 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b7eb444-14ed-43b2-0447-08d59f245e11 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR04MB1195 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 --- Changes compared to v1: changed the blk_queue_exit() inside the loop with "if (q)". block/blk-core.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 34e2f2227fd9..181b1a688a5b 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2386,8 +2386,19 @@ blk_qc_t generic_make_request(struct bio *bio) * yet. */ struct bio_list bio_list_on_stack[2]; + blk_mq_req_flags_t flags = bio->bi_opf & REQ_NOWAIT ? + BLK_MQ_REQ_NOWAIT : 0; + struct request_queue *q = bio->bi_disk->queue; blk_qc_t ret = BLK_QC_T_NONE; + 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 +2435,21 @@ 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 = bio->bi_opf & REQ_NOWAIT ? BLK_MQ_REQ_NOWAIT : + 0; + 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 +2457,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 +2483,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);