Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6663401ybv; Wed, 12 Feb 2020 17:05:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwZ5/9d19X7YfKdERvqb8EefDEt7FoFGKysx0vHUW7rNBSMr/y6zkh84y2pGkt4t+cYKMey X-Received: by 2002:aca:f587:: with SMTP id t129mr1221802oih.143.1581555910414; Wed, 12 Feb 2020 17:05:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581555910; cv=none; d=google.com; s=arc-20160816; b=hoF7RAIqRWtpiT4JpXovxAWcXg0FuSA4yz8XJrQcNnPEIzEoseaQ0MTODzR010P5y7 44E+0wpB7PFEei4NeFjpZafq3hs619KpDy8z76XOrr5VGRMJKRQWdDb1WMtoxFW51IPX iCvSfawl9t887Q646gxK1K7stY7LjiAB9GuoJHLHYw/ly+TNcvxHpt0Pa/iYQyL47veP 7nUNe1iPSKF4G2bwljxCOhY7Szgl3asDXKtPN18JJRhurE6kHU9UKcd5CZyGMQkR80He UZHXwUHM/aZ4lWHKKsypajwt2nc1ItWML6jQYKQNH4UwY8mDHr7kZZqfbDur5PoYxaTo iJgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=IUR9/es2jgJlDZyldWp7WeqFh/bFR0e4LzE2EHA5xLM=; b=xZiVioCc+y5ey2cLCjKDc5nRNY2m+jyTf8Ue4Iw0yz+G9B996s6ocOZvDxFBS0nKU3 mSFBp/2csX+VAaZUwDvyYYDD4KXlrCa/RVdFY4YhsOIBocB7TqdZXmR/3fBO5rUMz94z 0tKQEVXLosCyfV3IGAHGCRAcTpYCKRoZyv2yMNOTc35vyzQW89+IFC13xAtMxK31DCF3 9LsRhgkKJliMMpkHh92Sk0zRC+ldOqMAvFLnSl0PSgQaeFm7mcy81UOhdMsz1g2YYGzw 4myrcRjUaQUmVWVPlCNAMHtyQqisN0buBHLWqooatfP5Uk3qpTsEUhiSD9ufeAnuW1l4 xOCw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f190si390991oig.229.2020.02.12.17.04.51; Wed, 12 Feb 2020 17:05:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729413AbgBMBEe (ORCPT + 99 others); Wed, 12 Feb 2020 20:04:34 -0500 Received: from mga18.intel.com ([134.134.136.126]:32614 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729185AbgBMBEd (ORCPT ); Wed, 12 Feb 2020 20:04:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2020 17:04:33 -0800 X-IronPort-AV: E=Sophos;i="5.70,434,1574150400"; d="scan'208";a="233956351" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2020 17:04:33 -0800 Subject: [PATCH v2 2/4] libnvdimm/namespace: Enforce memremap_compat_align() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: "Aneesh Kumar K.V" , Jeff Moyer , "Aneesh Kumar K.V" , vishal.l.verma@intel.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 12 Feb 2020 16:48:29 -0800 Message-ID: <158155490897.3343782.14216276134794923581.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <158155489850.3343782.2687127373754434980.stgit@dwillia2-desk3.amr.corp.intel.com> References: <158155489850.3343782.2687127373754434980.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pmem driver on PowerPC crashes with the following signature when instantiating misaligned namespaces that map their capacity via memremap_pages(). BUG: Unable to handle kernel data access at 0xc001000406000000 Faulting instruction address: 0xc000000000090790 NIP [c000000000090790] arch_add_memory+0xc0/0x130 LR [c000000000090744] arch_add_memory+0x74/0x130 Call Trace: arch_add_memory+0x74/0x130 (unreliable) memremap_pages+0x74c/0xa30 devm_memremap_pages+0x3c/0xa0 pmem_attach_disk+0x188/0x770 nvdimm_bus_probe+0xd8/0x470 With the assumption that only memremap_pages() has alignment constraints, enforce memremap_compat_align() for pmem_should_map_pages(), nd_pfn, or nd_dax cases. Reported-by: Aneesh Kumar K.V Cc: Jeff Moyer Reviewed-by: Aneesh Kumar K.V Link: https://lore.kernel.org/r/158041477336.3889308.4581652885008605170.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams --- drivers/nvdimm/namespace_devs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 032dc61725ff..aff1f32fdb4f 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1739,6 +1739,16 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev) return ERR_PTR(-ENODEV); } + if (pmem_should_map_pages(dev) || nd_pfn || nd_dax) { + struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev); + resource_size_t start = nsio->res.start; + + if (!IS_ALIGNED(start | size, memremap_compat_align())) { + dev_dbg(&ndns->dev, "misaligned, unable to map\n"); + return ERR_PTR(-EOPNOTSUPP); + } + } + if (is_namespace_pmem(&ndns->dev)) { struct nd_namespace_pmem *nspm;