From nobody Mon Feb 9 23:00:24 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3547624DD1F; Sun, 11 Jan 2026 20:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768165154; cv=none; b=C0FTmOR/WircpzJuyDHQemUnAze07rlRInu/eESp9He+aGC1x5eo764Jag7gwH0mcHKKqHYWDVmV71DAdJbXuf/mPnVlA6q38n47rgPlclsOb9WKdRl9fCZtypMM72nv6FLfGSv0OVgbjt0DAf0iX46maON1i05YrV9+mPIcqi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768165154; c=relaxed/simple; bh=s1T9vuao+kXccuTcOMDTHHq+bj2twItjHB4YXvJcFdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ula7+9ZRv+a0BH6DGtCPWHQQKRe4KmYNDBkhO7yoagu6VZPh12lMG+fhOfdBlb+Ycg6oF3N/jeFgozKIx5R2s19gIcMVtRrwv1/1muALpWDFsbVz1VGIV/PVoX3x5jDQRlD97fFkKeaxTve30jqrEIsY+J36MPeAABTfia9N2I8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JtG3kzGY; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JtG3kzGY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768165154; x=1799701154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s1T9vuao+kXccuTcOMDTHHq+bj2twItjHB4YXvJcFdM=; b=JtG3kzGYXmq0jFZA5nRp6BiA0lll/Fbo53OMPwvEoQQGZ4aG9u3h7jx6 aljVpAMa1G3hgbk7yim4g8dX7XJ6na7qvn8d4RWQi9SzVbvU0tcWLYDmf eNN7pEd1z6995kPBryjBHNXgdey0HhpyK4JnOehyaSATq/NY+SWxfupJm SZaEdJtte3pOKudD7VVWVBmBCjTbAgR1ucmwVev92cYaRDjHrfHwIA9Zd lyktn8vbVNSI0UgiH/UWk1KNRNmAijESaKOW7vCvQq/TMiX3v/mIu46Qg d+kYm1TFxp7yj3kJ/V5jwSVDUK584B+hl2UC9ZO/BmEo2aNUvGAuxbo/w Q==; X-CSE-ConnectionGUID: s0vkVV1OTrOJ61LxYWUNsA== X-CSE-MsgGUID: 2GUEF3oeQnifolr9NeQ+Uw== X-IronPort-AV: E=McAfee;i="6800,10657,11668"; a="80904678" X-IronPort-AV: E=Sophos;i="6.21,219,1763452800"; d="scan'208";a="80904678" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2026 12:59:12 -0800 X-CSE-ConnectionGUID: x5hfc93rT7yYrL+IWOJYbg== X-CSE-MsgGUID: YcOO9Gc2RRmD+fYdz8alfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,219,1763452800"; d="scan'208";a="208419956" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO fdugast-desk.home) ([10.245.245.11]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2026 12:59:04 -0800 From: Francois Dugast To: intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, Matthew Brost , Zi Yan , Madhavan Srinivasan , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Felix Kuehling , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lyude Paul , Danilo Krummrich , Bjorn Helgaas , Logan Gunthorpe , David Hildenbrand , Oscar Salvador , Andrew Morton , Jason Gunthorpe , Leon Romanovsky , Balbir Singh , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Alistair Popple , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, Francois Dugast Subject: [PATCH v4 1/7] mm/zone_device: Add order argument to folio_free callback Date: Sun, 11 Jan 2026 21:55:40 +0100 Message-ID: <20260111205820.830410-2-francois.dugast@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260111205820.830410-1-francois.dugast@intel.com> References: <20260111205820.830410-1-francois.dugast@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Matthew Brost The core MM splits the folio before calling folio_free, restoring the zone pages associated with the folio to an initialized state (e.g., non-compound, pgmap valid, etc...). The order argument represents the folio=E2=80=99s order prior to the split which can be used driver side to k= now how many pages are being freed. Fixes: 3a5a06554566 ("mm/zone_device: rename page_free callback to folio_fr= ee") Cc: Zi Yan Cc: Madhavan Srinivasan Cc: Nicholas Piggin Cc: Michael Ellerman Cc: "Christophe Leroy (CS GROUP)" Cc: Felix Kuehling Cc: Alex Deucher Cc: "Christian K=C3=B6nig" Cc: David Airlie Cc: Simona Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: Lyude Paul Cc: Danilo Krummrich Cc: Bjorn Helgaas Cc: Logan Gunthorpe Cc: David Hildenbrand Cc: Oscar Salvador Cc: Andrew Morton Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: Balbir Singh Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: Alistair Popple Cc: linuxppc-dev@lists.ozlabs.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: amd-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: nouveau@lists.freedesktop.org Cc: linux-pci@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org Signed-off-by: Matthew Brost Signed-off-by: Francois Dugast --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 2 +- drivers/gpu/drm/drm_pagemap.c | 3 ++- drivers/gpu/drm/nouveau/nouveau_dmem.c | 4 ++-- drivers/pci/p2pdma.c | 2 +- include/linux/memremap.h | 7 ++++++- lib/test_hmm.c | 4 +--- mm/memremap.c | 5 +++-- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_h= v_uvmem.c index e5000bef90f2..b58f34eec6e5 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -1014,7 +1014,7 @@ static vm_fault_t kvmppc_uvmem_migrate_to_ram(struct = vm_fault *vmf) * to a normal PFN during H_SVM_PAGE_OUT. * Gets called with kvm->arch.uvmem_lock held. */ -static void kvmppc_uvmem_folio_free(struct folio *folio) +static void kvmppc_uvmem_folio_free(struct folio *folio, unsigned int orde= r) { struct page *page =3D &folio->page; unsigned long pfn =3D page_to_pfn(page) - diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd= /amdkfd/kfd_migrate.c index af53e796ea1b..a26e3c448e47 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -567,7 +567,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint3= 2_t best_loc, return r < 0 ? r : 0; } =20 -static void svm_migrate_folio_free(struct folio *folio) +static void svm_migrate_folio_free(struct folio *folio, unsigned int order) { struct page *page =3D &folio->page; struct svm_range_bo *svm_bo =3D page->zone_device_data; diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c index 03ee39a761a4..df253b13cf85 100644 --- a/drivers/gpu/drm/drm_pagemap.c +++ b/drivers/gpu/drm/drm_pagemap.c @@ -1144,11 +1144,12 @@ static int __drm_pagemap_migrate_to_ram(struct vm_a= rea_struct *vas, /** * drm_pagemap_folio_free() - Put GPU SVM zone device data associated with= a folio * @folio: Pointer to the folio + * @order: Order of the folio prior to being split by core MM * * This function is a callback used to put the GPU SVM zone device data * associated with a page when it is being released. */ -static void drm_pagemap_folio_free(struct folio *folio) +static void drm_pagemap_folio_free(struct folio *folio, unsigned int order) { drm_pagemap_zdd_put(folio->page.zone_device_data); } diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouve= au/nouveau_dmem.c index 58071652679d..545f316fca14 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -115,14 +115,14 @@ unsigned long nouveau_dmem_page_addr(struct page *pag= e) return chunk->bo->offset + off; } =20 -static void nouveau_dmem_folio_free(struct folio *folio) +static void nouveau_dmem_folio_free(struct folio *folio, unsigned int orde= r) { struct page *page =3D &folio->page; struct nouveau_dmem_chunk *chunk =3D nouveau_page_to_chunk(page); struct nouveau_dmem *dmem =3D chunk->drm->dmem; =20 spin_lock(&dmem->lock); - if (folio_order(folio)) { + if (order) { page->zone_device_data =3D dmem->free_folios; dmem->free_folios =3D folio; } else { diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4a2fc7ab42c3..a6fa7610f8a8 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -200,7 +200,7 @@ static const struct attribute_group p2pmem_group =3D { .name =3D "p2pmem", }; =20 -static void p2pdma_folio_free(struct folio *folio) +static void p2pdma_folio_free(struct folio *folio, unsigned int order) { struct page *page =3D &folio->page; struct pci_p2pdma_pagemap *pgmap =3D to_p2p_pgmap(page_pgmap(page)); diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 713ec0435b48..97fcffeb1c1e 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -79,8 +79,13 @@ struct dev_pagemap_ops { * Called once the folio refcount reaches 0. The reference count will be * reset to one by the core code after the method is called to prepare * for handing out the folio again. + * + * The core MM splits the folio before calling folio_free, restoring the + * zone pages associated with the folio to an initialized state (e.g., + * non-compound, pgmap valid, etc...). The order argument represents the + * folio=E2=80=99s order prior to the split. */ - void (*folio_free)(struct folio *folio); + void (*folio_free)(struct folio *folio, unsigned int order); =20 /* * Used for private (un-addressable) device memory only. Must migrate diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 8af169d3873a..e17c71d02a3a 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -1580,13 +1580,11 @@ static const struct file_operations dmirror_fops = =3D { .owner =3D THIS_MODULE, }; =20 -static void dmirror_devmem_free(struct folio *folio) +static void dmirror_devmem_free(struct folio *folio, unsigned int order) { struct page *page =3D &folio->page; struct page *rpage =3D BACKING_PAGE(page); struct dmirror_device *mdevice; - struct folio *rfolio =3D page_folio(rpage); - unsigned int order =3D folio_order(rfolio); =20 if (rpage !=3D page) { if (order) diff --git a/mm/memremap.c b/mm/memremap.c index 63c6ab4fdf08..39dc4bd190d0 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -417,6 +417,7 @@ void free_zone_device_folio(struct folio *folio) { struct dev_pagemap *pgmap =3D folio->pgmap; unsigned long nr =3D folio_nr_pages(folio); + unsigned int order =3D folio_order(folio); int i; =20 if (WARN_ON_ONCE(!pgmap)) @@ -453,7 +454,7 @@ void free_zone_device_folio(struct folio *folio) case MEMORY_DEVICE_COHERENT: if (WARN_ON_ONCE(!pgmap->ops || !pgmap->ops->folio_free)) break; - pgmap->ops->folio_free(folio); + pgmap->ops->folio_free(folio, order); percpu_ref_put_many(&folio->pgmap->ref, nr); break; =20 @@ -472,7 +473,7 @@ void free_zone_device_folio(struct folio *folio) case MEMORY_DEVICE_PCI_P2PDMA: if (WARN_ON_ONCE(!pgmap->ops || !pgmap->ops->folio_free)) break; - pgmap->ops->folio_free(folio); + pgmap->ops->folio_free(folio, order); break; } } --=20 2.43.0