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=1794585503; b=V9Bhyd9rMZuSuURyGjco1KXta4aZCP0q+hd0Pu6266gZ2zlqRABVbReZkqp1NJbGOiMX /XDXiSbpwU6OlXbGZ3ZEwXBvzzCQFxLmKXlArICPaMsIKf8fyEy5fCHzg3UIz/Pzo/wHL IvejVJQFdZtLO61q4N5u0JZ4ytLNte1CNoLg/3QRTJXMI9IASI5z/AagJeEb0dyR/HQzx QJdogOnu2x+SMjBs91LGdbTfsCLgdQBCQMLQ1U9NszkbQUtYczU6fDFkU+zvE42Vqlo9s SoDMoXXech89IkZDj5FXWbEjJCpQJuJOngKx9Jzk/NOxvbUvM7mry7OQWVBvXQlGuOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794585503; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Gh0uEYxEjQF22nXPLiEUhH6i7t1QWDuf8mRo1NRVUP8=; b=2w79gh3xiwjBC+gyKU/0Uc7Wywmvy9vgwDjEmw86JOzjZfXw/q/20SuW8ZkcMd2KRTmh VNr1JnaD5arl8/RHuTaMXZkemqrxSs8Qb1WIZMtxMJtwzW31nX6kaIGcGgRwlY6gMmc7i LxL0G2KRLTsbusJlmDjk5AqwYIjhLkvon2UY40PS/00+BqhrEMU/MHWb3uoyT6U2juuT6 N0y16VbReSAIDbf4MxqD63pa8nZTqFn9tU4pHpLYXELORcr9Ue/ORNYHGHE9eqOGTj5Dl OpPCWnr99lmpv141LQC/eh9BDQpyA+v/SzgfyS6ehObLT6oIw4g1elnB80+iGnR3k+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ENYTaid1; 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 B5884606AE0B; Fri, 13 Nov 2026 15:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ENYTaid1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 623BB1F000C4; Fri, 13 Nov 2026 15:58:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794585503; bh=Gh0uEYxEjQF22nXPLiEUhH6i7t1QWDuf8mRo1NRVUP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ENYTaid1zZdiZtbK6Q4TGPUJKDIIfVzaTpWRHRmwBoVL88/gbZx/g1FnUZ48cvYCm unK0nCDw+eMvpqGyNySMkq9md+w5SevQIhHBO1470TV8vXVCQ3KD79v2lVDtvjD1Y7 pyX9J4f65+mrx4l4UqPDtRVmmKGqASqnjsGo7lYQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Thadeu Lima de Souza Cascardo , Muhammad Usama Anjum , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 7.3 152/507] mm/filemap: finish fault cleanup before dropping the fault lock Date: Fri, 13 Nov 2026 10:47:36 -0500 Message-ID: <20261113153759.596717906@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153753.358973689@linuxfoundation.org> References: <20261113153753.358973689@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand (Arm) [ Upstream commit 97156a6c355c21f7122421915f05461bd11699a4 ] On a retried fault, a fatal signal interrupting the folio lock wait makes lock_folio_maybe_drop_mmap() drop the fault lock without pinning the file. However, filemap_fault() may still need to release mapping->invalidate_lock. A concurrent munmap() can release the last file reference and free the mapping before that unlock. Defer dropping the fault lock to filemap_fault()'s retry cleanup, after releasing invalidate_lock. If the fault lock was already dropped for I/O, release the existing file reference instead. Keep the fault lock held for FAULT_FLAG_RETRY_NOWAIT as before. Fixes: 730633f0b7f9 ("mm: Protect operations adding pages to page cache with invalidate_lock") Cc: stable@vger.kernel.org Reported-by: Chris Mason Reviewed-by: Thadeu Lima de Souza Cascardo Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-8-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Sasha Levin --- mm/filemap.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index c6a573caef70e..73a26cd5b6d52 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3290,11 +3290,11 @@ loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start, * @folio - the folio to lock. * @fpin - the pointer to the file we may pin (or is already pinned). * - * This works similar to lock_folio_or_retry in that it can drop the - * mmap_lock. It differs in that it actually returns the folio locked - * if it returns 1 and 0 if it couldn't lock the folio. If we did have - * to drop the mmap_lock then fpin will point to the pinned file and - * needs to be fput()'ed at a later point. + * Returns 1 with the folio locked, or 0 if locking failed. + * + * On both entry and return, a non-NULL *fpin means the fault lock has + * already been dropped and the caller must eventually fput() the file. + * Otherwise the fault lock is still held, including on failure. */ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio, struct file **fpin) @@ -3311,21 +3311,9 @@ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio, return 0; *fpin = maybe_unlock_mmap_for_io(vmf, *fpin); - if (vmf->flags & FAULT_FLAG_KILLABLE) { - if (__folio_lock_killable(folio)) { - /* - * We didn't have the right flags to drop the - * fault lock, but all fault_handlers only check - * for fatal signals if we return VM_FAULT_RETRY, - * so we need to drop the fault lock here and - * return 0 if we don't have a fpin. - */ - if (*fpin == NULL) - release_fault_lock(vmf); - return 0; - } - } else - __folio_lock(folio); + if (vmf->flags & FAULT_FLAG_KILLABLE) + return !__folio_lock_killable(folio); + __folio_lock(folio); return 1; } @@ -3554,7 +3542,7 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) * vma->vm_mm->mmap_lock must be held on entry. * * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock - * may be dropped before doing I/O or by lock_folio_maybe_drop_mmap(). + * may be dropped before doing I/O or when aborting an interrupted wait. * * If our return value does not have VM_FAULT_RETRY set, the mmap_lock * has not been released. @@ -3710,9 +3698,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) out_retry: /* - * We dropped the mmap_lock, we need to return to the fault handler to - * re-find the vma and come back and find our hopefully still populated - * page. + * With fpin set, the fault lock was already dropped. Otherwise it is + * still held. Release invalidate_lock before dropping either protection. */ if (!IS_ERR(folio)) folio_put(folio); @@ -3720,6 +3707,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) filemap_invalidate_unlock_shared(mapping); if (fpin) fput(fpin); + else if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) + release_fault_lock(vmf); return ret | VM_FAULT_RETRY; } EXPORT_SYMBOL(filemap_fault); -- 2.53.0