Re: Can kfree() sleep at runtime?

From: Matthew Wilcox
Date: Thu May 31 2018 - 10:15:00 EST


On Thu, May 31, 2018 at 02:12:00PM +0000, Christopher Lameter wrote:
> On Thu, 31 May 2018, Matthew Wilcox wrote:
>
> > On Thu, May 31, 2018 at 09:10:07PM +0800, Jia-Ju Bai wrote:
> > > I write a static analysis tool (DSAC), and it finds that kfree() can sleep.
> > >
> > > Here is the call path for kfree().
> > > Please look at it *from the bottom up*.
> > >
> > > [FUNC] alloc_pages(GFP_KERNEL)
> > > arch/x86/mm/pageattr.c, 756: alloc_pages in split_large_page
> > > arch/x86/mm/pageattr.c, 1283: split_large_page in __change_page_attr
> >
> > Here's your bug. Coming from kfree(), we can't end up in the
> > split_large_page() path. __change_page_attr may be called in several
> > different circumstances in which it would have to split a large page,
> > but the path from kfree() is not one of them.
>
> Freeing a page in the page allocator also was traditionally not sleeping.
> That has changed?

No. "Your bug" being "The bug in your static analysis tool". It probably
isn't following the data flow correctly (or deeply enough).