diff mbox

[kvm-unit-tests,2/4] pci: Assert when PCI bus address can not be translated

Message ID 2ce796c2ddfe691658b17f2e6e79c8a9acc76c6d.1480430576.git.agordeev@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Gordeev Nov. 29, 2016, 2:48 p.m. UTC
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
 lib/pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Andrew Jones Nov. 30, 2016, 12:45 p.m. UTC | #1
On Tue, Nov 29, 2016 at 03:48:51PM +0100, Alexander Gordeev wrote:
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Andrew Jones <drjones@redhat.com>
> Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
> ---
>  lib/pci.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/pci.c b/lib/pci.c
> index 6bd54cbac1bb..fdd88296f0ae 100644
> --- a/lib/pci.c
> +++ b/lib/pci.c
> @@ -43,11 +43,15 @@ phys_addr_t pci_bar_get_addr(pcidevaddr_t dev, int bar_num)
>  	uint32_t bar = pci_bar_get(dev, bar_num);
>  	uint32_t mask = pci_bar_mask(bar);
>  	uint64_t addr = bar & mask;
> +	phys_addr_t phys_addr;
>  
>  	if (pci_bar_is64(dev, bar_num))
>  		addr |= (uint64_t)pci_bar_get(dev, bar_num + 1) << 32;
>  
> -	return pci_translate_addr(dev, addr);
> +	phys_addr = pci_translate_addr(dev, addr);
> +	assert(phys_addr != INVALID_PHYS_ADDR);
> +
> +	return phys_addr;
>  }
>  
>  void pci_bar_set_addr(pcidevaddr_t dev, int bar_num, phys_addr_t addr)
> -- 
> 1.8.3.1
>

This patch needs a commit message with the justification for the assert.
I'll add

 Failing to translate the PCI address obtained from the bar means
 something isn't right with the PCI setup. As this should never
 happen, assert when it does.

Thanks,
drew
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/pci.c b/lib/pci.c
index 6bd54cbac1bb..fdd88296f0ae 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -43,11 +43,15 @@  phys_addr_t pci_bar_get_addr(pcidevaddr_t dev, int bar_num)
 	uint32_t bar = pci_bar_get(dev, bar_num);
 	uint32_t mask = pci_bar_mask(bar);
 	uint64_t addr = bar & mask;
+	phys_addr_t phys_addr;
 
 	if (pci_bar_is64(dev, bar_num))
 		addr |= (uint64_t)pci_bar_get(dev, bar_num + 1) << 32;
 
-	return pci_translate_addr(dev, addr);
+	phys_addr = pci_translate_addr(dev, addr);
+	assert(phys_addr != INVALID_PHYS_ADDR);
+
+	return phys_addr;
 }
 
 void pci_bar_set_addr(pcidevaddr_t dev, int bar_num, phys_addr_t addr)