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.129.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 4E82A367B70 for ; Fri, 29 May 2026 15:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068141; cv=none; b=FgP3/CppAEtP0/3kfqql/6+0eGzgd9hCBCXEDaQWm+FivYjOjFMzbaRFwuwcL0H8mcNjJ5Iw3U03xVYYub1A1k4vC3bDgk3QyfsKJmRkyhBYdAYwI5Y03TrWhzbFi3MsPtmVnFVwwm8KPJWUuuDv/kdQORArW8adX+SgUkwUZ4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068141; c=relaxed/simple; bh=B9hCuvGWJTakJ4KIERi0AyOg+0/ybGKp5cfFr2jdtWo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OGXmEaLw9WW8IjypLVJ71vVPNSxs7MLif4V3IliFrwS2yGdvKtZWdo1wEjY96aqfJSK22ZU5FtPe8ueKQItvJhcoaKOfGwGjL5eKF6n6v1oOZLqCEfMoDYdJUedfA//aMDKBAegXPPE5L2m6PcZ+1HFa/xUujrfLpyP+xhHjgEs= 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=H9olcQq8; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=UBHsnKVu; arc=none smtp.client-ip=170.10.129.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="H9olcQq8"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="UBHsnKVu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068139; 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=apkJ3vhwafShLYfDd+RnV0F+C4AxcxVXpW06K2eXGn8=; b=H9olcQq8GwknshUs0w5jZqcG6v8WeskuNJn2exfiI6ep0ps3cn9Hxftv/Yo0cqiTayajIC UsUeGloOYYhsRsqt0Cz5CwbIGExiX8qS+3a0ZByHXvQ+bxDwEVMLf5knUXoah4AgC3P+0S 7lfJB6x6gRoUOafidMqsjX7ZmHnIA2s= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-4jzV1ggwNjWhAxrYHbElLg-1; Fri, 29 May 2026 11:22:18 -0400 X-MC-Unique: 4jzV1ggwNjWhAxrYHbElLg-1 X-Mimecast-MFC-AGG-ID: 4jzV1ggwNjWhAxrYHbElLg_1780068137 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44a3aee3813so6281386f8f.3 for ; Fri, 29 May 2026 08:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068137; x=1780672937; 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=apkJ3vhwafShLYfDd+RnV0F+C4AxcxVXpW06K2eXGn8=; b=UBHsnKVueUqZIqC8svt2XHr80/+5jPYPceKcnFsTZQyizUrHUuJv/hM1tdUfBu1Ybv Oha/YZV4qfdUucXE4buzlR14h7N5PZC/1y+INcUTiKS+HMsDcptJ6NMiCq6Rn9HhqqrQ 2tUM4L2Blkn39j3sEy74FnbL7hBdcC06oLnnFJtaHk38by6SYrtCGWBkt9o3MI2q9jbp VGBSmr/qR/s8MTt0PBprq1LotyH6NS+WtvAGOlSkfDbOHQl9fVmEAArcWEePctklYe7i lHQNpxDSfdpHSveFf3BAzlEcxrriEZfdZnMAw+90Kbl9ZsxriN0VWAoO6eTT4X+WGpUa e3WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068137; x=1780672937; 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=apkJ3vhwafShLYfDd+RnV0F+C4AxcxVXpW06K2eXGn8=; b=Pb+Plh8rfpiP5ILiwSuDFAPPu5JPKWNgOunhXaEHNrJ4eZcHKDOw4IVaWPVGUfeNUC 2VeqiySt0pgV6JwmdLtPNKK1bhgKjuwwD42bBc7267w2VHIZz2MXlz45cUQwdPEqT6Xz DPgYd4s3XrwBZpRgvXFM8uPW/coVY8y9UE4k0+vE/v/+BfRS7i1U6IFYKn+38mzlS/YC 1jCKc8zJa/5ZVw5ygDEvpC5DE/WHRZYE2cFBGR5C6e3EgZP+QzREcH03OeMUR30Eofes iXN8cYUpEq32XRhvVNBBp4AqhtFFV6cpelvG1KXvpuXJjEPucJq6q2V5t/Q3wuUJcco7 PVug== X-Gm-Message-State: AOJu0YzznP0kpoFpdKOx4KC7mLp4O76l3kANcgBLJy9UFQ6bFJhTcJJU 1QLd/sgFAnokNefDTckD6x3ezyhA8/NDUXAl0rBkee5VVBm03UCXN+JSHm3/vzYlDGOFwyjAzYD UbJEMb9oszlDyTZ20YlO6U1m5h0qpOww8Ldm+5Ui/r1aQUU6AO76IoVe7UmJ49xz56YKBNQU/cg bPXvppcBJpKdpE1B298Rfpn4FopGfaKD7RtKVMlBT446M= X-Gm-Gg: Acq92OHE8uJHUb3EtKYjOFxn84NPsb/ByWI4/2VwG+nMPLT2DeVvXf4w411X+78u70+ Qq+MLs3Z0jflAI+qqMUEPaWT90+HFes6p/UVp1tSx/knjPEry5hTjphbnNnTn1sTclGtTO8DsTt bX/4789mOE3h5DWJlSPQBb7NEhw9RzoSBl8siffDIdyqW46nUUSN7sBNBggVmObQeCp+lw9QTUn EsJNtpBkV3Ij3cD0RKZVmrwxTrY/NoZvxlus9V8OxozWhljg9x7xANaxtCYkcTopjQGCISIZWn/ ehgwk9RiVA1xU9BWQ/Z7hUYp5Ecbs0WgHbDxdG384ZE9HPGztV0igiTM1mk81x8hossQXLuBpFP DgS27lHoUYMoHjtIlCDV8K2KG3fa/vMCtGxpiHZ6FMfvJwhJs8TCI6w== X-Received: by 2002:adf:e684:0:b0:45e:f31a:7ae6 with SMTP id ffacd0b85a97d-45ef6b8aadbmr345907f8f.30.1780068136717; Fri, 29 May 2026 08:22:16 -0700 (PDT) X-Received: by 2002:adf:e684:0:b0:45e:f31a:7ae6 with SMTP id ffacd0b85a97d-45ef6b8aadbmr345803f8f.30.1780068136163; Fri, 29 May 2026 08:22:16 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34b7d6bsm4708531f8f.10.2026.05.29.08.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:22:15 -0700 (PDT) Date: Fri, 29 May 2026 11:22:11 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "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 , Naoya Horiguchi Subject: [PATCH v9 02/37] mm: memory-failure: serialize TestSetPageHWPoison with zone->lock Message-ID: <2c527d20c99cdfe64a77bcf8da75f742d4c6991e.1780067977.git.mst@redhat.com> 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: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/memory-failure.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ee42d4361309..d106f2c135c7 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,10 @@ int memory_failure(unsigned long pfn, int flags) if (hugetlb) goto unlock_mutex; + 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 +2404,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 +2426,9 @@ int memory_failure(unsigned long pfn, int flags) } else { /* We lost the race, try again */ if (retry) { + spin_lock_irqsave(&zone->lock, mf_flags); ClearPageHWPoison(p); + spin_unlock_irqrestore(&zone->lock, mf_flags); retry = false; goto try_again; } -- MST