Re: [linux-next:master] [x86/module] 6661cae1aa: WARNING:at_arch/x86/mm/pat/set_memory.c:#__cpa_process_fault

From: Dave Hansen
Date: Mon Oct 14 2024 - 11:31:01 EST


On 10/13/24 01:17, Mike Rapoport wrote:
> On Fri, Oct 11, 2024 at 09:30:33AM -0700, Dave Hansen wrote:
>> On 10/11/24 08:40, Mike Rapoport wrote:
>>> On Fri, Oct 11, 2024 at 07:00:01AM -0700, Dave Hansen wrote:
>>>> On 10/11/24 06:08, Mike Rapoport wrote:
>>>>> This patch disables ROX caches on 32-bit, it should fix the issue.
>>>> While I'm not going to shed a tear for 32-bit, what's the actual
>>>> compatibility issue with 32-bit?
>>> From the stack trace it looks like execmem tries to update the direct map
>>> for highmem memory, and cpa is not happy about it.
>>
>> First of all, if it's a highmem problem, shouldn't the check be for
>> CONFIG_HIGHMEM and not on 32-bit vs. 64-bit? We do have non-highmem
>> 32-bit configs.
>
> 32 bit also does not have ARCH_HUGE_VMALLOC and execmem cache will be
> anyway populated with 4k pages, so I don't see why it would be useful on 32
> bit all.

It's not really about making it _available_ to 32-bit, but making sure
that we're actually doing the check against the right feature and in the
right way.

To me, it seems like execmem itself should be excluding all HIGHMEM=y
builds or _maybe_ all 32-bit builds because execmem has the built-in
assumption that vmalloc memory is in the direct map.

That seems preferable to sticking a 32-bit (or highmem) check in all the
architectures.

This code:

> +static int execmem_set_direct_map_valid(struct vm_struct *vm, bool valid)
> +{
> + unsigned int nr = (1 << get_vm_area_page_order(vm));
> + unsigned int updated = 0;
> + int err = 0;
> +
> + for (int i = 0; i < vm->nr_pages; i += nr) {
> + err = set_direct_map_valid_noflush(vm->pages[i], nr, valid);

seems arguably buggy (or at least potentially fragile) since it
implicitly assumes that vmalloc'd memory has a spot in the direct map.
The "this architecture and config has a direct map for all pages"
assumption is not clear here at all.

>> Also, where did the highmem come from? All of the execmem allocations
>> look like they're some variant of PAGE_KERNEL, but no __GFP_HIGHMEM.
>
> Despite that execmem allocations are PAGE_KERNEL, __vmalloc_area_node()
> implicitly adds __GFP_HIGHMEM for !DMA allocations.

Ahh, I missed that bit. Thanks for the explanation.