<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/arch/riscv/kernel, branch linux-6.0.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.0.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.0.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-01-12T11:00:47Z</updated>
<entry>
<title>riscv, kprobes: Stricter c.jr/c.jalr decoding</title>
<updated>2023-01-12T11:00:47Z</updated>
<author>
<name>Björn Töpel</name>
</author>
<published>2023-01-02T16:07:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1ce70a9ef9c63c08b89ab2d1d8428f4d254a30c5'/>
<id>urn:sha1:1ce70a9ef9c63c08b89ab2d1d8428f4d254a30c5</id>
<content type='text'>
commit b2d473a6019ef9a54b0156ecdb2e0398c9fa6a24 upstream.

In the compressed instruction extension, c.jr, c.jalr, c.mv, and c.add
is encoded the following way (each instruction is 16b):

---+-+-----------+-----------+--
100 0 rs1[4:0]!=0       00000 10 : c.jr
100 1 rs1[4:0]!=0       00000 10 : c.jalr
100 0  rd[4:0]!=0 rs2[4:0]!=0 10 : c.mv
100 1  rd[4:0]!=0 rs2[4:0]!=0 10 : c.add

The following logic is used to decode c.jr and c.jalr:

  insn &amp; 0xf007 == 0x8002 =&gt; instruction is an c.jr
  insn &amp; 0xf007 == 0x9002 =&gt; instruction is an c.jalr

When 0xf007 is used to mask the instruction, c.mv can be incorrectly
decoded as c.jr, and c.add as c.jalr.

Correct the decoding by changing the mask from 0xf007 to 0xf07f.

Fixes: c22b0bcb1dd0 ("riscv: Add kprobes supported")
Signed-off-by: Björn Töpel &lt;bjorn@rivosinc.com&gt;
Reviewed-by: Conor Dooley &lt;conor.dooley@microchip.com&gt;
Reviewed-by: Guo Ren &lt;guoren@kernel.org&gt;
Link: https://lore.kernel.org/r/20230102160748.1307289-1-bjorn@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument</title>
<updated>2023-01-07T10:15:57Z</updated>
<author>
<name>Guo Ren</name>
</author>
<published>2022-11-09T06:49:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a1f4700f214259292f961bc1754794c6f2e913bd'/>
<id>urn:sha1:a1f4700f214259292f961bc1754794c6f2e913bd</id>
<content type='text'>
commit 5c3022e4a616d800cf5f4c3a981d7992179e44a1 upstream.

The 'retp' is a pointer to the return address on the stack, so we
must pass the current return address pointer as the 'retp'
argument to ftrace_push_return_trace(). Not parent function's
return address on the stack.

Fixes: b785ec129bd9 ("riscv/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support")
Signed-off-by: Guo Ren &lt;guoren@linux.alibaba.com&gt;
Signed-off-by: Guo Ren &lt;guoren@kernel.org&gt;
Link: https://lore.kernel.org/r/20221109064937.3643993-2-guoren@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>RISC-V: kexec: Fix memory leak of elf header buffer</title>
<updated>2023-01-07T10:15:57Z</updated>
<author>
<name>Li Huafei</name>
</author>
<published>2022-11-04T09:56:58Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=090bfcfc9f14d05154893c67eeaecc56e894fbae'/>
<id>urn:sha1:090bfcfc9f14d05154893c67eeaecc56e894fbae</id>
<content type='text'>
commit cbc32023ddbdf4baa3d9dc513a2184a84080a5a2 upstream.

This is reported by kmemleak detector:

unreferenced object 0xff2000000403d000 (size 4096):
  comm "kexec", pid 146, jiffies 4294900633 (age 64.792s)
  hex dump (first 32 bytes):
    7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  .ELF............
    04 00 f3 00 01 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [&lt;00000000566ca97c&gt;] kmemleak_vmalloc+0x3c/0xbe
    [&lt;00000000979283d8&gt;] __vmalloc_node_range+0x3ac/0x560
    [&lt;00000000b4b3712a&gt;] __vmalloc_node+0x56/0x62
    [&lt;00000000854f75e2&gt;] vzalloc+0x2c/0x34
    [&lt;00000000e9a00db9&gt;] crash_prepare_elf64_headers+0x80/0x30c
    [&lt;0000000067e8bf48&gt;] elf_kexec_load+0x3e8/0x4ec
    [&lt;0000000036548e09&gt;] kexec_image_load_default+0x40/0x4c
    [&lt;0000000079fbe1b4&gt;] sys_kexec_file_load+0x1c4/0x322
    [&lt;0000000040c62c03&gt;] ret_from_syscall+0x0/0x2

