bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why does tail call only unwind the current stack frame instead of resetting the current stack?
@ 2021-09-12 17:48 Hsuan-Chi Kuo
  2021-09-13  4:08 ` Yonghong Song
  0 siblings, 1 reply; 4+ messages in thread
From: Hsuan-Chi Kuo @ 2021-09-12 17:48 UTC (permalink / raw)
  To: bpf

Hi,

The function check_max_stack_depth 
(https://elixir.bootlin.com/linux/latest/source/kernel/bpf/verifier.c#L3574) 
is used to ensure the stack size is no greater than 8KB.

The stack can only grow over 8KB because of tail calls as they only 
unwind the current stack frame. I wonder why not make tail call reset 
the stack since what was on the stack

will never be used again?


Thanks


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why does tail call only unwind the current stack frame instead of resetting the current stack?
  2021-09-12 17:48 Why does tail call only unwind the current stack frame instead of resetting the current stack? Hsuan-Chi Kuo
@ 2021-09-13  4:08 ` Yonghong Song
  2021-09-13  5:04   ` Hsuan-Chi Kuo
  0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2021-09-13  4:08 UTC (permalink / raw)
  To: Hsuan-Chi Kuo, bpf



On 9/12/21 10:48 AM, Hsuan-Chi Kuo wrote:
> Hi,
> 
> The function check_max_stack_depth 
> (https://elixir.bootlin.com/linux/latest/source/kernel/bpf/verifier.c#L3574 
> ) is used to ensure the stack size is no greater than 8KB.
> 
> The stack can only grow over 8KB because of tail calls as they only 
> unwind the current stack frame. I wonder why not make tail call reset 
> the stack since what was on the stack
> 
> will never be used again?

I think this is just an artifact of current implementation.
To do a correct reset of the stack, additional instructions
are needed to keep track and accumulate stack size properly,
so when a tail call is reached, it knows how much stack size
to reset.

Did you hit this limitation? Could you describe your use case
in detail?

> 
> 
> Thanks
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why does tail call only unwind the current stack frame instead of resetting the current stack?
  2021-09-13  4:08 ` Yonghong Song
@ 2021-09-13  5:04   ` Hsuan-Chi Kuo
  2021-09-13 16:32     ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Hsuan-Chi Kuo @ 2021-09-13  5:04 UTC (permalink / raw)
  To: Yonghong Song, bpf

No, I didn't hit this limit.

The current implementation already keeps tracks of the number of tail 
calls which to me is the same effort of tracking the stack size. I was 
just wondering if there's any fundamental reason that you can't reset 
the stack directly. But it seems that there is not.

Thanks

On 9/12/21 11:08 PM, Yonghong Song wrote:
>
>
> On 9/12/21 10:48 AM, Hsuan-Chi Kuo wrote:
>> Hi,
>>
>> The function check_max_stack_depth 
>> (https://elixir.bootlin.com/linux/latest/source/kernel/bpf/verifier.c#L3574 
>> ) is used to ensure the stack size is no greater than 8KB.
>>
>> The stack can only grow over 8KB because of tail calls as they only 
>> unwind the current stack frame. I wonder why not make tail call reset 
>> the stack since what was on the stack
>>
>> will never be used again?
>
> I think this is just an artifact of current implementation.
> To do a correct reset of the stack, additional instructions
> are needed to keep track and accumulate stack size properly,
> so when a tail call is reached, it knows how much stack size
> to reset.
>
> Did you hit this limitation? Could you describe your use case
> in detail?
>
>>
>>
>> Thanks
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why does tail call only unwind the current stack frame instead of resetting the current stack?
  2021-09-13  5:04   ` Hsuan-Chi Kuo
@ 2021-09-13 16:32     ` Alexei Starovoitov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2021-09-13 16:32 UTC (permalink / raw)
  To: Hsuan-Chi Kuo; +Cc: Yonghong Song, bpf

On Sun, Sep 12, 2021 at 10:08 PM Hsuan-Chi Kuo <hsuanchikuo@gmail.com> wrote:
>
> No, I didn't hit this limit.
>
> The current implementation already keeps tracks of the number of tail
> calls which to me is the same effort of tracking the stack size. I was
> just wondering if there's any fundamental reason that you can't reset
> the stack directly. But it seems that there is not.

The tail_call unwinds the current stack frame.
See comment at line 3585 for details.

And please don't top post.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-13 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 17:48 Why does tail call only unwind the current stack frame instead of resetting the current stack? Hsuan-Chi Kuo
2021-09-13  4:08 ` Yonghong Song
2021-09-13  5:04   ` Hsuan-Chi Kuo
2021-09-13 16:32     ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).