*** SUBJECT HERE ***
v11 cover *** SUBJECT HERE ***
*** BLURB HERE ***
Isaku Yamahata (5):
qdev: export qdev_find_recursive() for later use
pci: introduce a helper function to convert qdev id to PCIDevice pcie/aer: glue aer error injection into qemu monitor
pci: introduce a parser for fw device path to pci device pcie/aer: use fw device path as fallback for aer injection command
hmp-commands.hx | 30 +++++++ hw/pci-stub.c | 13 +++ hw/pci.c | 164 +++++++++++++++++++++++++++++++++++++++ hw/pci.h | 3 + hw/pcie_aer.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.c | 2 +- hw/qdev.h | 2 + sysemu.h | 5 + 8 files changed, 445 insertions(+), 1 deletions(-)
PATCH v11 1/5 qdev: export qdev_find_recursive() for later use
This patch exports qdev_find_recursive() for later use.
--- hw/qdev.c | 2 +- hw/qdev.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-)
hw/qdev.c +1 -1
@@ -548,7 +548,7 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,return NULL ; } -static DeviceState *qdev_find_recursive (BusState *bus,const char *id) +DeviceState *qdev_find_recursive (BusState *bus,const char *id) {DeviceState *dev, *ret;BusState *child;
hw/qdev.h +2 -0
@@ -183,6 +183,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);/*** BUS API. ***/ +DeviceState *qdev_find_recursive (BusState *bus,const char *id); +/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn )(BusState *bus,void *opaque);typedef int (qdev_walkerfn )(DeviceState *dev,void *opaque);
Signature · 1 line
1.7.1.1
PATCH v11 2/5 pci: introduce a helper function to convert qdev id to PCIDevice
In reply to Isaku YamahataThis patch introduce a helper function to get PCIDevice from qdev id. This function will be used later.
--- hw/pci.c | 35 +++++++++++++++++++++++++++++++++++ hw/pci.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-)
hw/pci.c +35 -0
@@ -2027,3 +2027,38 @@ static char *pcibus_get_dev_path(DeviceState *dev)return strdup (path); } +static int pci_qdev_find_recursive (PCIBus *bus, +const char *id,PCIDevice **pdev) +{ +DeviceState *qdev =qdev_find_recursive (&bus->qbus, id); +if (!qdev) { +return -ENODEV ; + } + +/* roughly check if given qdev is pci device */ +if (qdev->info->init == &pci_qdev_init && + qdev->parent_bus->info == &pci_bus_info) { + *pdev =DO_UPCAST (PCIDevice, qdev, qdev); +return 0 ; + } +return -EINVAL ; +} + +int pci_qdev_find_device (const char *id,PCIDevice **pdev) +{ +struct PCIHostBus *host; +int rc = -ENODEV ; + + QLIST_FOREACH(host, &host_buses, next) { +int tmp =pci_qdev_find_recursive (host->bus, id, pdev); +if (!tmp) { + rc =0 ; +break ; + } +if (tmp != -ENODEV ) { + rc = tmp; + } + } + +return rc; +}
hw/pci.h +1 -0
@@ -252,6 +252,7 @@ PCIBus *pci_find_root_bus(int domain);int pci_find_domain (const PCIBus *bus);PCIBus *pci_find_bus (PCIBus *bus,int bus_num);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,int slot,int function); +int pci_qdev_find_device (const char *id,PCIDevice **pdev);PCIBus *pci_get_bus_devfn (int *devfnp,const char *devaddr); int pci_parse_devaddr(const char *addr, int *domp, int *busp,
Signature · 1 line
1.7.1.1
PATCH v11 3/5 pcie/aer: glue aer error injection into qemu monitor
In reply to Isaku Yamahataintroduce pcie_aer_inject_error command.
---
Change v10 -> v11:
- use qdev id
Changes v9 -> v10:
- use fw device path
- error path
- pci-stub.c for CONFIG_PCI=n
Changes v8 -> v9:
- revise error code
Changes v7 -> v8:
- use domain:slot.func:slot.func...:slot.func instead of domain:bus:slot.func
- allow symbolic aer error name in addition to 32bit value
Changes v6 -> v7:
- check return value.
Changes v3 -> v4:
- s/PCIE_AER/PCIEAER/g for structure names.
- compilation adjustment.
Changes v2 -> v3:
- compilation adjustment.
--- hmp-commands.hx | 25 ++++++ hw/pci-stub.c | 13 +++ hw/pcie_aer.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ sysemu.h | 5 + 4 files changed, 266 insertions(+), 0 deletions(-)
hmp-commands.hx +25 -0
@@ -873,6 +873,31 @@ Hot remove PCI device. ETEXI { + .name = "pcie_aer_inject_error", + .args_type = "advisory_non_fatal:-a,correctable:-c," + "id:s,error_status:s," + "header0:i?,header1:i?,header2:i?,header3:i?," + "prefix0:i?,prefix1:i?,prefix2:i?,prefix3:i?", + .params = "[-a] [-c] id " + "<error_status> [<tlp header> [<tlp header prefix>]]", + .help = "inject pcie aer error\n\t\t\t" + " -a for advisory non fatal error\n\t\t\t" + " -c for correctable error\n\t\t\t" + "<id> = qdev device id\n\t\t\t" + "<error_status> = error string or 32bit\n\t\t\t" + "<tlb header> = 32bit x 4\n\t\t\t" + "<tlb header prefix> = 32bit x 4", + .user_print = pcie_aer_inject_error_print, + .mhandler.cmd_new = do_pcie_aer_inejct_error, + }, + +STEXI +@item pcie_aer_inject_error +@findex pcie_aer_inject_error +Inject PCIe AER error +ETEXI + + { .name = "host_net_add", .args_type = "device:s,opts:s?", .params = "tap|user|socket|vde|dump [options]",
hw/pci-stub.c +13 -0
@@ -18,6 +18,7 @@* with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "sysemu.h" #include "monitor.h" #include "pci.h"
@@ -35,3 +36,15 @@ void do_pci_info_print(Monitor *mon, const QObject *data) {pci_error_message (mon); } + +int do_pcie_aer_inejct_error (Monitor *mon, +const QDict *qdict,QObject **ret_data) +{ +pci_error_message (mon); +return -ENOSYS ; +} + +void pcie_aer_inject_error_print (Monitor *mon,const QObject *data) +{ +pci_error_message (mon); +}
hw/pcie_aer.c +223 -0
232 lines not on this page · raw message
sysemu.h +5 -0
@@ -157,6 +157,11 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict);void drive_hot_add (Monitor *mon,const QDict *qdict);void do_pci_device_hot_remove (Monitor *mon,const QDict *qdict); +/* pcie aer error injection */ +void pcie_aer_inject_error_print (Monitor *mon,const QObject *data); +int do_pcie_aer_inejct_error (Monitor *mon, +const QDict *qdict,QObject **ret_data); +/* serial ports */ #define MAX_SERIAL_PORTS 4
Signature · 1 line
1.7.1.1
PATCH v11 4/5 pci: introduce a parser for fw device path to pci device
In reply to Isaku YamahataIntroduce a function to parse fw device path to pci device.
the format is
/pci@{<ioport>, <mmio>}/[<fw_name>]@<slot>,<func>/.../[<fw_name>]@<slot>,<func>
<ioport> = "i"<ioport addr in hex>
<mmio> = <mmio addr in hex>
<slot> = slot number in hex
<func> = func number in hex
--- hw/pci.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci.h | 2 + 2 files changed, 131 insertions(+), 0 deletions(-)
hw/pci.c +129 -0
@@ -2062,3 +2062,132 @@ int pci_qdev_find_device(const char *id, PCIDevice **pdev)return rc; } + +/* +* Parse format and get PCIDevice +* return 0 on success +* <0 on error: format is invalid or device isn't found. +* +* Format: +* /pci@{<ioport>, <mmio>}/[<fw_name>]@<slot>,<func>/... +* .../[<fw_name>]@<slot>,<func> +* +* <ioport> = "i"<ioport addr in hex> +* <mmio> = <mmio addr in hex> +* <slot> = slot number in hex +* <func> = func number in hex +* +*/ +int pci_parse_fw_dev_path (const char *path,PCIDevice **pdev) +{ +const char *p = path; +char *e; +size_t len; +PCIBus *bus; +struct PCIHostBus *host; + +if (*p !='/' ) { +return -EINVAL ; + } + e =strchr (p +1 ,'/' ); +if (e ==NULL ) { +return -EINVAL ; + } + len = e - p; + p = e +1 ; + + bus =NULL ; + QLIST_FOREACH(host, &host_buses, next) { +DeviceState *qdev = host->bus->qbus.parent; +if (qdev) { +char *devpath =qdev_get_fw_dev_path (qdev); + +if (len ==strlen (devpath) && !strncmp (devpath, path, len)) { + bus = host->bus; +qemu_free (devpath); +break ; + } +qemu_free (devpath); + }else { +/* This pci bus doesn't have host-to-pci bridge device. +* Check only if the path is pci ignoring other parameters. */ +#define PCI_FW_PATH "/pci@" +if (strncmp (path,PCI_FW_PATH ,strlen (PCI_FW_PATH ))) { +return -EINVAL ; + } + bus = host->bus; +break ; + } + } + +for (;;) { +char *at; +char *comma; +unsigned long slot; +unsigned long func; +PCIDevice *dev; +PCIBus *child_bus; + +if (!bus) { +return -ENODEV ; + } +if (*p =='\0' ) { +return -EINVAL ; + } + + at =strchr (p,'@' ); +if (at ==NULL ) { +return -EINVAL ; + } + slot =strtoul (at +1 , &e,16 ); +if (e == at +1 || *e !=',' ) { +return -EINVAL ; + } +if (slot >=PCI_SLOT_MAX ) { +return -EINVAL ; + } + + comma = e; + func =strtoul (comma +1 , &e,16 ); +if (e == comma +1 || (*e !='/' && *e !='\0' )) { +return -EINVAL ; + } +if (func >=PCI_FUNC_MAX ) { +return -EINVAL ; + } + + len = e - p; + dev = bus->devices[PCI_DEVFN (slot, func)]; +if (!dev) { +return -ENODEV ; + } +if (at != p) { +/* fw_name is specified. */ +char *fw_dev_path =pcibus_get_fw_dev_path (&dev->qdev); +if (strncmp (p, fw_dev_path, len)) { +qemu_free (fw_dev_path); +return -EINVAL ; + } +qemu_free (fw_dev_path); + } + +if (*e =='\0' ) { + *pdev = dev; +return 0 ; + } + +/* +* descending down pci-to-pci bridge. +* At the moment, there is no way to safely determine if the given +* pci device is really pci-to-pci device. +*/ + p = e; + QLIST_FOREACH(child_bus, &bus->child, sibling) { +if (child_bus->parent_dev == dev) { + bus = child_bus; +continue ; + } + } + bus =NULL ; + } +}
hw/pci.h +2 -0
@@ -16,6 +16,7 @@#define PCI_DEVFN (slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07))#define PCI_SLOT (devfn) (((devfn) >> 3) & 0x1f)#define PCI_FUNC (devfn) ((devfn) & 0x07) +#define PCI_SLOT_MAX 32#define PCI_FUNC_MAX 8/* Class, Vendor and Device IDs from Linux's pci_ids.h */
@@ -259,6 +260,7 @@ int pci_parse_devaddr(const char *addr, int *domp, int *busp, unsigned int *slotp, unsigned int *funcp);int pci_read_devaddr (Monitor *mon,const char *addr,int *domp,int *busp,unsigned *slotp); +int pci_parse_fw_dev_path (const char *path,PCIDevice **pdev);void do_pci_info_print (Monitor *mon,const QObject *data);void do_pci_info (Monitor *mon,QObject **ret_data);
Signature · 1 line
1.7.1.1
PATCH v11 5/5 pcie/aer: use fw device path as fallback for aer injection command
In reply to Isaku Yamahatapcie_aer_inject command: When qdev id failed, try fw device path as fallback.
--- hmp-commands.hx | 7 ++++++- hw/pcie_aer.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-)
hmp-commands.hx +6 -1
@@ -878,12 +878,17 @@ ETEXI "id:s,error_status:s," "header0:i?,header1:i?,header2:i?,header3:i?," "prefix0:i?,prefix1:i?,prefix2:i?,prefix3:i?", - .params = "[-a] [-c] id " + .params = "[-a] [-c] [id|pci_fw_dev_path] " "<error_status> [<tlp header> [<tlp header prefix>]]", .help = "inject pcie aer error\n\t\t\t" " -a for advisory non fatal error\n\t\t\t" " -c for correctable error\n\t\t\t" "<id> = qdev device id\n\t\t\t" + "<pci_fw_dev_path> = fw device path to pci device" + "\n\t\t\t/pci@<ioport or mmio(hex)>" + "[<fw_name>]@<slot(hex)>,<func(hex)>/.../" + "[<fw_name>]@<slot(hex)>,<func(hex)>\n\t\t\t" + "e.g. /pci@i0cf8/@1,1\n\t\t\t" "<error_status> = error string or 32bit\n\t\t\t" "<tlb header> = 32bit x 4\n\t\t\t" "<tlb header prefix> = 32bit x 4",
hw/pcie_aer.c +8 -4
@@ -969,10 +969,14 @@ int do_pcie_aer_inejct_error(Monitor *mon, ret =pci_qdev_find_device (id, &dev);if (ret <0 ) { -monitor_printf (mon, -"id or pci device path is invalid or device not " -"found. %s\n" , id); -return ret; +/* fall back to fw device path */ + ret =pci_parse_fw_dev_path (id, &dev); +if (ret <0 ) { +monitor_printf (mon, +"id or pci device path is invalid or device not " +"found. %s\n" , id); +return ret; + } }if (!pci_is_express (dev)) { monitor_printf(mon, "the device doesn't support pci express. %s\n",
Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH v11 0/5] pcie/aer: glue inject aer error into hmp
In reply to Isaku YamahataQuoted 10 lines · Isaku Yamahata
This patch series introduces hmp command to inject aer error. Now fw device path is used to specify pci function.
Changes v10 -> v11:
- use qdev id and use fw dev path as fallbackIsaku Yamahata (5):
qdev: exportqdev_find_recursive()for later use
pci: introduce a helper function to convert qdev id to PCIDevice pcie/aer: glue aer error injection into qemu monitor
Applied 1-3, thanks.
Quoted 12 lines
pci: introduce a parser for fw device path to pci device pcie/aer: use fw device path as fallback for aer injection command
hmp-commands.hx | 30 +++++++ hw/pci-stub.c | 13 +++ hw/pci.c | 164 +++++++++++++++++++++++++++++++++++++++ hw/pci.h | 3 + hw/pcie_aer.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.c | 2 +- hw/qdev.h | 2 + sysemu.h | 5 + 8 files changed, 445 insertions(+), 1 deletions(-)