Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp908019ybm; Wed, 27 May 2020 10:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHkP9VNA6wpfJeT/6iVOCBUOXFLgZDmoCGKbpNTwT3O9UKHdDmhviW2Gvc/gr2hyY+JXDG X-Received: by 2002:a50:e44d:: with SMTP id e13mr3764657edm.373.1590601934211; Wed, 27 May 2020 10:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590601934; cv=none; d=google.com; s=arc-20160816; b=UchAzZchF9dR60RhH431LNaRxUsaSXl6s/6jwovAYz7ZK6Tz0VHy325pxYJei7MZGT j4PYaUtG582Ihma5d6Au4uMvW587e8f7IKlx0uxG13UQ/ZRrRWxJ82UVHfZEH/LmeYnI PgXfjGmR3OQAEGA0for66ss/tPOJo5P+1RmLXe//3Li7JI8BxsTVp3UxHcVrBzB2KMR9 K1AkBswce0YQLlGucJpwnmGpi26mqeMwUxkd8bOWiCMVMr2TuQM6Is6Bo4i7xQK0RIxD 7LS7R8BozDjeAglTRZg4qqEROA3z6DFF/YjlGRnEqqxjOHQwnsqVfrPI/EfVsw1E6p6O nBig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=93nc9UactqldkZQsy9TxG0/gpUJkP4kzPyvHUSXM25c=; b=xQNCqZHR4voRB8lKs+JIN8La6gVkSlX3/0HNBAGv5dv5nd+ju9A0F7+W2RPW1dk1O3 Zg/et/xmBxSu1Z14XcwIz7hARolx1sxHsuvcvy2r88oe1sn9hiO2GLECouGv6rdi+SJ0 gIwhC6Vr/gQmGiF0kHz5s/5fODOk5h+ZhYDKsSYE6VYczqGqTTTXrU1SP2QYLrRr+GmB AiNSK/+OG8Cz3yORo8M26/R75P2JJOXETmSXx8It0t/NY8S7HFEcENmIjUJakFBdNNYV Il/H0XojNyLrg/+RbwESN53f5EOanB0yW28y3b4kKBGx9xjDJjsHaCIecZaY2WcdF7lm JX9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt27si2191981edb.94.2020.05.27.10.51.51; Wed, 27 May 2020 10:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388231AbgE0Ndk (ORCPT + 99 others); Wed, 27 May 2020 09:33:40 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:46334 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387514AbgE0Ndi (ORCPT ); Wed, 27 May 2020 09:33:38 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 462FE1C0320; Wed, 27 May 2020 15:33:36 +0200 (CEST) Date: Wed, 27 May 2020 15:33:35 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Dan Williams , Dexuan Cui , Pedro dAquino Filocre F S Barbuda , Vishal Verma , Sasha Levin Subject: Re: [PATCH 4.19 53/81] libnvdimm/btt: Fix LBA masking during free list population Message-ID: <20200527133335.GB11424@amd> References: <20200526183923.108515292@linuxfoundation.org> <20200526183932.993059888@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="aVD9QWMuhilNxW9f" Content-Disposition: inline In-Reply-To: <20200526183932.993059888@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --aVD9QWMuhilNxW9f Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > If an implementation does happen to have it set, we would happily read > it in as the next block to write to for writes. Since a high bit is set, > it pushes the block number out of the range of an 'arena', and we fail > such a write with an EIO. >=20 > Follow the robustness principle, and tolerate such implementations by > stripping out the zero flag when populating the free list during > initialization. Additionally, use the same stripped out entries for > detection of incomplete writes and map restoration that happens at this > stage. > Add a sysfs file 'log_zero_flags' that indicates the ability to accept > such a layout to userspace applications. This enables 'ndctl > check-namespace' to recognize whether the kernel is able to handle zero > flags, or whether it should attempt a fix-up under the --repair > option. Ok, so new /sys file is added; but that should have entry in Documentation/ and that one is not there AFAICT. (Not in -linus, so I assume not in -stable, either). Best regards, Pavel > Cc: Dan Williams > Reported-by: Dexuan Cui > Reported-by: Pedro d'Aquino Filocre F S Barbuda > Tested-by: Dexuan Cui > Signed-off-by: Vishal Verma > Signed-off-by: Dan Williams > Signed-off-by: Sasha Levin > --- > drivers/nvdimm/btt.c | 25 +++++++++++++++++++------ > drivers/nvdimm/btt.h | 2 ++ > drivers/nvdimm/btt_devs.c | 8 ++++++++ > 3 files changed, 29 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c > index d78cfe82ad5c..1064a703ccec 100644 > --- a/drivers/nvdimm/btt.c > +++ b/drivers/nvdimm/btt.c > @@ -542,8 +542,8 @@ static int arena_clear_freelist_error(struct arena_in= fo *arena, u32 lane) > static int btt_freelist_init(struct arena_info *arena) > { > int new, ret; > - u32 i, map_entry; > struct log_entry log_new; > + u32 i, map_entry, log_oldmap, log_newmap; > =20 > arena->freelist =3D kcalloc(arena->nfree, sizeof(struct free_entry), > GFP_KERNEL); > @@ -555,16 +555,22 @@ static int btt_freelist_init(struct arena_info *are= na) > if (new < 0) > return new; > =20 > + /* old and new map entries with any flags stripped out */ > + log_oldmap =3D ent_lba(le32_to_cpu(log_new.old_map)); > + log_newmap =3D ent_lba(le32_to_cpu(log_new.new_map)); > + > /* sub points to the next one to be overwritten */ > arena->freelist[i].sub =3D 1 - new; > arena->freelist[i].seq =3D nd_inc_seq(le32_to_cpu(log_new.seq)); > - arena->freelist[i].block =3D le32_to_cpu(log_new.old_map); > + arena->freelist[i].block =3D log_oldmap; > =20 > /* > * FIXME: if error clearing fails during init, we want to make > * the BTT read-only > */ > - if (ent_e_flag(log_new.old_map)) { > + if (ent_e_flag(log_new.old_map) && > + !ent_normal(log_new.old_map)) { > + arena->freelist[i].has_err =3D 1; > ret =3D arena_clear_freelist_error(arena, i); > if (ret) > dev_err_ratelimited(to_dev(arena), > @@ -572,7 +578,7 @@ static int btt_freelist_init(struct arena_info *arena) > } > =20 > /* This implies a newly created or untouched flog entry */ > - if (log_new.old_map =3D=3D log_new.new_map) > + if (log_oldmap =3D=3D log_newmap) > continue; > =20 > /* Check if map recovery is needed */ > @@ -580,8 +586,15 @@ static int btt_freelist_init(struct arena_info *aren= a) > NULL, NULL, 0); > if (ret) > return ret; > - if ((le32_to_cpu(log_new.new_map) !=3D map_entry) && > - (le32_to_cpu(log_new.old_map) =3D=3D map_entry)) { > + > + /* > + * The map_entry from btt_read_map is stripped of any flag bits, > + * so use the stripped out versions from the log as well for > + * testing whether recovery is needed. For restoration, use the > + * 'raw' version of the log entries as that captured what we > + * were going to write originally. > + */ > + if ((log_newmap !=3D map_entry) && (log_oldmap =3D=3D map_entry)) { > /* > * Last transaction wrote the flog, but wasn't able > * to complete the map write. So fix up the map. > diff --git a/drivers/nvdimm/btt.h b/drivers/nvdimm/btt.h > index db3cb6d4d0d4..ddff49c707b0 100644 > --- a/drivers/nvdimm/btt.h > +++ b/drivers/nvdimm/btt.h > @@ -44,6 +44,8 @@ > #define ent_e_flag(ent) (!!(ent & MAP_ERR_MASK)) > #define ent_z_flag(ent) (!!(ent & MAP_TRIM_MASK)) > #define set_e_flag(ent) (ent |=3D MAP_ERR_MASK) > +/* 'normal' is both e and z flags set */ > +#define ent_normal(ent) (ent_e_flag(ent) && ent_z_flag(ent)) > =20 > enum btt_init_state { > INIT_UNCHECKED =3D 0, > diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c > index e341498876ca..9486acc08402 100644 > --- a/drivers/nvdimm/btt_devs.c > +++ b/drivers/nvdimm/btt_devs.c > @@ -159,11 +159,19 @@ static ssize_t size_show(struct device *dev, > } > static DEVICE_ATTR_RO(size); > =20 > +static ssize_t log_zero_flags_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + return sprintf(buf, "Y\n"); > +} > +static DEVICE_ATTR_RO(log_zero_flags); > + > static struct attribute *nd_btt_attributes[] =3D { > &dev_attr_sector_size.attr, > &dev_attr_namespace.attr, > &dev_attr_uuid.attr, > &dev_attr_size.attr, > + &dev_attr_log_zero_flags.attr, > NULL, > }; > =20 --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --aVD9QWMuhilNxW9f Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl7ObC8ACgkQMOfwapXb+vKI2QCgsQVbH25sPaT9obowvjG18XW2 4bYAn0eM2z+qaiMlvYRCpnmbjp+K1r8Z =0FpG -----END PGP SIGNATURE----- --aVD9QWMuhilNxW9f--