From patchwork Thu Apr 12 19:11:11 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: 10339133 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 A9DDD602D8 for ; Thu, 12 Apr 2018 19:13:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96B5C28390 for ; Thu, 12 Apr 2018 19:13:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B1C928397; Thu, 12 Apr 2018 19:13:43 +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 DA57D28390 for ; Thu, 12 Apr 2018 19:13:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753595AbeDLTNm (ORCPT ); Thu, 12 Apr 2018 15:13:42 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:33336 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753588AbeDLTNk (ORCPT ); Thu, 12 Apr 2018 15:13:40 -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=1523560420; x=1555096420; h=from:to:cc:subject:date:message-id:mime-version; bh=aYLNMe/Y8MnKV8Jw6jC5q2ppdNPBIKd8PyCQms9klCo=; b=ILKVkoHesV/NMG1K62LEHFCuoedRslI+Bp4pps6TtjGpg1Tu0dHfKdD+ GkSoKhJ5atjPs8av0Srq3QuZveZPtGV2Gc8jqOLJ0+nTgR4iVNAZi/pa5 2D590UbP9IynE0AeSPuXRC+I0FX0QjsLX5mpdWcUuer2Q62H4PGu7PCLS 3aer6D/1dTigVKYFTvfGdLo9kMKKuoU6oP3AK8SwF3lv3EdpfA3xt8q/+ XwFC+Liqx70ITe3hX+JJ4BeDGB4FX2MMOD3IyrRy5/U2y9cSu+PDRVrfQ 1hao2pfW+hrCWzFFc66Tj9mR7Lbx5EOA10r9LPLOSWvaWY5nNNvjrL5c8 Q==; X-IronPort-AV: E=Sophos;i="5.48,443,1517846400"; d="scan'208";a="75732609" Received: from mail-co1nam03lp0019.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.19]) by ob1.hgst.iphmx.com with ESMTP; 13 Apr 2018 03:13:39 +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=+Lmkvqi1+9RUWf35150L60IKMfuBVRYlgE8LVb51hxQ=; b=gyOn2EGNo+5tovYlYngMwKaA84xV83LQ6FuZZUOsYDhL0FilF+PBUOjK3tp4dysMC6514juX7pf9qnVgmpxRw6aOqVK5JtgZnInsJEmkz4hp9UsXzvXgLD/0kPgMbwHdHEbdvM3lwKO+P2nEtvg2RvjDHAnA7A8lc7AK79+3N0k= Received: from localhost.localdomain (50.225.201.71) by CY4PR04MB1192.namprd04.prod.outlook.com (2603:10b6:903:b8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Thu, 12 Apr 2018 19:13:38 +0000 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Tejun Heo , Alexandru Moise <00moses.alexander00@gmail.com>, Joseph Qi Subject: [PATCH v2] block: Ensure that a request queue is dissociated from the cgroup controller Date: Thu, 12 Apr 2018 13:11:11 -0600 Message-Id: <20180412191111.11882-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: DM5PR11CA0010.namprd11.prod.outlook.com (2603:10b6:3:115::20) To CY4PR04MB1192.namprd04.prod.outlook.com (2603:10b6:903:b8::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:CY4PR04MB1192; X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB1192; 3:+JTuyRy6JPXz3pi4uQFTYi/2XlyWd3Sf6v7yROGiMx5gRoa0+IoOJ+KtMBiCk2ArSOSZtobWTj/xnvidqDfLZQYf0n4rIUt0Mig6NGlsf7+Rg4/dasOe4bD9uYZRRmmPkLEUzjBzKVI3Ghy8BE72u26Xp6PMhqQGVvDNqJlPVX54khgDf1ZvKUGTfrsnZ2T+Xjn14/yxTYNdGk9u1y1swc57W2ctgZ0DvVxDwPMoZvnO4JdAO4MZhbFpuTphru6A; 25:JnUBp02pExrTmb8Tv/lYOmaDLOalU94uactrucoJ2hs+UQjTiXGnIr6pvPD7Bi/QpSe39qdmrF54ElUY/FsfYi9Y/1w+KKsts5Ta6bX5RpVXiYnVyaKqrI40XY+QL1riRzW+s78eWpzFOlSKvD6b9qeyG+Rdd1IiIu9y0VfIeoeoCdPloGRTU4y3vPCMLBI/oNQqdtbs9pyLFu6YuUTJ4G2O6Jy+jAT2LIOZUjrTsd6ZW8MYKMNjpfRXK9XSX4YP7/85K8+n+ffAIzqtfWNzP0EfQP1YioeDQcPww1fbv/0Mzs069Pjc+/gQUFQE+2d0J1kr3ORWIRoFGueTY8ZR8A==; 31:WfBPmFKDoEYcUZX6uhJ+KqdBucI3+LMfU2x5BW0aeTPxChx//y7eAwT43F/NChxAcxx8zXdOGaAJzvtmQEsIQhoje4yNj/NEE+erO0JNOHKnrUiY3BYHYmyKywWX1tAwIASi7AQhXIDXcqrS5evTV3eWT0UxJl2pON4A0IA+YnNAofwSJcj/vfRvAqWkbO3X6FDCztdOmU+xvugZFkFIuUnp0/X3GgV1/b2HPirX8MY= X-MS-TrafficTypeDiagnostic: CY4PR04MB1192: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB1192; 20:u8BbEAARBWXvJvwff8eNuDTVLB+VgXFJIlMnQQHcMiOW91zv7kD2a7rY38ZET6EQGzp9URpWlah11BjlTxuh8a/8/s7hB3/WBkqBoQ4kHQHToIbDFdHLGL1rccBen3ON48ktgM9oK6lRirsZwey/U6bYvId6ngGrLu8KGh54c5oHdRfTfBYewXXaaRuDDhfM+bnMySor4R3If71b0Z3ZGpVLlXJQ/WErSUGTX/paSoV8QhVGX6aYg58selTYYqmJoEkzUNabcucXdYI4em1Ky1ThWs5kca2dH3YmfP4Pn1OkdACWQbRJrg2nHKBBW2P4zkiFiUpEFPZ4os+d0hd1EP5H38tkLPRor5e1po+1HtFuvq8kAxwo0UGkeHy+lsF+y/drGp4Sc3Bm8lkB0J12XI1Hg9NSKtCU77zhKIQiWQXcseUh8geO+jXs2V3fqlQNp58k4QLxo5D3msspQaRFQ02uXJvR8AEuhWUqY26EEZ4OhN1N6LwpaYhdtcuwDaDl; 4:sTwUVGUK03GHvB33k0Ee94ShCmMFInzRSKaJhTSIWQC/X5cQg/3v4jpG+2MeGhBJqpqrF5XNSPY4WVfHAl0dg/9vlo6SIAKKAzKJullFMtGJuvqJ+RmAumwpEoWR9+j/ZtD6WBZXepWQQJdy/jILqvXEm+HE3IXIx07VlBUKp9iUybHcBWf2NBRfMzFZlZe9rux0SVG8H00IQDm/ykyTHAf08qX2TyVDVmZHFFAXUyqlM9ZmSTxnjafG+pXtIT2ijXHvKbbNdORXG9iGFC1mdlHeooHW/IjgvgBrLF26+b3tKelLr8w7P+5ZLGDolPiEOwvgOivD1C+454+Pjpp/LxwFsUxOWCXeiYbHLedWT6Y= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(168385556255192); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231228)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123560045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:CY4PR04MB1192; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB1192; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(346002)(39380400002)(376002)(396003)(39860400002)(366004)(199004)(189003)(105586002)(476003)(6486002)(305945005)(6512007)(6916009)(50226002)(86362001)(26005)(106356001)(186003)(68736007)(16526019)(5660300001)(486006)(52116002)(386003)(316002)(54906003)(48376002)(16586007)(50466002)(6666003)(51416003)(2616005)(59450400001)(6506007)(81166006)(956004)(36756003)(478600001)(3846002)(1076002)(72206003)(7736002)(8936002)(4326008)(81156014)(8676002)(25786009)(6116002)(97736004)(2906002)(66066001)(39060400002)(47776003)(53936002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB1192; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR04MB1192; 23:A8hCwuTZc9hAMFTaH0RB1QNVW/RlIeM6TpIMZtelp?= =?us-ascii?Q?cutWqjkwcl2hsedn/vpd1g3zP7p7TjFAT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HMZ7qdltOsL/lUc5YYR4RLFQZo+iMVYfcIma5w==; 5:vQpUdULhgFff4riPiqSy0H4Mj8j/dVYPJqFQPI/JD9NYYH7xiEkhLRZoLKTRP216tU6FT9XEWlU752Kua8XIXmnmfDZyNsxlW6JFtKI4FFIsQerBNhTdPdrbHtFXzfj0ETWCVQBUf11ZzcbvPHx+ZL+jYjrPYE2t34UGlHpx3s4=; 24:ffUg7G4kcsmbZ4rToXAeivWhvc5rLo2LZrmX7f/WtPq5nNUt6QJY5A7hS7rQPUyfnxpFq9fgUvK2jkKfu0mX3bFMgU9Gb7+PMY4h5iPB9WQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB1192; 7:pvQnV/frwRA/Ia/U81+L1ATP9AnJEXmHhDIqVFDdC4gRW0eOjUpjLFk448YnJAX0cfKAJrC/LrQhRJfjsSoSnKZbAR9vD/QwiILxFYCRx4D7D/AaPE9AJxJdzo9K5XlcIX6e7qqHcuwLtSao+0IfC2QQb4M81v9NsSSf9zUOAxcU4GYaFDBvXuAZXjSkVzn8uhfDbyMHhbPRoMEv3NjN/jlW+6NHxVISLCUL//0hhlUg23giVA64EZYx+bOLg0S2; 20:MhRgMKn1SEyT5LNezea2vMuQfRSDz310MVMxcxiNu3kaJPg52AoIoxKjPEPF3P0vxYUbzDlo7P2wlWVTZCjevjoFfdPInLkaW+V87bwHnLmmtdiWXRghjYPeIH0hq5M4m5y2ZjM9dfoha+lz0vvrOneGKLT//YT0x2Yvko7SJ8k= X-MS-Office365-Filtering-Correlation-Id: d4e81b5f-14c0-4a53-10bc-08d5a0a97f0c X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2018 19:13:38.0457 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4e81b5f-14c0-4a53-10bc-08d5a0a97f0c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB1192 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 Several block drivers call alloc_disk() followed by put_disk() if something fails before device_add_disk() is called without calling blk_cleanup_queue(). Make sure that also for this scenario a request queue is dissociated from the cgroup controller. This patch avoids that loading the parport_pc, paride and pf drivers triggers the following kernel crash: BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride] Read of size 4 at addr 0000000000000008 by task modprobe/744 Call Trace: dump_stack+0x9a/0xeb kasan_report+0x139/0x350 pi_init+0x42e/0x580 [paride] pf_init+0x2bb/0x1000 [pf] do_one_initcall+0x8e/0x405 do_init_module+0xd9/0x2f2 load_module+0x3ab4/0x4700 SYSC_finit_module+0x176/0x1a0 do_syscall_64+0xee/0x2b0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Reported-by: Alexandru Moise <00moses.alexander00@gmail.com> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller") Signed-off-by: Bart Van Assche Tested-by: Alexandru Moise <00moses.alexander00@gmail.com> Cc: Tejun Heo Cc: Alexandru Moise <00moses.alexander00@gmail.com> Cc: Joseph Qi Tested-by: Alexandru Moise <00moses.alexander00@gmail.com> --- Changes compared to v1: - Surrounded use of blkcg_root with #ifdef CONFIG_BLK_CGROUP / #endif. - Added Alex' Tested-by. block/blk-sysfs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index f8457d6f0190..46bb932721dc 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -793,6 +793,37 @@ static void __blk_release_queue(struct work_struct *work) blk_stat_remove_callback(q, q->poll_cb); blk_stat_free_callback(q->poll_cb); + if (!blk_queue_dead(q)) { + /* + * Last reference was dropped without having called + * blk_cleanup_queue(). + */ + WARN_ONCE(blk_queue_init_done(q), + "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n", + q); + bdi_put(q->backing_dev_info); + blkcg_exit_queue(q); + + if (q->elevator) { + ioc_clear_queue(q); + elevator_exit(q, q->elevator); + } + } + +#ifdef CONFIG_BLK_CGROUP + { + struct blkcg_gq *blkg; + + rcu_read_lock(); + blkg = blkg_lookup(&blkcg_root, q); + rcu_read_unlock(); + + WARN(blkg, + "request queue %p is being released but it has not yet been removed from the blkcg controller\n", + q); + } +#endif + blk_free_queue_stats(q->stats); blk_exit_rl(q, &q->root_rl);