From patchwork Thu Mar 8 01:10:05 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: 10265757 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 64F8E60247 for ; Thu, 8 Mar 2018 01:10:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5823D295F2 for ; Thu, 8 Mar 2018 01:10:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D19E295F6; Thu, 8 Mar 2018 01:10:19 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 E6852295F2 for ; Thu, 8 Mar 2018 01:10:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755144AbeCHBKR (ORCPT ); Wed, 7 Mar 2018 20:10:17 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:51958 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755044AbeCHBKO (ORCPT ); Wed, 7 Mar 2018 20:10:14 -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=1520471414; x=1552007414; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=J4jTFOVMDMfu/Lk2SwkEHQYZBCH4Qmiir17LfYre9GM=; b=hlzEbt+otq66TxY5HnipatPTBloObpmn0W/oMmj33W+pwOAxBfw2NfRm b//wKrl7HQzdT6JmrW5SA/e3GGuAiEQWBcDR6cZw+YnmSFRexFWJny/Ww Tv2tZ/YCry/5+c37BPZvndgay1e5lzqC3K47P+9JuIV1CxMyiNjhW1iQ2 CUiMr1iSLx6RCr8Ju/+dIqmyRrWReApYqRt4dCE9CyUb0Ha3CSJRF8Eiy MQHzUyM3HnooXt+sV7CJjbnd56QsIwm3alrP+SODRn7yyu/rO1bI03v+1 mEbdsMI7mglAWEIVfGR4UvNVcS7ViaQzqE3diDuU8hvrGFOp3e3MUurrZ A==; X-IronPort-AV: E=Sophos;i="5.47,438,1515427200"; d="scan'208";a="72999159" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Mar 2018 09:10:13 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Mar 2018 17:04:04 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Mar 2018 17:10:14 -0800 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Ming Lei Subject: [PATCH v2 04/11] block: Protect queue flag changes with the queue lock Date: Wed, 7 Mar 2018 17:10:05 -0800 Message-Id: <20180308011012.31522-5-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180308011012.31522-1-bart.vanassche@wdc.com> References: <20180308011012.31522-1-bart.vanassche@wdc.com> 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 Since the queue flags may be changed concurrently from multiple contexts after a queue becomes visible in sysfs, make these changes safe by protecting these with the queue lock. Signed-off-by: Bart Van Assche Reviewed-by: Martin K. Petersen Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Ming Lei Reviewed-by: Johannes Thumshirn --- block/blk-mq.c | 2 +- block/blk-stat.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 0f48ef5bf280..63a4e13da727 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3025,7 +3025,7 @@ EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues); static bool blk_poll_stats_enable(struct request_queue *q) { if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags) || - test_and_set_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags)) + blk_queue_flag_test_and_set(QUEUE_FLAG_POLL_STATS, q)) return true; blk_stat_add_callback(q, q->poll_cb); return false; diff --git a/block/blk-stat.c b/block/blk-stat.c index b664aa6df725..bd365a95fcf8 100644 --- a/block/blk-stat.c +++ b/block/blk-stat.c @@ -152,7 +152,7 @@ void blk_stat_add_callback(struct request_queue *q, spin_lock(&q->stats->lock); list_add_tail_rcu(&cb->list, &q->stats->callbacks); - queue_flag_set(QUEUE_FLAG_STATS, q); + blk_queue_flag_set(QUEUE_FLAG_STATS, q); spin_unlock(&q->stats->lock); } EXPORT_SYMBOL_GPL(blk_stat_add_callback); @@ -163,7 +163,7 @@ void blk_stat_remove_callback(struct request_queue *q, spin_lock(&q->stats->lock); list_del_rcu(&cb->list); if (list_empty(&q->stats->callbacks) && !q->stats->enable_accounting) - queue_flag_clear(QUEUE_FLAG_STATS, q); + blk_queue_flag_clear(QUEUE_FLAG_STATS, q); spin_unlock(&q->stats->lock); del_timer_sync(&cb->timer); @@ -191,7 +191,7 @@ void blk_stat_enable_accounting(struct request_queue *q) { spin_lock(&q->stats->lock); q->stats->enable_accounting = true; - queue_flag_set(QUEUE_FLAG_STATS, q); + blk_queue_flag_set(QUEUE_FLAG_STATS, q); spin_unlock(&q->stats->lock); }