Skip to contentSkip to conversation

PCI: define max devices number on PCIBus as PCIBUS_MAX_DEVICES in pci.h

PATCH In review Ken CC 4 participants 11 messages Aug 24, 2010 KVM

lore
Share & tools
lore

Ken CC

author
#0 lore raw

PATCH 1/3 PCI: define max devices number on PCIBus as PCIBUS_MAX_DEVICES in pci.h

---
 hw/pci.c |    2 +-
 hw/pci.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
hw/pci.c +1 -1
index 70dbace..02019a1 100644
@@ -47,7 +47,7 @@ struct PCIBus {
     pci_hotplug_fn hotplug;
     DeviceState *hotplug_qdev;
     void *irq_opaque;
-    PCIDevice *devices[256];
+    PCIDevice *devices[PCIBUS_MAX_DEVICES];
     PCIDevice *parent_dev;
     target_phys_addr_t mem_base;
 
hw/pci.h +1 -0
index ccb99d0..f90840c 100644
@@ -100,6 +100,7 @@ typedef struct PCIIORegion {
 
 #define PCI_ROM_SLOT 6
 #define PCI_NUM_REGIONS 7
+#define PCIBUS_MAX_DEVICES 256
 
 #include "pci_regs.h"
 
author
#1 lore raw

PATCH 2/3 pci init: fail qemu if devfn exceeding the max devices number supported on bus

assert(devfn < PCIBUS_MAX_DEVICES)

---
 hw/pci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.c +1 -0
index 02019a1..1e804da 100644
@@ -747,6 +747,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          PCIConfigWriteFunc *config_write,
                                          bool is_bridge)
 {
+    assert(devfn < PCIBUS_MAX_DEVICES);
     if (devfn < 0) {
         for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
             devfn += PCI_FUNC_MAX) {
author
#2 lore raw

PATCH 3/3 Check pci slot number in parse_pci_devfn

In reply to Ken CC

Define MAX_PCI_SLOTS as 0x1f, if pci addr provided from command line is bigger than 0x1f, return error -EINVAL.

0x1f << 3 | 7 == 255 (PCIBUS_MAX_DEVICES - 1)

---
 hw/qdev-properties.c |    2 ++
 hw/qdev.h            |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
hw/qdev-properties.c +2 -0
index 9219cd7..96d814c 100644
@@ -514,6 +514,8 @@ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
             return -EINVAL;
         }
     }
+    if (slot > MAX_PCI_SLOTS)
+        return -EINVAL;
     if (str[n] != '\0')
         return -EINVAL;
     if (fn > 7)
hw/qdev.h +3 -0
index 678f8b7..fcfe52e 100644
@@ -7,6 +7,9 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 
+
+#define MAX_PCI_SLOTS 0x1f
+
 typedef struct Property Property;
 
 typedef struct PropertyInfo PropertyInfo;
#3 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

thanks,

Quoted 40 lines · Ken CC

Define MAX_PCI_SLOTS as 0x1f, if pci addr provided from command line is bigger than 0x1f, return error -EINVAL.

0x1f << 3 | 7 == 255 (PCIBUS_MAX_DEVICES - 1)

---
 hw/qdev-properties.c |    2 ++
 hw/qdev.h            |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
hw/qdev-properties.c +2 -0
index 9219cd7..96d814c 100644
@@ -514,6 +514,8 @@ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
             return -EINVAL;
         }
     }
+    if (slot > MAX_PCI_SLOTS)
+        return -EINVAL;
     if (str[n] != '\0')
         return -EINVAL;
     if (fn > 7)
hw/qdev.h +3 -0
index 678f8b7..fcfe52e 100644
@@ -7,6 +7,9 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 
+
+#define MAX_PCI_SLOTS 0x1f
+
 typedef struct Property Property;
 
 typedef struct PropertyInfo PropertyInfo;
Signature · 1 line
yamahata
#4 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 7 lines · Isaku Yamahata

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

These aren't slots, are they? They are functions.

There's a lot of slot/function confusion in qemu.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 10 lines · Avi Kivity
Quoted 7 lines · Isaku Yamahata

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

Quoted 1 line

There's a lot of slot/function confusion in qemu.

Agreed.

Signature · 1 line
yamahata
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 4 lines · Isaku Yamahata
Quoted 3 lines · Avi Kivity
Quoted 2 lines · Isaku Yamahata

Add Cc: [email protected].

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

+ assert(devfn< PCIBUS_MAX_DEVICES);

Looks like we're comparing a function number to PCIBUS_MAX_DEVICES.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 10 lines · Avi Kivity
Quoted 9 lines · Isaku Yamahata
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Isaku Yamahata

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

+ assert(devfn< PCIBUS_MAX_DEVICES);

Looks like we're comparing a function number to PCIBUS_MAX_DEVICES.

Ah, you're talking about 2/3. I talked about 3/3.
You're right. The name is misleading.
PCIBUS_MAX_FUNCTIONS? Or suggestions?

Signature · 1 line
yamahata
#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 14 lines · Isaku Yamahata
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Isaku Yamahata
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Isaku Yamahata

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

Quoted 7 lines
Quoted 4 lines

+ assert(devfn< PCIBUS_MAX_DEVICES);

Looks like we're comparing a function number to PCIBUS_MAX_DEVICES.

Ah, you're talking about 2/3. I talked about 3/3.
You're right. The name is misleading.
PCIBUS_MAX_FUNCTIONS? Or suggestions?

Or assert(devfn / 8 < PCIBUS_MAX_DEVICES) (and change that to be 32).

Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

In reply to Avi Kivity
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Isaku Yamahata
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Isaku Yamahata

Add Cc: [email protected].

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

+ assert(devfn< PCIBUS_MAX_DEVICES);

Looks like we're comparing a function number to PCIBUS_MAX_DEVICES.

PCIBUS_MAX_DEVICES is the size of PCIBus.devices[], I have added it in the first patch at the defination of struct PCIBus, line 50 hw/pci.c. so i think the better name of the macro should be PCIBUS_MAX_FN, right?

Ken

Quoted 7 lines
Signature · 6 lines
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] Check pci slot number in parse_pci_devfn

Quoted 17 lines · Chen Cao
Quoted 16 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Quoted 3 lines · Avi Kivity
Quoted 2 lines · Isaku Yamahata

Add Cc: [email protected].

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

MAX_PCI_SLOTS should be in pci.h instead of qdev.h? And the name should be start with PCI_ prefix for consistency?

Except that, the patches look okay.

These aren't slots, are they? They are functions.

The function checks if given $slot.$fn (or $slot) is valid. So it's slots. max 32.

+ assert(devfn< PCIBUS_MAX_DEVICES);

Quoted 6 lines
Quoted 2 lines

Looks like we're comparing a function number to PCIBUS_MAX_DEVICES.

PCIBUS_MAX_DEVICES is the size of PCIBus.devices[], I have added it in the first patch at the defination of struct PCIBus, line 50 hw/pci.c. so i think the better name of the macro should be PCIBUS_MAX_FN, right?

Or make it 32 and scale it by PCI_FUNCTIONS_PER_DEVICE.

PCIBus.devices[] should be renamed to functions[] (later).

Signature · 1 line
error compiling committee.c: too many arguments to function