From nobody Fri Oct 2 01:56:04 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 7410038AC87 for ; Thu, 6 Aug 2026 05:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785995722; cv=none; b=Q0lQs21T6eA2ZZkJfaJpus1mugI4fT0s3mUFGU858mRZzRroVmmjB2HtHL8uM79MO/tt/rMNJKJwdTDEzmegwo3muPH/wmEJdCFTjOjloM/CamN6vD0hw+ML0pnSBZ7LfjyPEMZSMShVbY1OycI0f4N5/sc30IB7F1r2GJ5u/TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785995722; c=relaxed/simple; bh=DxfQm9W4krPzpEfAtVVVWIinLMUehnOesKs+H9lg9S4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=AXNmry8nm1kbrqKqFp//RZ21W28ZBC0vXUj+47dk3s3Hje3juaMAOzuhLazVgUo35+OFllYk6/LPmlzbDMz3DVJlGstJxHcqH9C9r2mYisoFcxBY1Gkn5bkYxnevUZ3oTzjeSJyRNhIomO+jx7JZEYqZ0i4ZUoPoENPqUs8XL5o= 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=f7ey23pR; arc=none smtp.client-ip=209.85.214.176 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="f7ey23pR" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2cc891373e0so22647585ad.2 for ; Wed, 05 Aug 2026 22:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1785995720; x=1786600520; 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=dGhdRgIgIMHfR7vy1rI13brOXOjVKrzvUJgGFI1i9XI=; b=f7ey23pRqiD7Hcc55I48Q8HZazhZ/uJkAXQ+HPgUUnLblc3Qv9TBBDTqXc24tM6CUk ZbCB/9/eq6X3Wd5QMsDgFMgKEaJeV+Yn62onww1z848qWikdwRi2jAPPqL0i5G1ILMdL pRCq8rUuWNT9YgfmMcGtXYtZ84Mb+hhUrfeo/cM0xGWM4oZn7G6mrBGJu5dHnwvELVDY 355u7KKrEEecW1VdxD0cyd/HAZR8pUp3ZdOOt4qnpK+Jf5m9NVYBgtAJ1nOCvPaekFXc yFM4s4IcJoOJ2TwaIf90+0HHmFWHdd4UxmE0mjYlHlSpJUinH1LH8W+/KwU1g1e8cHh0 N4uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785995720; x=1786600520; 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=dGhdRgIgIMHfR7vy1rI13brOXOjVKrzvUJgGFI1i9XI=; b=oRo4zAzQyes44GZs7D+yxwronmzygtyhMR96/VXKxlpS1iOQ4KdBzB4rruCixKGq1t JAHaLDfmzB5KhxAiilgL4q9388meh+c9LTsmyGrZemTo7OGeFcdmF7JVpSSuPoGlQKzu 4R4ZpUKOSCiGYj1UxcTWEFoEYs+Yu25D0JPPdDwNb6ywcEeuDAz4UAuJXzrB9cX2oAi6 Sl7bmswXI56kCsd5Kqrwd5Zb2ZkqAPY81/Mr+Hgz4Lp+K/lhXx99IXoCGHKnSqALt206 fqYrNrQVbFZT3Y+q1ZkFVHCnlOBLKQMY8q/v/nhQsGyhKbmpoparS8VeXeoWE+2nYfGG bngA== X-Forwarded-Encrypted: i=1; AHgh+RpIiyN5IruoZcKbzCyXw8hsoVj39RQUpHIyyyi3QyrCf9WEJEZtvPudJrGpz8yzZiU39QM/AFqUZNJJLew=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu3BkgQ3Sp3XNFFfvcjrLL4hMHvKs7N/4Aso97yC6og53h5NJu xtaATxP2sbnoxNppOHvg9j7Oy7hqzgDm9WeLc4MygZyCTeg0vpB8OAsDIJB5gmWktVQ= X-Gm-Gg: AR+sD11ZNIRemybamlZccIuvHJjyP2zTkvvhG963soDDBPyfx2u6VkDwF1qvLDYszhk AyxOmE2w8XmYEQo5VJIRF+5j9GGmXLtNrcvjH4lqi7N1CJPgX+067ZcBMqC/VTat3JS+JkOVlRI vbDgFsRwZ4HJAp1TmG23RYmq1uzPMfpMhZ+Atm2gvkGBWkTNKVL2AH3lqnXTvRuHF6reh6djywa cqkECeOhjKObbTpTxrkvEp8RSIWHnfF65BoDtPPc0fp5qVwWaLCY9UOylGrlMhYJq1lMQ9kMVPV DkIvuA2kr11vTfDoZMoDG0eFGB3XsyNl3p5Nkw+wFrz+671RUXLOLeuhkSp8rhaQjX1QnoxH8wg C+pKEAtxEhNAE0pOdA11n+i5eHmLiLogOfrAwvCo2s27+khB8cNPs133SDydC72CkoOorhGM69b Cft+17Nr3gaRiuRysYMbYzOvgZ3/vf/3Al9irl6F+xHNpTc172QvFl0oOYX0t/xeODNeNxc/L0P DtNPG0BAlkXt7zkrMunmsBA+umukSsTo5Z37A== X-Received: by 2002:a05:6a20:43a9:b0:3c3:8651:b302 with SMTP id adf61e73a8af0-3cb85f60443mr15100884637.28.1785995719569; Wed, 05 Aug 2026 22:55:19 -0700 (PDT) Received: from FR9WL0RHKY.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3158644a195sm21906471eec.13.2026.08.05.22.55.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Aug 2026 22:55:19 -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 v2] mm/madvise: avoid skipping pages after splitting large folios Date: Thu, 6 Aug 2026 13:55:01 +0800 Message-Id: <20260806055501.56761-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 in system memory. 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 folios in system memory. Retain folio_size() for hugetlb and ZONE_DEVICE folios, as compound Device DAX folios are handled as a whole. 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 5a09cc24f04a0..e9d4c3bbc5290 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1455,20 +1455,25 @@ static int madvise_inject_error(struct madvise_beha= vior *madv_behavior) =20 for (; start < end; start +=3D size) { unsigned long pfn; + struct folio *folio; struct page *page; int ret; =20 ret =3D get_user_pages_fast(start, 1, 0, &page); if (ret !=3D 1) return ret; + folio =3D page_folio(page); 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 in system memory are split and only + * the addressed base page is handled. Hugetlb folios may be + * dissolved and ZONE_DEVICE folios may be handled as a whole, + * so save their size before error injection. */ - size =3D page_size(compound_head(page)); + size =3D PAGE_SIZE; + if (folio_test_hugetlb(folio) || folio_is_zone_device(folio)) + size =3D folio_size(folio); =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