From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9084816D9C2 for ; Thu, 18 Dec 2025 04:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766030614; cv=none; b=Zn3EVsbKPaSyDcw82R/zuRbl0yuACBBWpExlJbnxtPfkoKMcanDZkyatgAo43Qczo/q71RBHd07L5/HS9Tg7BlrkpbIADjY8bcjAF/7LXOL0bEBVfEWGsyUUQ31bLopHqV7UJz0mNBxa8GUy4wavfCHLqOK3fPH95Os9K5H4m/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766030614; c=relaxed/simple; bh=wipqmJTb3RPr4bYzc7MlLp/HKbCdY/GhUhkFh7D5GpM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f3FL5uXSZG8b+PZvKjauLoV68ds7JE/M18H1b6dAVti3cELIPuokp2mQE8wAfXdF539v/+9VWWhkTtLP4wSMC85a2UWs4sXvBdut1o7ivo7U3EK7lKqWWlayIiObx07Zrua+ix+1tqHA5kZmzZmbhzS0CPpNM09GDpwSgo38BB4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J/pCWsH6; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J/pCWsH6" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2a0b4320665so2830265ad.1 for ; Wed, 17 Dec 2025 20:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766030612; x=1766635412; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=aHI6rvtpgTrf2rQzMwqNIBav/7/ZYbn4AXdiKjSA/wA=; b=J/pCWsH6ZIeXwnyY/YhHAxwuz0uapGe68KJYNP9GFw+46jadqqOkN4C/0IqlddkpqN sqq60ApIy8TTkiPyDBVoeTR37fmrFajVv6AAWMzwKTYuudIKCZph+l2KvrJLhLolGrM9 8ObryUBGx1e3xJytQjBpp9UXG4NsDMqgz/Ng/RLPZDq8NyyugpqdrRsAhxpo0qFcK0Eu 4NKw6Qj9V4ynMr5f+YTXbuDghQtIX3YpCcuD89ticlqIrwACda7KlPNsdr0qbWCRKOGP F1IsCrcPo+oRT1WSDAiCTpW07ppOYhe6xqalY4p9NVgAYwQHQGtnUvh7ixe3nJPKpvDm zNfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766030612; x=1766635412; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aHI6rvtpgTrf2rQzMwqNIBav/7/ZYbn4AXdiKjSA/wA=; b=QPEx2QIEbdmFOnrrCybY91qzCZ5WC21t9R5HWY941/H0gk8G9GUCHP2JXLCbbnSjAB s59m9SU6pLNYlU/ZUo9G/+UBqrtHDNtQFYxZ9AeClZdRSRca7dQrXL11KKrPuanlrNcv QJoemjOA3wSPjdVT02duw43hfAEnKHkIsGaaYeWPI3TQ2MWufJl76Qgy7qSeYA+uoZUW /WzwAfX2hZWLdHTTeU4ry7AGr38gRtFR7Bip77hV74uGiS7FydxUHN735efID07JSrwH AXFkINTrhTYfEg1l89e/dk7hcJrQOzWKWVBMyxWkfQszT9uQyHCxim3+fq76pS9QMaiU 6bTw== X-Forwarded-Encrypted: i=1; AJvYcCXJwEDgretCSbXYJxbpINaikPXk6/i2nn3yNMrsdX+3lxropvLBmLaYkT70c0NXif2gTs7bK06kC5Via94=@vger.kernel.org X-Gm-Message-State: AOJu0Yyx48lQPDOautDXTM/75f9D5UjCcsBVy3OxsRRAUtdaFW4dw+B5 1Ct99QJQgNnK00o4TKVmUYh1p7q9/SaePDDj3FDJgwGz7j5inaNXFXKZ X-Gm-Gg: AY/fxX4EGiBQf2MZmz2s6EFHp/9063tkR3YQm4s7psJeSN0Fhpluhi0/E90Dh2QKVjO rZdIuG2aa4mRgqk7RaW886weshou8JnxuXDNXALo1SXbT/zLMd3oOuLxFZqm2vmSC1zhpig3xXX Fcs1NE7jGFuP2i1kDH5/CL3kbB77E5l0FnIxLe+jm3D2OJ9aGWWAsOWn+ZBuTQ8i/UvwoVSnbfB cwOCeInVzUukNObltlAlwWv8yJoxlriZtHa36d8nE2f4j46dY3QgAZsQH2bkNLvu6cIr+W5XVCi 4nER5d7fNS3JSse3pm7klfIS6R+a/SL3vRQRZCIh+f90nuOfH89j2klBHQMilD1SiAakqq0GNEW 3v6y26H2XKlmJy/3VLNBYnpU8w1VqjUTVPf0Er7RfKSee6s2idn7tCaVQKpSC5toVEZvCjvGy+e 9w+9E= X-Google-Smtp-Source: AGHT+IHa7r0mYrLhWHjYQHKjTjGzpva8/SmCDywQMnfbi/eRtfbpSa8NAyazhiN4pJFcNwjNZ5uZlg== X-Received: by 2002:a17:903:11c8:b0:2a1:388c:ca5b with SMTP id d9443c01a7336-2a1388cced6mr90213585ad.39.1766030611814; Wed, 17 Dec 2025 20:03:31 -0800 (PST) Received: from localhost ([2a12:a304:100::105b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2d087c690sm8680035ad.20.2025.12.17.20.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 20:03:31 -0800 (PST) Date: Thu, 18 Dec 2025 12:03:28 +0800 From: Jinchao Wang To: Matthew Wilcox Cc: Andrew Morton , Christian Brauner , Hannes Reinecke , Luis Chamberlain , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, syzbot+4d3cc33ef7a77041efa6@syzkaller.appspotmail.com, syzbot+fdba5cca73fee92c69d6@syzkaller.appspotmail.com Subject: Re: [PATCH] mm/readahead: read min folio constraints under invalidate lock Message-ID: References: <20251215141936.1045907-1-wangjinchao600@gmail.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: On Tue, Dec 16, 2025 at 03:53:17AM +0000, Matthew Wilcox wrote: > On Tue, Dec 16, 2025 at 11:12:21AM +0800, Jinchao Wang wrote: > > On Tue, Dec 16, 2025 at 02:42:06AM +0000, Matthew Wilcox wrote: > > > On Tue, Dec 16, 2025 at 09:37:51AM +0800, Jinchao Wang wrote: > > > > On Mon, Dec 15, 2025 at 02:22:23PM +0000, Matthew Wilcox wrote: > > > > > On Mon, Dec 15, 2025 at 10:19:00PM +0800, Jinchao Wang wrote: > > > > > > page_cache_ra_order() and page_cache_ra_unbounded() read mapping minimum folio > > > > > > constraints before taking the invalidate lock, allowing concurrent changes to > > > > > > violate page cache invariants. > > > > > > > > > > > > Move the lookups under filemap_invalidate_lock_shared() to ensure readahead > > > > > > allocations respect the mapping constraints. > > > > > > > > > > Why are the mapping folio size constraints being changed? They're > > > > > supposed to be set at inode instantiation and then never changed. > > > > > > > > They can change after instantiation for block devices. In the syzbot repro: > > > > blkdev_ioctl() -> blkdev_bszset() -> set_blocksize() -> > > > > mapping_set_folio_min_order() > > > > > > Oh, this is just syzbot doing stupid things. We should probably make > > > blkdev_bszset() fail if somebody else has an fd open. > > > > Thanks, that makes sense. > > Tightening blkdev_bszset() would avoid the race entirely. > > This change is meant as a defensive fix to prevent BUGs. > > Yes, but the point is that there's a lot of code which relies on > the AS_FOLIO bits not changing in the middle. Syzbot found one of them, > but there are others. I've been thinking about this more, and I wanted to share another perspective if that's okay. Rather than tracking down every place that might change AS_FOLIO bits (like blkdev_bszset() and potentially others), what if we make the page cache layer itself robust against such changes? The invalidate_lock was introduced for exactly this kind of protection (commit 730633f0b7f9: "mm: Protect operations adding pages to page cache with invalidate_lock"). This way, the page cache doesn't need to rely on assumptions about what upper layers might do. The readahead functions already hold filemap_invalidate_lock_shared(), so moving the constraint reads under the lock adds no overhead. It would protect against AS_FOLIO changes regardless of their source. I think this separates concerns nicely: upper layers can change constraints through the invalidate_lock protocol, and page cache operations are automatically safe. But I'd really value your thoughts on this approach - you have much more experience with these tradeoffs than I do. Thanks again for taking the time to discuss this.