2023-03-23 17:41:29

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments

Refactor pci_bus_for_each_resource() in the same way as it's done in
pci_dev_for_each_resource() case. This will allow to hide iterator
inside the loop, where it's not used otherwise.

No functional changes intended.

Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Krzysztof Wilczyński <[email protected]>
---
drivers/pci/bus.c | 7 +++----
drivers/pci/hotplug/shpchp_sysfs.c | 8 ++++----
drivers/pci/pci.c | 3 +--
drivers/pci/probe.c | 2 +-
drivers/pci/setup-bus.c | 10 ++++------
include/linux/pci.h | 17 +++++++++++++----
6 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 549c4bd5caec..5bc81cc0a2de 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -182,13 +182,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
void *alignf_data,
struct pci_bus_region *region)
{
- int i, ret;
struct resource *r, avail;
resource_size_t max;
+ int ret;

type_mask |= IORESOURCE_TYPE_BITS;

- pci_bus_for_each_resource(bus, r, i) {
+ pci_bus_for_each_resource(bus, r) {
resource_size_t min_used = min;

if (!r)
@@ -289,9 +289,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
struct resource *res = &dev->resource[idx];
struct resource orig_res = *res;
struct resource *r;
- int i;

- pci_bus_for_each_resource(bus, r, i) {
+ pci_bus_for_each_resource(bus, r) {
resource_size_t start, end;

if (!r)
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index 64beed7a26be..01d47a42da04 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -24,16 +24,16 @@
static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
{
struct pci_dev *pdev;
- int index, busnr;
struct resource *res;
struct pci_bus *bus;
size_t len = 0;
+ int busnr;

pdev = to_pci_dev(dev);
bus = pdev->subordinate;

len += sysfs_emit_at(buf, len, "Free resources: memory\n");
- pci_bus_for_each_resource(bus, res, index) {
+ pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len,
@@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char
}
}
len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
- pci_bus_for_each_resource(bus, res, index) {
+ pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) &&
(res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len,
@@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char
}
}
len += sysfs_emit_at(buf, len, "Free resources: IO\n");
- pci_bus_for_each_resource(bus, res, index) {
+ pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_IO)) {
len += sysfs_emit_at(buf, len,
"start = %8.8llx, length = %8.8llx\n",
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7a67611dc5f4..99299f1299c4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -779,9 +779,8 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,
{
const struct pci_bus *bus = dev->bus;
struct resource *r;
- int i;

- pci_bus_for_each_resource(bus, r, i) {
+ pci_bus_for_each_resource(bus, r) {
if (!r)
continue;
if (resource_contains(r, res)) {
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index a3f68b6ba6ac..f8191750f6b7 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -533,7 +533,7 @@ void pci_read_bridge_bases(struct pci_bus *child)
pci_read_bridge_mmio_pref(child);

if (dev->transparent) {
- pci_bus_for_each_resource(child->parent, res, i) {
+ pci_bus_for_each_resource(child->parent, res) {
if (res && res->flags) {
pci_bus_add_resource(child, res,
PCI_SUBTRACTIVE_DECODE);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 027b985dd1ee..fdeb121e9175 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -770,9 +770,8 @@ static struct resource *find_bus_resource_of_type(struct pci_bus *bus,
unsigned long type)
{
struct resource *r, *r_assigned = NULL;
- int i;

- pci_bus_for_each_resource(bus, r, i) {
+ pci_bus_for_each_resource(bus, r) {
if (r == &ioport_resource || r == &iomem_resource)
continue;
if (r && (r->flags & type_mask) == type && !r->parent)
@@ -1204,7 +1203,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
additional_mmio_pref_size = 0;
struct resource *pref;
struct pci_host_bridge *host;
- int hdr_type, i, ret;
+ int hdr_type, ret;

list_for_each_entry(dev, &bus->devices, bus_list) {
struct pci_bus *b = dev->subordinate;
@@ -1228,7 +1227,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
host = to_pci_host_bridge(bus->bridge);
if (!host->size_windows)
return;
- pci_bus_for_each_resource(bus, pref, i)
+ pci_bus_for_each_resource(bus, pref)
if (pref && (pref->flags & IORESOURCE_PREFETCH))
break;
hdr_type = -1; /* Intentionally invalid - not a PCI device. */
@@ -1333,12 +1332,11 @@ EXPORT_SYMBOL(pci_bus_size_bridges);

static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r)
{
- int i;
struct resource *parent_r;
unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM |
IORESOURCE_PREFETCH;

- pci_bus_for_each_resource(b, parent_r, i) {
+ pci_bus_for_each_resource(b, parent_r) {
if (!parent_r)
continue;

diff --git a/include/linux/pci.h b/include/linux/pci.h
index e1277a2bb645..70a4684d5f26 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1446,10 +1446,19 @@ int devm_request_pci_bus_resources(struct device *dev,
/* Temporary until new and working PCI SBR API in place */
int pci_bridge_secondary_bus_reset(struct pci_dev *dev);

-#define pci_bus_for_each_resource(bus, res, i) \
- for (i = 0; \
- (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
- i++)
+#define __pci_bus_for_each_resource_0(bus, res, ...) \
+ for (unsigned int __b = 0; \
+ res = pci_bus_resource_n(bus, __b), __b < PCI_BRIDGE_RESOURCE_NUM;\
+ __b++)
+
+#define __pci_bus_for_each_resource_1(bus, res, __b) \
+ for (__b = 0; \
+ res = pci_bus_resource_n(bus, __b), __b < PCI_BRIDGE_RESOURCE_NUM;\
+ __b++)
+
+#define pci_bus_for_each_resource(bus, res, ...) \
+ CONCATENATE(__pci_bus_for_each_resource_, COUNT_ARGS(__VA_ARGS__)) \
+ (bus, res, __VA_ARGS__)

int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
struct resource *res, resource_size_t size,
--
2.40.0.1.gaa8946217a0b


2023-03-24 09:08:57

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments

On 23/3/23 18:36, Andy Shevchenko wrote:
> Refactor pci_bus_for_each_resource() in the same way as it's done in
> pci_dev_for_each_resource() case. This will allow to hide iterator
> inside the loop, where it's not used otherwise.
>
> No functional changes intended.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> Reviewed-by: Krzysztof Wilczyński <[email protected]>
> ---
> drivers/pci/bus.c | 7 +++----
> drivers/pci/hotplug/shpchp_sysfs.c | 8 ++++----
> drivers/pci/pci.c | 3 +--
> drivers/pci/probe.c | 2 +-
> drivers/pci/setup-bus.c | 10 ++++------
> include/linux/pci.h | 17 +++++++++++++----
> 6 files changed, 26 insertions(+), 21 deletions(-)

Nice.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>

2023-03-30 14:12:40

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments


Greeting,

FYI, we noticed various errors such like
"i40e: probe of 0000:3d:00.0 failed with error -12"
due to commit (built with gcc-11):

commit: d23d5938fd7ced817d6aa1ff86cd671ebbaebfc2 ("[PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments")
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/kernel-h-Split-out-COUNT_ARGS-and-CONCATENATE/20230324-013857
base: https://git.kernel.org/cgit/linux/kernel/git/pci/pci.git next
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments

in testcase: boot

on test machine: 96 threads 2 sockets Intel(R) Xeon(R) Gold 6252 CPU @ 2.10GHz (Cascade Lake) with 512G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


If you fix the issue, kindly add following tag
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-lkp/[email protected]


$ xzgrep error dmesg.xz
[ 51.684385][ T1] i40e: probe of 0000:3d:00.0 failed with error -12
[ 51.709906][ T1] i40e: probe of 0000:3d:00.1 failed with error -12
[ 51.979447][ T638] xhci_hcd: probe of 0000:00:14.0 failed with error -16
[ 55.722124][ T1] calling init_error_injection+0x0/0x70 @ 1
[ 55.729441][ T1] initcall init_error_injection+0x0/0x70 returned 0 after 1316 usecs
e Volatile Files[ 69.603735][ T1054] ioatdma: probe of 0000:00:04.0 failed with error -22
[ 69.630580][ T1054] ioatdma: probe of 0000:00:04.1 failed with error -22
[ 69.658415][ T1054] ioatdma: probe of 0000:00:04.2 failed with error -22
[ 69.706342][ T1054] ioatdma: probe of 0000:00:04.3 failed with error -22
[ 69.788776][ T1054] ioatdma: probe of 0000:00:04.4 failed with error -22
Startin[ 69.810610][ T1054] ioatdma: probe of 0000:00:04.5 failed with error -22
[ 69.838865][ T1054] ioatdma: probe of 0000:00:04.6 failed with error -22
ind portmap serv[ 69.866504][ T1054] ioatdma: probe of 0000:00:04.7 failed with error -22
[ 69.897288][ T1054] ioatdma: probe of 0000:80:04.0 failed with error -22
tem Boot/Shutdow[ 69.917172][ T1054] ioatdma: probe of 0000:80:04.1 failed with error -22
[ 69.936033][ T1054] ioatdma: probe of 0000:80:04.2 failed with error -22
1;39mRPC bind po[ 69.954728][ T1054] ioatdma: probe of 0000:80:04.3 failed with error -22
[ 69.979795][ T1054] ioatdma: probe of 0000:80:04.4 failed with error -22
[ 70.015547][ T1054] ioatdma: probe of 0000:80:04.6 failed with error -22
[ 70.017299][ T1054] ioatdma: probe of 0000:80:04.7 failed with error -22
[ 70.093241][ T1012] ahci: probe of 0000:00:11.5 failed with error -22
0m] Reached targ[ 70.113139][ T1012] ahci: probe of 0000:00:17.0 failed with error -22



To reproduce:

# build kernel
cd linux
cp config-6.3.0-rc1-00011-gd23d5938fd7c .config
make HOSTCC=gcc-11 CC=gcc-11 ARCH=x86_64 olddefconfig prepare modules_prepare bzImage modules
make HOSTCC=gcc-11 CC=gcc-11 ARCH=x86_64 INSTALL_MOD_PATH=<mod-install-dir> modules_install
cd <mod-install-dir>
find lib/ | cpio -o -H newc --quiet | gzip > modules.cgz


git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> -m modules.cgz job-script # job-script is attached in this email

# if come across any failure that blocks the test,
# please remove ~/.lkp and /lkp dir to run from a clean state.



--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests



Attachments:
(No filename) (3.60 kB)
config-6.3.0-rc1-00011-gd23d5938fd7c (172.81 kB)
job-script (5.54 kB)
dmesg.xz (43.29 kB)
Download all attachments

2023-03-30 15:41:02

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments

On Thu, Mar 30, 2023 at 09:24:21PM +0800, kernel test robot wrote:
>
> Greeting,
>
> FYI, we noticed various errors such like
> "i40e: probe of 0000:3d:00.0 failed with error -12"
> due to commit (built with gcc-11):
>
> commit: d23d5938fd7ced817d6aa1ff86cd671ebbaebfc2 ("[PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments")
> url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/kernel-h-Split-out-COUNT_ARGS-and-CONCATENATE/20230324-013857
> base: https://git.kernel.org/cgit/linux/kernel/git/pci/pci.git next
> patch link: https://lore.kernel.org/all/[email protected]/
> patch subject: [PATCH v7 3/6] PCI: Allow pci_bus_for_each_resource() to take less arguments
>
> in testcase: boot
>
> on test machine: 96 threads 2 sockets Intel(R) Xeon(R) Gold 6252 CPU @ 2.10GHz (Cascade Lake) with 512G memory
>
> caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):
>
>
> If you fix the issue, kindly add following tag
> | Reported-by: kernel test robot <[email protected]>
> | Link: https://lore.kernel.org/oe-lkp/[email protected]

Thanks, that is useful test!

--
With Best Regards,
Andy Shevchenko