PCI resource mmap cleanup
Subsystems (13)
cover PCI resource mmap cleanup
This started out as a fairly trivial "add pci_mmap_page_range() for ARM64" patch. But pci_mmap_page_range() is a vile interface, taking "user visible" resource addresses converted with pci_resource_to_user() on those platforms unlucky enough to use that... and even in the *sane* sysfs-based mmap method, we convert through user addresses to call the platform-specific method.
In most cases there's just no need for any of this crap. We can migrate most architectures to a generic implementation without much thought, and the few that aren't converted in this series can probably be added fairly easily too but need a little more arch-specific attention.
Utterly untested for now; I'll do some testing while I deal with the inevitable bikeshedding.
David Woodhouse (17):
pci: Fix pci_mmap_fits() for HAVE_PCI_RESOURCE_TO_USER platforms
pci: Fix another sanity check bug in /proc/pci mmap
pci: Only allow WC mmap on prefetchable resources
pci: Add arch_can_pci_mmap_wc() macro
pci: Move multiple declarations of pci_mmap_page_range() to <linux/pci.h>
pci: Add HAVE_PCI_MMAP_IO to architectures which can mmap() I/O space
pci: Use BAR index in sysfs attr->private instead of resource pointer
pci: Add BAR index argument to pci_mmap_page_range()
pci: Add pci_mmap_resource_range() and use it for ARM64
arm: Use generic pci_mmap_resource_range()
cris: Use generic pci_mmap_resource_range()
mips: Use generic pci_mmap_resource_range()
mn10300: Use generic pci_mmap_resource_range()
parisc: Use generic pci_mmap_resource_range()
sh: Use generic pci_mmap_resource_range()
unicore: Use generic pci_mmap_resource_range()
arm64: Do not expose PCI mmap through procfs
Documentation/filesystems/sysfs-pci.txt | 9 +++- arch/arm/include/asm/pci.h | 3 +- arch/arm/kernel/bios32.c | 19 ------- arch/arm64/include/asm/pci.h | 3 ++ arch/cris/arch-v32/drivers/pci/bios.c | 22 -------- arch/cris/include/asm/pci.h | 4 +- arch/ia64/include/asm/pci.h | 4 +- arch/ia64/pci/pci.c | 3 +- arch/microblaze/include/asm/pci.h | 6 +-- arch/microblaze/pci/pci-common.c | 2 +- arch/mips/include/asm/pci.h | 5 +- arch/mips/pci/pci.c | 24 --------- arch/mn10300/include/asm/pci.h | 4 +- arch/mn10300/unit-asb2305/pci-asb2305.c | 23 --------- arch/parisc/include/asm/pci.h | 4 +- arch/parisc/kernel/pci.c | 28 ---------- arch/powerpc/include/asm/pci.h | 9 ++-- arch/powerpc/kernel/pci-common.c | 3 +- arch/sh/drivers/pci/pci.c | 21 -------- arch/sh/include/asm/pci.h | 4 +- arch/sparc/include/asm/pci_64.h | 5 +- arch/sparc/kernel/pci.c | 6 +-- arch/unicore32/include/asm/pci.h | 3 +- arch/unicore32/kernel/pci.c | 23 --------- arch/x86/include/asm/pci.h | 6 +-- arch/x86/pci/i386.c | 3 +- arch/xtensa/include/asm/pci.h | 11 ++-- arch/xtensa/kernel/pci.c | 5 +- drivers/pci/Makefile | 2 +- drivers/pci/mmap.c | 90 +++++++++++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 77 +++++++++++++--------------- drivers/pci/proc.c | 55 ++++++++++++++------ include/linux/pci.h | 19 +++++++ 33 files changed, 233 insertions(+), 272 deletions(-) create mode 100644 drivers/pci/mmap.c
Signature · 1 line
2.9.3
PATCH 1/17 pci: Fix pci_mmap_fits() for HAVE_PCI_RESOURCE_TO_USER platforms
From: David Woodhouse <[email protected]>
In the PCI_MMAP_PROCFS case when the address being passed by the user is a 'user visible' resource address based on the bus window, and not the actual contents of the resource, that's what we need to be checking it against.
--- drivers/pci/pci-sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci-sysfs.c +7 -3
@@ -985,15 +985,19 @@ void pci_remove_legacy_files(struct pci_bus *b)int pci_mmap_fits (struct pci_dev *pdev,int resno,struct vm_area_struct *vma,enum pci_mmap_api mmap_api) { -unsigned long nr, start, size, pci_start; +unsigned long nr, start, size; +resource_size_t pci_start =0 , pci_end;if (pci_resource_len (pdev, resno) ==0 )return 0 ; nr =vma_pages (vma); start = vma->vm_pgoff; size = ((pci_resource_len (pdev, resno) -1 ) >>PAGE_SHIFT ) +1 ; - pci_start = (mmap_api ==PCI_MMAP_PROCFS ) ? -pci_resource_start (pdev, resno) >>PAGE_SHIFT :0 ; +if (mmap_api ==PCI_MMAP_PROCFS ) { +pci_resource_to_user (pdev, resno, &pdev->resource[resno], + &pci_start, &pci_end); + pci_start >>=PAGE_SHIFT ; + }if (start >= pci_start && start < pci_start + size && start + nr <= pci_start + size)return 1 ;
Signature · 1 line
2.9.3
PATCH 2/17 pci: Fix another sanity check bug in /proc/pci mmap
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Don't match MMIO maps with I/O BARs and vice versa.
--- drivers/pci/proc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pci/proc.c +8 -2
@@ -231,14 +231,20 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) {struct pci_dev *dev =PDE_DATA (file_inode (file));struct pci_filp_private *fpriv = file->private_data; -int i, ret, write_combine; +int i, ret, write_combine, res_bit;if (!capable (CAP_SYS_RAWIO ))return -EPERM ; +if (fpriv->mmap_state == pci_mmap_io) + res_bit =IORESOURCE_IO ; +else + res_bit =IORESOURCE_MEM ; +/* Make sure the caller is mapping a real resource for this device */ for (i =0 ; i <PCI_ROM_RESOURCE ; i++) { -if (pci_mmap_fits (dev, i, vma,PCI_MMAP_PROCFS )) +if (dev->resource[i].flags & res_bit && +pci_mmap_fits (dev, i, vma,PCI_MMAP_PROCFS ))break ; }
Signature · 1 line
2.9.3
PATCH 3/17 pci: Only allow WC mmap on prefetchable resources
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The /proc/bus/pci mmap interface allows the user to specify whether they want WC or not. Don't let them do so on non-prefetchable BARs.
--- drivers/pci/proc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/pci/proc.c +8 -5
@@ -231,7 +231,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) {struct pci_dev *dev =PDE_DATA (file_inode (file));struct pci_filp_private *fpriv = file->private_data; -int i, ret, write_combine, res_bit; +int i, ret, write_combine =0 , res_bit;if (!capable (CAP_SYS_RAWIO ))return -EPERM ;
@@ -251,10 +251,13 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)if (i >=PCI_ROM_RESOURCE )return -ENODEV ; -if (fpriv->mmap_state == pci_mmap_mem) - write_combine = fpriv->write_combine; -else - write_combine =0 ; +if (fpriv->mmap_state == pci_mmap_mem && + fpriv->write_combine) { +if (dev->resource[i].flags &IORESOURCE_PREFETCH ) + write_combine =1 ; +else +return -EINVAL ; + } ret =pci_mmap_page_range (dev, vma, fpriv->mmap_state, write_combine);if (ret <0 )
Signature · 1 line
2.9.3
PATCH 4/17 pci: Add arch_can_pci_mmap_wc() macro
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Most of the almost-identical versions of pci_mmap_page_range() silently ignore the 'write_combine' argument and give uncached mappings.
Yet we allow the PCIIOC_WRITE_COMBINE ioctl in /proc/bus/pci, expose the 'resourceX_wc' file in sysfs, and allow an attempted mapping to apparently succeed.
To fix this, introduce a macro arch_can_pci_mmap_wc() which indicates whether the platform can do a write-combining mapping. On x86 this ends up being pat_enabled(), while the few other platforms that support it can just set it to a literal '1'.
--- Documentation/filesystems/sysfs-pci.txt | 4 ++++ arch/ia64/include/asm/pci.h | 2 ++ arch/powerpc/include/asm/pci.h | 5 +++-- arch/x86/include/asm/pci.h | 2 ++ arch/xtensa/include/asm/pci.h | 6 +++++- arch/xtensa/kernel/pci.c | 2 +- drivers/pci/pci-sysfs.c | 6 ++++-- drivers/pci/proc.c | 17 ++++++++++------- 8 files changed, 31 insertions(+), 13 deletions(-)
Documentation/filesystems/sysfs-pci.txt +4 -0
@@ -117,6 +117,10 @@ code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function. Platforms are free to only support subsets of the mmap functionality, but useful return codes should be provided. +Platforms which support write-combining maps of PCI resources must define +arch_can_pci_mmap_wc() which shall evaluate to non-zero at runtime when +write-combining is permitted. + Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms wishing to support legacy functionality should define it and provide pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.
arch/ia64/include/asm/pci.h +2 -0
@@ -51,6 +51,8 @@ extern unsigned long ia64_max_iommu_merge_mask;#define PCI_DMA_BUS_IS_PHYS (ia64_max_iommu_merge_mask == ~0UL)#define HAVE_PCI_MMAP +#define arch_can_pci_mmap_wc () 1 +extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);#define HAVE_PCI_LEGACY
arch/powerpc/include/asm/pci.h +3 -2
@@ -81,8 +81,9 @@ struct vm_area_struct;int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine); -/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ -#define HAVE_PCI_MMAP 1 +/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() and it does WC */ +#define HAVE_PCI_MMAP 1 +#define arch_can_pci_mmap_wc () 1extern int pci_legacy_read (struct pci_bus *bus,loff_t port,u32 *val,size_t count);
arch/x86/include/asm/pci.h +2 -0
@@ -7,6 +7,7 @@#include <linux/string.h> #include <linux/scatterlist.h> #include <asm/io.h> +#include <asm/pat.h> #include <asm/x86_init.h> #ifdef __KERNEL__
@@ -102,6 +103,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);#define HAVE_PCI_MMAP +#define arch_can_pci_mmap_wc () pat_enabled()extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);
arch/xtensa/include/asm/pci.h +5 -1
@@ -51,7 +51,11 @@ int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma, enum pci_mmap_state mmap_state, int write_combine);/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ -#define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP 1 + +/* This was wrapped in #if 0 since the first merge of xtensa support... +#define arch_can_pci_mmap_wc() 1 +*/ #endif /* __KERNEL__ */
arch/xtensa/kernel/pci.c +1 -1
@@ -345,7 +345,7 @@ __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,/* Set to write-through */ prot = (prot & _PAGE_CA_MASK) | _PAGE_CA_WT; -#if 0 +#ifdef arch_can_pci_mmap_wcif (!write_combine) prot |= _PAGE_WRITETHRU;#endif
drivers/pci/pci-sysfs.c +4 -2
@@ -1210,10 +1210,12 @@ static int pci_create_resource_files(struct pci_dev *pdev)continue ; retval =pci_create_attr (pdev, i,0 ); +#ifdef arch_can_pci_mmap_wc/* for prefetchable resources, create a WC mappable file */ -if (!retval && pdev->resource[i].flags &IORESOURCE_PREFETCH ) +if (!retval &&arch_can_pci_mmap_wc () && + pdev->resource[i].flags &IORESOURCE_PREFETCH ) retval =pci_create_attr (pdev, i,1 ); - +#endif if (retval) {pci_remove_resource_files (pdev);return retval;
drivers/pci/proc.c +10 -7
@@ -209,15 +209,18 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd, fpriv->mmap_state = pci_mmap_mem;break ; +#ifdef arch_can_pci_mmap_wccase PCIIOC_WRITE_COMBINE : -if (arg) - fpriv->write_combine =1 ; -else - fpriv->write_combine =0 ; -break ; - +if (arch_can_pci_mmap_wc ()) { +if (arg) + fpriv->write_combine =1 ; +else + fpriv->write_combine =0 ; +break ; + } +/* If arch decided it can't, fall through... */ +#endif /* arch_can_pci_mmap_wc */ #endif /* HAVE_PCI_MMAP */ -default : ret = -EINVAL ;break ;
Signature · 1 line
2.9.3
PATCH 5/17 pci: Move multiple declarations of pci_mmap_page_range() to <linux/pci.h>
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
We can declare it <linux/pci.h> even on platforms where it isn't going to be defined. There's no need to have it littered through the various <asm/pci.h> files.
--- arch/arm/include/asm/pci.h | 2 -- arch/cris/include/asm/pci.h | 3 --- arch/ia64/include/asm/pci.h | 2 -- arch/microblaze/include/asm/pci.h | 3 --- arch/mips/include/asm/pci.h | 3 --- arch/mn10300/include/asm/pci.h | 3 --- arch/parisc/include/asm/pci.h | 3 --- arch/powerpc/include/asm/pci.h | 3 --- arch/sh/include/asm/pci.h | 3 +-- arch/sparc/include/asm/pci_64.h | 4 ---- arch/unicore32/include/asm/pci.h | 2 -- arch/x86/include/asm/pci.h | 4 ---- arch/xtensa/include/asm/pci.h | 4 ---- include/linux/pci.h | 7 +++++++ 14 files changed, 8 insertions(+), 38 deletions(-)
arch/arm/include/asm/pci.h +0 -2
@@ -29,8 +29,6 @@ static inline int pci_proc_domain(struct pci_bus *bus)#define PCI_DMA_BUS_IS_PHYS (1)#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine);static inline int pci_get_legacy_ide_irq (struct pci_dev *dev,int channel) {
arch/cris/include/asm/pci.h +0 -3
@@ -42,9 +42,6 @@ struct pci_dev;#define PCI_DMA_BUS_IS_PHYS (1)#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); -#endif /* __KERNEL__ */
arch/ia64/include/asm/pci.h +0 -2
@@ -53,8 +53,6 @@ extern unsigned long ia64_max_iommu_merge_mask;#define HAVE_PCI_MMAP #define arch_can_pci_mmap_wc () 1 -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine);#define HAVE_PCI_LEGACY extern int pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma,
arch/microblaze/include/asm/pci.h +0 -3
@@ -46,9 +46,6 @@ extern int pci_domain_nr(struct pci_bus *bus);extern int pci_proc_domain (struct pci_bus *bus);struct vm_area_struct ; -/* Map a range of PCI memory or I/O space for a device into user space */ -int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine);/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ #define HAVE_PCI_MMAP 1
arch/mips/include/asm/pci.h +0 -3
@@ -111,9 +111,6 @@ extern void pcibios_set_master(struct pci_dev *dev);#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); -#define HAVE_ARCH_PCI_RESOURCE_TO_USER /*
arch/mn10300/include/asm/pci.h +0 -3
@@ -74,9 +74,6 @@ static inline int pci_controller_num(struct pci_dev *dev) }#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state, -int write_combine);#endif /* __KERNEL__ */
arch/parisc/include/asm/pci.h +0 -3
@@ -201,7 +201,4 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); -#endif /* __ASM_PARISC_PCI_H */
arch/powerpc/include/asm/pci.h +0 -3
@@ -77,9 +77,6 @@ extern int pci_domain_nr(struct pci_bus *bus);extern int pci_proc_domain (struct pci_bus *bus);struct vm_area_struct ; -/* Map a range of PCI memory or I/O space for a device into user space */ -int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine);/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() and it does WC */ #define HAVE_PCI_MMAP 1
arch/sh/include/asm/pci.h +1 -2
@@ -66,8 +66,7 @@ extern unsigned long PCIBIOS_MIN_IO, PCIBIOS_MIN_MEM;struct pci_dev ;#define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); +extern void pcibios_set_master (struct pci_dev *dev);/* Dynamic DMA mapping stuff.
arch/sparc/include/asm/pci_64.h +0 -4
@@ -45,10 +45,6 @@ static inline int pci_proc_domain(struct pci_bus *bus)#define HAVE_ARCH_PCI_GET_UNMAPPED_AREA #define get_pci_unmapped_area get_fb_unmapped_area -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state, -int write_combine); -static inline int pci_get_legacy_ide_irq (struct pci_dev *dev,int channel) {return PCI_IRQ_NONE ;
arch/unicore32/include/asm/pci.h +0 -2
@@ -17,8 +17,6 @@#include <mach/hardware.h> /* for PCIBIOS_MIN_* */ #define HAVE_PCI_MMAP -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine);#endif /* __KERNEL__ */ #endif
arch/x86/include/asm/pci.h +0 -4
@@ -104,10 +104,6 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);#define HAVE_PCI_MMAP #define arch_can_pci_mmap_wc () pat_enabled() -extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state, -int write_combine); -#ifdef CONFIG_PCI extern void early_quirks (void );
arch/xtensa/include/asm/pci.h +0 -4
@@ -46,10 +46,6 @@ struct pci_dev;#define PCI_DMA_BUS_IS_PHYS (1) -/* Map a range of PCI memory or I/O space for a device into user space */ -int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); -/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ #define HAVE_PCI_MMAP 1
include/linux/pci.h +7 -0
@@ -1626,6 +1626,13 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }#include <asm/pci.h> +/* Map a range of PCI memory or I/O space for a device into user space. +* Architectures provide this function if they set HAVE_PCI_MMAP, and +* it accepts the 'write_combine' argument when arch_can_pci_mmap_wc() +* evaluates to nonzero. */ +int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma, +enum pci_mmap_state mmap_state,int write_combine); +#ifndef pci_root_bus_fwnode#define pci_root_bus_fwnode (bus) NULL#endif
Signature · 1 line
2.9.3
PATCH 6/17 pci: Add HAVE_PCI_MMAP_IO to architectures which can mmap() I/O space
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
This is relatively esoteric, and knowing that we don't have it makes life easier in some cases rather than just an eventual -EINVAL from pci_mmap_page_range().
--- arch/microblaze/include/asm/pci.h | 3 ++- arch/powerpc/include/asm/pci.h | 1 + arch/sparc/include/asm/pci_64.h | 1 + arch/xtensa/include/asm/pci.h | 1 + drivers/pci/pci-sysfs.c | 14 +++++++++----- drivers/pci/proc.c | 10 ++++++++-- 6 files changed, 22 insertions(+), 8 deletions(-)
arch/microblaze/include/asm/pci.h +2 -1
@@ -48,7 +48,8 @@ extern int pci_proc_domain(struct pci_bus *bus);struct vm_area_struct ;/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ -#define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP_IO 1extern int pci_legacy_read (struct pci_bus *bus,loff_t port,u32 *val,size_t count);
arch/powerpc/include/asm/pci.h +1 -0
@@ -80,6 +80,7 @@ struct vm_area_struct;/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() and it does WC */ #define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP_IO 1#define arch_can_pci_mmap_wc () 1 extern int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val,
arch/sparc/include/asm/pci_64.h +1 -0
@@ -42,6 +42,7 @@ static inline int pci_proc_domain(struct pci_bus *bus)/* Platform support for /proc/bus/pci/X/Y mmap()s. */ #define HAVE_PCI_MMAP +#define HAVE_PCI_MMAP_IO #define HAVE_ARCH_PCI_GET_UNMAPPED_AREA #define get_pci_unmapped_area get_fb_unmapped_area
arch/xtensa/include/asm/pci.h +1 -0
@@ -48,6 +48,7 @@ struct pci_dev;/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ #define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP_IO 1/* This was wrapped in #if 0 since the first merge of xtensa support... #define arch_can_pci_mmap_wc() 1
drivers/pci/pci-sysfs.c +9 -5
@@ -1174,11 +1174,15 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) }else { pdev->res_attr[num] = res_attr;sprintf (res_attr_name,"resource%d" , num); - res_attr->mmap = pci_mmap_resource_uc; - } -if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) { - res_attr->read = pci_read_resource_io; - res_attr->write = pci_write_resource_io; +if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) { + res_attr->read = pci_read_resource_io; + res_attr->write = pci_write_resource_io; +#ifdef HAVE_PCI_MMAP_IO + res_attr->mmap = pci_mmap_resource_uc; +#endif + }else { + res_attr->mmap = pci_mmap_resource_uc; + } } res_attr->attr.name = res_attr_name; res_attr->attr.mode =S_IRUSR |S_IWUSR ;
drivers/pci/proc.c +8 -2
@@ -200,11 +200,12 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd, ret =pci_domain_nr (dev->bus);break ; -#ifdef HAVE_PCI_MMAP +#ifdef HAVE_PCI_MMAP_IO case PCIIOC_MMAP_IS_IO : fpriv->mmap_state = pci_mmap_io;break ; - +#endif +#ifdef HAVE_PCI_MMAP case PCIIOC_MMAP_IS_MEM : fpriv->mmap_state = pci_mmap_mem;break ;
@@ -239,6 +240,11 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)if (!capable (CAP_SYS_RAWIO ))return -EPERM ; +#ifndef HAVE_PCI_MMAP_IO +if (fpriv->mmap_state == pci_mmap_io) +return -EINVAL ; +#endif +if (fpriv->mmap_state == pci_mmap_io) res_bit =IORESOURCE_IO ;else
Signature · 1 line
2.9.3
PATCH 7/17 pci: Use BAR index in sysfs attr->private instead of resource pointer
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
We store the pointer, and then on *every* use of it we loop over the device's resources to find out the index. That's kind of silly.
--- drivers/pci/pci-sysfs.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-)
drivers/pci/pci-sysfs.c +14 -24
@@ -1017,26 +1017,20 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, struct vm_area_struct *vma, int write_combine) {struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj)); -struct resource *res = attr->private; +int bar = (unsigned long )attr->private;enum pci_mmap_state mmap_type;resource_size_t start, end; -int i; - -for (i =0 ; i <PCI_ROM_RESOURCE ; i++) -if (res == &pdev->resource[i]) -break ; -if (i >=PCI_ROM_RESOURCE ) -return -ENODEV ; +struct resource *res = &pdev->resource[bar];if (res->flags &IORESOURCE_MEM &&iomem_is_exclusive (res->start))return -EINVAL ; -if (!pci_mmap_fits (pdev, i, vma,PCI_MMAP_SYSFS )) { +if (!pci_mmap_fits (pdev, bar, vma,PCI_MMAP_SYSFS )) {WARN (1 ,"process \"%s\" tried to map 0x%08lx bytes at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n" , current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff, -pci_name (pdev), i, - (u64 )pci_resource_start (pdev, i), - (u64 )pci_resource_len (pdev, i)); +pci_name (pdev), bar, + (u64 )pci_resource_start (pdev, bar), + (u64 )pci_resource_len (pdev, bar));return -EINVAL ; }
@@ -1044,7 +1038,7 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,* from /proc/bus/pci/ which is a "user visible" value. If this is * different from the resource itself, arch will do necessary fixup. */ -pci_resource_to_user (pdev, i, res, &start, &end); +pci_resource_to_user (pdev, bar, res, &start, &end); vma->vm_pgoff += start >>PAGE_SHIFT ; mmap_type = res->flags &IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;return pci_mmap_page_range (pdev, vma, mmap_type, write_combine);
@@ -1069,22 +1063,18 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj, loff_t off, size_t count, bool write) {struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj)); -struct resource *res = attr->private; +int bar = (unsigned long )attr->private; +struct resource *res;unsigned long port = off; -int i; -for (i =0 ; i <PCI_ROM_RESOURCE ; i++) -if (res == &pdev->resource[i]) -break ; -if (i >=PCI_ROM_RESOURCE ) -return -ENODEV ; + res = &pdev->resource[bar]; - port +=pci_resource_start (pdev, i); + port +=pci_resource_start (pdev, bar); -if (port >pci_resource_end (pdev, i)) +if (port >pci_resource_end (pdev, bar))return 0 ; -if (port + count -1 >pci_resource_end (pdev, i)) +if (port + count -1 >pci_resource_end (pdev, bar))return -EINVAL ;switch (count) {
@@ -1187,7 +1177,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) res_attr->attr.name = res_attr_name; res_attr->attr.mode =S_IRUSR |S_IWUSR ; res_attr->size =pci_resource_len (pdev, num); - res_attr->private = &pdev->resource[num]; + res_attr->private = (void *)(unsigned long )num; retval =sysfs_create_bin_file (&pdev->dev.kobj, res_attr);if (retval)kfree (res_attr);
Signature · 1 line
2.9.3
PATCH 8/17 pci: Add BAR index argument to pci_mmap_page_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
In all cases we know which BAR it is. Passing it in means that arch code (or generic code; watch this space) won't have to go looking for it again.
--- arch/arm/kernel/bios32.c | 3 ++- arch/cris/arch-v32/drivers/pci/bios.c | 3 ++- arch/ia64/pci/pci.c | 3 ++- arch/microblaze/pci/pci-common.c | 2 +- arch/mips/pci/pci.c | 3 ++- arch/mn10300/unit-asb2305/pci-asb2305.c | 3 ++- arch/parisc/kernel/pci.c | 3 ++- arch/powerpc/kernel/pci-common.c | 3 ++- arch/sh/drivers/pci/pci.c | 3 ++- arch/sparc/kernel/pci.c | 6 +++--- arch/unicore32/kernel/pci.c | 3 ++- arch/x86/pci/i386.c | 3 ++- arch/xtensa/kernel/pci.c | 3 ++- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/proc.c | 2 +- include/linux/pci.h | 3 ++- 16 files changed, 30 insertions(+), 18 deletions(-)
arch/arm/kernel/bios32.c +2 -1
@@ -597,7 +597,8 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,return start; } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {if (mmap_state == pci_mmap_io)
arch/cris/arch-v32/drivers/pci/bios.c +2 -1
@@ -14,7 +14,8 @@ void pcibios_set_master(struct pci_dev *dev)pci_write_config_byte (dev,PCI_LATENCY_TIMER , lat); } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long prot;
arch/ia64/pci/pci.c +2 -1
@@ -419,7 +419,8 @@ pcibios_align_resource (void *data, const struct resource *res, }int -pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long size = vma->vm_end - vma->vm_start;
arch/microblaze/pci/pci-common.c +1 -1
@@ -278,7 +278,7 @@ pgprot_t pci_phys_mem_access_prot(struct file *file,* * Returns a negative error code on failure, zero on success. */ -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) { resource_size_t offset =
arch/mips/pci/pci.c +2 -1
@@ -58,7 +58,8 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *end = rsrc->start + size; } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long prot;
arch/mn10300/unit-asb2305/pci-asb2305.c +2 -1
@@ -211,7 +211,8 @@ void __init pcibios_resource_survey(void)pcibios_allocate_resources (1 ); } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long prot;
arch/parisc/kernel/pci.c +2 -1
@@ -228,7 +228,8 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res, } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long prot;
arch/powerpc/kernel/pci-common.c +2 -1
@@ -513,7 +513,8 @@ pgprot_t pci_phys_mem_access_prot(struct file *file,* * Returns a negative error code on failure, zero on success. */ -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) { resource_size_t offset =
arch/sh/drivers/pci/pci.c +2 -1
@@ -269,7 +269,8 @@ void __ref pcibios_report_status(unsigned int status_mask, int warn) } } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {/*
arch/sparc/kernel/pci.c +3 -3
@@ -862,9 +862,9 @@ static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vm* * Returns a negative error code on failure, zero on success. */ -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state, -int write_combine) +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma, +enum pci_mmap_state mmap_state,int write_combine) {int ret;
arch/unicore32/kernel/pci.c +2 -1
@@ -357,7 +357,8 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)return 0 ; } -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long phys;
arch/x86/pci/i386.c +2 -1
@@ -411,7 +411,8 @@ static const struct vm_operations_struct pci_mmap_ops = { .access = generic_access_phys, }; -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {unsigned long prot;
arch/xtensa/kernel/pci.c +2 -1
@@ -362,7 +362,8 @@ __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,* * Returns a negative error code on failure, zero on success. */ -int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine) {
drivers/pci/pci-sysfs.c +1 -1
@@ -1041,7 +1041,7 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,pci_resource_to_user (pdev, bar, res, &start, &end); vma->vm_pgoff += start >>PAGE_SHIFT ; mmap_type = res->flags &IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; -return pci_mmap_page_range (pdev, vma, mmap_type, write_combine); +return pci_mmap_page_range (pdev, bar, vma, mmap_type, write_combine); } static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj,
drivers/pci/proc.c +1 -1
@@ -267,7 +267,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)else return -EINVAL ; } - ret =pci_mmap_page_range (dev, vma, + ret =pci_mmap_page_range (dev, i, vma, fpriv->mmap_state, write_combine);if (ret <0 )return ret;
include/linux/pci.h +2 -1
@@ -1630,7 +1630,8 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }* Architectures provide this function if they set HAVE_PCI_MMAP, and * it accepts the 'write_combine' argument when arch_can_pci_mmap_wc() * evaluates to nonzero. */ -int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma, +int pci_mmap_page_range (struct pci_dev *pdev,int bar, +struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);#ifndef pci_root_bus_fwnode
Signature · 1 line
2.9.3
PATCH 9/17 pci: Add pci_mmap_resource_range() and use it for ARM64
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Starting to leave behind the legacy of the pci_mmap_page_range() interface which takes "user-visible" BAR addresses. This takes just the resource and offset.
For now, both APIs coexist and depending on the platform, one is implemented as a wrapper around the other.
--- Documentation/filesystems/sysfs-pci.txt | 5 +- arch/arm64/include/asm/pci.h | 3 ++ drivers/pci/Makefile | 2 +- drivers/pci/mmap.c | 90 +++++++++++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 11 +--- include/linux/pci.h | 19 +++++-- 6 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 drivers/pci/mmap.c
Documentation/filesystems/sysfs-pci.txt +4 -1
@@ -113,7 +113,10 @@ Supporting PCI access on new platforms -------------------------------------- In order to support PCI resource mapping as described above, Linux platform -code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function. +code must define HAVE_PCI_MMAP and either provide a pci_mmap_page_range() +function or (preferably) also define ARCH_GENERIC_PCI_MMAP_RESOURCE to use +the generic implementation. + Platforms are free to only support subsets of the mmap functionality, but useful return codes should be provided.
arch/arm64/include/asm/pci.h +3 -0
@@ -22,6 +22,9 @@*/ #define PCI_DMA_BUS_IS_PHYS (0) +#define HAVE_PCI_MMAP 1 +#define ARCH_GENERIC_PCI_MMAP_RESOURCE 1 +extern int isa_dma_bridge_buggy;#ifdef CONFIG_PCI
drivers/pci/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-y += access.o bus.o probe.o host-bridge.o remove.o pci.o \ pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \ - irq.o vpd.o setup-bus.o vc.o + irq.o vpd.o setup-bus.o vc.o mmap.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += slot.o
drivers/pci/mmap.c new file +90 -0
90 lines not on this page · raw message
drivers/pci/pci-sysfs.c +2 -9
@@ -1019,7 +1019,6 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj));int bar = (unsigned long )attr->private;enum pci_mmap_state mmap_type; -resource_size_t start, end;struct resource *res = &pdev->resource[bar];if (res->flags &IORESOURCE_MEM &&iomem_is_exclusive (res->start))
@@ -1033,15 +1032,9 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, (u64)pci_resource_len(pdev, bar));return -EINVAL ; } - -/* pci_mmap_page_range() expects the same kind of entry as coming -* from /proc/bus/pci/ which is a "user visible" value. If this is -* different from the resource itself, arch will do necessary fixup. -*/ -pci_resource_to_user (pdev, bar, res, &start, &end); - vma->vm_pgoff += start >>PAGE_SHIFT ; mmap_type = res->flags &IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; -return pci_mmap_page_range (pdev, bar, vma, mmap_type, write_combine); + +return pci_mmap_resource_range (pdev, bar, vma, mmap_type, write_combine); } static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj,
include/linux/pci.h +15 -4
@@ -1626,10 +1626,21 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }#include <asm/pci.h> -/* Map a range of PCI memory or I/O space for a device into user space. -* Architectures provide this function if they set HAVE_PCI_MMAP, and -* it accepts the 'write_combine' argument when arch_can_pci_mmap_wc() -* evaluates to nonzero. */ +/* These two functions provide almost identical functionality. Depennding +* on the architecture, one will be implemented as a wrapper aroudn the +* other (in drivers/pci/mmap.c). +* +* pci_mmap_resource_range() maps a specific BAR, and vm->vm_pgoff +* is expected to be an offset within that region. +* +* pci_mmap_page_range() is the legacy architecture-specific interface, +* which accepts a "user visible" resource address converted by +* pci_resource_to_user(), as used in the legacy mmap() interface in +* /proc/bus/pci/. +*/ +int pci_mmap_resource_range (struct pci_dev *dev,int bar, +struct vm_area_struct *vma, +enum pci_mmap_state mmap_state,int write_combine);int pci_mmap_page_range (struct pci_dev *pdev,int bar,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);
Signature · 1 line
2.9.3
PATCH 10/17 arm: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/arm/include/asm/pci.h | 1 + arch/arm/kernel/bios32.c | 20 -------------------- 2 files changed, 1 insertion(+), 20 deletions(-)
arch/arm/include/asm/pci.h +1 -0
@@ -29,6 +29,7 @@ static inline int pci_proc_domain(struct pci_bus *bus)#define PCI_DMA_BUS_IS_PHYS (1)#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE static inline int pci_get_legacy_ide_irq (struct pci_dev *dev,int channel) {
arch/arm/kernel/bios32.c +0 -20
@@ -597,26 +597,6 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,return start; } -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -if (mmap_state == pci_mmap_io) -return -EINVAL ; - -/* -* Mark this as IO -*/ - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - -if (remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot)) -return -EAGAIN ; - -return 0 ; -} -void __init pci_map_io_early (unsigned long pfn) {struct map_desc pci_io_desc = {
Signature · 1 line
2.9.3
PATCH 11/17 cris: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/cris/arch-v32/drivers/pci/bios.c | 23 ----------------------- arch/cris/include/asm/pci.h | 1 + 2 files changed, 1 insertion(+), 23 deletions(-)
arch/cris/arch-v32/drivers/pci/bios.c +0 -23
@@ -14,29 +14,6 @@ void pcibios_set_master(struct pci_dev *dev)pci_write_config_byte (dev,PCI_LATENCY_TIMER , lat); } -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long prot; - -/* Leave vm_pgoff as-is, the PCI space address is the physical -* address on this platform. -*/ - prot =pgprot_val (vma->vm_page_prot); - vma->vm_page_prot =__pgprot (prot); - -/* Write-combine setting is ignored, it is changed via the mtrr -* interfaces on this platform. -*/ -if (remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot)) -return -EAGAIN ; - -return 0 ; -} -resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align)
arch/cris/include/asm/pci.h +1 -0
@@ -42,6 +42,7 @@ struct pci_dev;#define PCI_DMA_BUS_IS_PHYS (1)#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #endif /* __KERNEL__ */
Signature · 1 line
2.9.3
PATCH 12/17 mips: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/mips/include/asm/pci.h | 2 +- arch/mips/pci/pci.c | 25 ------------------------- 2 files changed, 1 insertion(+), 26 deletions(-)
arch/mips/include/asm/pci.h +1 -1
@@ -110,7 +110,7 @@ extern unsigned long PCIBIOS_MIN_MEM;extern void pcibios_set_master (struct pci_dev *dev);#define HAVE_PCI_MMAP - +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #define HAVE_ARCH_PCI_RESOURCE_TO_USER /*
arch/mips/pci/pci.c +0 -25
@@ -57,28 +57,3 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar, *start =fixup_bigphys_addr (rsrc->start, size); *end = rsrc->start + size; } - -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long prot; - -/* -* I/O space can be accessed via normal processor loads and stores on -* this platform but for now we elect not to do this and portable -* drivers should not do this anyway. -*/ -if (mmap_state == pci_mmap_io) -return -EINVAL ; - -/* -* Ignore write-combine; for now only return uncached mappings. -*/ - prot =pgprot_val (vma->vm_page_prot); - prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED; - vma->vm_page_prot =__pgprot (prot); - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, vma->vm_page_prot); -}
Signature · 1 line
2.9.3
PATCH 13/17 mn10300: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
This was setting vma->vm_flags |= VM_LOCKED. Not sure why...
--- arch/mn10300/include/asm/pci.h | 1 + arch/mn10300/unit-asb2305/pci-asb2305.c | 24 ------------------------ 2 files changed, 1 insertion(+), 24 deletions(-)
arch/mn10300/include/asm/pci.h +1 -0
@@ -74,6 +74,7 @@ static inline int pci_controller_num(struct pci_dev *dev) }#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #endif /* __KERNEL__ */
arch/mn10300/unit-asb2305/pci-asb2305.c +0 -24
@@ -210,27 +210,3 @@ void __init pcibios_resource_survey(void)pcibios_allocate_resources (0 );pcibios_allocate_resources (1 ); } - -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long prot; - -/* Leave vm_pgoff as-is, the PCI space address is the physical -* address on this platform. -*/ - vma->vm_flags |=VM_LOCKED ; - - prot =pgprot_val (vma->vm_page_prot); - prot &= ~_PAGE_CACHE; - vma->vm_page_prot =__pgprot (prot); - -/* Write-combine setting is ignored */ -if (io_remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot)) -return -EAGAIN ; - -return 0 ; -}
Signature · 1 line
2.9.3
PATCH 14/17 parisc: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/parisc/include/asm/pci.h | 1 + arch/parisc/kernel/pci.c | 29 ----------------------------- 2 files changed, 1 insertion(+), 29 deletions(-)
arch/parisc/include/asm/pci.h +1 -0
@@ -200,5 +200,6 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) }#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #endif /* __ASM_PARISC_PCI_H */
arch/parisc/kernel/pci.c +0 -29
@@ -227,35 +227,6 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,return start; } - -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long prot; - -/* -* I/O space can be accessed via normal processor loads and stores on -* this platform but for now we elect not to do this and portable -* drivers should not do this anyway. -*/ -if (mmap_state == pci_mmap_io) -return -EINVAL ; - -if (write_combine) -return -EINVAL ; - -/* -* Ignore write-combine; for now only return uncached mappings. -*/ - prot =pgprot_val (vma->vm_page_prot); - prot |= _PAGE_NO_CACHE; - vma->vm_page_prot =__pgprot (prot); - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, vma->vm_page_prot); -} -/* * A driver is enabling the device. We make sure that all the appropriate * bits are set to allow the device to operate as the driver is expecting.
Signature · 1 line
2.9.3
PATCH 15/17 sh: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/sh/drivers/pci/pci.c | 22 ---------------------- arch/sh/include/asm/pci.h | 1 + 2 files changed, 1 insertion(+), 22 deletions(-)
arch/sh/drivers/pci/pci.c +0 -22
@@ -269,28 +269,6 @@ void __ref pcibios_report_status(unsigned int status_mask, int warn) } } -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -/* -* I/O space can be accessed via normal processor loads and stores on -* this platform but for now we elect not to do this and portable -* drivers should not do this anyway. -*/ -if (mmap_state == pci_mmap_io) -return -EINVAL ; - -/* -* Ignore write-combine; for now only return uncached mappings. -*/ - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - -return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot); -} -#ifndef CONFIG_GENERIC_IOMAP void __iomem *__pci_ioport_map(struct pci_dev *dev,
arch/sh/include/asm/pci.h +1 -0
@@ -66,6 +66,7 @@ extern unsigned long PCIBIOS_MIN_IO, PCIBIOS_MIN_MEM;struct pci_dev ;#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE extern void pcibios_set_master (struct pci_dev *dev);
Signature · 1 line
2.9.3
PATCH 16/17 unicore: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- arch/unicore32/include/asm/pci.h | 1 + arch/unicore32/kernel/pci.c | 24 ------------------------ 2 files changed, 1 insertion(+), 24 deletions(-)
arch/unicore32/include/asm/pci.h +1 -0
@@ -17,6 +17,7 @@#include <mach/hardware.h> /* for PCIBIOS_MIN_* */ #define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #endif /* __KERNEL__ */ #endif
arch/unicore32/kernel/pci.c +0 -24
@@ -356,27 +356,3 @@ int pcibios_enable_device(struct pci_dev *dev, int mask) }return 0 ; } - -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long phys; - -if (mmap_state == pci_mmap_io) -return -EINVAL ; - - phys = vma->vm_pgoff; - -/* -* Mark this as IO -*/ - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - -if (remap_pfn_range (vma, vma->vm_start, phys, - vma->vm_end - vma->vm_start, - vma->vm_page_prot)) -return -EAGAIN ; - -return 0 ; -}
Signature · 1 line
2.9.3
PATCH 17/17 arm64: Do not expose PCI mmap through procfs
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- drivers/pci/proc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/pci/proc.c +5 -0
@@ -17,6 +17,11 @@static int proc_initialized;/* = 0 */ +#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proc like everyone else */ +#undef HAVE_PCI_MMAP +#endif +static loff_t proc_bus_pci_lseek (struct file *file,loff_t off,int whence) {struct pci_dev *dev =PDE_DATA (file_inode (file));
Signature · 1 line
2.9.3
Re: [PATCH 11/17] cris: Use generic pci_mmap_resource_range()
In reply to David WoodhouseQuoted 1 line · David Woodhouse
From: David Woodhouse <[email protected]>
Quoted 54 lines
Signed-off-by David Woodhouse <[email protected]>--- arch/cris/arch-v32/drivers/pci/bios.c | 23 ----------------------- arch/cris/include/asm/pci.h | 1 + 2 files changed, 1 insertion(+), 23 deletions(-)arch/cris/arch-v32/drivers/pci/bios.c +0
-23@@ -14,29 +14,6 @@ void pcibios_set_master(struct pci_dev *dev)pci_write_config_byte (dev,PCI_LATENCY_TIMER , lat); } -int pci_mmap_page_range (struct pci_dev *dev,int bar, -struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) -{ -unsigned long prot; - -/* Leave vm_pgoff as-is, the PCI space address is the physical -* address on this platform. -*/ - prot =pgprot_val (vma->vm_page_prot); - vma->vm_page_prot =__pgprot (prot); - -/* Write-combine setting is ignored, it is changed via the mtrr -* interfaces on this platform. -*/ -if (remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, - vma->vm_end - vma->vm_start, - vma->vm_page_prot)) -return -EAGAIN ; - -return 0 ; -} -resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align)arch/cris/include/asm/pci.h +1
-0@@ -42,6 +42,7 @@ struct pci_dev;#define PCI_DMA_BUS_IS_PHYS (1)#define HAVE_PCI_MMAP +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #endif /* __KERNEL__ */ Signature · 1 line
2.9.3
/^JN - Jesper Nilsson
Signature · 1 line
Jesper Nilsson -- [email protected]
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
In reply to David Woodhousedrivers/pci/proc.c line 24
Quoted 6 lines · David Woodhouse
drivers/pci/proc.c +5
-0+#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proc like everyone else */ +#undef HAVE_PCI_MMAP +#endif +
Where is this ARM64 special requirement coming from?
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
Quoted 10 lines · Sinan Kaya
drivers/pci/proc.c line 24
Quoted 8 lines · David Woodhouse
(quoted diff) +2
-0+#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proclike everyone else */
drivers/pci/proc.c +3
-0+#undef HAVE_PCI_MMAP +#endif +Where is this ARM64 special requirement coming from?
The idea is that as a new platform, ARM64 shouldn't need to implement legacy userspace interfaces.
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-April/422571.html
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
Quoted 12 lines · David Woodhouse
Quoted 10 lines · Sinan Kaya
drivers/pci/proc.c line 24
Quoted 8 lines · David Woodhouse
(quoted diff) +2
-0+#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proclike everyone else */
drivers/pci/proc.c +3
-0+#undef HAVE_PCI_MMAP +#endif +Where is this ARM64 special requirement coming from?
Quoted 5 lines
The idea is that as a new platform, ARM64 shouldn't need to implement legacy userspace interfaces.
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-April/422571.html
Aren't we breaking an ABI for userspace? I know DPDK relies on this feature.
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
Quoted 13 lines · Sinan Kaya
Quoted 12 lines · David Woodhouse
Quoted 10 lines · Sinan Kaya
drivers/pci/proc.c line 24
Quoted 8 lines · David Woodhouse
(quoted diff) +2
-0+#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proclike everyone else */
drivers/pci/proc.c +3
-0+#undef HAVE_PCI_MMAP +#endif +Where is this ARM64 special requirement coming from?
Quoted 7 lines
Quoted 5 lines
The idea is that as a new platform, ARM64 shouldn't need to implement legacy userspace interfaces.
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-April/422571.html
Aren't we breaking an ABI for userspace? I know DPDK relies on this feature.
It relies on the /proc interface? That's the first I've ever heard of that -- everybody so far has only been interested in the sysfs stuff.
Nothing's more broken than before, because we've never supported the /proc interface, but if existing arm64 code out there is failing because of that then I'm of course open to supporting it. I'm just surprised that nobody else has come up with that before, since DPDK is in common use.
Can you point me at the specific code, please?
Will
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
Quoted 25 lines · Will Deacon
Quoted 13 lines · Sinan Kaya
Quoted 12 lines · David Woodhouse
Quoted 10 lines · Sinan Kaya
drivers/pci/proc.c line 24
Quoted 8 lines · David Woodhouse
(quoted diff) +2
-0+#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proclike everyone else */
drivers/pci/proc.c +3
-0+#undef HAVE_PCI_MMAP +#endif +Where is this ARM64 special requirement coming from?
Quoted 7 lines
Quoted 5 lines
The idea is that as a new platform, ARM64 shouldn't need to implement legacy userspace interfaces.
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-April/422571.html
Aren't we breaking an ABI for userspace? I know DPDK relies on this feature.
It relies on the /proc interface? That's the first I've ever heard of that -- everybody so far has only been interested in the sysfs stuff.
Quoted 6 lines
Nothing's more broken than before, because we've never supported the /proc interface, but if existing arm64 code out there is failing because of that then I'm of course open to supporting it. I'm just surprised that nobody else has come up with that before, since DPDK is in common use.
Can you point me at the specific code, please?
I'm correcting myself. I had to go back my memory from last year.
DPDK requires HAVE_PCI_MMAP to be set. We have been carrying some old maillist patch around for DPDK customers internally.
When HAVE_PCI_MMAP is set, resource files are created in sysfs and procfs. DPDK is using the files in sysfs directory not procfs directory.
Having HAVE_PCI_MMAP defined is the DPDK requirement.
Quoted 3 lines
Will
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
[PATCH 18/17] x86: Use generic pci_mmap_resource_range()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
---
Actually it turns out this is fairly trivial for x86 too; it just looked more interesting at first glance. But pgprot_writecombine() and pgprot_device() will both do the right thing here, and allowing WC conditionally based on pat_enabled() is already working so we'll never get asked to do that when we don't want to.
arch/x86/include/asm/pci.h | 1 + arch/x86/pci/i386.c | 48 ---------------------------------------------- 2 files changed, 1 insertion(+), 48 deletions(-)
arch/x86/include/asm/pci.h +1 -0
@@ -104,6 +104,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);#define HAVE_PCI_MMAP #define arch_can_pci_mmap_wc () pat_enabled() +#define ARCH_GENERIC_PCI_MMAP_RESOURCE #ifdef CONFIG_PCI extern void early_quirks (void );
arch/x86/pci/i386.c +0 -48
51 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 7 lines · David Woodhouse
This started out as a fairly trivial "add
pci_mmap_page_range()for ARM64" patch. Butpci_mmap_page_range()is a vile interface, taking "user visible" resource addresses converted withpci_resource_to_user()on those platforms unlucky enough to use that... and even in the *sane* sysfs-based mmap method, we convert through user addresses to call the platform-specific method.
Quoted 7 lines
In most cases there's just no need for any of this crap. We can migrate most architectures to a generic implementation without much thought, and the few that aren't converted in this series can probably be added fairly easily too but need a little more arch-specific attention.
Utterly untested for now; I'll do some testing while I deal with the inevitable bikeshedding.
I added PowerPC too. Rather than posting it here as patches 18/17 and 19/17 I'll just point at
http://git.infradead.org/users/dwmw2/random-2.6.git/shortlog/refs/heads/pcimmap
To support pci_mmap_io I added a pci_iobar_pfn() function which the arch must provide, to adjust vma->vm_pgoff to the physical address of the I/O window of the appropriate PCI host controller. It looks something like this:
int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma)
{
struct pci_controller *hose = pci_bus_to_host(pdev->bus);
resource_size_t ioaddr = pci_resource_start(pdev, bar);
if (!hose)
return -EINVAL;
/* Convert to an offset within this PCI controller */
ioaddr -= (unsigned long)hose->io_base_virt - _IO_BASE;
vma->vm_pgoff += (ioaddr + hose->io_base_phys) >> PAGE_SHIFT;
return 0;
}It looks like SPARC, xtensa and Microblaze can all do the same thing, as they were all basically the same code in the first place. That leaves IA64 as the last holdout, as the selection of vm_page_prot there is rather complicated:
prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size, vma->vm_page_prot); /* * If the user requested WC, the kernel uses UC or WC for this region, * and the chipset supports WC, we can use WC. Otherwise, we have to * use the same attribute the kernel uses. */ if (write_combine && ((pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_UC || (pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_WC) && efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start)) vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); else vma->vm_page_prot = prot;
But I suspect it's *overcomplicated*, as the kernel should only ever be mapping PCI memory BARs as UC or WC in the first place, so the middle two checks in the if (write_combine…) condition are redundant.
And if the efi_range_is_wc() check isn't gratuitous, perhaps that should be in the generic code whenever CONFIG_EFI is set?
Tony?
Quoted 55 lines
David Woodhouse (17):
pci: Fixpci_mmap_fits()forHAVE_PCI_RESOURCE_TO_USERplatforms
pci: Fix another sanity check bug in/proc/pcimmap
pci: Only allow WC mmap on prefetchable resources
pci: Addarch_can_pci_mmap_wc()macro
pci: Move multiple declarations ofpci_mmap_page_range()to
pci: AddHAVE_PCI_MMAP_IOto architectures which canmmap()I/O space
pci: Use BAR index in sysfsattr->privateinstead of resource pointer
pci: Add BAR index argument topci_mmap_page_range()
pci: Addpci_mmap_resource_range()and use it for ARM64
arm: Use genericpci_mmap_resource_range()
cris: Use genericpci_mmap_resource_range()
mips: Use genericpci_mmap_resource_range()
mn10300: Use genericpci_mmap_resource_range()
parisc: Use genericpci_mmap_resource_range()
sh: Use genericpci_mmap_resource_range()
unicore: Use genericpci_mmap_resource_range()
arm64: Do not expose PCI mmap through procfsDocumentation/filesystems/sysfs-pci.txt | 9 +++- arch/arm/include/asm/pci.h | 3 +- arch/arm/kernel/bios32.c | 19 ------- arch/arm64/include/asm/pci.h | 3 ++ arch/cris/arch-v32/drivers/pci/bios.c | 22 -------- arch/cris/include/asm/pci.h | 4 +- arch/ia64/include/asm/pci.h | 4 +- arch/ia64/pci/pci.c | 3 +- arch/microblaze/include/asm/pci.h | 6 +-- arch/microblaze/pci/pci-common.c | 2 +- arch/mips/include/asm/pci.h | 5 +- arch/mips/pci/pci.c | 24 --------- arch/mn10300/include/asm/pci.h | 4 +-
arch/mn10300/unit-asb2305/pci-asb2305.c| 23 --------- arch/parisc/include/asm/pci.h | 4 +- arch/parisc/kernel/pci.c | 28 ---------- arch/powerpc/include/asm/pci.h | 9 ++-- arch/powerpc/kernel/pci-common.c | 3 +- arch/sh/drivers/pci/pci.c | 21 -------- arch/sh/include/asm/pci.h | 4 +- arch/sparc/include/asm/pci_64.h | 5 +- arch/sparc/kernel/pci.c | 6 +-- arch/unicore32/include/asm/pci.h | 3 +- arch/unicore32/kernel/pci.c | 23 --------- arch/x86/include/asm/pci.h | 6 +-- arch/x86/pci/i386.c | 3 +- arch/xtensa/include/asm/pci.h | 11 ++-- arch/xtensa/kernel/pci.c | 5 +- drivers/pci/Makefile | 2 +- drivers/pci/mmap.c | 90 +++++++++++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 77 +++++++++++++--------------- drivers/pci/proc.c | 55 ++++++++++++++------ include/linux/pci.h | 19 +++++++33 files changed, 233 insertions(+), 272 deletions(-)create mode 100644
drivers/pci/mmap.c
Arnd Bergmann
maintainerRe: [PATCH 03/17] pci: Only allow WC mmap on prefetchable resources
In reply to David WoodhouseQuoted 7 lines · David Woodhouse
From: David Woodhouse <[email protected]>
The
/proc/bus/pcimmap interface allows the user to specify whether they want WC or not. Don't let them do so on non-prefetchable BARs.Signed-off-by David Woodhouse <[email protected]>
Can you explain this a little more? I understand that we usually want to use WC mappings on prefetchable BARs, and uncached non-WC on non-prefetchable, but why do we have to force an error here?
Couldn't there be some hardware that allows write-combining access but no prefetches?
Arnd
Arnd Bergmann
maintainerRe: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
In reply to David WoodhouseQuoted 12 lines · David Woodhouse
From: David Woodhouse <[email protected]>
Signed-off-by David Woodhouse <[email protected]>--- drivers/pci/proc.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/pci/proc.c +0
-0
drivers/pci/proc.c line 23
Quoted 7 lines
drivers/pci/proc.c +4
-0@@ -17,6 +17,11 @@static int proc_initialized;/* = 0 */ +#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proc like everyone else */ +#undef HAVE_PCI_MMAP +#endif
I'd still prefer this to be a whitelist of the existing architectures using PCI MMAP in procfs, there is really no reason for arm64 to be special, the one thing we want to control here is whether new architectures (including arm64) that have never had either the sysfs or the procfs interface should get one or both of them.
As it seems that there are important use cases for the sysfs interface and your patch series will just make that work everywhere, I'd argue that we should just always provide the sysfs interface now, and use HAVE_PCI_MMAP only control the procfs interface.
That way, we turn on the sysfs interface on arc, arm64, frv and tile as well as any future architecture with PCI support, but leave the procfs support as opt-in.
Arnd
Arnd Bergmann
maintainerRe: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
Quoted 27 lines · Arnd Bergmann
Quoted 12 lines · David Woodhouse
From: David Woodhouse <[email protected]>
Signed-off-by David Woodhouse <[email protected]>--- drivers/pci/proc.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/pci/proc.c +0
-0drivers/pci/proc.c line 23
Quoted 7 lines
drivers/pci/proc.c +4
-0@@ -17,6 +17,11 @@static int proc_initialized;/* = 0 */ +#ifdef __aarch64__ +/* ARM64 wants to be special and not expose this through /proc like everyone else */ +#undef HAVE_PCI_MMAP +#endif I'd still prefer this to be a whitelist of the existing architectures using PCI MMAP in procfs, there is really no reason for arm64 to be special, the one thing we want to control here is whether new architectures (including arm64) that have never had either the sysfs or the procfs interface should get one or both of them.
Quoted 8 lines
As it seems that there are important use cases for the sysfs interface and your patch series will just make that work everywhere, I'd argue that we should just always provide the sysfs interface now, and use
HAVE_PCI_MMAPonly control the procfs interface.That way, we turn on the sysfs interface on arc, arm64, frv and tile as well as any future architecture with PCI support, but leave the procfs support as opt-in.
Something alone these lines, to replace your patch 17/17 and the one that turns on HAVE_PCI_MMAP for arm64.
drivers/pci/pci-sysfs.c +0 -2
@@ -980,8 +980,6 @@ void pci_remove_legacy_files(struct pci_bus *b) }#endif /* HAVE_PCI_LEGACY */ -#ifdef HAVE_PCI_MMAP -int pci_mmap_fits (struct pci_dev *pdev,int resno,struct vm_area_struct *vma,enum pci_mmap_api mmap_api) {
@@ -1217,10 +1215,6 @@ static int pci_create_resource_files(struct
pci_dev *pdev)
}
return 0;
}
-#else /* !HAVE_PCI_MMAP */
-int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } -void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } -#endif /* HAVE_PCI_MMAP */
/**
* pci_write_rom - used to enable access to the PCI ROM display
drivers/pci/pci.h +0 -2
@@ -21,14 +21,12 @@ void pci_create_firmware_label_files(struct pci_dev *pdev);void pci_remove_firmware_label_files (struct pci_dev *pdev);#endif void pci_cleanup_rom (struct pci_dev *dev); -#ifdef HAVE_PCI_MMAP enum pci_mmap_api {PCI_MMAP_SYSFS ,/* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ };int pci_mmap_fits (struct pci_dev *pdev,int resno,struct vm_area_struct *vmai,enum pci_mmap_api mmap_api); -#endif int pci_probe_reset_function (struct pci_dev *dev);/**
Arnd Bergmann
maintainerQuoted 7 lines · David Woodhouse
This started out as a fairly trivial "add
pci_mmap_page_range()for ARM64" patch. Butpci_mmap_page_range()is a vile interface, taking "user visible" resource addresses converted withpci_resource_to_user()on those platforms unlucky enough to use that... and even in the *sane* sysfs-based mmap method, we convert through user addresses to call the platform-specific method.
Quoted 7 lines
In most cases there's just no need for any of this crap. We can migrate most architectures to a generic implementation without much thought, and the few that aren't converted in this series can probably be added fairly easily too but need a little more arch-specific attention.
Utterly untested for now; I'll do some testing while I deal with the inevitable bikeshedding.
Looks good to me overall, I have replied with one request for clarification, and would like the bikeshed in patch 17 in a different colour.
Arnd
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
In reply to Arnd BergmannQuoted 11 lines · Arnd Bergmann
I'd still prefer this to be a whitelist of the existing architectures using PCI MMAP in procfs, there is really no reason for arm64 to be special, the one thing we want to control here is whether new architectures (including arm64) that have never had either the sysfs or the procfs interface should get one or both of them.
As it seems that there are important use cases for the sysfs interface and your patch series will just make that work everywhere, I'd argue that we should just always provide the sysfs interface now, and use
HAVE_PCI_MMAPonly control the procfs interface.
I still have no sympathy for the "we don't want <this> tiny part of the legacy generic non-architecture-specific procfs ABI to exist on ARM64". Why not just kill /proc/bus/pci *entirely* there?
But sure, I suppose we could refactor things so that the sysfs mmap bits depend on (HAVE_PCI_MMAP || ARCH_GENERIC_MMAP_RESOURCE_RANGE) rather than having architectures define the latter in *addition* to the former.
Quoted 3 lines
That way, we turn on the sysfs interface on arc, arm64, frv and tile as well as any future architecture with PCI support, but leave the procfs support as opt-in.
OK. My plan was for ARCH_GENERIC_MMAP_RESOURCE_RANGE to go away once all architectures were converted, and HAVE_PCI_MMAP to be all that's left. It does make send to do arc, fr-v and tile too though. So we can do it that way.
Re: [PATCH 17/17] arm64: Do not expose PCI mmap through procfs
In reply to Arnd BergmannQuoted 3 lines · Arnd Bergmann
Something alone these lines, to replace your patch 17/17 and the one that turns on
HAVE_PCI_MMAPfor arm64.
No, I think that won't build because you don't have a pci_mmap_page_range() function. And you didn't define ARCH_GENERIC_PCI_MMAP_RESOURCE_RANGE. You probably get away with it if you just fix up the ARCH_GENERIC_PCI_MMAP_RESOURCE_RANGE checks in drivers/pci/mmap.c to be !HAVE_PCI_MMAP?
Quoted 20 lines · David Woodhouse
That leaves IA64 as the last holdout, as the selection of
vm_page_protthere is rather complicated:prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size, vma->vm_page_prot); /* * If the user requested WC, the kernel uses UC or WC for this region, * and the chipset supports WC, we can use WC. Otherwise, we have to * use the same attribute the kernel uses. */ if (write_combine && ((pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_UC || (pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_WC) && efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start)) vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); else vma->vm_page_prot = prot;
Quoted 3 lines
But I suspect it's *overcomplicated*, as the kernel should only ever be mapping PCI memory BARs as UC or WC in the first place, so the middle two checks in the if (write_combine…) condition are redundant.
Agreed.
Quoted 2 lines
And if the
efi_range_is_wc()check isn't gratuitous, perhaps that should be in the generic code wheneverCONFIG_EFIis set?
Sounds dubious whether EFI could even get this right. The efi memory map table is static, but we could remap a BAR to a different spot. Does the efi map have entries for all the places that you could remap a BAR? Isn't it more likely a property of the device whether it supports WC?
-Tony
Re: [PATCH 03/17] pci: Only allow WC mmap on prefetchable resources
In reply to Arnd BergmannQuoted 7 lines · Arnd Bergmann
Quoted 6 lines · David Woodhouse
From: David Woodhouse <[email protected]>
The
/proc/bus/pcimmap interface allows the user to specify whether they want WC or not. Don't let them do so on non-prefetchable BARs.
Quoted 8 lines
Quoted 2 lines
Signed-off-by David Woodhouse <[email protected]>Can you explain this a little more? I understand that we usually want to use WC mappings on prefetchable BARs, and uncached non-WC on non-prefetchable, but why do we have to force an error here?
Couldn't there be some hardware that allows write-combining access but no prefetches?
Note that this is only for the procfs interface. The sysfs interface already imposes the same restriction by just *not* creating the 'resourceX_wc' attr when the resource isn't prefetchable. So this just brings procfs into line.
Re: [PATCH 04/17] pci: Add arch_can_pci_mmap_wc() macro
In reply to David WoodhouseQuoted 112 lines · David Woodhouse
From: David Woodhouse <[email protected]>
Most of the almost-identical versions of
pci_mmap_page_range()silently ignore the 'write_combine' argument and give uncached mappings.Yet we allow the
PCIIOC_WRITE_COMBINEioctl in/proc/bus/pci, expose the 'resourceX_wc' file in sysfs, and allow an attempted mapping to apparently succeed.To fix this, introduce a macro
arch_can_pci_mmap_wc()which indicates whether the platform can do a write-combining mapping. On x86 this ends up beingpat_enabled(), while the few other platforms that support it can just set it to a literal '1'.Signed-off-by David Woodhouse <[email protected]>--- Documentation/filesystems/sysfs-pci.txt | 4 ++++ arch/ia64/include/asm/pci.h | 2 ++ arch/powerpc/include/asm/pci.h | 5 +++-- arch/x86/include/asm/pci.h | 2 ++ arch/xtensa/include/asm/pci.h | 6 +++++- arch/xtensa/kernel/pci.c | 2 +- drivers/pci/pci-sysfs.c | 6 ++++-- drivers/pci/proc.c | 17 ++++++++++------- 8 files changed, 31 insertions(+), 13 deletions(-)Documentation/filesystems/sysfs-pci.txt +4
-0@@ -117,6 +117,10 @@ code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function. Platforms are free to only support subsets of the mmap functionality, but useful return codes should be provided. +Platforms which support write-combining maps of PCI resources must define +arch_can_pci_mmap_wc() which shall evaluate to non-zero at runtime when +write-combining is permitted. + Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms wishing to support legacy functionality should define it and provide pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.arch/ia64/include/asm/pci.h +2
-0@@ -51,6 +51,8 @@ extern unsigned long ia64_max_iommu_merge_mask;#define PCI_DMA_BUS_IS_PHYS (ia64_max_iommu_merge_mask == ~0UL)#define HAVE_PCI_MMAP +#define arch_can_pci_mmap_wc () 1 +extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);#define HAVE_PCI_LEGACY arch/powerpc/include/asm/pci.h +3
-2@@ -81,8 +81,9 @@ struct vm_area_struct;int pci_mmap_page_range (struct pci_dev *pdev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine); -/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ -#define HAVE_PCI_MMAP 1 +/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() and it does WC */ +#define HAVE_PCI_MMAP 1 +#define arch_can_pci_mmap_wc () 1extern int pci_legacy_read (struct pci_bus *bus,loff_t port,u32 *val,size_t count);arch/x86/include/asm/pci.h +2
-0@@ -7,6 +7,7 @@#include <linux/string.h> #include <linux/scatterlist.h> #include <asm/io.h> +#include <asm/pat.h> #include <asm/x86_init.h> #ifdef __KERNEL__@@ -102,6 +103,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);#define HAVE_PCI_MMAP +#define arch_can_pci_mmap_wc () pat_enabled()extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine);arch/xtensa/include/asm/pci.h +5
-1@@ -51,7 +51,11 @@ int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma, enum pci_mmap_state mmap_state, int write_combine);/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ -#define HAVE_PCI_MMAP 1 +#define HAVE_PCI_MMAP 1 + +/* This was wrapped in #if 0 since the first merge of xtensa support... +#define arch_can_pci_mmap_wc() 1 +*/ #endif /* __KERNEL__ */ arch/xtensa/kernel/pci.c +0
-0
arch/xtensa/kernel/pci.c __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma, · line 348
Quoted 5 lines
arch/xtensa/kernel/pci.c +1
-1@@ -345,7 +345,7 @@ __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,/* Set to write-through */ prot = (prot & _PAGE_CA_MASK) | _PAGE_CA_WT; -#if 0 +#ifdef arch_can_pci_mmap_wc
This hunk seems like maybe it should be a separate patch.
The rest of the patch:
- skips creation of /sys/.../resourceX_wc if !arch_can_pci_mmap_wc()
- makes PCIIOC_WRITE_COMBINE fail if !arch_can_pci_mmap_wc()
This part seems different -- it changes the way pci_mmap_page_range() works.
Quoted 27 lines
arch/xtensa/kernel/pci.c +0
-0if (!write_combine) prot |= _PAGE_WRITETHRU;#endif drivers/pci/pci-sysfs.c +4
-2@@ -1210,10 +1210,12 @@ static int pci_create_resource_files(struct pci_dev *pdev)continue ; retval =pci_create_attr (pdev, i,0 ); +#ifdef arch_can_pci_mmap_wc/* for prefetchable resources, create a WC mappable file */ -if (!retval && pdev->resource[i].flags &IORESOURCE_PREFETCH ) +if (!retval &&arch_can_pci_mmap_wc () && + pdev->resource[i].flags &IORESOURCE_PREFETCH ) retval =pci_create_attr (pdev, i,1 ); - +#endif if (retval) {pci_remove_resource_files (pdev);return retval;drivers/pci/proc.c +0
-0
drivers/pci/proc.c static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd, · line 212
Quoted 4 lines
drivers/pci/proc.c +1
-0@@ -209,15 +209,18 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd, fpriv->mmap_state = pci_mmap_mem;break ; +#ifdef arch_can_pci_mmap_wc
Can we get rid of these #ifdefs in the code by adding this to linux/pci.h?
#ifndef arch_can_pci_mmap_wc #define arch_can_pci_mmap_wc() 0 #endif
Quoted 24 lines
drivers/pci/proc.c +9
-7case PCIIOC_WRITE_COMBINE : -if (arg) - fpriv->write_combine =1 ; -else - fpriv->write_combine =0 ; -break ; - +if (arch_can_pci_mmap_wc ()) { +if (arg) + fpriv->write_combine =1 ; +else + fpriv->write_combine =0 ; +break ; + } +/* If arch decided it can't, fall through... */ +#endif /* arch_can_pci_mmap_wc */ #endif /* HAVE_PCI_MMAP */ -default : ret = -EINVAL ;break ;Signature · 1 line
2.9.3
Quoted 7 lines · David Woodhouse
This started out as a fairly trivial "add
pci_mmap_page_range()for ARM64" patch. Butpci_mmap_page_range()is a vile interface, taking "user visible" resource addresses converted withpci_resource_to_user()on those platforms unlucky enough to use that... and even in the *sane* sysfs-based mmap method, we convert through user addresses to call the platform-specific method.
Quoted 7 lines
In most cases there's just no need for any of this crap. We can migrate most architectures to a generic implementation without much thought, and the few that aren't converted in this series can probably be added fairly easily too but need a little more arch-specific attention.
Utterly untested for now; I'll do some testing while I deal with the inevitable bikeshedding.
This looks really nice; thanks a lot for doing this!
I agree with Arnd about the __aarch64__ ifdef in pci/proc.c; I'd rather get rid of that if we can.
I think you had a couple other updates; can you post a v2 when you're done with those?
Quoted 58 lines
David Woodhouse (17):
pci: Fixpci_mmap_fits()forHAVE_PCI_RESOURCE_TO_USERplatforms
pci: Fix another sanity check bug in/proc/pcimmap
pci: Only allow WC mmap on prefetchable resources
pci: Addarch_can_pci_mmap_wc()macro
pci: Move multiple declarations ofpci_mmap_page_range()to <linux/pci.h>
pci: AddHAVE_PCI_MMAP_IOto architectures which canmmap()I/O space
pci: Use BAR index in sysfsattr->privateinstead of resource pointer
pci: Add BAR index argument topci_mmap_page_range()
pci: Addpci_mmap_resource_range()and use it for ARM64
arm: Use genericpci_mmap_resource_range()
cris: Use genericpci_mmap_resource_range()
mips: Use genericpci_mmap_resource_range()
mn10300: Use genericpci_mmap_resource_range()
parisc: Use genericpci_mmap_resource_range()
sh: Use genericpci_mmap_resource_range()
unicore: Use genericpci_mmap_resource_range()
arm64: Do not expose PCI mmap through procfsDocumentation/filesystems/sysfs-pci.txt | 9 +++- arch/arm/include/asm/pci.h | 3 +- arch/arm/kernel/bios32.c | 19 ------- arch/arm64/include/asm/pci.h | 3 ++ arch/cris/arch-v32/drivers/pci/bios.c | 22 -------- arch/cris/include/asm/pci.h | 4 +- arch/ia64/include/asm/pci.h | 4 +- arch/ia64/pci/pci.c | 3 +- arch/microblaze/include/asm/pci.h | 6 +-- arch/microblaze/pci/pci-common.c | 2 +- arch/mips/include/asm/pci.h | 5 +- arch/mips/pci/pci.c | 24 --------- arch/mn10300/include/asm/pci.h | 4 +- arch/mn10300/unit-asb2305/pci-asb2305.c | 23 --------- arch/parisc/include/asm/pci.h | 4 +- arch/parisc/kernel/pci.c | 28 ---------- arch/powerpc/include/asm/pci.h | 9 ++-- arch/powerpc/kernel/pci-common.c | 3 +- arch/sh/drivers/pci/pci.c | 21 -------- arch/sh/include/asm/pci.h | 4 +- arch/sparc/include/asm/pci_64.h | 5 +- arch/sparc/kernel/pci.c | 6 +-- arch/unicore32/include/asm/pci.h | 3 +- arch/unicore32/kernel/pci.c | 23 --------- arch/x86/include/asm/pci.h | 6 +-- arch/x86/pci/i386.c | 3 +- arch/xtensa/include/asm/pci.h | 11 ++-- arch/xtensa/kernel/pci.c | 5 +- drivers/pci/Makefile | 2 +- drivers/pci/mmap.c | 90 +++++++++++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 77 +++++++++++++--------------- drivers/pci/proc.c | 55 ++++++++++++++------ include/linux/pci.h | 19 +++++++ 33 files changed, 233 insertions(+), 272 deletions(-) create mode 100644 drivers/pci/mmap.cSignature · 1 line
2.9.3
Re: [PATCH 04/17] pci: Add arch_can_pci_mmap_wc() macro
In reply to Bjorn HelgaasQuoted 11 lines · Bjorn Helgaas
arch/xtensa/kernel/pci.c __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma, · line 348
Quoted 8 lines
arch/xtensa/kernel/pci.c +0
-0@@ -345,7 +345,7 @@ __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
/* Set to write-through */
prot = (prot &_PAGE_CA_MASK) |_PAGE_CA_WT;arch/xtensa/kernel/pci.c +1
-1-#if 0 +#ifdef arch_can_pci_mmap_wcThis hunk seems like maybe it should be a separate patch.
Quoted 4 lines
...
This part seems different -- it changes the way
pci_mmap_page_range()works.
It doesn't, because arch_can_pci_map_wc isn't defined on xtensa. So it's just a trivial cleanup for future-proofing, turning that 'if 0' into 'if <something that isn't set>'.
Quoted 11 lines
Quoted 9 lines
drivers/pci/proc.c +0
-0@@ -209,15 +209,18 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd, fpriv->mmap_state = pci_mmap_mem; break;
+#ifdefarch_can_pci_mmap_wcCan we get rid of these #ifdefs in the code by adding this to
linux/pci.h?
Quoted 3 lines
#ifndef
arch_can_pci_mmap_wc
#definearch_can_pci_mmap_wc()0
#endif
Er.... at the time, that was non-trivial because there was something that actually needed to be *removed* with the preprocessor instead of just not being called. But after I settled on the incremental approach of having pci_mmap_resource_range() be a wrapper for pci_mmap_page_range() *and* vice versa I think that requirement went away. I'll take another look and see if I can do that now; thanks.
Are you happy with the suggestion that we use HAVE_PCI_MMAP *only* to control mmap on /proc/bus/pci, and we present mmap through sysfs on all platforms via the generic code?