From patchwork Wed Apr 13 08:27: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: 8819491 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 761D8C0553 for ; Wed, 13 Apr 2016 08:26:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A54620256 for ; Wed, 13 Apr 2016 08:26:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A34EC20122 for ; Wed, 13 Apr 2016 08:26:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934373AbcDMI00 (ORCPT ); Wed, 13 Apr 2016 04:26:26 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34077 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934039AbcDMI0V (ORCPT ); Wed, 13 Apr 2016 04:26:21 -0400 Received: by mail-pa0-f65.google.com with SMTP id hb4so3321266pac.1; Wed, 13 Apr 2016 01:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wafvyGgaokYf3MOSzxLT4xxnOBrgJeKL0cm4lbQrDOc=; b=KWsfHbY+waMYTGuM48OiDTre+r3og7H6eibKBlQFPu48JsBP0oM47XC97n/+addlZA HuLFGowWHy6IuXjbdUPF3p2HPY7MQWqhWvgBdua8CCrTk7BC77Rz7NYDQKCYzroqx/iG FCOXcxbYR106mE5awIuFsTuKUzjC6Ur0gczn6GDCWPpXRQjU6iU8KjUIe+H6fpWXcfJ9 oNBMupf8KIcciDV3jC77gbj6/mHiBoGEacxTJr52j/hSwvXqAgvBlf6okAzMcWtn7rTs g8ecqY4skU7LjofI//JrFP8wjrwQfwjiuytKUpYgYFQpYb4Cx9mP0ujzJcVAQxlS/HS+ WhAg== 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:in-reply-to :references; bh=wafvyGgaokYf3MOSzxLT4xxnOBrgJeKL0cm4lbQrDOc=; b=H/qrY2yvQ4lGmmr+vl7PUkO0LslPa4F7bp2OVw06l8LW5A2m/Zg+rAbZN8b8ldQ6vW ljFLInU6jG3s8mtnXtrO/18qXU9wMG+GCirxHKLc6iKIgcT8BUZ9jthX0wtuHDWjxD6Y 1rzHNrXS8Jk2VEGEOMYpx6I5NwfrwTcQTIrlwCzNK9is8bHtrCExUxHnesOynCIXfPma 9r7TAWjBXgnQ1WcrKuP5DUX+a3VMCyXm/0elvcue7UZremaHCiYSf9N5l+x5pbLsm72h QJJLRPTNJJVmEvdRkgqkrxWmEKsKMcMn67rZa61PYvgSUUsNpDJk0m95xFENqofcgEZh c8Fg== X-Gm-Message-State: AOPr4FV+0dFkZGVqWDco7+AtVs4WelvxUBC49rXccuwW51vbPNbXTgI1kR098F6dYl4q8w== X-Received: by 10.66.65.169 with SMTP id y9mr11212713pas.102.1460535980347; Wed, 13 Apr 2016 01:26:20 -0700 (PDT) Received: from taowenwei.bj-memblaze.com ([61.148.242.58]) by smtp.gmail.com with ESMTPSA id bb5sm3764391pac.21.2016.04.13.01.26.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 01:26:19 -0700 (PDT) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 3/3] lightnvm: fix address issues related to multi target Date: Wed, 13 Apr 2016 16:27:52 +0800 Message-Id: <1460536072-1728-3-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 2.7.1.windows.2 In-Reply-To: <1460536072-1728-1-git-send-email-ww.tao0320@gmail.com> References: <1460536072-1728-1-git-send-email-ww.tao0320@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.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=unavailable 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 In rrpc, some of the address operations are based on one target assumption, the global values are always used. Now multi target is available, we should use relative/global values properly. In rrpc_l2p_update, we use relative logical address to deal with trans_map and rev_trans_map, and check the bound of target's own intead of global device's. In rrpc_block_map_update, we should use the global physcical address to compare with the one in trans_map, since we store the global value in it. Signed-off-by: Wenwei Tao --- drivers/lightnvm/rrpc.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index 3143b98..159dc3b 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -116,15 +116,6 @@ static int block_is_full(struct rrpc *rrpc, struct rrpc_block *rblk) return (rblk->next_page == rrpc->dev->sec_per_blk); } -/* Calculate relative addr for the given block, considering instantiated LUNs */ -static u64 block_to_rel_addr(struct rrpc *rrpc, struct rrpc_block *rblk) -{ - struct nvm_block *blk = rblk->parent; - int lun_blk = blk->id % (rrpc->dev->blks_per_lun * rrpc->nr_luns); - - return lun_blk * rrpc->dev->sec_per_blk; -} - /* Calculate global addr for the given block */ static u64 block_to_addr(struct rrpc *rrpc, struct rrpc_block *rblk) { @@ -997,24 +988,29 @@ static void rrpc_map_free(struct rrpc *rrpc) static int rrpc_l2p_update(u64 slba, u32 nlb, __le64 *entries, void *private) { struct rrpc *rrpc = (struct rrpc *)private; - struct nvm_dev *dev = rrpc->dev; - struct rrpc_addr *addr = rrpc->trans_map + slba; - struct rrpc_rev_addr *raddr = rrpc->rev_trans_map; - u64 elba = slba + nlb; - u64 i; + struct rrpc_addr *addr; + struct rrpc_rev_addr *raddr; + u64 i, elba = slba + nlb - 1; - if (unlikely(elba > dev->total_secs)) { + if (unlikely(slba < rrpc->soffset || + elba > rrpc->soffset + rrpc->nr_sects - 1)) { pr_err("nvm: L2P data from device is out of bounds!\n"); return -EINVAL; } + slba -= rrpc->soffset; + addr = rrpc->trans_map + slba; + raddr = rrpc->rev_trans_map; + for (i = 0; i < nlb; i++) { u64 pba = le64_to_cpu(entries[i]); unsigned int mod; /* LNVM treats address-spaces as silos, LBA and PBA are * equally large and zero-indexed. */ - if (unlikely(pba >= dev->total_secs && pba != U64_MAX)) { + if (unlikely((pba < rrpc->poffset || + pba > rrpc->poffset + rrpc->nr_sects - 1) && + (pba != U64_MAX && pba != 0))) { pr_err("nvm: L2P data entry is out of bounds!\n"); return -EINVAL; } @@ -1289,19 +1285,20 @@ static void rrpc_block_map_update(struct rrpc *rrpc, struct rrpc_block *rblk) struct nvm_dev *dev = rrpc->dev; int offset; struct rrpc_addr *laddr; - u64 bpaddr, paddr, pladdr; + u64 paddr, rpaddr, pladdr; + + paddr = block_to_addr(rrpc, rblk); + rpaddr = paddr - rrpc->poffset; - bpaddr = block_to_rel_addr(rrpc, rblk); for (offset = 0; offset < dev->sec_per_blk; offset++) { - paddr = bpaddr + offset; - pladdr = rrpc->rev_trans_map[paddr].addr; + pladdr = rrpc->rev_trans_map[rpaddr + offset].addr; if (pladdr == ADDR_EMPTY) continue; laddr = &rrpc->trans_map[pladdr]; - if (paddr == laddr->addr) { + if (paddr + offset == laddr->addr) { laddr->rblk = rblk; } else { set_bit(offset, rblk->invalid_pages);