Received: by 10.223.185.116 with SMTP id b49csp4194458wrg; Mon, 26 Feb 2018 12:58:38 -0800 (PST) X-Google-Smtp-Source: AH8x224cINYcuQYMMt5KkcB73N5fD+a58TUbqjOe8rv42lNa2OT78NVJB4rvYYkS36TTd5KEPUQT X-Received: by 2002:a17:902:6b4c:: with SMTP id g12-v6mr11660397plt.363.1519678718184; Mon, 26 Feb 2018 12:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519678718; cv=none; d=google.com; s=arc-20160816; b=wvO6Oxpq8K/0HO3Tfn/X23FHYIqsw9lV62KRU50Y1FmE5TgrLLDv9cYqaOXNVdmr2u rC1ZHrlJCIj8GZalz1WPvHFE8Pv6KL/ank/ksb7DRvQuxpjKRmsxkuzR5alaB7Rok1ax d+LhKjK+WiFXbLJ5RV3BzNLkdsgpgh5MszCWzCsF6YyE+Ce0gG3s4xPpEyFPxBp91tHc lIt1Yo0ksw5Fd3sezY0gaZxpaBgsFDofVoqkxvb/TtzTHyrr/Vkdy8TfT+bpnwMMdni9 8v9GsHHUXsDHZDO166svpW0I0+Ah34OOBW5sZyHEFwM8B3T/svefvxcTynsghAvgAWgb ubFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HLzt02HCnJgwlRtJ7fgHfKRrC/R+IMm8urnWdMbCBiI=; b=A6rE2LADx28jpopyzxdjxNIhPzFhjvs9ey9nli7q/yai8J2mieUccv27y8UkOwIHKp Cc0jHl4xY7o20jPA5SokpH6VjF/li0s6sm3yb7ZftOeQFl2bTSi79A5zsBLKPQ4wi/kv GKK8AE/+Z7zqBhaPhEYqZ8O4RTUJf5qofaPMfLtUR2CTZ4JXauUWy9GZf/ptodRhnxg3 JZ3NOOzfBz1RI1DB3gtsThffM1IN9JZAzf40PGdV8gQwO+sUr5ymQOeTcexeMSQRBTJs //DCYo2J3Xr8qy71/ZhhbAea/jSI/4yfq1QpDW3oQhtWNMbGIEzMKfDEQJ8my3YqwILw PklA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9-v6si6115563pll.680.2018.02.26.12.58.21; Mon, 26 Feb 2018 12:58:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752456AbeBZU5h (ORCPT + 99 others); Mon, 26 Feb 2018 15:57:37 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34526 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752210AbeBZUWx (ORCPT ); Mon, 26 Feb 2018 15:22:53 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A2AA5ED2; Mon, 26 Feb 2018 20:22:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams Subject: [PATCH 4.9 36/39] libnvdimm, dax: fix 1GB-aligned namespaces vs physical misalignment Date: Mon, 26 Feb 2018 21:20:57 +0100 Message-Id: <20180226201645.252595532@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180226201643.660109883@linuxfoundation.org> References: <20180226201643.660109883@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 41fce90f26333c4fa82e8e43b9ace86c4e8a0120 upstream. The following namespace configuration attempt: # ndctl create-namespace -e namespace0.0 -m devdax -a 1G -f libndctl: ndctl_dax_enable: dax0.1: failed to enable Error: namespace0.0: failed to enable failed to reconfigure namespace: No such device or address ...fails when the backing memory range is not physically aligned to 1G: # cat /proc/iomem | grep Persistent 210000000-30fffffff : Persistent Memory (legacy) In the above example the 4G persistent memory range starts and ends on a 256MB boundary. We handle this case correctly when needing to handle cases that violate section alignment (128MB) collisions against "System RAM", and we simply need to extend that padding/truncation for the 1GB alignment use case. Cc: Fixes: 315c562536c4 ("libnvdimm, pfn: add 'align' attribute...") Reported-and-tested-by: Jane Chu Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/pfn_devs.c | 15 ++++++++++++--- include/linux/kernel.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -563,6 +563,12 @@ static struct vmem_altmap *__nvdimm_setu return altmap; } +static u64 phys_pmem_align_down(struct nd_pfn *nd_pfn, u64 phys) +{ + return min_t(u64, PHYS_SECTION_ALIGN_DOWN(phys), + ALIGN_DOWN(phys, nd_pfn->align)); +} + static int nd_pfn_init(struct nd_pfn *nd_pfn) { u32 dax_label_reserve = is_nd_dax(&nd_pfn->dev) ? SZ_128K : 0; @@ -618,13 +624,16 @@ static int nd_pfn_init(struct nd_pfn *nd start = nsio->res.start; size = PHYS_SECTION_ALIGN_UP(start + size) - start; if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM, - IORES_DESC_NONE) == REGION_MIXED) { + IORES_DESC_NONE) == REGION_MIXED + || !IS_ALIGNED(start + resource_size(&nsio->res), + nd_pfn->align)) { size = resource_size(&nsio->res); - end_trunc = start + size - PHYS_SECTION_ALIGN_DOWN(start + size); + end_trunc = start + size - phys_pmem_align_down(nd_pfn, + start + size); } if (start_pad + end_trunc) - dev_info(&nd_pfn->dev, "%s section collision, truncate %d bytes\n", + dev_info(&nd_pfn->dev, "%s alignment collision, truncate %d bytes\n", dev_name(&ndns->dev), start_pad + end_trunc); /* --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -46,6 +46,7 @@ #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)