From patchwork Tue Dec 18 09:52:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helmut Grohne X-Patchwork-Id: 1015206 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intenta.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RmhEAxuF"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43Jtck3s2vz9s3Z for ; Tue, 18 Dec 2018 20:53:10 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FausxZDfthdTJtT3ey8jndBshPfeuvXqAut89hpO2Kg=; b=RmhEAxuF1X8jhU 1VcVYcH/LlPeh3/DpcPfDH51X9KtGgiAEsnhrVNuoYjteiEYjJHot6Ky1y+KRvnztRYInfzPEAQ6y Jc+fIG3inoXtriK8nhExJg/lKTTewKLfKpdIsj0AMvbryULkjhlkZ3/UCCPyqG95xcuzbYhTkYYMx Xf2skpkxVxT5cq/i5jZOMLRUTmqocPoHQunze2lCzPyqBptn6xKQoL7U43hZhqQUZP2lF3w9KZZqd 6n1LrH+T8RtsTN+62kUQ3UG4NqWK9+VUYOQeqrAUfFyhPm0lA5GrQFnzkuBvJ6U4pdSuNgyPcZq1p OUnNI5VBJGe3USlS9aBQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZC3m-0002eg-7v; Tue, 18 Dec 2018 09:53:06 +0000 Received: from mail.intenta.de ([178.249.25.132]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZC3W-0002EC-Nu for linux-mtd@lists.infradead.org; Tue, 18 Dec 2018 09:53:03 +0000 Received: from [10.10.16.42] (port=19666 helo=ICSMA001.intenta.de) by mail.intenta.de with esmtps (TLSv1.2:AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1gZC3J-0005TL-0A; Tue, 18 Dec 2018 10:52:37 +0100 Received: from localhost (10.10.136.105) by ICSMA001.intenta.de (10.10.16.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 18 Dec 2018 10:52:36 +0100 X-CTCH-RefID: str=0001.0A0C0208.5C18C365.0016, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 Date: Tue, 18 Dec 2018 10:52:36 +0100 From: Helmut Grohne To: David Woodhouse , , Richard Weinberger Subject: [PATCH v3 3/3] jffs2: put directories f->sem on a separate lockdep class Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Originating-IP: [10.10.136.105] X-ClientProxiedBy: ICSMA001.intenta.de (10.10.16.42) To ICSMA001.intenta.de (10.10.16.42) X-EsetResult: clean, is OK X-EsetId: 37303A298ED8D26262706B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181218_015251_793689_9656B585 X-CRM114-Status: GOOD ( 11.83 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [178.249.25.132 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Zijlstra Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We get a lockdep warning if we read a directory (e.g. ls) and fault a page on a regular file: [ 181.206207] mmaptest/392 is trying to acquire lock: [ 181.211066] (&f->sem){+.+.}, at: [] jffs2_readpage+0x30/0x5c [ 181.217663] [ 181.217663] but task is already holding lock: [ 181.223477] (&mm->mmap_sem){++++}, at: [] do_page_fault+0xa8/0x454 [ 181.230596] [ 181.230596] which lock already depends on the new lock. [ 181.230596] [ 181.238755] [ 181.238755] the existing dependency chain (in reverse order) is: [ 181.246219] [ 181.246219] -> #1 (&mm->mmap_sem){++++}: [ 181.251614] __might_fault+0x90/0xc0 [ 181.255694] filldir+0xa4/0x1f4 [ 181.259334] jffs2_readdir+0xd8/0x1d4 [ 181.263499] iterate_dir+0x78/0x128 [ 181.267490] SyS_getdents+0x8c/0x12c [ 181.271576] ret_fast_syscall+0x0/0x28 [ 181.275818] [ 181.275818] -> #0 (&f->sem){+.+.}: [ 181.280690] lock_acquire+0xfc/0x2b0 [ 181.284763] __mutex_lock+0x8c/0xb0c [ 181.288842] mutex_lock_nested+0x2c/0x34 [ 181.293272] jffs2_readpage+0x30/0x5c [ 181.297438] filemap_fault+0x600/0x73c [ 181.301690] __do_fault+0x28/0xb8 [ 181.305510] handle_mm_fault+0x854/0xec0 [ 181.309937] do_page_fault+0x384/0x454 [ 181.314188] do_DataAbort+0x4c/0xc8 [ 181.318181] __dabt_usr+0x44/0x60 [ 181.321999] 0xb6dffb02 Like with inode->i_rwsem, we recognize that this can never result in a dead lock, because we cannot page fault directory inodes and we cannot call getdents on non-directories. Thus we need different lockdep classes depending on the mode. This mirrors what lockdep_annotate_inode_mutex_key does to inodes. Link: https://www.spinics.net/lists/linux-rt-users/msg07644.html Signed-off-by: Helmut Grohne Cc: Peter Zijlstra --- fs/jffs2/fs.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 89a10b398d00..d4d691488a19 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -26,6 +26,9 @@ #include #include "nodelist.h" +static struct lock_class_key jffs2_inode_info_sem_key, + jffs2_inode_info_sem_dir_key; + static int jffs2_flash_setup(struct jffs2_sb_info *c); int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) @@ -277,6 +280,13 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino) inode->i_mode = jemode_to_cpu(latest_node.mode); + /* Mirror lock class of inode->i_rwsem, see + * lockdep_annotate_inode_mutex_key. + */ + if (S_ISDIR(inode->i_mode)) + lockdep_set_class(&f->sem, &jffs2_inode_info_sem_dir_key); + else + lockdep_set_class(&f->sem, &jffs2_inode_info_sem_key); mutex_lock(&f->sem); i_uid_write(inode, je16_to_cpu(latest_node.uid)); @@ -439,6 +449,13 @@ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_r f = JFFS2_INODE_INFO(inode); jffs2_init_inode_info(f); + /* Mirror lock class of inode->i_rwsem, see + * lockdep_annotate_inode_mutex_key. + */ + if (S_ISDIR(inode->i_mode)) + lockdep_set_class(&f->sem, &jffs2_inode_info_sem_dir_key); + else + lockdep_set_class(&f->sem, &jffs2_inode_info_sem_key); mutex_lock(&f->sem); memset(ri, 0, sizeof(*ri));