Skip to content

Commit 33dd707

Browse files
djbwrafaeljw
authored andcommitted
lib: Uplevel the pmem "region" ida to a global allocator
In preparation for handling platform differentiated memory types beyond persistent memory, uplevel the "region" identifier to a global number space. This enables a device-dax instance to be registered to any memory type with guaranteed unique names. Signed-off-by: Dan Williams <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 199c847 commit 33dd707

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

drivers/nvdimm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ menuconfig LIBNVDIMM
44
depends on PHYS_ADDR_T_64BIT
55
depends on HAS_IOMEM
66
depends on BLK_DEV
7+
select MEMREGION
78
help
89
Generic support for non-volatile memory devices including
910
ACPI-6-NFIT defined resources. On platforms that define an

drivers/nvdimm/core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ static __exit void libnvdimm_exit(void)
455455
nd_region_exit();
456456
nvdimm_exit();
457457
nvdimm_bus_exit();
458-
nd_region_devs_exit();
459458
nvdimm_devs_exit();
460459
}
461460

drivers/nvdimm/nd-core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
114114
int __init nvdimm_bus_init(void);
115115
void nvdimm_bus_exit(void);
116116
void nvdimm_devs_exit(void);
117-
void nd_region_devs_exit(void);
118117
struct nd_region;
119118
void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
120119
void nd_region_create_ns_seed(struct nd_region *nd_region);

drivers/nvdimm/region_devs.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
44
*/
55
#include <linux/scatterlist.h>
6+
#include <linux/memregion.h>
67
#include <linux/highmem.h>
78
#include <linux/sched.h>
89
#include <linux/slab.h>
@@ -19,7 +20,6 @@
1920
*/
2021
#include <linux/io-64-nonatomic-hi-lo.h>
2122

22-
static DEFINE_IDA(region_ida);
2323
static DEFINE_PER_CPU(int, flush_idx);
2424

2525
static int nvdimm_map_flush(struct device *dev, struct nvdimm *nvdimm, int dimm,
@@ -133,7 +133,7 @@ static void nd_region_release(struct device *dev)
133133
put_device(&nvdimm->dev);
134134
}
135135
free_percpu(nd_region->lane);
136-
ida_simple_remove(&region_ida, nd_region->id);
136+
memregion_free(nd_region->id);
137137
if (is_nd_blk(dev))
138138
kfree(to_nd_blk_region(dev));
139139
else
@@ -985,7 +985,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
985985

986986
if (!region_buf)
987987
return NULL;
988-
nd_region->id = ida_simple_get(&region_ida, 0, 0, GFP_KERNEL);
988+
nd_region->id = memregion_alloc(GFP_KERNEL);
989989
if (nd_region->id < 0)
990990
goto err_id;
991991

@@ -1044,7 +1044,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
10441044
return nd_region;
10451045

10461046
err_percpu:
1047-
ida_simple_remove(&region_ida, nd_region->id);
1047+
memregion_free(nd_region->id);
10481048
err_id:
10491049
kfree(region_buf);
10501050
return NULL;
@@ -1216,8 +1216,3 @@ int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
12161216

12171217
return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict);
12181218
}
1219-
1220-
void __exit nd_region_devs_exit(void)
1221-
{
1222-
ida_destroy(&region_ida);
1223-
}

include/linux/memregion.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _MEMREGION_H_
3+
#define _MEMREGION_H_
4+
#include <linux/types.h>
5+
#include <linux/errno.h>
6+
7+
#ifdef CONFIG_MEMREGION
8+
int memregion_alloc(gfp_t gfp);
9+
void memregion_free(int id);
10+
#else
11+
static inline int memregion_alloc(gfp_t gfp)
12+
{
13+
return -ENOMEM;
14+
}
15+
void memregion_free(int id)
16+
{
17+
}
18+
#endif
19+
#endif /* _MEMREGION_H_ */

lib/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ config ARCH_NO_SG_CHAIN
606606
config ARCH_HAS_PMEM_API
607607
bool
608608

609+
config MEMREGION
610+
bool
611+
609612
# use memcpy to implement user copies for nommu architectures
610613
config UACCESS_MEMCPY
611614
bool

lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o
212212

213213
obj-$(CONFIG_SG_SPLIT) += sg_split.o
214214
obj-$(CONFIG_SG_POOL) += sg_pool.o
215+
obj-$(CONFIG_MEMREGION) += memregion.o
215216
obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
216217
obj-$(CONFIG_IRQ_POLL) += irq_poll.o
217218

lib/memregion.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/* identifiers for device / performance-differentiated memory regions */
3+
#include <linux/idr.h>
4+
#include <linux/types.h>
5+
6+
static DEFINE_IDA(memregion_ids);
7+
8+
int memregion_alloc(gfp_t gfp)
9+
{
10+
return ida_alloc(&memregion_ids, gfp);
11+
}
12+
EXPORT_SYMBOL(memregion_alloc);
13+
14+
void memregion_free(int id)
15+
{
16+
ida_free(&memregion_ids, id);
17+
}
18+
EXPORT_SYMBOL(memregion_free);

0 commit comments

Comments
 (0)