* [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*()
@ 2026-11-17 9:49 Christian
2026-11-17 9:49 ` [PATCH 1/2] x86/mm/pat: skip HIGHMEM pages in a page array Christian
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christian @ 2026-11-17 9:49 UTC (permalink / raw)
To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, x86
Cc: H. Peter Anvin, linux-kernel
On i386 without PAE nearly all memory is HIGHMEM, and a DRM driver that
keeps its shmem buffers there (drm_gem_shmem_get_pages_locked() ->
set_pages_array_wc()) hits two problems in the page-array CPA paths:
1. The CPA walk takes __cpa_addr()'s 0 for a HIGHMEM page as a virtual
address and oopses in __cpa_process_fault()'s warning path, with the
CPA lock held, so every later CPA user hangs.
2. _set_pages_array() and set_pages_array_wb() skip HIGHMEM pages when
they reserve and free the memory type, so a write-combined user mapping
of such a page is left write-back by PAT. A device that does not snoop
the CPU's caches then reads stale data.
Patch 1 skips HIGHMEM pages in the CPA walk, as there is nothing there for
it to change. Patch 2 reserves and frees their memory type like any other
page's.
Found and tested on an HP ElitePad 900 G1 (Atom Z2760, Clover Trail, i386
without PAE, 2 GB) running an out-of-tree PowerVR SGX545 DRM driver with
its buffers in HIGHMEM. Before: an oops in set_pages_array_wc() on the
first buffer and an unreachable machine (patch 1), then continuous GPU page
faults and firmware resets until the GPU wedged (patch 2). With both: no
GPU faults or kernel warnings through the driver's uAPI tests (50/50), 100
rendered frames checked against a reference, glmark2 and video playback.
Written and tested on 7.3.4; this series is rebased on v7.4-rc3, where it
builds for i386.
Christian (2):
x86/mm/pat: skip HIGHMEM pages in a page array
x86/mm/pat: track the memory type of HIGHMEM pages in a page array
arch/x86/mm/pat/set_memory.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] x86/mm/pat: skip HIGHMEM pages in a page array
2026-11-17 9:49 [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Christian
@ 2026-11-17 9:49 ` Christian
2026-11-17 9:49 ` [PATCH 2/2] x86/mm/pat: track the memory type of " Christian
2026-11-19 19:45 ` [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Dave Hansen
2 siblings, 0 replies; 4+ messages in thread
From: Christian @ 2026-11-17 9:49 UTC (permalink / raw)
To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, x86
Cc: H. Peter Anvin, linux-kernel
set_pages_array_wc() walks a page array through __cpa_addr(), which
returns 0 for a HIGHMEM page because it has no linear mapping.
__cpa_process_fault() then takes that 0 for a virtual address and
dereferences it in its warning path, so changing a HIGHMEM page's
caching oopses with a NULL pointer dereference, with the CPA lock held:
every later CPA user (installing a seccomp filter, for one) then spins
forever.
A page without a linear mapping has nothing for CPA to change, so skip
it, and take the pfn from the array: that is where the primary path
reads its page from, and cpa_process_alias() must not derive an address
for a page that has none.
Measured on an HP ElitePad 900 G1 (Atom Z2760, i386 without PAE, kernel
7.3.4) with a graphics driver that keeps its buffers in HIGHMEM: every
buffer oopsed in set_pages_array_wc() -> drm_gem_shmem_get_pages_locked(),
and the machine stayed up but became unreachable.
Signed-off-by: Christian <servidorjarvis1@gmail.com>
---
arch/x86/mm/pat/set_memory.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index b1d5c5a0f..4565438b6 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -1847,6 +1847,17 @@ static int __cpa_process_fault(struct cpa_data
*cpa, unsigned long vaddr,
return 0;
}
+ /*
+ * A HIGHMEM page in a page array has no linear mapping, so there is
+ * nothing to change: __cpa_addr() gives 0 for it. Skip it; its pfn
+ * keeps cpa_process_alias() off the direct map, where it isn't.
+ */
+ if ((cpa->flags & CPA_PAGES_ARRAY) && !vaddr) {
+ cpa->numpages = 1;
+ cpa->pfn = page_to_pfn(cpa->pages[cpa->curpage]);
+ return 0;
+ }
+
/*
* Ignore the NULL PTE for kernel identity mapping, as it is expected
* to have holes.
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/2] x86/mm/pat: track the memory type of HIGHMEM pages in a page array
2026-11-17 9:49 [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Christian
2026-11-17 9:49 ` [PATCH 1/2] x86/mm/pat: skip HIGHMEM pages in a page array Christian
@ 2026-11-17 9:49 ` Christian
2026-11-19 19:45 ` [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Dave Hansen
2 siblings, 0 replies; 4+ messages in thread
From: Christian @ 2026-11-17 9:49 UTC (permalink / raw)
To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, x86
Cc: H. Peter Anvin, linux-kernel
_set_pages_array() reserves a memory type only for pages that are not
HIGHMEM, and set_pages_array_wb() frees it only for those. The reservation
is what makes PAT apply the type to user mappings of the page; it is not
the CPA walk, which has nothing to change on a page without a linear
mapping.
Without it a driver that keeps its buffers in HIGHMEM gets a
write-combined user mapping that PAT leaves as write-back, so the CPU
keeps its writes in cache and a device that does not snoop them reads
stale memory. With the graphics driver on the ElitePad that showed up as
continuous GPU page faults and microkernel resets until the device wedged;
the same driver with its buffers in lowmem had none.
Signed-off-by: Christian <servidorjarvis1@gmail.com>
---
arch/x86/mm/pat/set_memory.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 4565438b6..77da61396 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2578,9 +2578,11 @@ static int _set_pages_array(struct page
**pages, int numpages,
int free_idx;
int ret;
+ /*
+ * HIGHMEM pages get their memory type too: CPA has no linear mapping of
+ * theirs to change, but PAT applies the type to user mappings of them.
+ */
for (i = 0; i < numpages; i++) {
- if (PageHighMem(pages[i]))
- continue;
start = page_to_pfn(pages[i]) << PAGE_SHIFT;
end = start + PAGE_SIZE;
if (memtype_reserve(start, end, new_type, NULL))
@@ -2605,8 +2607,6 @@ static int _set_pages_array(struct page **pages,
int numpages,
err_out:
free_idx = i;
for (i = 0; i < free_idx; i++) {
- if (PageHighMem(pages[i]))
- continue;
start = page_to_pfn(pages[i]) << PAGE_SHIFT;
end = start + PAGE_SIZE;
memtype_free(start, end);
@@ -2648,8 +2648,6 @@ int set_pages_array_wb(struct page **pages, int numpages)
return retval;
for (i = 0; i < numpages; i++) {
- if (PageHighMem(pages[i]))
- continue;
start = page_to_pfn(pages[i]) << PAGE_SHIFT;
end = start + PAGE_SIZE;
memtype_free(start, end);
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*()
2026-11-17 9:49 [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Christian
2026-11-17 9:49 ` [PATCH 1/2] x86/mm/pat: skip HIGHMEM pages in a page array Christian
2026-11-17 9:49 ` [PATCH 2/2] x86/mm/pat: track the memory type of " Christian
@ 2026-11-19 19:45 ` Dave Hansen
2 siblings, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2026-11-19 19:45 UTC (permalink / raw)
To: Christian, Dave Hansen, Andy Lutomirski, Peter Zijlstra,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86
Cc: H. Peter Anvin, linux-kernel
On 11/17/26 01:49, Christian wrote:
> Found and tested on an HP ElitePad 900 G1 (Atom Z2760, Clover Trail, i386
> without PAE, 2 GB) running an out-of-tree PowerVR SGX545 DRM driver with
> its buffers in HIGHMEM.
Reproduce upstream and we'll talk.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 19:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 9:49 [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Christian
2026-11-17 9:49 ` [PATCH 1/2] x86/mm/pat: skip HIGHMEM pages in a page array Christian
2026-11-17 9:49 ` [PATCH 2/2] x86/mm/pat: track the memory type of " Christian
2026-11-19 19:45 ` [PATCH 0/2] x86/mm/pat: HIGHMEM pages in set_pages_array_*() Dave Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®