Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1427671iog; Tue, 14 Jun 2022 06:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6msukbxTKc1GTK75D/vTFw1J2ouVsJAyH7Sw8NLiNrvbPe525/ac9/NDyq0mCDNdmxhxj X-Received: by 2002:a63:4a4e:0:b0:401:baa6:d695 with SMTP id j14-20020a634a4e000000b00401baa6d695mr4519684pgl.259.1655211617014; Tue, 14 Jun 2022 06:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655211617; cv=none; d=google.com; s=arc-20160816; b=Ob/Yf3pzu7XLWaKKxUV8qpiATr/Tiq2HI5FEcLNlZrYnve995cGjl45d6uXGd0+5W5 4b+zCmbq2oEVqTWOzCOrOAhgeBKl3WSzOYfJkIqv74RN4eG1pK0K1G189M3IrGE4/rko m1fqmHnUZL8zoHzts4YjM4cd4Iqlv4YGF2WayBOBQZm9srg90cSoDBHhJTlAYJ6Fqfmy gqEUvNvbr4GZK3hSZyGPVVfdq3iUD3taVjgZ5mdn2JIDwnQ8mChl0N202NxM4oRCb7Pw 5TYiUg79lfmG8pDSRleoHVlSIUnSVtgpTwNtKa2VXZQ1dGTayXuDlBI3nnO6YUlXAsIY +oqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=w85Mq0T1NDMH0MoEjmpfGBl0pSnG5ukSolBjwzDQZd4=; b=NUYmaayDGC72Ah8+gOxshW5U62jbBG/qwDpNYUZZxpPB3anqAWjew9E6nVVBGHWLZA jEY8pcYn2l32YO57y/oB8sFtRtlSF5TJLNt6/hky9m3yGgqg0Ey+vtRcGUbB8eCN8k9b wIsaxq/i505ip/aKiJXgHtewHFiWCNpSwx1QUsBQH2Mvw2nJJMVTpx42vsMk548K5uN8 Vl+du69s1PaYETrUJ3ZlsXTYkn9/z95+KgOYBbedKiQ+/t+RMcm9TNzv7o54kNG1LoAm 4oKw1i2Gs5DvVsYYYO5mMmfBw7TkriQJCSJ79PmgC5VhxWWSZeXS9K8GAw5hxLGeRqxN pxcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a056a000a9600b0050dd2797010si5700189pfl.321.2022.06.14.06.00.02; Tue, 14 Jun 2022 06:00:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243868AbiFNMqg (ORCPT + 99 others); Tue, 14 Jun 2022 08:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243000AbiFNMqd (ORCPT ); Tue, 14 Jun 2022 08:46:33 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9E2511461; Tue, 14 Jun 2022 05:46:32 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A47261650; Tue, 14 Jun 2022 05:46:32 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 70F723F73B; Tue, 14 Jun 2022 05:46:31 -0700 (PDT) From: Suzuki K Poulose To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Suzuki K Poulose , stable@vger.kernel.org, Jchao Sun , Jan Kara Subject: [PATCH] writeback: Avoid grabbing the wb if the we don't add it to dirty list Date: Tue, 14 Jun 2022 13:46:18 +0100 Message-Id: <20220614124618.2830569-1-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 10e14073107d moved grabbing the wb for an inode early enough, skipping the checks whether if this inode needs to be really added to the dirty list (backed by blockdev or unhashed inode). This causes a crash with kdevtmpfs as below, on an arm64 Juno board, as below: [ 1.446493] printk: console [ttyAMA0] printing thread started [ 1.447195] printk: bootconsole [pl11] printing thread stopped [ 1.467193] Unable to handle kernel paging request at virtual address ffff800871242000 [ 1.467793] Mem abort info: [ 1.468093] ESR = 0x0000000096000005 [ 1.468413] EC = 0x25: DABT (current EL), IL = 32 bits [ 1.468741] SET = 0, FnV = 0 [ 1.469093] EA = 0, S1PTW = 0 [ 1.469396] FSC = 0x05: level 1 translation fault [ 1.470493] Data abort info: [ 1.470793] ISV = 0, ISS = 0x00000005 [ 1.471093] CM = 0, WnR = 0 [ 1.471444] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000081c10000 [ 1.471798] [ffff800871242000] pgd=10000008fffff003, p4d=10000008fffff003, pud=0000000000000000 [ 1.472836] Internal error: Oops: 96000005 [#1] PREEMPT SMP [ 1.472918] Modules linked in: [ 1.473085] CPU: 1 PID: 35 Comm: kdevtmpfs Tainted: G T 5.19.0-rc1+ #49 [ 1.473246] Hardware name: Foundation-v8A (DT) [ 1.473345] pstate: 40400009 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 1.473493] pc : locked_inode_to_wb_and_lock_list+0xbc/0x2a4 [ 1.473656] lr : locked_inode_to_wb_and_lock_list+0x8c/0x2a4 [ 1.473820] sp : ffff80000b77bc10 [ 1.473901] x29: ffff80000b77bc10 x28: 0000000000000001 x27: 0000000000000004 [ 1.474193] x26: 0000000000000000 x25: ffff000800888600 x24: ffff0008008885e8 [ 1.474393] x23: ffff80000848ddd4 x22: ffff80000a754f30 x21: ffff80000a7eaaf0 [ 1.474693] x20: ffff000800888150 x19: ffff80000b6a4150 x18: ffff80000ac3ac00 [ 1.474917] x17: 0000000070526bee x16: 000000003ac581ee x15: ffff80000ac42660 [ 1.475195] x14: 0000000000000000 x13: 0000000000007a60 x12: 0000000000000002 [ 1.475428] x11: ffff80000a7eaaf0 x10: 0000000000000004 x9 : 000000008845fe88 [ 1.475622] x8 : ffff000800868000 x7 : ffff80000ab98000 x6 : 00000000114514e2 [ 1.475893] x5 : 0000000000000000 x4 : 0000000000020019 x3 : 0000000000000001 [ 1.476113] x2 : ffff800871242000 x1 : ffff800871242000 x0 : ffff000800868000 [ 1.476393] Call trace: [ 1.476493] locked_inode_to_wb_and_lock_list+0xbc/0x2a4 [ 1.476605] __mark_inode_dirty+0x3d8/0x6e0 [ 1.476793] simple_setattr+0x5c/0x84 [ 1.476933] notify_change+0x3ec/0x470 [ 1.477096] handle_create+0x1b8/0x224 [ 1.477193] devtmpfsd+0x98/0xf8 [ 1.477342] kthread+0x124/0x130 [ 1.477512] ret_from_fork+0x10/0x20 [ 1.477670] Code: b9000802 d2800023 d53cd042 8b020021 (f823003f) [ 1.477793] ---[ end trace 0000000000000000 ]--- [ 1.478093] note: kdevtmpfs[35] exited with preempt_count 2 The problem was bisected to the above commit and moving the bail check early solves the problem for me. Fixes: 10e14073107d ("writeback: Fix inode->i_io_list not be protected by inode->i_lock error") CC: stable@vger.kernel.org Cc: Jchao Sun Cc: Jan Kara Signed-off-by: Suzuki K Poulose --- fs/fs-writeback.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 05221366a16d..cf68114af68b 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -2416,6 +2416,14 @@ void __mark_inode_dirty(struct inode *inode, int flags) inode->i_state &= ~I_DIRTY_TIME; inode->i_state |= flags; + /* + * Only add valid (hashed) inodes to the superblock's + * dirty list. Add blockdev inodes as well. + */ + if (!S_ISBLK(inode->i_mode)) { + if (inode_unhashed(inode)) + goto out_unlock_inode; + } /* * Grab inode's wb early because it requires dropping i_lock and we * need to make sure following checks happen atomically with dirty @@ -2436,14 +2444,6 @@ void __mark_inode_dirty(struct inode *inode, int flags) if (inode->i_state & I_SYNC_QUEUED) goto out_unlock; - /* - * Only add valid (hashed) inodes to the superblock's - * dirty list. Add blockdev inodes as well. - */ - if (!S_ISBLK(inode->i_mode)) { - if (inode_unhashed(inode)) - goto out_unlock; - } if (inode->i_state & I_FREEING) goto out_unlock; -- 2.35.3