From patchwork Tue Apr 10 20:30:35 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: 10333819 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 011956053C for ; Tue, 10 Apr 2018 20:33:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E41C628408 for ; Tue, 10 Apr 2018 20:33:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2CCE2844C; Tue, 10 Apr 2018 20:33:44 +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 33A1328408 for ; Tue, 10 Apr 2018 20:32:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753499AbeDJUcy (ORCPT ); Tue, 10 Apr 2018 16:32:54 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:33121 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752064AbeDJUcx (ORCPT ); Tue, 10 Apr 2018 16:32:53 -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=1523392374; x=1554928374; h=from:to:cc:subject:date:message-id:mime-version; bh=OlG7PCa+otQhJM9uMiMCv5UD4JyFjtjXFvY7uMX0bxs=; b=LXYIwA3yUjZ3iMCoKoyVSOpdsVv4usPjLVPiKal5BpGs8rz9XmA2zAe0 8zwVsPG/+wNjQGg+nEcP5FvaSuyooF51zjOaS4psGS9GIO0T8osgaZIo0 +B05tapCz/QiADl/2yUFqiWhgg85ExDtmNVEqVcgyMQAQ6PmSuI4UkdLR sYd3YhP3l/WmJQkWu4QIF5Ig/nAq1HNSPpRfTl6ypQwiNBxDtgTTDNv4R KK9qmMQsV6vd+Y6/qhDIiDsWKNf+yzDdv12mytR4F2a7z3SJfZuF9U+va 3pa4Mid8IdgI4WACjKklBEYYRc0Wwqoxhns0vDxWvL0xqxNLBNZ2t9BoQ Q==; X-IronPort-AV: E=Sophos;i="5.48,433,1517846400"; d="scan'208";a="76394635" Received: from mail-sn1nam02lp0017.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([216.32.180.17]) by ob1.hgst.iphmx.com with ESMTP; 11 Apr 2018 04:32:53 +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=Ouu6LX4QrymUUon2lpreLxauF+ac+FmbmK5JIY/1//8=; b=QAv8Qp/bWj1GvSxyNQb6B8LC4S2e25+bMPH4v0L41cm5BbQKzrqlPnrcr1P7GWdJY+jvhkBhpbDCm/SlIQuQInhdQslyVs9raAE4ZbU9kAXPRlNvzmA3lkE4OBIfmJfV83uGadqjv6O0zz8ZcWc7qgDI8M0Vmdr2nBhN948IOLM= 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 20:32:49 +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] blk-mq: Avoid that submitting a bio concurrently with device removal triggers a crash Date: Tue, 10 Apr 2018 14:30:35 -0600 Message-Id: <20180410203035.26167-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: DM5PR1501CA0027.namprd15.prod.outlook.com (2603:10b6:4:9d::40) 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:HxnVem52NRSY/8SA6tl/fo4HNgWrDWqrqwoP1X4vS938GZQWmeNKwZ5FvPX6AkvTKG8ytvKnjGJ9UQZzy0ER91GlphjV9xaUx6I6BHZfyrHOieEr65R22j5xVYGIl9LZlqc1G7aSOeGgZUv/ecCnKGm24WCXultAdqTA+aHvm2VUPR7tXLDal4aKFkHXLBAOUnn7oAO4UpogkSgS/zD5k3GhnRVRqfAK+p+j+HmLDokrBxtyoPeDuSz0Oc+XQKRI; 25:KoNRsLMrZTR5wSVosJ6aDPhmVHFlUk8HUccQKts65080abSWYHF1eE+t2RRmuqakXIRL8iUH6VEBx8uCDwH1uHVSgLqjyZRgZEpN0FuKDiwgRbOzMJ5d9pbl+JhmfYNgncXWfpXYRHWLAkoIJG2vaLPiKiRTndTqKvxg21kinPPfs60pn+MeU2JBBuwTq80ZZEOdlZ/aO17B/z8SeraLgu4M2VzzcsruleoNP/9ODRKNELrvxDGR0YF5Ptbu6n+Os4T4CdtpXtpsgeSLM6D3UDf+IkZdeecPBX+kESAjNQNUrjQCBaz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jWaR0a8743sDw+DEZHHgdkpTjtWlSqo3DbkOZUOkg+QdTLcTCLf+4POPsF94BJ81i+gbtmLISIhslvSCP5DPplYV3cIlTksBhqbW11oGB0W7KWW2BU1xZTlwXy+yBckrpnzXMDlwPRvG6Tqet7ylJHHRJVWxOLKTSvqdyude/sM= 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)(5005006)(8121501046)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DM5PR04MB1194; BCL:0; PCL:0; RULEID:; SRVR:DM5PR04MB1194; X-Forefront-PRVS: 0638FD5066 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39380400002)(396003)(346002)(366004)(39860400002)(376002)(199004)(189003)(97736004)(25786009)(4326008)(50466002)(16586007)(6512007)(48376002)(53936002)(316002)(1857600001)(81156014)(8936002)(8676002)(81166006)(68736007)(6916009)(6486002)(186003)(478600001)(16526019)(86362001)(5660300001)(51416003)(52116002)(66066001)(26005)(50226002)(476003)(486006)(6116002)(1076002)(3846002)(106356001)(956004)(2616005)(59450400001)(2906002)(36756003)(105586002)(47776003)(6506007)(72206003)(54906003)(7736002)(6666003)(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:hgSh2w7Zk/TtlxVgLPoe5IYr1fTD8BQUaMqU2wJGw?= =?us-ascii?Q?eNsxeDLN21cbPvoENabp+N35MHrMpzwhYdy9N16ko8OoT6aK2r4fxqhRuW2B?= =?us-ascii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MvyNpXmqM5ywURKw==; 5:AUISr49xkLQO5qk+QYfd8IuTMeZFPzNzVUlhba4pkgRjDOOi233nfubeWYcaiQmLb54J5yhbR1MDDJsQa0SH1UfjmISIdobDwQD1tnZVOzTkd0f5w9mor9XXq3BywLcITTTQz6qsUkV8kPb3W4qvxbn0h82voT7pvpO2IwaRbAw=; 24:BV2IcEVO5kei0DtpF+/Eqd3n5Qu0NqgRWMKALMWRHmQUdf3O1wsANc8tqHMbRnK+EzT+Cvu1C2iACO671fEXuoxc8MF0w/ImF0/PoanOtEI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR04MB1194; 7:mZxl9CWlbcLAym5IEER1ZHaeiMbpC+NE0MlmngEZXtVJxB2PzQ/eFlkUuEjeYKrEpFWmQ/PQtFBqfzQS6VH8FO66tFhhP8mlf++ygDcEvAEqcbBO7h9r0PqO+Pr8qJC5d5oUelyi6xvoTeHHNM4yGND2bsdKj1lr35eO673ko2dfZPabQMez6ciDiiaD3HBYVxc0lYK/ddc7HyUYA3ExULJa8dW/VPNvUW4F8Ki8X7qhbyknRXT4ASMrMFdN41hX; 20:9eypFTPdMsjXqUoGBPFdLdtvHBeKH6XhbEXAc0BjbMyIrHZHaHNewiZKAK64epmVL8/t91ltJqeXYcaNTP7/ZsQZQ2YZLuJKf5UM1pCPGNLNyQTyYhB3I6lyyNjkHIuBqUWD5RsGWHe1AYnfnWhLS+u5CE2hOT4tqztRGWP4BTk= X-MS-Office365-Filtering-Correlation-Id: fffbe57b-2d0f-433b-0bb3-08d59f223a84 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2018 20:32:49.9573 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fffbe57b-2d0f-433b-0bb3-08d59f223a84 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 --- block/blk-core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 34e2f2227fd9..a330cd2829e1 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,20 @@ 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 (likely(blk_queue_enter(q, flags) == 0)) { + if (unlikely(q != bio->bi_disk->queue)) { + flags = bio->bi_opf & REQ_NOWAIT ? BLK_MQ_REQ_NOWAIT : + 0; + blk_queue_exit(q); + q = bio->bi_disk->queue; + if (blk_queue_enter(q, flags) < 0) { + enter_succeeded = false; + q = NULL; + } + } + + if (enter_succeeded) { struct bio_list lower, same; /* Create a fresh bio_list for all subordinate requests */ @@ -2436,8 +2456,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 +2482,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);