<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-dev/arch/riscv/lib, branch master</title>
<subtitle>Linux kernel development work - see feature branches</subtitle>
<id>https://git.zx2c4.com/linux-dev/atom/arch/riscv/lib?h=master</id>
<link rel='self' href='https://git.zx2c4.com/linux-dev/atom/arch/riscv/lib?h=master'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/'/>
<updated>2022-08-10T21:06:31Z</updated>
<entry>
<title>riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit</title>
<updated>2022-08-10T21:06:31Z</updated>
<author>
<name>Chen Lifu</name>
<email>chenlifu@huawei.com</email>
</author>
<published>2022-06-15T01:47:14Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=c08b4848f596fd95543197463b5162bd7bab2442'/>
<id>urn:sha1:c08b4848f596fd95543197463b5162bd7bab2442</id>
<content type='text'>
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;
</content>
</entry>
<entry>
<title>riscv: Fixed misaligned memory access. Fixed pointer comparison.</title>
<updated>2022-03-10T18:24:04Z</updated>
<author>
<name>Michael T. Kloos</name>
<email>michael@michaelkloos.com</email>
</author>
<published>2022-03-08T01:03:21Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=9d1f0ec9f71780e69ceb9d91697600c747d6e02e'/>
<id>urn:sha1:9d1f0ec9f71780e69ceb9d91697600c747d6e02e</id>
<content type='text'>
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;
</content>
</entry>
<entry>
<title>riscv: extable: consolidate definitions</title>
<updated>2022-01-06T01:52:47Z</updated>
<author>
<name>Jisheng Zhang</name>
<email>jszhang@kernel.org</email>
</author>
<published>2021-11-18T11:25:45Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=6dd10d9166a0c06260e0ac6b1fac454117c8024a'/>
<id>urn:sha1:6dd10d9166a0c06260e0ac6b1fac454117c8024a</id>
<content type='text'>
This is a riscv port of commit 819771cc2892 ("arm64: extable:
consolidate definitions").

Signed-off-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
</content>
</entry>
<entry>
<title>riscv: lib: uaccess: fold fixups into body</title>
<updated>2022-01-06T01:52:39Z</updated>
<author>
<name>Jisheng Zhang</name>
<email>jszhang@kernel.org</email>
</author>
<published>2021-11-18T11:25:14Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=9d504f9aa5c1b76673018da9503e76b351a24b8c'/>
<id>urn:sha1:9d504f9aa5c1b76673018da9503e76b351a24b8c</id>
<content type='text'>
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;
</content>
</entry>
<entry>
<title>riscv: switch to relative exception tables</title>
<updated>2022-01-06T01:52:20Z</updated>
<author>
<name>Jisheng Zhang</name>
<email>jszhang@kernel.org</email>
</author>
<published>2021-11-18T11:22:51Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=bb1f85d6046f0db757ac52ed60a5eba5df394819'/>
<id>urn:sha1:bb1f85d6046f0db757ac52ed60a5eba5df394819</id>
<content type='text'>
Similar as other architectures such as arm64, x86 and so on, use
offsets relative to the exception table entry values rather than
absolute addresses for both the exception locationand the fixup.

However, RISCV label difference will actually produce two relocations,
a pair of R_RISCV_ADD32 and R_RISCV_SUB32. Take below simple code for
example:

$ cat test.S
.section .text
1:
        nop
.section __ex_table,"a"
        .balign 4
        .long (1b - .)
.previous

$ riscv64-linux-gnu-gcc -c test.S
$ riscv64-linux-gnu-readelf -r test.o
Relocation section '.rela__ex_table' at offset 0x100 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000600000023 R_RISCV_ADD32     0000000000000000 .L1^B1 + 0
000000000000  000500000027 R_RISCV_SUB32     0000000000000000 .L0  + 0

The modpost will complain the R_RISCV_SUB32 relocation, so we need to
patch modpost.c to skip this relocation for .rela__ex_table section.

After this patch, the __ex_table section size of defconfig vmlinux is
reduced from 7072 Bytes to 3536 Bytes.

Signed-off-by: Jisheng Zhang &lt;jszhang@kernel.org&gt;
Reviewed-by: Kefeng Wang &lt;wangkefeng.wang@huawei.com&gt;
Signed-off-by: Palmer Dabbelt &lt;palmer@rivosinc.com&gt;
</content>
</entry>
<entry>
<title>include/linux/delay.h: replace kernel.h with the necessary inclusions</title>
<updated>2021-11-09T18:02:49Z</updated>
<author>
<name>Andy Shevchenko</name>
<email>andriy.shevchenko@linux.intel.com</email>
</author>
<published>2021-11-09T02:32:32Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/commit/?id=5f6286a608107a68646241b57d2bd2a4fc139ef9'/>
<id>urn:sha1:5f6286a608107a68646241b57d2bd2a4fc139ef9</id>
<content type='text'>
When kernel.h is used in the headers it adds a lot into dependency hell,
especially when there are circular dependencies are involved.

Replace kernel.h inclusion with the list of what is really being used.

[akpm@linux-foundation.org: cxd2880_common.h needs bits.h for GENMASK()]
[andriy.shevchenko@linux.intel.com: delay.h: fix for removed kernel.h]
  Link: https://lkml.kernel.org/r/20211028170143.56523-1-andriy.shevchenko@linux.intel.com
[akpm@linux-foundation.org: include/linux/fwnode.h needs bits.h for BIT()]

Link: https://lkml.kernel.org/r/20211027150324.79827-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>riscv: __asm_copy_to-from_user: Fix: Typos in comments</title>
<updated>2021-07-24T00:49:12Z</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:53:23Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/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:07Z</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:52:36Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/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:01Z</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:51:45Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/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:52Z</updated>
<author>
<name>Akira Tsukamoto</name>
<email>akira.tsukamoto@gmail.com</email>
</author>
<published>2021-07-20T08:50:52Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/linux-dev/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>
</feed>
