Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4797589ima; Tue, 5 Feb 2019 01:16:44 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib+DTkSCqLixwBGZC2P9am7Z4FKuwgGwFbkhQmzdTf0uouOO+ixS2VC7Quv/5cPdsvYgJrw X-Received: by 2002:a62:2cf:: with SMTP id 198mr3933929pfc.67.1549358204648; Tue, 05 Feb 2019 01:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549358204; cv=none; d=google.com; s=arc-20160816; b=souFmPl6PqwFGN1h3ach/jQuOmTWqTpiEl063ldAIX8dwLRycZQpqGvDZqRj3p0wxs +dlumpNU1t1A5hqkDt0SDtsAiCgGeblFRNmduG65siopkFtjuh0dy9icp2lcNqipuqi0 lNxs9WvwqfwPNkvzWU7ER+7zXw1tS4cWLqNatOXe7gVDJ6/nDKmoYFgIv7KM+SwHPB6e 0jKaM7qTNG8ydH+DXqk3V2AROh74N+rgzCJqDwITNTK5j4F6UicqR+dtDRtY0pgihgaY SYcWvRrAFT+1GBBQNBt6YEy46zQMs7KbDqZ4brczcvEK1aQEOnLAC4CzPMfC9tl9STxt gHtQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=wBjAkXS6AG0JXtwIUFRzSGrkzWivWXXHkmBnWk14Yzk=; b=kHKUAqxVE+83GvTywSjNJnz6LCAtF4l/GFfsREIh4IM0qwqQpOF9L6R6z32qhEqSZC jDvkAVq5HqYuwKAbRBxU3VNz8cynEMvLnN+kfkVrqI9sM+OmWbzQwy1lnoSQTFhYV2OR LSudfTysD+y1ytwbySe6RC+/yHSAWoXlYp2srYb6DU/W1oHE1zQn0uaZcRbNg1bYDaCw C8wikFsGX7R3A6xWiIvwNwz1D/8G54qhduTLKnEXBfN4MM6ILD0sV8lh9KVv3lfMvW4w 2IwOEHFdFSFJUQnB1vF6cBlbQbZR7op06C9xoGPWOBSe4ZnStIYS8nRqVeyWDkh+Ex0a ENWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=utxcVN2y; 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 x18si2660582pfm.39.2019.02.05.01.16.27; Tue, 05 Feb 2019 01:16:44 -0800 (PST) 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=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=utxcVN2y; 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 S1728037AbfBEJPF (ORCPT + 99 others); Tue, 5 Feb 2019 04:15:05 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39216 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727573AbfBEJPE (ORCPT ); Tue, 5 Feb 2019 04:15:04 -0500 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so2238954ljh.6 for ; Tue, 05 Feb 2019 01:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wBjAkXS6AG0JXtwIUFRzSGrkzWivWXXHkmBnWk14Yzk=; b=utxcVN2ydwFpn9DQ5K92r7Yps74JUdoEMBxNYBJhud4rp7Cmg1zNRCs9E4KNo1xKBS eg83IBohNdaFp5bSGz55xLmQBUCnlQUZxhJOW9SmXK4+PudbIuoo13oDadYtT39yNo8p PIld7stTfMlO8Eqf4f5vytSmptjn49hn0diHkqW0iHjfbwGcGcZFFpLoviU6cMMaWZ3g devUN1xPRoBl/pXNiXbEJVKyWE0uFeDPbQ2fj0Lx32NusZNL/aU6pTA03XR/WgeNAqNU 0yQQC0D8lCUMHztU5YTamhmNjHQhacaOqWtoU69At08quSbCXOerXr04g6LtXmCGF3Yz MmOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wBjAkXS6AG0JXtwIUFRzSGrkzWivWXXHkmBnWk14Yzk=; b=n3oMKtwLYFqoIRqCwehCYQ6uMcVMFbvM7pMzGs9jRxD+haW2q0sHCg4twE/hPF1TYI Ir5ODhXIywBtX6PRJOBQYSRm8a441x/DyAVXgN0EBLFtoK673HbnhSt5xS4ysykdf1cI Jbw8svV3ZFKmr9xwXy/ch94jNM7d82gEmMz40Jb1Y0G+vIzmOH4SrLFFMdVuiVOVeyj/ GS5QNtm9CVHFvvnksNlUUIf2lUU//w28bOVMKk6/eINFGv86TjlotZjcmNFosoEO4b3I RPSFEVtUvY3eYoo6nYgaoo8y0UhZgVdPSkEIWJ1R6NzX5U7xgfYYPsMK7ThX99KAty8h SBfw== X-Gm-Message-State: AHQUAuY6FIh3iNVA8+aZ6XxC1JIRu6VIUYhgUNpd5AvuWDqGwVzv7Qnx q8bGvxxRrYmd6PtCdBb6+kGlKnNhavE= X-Received: by 2002:a2e:914b:: with SMTP id q11-v6mr2296773ljg.164.1549358101293; Tue, 05 Feb 2019 01:15:01 -0800 (PST) Received: from [192.168.0.36] (2-111-91-225-cable.dk.customer.tdc.net. [2.111.91.225]) by smtp.googlemail.com with ESMTPSA id d5sm3602300lfi.65.2019.02.05.01.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 01:15:00 -0800 (PST) Subject: Re: [PATCH V2] lightnvm: pblk: fix race condition on GC To: Heiner Litz Cc: javier@javigon.com, hans.holmberg@cnexlabs.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190201023806.39895-1-hlitz@ucsc.edu> From: =?UTF-8?Q?Matias_Bj=c3=b8rling?= Message-ID: <79e30230-2af4-2fd4-f6ee-35e47c36291c@lightnvm.io> Date: Tue, 5 Feb 2019 10:14:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190201023806.39895-1-hlitz@ucsc.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/1/19 3:38 AM, Heiner Litz wrote: > This patch fixes a race condition where a write is mapped to the last > sectors of a line. The write is synced to the device but the L2P is not > updated yet. When the line is garbage collected before the L2P update is > performed, the sectors are ignored by the GC logic and the line is freed > before all sectors are moved. When the L2P is finally updated, it contains > a mapping to a freed line, subsequent reads of the corresponding LBAs fail. > > This patch introduces a per line counter specifying the number of sectors > that are synced to the device but have not been updated in the L2P. Lines > with a counter of greater than zero will not be selected for GC. > > Signed-off-by: Heiner Litz > --- > > v2: changed according to Javier's comment. Instead of performing check > while holding the trans_lock, add an atomic per line counter > > drivers/lightnvm/pblk-core.c | 1 + > drivers/lightnvm/pblk-gc.c | 20 +++++++++++++------- > drivers/lightnvm/pblk-map.c | 1 + > drivers/lightnvm/pblk-rb.c | 1 + > drivers/lightnvm/pblk-write.c | 1 + > drivers/lightnvm/pblk.h | 1 + > 6 files changed, 18 insertions(+), 7 deletions(-) > > diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c > index eabcbc119681..b7ed0502abef 100644 > --- a/drivers/lightnvm/pblk-core.c > +++ b/drivers/lightnvm/pblk-core.c > @@ -1278,6 +1278,7 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) > spin_unlock(&line->lock); > > kref_init(&line->ref); > + atomic_set(&line->sec_to_update, 0); > > return 0; > } > diff --git a/drivers/lightnvm/pblk-gc.c b/drivers/lightnvm/pblk-gc.c > index 2fa118c8eb71..26a52ea7ec45 100644 > --- a/drivers/lightnvm/pblk-gc.c > +++ b/drivers/lightnvm/pblk-gc.c > @@ -365,16 +365,22 @@ static struct pblk_line *pblk_gc_get_victim_line(struct pblk *pblk, > struct list_head *group_list) > { > struct pblk_line *line, *victim; > - int line_vsc, victim_vsc; > + unsigned int line_vsc = ~0x0L, victim_vsc = ~0x0L; > > victim = list_first_entry(group_list, struct pblk_line, list); > + > list_for_each_entry(line, group_list, list) { > - line_vsc = le32_to_cpu(*line->vsc); > - victim_vsc = le32_to_cpu(*victim->vsc); > - if (line_vsc < victim_vsc) > + if (!atomic_read(&line->sec_to_update)) > + line_vsc = le32_to_cpu(*line->vsc); > + if (line_vsc < victim_vsc) { > victim = line; > + victim_vsc = le32_to_cpu(*victim->vsc); > + } > } > > + if (victim_vsc == ~0x0) > + return NULL; > + > return victim; > } > > @@ -448,13 +454,13 @@ static void pblk_gc_run(struct pblk *pblk) > > do { > spin_lock(&l_mg->gc_lock); > - if (list_empty(group_list)) { > + > + line = pblk_gc_get_victim_line(pblk, group_list); > + if (!line) { > spin_unlock(&l_mg->gc_lock); > break; > } > > - line = pblk_gc_get_victim_line(pblk, group_list); > - > spin_lock(&line->lock); > WARN_ON(line->state != PBLK_LINESTATE_CLOSED); > line->state = PBLK_LINESTATE_GC; > diff --git a/drivers/lightnvm/pblk-map.c b/drivers/lightnvm/pblk-map.c > index 79df583ea709..7fbc99b60cac 100644 > --- a/drivers/lightnvm/pblk-map.c > +++ b/drivers/lightnvm/pblk-map.c > @@ -73,6 +73,7 @@ static int pblk_map_page_data(struct pblk *pblk, unsigned int sentry, > */ > if (i < valid_secs) { > kref_get(&line->ref); > + atomic_inc(&line->sec_to_update); > w_ctx = pblk_rb_w_ctx(&pblk->rwb, sentry + i); > w_ctx->ppa = ppa_list[i]; > meta->lba = cpu_to_le64(w_ctx->lba); > diff --git a/drivers/lightnvm/pblk-rb.c b/drivers/lightnvm/pblk-rb.c > index a6133b50ed9c..03c241b340ea 100644 > --- a/drivers/lightnvm/pblk-rb.c > +++ b/drivers/lightnvm/pblk-rb.c > @@ -260,6 +260,7 @@ static int __pblk_rb_update_l2p(struct pblk_rb *rb, unsigned int to_update) > entry->cacheline); > > line = pblk_ppa_to_line(pblk, w_ctx->ppa); > + atomic_dec(&line->sec_to_update); > kref_put(&line->ref, pblk_line_put); > clean_wctx(w_ctx); > rb->l2p_update = pblk_rb_ptr_wrap(rb, rb->l2p_update, 1); > diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c > index 06d56deb645d..6593deab52da 100644 > --- a/drivers/lightnvm/pblk-write.c > +++ b/drivers/lightnvm/pblk-write.c > @@ -177,6 +177,7 @@ static void pblk_prepare_resubmit(struct pblk *pblk, unsigned int sentry, > * re-map these entries > */ > line = pblk_ppa_to_line(pblk, w_ctx->ppa); > + atomic_dec(&line->sec_to_update); > kref_put(&line->ref, pblk_line_put); > } > spin_unlock(&pblk->trans_lock); > diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h > index a6386d5acd73..ac3ab778e976 100644 > --- a/drivers/lightnvm/pblk.h > +++ b/drivers/lightnvm/pblk.h > @@ -487,6 +487,7 @@ struct pblk_line { > __le32 *vsc; /* Valid sector count in line */ > > struct kref ref; /* Write buffer L2P references */ > + atomic_t sec_to_update; /* Outstanding L2P updates to ppa */ > > struct pblk_w_err_gc *w_err_gc; /* Write error gc recovery metadata */ > > Thanks Heiner. Applied for 5.1.