Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp56924rwb; Mon, 26 Sep 2022 14:41:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YRic8o7PzJ/6EHxwoRCOHA/efosAHuXI6IdkwMlqh2+lR/tqh9mmw+zV/TQ+H3LSdJmza X-Received: by 2002:a17:90a:7e84:b0:205:ad7d:fa9 with SMTP id j4-20020a17090a7e8400b00205ad7d0fa9mr863198pjl.104.1664228509842; Mon, 26 Sep 2022 14:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664228509; cv=none; d=google.com; s=arc-20160816; b=CHE5FOV4/a5+OwZ3vj5uM0Tbnl73sMPCjQZyTrxfOvcU8aDlOHXxQ1kyZkxIUS61KK Ulb52zzJ+CaQoyx2udyFS+2UPWMqkVmENgVzG2eGkkDQsdZNKNCIDic67bcCL1Hwd+6P n1rP2PvvNBc6LV17i+u9M9WHN63I4cBuDu+4K8+4Jo2gNPAfUL/+M3tlGQZ9f8U0D1o7 e38JP8aZDVcWRuEr+ZTJwbip4e8KByAEg2rpQMdwT7xumsbaN3whqRz1d5lDFkAiPZUJ T0zK3RXkYasJ0OEGOhXUiAXVn7OoGEAcQKE3+4ylkrCerNOa4/XMWatCpNboAKQw1keo uqvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-filter; bh=IIvYw/73vFNw1aIUybdRwJzrxpzcNoYAqXNQeK4NMlQ=; b=NMoaZiVFthoZH1HFEWVwoV8Ok8x9OOl6lufDrh0U/fTEJRbpgeFR84IUTAqF6IS3dp 99BCumjqEIaOk1loX0umJCSAgbdFLO0orLINl2EFwP53z2q6ILbjs6gQVDV6jkXS1Kx0 Adewcw00CabdCoTwN8nnTFnTseRDnVHblEDWMAEJI3TR5RbB6VjJOnmzjCtPnf+iNmqb VROwydcVvV3bGv+looeEcTQJs+XIXG4TmPPwZ8vuBDrvQRXExq8d9lCepkgvpo4UmzMF 0VlYW4F0wZIakAwpEM8utQJFwXDPdWsN7/BRdOAoD9TNJBCb6Urgi5B3DYadqEUfjX9y 3xgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=H7Ti8t0g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a632606000000b00438b7cb3311si20420632pgm.501.2022.09.26.14.41.37; Mon, 26 Sep 2022 14:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=H7Ti8t0g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiIZU34 (ORCPT + 99 others); Mon, 26 Sep 2022 16:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbiIZU3w (ORCPT ); Mon, 26 Sep 2022 16:29:52 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A3521647C7 for ; Mon, 26 Sep 2022 13:29:51 -0700 (PDT) Received: from sequoia (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 86BDF200DDF4; Mon, 26 Sep 2022 13:29:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 86BDF200DDF4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1664224191; bh=IIvYw/73vFNw1aIUybdRwJzrxpzcNoYAqXNQeK4NMlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H7Ti8t0g5BHaqNVxdGBqMBr74f2UXcsgOk2DApbeNw2gpIlg8gsfGg9WOkiIKo5Pv ycaO/ztAM3fp7nTp7h0vnLRzDsz1zsxFbYsQWKBo3RjP4vfYd4OBIFyn0IyfMz3VYR tbkb/NFhkbtSteAWNIVuTdKLY2+IhEjZWuGOo8/k= Date: Mon, 26 Sep 2022 15:29:12 -0500 From: Tyler Hicks To: Jeff Moyer Cc: Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , "Aneesh Kumar K.V" , Pavel Tatashin , "Madhavan T. Venkataraman" , nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] libnvdimm/region: Allow setting align attribute on regions without mappings Message-ID: <20220926202912.GA58978@sequoia> References: <20220830054505.1159488-1-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-09-26 16:18:18, Jeff Moyer wrote: > Tyler Hicks writes: > > > The alignment constraint for namespace creation in a region was > > increased, from 2M to 16M, for non-PowerPC architectures in v5.7 with > > commit 2522afb86a8c ("libnvdimm/region: Introduce an 'align' > > attribute"). The thought behind the change was that region alignment > > should be uniform across all architectures and, since PowerPC had the > > largest alignment constraint of 16M, all architectures should conform to > > that alignment. > > > > The change regressed namespace creation in pre-defined regions that > > relied on 2M alignment but a workaround was provided in the form of a > > sysfs attribute, named 'align', that could be adjusted to a non-default > > alignment value. > > > > However, the sysfs attribute's store function returned an error (-ENXIO) > > when userspace attempted to change the alignment of a region that had no > > mappings. This affected 2M aligned regions of volatile memory that were > > defined in a device tree using "pmem-region" and created by the > > of_pmem_region_driver, since those regions do not contain mappings > > (ndr_mappings is 0). > > > > Allow userspace to set the align attribute on pre-existing regions that > > do not have mappings so that namespaces can still be within those > > regions, despite not being aligned to 16M. > > > > Link: https://lore.kernel.org/lkml/CA+CK2bDJ3hrWoE91L2wpAk+Yu0_=GtYw=4gLDDD7mxs321b_aA@mail.gmail.com > > Fixes: 2522afb86a8c ("libnvdimm/region: Introduce an 'align' attribute") > > Signed-off-by: Tyler Hicks > > --- > > > > While testing with a recent kernel release (6.0-rc3), I rediscovered > > this bug and eventually realized that I never followed through with > > fixing it upstream. After a year later, here's the v2 that Aneesh > > requested. Sorry about that! > > > > v2: > > - Included Aneesh's feedback to ensure the val is a power of 2 and > > greater than PAGE_SIZE even for regions without mappings > > - Reused the max_t() trick from default_align() to avoid special > > casing, with an if-else, when regions have mappings and when they > > don't > > + Didn't include Pavel's Reviewed-by since this is a slightly > > different approach than what he reviewed in v1 > > - Added a Link commit tag to Pavel's initial problem description > > v1: https://lore.kernel.org/lkml/20210326152645.85225-1-tyhicks@linux.microsoft.com/ > > > > drivers/nvdimm/region_devs.c | 8 +++----- > > 1 file changed, 3 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c > > index 473a71bbd9c9..550ea0bd6c53 100644 > > --- a/drivers/nvdimm/region_devs.c > > +++ b/drivers/nvdimm/region_devs.c > > @@ -509,16 +509,13 @@ static ssize_t align_store(struct device *dev, > > { > > struct nd_region *nd_region = to_nd_region(dev); > > unsigned long val, dpa; > > - u32 remainder; > > + u32 mappings, remainder; > > int rc; > > > > rc = kstrtoul(buf, 0, &val); > > if (rc) > > return rc; > > > > - if (!nd_region->ndr_mappings) > > - return -ENXIO; > > - > > /* > > * Ensure space-align is evenly divisible by the region > > * interleave-width because the kernel typically has no facility > > @@ -526,7 +523,8 @@ static ssize_t align_store(struct device *dev, > > * contribute to the tail capacity in system-physical-address > > * space for the namespace. > > */ > > - dpa = div_u64_rem(val, nd_region->ndr_mappings, &remainder); > > + mappings = max_t(u32, 1, nd_region->ndr_mappings); > > + dpa = div_u64_rem(val, mappings, &remainder); > > if (!is_power_of_2(dpa) || dpa < PAGE_SIZE > > || val > region_size(nd_region) || remainder) > > return -EINVAL; > > The math all looks okay, and this matches what's done in default_align. > Unfortunately, I don't know enough about the power architecture to > understand how you can have a region with no dimms (ndr_mappings == 0). Thanks for having a look! FWIW, I need this working on arm64. It previously did before the commit mentioned in the Fixes line. ndr_mappings is 0 when defining a pmem-region in the device tree. The region is also marked as 'volatile' but I don't recall if that contributes to ndr_mappings being 0. Tyler > > -Jeff >