From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.151 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794397159; b=j3Ga22jiEa0HgV1ke1PypdClPCYmhAgC3APYc9tWvh+I1jfpApvroUiTZwsHgF8NlBsi K7ivMSk8/cw0D8tGbnbIZdlw8KaLDf0Xf94NjqkGctXuKExfDXsXdsqqrl0jcPOgFLx+Y o8dPyQtpihFNIBQ+WEZuLZs6IqE8tVHgMWHsCCNGTl7jw2HolkFX7JNOPyBB+lXKc2rxV f9mcJQWXRkHxTHgTT37uFdDDKR6hYhUjQsVKUJuKRnZitJfav2WnqKTmCDgwo1ki9NS7k FtJTRoaREz/S+tLceuiTi5At1I6risL7fPs862Ixacr2UY4p4dT+VqfEDafefOJJenQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794397159; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=JsSfYSFniRGmuPRfq48u5DDdTpeJF4QuAl3fe5dik5M=; b=uFk/zelNSiTNmYjONbrfzR0bo+1ZWUJ5p0BjXXaDTvRp5OzriYCAkdUJRIir2zyBP8CV BsKyFj62dwgzDEVeBPEQT27tf/RHxRmb8GsL7qpK0bgFNfDaQuaux3YkquOAZZFyqYMHn kRJy4JnTVSJj1/gwsbOG8u7R2izd+ye+HwtLfk6nSS3UNEN49TRpXKigLwIDyIQXXZrys YtSALYhLQBXicjEF+ySHDLHXd41kUmgTrme07v2l61PVvoXFp8glLiRfK4s2RV30Cvgqn 6H6ooc5sRqlqeT8+OA9ARREzrGqFuNondHYBxdCssdH+COec/CxkXY3YbM+IXxUe0Mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ag3zwCYS; arc=none smtp.remote-ip=95.215.58.151 Received: from mta1.migadu.com (out-151.mta1.migadu.com [95.215.58.151]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ADDA606A881 for ; Wed, 11 Nov 2026 11:39:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0ADDA606A881 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ag3zwCYS X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=zdZjBwRCrc/bJJQOamLttRr417Z2hw8mLNGL8JIUru8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794397155; v=1; x=1795001955; b=ag3zwCYSpzqYUYA54fdErOhJI5ZfvsIqZlLhFTR1lN2npGQBNhVAXh6oxEb6plsz/R/fgyCU V+qWgWJFemeb0IuQrEJ88ypX1XdKx5B74yIqkTzMdNehMo4ZhvIUBUaprRDrs1rOmFFyiM19fPu PlounxJCpV3EDB8RajRn5Nnw= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 780683f44d9afa50; Wed, 11 Nov 2026 11:39:15 +0000 X-Mizu-Trace-ID: 780683f44d9afa50 X-Migadu-Flow: FLOW_OUT From: Usama Arif To: Andrew Morton , apopple@nvidia.com, byungchul@sk.com, david@kernel.org, gourry@gourry.net, jannh@google.com, joshua.hahnjy@gmail.com, liam@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, matthew.brost@intel.com, mhocko@suse.com, pfalcato@suse.de, rppt@kernel.org, surenb@google.com, vbabka@kernel.org, ying.huang@linux.alibaba.com, ziy@nvidia.com, kas@kernel.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kernel-team@meta.com, baolin.wang@linux.alibaba.com, Nico Pache , ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev Cc: Usama Arif , stable@vger.kernel.org Subject: [PATCH 1/3] mm: don't PTE-batch a swap-in over a hardware-poisoned subpage Date: Wed, 11 Nov 2026 03:38:29 -0800 Message-ID: <20261111113904.650722-2-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261111113904.650722-1-usama.arif@linux.dev> References: <20261111113904.650722-1-usama.arif@linux.dev> X-Mailing-List: linux-kernel@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 do_swap_page() checks PageHWPoison() on the faulting page, but the large-folio batching path then maps the rest of the folio without looking at the other subpages. A poisoned subpage that is not the one being faulted gets mapped anyway, and the fault that would have reported it never happens. Skip batching for such a folio and let each page take its own fault, where the existing check catches it. Scan the subpages rather than testing the folio-level PG_has_hwpoisoned: memory_failure() sets PageHWPoison() on the subpage first and only sets the folio flag much later, and the bail-outs in between - for example get_hwpoison_page() losing a page lifecycle race - return with the subpage marked and the folio flag never set. Fixes: 508758960b8d ("mm: swap: entirely map large folios found in swapcache") Cc: stable@vger.kernel.org Signed-off-by: Usama Arif --- mm/internal.h | 15 +++++++++++++++ mm/memory.c | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/mm/internal.h b/mm/internal.h index cd3675c044e0a..e61c02f4019b0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -28,6 +28,21 @@ struct folio_batch; int __copy_remote_mm_str(struct mm_struct *mm, unsigned long addr, void *buf, int len, unsigned int gup_flags); +/* + * Check every page of the folio for HWPoison, rather than relying on the + * folio-level PG_has_hwpoisoned, which memory_failure() can leave clear. + */ +static inline bool folio_has_any_hwpoisoned_page(const struct folio *folio) +{ + long nr = folio_nr_pages(folio); + long i; + + for (i = 0; i < nr; i++) + if (PageHWPoison(folio_page(folio, i))) + return true; + return false; +} + /* mm/workingset.c */ bool workingset_test_recent(void *shadow, bool file, bool *workingset, bool flush); diff --git a/mm/memory.c b/mm/memory.c index d477a4f986bc8..4b7d456332200 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5158,6 +5158,10 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) swap_pte_batch(folio_ptep, nr, folio_pte) != nr) goto check_folio; + /* Let a poisoned subpage take its own fault. */ + if (folio_has_any_hwpoisoned_page(folio)) + goto check_folio; + page_idx = idx; address = folio_start; ptep = folio_ptep; -- 2.53.0-Meta