From nobody Fri Oct 2 04:46:28 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 81C7246A5F1 for ; Wed, 5 Aug 2026 12:50:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785934235; cv=none; b=qvW/vuw3cdm+XqDO9dlzI7A9Bbm9qPPnamdmUeGnLs7z4LmPKfbmn2763gajp8eixbARlyre9TB7bHuPNRPJ6yJYdSJaeRecLDEJWjUFeRtLIALg9p1ztzecQbypcWPoo6ecUvBanPbJ95R5nSLR8FyMe6kvZXaQMGtUAwRvMAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785934235; c=relaxed/simple; bh=JND0DIxNPheDV3c+Rk7qBx9BtfRRxaI/6bOm2Exdgts=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lGKg/v186DDKWq+eWEqVhZ+jtwJS2WExyHImjggpYKeRgqL3mQ76PvMTLeY9A+bbRv8aeRnxit2kp/GLkzebhPvnwAkzMDxv+S/TMoGB/ofdG7cmvLqtE+JK7xD4exmWEDQ8HaAWOwJvOydpb94Oh2lBsrwMkZXncU2Nu+GuTR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=dVmiKXFb; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="dVmiKXFb" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8487214ad2bso1411479b3a.1 for ; Wed, 05 Aug 2026 05:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1785934233; x=1786539033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=BVNKoUyYIF3h0gmseuybz7+MdTC/satf3XbsBQnLJSI=; b=dVmiKXFbdhcQAtHVg83X1pH0LfYNJ7gPd6V5WIv0tc7CByMWWMfovv4QkjxqvM9T/8 9VIFst1Koh28ThxOpERCf6YWX75CPYhgtGYkQDOhbbD/xIpL9G61scyjaah2x9rTfQoq uFCEOpTrWwVsQ7EtK9drgYSWfZC/SbQEPZO00g1uZsJWiLKfHpfmG4lB9O6XUcHHe16r XLcBAxV25bEFBRDNr35I30/mOQ19WCV2PXCjinMFzT2hCDfhTG9FD3NRr5QDTBRmtvEm 4uQ8wSydIzsbIHRrMeaRIxnUNZMhvcOtLcV57lVq1zvKRXyqUiUyiYSQczspZ0FNSojh m9rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785934233; x=1786539033; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BVNKoUyYIF3h0gmseuybz7+MdTC/satf3XbsBQnLJSI=; b=L+MYkjWbp+1lmkFE0OctHsSAz2X6BXmgzX5OVMYjF4L65hRVpQ302IXzfyTxPn/GP8 VojY2mFNvRTcAoDeaixmR22b+a77psl9rwu3/L2RTnQHZ+dyKVsszhI4/liRDpwfiNBM dBBdtqoAYw0j6f91dm9hFpl4yek9LHMEBslVc/LF2JOCRd2+mDnCwg80XeAwMr9aXKDJ PYo9EgUE3TWjGx6gtEklf+x/gPh2GwX+kx0AJitNrTF6U9nsZG0ugljaWtXaQbcU+VyV mAN7eGMq07u47FB5szbBYEllKeIdNHASHDL9I59RjjTLTUKy44zzo82FPOBbTrNO9J5k RreQ== X-Forwarded-Encrypted: i=1; AHgh+RrBK+wSRbdT88c4JVC6iaLPyee62j3cgRV4mkAAKnVxzP6fGyYKJpsyTtM4Neys3th7Ubg2eT+jZtP1i78=@vger.kernel.org X-Gm-Message-State: AOJu0YxxOiR2czUTm9KefZn3KmNksKz/Hd5B8zUVNzKnWh56U0m76Zq/ 5ELjrWlpqAZCuavC25oNrNEQv06+qYjEW8eAQaOsIpQbwNBQ9d7OVK14mQvtd/WFFXY= X-Gm-Gg: AR+sD102KOxjsLcEvnrAu3bRnyiyd9ltwbiv6IgZJJNfIZK2F+eDQJ3bhbQrEhifpIN POGcC3cYCzQ68rM3fRJqXRP360d8C1Kz44z+H0vARncjnfq6DJJPDt/InURZK1hYbnwTwmgI3lb Riagd+Ph+WL2jiQGE8JQbYB5WkROHDIsxLSwMCH+LkPEgv2A96NmNP/EXa8DoFOBoUYrcXgsYc5 Dx6vQvqvrPluLlykYkFRi8xktRDfMk11rVYVv8w2JpVYiXPYHqoXRY8WEVYIaF8C5z+oWsci3LV i8Qxi07pVryyfjPC06d6H5dJjGM6hbEpXNBrmzQoy0Tua/HG7ZYH5uW2YxR/V1e1xSDiwh/1bzV YjgFwRZ6+Zf2Fqx0+eX9Is57QskhRB6X+hJGk7WFioqtVxbXLrp0MYjP4JvBmF4sfjt0h5fXLHU aALubcYtRCK7u7LsbVQjk2Mo1OiklRHdm3Bl77s6fIRaXQpJNbenF9M41SDoTEMjly2Wlwy39Zu T/2kHV1OaRl9nUbuBKeMNNOF8c= X-Received: by 2002:a05:6a00:298d:b0:84e:7ec:aa42 with SMTP id d2e1a72fcca58-84f2dfb511emr8027091b3a.10.1785934232776; Wed, 05 Aug 2026 05:50:32 -0700 (PDT) Received: from FR9WL0RHKY.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f2e2e3089sm794446b3a.19.2026.08.05.05.50.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Aug 2026 05:50:32 -0700 (PDT) From: Yunhui Cui To: akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org, david@kernel.org, vbabka@kernel.org, jannh@google.com, 00moses.alexander00@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yunhui Cui , stable@vger.kernel.org Subject: [PATCH] mm/madvise: avoid skipping pages after splitting large folios Date: Wed, 5 Aug 2026 20:49:57 +0800 Message-Id: <20260805124957.91325-1-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" madvise_inject_error() advances through the requested range using the size of the page returned by get_user_pages_fast(). Saving the size before error injection is required for hugetlb pages because successful soft offlining can dissolve the source huge page. That stride is incorrect for non-hugetlb large folios. The memory failure handlers split such a folio and handle only the base page for the supplied PFN. Advancing by the pre-split folio size then skips the remaining pages in the requested range while madvise() still reports success. Advance by PAGE_SIZE for non-hugetlb pages and retain the whole-page stride for hugetlb pages. Fixes: 19bfbe22f59a ("mm, hugetlb, soft_offline: save compound page order b= efore page migration") Cc: stable@vger.kernel.org Signed-off-by: Yunhui Cui --- mm/madvise.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 07a21ca31bad4..f37abed29445b 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1464,11 +1464,12 @@ static int madvise_inject_error(struct madvise_beha= vior *madv_behavior) pfn =3D page_to_pfn(page); =20 /* - * When soft offlining hugepages, after migrating the page - * we dissolve it, therefore in the second loop "page" will - * no longer be a compound page. + * Non-hugetlb large folios are split and only the addressed + * base page is handled. Hugetlb folios are handled as a + * whole and may be dissolved, so save their size beforehand. */ - size =3D page_size(compound_head(page)); + size =3D PageHuge(page) ? + page_size(compound_head(page)) : PAGE_SIZE; =20 if (madv_behavior->behavior =3D=3D MADV_SOFT_OFFLINE) { pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", --=20 2.39.5