From patchwork Tue Jan 26 12:33:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 8121131 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 107E49F818 for ; Tue, 26 Jan 2016 12:35:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9EC82015A for ; Tue, 26 Jan 2016 12:35:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A47EC20165 for ; Tue, 26 Jan 2016 12:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965017AbcAZMfA (ORCPT ); Tue, 26 Jan 2016 07:35:00 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35069 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965005AbcAZMe6 (ORCPT ); Tue, 26 Jan 2016 07:34:58 -0500 Received: by mail-pf0-f193.google.com with SMTP id q63so900781pfb.2; Tue, 26 Jan 2016 04:34:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=kAtquKoYSHh8Ql5EbJCaPJetEapCziTjMaw1B5if7Rg=; b=sP782YWl2EmiMRbrERi1gFAVZAAbp1KDOwmi9e1gKYqhJKB7cZPYjbqE/hIME2Er7Z demoLhUULimpao8tHC+rt8H5VcAwBL+1o/s2sHNNUZmfUIFvS/f3NuMyQKHVlYQIXeM+ 4j5FHmIYvKkgQsm5h0SukZuBn7PvnV2PopO9VrC//YowYUTtQAfyXUPUOOPrmK/0j/ez G5x8wWyvkHjz+CHUT7jwf9fb5v6UJJZZFiJ+Etm3O87tywx9p3aPLSsCwi8Y8rwrj0mo P38QWZGHpH+Kuw3yrGwOaFsLjzga0M9pq2daOc6Y7FFeCFobuVwhGPFBi2ZQcY+35lrQ SL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kAtquKoYSHh8Ql5EbJCaPJetEapCziTjMaw1B5if7Rg=; b=nKIJzhR5vfTyx+Ytg9F3SpdwOG5cHvixplmg+CdbmYUAVs7rLeSilMy59XnW+bmJAt 4j4WRE2/dc+SWjjBMN+62elRP6dhSBzNcVHfA1LAntSRPxXdd8dkWpukufYp54+VgThb 2HkvJULUB5TSSHLp5Mkn5R1erw5kil4d3hcGMyHvJTrIGk3MzewmDe9TflZpKazPHCIi fAdHdlTjSsaysXR7+2I9Z/nI3bmhYaY6hwBG/f5lI2Bkjyab5B/naXZmjH+htLsQAJiL 8jnqdPVJGA9fy/WRPlCzgg7GJvVViyo/1wJYNLAY7ZHvinuT9pn7fYx2/dSYMaVratKI QP/A== X-Gm-Message-State: AG10YORHvKxghh83VHbvnlrDn6l1+YvIU+6M5nhxmN515+4YMqddMs5+4etXpY4VQEftOQ== X-Received: by 10.98.86.214 with SMTP id h83mr33261920pfj.112.1453811698474; Tue, 26 Jan 2016 04:34:58 -0800 (PST) Received: from localhost.localdomain.com ([111.204.49.2]) by smtp.gmail.com with ESMTPSA id fa3sm1674289pab.45.2016.01.26.04.33.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jan 2016 04:34:57 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 1/2] lightnvm: specify target's logical address area Date: Tue, 26 Jan 2016 20:33:52 +0800 Message-Id: <1453811633-3721-1-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We can create more than one target on a lightnvm device by specifying its begin lun and end lun. But only specify the physical address area is not enough, we need to get the corresponding non- intersection logical address area division from the backend device's logcial address space. Otherwise the targets on the device might use the same logical addresses cause incorrect information in the device's l2p table. Signed-off-by: Wenwei Tao --- Changes since v1: - rename some variables - add parentheses for clarity - make gennvm_get_area return int, and add one more sector_t* parameter to pass the begin sector of the corresponding target - rebase to v4.5-rc1 drivers/lightnvm/core.c | 1 + drivers/lightnvm/gennvm.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/gennvm.h | 6 +++++ drivers/lightnvm/rrpc.c | 45 +++++++++++++++++++++++++++++++++--- drivers/lightnvm/rrpc.h | 1 + include/linux/lightnvm.h | 8 +++++++ 6 files changed, 117 insertions(+), 3 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 33224cb..27a59e8 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -470,6 +470,7 @@ static int nvm_core_init(struct nvm_dev *dev) dev->total_pages = dev->total_blocks * dev->pgs_per_blk; INIT_LIST_HEAD(&dev->online_targets); mutex_init(&dev->mlock); + spin_lock_init(&dev->lock); return 0; } diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index 7fb725b..34ea4ff 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -20,6 +20,60 @@ #include "gennvm.h" +static int gennvm_get_area(struct nvm_dev *dev, sector_t *begin_sect, + sector_t size) +{ + struct gen_nvm *gn = dev->mp; + struct gennvm_area *area, *prev; + sector_t begin = 0; + int page_size = dev->sec_size * dev->sec_per_pg; + sector_t max_sectors = (page_size * dev->total_pages) >> 9; + + if (size > max_sectors) + return -EINVAL; + area = kmalloc(sizeof(struct gennvm_area), GFP_KERNEL); + if (!area) + return -ENOMEM; + + spin_lock(&dev->lock); + list_for_each_entry(prev, &gn->area_list, list) { + if (begin + size > prev->begin) { + begin = prev->end; + continue; + } + break; + } + + if ((begin + size) > max_sectors) { + spin_unlock(&dev->lock); + kfree(area); + return -EINVAL; + } + + area->begin = *begin_sect = begin; + area->end = begin + size; + list_add(&area->list, &prev->list); + spin_unlock(&dev->lock); + return 0; +} + +static void gennvm_put_area(struct nvm_dev *dev, sector_t begin) +{ + struct gen_nvm *gn = dev->mp; + struct gennvm_area *area; + + spin_lock(&dev->lock); + list_for_each_entry(area, &gn->area_list, list) { + if (area->begin == begin) { + list_del(&area->list); + spin_unlock(&dev->lock); + kfree(area); + return; + } + } + spin_unlock(&dev->lock); +} + static void gennvm_blocks_free(struct nvm_dev *dev) { struct gen_nvm *gn = dev->mp; @@ -230,6 +284,7 @@ static int gennvm_register(struct nvm_dev *dev) gn->dev = dev; gn->nr_luns = dev->nr_luns; + INIT_LIST_HEAD(&gn->area_list); dev->mp = gn; ret = gennvm_luns_init(dev, gn); @@ -466,6 +521,10 @@ static struct nvmm_type gennvm = { .get_lun = gennvm_get_lun, .lun_info_print = gennvm_lun_info_print, + + .get_area = gennvm_get_area, + .put_area = gennvm_put_area, + }; static int __init gennvm_module_init(void) diff --git a/drivers/lightnvm/gennvm.h b/drivers/lightnvm/gennvm.h index 9c24b5b..04d7c23 100644 --- a/drivers/lightnvm/gennvm.h +++ b/drivers/lightnvm/gennvm.h @@ -39,8 +39,14 @@ struct gen_nvm { int nr_luns; struct gen_lun *luns; + struct list_head area_list; }; +struct gennvm_area { + struct list_head list; + sector_t begin; + sector_t end; /* end is excluded */ +}; #define gennvm_for_each_lun(bm, lun, i) \ for ((i) = 0, lun = &(bm)->luns[0]; \ (i) < (bm)->nr_luns; (i)++, lun = &(bm)->luns[(i)]) diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index d8c7595..c8c27f9 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -1042,7 +1042,18 @@ static int rrpc_map_init(struct rrpc *rrpc) { struct nvm_dev *dev = rrpc->dev; sector_t i; - int ret; + u64 slba; + int ret, page_size; + int page_shfit, nr_pages; + + page_size = dev->sec_per_pg * dev->sec_size; + page_shfit = ilog2(page_size); + nr_pages = rrpc->nr_luns * + dev->nr_planes * + dev->blks_per_lun * + dev->pgs_per_blk; + slba = rrpc->soffset >> (page_shfit - 9); + rrpc->trans_map = vzalloc(sizeof(struct rrpc_addr) * rrpc->nr_pages); if (!rrpc->trans_map) @@ -1065,8 +1076,7 @@ static int rrpc_map_init(struct rrpc *rrpc) return 0; /* Bring up the mapping table from device */ - ret = dev->ops->get_l2p_tbl(dev, 0, dev->total_pages, - rrpc_l2p_update, rrpc); + ret = dev->ops->get_l2p_tbl(dev, slba, nr_pages, rrpc_l2p_update, rrpc); if (ret) { pr_err("nvm: rrpc: could not read L2P table.\n"); return -EINVAL; @@ -1189,12 +1199,33 @@ err: return -ENOMEM; } +static int rrpc_area_init(struct rrpc *rrpc, sector_t *begin) +{ + struct nvm_dev *dev = rrpc->dev; + struct nvmm_type *mt = dev->mt; + sector_t size = rrpc->nr_luns * + dev->sec_per_lun * + dev->sec_size; + + size >>= 9; + return mt->get_area(dev, begin, size); +} + +static void rrpc_area_free(struct rrpc *rrpc) +{ + struct nvm_dev *dev = rrpc->dev; + struct nvmm_type *mt = dev->mt; + + mt->put_area(dev, rrpc->soffset); +} + static void rrpc_free(struct rrpc *rrpc) { rrpc_gc_free(rrpc); rrpc_map_free(rrpc); rrpc_core_free(rrpc); rrpc_luns_free(rrpc); + rrpc_area_free(rrpc); kfree(rrpc); } @@ -1315,6 +1346,7 @@ static void *rrpc_init(struct nvm_dev *dev, struct gendisk *tdisk, struct request_queue *bqueue = dev->q; struct request_queue *tqueue = tdisk->queue; struct rrpc *rrpc; + sector_t soffset; int ret; if (!(dev->identity.dom & NVM_RSP_L2P)) { @@ -1340,6 +1372,13 @@ static void *rrpc_init(struct nvm_dev *dev, struct gendisk *tdisk, /* simple round-robin strategy */ atomic_set(&rrpc->next_lun, -1); + ret = rrpc_area_init(rrpc, &soffset); + if (ret < 0) { + pr_err("nvm: rrpc: could not initialize area\n"); + return ERR_PTR(ret); + } + rrpc->soffset = soffset; + ret = rrpc_luns_init(rrpc, lun_begin, lun_end); if (ret) { pr_err("nvm: rrpc: could not initialize luns\n"); diff --git a/drivers/lightnvm/rrpc.h b/drivers/lightnvm/rrpc.h index ef13ac7..9380c68 100644 --- a/drivers/lightnvm/rrpc.h +++ b/drivers/lightnvm/rrpc.h @@ -97,6 +97,7 @@ struct rrpc { struct nvm_dev *dev; struct gendisk *disk; + sector_t soffset; /* logical sector offset */ u64 poffset; /* physical page offset */ int lun_offset; diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index d675011..18f1bb0 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -351,6 +351,7 @@ struct nvm_dev { char name[DISK_NAME_LEN]; struct mutex mlock; + spinlock_t lock; }; static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev, @@ -463,6 +464,9 @@ typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int); typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *); +typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t); +typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t); + struct nvmm_type { const char *name; unsigned int version[3]; @@ -487,6 +491,10 @@ struct nvmm_type { /* Statistics */ nvmm_lun_info_print_fn *lun_info_print; + + nvmm_get_area_fn *get_area; + nvmm_put_area_fn *put_area; + struct list_head list; };