Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D731C433F5 for ; Thu, 5 May 2022 09:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236419AbiEEJEp (ORCPT ); Thu, 5 May 2022 05:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234570AbiEEJEn (ORCPT ); Thu, 5 May 2022 05:04:43 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB8F71FCF7 for ; Thu, 5 May 2022 02:01:03 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 9C9AB218F2; Thu, 5 May 2022 09:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651741262; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oDo27eh8JDaR4e2Fv+OryKwE09e8IYTXDEaW5hZ9iko=; b=nq9KzSgUTCCIl+L+Dc8IUr6+VQUlZVouJ7ieATrscMfP1wZijQHujRKwoJdJ9qXESZ+Zt5 NU4CRv34Btgay9XyJwSjniZjejZN2hw2sovjTD9OYhX2oFakAYjz28yz/k12M/oMr+0pIS whCmpx/PbTxwEa76bXEtSwxqRHhnaxA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651741262; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oDo27eh8JDaR4e2Fv+OryKwE09e8IYTXDEaW5hZ9iko=; b=6SAkjjBslsTemZBeUdpfyLULXTi2oCaMLTDQDUO8YSPx4QB/zxDiv9A5Lm8F4jv7s4sC+Y cgzCrrpDA5DHQqBQ== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8D6A12C141; Thu, 5 May 2022 09:01:02 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id BEB9AA0627; Thu, 5 May 2022 11:00:59 +0200 (CEST) Date: Thu, 5 May 2022 11:00:59 +0200 From: Jan Kara To: Jchao sun Cc: Jan Kara , linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Subject: Re: [PATCH v3] writeback: Fix inode->i_io_list not be protected by inode->i_lock error Message-ID: <20220505090059.bgbn7lv2jsvo3vu3@quack3.lan> References: <20220504143924.ix2m3azbxdmx67u6@quack3.lan> <20220504182514.25347-1-sunjunchao2870@gmail.com> <20220504193847.lx4eqcnqzqqffbtm@quack3.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu 05-05-22 12:45:56, Jchao sun wrote: > On Thu, May 5, 2022 at 3:38 AM Jan Kara wrote: > > > > On Wed 04-05-22 11:25:14, Jchao Sun wrote: > > > Commit b35250c0816c ("writeback: Protect inode->i_io_list with > > > inode->i_lock") made inode->i_io_list not only protected by > > > wb->list_lock but also inode->i_lock, but inode_io_list_move_locked() > > > was missed. Add lock there and also update comment describing things > > > protected by inode->i_lock. > > > > > > Fixes: b35250c0816c ("writeback: Protect inode->i_io_list with > inode->i_lock") > > > Signed-off-by: Jchao Sun > > > > Almost there :). A few comments below: > > > > > @@ -2402,6 +2404,9 @@ void __mark_inode_dirty(struct inode *inode, int > flags) > > > inode->i_state &= ~I_DIRTY_TIME; > > > inode->i_state |= flags; > > > > > > + wb = locked_inode_to_wb_and_lock_list(inode); > > > + spin_lock(&inode->i_lock); > > > + > > > > > > We don't want to lock wb->list_lock if the inode was already dirty (which > > > is a common path). So you want something like: > > > > > > if (was_dirty) > > > wb = locked_inode_to_wb_and_lock_list(inode); > > I'm a little confused about here. The logic of the current source tree is > like this: > if (!was_dirty) { > struct bdi_writeback *wb; > wb = > locked_inode_to_wb_and_lock_list(inode); > ... > dirty_list = &wb-> b_dirty_time; > assert_spin_locked(&wb->list_lock); > } > The logic is the opposite of the logic in the comments, and it seems like > that wb will > absolutely not be NULL. > Why is this? What is the difference between them? Sorry, that was a typo in my suggestion. It should have been if (!was_dirty) wb = locked_inode_to_wb_and_lock_list(inode); Honza -- Jan Kara SUSE Labs, CR