All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/hugetlb: Fix unsigned overflow in  __nr_hugepages_store_common()
@ 2019-02-22 13:55 Jing Xiangfeng
  0 siblings, 0 replies; only message in thread
From: Jing Xiangfeng @ 2019-02-22 13:55 UTC (permalink / raw)
  To: mike.kravetz, mhocko, akpm
  Cc: hughd, linux-mm, n-horiguchi, aarcange, kirill.shutemov,
	linux-kernel, Jing Xiangfeng

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="y", Size: 1169 bytes --]

User can change a node specific hugetlb count. i.e.
/sys/devices/system/node/node1/hugepages/hugepages-2048kB
the calculated value of count is a total number of huge pages. It could
be overflow when a user entering a crazy high value. If so,the total
number of huge pages could be a small value which is not user expect.
We can simply fix it by setting count to ULONG_MAX, then it goes on. This
may be more in line with user's intention of allocating as many huge pages
as possible.

Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
---
 mm/hugetlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index afef616..18fa7d7 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2423,7 +2423,10 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
 		 * per node hstate attribute: adjust count to global,
 		 * but restrict alloc/free to the specified node.
 		 */
+		unsigned long old_count = count;
 		count += h->nr_huge_pages - h->nr_huge_pages_node[nid];
+		if (count < old_count)
+			count = ULONG_MAX;
 		init_nodemask_of_node(nodes_allowed, nid);
 	} else
 		nodes_allowed = &node_states[N_MEMORY];
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-02-22 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-22 13:55 [PATCH v2] mm/hugetlb: Fix unsigned overflow in __nr_hugepages_store_common() Jing Xiangfeng

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.