From patchwork Wed Sep 6 10:50:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 9940421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9342A602CC for ; Wed, 6 Sep 2017 10:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8698728556 for ; Wed, 6 Sep 2017 10:58:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B36628BA1; Wed, 6 Sep 2017 10:58:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A96B28556 for ; Wed, 6 Sep 2017 10:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753275AbdIFK5p (ORCPT ); Wed, 6 Sep 2017 06:57:45 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:33268 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753270AbdIFKwi (ORCPT ); Wed, 6 Sep 2017 06:52:38 -0400 Received: by mail-wm0-f45.google.com with SMTP id f145so15984338wme.0 for ; Wed, 06 Sep 2017 03:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X7WAH12SqHkrY9Qx/A+nslQf/MiOZC0ga8vUPfoFbQ4=; b=Uv0SF4Tv6XRntkZDQi21whcIKyWCio4suwTBPcZMdBnEHjhkGOXytnsnnY/upGxizo s+pSayyCzL4/f7keMqhW25oZ42AV292d+1OuTxZ5abFg/k1PM+7108CuOn7f056zn4kb YkuTxe9+wU8mXPJW7vLf6dgBNnFS/UBapkOmfOvm3qMHb9JcLjexm8fEVZoqP591QNHb 4dPYXcyjhlHg/WEptLivS1PkgpzAXIu894UYaYq+b7WPdEl4drfP4HhWfR7CTE/rSv9G WCXDabAIvuA4Tc6VddjukZxYYSSiA3K1tBhknJSscBeorjPmOgNAqR7W6eRJxfErUgpB /tBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X7WAH12SqHkrY9Qx/A+nslQf/MiOZC0ga8vUPfoFbQ4=; b=k/oxoN/gy3y30ezmAq1HHg/5SOL82WgkUs5ekJVm2M04o7ftuHF0mQbfxscJqPm4uj 8/JxGGpNeyvPLcycwYt8ZqDYW0glYA59NJ4WX0m2QgcpB3te+jY/SfF/aTjV2kn+w7Tt WhXCLPcQtzIcf4Ng4Tuv2jUsJdZ9W2uqTGIIw5dCcZ9VSskmyKYwCGGoXn7mfiti/lu3 EltTndHsvxCl8SlH2Azu0GC6WQkGc6nijZcDjgkjn0ft98kiKMjKLZiRnO4jUcBquYu/ i+zZkebYILp/7QMz9ob9Oa6utOcJ8d2UcFwg5aW7zTpLBsOICXeDjkjIxoE6mDG8uwno 5SmQ== X-Gm-Message-State: AHPjjUgZtYa8dCIXApdS3xUmt/aBX7bY+mlGlijz6zGLkH5j2oh40iND 9xWFb+lgZ2JhTuXE X-Google-Smtp-Source: ADKCNb55DIeBJ0ECgH1yJUGRGkUjmNRI4jk8vrD0vN0G3ovdTKURqD1J2Z8ZM9gidq67UsjAsQve6w== X-Received: by 10.80.145.40 with SMTP id e37mr5580081eda.193.1504695157469; Wed, 06 Sep 2017 03:52:37 -0700 (PDT) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id b8sm1044007edi.46.2017.09.06.03.52.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Sep 2017 03:52:36 -0700 (PDT) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io, axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 02/18] lightnvm: pblk: refactor read lba sanity check Date: Wed, 6 Sep 2017 12:50:55 +0200 Message-Id: <1504695071-25928-3-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504695071-25928-1-git-send-email-javier@cnexlabs.com> References: <1504695071-25928-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactor lba sanity check on read path to avoid code duplication. Signed-off-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/pblk-read.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c index d682e89e6493..db9a3b575f62 100644 --- a/drivers/lightnvm/pblk-read.c +++ b/drivers/lightnvm/pblk-read.c @@ -39,21 +39,14 @@ static int pblk_read_from_cache(struct pblk *pblk, struct bio *bio, } static void pblk_read_ppalist_rq(struct pblk *pblk, struct nvm_rq *rqd, - unsigned long *read_bitmap) + sector_t blba, unsigned long *read_bitmap) { struct bio *bio = rqd->bio; struct ppa_addr ppas[PBLK_MAX_REQ_ADDRS]; - sector_t blba = pblk_get_lba(bio); int nr_secs = rqd->nr_ppas; bool advanced_bio = false; int i, j = 0; - /* logic error: lba out-of-bounds. Ignore read request */ - if (blba + nr_secs >= pblk->rl.nr_secs) { - WARN(1, "pblk: read lbas out of bounds\n"); - return; - } - pblk_lookup_l2p_seq(pblk, ppas, blba, nr_secs); for (i = 0; i < nr_secs; i++) { @@ -263,17 +256,10 @@ static int pblk_fill_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, } static void pblk_read_rq(struct pblk *pblk, struct nvm_rq *rqd, - unsigned long *read_bitmap) + sector_t lba, unsigned long *read_bitmap) { struct bio *bio = rqd->bio; struct ppa_addr ppa; - sector_t lba = pblk_get_lba(bio); - - /* logic error: lba out-of-bounds. Ignore read request */ - if (lba >= pblk->rl.nr_secs) { - WARN(1, "pblk: read lba out of bounds\n"); - return; - } pblk_lookup_l2p_seq(pblk, &ppa, lba, 1); @@ -309,14 +295,19 @@ static void pblk_read_rq(struct pblk *pblk, struct nvm_rq *rqd, int pblk_submit_read(struct pblk *pblk, struct bio *bio) { struct nvm_tgt_dev *dev = pblk->dev; + sector_t blba = pblk_get_lba(bio); unsigned int nr_secs = pblk_get_secs(bio); struct nvm_rq *rqd; unsigned long read_bitmap; /* Max 64 ppas per request */ unsigned int bio_init_idx; int ret = NVM_IO_ERR; - if (nr_secs > PBLK_MAX_REQ_ADDRS) + /* logic error: lba out-of-bounds. Ignore read request */ + if (blba >= pblk->rl.nr_secs || nr_secs > PBLK_MAX_REQ_ADDRS) { + WARN(1, "pblk: read lba out of bounds (lba:%llu, nr:%d)\n", + (unsigned long long)blba, nr_secs); return NVM_IO_ERR; + } bitmap_zero(&read_bitmap, nr_secs); @@ -348,9 +339,9 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) rqd->ppa_list = rqd->meta_list + pblk_dma_meta_size; rqd->dma_ppa_list = rqd->dma_meta_list + pblk_dma_meta_size; - pblk_read_ppalist_rq(pblk, rqd, &read_bitmap); + pblk_read_ppalist_rq(pblk, rqd, blba, &read_bitmap); } else { - pblk_read_rq(pblk, rqd, &read_bitmap); + pblk_read_rq(pblk, rqd, blba, &read_bitmap); } bio_get(bio);