From nobody Mon Sep 28 20:05:43 2026 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 A4D963D47C5 for ; Mon, 17 Aug 2026 22:08:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004501; cv=none; b=Q1do2Xu66JH+Cb9pHfC0WzOpX84DPJN/NUcDdGHRu4yfBLVcEni1QPQdPvd8he5eDBJvUSqqnWjWh6YnCAD49iQ2Hujap15/87xTV6E0t9zl3fSuQs42WKVumgiudWvSeN/r8OVSqN9Y6Nj0o3G1a7U02yt/Cn73DzTNsDEmosI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004501; c=relaxed/simple; bh=eGQzoSEE5m0muRmnymqYrMlvGNiyTyTu7qrpYKn3c/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cDkvUZ4mAZJknC1tDH8fA0VSnQa1HsUzm1BIeFGKvmLF3xd/TIn7iXwS7bMz3ooWPzCkJF5Fz7Mgmu+fBdIP877btSK2AHw15i4kBS3owFfjnSCI1u9J6AplrRJJV96kJe9RGoJf0ZUvH3qZ/NK/cvFElwuFkoYSCNuQcj8lRYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=etvdKpc2; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="etvdKpc2" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-92f03daaa97so225943785a.2 for ; Mon, 17 Aug 2026 15:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1787004497; x=1787609297; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2TbSdQcY7KD6I3WslktwD+M/q5vUGGfVm2gu43i1aVI=; b=etvdKpc2xritJ0nNaQaJ1DR2HWbhoonO9gXUxKyC16t3DfgUfRMGyEDzdLNeo4H2po 1N7Kqkj7BWcF7OJH0Rfq/ymV7Q2nlov7f840eqp3LsnGXRbVoxUv4NZp/gf+oiai0G9v oQExtBYc7EgQCRUIv9ZWgrp+/F2EsSeX9oj0ZiPAsHGiPCkBCErIqaoGyIDsTaUyOkpG ZDe+3dgYz4X7O0p968iwoExwSagDA/iLST8AV3nqvZcmFfsT2q7mY7X3oXyzqNLH2DaJ DOr2TP4cvBwyHSdlMOTXIf5hzZUJzs/tqAbBSX3yZ34OWFJoRIVI6YpMOZA+4ArDsKMT eA4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787004497; x=1787609297; h=content-transfer-encoding:mime-version:references:in-reply-to :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=2TbSdQcY7KD6I3WslktwD+M/q5vUGGfVm2gu43i1aVI=; b=SSlk0S9A1uuIizRJA1UxMndMkiGBHRxv2D1iySVyqZgaVSkTfNPCkDvkW1j6ifNOeu u8IL7nVlx30nyVyBjYgLyhJICWGYXiYyJXZZTBlPlU+CNUHtyiDnIlz4vPmR7xRSeMXm dZBdLTfRYZdx7oV/BIymgieVd1btKDfARP40EuUIBYtaAfBw8rTEtqrOzpfYacTQLzG0 ixoG2Pys4c7jgCOQ4DN37vpdzx1TlGi5B+4Zaef9iD7wam0lBlEBkS0mlT55hPopOX/5 bLZ+a+96k7vh/r7Bg2geAP6cmhFEUL4QQy2FKGn4pTOtO/mOkzaSzz+66TemTRGusjQw cCXQ== X-Gm-Message-State: AOJu0YyGLC6Twf6OxJ1Jx22YhO2KzUhfjgjhhQWRdukbKT5jcQJgbYaa oBnbwbq9PjChV8f6xwGtwtO6txNYgC/0Iv85c7GM12MbOfmLqIf/9R8mhGZFLAoVz98= X-Gm-Gg: AR+sD12C4+IsS3MJ6c+DrTOXGXNqVjxuEUIx8tne/TiQDdJvj5iJKWn/uafxjnyt3R0 reQa3C5JjCpF5BhT5tehZr5WO8c4wFK0Hb1OngNGKWqLeeycn54PNQ1xWXc2dXtTVMrrxUIb9Y/ jpcPiBH2W3zVFYCAotx+SpRHfi3ho5E8slpZsTgcDe8JVP12Z+BwowYmtaH01psKDaXOaGglnjM +kRpLkvOUUqrlrno1XnHvoUuAhtea2LGCuxT5msI0Pz0Jabp309IawYs7+Zd6P1fopIn5U2x1dW LIwsg2YwbNb967JcvZahs4GdNbSmP5nax9ivxItftnGR/R65qn/kkTUj0vWUx+g+JXUfB74PDKB 7dmKc6TICQ0Oz25bXtIACoje5K+Jxtl4vXIfPLhlhawAIen5NWpijaUvJc8qaIpRTg8rn+BENXI cDmNBm64MI4ersElb3zXsKfXbBnK0RIyriREXgu0BRaWtCjLBJg7m8x4cslPDasvG0Ho7jj9kP8 9m+lyt7f/MjrpMuhk9cg+hcl/O3RERR6+z2woQ34jQoqc0l0A== X-Received: by 2002:a05:620a:80d:b0:930:c12d:b915 with SMTP id af79cd13be357-936d202fbedmr2459244885a.18.1787004497552; Mon, 17 Aug 2026 15:08:17 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-937033ce78csm147108885a.31.2026.08.17.15.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 15:08:17 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, vbabka@kernel.org, jannh@google.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, balbirs@nvidia.com, stable@vger.kernel.org Subject: [PATCH v2 1/3] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd() Date: Mon, 17 Aug 2026 18:08:08 -0400 Message-ID: <20260817220810.1175596-2-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817220810.1175596-1-gourry@gourry.net> References: <20260817220810.1175596-1-gourry@gourry.net> 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_free_huge_pmd() resolves the folio backing a PMD via pmd_folio() and marks it lazyfree without checking for zone device memory. The surrounding guards do not cover every zone device case: - MADV_FREE only operates on anonymous VMAs (DAX mappings are excluded) - !pmd_present() branch rejects device-private and migration entries - present zone device PMD (device coherent THP) is not filtered. Unlike vm_normal_page_pmd(), it performs no special/pfnmap check, and would be marked lazyfree here. Bail out when the folio is a zone device folio. Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone de= vice pages") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) Tested-by: Lance Yang --- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ced400f72d43a..714773695bbff 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2381,6 +2381,10 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, s= truct vm_area_struct *vma, } =20 folio =3D pmd_folio(orig_pmd); + + if (folio_is_zone_device(folio)) + goto out; + /* * If other processes are mapping this folio, we couldn't discard * the folio unless they all do MADV_FREE so let's skip the folio. --=20 2.53.0-Meta From nobody Mon Sep 28 20:05:43 2026 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 B1DB23EA947 for ; Mon, 17 Aug 2026 22:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004505; cv=none; b=gO98ozYpkiBNgoAYIAHVeu3eLxrIKKO/sXhfyJH+v8JRo7AEgORrtsRKoKczlEN4LBdrGiUxx7qvdWGWeGs8IsxigT729Je1VvbyKyXyOOyFBQoZXhohoHGtzLNGkaYnoUmGPLFb80HWmtUN5ShqUaJ0nzsJYrGDpqummUa4fTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004505; c=relaxed/simple; bh=HLXd7r9UoHiCOCGXYySq+SbExbsYPes653QqEyqbsUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WzY4Dmh2CzPxAcTZOniCpKzFxKh3Hz2fQvuFKKImS+P5+w82cZdrus8mNzrkqi4SPNlt9NOUPiRtz7xNGBDkPXq7TavOQ7ZQ/Rha2BR8JowkFghoGxZ6e3BvaGJ/ELz6qMC57rPT7V/WgXl7YnHu4Vxi9hkDAhCrcpzhf3x0Drs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=W1RSBXYx; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="W1RSBXYx" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-93703cc9e2dso45475585a.3 for ; Mon, 17 Aug 2026 15:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1787004499; x=1787609299; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PYwESWun0fa6liMiTXLOYEKQD6iVsL/nuJsHb68bQDQ=; b=W1RSBXYxvSp4Bx+MpTdA7tYVjdzTPMp42cpQTj44pG9a+KH3KJuQs+t7g/y4o881ki 0cf/vVG3ithSk3upodZqb3CoR+C02b5OtwqI9yTjCVQ6OGL95/utiDSzbUpgAK1WYKzz XzejA44Jd4M+P4BK7buaoGV5f6k2jWkkfvOycPAoTYPqPR9hhS3BJ++z9ugnf+nvZz6O tMf1itWdu2CBq5kU+olf4VSEfNtS6D+VGuzmDSrlLSwpwvvEWjWh98+c+8VmTedDtK5U F8Z77a2cQnQ8gPEX6mx61kKuk0WrB4YLbOb6HauPVC4zF+GJ2ThgQBwSsSMX1ongV8p9 gHqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787004499; x=1787609299; h=content-transfer-encoding:mime-version:references:in-reply-to :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=PYwESWun0fa6liMiTXLOYEKQD6iVsL/nuJsHb68bQDQ=; b=m7tbfJiQNtUHZjPskwdVq2aNR4O+tRECEegh/hITLQnmyLtNHcTOZmQO13HmdByeNM hPdQjzlQjQ9EfYhpzUYtLpQnj+WpqNJg+F3DSb/Y3XzjyKqEUiLeHkgGszWjT30b4yQX epfFswxCJBSfkLhvhTElYUYfQQbe/XQEYlwlDZ0Pyc4qrDczSLWtcbrS8sGfP48BzMj9 K7B1ePU8j4Oqc7VpEMHJXTJ6czHxBKQX7geTu8go7rvI0pHMLxOvGWIvymIXFYTcKfeM +mUgpqHcc2MwDXJ14/fpcuILT5qCEe9PAL0PfRylFuNXNLywzMpzxHSeIPpWcLIpRnR4 LfzA== X-Gm-Message-State: AOJu0YzZgGurDoNfP+/gDjyvAWWqjRa+nYHbaDycPtQ2xjjV0qfTxL81 BGbCkmCfg/25vfptWvsUn/t9dLwDstc6OoJo4l6/leR+TFRxD6z3w7lXf6WLgtOFv0s= X-Gm-Gg: AR+sD10lDuKmLzJ9JmMo4SVQIu0EXPiEKoGKBR8T51ClKkZZq+MVjw0rjHPXubQT7K/ QdVOud+isyA0zivlfilfTgfdPygYN0vufXOudXmZRxphRm4fwI2yh/odEMLhchggVfkqfzXDBFy Jsn8PJ4Ke9zMr+1WqXRSrKOygKhNUYZSV5FTAIBZKe6pqf27MRqIVYEi2DSXpFYOCWEHMHtuVBB 2iRyUJdCZb8R1wp2t1Rm/+EVuMe8ijlORP85TCI1NN3O5LStWxy1VO6RXfsfBkxOFeHa2u/bIwl yKWDxJ4I4qqBI6WavHdVBmwO9rDmTppfmmJLzgw0QaR22941SO8amdXvPDdFEyXIOw02s8LhiPe vY//vYQrb7Ep4Pp5pdd5gYVCNmMmyFeQzoIT+sTJPRH3x1g7+CBP4prtjbsT6FCu8S+/26AcbqA DSNLKmUNqHQui3LiZEUA1Rfu9Qeeg7F+2IfneZtZxKZqXR0tfURPJT+z2/mOpNNCMKsdMnC1E+2 ASOgyzlgH/2dYvuKjM+j/n9uCKoz0baFXnUebGbOIiSuACBma49xHJXV7gJ X-Received: by 2002:a05:620a:4387:b0:92e:bc28:5479 with SMTP id af79cd13be357-93704b1ac3fmr488870385a.2.1787004499566; Mon, 17 Aug 2026 15:08:19 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-937033ce78csm147108885a.31.2026.08.17.15.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 15:08:19 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, vbabka@kernel.org, jannh@google.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, balbirs@nvidia.com, stable@vger.kernel.org Subject: [PATCH v2 2/3] mm/madvise: skip zone device folios in cold/pageout PMD range Date: Mon, 17 Aug 2026 18:08:09 -0400 Message-ID: <20260817220810.1175596-3-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817220810.1175596-1-gourry@gourry.net> References: <20260817220810.1175596-1-gourry@gourry.net> 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_cold_or_pageout_pte_range() resolves the folio backing a PMD via pmd_folio() and ages or reclaims it without checking for zone device memory. The surrounding guards do not cover every zone device case: - can_madv_lru_vma() excludes VM_PFNMAP and VM_HUGETLB VMAs (so device DAX is filtered) - !pmd_present() branch above rejects device-private and migration entries, which are non-present. - A present zone device PMD - e.g. a device-coherent THP - is not filtered by any of these, nor by pmd_folio() (unlike vm_normal_page_pmd(), it performs no special/pfnmap check), and would be aged or paged out here. Skip ZONE_DEVICE folios explicitly during MADV_COLD/PAGEOUT. Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone de= vice pages") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Balbir Singh Tested-by: Lance Yang --- mm/madvise.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index c179938097bf0..2151bb9468594 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -396,6 +396,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, =20 folio =3D pmd_folio(orig_pmd); =20 + if (folio_is_zone_device(folio)) + goto huge_unlock; + /* Do not interfere with other mappings of this folio */ if (folio_maybe_mapped_shared(folio)) goto huge_unlock; --=20 2.53.0-Meta From nobody Mon Sep 28 20:05:43 2026 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 6BE293E8340 for ; Mon, 17 Aug 2026 22:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004504; cv=none; b=sFUavzn3sUVY6txqtPf/L0HC+S8YpsLeAUYajW8K3+uA4AfKvweZ7fdvwvsfyz+fuKQ81FCARuU0ED/1Wgq2rSPNTvP8mZHE5f7fPux2cBv1Z8Q8xnMwl7jw+G/SItfoCmK2rexRxQyPnwhqgCTWmx/0tOOPlnKr0MTKwMBDy7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787004504; c=relaxed/simple; bh=ZXtcW5Eoj+sECtsN1QOXnQk3JSNbUEnxSoGOx9uaKHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bq3E5dEr7S1hWP0rJq/7eqVDwAYs9xUFECUiV0oETxtrDRqXXUe70YHJpy9IDp7T8yFJ+2t6ZFsNZ+riHUg36Qqmj25tSEq7uBVHcg/a/cePWghMT8AJ2i986aJxE7/2lgpgZBy229K1GhJmWWm7mUnzaYseNFmoZT3WtGrrPzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=VpoGboIi; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="VpoGboIi" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-92ed3993c1eso208796585a.1 for ; Mon, 17 Aug 2026 15:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1787004501; x=1787609301; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2oLjt6fqOYQqPl3RBDaIWJlYyCKzqU8AbAXeHyMH4wI=; b=VpoGboIi+7R5Ie1/wbOoaHqJMIL55HxwCaCS4HahyknzAvi6xPszqyjXfsS1QuDGhZ gP3UZyzzw/GMlCxZ9ugyO4+BEVvVgLd4Rs2nKbJTumMwREY4HzeH3Uod9EzEYvh/ms73 XkH6l01V0x5Q82Qcb/2yhO4binpt0DocmL0CuYBfoaAk1gbDUpvV3a7wCrhEGZfHzfAC Cs9JIKJHAGhUO4OhJeLiKmlBTmSNQloQxK/vWaWSpT7yjBm4nmAFkHmQm1IaI/zkmOGD WKsCqA/uMGpYyegc+tRv7xt6W1xyEyZQvDZEDBa8ICKWvQD3nF7/5C18vLuuG4PmU+Vk xQVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787004501; x=1787609301; h=content-transfer-encoding:mime-version:references:in-reply-to :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=2oLjt6fqOYQqPl3RBDaIWJlYyCKzqU8AbAXeHyMH4wI=; b=GvujAIhVCuX3HlcWNde4TnmEhKU9XitqMZaVpA+zY0nhHjmAvhZrT5cg9qMhykKGqm +THGx0XBskxPLd8YMEiGJhvkqm0QTuzGnIr9c0reBQw4fqe8osskombtJzlqSEVOqSS3 yF+GxwTzA2zgWSVU/IqonDV0Rnp3QfSGbU4B33kgxrhz1AdIilM0F3/llm19JjyzL2Bj 5s9/wsEQPF+AitAVftnajnLFn4lBcnlzPOooB3LDuYIird6wnIN3oPhnf+3EshVA7wnd fKc5XLBFY22nD2HAokE70SRZfeK1+d3SEGP8yvod6mzrrp8Fm7L102cYF+/+kGC4jUs9 8QpA== X-Gm-Message-State: AOJu0Yw3x85Gq9Tu96CKdwucSrwdwGNBrMCFYjum7D4OW1gm1parYEwi rA4Qt+MdxqIMGii4Ej8soSYNthr60atDH/jAXnxAWrammu5iK+iZowGk7hZaeml+tq4= X-Gm-Gg: AR+sD13rEqNSexPCeJFc6xDexFrFjP/WH94KMT9dTBqnxXSKDigI4jcrvuawzrg019Z i+/zX8uSCeRcy69eFdedbA4v2QGTDpNdNEI58WESKMweLvPDh0IU6TanQVcoefI6Z8/E8AHfaHV BBQ3zre8i+ljdRd7OzP+rAB45EKOjzJf2BsxaM6mrLx3YusrRE2tJqNapJdnWNFmMvznNoOiOFl a3GrLXuReroYe2Uht3Zf0467sAR6FQKC4M09aNioIcoKzm4kxS3/geZzRVge68mTwN+sBUKHqHX r3Xfas6p5IsmaAWIsOAPzUITfL/ZrWjoHQ8rYy7mQNHvKtYGhNrV0lr3WqOmkvOqaRzMA09cpkw IprKDSulB1imXQh7YenJzEKbB9FCgmnYvOQTLEJKE0kkD3mj49jvOg1KRluU7g9rrbI3xzBftK3 vUkhVtgLFeHzvsC0MyLxWQwbRbpOBtRFCQtHjW5zOHI+djXT8+zogSGb6xw55qCBSOqsp6mMHyo OX5VL8xrfLOcfSnGevMU3e//dxJT+YWVJpjVeG/QMy/3AUzb/i75VBbaWkzTA== X-Received: by 2002:a05:620a:2889:b0:92e:7cc9:a888 with SMTP id af79cd13be357-936d1fd98c4mr3001265785a.2.1787004501326; Mon, 17 Aug 2026 15:08:21 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-937033ce78csm147108885a.31.2026.08.17.15.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 15:08:21 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, vbabka@kernel.org, jannh@google.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, balbirs@nvidia.com, stable@vger.kernel.org Subject: [PATCH v2 3/3] mm/mempolicy: skip zone device folios when queueing folios Date: Mon, 17 Aug 2026 18:08:10 -0400 Message-ID: <20260817220810.1175596-4-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817220810.1175596-1-gourry@gourry.net> References: <20260817220810.1175596-1-gourry@gourry.net> 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" queue_folios_pte_range() already pairs vm_normal_folio() with an explicit folio_is_zone_device() check before adding folios to the migration pagelist. vm_normal_folio() alone does not reject zone device memory (a present device-coherent page in a normal VMA is returned as "normal"). Mirror the explicit check in queue_folios_pmd() as well. queue_folios_pmd() uses pmd_folio() directly and can encounter a present zone device PMD - e.g. a device-coherent THP. This is not filtered by existing checks: !pmd_present() - only rejects non-present device-private and migration entries vma_migratable() - excludes DAX and VM_PFNMAP. The early return also means such a folio is no longer counted in qp->nr_failed under MPOL_MF_STRICT. This is the same pattern used by queue_folios_pte_range() (skipping zone device without failing). Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone de= vice pages") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Acked-by: David Hildenbrand (Arm) Acked-by: Lorenzo Stoakes (ARM) Reviewed-by: Balbir Singh Tested-by: Lance Yang --- mm/mempolicy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3498a5651d50f..3418b5664dcf8 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -662,6 +662,8 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk= *walk) return; } folio =3D pmd_folio(pmdval); + if (folio_is_zone_device(folio)) + return; if (is_huge_zero_folio(folio)) { walk->action =3D ACTION_CONTINUE; return; --=20 2.53.0-Meta