Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.38 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796534396; b=oH+t+FQMnBboyI2FVZ/h1e7SkHg8y9gVn0i4zJmIw7lFX5cxzM0KaM2mrgci/65l9FDQ Ahn2zJb9W5xfLyZZoizLGhWlkZNVU7IMIZdsi2qLL+JgKtCQlsPedjsl7IPmZABOJ0p5u b9E26Y8FdT3ZlUa0YK0p7lNzwALBwn1yclaz5HdIZI92XoS+5d5w5LuFlOKdsy0Rs7XzZ 7nmAjJViHsRzgjWxwA9d1GlJtszsMo5lH20Rmswc1hEAbZyA5Jz95HLhVipXLeyXPLrjQ iMSw7HdPvWgE1BV03gHoPcm4A5MeOpS5DNTkEwUFjtTB3wxgX3g0VjY19VGSB12N8uA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796534396; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=z2n8bisgUHpbE07sJiM4cSEvDstxhCkwM0pC0+2/IzY=; b=g9PEVD0pM4KHKk2vDhjjxAegUMg+S33n8BVIiEmb+ok11+LU4nyjegNNv1vpImrQ1dGk MJuBDL1ZVaiMsXA228GWU5qr+Uy4PuN22980N32J88kZiQg8+0VbZDBrtZ1L3q5qHqdNA Lw25MOprsDTYFy9kLeAtpXleWdInhriCH4/5GYqVhTU/TLQOhDoNXtsls8brLCCi69Wmx 7HRBIEsVJ5CADRzhfrJZiqSmAp4dKegcEGweCNmn5ojYautY3vqnVc8ELa4Yzfk6Hzopz x7F+Zlbne8UULEKGUfjyLs9xwMX4Bgg4RDgyeRbf0D+E+cTKfLt7h8FwEQ0tEL/me+A== 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=nJMlnknw; arc=none smtp.remote-ip=91.218.175.38 Received: from mta0.migadu.com (out-38.mta0.migadu.com [91.218.175.38]) (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 D21AA606A31F for ; Sun, 6 Dec 2026 05:19:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D21AA606A31F 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=nJMlnknw X-Envelope-To: stable@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=1NAwP1qrqlPkx8jMlAvAm3yuu86n2mYtE69rDssvJ0o=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796534391; v=1; x=1797139191; b=nJMlnknwg6acYa4R1hOBwby2ydS4z3d2wtALyY0nm3exarBkxRiM5x5fmAqwhgBt4rcO4fQn 0yVo2zOR5tOt69lN+kPYb9RPnPZUnD5s6F1MhiPmkK2Gaoe/N1Rs7iCAh2DMRkfDdw+5Ym1loaF bFfdzdBnnA5Kml2NUnlKS/XY= X-Envelope-To: stable@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 79b1d70ccccfb465; Sun, 06 Dec 2026 05:19:51 +0000 X-Mizu-Trace-ID: 79b1d70ccccfb465 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v3] mm/memory-failure: fix races when handling free HugeTLB folios From: Muchun Song In-Reply-To: <20261205191252.7d9d0b3b2d15b00cef8aefe0@linux-foundation.org> Date: Sun, 6 Dec 2026 13:19:35 +0800 Cc: Muchun Song , Muchun Song , Oscar Salvador , Miaohe Lin , Mike Rapoport , David Hildenbrand , Naoya Horiguchi , Joao Martins , linux-mm@kvack.org, stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <689A1C20-5A59-43B2-97AD-3A66226A30F6@linux.dev> References: <20261205121205.83068-1-songmuchun@bytedance.com> <20261205173355.b23201f43437ce8a182a7d27@linux-foundation.org> <20261205191252.7d9d0b3b2d15b00cef8aefe0@linux-foundation.org> To: Andrew Morton X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Dec 6, 2026, at 11:12, Andrew Morton = wrote: >=20 > On Sun, 6 Dec 2026 10:26:05 +0800 Muchun Song = wrote: >=20 >>=20 >>=20 >> LGTM. But some nits bellow. >>=20 >> Acked-by: Muchun Song (ByteDance) >=20 > Thanks. >=20 >>=20 >> I think these comments were generated by AI, so they're not very = concise. I feel >> we should rewrite them. >>=20 >> This information is suitable for commit message, but it seems a bit = too clunky >> to put directly in the code. >=20 > ok. >=20 >>> + * Context: The caller holds mf_mutex, and either a reference on = @folio or >>> + * hugetlb_lock. >>=20 >> We usually use lock-assert. We only use comments when the code can't = express it. >=20 > yup. >=20 > From: Andrew Morton > Subject: mm/memory-failure: don't leave a filtered HugeTLB page = poisoned > Date: Sat, 05 Dec 2026 14:50:00 -0800 >=20 > When hwpoison_filter() rejects an error in a HugeTLB page, > memory_failure() returns -EOPNOTSUPP but leaves the page marked as > poisoned. >=20 > The filter rejects a page when a tester has used the hwpoison-inject > module's corrupt-filter-* debugfs files to limit a memory failure test = to > one filesystem, one memcg or pages with certain flags, and the page is = not > one of those. Nothing else registers a filter, so only such tests are > affected. Found by reading the code. >=20 > Depending on where the error was, the folio stays poisoned, or a tail = page > still has PG_hwpoison set when the folio is later freed to the page > allocator. free_pages_prepare() only refuses a PG_hwpoison page at = order > 0, so that page goes onto the free lists. When it is later allocated, = a > kernel with page checking enabled (CONFIG_DEBUG_VM, init_on_alloc, > init_on_free) quietly discards the allocated block and retries, so the > memory is lost. Other kernels hand the page out with PG_hwpoison set. >=20 > The filter paths undo hugetlb_update_hwpoison() with > folio_clear_hugetlb_hwpoison(). That function is for a folio which is > being freed to the page allocator: it moves PG_hwpoison to the raw = error > pages, and it does nothing if the folio's vmemmap is optimized or > HPG_raw_hwp_unreliable is set. Add hugetlb_undo_hwpoison(), which = removes > what hugetlb_update_hwpoison() added, and use it at both places. >=20 > A/B testing result: the same hwpoison filter rejected injections into = four > distinct HugeTLB folios on adjacent A and B kernels. On A, injections > into the head of both a free and a mapped folio left KPF_HWPOISON set. = On > B, the head flag was clear after those injections. Tail injections = did > not leave the head flag set on A, so the observed A failure concerns = the > head cases. >=20 > Fixes: 161df60e9e89 ("mm, hwpoison, hugetlb: support saving mechanism = of raw error pages") > Signed-off-by: Andrew Morton > Acked-by: Muchun Song (ByteDance) > Cc: Miaohe Lin > Cc: Naoya Horiguchi > Cc: Oscar Salvador > Cc: David Hildenbrand LGTM. Thanks.