]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/numa-change-get_mempolicy-to-use-nr_node_ids-instead-of-max_numnodes.patch
Linux 3.18.137
[thirdparty/kernel/stable-queue.git] / queue-4.4 / numa-change-get_mempolicy-to-use-nr_node_ids-instead-of-max_numnodes.patch
1 From 050c17f239fd53adb55aa768d4f41bc76c0fe045 Mon Sep 17 00:00:00 2001
2 From: Ralph Campbell <rcampbell@nvidia.com>
3 Date: Wed, 20 Feb 2019 22:18:58 -0800
4 Subject: numa: change get_mempolicy() to use nr_node_ids instead of MAX_NUMNODES
5
6 From: Ralph Campbell <rcampbell@nvidia.com>
7
8 commit 050c17f239fd53adb55aa768d4f41bc76c0fe045 upstream.
9
10 The system call, get_mempolicy() [1], passes an unsigned long *nodemask
11 pointer and an unsigned long maxnode argument which specifies the length
12 of the user's nodemask array in bits (which is rounded up). The manual
13 page says that if the maxnode value is too small, get_mempolicy will
14 return EINVAL but there is no system call to return this minimum value.
15 To determine this value, some programs search /proc/<pid>/status for a
16 line starting with "Mems_allowed:" and use the number of digits in the
17 mask to determine the minimum value. A recent change to the way this line
18 is formatted [2] causes these programs to compute a value less than
19 MAX_NUMNODES so get_mempolicy() returns EINVAL.
20
21 Change get_mempolicy(), the older compat version of get_mempolicy(), and
22 the copy_nodes_to_user() function to use nr_node_ids instead of
23 MAX_NUMNODES, thus preserving the defacto method of computing the minimum
24 size for the nodemask array and the maxnode argument.
25
26 [1] http://man7.org/linux/man-pages/man2/get_mempolicy.2.html
27 [2] https://lore.kernel.org/lkml/1545405631-6808-1-git-send-email-longman@redhat.com
28
29 Link: http://lkml.kernel.org/r/20190211180245.22295-1-rcampbell@nvidia.com
30 Fixes: 4fb8e5b89bcbbbb ("include/linux/nodemask.h: use nr_node_ids (not MAX_NUMNODES) in __nodemask_pr_numnodes()")
31 Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
32 Suggested-by: Alexander Duyck <alexander.duyck@gmail.com>
33 Cc: Waiman Long <longman@redhat.com>
34 Cc: <stable@vger.kernel.org>
35 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
36 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39 ---
40 mm/mempolicy.c | 6 +++---
41 1 file changed, 3 insertions(+), 3 deletions(-)
42
43 --- a/mm/mempolicy.c
44 +++ b/mm/mempolicy.c
45 @@ -1295,7 +1295,7 @@ static int copy_nodes_to_user(unsigned l
46 nodemask_t *nodes)
47 {
48 unsigned long copy = ALIGN(maxnode-1, 64) / 8;
49 - const int nbytes = BITS_TO_LONGS(MAX_NUMNODES) * sizeof(long);
50 + unsigned int nbytes = BITS_TO_LONGS(nr_node_ids) * sizeof(long);
51
52 if (copy > nbytes) {
53 if (copy > PAGE_SIZE)
54 @@ -1456,7 +1456,7 @@ SYSCALL_DEFINE5(get_mempolicy, int __use
55 int uninitialized_var(pval);
56 nodemask_t nodes;
57
58 - if (nmask != NULL && maxnode < MAX_NUMNODES)
59 + if (nmask != NULL && maxnode < nr_node_ids)
60 return -EINVAL;
61
62 err = do_get_mempolicy(&pval, &nodes, addr, flags);
63 @@ -1485,7 +1485,7 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, in
64 unsigned long nr_bits, alloc_size;
65 DECLARE_BITMAP(bm, MAX_NUMNODES);
66
67 - nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
68 + nr_bits = min_t(unsigned long, maxnode-1, nr_node_ids);
69 alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
70
71 if (nmask)