diff mbox series

[v2,1/8] riscv: remove unused functions in traps_misaligned.c

Message ID 20231004151405.521596-2-cleger@rivosinc.com (mailing list archive)
State Accepted
Commit f19c3b4239f5bfb69aacbaf75d4277c095e7aa7d
Headers show
Series Add support to handle misaligned accesses in S-mode | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-1-test-13 success .github/scripts/patches/verify_signedoff.sh
conchuod/patch-1-test-1 success .github/scripts/patches/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 success .github/scripts/patches/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/verify_signedoff.sh

Commit Message

Clément Léger Oct. 4, 2023, 3:13 p.m. UTC
Replace macros by the only two function calls that are done from this
file, store_u8() and load_u8().

Signed-off-by: Clément Léger <cleger@rivosinc.com>
---
 arch/riscv/kernel/traps_misaligned.c | 46 +++++-----------------------
 1 file changed, 7 insertions(+), 39 deletions(-)

Comments

Björn Töpel Oct. 4, 2023, 4:51 p.m. UTC | #1
Clément Léger <cleger@rivosinc.com> writes:

> Replace macros by the only two function calls that are done from this
> file, store_u8() and load_u8().
>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> ---
>  arch/riscv/kernel/traps_misaligned.c | 46 +++++-----------------------
>  1 file changed, 7 insertions(+), 39 deletions(-)
>
> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
> index 378f5b151443..e7bfb33089c1 100644
> --- a/arch/riscv/kernel/traps_misaligned.c
> +++ b/arch/riscv/kernel/traps_misaligned.c
> @@ -151,51 +151,19 @@
>  #define PRECISION_S 0
>  #define PRECISION_D 1
>  
> -#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn)			\
> -static inline type load_##type(const type *addr)			\
> -{									\
> -	type val;							\
> -	asm (#insn " %0, %1"						\
> -	: "=&r" (val) : "m" (*addr));					\
> -	return val;							\
> -}
> +static inline u8 load_u8(const u8 *addr)

Really a nit, and applies to the whole file: "static inline" in a .c
file is just useless.

> +{
> +	u8 val;
>  
> -#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn)			\
> -static inline void store_##type(type *addr, type val)			\
> -{									\
> -	asm volatile (#insn " %0, %1\n"					\
> -	: : "r" (val), "m" (*addr));					\
> -}
> +	asm volatile("lbu %0, %1" : "=&r" (val) : "m" (*addr));

Why do you need early clobber here?


Björn
Clément Léger Oct. 9, 2023, 1:02 p.m. UTC | #2
On 04/10/2023 18:51, Björn Töpel wrote:
> Clément Léger <cleger@rivosinc.com> writes:
> 
>> Replace macros by the only two function calls that are done from this
>> file, store_u8() and load_u8().
>>
>> Signed-off-by: Clément Léger <cleger@rivosinc.com>
>> ---
>>  arch/riscv/kernel/traps_misaligned.c | 46 +++++-----------------------
>>  1 file changed, 7 insertions(+), 39 deletions(-)
>>
>> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
>> index 378f5b151443..e7bfb33089c1 100644
>> --- a/arch/riscv/kernel/traps_misaligned.c
>> +++ b/arch/riscv/kernel/traps_misaligned.c
>> @@ -151,51 +151,19 @@
>>  #define PRECISION_S 0
>>  #define PRECISION_D 1
>>  
>> -#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn)			\
>> -static inline type load_##type(const type *addr)			\
>> -{									\
>> -	type val;							\
>> -	asm (#insn " %0, %1"						\
>> -	: "=&r" (val) : "m" (*addr));					\
>> -	return val;							\
>> -}
>> +static inline u8 load_u8(const u8 *addr)
> 
> Really a nit, and applies to the whole file: "static inline" in a .c
> file is just useless.

Oh yes clearly, I should have fixed that while factorizing, I simply
kept them from the previous code.

> 
>> +{
>> +	u8 val;
>>  
>> -#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn)			\
>> -static inline void store_##type(type *addr, type val)			\
>> -{									\
>> -	asm volatile (#insn " %0, %1\n"					\
>> -	: : "r" (val), "m" (*addr));					\
>> -}
>> +	asm volatile("lbu %0, %1" : "=&r" (val) : "m" (*addr));
> 
> Why do you need early clobber here?

Ditto, copy pasted from existing code but I don't think there is a need
for early clobber here.

Clément

> 
> 
> Björn
diff mbox series

Patch

diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
index 378f5b151443..e7bfb33089c1 100644
--- a/arch/riscv/kernel/traps_misaligned.c
+++ b/arch/riscv/kernel/traps_misaligned.c
@@ -151,51 +151,19 @@ 
 #define PRECISION_S 0
 #define PRECISION_D 1
 
-#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn)			\
-static inline type load_##type(const type *addr)			\
-{									\
-	type val;							\
-	asm (#insn " %0, %1"						\
-	: "=&r" (val) : "m" (*addr));					\
-	return val;							\
-}
+static inline u8 load_u8(const u8 *addr)
+{
+	u8 val;
 
-#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn)			\
-static inline void store_##type(type *addr, type val)			\
-{									\
-	asm volatile (#insn " %0, %1\n"					\
-	: : "r" (val), "m" (*addr));					\
-}
+	asm volatile("lbu %0, %1" : "=&r" (val) : "m" (*addr));
 
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8, lbu)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16, lhu)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s8, lb)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s16, lh)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(s32, lw)
-DECLARE_UNPRIVILEGED_STORE_FUNCTION(u8, sb)
-DECLARE_UNPRIVILEGED_STORE_FUNCTION(u16, sh)
-DECLARE_UNPRIVILEGED_STORE_FUNCTION(u32, sw)
-#if defined(CONFIG_64BIT)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lwu)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u64, ld)
-DECLARE_UNPRIVILEGED_STORE_FUNCTION(u64, sd)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, ld)
-#else
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u32, lw)
-DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, lw)
-
-static inline u64 load_u64(const u64 *addr)
-{
-	return load_u32((u32 *)addr)
-		+ ((u64)load_u32((u32 *)addr + 1) << 32);
+	return val;
 }
 
-static inline void store_u64(u64 *addr, u64 val)
+static inline void store_u8(u8 *addr, u8 val)
 {
-	store_u32((u32 *)addr, val);
-	store_u32((u32 *)addr + 1, val >> 32);
+	asm volatile ("sb %0, %1\n" : : "r" (val), "m" (*addr));
 }
-#endif
 
 static inline ulong get_insn(ulong mepc)
 {