Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1482057pxf; Fri, 26 Mar 2021 08:29:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHtImeh0q4nmEHSBNPp+JiWinlx+V8AEtieUFlq0/I4xYi0twMGM2Sh42Hi5A7xK5eBpRb X-Received: by 2002:a17:906:379b:: with SMTP id n27mr16561080ejc.182.1616772545952; Fri, 26 Mar 2021 08:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616772545; cv=none; d=google.com; s=arc-20160816; b=edV+HR6H1qLQqO6SWw+liRzEfQAuiY9UP/n+QSTRkzZR8xD3zCZYkLNyhjMIVppaoS am32nvs1DFPQVxGh/feB9buW+gv2nwLO8Ux6tFyKyamDpVnz/9Gbimfc4cgwx/JD08Sk G16A057oJS83bDKQSBBs+DKhUim8jN8KyVJbgMidiSNwyojr0xMlwTtCX4G9PVQpVP7V JmmotA+SuGQVYtygTHThx1dcYP89z5WJyZyKhMNn6WxyfPCFcYR3j0gnHXuYv0+kIZ0b ehUVGFJ8sANQNP7jhYK+qNvKrr1Pu1CMGzrq+VCBUibRBuz/M5ewhrkiqG6CKISMq1dI 2Ekg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=pjJC8+RuCiRNDhNHwIzgJu6U7+9wO1VcQ0wueos6N2Y=; b=HXz9Uizla1qMokwcJL1MdBY0DPn89UK/E367ipFHpJkVdHfXAVmaD90cPSJuHloPWN 72DJqj7emIPtkb+BgMR4iY/Oa9LD0iUhdG7Vrlxc+Dxt4jKI5Lml2KAhb1hRqFULOowG jwvMr+D68xgCftPlUNZzF7BYw+JHrFgUweleU5zby4pJ+iGnJedcnWPb+W9sE4ETRalf 9/cmVv/q3RSzcM9+o30zYrolGLMfLOAqZA/zTvfEQ3HAsxTlZ3OIJ0NFv2yK2EBhnCjT vfymI8T8nC/YeSBJieX5qafLdFdFtoJHQiRLlHqVlD/uVlAI1Pkosgo0I1u+1yHWOk/u 3bsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gtq5M7e6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si7889464edv.49.2021.03.26.08.28.42; Fri, 26 Mar 2021 08:29:05 -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; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gtq5M7e6; 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; 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 S230225AbhCZP1p (ORCPT + 99 others); Fri, 26 Mar 2021 11:27:45 -0400 Received: from linux.microsoft.com ([13.77.154.182]:37596 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230139AbhCZP1S (ORCPT ); Fri, 26 Mar 2021 11:27:18 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 1EE8820B5680; Fri, 26 Mar 2021 08:27:17 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1EE8820B5680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1616772437; bh=pjJC8+RuCiRNDhNHwIzgJu6U7+9wO1VcQ0wueos6N2Y=; h=From:To:Cc:Subject:Date:From; b=Gtq5M7e60kUb3b7t/PCrEEYN56deqD/0jJlgJSgugIK1US8nFGoDlMgdQDvu+GjMn eNoT7bBhYT6fpBZ917mdNtlALapS++F2ZGPgHezhGuSDuNrVoiA1QYCmjzT2YiFBYY mZChQi2j4Uu0DYlQIjcCMEX5msTo4GebuA6UHmS8= From: Tyler Hicks To: Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny Cc: "Aneesh Kumar K.V" , Jeff Moyer , Pavel Tatashin , linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Subject: [PATCH] libnvdimm/region: Allow setting align attribute on regions without mappings Date: Fri, 26 Mar 2021 10:26:45 -0500 Message-Id: <20210326152645.85225-1-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fixes: 2522afb86a8c ("libnvdimm/region: Introduce an 'align' attribute") Signed-off-by: Tyler Hicks --- drivers/nvdimm/region_devs.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index ef23119db574..09cff8aa6b40 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -545,29 +545,32 @@ static ssize_t align_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct nd_region *nd_region = to_nd_region(dev); - unsigned long val, dpa; - u32 remainder; + unsigned long val; 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 - * to determine which DIMM(s), dimm-physical-addresses, would - * contribute to the tail capacity in system-physical-address - * space for the namespace. - */ - dpa = div_u64_rem(val, nd_region->ndr_mappings, &remainder); - if (!is_power_of_2(dpa) || dpa < PAGE_SIZE - || val > region_size(nd_region) || remainder) + if (val > region_size(nd_region)) return -EINVAL; + if (nd_region->ndr_mappings) { + unsigned long dpa; + u32 remainder; + + /* + * Ensure space-align is evenly divisible by the region + * interleave-width because the kernel typically has no facility + * to determine which DIMM(s), dimm-physical-addresses, would + * contribute to the tail capacity in system-physical-address + * space for the namespace. + */ + dpa = div_u64_rem(val, nd_region->ndr_mappings, &remainder); + if (!is_power_of_2(dpa) || dpa < PAGE_SIZE || remainder) + return -EINVAL; + } + /* * Given that space allocation consults this value multiple * times ensure it does not change for the duration of the -- 2.25.1