Re: How to unwind stack to seek for specific caller?

2018-08-03 Thread Lev Olshvang


03.08.2018, 15:42, "valdis.kletni...@vt.edu" :
> On Fri, 03 Aug 2018 15:14:45 +0300, Lev Olshvang said:
>
>>  But I need to find out whether my function y() was called from linux kernel
>>  function x().\
>
> What problem are you trying to solve? If it's your function, don't you already
> *know* which functions call it?
>
> And if being called from code A requires different behavior than if it was
> called from B, the *right* answer is to create a flag and pass it. That
> requires less code, is simpler than trying to unwind the stack, and makes it
> easier if 6 months from now you call a call from routine C.
>
> For an example, see the memory-allocation flags GFP_ATOMIC and similar - if
> you're adding another call site that needs it, you just add GFP_ATOMIC to the
> flags.
>
> And I'm willing to bet that most of those GFP_ flags were *all* originally "we
> have to do something special if we try to do memory allocation from That One
> Problem Spot. :)

Hi Valdis,

Thanks for the reply.
Now I see i miised to explain that my function x() in my module might be called 
from kernel functions foo() or bar() which I do not own
( function my_x() is sort of callback) . Since  I can not change foo()) or 
bar() code and add flags I need to inspect the stack.

I am confused to see in kernel code that there is a new to me objects of type 
kernel dumper who need to be registered in order to get dump_stack() 
output.

Saw I applied yo list wisdom to seek for an advise.

Thanks All.
Lev


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to unwind stack to seek for specific caller?

2018-08-03 Thread valdis . kletnieks
On Fri, 03 Aug 2018 15:14:45 +0300, Lev Olshvang said:

> But I need to find out whether  my function y() was called from linux  kernel
> function x().\

What problem are you trying to solve?  If it's your function, don't you already
*know* which functions call it?

And if being called from code A requires different behavior than if it was
called from B, the *right*  answer is to create a flag and pass it.  That
requires less code, is simpler than trying to unwind the stack, and makes it
easier if 6 months from now you call a call from routine C.

For an example, see the memory-allocation flags GFP_ATOMIC and similar - if
you're adding another call site that needs it, you just add GFP_ATOMIC to the
flags.

And I'm willing to bet that most of those GFP_ flags were *all* originally "we
have to do something special if we try to do memory allocation from That One
Problem Spot. :)



pgpG_JgpbR3tq.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


How to unwind stack to seek for specific caller?

2018-08-03 Thread Lev Olshvang
Hello all

I know that I can print stack of function using dump_stack()

But I need to find out whether  my function y() was called from linux  kernel 
function x().\

I see that kmsg_dump_get_buffer() function can get kernel messages but it is 
not clear for me should I use it 
bedore calling dump_stack or I need to do additional setup before calling for 
these 2 functions?

Regards,
Lev
 




___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies