linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <syrjala@sci.fi>
To: "Luis R. Rodriguez" <mcgrof@suse.com>
Cc: Andy Lutomirski <luto@amacapital.net>,
	Bjorn Helgaas <bhelgaas@google.com>,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>,
	Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Juergen Gross <jgross@suse.com>,
	Jan Beulich <JBeulich@suse.com>, Borislav Petkov <bp@suse.de>,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	venkatesh.pallipadi@intel.com, Dave Airlie <airlied@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Linux Fbdev development list <linux-fbdev@vger.kernel.org>,
	X86 ML <x86@kernel.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Antonino Daplas <adaplas@gmail.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Date: Sat, 28 Mar 2015 12:23:34 +0000	[thread overview]
Message-ID: <20150328122334.GA32543@sci.fi> (raw)
In-Reply-To: <20150328002818.GT5622@wotan.suse.de>

On Sat, Mar 28, 2015 at 01:28:18AM +0100, Luis R. Rodriguez wrote:
> On Fri, Mar 27, 2015 at 03:02:10PM -0700, Andy Lutomirski wrote:
> > On Fri, Mar 27, 2015 at 2:56 PM, Ville Syrjälä <syrjala@sci.fi> wrote:
> > > On Fri, Mar 27, 2015 at 08:57:59PM +0100, Luis R. Rodriguez wrote:
> > >> On Fri, Mar 27, 2015 at 12:43:55PM -0700, Andy Lutomirski wrote:
> > >> > On Fri, Mar 27, 2015 at 12:38 PM, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> > >> > > On Sat, Mar 21, 2015 at 11:15:14AM +0200, Ville Syrjälä wrote:
> > >> > >> On Fri, Mar 20, 2015 at 04:17:59PM -0700, Luis R. Rodriguez wrote:
> > >> > >> > diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
> > >> > >> > index 8025624..8875e56 100644
> > >> > >> > --- a/drivers/video/fbdev/aty/atyfb_base.c
> > >> > >> > +++ b/drivers/video/fbdev/aty/atyfb_base.c
> > >> > >> > @@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)
> > >> > >> >
> > >> > >> >  #ifdef CONFIG_MTRR
> > >> > >> >     par->mtrr_aper = -1;
> > >> > >> > -   par->mtrr_reg = -1;
> > >> > >> >     if (!nomtrr) {
> > >> > >> > -           /* Cover the whole resource. */
> > >> > >> > -           par->mtrr_aper = mtrr_add(par->res_start, par->res_size,
> > >> > >> > +           par->mtrr_aper = mtrr_add(info->fix.smem_start,
> > >> > >> > +                                     info->fix.smem_len,
> > >> > >> >                                       MTRR_TYPE_WRCOMB, 1);
> > >> > >>
> > >> > >> MTRRs need power of two size, so how is this supposed to work?
> > >> > >
> > >> > > As per mtrr_add_page() [0] the base and size are just supposed to be in units
> > >> > > of 4 KiB, although the practice is to use powers of 2 in *some* drivers this
> > >> > > is not standardized and by no means recorded as a requirement. Obviously
> > >> > > powers of 2 will work too and you'd end up neatly aligned as well. mtrr_add()
> > >> > > will use mtrr_check() to verify the the same requirement. Furthermore,
> > >> > > as per my commit log message:
> > >> >
> > >> > Whatever the code may or may not do, the x86 architecture uses
> > >> > power-of-two MTRR sizes.  So I'm confused.
> > >>
> > >> There should be no confusion, I simply did not know that *was* the
> > >> requirement for x86, if that is the case we should add a check for that
> > >> and perhaps generalize a helper that does the power of two helper changes,
> > >> the cleanest I found was the vesafb driver solution.
> > >>
> > >> Thoughts?
> > >
> > > The vesafb solution is bad since you'll only end up covering only
> > > the first 4MB of the framebuffer instead of the almost 8MB you want.
> > > Which in practice will mean throwing away half the VRAM since you really
> > > don't want the massive performance hit from accessing it as UC. And that
> > > would mean giving up decent display resolutions as well :(
> > >
> > > And the other option of trying to cover the remainder with multiple ever
> > > smaller MTRRs doesn't work either since you'll run out of MTRRs very
> > > quickly.
> > >
> > > This is precisely why I used the hole method in atyfb in the first
> > > place.
> > >
> > > I don't really like the idea of any new mtrr code not supporting that
> > > use case, especially as these things tend to be present in older machines
> > > where PAT isn't an option.
> > 
> > According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6,
> > non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have
> > an effective memory type of UC.  Hence my suggestion to add
> > ioremap_x86_uc and/or set_memory_x86_uc to punch a UC hole in an
> > otherwise WC MTRR-covered region.
> 
> OK I think I get it now.
> 
> And I take it this would hopefully only be used for non-PAT systems?
> Would there be a use case for PAT systems? I wonder if we can wrap
> this under some APIs to make it clean and hide this dirty thing
> behind the scenes, it seems a fragile and error prone and my hope
> would be that we won't need more specialization in this area for
> PAT systems.

One potential complication is kernel vs. userspace mmap. MTRR applies to
the physical address, but PAT applies to the virtual address, so with
the WC MTRR you get WC for userspace "for free" as well. Also the
userspace mmaps request will have the length of smem_len (at most), so
it won't be the nice power of two in that case.

Also on PAT systems w/o a BIOS provided WC MTRR, the fbdev mmap seems
to be total crap at the moment. IIRC I have a patch to fix things a bit...

From 4e6d70d223f35953c8a11a58cf3376a8a001fa4f Mon Sep 17 00:00:00 2001
From: Ville Syrjala <syrjala@sci.fi>
Date: Fri, 15 Apr 2011 04:02:43 +0300
Subject: [PATCH] fb: writecombine fb

---
 drivers/video/fbdev/core/fbmem.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 0705d88..ecbde0e 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1396,6 +1396,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
 	unsigned long mmio_pgoff;
 	unsigned long start;
 	u32 len;
+	bool mmio = false;
 
 	if (!info)
 		return -ENODEV;
@@ -1426,11 +1427,20 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
 		vma->vm_pgoff -= mmio_pgoff;
 		start = info->fix.mmio_start;
 		len = info->fix.mmio_len;
+		mmio = true;
 	}
 	mutex_unlock(&info->mm_lock);
 
+	if (!mmio) {
+		vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
+		vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+
+		if (!vm_iomap_memory(vma, start, len))
+			return 0;
+	}
+
 	vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
-	fb_pgprotect(file, vma, start);
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return vm_iomap_memory(vma, start, len);
 }

Perhaps it's time I tried to send that upstream properly :P

-- 
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/

  reply	other threads:[~2015-03-28 12:23 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 23:17 [PATCH v1 00/47] mtrr/x86/drivers: bury MTRR Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 01/47] x86: mtrr: annotate mtrr_type_lookup() is only implemented on generic_mtrr_ops Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR Luis R. Rodriguez
2015-03-25 19:59   ` Konrad Rzeszutek Wilk
2015-03-26  4:38     ` Juergen Gross
2015-03-26 23:35     ` Luis R. Rodriguez
2015-04-02 20:13       ` Bjorn Helgaas
2015-04-02 20:20         ` Luis R. Rodriguez
2015-04-02 20:28           ` Bjorn Helgaas
2015-04-02 21:02             ` Luis R. Rodriguez
2015-04-02 22:09               ` Bjorn Helgaas
2015-04-02 22:12                 ` [Xen-devel] " Luis R. Rodriguez
2015-03-27 20:40   ` Toshi Kani
2015-03-27 23:56     ` Luis R. Rodriguez
2015-04-02 21:49       ` Luis R. Rodriguez
2015-04-02 23:52         ` Toshi Kani
2015-04-03  1:08           ` Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 03/47] devres: add devm_ioremap_wc() Luis R. Rodriguez
2015-03-20 23:49   ` Andy Lutomirski
2015-03-25 19:50     ` Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 04/47] pci: add pci_ioremap_wc_bar() Luis R. Rodriguez
2015-03-20 23:50   ` Andy Lutomirski
2015-03-25 20:06     ` Luis R. Rodriguez
2015-03-25 20:03   ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-03-25 20:39     ` Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 05/47] pci: add pci_iomap_wc() variants Luis R. Rodriguez
2015-03-23 17:20   ` Bjorn Helgaas
2015-03-26  3:00     ` Luis R. Rodriguez
2015-03-27 19:18     ` Toshi Kani
2015-04-21 19:25     ` Michael S. Tsirkin
2015-04-21 19:27       ` Luis R. Rodriguez
2015-03-25 20:07   ` Konrad Rzeszutek Wilk
2015-03-27 18:40     ` Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 06/47] mtrr: add __arch_phys_wc_add() Luis R. Rodriguez
2015-03-20 23:48   ` Andy Lutomirski
2015-03-27 19:53     ` Luis R. Rodriguez
2015-03-27 19:58       ` Andy Lutomirski
2015-03-27 20:30         ` Luis R. Rodriguez
2015-03-27 21:23           ` Andy Lutomirski
2015-03-27 23:04             ` Luis R. Rodriguez
2015-03-27 23:10               ` Andy Lutomirski
2015-03-27 23:33                 ` Luis R. Rodriguez
2015-04-02 20:21   ` Bjorn Helgaas
2015-04-02 20:55     ` Luis R. Rodriguez
2015-04-02 22:35       ` Bjorn Helgaas
2015-04-02 22:54         ` Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 07/47] video: fbdev: atyfb: move framebuffer length fudging to helper Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 08/47] video: fbdev: atyfb: clarify ioremap() base and length used Luis R. Rodriguez
2015-03-20 23:17 ` [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around Luis R. Rodriguez
2015-03-20 23:52   ` Andy Lutomirski
2015-03-27 20:12     ` Luis R. Rodriguez
2015-03-27 21:21       ` Andy Lutomirski
2015-03-27 23:31         ` Luis R. Rodriguez
2015-03-21  9:15   ` Ville Syrjälä
2015-03-27  8:37     ` Ville Syrjälä
2015-03-27 19:38       ` Luis R. Rodriguez
2015-03-27 19:38     ` Luis R. Rodriguez
2015-03-27 19:43       ` Andy Lutomirski
2015-03-27 19:57         ` Luis R. Rodriguez
2015-03-27 21:56           ` Ville Syrjälä
2015-03-27 22:02             ` Andy Lutomirski
2015-03-28  0:28               ` Luis R. Rodriguez
2015-03-28 12:23                 ` Ville Syrjälä [this message]
2015-04-01 23:52                   ` Luis R. Rodriguez
2015-04-02  0:04                     ` Andy Lutomirski
2015-04-02 19:45                       ` Luis R. Rodriguez
2015-04-02 19:50                         ` Andy Lutomirski
2015-03-28  0:21             ` Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 10/47] video: fbdev: atyfb: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 11/47] IB/qib: add acounting for MTRR Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 12/47] IB/qib: use arch_phys_wc_add() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 13/47] IB/ipath: add counting for MTRR Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 14/47] IB/ipath: use __arch_phys_wc_add() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 15/47] [media] media: ivtv: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 16/47] fusion: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 17/47] video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 18/47] vidoe: fbdev: vesafb: add missing mtrr_del() for added MTRR Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 19/47] video: fbdev: vesafb: use arch_phys_wc_add() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 20/47] mtrr: avoid ifdef'ery with phys_wc_to_mtrr_index() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 21/47] ethernet: myri10ge: use arch_phys_wc_add() Luis R. Rodriguez
2015-03-21  7:08   ` Hyong-Youb Kim
2015-03-27 20:36     ` Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 22/47] staging: sm750fb: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 23/47] staging: xgifb: " Luis R. Rodriguez
2015-04-30 17:40   ` Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 24/47] video: fbdev: arkfb: use arch_phys_wc_add() and pci_iomap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 25/47] video: fbdev: radeonfb: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 26/47] video: fbdev: gbefb: add missing mtrr_del() calls Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 27/47] video: fbdev: gbefb: use arch_phys_wc_add() and devm_ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 28/47] video: fbdev: intelfb: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 29/47] video: fbdev: matrox: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 30/47] video: fbdev: neofb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 31/47] video: fbdev: s3fb: use arch_phys_wc_add() and pci_iomap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 32/47] video: fbdev: nvidia: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 33/47] video: fbdev: savagefb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 34/47] video: fbdev: sisfb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 35/47] video: fbdev: aty: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 36/47] video: fbdev: i810: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 37/47] video: fbdev: i740fb: use arch_phys_wc_add() and pci_ioremap_wc_bar() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 38/47] video: fbdev: kyrofb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 39/47] video: fbdev: pm2fb: use arch_phys_wc_add() and ioremap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 40/47] video: fbdev: pm3fb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 41/47] video: fbdev: rivafb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 42/47] video: fbdev: tdfxfb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 43/47] video: fbdev: vt8623fb: use arch_phys_wc_add() and pci_iomap_wc() Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 44/47] video: fbdev: atmel_lcdfb: use ioremap_wc() for framebuffer Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 45/47] video: fbdev: geode gxfb: " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 46/47] video: fbdev: gxt4500: use pci_ioremap_wc_bar() " Luis R. Rodriguez
2015-03-20 23:18 ` [PATCH v1 47/47] mtrr: bury MTRR - unexport mtrr_add() and mtrr_del() Luis R. Rodriguez
2015-03-21  1:08 ` [PATCH v1 00/47] mtrr/x86/drivers: bury MTRR Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150328122334.GA32543@sci.fi \
    --to=syrjala@sci.fi \
    --cc=JBeulich@suse.com \
    --cc=adaplas@gmail.com \
    --cc=airlied@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=bp@suse.de \
    --cc=daniel.vetter@ffwll.ch \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mcgrof@do-not-panic.com \
    --cc=mcgrof@suse.com \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=plagnioj@jcrosoft.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tomi.valkeinen@ti.com \
    --cc=torvalds@linux-foundation.org \
    --cc=venkatesh.pallipadi@intel.com \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).