<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/arch/riscv/lib, branch v5.15.208</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v5.15.208</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v5.15.208'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-08-26T12:23:36+00:00</updated>
<entry>
<title>riscv: uaccess: Return the number of bytes effectively not copied</title>
<updated>2023-08-26T12:23:36+00:00</updated>
<author>
<name>Alexandre Ghiti</name>
<email>alexghiti@rivosinc.com</email>
</author>
<published>2023-08-11T15:06:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e9b8ee715dbcaa1da94d1c0df2c52d587f46dec2'/>
<id>urn:sha1:e9b8ee715dbcaa1da94d1c0df2c52d587f46dec2</id>
<content type='text'>
[ Upstream commit 4b05b993900dd3eba0fc83ef5c5ddc7d65d786c6 ]

It was reported that the riscv kernel hangs while executing the test
in [1].

Indeed, the test hangs when trying to write a buffer to a file. The
problem is that the riscv implementation of raw_copy_from_user() does not
return the correct number of bytes not written when an exception happens
and is fixed up, instead it always returns the initial size to copy,
even if some bytes were actually copied.

generic_perform_write() pre-faults the user pages and bails out if nothing
can be written, otherwise it will access the userspace buffer: here the
riscv implementation keeps returning it was not able to copy any byte
though the pre-faulting indicates otherwise. So generic_perform_write()
keeps retrying to access the user memory and ends up in an infinite
loop.

Note that before the commit mentioned in [1] that introduced this
regression, it worked because generic_perform_write() would bail out if
only one byte could not be written.

So fix this by returning the number of bytes effectively not written in
__asm_copy_[to|from]_user() and __clear_user(), as it is expected.

Link: https://lore.kernel.org/linux-riscv/20230309151841.bomov6hq3ybyp42a@debian/ [1]
Fixes: ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")
Reported-by: Bo YU &lt;tsu.yubo@gmail.com&gt;
Closes: https://lore.kernel.org/linux-riscv/20230309151841.bomov6hq3ybyp42a@debian/#t
Reported-by: Aurelien Jarno &lt;aurelien@aurel32.net&gt;
Closes: https://lore.kernel.org/linux-riscv/ZNOnCakhwIeue3yr@aurel32.net/
Signed-off-by: Alexandre Ghiti &lt;alexghiti@rivosinc.com&gt;
Reviewed-by: Björn Töpel &lt;bjorn@rivosinc.com&gt;
Tested-by: Aurelien Jarno &lt;aurelien@aurel32.net&gt;
Reviewed-by: Aurelien Jarno &lt;aurelien@aurel32.net&gt;
Link: https://lore.kernel.org/r/20230811150604.1621784-1-alexghiti@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: lib: uaccess: fix CSR_STATUS SR_SUM bit</title>
<updated>2022-08-31T15:16:36+00:00</updated>
<author>
<name>Chen Lifu</name>
<email>chenlifu@huawei.com</email>
</author>
<published>2022-06-15T01:47:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=044f8ff30e62a8092a0735aff6bde1ddccde5b0e'/>
<id>urn:sha1:044f8ff30e62a8092a0735aff6bde1ddccde5b0e</id>
<content type='text'>
[ Upstream commit c08b4848f596fd95543197463b5162bd7bab2442 ]

Since commit 5d8544e2d007 ("RISC-V: Generic library routines and assembly")
and commit ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code"),
if __clear_user and __copy_user return from an fixup branch,
CSR_STATUS SR_SUM bit will be set, it is a vulnerability, so that
S-mode memory accesses to pages that are accessible by U-mode will success.
Disable S-mode access to U-mode memory should clear SR_SUM bit.

Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly")
Fixes: ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")
Signed-off-by: Chen Lifu &lt;chenlifu@huawei.com&gt;
Reviewed-by: Ben Dooks &lt;ben.dooks@codethink.co.uk&gt;
Link: https://lore.kernel.org/r/20220615014714.1650349-1-chenlifu@huawei.com
Cc: stable@vger.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: lib: uaccess: fold fixups into body</title>
<updated>2022-08-31T15:16:36+00:00</updated>
<author>
<name>Jisheng Zhang</name>
<email>jszhang@kernel.org</email>
</author>
<published>2021-11-18T11:25:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=093cb743dcadc83d3923db88a9bad93f3d8bb706'/>
<id>urn:sha1:093cb743dcadc83d3923db88a9bad93f3d8bb706</id>
<content type='text'>
[ Upstream commit 9d504f9aa5c1b76673018da9503e76b351a24b8c ]

