Re: [PATCH v4] mm: fix is_pinnable_page against on cma page

John Hubbard
2022-05-12T01:01:50Z

On 5/11/22 17:49, Paul E. McKenney wrote:
>> Thanks Paul for explaining the state of things.
>>
>> Minchan, how about something like very close to your original draft,
>> then, but with a little note, and the "&" as well:
>>
>> int __mt = get_pageblock_migratetype(page);
>>
>> /*
>> * Defend against future compiler LTO features, or code refactoring
>> * that inlines the above function, by forcing a single read. Because, this
>> * routine races with set_pageblock_migratetype(), and we want to avoid
>> * reading zero, when actually one or the other flags was set.
>> */
>> int mt = __READ_ONCE(__mt);
>>
>> if (mt & (MIGRATE_CMA | MIGRATE_ISOLATE))
>> return false;
>>
>>
>> ...which should make everyone comfortable and protected from the
>> future sins of the compiler and linker teams? :)
>
> This would work, but it would force a store to the stack and an immediate
> reload. Which might be OK on this code path.
>
> But using READ_ONCE() in (I think?) __get_pfnblock_flags_mask()
> would likely generate the same code that is produced today.
>
> word = READ_ONCE(bitmap[word_bitidx]);

Ah right, I like that much, much better. The READ_ONCE is placed where
it actually clearly matters, rather than several layers removed.

>
> But I could easily have missed a turn in that cascade of functions. ;-)
>
> Or there might be some code path that really hates a READ_ONCE() in
> that place.

I certainly hope not. I see free_one_page(), among other things, calls
this. But having the correct READ_ONCE() in a central place seems worth
it, unless we know that this will cause a measurable slowdown somewhere.

thanks,
--
John Hubbard
NVIDIA

>
> Thanx, Paul