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 8D40C3B14B8 for ; Mon, 8 Jun 2026 08:34:43 +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=1780907688; cv=none; b=bayFQjU2hcUZZ1XD9IDnpDgwVPNPC0X2qd9wBXr+upSeTB5iwvfMEkxTkRrzX5spIDcJAhRLa/1XzEtOHPUCQRJMgxk/++VBcrzcwdifG6tWtWvH0Ep/sLlWFG+0smmsfmxUTHZj4vS0oG0+3KB0mAumkIOhLtaeOodrjM2dER4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907688; c=relaxed/simple; bh=lgTFAAybKpw8Lv7QpTHpNFrj++hl60eW9AsRt64i/XU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=StF3/i7dhcO1gVcIB5Z+QIxIqfHWYceNuYQ2MlZgL9acK8FJVR8iEVY6E3SVK2c1QB/H5GVzczv/my8321975OytUIK+lPepRT9Ja3XbfjV8Xv6jylUiJrkSurZrvbctbB0wk06H1oztfmnze+HLy7c2pGLi0UZI1Dg2Pll8lvg= 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=jAWWEee+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rdEO8HWN; 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="jAWWEee+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rdEO8HWN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907682; 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=NUdBC37dWtUhtr3poKTRLbvv+0k/F3lQxPVXzGOdb1o=; b=jAWWEee+7tFInba1r5hF5OKU0EepwJpjJLcF+GGPX5njoWRYjSbaesl5CKyueLL0rgNLCK t6JancLe4Kkj9eXujurciXEWtAnuhQ1KfQkaslsIxC4XWyMErZ512tJhZzwm0XIt1yUMVf Ei4GjXmq0nobvareNynCKIWyZFKSHtc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-7p0B6uTiOc6TO2pDmsGHtw-1; Mon, 08 Jun 2026 04:34:41 -0400 X-MC-Unique: 7p0B6uTiOc6TO2pDmsGHtw-1 X-Mimecast-MFC-AGG-ID: 7p0B6uTiOc6TO2pDmsGHtw_1780907680 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-45efa2f7009so2516387f8f.3 for ; Mon, 08 Jun 2026 01:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907680; x=1781512480; 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=NUdBC37dWtUhtr3poKTRLbvv+0k/F3lQxPVXzGOdb1o=; b=rdEO8HWNFGyjyaLic7fZxa9O1MBGjkXyfukFzmEbQelHaMRJ4/EN8pmndsR11bNXtb daP/UaOr+HucqpBa/ySrfQSXa3sLbzvvvRx/KY2Qzv751DLrhTLkld6mZvM8m4FhyH2Z BXRV1AtGtEe9jO03h2spPf6oDZ85S0ZpvnhqSQDNvOhgif/EaSAMPxupkdp4Ga8bbCix SuuM00XsPD+s003P3VuldR9xjSJ6bI0xkZ7zxehEBbKs5klZ8DjBIRd1xjKMtAghlXrC zNXuQUpi9a4fSgvCcv8zwIZ4DYpXB2TGh3zeX9zBtXRhMx1M+UdJW60sRC/2EgxPQO28 PcdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907680; x=1781512480; 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=NUdBC37dWtUhtr3poKTRLbvv+0k/F3lQxPVXzGOdb1o=; b=tJ5Ua4PZcmMWpdf6uewrNR8xZN4I+FgcCUj4/DPpBPkT6/JBhwQrRqL98sfL69yFyf L0fHvRI+jCIJqRdsoQ0LHnHS3/isNXCKClIRKL91N/6iDu8wqUdc61BQcJPdGGwHrzAL 9EqWqjWKL1Au7CYufd4fGvVy2KKwOoBKJ+gn/qzHAtavvj7O/L9Gw2vOgYsAXKFqTENe R2737fLuGqQVyGXUNlUel/Tr3EB96Sx+uFgrWLb1PLqgfOdipqjgpr4Sqk7laKEFvCm0 yotp89e6jMocZFd5Nb1TX3FKqRu47JetV2i88b9j0p/oG/k8jgOuj3VYmWcaPXS6VM37 czLw== X-Gm-Message-State: AOJu0YwcZTr7YiBR/yZfoECAbCoqg8cHXeBM2KWZs6Wn/w2U5oxsaRR4 qrgGub9ANk1PiCIi9bg4J70YJJS4cqc9+7Aa84lnfkFMm2z0v8+M0nEi/XuJmfcwU0lp7wZiZcm MOKzAZ5n2BHaTdWToTSDx+UobsAeteZx0MEh44qJZkqXMa6MHGsrjkB9wbut0Oo/m4GRjIzp0eh FjveqZ/6pJnbKoA4W0igVTRDXcw8BRilfja5sVEa+vN6U= X-Gm-Gg: Acq92OEgqJxuDS6K/fuVsNgaBEw3y4eY2RKDLiy2B+S+lIIqtdYWLpdK+51N09goX0k mMNRoVQqEeGoseswT1D9l3kv0FHMqCDyGGHW+nvnNdsorMNVvFXeqJC/QFKJ3ORVwf34qP5o3Ru M1ckZvFz0rL9WiFHUnlIp77RQ0v5jvO/+7JYVJcbHi4vkdz3brR2739hYTK/zSdeuSPsfgN7/Ku YIcOZt99/XDCm6IEfV2TyfW0BEkVhnOA20IZsRImkgLUXt3Tfq6dHZK4nSP++WzsUMkvGnCxx12 OYsGm/rmgCenuOkjugkgOSfqN91zqIa2eDkk/0HZHDsHG0SBk/GefNLuBdHXUPxqrqTJ5RF9yKf u2VK/BF2STojiyoVuxqfN+fs= X-Received: by 2002:a05:600c:154d:b0:490:44eb:c1ec with SMTP id 5b1f17b1804b1-490c260f3cdmr236254925e9.27.1780907679688; Mon, 08 Jun 2026 01:34:39 -0700 (PDT) X-Received: by 2002:a05:600c:154d:b0:490:44eb:c1ec with SMTP id 5b1f17b1804b1-490c260f3cdmr236253855e9.27.1780907679052; Mon, 08 Jun 2026 01:34:39 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3d6c65sm366951975e9.12.2026.06.08.01.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:34:38 -0700 (PDT) Date: Mon, 8 Jun 2026 04:34:23 -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 Subject: [PATCH v10 02/37] mm: memory-failure: serialize TestSetPageHWPoison with zone->lock Message-ID: 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.51.2.2891.g4157995a80.dirty 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. Acked-by: Miaohe Lin Signed-off-by: Michael S. Tsirkin 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