Skip to content

Commit da72ff5

Browse files
committed
partially revert "xen: Remove event channel notification through Xen PCI platform device"
Commit 72a9b18 ("xen: Remove event channel notification through Xen PCI platform device") broke Linux when booting as Dom0 on Xen in a nested Xen environment (Xen installed inside a Xen VM). In this scenario, Linux is a PV guest, but at the same time it uses the platform-pci driver to receive notifications from L0 Xen. vector callbacks are not available because L1 Xen doesn't allow them. Partially revert the offending commit, by restoring IRQ based notifications for PV guests only. I restored only the code which is strictly needed and replaced the xen_have_vector_callback checks within it with xen_pv_domain() checks. Signed-off-by: Stefano Stabellini <sstabellini@kernel.org> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
1 parent 0b47a6b commit da72ff5

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

‎drivers/xen/platform-pci.c‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
static unsigned long platform_mmio;
4343
static unsigned long platform_mmio_alloc;
4444
static unsigned long platform_mmiolen;
45+
static uint64_t callback_via;
4546

4647
static unsigned long alloc_xen_mmio(unsigned long len)
4748
{
@@ -54,6 +55,51 @@ static unsigned long alloc_xen_mmio(unsigned long len)
5455
return addr;
5556
}
5657

58+
static uint64_t get_callback_via(struct pci_dev *pdev)
59+
{
60+
u8 pin;
61+
int irq;
62+
63+
irq = pdev->irq;
64+
if (irq < 16)
65+
return irq; /* ISA IRQ */
66+
67+
pin = pdev->pin;
68+
69+
/* We don't know the GSI. Specify the PCI INTx line instead. */
70+
return ((uint64_t)0x01 << HVM_CALLBACK_VIA_TYPE_SHIFT) | /* PCI INTx identifier */
71+
((uint64_t)pci_domain_nr(pdev->bus) << 32) |
72+
((uint64_t)pdev->bus->number << 16) |
73+
((uint64_t)(pdev->devfn & 0xff) << 8) |
74+
((uint64_t)(pin - 1) & 3);
75+
}
76+
77+
static irqreturn_t do_hvm_evtchn_intr(int irq, void *dev_id)
78+
{
79+
xen_hvm_evtchn_do_upcall();
80+
return IRQ_HANDLED;
81+
}
82+
83+
static int xen_allocate_irq(struct pci_dev *pdev)
84+
{
85+
return request_irq(pdev->irq, do_hvm_evtchn_intr,
86+
IRQF_NOBALANCING | IRQF_TRIGGER_RISING,
87+
"xen-platform-pci", pdev);
88+
}
89+
90+
static int platform_pci_resume(struct pci_dev *pdev)
91+
{
92+
int err;
93+
if (!xen_pv_domain())
94+
return 0;
95+
err = xen_set_callback_via(callback_via);
96+
if (err) {
97+
dev_err(&pdev->dev, "platform_pci_resume failure!\n");
98+
return err;
99+
}
100+
return 0;
101+
}
102+
57103
static int platform_pci_probe(struct pci_dev *pdev,
58104
const struct pci_device_id *ent)
59105
{
@@ -92,6 +138,28 @@ static int platform_pci_probe(struct pci_dev *pdev,
92138
platform_mmio = mmio_addr;
93139
platform_mmiolen = mmio_len;
94140

141+
/*
142+
* Xen HVM guests always use the vector callback mechanism.
143+
* L1 Dom0 in a nested Xen environment is a PV guest inside in an
144+
* HVM environment. It needs the platform-pci driver to get
145+
* notifications from L0 Xen, but it cannot use the vector callback
146+
* as it is not exported by L1 Xen.
147+
*/
148+
if (xen_pv_domain()) {
149+
ret = xen_allocate_irq(pdev);
150+
if (ret) {
151+
dev_warn(&pdev->dev, "request_irq failed err=%d\n", ret);
152+
goto out;
153+
}
154+
callback_via = get_callback_via(pdev);
155+
ret = xen_set_callback_via(callback_via);
156+
if (ret) {
157+
dev_warn(&pdev->dev, "Unable to set the evtchn callback "
158+
"err=%d\n", ret);
159+
goto out;
160+
}
161+
}
162+
95163
max_nr_gframes = gnttab_max_grant_frames();
96164
grant_frames = alloc_xen_mmio(PAGE_SIZE * max_nr_gframes);
97165
ret = gnttab_setup_auto_xlat_frames(grant_frames);
@@ -123,6 +191,9 @@ static struct pci_driver platform_driver = {
123191
.name = DRV_NAME,
124192
.probe = platform_pci_probe,
125193
.id_table = platform_pci_tbl,
194+
#ifdef CONFIG_PM
195+
.resume_early = platform_pci_resume,
196+
#endif
126197
};
127198

128199
builtin_pci_driver(platform_driver);

0 commit comments

Comments
 (0)