From patchwork Tue Aug 21 23:18:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10572477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94129109C for ; Tue, 21 Aug 2018 23:19:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 943952AD5B for ; Tue, 21 Aug 2018 23:19:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 872742AE3E; Tue, 21 Aug 2018 23:19:02 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 532022AD5B for ; Tue, 21 Aug 2018 23:19:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D55D6B213D; Tue, 21 Aug 2018 19:19:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 384026B213E; Tue, 21 Aug 2018 19:19:00 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29BF26B213F; Tue, 21 Aug 2018 19:19:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id DF6E66B213D for ; Tue, 21 Aug 2018 19:18:59 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id s1-v6so42110pfm.22 for ; Tue, 21 Aug 2018 16:18:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=iXRu6mqKrKlPHH0Xoja1r/KUw3eBTunSLRtdhX6rtss=; b=rH9RUpOIUxnK9McJ9hYNeVnaxYRIXOF3KAUUb6jx9ADTLpSGT8nmnbz80wI+r2Rlep Tawc8Ja9LbBw5fpYNaHH9EDBZ0cevGKp3h7ymZQQmlRHpWDqm4l79b+cL2gVwzirRr14 O71gpVebqbNHjxr35ncUhOMi5wXdtdjE/4WowXUkVbP/zFGoMyZw6EarUBdz7SpdiOPL aFaYjrnoqciVLCebR3DRyTa1JdI9s1PVNQIhUvDcg7c7k5Zu+yQzbnzwYk2YZGYDXa23 39uaIXmaIZp910bEUVK1Jt5bC5k7ESlbaKZtPmwYC7OkIQeCJBw8oQyZM4K1Fn66tk1w CCeA== X-Gm-Message-State: AOUpUlFMourB8XOebtCvBF1d9MhAADuiIVqvl5SmpgxBG0kjA5bHPAPD dYwrMM06nq8yQbTMXTaOIhFtKe/AddyVY8rsIvfHT/1keNAp5WvitKgD82667qXtMO0Pc2ZEAsI dBO7yD6GZA+EQPIefkmZ3rImpjWu6eIJNKh8c4Citv93Qoh97vEVp3EENtL91HUoJZVk0M4Jt92 Oid9/Rbxm9QS1U/smAQ93eCHQVrk84NpzBPTVO9P7gWsYtcNWcZ6/fHCvIPw8NQ4DNP4cTmo0n4 Uhogpq6efYUa2HTxTPAgKri96M3DA93r3WmeDC7cHknIHEePW/mTdWQXI3LoGPO43sD8+MXtAtt 5ZC2BsRWvHgyjKdbo7qoUn+Tv2YJ9RR7ZVRTNiE+sOwOOBx1tz2TzBpYPHRN95kixvExpBPgNZa 5 X-Received: by 2002:a62:1219:: with SMTP id a25-v6mr55194903pfj.104.1534893539500; Tue, 21 Aug 2018 16:18:59 -0700 (PDT) X-Received: by 2002:a62:1219:: with SMTP id a25-v6mr55194856pfj.104.1534893538594; Tue, 21 Aug 2018 16:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534893538; cv=none; d=google.com; s=arc-20160816; b=s9ohlUi5NUPlJ4EGXWFI1zwrfqgk/LC3Ql+JWdKIWyZCC6jDK6u7evl4R24pPQbSMf 0fcQODYY26pWZH8Icn1ZkjMc5Ur0CACC60vD0+iy8vnyavxLU7ObryjhSXVnXcASm2sV 0HYEcZofh9rglHUJhtS/DEFLYZjym/kOY4p8iO8hdLbV/pSJHJrDGsu4qW87oOP9QRKi 5ZXhC0QrOGJDmiXJ6nDDzGMLP5rxtpGgNEfBQJ0VmimjvH4u/PPnparIV6/4kIbmMP1i Wk7eJUA+XPEQC/XCABxFyz4K5Th1534Y8MnA/bUqOjLpUs2ghDSHiadKbXGDfNuMyuUE rfzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=iXRu6mqKrKlPHH0Xoja1r/KUw3eBTunSLRtdhX6rtss=; b=lPsITp6qefkaDT8uDSWwlRlhMt/YmWFmX0Q44Mk8GUX6osqGd8k+JgClx9xLVIYZFz 7VI3GeCNu5JR2bc9S/QctONxhLgSIiSCi2SsiHHWgRS5U8kwlNylKKaxuA3wpWhMpaMA RK63BWzRUQ+3AUa9v3BnwXtmCVU+7dfIl8WF/Lqnrp8ozLctm459iO9DA6LW9JVEAGqv Lr/uBzApmwb+pTIv1gdyJpa8OIozfmOipF2r+TMoqif25EzlvC/tokL8lBtSqYhIfMbt 4HJpkLSM817KV44qbbfJUgJB5vQeO0Hue/Gr/vK7lg4jbe/QKiy21Yoxw8t/co0d/ycG HsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="ajds/Zpo"; spf=pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=joel@joelfernandes.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s16-v6sor25894pfh.88.2018.08.21.16.18.58 for (Google Transport Security); Tue, 21 Aug 2018 16:18:58 -0700 (PDT) Received-SPF: pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="ajds/Zpo"; spf=pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=joel@joelfernandes.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iXRu6mqKrKlPHH0Xoja1r/KUw3eBTunSLRtdhX6rtss=; b=ajds/Zpo6SuBC5FbDABU8lPssoPNl0E+84zV+65h/gmRN7iQ+4aFqF/hq3OkdkkrS4 tq8/xRtfjYdjUeegmhLVMzeJngJlrwvCcmXxCHcHjXWuBEIsAwT6ZnT3MMi4zH4Mlh32 Sjai166qYArpVa91kcw2O5s52Jq7EZXv3ZW7Y= X-Google-Smtp-Source: ANB0VdZnxasPeMX1LXzLzlnkDHkJqir3RZRfYps8S2hSoSHCXlQc6Nrn6LHnGho/RVDbHinakF8YMw== X-Received: by 2002:a62:3a08:: with SMTP id h8-v6mr100419pfa.61.1534893538175; Tue, 21 Aug 2018 16:18:58 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a16-v6sm37356pgv.29.2018.08.21.16.18.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 16:18:57 -0700 (PDT) From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, "Joel Fernandes (Google)" , willy@infradead.org, stable@vger.kernel.org, peterz@infradead.org, Andrew Morton , linux-mm@kvack.org, NeilBrown Subject: [PATCH v2] mm: shmem: Correctly annotate new inodes for lockdep Date: Tue, 21 Aug 2018 16:18:35 -0700 Message-Id: <20180821231835.166639-1-joel@joelfernandes.org> X-Mailer: git-send-email 2.18.0.1017.ga543ac7ca45-goog MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: "Joel Fernandes (Google)" Directories and inodes don't necessarily need to be in the same lockdep class. For ex, hugetlbfs splits them out too to prevent false positives in lockdep. Annotate correctly after new inode creation. If its a directory inode, it will be put into a different class. This should fix a lockdep splat reported by syzbot: > ====================================================== > WARNING: possible circular locking dependency detected > 4.18.0-rc8-next-20180810+ #36 Not tainted > ------------------------------------------------------ > syz-executor900/4483 is trying to acquire lock: > 00000000d2bfc8fe (&sb->s_type->i_mutex_key#9){++++}, at: inode_lock > include/linux/fs.h:765 [inline] > 00000000d2bfc8fe (&sb->s_type->i_mutex_key#9){++++}, at: > shmem_fallocate+0x18b/0x12e0 mm/shmem.c:2602 > > but task is already holding lock: > 0000000025208078 (ashmem_mutex){+.+.}, at: ashmem_shrink_scan+0xb4/0x630 > drivers/staging/android/ashmem.c:448 > > which lock already depends on the new lock. > > -> #2 (ashmem_mutex){+.+.}: > __mutex_lock_common kernel/locking/mutex.c:925 [inline] > __mutex_lock+0x171/0x1700 kernel/locking/mutex.c:1073 > mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:1088 > ashmem_mmap+0x55/0x520 drivers/staging/android/ashmem.c:361 > call_mmap include/linux/fs.h:1844 [inline] > mmap_region+0xf27/0x1c50 mm/mmap.c:1762 > do_mmap+0xa10/0x1220 mm/mmap.c:1535 > do_mmap_pgoff include/linux/mm.h:2298 [inline] > vm_mmap_pgoff+0x213/0x2c0 mm/util.c:357 > ksys_mmap_pgoff+0x4da/0x660 mm/mmap.c:1585 > __do_sys_mmap arch/x86/kernel/sys_x86_64.c:100 [inline] > __se_sys_mmap arch/x86/kernel/sys_x86_64.c:91 [inline] > __x64_sys_mmap+0xe9/0x1b0 arch/x86/kernel/sys_x86_64.c:91 > do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > -> #1 (&mm->mmap_sem){++++}: > __might_fault+0x155/0x1e0 mm/memory.c:4568 > _copy_to_user+0x30/0x110 lib/usercopy.c:25 > copy_to_user include/linux/uaccess.h:155 [inline] > filldir+0x1ea/0x3a0 fs/readdir.c:196 > dir_emit_dot include/linux/fs.h:3464 [inline] > dir_emit_dots include/linux/fs.h:3475 [inline] > dcache_readdir+0x13a/0x620 fs/libfs.c:193 > iterate_dir+0x48b/0x5d0 fs/readdir.c:51 > __do_sys_getdents fs/readdir.c:231 [inline] > __se_sys_getdents fs/readdir.c:212 [inline] > __x64_sys_getdents+0x29f/0x510 fs/readdir.c:212 > do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > -> #0 (&sb->s_type->i_mutex_key#9){++++}: > lock_acquire+0x1e4/0x540 kernel/locking/lockdep.c:3924 > down_write+0x8f/0x130 kernel/locking/rwsem.c:70 > inode_lock include/linux/fs.h:765 [inline] > shmem_fallocate+0x18b/0x12e0 mm/shmem.c:2602 > ashmem_shrink_scan+0x236/0x630 drivers/staging/android/ashmem.c:455 > ashmem_ioctl+0x3ae/0x13a0 drivers/staging/android/ashmem.c:797 > vfs_ioctl fs/ioctl.c:46 [inline] > file_ioctl fs/ioctl.c:501 [inline] > do_vfs_ioctl+0x1de/0x1720 fs/ioctl.c:685 > ksys_ioctl+0xa9/0xd0 fs/ioctl.c:702 > __do_sys_ioctl fs/ioctl.c:709 [inline] > __se_sys_ioctl fs/ioctl.c:707 [inline] > __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:707 > do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > other info that might help us debug this: > > Chain exists of: > &sb->s_type->i_mutex_key#9 --> &mm->mmap_sem --> ashmem_mutex > > Possible unsafe locking scenario: > > CPU0 CPU1 > ---- ---- > lock(ashmem_mutex); > lock(&mm->mmap_sem); > lock(ashmem_mutex); > lock(&sb->s_type->i_mutex_key#9); > > *** DEADLOCK *** > > 1 lock held by syz-executor900/4483: > #0: 0000000025208078 (ashmem_mutex){+.+.}, at: > ashmem_shrink_scan+0xb4/0x630 drivers/staging/android/ashmem.c:448 Reported-by: syzbot Cc: willy@infradead.org Cc: stable@vger.kernel.org Cc: peterz@infradead.org Cc: Andrew Morton Reviewed-by: NeilBrown Suggested-by: NeilBrown Signed-off-by: Joel Fernandes (Google) --- v1->v2: Added Reviewed-by of NeilBrown and CC Andrew. mm/shmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 41b9bbf24e16..8264bbdbb6a5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2226,6 +2226,8 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode mpol_shared_policy_init(&info->policy, NULL); break; } + + lockdep_annotate_inode_mutex_key(inode); } else shmem_free_inode(sb); return inode;