From patchwork Mon May 28 08:58:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10430175 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 CB1A560249 for ; Mon, 28 May 2018 09:05:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD52528BE1 for ; Mon, 28 May 2018 09:05:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B066928BE5; Mon, 28 May 2018 09:05:37 +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 22CF528BE1 for ; Mon, 28 May 2018 09:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754187AbeE1I67 (ORCPT ); Mon, 28 May 2018 04:58:59 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:54130 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753493AbeE1I6x (ORCPT ); Mon, 28 May 2018 04:58:53 -0400 Received: by mail-wm0-f65.google.com with SMTP id a67-v6so30046486wmf.3 for ; Mon, 28 May 2018 01:58:52 -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=H4JC/4uYZ53iW+3FIJgfAZL0HD7nUDEobIvWTBH2Wd1R1uoOYJREMm2/FfADDzAR7e UL8Jml2OV5uTIJhqhyq8Eg7L0my8b/Vk7H7UNa8aku8jPWtG8Z3eOGlwMIDzJxCSwjqF QOt60vgGjsfeXZuLqk6nn0JXeH3Jy89bv9cCKXxpHcvpEpK/O1Jn0TXWtLaSviHb1wkY 1aO95TpsT4yFvM5HiAf6k33yWwr41SkHba5akI7qKXU1FVuOV+KtBeZdy/S0nN3khpuZ fE9myd1hZppCO715pyF9htr2/Q92eHfzIfIzWRmLT2uaU4zYSu5MAJ/Cst0TRjp9zGF7 md0Q== 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=m3lUUlt7j7UePJqLqS9UAwt/rRqKHLKDPm9ppP3ZRt6sw5/CCw/oC1NwGayl6YMijF 9+IDAaJG2KlXwkXzhCvq7boPiOSEwyStRrO0G8ypv8SD8mdPc7lIseq803AeTgt16KIf ucF/oe+41URmQN7SBD64CXKvsGDnBb8ZXn8iHKfM//YooRgt686skCAihywfdq5o1dNp AIq5+JoVZ0BYPfKUvvvx7q/C9PTyayINmkbXfIFlKMtJL9A10GT94zxU8DcSrmDJtCyO NMBkfnI3Q0vmTAzZuxsuXToSXyKzJ4hL86diUmQuqfglwCD57O2pwEPR05u2Sh44DCL0 vdAA== X-Gm-Message-State: ALKqPwfWHed80UmXwpBlGQIlombkIqBgDSrLVYD4hxnArcn4I4Enbz5n OrkIAEhhnLnpuq0X/GJMCiE0rk0W X-Google-Smtp-Source: ADUXVKIJquyfOhnYDy0os2MA0OsqzLQ17Z5hnNhGeCt6itTYjDxFCkX9AcbzqmSZc8yLzXMaghuBpg== X-Received: by 2002:a2e:86d9:: with SMTP id n25-v6mr7844620ljj.18.1527497931869; Mon, 28 May 2018 01:58:51 -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 u2-v6sm5777848lji.4.2018.05.28.01.58.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 01:58:50 -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, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 02/20] lightnvm: pblk: recheck for bad lines at runtime Date: Mon, 28 May 2018 10:58:23 +0200 Message-Id: <20180528085841.26684-3-mb@lightnvm.io> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180528085841.26684-1-mb@lightnvm.io> References: <20180528085841.26684-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)