[PATCH 2/2] x86/mm/pat: track the memory type of HIGHMEM pages in a page array

From: Christian

Date: Tue Nov 17 2026 - 04:49:29 EST


_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@xxxxxxxxx>
---
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