Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751666AbZJWE6s (ORCPT ); Fri, 23 Oct 2009 00:58:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751041AbZJWE6r (ORCPT ); Fri, 23 Oct 2009 00:58:47 -0400 Received: from mga09.intel.com ([134.134.136.24]:50925 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750864AbZJWE6r (ORCPT ); Fri, 23 Oct 2009 00:58:47 -0400 X-ExtLoop1: 1 Subject: Re: [RFC Patch] use MTRR for write combining if PAT is not available From: Suresh Siddha Reply-To: Suresh Siddha To: Jesse Barnes Cc: Eric Anholt , Thomas Hellstrom , Jeremy Fitzhardinge , "H. Peter Anvin" , Arjan van de Ven , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Jan Beulich , Ingo Molnar , Thomas Gleixner , Henrique de Moraes Holschuh , "Pallipadi, Venkatesh" , Tejun Heo , Thomas Schlichter , "dri-devel@lists.sourceforge.net" , Yinghai Lu , Ingo Molnar , Robert Hancock In-Reply-To: <20091023133152.1a15ba69@jbarnes-x200> References: <1394846127@web.de> <4ADF32A0020000780001B20A@vpn.id2.novell.com> <20091021173514.GA32227@elte.hu> <200910212201.36578.thomas.schlichter@web.de> <1256205210.2530.28.camel@sbs-t61> <1256225689.32075.6.camel@gaiman.anholt.net> <1256248050.2546.9.camel@sbs-t61> <20091023081047.4d8abc29@jbarnes-x200> <1256256717.2534.6.camel@sbs-t61> <1256262799.15120.8.camel@gaiman.anholt.net> <20091023133152.1a15ba69@jbarnes-x200> Content-Type: text/plain Organization: Intel Corp Date: Thu, 22 Oct 2009 21:58:15 -0700 Message-Id: <1256273896.2569.10.camel@sbs-t61> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2376 Lines: 65 On Thu, 2009-10-22 at 21:31 -0700, Jesse Barnes wrote: > Here's a quick & dirty version, totally untested. A cleaner approach > would be to separate the WC mapping routines and hide the return > -EINVAL in arch specific code... Jesse How about this patch? Doing this in x86 is cleaner. I would like Acks/sign-offs-by Thomas, Eric and Jesse, if it is ok with this patch and works. thanks, suresh --- From: Suresh Siddha Subject: x86, pat: return EINVAL for pci mmap WC request for !pat_enabled Thomas Schlichter reported: > 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: > 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). Reported-by: Thomas Schlichter Signed-off-by: Suresh Siddha --- diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c index b22d13b..a672f12 100644 --- a/arch/x86/pci/i386.c +++ b/arch/x86/pci/i386.c @@ -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) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/