From patchwork Mon Mar 23 05:25:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 6070541 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 717F3BF90F for ; Mon, 23 Mar 2015 05:27:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5392201FA for ; Mon, 23 Mar 2015 05:27:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B44D52017E for ; Mon, 23 Mar 2015 05:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752752AbbCWF0m (ORCPT ); Mon, 23 Mar 2015 01:26:42 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:34268 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752363AbbCWF0D (ORCPT ); Mon, 23 Mar 2015 01:26:03 -0400 Received: by qgep97 with SMTP id p97so5997763qge.1; Sun, 22 Mar 2015 22:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oAA0vczux2BkSbmkopgYUpuZlLP5H4dmLZElsAg2HMA=; b=jM6GJXK++xOfJP+gWYv6eCn2B7VZizi8QsKIa2qegmRuIOOR/qJghtwZCMOLh/pjEE MWmHwAdFfqtfBSI25JfFdy/gULk2x04tYoIkij9wzGlG2wV7LAEbc4L11ccAYRRmOgJp uHyQMBxqUJcDoPjOacgMoLTRbi4Wn52T778hn9ul9Iop6Jx6zVK3B0NeIjxt2qjrvGvX T51q9jJ+DbBcjvG1u/A9oIj83/7UhWrgQxBn0CyraYUwCwePYHB2B8Ird21Y1I+iUCmM 5jbGu0aoU7UcWIY2MNRRgtKn0D6WGe7IhHZCrBfIN6uF3uJf6M1hKG29bjs5765WeQ68 HQOg== X-Received: by 10.140.96.87 with SMTP id j81mr111703731qge.92.1427088362429; Sun, 22 Mar 2015 22:26:02 -0700 (PDT) Received: from htj.duckdns.org.lan (207-38-238-8.c3-0.wsd-ubr1.qens-wsd.ny.cable.rcn.com. [207.38.238.8]) by mx.google.com with ESMTPSA id h6sm8551624qgh.32.2015.03.22.22.26.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2015 22:26:01 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org, hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org, vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com, fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com, Tejun Heo Subject: [PATCH 7/8] writeback: add lockdep annotation to inode_to_wb() Date: Mon, 23 Mar 2015 01:25:43 -0400 Message-Id: <1427088344-17542-8-git-send-email-tj@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427088344-17542-1-git-send-email-tj@kernel.org> References: <1427088344-17542-1-git-send-email-tj@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the previous two patches, all operations which acquire wb from inode are either under one of inode->i_lock, mapping->tree_lock or wb->list_lock, or protected by stat transaction, which will be depended upon by foreign inode wb switching. This patch adds lockdep assertion to inode_to_wb() so that usages outside the above list locks can be caught easily. inode_wb_stat_unlocked_begin() is an exception as it's usually protected by combination of !I_WB_SWITCH and rcu_read_lock(). It's updated to dereference inode->i_wb directly. Signed-off-by: Tejun Heo Cc: Jens Axboe Cc: Jan Kara Cc: Wu Fengguang Cc: Greg Thelen --- include/linux/backing-dev.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 040be1a..b9937e5 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -326,10 +326,18 @@ wb_get_create_current(struct backing_dev_info *bdi, gfp_t gfp) * inode_to_wb - determine the wb of an inode * @inode: inode of interest * - * Returns the wb @inode is currently associated with. + * Returns the wb @inode is currently associated with. The caller must be + * holding either @inode->i_lock, @inode->i_mapping->tree_lock, or the + * associated wb's list_lock. */ static inline struct bdi_writeback *inode_to_wb(struct inode *inode) { +#ifdef CONFIG_LOCKDEP + WARN_ON_ONCE(debug_locks && + (!lockdep_is_held(&inode->i_lock) && + !lockdep_is_held(&inode->i_mapping->tree_lock) && + !lockdep_is_held(&inode->i_wb->list_lock))); +#endif return inode->i_wb; } @@ -360,7 +368,12 @@ inode_wb_stat_unlocked_begin(struct inode *inode, bool *lockedp) if (unlikely(*lockedp)) spin_lock_irq(&inode->i_mapping->tree_lock); - return inode_to_wb(inode); + + /* + * Protected by either !I_WB_SWITCH + rcu_read_lock() or tree_lock. + * inode_to_wb() will bark. Deref directly. + */ + return inode->i_wb; } /**