From patchwork Fri Jun 1 13:04:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10443391 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 342E6602BC for ; Fri, 1 Jun 2018 13:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27DF528CC6 for ; Fri, 1 Jun 2018 13:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C88928CDD; Fri, 1 Jun 2018 13:09:08 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 AB63F28CD4 for ; Fri, 1 Jun 2018 13:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751342AbeFANJG (ORCPT ); Fri, 1 Jun 2018 09:09:06 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:43522 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751837AbeFANEr (ORCPT ); Fri, 1 Jun 2018 09:04:47 -0400 Received: by mail-lf0-f65.google.com with SMTP id n18-v6so14712127lfh.10 for ; Fri, 01 Jun 2018 06:04:46 -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=ii462TkXZnpoLxbk9hCfijjWq4Zq4MtCLHRs0Rzhln4=; b=XJYaKBu2d8e5BHGWzLD8WKyF6DJSTJ72NXrHGfXLaGjohWbibyB9YJ62Cb2LhyY2BP G4e5h2koMk1jbesthaCD2E8A0aEIHi9UO2VaEAGbD9TCdNcmDBWmaGo76YZ4Tp8YM+rw p8Aa24w6tS70Ufv0cnjF/bJqdH1EzQGNtSm00VkBV0cSB9ZS17/Dt66SNf0sB9xk+c2n 9L3kVCfni8fzqkPWsZ5DBj+yqzUfSFlVL+OqdqUTRweEgTCFEomP/blUhG3+kY2byUar nThnTHMStlWcOis+dJ8MrNJYxChSR98f+FdALCyOOlQZPVMqNWN0vy/xqd+PZXe4S0p+ hiRg== 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=ii462TkXZnpoLxbk9hCfijjWq4Zq4MtCLHRs0Rzhln4=; b=CzoyDOF1Ss9qPa9G68nJhYblZFVVdUzFyjoGcNoD0FI2ru/cszge4GpupQdFVoErmy FveP4ViZoS5ypHlxBKSXw1u8mrxCmyrj4JdQYgOUgF5ONr4wGu+H//CeHeQ4acrQBGew CODId/X5YgV4+nCGe7sgj57+SvDyk1yOBOdb8nOCygYQ3iewhPFm43dL/iQ4EfWvkP3w Fp6k4xELCIRE2xAB89BrRV7fv/hpNjAkvOUSgrNJ6lONsgmrEZ2aM+r4QM+07P4B+6jv LOwV9x+hTIXd+e7irlJEJQvrTMldeOAss52CrJetyDcx5B8Evd4vX83S8z/UNkVM/yPA QqEA== X-Gm-Message-State: ALKqPwfKTsbJj2h8C13W8sX8iEf0tQu92RU2INwndrkxx2iPtM1oQquE nv7oxnKsH+yc4V+AfVf++GIwYQ== X-Google-Smtp-Source: ADUXVKLOI4SSsx0AdmQ9oqNc+gTEQTfpK6jNi0M7Myw2NpLCwGP7wZ4zvgwSG8Inr9JxFq9PK1TWiQ== X-Received: by 2002:a2e:458a:: with SMTP id s132-v6mr5095171lja.92.1527858285606; Fri, 01 Jun 2018 06:04:45 -0700 (PDT) Received: from Macroninja.cnexlabs.com (95-166-82-66-cable.dk.customer.tdc.net. [95.166.82.66]) by smtp.gmail.com with ESMTPSA id g5-v6sm303161lje.21.2018.06.01.06.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 06:04:44 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, javier@cnexlabs.com, igor.j.konopko@intel.com, marcin.dziegielewski@intel.com, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 02/18] lightnvm: pblk: recheck for bad lines at runtime Date: Fri, 1 Jun 2018 15:04:16 +0200 Message-Id: <20180601130432.30866-3-mb@lightnvm.io> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601130432.30866-1-mb@lightnvm.io> References: <20180601130432.30866-1-mb@lightnvm.io> 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 From: Javier González Bad blocks can grow at runtime. Check that the number of valid blocks in a line are within the sanity threshold before allocating the line for new writes. Signed-off-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/pblk-core.c | 38 ++++++++++++++++++++++++++++---------- drivers/lightnvm/pblk-init.c | 11 +++++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index 94d5d97c9d8a..2cad918434a7 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -1174,7 +1174,8 @@ static int pblk_prepare_new_line(struct pblk *pblk, struct pblk_line *line) static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) { struct pblk_line_meta *lm = &pblk->lm; - int blk_to_erase; + int blk_in_line = atomic_read(&line->blk_in_line); + int blk_to_erase, ret; line->map_bitmap = kzalloc(lm->sec_bitmap_len, GFP_ATOMIC); if (!line->map_bitmap) @@ -1183,8 +1184,8 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) /* will be initialized using bb info from map_bitmap */ line->invalid_bitmap = kmalloc(lm->sec_bitmap_len, GFP_ATOMIC); if (!line->invalid_bitmap) { - kfree(line->map_bitmap); - return -ENOMEM; + ret = -ENOMEM; + goto fail_free_map_bitmap; } /* Bad blocks do not need to be erased */ @@ -1199,16 +1200,19 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) blk_to_erase = pblk_prepare_new_line(pblk, line); line->state = PBLK_LINESTATE_FREE; } else { - blk_to_erase = atomic_read(&line->blk_in_line); + blk_to_erase = blk_in_line; + } + + if (blk_in_line < lm->min_blk_line) { + ret = -EAGAIN; + goto fail_free_invalid_bitmap; } if (line->state != PBLK_LINESTATE_FREE) { - kfree(line->map_bitmap); - kfree(line->invalid_bitmap); - spin_unlock(&line->lock); WARN(1, "pblk: corrupted line %d, state %d\n", line->id, line->state); - return -EAGAIN; + ret = -EINTR; + goto fail_free_invalid_bitmap; } line->state = PBLK_LINESTATE_OPEN; @@ -1222,6 +1226,16 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) kref_init(&line->ref); return 0; + +fail_free_invalid_bitmap: + spin_unlock(&line->lock); + kfree(line->invalid_bitmap); + line->invalid_bitmap = NULL; +fail_free_map_bitmap: + kfree(line->map_bitmap); + line->map_bitmap = NULL; + + return ret; } int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) @@ -1292,10 +1306,14 @@ struct pblk_line *pblk_line_get(struct pblk *pblk) ret = pblk_line_prepare(pblk, line); if (ret) { - if (ret == -EAGAIN) { + switch (ret) { + case -EAGAIN: + list_add(&line->list, &l_mg->bad_list); + goto retry; + case -EINTR: list_add(&line->list, &l_mg->corrupt_list); goto retry; - } else { + default: pr_err("pblk: failed to prepare line %d\n", line->id); list_add(&line->list, &l_mg->free_list); l_mg->nr_free_lines++; diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index dee64f91227d..8f8c9abd14fc 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -127,10 +127,8 @@ static int pblk_l2p_recover(struct pblk *pblk, bool factory_init) if (!line) { /* Configure next line for user data */ line = pblk_line_get_first_data(pblk); - if (!line) { - pr_err("pblk: line list corrupted\n"); + if (!line) return -EFAULT; - } } return 0; @@ -141,6 +139,7 @@ static int pblk_l2p_init(struct pblk *pblk, bool factory_init) sector_t i; struct ppa_addr ppa; size_t map_size; + int ret = 0; map_size = pblk_trans_map_size(pblk); pblk->trans_map = vmalloc(map_size); @@ -152,7 +151,11 @@ static int pblk_l2p_init(struct pblk *pblk, bool factory_init) for (i = 0; i < pblk->rl.nr_secs; i++) pblk_trans_map_set(pblk, i, ppa); - return pblk_l2p_recover(pblk, factory_init); + ret = pblk_l2p_recover(pblk, factory_init); + if (ret) + vfree(pblk->trans_map); + + return ret; } static void pblk_rwb_free(struct pblk *pblk)