Support for Open-Channel SSDs
Subsystems (3)
v7 cover Support for Open-Channel SSDs
These patches implement support for Open-Channel SSDs.
Applies against axboe's linux-block/for-4.3/drivers and can be found in the lkml_v7 branch at https://github.com/OpenChannelSSD/linux
Any feedback is greatly appreciated.
Changes since v6:
- Multipage support (Javier Gonzalez)
- General code cleanups
- Fixed memleak on register failure
Changes since v5:
Feedback from Christoph Hellwig.
- Created new null_nvm from null_blk to register itself as a lightnvm device.
- Changed the interface of register/unregister to only take disk_name. The gendisk alloc in nvme is kept. Most instantiations will involve the device gendisk, therefore wait with refactoring to a later time.
- Renamed global parameters in core.c and rrpc.c
Changes since v4:
- Remove gendisk->nvm dependency
- Remove device driver rq private field dependency.
- Update submission and completion. The flow is now
Target -> Block Manager -> Device Driver, replacing callbacks in
device driver. - Abstracted out the block manager into its own module. Other block managers can now be implemented. For example to support fully host-based SSDs.
- No longer exposes the device driver gendisk to user-space.
- Management is moved into /sys/modules/lnvm/parameters/configure_debug
Changes since v3:
- Remove dependency on REQ_NVM_GC
- Refactor nvme integration to use nvme_submit_sync_cmd for internal commands.
- Fix race condition bug on multiple threads on RRPC target.
- Rename sysfs entry under the block device from nvm to lightnvm. The configuration is found in /sys/block/*/lightnvm/
Changes since v2:
Feedback from Paul Bolle:
- Fix license to GPLv2, documentation, compilation. Feedback from Keith Busch:
- nvme: Move lightnvm out and into nvme-lightnvm.c.
- nvme: Set controller css on lightnvm command set.
- nvme: Remove OACS.
Feedback from Christoph Hellwig:
- lightnvm: Move out of block layer into /drivers/lightnvm/core.c
- lightnvm: refactor request->phys_sector into device drivers.
- lightnvm: refactor prep/unprep into device drivers.
- lightnvm: move nvm_dev from request_queue to gendisk.
New
- Bad block table support (From Javier).
- Update maintainers file.
Changes since v1:
- Splitted LightNVM into two parts. A get/put interface for flash blocks and the respective targets that implement flash translation layer logic.
- Updated the patches according to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.
Thanks to Jens Axboe, Christoph Hellwig, Keith Busch, Paul Bolle, Javier Gonzalez and Jesper Madsen for discussions and contributions.
Matias Bjørling (5):
lightnvm: Support for Open-Channel SSDs
lightnvm: Hybrid Open-Channel SSD RRPC target
lightnvm: Hybrid Open-Channel SSD block manager
null_nvm: Lightnvm test driver
nvme: LightNVM support
MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 5 + drivers/block/Makefile | 2 +- drivers/block/nvme-core.c | 23 +- drivers/block/nvme-lightnvm.c | 568 ++++++++++++++++++ drivers/lightnvm/Kconfig | 36 ++ drivers/lightnvm/Makefile | 8 + drivers/lightnvm/bm_hb.c | 366 ++++++++++++ drivers/lightnvm/bm_hb.h | 46 ++ drivers/lightnvm/core.c | 591 +++++++++++++++++++ drivers/lightnvm/null_nvm.c | 481 +++++++++++++++ drivers/lightnvm/rrpc.c | 1296 +++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/rrpc.h | 236 ++++++++ include/linux/lightnvm.h | 334 +++++++++++ include/linux/nvme.h | 6 + include/uapi/linux/nvme.h | 3 + 17 files changed, 4007 insertions(+), 4 deletions(-) create mode 100644 drivers/block/nvme-lightnvm.c create mode 100644 drivers/lightnvm/Kconfig create mode 100644 drivers/lightnvm/Makefile create mode 100644 drivers/lightnvm/bm_hb.c create mode 100644 drivers/lightnvm/bm_hb.h create mode 100644 drivers/lightnvm/core.c create mode 100644 drivers/lightnvm/null_nvm.c create mode 100644 drivers/lightnvm/rrpc.c create mode 100644 drivers/lightnvm/rrpc.h create mode 100644 include/linux/lightnvm.h
Signature · 1 line
2.1.4
PATCH v7 1/5 lightnvm: Support for Open-Channel SSDs
Open-channel SSDs are devices that share responsibilities with the host in order to implement and maintain features that typical SSDs keep strictly in firmware. These include (i) the Flash Translation Layer (FTL), (ii) bad block management, and (iii) hardware units such as the flash controller, the interface controller, and large amounts of flash chips. In this way, Open-channels SSDs exposes direct access to their physical flash storage, while keeping a subset of the internal features of SSDs.
LightNVM is a specification that gives support to Open-channel SSDs LightNVM allows the host to manage data placement, garbage collection, and parallelism. Device specific responsibilities such as bad block management, FTL extensions to support atomic IOs, or metadata persistence are still handled by the device.
The implementation of LightNVM consists of two parts: core and (multiple) targets. The core implements functionality shared across targets. This is initialization, teardown and statistics. The targets implement the interface that exposes physical flash to user-space applications. Examples of such targets include key-value store, object-store, as well as traditional block devices, which can be application-specific.
Contributions in this patch from:
Javier Gonzalez <jg at lightnvm.io>
Jesper Madsen <jmad at itu.dk>
--- MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 5 + drivers/lightnvm/Kconfig | 16 ++ drivers/lightnvm/Makefile | 5 + drivers/lightnvm/core.c | 590 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/lightnvm.h | 335 ++++++++++++++++++++++++++ 7 files changed, 961 insertions(+) create mode 100644 drivers/lightnvm/Kconfig create mode 100644 drivers/lightnvm/Makefile create mode 100644 drivers/lightnvm/core.c create mode 100644 include/linux/lightnvm.h
MAINTAINERS +8 -0
@@ -6162,6 +6162,14 @@ S: Supported F: drivers/nvdimm/pmem.c F: include/linux/pmem.h +LIGHTNVM PLATFORM SUPPORT +M: Matias Bjorling <mb at lightnvm.io> +W: http://github/OpenChannelSSD +S: Maintained +F: drivers/lightnvm/ +F: include/linux/lightnvm.h +F: include/uapi/linux/lightnvm.h + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras <paulus at au.ibm.com> W: http://www.ibm.com/linux/ltc/projects/ppc
drivers/Kconfig +2 -0
@@ -42,6 +42,8 @@ source "drivers/net/Kconfig" source "drivers/isdn/Kconfig" +source "drivers/lightnvm/Kconfig" + # input before char - char/joystick depends on it. As does USB. source "drivers/input/Kconfig"
drivers/Makefile +5 -0
@@ -63,6 +63,10 @@ obj-$(CONFIG_FB_I810) += video/fbdev/i810/ obj-$(CONFIG_FB_INTEL) += video/fbdev/intelfb/ obj-$(CONFIG_PARPORT) += parport/ + +# lightnvm/ comes before block to initialize bm before usage +obj-$(CONFIG_NVM) += lightnvm/ + obj-y += base/ block/ misc/ mfd/ nfc/ obj-$(CONFIG_LIBNVDIMM) += nvdimm/ obj-$(CONFIG_DMA_SHARED_BUFFER) += dma-buf/
@@ -165,3 +169,4 @@ obj-$(CONFIG_RAS) += ras/ obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-$(CONFIG_ANDROID) += android/ +
drivers/lightnvm/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# +# Open-Channel SSD NVM configuration +# + +menuconfig NVM + bool "Open-Channel SSD target support" + depends on BLOCK + help + Say Y here to get to enable Open-channel SSDs. + + Open-Channel SSDs implement a set of extension to SSDs, that + exposes direct access to the underlying non-volatile memory. + + If you say N, all options in this submenu will be skipped and disabled + only do this if you know what you are doing. +
drivers/lightnvm/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for Open-Channel SSDs. +# + +obj-$(CONFIG_NVM) := core.o
drivers/lightnvm/core.c new file +590 -0
590 lines not on this page · raw message
include/linux/lightnvm.h new file +335 -0
335 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 386 lines · Matias Bj?rling
Open-channel SSDs are devices that share responsibilities with the host in order to implement and maintain features that typical SSDs keep strictly in firmware. These include (i) the Flash Translation Layer (FTL), (ii) bad block management, and (iii) hardware units such as the flash controller, the interface controller, and large amounts of flash chips. In this way, Open-channels SSDs exposes direct access to their physical flash storage, while keeping a subset of the internal features of SSDs.
LightNVM is a specification that gives support to Open-channel SSDs LightNVM allows the host to manage data placement, garbage collection, and parallelism. Device specific responsibilities such as bad block management, FTL extensions to support atomic IOs, or metadata persistence are still handled by the device.
The implementation of LightNVM consists of two parts: core and (multiple) targets. The core implements functionality shared across targets. This is initialization, teardown and statistics. The targets implement the interface that exposes physical flash to user-space applications. Examples of such targets include key-value store, object-store, as well as traditional block devices, which can be application-specific.
Contributions in this patch from:
Javier Gonzalez <jg at lightnvm.io>
Jesper Madsen <jmad at itu.dk>Signed-off-by Matias Bj?rling <mb at lightnvm.io>--- MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 5 + drivers/lightnvm/Kconfig | 16 ++ drivers/lightnvm/Makefile | 5 + drivers/lightnvm/core.c | 590 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/lightnvm.h | 335 ++++++++++++++++++++++++++ 7 files changed, 961 insertions(+)create mode 100644
drivers/lightnvm/Kconfig
create mode 100644drivers/lightnvm/Makefile
create mode 100644drivers/lightnvm/core.c
create mode 100644include/linux/lightnvm.hMAINTAINERS +8
-0@@ -6162,6 +6162,14 @@ S: Supported F: drivers/nvdimm/pmem.c F: include/linux/pmem.h +LIGHTNVM PLATFORM SUPPORT +M: Matias Bjorling <mb at lightnvm.io> +W: http://github/OpenChannelSSD +S: Maintained +F: drivers/lightnvm/ +F: include/linux/lightnvm.h +F: include/uapi/linux/lightnvm.h + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras <paulus at au.ibm.com> W: http://www.ibm.com/linux/ltc/projects/ppcdrivers/Kconfig +2
-0@@ -42,6 +42,8 @@ source "drivers/net/Kconfig" source "drivers/isdn/Kconfig" +source "drivers/lightnvm/Kconfig" + # input before char - char/joystick depends on it. As does USB. source "drivers/input/Kconfig"drivers/Makefile +5
-0@@ -63,6 +63,10 @@ obj-$(CONFIG_FB_I810) += video/fbdev/i810/ obj-$(CONFIG_FB_INTEL) += video/fbdev/intelfb/ obj-$(CONFIG_PARPORT) += parport/ + +# lightnvm/ comes before block to initialize bm before usage +obj-$(CONFIG_NVM) += lightnvm/ + obj-y += base/ block/ misc/ mfd/ nfc/ obj-$(CONFIG_LIBNVDIMM) += nvdimm/ obj-$(CONFIG_DMA_SHARED_BUFFER) += dma-buf/@@ -165,3 +169,4 @@ obj-$(CONFIG_RAS) += ras/ obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-$(CONFIG_ANDROID) += android/ +drivers/lightnvm/Kconfig new file +16
-0@@ -0,0 +1,16 @@ +# +# Open-Channel SSD NVM configuration +# + +menuconfig NVM + bool "Open-Channel SSD target support" + depends on BLOCK + help + Say Y here to get to enable Open-channel SSDs. + + Open-Channel SSDs implement a set of extension to SSDs, that + exposes direct access to the underlying non-volatile memory. + + If you say N, all options in this submenu will be skipped and disabled + only do this if you know what you are doing. +drivers/lightnvm/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Makefile for Open-Channel SSDs. +# + +obj-$(CONFIG_NVM) := core.odrivers/lightnvm/core.c new file +252
-0@@ -0,0 +1,590 @@ +/* +* Copyright (C) 2015 IT University of Copenhagen +* Initial release: Matias Bjorling <mabj at itu.dk> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, +* USA. +* +*/ + +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/sem.h> +#include <linux/bitmap.h> +#include <linux/module.h> + +#include <linux/lightnvm.h> + +static LIST_HEAD (nvm_targets); +static LIST_HEAD (nvm_bms); +static LIST_HEAD (nvm_devices); +static DECLARE_RWSEM (nvm_lock); + +struct nvm_tgt_type *nvm_find_target_type (const char *name) +{ +struct nvm_tgt_type *tt; + +list_for_each_entry (tt, &nvm_targets, list) +if (!strcmp (name, tt->name)) +return tt; + +return NULL ; +} + +int nvm_register_target (struct nvm_tgt_type *tt) +{ +int ret =0 ; + +down_write (&nvm_lock); +if (nvm_find_target_type (tt->name)) + ret = -EEXIST ; +else +list_add (&tt->list, &nvm_targets); +up_write (&nvm_lock); + +return ret; +} +EXPORT_SYMBOL (nvm_register_target); + +void nvm_unregister_target (struct nvm_tgt_type *tt) +{ +if (!tt) +return ; + +down_write (&nvm_lock); +list_del (&tt->list); +up_write (&nvm_lock); +} +EXPORT_SYMBOL (nvm_unregister_target); + +void *nvm_alloc_ppalist (struct nvm_dev *dev,gfp_t mem_flags, +dma_addr_t *dma_handler) +{ +return dev->ops->alloc_ppalist (dev->q, dev->ppalist_pool, mem_flags, + dma_handler); +} +EXPORT_SYMBOL (nvm_alloc_ppalist); + +void nvm_free_ppalist (struct nvm_dev *dev,void *ppa_list, +dma_addr_t dma_handler) +{ + dev->ops->free_ppalist (dev->ppalist_pool, ppa_list, dma_handler); +} +EXPORT_SYMBOL (nvm_free_ppalist); + +struct nvm_bm_type *nvm_find_bm_type (const char *name) +{ +struct nvm_bm_type *bt; + +list_for_each_entry (bt, &nvm_bms, list) +if (!strcmp (name, bt->name)) +return bt; + +return NULL ; +} + +int nvm_register_bm (struct nvm_bm_type *bt) +{ +int ret =0 ; + +down_write (&nvm_lock); +if (nvm_find_bm_type (bt->name)) + ret = -EEXIST ; +else +list_add (&bt->list, &nvm_bms); +up_write (&nvm_lock); + +return ret; +} +EXPORT_SYMBOL (nvm_register_bm); + +void nvm_unregister_bm (struct nvm_bm_type *bt) +{ +if (!bt) +return ; + +down_write (&nvm_lock); +list_del (&bt->list); +up_write (&nvm_lock); +} +EXPORT_SYMBOL (nvm_unregister_bm); + +struct nvm_dev *nvm_find_nvm_dev (const char *name) +{ +struct nvm_dev *dev; + +list_for_each_entry (dev, &nvm_devices, devices) +if (!strcmp (name, dev->name)) +return dev; + +return NULL ; +} + +struct nvm_block *nvm_get_blk (struct nvm_dev *dev,struct nvm_lun *lun, +unsigned long flags) +{ +return dev->bm->get_blk (dev, lun, flags); +} +EXPORT_SYMBOL (nvm_get_blk); + +/* Assumes that all valid pages have already been moved on release to bm */ +void nvm_put_blk (struct nvm_dev *dev,struct nvm_block *blk) +{ +return dev->bm->put_blk (dev, blk); +} +EXPORT_SYMBOL (nvm_put_blk); + +int nvm_submit_io (struct nvm_dev *dev,struct nvm_rq *rqd) +{ +return dev->ops->submit_io (dev->q, rqd); +} +EXPORT_SYMBOL (nvm_submit_io); + +/* Send erase command to device */ +int nvm_erase_blk (struct nvm_dev *dev,struct nvm_block *blk) +{ +return dev->bm->erase_blk (dev, blk); +} +EXPORT_SYMBOL (nvm_erase_blk); + +static void nvm_core_free (struct nvm_dev *dev) +{ +kfree (dev->identity.chnls); +kfree (dev); +} + +static int nvm_core_init (struct nvm_dev *dev) +{ + dev->nr_luns = dev->identity.nchannels; + dev->sector_size =EXPOSED_PAGE_SIZE ; +INIT_LIST_HEAD (&dev->online_targets); + +return 0 ; +} + +static void nvm_free (struct nvm_dev *dev) +{ +if (!dev) +return ; + +if (dev->bm) + dev->bm->unregister_bm (dev); + +nvm_core_free (dev); +} + +int nvm_validate_features (struct nvm_dev *dev) +{ +struct nvm_get_features gf; +int ret; + + ret = dev->ops->get_features (dev->q, &gf); +if (ret) +return ret; + + dev->features = gf; + +return 0 ; +} + +int nvm_validate_responsibility (struct nvm_dev *dev) +{ +if (!dev->ops->set_responsibility) +return 0 ; + +return dev->ops->set_responsibility (dev->q,0 ); +} + +int nvm_init (struct nvm_dev *dev) +{ +struct nvm_bm_type *bt; +int ret =0 ; + +if (!dev->q || !dev->ops) +return -EINVAL ; + +if (dev->ops->identify (dev->q, &dev->identity)) { +pr_err ("nvm: device could not be identified\n" ); + ret = -EINVAL ; + goto err; + } + +pr_debug ("nvm dev: ver %u type %u chnls %u\n" , + dev->identity.ver_id, + dev->identity.nvm_type, + dev->identity.nchannels); + + ret =nvm_validate_features (dev); +if (ret) { +pr_err ("nvm: disk features are not supported." ); + goto err; + } + + ret =nvm_validate_responsibility (dev); +if (ret) { +pr_err ("nvm: disk responsibilities are not supported." ); + goto err; + } + + ret =nvm_core_init (dev); +if (ret) { +pr_err ("nvm: could not initialize core structures.\n" ); + goto err; + } + +if (!dev->nr_luns) { +pr_err ("nvm: device did not expose any luns.\n" ); + goto err; + } +
drivers/lightnvm/core.c line 262
Quoted 10 lines
drivers/lightnvm/core.c new file +10
-0+/* register with device with a supported BM */ +list_for_each_entry (bt, &nvm_bms, list) { + ret = bt->register_bm (dev); +if (ret <0 ) + goto err;/* initialization failed */ +if (ret >0 ) { + dev->bm = bt; +break ;/* successfully initialized */ + } + }
Why just search it from head to tail? Can user specific it in nvm_create_target()?
drivers/lightnvm/core.c line 267
Quoted 5 lines
drivers/lightnvm/core.c new file +5
-0+ +if (!ret) { +pr_info ("nvm: no compatible bm was found.\n" ); +return 0 ; + }
If we allow nvm_device registered with no bm, we would get a NULL pointer reference problem in later using.
As mentioned above, why we have to choose bm for nvm in nvm_register?
Thanx
Yang
Quoted 665 lines
drivers/lightnvm/core.c new file +323
-0+ +pr_info ("nvm: registered %s with luns: %u blocks: %lu sector size: %d\n" , + dev->name, dev->nr_luns, dev->total_blocks, dev->sector_size); + +return 0 ; +err: +nvm_free (dev); +pr_err ("nvm: failed to initialize nvm\n" ); +return ret; +} + +void nvm_exit (struct nvm_dev *dev) +{ +if (dev->ppalist_pool) + dev->ops->destroy_ppa_pool (dev->ppalist_pool); +nvm_free (dev); + +pr_info ("nvm: successfully unloaded\n" ); +} + +static const struct block_device_operations nvm_fops = { + .owner =THIS_MODULE , +}; + +static int nvm_create_target (struct nvm_dev *dev,char *ttname,char *tname, +int lun_begin,int lun_end) +{ +struct request_queue *tqueue; +struct gendisk *tdisk; +struct nvm_tgt_type *tt; +struct nvm_target *t; +void *targetdata; + + tt =nvm_find_target_type (ttname); +if (!tt) { +pr_err ("nvm: target type %s not found\n" , ttname); +return -EINVAL ; + } + +down_write (&nvm_lock); +list_for_each_entry (t, &dev->online_targets, list) { +if (!strcmp (tname, t->disk->disk_name)) { +pr_err ("nvm: target name already exists.\n" ); +up_write (&nvm_lock); +return -EINVAL ; + } + } +up_write (&nvm_lock); + + t =kmalloc (sizeof (struct nvm_target ),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + + tqueue =blk_alloc_queue_node (GFP_KERNEL , dev->q->node); +if (!tqueue) + goto err_t; +blk_queue_make_request (tqueue, tt->make_rq); + + tdisk =alloc_disk (0 ); +if (!tdisk) + goto err_queue; + +sprintf (tdisk->disk_name,"%s" , tname); + tdisk->flags =GENHD_FL_EXT_DEVT ; + tdisk->major =0 ; + tdisk->first_minor =0 ; + tdisk->fops = &nvm_fops; + tdisk->queue = tqueue; + + targetdata = tt->init (dev, tdisk, lun_begin, lun_end); +if (IS_ERR (targetdata)) + goto err_init; + + tdisk->private_data = targetdata; + tqueue->queuedata = targetdata; + +blk_queue_max_hw_sectors (tqueue,8 * dev->ops->max_phys_sect); + +set_capacity (tdisk, tt->capacity (targetdata)); +add_disk (tdisk); + + t->type = tt; + t->disk = tdisk; + +down_write (&nvm_lock); +list_add_tail (&t->list, &dev->online_targets); +up_write (&nvm_lock); + +return 0 ; +err_init: +put_disk (tdisk); +err_queue: +blk_cleanup_queue (tqueue); +err_t: +kfree (t); +return -ENOMEM ; +} + +static void nvm_remove_target (struct nvm_target *t) +{ +struct nvm_tgt_type *tt = t->type; +struct gendisk *tdisk = t->disk; +struct request_queue *q = tdisk->queue; + +lockdep_assert_held (&nvm_lock); + +del_gendisk (tdisk); +if (tt->exit) + tt->exit (tdisk->private_data); + +blk_cleanup_queue (q); + +put_disk (tdisk); + +list_del (&t->list); +kfree (t); +} + +static int nvm_configure_show (const char *val) +{ +struct nvm_dev *dev; +char opcode, devname[DISK_NAME_LEN ]; +int ret; + + ret =sscanf (val,"%c %s" , &opcode, devname); +if (ret !=2 ) { +pr_err ("nvm: invalid command. Use \"opcode devicename\".\n" ); +return -EINVAL ; + } + + dev =nvm_find_nvm_dev (devname); +if (!dev) { +pr_err ("nvm: device not found\n" ); +return -EINVAL ; + } + +if (!dev->bm) +return 0 ; + + dev->bm->free_blocks_print (dev); + +return 0 ; +} + +static int nvm_configure_del (const char *val) +{ +struct nvm_target *t =NULL ; +struct nvm_dev *dev; +char opcode, tname[255 ]; +int ret; + + ret =sscanf (val,"%c %s" , &opcode, tname); +if (ret !=2 ) { +pr_err ("nvm: invalid command. Use \"d targetname\".\n" ); +return -EINVAL ; + } + +down_write (&nvm_lock); +list_for_each_entry (dev, &nvm_devices, devices) +list_for_each_entry (t, &dev->online_targets, list) { +if (!strcmp (tname, t->disk->disk_name)) { +nvm_remove_target (t); + ret =0 ; +break ; + } + } +up_write (&nvm_lock); + +if (ret) { +pr_err ("nvm: target \"%s\" doesn't exist.\n" , tname); +return -EINVAL ; + } + +return 0 ; +} + +static int nvm_configure_add (const char *val) +{ +struct nvm_dev *dev; +char opcode, devname[DISK_NAME_LEN ], tgtengine[255 ], tname[255 ]; +int lun_begin, lun_end, ret; + + ret =sscanf (val,"%c %s %s %s %u:%u" , &opcode, devname, tgtengine, + tname, &lun_begin, &lun_end); +if (ret !=6 ) { +pr_err ("nvm: invalid command. Use \"opcode device name tgtengine lun_begin:lun_end\".\n" ); +return -EINVAL ; + } + + dev =nvm_find_nvm_dev (devname); +if (!dev) { +pr_err ("nvm: device not found\n" ); +return -EINVAL ; + } + +if (lun_begin > lun_end || lun_end > dev->nr_luns) { +pr_err ("nvm: lun out of bound (%u:%u > %u)\n" , + lun_begin, lun_end, dev->nr_luns); +return -EINVAL ; + } + +return nvm_create_target (dev, tname, tgtengine, lun_begin, lun_end); +} + +/* Exposes administrative interface through /sys/module/lnvm/configure_by_str */ +static int nvm_configure_by_str_event (const char *val, +const struct kernel_param *kp) +{ +char opcode; +int ret; + + ret =sscanf (val,"%c" , &opcode); +if (ret !=1 ) { +pr_err ("nvm: configure must be in the format of \"opcode ...\"\n" ); +return -EINVAL ; + } + +switch (opcode) { +case 'a' : +return nvm_configure_add (val); +case 'd' : +return nvm_configure_del (val); +case 's' : +return nvm_configure_show (val); +default : +pr_err ("nvm: invalid opcode.\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static int nvm_configure_get (char *buf,const struct kernel_param *kp) +{ +int sz =0 ; +char *buf_start = buf; +struct nvm_dev *dev; + + buf +=sprintf (buf,"available devices:\n" ); +down_write (&nvm_lock); +list_for_each_entry (dev, &nvm_devices, devices) { +if (sz >4095 -DISK_NAME_LEN ) +break ; + buf +=sprintf (buf," %s\n" , dev->name); + } +up_write (&nvm_lock); + +return buf - buf_start -1 ; +} + +static const struct kernel_param_ops nvm_configure_by_str_event_param_ops = { + .set = nvm_configure_by_str_event, + .get = nvm_configure_get, +}; + +#undef MODULE_PARAM_PREFIX +#define MODULE_PARAM_PREFIX "lnvm." + +module_param_cb (configure_debug, &nvm_configure_by_str_event_param_ops,NULL , +0644 ); + +int nvm_register (struct request_queue *q,char *disk_name, +struct nvm_dev_ops *ops) +{ +struct nvm_dev *dev; +int ret; + +if (!ops->identify || !ops->get_features) +return -EINVAL ; + + dev =kzalloc (sizeof (struct nvm_dev ),GFP_KERNEL ); +if (!dev) +return -ENOMEM ; + + dev->q = q; + dev->ops = ops; +strncpy (dev->name, disk_name,DISK_NAME_LEN ); + + ret =nvm_init (dev); +if (ret) + goto err_init; + +down_write (&nvm_lock); +list_add (&dev->devices, &nvm_devices); +up_write (&nvm_lock); + +if (dev->ops->max_phys_sect >256 ) { +pr_info ("nvm: maximum number of sectors supported in target is 255. max_phys_sect set to 255\n" ); + dev->ops->max_phys_sect =255 ; + } + +if (dev->ops->max_phys_sect >1 ) { + dev->ppalist_pool = dev->ops->create_ppa_pool (dev->q); +if (!dev->ppalist_pool) { +pr_err ("nvm: could not create ppa pool\n" ); +return -ENOMEM ; + } + } + +return 0 ; +err_init: +kfree (dev); +return ret; +} +EXPORT_SYMBOL (nvm_register); + +void nvm_unregister (char *disk_name) +{ +struct nvm_dev *dev =nvm_find_nvm_dev (disk_name); + +if (!dev) { +pr_err ("nvm: could not find device %s on unregister\n" , + disk_name); +return ; + } + +nvm_exit (dev); + +down_write (&nvm_lock); +list_del (&dev->devices); +up_write (&nvm_lock); +} +EXPORT_SYMBOL (nvm_unregister);include/linux/lightnvm.h new file +335
-0@@ -0,0 +1,335 @@ +#ifndef NVM_H +#define NVM_H + +enum { +NVM_IO_OK =0 , +NVM_IO_REQUEUE =1 , +NVM_IO_DONE =2 , +NVM_IO_ERR =3 , + +NVM_IOTYPE_NONE =0 , +NVM_IOTYPE_GC =1 , +}; + +#ifdef CONFIG_NVM + +#include <linux/blkdev.h> +#include <linux/types.h> +#include <linux/file.h> +#include <linux/dmapool.h> + +enum { +/* HW Responsibilities */ +NVM_RSP_L2P =1 <<0 , +NVM_RSP_GC =1 <<1 , +NVM_RSP_ECC =1 <<2 , + +/* Physical NVM Type */ +NVM_NVMT_BLK =0 , +NVM_NVMT_BYTE =1 , + +/* Internal IO Scheduling algorithm */ +NVM_IOSCHED_CHANNEL =0 , +NVM_IOSCHED_CHIP =1 , + +/* Status codes */ +NVM_SUCCESS =0 , +NVM_RSP_NOT_CHANGEABLE =1 , +}; + +struct nvm_id_chnl { +u64 laddr_begin; +u64 laddr_end; +u32 oob_size; +u32 queue_size; +u32 gran_read; +u32 gran_write; +u32 gran_erase; +u32 t_r; +u32 t_sqr; +u32 t_w; +u32 t_sqw; +u32 t_e; +u16 chnl_parallelism; +u8 io_sched; +u8 res[133 ]; +}; + +struct nvm_id { +u8 ver_id; +u8 nvm_type; +u16 nchannels; +struct nvm_id_chnl *chnls; +}; + +struct nvm_get_features { +u64 rsp; +u64 ext; +}; + +struct nvm_target { +struct list_head list; +struct nvm_tgt_type *type; +struct gendisk *disk; +}; + +struct nvm_tgt_instance { +struct nvm_tgt_type *tt; +}; + +struct nvm_rq { +struct nvm_tgt_instance *ins; +struct bio *bio; +union { +sector_t ppa; +sector_t *ppa_list; + }; +/*DMA handler to be used by underlying devices supporting DMA*/ +dma_addr_t dma_ppa_list; +uint8_t npages; +}; + +static inline struct nvm_rq *nvm_rq_from_pdu (void *pdu) +{ +return pdu -sizeof (struct nvm_rq ); +} + +static inline void *nvm_rq_to_pdu (struct nvm_rq *rqdata) +{ +return rqdata +1 ; +} + +struct nvm_block ; + +typedef int (nvm_l2p_update_fn )(u64 ,u64 ,u64 *,void *); +typedef int (nvm_bb_update_fn )(u32 ,void *,unsigned int ,void *); +typedef int (nvm_id_fn )(struct request_queue *,struct nvm_id *); +typedef int (nvm_get_features_fn )(struct request_queue *, +struct nvm_get_features *); +typedef int (nvm_set_rsp_fn )(struct request_queue *,u64 ); +typedef int (nvm_get_l2p_tbl_fn )(struct request_queue *,u64 ,u64 , +nvm_l2p_update_fn *,void *); +typedef int (nvm_op_bb_tbl_fn )(struct request_queue *,int ,unsigned int , +nvm_bb_update_fn *,void *); +typedef int (nvm_submit_io_fn )(struct request_queue *,struct nvm_rq *); +typedef int (nvm_erase_blk_fn )(struct request_queue *,sector_t ); +typedef void *(nvm_create_ppapool_fn )(struct request_queue *); +typedef void (nvm_destroy_ppapool_fn )(void *); +typedef void *(nvm_alloc_ppalist_fn )(struct request_queue *,void *,gfp_t , +dma_addr_t *); +typedef void (nvm_free_ppalist_fn )(void *,void *,dma_addr_t ); + +struct nvm_dev_ops { +nvm_id_fn *identify; +nvm_get_features_fn *get_features; +nvm_set_rsp_fn *set_responsibility; +nvm_get_l2p_tbl_fn *get_l2p_tbl; +nvm_op_bb_tbl_fn *set_bb_tbl; +nvm_op_bb_tbl_fn *get_bb_tbl; + +nvm_submit_io_fn *submit_io; +nvm_erase_blk_fn *erase_block; + +nvm_create_ppapool_fn *create_ppa_pool; +nvm_destroy_ppapool_fn *destroy_ppa_pool; +nvm_alloc_ppalist_fn *alloc_ppalist; +nvm_free_ppalist_fn *free_ppalist; + +uint8_t max_phys_sect; +}; + +struct nvm_lun { +int id; + +int nr_pages_per_blk; +unsigned int nr_blocks;/* end_block - start_block. */ +unsigned int nr_free_blocks;/* Number of unused blocks */ + +struct nvm_block *blocks; + +spinlock_t lock; +}; + +struct nvm_block { +struct list_head list; +struct nvm_lun *lun; +unsigned long long id; + +void *priv; +int type; +}; + +struct nvm_dev { +struct nvm_dev_ops *ops; + +struct list_head devices; +struct list_head online_targets; + +/* Block manager */ +struct nvm_bm_type *bm; +void *bmp; + +/* Target information */ +int nr_luns; + +/* Calculated/Cached values. These do not reflect the actual usable +* blocks at run-time. */ +unsigned long total_pages; +unsigned long total_blocks; +unsigned max_pages_per_blk; + +uint32_t sector_size; + +void *ppalist_pool; + +/* Identity */ +struct nvm_id identity; +struct nvm_get_features features; + +/* Backend device */ +struct request_queue *q; +char name[DISK_NAME_LEN ]; +}; + +typedef void (nvm_tgt_make_rq_fn )(struct request_queue *,struct bio *); +typedef sector_t (nvm_tgt_capacity_fn )(void *); +typedef void (nvm_tgt_end_io_fn )(struct nvm_rq *,int ); +typedef void *(nvm_tgt_init_fn )(struct nvm_dev *,struct gendisk *,int ,int ); +typedef void (nvm_tgt_exit_fn )(void *); + +struct nvm_tgt_type { +const char *name; +unsigned int version[3 ]; + +/* target entry points */ +nvm_tgt_make_rq_fn *make_rq; +nvm_tgt_capacity_fn *capacity; +nvm_tgt_end_io_fn *end_io; + +/* module-specific init/teardown */ +nvm_tgt_init_fn *init; +nvm_tgt_exit_fn *exit; + +/* For internal use */ +struct list_head list; +}; + +extern int nvm_register_target (struct nvm_tgt_type *); +extern void nvm_unregister_target (struct nvm_tgt_type *); + +extern void *nvm_alloc_ppalist (struct nvm_dev *,gfp_t ,dma_addr_t *); +extern void nvm_free_ppalist (struct nvm_dev *,void *,dma_addr_t ); + +typedef int (nvm_bm_register_fn )(struct nvm_dev *); +typedef void (nvm_bm_unregister_fn )(struct nvm_dev *); +typedef struct nvm_block *(nvm_bm_get_blk_fn )(struct nvm_dev *, +struct nvm_lun *,unsigned long ); +typedef void (nvm_bm_put_blk_fn )(struct nvm_dev *,struct nvm_block *); +typedef int (nvm_bm_open_blk_fn )(struct nvm_dev *,struct nvm_block *); +typedef int (nvm_bm_close_blk_fn )(struct nvm_dev *,struct nvm_block *); +typedef void (nvm_bm_flush_blk_fn )(struct nvm_dev *,struct nvm_block *); +typedef int (nvm_bm_submit_io_fn )(struct nvm_dev *,struct nvm_rq *); +typedef void (nvm_bm_end_io_fn )(struct nvm_rq *,int ); +typedef int (nvm_bm_erase_blk_fn )(struct nvm_dev *,struct nvm_block *); +typedef int (nvm_bm_register_prog_err_fn )(struct nvm_dev *, +void (prog_err_fn )(struct nvm_dev *,struct nvm_block *)); +typedef int (nvm_bm_save_state_fn )(struct file *); +typedef int (nvm_bm_restore_state_fn )(struct file *); +typedef struct nvm_lun *(nvm_bm_get_luns_fn )(struct nvm_dev *,int ,int ); +typedef void (nvm_bm_free_blocks_print_fn )(struct nvm_dev *); + +struct nvm_bm_type { +const char *name; +unsigned int version[3 ]; + +nvm_bm_register_fn *register_bm; +nvm_bm_unregister_fn *unregister_bm; + +/* Block administration callbacks */ +nvm_bm_get_blk_fn *get_blk; +nvm_bm_put_blk_fn *put_blk; +nvm_bm_open_blk_fn *open_blk; +nvm_bm_close_blk_fn *close_blk; +nvm_bm_flush_blk_fn *flush_blk; + +nvm_bm_submit_io_fn *submit_io; +nvm_bm_end_io_fn *end_io; +nvm_bm_erase_blk_fn *erase_blk; + +/* State management for debugging purposes */ +nvm_bm_save_state_fn *save_state; +nvm_bm_restore_state_fn *restore_state; + +/* Configuration management */ +nvm_bm_get_luns_fn *get_luns; + +/* Statistics */ +nvm_bm_free_blocks_print_fn *free_blocks_print; +struct list_head list; +}; + +extern int nvm_register_bm (struct nvm_bm_type *); +extern void nvm_unregister_bm (struct nvm_bm_type *); + +extern struct nvm_block *nvm_get_blk (struct nvm_dev *,struct nvm_lun *, +unsigned long ); +extern void nvm_put_blk (struct nvm_dev *,struct nvm_block *); +extern int nvm_erase_blk (struct nvm_dev *,struct nvm_block *); + +extern int nvm_register (struct request_queue *,char *, +struct nvm_dev_ops *); +extern void nvm_unregister (char *); + +extern int nvm_submit_io (struct nvm_dev *,struct nvm_rq *); + +/* We currently assume that we the lightnvm device is accepting data in 512 +* bytes chunks. This should be set to the smallest command size available for a +* given device. +*/ +#define NVM_SECTOR (512) +#define EXPOSED_PAGE_SIZE (4096) + +#define NR_PHY_IN_LOG (EXPOSED_PAGE_SIZE / NVM_SECTOR) + +#define NVM_MSG_PREFIX "nvm" +#define ADDR_EMPTY (~0ULL) + +static inline unsigned long nvm_get_rq_flags (struct request *rq) +{ +return (unsigned long )rq->cmd; +} + +#else /* CONFIG_NVM */ + +struct nvm_dev_ops ; +struct nvm_dev ; +struct nvm_lun ; +struct nvm_block ; +struct nvm_rq { +}; +struct nvm_tgt_type ; +struct nvm_tgt_instance ; + +static inline struct nvm_tgt_type *nvm_find_target_type (const char *c) +{ +return NULL ; +} +static inline int nvm_register (struct request_queue *q,char *disk_name, +struct nvm_dev_ops *ops) +{ +return -EINVAL ; +} +static inline void nvm_unregister (char *disk_name) {} +static inline struct nvm_block *nvm_get_blk (struct nvm_dev *dev, +struct nvm_lun *lun,unsigned long flags) +{ +return NULL ; +} +static inline void nvm_put_blk (struct nvm_dev *dev,struct nvm_block *blk) {} +static inline int nvm_erase_blk (struct nvm_dev *dev,struct nvm_block *blk) +{ +return -EINVAL ; +} + +#endif /* CONFIG_NVM */ +#endif /* LIGHTNVM.H */
Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 12 lines
drivers/lightnvm/core.c line 262
Quoted 11 lines
drivers/lightnvm/core.c new file +11
-0+ +/* register with device with a supported BM */ +list_for_each_entry (bt, &nvm_bms, list) { + ret = bt->register_bm (dev); +if (ret <0 ) + goto err;/* initialization failed */ +if (ret >0 ) { + dev->bm = bt; +break ;/* successfully initialized */ + } + }
Quoted 2 lines
Why just search it from head to tail? Can user specific it in
nvm_create_target()?
Hi Yang,
Currently only the rrpc and a couple of out of tree block managers are built. The register_bm only tries to find a block manager that supports the device, when it finds it, that one is initialized. It is an open question on how we choose the right block manager, e.g. a proprietary and a open-source block manager is in place. Priorities might be a way to go? or mark certain block managers as a catch all?
Hopefully we will get away with only a single or two block managers in the future, so we won't have one for each type of device.
Quoted 9 lines
drivers/lightnvm/core.c line 267
Quoted 5 lines
drivers/lightnvm/core.c new file +5
-0+ +if (!ret) { +pr_info ("nvm: no compatible bm was found.\n" ); +return 0 ; + }If we allow
nvm_deviceregistered with no bm, we would get a NULL pointer reference problem in later using.
Yes, definitely. In the care that happens, I envision it should be possible to register a block manager after a device is loaded, and then any outstanding devices (which does not have a registered block manager), will be probed again.
Quoted 1 line
As mentioned above, why we have to choose bm for nvm in
nvm_register?
Without a block manager, we don't know the structure of the device and how to interact with it. I want to initialize that as soon as possible. So that layers on top can start interacting.
Quoted 3 lines
Thanx
Yang
Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 33 lines · Matias Bj?rling
Quoted 12 lines
drivers/lightnvm/core.c line 262
Quoted 11 lines
drivers/lightnvm/core.c new file +11
-0+ +/* register with device with a supported BM */ +list_for_each_entry (bt, &nvm_bms, list) { + ret = bt->register_bm (dev); +if (ret <0 ) + goto err;/* initialization failed */ +if (ret >0 ) { + dev->bm = bt; +break ;/* successfully initialized */ + } + }Quoted 2 lines
Why just search it from head to tail? Can user specific it in
nvm_create_target()?Hi Yang,
Currently only the rrpc and a couple of out of tree block managers are built. The
register_bmonly tries to find a block manager that supports the device, when it finds it, that one is initialized. It is an open question on how we choose the right block manager, e.g. a proprietary and a open-source block manager is in place. Priorities might be a way to go? or mark certain block managers as a catch all?Hopefully we will get away with only a single or two block managers in the future, so we won't have one for each type of device.
Quoted 6 lines
Quoted 5 lines
drivers/lightnvm/core.c new file +5
-0+ +if (!ret) { +pr_info ("nvm: no compatible bm was found.\n" ); +return 0 ; + }
Quoted 5 lines
Quoted 3 lines
If we allow
nvm_deviceregistered with no bm, we would get a NULL pointer reference problem in later using.Yes, definitely.
So here is a suggestion, register_bm again
if we found nvm_dev->bm == NULL in create_target(). And if it is still NULL after that. return an error "nvm: no compatible bm was found" and stop target creating. Otherwise, there would be a NULL Pointer reference problem.
That's a real problem I met in my testing and I did this change in my local using. I hope that's useful to you.
Thanx
Yang
Quoted 16 lines
In the care that happens, I envision it should be
possible to register a block manager after a device is loaded, and then any outstanding devices (which does not have a registered block manager), will be probed again.Quoted 1 line
As mentioned above, why we have to choose bm for nvm in
nvm_register?Without a block manager, we don't know the structure of the device and how to interact with it. I want to initialize that as soon as possible. So that layers on top can start interacting.
Quoted 3 lines
Thanx
Yang.
Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 10 lines
So here is a suggestion,
register_bmagain
if we foundnvm_dev->bm== NULL increate_target(). And if it is still NULL after that. return an error "nvm: no compatible bm was found" and stop target creating. Otherwise, there would be a NULL Pointer reference problem.That's a real problem I met in my testing and I did this change in my local using. I hope that's useful to you.
Hi Yang,
Similar to this?
drivers/lightnvm/core.c +1 -2
@@ -262,8 +262,9 @@ int nvm_init(struct nvm_dev *dev) }if (!ret) { -pr_info ("nvm: no compatible bm was found.\n" ); -return 0 ; + pr_info("nvm: %s was not initialized due to no
compatible bm.\n",
+ dev->name);
+ return -EINVAL;
}
pr_info("nvm: registered %s with luns: %u blocks: %lu sector
size: %d\n",
Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 7 lines · Matias Bjørling
Quoted 7 lines
So here is a suggestion,
register_bmagain
if we foundnvm_dev->bm== NULL increate_target(). And if it is still NULL after that. return an error "nvm: no compatible bm was found" and stop target creating. Otherwise, there would be a NULL Pointer reference problem.
Quoted 6 lines
Quoted 3 lines
That's a real problem I met in my testing and I did this change in my local using. I hope that's useful to you.
Hi Yang,
ac
Similar to this?
Okey, I attached two changes in my local using. I hope that useful to you.
Yang
Quoted 22 lines
drivers/lightnvm/core.c +3
-2@@ -262,8 +262,9 @@ int nvm_init(struct nvm_dev *dev) }if (!ret) { -pr_info ("nvm: no compatible bm was found.\n" ); -return 0 ; + pr_info("nvm: %s was not initialized due to no compatible bm.\n", + dev->name); +return -EINVAL ; }pr_info("nvm: registered %s with luns: %u blocks: %lu sector
size: %d\n",
Quoted 4 lines
.
From
2060232d379328679b22753587d16249f01fa219Mon Sep 17 00:00:00 2001
From: Dongsheng Yang <[email protected]>
Date: Fri, 4 Sep 2015 08:10:13 +0900
Subject: [PATCH 2/2] lightNVM: register bm in nvm_create_target if dev->bm is
NULL
When we create target, we need to make sure dev->bm is not NULL. If it's NULL try to register bm again. If we still fail to find a proper bm for this dev, return error rather than continue to provide a NULL pointer dereference problem later.
--- drivers/lightnvm/core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/lightnvm/core.c +20 -0
@@ -293,10 +293,30 @@ static int nvm_create_target(struct nvm_dev *dev, char *ttname, char *tname, int lun_begin, int lun_end) {struct request_queue *tqueue; +struct nvm_bm_type *bt;struct gendisk *tdisk;struct nvm_tgt_type *tt;struct nvm_target *t;void *targetdata; +int ret =0 ; + +if (!dev->bm) { +/* register with device with a supported BM */ +list_for_each_entry (bt, &nvm_bms, list) { + ret = bt->register_bm (dev); +if (ret <0 ) +return ret;/* initialization failed */ +if (ret >0 ) { + dev->bm = bt; +break ;/* successfully initialized */ + } + } + +if (!ret) { +pr_info ("nvm: no compatible bm was found.\n" ); +return -ENODEV ; + } + } tt =nvm_find_target_type (ttname);if (!tt) {
Signature · 1 line
1.8.4.2
Quoted 1 line
From
699d279ee0dbf3db5a4e7a78d52fb93e954294a1Mon Sep 17 00:00:00 2001
From: Dongsheng Yang <[email protected]>
Date: Mon, 31 Aug 2015 17:22:23 -0400
Subject: [PATCH 1/2] lightNVM: fix a compatibility problem in compiling.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In some old gcc version, such as [gcc version 4.4.7 20120313 (Red Hat 4.4.7-4)] there is a compiling error with this kind of code:
struct test {
union {
int data;
};
};int main()
{
struct test ins = {
.data = 1,
};
return 0;
}# gcc test.c # test.c: In function ‘main’: # test.c:12: error: unknown field ‘data’ specified in initializer
This patch fix this problem to initialize it in a compatible way.
--- drivers/block/nvme-lightnvm.c | 58 +++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 32 deletions(-)
drivers/block/nvme-lightnvm.c +26 -32
121 lines not on this page · raw message
Signature · 1 line
1.8.4.2
Matias Bjørling
AppliedRe: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs
Quoted 11 lines · Dongsheng Yang
Quoted 10 lines · Matias Bjørling
Quoted 10 lines
So here is a suggestion,
register_bmagain
if we foundnvm_dev->bm== NULL increate_target(). And if it is still NULL after that. return an error "nvm: no compatible bm was found" and stop target creating. Otherwise, there would be a NULL Pointer reference problem.That's a real problem I met in my testing and I did this change in my local using. I hope that's useful to you.
Quoted 7 lines
Quoted 3 lines
Hi Yang,
ac
Similar to this?Okey, I attached two changes in my local using. I hope that useful to you.
Thanks! Applied and pushed to master.
PATCH v7 2/5 lightnvm: Hybrid Open-Channel SSD RRPC target
In reply to Matias BjørlingThis target implements a simple strategy FTL for Open-Channel SSDs. It does round-robin selection across channels and luns. It uses a simple greedy cost-based garbage collector and exposes the physical flash as a block device.
--- drivers/lightnvm/Kconfig | 10 + drivers/lightnvm/Makefile | 1 + drivers/lightnvm/core.c | 3 +- drivers/lightnvm/rrpc.c | 1296 +++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/rrpc.h | 236 +++++++++ include/linux/lightnvm.h | 5 +- 6 files changed, 1547 insertions(+), 4 deletions(-) create mode 100644 drivers/lightnvm/rrpc.c create mode 100644 drivers/lightnvm/rrpc.h
drivers/lightnvm/Kconfig +10 -0
@@ -14,3 +14,13 @@ menuconfig NVM If you say N, all options in this submenu will be skipped and disabled only do this if you know what you are doing. +if NVM + +config NVM_RRPC + tristate "Round-robin Hybrid Open-Channel SSD target" + ---help--- + Allows an open-channel SSD to be exposed as a block device to the + host. The target is implemented using a linear mapping table and + cost-based garbage collection. It is optimized for 4K IO sizes. + +endif # NVM
drivers/lightnvm/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_NVM) := core.o +obj-$(CONFIG_NVM_RRPC) += rrpc.o
drivers/lightnvm/core.c +2 -1
@@ -169,7 +169,7 @@ static void nvm_core_free(struct nvm_dev *dev)static int nvm_core_init (struct nvm_dev *dev) { dev->nr_luns = dev->identity.nchannels; - dev->sector_size =EXPOSED_PAGE_SIZE ; + dev->sector_size = dev->ops->dev_sector_size;INIT_LIST_HEAD (&dev->online_targets);return 0 ;
@@ -541,6 +541,7 @@ int nvm_register(struct request_queue *q, char *disk_name, dev->q = q; dev->ops = ops; + dev->ops->dev_sector_size =DEV_EXPOSED_PAGE_SIZE ;strncpy (dev->name, disk_name,DISK_NAME_LEN ); ret =nvm_init (dev);
drivers/lightnvm/rrpc.c new file +1296 -0
1,296 lines not on this page · raw message
drivers/lightnvm/rrpc.h new file +236 -0
236 lines not on this page · raw message
include/linux/lightnvm.h +2 -3
@@ -135,6 +135,7 @@ struct nvm_dev_ops {nvm_alloc_ppalist_fn *alloc_ppalist;nvm_free_ppalist_fn *free_ppalist; +int dev_sector_size;uint8_t max_phys_sect; };
@@ -286,10 +287,8 @@ extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *);* bytes chunks. This should be set to the smallest command size available for a * given device. */ -#define NVM_SECTOR (512) -#define EXPOSED_PAGE_SIZE (4096) -#define NR_PHY_IN_LOG (EXPOSED_PAGE_SIZE / NVM_SECTOR) +#define DEV_EXPOSED_PAGE_SIZE (4096)#define NVM_MSG_PREFIX "nvm"#define ADDR_EMPTY (~0ULL)
Signature · 1 line
2.1.4
PATCH v7 3/5 lightnvm: Hybrid Open-Channel SSD block manager
In reply to Matias BjørlingThe host implementation for Open-Channel SSDs is divided into block management and targets. This patch implements the block manager for hybrid open-channel SSDs. On top a target, such as rrpc is initialized.
--- drivers/lightnvm/Kconfig | 7 + drivers/lightnvm/Makefile | 1 + drivers/lightnvm/bm_hb.c | 366 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/bm_hb.h | 46 ++++++ 4 files changed, 420 insertions(+) create mode 100644 drivers/lightnvm/bm_hb.c create mode 100644 drivers/lightnvm/bm_hb.h
drivers/lightnvm/Kconfig +7 -0
@@ -23,4 +23,11 @@ config NVM_RRPC host. The target is implemented using a linear mapping table and cost-based garbage collection. It is optimized for 4K IO sizes. +config NVM_BM_HB + tristate "Block manager for Hybrid Open-Channel SSD" + ---help--- + Block manager for SSDs that offload block management off to the device, + while keeping data placement and garbage collection decisions on the + host. + endif # NVM
drivers/lightnvm/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_NVM) := core.o obj-$(CONFIG_NVM_RRPC) += rrpc.o +obj-$(CONFIG_NVM_BM_HB) += bm_hb.o
drivers/lightnvm/bm_hb.c new file +366 -0
366 lines not on this page · raw message
drivers/lightnvm/bm_hb.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v7 4/5 null_nvm: Lightnvm test driver
In reply to Matias BjørlingThis driver implements the I/O flow for a LightNVM device driver. It does no transfers. It can be used to test setup/teardown of devices and evaluating performance of block managers and targets.
The framework of the driver is derived from the null_blk module.
--- drivers/lightnvm/Kconfig | 3 + drivers/lightnvm/Makefile | 1 + drivers/lightnvm/null_nvm.c | 481 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 485 insertions(+) create mode 100644 drivers/lightnvm/null_nvm.c
drivers/lightnvm/Kconfig +3 -0
@@ -30,4 +30,7 @@ config NVM_BM_HB while keeping data placement and garbage collection decisions on the host. +config NVM_NULL_NVM + tristate "Null test LightNVM driver" + endif # NVM
drivers/lightnvm/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_NVM) := core.o obj-$(CONFIG_NVM_RRPC) += rrpc.o obj-$(CONFIG_NVM_BM_HB) += bm_hb.o +obj-$(CONFIG_NVM_NULL_NVM) += null_nvm.o
drivers/lightnvm/null_nvm.c new file +481 -0
481 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v7 5/5 nvme: LightNVM support
In reply to Matias BjørlingThe first generation of Open-Channel SSDs will be based on NVMe. The integration requires that a NVMe device exposes itself as a LightNVM device. The way this is done currently is by hooking into the Controller Capabilities (CAP register) and a bit in NSFEAT for each namespace.
After detection, vendor specific codes are used to identify the device and enumerate supported features.
--- drivers/block/Makefile | 2 +- drivers/block/nvme-core.c | 23 +- drivers/block/nvme-lightnvm.c | 568 ++++++++++++++++++++++++++++++++++++++++++ include/linux/nvme.h | 6 + include/uapi/linux/nvme.h | 3 + 5 files changed, 598 insertions(+), 4 deletions(-) create mode 100644 drivers/block/nvme-lightnvm.c
drivers/block/Makefile +1 -1
@@ -44,6 +44,6 @@ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o obj-$(CONFIG_ZRAM) += zram/ -nvme-y := nvme-core.o nvme-scsi.o +nvme-y := nvme-core.o nvme-scsi.o nvme-lightnvm.o skd-y := skd_main.o swim_mod-y := swim.o swim_asm.o
drivers/block/nvme-core.c +20 -3
@@ -40,6 +40,7 @@#include <linux/slab.h> #include <linux/t10-pi.h> #include <linux/types.h> +#include <linux/lightnvm.h> #include <scsi/sg.h> #include <asm-generic/io-64-nonatomic-lo-hi.h>
@@ -1751,7 +1752,8 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev) dev->page_size =1 << page_shift; - dev->ctrl_config =NVME_CC_CSS_NVM ; + dev->ctrl_config =NVME_CAP_LIGHTNVM (cap) ? +NVME_CC_CSS_LIGHTNVM :NVME_CC_CSS_NVM ; dev->ctrl_config |= (page_shift -12 ) <<NVME_CC_MPS_SHIFT ; dev->ctrl_config |=NVME_CC_ARB_RR |NVME_CC_SHN_NONE ; dev->ctrl_config |=NVME_CC_IOSQES |NVME_CC_IOCQES ;
@@ -1997,6 +1999,17 @@ static int nvme_revalidate_disk(struct gendisk *disk)return -ENODEV ; } +if ((dev->ctrl_config &NVME_CC_CSS_LIGHTNVM ) && + id->nsfeat &NVME_NS_FEAT_NVM && ns->type !=NVME_NS_NVM ) { +if (nvme_nvm_register (ns->queue, disk->disk_name)) { +dev_warn (dev->dev, +"%s: LightNVM init failure\n" , __func__); +kfree (id); +return -ENODEV ; + } + ns->type =NVME_NS_NVM ; + } + old_ms = ns->ms; lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; ns->lba_shift = id->lbaf[lbaf].ds;
@@ -2028,7 +2041,7 @@ static int nvme_revalidate_disk(struct gendisk *disk) !ns->ext)nvme_init_integrity (ns); -if (ns->ms && !blk_get_integrity (disk)) +if ((ns->ms && !blk_get_integrity (disk)) || ns->type ==NVME_NS_NVM )set_capacity (disk,0 );else set_capacity (disk,le64_to_cpup (&id->nsze) << (ns->lba_shift -9 ));
@@ -2146,7 +2159,8 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)if (nvme_revalidate_disk (ns->disk)) goto out_free_disk; -add_disk (ns->disk); +if (ns->type !=NVME_NS_NVM ) +add_disk (ns->disk);if (ns->ms) {struct block_device *bd =bdget_disk (ns->disk,0 );if (!bd)
@@ -2345,6 +2359,9 @@ static void nvme_free_namespace(struct nvme_ns *ns) {list_del (&ns->list); +if (ns->type ==NVME_NS_NVM ) +nvme_nvm_unregister (ns->disk->disk_name); +spin_lock (&dev_list_lock); ns->disk->private_data =NULL ;spin_unlock (&dev_list_lock);
drivers/block/nvme-lightnvm.c new file +568 -0
568 lines not on this page · raw message
include/linux/nvme.h +6 -0
@@ -19,6 +19,7 @@#include <linux/pci.h> #include <linux/kref.h> #include <linux/blk-mq.h> +#include <linux/lightnvm.h> struct nvme_bar {__u64 cap;/* Controller Capabilities */
@@ -41,6 +42,7 @@ struct nvme_bar {#define NVME_CAP_STRIDE (cap) (((cap) >> 32) & 0xf)#define NVME_CAP_MPSMIN (cap) (((cap) >> 48) & 0xf)#define NVME_CAP_MPSMAX (cap) (((cap) >> 52) & 0xf) +#define NVME_CAP_LIGHTNVM (cap) (((cap) >> 38) & 0x1)#define NVME_CMB_BIR (cmbloc) ((cmbloc) & 0x7)#define NVME_CMB_OFST (cmbloc) (((cmbloc) >> 12) & 0xfffff)
@@ -56,6 +58,7 @@ struct nvme_bar {enum {NVME_CC_ENABLE =1 <<0 ,NVME_CC_CSS_NVM =0 <<4 , +NVME_CC_CSS_LIGHTNVM =1 <<4 ,NVME_CC_MPS_SHIFT =7 ,NVME_CC_ARB_RR =0 <<11 ,NVME_CC_ARB_WRRU =1 <<11 ,
@@ -138,6 +141,7 @@ struct nvme_ns {u16 ms;bool ext;u8 pi_type; +int type;u64 mode_select_num_blocks;u32 mode_select_block_len; };
@@ -184,4 +188,6 @@ int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);int nvme_sg_io32 (struct nvme_ns *ns,unsigned long arg);int nvme_sg_get_version_num (int __user *ip); +int nvme_nvm_register (struct request_queue *q,char *disk_name); +void nvme_nvm_unregister (char *disk_name);#endif /* _LINUX_NVME_H */
include/uapi/linux/nvme.h +3 -0
@@ -130,6 +130,7 @@ struct nvme_id_ns {enum {NVME_NS_FEAT_THIN =1 <<0 , +NVME_NS_FEAT_NVM =1 <<3 ,NVME_NS_FLBAS_LBA_MASK =0xf ,NVME_NS_FLBAS_META_EXT =0x10 ,NVME_LBAF_RP_BEST =0 ,
@@ -146,6 +147,8 @@ enum {NVME_NS_DPS_PI_TYPE1 =1 ,NVME_NS_DPS_PI_TYPE2 =2 ,NVME_NS_DPS_PI_TYPE3 =3 , + + NVME_NS_NVM = 1, }; struct nvme_smart_log {
Signature · 1 line
2.1.4
Quoted 6 lines · Matias Bj?rling
These patches implement support for Open-Channel SSDs.
Applies against axboe's linux-block/for-4.3/drivers and can be found in the
lkml_v7branch at https://github.com/OpenChannelSSD/linuxAny feedback is greatly appreciated.
Hi Matias,
After a reading of your code, that's a great idea.
I tried it with null_nvm and qemu-nvm. I have two questions here.
(1), Why we name it lightnvm? IIUC, this framework
can work for other flashes not only NVMe protocol.
(2), There are gc and bm, but where is the wear leveling?
In hardware?
Thanx
Yang
Quoted 102 lines
Changes since v6:
- Multipage support (Javier Gonzalez)
- General code cleanups
- Fixed memleak on register failureChanges since v5:
Feedback from Christoph Hellwig.
- Created newnull_nvmfromnull_blkto register itself as a lightnvm device.
- Changed the interface of register/unregister to only takedisk_name. The gendisk alloc in nvme is kept. Most instantiations will involve the device gendisk, therefore wait with refactoring to a later time.
- Renamed global parameters incore.candrrpc.cChanges since v4:
- Removegendisk->nvmdependency
- Remove device driver rq private field dependency.
- Update submission and completion. The flow is nowTarget -> Block Manager -> Device Driver, replacing callbacks in device driver.- Abstracted out the block manager into its own module. Other block managers can now be implemented. For example to support fully host-based SSDs.
- No longer exposes the device driver gendisk to user-space.
- Management is moved into/sys/modules/lnvm/parameters/configure_debugChanges since v3:
- Remove dependency on
REQ_NVM_GC
- Refactor nvme integration to usenvme_submit_sync_cmdfor internal commands.
- Fix race condition bug on multiple threads on RRPC target.
- Rename sysfs entry under the block device from nvm to lightnvm. The configuration is found in/sys/block/*/lightnvm/Changes since v2:
Feedback from Paul Bolle:
- Fix license to GPLv2, documentation, compilation. Feedback from Keith Busch:
- nvme: Move lightnvm out and intonvme-lightnvm.c.
- nvme: Set controller css on lightnvm command set.
- nvme: Remove OACS.
Feedback from Christoph Hellwig:
- lightnvm: Move out of block layer into /drivers/lightnvm/core.c
- lightnvm: refactorrequest->phys_sectorinto device drivers.
- lightnvm: refactor prep/unprep into device drivers.
- lightnvm: movenvm_devfromrequest_queueto gendisk.New
- Bad block table support (From Javier).
- Update maintainers file.Changes since v1:
- Splitted LightNVM into two parts. A get/put interface for flash blocks and the respective targets that implement flash translation layer logic.
- Updated the patches according to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.Thanks to Jens Axboe, Christoph Hellwig, Keith Busch, Paul Bolle, Javier Gonzalez and Jesper Madsen for discussions and contributions.
Matias Bj?rling (5):
lightnvm: Support for Open-Channel SSDs
lightnvm: Hybrid Open-Channel SSD RRPC target
lightnvm: Hybrid Open-Channel SSD block manager
null_nvm: Lightnvm test driver
nvme: LightNVM supportMAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 5 + drivers/block/Makefile | 2 +- drivers/block/nvme-core.c | 23 +- drivers/block/nvme-lightnvm.c | 568 ++++++++++++++++++ drivers/lightnvm/Kconfig | 36 ++ drivers/lightnvm/Makefile | 8 + drivers/lightnvm/bm_hb.c | 366 ++++++++++++ drivers/lightnvm/bm_hb.h | 46 ++ drivers/lightnvm/core.c | 591 +++++++++++++++++++ drivers/lightnvm/null_nvm.c | 481 +++++++++++++++ drivers/lightnvm/rrpc.c | 1296 +++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/rrpc.h | 236 ++++++++ include/linux/lightnvm.h | 334 +++++++++++ include/linux/nvme.h | 6 + include/uapi/linux/nvme.h | 3 + 17 files changed, 4007 insertions(+), 4 deletions(-)create mode 100644
drivers/block/nvme-lightnvm.ccreate mode 100644drivers/lightnvm/Kconfigcreate mode 100644drivers/lightnvm/Makefilecreate mode 100644drivers/lightnvm/bm_hb.ccreate mode 100644drivers/lightnvm/bm_hb.hcreate mode 100644drivers/lightnvm/core.ccreate mode 100644drivers/lightnvm/null_nvm.ccreate mode 100644drivers/lightnvm/rrpc.ccreate mode 100644drivers/lightnvm/rrpc.hcreate mode 100644include/linux/lightnvm.h
Quoted 6 lines
Quoted 1 line
Any feedback is greatly appreciated.
Hi Matias,
After a reading of your code, that's a great idea.
I tried it withnull_nvmand qemu-nvm. I have two questions here.
Hi Yang, thanks for taking a look. I appreciate it.
Quoted 2 lines
(1), Why we name it lightnvm? IIUC, this framework
can work for other flashes not only NVMe protocol.
Indeed, there are people that work on using it with rapidio. It can also work with SATA/SAS, etc.
The lightnvm name came from the technique to offload devices (which contains non-volatile memory) so they only care about managing the media. In that sense "light" nvm. I'm open to other suggestions. I really wanted the OpenNVM / OpenSSD name, but they where already taken.
Quoted 2 lines
(2), There are gc and bm, but where is the wear leveling?
In hardware?
It should be implemented within each target. The rrpc module implements it within its gc routines. Currently rrpc only looks at the least about of invalid pages. The PE cycles should also be taken into account. Properly some weighted function to decide the cost. Similar to the cost-based gc used in the DFTL paper.
Quoted 3 lines
Thanx
Yang