From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9350A2F363F for ; Mon, 8 Jun 2026 13:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780926527; cv=none; b=ZZuOfGNNbEboupF9OrDrCFmTQQeUtQphCDaVVMrLv2IVdeWRRYMlK7cah2TK8KobCVFzo2bCPLhWgdVPQNv96NBCS+BybyOPCd3QjoyBHAv4U7dLktGhwgkYcdqik9Kbyo6aNiGjvDKMe/tHsdWXInLaUlGS9pXidBNM4GPQKuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780926527; c=relaxed/simple; bh=V/3C3iHgYOS9sDi2nK/Ncy4FwliOr4kXu6TWRUNB6JU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y+ZkLUJsvyo1Uj9M3eKbbzM1UMWEICwPy0aLzo9alq937bq6heuJEv5jlGpwqy4up893/AV+vgQdAiAUsBw5a1fbc7nRjPUg3ZwNu+KjdkMN5Umj2No6Im43ExUkHAHb8rJRByeI1uydVzps9D/wwdnat837zAN+KDVLOqBvzjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EVGYg7cy; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=qqn9eMuc; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EVGYg7cy"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="qqn9eMuc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780926525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xoJIhnuvHMP+I5R4ZGbFyAQYvKF+rv0fOA2ZXMSfz9U=; b=EVGYg7cyu/iPAsmSM8+XkooC0xS7zKZ56YWvDvucfvCkkIFbdNpy4V9B/3CoKdJxJ7C4ji YjED0vGeapWrfi7ZOYOYtfE79Ijwf1uZMKlfLWhofB/A9V8bGjrFnXPWaINk7oyWc7oYHZ EddBWv9fx25OEqdU9yVVjNqoqKEIlVQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-fKrC0fYJMy-l2Ce07vAvUw-1; Mon, 08 Jun 2026 09:48:42 -0400 X-MC-Unique: fKrC0fYJMy-l2Ce07vAvUw-1 X-Mimecast-MFC-AGG-ID: fKrC0fYJMy-l2Ce07vAvUw_1780926522 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490b3ec3f7fso29200895e9.1 for ; Mon, 08 Jun 2026 06:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780926521; x=1781531321; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xoJIhnuvHMP+I5R4ZGbFyAQYvKF+rv0fOA2ZXMSfz9U=; b=qqn9eMucUbxhM4mRuQKLulvj3WKEY+h3Lnsk2Di0dp2diFhz49Px6OMxBDFypXFnL3 qPNaWMXH6VNQpO2DU9zu/oW5492au7JIC6JUtOHrqTeb0pzXNOFsxgGpSz9CB2IxDu8k Hw1vryyuYet36YVlyQXfsY2iYa6iVLZTTtdeYMMDqrwiebqFDpegvJITDQfNj1XyfNu2 fL81HxXVxYj64vc+Pnk9eZIgtdnrAwyYvYmCOTP5rko37Im/Rkyw3Nf0tt8N8E6E2BMm HmJ323tVpX3/66e7okl6ztWbn3FCY2jiBiMu4T1N1JuSB/0iiRNewEUUNX1nI7q/GwnE d2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780926521; x=1781531321; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xoJIhnuvHMP+I5R4ZGbFyAQYvKF+rv0fOA2ZXMSfz9U=; b=QO1rfYEinjHLihXBn3UUMsN0AWcN6EjkrrNKCiAT1N2npfwVJPxujFBPWk3n/Ay5Xf JWmtTUZpBmrRR1dyumq8WHN0dx7G9fyc2xliO+R/tt4poml52XR9yel7dWXAwRMLewIc Q2idIfyszXD5ftjGyYaSqRXmBWQxpCZwg2PPlW35lTk/ZH8S8Rz0ewYNRAz/KMk0oIfD E+dEIBpeiwFkz71lWMbKlGnboQ6bfDmMdE951WWyfTDv/GH1dcHhfCc++2XLeUiaF2qB xqC/r8iFPQkXbozp3edtnJhgogsO12wvV5eOUg9FoYnAZhBzfSqnOpgSHIjWTJwfZRw3 WN5g== X-Gm-Message-State: AOJu0YwPmxP5wIekzQATiekHazqnRZhaMsBLJ+mSP1wPAtwRvqMDrL8x x3GqkhRTQLIsXCf303b1WfvBdHOe6CmUyzNVaoMJ27H72DuZf/CrB4HeI//MnkLe1OveRHLC6v+ gZUi8bQBMAP4PYXRp0Ef4LgQhY5dKRTUwjzRw1To7cQ/yzohP6m94UC1gdV3ANIhD0Q== X-Gm-Gg: Acq92OHkmIlLwJl1vuXhXJ4b0W06XKGa7EQQpLnEedLQ+9eAaLTbv804OUyq2XBwA4t F1ulm7dYUwIr2cmt8DdHBuZbC6OabdFdAoz66YJcgN7EYH7D2Q4L3BUPNUHUHoiJ0udq2UL48Uf +Fho+RUjakm2LX8VnhORV0N6gpnnw+nN7jdg+Vrik8vMojgJ9EVEZk1Qa6JfZmWnrSkDbKBUqFt S1+kbXlXMY3by6mC3FZjCrFIvujG5gSs4uX46ZfJoT03Kk/vdwBstFMfLWp6snYEzzX2NKPW8Ok /3q3UaUU43+MIimeU0am10v9MaScM7MV0HrOKxR13lUe9LqKilI2UqjtJi6fN0qYboGISw9G4ho M93/nqGesqDlsZyXqfLWq/5c= X-Received: by 2002:a05:600c:c0d3:b0:490:53b0:9e53 with SMTP id 5b1f17b1804b1-490c265c107mr216680495e9.1.1780926521311; Mon, 08 Jun 2026 06:48:41 -0700 (PDT) X-Received: by 2002:a05:600c:c0d3:b0:490:53b0:9e53 with SMTP id 5b1f17b1804b1-490c265c107mr216679675e9.1.1780926520756; Mon, 08 Jun 2026 06:48:40 -0700 (PDT) Received: from redhat.com ([185.16.164.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3918fcsm451375885e9.3.2026.06.08.06.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 06:48:40 -0700 (PDT) Date: Mon, 8 Jun 2026 09:48:34 -0400 From: "Michael S. Tsirkin" To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Muchun Song , Oscar Salvador , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli , Miaohe Lin Subject: Re: [PATCH v10 02/37] mm: memory-failure: serialize TestSetPageHWPoison with zone->lock Message-ID: <20260608094153-mutt-send-email-mst@kernel.org> References: 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=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jun 08, 2026 at 10:43:21AM +0100, Lorenzo Stoakes wrote: > On Mon, Jun 08, 2026 at 04:34:23AM -0400, Michael S. Tsirkin wrote: > > 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. Follow-up patches in this > > series add similar non-atomic flag operations as well. > > > > 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. > > > > Acked-by: Miaohe Lin > > Signed-off-by: Michael S. Tsirkin > > Can we have Fixes: and Cc: stable and also send this separately please? > > These patches seem like unrelated fixups that you've discovered along the way, > and don't belong as part of the already rather large series, unless I'm missing > something here. > > Thanks, Lorenzo I think you are mising that they are a dependency, not unrelated. For example, this issue gets worse with the patchset as there are more places that manipulate flags without atomics. No? You are welcome to send this to stable, but I think stable rules preclude theoretical bugfixes. As for Fixes: the issue has been there for decades. I wouldn't know what to attribute it for. I guess I could send these separately, too, why not. Not sure what this accomplishes, but hey. But is that an ack? You want this fix merged even before the feature? > > Assisted-by: Claude:claude-opus-4-6 > > --- > > mm/memory-failure.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > > index ee42d4361309..3880486028a1 100644 > > --- a/mm/memory-failure.c > > +++ b/mm/memory-failure.c > > @@ -2348,6 +2348,8 @@ int memory_failure(unsigned long pfn, int flags) > > unsigned long page_flags; > > bool retry = true; > > int hugetlb = 0; > > + struct zone *zone; > > + unsigned long mf_flags; > > > > if (!sysctl_memory_failure_recovery) > > panic("Memory failure on page %lx", pfn); > > @@ -2390,7 +2392,11 @@ int memory_failure(unsigned long pfn, int flags) > > if (hugetlb) > > 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); > > @@ -2399,6 +2405,7 @@ int memory_failure(unsigned long pfn, int flags) > > 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. > > @@ -2420,7 +2427,10 @@ int memory_failure(unsigned long pfn, int flags) > > } 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; > > } > > -- > > MST > >