VT-d: set_msi_source_id() (XSA-467 follow-up)
cover VT-d: set_msi_source_id() (XSA-467 follow-up)
1: move obtaining of MSI/HPET source ID
2: have set_msi_source_id() return a success indicator
Jan
PATCH 1/2 VT-d: move obtaining of MSI/HPET source ID
This was the original attempt to address XSA-467, until it was found that IRQs can be off already from higher up the call stack. Nevertheless moving code out of locked regions is generally desirable anyway; some of the callers, after all, don't disable interrupts or acquire other locks.
Hence, despite this not addressing the original report:
Data collection solely depends on the passed in PCI device. Furthermore, since the function only writes to a local variable, we can pull the invocation of set_msi_source_id() (and also set_hpet_source_id()) ahead of the acquiring of the (IRQ-safe) lock.
xen/drivers/passthrough/vtd/intremap.c +5 -5
@@ -508,6 +508,11 @@ static int msi_msg_to_remap_entry(const struct pi_desc *pi_desc = msi_desc->pi_desc;bool alloc = false; +if ( pdev ) +set_msi_source_id (pdev, &new_ire); +else +set_hpet_source_id (msi_desc->hpet_id, &new_ire); +if ( msi_desc->msi_attrib.type ==PCI_CAP_ID_MSI ) nr = msi_desc->msi.nvec;
@@ -575,11 +580,6 @@ static int msi_msg_to_remap_entry( new_ire.post.p =1 ; } -if ( pdev ) -set_msi_source_id (pdev, &new_ire); -else -set_hpet_source_id (msi_desc->hpet_id, &new_ire); -/* now construct new MSI/MSI-X rte entry */ remap_rte = (struct msi_msg_remap_entry *)msg; remap_rte->address_lo.dontcare =0 ;
Re: [PATCH 1/2] VT-d: move obtaining of MSI/HPET source ID
Quoted 7 lines · Jan Beulich
This was the original attempt to address XSA-467, until it was found that IRQs can be off already from higher up the call stack. Nevertheless moving code out of locked regions is generally desirable anyway; some of the callers, after all, don't disable interrupts or acquire other locks.
Hence, despite this not addressing the original report:
Quoted 7 lines
Data collection solely depends on the passed in PCI device. Furthermore, since the function only writes to a local variable, we can pull the invocation of
set_msi_source_id()(and alsoset_hpet_source_id()) ahead of the acquiring of the (IRQ-safe) lock.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
It's worth noting that this patch was shown to fix the original crash, only to expose the second. i.e. it's had some testing.
PATCH 2/2 VT-d: have set_msi_source_id() return a success indicator
In reply to Jan BeulichHandling possible internal errors by just emitting a (debug-build-only) log message can't be quite enough. Return error codes in those cases, and have the caller propagate those up.
Drop a pointless return path, rather than "inventing" an error code for it.
While touching the function declarator anyway also constify its first parameter.
xen/drivers/passthrough/vtd/intremap.c +15 -7
@@ -436,15 +436,13 @@ void cf_check io_apic_write_remap_rte(__ioapic_write_entry (apic, pin, true, old_rte); } -static void set_msi_source_id (struct pci_dev *pdev,struct iremap_entry *ire) +static int set_msi_source_id (const struct pci_dev *pdev, +struct iremap_entry *ire) {u16 seg;u8 bus, devfn, secbus;int ret; -if ( !pdev || !ire ) -return ; - seg = pdev->seg; bus = pdev->bus; devfn = pdev->devfn;
@@ -485,16 +483,21 @@ static void set_msi_source_id(struct pci PCI_BDF(bus, devfn)); }else + { dprintk(XENLOG_WARNING VTDPREFIX,"d%d: no upstream bridge for %pp\n" , pdev->domain->domain_id, &pdev->sbdf); +return -ENXIO ; + }break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "d%d: unknown(%u): %pp\n", pdev->domain->domain_id, pdev->type, &pdev->sbdf); -break ; - } +return -EOPNOTSUPP ; + } + +return 0 ; } static int msi_msg_to_remap_entry(
@@ -509,7 +512,12 @@ static int msi_msg_to_remap_entry(bool alloc = false;if ( pdev ) -set_msi_source_id (pdev, &new_ire); + { +int rc =set_msi_source_id (pdev, &new_ire); + +if ( rc ) +return rc; + }else set_hpet_source_id (msi_desc->hpet_id, &new_ire);
Re: [PATCH 2/2] VT-d: have set_msi_source_id() return a success indicator
Quoted 4 lines · Jan Beulich
Handling possible internal errors by just emitting a (debug-build-only) log message can't be quite enough. Return error codes in those cases, and have the caller propagate those up.
Quoted 8 lines
Drop a pointless return path, rather than "inventing" an error code for it.
While touching the function declarator anyway also constify its first parameter.
Fixes 476bbccc811c ("VT-d: fix MSI source-id of interrupt remapping")Signed-off-by Jan Beulich <[email protected]>
Quoted 22 lines
xen/drivers/passthrough/vtd/intremap.c +2
-4@@ -436,15 +436,13 @@ void cf_check io_apic_write_remap_rte(__ioapic_write_entry (apic, pin, true, old_rte); } -static void set_msi_source_id (struct pci_dev *pdev,struct iremap_entry *ire) +static int set_msi_source_id (const struct pci_dev *pdev, +struct iremap_entry *ire) {u16 seg;u8 bus, devfn, secbus;int ret; -if ( !pdev || !ire ) -return ; - seg = pdev->seg; bus = pdev->bus; devfn = pdev->devfn;
xen/drivers/passthrough/vtd/intremap.c static void set_msi_source_id(struct pci · line 489
Quoted 7 lines
xen/drivers/passthrough/vtd/intremap.c +1
-0@@ -485,16 +483,21 @@ static void set_msi_source_id(struct pci PCI_BDF(bus, devfn)); }else + { dprintk(XENLOG_WARNING VTDPREFIX,"d%d: no upstream bridge for %pp\n" , pdev->domain->domain_id, &pdev->sbdf);
as you're doing cleanup, %pd here? Given DOM_IO for quarantine, I think it's more likely now than it used to be.
xen/drivers/passthrough/vtd/intremap.c static void set_msi_source_id(struct pci · line 496
Quoted 7 lines
xen/drivers/passthrough/vtd/intremap.c +2
-0+return -ENXIO ; + }break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "d%d: unknown(%u): %pp\n", pdev->domain->domain_id, pdev->type, &pdev->sbdf);
Here too. Also, the "unknown(%u)" is less than ideal. "%pd: %pp unknown type %u\n" would be better.
~Andrew
Re: [PATCH 2/2] VT-d: have set_msi_source_id() return a success indicator
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Handling possible internal errors by just emitting a (debug-build-only) log message can't be quite enough. Return error codes in those cases, and have the caller propagate those up.
Drop a pointless return path, rather than "inventing" an error code for it.
Quoted 7 lines
Quoted 5 lines
While touching the function declarator anyway also constify its first parameter.
Fixes 476bbccc811c ("VT-d: fix MSI source-id of interrupt remapping")Signed-off-by Jan Beulich <[email protected]>Reviewed-by Andrew Cooper <[email protected]>,
Thanks.
Quoted 38 lines
although...
Quoted 21 lines
xen/drivers/passthrough/vtd/intremap.c +2
-4@@ -436,15 +436,13 @@ void cf_check io_apic_write_remap_rte(__ioapic_write_entry (apic, pin, true, old_rte); } -static void set_msi_source_id (struct pci_dev *pdev,struct iremap_entry *ire) +static int set_msi_source_id (const struct pci_dev *pdev, +struct iremap_entry *ire) {u16 seg;u8 bus, devfn, secbus;int ret; -if ( !pdev || !ire ) -return ; - seg = pdev->seg; bus = pdev->bus; devfn = pdev->devfn;xen/drivers/passthrough/vtd/intremap.c static void set_msi_source_id(struct pci · line 489
Quoted 7 lines
xen/drivers/passthrough/vtd/intremap.c +1
-0@@ -485,16 +483,21 @@ static void set_msi_source_id(struct pci PCI_BDF(bus, devfn)); }else + { dprintk(XENLOG_WARNING VTDPREFIX,"d%d: no upstream bridge for %pp\n" , pdev->domain->domain_id, &pdev->sbdf);as you're doing cleanup, %pd here? Given
DOM_IOfor quarantine, I think it's more likely now than it used to be.Quoted 4 lines
xen/drivers/passthrough/vtd/intremap.c +2
-0+return -ENXIO ; + }break ;
Quoted 6 lines
xen/drivers/passthrough/vtd/intremap.c static void set_msi_source_id(struct pci · line 496
Quoted 3 lines
xen/drivers/passthrough/vtd/intremap.c +0
-0default : dprintk(XENLOG_WARNING VTDPREFIX, "d%d: unknown(%u): %pp\n", pdev->domain->domain_id, pdev->type, &pdev->sbdf);Here too. Also, the "unknown(%u)" is less than ideal. "%pd: %pp unknown type %u\n" would be better.
To be honest this feels like going too far with unrelated cleanup here, even if it's all in patch context. It would be different if at least I touched those dprintk() invocations.
Jan