[PATCH RFC v2 riscv/for-next 5/5] riscv: align arch_static_branch function
Jessica Clarke
jrtc27 at jrtc27.com
Wed Sep 14 19:34:05 PDT 2022
On 15 Sept 2022, at 02:47, Guo Ren <guoren at kernel.org> wrote:
>
> On Wed, Sep 14, 2022 at 10:24 PM Jessica Clarke <jrtc27 at jrtc27.com> wrote:
>>
>> On 13 Sept 2022, at 10:42, Andy Chiu <andy.chiu at sifive.com> wrote:
>>>
>>> runtime code patching must be done at a naturally aligned address, or we
>>> may execute on a partial instruction.
>>>
>>> Signed-off-by: Andy Chiu <andy.chiu at sifive.com>
>>> Reviewed-by: Greentime Hu <greentime.hu at sifive.com>
>>> ---
>>> arch/riscv/include/asm/jump_label.h | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h
>>> index 38af2ec7b9bf..729991e8f782 100644
>>> --- a/arch/riscv/include/asm/jump_label.h
>>> +++ b/arch/riscv/include/asm/jump_label.h
>>> @@ -18,6 +18,7 @@ static __always_inline bool arch_static_branch(struct static_key *key,
>>> bool branch)
>>> {
>>> asm_volatile_goto(
>>> + " .align 2 \n\t"
>>
>> .align is a horrible directive whose meaning changes between
>> architectures and requires careful thought, especially when the
>> argument is a power of 2. Better to use .balign 4, or .p2align 2 if you
>> really want to for some reason.
> Do we really need to align here? Should it be naturally done by the compiler?
Compilers don’t add alignment do inline assembly beyond what’s needed.
And assemblers won’t align beyond what the architecture requires here
either as far as I know for .option rvc, since normally you still have
an RVC-capable processor you just don’t want compressed instructions at
that specific point.
Jess
>>
>> Jess
>>
>>> " .option push \n\t"
>>> " .option norelax \n\t"
>>> " .option norvc \n\t"
>>> @@ -39,6 +40,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key,
>>> bool branch)
>>> {
>>> asm_volatile_goto(
>>> + " .align 2 \n\t"
>>> " .option push \n\t"
>>> " .option norelax \n\t"
>>> " .option norvc \n\t"
>>> --
>>> 2.36.0
>>>
>>>
>>> _______________________________________________
>>> linux-riscv mailing list
>>> linux-riscv at lists.infradead.org
>>> http://lists.infradead.org/mailman/listinfo/linux-riscv
>>
>
>
> --
> Best Regards
> Guo Ren
More information about the linux-riscv
mailing list