Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1704588 > unrolled thread

[PATCH 00/10] PCI: pci resource allocation test module

Started byYinghai Lu <yinghai@kernel.org>
First post2017-08-05 08:40 +0200
Last post2017-08-05 08:50 +0200
Articles 4 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/10] PCI: pci resource allocation test module Yinghai Lu <yinghai@kernel.org> - 2017-08-05 08:40 +0200
    [PATCH 03/10] PCI: export symbol for PCI_TEST module Yinghai Lu <yinghai@kernel.org> - 2017-08-05 08:50 +0200
    [PATCH 04/10] PCI: extend pci device match_driver state Yinghai Lu <yinghai@kernel.org> - 2017-08-05 08:50 +0200
    [PATCH 01/10] PCI: avoid arch_remove_reservations() for PCI_TEST Yinghai Lu <yinghai@kernel.org> - 2017-08-05 08:50 +0200

#1704588 — [PATCH 00/10] PCI: pci resource allocation test module

FromYinghai Lu <yinghai@kernel.org>
Date2017-08-05 08:40 +0200
Subject[PATCH 00/10] PCI: pci resource allocation test module
Message-ID<ub0UF-189-3@gated-at.bofh.it>
Read from data file and mask file, to build simulated data structure, and
have pci_ops to use them.

Extract calling for pci_create_root_bus, scan_child_bus, resource survey
and resource assign ... to see if those functions work as expected with
simulated data.

mask is with rw bits on pci registers, so we can make pci BAR sizing working.

It also support bus number assign-all.

Only tested on x86 64bit arch.

  # insmod pci_test.ko data_file=pci_test_data.txt mask_file=pci_test_mask.txt
  # lspci -tv
  # cat /proc/ioports_test
  # cat /proc/iomem_test
  # rmmod pci_test

also in git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for_pci_v4.14_pci_next

Thanks

Yinghai

Yinghai Lu (10):
  PCI: avoid arch_remove_reservations() for PCI_TEST
  PCI: introduce ioport_res/iomem_res for PCI_TEST
  PCI: export symbol for PCI_TEST module
  PCI: extend pci device match_driver state
  PCI: Add PCI_TEST module for resource allocation
  PCI: PCI_TEST simple data
  PCI: PCI_TEST data from x5-8
  PCI: PCI_TEST data from x5-8 with zeroed bus number
  PCI: PCI_TEST data from x2-8
  PCI: PCI_TEST data from x2-8 with zeroed bus number

 arch/x86/kernel/resource.c             |    15 +-
 arch/x86/pci/i386.c                    |     1 +
 drivers/iommu/amd_iommu_init.c         |     2 +-
 drivers/pci/Kconfig                    |     6 +
 drivers/pci/Makefile                   |     2 +
 drivers/pci/bus.c                      |     3 +-
 drivers/pci/pci-driver.c               |     2 +-
 drivers/pci/pci_test.c                 |  1281 ++
 drivers/pci/pci_test_data.txt          |    24 +
 drivers/pci/pci_test_data_x2-8.txt     | 22818 +++++++++++++++++++++++++++++++
 drivers/pci/pci_test_data_x2-8_bus.txt | 22818 +++++++++++++++++++++++++++++++
 drivers/pci/pci_test_data_x5-8.txt     |  5656 ++++++++
 drivers/pci/pci_test_data_x5-8_bus.txt |  5656 ++++++++
 drivers/pci/pci_test_mask.txt          |     5 +
 drivers/pci/pci_test_mask_x2-8.txt     |   319 +
 drivers/pci/pci_test_mask_x5-8.txt     |   176 +
 drivers/pci/probe.c                    |     4 +-
 drivers/pci/quirks.c                   |     2 +-
 drivers/pci/setup-bus.c                |     3 +-
 drivers/pci/setup-res.c                |     4 +-
 include/linux/ioport.h                 |     3 +-
 include/linux/pci.h                    |    15 +-
 kernel/resource.c                      |     7 +-
 23 files changed, 58808 insertions(+), 14 deletions(-)
 create mode 100644 drivers/pci/pci_test.c
 create mode 100644 drivers/pci/pci_test_data.txt
 create mode 100644 drivers/pci/pci_test_data_x2-8.txt
 create mode 100644 drivers/pci/pci_test_data_x2-8_bus.txt
 create mode 100644 drivers/pci/pci_test_data_x5-8.txt
 create mode 100644 drivers/pci/pci_test_data_x5-8_bus.txt
 create mode 100644 drivers/pci/pci_test_mask.txt
 create mode 100644 drivers/pci/pci_test_mask_x2-8.txt
 create mode 100644 drivers/pci/pci_test_mask_x5-8.txt

