From patchwork Wed Feb 28 19:28:22 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: 10249453 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 1500D60594 for ; Wed, 28 Feb 2018 19:28:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C3828D97 for ; Wed, 28 Feb 2018 19:28:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E95EA28E63; Wed, 28 Feb 2018 19:28:31 +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 87EAF28D9F for ; Wed, 28 Feb 2018 19:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933430AbeB1T2a (ORCPT ); Wed, 28 Feb 2018 14:28:30 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:44088 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933497AbeB1T20 (ORCPT ); Wed, 28 Feb 2018 14:28:26 -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=1519846563; x=1551382563; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=xhOGmbQvFMtp7hl+6u9a0zFT6boWO37kRgZrNZsixiE=; b=DkgNq2rB1aNI7kIcqcADVky1Rv0ev3lfCE+k4/LDVOTjNdx9agDQhRk8 KKquqAdIfO9Jedt417+kRmPBfiJYrByBQ/ztYJ9+jwUUFZPM1/E8Kcbyf W4jSAc5BdjgimC7e3ZtIE/xVJ5w5mVKHZ8S2lZ8PCOteW4dLBbZNMQXF4 lLLkR5GUEsPSIB7uMVmKdqYp3qI54h8+0/kpgoVCEsBVqfSc3nJzG0k2U wUZQ5qxDUfUdQHGvA6hz09KNUmMyGVGFgvYhMQZnupGuP46ft5kZHvvuz UfWOXg8LsH5WB0J7izTmJ8A28NLxuYyZhaPt3vl63TXJ7GRDPXNfEueYl A==; X-IronPort-AV: E=Sophos;i="5.47,406,1515427200"; d="scan'208";a="169051669" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Mar 2018 03:36:03 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 28 Feb 2018 11:22:31 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip01.wdc.com with ESMTP; 28 Feb 2018 11:28:26 -0800 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Mike Snitzer , Hannes Reinecke , Johannes Thumshirn , Ming Lei Subject: [PATCH 10/11] block: Complain if queue_flag_(set|clear)_unlocked() is abused Date: Wed, 28 Feb 2018 11:28:22 -0800 Message-Id: <20180228192823.5191-11-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228192823.5191-1-bart.vanassche@wdc.com> References: <20180228192823.5191-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 it is not safe to use queue_flag_(set|clear)_unlocked() without holding the queue lock after the sysfs entries for a queue have been created, complain if this happens. Signed-off-by: Bart Van Assche Cc: Mike Snitzer Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Ming Lei Reviewed-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- include/linux/blkdev.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index eca31d0ef2df..1f3ec9a7fbc7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -726,12 +726,18 @@ static inline void queue_lockdep_assert_held(struct request_queue *q) static inline void queue_flag_set_unlocked(unsigned int flag, struct request_queue *q) { + if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) && + kref_read(&q->kobj.kref)) + lockdep_assert_held(q->queue_lock); __set_bit(flag, &q->queue_flags); } static inline void queue_flag_clear_unlocked(unsigned int flag, struct request_queue *q) { + if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) && + kref_read(&q->kobj.kref)) + lockdep_assert_held(q->queue_lock); __clear_bit(flag, &q->queue_flags); }