Re: [PATCH v5 7/9] riscv/kprobe: Prepare detour buffer for optimized kprobe

From: liaochang (A)
Date: Wed Jan 04 2023 - 20:03:05 EST




在 2023/1/4 17:12, Björn Töpel 写道:
> "liaochang (A)" <liaochang1@xxxxxxxxxx> writes:
>
>>>> +SYM_ENTRY(optprobe_template_insn, SYM_L_GLOBAL, SYM_A_NONE)
>>>> + /*
>>>> + * Step3:
>>>> + * NOPS will be replaced by the probed instruction, at worst case 3 RVC
>>>> + * and 1 RVI instructions is about to execute out of line.
>>>> + */
>>>> + nop
>>>
>>> A nop here will be either a compressed nop or a non-compressed,
>>> depending on the build (C-enabled or not), right? Maybe be explicit to
>>> the assembler what you want?
>>>
>>
>> You are right, if CONFIG_RISCV_ISA_C is disabled, two NOP is enough for 2 RVI execute out of line,
>> if CONFIG_RISCV_ISA_C is enabled, it needs eight C.NOP here for the worst case (3 RVC + 1 RVI).
>>
>> I will use {C}.NOP explicitly for different configure in next revision, thanks.
>
> What I meant was that "nop" can expand to compressed instructions, and
> you should be explicit. So you know how it's expanded by the
> compiler/assembler.
>
> An example:
>
> $ cat bar.S
> .text
> bar:
> nop
> nop
> $ riscv64-linux-gnu-gcc -O2 -o bar.o -c bar.S && riscv64-linux-gnu-objdump -M no-aliases -d bar.o
>
> bar.o: file format elf64-littleriscv
>
>
> Disassembly of section .text:
>
> 0000000000000000 <bar>:
> 0: 0001 c.addi zero,0
> 2: 0001 c.addi zero,0
>
>
> vs
>
> $ cat foo.S
> .text
> foo:
> .option norvc
> nop
> nop
>
> $ riscv64-linux-gnu-gcc -O2 -o foo.o -c foo.S && riscv64-linux-gnu-objdump -M no-aliases -d foo.o
>
> foo.o: file format elf64-littleriscv
>
>
> Disassembly of section .text:
>
> 0000000000000000 <foo>:
> 0: 00000013 addi zero,zero,0
> 4: 00000013 addi zero,zero,0

Above examples are very clear, i will use these expaned instructions in next revision, thanks.

>
>
> Björn

--
BR,
Liao, Chang