Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754630AbdGJVc4 (ORCPT ); Mon, 10 Jul 2017 17:32:56 -0400 Received: from mga11.intel.com ([192.55.52.93]:46457 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752261AbdGJVcz (ORCPT ); Mon, 10 Jul 2017 17:32:55 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,342,1496127600"; d="scan'208";a="285219970" Date: Mon, 10 Jul 2017 15:31:18 -0600 From: Vishal Verma To: Toshi Kani Cc: dan.j.williams@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] libnvdimm: fix badblock range handling of ARS range Message-ID: <20170710213116.GB27581@omniknight.lm.intel.com> References: <20170707234426.25136-1-toshi.kani@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170707234426.25136-1-toshi.kani@hpe.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1670 Lines: 46 On 07/07, Toshi Kani wrote: > __add_badblock_range() does not account sector alignment when > it sets 'num_sectors'. Therefore, an ARS error record range > spanning across two sectors is set to a single sector length, > which leaves the 2nd sector unprotected. > > Change __add_badblock_range() to set 'num_sectors' properly. > > Fixes: 0caeef63e6d2f866d85bb507bf63e0ce8ec91cef > Signed-off-by: Toshi Kani > Cc: Dan Williams > Cc: Vishal Verma > Cc: > --- > drivers/nvdimm/core.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) Good find! I don't know why I assumed a poison entry spanning past the end of a sector wouldn't span past multiple sectors :) Reviewed-by: Vishal Verma > > diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c > index 2dee908..932c3994 100644 > --- a/drivers/nvdimm/core.c > +++ b/drivers/nvdimm/core.c > @@ -421,14 +421,15 @@ static void set_badblock(struct badblocks *bb, sector_t s, int num) > static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len) > { > const unsigned int sector_size = 512; > - sector_t start_sector; > + sector_t start_sector, end_sector; > u64 num_sectors; > u32 rem; > > start_sector = div_u64(ns_offset, sector_size); > - num_sectors = div_u64_rem(len, sector_size, &rem); > + end_sector = div_u64_rem(ns_offset + len, sector_size, &rem); > if (rem) > - num_sectors++; > + end_sector++; > + num_sectors = end_sector - start_sector; > > if (unlikely(num_sectors > (u64)INT_MAX)) { > u64 remaining = num_sectors;