blob: 6c3dbb692037d7bacbc1e2d303cfac95ee1c30d4 [file] [log] [blame]
Dan Williams59816902018-03-29 19:07:13 -07001/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright(c) 2015 Intel Corporation. All rights reserved. */
Christoph Hellwig7d3dcf22015-08-10 23:07:07 -04003#include <linux/device.h>
Dan Williams92281dee2015-08-10 23:07:06 -04004#include <linux/io.h>
Andrey Ryabinin0207df42018-08-17 15:47:04 -07005#include <linux/kasan.h>
Christoph Hellwig41e94a82015-08-17 16:00:35 +02006#include <linux/memory_hotplug.h>
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -04007#include <linux/mm.h>
8#include <linux/pfn_t.h>
Jérôme Glisse5042db42017-09-08 16:11:43 -07009#include <linux/swap.h>
10#include <linux/swapops.h>
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -040011#include <linux/types.h>
Dan Williamse76384882018-05-16 11:46:08 -070012#include <linux/wait_bit.h>
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -040013#include <linux/xarray.h>
Dan Williams92281dee2015-08-10 23:07:06 -040014
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -040015static DEFINE_XARRAY(pgmap_array);
Dan Williams9476df72016-01-15 16:56:19 -080016#define SECTION_MASK ~((1UL << PA_SECTION_SHIFT) - 1)
17#define SECTION_SIZE (1UL << PA_SECTION_SHIFT)
18
Christoph Hellwigf6a55e12019-06-26 14:27:10 +020019#ifdef CONFIG_DEV_PAGEMAP_OPS
20DEFINE_STATIC_KEY_FALSE(devmap_managed_key);
21EXPORT_SYMBOL(devmap_managed_key);
22static atomic_t devmap_managed_enable;
23
24static void devmap_managed_enable_put(void *data)
25{
26 if (atomic_dec_and_test(&devmap_managed_enable))
27 static_branch_disable(&devmap_managed_key);
28}
29
30static int devmap_managed_enable_get(struct device *dev, struct dev_pagemap *pgmap)
31{
32 if (!pgmap->ops->page_free) {
33 WARN(1, "Missing page_free method\n");
34 return -EINVAL;
35 }
36
37 if (atomic_inc_return(&devmap_managed_enable) == 1)
38 static_branch_enable(&devmap_managed_key);
39 return devm_add_action_or_reset(dev, devmap_managed_enable_put, NULL);
40}
41#else
42static int devmap_managed_enable_get(struct device *dev, struct dev_pagemap *pgmap)
43{
44 return -EINVAL;
45}
46#endif /* CONFIG_DEV_PAGEMAP_OPS */
47
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -040048static void pgmap_array_delete(struct resource *res)
Christoph Hellwig41e94a82015-08-17 16:00:35 +020049{
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -040050 xa_store_range(&pgmap_array, PHYS_PFN(res->start), PHYS_PFN(res->end),
51 NULL, GFP_KERNEL);
Dan Williamsab1b5972017-09-06 16:24:13 -070052 synchronize_rcu();
Dan Williams9476df72016-01-15 16:56:19 -080053}
54
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010055static unsigned long pfn_first(struct dev_pagemap *pgmap)
Dan Williams5c2c2582016-01-15 16:56:49 -080056{
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010057 const struct resource *res = &pgmap->res;
58 struct vmem_altmap *altmap = &pgmap->altmap;
Dan Williams5c2c2582016-01-15 16:56:49 -080059 unsigned long pfn;
60
61 pfn = res->start >> PAGE_SHIFT;
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010062 if (pgmap->altmap_valid)
Dan Williams5c2c2582016-01-15 16:56:49 -080063 pfn += vmem_altmap_offset(altmap);
64 return pfn;
65}
66
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010067static unsigned long pfn_end(struct dev_pagemap *pgmap)
Dan Williams5c2c2582016-01-15 16:56:49 -080068{
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010069 const struct resource *res = &pgmap->res;
Dan Williams5c2c2582016-01-15 16:56:49 -080070
71 return (res->start + resource_size(res)) >> PAGE_SHIFT;
72}
73
Dan Williams949b93252018-02-06 19:34:11 -080074static unsigned long pfn_next(unsigned long pfn)
75{
76 if (pfn % 1024 == 0)
77 cond_resched();
78 return pfn + 1;
79}
80
Dan Williams5c2c2582016-01-15 16:56:49 -080081#define for_each_device_pfn(pfn, map) \
Dan Williams949b93252018-02-06 19:34:11 -080082 for (pfn = pfn_first(map); pfn < pfn_end(map); pfn = pfn_next(pfn))
Dan Williams5c2c2582016-01-15 16:56:49 -080083
Christoph Hellwige8d51342017-12-29 08:54:05 +010084static void devm_memremap_pages_release(void *data)
Dan Williams9476df72016-01-15 16:56:19 -080085{
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010086 struct dev_pagemap *pgmap = data;
Christoph Hellwige8d51342017-12-29 08:54:05 +010087 struct device *dev = pgmap->dev;
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010088 struct resource *res = &pgmap->res;
Dan Williams9476df72016-01-15 16:56:19 -080089 resource_size_t align_start, align_size;
Dan Williams71389702017-04-28 10:23:37 -070090 unsigned long pfn;
Oscar Salvador2c2a5af2018-12-28 00:36:22 -080091 int nid;
Dan Williams71389702017-04-28 10:23:37 -070092
Christoph Hellwigd8668bb2019-06-26 14:27:09 +020093 pgmap->ops->kill(pgmap);
Logan Gunthorpee7744aa2017-12-29 08:54:04 +010094 for_each_device_pfn(pfn, pgmap)
Dan Williams71389702017-04-28 10:23:37 -070095 put_page(pfn_to_page(pfn));
Christoph Hellwigd8668bb2019-06-26 14:27:09 +020096 pgmap->ops->cleanup(pgmap);
Dan Williams9476df72016-01-15 16:56:19 -080097
Christoph Hellwig41e94a82015-08-17 16:00:35 +020098 /* pages are dead and unused, undo the arch mapping */
Dan Williams9476df72016-01-15 16:56:19 -080099 align_start = res->start & ~(SECTION_SIZE - 1);
Jan H. Schönherr10a0cd62018-01-19 16:27:54 -0800100 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
101 - align_start;
Dan Williamsb5d24fd2017-02-24 14:55:45 -0800102
Oscar Salvador2c2a5af2018-12-28 00:36:22 -0800103 nid = page_to_nid(pfn_to_page(align_start >> PAGE_SHIFT));
104
Dan Williamsf931ab42017-01-10 16:57:36 -0800105 mem_hotplug_begin();
Dan Williams69324b82018-12-28 00:35:01 -0800106 if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
107 pfn = align_start >> PAGE_SHIFT;
108 __remove_pages(page_zone(pfn_to_page(pfn)), pfn,
109 align_size >> PAGE_SHIFT, NULL);
110 } else {
Oscar Salvador2c2a5af2018-12-28 00:36:22 -0800111 arch_remove_memory(nid, align_start, align_size,
Dan Williams69324b82018-12-28 00:35:01 -0800112 pgmap->altmap_valid ? &pgmap->altmap : NULL);
113 kasan_remove_zero_shadow(__va(align_start), align_size);
114 }
Dan Williamsf931ab42017-01-10 16:57:36 -0800115 mem_hotplug_done();
Dan Williamsb5d24fd2017-02-24 14:55:45 -0800116
Dan Williams90497712016-09-07 08:51:21 -0700117 untrack_pfn(NULL, PHYS_PFN(align_start), align_size);
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -0400118 pgmap_array_delete(res);
Logan Gunthorpee7744aa2017-12-29 08:54:04 +0100119 dev_WARN_ONCE(dev, pgmap->altmap.alloc,
120 "%s: failed to free all reserved pages\n", __func__);
Dan Williams9476df72016-01-15 16:56:19 -0800121}
122
Dan Williams4b94ffd2016-01-15 16:56:22 -0800123/**
124 * devm_memremap_pages - remap and provide memmap backing for the given resource
125 * @dev: hosting device for @res
Dan Williamsa95c90f2018-12-28 00:34:57 -0800126 * @pgmap: pointer to a struct dev_pagemap
Dan Williams4b94ffd2016-01-15 16:56:22 -0800127 *
Dan Williams5c2c2582016-01-15 16:56:49 -0800128 * Notes:
Christoph Hellwig1e240e82019-06-26 14:27:08 +0200129 * 1/ At a minimum the res, ref and type and ops members of @pgmap must be
130 * initialized by the caller before passing it to this function
Christoph Hellwige8d51342017-12-29 08:54:05 +0100131 *
132 * 2/ The altmap field may optionally be initialized, in which case altmap_valid
133 * must be set to true
134 *
Dan Williams50f44ee2019-06-13 15:56:33 -0700135 * 3/ pgmap->ref must be 'live' on entry and will be killed and reaped
136 * at devm_memremap_pages_release() time, or if this routine fails.
Dan Williams5c2c2582016-01-15 16:56:49 -0800137 *
Christoph Hellwige8d51342017-12-29 08:54:05 +0100138 * 4/ res is expected to be a host memory range that could feasibly be
Dan Williams5c2c2582016-01-15 16:56:49 -0800139 * treated as a "System RAM" range, i.e. not a device mmio range, but
140 * this is not enforced.
Dan Williams4b94ffd2016-01-15 16:56:22 -0800141 */
Christoph Hellwige8d51342017-12-29 08:54:05 +0100142void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200143{
Dan Williamsab1b5972017-09-06 16:24:13 -0700144 resource_size_t align_start, align_size, align_end;
Christoph Hellwige8d51342017-12-29 08:54:05 +0100145 struct vmem_altmap *altmap = pgmap->altmap_valid ?
146 &pgmap->altmap : NULL;
Dan Williams949b93252018-02-06 19:34:11 -0800147 struct resource *res = &pgmap->res;
Dave Jiang15d36fe2018-07-26 16:37:15 -0700148 struct dev_pagemap *conflict_pgmap;
Michal Hocko940519f2019-05-13 17:21:26 -0700149 struct mhp_restrictions restrictions = {
150 /*
151 * We do not want any optional features only our own memmap
152 */
153 .altmap = altmap,
154 };
Alexander Duyck966cf442018-10-26 15:07:52 -0700155 pgprot_t pgprot = PAGE_KERNEL;
Alexander Duyck966cf442018-10-26 15:07:52 -0700156 int error, nid, is_ram;
Christoph Hellwigf6a55e12019-06-26 14:27:10 +0200157 bool need_devmap_managed = true;
Dan Williams5f29a772016-03-09 14:08:13 -0800158
Christoph Hellwig3ed2dcd2019-06-26 14:27:07 +0200159 switch (pgmap->type) {
160 case MEMORY_DEVICE_PRIVATE:
161 if (!IS_ENABLED(CONFIG_DEVICE_PRIVATE)) {
162 WARN(1, "Device private memory not supported\n");
163 return ERR_PTR(-EINVAL);
164 }
Christoph Hellwig897e6362019-06-26 14:27:11 +0200165 if (!pgmap->ops || !pgmap->ops->migrate_to_ram) {
166 WARN(1, "Missing migrate_to_ram method\n");
167 return ERR_PTR(-EINVAL);
168 }
Christoph Hellwig3ed2dcd2019-06-26 14:27:07 +0200169 break;
170 case MEMORY_DEVICE_FS_DAX:
171 if (!IS_ENABLED(CONFIG_ZONE_DEVICE) ||
172 IS_ENABLED(CONFIG_FS_DAX_LIMITED)) {
173 WARN(1, "File system DAX not supported\n");
174 return ERR_PTR(-EINVAL);
175 }
176 break;
177 case MEMORY_DEVICE_DEVDAX:
178 case MEMORY_DEVICE_PCI_P2PDMA:
Christoph Hellwigf6a55e12019-06-26 14:27:10 +0200179 need_devmap_managed = false;
Christoph Hellwig3ed2dcd2019-06-26 14:27:07 +0200180 break;
181 default:
182 WARN(1, "Invalid pgmap type %d\n", pgmap->type);
183 break;
184 }
185
Christoph Hellwig1e240e82019-06-26 14:27:08 +0200186 if (!pgmap->ref || !pgmap->ops || !pgmap->ops->kill ||
187 !pgmap->ops->cleanup) {
Dan Williams50f44ee2019-06-13 15:56:33 -0700188 WARN(1, "Missing reference count teardown definition\n");
Dan Williamsa95c90f2018-12-28 00:34:57 -0800189 return ERR_PTR(-EINVAL);
Dan Williams50f44ee2019-06-13 15:56:33 -0700190 }
Dan Williamsa95c90f2018-12-28 00:34:57 -0800191
Christoph Hellwigf6a55e12019-06-26 14:27:10 +0200192 if (need_devmap_managed) {
193 error = devmap_managed_enable_get(dev, pgmap);
194 if (error)
195 return ERR_PTR(error);
196 }
197
Dan Williams5f29a772016-03-09 14:08:13 -0800198 align_start = res->start & ~(SECTION_SIZE - 1);
199 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
200 - align_start;
Dave Jiang15d36fe2018-07-26 16:37:15 -0700201 align_end = align_start + align_size - 1;
202
203 conflict_pgmap = get_dev_pagemap(PHYS_PFN(align_start), NULL);
204 if (conflict_pgmap) {
205 dev_WARN(dev, "Conflicting mapping in same section\n");
206 put_dev_pagemap(conflict_pgmap);
Dan Williams50f44ee2019-06-13 15:56:33 -0700207 error = -ENOMEM;
208 goto err_array;
Dave Jiang15d36fe2018-07-26 16:37:15 -0700209 }
210
211 conflict_pgmap = get_dev_pagemap(PHYS_PFN(align_end), NULL);
212 if (conflict_pgmap) {
213 dev_WARN(dev, "Conflicting mapping in same section\n");
214 put_dev_pagemap(conflict_pgmap);
Dan Williams50f44ee2019-06-13 15:56:33 -0700215 error = -ENOMEM;
216 goto err_array;
Dave Jiang15d36fe2018-07-26 16:37:15 -0700217 }
218
Linus Torvaldsd37a14bb2016-03-14 15:15:51 -0700219 is_ram = region_intersects(align_start, align_size,
220 IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200221
Dan Williams06489cf2018-12-28 00:34:54 -0800222 if (is_ram != REGION_DISJOINT) {
223 WARN_ONCE(1, "%s attempted on %s region %pr\n", __func__,
224 is_ram == REGION_MIXED ? "mixed" : "ram", res);
Dan Williamsa95c90f2018-12-28 00:34:57 -0800225 error = -ENXIO;
226 goto err_array;
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200227 }
228
Dan Williams4b94ffd2016-01-15 16:56:22 -0800229 pgmap->dev = dev;
Dan Williams4b94ffd2016-01-15 16:56:22 -0800230
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -0400231 error = xa_err(xa_store_range(&pgmap_array, PHYS_PFN(res->start),
232 PHYS_PFN(res->end), pgmap, GFP_KERNEL));
Dan Williams9476df72016-01-15 16:56:19 -0800233 if (error)
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -0400234 goto err_array;
Dan Williams9476df72016-01-15 16:56:19 -0800235
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200236 nid = dev_to_node(dev);
237 if (nid < 0)
Dan Williams7eff93b2015-10-05 20:35:55 -0400238 nid = numa_mem_id();
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200239
Dan Williams90497712016-09-07 08:51:21 -0700240 error = track_pfn_remap(NULL, &pgprot, PHYS_PFN(align_start), 0,
241 align_size);
242 if (error)
243 goto err_pfn_remap;
244
Dan Williamsf931ab42017-01-10 16:57:36 -0800245 mem_hotplug_begin();
Dan Williams69324b82018-12-28 00:35:01 -0800246
247 /*
248 * For device private memory we call add_pages() as we only need to
249 * allocate and initialize struct page for the device memory. More-
250 * over the device memory is un-accessible thus we do not want to
251 * create a linear mapping for the memory like arch_add_memory()
252 * would do.
253 *
254 * For all other device memory types, which are accessible by
255 * the CPU, we do want the linear mapping and thus use
256 * arch_add_memory().
257 */
258 if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
259 error = add_pages(nid, align_start >> PAGE_SHIFT,
Michal Hocko940519f2019-05-13 17:21:26 -0700260 align_size >> PAGE_SHIFT, &restrictions);
Dan Williams69324b82018-12-28 00:35:01 -0800261 } else {
262 error = kasan_add_zero_shadow(__va(align_start), align_size);
263 if (error) {
264 mem_hotplug_done();
265 goto err_kasan;
266 }
267
Michal Hocko940519f2019-05-13 17:21:26 -0700268 error = arch_add_memory(nid, align_start, align_size,
269 &restrictions);
Andrey Ryabinin0207df42018-08-17 15:47:04 -0700270 }
271
Dan Williams69324b82018-12-28 00:35:01 -0800272 if (!error) {
273 struct zone *zone;
274
275 zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE];
276 move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT,
277 align_size >> PAGE_SHIFT, altmap);
278 }
279
Dan Williamsf931ab42017-01-10 16:57:36 -0800280 mem_hotplug_done();
Dan Williams9476df72016-01-15 16:56:19 -0800281 if (error)
282 goto err_add_memory;
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200283
Alexander Duyck966cf442018-10-26 15:07:52 -0700284 /*
285 * Initialization of the pages has been deferred until now in order
286 * to allow us to do the work while not holding the hotplug lock.
287 */
288 memmap_init_zone_device(&NODE_DATA(nid)->node_zones[ZONE_DEVICE],
289 align_start >> PAGE_SHIFT,
290 align_size >> PAGE_SHIFT, pgmap);
291 percpu_ref_get_many(pgmap->ref, pfn_end(pgmap) - pfn_first(pgmap));
Christoph Hellwige8d51342017-12-29 08:54:05 +0100292
Dan Williamsa95c90f2018-12-28 00:34:57 -0800293 error = devm_add_action_or_reset(dev, devm_memremap_pages_release,
294 pgmap);
295 if (error)
296 return ERR_PTR(error);
Christoph Hellwige8d51342017-12-29 08:54:05 +0100297
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200298 return __va(res->start);
Dan Williams9476df72016-01-15 16:56:19 -0800299
300 err_add_memory:
Andrey Ryabinin0207df42018-08-17 15:47:04 -0700301 kasan_remove_zero_shadow(__va(align_start), align_size);
302 err_kasan:
Dan Williams90497712016-09-07 08:51:21 -0700303 untrack_pfn(NULL, PHYS_PFN(align_start), align_size);
304 err_pfn_remap:
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -0400305 pgmap_array_delete(res);
306 err_array:
Christoph Hellwigd8668bb2019-06-26 14:27:09 +0200307 pgmap->ops->kill(pgmap);
308 pgmap->ops->cleanup(pgmap);
Dan Williams9476df72016-01-15 16:56:19 -0800309 return ERR_PTR(error);
Christoph Hellwig41e94a82015-08-17 16:00:35 +0200310}
Dan Williams808153e2018-12-28 00:34:50 -0800311EXPORT_SYMBOL_GPL(devm_memremap_pages);
Dan Williams4b94ffd2016-01-15 16:56:22 -0800312
Dan Williams2e3f1392019-06-13 15:56:21 -0700313void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap)
314{
315 devm_release_action(dev, devm_memremap_pages_release, pgmap);
316}
317EXPORT_SYMBOL_GPL(devm_memunmap_pages);
318
Dan Williams4b94ffd2016-01-15 16:56:22 -0800319unsigned long vmem_altmap_offset(struct vmem_altmap *altmap)
320{
321 /* number of pfns from base where pfn_to_page() is valid */
322 return altmap->reserve + altmap->free;
323}
324
325void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns)
326{
327 altmap->alloc -= nr_pfns;
328}
329
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100330/**
331 * get_dev_pagemap() - take a new live reference on the dev_pagemap for @pfn
332 * @pfn: page frame number to lookup page_map
333 * @pgmap: optional known pgmap that already has a reference
334 *
Christoph Hellwig832d7aa2017-12-29 08:54:01 +0100335 * If @pgmap is non-NULL and covers @pfn it will be returned as-is. If @pgmap
336 * is non-NULL but does not cover @pfn the reference to it will be released.
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100337 */
338struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
339 struct dev_pagemap *pgmap)
340{
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100341 resource_size_t phys = PFN_PHYS(pfn);
342
343 /*
Christoph Hellwig832d7aa2017-12-29 08:54:01 +0100344 * In the cached case we're already holding a live reference.
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100345 */
Christoph Hellwig832d7aa2017-12-29 08:54:01 +0100346 if (pgmap) {
Logan Gunthorpee7744aa2017-12-29 08:54:04 +0100347 if (phys >= pgmap->res.start && phys <= pgmap->res.end)
Christoph Hellwig832d7aa2017-12-29 08:54:01 +0100348 return pgmap;
349 put_dev_pagemap(pgmap);
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100350 }
351
352 /* fall back to slow path lookup */
353 rcu_read_lock();
Matthew Wilcoxbcfa4b72018-08-15 14:22:16 -0400354 pgmap = xa_load(&pgmap_array, PHYS_PFN(phys));
Christoph Hellwig0822acb2017-12-29 08:54:00 +0100355 if (pgmap && !percpu_ref_tryget_live(pgmap->ref))
356 pgmap = NULL;
357 rcu_read_unlock();
358
359 return pgmap;
360}
Dan Williamse76384882018-05-16 11:46:08 -0700361EXPORT_SYMBOL_GPL(get_dev_pagemap);
Jérôme Glisse7b2d55d22017-09-08 16:11:46 -0700362
Dan Williamse76384882018-05-16 11:46:08 -0700363#ifdef CONFIG_DEV_PAGEMAP_OPS
Dan Williamse76384882018-05-16 11:46:08 -0700364void __put_devmap_managed_page(struct page *page)
Jérôme Glisse7b2d55d22017-09-08 16:11:46 -0700365{
366 int count = page_ref_dec_return(page);
367
368 /*
369 * If refcount is 1 then page is freed and refcount is stable as nobody
370 * holds a reference on the page.
371 */
372 if (count == 1) {
373 /* Clear Active bit in case of parallel mark_page_accessed */
374 __ClearPageActive(page);
375 __ClearPageWaiters(page);
376
Jérôme Glissec733a822017-09-08 16:11:54 -0700377 mem_cgroup_uncharge(page);
Jérôme Glisse7b2d55d22017-09-08 16:11:46 -0700378
Christoph Hellwig80a72d02019-06-26 14:27:12 +0200379 page->pgmap->ops->page_free(page);
Jérôme Glisse7b2d55d22017-09-08 16:11:46 -0700380 } else if (!count)
381 __put_page(page);
382}
Dan Williams31c5bda2018-07-26 16:37:22 -0700383EXPORT_SYMBOL(__put_devmap_managed_page);
Dan Williamse76384882018-05-16 11:46:08 -0700384#endif /* CONFIG_DEV_PAGEMAP_OPS */