Linux MM tree latest commits
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,ziy@nvidia.com,vbabka@kernel.org,rppt@kernel.org,osalvador@suse.de,muchun.song@linux.dev,mhocko@suse.com,matthew.brost@intel.com,ljs@kernel.org,linmiaohe@huawei.com,lance.yang@linux.dev,hannes@cmpxchg.org,dev.jain@arm.com,david@kernel.org,bhe@redhat.com,baolin.wang@linux.alibaba.com,baohua@kernel.org,mst@redhat.com,akpm@linux-foundation.org
Subject: [to-be-updated] mm-memory-failure-serialize-testsetpagehwpoison-with-zone-lock.patch removed from -mm tree
Date: Tue, 09 Jun 2026 12:58:33 -0700	[thread overview]
Message-ID: <20260609195833.A89801F00893@smtp.kernel.org> (raw)


The quilt patch titled
     Subject: mm: memory-failure: serialize TestSetPageHWPoison with zone->lock
has been removed from the -mm tree.  Its filename was
     mm-memory-failure-serialize-testsetpagehwpoison-with-zone-lock.patch

This patch was dropped because an updated version will be issued

------------------------------------------------------
From: "Michael S. Tsirkin" <mst@redhat.com>
Subject: mm: memory-failure: serialize TestSetPageHWPoison with zone->lock
Date: Tue, 9 Jun 2026 06:12:49 -0400

TestSetPageHWPoison() is called without zone->lock, so its atomic update
to page->flags can race with non-atomic flag operations that run under
zone->lock in the buddy allocator.

In particular, __free_pages_prepare() does:

    page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;

This non-atomic read-modify-write, while correctly excluding __PG_HWPOISON
from the mask, can still lose a concurrent TestSetPageHWPoison if the read
happens before the poison bit is set and the write happens after.  Will
only get worse if/when we add more non-atomic flag operations.

Fix by acquiring zone->lock around TestSetPageHWPoison and around
ClearPageHWPoison in the retry path.  This serializes with all buddy flag
manipulation.  The cost is negligible: one lock/unlock in an extremely
rare path (hardware memory errors).

Note: SetPageHWPoison and TestClearPageHWPoison calls elsewhere in this
file operate on pages already removed from the buddy allocator or on
non-buddy pages (DAX, hugetlb), so they do not need zone->lock protection.

Link: https://lore.kernel.org/df06b66fe4ff8e925ee0714955abc2183a727b90.1780998980.git.mst@redhat.com
Fixes: 6a46079cf57a ("HWPOISON: The high level memory error handler in the VM v7")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Zi Yan <ziy@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Vlastimil Babka <vbabka@kernel.org>
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/memory-failure.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/mm/memory-failure.c~mm-memory-failure-serialize-testsetpagehwpoison-with-zone-lock
+++ a/mm/memory-failure.c
@@ -2335,6 +2335,8 @@ int memory_failure(unsigned long pfn, in
 	int res = 0;
 	unsigned long page_flags;
 	bool retry = true;
+	struct zone *zone;
+	unsigned long mf_flags;
 
 	if (!sysctl_memory_failure_recovery)
 		panic("Memory failure on page %lx", pfn);
@@ -2380,7 +2382,11 @@ try_again:
 	if (res != -ENOENT)
 		goto unlock_mutex;
 
+	/* Serialize with non-atomic buddy flag operations */
+	zone = page_zone(p);
+	spin_lock_irqsave(&zone->lock, mf_flags);
 	if (TestSetPageHWPoison(p)) {
+		spin_unlock_irqrestore(&zone->lock, mf_flags);
 		res = -EHWPOISON;
 		if (flags & MF_ACTION_REQUIRED)
 			res = kill_accessing_process(current, pfn, flags);
@@ -2389,6 +2395,7 @@ try_again:
 		action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
 		goto unlock_mutex;
 	}
+	spin_unlock_irqrestore(&zone->lock, mf_flags);
 
 	/*
 	 * We need/can do nothing about count=0 pages.
@@ -2410,7 +2417,10 @@ try_again:
 			} else {
 				/* We lost the race, try again */
 				if (retry) {
+					/* Serialize with non-atomic buddy flag operations */
+					spin_lock_irqsave(&zone->lock, mf_flags);
 					ClearPageHWPoison(p);
+					spin_unlock_irqrestore(&zone->lock, mf_flags);
 					retry = false;
 					goto try_again;
 				}
_

Patches currently in -mm which might be from mst@redhat.com are



                 reply	other threads:[~2026-06-09 19:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260609195833.A89801F00893@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bhe@redhat.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=lance.yang@linux.dev \
    --cc=linmiaohe@huawei.com \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=rppt@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox