Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4295618ima; Mon, 4 Feb 2019 13:51:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IaG39yMTraO45aVE9FYaQdlWG2L+tx9Kd0DZS4j+lsMOVRR0/66ksvOaMeCdMCz04E2qRKC X-Received: by 2002:a63:165e:: with SMTP id 30mr1395298pgw.103.1549317065886; Mon, 04 Feb 2019 13:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549317065; cv=none; d=google.com; s=arc-20160816; b=cz5gOeaVXFshhVuey1DOPKLVs3nLaX8qBW9LrxrGiPsSsrq1o+Y+RAQdlKHiv11E71 4p5C+6ZdgOug2C/mVLG3om3nzw/Y/XG4ez/VSFc3e57fJpVBqg/ZS9MxePylLaEymEx0 5QWpkQ3UVDJO7/tr9VL3+ZDG7Zwq1ULHGmks4oGKIDTVK0nFuHxx0d+1LHsYsCibkZCQ m+3ty9VQVs8Ul0P5YpvZ3ISJ/CSZ/e8FUHweNTQZtPc/NTs/aLk2x8Yr9/s9o1QPTe4x 02buCI12GYxBNrsx2IJtJAD6ujQ2PDp/N9oKnkmcf56Smj/2auGQJm830DsNqGrB1LXz Vmgw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=u2uaSjFTAzt74S+zPV9Y6fyT0EjStLAXSexFtbRvYAM=; b=VGP9SZMudUTogjEqsfCj/eTYqJXSvlBI8lda8fZhUe+PRANIgb/v46BUD/lI4PnfCy ILxU9Ja1yVOpo5Ms+VEZC6/EXaOKSsJ7YYiY9x4R+6r7Krgf5wWS81cb7vD3TPTDlRnr szHeWVCUZ+nSfqjQ/GSFdCP7/JtYHgw2XUgTTpiRZ39+QtTrEfuHXwiqxsiwvjiFasJF /Cj5OCMM0/aR8VkM9xwxl2IAtOSPP3ea9SOhWbnEHMpYQRbzHkb10pMenkb3wFRb7UNf RTLssfRvfiRbBbzcd/JkX/m1TQGnHqqe5nrelrRX6FdOfmrkwCzyg2EjR8cUu5Fq4hyA X9sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=EMQnQdQe; 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 q5si1124120pgg.204.2019.02.04.13.50.50; Mon, 04 Feb 2019 13:51:05 -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=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=EMQnQdQe; 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 S1728654AbfBDVB6 (ORCPT + 99 others); Mon, 4 Feb 2019 16:01:58 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:42891 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726622AbfBDVB5 (ORCPT ); Mon, 4 Feb 2019 16:01:57 -0500 Received: by mail-ua1-f66.google.com with SMTP id d21so450116uap.9 for ; Mon, 04 Feb 2019 13:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owltronix-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=u2uaSjFTAzt74S+zPV9Y6fyT0EjStLAXSexFtbRvYAM=; b=EMQnQdQeni3x54I+xDOZTgPtcT91nrrjdFWw1PIo5qmd7b2O6VQDW7SYf+4U1TO7jd wZEfgEKvJHWcI7oh2TYlDXsRBTN6UpTk3nVtYJMH+fq3JgCjW/wdXBFDFV5/WKBHL/uU R0DirO/r1JLNrBvWmONXP+snEAtNVar8jM7enOJhh7dEtic1F46ZZn6CJzSmbunr5zHJ HNwgW2GN+JoPYsjlsi/YHv0cwIgl/ePbMmNtpVRW641p+VWfwDsZGcNWpddNFf5Dy+U1 +BA4XcwNOM4VTKc7XS8x12v3Tdc7/998FdhQLxEUo6mS9yzqFfqTDmm/A2hb5PWeZjPN XJEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=u2uaSjFTAzt74S+zPV9Y6fyT0EjStLAXSexFtbRvYAM=; b=GCoEfWw8Dt4mkAi2lBYPe6jf9ueldvAAR7FXUW5vhhmg0tB3yNQv7RpxoeiL8WWW8I aGcyQCMbTnAJIm9PKdx11nT4XVkoriG74kmOMHLeffgT2HphQM2e0werWAL0kCTwv2tF 989Ph/R+D1SzMWcbnKsC2S06s+FhHue0utsQT3f1EtKfFVMRJKPxkeAxItCuzr3rNfU6 a7l/Ou6oN/oBgWQMjUtmWWN8tNHcckKRmXUKxXZ4SVIgdHxJgNCKO/N1hYwDsOAeyNBT dF7GhmHZg4z5gdIUEUAoU/WbtxwxLmu+SlycI6ltv8TQ/KAwjWPAmDuy6+SKRAXHby44 Oycw== X-Gm-Message-State: AHQUAua0PO79d7zWNo2PFlseDXRvEL2K7CTLnWnU/Hseit5N/TuYMOWS jebqgNUUp+w92uwdTlrFdIDLGwS7WiQtuzDseUzDLQ== X-Received: by 2002:ab0:77c4:: with SMTP id y4mr578797uar.45.1549314115981; Mon, 04 Feb 2019 13:01:55 -0800 (PST) MIME-Version: 1.0 References: <20190201023806.39895-1-hlitz@ucsc.edu> <7BC68605-5E76-4E0D-8C3E-29B2CB329FEB@javigon.com> In-Reply-To: <7BC68605-5E76-4E0D-8C3E-29B2CB329FEB@javigon.com> From: Hans Holmberg Date: Mon, 4 Feb 2019 22:01:45 +0100 Message-ID: Subject: Re: [PATCH V2] lightnvm: pblk: fix race condition on GC To: =?UTF-8?Q?Javier_Gonz=C3=A1lez?= Cc: Heiner Litz , =?UTF-8?Q?Matias_Bj=C3=B8rling?= , Hans Holmberg , linux-block@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Heiner, it's awesome to get this fixed! Reviewed-by: Hans Holmberg On Mon, Feb 4, 2019 at 9:19 AM Javier Gonz=C3=A1lez wr= ote: > > > On 1 Feb 2019, at 03.38, 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 i= s > > performed, the sectors are ignored by the GC logic and the line is free= d > > before all sectors are moved. When the L2P is finally updated, it conta= ins > > a mapping to a freed line, subsequent reads of the corresponding LBAs f= ail. > > > > This patch introduces a per line counter specifying the number of secto= rs > > that are synced to the device but have not been updated in the L2P. Lin= es > > 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, s= truct 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 =3D ~0x0L, victim_vsc =3D ~0x0L; > > > > victim =3D list_first_entry(group_list, struct pblk_line, list); > > + > > list_for_each_entry(line, group_list, list) { > > - line_vsc =3D le32_to_cpu(*line->vsc); > > - victim_vsc =3D le32_to_cpu(*victim->vsc); > > - if (line_vsc < victim_vsc) > > + if (!atomic_read(&line->sec_to_update)) > > + line_vsc =3D le32_to_cpu(*line->vsc); > > + if (line_vsc < victim_vsc) { > > victim =3D line; > > + victim_vsc =3D le32_to_cpu(*victim->vsc); > > + } > > } > > > > + if (victim_vsc =3D=3D ~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 =3D pblk_gc_get_victim_line(pblk, group_list); > > + if (!line) { > > spin_unlock(&l_mg->gc_lock); > > break; > > } > > > > - line =3D pblk_gc_get_victim_line(pblk, group_list); > > - > > spin_lock(&line->lock); > > WARN_ON(line->state !=3D PBLK_LINESTATE_CLOSED); > > line->state =3D 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, unsi= gned int sentry, > > */ > > if (i < valid_secs) { > > kref_get(&line->ref); > > + atomic_inc(&line->sec_to_update); > > w_ctx =3D pblk_rb_w_ctx(&pblk->rwb, sentry + i); > > w_ctx->ppa =3D ppa_list[i]; > > meta->lba =3D 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 =3D 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 =3D pblk_rb_ptr_wrap(rb, rb->l2p_update, 1= ); > > diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-writ= e.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 =3D 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 metada= ta */ > > > > -- > > 2.17.1 > > > Looks good to me. Again, good marathon-catch! :) > > Reviewed-by: Javier Gonz=C3=A1lez > >