From 8c88375cd0dd6f361beafc85b534103bee9bf847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 18 Nov 2022 03:37:14 +0100 Subject: [PATCH] Add fixup patch for MSI-X handling QubesOS/qubes-issues#4799 QubesOS/qubes-issues#7057 QubesOS/qubes-issues#7052 --- ...ider-INTx-disabled-when-MSI-MSI-X-is.patch | 82 +++++++++++++++++++ kernel.spec.in | 1 + 2 files changed, 83 insertions(+) create mode 100644 0001-xen-pciback-Consider-INTx-disabled-when-MSI-MSI-X-is.patch diff --git a/0001-xen-pciback-Consider-INTx-disabled-when-MSI-MSI-X-is.patch b/0001-xen-pciback-Consider-INTx-disabled-when-MSI-MSI-X-is.patch new file mode 100644 index 00000000..8d8eb07d --- /dev/null +++ b/0001-xen-pciback-Consider-INTx-disabled-when-MSI-MSI-X-is.patch @@ -0,0 +1,82 @@ +From 7336f034ba268aa2d3bf944e18b6a63e704799c1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= + +Date: Thu, 17 Nov 2022 12:35:41 +0100 +Subject: [PATCH] xen-pciback: Consider INTx disabled when MSI/MSI-X is enabled +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Linux enables MSI-X before disabling INTx, but keeps MSI-X masked until +the table is filled. Then it disables INTx just before clearing MASKALL +bit. Currently this approach is rejected by xen-pciback. +According to the PCIe spec, device cannot use INTx when MSI/MSI-X is +enabled. Change the logic to consider INTx disabled if MSI/MSI-X is +enabled. This applies to two places: checking currently enabled +interrupts type, and transition to MSI/MSI-X - where INTx would be +implicitly disabled. + +Fixes: 5e29500eba2a ("xen-pciback: Allow setting PCI_MSIX_FLAGS_MASKALL too") +Signed-off-by: Marek Marczykowski-Górecki +--- + drivers/xen/xen-pciback/conf_space.c | 19 +++++++++++++------ + .../xen/xen-pciback/conf_space_capability.c | 3 ++- + 2 files changed, 15 insertions(+), 7 deletions(-) + +diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c +index 059de92aea7d..d47eee6c5143 100644 +--- a/drivers/xen/xen-pciback/conf_space.c ++++ b/drivers/xen/xen-pciback/conf_space.c +@@ -288,12 +288,6 @@ int xen_pcibk_get_interrupt_type(struct pci_dev *dev) + u16 val; + int ret = 0; + +- err = pci_read_config_word(dev, PCI_COMMAND, &val); +- if (err) +- return err; +- if (!(val & PCI_COMMAND_INTX_DISABLE)) +- ret |= INTERRUPT_TYPE_INTX; +- + /* + * Do not trust dev->msi(x)_enabled here, as enabling could be done + * bypassing the pci_*msi* functions, by the qemu. +@@ -316,6 +310,19 @@ int xen_pcibk_get_interrupt_type(struct pci_dev *dev) + if (val & PCI_MSIX_FLAGS_ENABLE) + ret |= INTERRUPT_TYPE_MSIX; + } ++ ++ /* ++ * PCIe spec says device cannot use INTx if MSI/MSI-X is enabled, ++ * so check for INTx only when both are disabled. ++ */ ++ if (!ret) { ++ err = pci_read_config_word(dev, PCI_COMMAND, &val); ++ if (err) ++ return err; ++ if (!(val & PCI_COMMAND_INTX_DISABLE)) ++ ret |= INTERRUPT_TYPE_INTX; ++ } ++ + return ret ?: INTERRUPT_TYPE_NONE; + } + +diff --git a/drivers/xen/xen-pciback/conf_space_capability.c b/drivers/xen/xen-pciback/conf_space_capability.c +index 097316a74126..eb4c1af44f5c 100644 +--- a/drivers/xen/xen-pciback/conf_space_capability.c ++++ b/drivers/xen/xen-pciback/conf_space_capability.c +@@ -236,10 +236,11 @@ static int msi_msix_flags_write(struct pci_dev *dev, int offset, u16 new_value, + return PCIBIOS_SET_FAILED; + + if (new_value & field_config->enable_bit) { +- /* don't allow enabling together with other interrupt types */ ++ /* don't allow enabling together with other interrupt type */ + int int_type = xen_pcibk_get_interrupt_type(dev); + + if (int_type == INTERRUPT_TYPE_NONE || ++ int_type == INTERRUPT_TYPE_INTX || + int_type == field_config->int_type) + goto write; + return PCIBIOS_SET_FAILED; +-- +2.37.3 + diff --git a/kernel.spec.in b/kernel.spec.in index 4fc13538..342936e2 100644 --- a/kernel.spec.in +++ b/kernel.spec.in @@ -144,6 +144,7 @@ Patch25: 0001-Re-enable-interrupts-before-loading-PNVM.patch Patch26: 0001-sound-Disable-SG-buffer.patch Patch27: 0001-amdgpu-timeout.patch Patch28: 0001-iwlwifi-avoid-writing-to-MSI-X-page-when-MSI-X-is-no.patch +Patch29: 0001-xen-pciback-Consider-INTx-disabled-when-MSI-MSI-X-is.patch # S0ix support: Patch61: xen-events-Add-wakeup-support-to-xen-pirq.patch