Re: [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*()

From: Christian

Date: Fri Nov 20 2026 - 02:50:29 EST


On 11/19/26 11:45, Dave Hansen wrote:
> Reproduce upstream and we'll talk.

vgem does it. It keeps its buffers in shmem pages (GFP_HIGHUSER) and sets
map_wc, so on x86 mmap() reaches set_pages_array_wc() through
drm_gem_shmem_get_pages_locked(). On i386 without PAE, once RAM is above
lowmem, those pages are HIGHMEM.

Reproduce with v7.4-rc3:

make i386_defconfig
scripts/config -e HIGHMEM4G -e DRM_VGEM -e DEBUG_FS -e PTDUMP_DEBUGFS
make -j$(nproc) # no PAE: i386_defconfig is 32-bit only
qemu-system-i386 -cpu n270 -m 2G -smp 2 -kernel arch/x86/boot/bzImage \
-initrd <initramfs with the program below as /init> \
-append console=ttyS0

(-m 512M stays below lowmem and is the control run; -cpu n270 has PAT,
but -cpu qemu32 oopses the same way without it.)

BUG: kernel NULL pointer dereference, address: 00000000
EIP: __cpa_process_fault+0x336/0x360
Call Trace:
__change_page_attr_set_clr+0x782/0xa10
change_page_attr_set_clr+0xdc/0x540
_set_pages_array+0xb2/0x160
set_pages_array_wc+0xd/0x10
drm_gem_shmem_get_pages_locked+0x86/0xe0
drm_gem_shmem_mmap+0x97/0x130
drm_gem_shmem_object_mmap+0x8/0x10
drm_gem_mmap_obj+0x5a/0x180
drm_gem_mmap+0x32/0xa0
__mmap_region+0x930/0x1120
...

A second buffer's mmap() then never returns: the CPA lock is still held.

With patch 1 alone both buffers map, but the user mapping is write-back
(page_tables/current_kernel, CONFIG_PTDUMP_DEBUGFS):

0xb6fdc000-0xb7fdc000 16M USR RW x pte

With -m 512M (no HIGHMEM) and with both patches it is write-combined:

0xb6f76000-0xb7f76000 16M USR RW PWT x pte

The program:

// gcc -m32 -static -I/usr/include/libdrm vgem_highmem.c
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <unistd.h>
#include <drm/drm.h>
#include <drm/drm_mode.h>

int main(void)
{
struct drm_mode_create_dumb c = { .width = 1024, .height = 4096, .bpp = 32 };
struct drm_mode_map_dumb m = { 0 };
char path[32], name[16];
unsigned int *p;
int fd = -1;

mount("devtmpfs", "/dev", "devtmpfs", 0, NULL); /* when run as /init */
for (int i = 0; i < 8 && fd < 0; i++) {
struct drm_version v = { .name = name, .name_len = sizeof(name) - 1 };

snprintf(path, sizeof(path), "/dev/dri/card%d", i);
fd = open(path, O_RDWR);
memset(name, 0, sizeof(name));
if (fd >= 0 && (ioctl(fd, DRM_IOCTL_VERSION, &v) || strcmp(name, "vgem"))) {
close(fd);
fd = -1;
}
}
if (fd < 0 || ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &c))
return perror("vgem"), 1;
m.handle = c.handle;
if (ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &m))
return perror("MAP_DUMB"), 1;

p = mmap(NULL, c.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, m.offset);
if (p == MAP_FAILED)
return perror("mmap"), 1;
p[0] = 1;
printf("mapped %llu bytes at %p\n", (unsigned long long)c.size, (void *)p);
pause();
return 0;
}

I can send a v2 with this in the changelogs, and with hpa and
linux-kernel on Cc, which I left out the first time.

Christian