From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795943129; b=mpzyGiA2CPsFW4KrmDwn6vGecEngBhxef1qO+KSOLglj3+OoUXDQnI3Vu2nxWA/ow+h4 EDKkCzu6RONORBpJ8iNj9jDPBRGSIlt+T8dN87Slv067qO2N/+eRnYtkRXtZAj4eMQ9wQ pcpI70MIzpPWTYUfFnJi26XBuuYT/8zE2tGQwx1Z2UQymBGASnRyBHNXIhVNA2K9LQBJx 7C6DmK3dv0AxnAfdYjb8+TiroSi9vqk45bJeLJ4ghO8qDHQiQdBDCvGFFSKZCFFFeeb65 M1k39M/HAW4eO3ZMevHk6UPvIIm0N8D8chH6sqjM+LSjzZVj3YYJLaefZ8agXJ9YwLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795943129; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=cDJQqqFuY4VRaas+JDisRGwJYeq8k/IZWnauzyP8Qz4=; b=F+dFafC2YhOcL1UBSu4yW6+i4xLCK8e++ny/bxwRaENYrRgyNTCrmXIx0Njyjv8zPMa3 OPv7xC6z3+tH8QOnN/EAg1E7QiKRA0ZsBzmPiPy8Ssfjt20/BBxIJOJUXr0pa2DJuo72J LzzZ7vqFWRTIHU1djaPVp1yc/eRWmT098k4ZdgHRqN97UdVSMbVFypL2z1pMFQqJ0h/IS TSEf+7ZgFhMSpAewYuVuyfkPwEZaWGEYfLb8vzry4/d39DHCDY9hgjsHKWJikE/K+Nz9o FrXwD4gKcwOkv246b2jo3cNLcrNomSb8mWl2uK5xakR8iroG+l8Qdiz7UXO/r0tT6mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YhiM4ud3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD419606A337; Sun, 29 Nov 2026 09:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YhiM4ud3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E7121F0092F; Sun, 29 Nov 2026 09:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795943129; bh=cDJQqqFuY4VRaas+JDisRGwJYeq8k/IZWnauzyP8Qz4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YhiM4ud3O/+/8MP/mZXzLW/fLGBiUYsU1aZKBbd7kcQqUEKMPfzBR4b80QcHsbhvR Jj2GGItqy+Wiwz1rdLl8dF/kTVMpx5/rI5zGJU/M/TNyUvNaXtUN14BlWKFZcBHORP P0r91N09hrIXM33ljUlhHkF9Ry8xmBKaTvOaF2Zh+KxhGKWnoCKS6g3rF5RYfCwsxV bJDY1YF4fl+mN2ho0+Ka/3JBjjUzRsCUoNoevw5olBj3tYgmPbunTALNhqC3T7Jchq gAg1JvyZsA4ejXMtcLOtZ8lvawmRgQ0Qr0jh9xexAHKfeGndwFWexYhapZ8B1DW0F/ 7QhDMQsTHfibg== From: "David Hildenbrand (Arm)" Date: Sun, 29 Nov 2026 10:05:10 +0100 Subject: [PATCH 2/2] mm/filemap: update the folio order range atomically X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-filemap_fixes-v1-2-1546675e3c97@kernel.org> References: <20261129-filemap_fixes-v1-0-1546675e3c97@kernel.org> In-Reply-To: <20261129-filemap_fixes-v1-0-1546675e3c97@kernel.org> To: "Matthew Wilcox (Oracle)" , Jan Kara , Andrew Morton , Ying Huang , Kefeng Wang , ZhangPeng , Hannes Reinecke , Christian Brauner , Luis Chamberlain , John Garry , Zhang Yi , Baokun Li , Ojaswin Mujoo , Theodore Ts'o Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, "David Hildenbrand (Arm)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3170; i=david@kernel.org; h=from:subject:message-id; bh=lwp4N6sX9bRrcWddZWr8pK3JDzWGmjqD9UV29NMG9TQ=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLK5X526rlR0JJZdWe9B6+5SuUVBxqePxJ688Gn929W73 kmebtPZ2lHKwiDGwSArpsgSFHzf4OXLdbXVbnzMMHNYmUCGMHBxCsBEmEUYGc4fPP2mpaHv/+ym KxO3XPmUezFvdeD27j1dXJMiOFS2PlzP8D9A6lxT7YX0uiDpO6VxufuFrn6ViztUH5EwK+lFgdn OjbwA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Chris Mason mapping_set_folio_order_range() updates mapping->flags with a plain load and store, assuming that nobody can modify the flags concurrently. However, set_blocksize() and ext4_change_inode_journal_flag() call it on active inodes, and none of their locks protects from concurrent mm_take_all_locks(): set_blocksize() mm_take_all_locks() =============== =================== load mapping->flags test_and_set_bit(AS_MM_ALL_LOCKS) down_write(i_mmap_rwsem) store mapping->flags mm_drop_all_locks() bit is clear, no up_write() Consequently, we can lose concurrent setting/clearing of AS_MM_ALL_LOCKS, resulting in i_mmap_rwsem staying write-locked forever or being released by another task. Let's fix it by updating the order bits atomically, and document what callers on an active inode still have to ensure. This has medium urgency, as an unsuspecting admin can trigger it, leaving i_mmap_rwsem locked forever. Fixes: 3c20917120ce ("block/bdev: enable large folio support for large logical block sizes") Fixes: 58fd191f99f3 ("ext4: make data=journal support large block size") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ david: adjust comment and description ] Signed-off-by: David Hildenbrand (Arm) --- include/linux/pagemap.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 73af18a373670..0363ce1b1e5ab 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -411,8 +411,8 @@ static inline size_t mapping_max_folio_size_supported(void) * something the core cannot know). * Do not tune it based on, eg, i_size. * - * Context: This should not be called while the inode is active as it - * is non-atomic. + * Context: Safe to be called while the inode is active. However, the page + * cache must be empty and must be kept empty while setting the order range. */ static inline void mapping_set_folio_order_range(struct address_space *mapping, unsigned int min, @@ -430,8 +430,8 @@ static inline void mapping_set_folio_order_range(struct address_space *mapping, if (max < min) max = min; - mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | - (min << AS_FOLIO_ORDER_MIN) | (max << AS_FOLIO_ORDER_MAX); + set_mask_bits(&mapping->flags, AS_FOLIO_ORDER_MASK, + (min << AS_FOLIO_ORDER_MIN) | (max << AS_FOLIO_ORDER_MAX)); } static inline void mapping_set_folio_min_order(struct address_space *mapping, @@ -448,8 +448,7 @@ static inline void mapping_set_folio_min_order(struct address_space *mapping, * indicate that the VFS can use large folios to cache the contents of * the file. * - * Context: This should not be called while the inode is active as it - * is non-atomic. + * Context: See mapping_set_folio_order_range(). */ static inline void mapping_set_large_folios(struct address_space *mapping) { -- 2.56.1