Re: [RFC] /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a new patch to address boarder issues.

---

>From f90b54f9f5607128e375bd78d21e751c433b3cf6 Mon Sep 17 00:00:00 2001
From: CAI Qian <caiqian@xxxxxxxxxx>
Date: Wed, 5 Jan 2011 23:26:57 +0800
Subject: [PATCH] hugetlbfs: check invalid nr_hugepages and nr_overcommit_hugepages

First, nr_*hugepages* in procfs and sysfs do not check for invalid
input like "". Second, when using oversize pages, nr_*hugepages* are
expected to be allocated during boot time. Therefore, return -EINVAL
for those cases.

Signed-off-by: CAI Qian <caiqian@xxxxxxxxxx>
---
 fs/sysfs/file.c |    2 ++
 mm/hugetlb.c    |   18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index da3fefe..9f4ea67 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -207,6 +207,8 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
 		return -ENODEV;
 
 	rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
+	if (!rc)
+		return -EINVAL;
 
 	sysfs_put_active(attr_sd);
 
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index adc9a9f..f76a443 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1443,6 +1443,9 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
 		return 0;
 
 	h = kobj_to_hstate(kobj, &nid);
+	if (h->order >= MAX_ORDER)
+		return 0;
+
 	if (nid == NUMA_NO_NODE) {
 		/*
 		 * global hstate attribute
@@ -1517,6 +1520,9 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj,
 	unsigned long input;
 	struct hstate *h = kobj_to_hstate(kobj, NULL);
 
+	if (h->order >= MAX_ORDER)
+		return 0;
+
 	err = strict_strtoul(buf, 10, &input);
 	if (err)
 		return 0;
@@ -1942,12 +1948,16 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
 	struct hstate *h = &default_hstate;
 	unsigned long tmp;
 
+	if (h->order >= MAX_ORDER)
+		return -EINVAL;
+
 	if (!write)
 		tmp = h->max_huge_pages;
 
 	table->data = &tmp;
 	table->maxlen = sizeof(unsigned long);
-	proc_doulongvec_minmax(table, write, buffer, length, ppos);
+	if (proc_doulongvec_minmax(table, write, buffer, length, ppos))
+		return -EINVAL;
 
 	if (write) {
 		NODEMASK_ALLOC(nodemask_t, nodes_allowed,
@@ -2002,12 +2012,16 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
 	struct hstate *h = &default_hstate;
 	unsigned long tmp;
 
+	if (h->order >= MAX_ORDER)
+		return -EINVAL;
+
 	if (!write)
 		tmp = h->nr_overcommit_huge_pages;
 
 	table->data = &tmp;
 	table->maxlen = sizeof(unsigned long);
-	proc_doulongvec_minmax(table, write, buffer, length, ppos);
+	if (proc_doulongvec_minmax(table, write, buffer, length, ppos))
+		return -EINVAL;
 
 	if (write) {
 		spin_lock(&hugetlb_lock);
-- 
1.7.3.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxxx  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]