In elf_kexec_load(), a buffer is allocated via vzalloc() to store elf
headers.  While it's not freed back to system when kdump kernel is
reloaded or unloaded, or when image-&gt;elf_header is successfully set and
then fails to load kdump kernel for some reason. Fix it by freeing the
buffer in arch_kimage_file_post_load_cleanup().

Fixes: 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Signed-off-by: Li Huafei &lt;lihuafei1@huawei.com&gt;
Reviewed-by: Conor Dooley &lt;conor.dooley@microchip.com&gt;
Link: https://lore.kernel.org/r/20221104095658.141222-2-lihuafei1@huawei.com
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>RISC-V: kexec: Fix memory leak of fdt buffer</title>
<updated>2023-01-07T10:15:56Z</updated>
<author>
<name>Li Huafei</name>
</author>
<published>2022-11-04T09:56:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c66ad198b6497dee8f45d7ed5c03629c4525c7d0'/>
<id>urn:sha1:c66ad198b6497dee8f45d7ed5c03629c4525c7d0</id>
<content type='text'>
commit 96df59b1ae23f5c11698c3c2159aeb2ecd4944a4 upstream.

This is reported by kmemleak detector:

unreferenced object 0xff60000082864000 (size 9588):
  comm "kexec", pid 146, jiffies 4294900634 (age 64.788s)
  hex dump (first 32 bytes):
    d0 0d fe ed 00 00 12 ed 00 00 00 48 00 00 11 40  ...........H...@
    00 00 00 28 00 00 00 11 00 00 00 02 00 00 00 00  ...(............
  backtrace:
    [&lt;00000000f95b17c4&gt;] kmemleak_alloc+0x34/0x3e
    [&lt;00000000b9ec8e3e&gt;] kmalloc_order+0x9c/0xc4
    [&lt;00000000a95cf02e&gt;] kmalloc_order_trace+0x34/0xb6
    [&lt;00000000f01e68b4&gt;] __kmalloc+0x5c2/0x62a
    [&lt;000000002bd497b2&gt;] kvmalloc_node+0x66/0xd6
    [&lt;00000000906542fa&gt;] of_kexec_alloc_and_setup_fdt+0xa6/0x6ea
    [&lt;00000000e1166bde&gt;] elf_kexec_load+0x206/0x4ec
    [&lt;0000000036548e09&gt;] kexec_image_load_default+0x40/0x4c
    [&lt;0000000079fbe1b4&gt;] sys_kexec_file_load+0x1c4/0x322
    [&lt;0000000040c62c03&gt;] ret_from_syscall+0x0/0x2

In elf_kexec_load(), a buffer is allocated via kvmalloc() to store fdt.
While it's not freed back to system when kexec kernel is reloaded or
unloaded.  Then memory leak is caused.  Fix it by introducing riscv
specific function arch_kimage_file_post_load_cleanup(), and freeing the
buffer there.

Fixes: 6261586e0c91 ("RISC-V: Add kexec_file support")
Signed-off-by: Li Huafei &lt;lihuafei1@huawei.com&gt;
Reviewed-by: Conor Dooley &lt;conor.dooley@microchip.com&gt;
Reviewed-by: Liao Chang &lt;liaochang1@huawei.com&gt;
Link: https://lore.kernel.org/r/20221104095658.141222-1-lihuafei1@huawei.com
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>RISC-V: Align the shadow stack</title>
<updated>2022-12-31T12:26:23Z</updated>
<author>
<name>Palmer Dabbelt</name>
</author>
<published>2022-11-30T02:35:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7a270e44c9a9bd046742451e89a2abd93d96a79b'/>
<id>urn:sha1:7a270e44c9a9bd046742451e89a2abd93d96a79b</id>
<content type='text'>
[ Upstream commit b003b3b77d65133a0011ae3b7b255347438c12f6 ]

The standard RISC-V ABIs all require 16-byte stack alignment.  We're
only calling that one function on the shadow stack so I doubt it'd
result in a real issue, but might as well keep this lined up.

Fixes: 31da94c25aea ("riscv: add VMAP_STACK overflow detection")
Reviewed-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
Link: https://lore.kernel.org/r/20221130023515.20217-1-palmer@rivosinc.com
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>RISC-V: Fix unannoted hardirqs-on in return to userspace slow-path</title>
<updated>2022-12-31T12:26:23Z</updated>
<author>
<name>Andrew Bresticker</name>
</author>
<published>2022-11-11T22:31:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9dc86d1a316d2cbb935129d2a8d0c95d6f5c2ae5'/>
<id>urn:sha1:9dc86d1a316d2cbb935129d2a8d0c95d6f5c2ae5</id>
<content type='text'>
[ Upstream commit b0f4c74eadbf69a3298f38566bfaa2e202541f2f ]

The return to userspace path in entry.S may enable interrupts without the
corresponding lockdep annotation, producing a splat[0] when DEBUG_LOCKDEP
is enabled. Simply calling __trace_hardirqs_on() here gets a bit messy
due to the use of RA to point back to ret_from_exception, so just move
the whole slow-path loop into C. It's more readable and it lets us use
local_irq_{enable,disable}(), avoiding the need for manual annotations
altogether.

[0]:
  ------------[ cut here ]------------
  DEBUG_LOCKS_WARN_ON(!lockdep_hardirqs_enabled())
  WARNING: CPU: 2 PID: 1 at kernel/locking/lockdep.c:5512 check_flags+0x10a/0x1e0
  Modules linked in:
  CPU: 2 PID: 1 Comm: init Not tainted 6.1.0-rc4-00160-gb56b6e2b4f31 #53
  Hardware name: riscv-virtio,qemu (DT)
  epc : check_flags+0x10a/0x1e0
  ra : check_flags+0x10a/0x1e0
  &lt;snip&gt;
   status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
  [&lt;ffffffff808edb90&gt;] lock_is_held_type+0x78/0x14e
  [&lt;ffffffff8003dae2&gt;] __might_resched+0x26/0x22c
  [&lt;ffffffff8003dd24&gt;] __might_sleep+0x3c/0x66
  [&lt;ffffffff80022c60&gt;] get_signal+0x9e/0xa70
  [&lt;ffffffff800054a2&gt;] do_notify_resume+0x6e/0x422
  [&lt;ffffffff80003c68&gt;] ret_from_exception+0x0/0x10
  irq event stamp: 44512
  hardirqs last  enabled at (44511): [&lt;ffffffff808f901c&gt;] _raw_spin_unlock_irqrestore+0x54/0x62
  hardirqs last disabled at (44512): [&lt;ffffffff80008200&gt;] __trace_hardirqs_off+0xc/0x14
  softirqs last  enabled at (44472): [&lt;ffffffff808f9fbe&gt;] __do_softirq+0x3de/0x51e
  softirqs last disabled at (44467): [&lt;ffffffff80017760&gt;] irq_exit+0xd6/0x104
  ---[ end trace 0000000000000000 ]---
  possible reason: unannotated irqs-on.

Signed-off-by: Andrew Bresticker &lt;abrestic@rivosinc.com&gt;
Fixes: 3c4697982982 ("riscv: Enable LOCKDEP_SUPPORT &amp; fixup TRACE_IRQFLAGS_SUPPORT")
Link: https://lore.kernel.org/r/20221111223108.1976562-1-abrestic@rivosinc.com
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>riscv: kexec: Fixup irq controller broken in kexec crash path</title>
<updated>2022-12-08T10:30:21Z</updated>
<author>
<name>Guo Ren</name>
</author>
<published>2022-10-20T14:16:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7594956fec8902dfc18150bf1dca0940cd4ad025'/>
<id>urn:sha1:7594956fec8902dfc18150bf1dca0940cd4ad025</id>
<content type='text'>
[ Upstream commit b17d19a5314a37f7197afd1a0200affd21a7227d ]

If a crash happens on cpu3 and all interrupts are binding on cpu0, the
bad irq routing will cause a crash kernel which can't receive any irq.
Because crash kernel won't clean up all harts' PLIC enable bits in
enable registers. This patch is similar to 9141a003a491 ("ARM: 7316/1:
kexec: EOI active and mask all interrupts in kexec crash path") and
78fd584cdec0 ("arm64: kdump: implement machine_crash_shutdown()"), and
PowerPC also has the same mechanism.

Fixes: fba8a8674f68 ("RISC-V: Add kexec support")
Signed-off-by: Guo Ren &lt;guoren@linux.alibaba.com&gt;
Signed-off-by: Guo Ren &lt;guoren@kernel.org&gt;
Reviewed-by: Xianting Tian &lt;xianting.tian@linux.alibaba.com&gt;
Cc: Nick Kossifidis &lt;mick@ics.forth.gr&gt;
Cc: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Link: https://lore.kernel.org/r/20221020141603.2856206-2-guoren@kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>riscv: fix race when vmap stack overflow</title>
<updated>2022-12-08T10:30:20Z</updated>
<author>
<name>Jisheng Zhang</name>
</author>
<published>2022-10-30T12:45:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=879fabc5a95401d9bce357e4b1d24ae4a360a81f'/>
<id>urn:sha1:879fabc5a95401d9bce357e4b1d24ae4a360a81f</id>
<content type='text'>
[ Upstream commit 7e1864332fbc1b993659eab7974da9fe8bf8c128 ]

Currently, when detecting vmap stack overflow, riscv firstly switches
to the so called shadow stack, then use this shadow stack to call the
get_overflow_stack() to get the overflow stack. However, there's
a race here if two or more harts use the same shadow stack at the same
time.

To solve this race, we introduce spin_shadow_stack atomic var, which
will be swap between its own address and 0 in atomic way, when the
var is set, it means the shadow_stack is being used; when the var
is cleared, it means the shadow_stack isn't being used.

Fixes: 31da94c25aea ("riscv: add VMAP_STACK overflow detection")
Signed-off-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
Suggested-by: Guo Ren &lt;guoren@kernel.org&gt;
Reviewed-by: Guo Ren &lt;guoren@kernel.org&gt;
Link: https://lore.kernel.org/r/20221030124517.2370-1-jszhang@kernel.org
[Palmer: Add AQ to the swap, and also some comments.]
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>riscv: mm: Proper page permissions after initmem free</title>
<updated>2022-12-08T10:30:18Z</updated>
<author>
<name>Björn Töpel</name>
</author>
<published>2022-11-15T09:06:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3d36a150f2d56e33f5ed39d610e28bf641987c9d'/>
<id>urn:sha1:3d36a150f2d56e33f5ed39d610e28bf641987c9d</id>
<content type='text'>
commit 6fdd5d2f8c2f54b7fad4ff4df2a19542aeaf6102 upstream.

64-bit RISC-V kernels have the kernel image mapped separately to alias
the linear map. The linear map and the kernel image map are documented
as "direct mapping" and "kernel" respectively in [1].

At image load time, the linear map corresponding to the kernel image
is set to PAGE_READ permission, and the kernel image map is set to
PAGE_READ|PAGE_EXEC.

When the initmem is freed, the pages in the linear map should be
restored to PAGE_READ|PAGE_WRITE, whereas the corresponding pages in
the kernel image map should be restored to PAGE_READ, by removing the
PAGE_EXEC permission.

This is not the case. For 64-bit kernels, only the linear map is
restored to its proper page permissions at initmem free, and not the
kernel image map.

In practise this results in that the kernel can potentially jump to
dead __init code, and start executing invalid instructions, without
getting an exception.

Restore the freed initmem properly, by setting both the kernel image
map to the correct permissions.

[1] Documentation/riscv/vm-layout.rst

Fixes: e5c35fa04019 ("riscv: Map the kernel with correct permissions the first time")
Signed-off-by: Björn Töpel &lt;bjorn@rivosinc.com&gt;
Reviewed-by: Alexandre Ghiti &lt;alex@ghiti.fr&gt;
Tested-by: Alexandre Ghiti &lt;alex@ghiti.fr&gt;
Link: https://lore.kernel.org/r/20221115090641.258476-1-bjorn@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>riscv: vdso: fix section overlapping under some conditions</title>
<updated>2022-12-08T10:30:18Z</updated>
<author>
<name>Jisheng Zhang</name>
</author>
<published>2022-11-02T17:02:54Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=deb460c36d83e85636e0f9e9a9e60957a2cea603'/>
<id>urn:sha1:deb460c36d83e85636e0f9e9a9e60957a2cea603</id>
<content type='text'>
commit 74f6bb55c834da6d4bac24f44868202743189b2b upstream.

lkp reported a build error, I tried the config and can reproduce
build error as below:

  VDSOLD  arch/riscv/kernel/vdso/vdso.so.dbg
ld.lld: error: section .note file range overlaps with .text
&gt;&gt;&gt; .note range is [0x7C8, 0x803]
&gt;&gt;&gt; .text range is [0x800, 0x1993]

ld.lld: error: section .text file range overlaps with .dynamic
&gt;&gt;&gt; .text range is [0x800, 0x1993]
&gt;&gt;&gt; .dynamic range is [0x808, 0x937]

ld.lld: error: section .note virtual address range overlaps with .text
&gt;&gt;&gt; .note range is [0x7C8, 0x803]
&gt;&gt;&gt; .text range is [0x800, 0x1993]

Fix it by setting DISABLE_BRANCH_PROFILING which will disable branch
tracing for vdso, thus avoid useless _ftrace_annotated_branch section
and _ftrace_branch section. Although we can also fix it by removing
the hardcoded .text begin address, but I think that's another story
and should be put into another patch.

Link: https://lore.kernel.org/lkml/202210122123.Cc4FPShJ-lkp@intel.com/#r
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
Link: https://lore.kernel.org/r/20221102170254.1925-1-jszhang@kernel.org
Fixes: ad5d1122b82f ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
