From patchwork Wed Jan 30 10:59:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B78091E for ; Wed, 30 Jan 2019 10:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 079B52E3BB for ; Wed, 30 Jan 2019 10:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFCB82E3C3; Wed, 30 Jan 2019 10:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DFC42E3E2 for ; Wed, 30 Jan 2019 10:59:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 67EF5211BFCD4; Wed, 30 Jan 2019 02:59:45 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::641; helo=mail-pl1-x641.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8E795211BFCC4 for ; Wed, 30 Jan 2019 02:59:44 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id z23so10905109plo.0 for ; Wed, 30 Jan 2019 02:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uUaBuQNjN+mwEK3nGm85GwqwVxv+e1kYXkYn5D57eJ4=; b=MLhPckB8y8Ol1HHYEWxJUXzzycK3HO0u7hyAbDMmgQ2zIfRcko4wro5xnpTor7wEwl GObNrnvOuTBaaUXfhmCMMOESCriqf3JzBN44y6y02j+W8v8V55TRmQulLr1CZBPyr1SZ UYgLw4JFtrdMji6HgyC0r6TTUqlPeTGXdx1kS85Ky4y/3ppFgaxEL1xP+/CZKHjmIGtY R2umXqSNIfZfRc23CEzZAl8Qk0Uvbap3N0wN6PyAWWtrknOW7MdyURQztUilvYEoGtkn lWYEGovVO1nt1CXlr5QkjTDg1RQs0Y+H5k1OwbUWkRGpVaAj234jKzf2wtNlJ0OpamIR RylQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uUaBuQNjN+mwEK3nGm85GwqwVxv+e1kYXkYn5D57eJ4=; b=PXtAeJRopIvrWieHfhbsUgrHq/Ou/C2CoOCcGIxZqjp/0vmERq25+J3eqUJ/Xvmo94 Csia/skvQrbV9uVOuO067Ier2n7KkD56ABIAtfIB3reiJIh2YGVya97oPGuY8ztnL+mx wXEJ35GH4mPY8eZg5LTe0Q4j4vdw3YqHpau35DtLAnmWuFjs3V1BtDYx/Pn4Rx0AUTOe JAJgW872mCGiG7CJ7xPRmeJfBlBlOea6JKH8dt7BG1xJM8rGaGYqESv9jcFyfxJgAba3 h2miKzYD/+QOAPucDDELT+c0dfopZI3jxEhK20AGdEWebenxWGGqEwyXExVx+rp3lOI/ gsVQ== X-Gm-Message-State: AHQUAuZFODOWs3gI4zKGCqDJa2LMcue7VPDhPojTlQpg7OurKvhwRQPz rpKNZl2MtIPQrikYEfH50FCWz6Tu X-Google-Smtp-Source: AHgI3IbnAxGc+yM8mw7RWCLbxvGz7lLgKrVd1p/Es2LRMfc2h0XHvi+axnx1hSU1K6qM8dhtRnTo0g== X-Received: by 2002:a17:902:9687:: with SMTP id n7mr8189612plp.94.1548845984015; Wed, 30 Jan 2019 02:59:44 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:43 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 3/7] ndctl/namespace: Use seed alignment as the default Date: Wed, 30 Jan 2019 21:59:23 +1100 Message-Id: <20190130105927.31901-3-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When creating a pfn or dax namespace ndctl uses a default alignment of 2MB when the user does not explicitly supply one. This works on most systems (x86, ARM, PPC64 with radix MMU), but it fails when the kernel does not support a 2MB page size (PPC64 with hash MMU). This patch makes ndctl use the alignment of the relevant seed namespace as the default instead. The kernel will always pick a valid default alignment so this should be a bit more portable. Signed-off-by: Oliver O'Halloran --- v3: Only use the pfn seed for the default alignment if there is a pfn seed. --- ndctl/namespace.c | 96 +++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 12253a96e095..5d672810a712 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -39,7 +39,6 @@ static bool logfix; static struct parameters { bool do_scan; bool mode_default; - bool align_default; bool autolabel; const char *bus; const char *map; @@ -226,9 +225,6 @@ static int set_defaults(enum device_action mode) error("failed to parse namespace alignment '%s'\n", param.align); rc = -EINVAL; - } else if (!param.align) { - param.align = "2M"; - param.align_default = true; } if (param.uuid) { @@ -468,7 +464,7 @@ static int validate_namespace_options(struct ndctl_region *region, struct ndctl_namespace *ndns, struct parsed_parameters *p) { const char *region_name = ndctl_region_get_devname(region); - unsigned long long size_align = SZ_4K, units = 1, resource; + unsigned long long size_align, units = 1, resource; struct ndctl_pfn *pfn = NULL; struct ndctl_dax *dax = NULL; unsigned int ways; @@ -545,53 +541,15 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.align) { - p->align = parse_size64(param.align); - - if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M - && (!pfn || !ndctl_pfn_has_align(pfn))) { - /* - * Initial pfn device support in the kernel - * supported a 2M default alignment when - * ndctl_pfn_has_align() returns false. - */ - debug("%s not support 'align' for fsdax mode\n", - region_name); - return -EAGAIN; - } else if (p->mode == NDCTL_NS_MODE_DAX - && (!dax || !ndctl_dax_has_align(dax))) { - /* - * Unlike the pfn case, we require the kernel to - * have 'align' support for device-dax. - */ - debug("%s not support 'align' for devdax mode\n", - region_name); - return -EAGAIN; - } else if (!param.align_default - && (p->mode == NDCTL_NS_MODE_SAFE - || p->mode == NDCTL_NS_MODE_RAW)) { - /* - * Specifying an alignment has no effect for - * raw, or btt mode namespaces. - */ + if (p->mode != NDCTL_NS_MODE_MEMORY && + p->mode != NDCTL_NS_MODE_DAX) { error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); return -ENXIO; } - /* - * Fallback to a 4K default alignment if the region is - * not 2MB (typical default) aligned. This mainly helps - * the nfit_test use case where it is backed by vmalloc - * memory. - */ - resource = ndctl_region_get_resource(region); - if (param.align_default && resource < ULLONG_MAX - && (resource & (SZ_2M - 1))) { - debug("%s: falling back to a 4K alignment\n", - region_name); - p->align = SZ_4K; - } + p->align = parse_size64(param.align); switch (p->align) { case SZ_4K: @@ -602,16 +560,48 @@ static int validate_namespace_options(struct ndctl_region *region, error("unsupported align: %s\n", param.align); return -ENXIO; } + } else { + /* + * Use the seed namespace alignment as the default if we need + * one. If we don't then use PAGE_SIZE so the size_align + * checking works. + */ + if (p->mode == NDCTL_NS_MODE_MEMORY) { + /* + * The initial pfn device support in the kernel didn't + * have the 'align' sysfs attribute and assumed a 2MB + * alignment. Fall back to that if we don't have the + * attribute. + */ + if (pfn && ndctl_pfn_has_align(pfn)) + p->align = ndctl_pfn_get_align(pfn); + else + p->align = SZ_2M; + } else if (p->mode == NDCTL_NS_MODE_DAX) { + /* + * device dax mode was added after the align attribute + * so checking for it is unnecessary. + */ + p->align = ndctl_dax_get_align(dax); + } else { + p->align = sysconf(_SC_PAGE_SIZE); + } /* - * 'raw' and 'sector' mode namespaces don't support an - * alignment attribute. + * Fallback to a page alignment if the region is not aligned + * to the default. This is mainly useful for the nfit_test + * use case where it is backed by vmalloc memory. */ - if (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX) - size_align = p->align; + resource = ndctl_region_get_resource(region); + if (resource < ULLONG_MAX && (resource & (p->align - 1))) { + debug("%s: falling back to a page alignment\n", + region_name); + p->align = sysconf(_SC_PAGE_SIZE); + } } + size_align = p->align; + /* (re-)validate that the size satisfies the alignment */ ways = ndctl_region_get_interleave_ways(region); if (p->size % (size_align * ways)) { @@ -637,8 +627,8 @@ static int validate_namespace_options(struct ndctl_region *region, p->size *= size_align; p->size /= units; error("'--size=' must align to interleave-width: %d and alignment: %ld\n" - " did you intend --size=%lld%s?\n", ways, param.align - ? p->align : SZ_4K, p->size, suffix); + "did you intend --size=%lld%s?\n", + ways, p->align, p->size, suffix); return -EINVAL; }