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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
90eb270d 85e1f758

+29 -31
+29 -31
kernel/fork.c
··· 198 198 struct vm_struct *stack_vm_area; 199 199 }; 200 200 201 - static bool try_release_thread_stack_to_cache(struct vm_struct *vm) 201 + static bool try_release_thread_stack_to_cache(struct vm_struct *vm_area) 202 202 { 203 203 unsigned int i; 204 204 205 205 for (i = 0; i < NR_CACHED_STACKS; i++) { 206 206 struct vm_struct *tmp = NULL; 207 207 208 - if (this_cpu_try_cmpxchg(cached_stacks[i], &tmp, vm)) 208 + if (this_cpu_try_cmpxchg(cached_stacks[i], &tmp, vm_area)) 209 209 return true; 210 210 } 211 211 return false; ··· 214 214 static void thread_stack_free_rcu(struct rcu_head *rh) 215 215 { 216 216 struct vm_stack *vm_stack = container_of(rh, struct vm_stack, rcu); 217 + struct vm_struct *vm_area = vm_stack->stack_vm_area; 217 218 218 219 if (try_release_thread_stack_to_cache(vm_stack->stack_vm_area)) 219 220 return; 220 221 221 - vfree(vm_stack); 222 + vfree(vm_area->addr); 222 223 } 223 224 224 225 static void thread_stack_delayed_free(struct task_struct *tsk) ··· 232 231 233 232 static int free_vm_stack_cache(unsigned int cpu) 234 233 { 235 - struct vm_struct **cached_vm_stacks = per_cpu_ptr(cached_stacks, cpu); 234 + struct vm_struct **cached_vm_stack_areas = per_cpu_ptr(cached_stacks, cpu); 236 235 int i; 237 236 238 237 for (i = 0; i < NR_CACHED_STACKS; i++) { 239 - struct vm_struct *vm_stack = cached_vm_stacks[i]; 238 + struct vm_struct *vm_area = cached_vm_stack_areas[i]; 240 239 241 - if (!vm_stack) 240 + if (!vm_area) 242 241 continue; 243 242 244 - vfree(vm_stack->addr); 245 - cached_vm_stacks[i] = NULL; 243 + vfree(vm_area->addr); 244 + cached_vm_stack_areas[i] = NULL; 246 245 } 247 246 248 247 return 0; 249 248 } 250 249 251 - static int memcg_charge_kernel_stack(struct vm_struct *vm) 250 + static int memcg_charge_kernel_stack(struct vm_struct *vm_area) 252 251 { 253 252 int i; 254 253 int ret; 255 254 int nr_charged = 0; 256 255 257 - BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE); 256 + BUG_ON(vm_area->nr_pages != THREAD_SIZE / PAGE_SIZE); 258 257 259 258 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) { 260 - ret = memcg_kmem_charge_page(vm->pages[i], GFP_KERNEL, 0); 259 + ret = memcg_kmem_charge_page(vm_area->pages[i], GFP_KERNEL, 0); 261 260 if (ret) 262 261 goto err; 263 262 nr_charged++; ··· 265 264 return 0; 266 265 err: 267 266 for (i = 0; i < nr_charged; i++) 268 - memcg_kmem_uncharge_page(vm->pages[i], 0); 267 + memcg_kmem_uncharge_page(vm_area->pages[i], 0); 269 268 return ret; 270 269 } 271 270 272 271 static int alloc_thread_stack_node(struct task_struct *tsk, int node) 273 272 { 274 - struct vm_struct *vm; 273 + struct vm_struct *vm_area; 275 274 void *stack; 276 275 int i; 277 276 278 277 for (i = 0; i < NR_CACHED_STACKS; i++) { 279 - struct vm_struct *s; 280 - 281 - s = this_cpu_xchg(cached_stacks[i], NULL); 282 - 283 - if (!s) 278 + vm_area = this_cpu_xchg(cached_stacks[i], NULL); 279 + if (!vm_area) 284 280 continue; 285 281 286 282 /* Reset stack metadata. */ 287 - kasan_unpoison_range(s->addr, THREAD_SIZE); 283 + kasan_unpoison_range(vm_area->addr, THREAD_SIZE); 288 284 289 - stack = kasan_reset_tag(s->addr); 285 + stack = kasan_reset_tag(vm_area->addr); 290 286 291 287 /* Clear stale pointers from reused stack. */ 292 288 memset(stack, 0, THREAD_SIZE); 293 289 294 - if (memcg_charge_kernel_stack(s)) { 295 - vfree(s->addr); 290 + if (memcg_charge_kernel_stack(vm_area)) { 291 + vfree(vm_area->addr); 296 292 return -ENOMEM; 297 293 } 298 294 299 - tsk->stack_vm_area = s; 295 + tsk->stack_vm_area = vm_area; 300 296 tsk->stack = stack; 301 297 return 0; 302 298 } ··· 309 311 if (!stack) 310 312 return -ENOMEM; 311 313 312 - vm = find_vm_area(stack); 313 - if (memcg_charge_kernel_stack(vm)) { 314 + vm_area = find_vm_area(stack); 315 + if (memcg_charge_kernel_stack(vm_area)) { 314 316 vfree(stack); 315 317 return -ENOMEM; 316 318 } ··· 319 321 * free_thread_stack() can be called in interrupt context, 320 322 * so cache the vm_struct. 321 323 */ 322 - tsk->stack_vm_area = vm; 324 + tsk->stack_vm_area = vm_area; 323 325 stack = kasan_reset_tag(stack); 324 326 tsk->stack = stack; 325 327 return 0; ··· 515 517 static void account_kernel_stack(struct task_struct *tsk, int account) 516 518 { 517 519 if (IS_ENABLED(CONFIG_VMAP_STACK)) { 518 - struct vm_struct *vm = task_stack_vm_area(tsk); 520 + struct vm_struct *vm_area = task_stack_vm_area(tsk); 519 521 int i; 520 522 521 523 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) 522 - mod_lruvec_page_state(vm->pages[i], NR_KERNEL_STACK_KB, 524 + mod_lruvec_page_state(vm_area->pages[i], NR_KERNEL_STACK_KB, 523 525 account * (PAGE_SIZE / 1024)); 524 526 } else { 525 527 void *stack = task_stack_page(tsk); ··· 535 537 account_kernel_stack(tsk, -1); 536 538 537 539 if (IS_ENABLED(CONFIG_VMAP_STACK)) { 538 - struct vm_struct *vm; 540 + struct vm_struct *vm_area; 539 541 int i; 540 542 541 - vm = task_stack_vm_area(tsk); 543 + vm_area = task_stack_vm_area(tsk); 542 544 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) 543 - memcg_kmem_uncharge_page(vm->pages[i], 0); 545 + memcg_kmem_uncharge_page(vm_area->pages[i], 0); 544 546 } 545 547 } 546 548