-- 
2.9.4

[toc] | [next] | [standalone]


#1704589 — [PATCH 03/10] PCI: export symbol for PCI_TEST module

FromYinghai Lu <yinghai@kernel.org>
Date2017-08-05 08:50 +0200
Subject[PATCH 03/10] PCI: export symbol for PCI_TEST module
Message-ID<ub14l-1by-1@gated-at.bofh.it>
In reply to#1704588
We need to use them from pci_test module, so expose them.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/pci/i386.c     | 1 +
 drivers/pci/setup-bus.c | 1 +
 kernel/resource.c       | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 7b43071..9065c58 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -383,6 +383,7 @@ void pcibios_resource_survey_bus(struct pci_bus *bus)
 	if (!(pci_probe & PCI_ASSIGN_ROMS))
 		pcibios_allocate_rom_resources(bus);
 }
+EXPORT_SYMBOL_GPL(pcibios_resource_survey_bus);
 
 void __init pcibios_resource_survey(void)
 {
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1c30102..24292e9 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1839,6 +1839,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
 	/* dump the resource on buses */
 	pci_bus_dump_resources(bus);
 }
+EXPORT_SYMBOL_GPL(pci_assign_unassigned_root_bus_resources);
 
 void __init pci_assign_unassigned_resources(void)
 {
diff --git a/kernel/resource.c b/kernel/resource.c
index 4174020..0d40d9a 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -301,6 +301,8 @@ void release_child_resources(struct resource *r)
 	write_unlock(&resource_lock);
 }
 
+EXPORT_SYMBOL_GPL(release_child_resources);
+
 /**
  * request_resource_conflict - request and reserve an I/O or memory resource
  * @root: root resource descriptor
-- 
2.9.4

[toc] | [prev] | [next] | [standalone]


#1704590 — [PATCH 04/10] PCI: extend pci device match_driver state

FromYinghai Lu <yinghai@kernel.org>
Date2017-08-05 08:50 +0200
Subject[PATCH 04/10] PCI: extend pci device match_driver state
Message-ID<ub14m-1by-3@gated-at.bofh.it>
In reply to#1704588
Change it from false/true to -1/0/1.

If it is set from -1, then it will never get change to 1 later.

For PCI_TEST, the simulated device does not have realy function
support except bus number and BAR setting.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/iommu/amd_iommu_init.c | 2 +-
 drivers/pci/bus.c              | 3 ++-
 drivers/pci/pci-driver.c       | 2 +-
 drivers/pci/probe.c            | 2 +-
 include/linux/pci.h            | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 3723037..6d706ca 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1558,7 +1558,7 @@ static int iommu_init_pci(struct amd_iommu *iommu)
 		return -ENODEV;
 
 	/* Prevent binding other PCI device drivers to IOMMU devices */
-	iommu->dev->match_driver = false;
+	iommu->dev->match_driver = 0;
 
 	pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET,
 			      &iommu->cap);
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index bc56cf1..e2c0bda 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -322,7 +322,8 @@ void pci_bus_add_device(struct pci_dev *dev)
 	pci_proc_attach_device(dev);
 	pci_bridge_d3_update(dev);
 
