Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Aug 01, 2024
  2. Jul 24, 2024
    • Joel Granados's avatar
      sysctl: treewide: constify the ctl_table argument of proc_handlers · 78eb4ea2
      Joel Granados authored
      const qualify the struct ctl_table argument in the proc_handler function
      signatures. This is a prerequisite to moving the static ctl_table
      structs into .rodata data which will ensure that proc_handler function
      pointers cannot be modified.
      
      This patch has been generated by the following coccinelle script:
      
      ```
        virtual patch
      
        @r1@
        identifier ctl, write, buffer, lenp, ppos;
        identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)";
        @@
      
        int func(
        - struct ctl_table *ctl
        + const struct ctl_table *ctl
          ,int write, void *buffer, size_t *lenp, loff_t *ppos);
      
        @r2@
        identifier func, ctl, write, buffer, lenp, ppos;
        @@
      
        int func(
        - struct ctl_table *ctl
        + const struct ctl_table *ctl
          ,int write, void *buffer, size_t *lenp, loff_t *ppos)
        { ... }
      
        @r3@
        identifier func;
        @@
      
        int func(
        - stru...
      78eb4ea2
  3. Jul 22, 2024
  4. Jul 03, 2024
  5. Apr 26, 2024
  6. Apr 22, 2024
  7. Apr 19, 2024
  8. Apr 09, 2024
  9. Mar 12, 2024
  10. Feb 29, 2024
    • Fei Wu's avatar
      perf: RISCV: Fix panic on pmu overflow handler · 34b56786
      Fei Wu authored
      
      (1 << idx) of int is not desired when setting bits in unsigned long
      overflowed_ctrs, use BIT() instead. This panic happens when running
      'perf record -e branches' on sophgo sg2042.
      
      [  273.311852] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000098
      [  273.320851] Oops [#1]
      [  273.323179] Modules linked in:
      [  273.326303] CPU: 0 PID: 1475 Comm: perf Not tainted 6.6.0-rc3+ #9
      [  273.332521] Hardware name: Sophgo Mango (DT)
      [  273.336878] epc : riscv_pmu_ctr_get_width_mask+0x8/0x62
      [  273.342291]  ra : pmu_sbi_ovf_handler+0x2e0/0x34e
      [  273.347091] epc : ffffffff80aecd98 ra : ffffffff80aee056 sp : fffffff6e36928b0
      [  273.354454]  gp : ffffffff821f82d0 tp : ffffffd90c353200 t0 : 0000002ade4f9978
      [  273.361815]  t1 : 0000000000504d55 t2 : ffffffff8016cd8c s0 : fffffff6e3692a70
      [  273.369180]  s1 : 0000000000000020 a0 : 0000000000000000 a1 : 00001a8e81800000
      [  273.376540]  a2 : 0000003c00070198 a3 : 0000003c00db75a4 a4 : 0000000000000015
      [  273.383901]  a5 : ffffffd7ff8804b0 a6 : 0000000000000015 a7 : 000000000000002a
      [  273.391327]  s2 : 000000000000ffff s3 : 0000000000000000 s4 : ffffffd7ff8803b0
      [  273.398773]  s5 : 0000000000504d55 s6 : ffffffd905069800 s7 : ffffffff821fe210
      [  273.406139]  s8 : 000000007fffffff s9 : ffffffd7ff8803b0 s10: ffffffd903f29098
      [  273.413660]  s11: 0000000080000000 t3 : 0000000000000003 t4 : ffffffff8017a0ca
      [  273.421022]  t5 : ffffffff8023cfc2 t6 : ffffffd9040780e8
      [  273.426437] status: 0000000200000100 badaddr: 0000000000000098 cause: 000000000000000d
      [  273.434512] [<ffffffff80aecd98>] riscv_pmu_ctr_get_width_mask+0x8/0x62
      [  273.441169] [<ffffffff80076bd8>] handle_percpu_devid_irq+0x98/0x1ee
      [  273.447562] [<ffffffff80071158>] generic_handle_domain_irq+0x28/0x36
      [  273.454151] [<ffffffff8047a99a>] riscv_intc_irq+0x36/0x4e
      [  273.459659] [<ffffffff80c944de>] handle_riscv_irq+0x4a/0x74
      [  273.465442] [<ffffffff80c94c48>] do_irq+0x62/0x92
      [  273.470360] Code: 0420 60a2 6402 5529 0141 8082 0013 0000 0013 0000 (6d5c) b783
      [  273.477921] ---[ end trace 0000000000000000 ]---
      [  273.482630] Kernel panic - not syncing: Fatal exception in interrupt
      
      Reviewed-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Reviewed-by: default avatarAtish Patra <atishp@rivosinc.com>
      Signed-off-by: default avatarFei Wu <fei2.wu@intel.com>
      Link: https://lore.kernel.org/r/20240228115425.2613856-1-fei2.wu@intel.com
      
      
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      34b56786
  11. Nov 09, 2023
    • Xiao Wang's avatar
      riscv: Rearrange hwcap.h and cpufeature.h · e72c4333
      Xiao Wang authored
      
      Now hwcap.h and cpufeature.h are mutually including each other, and most of
      the variable/API declarations in hwcap.h are implemented in cpufeature.c,
      so, it's better to move them into cpufeature.h and leave only macros for
      ISA extension logical IDs in hwcap.h.
      
      BTW, the riscv_isa_extension_mask macro is not used now, so this patch
      removes it.
      
      Suggested-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Signed-off-by: default avatarXiao Wang <xiao.w.wang@intel.com>
      Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
      Link: https://lore.kernel.org/r/20231031064553.2319688-2-xiao.w.wang@intel.com
      
      
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      e72c4333
    • Alexandre Ghiti's avatar
      drivers: perf: Do not broadcast to other cpus when starting a counter · 61e3d993
      Alexandre Ghiti authored
      This command:
      
      $ perf record -e cycles:k -e instructions:k -c 10000 -m 64M dd if=/dev/zero of=/dev/null count=1000
      
      gives rise to this kernel warning:
      
      [  444.364395] WARNING: CPU: 0 PID: 104 at kernel/smp.c:775 smp_call_function_many_cond+0x42c/0x436
      [  444.364515] Modules linked in:
      [  444.364657] CPU: 0 PID: 104 Comm: perf-exec Not tainted 6.6.0-rc6-00051-g391df82e8ec3-dirty #73
      [  444.364771] Hardware name: riscv-virtio,qemu (DT)
      [  444.364868] epc : smp_call_function_many_cond+0x42c/0x436
      [  444.364917]  ra : on_each_cpu_cond_mask+0x20/0x32
      [  444.364948] epc : ffffffff8009f9e0 ra : ffffffff8009fa5a sp : ff20000000003800
      [  444.364966]  gp : ffffffff81500aa0 tp : ff60000002b83000 t0 : ff200000000038c0
      [  444.364982]  t1 : ffffffff815021f0 t2 : 000000000000001f s0 : ff200000000038b0
      [  444.364998]  s1 : ff60000002c54d98 a0 : ff60000002a73940 a1 : 0000000000000000
      [  444.365013]  a2 : 0000000000000000 a3 : 0000000000000003 a4 : 0000000000000100
      [  444.365029]  a5 : 0000000000010100 a6 : 0000000000f00000 a7 : 0000000000000000
      [  444.365044]  s2 : 0000000000000000 s3 : ffffffffffffffff s4 : ff60000002c54d98
      [  444.365060]  s5 : ffffffff81539610 s6 : ffffffff80c20c48 s7 : 0000000000000000
      [  444.365075]  s8 : 0000000000000000 s9 : 0000000000000001 s10: 0000000000000001
      [  444.365090]  s11: ffffffff80099394 t3 : 0000000000000003 t4 : 00000000eac0c6e6
      [  444.365104]  t5 : 0000000400000000 t6 : ff60000002e010d0
      [  444.365120] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
      [  444.365226] [<ffffffff8009f9e0>] smp_call_function_many_cond+0x42c/0x436
      [  444.365295] [<ffffffff8009fa5a>] on_each_cpu_cond_mask+0x20/0x32
      [  444.365311] [<ffffffff806e90dc>] pmu_sbi_ctr_start+0x7a/0xaa
      [  444.365327] [<ffffffff806e880c>] riscv_pmu_start+0x48/0x66
      [  444.365339] [<ffffffff8012111a>] perf_adjust_freq_unthr_context+0x196/0x1ac
      [  444.365356] [<ffffffff801237aa>] perf_event_task_tick+0x78/0x8c
      [  444.365368] [<ffffffff8003faf4>] scheduler_tick+0xe6/0x25e
      [  444.365383] [<ffffffff8008a042>] update_process_times+0x80/0x96
      [  444.365398] [<ffffffff800991ec>] tick_sched_handle+0x26/0x52
      [  444.365410] [<ffffffff800993e4>] tick_sched_timer+0x50/0x98
      [  444.365422] [<ffffffff8008a6aa>] __hrtimer_run_queues+0x126/0x18a
      [  444.365433] [<ffffffff8008b350>] hrtimer_interrupt+0xce/0x1da
      [  444.365444] [<ffffffff806cdc60>] riscv_timer_interrupt+0x30/0x3a
      [  444.365457] [<ffffffff8006afa6>] handle_percpu_devid_irq+0x80/0x114
      [  444.365470] [<ffffffff80065b82>] generic_handle_domain_irq+0x1c/0x2a
      [  444.365483] [<ffffffff8045faec>] riscv_intc_irq+0x2e/0x46
      [  444.365497] [<ffffffff808a9c62>] handle_riscv_irq+0x4a/0x74
      [  444.365521] [<ffffffff808aa760>] do_irq+0x7c/0x7e
      [  444.365796] ---[ end trace 0000000000000000 ]---
      
      That's because the fix in commit 3fec3233 ("drivers: perf: Fix panic
      in riscv SBI mmap support") was wrong since there is no need to broadcast
      to other cpus when starting a counter, that's only needed in mmap when
      the counters could have already been started on other cpus, so simply
      remove this broadcast.
      
      Fixes: 3fec3233
      
       ("drivers: perf: Fix panic in riscv SBI mmap support")
      Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Tested-by: default avatarClément Léger <cleger@rivosinc.com>
      Tested-by: default avatarYu Chien Peter Lin <peterlin@andestech.com>
      Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> #On
      Link: https://lore.kernel.org/r/20231026084010.11888-1-alexghiti@rivosinc.com
      
      
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      61e3d993
    • Alexandre Ghiti's avatar
      drivers: perf: Check find_first_bit() return value · c6e316ac
      Alexandre Ghiti authored
      We must check the return value of find_first_bit() before using the
      return value as an index array since it happens to overflow the array
      and then panic:
      
      [  107.318430] Kernel BUG [#1]
      [  107.319434] CPU: 3 PID: 1238 Comm: kill Tainted: G            E      6.6.0-rc6ubuntu-defconfig #2
      [  107.319465] Hardware name: riscv-virtio,qemu (DT)
      [  107.319551] epc : pmu_sbi_ovf_handler+0x3a4/0x3ae
      [  107.319840]  ra : pmu_sbi_ovf_handler+0x52/0x3ae
      [  107.319868] epc : ffffffff80a0a77c ra : ffffffff80a0a42a sp : ffffaf83fecda350
      [  107.319884]  gp : ffffffff823961a8 tp : ffffaf8083db1dc0 t0 : ffffaf83fecda480
      [  107.319899]  t1 : ffffffff80cafe62 t2 : 000000000000ff00 s0 : ffffaf83fecda520
      [  107.319921]  s1 : ffffaf83fecda380 a0 : 00000018fca29df0 a1 : ffffffffffffffff
      [  107.319936]  a2 : 0000000001073734 a3 : 0000000000000004 a4 : 0000000000000000
      [  107.319951]  a5 : 0000000000000040 a6 : 000000001d1c8774 a7 : 0000000000504d55
      [  107.319965]  s2 : ffffffff82451f10 s3 : ffffffff82724e70 s4 : 000000000000003f
      [  107.319980]  s5 : 0000000000000011 s6 : ffffaf8083db27c0 s7 : 0000000000000000
      [  107.319995]  s8 : 0000000000000001 s9 : 00007fffb45d6558 s10: 00007fffb45d81a0
      [  107.320009]  s11: ffffaf7ffff60000 t3 : 0000000000000004 t4 : 0000000000000000
      [  107.320023]  t5 : ffffaf7f80000000 t6 : ffffaf8000000000
      [  107.320037] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
      [  107.320081] [<ffffffff80a0a77c>] pmu_sbi_ovf_handler+0x3a4/0x3ae
      [  107.320112] [<ffffffff800b42d0>] handle_percpu_devid_irq+0x9e/0x1a0
      [  107.320131] [<ffffffff800ad92c>] generic_handle_domain_irq+0x28/0x36
      [  107.320148] [<ffffffff8065f9f8>] riscv_intc_irq+0x36/0x4e
      [  107.320166] [<ffffffff80caf4a0>] handle_riscv_irq+0x54/0x86
      [  107.320189] [<ffffffff80cb0036>] do_irq+0x64/0x96
      [  107.320271] Code: 85a6 855e b097 ff7f 80e7 9220 b709 9002 4501 bbd9 (9002) 6097
      [  107.320585] ---[ end trace 0000000000000000 ]---
      [  107.320704] Kernel panic - not syncing: Fatal exception in interrupt
      [  107.320775] SMP: stopping secondary CPUs
      [  107.321219] Kernel Offset: 0x0 from 0xffffffff80000000
      [  107.333051] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]---
      
      Fixes: 4905ec2f
      
       ("RISC-V: Add sscofpmf extension support")
      Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Link: https://lore.kernel.org/r/20231109082128.40777-1-alexghiti@rivosinc.com
      
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      c6e316ac
  12. Oct 12, 2023
    • Alexandre Ghiti's avatar
      drivers: perf: Fix panic in riscv SBI mmap support · 3fec3233
      Alexandre Ghiti authored
      The following panic can happen when mmap is called before the pmu add
      callback which sets the hardware counter index: this happens for example
      with the following command `perf record --no-bpf-event -n kill`.
      
      [   99.461486] CPU: 1 PID: 1259 Comm: perf Tainted: G            E      6.6.0-rc4ubuntu-defconfig #2
      [   99.461669] Hardware name: riscv-virtio,qemu (DT)
      [   99.461748] epc : pmu_sbi_set_scounteren+0x42/0x44
      [   99.462337]  ra : smp_call_function_many_cond+0x126/0x5b0
      [   99.462369] epc : ffffffff809f9d24 ra : ffffffff800f93e0 sp : ff60000082153aa0
      [   99.462407]  gp : ffffffff82395c98 tp : ff6000009a218040 t0 : ff6000009ab3a4f0
      [   99.462425]  t1 : 0000000000000004 t2 : 0000000000000100 s0 : ff60000082153ab0
      [   99.462459]  s1 : 0000000000000000 a0 : ff60000098869528 a1 : 0000000000000000
      [   99.462473]  a2 : 000000000000001f a3 : 0000000000f00000 a4 : fffffffffffffff8
      [   99.462488]  a5 : 00000000000000cc a6 : 0000000000000000 a7 : 0000000000735049
      [   99.462502]  s2 : 0000000000000001 s3 : ffffffff809f9ce2 s4 : ff60000098869528
      [   99.462516]  s5 : 0000000000000002 s6 : 0000000000000004 s7 : 0000000000000001
      [   99.462530]  s8 : ff600003fec98bc0 s9 : ffffffff826c5890 s10: ff600003fecfcde0
      [   99.462544]  s11: ff600003fec98bc0 t3 : ffffffff819e2558 t4 : ff1c000004623840
      [   99.462557]  t5 : 0000000000000901 t6 : ff6000008feeb890
      [   99.462570] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
      [   99.462658] [<ffffffff809f9d24>] pmu_sbi_set_scounteren+0x42/0x44
      [   99.462979] Code: 1060 4785 97bb 00d7 8fd9 9073 1067 6422 0141 8082 (9002) 0013
      [   99.463335] Kernel BUG [#2]
      
      To circumvent this, try to enable userspace access to the hardware counter
      when it is selected in addition to when the event is mapped. And vice-versa
      when the event is stopped/unmapped.
      
      Fixes: cc4c07c8
      
       ("drivers: perf: Implement perf event mmap support in the SBI backend")
      Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Link: https://lore.kernel.org/r/20231006082010.11963-1-alexghiti@rivosinc.com
      
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      3fec3233
  13. Aug 16, 2023
  14. Jun 20, 2023
  15. Jun 19, 2023
  16. Apr 29, 2023
  17. Mar 01, 2023
  18. Feb 07, 2023
  19. Jan 13, 2023
  20. Oct 27, 2022
  21. Oct 13, 2022
  22. Sep 08, 2022
  23. Aug 11, 2022
  24. Jul 19, 2022
  25. Jul 06, 2022