Re: arch/powerpc/kernel/head_85xx.o: warning: objtool: .head.text+0x1a6c: unannotated intra-function call

2023-01-26 Thread Segher Boessenkool
Hi!

On Wed, Jan 25, 2023 at 12:57:35PM +0530, Naveen N. Rao wrote:
> Sathvika Vasireddy wrote:
> >--- a/arch/powerpc/kvm/booke.c
> >+++ b/arch/powerpc/kvm/booke.c
> >@@ -917,7 +917,9 @@ static void kvmppc_fill_pt_regs(struct pt_regs *regs)
> >     asm("mr %0, 1" : "=r"(r1));
> >     asm("mflr %0" : "=r"(lr));
> >     asm("mfmsr %0" : "=r"(msr));
> >+   asm(".pushsection .discard.intra_function_calls; .long 999f; 
> >.popsection; 999:");
> >     asm("bl 1f; 1: mflr %0" : "=r"(ip));
> 
> I don't think you can assume that there won't be anything in between two 
> asm statements.

It would be a false assumption.  There is nothing that stops the
compiler from moving, duplicating, or even removing these statements
(removing only if no outputs from the asm are required of course).

> Does it work if you combine both the above asm 
> statements into a single one?
> 
> Even if that works, I don't think it is good to expand the macro here.  
> That asm statement looks to be trying to grab the current nip. I don't 
> know enough about that code, and someone who knows more about KVM may be 
> able to help, but it looks like we should be able to simply set 'ip' to 
> the address of kvmppc_fill_pt_regs()?

Such things are much better as actual assembler code (like, a .s file).
You have to be certain the compiler doesn't transform this in unexpected
ways, like, copy and move it to all callers for example.  You need the
mfmsr to remain somewhat in place for example.

A big reason to not want inline asm for things like this is you need so
very many operands in a single asm that way; it becomes very hard to
write, esp. if you want it to be correct code as well.  That is a good
hint there are better way to do this ;-)


Segher


Re: arch/powerpc/kernel/head_85xx.o: warning: objtool: .head.text+0x1a6c: unannotated intra-function call

2023-01-25 Thread Michael Ellerman
"Naveen N. Rao"  writes:
> Sathvika Vasireddy wrote:
>> 
> arch/powerpc/kvm/booke.o: warning: objtool: kvmppc_fill_pt_regs+0x30: 
> unannotated intra-function call
>> 
>> As an attempt to fix it, I tried expanding ANNOTATE_INTRA_FUNCTION_CALL 
>> macro to indicate that the branch target is valid. It then threw another 
>> warning (arch/powerpc/kvm/booke.o: warning: objtool: 
>> kvmppc_fill_pt_regs+0x38: intra_function_call not a direct call). The 
>> below diff just removes the warnings for me, but I'm not very sure if 
>> this is the best way to fix the objtool warnings seen with this 
>> particular file. Please let me know if there are any better ways to fix it.
>> 
>> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
>> index 0dce93ccaadf..b6a413824b98 100644
>> --- a/arch/powerpc/kvm/booke.c
>> +++ b/arch/powerpc/kvm/booke.c
>> @@ -917,7 +917,9 @@ static void kvmppc_fill_pt_regs(struct pt_regs *regs)
>>      asm("mr %0, 1" : "=r"(r1));
>>      asm("mflr %0" : "=r"(lr));
>>      asm("mfmsr %0" : "=r"(msr));
>> +   asm(".pushsection .discard.intra_function_calls; .long 999f; 
>> .popsection; 999:");
>>      asm("bl 1f; 1: mflr %0" : "=r"(ip));
>
> I don't think you can assume that there won't be anything in between two 
> asm statements.

Yeah, compiler could interleave something theoretically.

> Even if that works, I don't think it is good to expand the macro here.  
> That asm statement looks to be trying to grab the current nip. I don't 
> know enough about that code, and someone who knows more about KVM may be 
> able to help, but it looks like we should be able to simply set 'ip' to 
> the address of kvmppc_fill_pt_regs()?

There is _THIS_IP_ which should be sufficient.

cheers


Re: arch/powerpc/kernel/head_85xx.o: warning: objtool: .head.text+0x1a6c: unannotated intra-function call

2023-01-24 Thread Naveen N. Rao

Sathvika Vasireddy wrote:



arch/powerpc/kvm/booke.o: warning: objtool: kvmppc_fill_pt_regs+0x30: 
unannotated intra-function call


As an attempt to fix it, I tried expanding ANNOTATE_INTRA_FUNCTION_CALL 
macro to indicate that the branch target is valid. It then threw another 
warning (arch/powerpc/kvm/booke.o: warning: objtool: 
kvmppc_fill_pt_regs+0x38: intra_function_call not a direct call). The 
below diff just removes the warnings for me, but I'm not very sure if 
this is the best way to fix the objtool warnings seen with this 
particular file. Please let me know if there are any better ways to fix it.


diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 0dce93ccaadf..b6a413824b98 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -917,7 +917,9 @@ static void kvmppc_fill_pt_regs(struct pt_regs *regs)
     asm("mr %0, 1" : "=r"(r1));
     asm("mflr %0" : "=r"(lr));
     asm("mfmsr %0" : "=r"(msr));
+   asm(".pushsection .discard.intra_function_calls; .long 999f; 
.popsection; 999:");

     asm("bl 1f; 1: mflr %0" : "=r"(ip));


I don't think you can assume that there won't be anything in between two 
asm statements. Does it work if you combine both the above asm 
statements into a single one?


Even if that works, I don't think it is good to expand the macro here.  
That asm statement looks to be trying to grab the current nip. I don't 
know enough about that code, and someone who knows more about KVM may be 
able to help, but it looks like we should be able to simply set 'ip' to 
the address of kvmppc_fill_pt_regs()?



- Naveen