Received: by 10.192.165.156 with SMTP id m28csp466852imm; Mon, 16 Apr 2018 03:29:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/pClI/h8LsVDjHnus7wJ5hZG7UMqwKDX1wU9ZZ8voWyrp04ha/QeU2KPmaxAwUaEy5Ofd8 X-Received: by 10.99.97.16 with SMTP id v16mr6179452pgb.292.1523874552254; Mon, 16 Apr 2018 03:29:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523874552; cv=none; d=google.com; s=arc-20160816; b=W10R4iy3qK/mEc0hPVznH3s2502Vlf+xQeUdFPLQsUQb59zye9BockIqtyao3DStbq V6jg8Gk+Qvf45Jx9tRSDahIt80N+LBxvlRakilaOEdzQmTDrCa+fgMp3WOMB7HWK1KMG 5Xp1FBmyUmhVOWAdp/PM0NO6S8LJ6dAODDlrJbmmQD/0N9PkX8FAuJdY/FCk039h5++0 snaOwLnrfor9DTQDWjoyIVwWfMPzux0Mn7X+jaS7ZrWoobNgnboHMtmS5jaiAOTqSeTu AIaauClywkzFL3hRutKRL0Zg84briSuJwzI051JDw5GLU6FWv4xtKpmWGlUv+CZOeO+s GWOw== 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=RTi095cy4niOowzbxzxOQaxxFvkZkoJcTnA/MupFL7IwhqfFSeRPD0oT8xilpCd/OP 2Q36dYHNKxf5jKdikMhex+qcOcHrfkScAbH8DbyjESOt3nRT6WD3ef4luCSmXEq7jvOJ Tsapa/jkYIxfX13ivAbcInGJntBzgLGB6lVyd+Fd2pnJGGv2Mve8S45F4PvDyRKRgNRn n90cHCnXgeVUrq7zTFMRjEkhvcm1h4lt4NvO/VKdd2DR4OkMtE6QjNaDZoZ47FpWs9AN lFYxM3X3MGPTBw3EBhEUudNh3cFtL/6nawkT2Os7XBn4LVHs/TPg8ytMVcJP6sVrMEAy /sPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=vTs4IgQc; 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 g12-v6si11561334pla.133.2018.04.16.03.28.58; Mon, 16 Apr 2018 03:29:12 -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=vTs4IgQc; 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 S1754027AbeDPKZq (ORCPT + 99 others); Mon, 16 Apr 2018 06:25:46 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43646 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154AbeDPKZn (ORCPT ); Mon, 16 Apr 2018 06:25:43 -0400 Received: by mail-wr0-f193.google.com with SMTP id y7so24424430wrh.10 for ; Mon, 16 Apr 2018 03:25:42 -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=vTs4IgQcVOT7nBTgXrUsrL9nopiJP4mNVz9WTDoGJ4tKVmbZVXY4lnARm2tLVALYSH Ah/UHTb7v6MmZvXpU+uIIBrn8Uu1laiUGuJy4fjB569b7tNZAgib5zBNWdrPSb+3mL9s bO+3fZoO9gBqUdBHcdpZyvtn/dwK+nAkqbrwRZnizUsvDOd9Ckn+3uXt1zhekxR8pDCf PZnqm1KRdJ9b4WkTc3O08orcVZ39BMqdprzVwxELmrR+B2jOVHTX1NUrBjVpVCxS0A67 dDZcQD9dP/x1bw9TthHh1Ta5sCliiXIAkZCuhOUOeEEWexWYj0weuD44bcAyCh2HdxBX hhiQ== 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=ma+p12kxysaN/G1FoTlXnFMk6ANxSP6sXBoXiBjMWT54CWek5XBMGczjxFI4h+48HD ZBOI1+Y1O7zgweoIaLuHd9BF+e+kswBCGLUufCM0PwbFxgmoU+sQwwY2cjMsrCU7EHnc OAn2it5kJsUud/XDtEDV4MTwcjwqJ9N//YPnAw6mowjpKUHwoa7m0iQfh17JphLLGRVD G2Er+sAFetZxt/64tmHpnTQxK7DeVmbhXQhdGAWW+ghkNKRARTLgHpqwPZETmb0d4h3T +EpSQtZUU+PJgxb+9FQ9BS7/J+gl5oUZXZOKu4sTI6UtUbL5L0njvnxHKwn9JfrVwqJE +Few== X-Gm-Message-State: ALQs6tBrt/zafEnPsf82Akv2Nj9boLVqY6XK5SSBm37JKqPVMcH4JkLZ qpaorzzy2uLiovk27kxpVq/tyZNQ X-Received: by 10.80.177.25 with SMTP id k25mr14373071edd.217.1523874342353; Mon, 16 Apr 2018 03:25:42 -0700 (PDT) Received: from uhalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id q11sm4250074edj.2.2018.04.16.03.25.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 03:25:41 -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, 16 Apr 2018 12:25:23 +0200 Message-Id: <1523874332-6272-3-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523874332-6272-1-git-send-email-javier@cnexlabs.com> References: <1523874332-6272-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