Re: [PATCH 1/3] perf/core: Make sure the ring-buffer is mapped in all page-tables

From: Andy Lutomirski
Date: Fri Jul 20 2018 - 18:20:31 EST



> On Jul 20, 2018, at 11:37 AM, Joerg Roedel <jroedel@xxxxxxx> wrote:
>
>> On Fri, Jul 20, 2018 at 12:32:10PM -0700, Andy Lutomirski wrote:
>> I'm just reading your changelog, and you said the PMDs are no longer
>> shared between the page tables. So this presumably means that
>> vmalloc_fault() no longer actually works correctly on PTI systems. I
>> didn't read the code to figure out *why* it doesn't work, but throwing
>> random vmalloc_sync_all() calls around is wrong.
>
> Hmm, so the whole point of vmalloc_fault() fault is to sync changes from
> swapper_pg_dir to process page-tables when the relevant parts of the
> kernel page-table are not shared, no?
>
> That is also the reason we don't see this on 64 bit, because there these
> parts *are* shared.
>
> So with that reasoning vmalloc_fault() works as designed, except that
> a warning is issued when it's happens in the NMI path. That warning comes
> from
>
> ebc8827f75954 x86: Barf when vmalloc and kmemcheck faults happen in NMI
>
> which went into 2.6.37 and was added because the NMI handler were not
> nesting-safe back then. Reason probably was that the handler on 64 bit
> has to use an IST stack and a nested NMI would overwrite the stack of
> the upper handler. We don't have this problem on 32 bit as a nested NMI
> will not do another stack-switch there.
>

Thanks for digging! The problem was presumably that vmalloc_fault() will IRET and re-enable NMIs on the way out. But weâve supported page faults on user memory in NMI handlers on 32-bit and 64-bit for quite a while, and itâs fine now.

I would remove the warning, re-test, and revert the other patch.

The one case we canât handle in vmalloc_fault() is a fault on a stack access. I donât expect this to be a problem for PTI. It was a problem for CONFIG_VMAP_STACK, though.

> I am not sure about 64 bit, but there is a lot of assembly magic to make
> NMIs nesting-safe, so I guess the problem should be gone there too.
>
>
> Regards,
>
> Joerg