Skip to content

Commit 55e901f

Browse files
jbeulichkonradwilk
authored andcommitted
xen/pci: support multi-segment systems
Now that the hypercall interface changes are in -unstable, make the kernel side code not ignore the segment (aka domain) number anymore (which results in pretty odd behavior on such systems). Rather, if only the old interfaces are available, don't call them for devices on non-zero segments at all. Signed-off-by: Jan Beulich <jbeulich@suse.com> [v1: Edited git description] Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 6810df8 commit 55e901f

3 files changed

Lines changed: 136 additions & 14 deletions

File tree

‎arch/x86/pci/xen.c‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static void xen_teardown_msi_irq(unsigned int irq)
185185
}
186186

187187
#ifdef CONFIG_XEN_DOM0
188+
static bool __read_mostly pci_seg_supported = true;
189+
188190
static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
189191
{
190192
int ret = 0;
@@ -202,10 +204,11 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
202204

203205
memset(&map_irq, 0, sizeof(map_irq));
204206
map_irq.domid = domid;
205-
map_irq.type = MAP_PIRQ_TYPE_MSI;
207+
map_irq.type = MAP_PIRQ_TYPE_MSI_SEG;
206208
map_irq.index = -1;
207209
map_irq.pirq = -1;
208-
map_irq.bus = dev->bus->number;
210+
map_irq.bus = dev->bus->number |
211+
(pci_domain_nr(dev->bus) << 16);
209212
map_irq.devfn = dev->devfn;
210213

211214
if (type == PCI_CAP_ID_MSIX) {
@@ -222,7 +225,20 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
222225
map_irq.entry_nr = msidesc->msi_attrib.entry_nr;
223226
}
224227

225-
ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
228+
ret = -EINVAL;
229+
if (pci_seg_supported)
230+
ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq,
231+
&map_irq);
232+
if (ret == -EINVAL && !pci_domain_nr(dev->bus)) {
233+
map_irq.type = MAP_PIRQ_TYPE_MSI;
234+
map_irq.index = -1;
235+
map_irq.pirq = -1;
236+
map_irq.bus = dev->bus->number;
237+
ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq,
238+
&map_irq);
239+
if (ret != -EINVAL)
240+
pci_seg_supported = false;
241+
}
226242
if (ret) {
227243
dev_warn(&dev->dev, "xen map irq failed %d for %d domain\n",
228244
ret, domid);

‎drivers/xen/pci.c‎

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <linux/pci.h>
21+
#include <linux/acpi.h>
2122
#include <xen/xen.h>
2223
#include <xen/interface/physdev.h>
2324
#include <xen/interface/xen.h>
@@ -26,26 +27,85 @@
2627
#include <asm/xen/hypercall.h>
2728
#include "../pci/pci.h"
2829

30+
static bool __read_mostly pci_seg_supported = true;
31+
2932
static int xen_add_device(struct device *dev)
3033
{
3134
int r;
3235
struct pci_dev *pci_dev = to_pci_dev(dev);
36+
#ifdef CONFIG_PCI_IOV
37+
struct pci_dev *physfn = pci_dev->physfn;
38+
#endif
39+
40+
if (pci_seg_supported) {
41+
struct physdev_pci_device_add add = {
42+
.seg = pci_domain_nr(pci_dev->bus),
43+
.bus = pci_dev->bus->number,
44+
.devfn = pci_dev->devfn
45+
};
46+
#ifdef CONFIG_ACPI
47+
acpi_handle handle;
48+
#endif
3349

3450
#ifdef CONFIG_PCI_IOV
35-
if (pci_dev->is_virtfn) {
51+
if (pci_dev->is_virtfn) {
52+
add.flags = XEN_PCI_DEV_VIRTFN;
53+
add.physfn.bus = physfn->bus->number;
54+
add.physfn.devfn = physfn->devfn;
55+
} else
56+
#endif
57+
if (pci_ari_enabled(pci_dev->bus) && PCI_SLOT(pci_dev->devfn))
58+
add.flags = XEN_PCI_DEV_EXTFN;
59+
60+
#ifdef CONFIG_ACPI
61+
handle = DEVICE_ACPI_HANDLE(&pci_dev->dev);
62+
if (!handle)
63+
handle = DEVICE_ACPI_HANDLE(pci_dev->bus->bridge);
64+
#ifdef CONFIG_PCI_IOV
65+
if (!handle && pci_dev->is_virtfn)
66+
handle = DEVICE_ACPI_HANDLE(physfn->bus->bridge);
67+
#endif
68+
if (handle) {
69+
acpi_status status;
70+
71+
do {
72+
unsigned long long pxm;
73+
74+
status = acpi_evaluate_integer(handle, "_PXM",
75+
NULL, &pxm);
76+
if (ACPI_SUCCESS(status)) {
77+
add.optarr[0] = pxm;
78+
add.flags |= XEN_PCI_DEV_PXM;
79+
break;
80+
}
81+
status = acpi_get_parent(handle, &handle);
82+
} while (ACPI_SUCCESS(status));
83+
}
84+
#endif /* CONFIG_ACPI */
85+
86+
r = HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_add, &add);
87+
if (r != -ENOSYS)
88+
return r;
89+
pci_seg_supported = false;
90+
}
91+
92+
if (pci_domain_nr(pci_dev->bus))
93+
r = -ENOSYS;
94+
#ifdef CONFIG_PCI_IOV
95+
else if (pci_dev->is_virtfn) {
3696
struct physdev_manage_pci_ext manage_pci_ext = {
3797
.bus = pci_dev->bus->number,
3898
.devfn = pci_dev->devfn,
3999
.is_virtfn = 1,
40-
.physfn.bus = pci_dev->physfn->bus->number,
41-
.physfn.devfn = pci_dev->physfn->devfn,
100+
.physfn.bus = physfn->bus->number,
101+
.physfn.devfn = physfn->devfn,
42102
};
43103

44104
r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext,
45105
&manage_pci_ext);
46-
} else
106+
}
47107
#endif
48-
if (pci_ari_enabled(pci_dev->bus) && PCI_SLOT(pci_dev->devfn)) {
108+
else if (pci_ari_enabled(pci_dev->bus) && PCI_SLOT(pci_dev->devfn)) {
49109
struct physdev_manage_pci_ext manage_pci_ext = {
50110
.bus = pci_dev->bus->number,
51111
.devfn = pci_dev->devfn,
@@ -71,13 +131,27 @@ static int xen_remove_device(struct device *dev)
71131
{
72132
int r;
73133
struct pci_dev *pci_dev = to_pci_dev(dev);
74-
struct physdev_manage_pci manage_pci;
75134

76-
manage_pci.bus = pci_dev->bus->number;
77-
manage_pci.devfn = pci_dev->devfn;
135+
if (pci_seg_supported) {
136+
struct physdev_pci_device device = {
137+
.seg = pci_domain_nr(pci_dev->bus),
138+
.bus = pci_dev->bus->number,
139+
.devfn = pci_dev->devfn
140+
};
78141

79-
r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove,
80-
&manage_pci);
142+
r = HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_remove,
143+
&device);
144+
} else if (pci_domain_nr(pci_dev->bus))
145+
r = -ENOSYS;
146+
else {
147+
struct physdev_manage_pci manage_pci = {
148+
.bus = pci_dev->bus->number,
149+
.devfn = pci_dev->devfn
150+
};
151+
152+
r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove,
153+
&manage_pci);
154+
}
81155

82156
return r;
83157
}

