* [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail
@ 2016-11-25 14:56 Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 1/2] pci: Make all ones invalid translate address Alexander Gordeev
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alexander Gordeev @ 2016-11-25 14:56 UTC (permalink / raw)
To: kvm; +Cc: Alexander Gordeev, Thomas Huth, Andrew Jones
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Alexander Gordeev (2):
pci: Make all ones invalid translate address
pci: pci_host_bridge_get_paddr() can not fail
lib/pci-host-generic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [kvm-unit-tests PATCH 1/2] pci: Make all ones invalid translate address
2016-11-25 14:56 [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
@ 2016-11-25 14:56 ` Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 2/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
2016-11-25 15:19 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Gordeev @ 2016-11-25 14:56 UTC (permalink / raw)
To: kvm; +Cc: Alexander Gordeev, Thomas Huth, Andrew Jones
Function pci_host_bridge_get_paddr() returns zero in case
no mapping for a passed PCI address is found. All ones is
a better choice, since zero may be a legitimate physical
address.
Suggested-by: Andrew Jones <drjones@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
lib/pci-host-generic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pci-host-generic.c b/lib/pci-host-generic.c
index d57b47ee4c53..7f72d649144e 100644
--- a/lib/pci-host-generic.c
+++ b/lib/pci-host-generic.c
@@ -271,7 +271,7 @@ phys_addr_t pci_host_bridge_get_paddr(u64 pci_addr)
as++;
}
- return 0;
+ return ~0;
}
static void __iomem *pci_get_dev_conf(struct pci_host_bridge *host, int devfn)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [kvm-unit-tests PATCH 2/2] pci: pci_host_bridge_get_paddr() can not fail
2016-11-25 14:56 [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 1/2] pci: Make all ones invalid translate address Alexander Gordeev
@ 2016-11-25 14:56 ` Alexander Gordeev
2016-11-25 15:19 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Gordeev @ 2016-11-25 14:56 UTC (permalink / raw)
To: kvm; +Cc: Alexander Gordeev, Thomas Huth, Andrew Jones
Function pci_host_bridge_get_paddr() is passed a PCI bus
address to translate into physical one. The PCI address
is always read from a device BAR and is expected to be
valid. Therefore, a failure to find the mapping for the
PCI address indicates a serious implementation problem
elsewhere.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
lib/pci-host-generic.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/pci-host-generic.c b/lib/pci-host-generic.c
index 7f72d649144e..433a0c8e4d15 100644
--- a/lib/pci-host-generic.c
+++ b/lib/pci-host-generic.c
@@ -271,6 +271,7 @@ phys_addr_t pci_host_bridge_get_paddr(u64 pci_addr)
as++;
}
+ assert(0);
return ~0;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail
2016-11-25 14:56 [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 1/2] pci: Make all ones invalid translate address Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 2/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
@ 2016-11-25 15:19 ` Andrew Jones
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2016-11-25 15:19 UTC (permalink / raw)
To: Alexander Gordeev; +Cc: kvm, Thomas Huth
On Fri, Nov 25, 2016 at 03:56:04PM +0100, Alexander Gordeev wrote:
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Andrew Jones <drjones@redhat.com>
>
> Alexander Gordeev (2):
> pci: Make all ones invalid translate address
> pci: pci_host_bridge_get_paddr() can not fail
>
> lib/pci-host-generic.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> --
> 1.8.3.1
I applied the first to arm/next, but not the other. I think
returning ~0 makes more sense here, and that callers (even
callers that are part of the API) should consider asserting
on receiving it.
As we discussed, low-level API should return whatever it
finds/doesn't find (no asserts). Higher-level API can assert
on invalid inputs and unexpected results from the low-level
API.
Additionally, this series doesn't solve the problem I reported,
which is, if you do
pci_bar_get_addr(any_device, invalid_bar_num)
you get back the base address of the PIO region. That happens
because pci_bar_get(any_device, invalid_bar_num) returns zero
and then that zero gets translated correctly by pci_translate_addr
to the PIO region's physical base address.
I think we should look into adding asserts to pci_bar_get/set_addr
and the other higher-level API calls instead. We should add
assert(pci_bar_is_valid(bar_num))
many places, and pci_bar_get_addr should have
phys_addr = pci_translate_addr(dev, pci_addr)
assert(phys_addr != ~0)
Thanks,
drew
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-25 15:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-25 14:56 [kvm-unit-tests PATCH 0/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 1/2] pci: Make all ones invalid translate address Alexander Gordeev
2016-11-25 14:56 ` [kvm-unit-tests PATCH 2/2] pci: pci_host_bridge_get_paddr() can not fail Alexander Gordeev
2016-11-25 15:19 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox