vpci/msix: restore PBA access length and alignment restrictions
PATCH 1/1 vpci/msix: restore PBA access length and alignment restrictions
Accesses to the PBA array have the same length and alignment limitations as accesses to the MSI-X table:
"For all accesses to MSI-X Table and MSI-X PBA fields, software must use aligned full DWORD or aligned full QWORD transactions; otherwise, the result is undefined."
Introduce such length and alignment checks into the handling of PBA accesses for vPCI. This was a mistake of mine for not reading the specification correctly.
Note that accesses must now be aligned, and hence there's no longer a need to check that the end of the access falls into the PBA region as both the access and the region addresses must be aligned.
--- xen/drivers/vpci/msix.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
xen/drivers/vpci/msix.c +7 -3
@@ -278,6 +278,11 @@ static int adjacent_read(const struct domain *d, const struct vpci_msix *msix,if ( !adjacent_handle (msix, addr + len -1 ) )return X86EMUL_OKAY ; +if (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) && + !access_allowed (msix->pdev, addr, len) ) +/* PBA accesses must be aligned and 4 or 8 bytes in size. */ +return X86EMUL_OKAY ; + slot =get_slot (vpci, addr);if ( slot >=ARRAY_SIZE (msix->table) )return X86EMUL_OKAY ;
@@ -419,9 +424,8 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix,* assumed to be equal or bigger (8 bytes) than the length of any access * handled here. */ -if ( (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) || -VMSIX_ADDR_IN_RANGE (addr + len -1 , vpci,VPCI_MSIX_PBA )) && - !is_hardware_domain (d) ) +if (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) && + (!access_allowed (msix->pdev, addr, len) || !is_hardware_domain (d)) )/* Ignore writes to PBA for DomUs, it's undefined behavior. */ return X86EMUL_OKAY ;
Signature · 1 line
2.40.0
Quoted 11 lines · Roger Pau Monne
Accesses to the PBA array have the same length and alignment limitations as accesses to the MSI-X table:
"For all accesses to MSI-X Table and MSI-X PBA fields, software must use aligned full DWORD or aligned full QWORD transactions; otherwise, the result is undefined."
Introduce such length and alignment checks into the handling of PBA accesses for vPCI. This was a mistake of mine for not reading the specification correctly.
Quoted 7 lines
Note that accesses must now be aligned, and hence there's no longer a need to check that the end of the access falls into the PBA region as both the access and the region addresses must be aligned.
Fixes b177892d2d ('vpci/msix: handle accesses adjacent to the MSI-X table')Reported-by Jan Beulich <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
And thanks for taking care of this so quickly.
Jan
xen/drivers/vpci/msix.c static int adjacent_write(const struct domain *d, const struct vpci_msix *msix, · line 430
Quoted 11 lines · Roger Pau Monne
xen/drivers/vpci/msix.c +2
-3@@ -419,9 +424,8 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix,* assumed to be equal or bigger (8 bytes) than the length of any access * handled here. */ -if ( (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) || -VMSIX_ADDR_IN_RANGE (addr + len -1 , vpci,VPCI_MSIX_PBA )) && - !is_hardware_domain (d) ) +if (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) && + (!access_allowed (msix->pdev, addr, len) || !is_hardware_domain (d)) )/* Ignore writes to PBA for DomUs, it's undefined behavior. */ return X86EMUL_OKAY ;
While preparing the backport, where I'm folding this into the earlier patch, I've noticed that this change has now left the comment stale (the problematic part if just out of context). Not sure though whether that's worth yet another fixup patch.
Jan
Quoted 17 lines · Jan Beulich
xen/drivers/vpci/msix.c static int adjacent_write(const struct domain *d, const struct vpci_msix *msix, · line 430
Quoted 11 lines · Roger Pau Monne
xen/drivers/vpci/msix.c +2
-3@@ -419,9 +424,8 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix,* assumed to be equal or bigger (8 bytes) than the length of any access * handled here. */ -if ( (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) || -VMSIX_ADDR_IN_RANGE (addr + len -1 , vpci,VPCI_MSIX_PBA )) && - !is_hardware_domain (d) ) +if (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) && + (!access_allowed (msix->pdev, addr, len) || !is_hardware_domain (d)) )/* Ignore writes to PBA for DomUs, it's undefined behavior. */ return X86EMUL_OKAY ;While preparing the backport, where I'm folding this into the earlier patch, I've noticed that this change has now left the comment stale (the problematic part if just out of context). Not sure though whether that's worth yet another fixup patch.
I see, thanks for noticing. I think I can likely adjust in some further change, or even just drop it, not sure the comment is that relevant anymore if both the PBA and the access must be aligned now.
Roger.
Quoted 19 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
xen/drivers/vpci/msix.c static int adjacent_write(const struct domain *d, const struct vpci_msix *msix, · line 430
Quoted 11 lines · Roger Pau Monne
xen/drivers/vpci/msix.c +2
-3@@ -419,9 +424,8 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix,* assumed to be equal or bigger (8 bytes) than the length of any access * handled here. */ -if ( (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) || -VMSIX_ADDR_IN_RANGE (addr + len -1 , vpci,VPCI_MSIX_PBA )) && - !is_hardware_domain (d) ) +if (VMSIX_ADDR_IN_RANGE (addr, vpci,VPCI_MSIX_PBA ) && + (!access_allowed (msix->pdev, addr, len) || !is_hardware_domain (d)) )/* Ignore writes to PBA for DomUs, it's undefined behavior. */ return X86EMUL_OKAY ;While preparing the backport, where I'm folding this into the earlier patch, I've noticed that this change has now left the comment stale (the problematic part if just out of context). Not sure though whether that's worth yet another fixup patch.
Quoted 3 lines
I see, thanks for noticing. I think I can likely adjust in some further change, or even just drop it, not sure the comment is that relevant anymore if both the PBA and the access must be aligned now.
Yeah, dropping would be fine with me. Plus you're the maintainer anyway ...
Jan