CC: [email protected] CC: [email protected] TO: Liu Yuntao <[email protected]> CC: Johannes Weiner <[email protected]> CC: Mike Kravetz <[email protected]> CC: Andrew Morton <[email protected]> CC: Linux Memory Management List <[email protected]>
tree: https://github.com/hnaz/linux-mm master head: 31e523f69aa14a1f4ba298c63034d8dc62c4aae7 commit: a9cab87f99a622ebdceb96c678eddfda78786005 [14/304] hugetlbfs: fix a truncation issue in hugepages parameter :::::: branch date: 2 days ago :::::: commit date: 2 days ago config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220214/[email protected]/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> smatch warnings: mm/hugetlb.c:4170 hugepages_setup() warn: potential spectre issue 'default_hugepages_in_node' [w] mm/hugetlb.c:4172 hugepages_setup() warn: potential spectre issue 'parsed_hstate->max_huge_pages_node' [w] vim +/default_hugepages_in_node +4170 mm/hugetlb.c a3437870160cf2 Nishanth Aravamudan 2008-07-23 4109 b5389086ad7be0 Zhenguo Yao 2021-11-05 4110 bool __init __weak hugetlb_node_alloc_supported(void) b5389086ad7be0 Zhenguo Yao 2021-11-05 4111 { b5389086ad7be0 Zhenguo Yao 2021-11-05 4112 return true; b5389086ad7be0 Zhenguo Yao 2021-11-05 4113 } 282f4214384ee2 Mike Kravetz 2020-06-03 4114 /* 282f4214384ee2 Mike Kravetz 2020-06-03 4115 * hugepages command line processing 282f4214384ee2 Mike Kravetz 2020-06-03 4116 * hugepages normally follows a valid hugepagsz or default_hugepagsz 282f4214384ee2 Mike Kravetz 2020-06-03 4117 * specification. If not, ignore the hugepages value. hugepages can also 282f4214384ee2 Mike Kravetz 2020-06-03 4118 * be the first huge page command line option in which case it implicitly 282f4214384ee2 Mike Kravetz 2020-06-03 4119 * specifies the number of huge pages for the default size. 282f4214384ee2 Mike Kravetz 2020-06-03 4120 */ 282f4214384ee2 Mike Kravetz 2020-06-03 4121 static int __init hugepages_setup(char *s) a3437870160cf2 Nishanth Aravamudan 2008-07-23 4122 { a3437870160cf2 Nishanth Aravamudan 2008-07-23 4123 unsigned long *mhp; 8faa8b077b2cdc Andi Kleen 2008-07-23 4124 static unsigned long *last_mhp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4125 int node = NUMA_NO_NODE; b5389086ad7be0 Zhenguo Yao 2021-11-05 4126 int count; b5389086ad7be0 Zhenguo Yao 2021-11-05 4127 unsigned long tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4128 char *p = s; a3437870160cf2 Nishanth Aravamudan 2008-07-23 4129 9fee021d15ddd8 Vaishali Thakkar 2016-05-19 4130 if (!parsed_valid_hugepagesz) { 282f4214384ee2 Mike Kravetz 2020-06-03 4131 pr_warn("HugeTLB: hugepages=%s does not follow a valid hugepagesz, ignoring\n", s); 9fee021d15ddd8 Vaishali Thakkar 2016-05-19 4132 parsed_valid_hugepagesz = true; 282f4214384ee2 Mike Kravetz 2020-06-03 4133 return 0; 9fee021d15ddd8 Vaishali Thakkar 2016-05-19 4134 } 282f4214384ee2 Mike Kravetz 2020-06-03 4135 a3437870160cf2 Nishanth Aravamudan 2008-07-23 4136 /* 282f4214384ee2 Mike Kravetz 2020-06-03 4137 * !hugetlb_max_hstate means we haven't parsed a hugepagesz= parameter 282f4214384ee2 Mike Kravetz 2020-06-03 4138 * yet, so this hugepages= parameter goes to the "default hstate". 282f4214384ee2 Mike Kravetz 2020-06-03 4139 * Otherwise, it goes with the previously parsed hugepagesz or 282f4214384ee2 Mike Kravetz 2020-06-03 4140 * default_hugepagesz. a3437870160cf2 Nishanth Aravamudan 2008-07-23 4141 */ 9fee021d15ddd8 Vaishali Thakkar 2016-05-19 4142 else if (!hugetlb_max_hstate) a3437870160cf2 Nishanth Aravamudan 2008-07-23 4143 mhp = &default_hstate_max_huge_pages; a3437870160cf2 Nishanth Aravamudan 2008-07-23 4144 else a3437870160cf2 Nishanth Aravamudan 2008-07-23 4145 mhp = &parsed_hstate->max_huge_pages; a3437870160cf2 Nishanth Aravamudan 2008-07-23 4146 8faa8b077b2cdc Andi Kleen 2008-07-23 4147 if (mhp == last_mhp) { 282f4214384ee2 Mike Kravetz 2020-06-03 4148 pr_warn("HugeTLB: hugepages= specified twice without interleaving hugepagesz=, ignoring hugepages=%s\n", s); 282f4214384ee2 Mike Kravetz 2020-06-03 4149 return 0; 8faa8b077b2cdc Andi Kleen 2008-07-23 4150 } 8faa8b077b2cdc Andi Kleen 2008-07-23 4151 b5389086ad7be0 Zhenguo Yao 2021-11-05 4152 while (*p) { b5389086ad7be0 Zhenguo Yao 2021-11-05 4153 count = 0; b5389086ad7be0 Zhenguo Yao 2021-11-05 4154 if (sscanf(p, "%lu%n", &tmp, &count) != 1) b5389086ad7be0 Zhenguo Yao 2021-11-05 4155 goto invalid; b5389086ad7be0 Zhenguo Yao 2021-11-05 4156 /* Parameter is node format */ b5389086ad7be0 Zhenguo Yao 2021-11-05 4157 if (p[count] == ':') { b5389086ad7be0 Zhenguo Yao 2021-11-05 4158 if (!hugetlb_node_alloc_supported()) { b5389086ad7be0 Zhenguo Yao 2021-11-05 4159 pr_warn("HugeTLB: architecture can't support node specific alloc, ignoring!\n"); b5389086ad7be0 Zhenguo Yao 2021-11-05 4160 return 0; b5389086ad7be0 Zhenguo Yao 2021-11-05 4161 } a9cab87f99a622 Liu Yuntao 2022-02-11 4162 if (tmp >= nr_online_nodes) a9cab87f99a622 Liu Yuntao 2022-02-11 4163 goto invalid; b5389086ad7be0 Zhenguo Yao 2021-11-05 4164 node = tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4165 p += count + 1; b5389086ad7be0 Zhenguo Yao 2021-11-05 4166 /* Parse hugepages */ b5389086ad7be0 Zhenguo Yao 2021-11-05 4167 if (sscanf(p, "%lu%n", &tmp, &count) != 1) b5389086ad7be0 Zhenguo Yao 2021-11-05 4168 goto invalid; b5389086ad7be0 Zhenguo Yao 2021-11-05 4169 if (!hugetlb_max_hstate) b5389086ad7be0 Zhenguo Yao 2021-11-05 @4170 default_hugepages_in_node[node] = tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4171 else b5389086ad7be0 Zhenguo Yao 2021-11-05 @4172 parsed_hstate->max_huge_pages_node[node] = tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4173 *mhp += tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4174 /* Go to parse next node*/ b5389086ad7be0 Zhenguo Yao 2021-11-05 4175 if (p[count] == ',') b5389086ad7be0 Zhenguo Yao 2021-11-05 4176 p += count + 1; b5389086ad7be0 Zhenguo Yao 2021-11-05 4177 else b5389086ad7be0 Zhenguo Yao 2021-11-05 4178 break; b5389086ad7be0 Zhenguo Yao 2021-11-05 4179 } else { b5389086ad7be0 Zhenguo Yao 2021-11-05 4180 if (p != s) b5389086ad7be0 Zhenguo Yao 2021-11-05 4181 goto invalid; b5389086ad7be0 Zhenguo Yao 2021-11-05 4182 *mhp = tmp; b5389086ad7be0 Zhenguo Yao 2021-11-05 4183 break; b5389086ad7be0 Zhenguo Yao 2021-11-05 4184 } b5389086ad7be0 Zhenguo Yao 2021-11-05 4185 } a3437870160cf2 Nishanth Aravamudan 2008-07-23 4186 8faa8b077b2cdc Andi Kleen 2008-07-23 4187 /* 8faa8b077b2cdc Andi Kleen 2008-07-23 4188 * Global state is always initialized later in hugetlb_init. 04adbc3f7bff40 Miaohe Lin 2021-05-04 4189 * But we need to allocate gigantic hstates here early to still 8faa8b077b2cdc Andi Kleen 2008-07-23 4190 * use the bootmem allocator. 8faa8b077b2cdc Andi Kleen 2008-07-23 4191 */ 04adbc3f7bff40 Miaohe Lin 2021-05-04 4192 if (hugetlb_max_hstate && hstate_is_gigantic(parsed_hstate)) 8faa8b077b2cdc Andi Kleen 2008-07-23 4193 hugetlb_hstate_alloc_pages(parsed_hstate); 8faa8b077b2cdc Andi Kleen 2008-07-23 4194 8faa8b077b2cdc Andi Kleen 2008-07-23 4195 last_mhp = mhp; 8faa8b077b2cdc Andi Kleen 2008-07-23 4196 a3437870160cf2 Nishanth Aravamudan 2008-07-23 4197 return 1; b5389086ad7be0 Zhenguo Yao 2021-11-05 4198 b5389086ad7be0 Zhenguo Yao 2021-11-05 4199 invalid: b5389086ad7be0 Zhenguo Yao 2021-11-05 4200 pr_warn("HugeTLB: Invalid hugepages parameter %s\n", p); b5389086ad7be0 Zhenguo Yao 2021-11-05 4201 return 0; a3437870160cf2 Nishanth Aravamudan 2008-07-23 4202 } 282f4214384ee2 Mike Kravetz 2020-06-03 4203 __setup("hugepages=", hugepages_setup); e11bfbfcb08ef4 Nicholas Piggin 2008-07-23 4204 :::::: The code at line 4170 was first introduced by commit :::::: b5389086ad7be0453c55e0069a89856d1fbdf605 hugetlbfs: extend the definition of hugepages parameter to support node allocation :::::: TO: Zhenguo Yao <[email protected]> :::::: CC: Linus Torvalds <[email protected]> --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/[email protected] _______________________________________________ kbuild mailing list -- [email protected] To unsubscribe send an email to [email protected]
