From: Dan Williams <dan.j.williams@intel.com> To: mingo@redhat.com Cc: Keith Busch <kbusch@kernel.org>, peterz@infradead.org, dave.hansen@linux.intel.com, ard.biesheuvel@linaro.org, x86@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-efi@vger.kernel.org Subject: [PATCH v8 08/12] lib: Uplevel the pmem "region" ida to a global allocator Date: Wed, 06 Nov 2019 17:43:31 -0800 Message-ID: <157309101170.1579826.1637173575943713427.stgit@dwillia2-desk3.amr.corp.intel.com> (raw) In-Reply-To: <157309097008.1579826.12818463304589384434.stgit@dwillia2-desk3.amr.corp.intel.com> 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. Cc: Keith Busch <kbusch@kernel.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/nvdimm/Kconfig | 1 + drivers/nvdimm/core.c | 1 - drivers/nvdimm/nd-core.h | 1 - drivers/nvdimm/region_devs.c | 13 ++++--------- include/linux/memregion.h | 19 +++++++++++++++++++ lib/Kconfig | 3 +++ lib/Makefile | 1 + lib/memregion.c | 18 ++++++++++++++++++ 8 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 include/linux/memregion.h create mode 100644 lib/memregion.c diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 36af7af6b7cf..b7d1eb38b27d 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -4,6 +4,7 @@ menuconfig LIBNVDIMM depends on PHYS_ADDR_T_64BIT depends on HAS_IOMEM depends on BLK_DEV + select MEMREGION help Generic support for non-volatile memory devices including ACPI-6-NFIT defined resources. On platforms that define an diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c index 9204f1e9fd14..e592c4964674 100644 --- a/drivers/nvdimm/core.c +++ b/drivers/nvdimm/core.c @@ -455,7 +455,6 @@ static __exit void libnvdimm_exit(void) nd_region_exit(); nvdimm_exit(); nvdimm_bus_exit(); - nd_region_devs_exit(); nvdimm_devs_exit(); } diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index 25fa121104d0..aa059439fca0 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -114,7 +114,6 @@ struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev); int __init nvdimm_bus_init(void); void nvdimm_bus_exit(void); void nvdimm_devs_exit(void); -void nd_region_devs_exit(void); struct nd_region; void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev); void nd_region_create_ns_seed(struct nd_region *nd_region); diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index ef423ba1a711..fbf34cf688f4 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -3,6 +3,7 @@ * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. */ #include <linux/scatterlist.h> +#include <linux/memregion.h> #include <linux/highmem.h> #include <linux/sched.h> #include <linux/slab.h> @@ -19,7 +20,6 @@ */ #include <linux/io-64-nonatomic-hi-lo.h> -static DEFINE_IDA(region_ida); static DEFINE_PER_CPU(int, flush_idx); 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) put_device(&nvdimm->dev); } free_percpu(nd_region->lane); - ida_simple_remove(®ion_ida, nd_region->id); + memregion_free(nd_region->id); if (is_nd_blk(dev)) kfree(to_nd_blk_region(dev)); else @@ -985,7 +985,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, if (!region_buf) return NULL; - nd_region->id = ida_simple_get(®ion_ida, 0, 0, GFP_KERNEL); + nd_region->id = memregion_alloc(GFP_KERNEL); if (nd_region->id < 0) goto err_id; @@ -1044,7 +1044,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, return nd_region; err_percpu: - ida_simple_remove(®ion_ida, nd_region->id); + memregion_free(nd_region->id); err_id: kfree(region_buf); return NULL; @@ -1216,8 +1216,3 @@ int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict); } - -void __exit nd_region_devs_exit(void) -{ - ida_destroy(®ion_ida); -} diff --git a/include/linux/memregion.h b/include/linux/memregion.h new file mode 100644 index 000000000000..7de7c0a1444e --- /dev/null +++ b/include/linux/memregion.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _MEMREGION_H_ +#define _MEMREGION_H_ +#include <linux/types.h> +#include <linux/errno.h> + +#ifdef CONFIG_MEMREGION +int memregion_alloc(gfp_t gfp); +void memregion_free(int id); +#else +static inline int memregion_alloc(gfp_t gfp) +{ + return -ENOMEM; +} +void memregion_free(int id) +{ +} +#endif +#endif /* _MEMREGION_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index 183f92a297ca..0dc043ac271d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -606,6 +606,9 @@ config ARCH_NO_SG_CHAIN config ARCH_HAS_PMEM_API bool +config MEMREGION + bool + # use memcpy to implement user copies for nommu architectures config UACCESS_MEMCPY bool diff --git a/lib/Makefile b/lib/Makefile index c5892807e06f..2fb7b47018f1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -212,6 +212,7 @@ obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o obj-$(CONFIG_SG_SPLIT) += sg_split.o obj-$(CONFIG_SG_POOL) += sg_pool.o +obj-$(CONFIG_MEMREGION) += memregion.o obj-$(CONFIG_STMP_DEVICE) += stmp_device.o obj-$(CONFIG_IRQ_POLL) += irq_poll.o diff --git a/lib/memregion.c b/lib/memregion.c new file mode 100644 index 000000000000..77c85b5251da --- /dev/null +++ b/lib/memregion.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* identifiers for device / performance-differentiated memory regions */ +#include <linux/idr.h> +#include <linux/types.h> + +static DEFINE_IDA(memregion_ids); + +int memregion_alloc(gfp_t gfp) +{ + return ida_alloc(&memregion_ids, gfp); +} +EXPORT_SYMBOL(memregion_alloc); + +void memregion_free(int id) +{ + ida_free(&memregion_ids, id); +} +EXPORT_SYMBOL(memregion_free); _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply index Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-11-07 1:42 [PATCH v8 00/12] EFI Specific Purpose Memory Support Dan Williams 2019-11-07 1:42 ` [PATCH v8 01/12] acpi/numa: Establish a new drivers/acpi/numa/ directory Dan Williams 2019-11-07 1:43 ` [PATCH v8 02/12] efi: Enumerate EFI_MEMORY_SP Dan Williams 2019-11-07 1:43 ` [PATCH v8 03/12] x86/efi: Push EFI_MEMMAP check into leaf routines Dan Williams 2019-11-07 1:43 ` [PATCH v8 04/12] efi: Common enable/disable infrastructure for EFI soft reservation Dan Williams 2019-11-07 1:43 ` [PATCH v8 05/12] x86/efi: EFI soft reservation to E820 enumeration Dan Williams 2019-11-07 1:43 ` [PATCH v8 06/12] arm/efi: EFI soft reservation to memblock Dan Williams 2019-11-07 1:43 ` [PATCH v8 07/12] x86/efi: Add efi_fake_mem support for EFI_MEMORY_SP Dan Williams 2019-11-07 1:43 ` Dan Williams [this message] 2019-11-07 1:43 ` [PATCH v8 09/12] dax: Fix alloc_dax_region() compile warning Dan Williams 2019-11-07 1:43 ` [PATCH v8 10/12] device-dax: Add a driver for "hmem" devices Dan Williams 2019-11-07 1:43 ` [PATCH v8 11/12] acpi/numa/hmat: Register HMAT at device_initcall level Dan Williams 2019-11-07 1:43 ` [PATCH v8 12/12] acpi/numa/hmat: Register "soft reserved" memory as an "hmem" device Dan Williams 2019-11-07 12:46 ` [PATCH v8 00/12] EFI Specific Purpose Memory Support Rafael J. Wysocki 2019-11-07 13:48 ` Thomas Gleixner 2019-11-07 14:12 ` Rafael J. Wysocki
Reply instructions: You may reply publically to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=157309101170.1579826.1637173575943713427.stgit@dwillia2-desk3.amr.corp.intel.com \ --to=dan.j.williams@intel.com \ --cc=ard.biesheuvel@linaro.org \ --cc=dave.hansen@linux.intel.com \ --cc=kbusch@kernel.org \ --cc=linux-acpi@vger.kernel.org \ --cc=linux-efi@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-nvdimm@lists.01.org \ --cc=mingo@redhat.com \ --cc=peterz@infradead.org \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Linux-NVDIMM Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/linux-nvdimm/0 linux-nvdimm/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-nvdimm linux-nvdimm/ https://lore.kernel.org/linux-nvdimm \ linux-nvdimm@lists.01.org public-inbox-index linux-nvdimm Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.01.lists.linux-nvdimm AGPL code for this site: git clone https://public-inbox.org/public-inbox.git