pcie aer fixes
PATCH v2 2/6 Makefile: make msix/msi depend on CONFIG_PCI
In reply to Isaku YamahataFrom: Michael S. Tsirkin <[email protected]>
Possible now that pci is not depending on these.
--- Makefile.objs | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
Makefile.objs +2 -1
@@ -168,7 +168,8 @@ hw-obj-$(CONFIG_VIRTIO) += virtio.o virtio-console.o hw-obj-y += fw_cfg.o # FIXME: Core PCI code and its direct dependencies are required by the # QMP query-pci command. -hw-obj-y += pci.o pci_bridge.o msix.o msi.o +hw-obj-y += pci.o pci_bridge.o +hw-obj-$(CONFIG_PCI) += msix.o msi.o hw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o hw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o hw-obj-y += watchdog.o
Signature · 1 line
1.7.1.1
PATCH v2 4/6 pci/aer: fix interrupt on config write
In reply to Isaku YamahataFrom: Michael S. Tsirkin <[email protected]>
config write handling for aer seems broken:
For example, it won't clear a level interrupt when command register is set to 0.
Make it match the spec: level should equal the logical or of enabled bits, msi only be sent when the logical or changes.
---
- reorder
- abort() instead of assert(0)
--- hw/pcie_aer.c | 46 +++++++++++++++++----------------------------- 1 files changed, 17 insertions(+), 29 deletions(-)
hw/pcie_aer.c +17 -29
@@ -762,43 +762,31 @@ void pcie_aer_root_reset(PCIDevice *dev)*/ } -static bool pcie_aer_root_does_trigger (uint32_t cmd,uint32_t status) -{ -return - ((cmd &PCI_ERR_ROOT_CMD_COR_EN ) && (status &PCI_ERR_ROOT_COR_RCV )) || - ((cmd &PCI_ERR_ROOT_CMD_NONFATAL_EN ) && - (status &PCI_ERR_ROOT_NONFATAL_RCV )) || - ((cmd &PCI_ERR_ROOT_CMD_FATAL_EN ) && - (status &PCI_ERR_ROOT_FATAL_RCV )); -} -void pcie_aer_root_write_config (PCIDevice *dev,uint32_t addr,uint32_t val,int len,uint32_t root_cmd_prev) {uint8_t *aer_cap = dev->config + dev->exp.aer_cap; - -/* root command register */ +uint32_t root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); +uint32_t enabled_cmd =pcie_aer_status_to_cmd (root_status);uint32_t root_cmd =pci_get_long (aer_cap +PCI_ERR_ROOT_COMMAND ); -if (root_cmd &PCI_ERR_ROOT_CMD_EN_MASK ) { -/* 6.2.4.1.2 Interrupt Generation */ +/* 6.2.4.1.2 Interrupt Generation */ +if (!msix_enabled (dev) && !msi_enabled (dev)) { +qemu_set_irq (dev->irq[dev->exp.aer_intx], !!(root_cmd & enabled_cmd)); +return ; + } -/* 0 -> 1 */ -uint32_t root_cmd_set = ~root_cmd_prev & root_cmd; -uint32_t root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); -bool trigger =pcie_aer_root_does_trigger (root_cmd_set, root_status); +if ((root_cmd_prev & enabled_cmd) || !(root_cmd & enabled_cmd)) { +/* Send MSI on transition from false to true. */ +return ; + } -if (msix_enabled (dev)) { -if (trigger) { -msix_notify (dev,pcie_aer_root_get_vector (dev)); - } - }else if (msi_enabled (dev)) { -if (trigger) { -msi_notify (dev,pcie_aer_root_get_vector (dev)); - } - }else { -qemu_set_irq (dev->irq[dev->exp.aer_intx], trigger); - } +if (msix_enabled (dev)) { +msix_notify (dev,pcie_aer_root_get_vector (dev)); + }else if (msi_enabled (dev)) { +msi_notify (dev,pcie_aer_root_get_vector (dev)); + }else { +abort (); } }
Signature · 1 line
1.7.1.1
v2 cover pcie aer fixes
I respined the patch series by mst for bisectability.
Changes v1 -> v2:
- reorder patches for bisectability
- s/assert/trigger/ to avoid name conflict
- abort() instead of assert(0)
Original patch description:
Here are a bunch of fixes and cleanups to aer interrupt injection. Compile tested only, issues were found by reading the code and spec.
Michael S. Tsirkin (6):
pci: untangle pci/msi dependency
Makefile: make msix/msi depend on CONFIG_PCI
pci/aer: fix error injection
pci/aer: fix interrupt on config write
pci/aer: remove dead code
pci/aer: factor out common code
Makefile.objs | 3 +- hw/pci.c | 19 ---------- hw/pci.h | 3 -- hw/pcie.c | 8 +++-- hw/pcie_aer.c | 111 ++++++++++++++++++++++++++------------------------------ 5 files changed, 59 insertions(+), 85 deletions(-)
PATCH v2 5/6 pci/aer: remove dead code
From: Michael S. Tsirkin <[email protected]>
Remove some unused variables and return values.
---
changes v1 -> v2:
- reorder
--- hw/pcie_aer.c | 25 ++----------------------- 1 files changed, 2 insertions(+), 23 deletions(-)
hw/pcie_aer.c +2 -23
@@ -274,29 +274,21 @@ static uint32_t pcie_aer_status_to_cmd(uint32_t status) }/* -* return value: -* true: error message is sent up -* false: error message is masked -* * 6.2.6 Error Message Control * Figure 6-3 * root port part */ -static bool pcie_aer_msg_root_port (PCIDevice *dev,const PCIEAERMsg *msg) +static void pcie_aer_msg_root_port (PCIDevice *dev,const PCIEAERMsg *msg) { -bool msg_sent;uint16_t cmd;uint8_t *aer_cap;uint32_t root_cmd;uint32_t root_status, prev_status; -bool msi_trigger; - msg_sent = false; cmd =pci_get_word (dev->config +PCI_COMMAND ); aer_cap = dev->config + dev->exp.aer_cap; root_cmd =pci_get_long (aer_cap +PCI_ERR_ROOT_COMMAND ); prev_status = root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); - msi_trigger = false;if (cmd &PCI_COMMAND_SERR ) {/* System Error.
@@ -315,25 +307,14 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)if (root_status &PCI_ERR_ROOT_COR_RCV ) { root_status |=PCI_ERR_ROOT_MULTI_COR_RCV ; }else { -if (root_cmd &PCI_ERR_ROOT_CMD_COR_EN ) { - msi_trigger = true; - }pci_set_word (aer_cap +PCI_ERR_ROOT_COR_SRC , msg->source_id); } root_status |=PCI_ERR_ROOT_COR_RCV ;break ;case PCI_ERR_ROOT_CMD_NONFATAL_EN : -if (!(root_status &PCI_ERR_ROOT_NONFATAL_RCV ) && - root_cmd &PCI_ERR_ROOT_CMD_NONFATAL_EN ) { - msi_trigger = true; - } root_status |=PCI_ERR_ROOT_NONFATAL_RCV ;break ;case PCI_ERR_ROOT_CMD_FATAL_EN : -if (!(root_status &PCI_ERR_ROOT_FATAL_RCV ) && - root_cmd &PCI_ERR_ROOT_CMD_FATAL_EN ) { - msi_trigger = true; - }if (!(root_status &PCI_ERR_ROOT_UNCOR_RCV )) { root_status |=PCI_ERR_ROOT_FIRST_FATAL ; }
@@ -360,10 +341,9 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)if (!(root_cmd & msg->severity) || (pcie_aer_status_to_cmd (prev_status) & root_cmd)) {/* Condition is not being set or was already true so nothing to do. */ -return msg_sent; +return ; } - msg_sent = true;if (msix_enabled (dev)) {msix_notify (dev,pcie_aer_root_get_vector (dev)); }else if (msi_enabled (dev)) {
@@ -371,7 +351,6 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg) }else {qemu_set_irq (dev->irq[dev->exp.aer_intx],1 ); } -return msg_sent; }/*
Signature · 1 line
1.7.1.1
PATCH v2 6/6 pci/aer: factor out common code
In reply to Isaku YamahataFrom: Michael S. Tsirkin <[email protected]>
Same logic is used to assert interrupts
and send msix messages, so add a static functin for this.
--- hw/pcie_aer.c | 27 +++++++++++++-------------- 1 files changed, 13 insertions(+), 14 deletions(-)
hw/pcie_aer.c +13 -14
@@ -273,6 +273,17 @@ static uint32_t pcie_aer_status_to_cmd(uint32_t status)return cmd; } +static void pcie_aer_root_notify (PCIDevice *dev) +{ +if (msix_enabled (dev)) { +msix_notify (dev,pcie_aer_root_get_vector (dev)); + }else if (msi_enabled (dev)) { +msi_notify (dev,pcie_aer_root_get_vector (dev)); + }else { +qemu_set_irq (dev->irq[dev->exp.aer_intx],1 ); + } +} +/* * 6.2.6 Error Message Control * Figure 6-3
@@ -344,13 +355,7 @@ static void pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)return ; } -if (msix_enabled (dev)) { -msix_notify (dev,pcie_aer_root_get_vector (dev)); - }else if (msi_enabled (dev)) { -msi_notify (dev,pcie_aer_root_get_vector (dev)); - }else { -qemu_set_irq (dev->irq[dev->exp.aer_intx],1 ); - } +pcie_aer_root_notify (dev); }/*
@@ -760,13 +765,7 @@ void pcie_aer_root_write_config(PCIDevice *dev,return ; } -if (msix_enabled (dev)) { -msix_notify (dev,pcie_aer_root_get_vector (dev)); - }else if (msi_enabled (dev)) { -msi_notify (dev,pcie_aer_root_get_vector (dev)); - }else { -abort (); - } +pcie_aer_root_notify (dev); }static const VMStateDescription vmstate_pcie_aer_err = {
Signature · 1 line
1.7.1.1
PATCH v2 3/6 pci/aer: fix error injection
In reply to Isaku YamahataFrom: Michael S. Tsirkin <[email protected]>
Fix the injection logic upon aer message to follow 6.2.4.1.2 more
closely: specifically only send an msi interrupt when the logical or of the enabled bits changed, not when a bit which was previously clear becomes set.
---
Changes v1 -> v2:
- reorder
--- hw/pcie_aer.c | 51 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 35 insertions(+), 16 deletions(-)
hw/pcie_aer.c +35 -16
@@ -257,6 +257,22 @@ static unsigned int pcie_aer_root_get_vector(PCIDevice *dev)return (root_status &PCI_ERR_ROOT_IRQ ) >>PCI_ERR_ROOT_IRQ_SHIFT ; } +/* Given a status register, get corresponding bits in the command register */ +static uint32_t pcie_aer_status_to_cmd (uint32_t status) +{ +uint32_t cmd =0 ; +if (status &PCI_ERR_ROOT_COR_RCV ) { + cmd |=PCI_ERR_ROOT_CMD_COR_EN ; + } +if (status &PCI_ERR_ROOT_NONFATAL_RCV ) { + cmd |=PCI_ERR_ROOT_CMD_NONFATAL_EN ; + } +if (status &PCI_ERR_ROOT_FATAL_RCV ) { + cmd |=PCI_ERR_ROOT_CMD_FATAL_EN ; + } +return cmd; +} +/* * return value: * true: error message is sent up
@@ -272,14 +288,14 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)uint16_t cmd;uint8_t *aer_cap;uint32_t root_cmd; -uint32_t root_status; +uint32_t root_status, prev_status;bool msi_trigger; msg_sent = false; cmd =pci_get_word (dev->config +PCI_COMMAND ); aer_cap = dev->config + dev->exp.aer_cap; root_cmd =pci_get_long (aer_cap +PCI_ERR_ROOT_COMMAND ); - root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); + prev_status = root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); msi_trigger = false;if (cmd &PCI_COMMAND_SERR ) {
@@ -337,20 +353,23 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg) }pci_set_long (aer_cap +PCI_ERR_ROOT_STATUS , root_status); -if (root_cmd & msg->severity) { -/* 6.2.4.1.2 Interrupt Generation */ -if (msix_enabled (dev)) { -if (msi_trigger) { -msix_notify (dev,pcie_aer_root_get_vector (dev)); - } - }else if (msi_enabled (dev)) { -if (msi_trigger) { -msi_notify (dev,pcie_aer_root_get_vector (dev)); - } - }else { -qemu_set_irq (dev->irq[dev->exp.aer_intx],1 ); - } - msg_sent = true; +/* 6.2.4.1.2 Interrupt Generation */ +/* All the above did was set some bits in the status register. +* Specifically these that match message severity. +* The below code relies on this fact. */ +if (!(root_cmd & msg->severity) || + (pcie_aer_status_to_cmd (prev_status) & root_cmd)) { +/* Condition is not being set or was already true so nothing to do. */ +return msg_sent; + } + + msg_sent = true; +if (msix_enabled (dev)) { +msix_notify (dev,pcie_aer_root_get_vector (dev)); + }else if (msi_enabled (dev)) { +msi_notify (dev,pcie_aer_root_get_vector (dev)); + }else { +qemu_set_irq (dev->irq[dev->exp.aer_intx],1 ); }return msg_sent; }
Signature · 1 line
1.7.1.1
PATCH v2 1/6 pci: untangle pci/msi dependency
In reply to Isaku YamahataFrom: Michael S. Tsirkin <[email protected]>
msi depends on pci but pci should not depend on msi. The only dependency we have is a recent addition of pci_msi_ functions, IMO they add little enough to open-code in the small number of users.
Follow-up patches add more cleanups.
---
Changes v1 -> v2:
- s/assert/trigger/g
variable name, assert, would conflict with assert.h
- msi_trigger
--- hw/pci.c | 19 ------------------- hw/pci.h | 3 --- hw/pcie.c | 8 +++++--- hw/pcie_aer.c | 24 ++++++++++++++++-------- 4 files changed, 21 insertions(+), 33 deletions(-)
hw/pci.c +0 -19
@@ -25,8 +25,6 @@#include "pci.h" #include "pci_bridge.h" #include "pci_internals.h" -#include "msix.h" -#include "msi.h" #include "monitor.h" #include "net.h" #include "sysemu.h"
@@ -1099,23 +1097,6 @@ static void pci_set_irq(void *opaque, int irq_num, int level)pci_change_irq_level (pci_dev, irq_num, change); } -bool pci_msi_enabled (PCIDevice *dev) -{ -return msix_enabled (dev) ||msi_enabled (dev); -} - -void pci_msi_notify (PCIDevice *dev,unsigned int vector) -{ -if (msix_enabled (dev)) { -msix_notify (dev, vector); - }else if (msi_enabled (dev)) { -msi_notify (dev, vector); - }else { -/* MSI/MSI-X must be enabled */ -abort (); - } -} -/***********************************************************/ /* monitor info on PCI */
hw/pci.h +0 -3
@@ -261,9 +261,6 @@ void do_pci_info_print(Monitor *mon, const QObject *data);void do_pci_info (Monitor *mon,QObject **ret_data);void pci_bridge_update_mappings (PCIBus *b); -bool pci_msi_enabled (PCIDevice *dev); -void pci_msi_notify (PCIDevice *dev,unsigned int vector); -static inline void pci_set_byte (uint8_t *config,uint8_t val) {
hw/pcie.c +5 -3
@@ -167,10 +167,12 @@ static void hotplug_event_notify(PCIDevice *dev)* The Port may optionally send an MSI when there are hot-plug events that * occur while interrupt generation is disabled, and interrupt generation is * subsequently enabled. */ -if (!pci_msi_enabled (dev)) { +if (msix_enabled (dev)) { +msix_notify (dev,pcie_cap_flags_get_vector (dev)); + }else if (msi_enabled (dev)) { +msi_notify (dev,pcie_cap_flags_get_vector (dev)); + }else {qemu_set_irq (dev->irq[dev->exp.hpev_intx], dev->exp.hpev_notified); - }else if (dev->exp.hpev_notified) { -pci_msi_notify (dev,pcie_cap_flags_get_vector (dev)); } }
hw/pcie_aer.c +16 -8
@@ -339,9 +339,13 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)if (root_cmd & msg->severity) {/* 6.2.4.1.2 Interrupt Generation */ -if (pci_msi_enabled (dev)) { +if (msix_enabled (dev)) {if (msi_trigger) { -pci_msi_notify (dev,pcie_aer_root_get_vector (dev)); +msix_notify (dev,pcie_aer_root_get_vector (dev)); + } + }else if (msi_enabled (dev)) { +if (msi_trigger) { +msi_notify (dev,pcie_aer_root_get_vector (dev)); } }else {qemu_set_irq (dev->irq[dev->exp.aer_intx],1 );
@@ -761,16 +765,20 @@ void pcie_aer_root_write_config(PCIDevice *dev,/* 6.2.4.1.2 Interrupt Generation */ /* 0 -> 1 */ -uint32_t root_cmd_set = (root_cmd_prev ^ root_cmd) & root_cmd; +uint32_t root_cmd_set = ~root_cmd_prev & root_cmd;uint32_t root_status =pci_get_long (aer_cap +PCI_ERR_ROOT_STATUS ); +bool trigger =pcie_aer_root_does_trigger (root_cmd_set, root_status); -if (pci_msi_enabled (dev)) { -if (pcie_aer_root_does_trigger (root_cmd_set, root_status)) { -pci_msi_notify (dev,pcie_aer_root_get_vector (dev)); +if (msix_enabled (dev)) { +if (trigger) { +msix_notify (dev,pcie_aer_root_get_vector (dev)); + } + }else if (msi_enabled (dev)) { +if (trigger) { +msi_notify (dev,pcie_aer_root_get_vector (dev)); } }else { -int int_level =pcie_aer_root_does_trigger (root_cmd, root_status); -qemu_set_irq (dev->irq[dev->exp.aer_intx], int_level); +qemu_set_irq (dev->irq[dev->exp.aer_intx], trigger); } } }
Signature · 1 line
1.7.1.1
Michael S. Tsirkin
AppliedQuoted 1 line · Isaku Yamahata
I respined the patch series by mst for bisectability.
Applied, thanks.
Quoted 24 lines
Changes v1 -> v2:
- reorder patches for bisectability
- s/assert/trigger/ to avoid name conflict
-abort()instead of assert(0)Original patch description:
Here are a bunch of fixes and cleanups to aer interrupt injection. Compile tested only, issues were found by reading the code and spec.Michael S. Tsirkin (6):
pci: untangle pci/msi dependency
Makefile: make msix/msi depend onCONFIG_PCI
pci/aer: fix error injection
pci/aer: fix interrupt on config write
pci/aer: remove dead code
pci/aer: factor out common codeMakefile.objs | 3 +- hw/pci.c | 19 ---------- hw/pci.h | 3 -- hw/pcie.c | 8 +++-- hw/pcie_aer.c | 111 ++++++++++++++++++++++++++------------------------------ 5 files changed, 59 insertions(+), 85 deletions(-)