From patchwork Mon Oct 28 09:48:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 11215049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B31BF1864 for ; Mon, 28 Oct 2019 09:48:45 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E1A521850 for ; Mon, 28 Oct 2019 09:48:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E1A521850 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from new-ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EE3CF100EA624; Mon, 28 Oct 2019 02:49:36 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=aneesh.kumar@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BDC2E100EA61F for ; Mon, 28 Oct 2019 02:49:34 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9S9lWOK146660; Mon, 28 Oct 2019 05:48:37 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vwt4x6dh3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 05:48:37 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x9S9jBAT013274; Mon, 28 Oct 2019 09:48:36 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma01dal.us.ibm.com with ESMTP id 2vvds8n21g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 09:48:36 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9S9mYvo51249518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Oct 2019 09:48:34 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6EF1C605D; Mon, 28 Oct 2019 09:48:34 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E450AC6055; Mon, 28 Oct 2019 09:48:32 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.199.43.125]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 28 Oct 2019 09:48:32 +0000 (GMT) From: "Aneesh Kumar K.V" To: dan.j.williams@intel.com, mpe@ellerman.id.au Subject: [RFC PATCH 2/4] libnvdimm/namespace: Disable the region if the namespace size is not aligned correctly Date: Mon, 28 Oct 2019 15:18:23 +0530 Message-Id: <20191028094825.21448-2-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> References: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-28_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=978 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910280098 Message-ID-Hash: EJEUX2LXFHMTY43B3HJTGO66UL3MYBDO X-Message-ID-Hash: EJEUX2LXFHMTY43B3HJTGO66UL3MYBDO X-MailFrom: aneesh.kumar@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: linux-nvdimm@lists.01.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: During namespace initialization, if kernel finds the namespace size not aligned as per arch-specific restriction, disable the region completely. Even though kernel validates the namespace size while creating the namespace nvdimm core still needs to make sure namespaces with wrong size are not initialized. This can happen when users move SCM across different architectures and with architectures like ppc64 when we use different MMU translation modes. ppc64 allow booting systems with different translation mode based on kernel parameter and the two translation mode (hash and radix) have different direct-map page size restrictions. Marking the region disabled enables the user to either re-init the namespace using the dimm interface or boot back to the right kernel supporting the alignment. Signed-off-by: Aneesh Kumar K.V --- drivers/nvdimm/namespace_devs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index cca0a3ba1d2c..fcde9f2bf2ea 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1912,6 +1912,7 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region, struct nd_label_ent *label_ent; struct nd_namespace_pmem *nspm; struct nd_mapping *nd_mapping; + unsigned long map_align_size; resource_size_t size = 0; struct resource *res; struct device *dev; @@ -2010,6 +2011,20 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region, } + map_align_size = arch_validate_namespace_size(nd_region->ndr_mappings, size); + if (map_align_size) { + dev_err(&nd_region->dev, "%llu is not %ldK aligned\n", size, + map_align_size/ SZ_1K); + /* + * Disable this region completely. A wrongly sized namespace + * size implies the start address of other namespace would also + * be wrong and we would find confusing crashes w.r.t + * direct-map address. + */ + rc = -EINVAL; + goto err; + } + if (!nspm->alt_name || !nspm->uuid) { rc = -ENOMEM; goto err; From patchwork Mon Oct 28 09:48:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 11215053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7585E913 for ; Mon, 28 Oct 2019 09:48:48 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CE9E208C0 for ; Mon, 28 Oct 2019 09:48:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CE9E208C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from new-ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0B8FD100EA627; Mon, 28 Oct 2019 02:49:40 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=aneesh.kumar@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AD649100EA625 for ; Mon, 28 Oct 2019 02:49:37 -0700 (PDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9S9lSpp046224; Mon, 28 Oct 2019 05:48:39 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com with ESMTP id 2vwvrctcp9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 05:48:39 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x9S9jBI9006132; Mon, 28 Oct 2019 09:48:38 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma04dal.us.ibm.com with ESMTP id 2vvds7d18u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 09:48:38 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9S9mbkF52232594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Oct 2019 09:48:37 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35126C6055; Mon, 28 Oct 2019 09:48:37 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52F9FC6057; Mon, 28 Oct 2019 09:48:35 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.199.43.125]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 28 Oct 2019 09:48:35 +0000 (GMT) From: "Aneesh Kumar K.V" To: dan.j.williams@intel.com, mpe@ellerman.id.au Subject: [RFC PATCH 3/4] libnvdimm/namespace: Use direct-mapping page size to validate namespace size Date: Mon, 28 Oct 2019 15:18:24 +0530 Message-Id: <20191028094825.21448-3-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> References: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-28_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=893 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910280098 Message-ID-Hash: MLN2W66JP4VZEBMNBLBHUHVG22TSLTBE X-Message-ID-Hash: MLN2W66JP4VZEBMNBLBHUHVG22TSLTBE X-MailFrom: aneesh.kumar@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: linux-nvdimm@lists.01.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Architectures like ppc64 use different page size than PAGE_SIZE to map direct-map address range. The kernel needs to make sure the namespace size is aligned correctly for the direct-map page size. Signed-off-by: Aneesh Kumar K.V --- drivers/nvdimm/namespace_devs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index fcde9f2bf2ea..83c70631a86f 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -975,7 +975,8 @@ static ssize_t __size_store(struct device *dev, unsigned long long val) struct nd_mapping *nd_mapping; struct nvdimm_drvdata *ndd; struct nd_label_id label_id; - u32 flags = 0, remainder; + unsigned long map_size; + u32 flags = 0; int rc, i, id = -1; u8 *uuid = NULL; @@ -1006,10 +1007,9 @@ static ssize_t __size_store(struct device *dev, unsigned long long val) return -ENXIO; } - div_u64_rem(val, PAGE_SIZE * nd_region->ndr_mappings, &remainder); - if (remainder) { - dev_dbg(dev, "%llu is not %ldK aligned\n", val, - (PAGE_SIZE * nd_region->ndr_mappings) / SZ_1K); + map_size = arch_validate_namespace_size(nd_region->ndr_mappings, val); + if (map_size) { + dev_err(dev, "%llu is not %ldK aligned\n", val, map_size / SZ_1K); return -EINVAL; } From patchwork Mon Oct 28 09:48:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 11215055 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7550B913 for ; Mon, 28 Oct 2019 09:48:49 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C878208C0 for ; Mon, 28 Oct 2019 09:48:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C878208C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from new-ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 20A4F100EA629; Mon, 28 Oct 2019 02:49:41 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=aneesh.kumar@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 46B2F100EA621 for ; Mon, 28 Oct 2019 02:49:38 -0700 (PDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9S9lZjP055210; Mon, 28 Oct 2019 05:48:41 -0400 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vwv3uujtp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 05:48:41 -0400 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x9S9jBpe026795; Mon, 28 Oct 2019 09:48:40 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma02wdc.us.ibm.com with ESMTP id 2vvds80t8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 09:48:40 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9S9mdrH45220108 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Oct 2019 09:48:39 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A02FBC605D; Mon, 28 Oct 2019 09:48:39 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B487FC6059; Mon, 28 Oct 2019 09:48:37 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.199.43.125]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 28 Oct 2019 09:48:37 +0000 (GMT) From: "Aneesh Kumar K.V" To: dan.j.williams@intel.com, mpe@ellerman.id.au Subject: [RFC PATCH 4/4] libnvdimm/namespace: Add debug check while initializing namespace resource size. Date: Mon, 28 Oct 2019 15:18:25 +0530 Message-Id: <20191028094825.21448-4-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> References: <20191028094825.21448-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-28_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910280098 Message-ID-Hash: YPZH33YO4REVT73QPEWB6W5KZPQHVAZE X-Message-ID-Hash: YPZH33YO4REVT73QPEWB6W5KZPQHVAZE X-MailFrom: aneesh.kumar@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: linux-nvdimm@lists.01.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: This should enable us to catch if we are initializing the namespace with a wrong size. Signed-off-by: Aneesh Kumar K.V --- drivers/nvdimm/namespace_devs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 83c70631a86f..9f2dc20bcc73 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -956,6 +956,18 @@ static void nd_namespace_pmem_set_resource(struct nd_region *nd_region, out: res->start = nd_region->ndr_start + offset; res->end = res->start + size - 1; +#ifdef CONFIG_DEBUG_VM + if (size) { + unsigned long map_size; + + map_size = arch_validate_namespace_size(nd_region->ndr_mappings, size); + WARN_ON(map_size); + + map_size = arch_validate_namespace_size(1, res->start); + WARN_ON(map_size); + + } +#endif } static bool uuid_not_set(const u8 *uuid, struct device *dev, const char *where)