-	dev->match_driver = true;
+	if (dev->match_driver == 0)
+		dev->match_driver = 1;
 	retval = device_attach(&dev->dev);
 	if (retval < 0 && retval != -EPROBE_DEFER) {
 		dev_warn(&dev->dev, "device attach failed (%d)\n", retval);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index d51e873..c67b872 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1373,7 +1373,7 @@ static int pci_bus_match(struct device *dev, struct device_driver *drv)
 	struct pci_driver *pci_drv;
 	const struct pci_device_id *found_id;
 
-	if (!pci_dev->match_driver)
+	if (pci_dev->match_driver != 1)
 		return 0;
 
 	pci_drv = to_pci_driver(drv);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 1811016..34ffbdf 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2021,7 +2021,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 	pci_set_msi_domain(dev);
 
 	/* Notifier could use PCI capabilities */
-	dev->match_driver = false;
+	dev->match_driver = 0;
 	ret = device_add(&dev->dev);
 	WARN_ON(ret < 0);
 }
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c58a635..6e81d64 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -344,7 +344,7 @@ struct pci_dev {
 	unsigned int	irq;
 	struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
 
-	bool match_driver;		/* Skip attaching driver */
+	int match_driver;		/* Skip attaching driver */
 	/* These fields are used by common fixups */
 	unsigned int	transparent:1;	/* Subtractive decode PCI bridge */
 	unsigned int	multifunction:1;/* Part of multi-function device */
-- 
2.9.4

[toc] | [prev] | [next] | [standalone]


#1704591 — [PATCH 01/10] PCI: avoid arch_remove_reservations() for PCI_TEST

FromYinghai Lu <yinghai@kernel.org>
Date2017-08-05 08:50 +0200
Subject[PATCH 01/10] PCI: avoid arch_remove_reservations() for PCI_TEST
Message-ID<ub14m-1by-7@gated-at.bofh.it>
In reply to#1704588
arch_remove_reservations will clip out with e820 from host that kernel
running, that will cause failure from PCI_TEST from simulated data.

PCI_TEST has different iomem resource instead iomem_resource,
so check if iomem_resource is related to avoid calling
arch_remove_reservations()

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/kernel/resource.c | 15 +++++++++++++--
 include/linux/ioport.h     |  3 ++-
 kernel/resource.c          |  5 +++--
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
index 5ab3895..f19b0f6 100644
--- a/arch/x86/kernel/resource.c
+++ b/arch/x86/kernel/resource.c
@@ -35,14 +35,25 @@ static void remove_e820_regions(struct resource *avail)
 	}
 }
 
-void arch_remove_reservations(struct resource *avail)
+static int is_from_iomem_resource(struct resource *root)
+{
+	while (root->parent)
+		root = root->parent;
+
+	if (root == &iomem_resource)
+		return 1;
+
+	return 0;
+}
+
+void arch_remove_reservations(struct resource *root, struct resource *avail)
 {
 	/*
 	 * Trim out BIOS area (high 2MB) and E820 regions. We do not remove
 	 * the low 1MB unconditionally, as this area is needed for some ISA
 	 * cards requiring a memory range, e.g. the i82365 PCMCIA controller.
 	 */
-	if (avail->flags & IORESOURCE_MEM) {
+	if ((avail->flags & IORESOURCE_MEM) && is_from_iomem_resource(root)) {
 		resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
 
 		remove_e820_regions(avail);
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 6230064..4e9272d 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -177,7 +177,8 @@ extern struct resource *insert_resource_conflict(struct resource *parent, struct
 extern int insert_resource(struct resource *parent, struct resource *new);
 extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
 extern int remove_resource(struct resource *old);
-extern void arch_remove_reservations(struct resource *avail);
+extern void arch_remove_reservations(struct resource *root,
+					struct resource *avail);
 extern int allocate_resource(struct resource *root, struct resource *new,
 			     resource_size_t size, resource_size_t min,
 			     resource_size_t max, resource_size_t align,
diff --git a/kernel/resource.c b/kernel/resource.c
index 9b5f044..4174020 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -570,7 +570,8 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags,
 }
 EXPORT_SYMBOL_GPL(region_intersects);
 
-void __weak arch_remove_reservations(struct resource *avail)
+void __weak arch_remove_reservations(struct resource *root,
+					 struct resource *avail)
 {
 }
 
@@ -622,7 +623,7 @@ static int __find_resource(struct resource *root, struct resource *old,
 			goto next;
 
 		resource_clip(&tmp, constraint->min, constraint->max);
-		arch_remove_reservations(&tmp);
+		arch_remove_reservations(root, &tmp);
 
 		/* Check for overflow after ALIGN() */
 		avail.start = ALIGN(tmp.start, constraint->align);
-- 
2.9.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web