‎include/xen/interface/physdev.h‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct physdev_irq {
109109
#define MAP_PIRQ_TYPE_MSI 0x0
110110
#define MAP_PIRQ_TYPE_GSI 0x1
111111
#define MAP_PIRQ_TYPE_UNKNOWN 0x2
112+
#define MAP_PIRQ_TYPE_MSI_SEG 0x3
112113

113114
#define PHYSDEVOP_map_pirq 13
114115
struct physdev_map_pirq {
@@ -119,7 +120,7 @@ struct physdev_map_pirq {
119120
int index;
120121
/* IN or OUT */
121122
int pirq;
122-
/* IN */
123+
/* IN - high 16 bits hold segment for MAP_PIRQ_TYPE_MSI_SEG */
123124
int bus;
124125
/* IN */
125126
int devfn;
@@ -198,6 +199,37 @@ struct physdev_get_free_pirq {
198199
uint32_t pirq;
199200
};
200201

202+
#define XEN_PCI_DEV_EXTFN 0x1
203+
#define XEN_PCI_DEV_VIRTFN 0x2
204+
#define XEN_PCI_DEV_PXM 0x4
205+
206+
#define PHYSDEVOP_pci_device_add 25
207+
struct physdev_pci_device_add {
208+
/* IN */
209+
uint16_t seg;
210+
uint8_t bus;
211+
uint8_t devfn;
212+
uint32_t flags;
213+
struct {
214+
uint8_t bus;
215+
uint8_t devfn;
216+
} physfn;
217+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
218+
uint32_t optarr[];
219+
#elif defined(__GNUC__)
220+
uint32_t optarr[0];
221+
#endif
222+
};
223+
224+
#define PHYSDEVOP_pci_device_remove 26
225+
#define PHYSDEVOP_restore_msi_ext 27
226+
struct physdev_pci_device {
227+
/* IN */
228+
uint16_t seg;
229+
uint8_t bus;
230+
uint8_t devfn;
231+
};
232+
201233
/*
202234
* Notify that some PIRQ-bound event channels have been unmasked.
203235
* ** This command is obsolete since interface version 0x00030202 and is **

0 commit comments

Comments
 (0)