Received: by 10.192.165.148 with SMTP id m20csp3557115imm; Mon, 30 Apr 2018 02:15:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOvuiWqzSQnZgZooOwOJjTaWLonCSXEWSj48Ak+48WAQTFMK2JnJsyr3j2WNiOPO1qQMVd X-Received: by 2002:a17:902:7b90:: with SMTP id w16-v6mr3722434pll.294.1525079726447; Mon, 30 Apr 2018 02:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525079726; cv=none; d=google.com; s=arc-20160816; b=tx+YM4XBHNN02GlNydK7Il1B9qEohjhSR3X9m9y+hbzDR87mDpVRIoawKz0+Q22YMw 7QmeYWyyx/q42LpMM9hL8SBj3dboBKzYba5QkYKs3QEGDBQz9KxF6eRTvqEbR+gx0h2Z BlniR4m354a3+XRR9jG/WN1FeRzdgnB32a+XP4j9tKstBoXx8v4HBoOvnMMUvp84qp3U VcVUbgVeOoweiY0FzE/U1hxv2ChfnA4kUqD9gXUUnxVuPxrTHQERQgt9WyMMACI0LhJi 6+7WozjA6YdlUnNljSasaxZBVlaZ0ki/cNNBxeBkEROY17NfaKL/7Fd3AdIiM/WfUrQ6 zL+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ZfDQeN+q8lRTFLa5iZIkmMdk01IdQAJowiVaIMgQ6H0=; b=tg6bm4G9hcyraCV4E+QDRhKqCA9piuBDpnDv4PpXTbstony88PzC67Fle73z9Jksex 4zeimtilCaBjftWyl/O1DRVXZx7cSSWELN7p07OGGCFWhZTYaQzBWLsmpO4vVLzYBkNv KteJnYhRaY1SKdGvck8U5RLJTZjB0vwF/G3vhPrAoyYLLX0ER84xmsuOmUa1GB/6YBHV 5p1QmV/u9iWPZabUCvuRwZF6xU1Y0LoNNrq+r1zy2gpFLb6QbB1JTDrgg9JX+PEH9O8q /TjyCNSgTFbkCfVQbrVzOxHzIzjbsGrbuGsxyr0NODg9ysxO8JgCCLPFt+RHgup/uZ6p LozQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=CqwDg2dm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c129si6410899pfc.367.2018.04.30.02.15.12; Mon, 30 Apr 2018 02:15:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=CqwDg2dm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753589AbeD3JOn (ORCPT + 99 others); Mon, 30 Apr 2018 05:14:43 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37275 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753581AbeD3JKT (ORCPT ); Mon, 30 Apr 2018 05:10:19 -0400 Received: by mail-wm0-f66.google.com with SMTP id l1so13088661wmb.2 for ; Mon, 30 Apr 2018 02:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZfDQeN+q8lRTFLa5iZIkmMdk01IdQAJowiVaIMgQ6H0=; b=CqwDg2dmx6RfJRdvGakRWovZfeQ1iG7FghOCBYDNsf/dkaNPghpfvFap4i8lxt8Yp3 RvG5Ubq5IpkGTfyGrsKd9Ng9bjAjTau+AoRqjIRzC54slmvcQT2WuNxISmjlsH4y+715 R2gHJMjqp+XZt45lekliDVDOHyCtLt+REY1WGVrMcrBsfXx02+62fU9a6la4A3Nx6h6T UR0ve1Qu7zdBX5W4OfR5jOpc1vBRuBPg6ZmaeaQkJIJu+HqvL76SSb5hKnMH2lQGY/8a B3xJE+HgZK8QMGz0jF3F0IjI+eR57UfMwqwantpsxaIlulaCmnJtqj2urbrBeygnUQGU fWSQ== 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=ZfDQeN+q8lRTFLa5iZIkmMdk01IdQAJowiVaIMgQ6H0=; b=pLJ3q8B8kbIB3WoQGgaGArCwgly+nBfILlPyXzLPn7zNIN5HCUMFlKpRZNF8FtXuc/ o5pAYq/Lyq4IM+XCsIYW06q+he/zJ0pBZ6hOFJySzElk/FR6Iv9belazScSrsMcM98YR DgSTJMA3ymOcnrT0ogZ5Kxx+XUjCFueDhozw+ari02tzR3Q3qlMvjFdWHpT9Vgr4LBfx 78XbHkyW94lifvHAvwD2ZzEVP4vZxrfprGBxksObEAvU056TsYfERHQDwjDoivCoRddp 0pMYfow1kYCcIjnt9oNnJKKZVrl9a2MBc+iAAghseC6xMkbmi01TWDtFRBEtfQj9Pqf9 6tMQ== X-Gm-Message-State: ALQs6tBzrjYjPQr8DSG5jY0UsNW1Yo1OUZMtf4j6YImAW5keTKfHEnf8 5K+oFcIu7JPAUxjtkVLfH+wMbrwE X-Received: by 2002:a50:90fa:: with SMTP id d55-v6mr15598794eda.54.1525079418279; Mon, 30 Apr 2018 02:10:18 -0700 (PDT) Received: from uhalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id b56-v6sm2108638edd.85.2018.04.30.02.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Apr 2018 02:10:17 -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 Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 02/11] lightnvm: pblk: recheck for bad lines at runtime Date: Mon, 30 Apr 2018 11:10:00 +0200 Message-Id: <1525079409-6588-3-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525079409-6588-1-git-send-email-javier@cnexlabs.com> References: <1525079409-6588-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 ceacd10a043e..128101f9e606 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) -- 2.7.4