From nobody Tue Sep 29 02:33:20 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 2E4FF378D8B for ; Thu, 13 Aug 2026 10:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615375; cv=none; b=EN+WKxpC1Y+mTEdGt3vYxVawYFnQWx5XTw2udbZSjHoNDQHCjuRbPbeCE/FBI1MGbJxNwO/OCCIn0OPnL6adRnIT+cKLltry0+1kf8gHvXvANniZHLKMxSwaVrQ7Dhk9Ov2Y4Z5cGteu9bmP9y/JSR2L+d5n++SD+21niWvzZ0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615375; c=relaxed/simple; bh=tanX7f1b9c0MmsWbxVq9RS0LlQm73iyrFiiu0xCz+SY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KjMnskaDOE+v0Dh4pKgLjadI6WWjyeyhQ1mnqf/cqfJw7E3f/6ubZlmRSJ0+vRLOzTSRrlrhDZs2bikO5lWmKBoFmqwXvMASRhcjjkmq35GKtHUKxki2pXMjLM+TQ9P+dOAWkda8UGm+JPCi1l0zD0sQsXcQ8zyvFNnjXUu+kXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=Uc6B1+54; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="Uc6B1+54" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=Y20Ns8/o42YLbUNZyUIkw/RjdW/LS6iDwOmz4RkCo2g=; b=Uc6B1+54cds4o9pQiQUqSOQnJj Iw35vhsYmab52ZbTRJti+wIUS3gZ1DdEtWR3SLfj0cuMAxcDV3yVPOhTwkruzbyXorE9qxHa+Scq7 62828SI3KU0CPQBuaVHqgjawHCqipuW9Brug0193uZ/1R7S7o74F/jkd8A6G8znA9Zv729ZJEKD2W 1Y1KZPppAE+W+g1ENvoI1jheO7/y1zD36+Y9zHZw0Yov5uhv8+SIiKQ3UE+9LPjzwt1qwhVa/M7kk pVCpXJX+enUYXgM2KdsFUdCrMFi4jIFEgRdx4NBvcG6Z4gENn2/bss4cjAaL2IdPu92P7sEy2jesK O+QmRN+A==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wuSGj-00520V-2U; Thu, 13 Aug 2026 10:02:38 +0000 From: Breno Leitao Date: Thu, 13 Aug 2026 03:02:20 -0700 Subject: [PATCH v2 1/3] mm, swap: ratelimit bad swap entry reports 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260813-swap-v2-1-4a625ccabdae@debian.org> References: <20260813-swap-v2-0-4a625ccabdae@debian.org> In-Reply-To: <20260813-swap-v2-0-4a625ccabdae@debian.org> To: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , Hugh Dickins , Baolin Wang , Peter Xu , Johannes Weiner , Yosry Ahmed , Chengming Zhou Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=1410; i=leitao@debian.org; h=from:subject:message-id; bh=tanX7f1b9c0MmsWbxVq9RS0LlQm73iyrFiiu0xCz+SY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqfZYwUNV/hsWYVXh0g9Yl/bbnTzarJh+bZt0Dv YjK4FGOAhKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCan2WMAAKCRA1o5Of/Hh3 bbjeD/9wylsh0OoUfAP4Sfl4AOZVYZSdOyuXtSPCArhrnvA7XBNQ029lqt81WKo/905j9kEqNbh gr/9oo7wEt/QZpUHcyvCZ3Lw5DWzTe8DkSBDFYZb6fvnruBSA4IRXfz+0Iow7x6TKSLt5GA/czz LFx8trtpgKTX3AJKQj7KhrOnVjWz/RtcAnbVqMlsgDnBHg/+RkD2gbf/H3VW+J/V07wpmq1v66z zxx8ASEddvix+EBFJUCYByNjTeZxd2ZEWIvGPEgr+82H9gyHtdcyTTyRw36CKpAq/i3fpZvLBBx I1l+7X0NeVeBmGwuH3QYDJjj0XerakXaAtqfdKUo2CbDr6+eXgaDWaSHEsm03QgRS68mwiaSBfR /pmxoDTd7IQHZS1CcTLQky9wdI4lVkAjH7N0LGktdO4q9k4RmiheRc3E61+D32PJuJnfkUbkTbb QhY2HVG3D2G7EI4GQs3EgY1Od765pz/lkET+FOhkoPinOXHB8vVqP0lwdkkw8WmSBPd57QXcRVx Ci0W8W4qC1LNZMnisEZLeNVgBppJSmBrt5FvGIlJZ6J2et67g3iR/hkv436TvLja/b5jLbUl+Pb 0J1w7Cv2jQdi8U2N563YY3hx5B0KHQHUun66XWrHnSyH12PV1mjPWnCCat8lkB5Kt8Lb2BkyPEz KX988srXNdlhE/Q== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao A corrupt page table hands the same bogus entry to get_swap_device() on every access to the mapping, and every rejection is logged. One machine logged 6185620 copies of the same line in a few hours. swap_dup_entry_direct() prints the same message from the fork path, once per call: the WARN_ON_ONCE() guarding it warns once, the pr_err() inside does not. Rate limit all three prints. Signed-off-by: Breno Leitao Acked-by: Kairui Song Reviewed-by: Barry Song Reviewed-by: Nhat Pham --- mm/swapfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 4d4e3e3059f6b..31c8a340606bb 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1899,11 +1899,11 @@ struct swap_info_struct *get_swap_device(swp_entry_= t entry) =20 return si; bad_nofile: - pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val); + pr_err_ratelimited("%s: %s%08lx\n", __func__, Bad_file, entry.val); out: return NULL; put_out: - pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val); + pr_err_ratelimited("%s: %s%08lx\n", __func__, Bad_offset, entry.val); percpu_ref_put(&si->users); return NULL; } @@ -3876,7 +3876,7 @@ int swap_dup_entry_direct(swp_entry_t entry) =20 si =3D swap_entry_to_info(entry); if (WARN_ON_ONCE(!si)) { - pr_err("%s%08lx\n", Bad_file, entry.val); + pr_err_ratelimited("%s%08lx\n", Bad_file, entry.val); return -EINVAL; } =20 --=20 2.53.0-Meta From nobody Tue Sep 29 02:33:20 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 F0E903FDC18 for ; Thu, 13 Aug 2026 10:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615376; cv=none; b=p9XwO6EUiifroRnX+gL4EhQS8JJsLL7YSa4KOs2xmxc89s/qO6tWovtwh0x1aFYyXaPYCciZ6JY4+qQQWNg+BwZwl6C5uV6LQ5ybvzFvxfJDT2ui+pY8W039uyzo7o2VEru1Ypf0O4v5JbfQ6FbvfwZheu7DRtnrJ8Na8E4ErqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615376; c=relaxed/simple; bh=NTv5/DwTN5mFixsR8Cr3qjEgNKg+xDGXeNdv6HjXAnI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OibgCkJMYfHtAcvHOnTfEjcXI8ZkkFTEV3WpD0Cs8fN7Kl/g+bhiEzj9an/v08GPN9h1ncSPObtOvz9uqYe5GPiFNW6qVU1INEb3SVp8OG6kb09KpNjbTpIrBc06FkQiJGMULRdRmZa/ttZAIrMd9ljjNKFX3eFLkDKns+RZhPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=jr/gtnYU; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="jr/gtnYU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=nW4dx7azFe7LSVA6jpBULm/JBvhTDPlBwBxqVX/o6v4=; b=jr/gtnYUPJn35bFbgnTThAFd3i mtksnuQUghedUQr8c6jm5LlOllAB3R3ehY7g8J5bELF1jP0o3HetsYcimWm2JUzWAnntKmcEmRew/ 0CO2R6zOVxeYRRBuaIlNPypBSg0M8i7+AZ4fDeCZRrZRLUd66S9L//+vgLQLN3VrZl9osXejugCT4 +XaU3SwWsLaxHctoOvodE1LaJbqWxFFzwWsxV2KcNxVKaHHbxVQ4zLgiNMoau8G0Q6ntO8VW2SquM MVakD19DCowOIFfjMTzUrht2wdHhVEpkNznqMEdyALli7zSP7PhwW9VQ81L2yCcGmsKaK1XfOQh2G 1y6HIqPw==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wuSGp-00520d-2l; Thu, 13 Aug 2026 10:02:44 +0000 From: Breno Leitao Date: Thu, 13 Aug 2026 03:02:21 -0700 Subject: [PATCH v2 2/3] mm, swap: distinguish a malformed swap entry from a dying device 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260813-swap-v2-2-4a625ccabdae@debian.org> References: <20260813-swap-v2-0-4a625ccabdae@debian.org> In-Reply-To: <20260813-swap-v2-0-4a625ccabdae@debian.org> To: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , Hugh Dickins , Baolin Wang , Peter Xu , Johannes Weiner , Yosry Ahmed , Chengming Zhou Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=5745; i=leitao@debian.org; h=from:subject:message-id; bh=NTv5/DwTN5mFixsR8Cr3qjEgNKg+xDGXeNdv6HjXAnI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqfZYwXdMP2H5UT67k+zQAurHB5wIbkOKJoS0l9 Y8qCjVrOzaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCan2WMAAKCRA1o5Of/Hh3 bXLmD/wPbEfuG7uCd9zWW4kPRlgxcvF5VGKtVq6f0teE3v3NYCo6u5yMsJW1nVjzEJ4fHyAcvnX Mgay5zRzzIQLWKD3xqyzNrzaFZ7ZibMRFeg1FPGPw5vwFQ3cPD5rQetn649hcZ+Gia/5aPpy2UQ /hEkp8mvn3E9kMPYQpR0M03lp//wNPCkK4PMzJVwH5VGLJDoTA83hQ0Gu3izR+ZnJMbvJidiYEi 5+atSAKQaInTlKfOHpAAublGxU65jMRRUiUuoPLFWza+dyd/C9DCd46TMJYi1KTQI5zF+wXkj/w jLauqHPKs4jqT3vMQ5zJbeYx+4l/Mhui48yP8i48KmPzvaFbpQ4msnMIW4Hv60gM28SlIkW7vZw W8W485kjSWmwLLX5t7CwARFVdxIFEEJqDfhi8U2bckFjDWuPJnN7DKjFQPNbeyTCxgTskQZPWcW tHsI9TtvbwT8AlEZiaSP6sqQHyxnoLrJUo5pqDUpee8NFNKzzipeN5kbRAcaRxOLxhHwxsShDQA 3KdJc5M7bwzlrsi61/6JK1B5f6kKBZZq+EJd7icEG4LD86z2UxxswrfORGzANxJvVZkI67cOOVA zPeC3/mpoHHDYUpnDMXkfskHLF78FUtt9SlYbTSJC6HZFmmuANrSXN49GO5f3Cq367PjRCSPW6W ry3nkTKzvFvrCyg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao get_swap_device() returns NULL for two different things: an entry whose type names no swap device or whose offset is past the end of one, and a device that swapoff is taking away. The first never becomes valid, the second does, and callers cannot tell them apart. Return ERR_PTR(-EIO) for the two malformed cases and keep NULL for swapoff. copy_nonpresent_pte() already reports -EIO for the same corruption on the fork path. Callers bail out on failure either way, so switch them to IS_ERR_OR_NULL() and clear si where the cleanup path would otherwise put an ERR_PTR. No functional change. Signed-off-by: Breno Leitao Acked-by: Kairui Song Reviewed-by: Barry Song --- mm/memory.c | 6 ++++-- mm/mincore.c | 2 +- mm/shmem.c | 2 +- mm/swap_state.c | 4 ++-- mm/swapfile.c | 14 +++++++++----- mm/userfaultfd.c | 3 ++- mm/zswap.c | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d9cf941967cf0..7201e848129a7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4954,10 +4954,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out; } =20 - /* Prevent swapoff from happening to us. */ + /* Prevent swapoff from happening to us, and reject a bad entry. */ si =3D get_swap_device(entry); - if (unlikely(!si)) + if (IS_ERR_OR_NULL(si)) { + si =3D NULL; goto out; + } =20 folio =3D swap_cache_get_folio(entry); if (folio) diff --git a/mm/mincore.c b/mm/mincore.c index ff4ac82817683..c086836bc4bcc 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -71,7 +71,7 @@ static unsigned char mincore_swap(swp_entry_t entry, bool= shmem) */ if (shmem) { si =3D get_swap_device(entry); - if (!si) + if (IS_ERR_OR_NULL(si)) return 0; } folio =3D swap_cache_get_folio(entry); diff --git a/mm/shmem.c b/mm/shmem.c index 65572cbf1bd3c..d0a9f52bfed71 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2276,7 +2276,7 @@ static int shmem_swapin_folio(struct inode *inode, pg= off_t index, =20 si =3D get_swap_device(index_entry); order =3D shmem_confirm_swap(mapping, index, index_entry); - if (unlikely(!si)) { + if (IS_ERR_OR_NULL(si)) { if (order < 0) return -EEXIST; else diff --git a/mm/swap_state.c b/mm/swap_state.c index 4b7a3303c463b..f2e86d6626ecc 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -715,7 +715,7 @@ struct folio *read_swap_cache_async(struct swap_io_ctx = *ctx, swp_entry_t entry, struct folio *folio; =20 si =3D get_swap_device(entry); - if (!si) + if (IS_ERR_OR_NULL(si)) return NULL; =20 mpol =3D get_vma_policy(vma, addr, 0, &ilx); @@ -951,7 +951,7 @@ static struct folio *swap_vma_readahead(swp_entry_t tar= g_entry, gfp_t gfp_mask, */ if (swp_type(entry) !=3D swp_type(targ_entry)) { si =3D get_swap_device(entry); - if (!si) + if (IS_ERR_OR_NULL(si)) continue; } folio =3D swap_cache_read_folio(&ctx, entry, gfp_mask, mpol, ilx, diff --git a/mm/swapfile.c b/mm/swapfile.c index 31c8a340606bb..b96bc89815935 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1504,7 +1504,7 @@ int swap_retry_table_alloc(swp_entry_t entry, gfp_t g= fp) unsigned long offset =3D swp_offset(entry); =20 si =3D get_swap_device(entry); - if (!si) + if (IS_ERR_OR_NULL(si)) return 0; =20 ci =3D __swap_offset_to_cluster(si, offset); @@ -1859,7 +1859,10 @@ void folio_put_swap(struct folio *folio, struct page= *page) * Check whether swap entry is valid in the swap device. If so, * return pointer to swap_info_struct, and keep the swap entry valid * via preventing the swap device from being swapoff, until - * put_swap_device() is called. Otherwise return NULL. + * put_swap_device() is called. Return NULL for an empty entry or a + * device that is going away, and ERR_PTR(-EIO) if the entry's type + * names no swap device or its offset is past the end of one. These EIOs + * are preceded by pr_err(). * * Notice that swapoff or swapoff+swapon can still happen before the * percpu_ref_tryget_live() in get_swap_device() or after the @@ -1900,12 +1903,13 @@ struct swap_info_struct *get_swap_device(swp_entry_= t entry) return si; bad_nofile: pr_err_ratelimited("%s: %s%08lx\n", __func__, Bad_file, entry.val); + return ERR_PTR(-EIO); out: return NULL; put_out: pr_err_ratelimited("%s: %s%08lx\n", __func__, Bad_offset, entry.val); percpu_ref_put(&si->users); - return NULL; + return ERR_PTR(-EIO); } =20 /* @@ -2001,7 +2005,7 @@ int swp_swapcount(swp_entry_t entry) int count; =20 si =3D get_swap_device(entry); - if (!si) + if (IS_ERR_OR_NULL(si)) return 0; =20 ci =3D swap_cluster_lock(si, swp_offset(entry)); @@ -2127,7 +2131,7 @@ void swap_put_entries_direct(swp_entry_t entry, int n= r) struct swap_info_struct *si; =20 si =3D get_swap_device(entry); - if (WARN_ON_ONCE(!si)) + if (WARN_ON_ONCE(IS_ERR_OR_NULL(si))) return; if (WARN_ON_ONCE(end_offset > si->max)) goto out; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 24a4d92ffa3c2..bf7bc7fb1aa0f 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1700,7 +1700,8 @@ static long move_pages_ptes(struct mm_struct *mm, pmd= _t *dst_pmd, pmd_t *src_pmd } =20 si =3D get_swap_device(entry); - if (unlikely(!si)) { + if (IS_ERR_OR_NULL(si)) { + si =3D NULL; ret =3D -EAGAIN; goto out; } diff --git a/mm/zswap.c b/mm/zswap.c index f7c9c89f6449c..bc9b931d6f447 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -997,7 +997,7 @@ static int zswap_writeback_entry(struct zswap_entry *en= try, =20 /* try to allocate swap cache folio */ si =3D get_swap_device(swpentry); - if (!si) + if (IS_ERR_OR_NULL(si)) return -EEXIST; =20 mpol =3D get_task_policy(current); --=20 2.53.0-Meta From nobody Tue Sep 29 02:33:20 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 3521E445AF2 for ; Thu, 13 Aug 2026 10:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615375; cv=none; b=rEbRgyaBVrs9lAftOvXeDNxDHol4gqVPqdlmuazOPgeIUIdRxZ0ZpIACAEKAXCaWBOc9ddu/R0OTZiBV4KBsbBbsiLZHHeZLwCn5pjQ5TdIul9E6JiQh276K8MvoSaGOu4Tya4j+Yk6n0rZBgOundiyM+cS2gd9F5/B7WHwO1+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786615375; c=relaxed/simple; bh=SmrcYFoWWX0gEHdUAwCRGijyGvjB/SH6IwdV5jR8akM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gVs+5UkNBc+4nNZS+yxCQcNcEL1wkDJ5lywMHPkWYtK+XzR7JFVDOwPmpRNCe1qcAG31eFfHW1Y2KxlHoFFld6nci7xhAEWWJmGhntY9U65hYqerUnxOBr4rOcUBc4czUhhRHLRYsXY2T84M/BQl7poFL/40cvsAdUhGV7Ys++s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=jTcssKBz; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="jTcssKBz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=hLVa+zjcHZ3q89ZlAQukI32EVVr5AUEVuCmPcq6Ui6I=; b=jTcssKBz7dr2qg6m1N2so6N7BO q+nPfb1dlbVYlKRSKu278fmNllB8oizjDynyYTea4w/doHRjyyXoc01tCXBbzMNzkh1JL4dvigoq0 wn9U2D9nX1DLlpojcc42pkcjK8uC7zUBZKdBDy6H+OVisKC7JoxPpivwFy1w43r3Fk+lACgIvKg7E m3ECEyRimVWkUTSTq+O4c9spEhe2aBFtGDlmwH1hdhDB4kzZdgVCNM9kcRk9jdvnUSoyyMNfJsNak tSVQZ8+RiYbWt+OpJnF5RVl3Jj2POahrdBK1QLsj+OqgtPFSwUJWJrT7mfV7iUqwSodyCfTnm0rnd LUAj5VuQ==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wuSGv-00520o-3D; Thu, 13 Aug 2026 10:02:50 +0000 From: Breno Leitao Date: Thu, 13 Aug 2026 03:02:22 -0700 Subject: [PATCH v2 3/3] mm: fail the fault on a malformed swap entry instead of retrying it 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260813-swap-v2-3-4a625ccabdae@debian.org> References: <20260813-swap-v2-0-4a625ccabdae@debian.org> In-Reply-To: <20260813-swap-v2-0-4a625ccabdae@debian.org> To: Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , Hugh Dickins , Baolin Wang , Peter Xu , Johannes Weiner , Yosry Ahmed , Chengming Zhou Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-f8e9d X-Developer-Signature: v=1; a=openpgp-sha256; l=951; i=leitao@debian.org; h=from:subject:message-id; bh=SmrcYFoWWX0gEHdUAwCRGijyGvjB/SH6IwdV5jR8akM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqfZYw9iNKkPP+i+19qL3SClZWK1+Fa9721SNcr UBC7tBWG3uJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCan2WMAAKCRA1o5Of/Hh3 bad1EACgMQM2KbtrxWEgwHNbB7QPz+gCJwzh4OW8BQ7Wj+BguF4gu28JGQl1Qy5o9MOFuhNjA4k 7SoINP180rTa9PmSoDVXIflJ+UJbZigq1nsXuJCutdNPOOWM3lPbvAtmhBLOua15cSbKZwRmQsM qf2yCRJwA2nSTAoSWlG86gv4q99tPro36mUr+P/0YWpydC4jXp03XFoExMBal3N/PcAlzUgTpNX EAjZUYc6eBXFOHCYw4A3pf8Bx1MU+0m4b1Yg17k6I3sp2Zi3s7An054zKYiJxzSRmpjgiwAS3m0 YlW4aQd8Zrno/YGyanJjm+1tgNG9KoA4ZHd9gICzh4JvZWsw87FRzlLukpgG+cT/teIEuLRRYIB QrGNs0aaHkuTIihG2ll+ClCEPOCvmmP03po5iAhNuff7YpHYumm25pLw6MU5ZggAWyVYZkwFXqe zmPiUL81D6EGsRC7TVQuXdKChdXupd+5JVn8QNKLuskCdDI1vz8M1Ky/LMd60ryIVTBav/ou1pa 4OIErsleCnefOj0fJqGD0OmnN1v46fePOyhg3qGxJWXTRhEPTcgFXmOWI/yEbjdIG909TFjpebH wdD8R8MdHsJK3jaUakVsRZf7FQGylfaAxTijrZmn//T49hT88BVfT/hYD9al0ZOJZ3teBRYUnwf po/eNDPaRnDsDgA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao do_swap_page() returns 0 when get_swap_device() fails, which the fault handler reads as "handled". For an entry that can never become valid the retry takes the same fault again, so the thread spins forever, retrying on the same fault. Return VM_FAULT_SIGBUS (Bad access) for a malformed entry (pr_err() was called at get_swap_device()). Signed-off-by: Breno Leitao Acked-by: Kairui Song Reviewed-by: Barry Song --- mm/memory.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 7201e848129a7..fa2b3d2ad3202 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4957,6 +4957,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) /* Prevent swapoff from happening to us, and reject a bad entry. */ si =3D get_swap_device(entry); if (IS_ERR_OR_NULL(si)) { + /* A malformed entry never becomes valid, so don't retry it. */ + if (IS_ERR(si)) + ret =3D VM_FAULT_SIGBUS; si =3D NULL; goto out; } --=20 2.53.0-Meta