uaccess functions such __asm_copy_to_user(),  __arch_copy_from_user()
and __clear_user() place their exception fixups in the `.fixup` section
without any clear association with themselves. If we backtrace the
fixup code, it will be symbolized as an offset from the nearest prior
symbol.

Similar as arm64 does, we must move fixups into the body of the
functions themselves, after the usual fast-path returns.

Signed-off-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
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: Fixed misaligned memory access. Fixed pointer comparison.</title>
<updated>2022-04-13T18:59:09+00:00</updated>
<author>
<name>Michael T. Kloos</name>
<email>michael@michaelkloos.com</email>
</author>
<published>2022-03-08T01:03:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d804db3dafd11a2973d0d3ce38ef844d8c10a22a'/>
<id>urn:sha1:d804db3dafd11a2973d0d3ce38ef844d8c10a22a</id>
<content type='text'>
[ Upstream commit 9d1f0ec9f71780e69ceb9d91697600c747d6e02e ]

Rewrote the RISC-V memmove() assembly implementation.  The
previous implementation did not check memory alignment and it
compared 2 pointers with a signed comparison.  The misaligned
memory access would cause the kernel to crash on systems that
did not emulate it in firmware and did not support it in hardware.
Firmware emulation is slow and may not exist.  The RISC-V spec
does not guarantee that support for misaligned memory accesses
will exist.  It should not be depended on.

This patch now checks for XLEN granularity of co-alignment between
the pointers.  Failing that, copying is done by loading from the 2
contiguous and naturally aligned XLEN memory locations containing
the overlapping XLEN sized data to be copied.  The data is shifted
into the correct place and binary or'ed together on each
iteration.  The result is then stored into the corresponding
naturally aligned XLEN sized location in the destination.  For
unaligned data at the terminations of the regions to be copied
or for copies less than (2 * XLEN) in size, byte copy is used.

This patch also now uses unsigned comparison for the pointers and
migrates to the newer assembler annotations from the now deprecated
ones.

Signed-off-by: Michael T. Kloos &lt;michael@michaelkloos.com&gt;
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: __asm_copy_to-from_user: Fix: Typos in comments</title>
<updated>2021-07-24T00:49:12+00:00</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:53:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ea196c548c0ac407afd31d142712b6da8bd00244'/>
<id>urn:sha1:ea196c548c0ac407afd31d142712b6da8bd00244</id>
<content type='text'>
Fixing typos and grammar mistakes and using more intuitive label
name.

Signed-off-by: Akira Tsukamoto &lt;akira.tsukamoto@gmail.com&gt;
Fixes: ca6eaaa210de ("riscv: __asm_copy_to-from_user: Optimize unaligned memory access and pipeline stall")
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
<entry>
<title>riscv: __asm_copy_to-from_user: Remove unnecessary size check</title>
<updated>2021-07-24T00:49:07+00:00</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:52:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d4b3e0105e3c2411af666a50b1bf2d25656a5e83'/>
<id>urn:sha1:d4b3e0105e3c2411af666a50b1bf2d25656a5e83</id>
<content type='text'>
Clean up:

The size of 0 will be evaluated in the next step. Not
required here.

Signed-off-by: Akira Tsukamoto &lt;akira.tsukamoto@gmail.com&gt;
Fixes: ca6eaaa210de ("riscv: __asm_copy_to-from_user: Optimize unaligned memory access and pipeline stall")
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
<entry>
<title>riscv: __asm_copy_to-from_user: Fix: fail on RV32</title>
<updated>2021-07-24T00:49:01+00:00</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:51:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=22b5f16ffeff38938ad7420a2bfa3c281c36fd17'/>
<id>urn:sha1:22b5f16ffeff38938ad7420a2bfa3c281c36fd17</id>
<content type='text'>
Had a bug when converting bytes to bits when the cpu was rv32.

The a3 contains the number of bytes and multiple of 8
would be the bits. The LGREG is holding 2 for RV32 and 3 for
RV32, so to achieve multiple of 8 it must always be constant 3.
The 2 was mistakenly used for rv32.

Signed-off-by: Akira Tsukamoto &lt;akira.tsukamoto@gmail.com&gt;
Fixes: ca6eaaa210de ("riscv: __asm_copy_to-from_user: Optimize unaligned memory access and pipeline stall")
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
<entry>
<title>riscv: __asm_copy_to-from_user: Fix: overrun copy</title>
<updated>2021-07-24T00:48:52+00:00</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:50:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6010d300f9f7e16d1bf327b4730bcd0c0886d9e6'/>
<id>urn:sha1:6010d300f9f7e16d1bf327b4730bcd0c0886d9e6</id>
<content type='text'>
There were two causes for the overrun memory access.

