Skip to contentSkip to conversation

x86, pat: return EINVAL for pci mmap WC request for !pat_enabled

PATCH Applied Suresh Siddha 2 participants 2 messages Oct 23, 2009 – Oct 26, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, pat: return EINVAL for pci mmap WC request for !pat_enabled

Thomas Schlichter reported:

Quoted 5 lines

X.org uses libpciaccess which tries to mmap with write combining enabled via /sys/bus/pci/devices/*/resource0_wc. Currently, when PAT is not enabled, the kernel does fall back to uncached mmap. Then libpciaccess thinks it succeeded mapping with write combining enabled and does not set up suited MTRR entries. ;-(

Instead of silently mapping pci mmap region as UC minus in the case of !pat_enabled and wc request, we can return error. Eric Anholt mentioned that caller (like X) typically follows up with UC minus pci mmap request and if there is a free mtrr slot, caller will manage adding WC mtrr.

Jesse Barnes says:

Quoted 3 lines

Older versions of libpciaccess will behave better if we do it that way (iirc it only allocates an MTRR if the resource_wc file doesn't exist or fails to get mapped).

---

arch/x86/pci/i386.c +9 -0
index b22d13b..a672f12 100644
@@ -282,6 +282,15 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
 		return -EINVAL;
 
 	prot = pgprot_val(vma->vm_page_prot);
+
+	/*
+ 	 * Return error if pat is not enabled and write_combine is requested.
+ 	 * Caller can followup with UC MINUS request and add a WC mtrr if there
+ 	 * is a free mtrr slot.
+ 	 */
+	if (!pat_enabled && write_combine)
+		return -EINVAL;
+
 	if (pat_enabled && write_combine)
 		prot |= _PAGE_CACHE_WC;
 	else if (pat_enabled || boot_cpu_data.x86 > 3)
Applied
#1 lore raw
Quoted 18 lines · On Mon, 26 Oct 2009 13:21:32 -0800 Suresh Siddha <[email protected]>…

Thomas Schlichter reported:

Quoted 5 lines

X.org uses libpciaccess which tries to mmap with write combining enabled via /sys/bus/pci/devices/*/resource0_wc. Currently, when PAT is not enabled, the kernel does fall back to uncached mmap. Then libpciaccess thinks it succeeded mapping with write combining enabled and does not set up suited MTRR entries. ;-(

Instead of silently mapping pci mmap region as UC minus in the case of !pat_enabled and wc request, we can return error. Eric Anholt mentioned that caller (like X) typically follows up with UC minus pci mmap request and if there is a free mtrr slot, caller will manage adding WC mtrr.

Jesse Barnes says:

Quoted 3 lines

Older versions of libpciaccess will behave better if we do it that way (iirc it only allocates an MTRR if the resource_wc file doesn't exist or fails to get mapped).

Quoted 7 lines

---

Applied to my linux-next branch, thanks.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center