1. 09 Nov, 2023 6 commits
    • Palmer Dabbelt's avatar
      Merge patch "drivers: perf: Do not broadcast to other cpus when starting a counter" · 68444b93
      Palmer Dabbelt authored
      This is really just a single patch, but since the offending fix hasn't
      yet made it to my for-next I'm merging it here.
      Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      68444b93
    • 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.comSigned-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
    • Palmer Dabbelt's avatar
      Merge patch series "Linux RISC-V AIA Preparatory Series" · f9a619eb
      Palmer Dabbelt authored
      These two  ended up in the AIA series, but they're really independent
      improvements.
      
      * b4-shazam-merge:
        of: property: Add fw_devlink support for msi-parent
        RISC-V: Don't fail in riscv_of_parent_hartid() for disabled HARTs
      
      Link: https://lore.kernel.org/r/20231027154254.355853-1-apatel@ventanamicro.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      f9a619eb
    • Anup Patel's avatar
      of: property: Add fw_devlink support for msi-parent · c5e4ce9d
      Anup Patel authored
      This allows fw_devlink to create device links between consumers of
      a MSI and the supplier of the MSI.
      Signed-off-by: default avatarAnup Patel <apatel@ventanamicro.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Reviewed-by: default avatarSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20231027154254.355853-3-apatel@ventanamicro.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      c5e4ce9d
    • Anup Patel's avatar
      RISC-V: Don't fail in riscv_of_parent_hartid() for disabled HARTs · c4676f8d
      Anup Patel authored
      The riscv_of_processor_hartid() used by riscv_of_parent_hartid() fails
      for HARTs disabled in the DT. This results in the following warning
      thrown by the RISC-V INTC driver for the E-core on SiFive boards:
      
      [    0.000000] riscv-intc: unable to find hart id for /cpus/cpu@0/interrupt-controller
      
      The riscv_of_parent_hartid() is only expected to read the hartid
      from the DT so we directly call of_get_cpu_hwid() instead of calling
      riscv_of_processor_hartid().
      
      Fixes: ad635e72 ("riscv: cpu: Add 64bit hartid support on RV64")
      Signed-off-by: default avatarAnup Patel <apatel@ventanamicro.com>
      Reviewed-by: default avatarAtish Patra <atishp@rivosinc.com>
      Link: https://lore.kernel.org/r/20231027154254.355853-2-apatel@ventanamicro.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      c4676f8d
  2. 08 Nov, 2023 3 commits
    • Palmer Dabbelt's avatar
      Merge patch series "riscv: Fix set_memory_XX() and set_direct_map_XX()" · 05942f78
      Palmer Dabbelt authored
      Alexandre Ghiti <alexghiti@rivosinc.com> says:
      
      Those 2 patches fix the set_memory_XX() and set_direct_map_XX() APIs, which
      in turn fix STRICT_KERNEL_RWX and memfd_secret(). Those were broken since the
      permission changes were not applied to the linear mapping because the linear
      mapping is mapped using hugepages and walk_page_range_novma() does not split
      such mappings.
      
      To fix that, patch 1 disables PGD mappings in the linear mapping as it is
      hard to propagate changes at this level in *all* the page tables, this has the
      downside of disabling PMD mapping for sv32 and PUD (1GB) mapping for sv39 in
      the linear mapping (for specific kernels, we could add a Kconfig to enable
      ARCH_HAS_SET_DIRECT_MAP and STRICT_KERNEL_RWX if needed, I'm pretty sure we'll
      discuss that).
      
      patch 2 implements the split of the huge linear mappings so that
      walk_page_range_novma() can properly apply the permissions. The whole split is
      protected with mmap_sem in write mode, but I'm wondering if that's enough,
      any opinion on that is appreciated.
      
      * b4-shazam-merge:
        riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings
        riscv: Don't use PGD entries for the linear mapping
      
      Link: https://lore.kernel.org/r/20231108075930.7157-1-alexghiti@rivosinc.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      05942f78
    • Alexandre Ghiti's avatar
      riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings · 311cd2f6
      Alexandre Ghiti authored
      When STRICT_KERNEL_RWX is set, any change of permissions on any kernel
      mapping (vmalloc/modules/kernel text...etc) should be applied on its
      linear mapping alias. The problem is that the riscv kernel uses huge
      mappings for the linear mapping and walk_page_range_novma() does not
      split those huge mappings.
      
      So this patchset implements such split in order to apply fine-grained
      permissions on the linear mapping.
      
      Below is the difference before and after (the first PUD mapping is split
      into PTE/PMD mappings):
      
      Before:
      
      ---[ Linear mapping ]---
      0xffffaf8000080000-0xffffaf8000200000    0x0000000080080000      1536K PTE     D A G . . W R V
      0xffffaf8000200000-0xffffaf8077c00000    0x0000000080200000      1914M PMD     D A G . . W R V
      0xffffaf8077c00000-0xffffaf8078800000    0x00000000f7c00000        12M PMD     D A G . . . R V
      0xffffaf8078800000-0xffffaf8078c00000    0x00000000f8800000         4M PMD     D A G . . W R V
      0xffffaf8078c00000-0xffffaf8079200000    0x00000000f8c00000         6M PMD     D A G . . . R V
      0xffffaf8079200000-0xffffaf807e600000    0x00000000f9200000        84M PMD     D A G . . W R V
      0xffffaf807e600000-0xffffaf807e716000    0x00000000fe600000      1112K PTE     D A G . . W R V
      0xffffaf807e717000-0xffffaf807e71a000    0x00000000fe717000        12K PTE     D A G . . W R V
      0xffffaf807e71d000-0xffffaf807e71e000    0x00000000fe71d000         4K PTE     D A G . . W R V
      0xffffaf807e722000-0xffffaf807e800000    0x00000000fe722000       888K PTE     D A G . . W R V
      0xffffaf807e800000-0xffffaf807fe00000    0x00000000fe800000        22M PMD     D A G . . W R V
      0xffffaf807fe00000-0xffffaf807ff54000    0x00000000ffe00000      1360K PTE     D A G . . W R V
      0xffffaf807ff55000-0xffffaf8080000000    0x00000000fff55000       684K PTE     D A G . . W R V
      0xffffaf8080000000-0xffffaf8400000000    0x0000000100000000        14G PUD     D A G . . W R V
      
      After:
      
      ---[ Linear mapping ]---
      0xffffaf8000080000-0xffffaf8000200000    0x0000000080080000      1536K PTE     D A G . . W R V
      0xffffaf8000200000-0xffffaf8077c00000    0x0000000080200000      1914M PMD     D A G . . W R V
      0xffffaf8077c00000-0xffffaf8078800000    0x00000000f7c00000        12M PMD     D A G . . . R V
      0xffffaf8078800000-0xffffaf8078a00000    0x00000000f8800000         2M PMD     D A G . . W R V
      0xffffaf8078a00000-0xffffaf8078c00000    0x00000000f8a00000         2M PTE     D A G . . W R V
      0xffffaf8078c00000-0xffffaf8079200000    0x00000000f8c00000         6M PMD     D A G . . . R V
      0xffffaf8079200000-0xffffaf807e600000    0x00000000f9200000        84M PMD     D A G . . W R V
      0xffffaf807e600000-0xffffaf807e716000    0x00000000fe600000      1112K PTE     D A G . . W R V
      0xffffaf807e717000-0xffffaf807e71a000    0x00000000fe717000        12K PTE     D A G . . W R V
      0xffffaf807e71d000-0xffffaf807e71e000    0x00000000fe71d000         4K PTE     D A G . . W R V
      0xffffaf807e722000-0xffffaf807e800000    0x00000000fe722000       888K PTE     D A G . . W R V
      0xffffaf807e800000-0xffffaf807fe00000    0x00000000fe800000        22M PMD     D A G . . W R V
      0xffffaf807fe00000-0xffffaf807ff54000    0x00000000ffe00000      1360K PTE     D A G . . W R V
      0xffffaf807ff55000-0xffffaf8080000000    0x00000000fff55000       684K PTE     D A G . . W R V
      0xffffaf8080000000-0xffffaf8080800000    0x0000000100000000         8M PMD     D A G . . W R V
      0xffffaf8080800000-0xffffaf8080af6000    0x0000000100800000      3032K PTE     D A G . . W R V
      0xffffaf8080af6000-0xffffaf8080af8000    0x0000000100af6000         8K PTE     D A G . X . R V
      0xffffaf8080af8000-0xffffaf8080c00000    0x0000000100af8000      1056K PTE     D A G . . W R V
      0xffffaf8080c00000-0xffffaf8081a00000    0x0000000100c00000        14M PMD     D A G . . W R V
      0xffffaf8081a00000-0xffffaf8081a40000    0x0000000101a00000       256K PTE     D A G . . W R V
      0xffffaf8081a40000-0xffffaf8081a44000    0x0000000101a40000        16K PTE     D A G . X . R V
      0xffffaf8081a44000-0xffffaf8081a52000    0x0000000101a44000        56K PTE     D A G . . W R V
      0xffffaf8081a52000-0xffffaf8081a54000    0x0000000101a52000         8K PTE     D A G . X . R V
      ...
      0xffffaf809e800000-0xffffaf80c0000000    0x000000011e800000       536M PMD     D A G . . W R V
      0xffffaf80c0000000-0xffffaf8400000000    0x0000000140000000        13G PUD     D A G . . W R V
      
      Note that this also fixes memfd_secret() syscall which uses
      set_direct_map_invalid_noflush() and set_direct_map_default_noflush() to
      remove the pages from the linear mapping. Below is the kernel page table
      while a memfd_secret() syscall is running, you can see all the !valid
      page table entries in the linear mapping:
      
      ...
      0xffffaf8082240000-0xffffaf8082241000    0x0000000102240000         4K PTE     D A G . . W R .
      0xffffaf8082241000-0xffffaf8082250000    0x0000000102241000        60K PTE     D A G . . W R V
      0xffffaf8082250000-0xffffaf8082252000    0x0000000102250000         8K PTE     D A G . . W R .
      0xffffaf8082252000-0xffffaf8082256000    0x0000000102252000        16K PTE     D A G . . W R V
      0xffffaf8082256000-0xffffaf8082257000    0x0000000102256000         4K PTE     D A G . . W R .
      0xffffaf8082257000-0xffffaf8082258000    0x0000000102257000         4K PTE     D A G . . W R V
      0xffffaf8082258000-0xffffaf8082259000    0x0000000102258000         4K PTE     D A G . . W R .
      0xffffaf8082259000-0xffffaf808225a000    0x0000000102259000         4K PTE     D A G . . W R V
      0xffffaf808225a000-0xffffaf808225c000    0x000000010225a000         8K PTE     D A G . . W R .
      0xffffaf808225c000-0xffffaf8082266000    0x000000010225c000        40K PTE     D A G . . W R V
      0xffffaf8082266000-0xffffaf8082268000    0x0000000102266000         8K PTE     D A G . . W R .
      0xffffaf8082268000-0xffffaf8082284000    0x0000000102268000       112K PTE     D A G . . W R V
      0xffffaf8082284000-0xffffaf8082288000    0x0000000102284000        16K PTE     D A G . . W R .
      0xffffaf8082288000-0xffffaf808229c000    0x0000000102288000        80K PTE     D A G . . W R V
      0xffffaf808229c000-0xffffaf80822a0000    0x000000010229c000        16K PTE     D A G . . W R .
      0xffffaf80822a0000-0xffffaf80822a5000    0x00000001022a0000        20K PTE     D A G . . W R V
      0xffffaf80822a5000-0xffffaf80822a6000    0x00000001022a5000         4K PTE     D A G . . . R V
      0xffffaf80822a6000-0xffffaf80822ab000    0x00000001022a6000        20K PTE     D A G . . W R V
      ...
      
      And when the memfd_secret() fd is released, the linear mapping is
      correctly reset:
      
      ...
      0xffffaf8082240000-0xffffaf80822a5000    0x0000000102240000       404K PTE     D A G . . W R V
      0xffffaf80822a5000-0xffffaf80822a6000    0x00000001022a5000         4K PTE     D A G . . . R V
      0xffffaf80822a6000-0xffffaf80822af000    0x00000001022a6000        36K PTE     D A G . . W R V
      ...
      Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Link: https://lore.kernel.org/r/20231108075930.7157-3-alexghiti@rivosinc.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      311cd2f6
    • Alexandre Ghiti's avatar
      riscv: Don't use PGD entries for the linear mapping · 629db01c
      Alexandre Ghiti authored
      Propagating changes at this level is cumbersome as we need to go through
      all the page tables when that happens (either when changing the
      permissions or when splitting the mapping).
      
      Note that this prevents the use of 4MB mapping for sv32 and 1GB mapping for
      sv39 in the linear mapping.
      Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
      Link: https://lore.kernel.org/r/20231108075930.7157-2-alexghiti@rivosinc.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
      629db01c
  3. 07 Nov, 2023 15 commits
  4. 06 Nov, 2023 9 commits
  5. 05 Nov, 2023 7 commits