From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 7E6D73BCD0A for ; Mon, 8 Jun 2026 14:02:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780927350; cv=none; b=b0UGpGIbPpurrV+APbmF822fJt48L7Syg9EW7HpXBnEY0zhIcWZOfyLxXbVLhGjTd9tFyFNZZnX2j1qQ0Ksm14+va46yuL+0hyn0zPMRcw39epyVtxEYIDzmeavp4vvm28ekl0jfAunnchi0o7gHpmyn0eBQGvXDgvR0biD5YLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780927350; c=relaxed/simple; bh=Mzr8U4Ct+hKouya0LV38T8reDTmv9ByRYhAvNYlfVqo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZvCsVNnf/hljC0kSHXmblMgohQi6h/qZ7Do+E+LaMEyK2xr9oBWBi7jj1es3/9W2GZFyyOuMNmMF5R3Vxbv9IXgf0yXR1jFXQl+JiHTnoumN/QPFHxAEDN6+tYnxIePzr0Y/zvYcUAssZJVclnu42JCKpTid8VZgidt/H+uXZMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ND9GCJrh; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ND9GCJrh" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8TKX08CRvSuVhFmNgIKWVRWM8aqxu1xw/8GwzDfzCGs=; b=ND9GCJrh6SNtQG54pIYuK4w2fI ETbp1GJ4e0SLbi7ZtSchnZMZAr4RL0B+lnYdV19bIXnBFZ8d/GBx4ffx2J5L9bfU3FZcaTWgwsgiD lKJpZFg3hxJlNsNX7623F7wCyGQAVgdRmvpPz0QFG2ak5hCB1cAMtrQ8KjempW40+bZdZvK28llh4 CkAzShCEhPOpmQaossI8/cZhi9RpzJH5nhglwBpphiQsdrxrrf7QGvKFecjHjOMcl9zJtyD9SXFnZ Rme/IiLM3gShCr3vNZcKvomSdQZuxgX/lapZyqM5NHQHzNr8ezN7NAynIxF0Iw/hCJxIvGggTUjve 2T39L6Mg==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWaYY-0000000DodS-0Baq; Mon, 08 Jun 2026 14:02:22 +0000 Date: Mon, 8 Jun 2026 15:02:21 +0100 From: Matthew Wilcox To: Dev Jain Cc: Jan Kara , "linux-mm@kvack.org" , David Hildenbrand , Ryan Roberts , LKML Subject: Re: [BUG?] invalidate_lock not held in read_cache_folio() Message-ID: References: <5ca6512c-bdc1-4620-9c99-c7525e059099@arm.com> <903740a1-d48d-458e-8fa3-c129c68b5390@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <903740a1-d48d-458e-8fa3-c129c68b5390@arm.com> On Mon, Jun 08, 2026 at 06:59:46PM +0530, Dev Jain wrote: > > > On 08/06/26 5:49 pm, Matthew Wilcox wrote: > > On Mon, Jun 08, 2026 at 04:54:51PM +0530, Dev Jain wrote: > >> Hi, > >> > >> My understanding is that there are two ways we are serializing against concurrent > >> addition of a folio into the pagecache (see 730633f0b7f9). > >> > >> The kerneldoc of read_cache_folio() says: > >> > >> "Context: May sleep. Expects mapping->invalidate_lock to be held." > >> > >> I put the following in __filemap_add_folio(): > >> > >> + BUG_ON(!inode_is_locked(mapping->host) && > >> + !rwsem_is_locked(&mapping->invalidate_lock)); > >> > >> > >> And got the following trace: > >> > >> > >> [ 0.115587] Call trace: > >> [ 0.115686] __filemap_add_folio+0x5dc/0x680 (P) > >> [ 0.115871] filemap_add_folio+0xec/0x2d0 > >> [ 0.116031] do_read_cache_folio+0x144/0x2d8 > >> [ 0.116194] read_cache_folio+0x1c/0x30 > >> [ 0.116344] read_part_sector+0x4c/0xf0 > >> [ 0.116499] read_lba+0xb0/0x1a0 > >> [ 0.116627] efi_partition+0xa8/0x740 > >> [ 0.116769] bdev_disk_changed+0x238/0x620 > >> [ 0.116939] blkdev_get_whole+0xac/0x100 > >> [ 0.117090] bdev_open+0x280/0x3c0 > > > > You can't truncate or holepunch a bdev > > Yep, I realized that later, thanks : ) > > Just that the kerneldoc says "Expects mapping->invalidate_lock to be held" > so was wondering whether this comment is appropriate. Difficult for me to > reason about that since this goes into fs/block code. Yes, you've found a documentation bug. + BUG_ON(!inode_is_locked(mapping->host) && + !rwsem_is_locked(&mapping->invalidate_lock) && + !S_ISBLK(mapping->host->i_mode)); might do what you're looking for?