From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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 device pages") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) --- 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, struct vm_area_struct *vma, } folio = 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. -- 2.53.0-Meta