From nobody Fri Sep 25 01:20:29 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A0183B27CE for ; Thu, 17 Sep 2026 20:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677915; cv=none; b=nhjtB0Ri6mtRSDyxg5qIkp8Fg3Z3xfVqJpIhKJVLVm2p2Teh2T1kSdkV0N9k9Fxpqn1GiBFfXIa8tFibeqfmJYODDkAOZPhFhqyLIH57ZmxXO1COcgiLW3s1a8qHADsH9uvXWWoz4ynz9F4YC/FG+RlWrCMjEr82mqPt95ZXBfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677915; c=relaxed/simple; bh=VByVeEjI4LUQrNUSvfcdQ/qkaw2W/Fj0TZtQKNhauZ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HWEUpN95wJIeZy8gpEXFIXvnuKFGgdqV/ZnjNUuDwYyQmrR+4/UgBWXp03EHE1f9bQyymPTVdXW7betKvnM6bucYnzLqQX0YWRTGkE4B2YKAU+E40lBcK43FdfH9ItjhBnVcRde3rrGCFJjlVCVoe0swIvt32cuPcLmttb1UQyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MRqonI+n; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MRqonI+n" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-39de1f85cb2so110305a91.0 for ; Thu, 17 Sep 2026 13:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789677909; x=1790282709; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JxlCNYOwsW45BnQIn3JTG+O/SEl/6G4eXS+I5oaCDnU=; b=MRqonI+nHeywoLMhrBjnzBL3OVdhM5yIzLFh7gn568V6uex2cDxSGywudR31v3ApUG Vcr6lmKCoHul00MV+iRxo8IhueDX4NjW428DUTv+VsqhA7W9/tr/9N0XpWQ/JXrdoehP boEswlQrPr5jdhI+h/c/Jzq7/BjU1cxex2I4l+RsBXO3kg7zQxYNtBczOZB7vKB5t6/f 2Ba+U6rup/kxnLQPDzPl50OGsn1OJq/2XbFfnXyGyIiwJTSUTWICFH4s2i2nUlqr+9EG d/+TcmzJl/U0JA1ifPAXhiLDdF3ZfyT+ZJIFlYffTuKZkTu0+zzsY49+4ZVdwhgupqzS z7JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789677909; x=1790282709; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JxlCNYOwsW45BnQIn3JTG+O/SEl/6G4eXS+I5oaCDnU=; b=2OE5fODDxe3Fu54KNFB6w1SgoaFXgv00S7zQDgICbPwTsUhpzqTducJIaGGTkkzYGP CjJzDQRhlLOckRs47an0PzU266sMX2/EOfCguy55ssTSzLOaOSQ5h9WcKF6E/JMzxDds j3riArnf4GbAI2ZAtpYsksCHq3q+rP/42usgxX4DwFar+mVSE4TsvxqwAgLd4/OmZvXb TKFs+M4kdWhyb78WnDDHI6HSbvNd46T+2kT30PXN3M+F1TotA5l0wt1cavvEHKm+G3HX rUsjmAT+NDfDBb5ZRRsgPdcGBN/3piCtGtrpr2AlraqpO2zqdnMvBhjfTYN+eL6n77LO MOsw== X-Forwarded-Encrypted: i=1; AKwUvBwTCFNngpkB3rDJyQSJID/wDk+QL9LsDBmA0iM80ytIwxIZq2VptxN6MZWMM8kbY2PfACpqgzmO0Sa+6/c=@vger.kernel.org X-Gm-Message-State: AFuF++l2apV9ioC5Ys3kQyhzcYViNVUKkJKX+9L1K52qvvIHcFf+YhGT v5Y2r4NDSZs1qMthQ2aX3jZ0rLO4iTESbAmJT0tqn6rLGaUXY3QzurJuzTU9frqFXoSqe27/H3r ptPK7Dw== X-Received: from pjyd8.prod.google.com ([2002:a17:90a:dfc8:b0:39e:4bdd:a2c8]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d8b:b0:39e:410b:bec4 with SMTP id 98e67ed59e1d1-39e54dca306mr707986a91.11.1789677908717; Thu, 17 Sep 2026 13:45:08 -0700 (PDT) Date: Thu, 17 Sep 2026 20:43:47 +0000 In-Reply-To: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1789677906; l=2541; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=VByVeEjI4LUQrNUSvfcdQ/qkaw2W/Fj0TZtQKNhauZ4=; b=26Q9nOB/cKS3IbZahb3B67Qv7bStXKlTukEhrVZ3ZTwAxnSeS1vUPLqyUMVeJYRB0EYtlJR7z gJoC/MAIdDNALDdHkcigEox0KlId9ndvnjep7WAdkFOdJ368ZU4Ehy+ X-Mailer: b4 0.14.3 Message-ID: <20260917-memory-failure-mf-delayed-fix-v6-1-4b00856b5364@google.com> Subject: [PATCH v6 1/5] mm: memory_failure: Clarify the MF_DELAYED definition From: Lisa Wang To: Miaohe Lin , Naoya Horiguchi , Andrew Morton , Paolo Bonzini , Shuah Khan , Hugh Dickins , Baolin Wang , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andi Kleen , Hidehiro Kawai , Rik van Riel , Yu Zhang , Lorenzo Stoakes , "Liam R. Howlett" Cc: rientjes@google.com, seanjc@google.com, ackerleytng@google.com, vannapurve@google.com, michael.roth@amd.com, jiaqiyan@google.com, tabba@google.com, dave.hansen@linux.intel.com, Lisa Wang , Isaku Yamahata , Xiaoyao Li Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch clarifies the definition of MF_DELAYED to represent cases where a folio's removal is initiated but not immediately completed (e.g., due to remaining metadata references). Acked-by: David Hildenbrand (Arm) Acked-by: Miaohe Lin Reviewed-by: Ackerley Tng Signed-off-by: Lisa Wang --- mm/memory-failure.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index aaf14608b30e..e698d0e9711d 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -847,24 +847,25 @@ static int kill_accessing_process(struct task_struct = *p, unsigned long pfn, } =20 /* - * MF_IGNORED - The m-f() handler marks the page as PG_hwpoisoned'ed. + * MF_IGNORED - The m-f() handler marks the page as PG_hwpoison'ed. * But it could not do more to isolate the page from being accessed again, * nor does it kill the process. This is extremely rare and one of the * potential causes is that the page state has been changed due to * underlying race condition. This is the most severe outcomes. * - * MF_FAILED - The m-f() handler marks the page as PG_hwpoisoned'ed. + * MF_FAILED - The m-f() handler marks the page as PG_hwpoison'ed. * It should have killed the process, but it can't isolate the page, * due to conditions such as extra pin, unmap failure, etc. Accessing * the page again may trigger another MCE and the process will be killed * by the m-f() handler immediately. * - * MF_DELAYED - The m-f() handler marks the page as PG_hwpoisoned'ed. - * The page is unmapped, and is removed from the LRU or file mapping. - * An attempt to access the page again will trigger page fault and the - * PF handler will kill the process. + * MF_DELAYED - The m-f() handler marks the page as PG_hwpoison'ed. + * It means the page was unmapped and partially isolated (e.g. removed from + * file mapping or the LRU) but full cleanup is deferred (e.g. the metadata + * for the memory, as in struct page/folio, is still referenced). Any + * further access to the page will result in the process being killed. * - * MF_RECOVERED - The m-f() handler marks the page as PG_hwpoisoned'ed. + * MF_RECOVERED - The m-f() handler marks the page as PG_hwpoison'ed. * The page has been completely isolated, that is, unmapped, taken out of * the buddy system, or hole-punched out of the file mapping. */ --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 01:20:29 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 578B637E2FE for ; Thu, 17 Sep 2026 20:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677913; cv=none; b=NthlaRTrfMNTaTREK7ZT1WuSHoL+3Y7r7/FrYVU7X5PV58bBeVulCUQ8Yoi+4vSxE60b4bwkkcniA3olcwCLQzLVbwOj/G5oUqbDA82h3y88T2Mi9CW/TZ6k33oXwbA80Bq/3pGo0ULtTMCYx4hIUmzTLtXtRcX8P0I4cKQO4qI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677913; c=relaxed/simple; bh=AkbxLkF/+nAmGEf9KgEr5gQ3H9mZvwt0D27L0+zaegU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jVGYDn01tjaEqPyPADbvu0cZQ27T0MUlwFHJi35YQXG39NIjf1XbbTE+VInc6ze6LQEC+5qmSXss2Pl11RdzSz5eXzrFJ4x6H800W87/jSIsA8EyD5CEIjhaaCE2WjT+3mg61oJXa1o+SCBAICLKy7JvSNJk1FPq79frE3klcs8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LB/joyzB; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LB/joyzB" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-39d8646b10eso65527a91.1 for ; Thu, 17 Sep 2026 13:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789677910; x=1790282710; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Hoad39omJnatpjgiztoN01A08gT8UYIlksvJjwoC6QM=; b=LB/joyzBePGiI7tkKSlYZq3igeTLEQwIbfTTi2+2c68POih/95MDqqrFzGtH+O2TRy tDwqb7E1Lv2aqNebtuRG8xiWsyM3LXQn7TlpCJKJfl6hJMFf2uNMqnwwCDgL/fH8KkBv QdK9wRQNf+3xYNa2cqFHYJxm5me5QmFq74w6Wg5jyE6JPuBAbH94n4JXyar9eRbhZzTL h7KqJSV8A+cLL7Z66qx4nyJId1AB+bXC9WBkuiXwzYyE8QVkyWgI0z5X1D9QVnBzySdW zwoal8jyv/sofhyxgLjMqHEpM/5pkGjmpg2CZatAqkSZmHx0Zrolr+FoVKpnku+TkDT0 VZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789677910; x=1790282710; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Hoad39omJnatpjgiztoN01A08gT8UYIlksvJjwoC6QM=; b=tXdrJ004dYRuPYxr0McVbmGvD7UeRD2jlq3CSdxCGdInpMhNVkNeEoj53GS9bl8J18 6ncqG/a3u0V/hIorhY3wB9wg3TnySbk/CdZ36ni6zJJYJ2U7G7Qga9he9S9UWPs7xB+r l1Is3eXF7tTFJIc/94rhJuQt7+WxqjllWpFq4AnUMGahucNd0fBNPM7oIQ0EP7WFs6l/ 6y0YtlOg64iPi7updcUHJaHF1pj+OGeYfuq/UteFI4ejzO9bGNMtUrsMDe59TKt7MkjD /lwPz9lHC7eBjbP3mK1vG/oJ9JYs7oLP6A3CQP7Z+mZXuuYFYOlLknzjILR9nhltLpqC BaRg== X-Forwarded-Encrypted: i=1; AKwUvBz5GuE8NH+Wi+4hlj92Yz/HPnsbzl+tyo2wFxw1GME1HDaM8Q1odHsMUnQjES01W1//FPLGTQj687Lq5w4=@vger.kernel.org X-Gm-Message-State: AFuF++nwg0GMTJigl7ad90TROdMa1diia0jtER5FscGH11sgPEz3N3lV 85jHZRzygeC7A31bGFdsePR9Sg4YrpsXIf0+HPTqcL1TB7hnFhTw/hDLP1fsqenj08FszyLrCQN JKLkhlQ== X-Received: from pjbei24.prod.google.com ([2002:a17:90a:e558:b0:39e:ac:d0a2]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:224c:b0:39d:f317:44cd with SMTP id 98e67ed59e1d1-39e54eab3dbmr1101051a91.14.1789677909569; Thu, 17 Sep 2026 13:45:09 -0700 (PDT) Date: Thu, 17 Sep 2026 20:43:48 +0000 In-Reply-To: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1789677906; l=2010; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=AkbxLkF/+nAmGEf9KgEr5gQ3H9mZvwt0D27L0+zaegU=; b=l43vikXXPWbiYd0vKIvQqVDarn1Ty3l6Vrm71axmlmmBFUC/OJBsLcDslWeQrnqbkktxP00pO rxclAE9wwFRBWLRaf58fDlGZj9/LGabzo7cne5Pv9ImCfAttWfE42ZJ X-Mailer: b4 0.14.3 Message-ID: <20260917-memory-failure-mf-delayed-fix-v6-2-4b00856b5364@google.com> Subject: [PATCH v6 2/5] mm: memory_failure: Allow truncate_error_folio to return MF_DELAYED From: Lisa Wang To: Miaohe Lin , Naoya Horiguchi , Andrew Morton , Paolo Bonzini , Shuah Khan , Hugh Dickins , Baolin Wang , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andi Kleen , Hidehiro Kawai , Rik van Riel , Yu Zhang , Lorenzo Stoakes , "Liam R. Howlett" Cc: rientjes@google.com, seanjc@google.com, ackerleytng@google.com, vannapurve@google.com, michael.roth@amd.com, jiaqiyan@google.com, tabba@google.com, dave.hansen@linux.intel.com, Lisa Wang , Isaku Yamahata , Xiaoyao Li Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The .error_remove_folio a_ops is used by different filesystems to handle folio truncation upon discovery of a memory failure in the memory associated with the given folio. Currently, MF_DELAYED is treated as an error, causing "Failed to punch page" to be written to the console. MF_DELAYED is then relayed to the caller of truncate_error_folio() as MF_FAILED. This further causes memory_failure() to return -EBUSY, which then always causes a SIGBUS. This is also implies that regardless of whether the thread's memory corruption kill policy is PR_MCE_KILL_EARLY or PR_MCE_KILL_LATE, a memory failure with MF_DELAYED will always cause a SIGBUS. Update truncate_error_folio() to return MF_DELAYED to the caller if the .error_remove_folio() callback reports MF_DELAYED. Acked-by: David Hildenbrand (Arm) Acked-by: Miaohe Lin Reviewed-by: Ackerley Tng Fixes: 6a46079cf57a ("HWPOISON: The high level memory error handler in the = VM v7") Fixes: a7800aa80ea4 ("KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-spe= cific backing memory") Signed-off-by: Lisa Wang --- mm/memory-failure.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e698d0e9711d..37ea23489b75 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -939,10 +939,12 @@ static int truncate_error_folio(struct folio *folio, = unsigned long pfn, if (mapping->a_ops->error_remove_folio) { int err =3D mapping->a_ops->error_remove_folio(mapping, folio); =20 - if (err !=3D 0) + if (err =3D=3D MF_DELAYED) + ret =3D err; + else if (err !=3D 0) pr_info("%#lx: Failed to punch page: %d\n", pfn, err); else if (!filemap_release_folio(folio, GFP_NOIO)) - pr_info("%#lx: failed to release buffers\n", pfn); + pr_info("%#lx: Failed to release buffers\n", pfn); else ret =3D MF_RECOVERED; } else { --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 01:20:29 2026 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4875C4E9C30 for ; Thu, 17 Sep 2026 20:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677915; cv=none; b=E9WBMxMBM4aDMhwv1QwDozThLoPp0ilO8uMX1jFScFo2DBrC4wsBHqJqv6qQzZIfAZdsoNvkmcVoX7FgF7/QrDZyh7GQg/1nBB4ZSm86+s8189VvesuTKVHjtR7EO+uqBJuKvq1V5xPmm6YEnN59VoRxnipxrA+yCENFyfKfsZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677915; c=relaxed/simple; bh=3xlog7W6+Eb7uaognsijeu++wSjtW/1ijfNh02cWLeM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FaUA/xNpUGoX4JpQKxTQxCpXUj9hDZ96CEJPJslHDR4xSfhT0DLderQFQ4DSrUYhEYAvO0G7/yU4Ez3YdnbbFAyyEGifwmyy4/fTGnVqlAM9nwTKYEt72g+YDop0HoUQl8jBRYNZFsRD5xB8W/ekSnJ5Ss2JMSXxKoXZzHwx2CM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=clTozH0R; arc=none smtp.client-ip=209.85.214.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="clTozH0R" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2dc7337e2a7so890355ad.0 for ; Thu, 17 Sep 2026 13:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789677910; x=1790282710; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FWbGWX7ba0RN8OdLexXyHstVRWEHpkbx670qUQ+b2/Y=; b=clTozH0RI9OcJ4tb1hTm8y7J/empplmvyXkRqHdJCGnpSRUpwxTWaXjMTkyrAShSUn PGQOzurkMXCH305nqeQnbXgsWPHY72IkU+v1sL0//WK4hmhI8XVGZ9RtqgTpYW8p7nOX BO7vJOGu92o7G3AZXzZynvrpF787UVtbk3t/9pbGnANMShdrLnuerB02/x5mqdPiT93P 0lJKt9gJ4dUQo0XZGl6G2mWTJdoJckeaJb2AcTqam/ZmtvbOIXhgQgp6fzE3cj1F1laX JnDgg1nsbiN6XX5b6fWb7Qe/wUrtJ6dCdO8Ww2cvZhF4cQ7TZjUE/TcudC+XaRSkVD8a kTyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789677910; x=1790282710; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FWbGWX7ba0RN8OdLexXyHstVRWEHpkbx670qUQ+b2/Y=; b=MegE7XDRbWnAvK/cX8t6dT1eZlwuIQ30kQ+BgXcBSnGnBYnrm4g0wlLN3UvjLgd/S6 SRSSs3ZTXklT9TUA94C9hXrCPbTlgz4wWLhf4JwJSKrcJfCdl30YyScRC1Ua/SZHgUU1 QMQB0evbn6U/uZI8Z0sHhP5KqeUYXmsvdg62PhqIOS6/tMoiaA0hFYkE/8q8AXTG+YoW 4g76y6KpM6KPCeYpMt2fG0njSE94od6kny10jeKFbtXmkWCKK8780qw7vjaJKwtavfPC cltx2vi0uLm8i8KXhm4YjrH77F6Mgi4PsRj9X57ySmb+w/28KIuQU3g69VrJ9NmNcTYs Ktyw== X-Forwarded-Encrypted: i=1; AKwUvBwIznL+sLPL5W3o+IeedvfI4icQOmt9ZipPJMRzqmcMFf/GbnmqZw+YeNYHRJLXHluVL2gyTC5fxIDFjJI=@vger.kernel.org X-Gm-Message-State: AFuF++kKZ/4bYqqij4E/IwiWJYQ0GRbbdpLBa3ke3DPjeHfNuqN30tHp C9JxMXoGWd4zMEy166Wykni4u3ScMxOWxRC5FPOoAfYTLOvuyDx4V5lVzZElAV1K6MjsQVrqYi3 8Tm/Gsg== X-Received: from plml16.prod.google.com ([2002:a17:903:1850:b0:2db:78a3:f716]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:32c6:b0:2dd:ad74:ac29 with SMTP id d9443c01a7336-2ddb1bae2b9mr6705575ad.27.1789677910414; Thu, 17 Sep 2026 13:45:10 -0700 (PDT) Date: Thu, 17 Sep 2026 20:43:49 +0000 In-Reply-To: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1789677906; l=1749; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=3xlog7W6+Eb7uaognsijeu++wSjtW/1ijfNh02cWLeM=; b=mnhxUqOuObNj+R5apFx/dutD/hRRG/ythFNvIOI5goZLBTNWbCm8BcyPLsM2Vszxyyckiwnet SZYrzREtHi+DHtWpEun46A6CGi7NLx95gjCXlHx8OcmRZ0VdUKFkwcO X-Mailer: b4 0.14.3 Message-ID: <20260917-memory-failure-mf-delayed-fix-v6-3-4b00856b5364@google.com> Subject: [PATCH v6 3/5] mm: shmem: Update shmem handler to the MF_DELAYED definition From: Lisa Wang To: Miaohe Lin , Naoya Horiguchi , Andrew Morton , Paolo Bonzini , Shuah Khan , Hugh Dickins , Baolin Wang , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andi Kleen , Hidehiro Kawai , Rik van Riel , Yu Zhang , Lorenzo Stoakes , "Liam R. Howlett" Cc: rientjes@google.com, seanjc@google.com, ackerleytng@google.com, vannapurve@google.com, michael.roth@amd.com, jiaqiyan@google.com, tabba@google.com, dave.hansen@linux.intel.com, Lisa Wang , Isaku Yamahata , Xiaoyao Li Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To align with the definition of MF_DELAYED, update shmem_error_remove_folio() to return MF_DELAYED. shmem handles memory failures but defers the actual file truncation. The function's return value should therefore be MF_DELAYED to accurately reflect the state. Currently, this logical error does not cause a bug, because: - For shmem folios, folio->private is not set. - As a result, filemap_release_folio() is a no-op and returns true. - This, in turn, causes truncate_error_folio() to incorrectly return MF_RECOVERED. - The caller then treats MF_RECOVERED as a success condition, masking the issue. The previous patch relays MF_DELAYED to the caller of truncate_error_folio() before any logging, so returning MF_DELAYED from shmem_error_remove_folio() will retain the original behavior of not adding any logs. The return value of truncate_error_folio() is consumed in action_result(), which treats MF_DELAYED the same way as MF_RECOVERED, hence action_result() also returns the same thing after this change. Acked-by: David Hildenbrand (Arm) Acked-by: Miaohe Lin Reviewed-by: Ackerley Tng Signed-off-by: Lisa Wang --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 774f4b18ff5c..d6f94786e709 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5136,7 +5136,7 @@ static void __init shmem_destroy_inodecache(void) static int shmem_error_remove_folio(struct address_space *mapping, struct folio *folio) { - return 0; + return MF_DELAYED; } =20 static const struct address_space_operations shmem_aops =3D { --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 01:20:29 2026 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BCD84B7A24 for ; Thu, 17 Sep 2026 20:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677916; cv=none; b=DD7T4qkQl906cIQJB1QCHCQtH6+SYmfAAwyLTv42LPx357FxlnBTClpORb1thyS0WRve4JQNchRmYJnIKlYdRiIHIUhKIACZTsw5lztBDJRusDgiAgfuF3pdzEklKCZKhGustxMZ92kAV7er8/pFcbgOe2/z+veolJiPf2bk4I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677916; c=relaxed/simple; bh=y+kljbprzv16FEW0R5LMRlVvQbhp1uI0L+ucmxjcblI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gFjtQVEqfwlD8DP1FjqpSzceJFD70fIzJg7qS6pUgoxwT6Xbtkjq/G2QaCDg5u4vCgo+vSN7K62qGy654siGh/7JSQk+F6Wsly9VCnLeN+QsJKk6eo1LD6L27ibtn5KIbRVTo8eWYrLtwjJWoTm5kPoPtSVZTIFQQZOnhdqCylk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YMl2ghSw; arc=none smtp.client-ip=209.85.215.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YMl2ghSw" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cc4c1fc9ceaso1064692a12.3 for ; Thu, 17 Sep 2026 13:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789677911; x=1790282711; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kGFXLYLaJ+InCA49wUVYw7NUJomlNkAd8fgmCjgGvRw=; b=YMl2ghSwaOA4xL0aTxd1LZunMvWLWGqI6CICXrrkbfw6/t2vmnR0lRoSKEIeSR55kI k6gg6+TxBLtlX12bxWuO/JaUmnQ8kRvAbojANjoLkoEegz0NBa1jUI2Wunn0f2yF1dnO uLLjuBfNmygxJBe0KIVbOtQJxPyE/tMRUQQdxTXlxixAm9eVPvWsktwXf0c1Wt0cALj9 Fs6xe2/99xkxO+1BfbMUfIdfgyYbE0R7+1akl6Hzw0ZesGVYodPU4s424SFcphK6GUJU D04lTvXRWVLg4WnEfa0Guvcyzg3b4EBFltCTwFENKnFfVBiST23wVvWsi824r9iblR8X UCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789677911; x=1790282711; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kGFXLYLaJ+InCA49wUVYw7NUJomlNkAd8fgmCjgGvRw=; b=yECczW5ihsQNEw0D2YquQrIaj0F7prZa4m89IcB3MP3GjhirkYLGGIJjwqBSWLR+EZ KOZA6+Zi4VSefcj5lUDvTFeqmhOz3ILfXn5+E5IKo3YKpaVMApnzFyQL1+pkxLowQEqR RvU3q0Pb3g+lbOS4uax6Yre7c60NXTYQUvMl+oTbOfOBmpz9ep+7jKgNiQSZIBs9KSZ6 TVmeCPnG8XNh57jLTU9DSradpOE1Q+8zh/2QWZSAznFbjiCiAN2p2hoSBhtAPTDVTqQa cn2yP2KJuJML+DeFaG3S5TXaS2tW9pQG011IwlmfLYnfp5+pRogFiYgpFd8LwPMihm2o gBVQ== X-Forwarded-Encrypted: i=1; AKwUvBx4iWp/Y5AH24NkS1RxsJuKzOTxN0jNhbRClrG/fgxMklGQJjdpoASaJ9vX52Rp6C+sqigDM3jTb2yClWE=@vger.kernel.org X-Gm-Message-State: AFuF++m57L+2fZRlxzaXE1LCPaD81bTuWpVJs2YQ86ceDgE7Td/qZpBb l64XF39a8zQsu5m5JjgxoYCwxU29e4++BD8gxqRFJoi5ZpvTbXfrfUEy8IblwektKz2vfQ8WO3Z iIGsP8w== X-Received: from pgby18-n1.prod.google.com ([2002:a05:6a02:6512:10b0:cc4:b427:4edc]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2586:b0:3dd:85aa:452a with SMTP id adf61e73a8af0-3dd8c53aa87mr322161637.37.1789677911269; Thu, 17 Sep 2026 13:45:11 -0700 (PDT) Date: Thu, 17 Sep 2026 20:43:50 +0000 In-Reply-To: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1789677906; l=1694; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=y+kljbprzv16FEW0R5LMRlVvQbhp1uI0L+ucmxjcblI=; b=dGqQYjedOERCKiCjnJKisYhsTZMBcs8c13M3JPpg6A9i4it98kymjesDKoJjNEGSRfSyI5HCc ODtrd4OL3p8AnfgcbvoGkMFMPXtlua/Nkbp4d/SrhzytfRXP5wu1rg0 X-Mailer: b4 0.14.3 Message-ID: <20260917-memory-failure-mf-delayed-fix-v6-4-4b00856b5364@google.com> Subject: [PATCH v6 4/5] mm: memory_failure: Generalize extra_pins handling to all MF_DELAYED cases From: Lisa Wang To: Miaohe Lin , Naoya Horiguchi , Andrew Morton , Paolo Bonzini , Shuah Khan , Hugh Dickins , Baolin Wang , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andi Kleen , Hidehiro Kawai , Rik van Riel , Yu Zhang , Lorenzo Stoakes , "Liam R. Howlett" Cc: rientjes@google.com, seanjc@google.com, ackerleytng@google.com, vannapurve@google.com, michael.roth@amd.com, jiaqiyan@google.com, tabba@google.com, dave.hansen@linux.intel.com, Lisa Wang , Isaku Yamahata , Xiaoyao Li Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Generalize extra_pins handling to all MF_DELAYED cases not only shmem_mapping. If MF_DELAYED is returned, the filemap continues to hold refcounts on the folio. Hence, take that into account when checking for extra refcounts. As clarified in an earlier patch, a return value of MF_DELAYED implies that the page still has elevated refcounts. Hence, set extra_pins to true if the return value is MF_DELAYED. This is aligned with the implementation in me_swapcache_dirty(), where, if a folio is still in the swap cache, ret is set to MF_DELAYED and extra_pins is set to true. Acked-by: David Hildenbrand (Arm) Acked-by: Miaohe Lin Reviewed-by: Ackerley Tng Signed-off-by: Lisa Wang --- mm/memory-failure.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 37ea23489b75..c7a00c7be368 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1039,18 +1039,14 @@ static int me_pagecache_clean(struct page_state *ps= , struct page *p) goto out; } =20 - /* - * The shmem page is kept in page cache instead of truncating - * so is expected to have an extra refcount after error-handling. - */ - extra_pins =3D shmem_mapping(mapping); - /* * Truncation is a bit tricky. Enable it per file system for now. * * Open: to take i_rwsem or not for this? Right now we don't. */ ret =3D truncate_error_folio(folio, page_to_pfn(p), mapping); + + extra_pins =3D ret =3D=3D MF_DELAYED; if (has_extra_refcount(ps, p, extra_pins)) ret =3D MF_FAILED; =20 --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Fri Sep 25 01:20:29 2026 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 200864ED19A for ; Thu, 17 Sep 2026 20:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677916; cv=none; b=ZgamEQWknSA2Fz2gipd8u8Pn+BLFxx1b9nWPXjcLVlz0V+U+tnlejFKQcXtAUJzhvWCqVPOvZF3vWlLmpeb3PxteMXrXz9e7xQNqH/MbZxqavqCJxU1bQqHa/zlVgKMv9wLCChJ1MNjdOxBIE6A8ruQDzqa5yyV9yJp8PY1kOHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789677916; c=relaxed/simple; bh=oCZbQTSw2Yyl7B5BQDviNb8o0kDmMbfd/szlr3bi9Xc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MUE8I0HYPGHM9ythf3CdHebd/Z8D8AC4Ocv9C5LwK5/xm1hYIs6KuLdR+aI5+7+P7K90cVBXJSO1h/ssjCMVoVzJInSZl09/xA2CEwB+sinzLBPlUGThhCI5lle9/+kE6vnBC7PEhSHsNStL8w33AHAC4E5Nf8lXbClD3Ia8Kbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Bab+nJ/0; arc=none smtp.client-ip=209.85.214.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bab+nJ/0" Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2dc92350888so908705ad.3 for ; Thu, 17 Sep 2026 13:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789677912; x=1790282712; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GhFaT1pWqaSYrZ5igcNnVG6b2J5qZxAlydhAJEnR0ZM=; b=Bab+nJ/0V6jpXMC97e+ZPo3Xllxynjs3pqo0pZPG2wu4/HhmLCvJVTaePNSNCmEb5Y J7bVslQaF3VyYZ0opid7LGYexvYs32CCdHPZ6zfI2RFvK3KnUdqJxUYyrzlLZX+KzMHY 7wES20uOL7attywKQWSMC3WmfGv8qFHFGU0lw8i1FbLYu9u2eokdQ3gRy4WIfvUFVhZf hzdKTUKb0sGV7km2WczuDF2RXxo7qZ7eYPKOFv+B8RE1q+KoZbghpTpn1lt/Zo/1bEOd jmDTBV5wTsmXTy94ULHVjw89nKnT3khP4cb2+ED/7n1wHI1H0bEcXb+mR6VmNWSOqNPW dEbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789677912; x=1790282712; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GhFaT1pWqaSYrZ5igcNnVG6b2J5qZxAlydhAJEnR0ZM=; b=atewFFp8Sm1LDI8eFr3RZGChycLQ9e+ZcYqxEqUmCscn+VL587yjvH6qV0/TTdZYqK Q+PqZVFgiUaqLMUAh+bY3iKrZcX0hR3WBcZMl+qBgEMeKDPVu0lYleQbtvugt1oNKnqp n3uy0eIOgsJ7vHI50O9f6Fi3D+pE7BgaNLzByD7iB3Uwsr7tCYGCCND/AxqevW/qBvRb J4M2HpASUfEM42pY/A8Yeh2fQJaIvdgn5W6ohYLRXHW5YFAwtMV3neV86QFUoeqkvCkg arHX0hTo7WG+yOR7KKP3ssCFV8XuxJRrxWQI0vGgjCyHead2Y0QP/sKsRoxRjq4N13Rt MP0A== X-Forwarded-Encrypted: i=1; AKwUvByxeUimV5SwSMAOQIWu3DoeNsHsfO3hlhMcNMlQfMicUaF60n/h1mOSY4VktOvoW74kOPmMYGZmQ2M3BfI=@vger.kernel.org X-Gm-Message-State: AFuF++kUo2NOksdI+VxOEn2h8nn1QIf3saNKsCuHXSt6Dky0r8X84KtO cLO06ySOMcCr55Vq2I6k0JXg2bIUpCUdwhXqwe4DbQhZMWBKuhvxZ4z3Sq8Na5YxwA1TKBEO2kp mXFMtbg== X-Received: from pjzm16.prod.google.com ([2002:a17:90b:690:b0:39d:9b47:4551]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:224c:b0:39b:61f1:8032 with SMTP id 98e67ed59e1d1-39e54e7c18emr677747a91.16.1789677912150; Thu, 17 Sep 2026 13:45:12 -0700 (PDT) Date: Thu, 17 Sep 2026 20:43:51 +0000 In-Reply-To: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260917-memory-failure-mf-delayed-fix-v6-0-4b00856b5364@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1789677906; l=5191; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=oCZbQTSw2Yyl7B5BQDviNb8o0kDmMbfd/szlr3bi9Xc=; b=2sjWrqtdOcssMiZtTNK//2RmRxIpXb5yhivrXeyIB1v0t2FyBFn36kmbEWN2P8Ax0XR7UqVYg PdjG1ilLGPiDeSDyMaCfp7cPG5UuHvIdRtwg6rJOtaSMWsW7wX2rc6R X-Mailer: b4 0.14.3 Message-ID: <20260917-memory-failure-mf-delayed-fix-v6-5-4b00856b5364@google.com> Subject: [PATCH v6 5/5] mm: selftests: Add shmem into memory failure test From: Lisa Wang To: Miaohe Lin , Naoya Horiguchi , Andrew Morton , Paolo Bonzini , Shuah Khan , Hugh Dickins , Baolin Wang , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Andi Kleen , Hidehiro Kawai , Rik van Riel , Yu Zhang , Lorenzo Stoakes , "Liam R. Howlett" Cc: rientjes@google.com, seanjc@google.com, ackerleytng@google.com, vannapurve@google.com, michael.roth@amd.com, jiaqiyan@google.com, tabba@google.com, dave.hansen@linux.intel.com, Lisa Wang , Isaku Yamahata , Xiaoyao Li Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a shmem memory failure selftest to test the shmem memory failure is correct after modifying shmem return value. Specifically, test the expected behavior under various scenarios combining page dirtiness (dirty vs clean) and failure types (hard vs soft): + Dirty + Hard: Trigger a SIGBUS on injection, and trigger another SIGBUS when reading the page again. + Dirty + Soft: No SIGBUS is triggered, and the original value can be read successfully. + Clean + Hard: No SIGBUS is triggered on injection, but trigger a SIGBUS when trying to read the page again. + Clean + Soft: No SIGBUS is triggered, and the page can be read successfully. Acked-by: Miaohe Lin Signed-off-by: Lisa Wang --- tools/testing/selftests/mm/memory-failure.c | 114 ++++++++++++++++++++++++= +++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/memory-failure.c b/tools/testing/se= lftests/mm/memory-failure.c index 1a5a32e22cce..d5d17a262c00 100644 --- a/tools/testing/selftests/mm/memory-failure.c +++ b/tools/testing/selftests/mm/memory-failure.c @@ -29,9 +29,14 @@ enum result_type { MADV_HARD_ANON, MADV_HARD_CLEAN_PAGECACHE, MADV_HARD_DIRTY_PAGECACHE, + MADV_HARD_CLEAN_SHMEM, + MADV_HARD_DIRTY_SHMEM, MADV_SOFT_ANON, MADV_SOFT_CLEAN_PAGECACHE, MADV_SOFT_DIRTY_PAGECACHE, + MADV_SOFT_CLEAN_SHMEM, + MADV_SOFT_DIRTY_SHMEM, + READ_ERROR, }; =20 static jmp_buf signal_jmp_buf; @@ -157,17 +162,22 @@ static void check(struct __test_metadata *_metadata, = FIXTURE_DATA(memory_failure case MADV_HARD_CLEAN_PAGECACHE: case MADV_SOFT_CLEAN_PAGECACHE: case MADV_SOFT_DIRTY_PAGECACHE: - /* It is not expected to receive a SIGBUS signal. */ - ASSERT_EQ(setjmp, 0); - + case MADV_SOFT_DIRTY_SHMEM: /* The page content should remain unchanged. */ ASSERT_TRUE(check_memory(vaddr, self->page_size)); + /* FALLTHORUGH */ + case MADV_HARD_CLEAN_SHMEM: + case MADV_SOFT_CLEAN_SHMEM: + /* It is not expected to receive a SIGBUS signal. */ + ASSERT_EQ(setjmp, 0); =20 /* The backing pfn of addr should have changed. */ ASSERT_NE(pagemap_get_pfn(self->pagemap_fd, vaddr), self->pfn); break; case MADV_HARD_ANON: case MADV_HARD_DIRTY_PAGECACHE: + case MADV_HARD_DIRTY_SHMEM: + case READ_ERROR: /* The SIGBUS signal should have been received. */ ASSERT_EQ(setjmp, 1); =20 @@ -263,6 +273,20 @@ static int prepare_file(const char *fname, unsigned lo= ng size) return fd; } =20 +static int prepare_shmem(const char *fname, unsigned long size) +{ + int fd; + + fd =3D memfd_create(fname, 0); + if (fd < 0) + return -1; + if (ftruncate(fd, size) < 0) { + close(fd); + return -1; + } + return fd; +} + /* Borrowed from mm/gup_longterm.c. */ static int get_fs_type(int fd) { @@ -355,4 +379,88 @@ TEST_F(memory_failure, dirty_pagecache) ASSERT_EQ(close(fd), 0); } =20 +TEST_F(memory_failure, dirty_shmem) +{ + int fd; + char *addr; + int ret; + + fd =3D prepare_shmem("shmem-file", self->page_size); + if (fd < 0) + SKIP(return, "failed to open test shmem-file.\n"); + + addr =3D mmap(0, self->page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (addr =3D=3D MAP_FAILED) { + close(fd); + SKIP(return, "mmap failed, not enough memory.\n"); + } + memset(addr, 0xce, self->page_size); + + prepare(_metadata, self, addr); + + ret =3D sigsetjmp(signal_jmp_buf, 1); + if (!ret && !self->injection_attempted) { + self->injection_attempted =3D true; + ASSERT_EQ(variant->inject(self, addr), 0); + } + + if (variant->type =3D=3D MADV_HARD) { + check(_metadata, self, addr, MADV_HARD_DIRTY_SHMEM, ret); + ret =3D sigsetjmp(signal_jmp_buf, 1); + if (ret =3D=3D 0) + FORCE_READ(*addr); + check(_metadata, self, addr, READ_ERROR, ret); + } else { + check(_metadata, self, addr, MADV_SOFT_DIRTY_SHMEM, ret); + } + + ASSERT_EQ(munmap(addr, self->page_size), 0); + + ASSERT_EQ(close(fd), 0); +} + +TEST_F(memory_failure, clean_shmem) +{ + int fd; + char *addr; + int ret; + + fd =3D prepare_shmem("shmem-file", self->page_size); + if (fd < 0) + SKIP(return, "failed to open test shmem-file.\n"); + + addr =3D mmap(0, self->page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (addr =3D=3D MAP_FAILED) { + close(fd); + SKIP(return, "mmap failed, not enough memory.\n"); + } + FORCE_READ(*addr); + + prepare(_metadata, self, addr); + + ret =3D sigsetjmp(signal_jmp_buf, 1); + if (!ret && !self->injection_attempted) { + self->injection_attempted =3D true; + ASSERT_EQ(variant->inject(self, addr), 0); + } + + if (variant->type =3D=3D MADV_HARD) { + check(_metadata, self, addr, MADV_HARD_CLEAN_SHMEM, ret); + ret =3D sigsetjmp(signal_jmp_buf, 1); + if (ret =3D=3D 0) + FORCE_READ(*addr); + check(_metadata, self, addr, READ_ERROR, ret); + } else { + /* Test the address accessability without check_memory(). */ + FORCE_READ(*addr); + check(_metadata, self, addr, MADV_SOFT_CLEAN_SHMEM, ret); + } + + ASSERT_EQ(munmap(addr, self->page_size), 0); + + ASSERT_EQ(close(fd), 0); +} + TEST_HARNESS_MAIN --=20 2.55.0.1082.g2b9226bbc0-goog