.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/kernel/profile.c |
---|
3 | 4 | * Simple profiling. Manages a direct-mapped profile hit count buffer, |
---|
.. | .. |
---|
16 | 17 | |
---|
17 | 18 | #include <linux/export.h> |
---|
18 | 19 | #include <linux/profile.h> |
---|
19 | | -#include <linux/bootmem.h> |
---|
| 20 | +#include <linux/memblock.h> |
---|
20 | 21 | #include <linux/notifier.h> |
---|
21 | 22 | #include <linux/mm.h> |
---|
22 | 23 | #include <linux/cpumask.h> |
---|
.. | .. |
---|
108 | 109 | |
---|
109 | 110 | /* only text is profiled */ |
---|
110 | 111 | prof_len = (_etext - _stext) >> prof_shift; |
---|
| 112 | + |
---|
| 113 | + if (!prof_len) { |
---|
| 114 | + pr_warn("profiling shift: %u too large\n", prof_shift); |
---|
| 115 | + prof_on = 0; |
---|
| 116 | + return -EINVAL; |
---|
| 117 | + } |
---|
| 118 | + |
---|
111 | 119 | buffer_bytes = prof_len*sizeof(atomic_t); |
---|
112 | 120 | |
---|
113 | 121 | if (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL)) |
---|
.. | .. |
---|
336 | 344 | struct page *page; |
---|
337 | 345 | int i; |
---|
338 | 346 | |
---|
339 | | - if (prof_cpu_mask != NULL) |
---|
| 347 | + if (cpumask_available(prof_cpu_mask)) |
---|
340 | 348 | cpumask_clear_cpu(cpu, prof_cpu_mask); |
---|
341 | 349 | |
---|
342 | 350 | for (i = 0; i < 2; i++) { |
---|
.. | .. |
---|
373 | 381 | |
---|
374 | 382 | static int profile_online_cpu(unsigned int cpu) |
---|
375 | 383 | { |
---|
376 | | - if (prof_cpu_mask != NULL) |
---|
| 384 | + if (cpumask_available(prof_cpu_mask)) |
---|
377 | 385 | cpumask_set_cpu(cpu, prof_cpu_mask); |
---|
378 | 386 | |
---|
379 | 387 | return 0; |
---|
.. | .. |
---|
403 | 411 | { |
---|
404 | 412 | struct pt_regs *regs = get_irq_regs(); |
---|
405 | 413 | |
---|
406 | | - if (!user_mode(regs) && prof_cpu_mask != NULL && |
---|
| 414 | + if (!user_mode(regs) && cpumask_available(prof_cpu_mask) && |
---|
407 | 415 | cpumask_test_cpu(smp_processor_id(), prof_cpu_mask)) |
---|
408 | 416 | profile_hit(type, (void *)profile_pc(regs)); |
---|
409 | 417 | } |
---|
.. | .. |
---|
442 | 450 | return err; |
---|
443 | 451 | } |
---|
444 | 452 | |
---|
445 | | -static const struct file_operations prof_cpu_mask_proc_fops = { |
---|
446 | | - .open = prof_cpu_mask_proc_open, |
---|
447 | | - .read = seq_read, |
---|
448 | | - .llseek = seq_lseek, |
---|
449 | | - .release = single_release, |
---|
450 | | - .write = prof_cpu_mask_proc_write, |
---|
| 453 | +static const struct proc_ops prof_cpu_mask_proc_ops = { |
---|
| 454 | + .proc_open = prof_cpu_mask_proc_open, |
---|
| 455 | + .proc_read = seq_read, |
---|
| 456 | + .proc_lseek = seq_lseek, |
---|
| 457 | + .proc_release = single_release, |
---|
| 458 | + .proc_write = prof_cpu_mask_proc_write, |
---|
451 | 459 | }; |
---|
452 | 460 | |
---|
453 | 461 | void create_prof_cpu_mask(void) |
---|
454 | 462 | { |
---|
455 | 463 | /* create /proc/irq/prof_cpu_mask */ |
---|
456 | | - proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_fops); |
---|
| 464 | + proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_ops); |
---|
457 | 465 | } |
---|
458 | 466 | |
---|
459 | 467 | /* |
---|
.. | .. |
---|
517 | 525 | return count; |
---|
518 | 526 | } |
---|
519 | 527 | |
---|
520 | | -static const struct file_operations proc_profile_operations = { |
---|
521 | | - .read = read_profile, |
---|
522 | | - .write = write_profile, |
---|
523 | | - .llseek = default_llseek, |
---|
| 528 | +static const struct proc_ops profile_proc_ops = { |
---|
| 529 | + .proc_read = read_profile, |
---|
| 530 | + .proc_write = write_profile, |
---|
| 531 | + .proc_lseek = default_llseek, |
---|
524 | 532 | }; |
---|
525 | 533 | |
---|
526 | 534 | int __ref create_proc_profile(void) |
---|
.. | .. |
---|
548 | 556 | err = 0; |
---|
549 | 557 | #endif |
---|
550 | 558 | entry = proc_create("profile", S_IWUSR | S_IRUGO, |
---|
551 | | - NULL, &proc_profile_operations); |
---|
| 559 | + NULL, &profile_proc_ops); |
---|
552 | 560 | if (!entry) |
---|
553 | 561 | goto err_state_onl; |
---|
554 | 562 | proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t)); |
---|