From: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
To: dan.j.williams@intel.com, vishal.l.verma@intel.com, jmoyer@redhat.com
Cc: linux-nvdimm@lists.01.org,
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Subject: [PATCH v4 4/6] libnvdimm/namespace: Validate namespace size when creating a new namespace.
Date: Mon, 20 Jan 2020 19:37:47 +0530 [thread overview]
Message-ID: <20200120140749.69549-5-aneesh.kumar@linux.ibm.com> (raw)
In-Reply-To: <20200120140749.69549-1-aneesh.kumar@linux.ibm.com>
Kernel should validate the namespace size against SUBSECTION_SIZE rather than
PAGE_SIZE. blk namespace continues to use old rule so that the new kernel don't
break the creation of blk namespaces.
Use the new helper arch_namespace_align_size() so that architecture specific
restrictions are also taken care of.
kernel log will contain the below details
[ 939.620064] nd namespace0.3: 1071644672 is not 16384K aligned
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
drivers/nvdimm/namespace_devs.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 0e2c90730ce3..e318566ae135 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -891,6 +891,17 @@ static int grow_dpa_allocation(struct nd_region *nd_region,
return 0;
}
+static unsigned long nvdimm_validate_namespace_size(struct nd_region *nd_region,
+ unsigned long size, unsigned long align_size)
+{
+ u32 remainder;
+
+ div_u64_rem(size, align_size * nd_region->ndr_mappings, &remainder);
+ if (remainder)
+ return align_size * nd_region->ndr_mappings;
+ return 0;
+}
+
static void nd_namespace_pmem_set_resource(struct nd_region *nd_region,
struct nd_namespace_pmem *nspm, resource_size_t size)
{
@@ -945,11 +956,13 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
{
resource_size_t allocated = 0, available = 0;
struct nd_region *nd_region = to_nd_region(dev->parent);
+ unsigned long align_size = arch_namespace_align_size();
struct nd_namespace_common *ndns = to_ndns(dev);
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;
@@ -967,6 +980,8 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
uuid = nsblk->uuid;
flags = NSLABEL_FLAG_LOCAL;
id = nsblk->id;
+ /* Let's not break blk region */
+ align_size = PAGE_SIZE;
}
/*
@@ -980,10 +995,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 = nvdimm_validate_namespace_size(nd_region, val, align_size);
+ if (map_size) {
+ dev_err(dev, "%llu is not %ldK aligned\n", val, map_size / SZ_1K);
return -EINVAL;
}
--
2.24.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-01-20 14:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-20 14:07 [PATCH v4 0/6] Validating namespace size and start address attributes Aneesh Kumar K.V
2020-01-20 14:07 ` [PATCH v4 1/6] libnvdimm/namespace: Make namespace size validation arch dependent Aneesh Kumar K.V
2020-01-24 5:57 ` Dan Williams
2020-01-24 7:34 ` Aneesh Kumar K.V
2020-01-24 16:45 ` Dan Williams
2020-01-24 17:07 ` Aneesh Kumar K.V
2020-01-24 17:07 ` Aneesh Kumar K.V
2020-01-24 18:25 ` Dan Williams
2020-01-24 18:25 ` Dan Williams
2020-01-26 11:41 ` Aneesh Kumar K.V
2020-01-26 11:41 ` Aneesh Kumar K.V
2020-01-24 17:08 ` Aneesh Kumar K.V
2020-01-20 14:07 ` [PATCH v4 2/6] libnvdimm/namespace: Validate namespace start addr and size Aneesh Kumar K.V
2020-01-25 1:55 ` Dan Williams
2020-01-20 14:07 ` [PATCH v4 3/6] libnvdimm/namespace: Add arch dependent callback for namespace create time validation Aneesh Kumar K.V
2020-01-25 1:59 ` Dan Williams
2020-01-20 14:07 ` Aneesh Kumar K.V [this message]
2020-01-25 2:22 ` [PATCH v4 4/6] libnvdimm/namespace: Validate namespace size when creating a new namespace Dan Williams
2020-01-20 14:07 ` [PATCH v4 5/6] libnvdimm/namespace: Align DPA based on arch restrictions Aneesh Kumar K.V
2020-01-20 14:07 ` [PATCH v4 6/6] libnvdimm/namespace: Expose arch specific supported size align value Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200120140749.69549-5-aneesh.kumar@linux.ibm.com \
--to=aneesh.kumar@linux.ibm.com \
--cc=dan.j.williams@intel.com \
--cc=jmoyer@redhat.com \
--cc=linux-nvdimm@lists.01.org \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.