drivers/base: Fix unsigned comparison to -1 in CPUMAP_FILE_MAX_BYTES
Subsystems (2)
PATCH v2 1/1 drivers/base: Fix unsigned comparison to -1 in CPUMAP_FILE_MAX_BYTES
As PAGE_SIZE is unsigned long, -1 > PAGE_SIZE when NR_CPUS <= 3. This leads to very large file sizes:
topology$ ls -l
total 0
-r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_list
Adjust the inequality to catch the case when NR_CPUS is configured to a small value.
---
v2: Remove the +/-1 completely from the test since it will produce the same results, and remove some extra parentheses.
include/linux/cpumask.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/cpumask.h +3 -2
@@ -1127,9 +1127,10 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,* cover a worst-case of every other cpu being on one of two nodes for a * very large NR_CPUS. * -* Use PAGE_SIZE as a minimum for smaller configurations. +* Use PAGE_SIZE as a minimum for smaller configurations while avoiding +* unsigned comparison to -1. */ -#define CPUMAP_FILE_MAX_BYTES ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \ +#define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \ ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)#define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)
Signature · 1 line
2.31.1
Yury Norov
maintainerQuoted 22 lines · Phil Auld
As
PAGE_SIZEis unsigned long, -1 >PAGE_SIZEwhenNR_CPUS<= 3. This leads to very large file sizes:topology$ ls -l
total 0(quoted diff) +0
-13-r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_listAdjust the inequality to catch the case when
NR_CPUSis configured to a small value.
Quoted 8 lines
Fixes 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist")Reported-by feng xiangjun <[email protected]>Signed-off-by Phil Auld <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Yury Norov <[email protected]>Cc feng xiangjun <[email protected]>
Applied on bitmap-for-next. Thanks!
Quoted 27 lines
---
v2: Remove the +/-1 completely from the test since it will produce the same results, and remove some extra parentheses.
include/linux/cpumask.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)include/linux/cpumask.h +3
-2@@ -1127,9 +1127,10 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,* cover a worst-case of every other cpu being on one of two nodes for a * very large NR_CPUS. * -* Use PAGE_SIZE as a minimum for smaller configurations. +* Use PAGE_SIZE as a minimum for smaller configurations while avoiding +* unsigned comparison to -1. */ -#define CPUMAP_FILE_MAX_BYTES ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \ +#define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \ ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)#define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)Signature · 1 line
2.31.1
Quoted 23 lines · On Tue, Sep 06, 2022 at 01:59:53PM -0700 Yury Norov wrote:
Quoted 22 lines · Phil Auld
As
PAGE_SIZEis unsigned long, -1 >PAGE_SIZEwhenNR_CPUS<= 3. This leads to very large file sizes:topology$ ls -l
total 0(quoted diff) +0
-13-r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_listAdjust the inequality to catch the case when
NR_CPUSis configured to a small value.
Quoted 11 lines
Quoted 8 lines
Fixes 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist")Reported-by feng xiangjun <[email protected]>Signed-off-by Phil Auld <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Yury Norov <[email protected]>Cc feng xiangjun <[email protected]>Applied on bitmap-for-next. Thanks!
Great, thanks!
Quoted 28 lines
Quoted 27 lines
---
v2: Remove the +/-1 completely from the test since it will produce the same results, and remove some extra parentheses.
include/linux/cpumask.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)include/linux/cpumask.h +3
-2@@ -1127,9 +1127,10 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,* cover a worst-case of every other cpu being on one of two nodes for a * very large NR_CPUS. * -* Use PAGE_SIZE as a minimum for smaller configurations. +* Use PAGE_SIZE as a minimum for smaller configurations while avoiding +* unsigned comparison to -1. */ -#define CPUMAP_FILE_MAX_BYTES ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \ +#define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \ ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)#define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)Signature · 1 line
2.31.1
Greg Kroah-Hartman
maintainerQuoted 36 lines · Phil Auld
Quoted 23 lines · On Tue, Sep 06, 2022 at 01:59:53PM -0700 Yury Norov wrote:
Quoted 22 lines · Phil Auld
As
PAGE_SIZEis unsigned long, -1 >PAGE_SIZEwhenNR_CPUS<= 3. This leads to very large file sizes:topology$ ls -l
total 0(quoted diff) +0
-13-r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_listAdjust the inequality to catch the case when
NR_CPUSis configured to a small value.Quoted 11 lines
Quoted 8 lines
Fixes 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist")Reported-by feng xiangjun <[email protected]>Signed-off-by Phil Auld <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Yury Norov <[email protected]>Cc feng xiangjun <[email protected]>Applied on bitmap-for-next. Thanks!
Quoted 1 line
Great, thanks!
This is hitting people already and causing problems, so I'll go add it to my tree as well to get it to Linus quicker. Here's one report of the problem:
https://github.com/util-linux/util-linux/issues/1810
thanks,
greg k-h
Quoted 37 lines · On Thu, Sep 22, 2022 at 01:02:45PM +0200 Greg Kroah-Hartman wrote:
Quoted 36 lines · Phil Auld
Quoted 34 lines · On Tue, Sep 06, 2022 at 01:59:53PM -0700 Yury Norov wrote:
Quoted 22 lines · Phil Auld
As
PAGE_SIZEis unsigned long, -1 >PAGE_SIZEwhenNR_CPUS<= 3. This leads to very large file sizes:topology$ ls -l
total 0(quoted diff) +0
-13-r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_listAdjust the inequality to catch the case when
NR_CPUSis configured to a small value.Quoted 8 lines
Fixes 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist")Reported-by feng xiangjun <[email protected]>Signed-off-by Phil Auld <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Yury Norov <[email protected]>Cc feng xiangjun <[email protected]>Applied on bitmap-for-next. Thanks!
Quoted 7 lines
Quoted 1 line
Great, thanks!
This is hitting people already and causing problems, so I'll go add it to my tree as well to get it to Linus quicker. Here's one report of the problem:
https://github.com/util-linux/util-linux/issues/1810
Arrgh! Thanks Greg. I stopped watching it when it got merged above but yeah, this needs to get in soon and then get into any stable trees that got the first one. Sorry about that!
Cheers,
Phil
Quoted 4 lines
thanks,
greg k-h