Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1060116pxb; Fri, 1 Apr 2022 03:36:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGnghCmx1bpOwV5aaASVno5YIC1CCpAM665yYOIl1To71phNrmzg2jFM9LkWwFfwctRIF+ X-Received: by 2002:a63:111b:0:b0:382:56b1:f16d with SMTP id g27-20020a63111b000000b0038256b1f16dmr14638959pgl.585.1648809370566; Fri, 01 Apr 2022 03:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648809370; cv=none; d=google.com; s=arc-20160816; b=MDziJZlorJZL6V3cB89O+0Ny10bQEaXSIxW3i5VskwebjFgS9cZlqBBUOOoSJ98hng N2bw8+3/RhXfUTErOJp6ZJtMhWJUqo0827JwCDNjwo+y8esyeRYIz0axoTH968Y7KCGX QoW8b5wCqVrWDkE9dkhBzQFZFYIm76kdWnT9xdEmBsN5pQH8yru/w1lO4ni8lwzjYkXx Md/b0zU4daZkUYIo49zO+dTrgoMQrwwbL/etTYnTNyzvHLLXCpCsKogQyggCmZHvRqsN Zl18NObF7r0F3WrLS2S549XUw2v0L8kVssi+2PK6KJM+4LSFwI+4dLiGlGjMsDP135x/ pxsw== 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:dkim-signature; bh=mAxMsYYtX2X2keHpqn1vdPcI7xsWZyUwopfDKNZIcWk=; b=Ov9+v7Zwt2L65CSTCVXCjOBIm06lfOcT4tlIS4vEOlOcMPFTMoVmZCQ8jhZAQ63+rT Mu+9Sp6NhFeIoZFuvMpNt6oWXg9RFq5fTS2JvFrwM6mtsPSlaHj12vyVID8wjf2pEJFJ tplmDd6RWQ2/0UzrYZt4iv9USvLThbmiYgxKNvUbqNzUq6UlJItfkrqI9fTEgb/b1BUa ZzopPi0Si9tS3rXXzKJEnR0cpcZaR5pb++jkHuLwvCec8C5af/UQbpFXXz500Ih0Owf5 KZqiO1gqTeNI/I9eE25hxb6TVXvu5uQLDSx0DW5lC0wrQplhTJGDc/5rSsIt/6dXOKPe 78Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J8JMzh4V; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a170902d88b00b00153b2d165a5si1739838plz.429.2022.04.01.03.35.57; Fri, 01 Apr 2022 03:36:10 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J8JMzh4V; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242695AbiCaW6Y (ORCPT + 99 others); Thu, 31 Mar 2022 18:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239309AbiCaW6X (ORCPT ); Thu, 31 Mar 2022 18:58:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7A22325D6; Thu, 31 Mar 2022 15:56:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5846361660; Thu, 31 Mar 2022 22:56:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B302C340ED; Thu, 31 Mar 2022 22:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648767394; bh=QThZI7tHhBglWLB+tvKaUGnhtbdylP2EGYTJaJlJio4=; h=From:To:Cc:Subject:Date:From; b=J8JMzh4VJmddMyni9deTyx+5xAOEZMrVJqRn5OpAGfNxCl25S4PU+kOGwaeP5th7I PFHpGI0Jd7D6poVg7TjGwDlJWbDz/QWr3iQMJiDqK2DFiVth8/hDEhDmh9G9cv5L6q NmDfec+Md9goHnugcNR6kJJHVpzSkwRrdQpIB/KRy/ckIRZx6fCAEao72HgwPJA8fT teOfdU0DxJAN6CFkVm2LAgd4aTEQt4hOI6p4K/zwkQ6FR21EHxnKbkhN8YZ1y42PXG eFHJaXQCZKesogajnbqgTVf3BFmXZM6ZjmIl9U4YFIZeGqZvZhwjiGgYOLxiu1rAKH XdO8bCnUj3d6Q== From: Jeff Layton To: viro@zeniv.linux.org.uk Cc: ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs: change test in inode_insert5 for adding to the sb list Date: Thu, 31 Mar 2022 18:56:32 -0400 Message-Id: <20220331225632.247244-1-jlayton@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 The inode_insert5 currently looks at I_CREATING to decide whether to insert the inode into the sb list. This test is a bit ambiguous though as I_CREATING state is not directly related to that list. This test is also problematic for some upcoming ceph changes to add fscrypt support. We need to be able to allocate an inode using new_inode and insert it into the hash later if we end up using it, and doing that now means that we double add it and corrupt the list. What we really want to know in this test is whether the inode is already in its superblock list, and then add it if it isn't. Have it test for list_empty instead and ensure that we always initialize the list by doing it in inode_init_once. It's only ever removed from the list with list_del_init, so that should be sufficient. Suggested-by: Al Viro Signed-off-by: Jeff Layton --- fs/inode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) This is the alternate approach that Al suggested to me on IRC. I think this is likely to be more robust in the long run, and we can avoid exporting another symbol. Al, if you're ok with this, would you mind taking this in via your tree? I'd like to see this in sit in linux-next for a bit so we can see if any benchmarks get dinged. diff --git a/fs/inode.c b/fs/inode.c index 63324df6fa27..e10cff5102d4 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -422,6 +422,7 @@ void inode_init_once(struct inode *inode) INIT_LIST_HEAD(&inode->i_io_list); INIT_LIST_HEAD(&inode->i_wb_list); INIT_LIST_HEAD(&inode->i_lru); + INIT_LIST_HEAD(&inode->i_sb_list); __address_space_init_once(&inode->i_data); i_size_ordered_init(inode); } @@ -1021,7 +1022,6 @@ struct inode *new_inode_pseudo(struct super_block *sb) spin_lock(&inode->i_lock); inode->i_state = 0; spin_unlock(&inode->i_lock); - INIT_LIST_HEAD(&inode->i_sb_list); } return inode; } @@ -1165,7 +1165,6 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, { struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); struct inode *old; - bool creating = inode->i_state & I_CREATING; again: spin_lock(&inode_hash_lock); @@ -1199,7 +1198,13 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, inode->i_state |= I_NEW; hlist_add_head_rcu(&inode->i_hash, head); spin_unlock(&inode->i_lock); - if (!creating) + + /* + * Add it to the list if it wasn't already in, + * e.g. new_inode. We hold I_NEW at this point, so + * we should be safe to test i_sb_list locklessly. + */ + if (list_empty(&inode->i_sb_list)) inode_sb_list_add(inode); unlock: spin_unlock(&inode_hash_lock); -- 2.35.1