The threshold size was too small.
The aligning dst require one SZREG and unrolling word copy requires
8*SZREG, total have to be at least 9*SZREG.

Inside the unrolling copy, the subtracting -(8*SZREG-1) would make
iteration happening one extra loop. Proper value is -(8*SZREG).

Signed-off-by: Akira Tsukamoto &lt;akira.tsukamoto@gmail.com&gt;
Fixes: ca6eaaa210de ("riscv: __asm_copy_to-from_user: Optimize unaligned memory access and pipeline stall")
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
<entry>
<title>riscv: __asm_copy_to-from_user: Optimize unaligned memory access and pipeline stall</title>
<updated>2021-07-06T22:09:48+00:00</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-06-23T12:40:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ca6eaaa210deec0e41cbfc380bf89cf079203569'/>
<id>urn:sha1:ca6eaaa210deec0e41cbfc380bf89cf079203569</id>
<content type='text'>
This patch will reduce cpu usage dramatically in kernel space especially
for application which use sys-call with large buffer size, such as
network applications. The main reason behind this is that every
unaligned memory access will raise exceptions and switch between s-mode
and m-mode causing large overhead.

First copy in bytes until reaches the first word aligned boundary in
destination memory address. This is the preparation before the bulk
aligned word copy.

The destination address is aligned now, but oftentimes the source
address is not in an aligned boundary. To reduce the unaligned memory
access, it reads the data from source in aligned boundaries, which will
cause the data to have an offset, and then combines the data in the next
iteration by fixing offset with shifting before writing to destination.
The majority of the improving copy speed comes from this shift copy.

In the lucky situation that the both source and destination address are
on the aligned boundary, perform load and store with register size to
copy the data. Without the unrolling, it will reduce the speed since the
next store instruction for the same register using from the load will
stall the pipeline.

At last, copying the remainder in one byte at a time.

Signed-off-by: Akira Tsukamoto &lt;akira.tsukamoto@gmail.com&gt;
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
<entry>
<title>riscv: Add support for function error injection</title>
<updated>2021-01-14T23:09:09+00:00</updated>
<author>
<name>Guo Ren</name>
<email>guoren@linux.alibaba.com</email>
</author>
<published>2020-12-17T16:01:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ee55ff803b383e03d0855661d3416aa1763e54f9'/>
<id>urn:sha1:ee55ff803b383e03d0855661d3416aa1763e54f9</id>
<content type='text'>
Inspired by the commit 42d038c4fb00 ("arm64: Add support for function
error injection"), this patch supports function error injection for
riscv.

This patch mainly support two functions: one is regs_set_return_value()
which is used to overwrite the return value; the another function is
override_function_with_return() which is to override the probed
function returning and jump to its caller.

Test log:
 cd /sys/kernel/debug/fail_function
 echo sys_clone &gt; inject
 echo 100 &gt; probability
 echo 1 &gt; interval
 ls /
[  313.176875] FAULT_INJECTION: forcing a failure.
[  313.176875] name fail_function, interval 1, probability 100, space 0, times 1
[  313.184357] CPU: 0 PID: 87 Comm: sh Not tainted 5.8.0-rc5-00007-g6a758cc #117
[  313.187616] Call Trace:
[  313.189100] [&lt;ffffffe0002036b6&gt;] walk_stackframe+0x0/0xc2
[  313.191626] [&lt;ffffffe00020395c&gt;] show_stack+0x40/0x4c
[  313.193927] [&lt;ffffffe000556c60&gt;] dump_stack+0x7c/0x96
[  313.194795] [&lt;ffffffe0005522e8&gt;] should_fail+0x140/0x142
[  313.195923] [&lt;ffffffe000299ffc&gt;] fei_kprobe_handler+0x2c/0x5a
[  313.197687] [&lt;ffffffe0009e2ec4&gt;] kprobe_breakpoint_handler+0xb4/0x18a
[  313.200054] [&lt;ffffffe00020357e&gt;] do_trap_break+0x36/0xca
[  313.202147] [&lt;ffffffe000201bca&gt;] ret_from_exception+0x0/0xc
[  313.204556] [&lt;ffffffe000201bbc&gt;] ret_from_syscall+0x0/0x2
-sh: can't fork: Invalid argument

Signed-off-by: Guo Ren &lt;guoren@linux.alibaba.com&gt;
Reviewed-by: Masami Hiramatsu &lt;mhiramat@kernel.org&gt;
Cc: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
Cc: Paul Walmsley &lt;paul.walmsley@sifive.com&gt;
Signed-off-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt;
</content>
</entry>
</feed>
