* Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
[not found] ` <1430343372-687-2-git-send-email-mcgrof@do-not-panic.com>
@ 2015-04-30 15:59 ` Bjorn Helgaas
2015-04-30 16:52 ` Luis R. Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2015-04-30 15:59 UTC (permalink / raw)
To: Luis R. Rodriguez
Cc: mst, plagnioj, tomi.valkeinen, airlied, daniel.vetter,
linux-fbdev, luto, cocci, linux-kernel, Luis R. Rodriguez,
Toshi Kani, Suresh Siddha, Ingo Molnar, Thomas Gleixner,
Juergen Gross, Daniel Vetter, Dave Airlie, Antonino Daplas,
Dave Hansen, Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
[+cc linux-pci]
Hi Luis,
On Wed, Apr 29, 2015 at 02:36:08PM -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>
> This allows drivers to take advantage of write-combining
> when possible. Ideally we'd have pci_read_bases() just
> peg an IORESOURCE_WC flag for us
This makes it sound like pci_read_bases() could do a better job
if we just tried harder, but I don't think that's the case. All
pci_read_bases() can do is look at the bits in the BAR. For
memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
If you just want to complain that the PCI spec didn't define a
way for software to discover whether a BAR can be mapped with WC,
that's fine, but it's misleading to suggest that pci_read_bases()
could figure out WC without some help from the spec.
> but where exactly
> video devices memory lie varies *largely* and at times things
> are mixed with MMIO registers, sometimes we can address
> the changes in drivers, other times the change requires
> intrusive changes.
>
> Although there is also arch_phys_wc_add() that makes use of
> architecture specific write-combining alternatives (MTRR on
> x86 when a system does not have PAT) we void polluting
> pci_iomap() space with it and force drivers and subsystems
> that want to use it to be explicit.
I'm not quite sure I understand the point you're making here
about not polluting pci_iomap_wc() with arch_phys_wc_add(). I
think the choice is for a driver to do either this:
info->screen_base = pci_iomap_wc(dev, 0, 0);
or this:
info->screen_base = pci_iomap_wc(dev, 0, 0);
par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0),
pci_resource_len(dev, 0));
The driver is *already* being explicit because it calls
pci_iomap_wc() instead of pci_iomap().
It seems like it would be ideal if ioremap_wc() could call
arch_phys_wc_add() internally. Doesn't any caller of
arch_phys_wc_add() have to also do some sort of ioremap()
beforehand? I assume there's some reason for separating them,
and I see that the current arch_phys_wc_add() requires the caller
to store a handle, but doing both seems confusing.
> There are a few motivations for this:
>
> a) Take advantage of PAT when available
>
> b) Help bury MTRR code away, MTRR is architecture specific and on
> x86 its replaced by PAT
>
> c) Help with the goal of eventually using _PAGE_CACHE_UC over
> _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit
> de33c442e titled "x86 PAT: fix performance drop for glx,
> use UC minus for ioremap(), ioremap_nocache() and
> pci_mmap_page_range()")
I think these are now _PAGE_CACHE_MODE_UC and
_PAGE_CACHE_MODE_UC_MINUS, right?
> ...
> +void __iomem *pci_iomap_wc_range(struct pci_dev *dev,
> + int bar,
> + unsigned long offset,
> + unsigned long maxlen)
> +{
> + resource_size_t start = pci_resource_start(dev, bar);
> + resource_size_t len = pci_resource_len(dev, bar);
> + unsigned long flags = pci_resource_flags(dev, bar);
> +
> + if (len <= offset || !start)
> + return NULL;
> + len -= offset;
> + start += offset;
> + if (maxlen && len > maxlen)
> + len = maxlen;
> + if (flags & IORESOURCE_IO)
> + return __pci_ioport_map(dev, start, len);
Is there any point in checking for IORESOURCE_IO? If a driver
calls pci_iomap_wc_range(), I assume it already knows this is an
IORESOURCE_MEM BAR, so if we see IORESOURCE_IO here we should
just return an error, i.e., NULL.
> + if (flags & IORESOURCE_MEM)
> + return ioremap_wc(start, len);
> + /* What? */
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(pci_iomap_wc_range);
Bjorn
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
[not found] ` <1430343372-687-3-git-send-email-mcgrof@do-not-panic.com>
@ 2015-04-30 16:26 ` Bjorn Helgaas
2015-04-30 17:27 ` Luis R. Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2015-04-30 16:26 UTC (permalink / raw)
To: Luis R. Rodriguez
Cc: mst, plagnioj, tomi.valkeinen, airlied, daniel.vetter,
linux-fbdev, luto, cocci, linux-kernel, Luis R. Rodriguez,
Toshi Kani, Suresh Siddha, Ingo Molnar, Thomas Gleixner,
Juergen Gross, Daniel Vetter, Dave Airlie, Antonino Daplas,
Dave Hansen, Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
[+cc linux-pci]
Hi Luis,
On Wed, Apr 29, 2015 at 02:36:09PM -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>
> Now that we have pci_iomap_wc() add the respective devres helpers.
I guess I'm still confused about the relationship between pci_iomap_wc()
and arch_phys_wc_add().
Do you expect every caller of pcim_iomap_wc() to also call
arch_phys_wc_add()?
If so, I'm not sure how pcim_iomap_wc() fits into the picture. A driver
can call both pcim_iomap_wc() and arch_phys_wc_add(), but the driver
doesn't explicitly do the unmap, so where would the arch_phys_wc_del()
happen?
If not, how does a driver know whether it should call arch_phys_wc_add()?
> ...
> /**
> + * pcim_iomap_wc_regions - Request and iomap PCI BARs with write-combining
> + * @pdev: PCI device to map IO resources for
> + * @mask: Mask of BARs to request and iomap
> + * @name: Name used when requesting regions
> + *
> + * Request and iomap regions specified by @mask with a preference for
> + * write-combining.
> + */
> +int pcim_iomap_wc_regions(struct pci_dev *pdev, int mask, const char *name)
> +{
> + void __iomem * const *iomap;
> + int i, rc;
> +
> + iomap = pcim_iomap_table(pdev);
> + if (!iomap)
> + return -ENOMEM;
> +
> + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
> + unsigned long len;
> +
> + if (!(mask & (1 << i)))
> + continue;
> +
> + rc = -EINVAL;
> + len = pci_resource_len(pdev, i);
> + if (!len)
> + goto err_inval;
> +
> + rc = pci_request_region(pdev, i, name);
> + if (rc)
> + goto err_inval;
> +
> + rc = -ENOMEM;
> + if (!pcim_iomap_wc(pdev, i, 0))
> + goto err_region;
Is there a user for this? Are there really devices where *all* the BARs
can be mapped with WC? Are there enough of them to make it worth adding
this?
I don't see users of either pcim_iomap_wc() or pcim_iomap_wc_regions() so
far. Did I miss them, or do you just expect them in the near future?
Bjorn
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
2015-04-30 15:59 ` [PATCH v4 1/5] pci: add pci_iomap_wc() variants Bjorn Helgaas
@ 2015-04-30 16:52 ` Luis R. Rodriguez
2015-04-30 17:03 ` Andy Lutomirski
0 siblings, 1 reply; 8+ messages in thread
From: Luis R. Rodriguez @ 2015-04-30 16:52 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Luis R. Rodriguez, mst, plagnioj, tomi.valkeinen, airlied,
daniel.vetter, linux-fbdev, luto, cocci, linux-kernel, Toshi Kani,
Suresh Siddha, Ingo Molnar, Thomas Gleixner, Juergen Gross,
Daniel Vetter, Dave Airlie, Antonino Daplas, Dave Hansen,
Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
On Thu, Apr 30, 2015 at 10:59:17AM -0500, Bjorn Helgaas wrote:
> [+cc linux-pci]
>
> Hi Luis,
>
> On Wed, Apr 29, 2015 at 02:36:08PM -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> >
> > This allows drivers to take advantage of write-combining
> > when possible. Ideally we'd have pci_read_bases() just
> > peg an IORESOURCE_WC flag for us
>
> This makes it sound like pci_read_bases() could do a better job
> if we just tried harder, but I don't think that's the case. All
> pci_read_bases() can do is look at the bits in the BAR. For
> memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
>
> If you just want to complain that the PCI spec didn't define a
> way for software to discover whether a BAR can be mapped with WC,
> that's fine, but it's misleading to suggest that pci_read_bases()
> could figure out WC without some help from the spec.
You're right sorry about that, in my original patch this was more
of a question and I did not have a full answer for but mst had
clarified before the spec doesn't allow for this [0] and you are
confirming this now as well.
[0] https://lkml.org/lkml/2015/4/21/714
I'll update the patch and at least document we did think about
this and that its a shortcoming of the spec.
> > but where exactly
> > video devices memory lie varies *largely* and at times things
> > are mixed with MMIO registers, sometimes we can address
> > the changes in drivers, other times the change requires
> > intrusive changes.
> >
> > Although there is also arch_phys_wc_add() that makes use of
> > architecture specific write-combining alternatives (MTRR on
> > x86 when a system does not have PAT) we void polluting
> > pci_iomap() space with it and force drivers and subsystems
> > that want to use it to be explicit.
>
> I'm not quite sure I understand the point you're making here
> about not polluting pci_iomap_wc() with arch_phys_wc_add(). I
> think the choice is for a driver to do either this:
>
> info->screen_base = pci_iomap_wc(dev, 0, 0);
>
> or this:
>
> info->screen_base = pci_iomap_wc(dev, 0, 0);
> par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0),
> pci_resource_len(dev, 0));
>
> The driver is *already* being explicit because it calls
> pci_iomap_wc() instead of pci_iomap().
>
> It seems like it would be ideal if ioremap_wc() could call
> arch_phys_wc_add() internally.
Indeed, that's what I was alluding to.
> Doesn't any caller of
> arch_phys_wc_add() have to also do some sort of ioremap()
> beforehand?
This is not a requirement as the physical address is used,
not the virtual address.
> I assume there's some reason for separating them,
Well a full sweep to change to arch_phys_wc_add() was never done,
consider this part of the last effort to do so. In retrospect now
that I've covered all other drivers in 12 different series of patches
I think its perhaps best to not mesh them together as we're phasing
out MTRR and the only reason to have arch_phys_wc_add() is for MTRR
which is legacy.
I'll update the commit log to mention that.
> and I see that the current arch_phys_wc_add() requires the caller
> to store a handle, but doing both seems confusing.
That's just a cookie so that later when we undo the driver we can
tell the backend to remove it.
> > There are a few motivations for this:
> >
> > a) Take advantage of PAT when available
> >
> > b) Help bury MTRR code away, MTRR is architecture specific and on
> > x86 its replaced by PAT
> >
> > c) Help with the goal of eventually using _PAGE_CACHE_UC over
> > _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit
> > de33c442e titled "x86 PAT: fix performance drop for glx,
> > use UC minus for ioremap(), ioremap_nocache() and
> > pci_mmap_page_range()")
>
> I think these are now _PAGE_CACHE_MODE_UC and
> _PAGE_CACHE_MODE_UC_MINUS, right?
Indeed, thanks, I'll fix that in the commit log.
> > ...
>
> > +void __iomem *pci_iomap_wc_range(struct pci_dev *dev,
> > + int bar,
> > + unsigned long offset,
> > + unsigned long maxlen)
> > +{
> > + resource_size_t start = pci_resource_start(dev, bar);
> > + resource_size_t len = pci_resource_len(dev, bar);
> > + unsigned long flags = pci_resource_flags(dev, bar);
> > +
> > + if (len <= offset || !start)
> > + return NULL;
> > + len -= offset;
> > + start += offset;
> > + if (maxlen && len > maxlen)
> > + len = maxlen;
> > + if (flags & IORESOURCE_IO)
> > + return __pci_ioport_map(dev, start, len);
>
> Is there any point in checking for IORESOURCE_IO? If a driver
> calls pci_iomap_wc_range(), I assume it already knows this is an
> IORESOURCE_MEM BAR, so if we see IORESOURCE_IO here we should
> just return an error, i.e., NULL.
Agreed, will fix with all the other changes on the commit log and
repost. I won't repost the full series but just this one patch as
a v5.
Thanks for the review.
Luis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
2015-04-30 16:52 ` Luis R. Rodriguez
@ 2015-04-30 17:03 ` Andy Lutomirski
2015-04-30 17:15 ` Luis R. Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Andy Lutomirski @ 2015-04-30 17:03 UTC (permalink / raw)
To: Luis R. Rodriguez
Cc: Bjorn Helgaas, Luis R. Rodriguez, Michael S. Tsirkin,
Jean-Christophe Plagniol-Villard, Tomi Valkeinen, David Airlie,
daniel.vetter, Linux Fbdev development list, cocci,
linux-kernel@vger.kernel.org, Toshi Kani, Suresh Siddha,
Ingo Molnar, Thomas Gleixner, Juergen Gross, Daniel Vetter,
Dave Airlie, Antonino Daplas, Dave Hansen, Arnd Bergmann,
venkatesh.pallipadi, Stefan Bader, Ville Syrjälä,
Mel Gorman, Vlastimil Babka, Borislav Petkov, Davidlohr Bueso,
Konrad Rzeszutek Wilk, ville.syrjala, David Vrabel, Jan Beulich,
Roger Pau Monné, xen-devel, linux-pci@vger.kernel.org
On Thu, Apr 30, 2015 at 9:52 AM, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> On Thu, Apr 30, 2015 at 10:59:17AM -0500, Bjorn Helgaas wrote:
>> [+cc linux-pci]
>>
>> Hi Luis,
>>
>> On Wed, Apr 29, 2015 at 02:36:08PM -0700, Luis R. Rodriguez wrote:
>> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
>> >
>> > This allows drivers to take advantage of write-combining
>> > when possible. Ideally we'd have pci_read_bases() just
>> > peg an IORESOURCE_WC flag for us
>>
>> This makes it sound like pci_read_bases() could do a better job
>> if we just tried harder, but I don't think that's the case. All
>> pci_read_bases() can do is look at the bits in the BAR. For
>> memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
>>
>> If you just want to complain that the PCI spec didn't define a
>> way for software to discover whether a BAR can be mapped with WC,
>> that's fine, but it's misleading to suggest that pci_read_bases()
>> could figure out WC without some help from the spec.
>
> You're right sorry about that, in my original patch this was more
> of a question and I did not have a full answer for but mst had
> clarified before the spec doesn't allow for this [0] and you are
> confirming this now as well.
>
> [0] https://lkml.org/lkml/2015/4/21/714
>
> I'll update the patch and at least document we did think about
> this and that its a shortcoming of the spec.
>
>> > but where exactly
>> > video devices memory lie varies *largely* and at times things
>> > are mixed with MMIO registers, sometimes we can address
>> > the changes in drivers, other times the change requires
>> > intrusive changes.
>> >
>> > Although there is also arch_phys_wc_add() that makes use of
>> > architecture specific write-combining alternatives (MTRR on
>> > x86 when a system does not have PAT) we void polluting
>> > pci_iomap() space with it and force drivers and subsystems
>> > that want to use it to be explicit.
>>
>> I'm not quite sure I understand the point you're making here
>> about not polluting pci_iomap_wc() with arch_phys_wc_add(). I
>> think the choice is for a driver to do either this:
>>
>> info->screen_base = pci_iomap_wc(dev, 0, 0);
>>
>> or this:
>>
>> info->screen_base = pci_iomap_wc(dev, 0, 0);
>> par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0),
>> pci_resource_len(dev, 0));
>>
>> The driver is *already* being explicit because it calls
>> pci_iomap_wc() instead of pci_iomap().
>>
>> It seems like it would be ideal if ioremap_wc() could call
>> arch_phys_wc_add() internally.
>
> Indeed, that's what I was alluding to.
>
>> Doesn't any caller of
>> arch_phys_wc_add() have to also do some sort of ioremap()
>> beforehand?
>
> This is not a requirement as the physical address is used,
> not the virtual address.
>
>> I assume there's some reason for separating them,
>
> Well a full sweep to change to arch_phys_wc_add() was never done,
> consider this part of the last effort to do so. In retrospect now
> that I've covered all other drivers in 12 different series of patches
> I think its perhaps best to not mesh them together as we're phasing
> out MTRR and the only reason to have arch_phys_wc_add() is for MTRR
> which is legacy.
I would say it much more strongly.
Drivers for new hardware SHOULD NOT call arch_phys_wc_add, directly or
otherwise. MTRRs are crap. They have nasty alignment requirements,
they are a very limited and unpredictable resource, and the interact
poorly with BIOS. They should really only be used for old video
framebuffers and such.
Anything new should use PAT (it's been available for a long time) and
possibly streaming memory writes. Even fancy server gear (myri10ge,
for example) should stay far away from MTRRs and such: it's very easy
to put enough devices in a server board that you simply run out of
MTRRs and arch_phys_wc_add will stop working.
If we make ioremap_wc and similar start automatically adding MTRRs,
then performance will vary wildly with the order of driver loading,
because we'll run out of MTRRs part-way through bootup.
ioremap_wc via PAT, on the other hand, is 100% reliable on newer hardware.
Maybe I should have called it arch_phys_wc_add_awful_legacy_hack.
--Andy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
2015-04-30 17:03 ` Andy Lutomirski
@ 2015-04-30 17:15 ` Luis R. Rodriguez
0 siblings, 0 replies; 8+ messages in thread
From: Luis R. Rodriguez @ 2015-04-30 17:15 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Bjorn Helgaas, Luis R. Rodriguez, Michael S. Tsirkin,
Jean-Christophe Plagniol-Villard, Tomi Valkeinen, David Airlie,
daniel.vetter, Linux Fbdev development list, cocci,
linux-kernel@vger.kernel.org, Toshi Kani, Suresh Siddha,
Ingo Molnar, Thomas Gleixner, Juergen Gross, Daniel Vetter,
Dave Airlie, Antonino Daplas, Dave Hansen, Arnd Bergmann,
venkatesh.pallipadi, Stefan Bader, Ville Syrjälä,
Mel Gorman, Vlastimil Babka, Borislav Petkov, Davidlohr Bueso,
Konrad Rzeszutek Wilk, ville.syrjala, David Vrabel, Jan Beulich,
Roger Pau Monné, xen-devel, linux-pci@vger.kernel.org
On Thu, Apr 30, 2015 at 10:03:18AM -0700, Andy Lutomirski wrote:
> On Thu, Apr 30, 2015 at 9:52 AM, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> > On Thu, Apr 30, 2015 at 10:59:17AM -0500, Bjorn Helgaas wrote:
> >> [+cc linux-pci]
> >>
> >> Hi Luis,
> >>
> >> On Wed, Apr 29, 2015 at 02:36:08PM -0700, Luis R. Rodriguez wrote:
> >> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> >> >
> >> > This allows drivers to take advantage of write-combining
> >> > when possible. Ideally we'd have pci_read_bases() just
> >> > peg an IORESOURCE_WC flag for us
> >>
> >> This makes it sound like pci_read_bases() could do a better job
> >> if we just tried harder, but I don't think that's the case. All
> >> pci_read_bases() can do is look at the bits in the BAR. For
> >> memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
> >>
> >> If you just want to complain that the PCI spec didn't define a
> >> way for software to discover whether a BAR can be mapped with WC,
> >> that's fine, but it's misleading to suggest that pci_read_bases()
> >> could figure out WC without some help from the spec.
> >
> > You're right sorry about that, in my original patch this was more
> > of a question and I did not have a full answer for but mst had
> > clarified before the spec doesn't allow for this [0] and you are
> > confirming this now as well.
> >
> > [0] https://lkml.org/lkml/2015/4/21/714
> >
> > I'll update the patch and at least document we did think about
> > this and that its a shortcoming of the spec.
> >
> >> > but where exactly
> >> > video devices memory lie varies *largely* and at times things
> >> > are mixed with MMIO registers, sometimes we can address
> >> > the changes in drivers, other times the change requires
> >> > intrusive changes.
> >> >
> >> > Although there is also arch_phys_wc_add() that makes use of
> >> > architecture specific write-combining alternatives (MTRR on
> >> > x86 when a system does not have PAT) we void polluting
> >> > pci_iomap() space with it and force drivers and subsystems
> >> > that want to use it to be explicit.
> >>
> >> I'm not quite sure I understand the point you're making here
> >> about not polluting pci_iomap_wc() with arch_phys_wc_add(). I
> >> think the choice is for a driver to do either this:
> >>
> >> info->screen_base = pci_iomap_wc(dev, 0, 0);
> >>
> >> or this:
> >>
> >> info->screen_base = pci_iomap_wc(dev, 0, 0);
> >> par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0),
> >> pci_resource_len(dev, 0));
> >>
> >> The driver is *already* being explicit because it calls
> >> pci_iomap_wc() instead of pci_iomap().
> >>
> >> It seems like it would be ideal if ioremap_wc() could call
> >> arch_phys_wc_add() internally.
> >
> > Indeed, that's what I was alluding to.
> >
> >> Doesn't any caller of
> >> arch_phys_wc_add() have to also do some sort of ioremap()
> >> beforehand?
> >
> > This is not a requirement as the physical address is used,
> > not the virtual address.
> >
> >> I assume there's some reason for separating them,
> >
> > Well a full sweep to change to arch_phys_wc_add() was never done,
> > consider this part of the last effort to do so. In retrospect now
> > that I've covered all other drivers in 12 different series of patches
> > I think its perhaps best to not mesh them together as we're phasing
> > out MTRR and the only reason to have arch_phys_wc_add() is for MTRR
> > which is legacy.
>
> I would say it much more strongly.
>
> Drivers for new hardware SHOULD NOT call arch_phys_wc_add, directly or
> otherwise. MTRRs are crap. They have nasty alignment requirements,
> they are a very limited and unpredictable resource, and the interact
> poorly with BIOS. They should really only be used for old video
> framebuffers and such.
>
> Anything new should use PAT (it's been available for a long time) and
> possibly streaming memory writes. Even fancy server gear (myri10ge,
> for example) should stay far away from MTRRs and such: it's very easy
> to put enough devices in a server board that you simply run out of
> MTRRs and arch_phys_wc_add will stop working.
>
> If we make ioremap_wc and similar start automatically adding MTRRs,
> then performance will vary wildly with the order of driver loading,
> because we'll run out of MTRRs part-way through bootup.
>
> ioremap_wc via PAT, on the other hand, is 100% reliable on newer hardware.
>
> Maybe I should have called it arch_phys_wc_add_awful_legacy_hack.
Thanks, I'll document such technicalities as well ;)
Luis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
2015-04-30 16:26 ` [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants Bjorn Helgaas
@ 2015-04-30 17:27 ` Luis R. Rodriguez
2015-04-30 21:46 ` Bjorn Helgaas
0 siblings, 1 reply; 8+ messages in thread
From: Luis R. Rodriguez @ 2015-04-30 17:27 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Luis R. Rodriguez, mst, plagnioj, tomi.valkeinen, airlied,
daniel.vetter, linux-fbdev, luto, cocci, linux-kernel, Toshi Kani,
Suresh Siddha, Ingo Molnar, Thomas Gleixner, Juergen Gross,
Daniel Vetter, Dave Airlie, Antonino Daplas, Dave Hansen,
Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
On Thu, Apr 30, 2015 at 11:26:47AM -0500, Bjorn Helgaas wrote:
> [+cc linux-pci]
>
> Hi Luis,
>
> On Wed, Apr 29, 2015 at 02:36:09PM -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> >
> > Now that we have pci_iomap_wc() add the respective devres helpers.
>
> I guess I'm still confused about the relationship between pci_iomap_wc()
> and arch_phys_wc_add().
>
> Do you expect every caller of pcim_iomap_wc() to also call
> arch_phys_wc_add()?
Yeap.
> If so, I'm not sure how pcim_iomap_wc() fits into the picture. A driver
> can call both pcim_iomap_wc() and arch_phys_wc_add(), but the driver
> doesn't explicitly do the unmap, so where would the arch_phys_wc_del()
> happen?
As with other current drivers not using devres, upon exit or where they
would otherwise typically iounmap().
> If not, how does a driver know whether it should call arch_phys_wc_add()?
Sadly they'd have to figure it out, as Andy notes arch_phys_wc_add() is
a hack so I think we need to leave it as such and hope to see arch_phys_wc_add()
use phased as it won't be needed anymore really. arch_phys_wc_add() really should
only be used by device drivers that know that are working with non-PAT systems.
The code already takes care of this but since its an x86 write-combining hack
we should not consider meshing it with devres.
> > ...
> > /**
> > + * pcim_iomap_wc_regions - Request and iomap PCI BARs with write-combining
> > + * @pdev: PCI device to map IO resources for
> > + * @mask: Mask of BARs to request and iomap
> > + * @name: Name used when requesting regions
> > + *
> > + * Request and iomap regions specified by @mask with a preference for
> > + * write-combining.
> > + */
> > +int pcim_iomap_wc_regions(struct pci_dev *pdev, int mask, const char *name)
> > +{
> > + void __iomem * const *iomap;
> > + int i, rc;
> > +
> > + iomap = pcim_iomap_table(pdev);
> > + if (!iomap)
> > + return -ENOMEM;
> > +
> > + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
> > + unsigned long len;
> > +
> > + if (!(mask & (1 << i)))
> > + continue;
> > +
> > + rc = -EINVAL;
> > + len = pci_resource_len(pdev, i);
> > + if (!len)
> > + goto err_inval;
> > +
> > + rc = pci_request_region(pdev, i, name);
> > + if (rc)
> > + goto err_inval;
> > +
> > + rc = -ENOMEM;
> > + if (!pcim_iomap_wc(pdev, i, 0))
> > + goto err_region;
>
> Is there a user for this? Are there really devices where *all* the BARs
> can be mapped with WC? Are there enough of them to make it worth adding
> this?
Not right now, I did this more to help with a friend who is testing one
driver for a feature. The driver is upstream but a way to make the feature
take effect only under certain conditions still would need to be done.
> I don't see users of either pcim_iomap_wc() or pcim_iomap_wc_regions() so
> far. Did I miss them, or do you just expect them in the near future?
The later, and also I hate seeing folks later add code under EXPORT_SYMBOL()
rather than EXPORT_SYMBOL_GPL() so I figure I'd rather do it first. It happened
recently in my v1 series, someone beat me to a write-combining export symbol
and changed it to EXPORT_SYMBOL(). Feel free to drop this though but I hope
no one out there then tries to just add an EXPORT_SYMBOL() later for this...
Luis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
2015-04-30 17:27 ` Luis R. Rodriguez
@ 2015-04-30 21:46 ` Bjorn Helgaas
2015-05-01 0:20 ` Luis R. Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2015-04-30 21:46 UTC (permalink / raw)
To: Luis R. Rodriguez
Cc: Luis R. Rodriguez, mst, plagnioj, tomi.valkeinen, airlied,
daniel.vetter, linux-fbdev, luto, cocci, linux-kernel, Toshi Kani,
Suresh Siddha, Ingo Molnar, Thomas Gleixner, Juergen Gross,
Daniel Vetter, Dave Airlie, Antonino Daplas, Dave Hansen,
Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
On Thu, Apr 30, 2015 at 07:27:23PM +0200, Luis R. Rodriguez wrote:
> On Thu, Apr 30, 2015 at 11:26:47AM -0500, Bjorn Helgaas wrote:
> > I don't see users of either pcim_iomap_wc() or pcim_iomap_wc_regions() so
> > far. Did I miss them, or do you just expect them in the near future?
>
> The later, and also I hate seeing folks later add code under EXPORT_SYMBOL()
> rather than EXPORT_SYMBOL_GPL() so I figure I'd rather do it first. It happened
> recently in my v1 series, someone beat me to a write-combining export symbol
> and changed it to EXPORT_SYMBOL(). Feel free to drop this though but I hope
> no one out there then tries to just add an EXPORT_SYMBOL() later for this...
Why do you want them to be EXPORT_SYMBOL_GPL? I would expect them to be
exported the same way pcim_iomap(), pcim_iomap_regions(), and ioremap_wc()
are exported, i.e., with EXPORT_SYMBOL.
Per Documentation/DocBook/kernel-hacking.tmpl, EXPORT_SYMBOL_GPL "implies
that the function is considered an internal implementation issue, and not
really an interface." I don't think these are internal implementation
issues.
Bjorn
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
2015-04-30 21:46 ` Bjorn Helgaas
@ 2015-05-01 0:20 ` Luis R. Rodriguez
0 siblings, 0 replies; 8+ messages in thread
From: Luis R. Rodriguez @ 2015-05-01 0:20 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Luis R. Rodriguez, mst, plagnioj, tomi.valkeinen, airlied,
daniel.vetter, linux-fbdev, luto, cocci, linux-kernel, Toshi Kani,
Suresh Siddha, Ingo Molnar, Thomas Gleixner, Juergen Gross,
Daniel Vetter, Dave Airlie, Antonino Daplas, Dave Hansen,
Arnd Bergmann, venkatesh.pallipadi, Stefan Bader,
Ville Syrjälä, Mel Gorman, Vlastimil Babka,
Borislav Petkov, Davidlohr Bueso, konrad.wilk, ville.syrjala,
david.vrabel, jbeulich, Roger Pau Monné, xen-devel,
linux-pci
On Thu, Apr 30, 2015 at 04:46:38PM -0500, Bjorn Helgaas wrote:
> On Thu, Apr 30, 2015 at 07:27:23PM +0200, Luis R. Rodriguez wrote:
> > On Thu, Apr 30, 2015 at 11:26:47AM -0500, Bjorn Helgaas wrote:
>
> > > I don't see users of either pcim_iomap_wc() or pcim_iomap_wc_regions() so
> > > far. Did I miss them, or do you just expect them in the near future?
> >
> > The later, and also I hate seeing folks later add code under EXPORT_SYMBOL()
> > rather than EXPORT_SYMBOL_GPL() so I figure I'd rather do it first. It happened
> > recently in my v1 series, someone beat me to a write-combining export symbol
> > and changed it to EXPORT_SYMBOL(). Feel free to drop this though but I hope
> > no one out there then tries to just add an EXPORT_SYMBOL() later for this...
>
> Why do you want them to be EXPORT_SYMBOL_GPL? I would expect them to be
> exported the same way pcim_iomap(), pcim_iomap_regions(), and ioremap_wc()
> are exported, i.e., with EXPORT_SYMBOL.
>>
> Per Documentation/DocBook/kernel-hacking.tmpl, EXPORT_SYMBOL_GPL "implies
> that the function is considered an internal implementation issue, and not
> really an interface." I don't think these are internal implementation
> issues.
What Documentation/DocBook/kernel-hacking.tmpl states over EXPORT_SYMBOL_GPL()
is old and in no way reflects current trends and reality. For instance, some
folks believe that if some code has EXPORT_SYMBOL() declared that they can use
it on proprietary modules. This is terribly incorrect, quite a few developers
do not in any way stand by this as a "needed" clarification on their code [0].
I'm one of them, but to be even more clear on this I simply *always* use
EXPORT_SYMBOL_GPL() to remove any possible doubt over this on any symbols
that I export. Heck, even tons of driver library code uses EXPORT_SYMBOL_GPL().
[0] https://lkml.org/lkml/2012/4/20/402
Luis
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-05-01 0:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1430343372-687-1-git-send-email-mcgrof@do-not-panic.com>
[not found] ` <1430343372-687-2-git-send-email-mcgrof@do-not-panic.com>
2015-04-30 15:59 ` [PATCH v4 1/5] pci: add pci_iomap_wc() variants Bjorn Helgaas
2015-04-30 16:52 ` Luis R. Rodriguez
2015-04-30 17:03 ` Andy Lutomirski
2015-04-30 17:15 ` Luis R. Rodriguez
[not found] ` <1430343372-687-3-git-send-email-mcgrof@do-not-panic.com>
2015-04-30 16:26 ` [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants Bjorn Helgaas
2015-04-30 17:27 ` Luis R. Rodriguez
2015-04-30 21:46 ` Bjorn Helgaas
2015-05-01 0:20 ` Luis R. Rodriguez
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).