Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fork: clean-up naming of vm_stack/vm_struct variables in vmap stacks code

There are two data types: "struct vm_struct" and "struct vm_stack" that
have the same local variable names: vm_stack, or vm, or s, which makes the
code confusing to read.

Change the code so the naming is consistent:

struct vm_struct is always called vm_area
struct vm_stack is always called vm_stack

One change altering vfree(vm_stack) to vfree(vm_area->addr) may look like
a semantic change but it is not: vm_area->addr points to the vm_stack.
This was done to improve readability.

[linus.walleij@linaro.org: rebased and added new users of the variable names, address review comments]
Link: https://lore.kernel.org/20240311164638.2015063-4-pasha.tatashin@soleen.com
Link: https://lkml.kernel.org/r/20250509-fork-fixes-v3-2-e6c69dd356f2@linaro.org
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
449e0b4e 08e2153d

+29 -31
+29 -31
kernel/fork.c
··· 207 207 struct vm_struct *stack_vm_area; 208 208 }; 209 209 210 - static bool try_release_thread_stack_to_cache(struct vm_struct *vm) 210 + static bool try_release_thread_stack_to_cache(struct vm_struct *vm_area) 211 211 { 212 212 unsigned int i; 213 213 214 214 for (i = 0; i < NR_CACHED_STACKS; i++) { 215 215 struct vm_struct *tmp = NULL; 216 216 217 - if (this_cpu_try_cmpxchg(cached_stacks[i], &tmp, vm)) 217 + if (this_cpu_try_cmpxchg(cached_stacks[i], &tmp, vm_area)) 218 218 return true; 219 219 } 220 220 return false; ··· 223 223 static void thread_stack_free_rcu(struct rcu_head *rh) 224 224 { 225 225 struct vm_stack *vm_stack = container_of(rh, struct vm_stack, rcu); 226 + struct vm_struct *vm_area = vm_stack->stack_vm_area; 226 227 227 228 if (try_release_thread_stack_to_cache(vm_stack->stack_vm_area)) 228 229 return; 229 230 230 - vfree(vm_stack); 231 + vfree(vm_area->addr); 231 232 } 232 233 233 234 static void thread_stack_delayed_free(struct task_struct *tsk) ··· 241 240 242 241 static int free_vm_stack_cache(unsigned int cpu) 243 242 { 244 - struct vm_struct **cached_vm_stacks = per_cpu_ptr(cached_stacks, cpu); 243 + struct vm_struct **cached_vm_stack_areas = per_cpu_ptr(cached_stacks, cpu); 245 244 int i; 246 245 247 246 for (i = 0; i < NR_CACHED_STACKS; i++) { 248 - struct vm_struct *vm_stack = cached_vm_stacks[i]; 247 + struct vm_struct *vm_area = cached_vm_stack_areas[i]; 249 248 250 - if (!vm_stack) 249 + if (!vm_area) 251 250 continue; 252 251 253 - vfree(vm_stack->addr); 254 - cached_vm_stacks[i] = NULL; 252 + vfree(vm_area->addr); 253 + cached_vm_stack_areas[i] = NULL; 255 254 } 256 255 257 256 return 0; 258 257 } 259 258 260 - static int memcg_charge_kernel_stack(struct vm_struct *vm) 259 + static int memcg_charge_kernel_stack(struct vm_struct *vm_area) 261 260 { 262 261 int i; 263 262 int ret; 264 263 int nr_charged = 0; 265 264 266 - BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE); 265 + BUG_ON(vm_area->nr_pages != THREAD_SIZE / PAGE_SIZE); 267 266 268 267 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) { 269 - ret = memcg_kmem_charge_page(vm->pages[i], GFP_KERNEL, 0); 268 + ret = memcg_kmem_charge_page(vm_area->pages[i], GFP_KERNEL, 0); 270 269 if (ret) 271 270 goto err; 272 271 nr_charged++; ··· 274 273 return 0; 275 274 err: 276 275 for (i = 0; i < nr_charged; i++) 277 - memcg_kmem_uncharge_page(vm->pages[i], 0); 276 + memcg_kmem_uncharge_page(vm_area->pages[i], 0); 278 277 return ret; 279 278 } 280 279 281 280 static int alloc_thread_stack_node(struct task_struct *tsk, int node) 282 281 { 283 - struct vm_struct *vm; 282 + struct vm_struct *vm_area; 284 283 void *stack; 285 284 int i; 286 285 287 286 for (i = 0; i < NR_CACHED_STACKS; i++) { 288 - struct vm_struct *s; 289 - 290 - s = this_cpu_xchg(cached_stacks[i], NULL); 291 - 292 - if (!s) 287 + vm_area = this_cpu_xchg(cached_stacks[i], NULL); 288 + if (!vm_area) 293 289 continue; 294 290 295 291 /* Reset stack metadata. */ 296 - kasan_unpoison_range(s->addr, THREAD_SIZE); 292 + kasan_unpoison_range(vm_area->addr, THREAD_SIZE); 297 293 298 - stack = kasan_reset_tag(s->addr); 294 + stack = kasan_reset_tag(vm_area->addr); 299 295 300 296 /* Clear stale pointers from reused stack. */ 301 297 memset(stack, 0, THREAD_SIZE); 302 298 303 - if (memcg_charge_kernel_stack(s)) { 304 - vfree(s->addr); 299 + if (memcg_charge_kernel_stack(vm_area)) { 300 + vfree(vm_area->addr); 305 301 return -ENOMEM; 306 302 } 307 303 308 - tsk->stack_vm_area = s; 304 + tsk->stack_vm_area = vm_area; 309 305 tsk->stack = stack; 310 306 return 0; 311 307 } ··· 318 320 if (!stack) 319 321 return -ENOMEM; 320 322 321 - vm = find_vm_area(stack); 322 - if (memcg_charge_kernel_stack(vm)) { 323 + vm_area = find_vm_area(stack); 324 + if (memcg_charge_kernel_stack(vm_area)) { 323 325 vfree(stack); 324 326 return -ENOMEM; 325 327 } ··· 328 330 * free_thread_stack() can be called in interrupt context, 329 331 * so cache the vm_struct. 330 332 */ 331 - tsk->stack_vm_area = vm; 333 + tsk->stack_vm_area = vm_area; 332 334 stack = kasan_reset_tag(stack); 333 335 tsk->stack = stack; 334 336 return 0; ··· 435 437 static void account_kernel_stack(struct task_struct *tsk, int account) 436 438 { 437 439 if (IS_ENABLED(CONFIG_VMAP_STACK)) { 438 - struct vm_struct *vm = task_stack_vm_area(tsk); 440 + struct vm_struct *vm_area = task_stack_vm_area(tsk); 439 441 int i; 440 442 441 443 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) 442 - mod_lruvec_page_state(vm->pages[i], NR_KERNEL_STACK_KB, 444 + mod_lruvec_page_state(vm_area->pages[i], NR_KERNEL_STACK_KB, 443 445 account * (PAGE_SIZE / 1024)); 444 446 } else { 445 447 void *stack = task_stack_page(tsk); ··· 455 457 account_kernel_stack(tsk, -1); 456 458 457 459 if (IS_ENABLED(CONFIG_VMAP_STACK)) { 458 - struct vm_struct *vm; 460 + struct vm_struct *vm_area; 459 461 int i; 460 462 461 - vm = task_stack_vm_area(tsk); 463 + vm_area = task_stack_vm_area(tsk); 462 464 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) 463 - memcg_kmem_uncharge_page(vm->pages[i], 0); 465 + memcg_kmem_uncharge_page(vm_area->pages[i], 0); 464 466 } 465 467 } 466 468