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=1795054533; b=eD9VeiuEWlecuk3JFZgL/1m1/EpxvKF31G05V/n+bphj8vZemDTQLxto8O3/M2o6mGXH HDcz4CEJA13RCGT511W6i89rM7bY28hSNTpQWzNdVIKfygtrN7QhSxzHmgVfsaVp5+8D3 oU35Nf9GrXrdF8iXrIs37BgFH3C9Hznp8bSWuldTO8NRus5r3JQtD8yIHG/XCpzLh+USi qN1arMfWpOUn51cleKXiidIAKehV+Y152hfizZFhDKkaqbkLFJRr7P9HblPUCdLS3DaDb JIlZa2wppgUYpUhb9hD9KbzBIGJv2Vb3R14Qrg7ggepJ3KMA8UBATxPp2TwDO0wKGdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795054533; 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=54JW1enml96DMHvJ4PIo4zsyBfSQm3YzH7fphjarYXc=; b=cQ6MZiRTzbY6ccEW0l0RSO3pMi6v9nmxSeAJ2Nyoy3ivIihdzQQhNqHTZ7xyL1jwSdUL RJ4oMKfrYBfU54xv4qaxeGZipuOE7nBaI/BRTTtVyorrwv4yhhNc+xbU21mkN74/iwbjP ZcaQtfdon1UaAZVhnczRZVBm6VhI2E5qFT5xBu768+24d72z5rHHgZ9VhmZ8XHcPKvfZ8 q9xRZ+kG1v5LnPwOUd0tUFVMy9RGI+3bkBnIbOO5g21Ow1YHt/E5z7AnaqjLH3ekXc77T rP5SRXTLY6hB2LuK4mI4NYM0vy3s6fmvr4oRST2q7H5HHb/etJnIG78j2g/5/p7FEsQ== 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=PEeggYLP; 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 4B966606A31C; Thu, 19 Nov 2026 02:15:33 +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=PEeggYLP Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7DBB1F000C5; Thu, 19 Nov 2026 02:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795054533; bh=54JW1enml96DMHvJ4PIo4zsyBfSQm3YzH7fphjarYXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PEeggYLPV0zJk/EnDTmCLhlOPYWszf7/M4VcVijHN8I/jT/vPONi6goG5EshRtKLr Ohcz/rXt5VvTVLbViLJgwNxSojmK0QUbpxFNsiaPEgqdV/AljpPX0AB0tXlkXNJNEp s8+/4vBRiR9xtKvl98ve7RHEOxzxyvWhhBu8i7wM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Rik van Riel , Pedro Falcato , Muhammad Usama Anjum , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 5.15 1308/2214] mm/filemap: dont lose a folio lock wakeup to a signal Date: Wed, 18 Nov 2026 15:49:44 +0100 Message-ID: <20261118150103.836649757@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 8ccb6ded6a47b59b4907ed4f8c293cf8122de889 ] An exclusive waiter in folio_wait_bit_common() can leave the wait loop because of a fatal signal, then be woken by folio_unlock() before finish_wait(). If the waker did not hand over the lock, the waiter returns -EINTR without trying to acquire it. folio_wake_bit() stops after waking the first exclusive waiter, so this loses the wakeup and can leave other waiters asleep indefinitely on an unlocked folio. After finish_wait(), let a waiter woken without a lock handoff try once more to acquire the lock. If successful, return success so the caller's eventual unlock wakes the next waiter. Otherwise, the current lock owner will do so. Fix generated by an LLM and sent by Josef Bacik in private. Fixes: 5ef64cc8987a ("mm: allow a controlled amount of unfairness in the page lock") Cc: stable@vger.kernel.org Signed-off-by: Josef Bacik [ david: clarify and simplify comment + description ] Reviewed-by: Rik van Riel Acked-by: Pedro Falcato Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-7-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) [ sashal: Replaced folio_flags(folio, 0) with &page->flags in wait_on_page_bit_common(). ] Signed-off-by: Sasha Levin --- mm/filemap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b0d046f0d3b27..c08f24c562607 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1407,10 +1407,22 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, * return value based on that state without races. * * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive - * waiter, but an exclusive one requires WQ_FLAG_DONE. + * waiter, but an exclusive one must also acquire the bit. */ - if (behavior == EXCLUSIVE) - return wait->flags & WQ_FLAG_DONE ? 0 : -EINTR; + if (behavior == EXCLUSIVE) { + if (wait->flags & WQ_FLAG_DONE) + return 0; + /* + * We might have just been woken up and the waker will not + * wake up anybody else. If we ignore that now, the remaining + * waiters may not get woken up: take the bit now if it is + * still free. + */ + if ((wait->flags & WQ_FLAG_WOKEN) && + !test_and_set_bit(bit_nr, &page->flags)) + return 0; + return -EINTR; + } return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR; } -- 2.53.0