From patchwork Thu Feb 1 16:16:02 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: 10195633 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 54936601A0 for ; Thu, 1 Feb 2018 16:16:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4123928779 for ; Thu, 1 Feb 2018 16:16:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 356B428A44; Thu, 1 Feb 2018 16:16:32 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B65EE28779 for ; Thu, 1 Feb 2018 16:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752753AbeBAQQL (ORCPT ); Thu, 1 Feb 2018 11:16:11 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:20927 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752723AbeBAQQG (ORCPT ); Thu, 1 Feb 2018 11:16:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1517501989; x=1549037989; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=OXlwlzB/Knfstlw/cTWb5eyYF90VcgbDwDRr/K+oZZc=; b=U+O3P0ou7p1tU32sADgfMsi8r+CZLfZnkpFKMktmVLi+HrttvjQYpdF+ WlWZUUa2oCKLoiiVXiqjsoB1n7LmJNNznONnTSmN52dNXmz/wr+XeQ6WK 7JNI8EWg/+CDnQ5JRCfMEc4nW3UwolvjqdrE8/GaI1CGhjlo7VsHklBo7 gw+pi1LgOYPMLiYLQzlMY2BA58kCf1ZxCxXJxnY5n9Q2hShpDIoFnwRCS pZqmYZoUlNHHFmntRUwX0A4AEGG98efZIlES6KDLJur0AvVG+CTRr2RFv nFbI+rr05Gx1oc5BZF0Cko94BnABWeq24B3ihmPHKXgzuUxzi+pQKFrWV w==; X-IronPort-AV: E=Sophos;i="5.46,444,1511798400"; d="scan'208";a="166769278" Received: from mail-sn1nam01lp0114.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.114]) by ob1.hgst.iphmx.com with ESMTP; 02 Feb 2018 00:19:47 +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=OXlwlzB/Knfstlw/cTWb5eyYF90VcgbDwDRr/K+oZZc=; b=Oe6ljDKim9fbXCO9S9qf45gml4TRXNve4d26aJq069/V6Xwr4Ym7DHONLwvyscnnXvI1Akyfy5vHUnUqreTq/CHRcB9Y9tkGYi+58RxTbRc4oj7TU1ELXCi5tof9n4B7pBTI4tn7d6QegXFvIX1wlWeBZ9iTyxoUlxzRszm4T/A= Received: from BY1PR0401MB1532.namprd04.prod.outlook.com (10.162.109.154) by BY1PR0401MB1175.namprd04.prod.outlook.com (10.160.194.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Thu, 1 Feb 2018 16:16:03 +0000 Received: from BY1PR0401MB1532.namprd04.prod.outlook.com ([fe80::e158:7126:eeb8:3cfe]) by BY1PR0401MB1532.namprd04.prod.outlook.com ([fe80::e158:7126:eeb8:3cfe%13]) with mapi id 15.20.0444.016; Thu, 1 Feb 2018 16:16:02 +0000 From: Bart Van Assche To: "joseph.qi@linux.alibaba.com" , "axboe@kernel.dk" CC: "hch@lst.de" , "ulf.hansson@linaro.org" , "linux-block@vger.kernel.org" , "philipp.reisner@linbit.com" , "stable@vger.kernel.org" , "keescook@chromium.org" Subject: Re: [PATCH v2 2/2] block: Fix a race between the throttling code and request queue initialization Thread-Topic: [PATCH v2 2/2] block: Fix a race between the throttling code and request queue initialization Thread-Index: AQHTmu6jTpBe+bNQa0WcC8wdqiAj06OOyQYAgADxA4A= Date: Thu, 1 Feb 2018 16:16:02 +0000 Message-ID: <1517501761.2746.21.camel@wdc.com> References: <20180131235300.12773-1-bart.vanassche@wdc.com> <20180131235300.12773-3-bart.vanassche@wdc.com> <1ff1b2fa-ffe1-20f4-6be9-919c6a5b8227@linux.alibaba.com> In-Reply-To: <1ff1b2fa-ffe1-20f4-6be9-919c6a5b8227@linux.alibaba.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; x-originating-ip: [199.255.44.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BY1PR0401MB1175; 7:qVEPjZ3owrtaxAUTqdYM0LW12iJ8fVSJTeWK+8VdIvAwm2jxQYW1P+C66OBHZ+MUmbc16MCipYG5oa8M0l40HH1Rw7N7jFm6Yoxx06GSyQZOYJbvFw2whcobR8ZveVjbc82wDq/CWU1/4yJ7EBgE0LGKjOAaIIl2Wj2+cDGUq5i/d5WYmYZrZlMiLqBimsyWDEAdPYHhZgMSnieAiX614/Qpte9Z8KKJTjwA60H/4o4Mhkzze77nkiDKnFaJMl/m; 20:P7FGJ382zsQ3jxFsM1PGVZ7sLkt9rkwv+C1BcJlHNBEK69jgrJsrKPsl7WPmc8tOSklyni13m0zMvR8kgHaNyJyy9GUjmdeWFJYcSFwJnUBWK/mufsGgUy4BRYyXjr7fQl4h8zFST2bAIfPOPvXrBPXaxYaLtaVc92flvJft6pE= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 76374db8-9c45-47fc-8e0b-08d5698f16cd x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:BY1PR0401MB1175; x-ms-traffictypediagnostic: BY1PR0401MB1175: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231101)(2400082)(944501161)(6055026)(6041288)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:BY1PR0401MB1175; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0401MB1175; x-forefront-prvs: 0570F1F193 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(39860400002)(39380400002)(346002)(366004)(376002)(377424004)(189003)(199004)(229853002)(3660700001)(14454004)(6486002)(5250100002)(76176011)(81166006)(2900100001)(2950100002)(97736004)(86362001)(8676002)(2501003)(53936002)(8936002)(186003)(103116003)(316002)(3280700002)(6512007)(36756003)(81156014)(6436002)(110136005)(26005)(6116002)(7736002)(66066001)(305945005)(99286004)(5660300001)(54906003)(4326008)(68736007)(105586002)(25786009)(2906002)(6246003)(72206003)(6506007)(59450400001)(478600001)(3846002)(102836004)(106356001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR0401MB1175; H:BY1PR0401MB1532.namprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-microsoft-antispam-message-info: E7A3acm4prlI1YCZK4NEBCIcfroYtj6CL7LOOV1bS7g5CFIfSsAvGQOSlOb+ifMe2uYeUFnTDjzJyyA3ZVg6sw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <4150E428E66709419E7574FB45600D63@namprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76374db8-9c45-47fc-8e0b-08d5698f16cd X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2018 16:16:02.5509 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0401MB1175 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 Thu, 2018-02-01 at 09:53 +0800, Joseph Qi wrote: > I'm afraid the risk may also exist in blk_cleanup_queue, which will > set queue_lock to to the default internal lock. > > spin_lock_irq(lock); > if (q->queue_lock != &q->__queue_lock) > q->queue_lock = &q->__queue_lock; > spin_unlock_irq(lock); > > I'm thinking of getting blkg->q->queue_lock to local first, but this > will result in still using driver lock even the queue_lock has already > been set to the default internal lock. Hello Joseph, I think the race between the queue_lock assignment in blk_cleanup_queue() and the use of that pointer by cgroup attributes could be solved by removing the visibility of these attributes from blk_cleanup_queue() instead of __blk_release_queue(). However, last time I proposed to move code from __blk_release_queue() into blk_cleanup_queue() I received the feedback that from some kernel developers that they didn't like this. Is the block driver that triggered the race on the q->queue_lock assignment using legacy (single queue) or multiqueue (blk-mq) mode? If that driver is using legacy mode, are you aware that there are plans to remove legacy mode from the upstream kernel? And if your driver is using multiqueue mode, how about the following change instead of the two patches in this patch series: Thanks, Bart. --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1093,7 +1093,7 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id) return NULL; q->request_fn = rfn; - if (lock) + if (!q->mq_ops && lock) q->queue_lock = lock; if (blk_init_allocated_queue(q) < 0) { blk_cleanup_queue(q);