xen/pci: implement is_memory_hole for ARM
v2 cover xen/pci: implement is_memory_hole for ARM
This patch series is to implement something like is_memory_hole function for ARM.
Rahul Singh (2):
xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev xen/pci: replace call to is_memory_hole to pci_check_bar
xen/arch/arm/include/asm/pci.h | 5 ++- xen/arch/arm/pci/pci-host-common.c | 50 ++++++++++++++++++++++++++++-- xen/arch/x86/include/asm/pci.h | 10 ++++++ xen/drivers/passthrough/pci.c | 8 ++--- 4 files changed, 66 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev
Modify pci_find_host_bridge_node argument to const pdev to avoid converting the dev to pdev in pci_find_host_bridge_node and also constify the return.
---
Changes in v2:
- this patch is introduced in this version
--- xen/arch/arm/include/asm/pci.h | 3 ++- xen/arch/arm/pci/pci-host-common.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/pci.h +2 -1
@@ -106,7 +106,8 @@ bool pci_ecam_need_p2m_hwdom_mapping(struct domain *d,struct pci_host_bridge *bridge, uint64_t addr);struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); -struct dt_device_node *pci_find_host_bridge_node (struct device *dev); +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev);int pci_get_host_bridge_segment (const struct dt_device_node *node,uint16_t *segment);
xen/arch/arm/pci/pci-host-common.c +2 -2
@@ -243,10 +243,10 @@ err_exit:/* * Get host bridge node given a device attached to it. */ -struct dt_device_node *pci_find_host_bridge_node (struct device *dev) +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev) {struct pci_host_bridge *bridge; -struct pci_dev *pdev =dev_to_pci (dev); bridge =pci_find_host_bridge (pdev->seg, pdev->bus);if (unlikely (!bridge) )
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev
On 17.08.22 17:45, Rahul Singh wrote:
Hello Rahul
Quoted 5 lines
Modify
pci_find_host_bridge_nodeargument to const pdev to avoid converting the dev to pdev inpci_find_host_bridge_nodeand also constify the return.Signed-off-by Rahul Singh <[email protected]>
Quoted 39 lines
---
Changes in v2:
- this patch is introduced in this version--- xen/arch/arm/include/asm/pci.h | 3 ++- xen/arch/arm/pci/pci-host-common.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/pci.h +2
-1@@ -106,7 +106,8 @@ bool pci_ecam_need_p2m_hwdom_mapping(struct domain *d,struct pci_host_bridge *bridge, uint64_t addr);struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); -struct dt_device_node *pci_find_host_bridge_node (struct device *dev); +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev);int pci_get_host_bridge_segment (const struct dt_device_node *node,uint16_t *segment);xen/arch/arm/pci/pci-host-common.c +2
-2@@ -243,10 +243,10 @@ err_exit:/* * Get host bridge node given a device attached to it. */ -struct dt_device_node *pci_find_host_bridge_node (struct device *dev) +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev) {struct pci_host_bridge *bridge; -struct pci_dev *pdev =dev_to_pci (dev); bridge =pci_find_host_bridge (pdev->seg, pdev->bus);if (unlikely (!bridge) )
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Stefano Stabellini
Acked-byRe: [PATCH v2 1/2] xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev
Quoted 11 lines · Oleksandr
On 17.08.22 17:45, Rahul Singh wrote:
Hello RahulQuoted 5 lines
Modify
pci_find_host_bridge_nodeargument to const pdev to avoid converting the dev to pdev inpci_find_host_bridge_nodeand also constify the return.Signed-off-by Rahul Singh <[email protected]>Reviewed-by Oleksandr Tyshchenko <[email protected]>
Quoted 45 lines
Quoted 39 lines
---
Changes in v2:
- this patch is introduced in this version--- xen/arch/arm/include/asm/pci.h | 3 ++- xen/arch/arm/pci/pci-host-common.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/pci.h +2
-1@@ -106,7 +106,8 @@ bool pci_ecam_need_p2m_hwdom_mapping(struct domain *d,struct pci_host_bridge *bridge, uint64_t addr);struct pci_host_bridge *pci_find_host_bridge (uint16_t segment,uint8_t bus); -struct dt_device_node *pci_find_host_bridge_node (struct device *dev); +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev);int pci_get_host_bridge_segment (const struct dt_device_node *node,uint16_t *segment);diff --git
a/xen/arch/arm/pci/pci-host-common.cb/xen/arch/arm/pci/pci-host-common.c
indexfd8c0f837a..89ef30028e100644xen/arch/arm/pci/pci-host-common.c +2
-2@@ -243,10 +243,10 @@ err_exit:/* * Get host bridge node given a device attached to it. */ -struct dt_device_node *pci_find_host_bridge_node (struct device *dev) +const struct dt_device_node * +pci_find_host_bridge_node (const struct pci_dev *pdev) {struct pci_host_bridge *bridge; -struct pci_dev *pdev =dev_to_pci (dev); bridge =pci_find_host_bridge (pdev->seg, pdev->bus);if (unlikely (!bridge) )Signature · 3 lines
Regards, Oleksandr Tyshchenko
PATCH v2 2/2 xen/pci: replace call to is_memory_hole to pci_check_bar
In reply to Rahul Singhis_memory_hole was implemented for x86 and not for ARM when introduced. Replace is_memory_hole call to pci_check_bar as function should check if device BAR is in defined memory range. Also, add an implementation for ARM which is required for PCI passthrough.
On x86, pci_check_bar will call is_memory_hole which will check if BAR is not overlapping with any memory region defined in the memory map.
On ARM, pci_check_bar will go through the host bridge ranges and check if the BAR is in the range of defined ranges.
---
Changes in v2:
- fixed minor comment
- modify pci_find_host_bridge_node argument to const pdev
--- xen/arch/arm/include/asm/pci.h | 2 ++ xen/arch/arm/pci/pci-host-common.c | 46 ++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/pci.h | 10 +++++++ xen/drivers/passthrough/pci.c | 8 +++--- 4 files changed, 62 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/pci.h +2 -0
@@ -126,6 +126,8 @@ int pci_host_iterate_bridges_and_count(struct domain *d,int pci_host_bridge_mappings (struct domain *d); +bool pci_check_bar (const struct pci_dev *pdev,mfn_t start,mfn_t end); +#else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { };
xen/arch/arm/pci/pci-host-common.c +46 -0
58 lines not on this page · raw message
xen/arch/x86/include/asm/pci.h +10 -0
@@ -57,4 +57,14 @@ static always_inline bool is_pci_passthrough_enabled(void)void arch_pci_init_pdev (struct pci_dev *pdev); +static inline bool pci_check_bar (const struct pci_dev *pdev, +mfn_t start,mfn_t end) +{ +/* +* Check if BAR is not overlapping with any memory region defined +* in the memory map. +*/ +return is_memory_hole (start, end); +} +#endif /* __X86_PCI_H__ */
xen/drivers/passthrough/pci.c +4 -4
@@ -304,8 +304,8 @@ static void check_pdev(const struct pci_dev *pdev)if ( rc <0 )/* Unable to size, better leave memory decoding disabled. */ return ; -if ( size && !is_memory_hole (maddr_to_mfn (addr), -maddr_to_mfn (addr + size -1 )) ) +if ( size && !pci_check_bar (pdev,maddr_to_mfn (addr), +maddr_to_mfn (addr + size -1 )) ) {/* * Return without enabling memory decoding if BAR position is not
@@ -331,8 +331,8 @@ static void check_pdev(const struct pci_dev *pdev)if ( rc <0 )return ; -if ( size && !is_memory_hole (maddr_to_mfn (addr), -maddr_to_mfn (addr + size -1 )) ) +if ( size && !pci_check_bar (pdev,maddr_to_mfn (addr), +maddr_to_mfn (addr + size -1 )) ) {printk (warn, &pdev->sbdf,"ROM " ,PFN_DOWN (addr),PFN_DOWN (addr + size -1 ));
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 377
Quoted 6 lines · Rahul Singh
xen/arch/arm/pci/pci-host-common.c +2
-0@@ -363,6 +373,42 @@ int __init pci_host_bridge_mappings(struct domain *d)return 0 ; } +static int is_bar_valid (const struct dt_device_node *dev, +u64 addr,u64 len,void *data)
s/u64/uint64_t/g please.
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 383
Quoted 6 lines
xen/arch/arm/pci/pci-host-common.c +6
-0+{ +struct pdev_bar *bar_data = data; +unsigned long s =mfn_x (bar_data->start); +unsigned long e =mfn_x (bar_data->end); + +if ( (s < e) && (s >=PFN_UP (addr)) && (e <=PFN_UP (addr + len -1 )) )
Doesn't this need to be s >= PFN_DOWN(addr)? Or else why is e checked against PFN_UP()?
Quoted 10 lines
xen/arch/arm/pci/pci-host-common.c +10
-0+ bar_data->is_valid = true; + +return 0 ; +} + +bool pci_check_bar (const struct pci_dev *pdev,mfn_t start,mfn_t end) +{ +int ret; +const struct dt_device_node *dt_node; +struct pdev_bar bar_data = {
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 403
Quoted 10 lines
xen/arch/arm/pci/pci-host-common.c +10
-0+ .start = start, + .end = end, + .is_valid = false + }; + + dt_node =pci_find_host_bridge_node (pdev); +if ( !dt_node ) +return false; + + ret =dt_for_each_range (dt_node, &is_bar_valid, &bar_data);
Just as a side note - I find such (the first instance here) uses of the unary & operator odd. The same effect will be had without it. So all it does (in my opinion) is make things harder to read (just very slightly, of course).
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 410
Quoted 7 lines
xen/arch/arm/pci/pci-host-common.c +7
-0+if ( ret <0 ) +return false; + +if ( !bar_data.is_valid ) +return false; + +return true;
Simply "return bar_data.is_valid;"?
Jan
Re: [PATCH v2 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar
Hello Jan,
Quoted 11 lines · Jan Beulich
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 377
Quoted 6 lines · Rahul Singh
xen/arch/arm/pci/pci-host-common.c +2
-0@@ -363,6 +373,42 @@ int __init pci_host_bridge_mappings(struct domain *d)return 0 ; } +static int is_bar_valid (const struct dt_device_node *dev, +u64 addr,u64 len,void *data)s/u64/uint64_t/g please.
Ack.
Quoted 10 lines
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 383
Quoted 7 lines
xen/arch/arm/pci/pci-host-common.c +6
-0+{ +struct pdev_bar *bar_data = data; +unsigned long s =mfn_x (bar_data->start); +unsigned long e =mfn_x (bar_data->end); + +if ( (s < e) && (s >=PFN_UP (addr)) && (e <=PFN_UP (addr + len -1 )) )Doesn't this need to be s >=
PFN_DOWN(addr)? Or else why is e checked againstPFN_UP()?
Ack. I will modify as if ( (s < e) && (s >= PFN_DOWN(addr)) && (e <= PFN_UP(addr + len - 1)) )
Quoted 18 lines
Quoted 18 lines
xen/arch/arm/pci/pci-host-common.c +17
-0+ bar_data->is_valid = true; + +return 0 ; +} + +bool pci_check_bar (const struct pci_dev *pdev,mfn_t start,mfn_t end) +{ +int ret; +const struct dt_device_node *dt_node; +struct pdev_bar bar_data = { + .start = start, + .end = end, + .is_valid = false + }; + + dt_node =pci_find_host_bridge_node (pdev); +if ( !dt_node )
Quoted 8 lines
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 403
Quoted 3 lines
xen/arch/arm/pci/pci-host-common.c +3
-0+return false; + + ret =dt_for_each_range (dt_node, &is_bar_valid, &bar_data);Just as a side note - I find such (the first instance here) uses of the unary & operator odd. The same effect will be had without it. So all it does (in my opinion) is make things harder to read (just very slightly, of course).
I follow the same calling method as used in map_device_children() function in file arch/arm/domain_build.c
Quoted 10 lines
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 410
Quoted 8 lines
xen/arch/arm/pci/pci-host-common.c +7
-0+if ( ret <0 ) +return false; + +if ( !bar_data.is_valid ) +return false; + +return true;Simply "return bar_data.is_valid;"?
Ack.
Regards,
Rahul
Re: [PATCH v2 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar
Quoted 6 lines · Rahul Singh
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Rahul Singh
xen/arch/arm/pci/pci-host-common.c +0
-0@@ -363,6 +373,42 @@ int __init pci_host_bridge_mappings(struct domain *d)return 0 ; }
Quoted 9 lines
Quoted 4 lines
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 377
Quoted 2 lines
xen/arch/arm/pci/pci-host-common.c +2
-0+static int is_bar_valid (const struct dt_device_node *dev, +u64 addr,u64 len,void *data)s/u64/uint64_t/g please.
Ack.
Quoted 3 lines
Quoted 3 lines
xen/arch/arm/pci/pci-host-common.c +2
-0+{ +struct pdev_bar *bar_data = data;
const?
Quoted 9 lines
Quoted 7 lines
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 383
Quoted 4 lines
xen/arch/arm/pci/pci-host-common.c +4
-0+unsigned long s =mfn_x (bar_data->start); +unsigned long e =mfn_x (bar_data->end); + +if ( (s < e) && (s >=PFN_UP (addr)) && (e <=PFN_UP (addr + len -1 )) )Doesn't this need to be s >=
PFN_DOWN(addr)? Or else why is e checked againstPFN_UP()?Ack. I will modify as if ( (s < e) && (s >=
PFN_DOWN(addr)) && (e <=PFN_UP(addr + len - 1)) )
Hmm, doesn't it further need to be s <= e, seeing that the range passed to pci_check_bar() is an inclusive one?
Jan
Re: [PATCH v2 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar
Hi Jan,
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Rahul Singh
Quoted 10 lines · Jan Beulich
xen/arch/arm/pci/pci-host-common.c int __init pci_host_bridge_mappings(struct domain *d) · line 377
Quoted 6 lines · Rahul Singh
xen/arch/arm/pci/pci-host-common.c +2
-0@@ -363,6 +373,42 @@ int __init pci_host_bridge_mappings(struct domain *d)return 0 ; } +static int is_bar_valid (const struct dt_device_node *dev, +u64 addr,u64 len,void *data)s/u64/uint64_t/g please.
Quoted 6 lines
Quoted 4 lines
Ack.
Quoted 3 lines
Quoted 3 lines
xen/arch/arm/pci/pci-host-common.c +2
-0+{ +struct pdev_bar *bar_data = data;const?
Ack.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/arm/pci/pci-host-common.c +4
-0+unsigned long s =mfn_x (bar_data->start); +unsigned long e =mfn_x (bar_data->end); + +if ( (s < e) && (s >=PFN_UP (addr)) && (e <=PFN_UP (addr + len -1 )) )
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Doesn't this need to be s >=
PFN_DOWN(addr)? Or else why is e checked againstPFN_UP()?Ack. I will modify as if ( (s < e) && (s >=
PFN_DOWN(addr)) && (e <=PFN_UP(addr + len - 1)) )Hmm, doesn't it further need to be s <= e, seeing that the range passed to
pci_check_bar()is an inclusive one?
Agree, I will do the modification in next version.
Regards,
Rahul