Skip to contentSkip to conversation

pci-assign: Do not expose MSI/MSI-X if the kernel does not support it

PATCH Applied Jan Kiszka 3 participants 5 messages Aug 2, 2011 – Aug 3, 2011 KVM

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 pci-assign: Do not expose MSI/MSI-X if the kernel does not support it

Add checks for KVM_CAP_ASSIGN_DEV_IRQ (MSI) and KVM_CAP_DEVICE_MSIX, do not set up MSI/MSI-X if the required kernel features are missing.

---
 hw/device-assignment.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/device-assignment.c +4 -2
index 4cc7b1a..7e965cb 100644
@@ -1201,7 +1201,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
 
     /* Expose MSI capability
      * MSI capability is the 1st capability in capability config */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {
         dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
         /* Only 32-bit/no-mask currently supported */
         if ((ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSI, pos, 10)) < 0) {
@@ -1222,7 +1223,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
         pci_set_word(pci_dev->wmask + pos + PCI_MSI_DATA_32, 0xffff);
     }
     /* Expose MSI-X capability */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_DEVICE_MSIX)) {
         int bar_nr;
         uint32_t msix_table_entry;
 
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 13 lines · Jan Kiszka

Add checks for KVM_CAP_ASSIGN_DEV_IRQ (MSI) and KVM_CAP_DEVICE_MSIX, do not set up MSI/MSI-X if the required kernel features are missing.

---
 hw/device-assignment.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/device-assignment.c +0 -0
index 4cc7b1a..7e965cb 100644

hw/device-assignment.c static int assigned_device_pci_cap_init(PCIDevice *pci_dev) · line 1205

Quoted 6 lines
hw/device-assignment.c +2 -1
@@ -1201,7 +1201,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
 
     /* Expose MSI capability
      * MSI capability is the 1st capability in capability config */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {

Is it even useful to have a device assigned w/o KVM_CAP_ASSIGN_DEV_IRQ? Thanks,

Alex

Quoted 13 lines
hw/device-assignment.c +2 -1
         dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
         /* Only 32-bit/no-mask currently supported */
         if ((ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSI, pos, 10)) < 0) {
@@ -1222,7 +1223,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
         pci_set_word(pci_dev->wmask + pos + PCI_MSI_DATA_32, 0xffff);
     }
     /* Expose MSI-X capability */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_DEVICE_MSIX)) {
         int bar_nr;
         uint32_t msix_table_entry;
 
author
#2 lore raw
Quoted 15 lines · Alex Williamson
Quoted 14 lines · Jan Kiszka

Add checks for KVM_CAP_ASSIGN_DEV_IRQ (MSI) and KVM_CAP_DEVICE_MSIX, do not set up MSI/MSI-X if the required kernel features are missing.

---
 hw/device-assignment.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/device-assignment.c +0 -0
index 4cc7b1a..7e965cb 100644
@@ -1201,7 +1201,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
 
Quoted 7 lines

hw/device-assignment.c static int assigned_device_pci_cap_init(PCIDevice *pci_dev) · line 1205

Quoted 5 lines
hw/device-assignment.c +2 -1
     /* Expose MSI capability
      * MSI capability is the 1st capability in capability config */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {

Is it even useful to have a device assigned w/o KVM_CAP_ASSIGN_DEV_IRQ?

If that feature is lacking, we fall back to the old KVM_ASSIGN_IRQ interface. I guess that used to work, but I bet no one tested it recently. However, the code is there, also in the kvm core.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 24 lines · Jan Kiszka
Quoted 15 lines · Alex Williamson
Quoted 14 lines · Jan Kiszka

Add checks for KVM_CAP_ASSIGN_DEV_IRQ (MSI) and KVM_CAP_DEVICE_MSIX, do not set up MSI/MSI-X if the required kernel features are missing.

---
 hw/device-assignment.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/device-assignment.c +0 -0
index 4cc7b1a..7e965cb 100644
@@ -1201,7 +1201,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
 
Quoted 7 lines

hw/device-assignment.c static int assigned_device_pci_cap_init(PCIDevice *pci_dev) · line 1205

Quoted 5 lines
hw/device-assignment.c +2 -1
     /* Expose MSI capability
      * MSI capability is the 1st capability in capability config */
-    if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0))) {
+    pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
+    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {

Is it even useful to have a device assigned w/o KVM_CAP_ASSIGN_DEV_IRQ?

Quoted 3 lines

If that feature is lacking, we fall back to the old KVM_ASSIGN_IRQ interface. I guess that used to work, but I bet no one tested it recently. However, the code is there, also in the kvm core.

Ah right. Not sure how much I trust that, but seems obviously correct to not expose capabilities we can't support.

#4 lore raw
In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

Add checks for KVM_CAP_ASSIGN_DEV_IRQ (MSI) and KVM_CAP_DEVICE_MSIX, do not set up MSI/MSI-X if the required kernel features are missing.

---
 hw/device-assignment.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Applied, thanks.