From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F06336D9E8 for ; Fri, 13 Mar 2026 07:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773387915; cv=none; b=P5I6o9XWRbHJ51Sp5zy/bK9mcphR4uwWWzYg3+eCcgYPdHY4bYDt6q/WgkuMQ1/obVmNXW6bT+zGFBg7M8z9McHLULvI5we0l0fR2tjYanKCzS71IFNqn7gpnGIht5A6Bl0MFTLxyXSd5pMRGQdkuQE+NrvLvK7PyS358/3bRDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773387915; c=relaxed/simple; bh=QLtG9/4GxAHmntod/5fYn/dD30apEMsSsw4oBgbFtM4=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=G8i9N1gE0GZRDoCtvHzZ9nes7mKuaTKhfftboOlqdqXha+p6vzmYxxdhgCeGhE0DG1OQTkCDfMpwA/1G6TCz6yBpajcDMXeyAZuKyLxaqxO/eaJeOwFrwSvhZRP+wIS86UJnZzLnA2jxKJmwTegVc6JeyFS9QeslUjDYXuTqEis= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MWrfL82M; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MWrfL82M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51E3DC19421; Fri, 13 Mar 2026 07:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773387915; bh=QLtG9/4GxAHmntod/5fYn/dD30apEMsSsw4oBgbFtM4=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=MWrfL82MonORdKopFBeiEFy0saT1Qt+wRKYm54YEn1F3Sr2gSi6VUNKLMhV7NNk/1 4xqk12pCZ14v5cuTjbufC1U0xuLNBMzmOXkhXr8LwIfJ5XB8yi3iVg2OYB51l8Zc9q iW32wFiFgNLRa0oi80uODdw4waK9l76SQ/rrAZnkUu35yN/sFKEa5YcmqfvhzJtF+j YIjIb7G2TNLEfD90v2SU5+RE7BU8HKIbFGqkLiJprcdATEstAXwXS9mItRyi1FNsXS uWC9kcBQ567MIApoqIST8H/sUade9JlLgqsR5bO8kwKrvy3qancY4KmpNQ+u3JqRj7 WS67Q+E/Bb8/w== Message-ID: <0b5bfbdd-fc2d-4dc2-91d3-9af1b5703a76@kernel.org> Date: Fri, 13 Mar 2026 15:45:11 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, syzbot+fc026e87558558f75c00@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org Subject: Re: [f2fs-dev] [PATCH v2] f2fs: evict: truncate page cache before clear_inode To: kth5965@gmail.com, jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20260224160654.448538-1-kth5965@gmail.com> <20260224165408.450957-1-kth5965@gmail.com> <9df7bc57-f0e1-4c7b-9ce1-0017eab62c2a@kernel.org> <20260309142509.75703-1-kth5965@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260309142509.75703-1-kth5965@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/9/2026 10:25 PM, kth5965@gmail.com wrote: > Hi Chao, > > Thanks for the comment. > > I took another look at the path, and I think you are right that my > current fix is too broad and may hide the real problem. > > It looks like this happens in a more specific case, where an inode > still has FI_INLINE_DATA set, but FI_DATA_EXIST is not set. > > In that case, f2fs_truncate() goes into the inline conversion path, > and f2fs_convert_inline_inode() grabs folio 0 before it checks > whether there is real inline data to move. > > Then f2fs_convert_inline_folio() does this: > > if (!f2fs_exist_data(dn->inode)) > goto clear_out; > > So for the empty-inline case, it returns success, but folio 0 seems to > have already been added to the page cache by then. > > From what I can see, f2fs_grab_cache_folio() may create folio 0 and add > it to inode->i_mapping when there is no folio at that index, so > inode->i_data.nrpages becomes 1 there. > > After that, f2fs_folio_put() only drops the ref, and the folio stays > there. Because of that, clear_inode() later sees nrpages != 0 and > hits the BUG. > > This is the flow I am seeing: > > f2fs_evict_inode() > -> truncate_inode_pages_final(&inode->i_data) > // nrpages = 0 > > -> i_size_write(inode, 0) > -> f2fs_truncate(inode) > -> !f2fs_may_inline_data(inode) > -> f2fs_convert_inline_inode(inode) > -> f2fs_grab_cache_folio(inode->i_mapping, 0, false) > // folio 0 is inserted into page cache > // nrpages = 1 > -> f2fs_convert_inline_folio(&dn, folio) > -> !f2fs_exist_data(inode) > -> clear_out > -> f2fs_folio_put(folio, true) > // only drops the ref > // folio stays in page cache > > -> clear_inode() > -> BUG_ON(inode->i_data.nrpages) Hi, Sorry for the late reply. Yes, we may missed to truncate page #0 cache once we converted inline inode. The reason why we convert the inline inode is the inode may already be corrupted (filesize is larger than MAX_INLINE_DATA(), and it has FI_INLINE_DATA flag). My question is: we should has ability to detect such corrupted inode in sanity_check_inode(), however, I didn't find any log related to that, any thoughts? Thanks, > > So it seems better to fix this in the inline conversion path, > instead of truncating all page cache again at the end of eviction. > > If you agree, I can send a new patch in that direction. > > Thanks,