Re: [GIT PULL] ftrace: Check if pages were allocated before calling free_pages()
From: Steven Rostedt
Date: Wed Mar 31 2021 - 15:04:21 EST
On Wed, 31 Mar 2021 11:03:21 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> I found another bug in there, for example:
>
> ftrace_number_of_pages -= 1 << order;
>
> is also wrong if order is negative.
True, but ftrace_number_of_pages is only used for accounting (used to
display the number of pages at boot up and the number in
/sys/kernel/tracing/dyn_ftrace_total_info). If order is negative, this
value could be used to debug what went wrong ;-)
> Doesn't this make the code now make SENSE? Instead of that
> incomprehensible mess it was before?
I'll look into it. This code has been there since pretty much the beginning
and slowly "grew". It suffered the thousand cuts, instead of going in and
doing surgery on making it clean. It hasn't changed in a long time, so it's
due for a clean up as I believe it's in a stable state now.
>
> I dunno. Maybe it's just my "pee in the snow" thing, but honestly, the
> fact that I seem to have found another bug wrt the whole
> 'ftrace_number_of_pages' handling really says that the code was
> garbage.
Again, that variable was just used to see what the page count was. It was
never used for any logic.
>
> And maybe it's just me who doesn't understand the subtle perfection of
> the old code, and I'm being stupid. Feel free to educate me about it.
>
> Final note: note the "TOTALLY UNTESTED" part of the patch. The patch
> CompilesForMe(tm), but please consider it a "how about something like
> this" rather than anything finished.
>
> Also note that I did *not* change the initial "order" calculation
> itself in ftrace_allocate_records() in this patch. I left that
> particular oddity alone. Again, I *think* the math just ends up being
>
> pages = DIV_ROUND_UP(count, ENTRIES_PER_PAGE);
> order = fls(pages)-1;
>
> but the attached patch is not about that, it's about the crazy "pg->size" games.
>
> Linus
>
> PS. TOTALLY UNTESTED!!
Thanks, I'll look at it and see if it doesn't break anything, or if it can
be easily modified to not break anything.
-- Steve