unexport swiotlb_active
Subsystems (10)
Hi all,
this little series removes the last swiotlb API exposed to modules.
Diffstat:
arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------ arch/x86/kernel/pci-dma.c | 28 ++++------------------------ drivers/gpu/drm/nouveau/nouveau_ttm.c | 10 +++------- drivers/pci/xen-pcifront.c | 6 ------ kernel/dma/swiotlb.c | 1 - 5 files changed, 7 insertions(+), 44 deletions(-)
PATCH 1/4 x86: move a check out of pci_xen_swiotlb_init
Move the exact checks when to initialize the Xen swiotlb code out of pci_xen_swiotlb_init and into the caller so that is uses readable positive checks, rather than negative ones that will get even more confusing with another addition.
--- arch/x86/kernel/pci-dma.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/pci-dma.c +2 -3
@@ -74,8 +74,6 @@ static inline void __init pci_swiotlb_detect(void)#ifdef CONFIG_SWIOTLB_XEN static void __init pci_xen_swiotlb_init (void ) { -if (!xen_initial_domain () && !x86_swiotlb_enable) -return ; x86_swiotlb_enable = true; x86_swiotlb_flags |=SWIOTLB_ANY ;swiotlb_init_remap (true, x86_swiotlb_flags, xen_swiotlb_fixup);
@@ -113,7 +111,8 @@ static inline void __init pci_xen_swiotlb_init(void)void __init pci_iommu_alloc (void ) {if (xen_pv_domain ()) { -pci_xen_swiotlb_init (); +if (xen_initial_domain () || x86_swiotlb_enable) +pci_xen_swiotlb_init ();return ; }pci_swiotlb_detect ();
Signature · 1 line
2.39.2
PATCH 2/4 x86: always initialize xen-swiotlb when xen-pcifront is enabling
In reply to Christoph HellwigRemove the dangerous late initialization of xen-swiotlb in pci_xen_swiotlb_init_late and instead just always initialize xen-swiotlb in the boot code if CONFIG_XEN_PCIDEV_FRONTEND is enabled.
--- arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------ arch/x86/kernel/pci-dma.c | 25 +++---------------------- drivers/pci/xen-pcifront.c | 6 ------ 3 files changed, 3 insertions(+), 34 deletions(-)
arch/x86/include/asm/xen/swiotlb-xen.h +0 -6
@@ -2,12 +2,6 @@#ifndef _ASM_X86_SWIOTLB_XEN_H#define _ASM_X86_SWIOTLB_XEN_H -#ifdef CONFIG_SWIOTLB_XEN -extern int pci_xen_swiotlb_init_late (void ); -#else -static inline int pci_xen_swiotlb_init_late (void ) {return -ENXIO ; } -#endif -int xen_swiotlb_fixup (void *buf,unsigned long nslabs); int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits,
arch/x86/kernel/pci-dma.c +3 -22
@@ -81,27 +81,6 @@ static void __init pci_xen_swiotlb_init(void)if (IS_ENABLED (CONFIG_PCI )) pci_request_acs(); } - -int pci_xen_swiotlb_init_late (void ) -{ -if (dma_ops == &xen_swiotlb_dma_ops) -return 0 ; - -/* we can work with the default swiotlb */ -if (!io_tlb_default_mem.nslabs) { -int rc =swiotlb_init_late (swiotlb_size_or_default (), -GFP_KERNEL , xen_swiotlb_fixup); -if (rc <0 ) -return rc; - } - -/* XXX: this switches the dma ops under live devices! */ - dma_ops = &xen_swiotlb_dma_ops; -if (IS_ENABLED (CONFIG_PCI )) -pci_request_acs (); -return 0 ; -} -EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late);#else static inline void __init pci_xen_swiotlb_init (void ) {
@@ -111,7 +90,9 @@ static inline void __init pci_xen_swiotlb_init(void)void __init pci_iommu_alloc (void ) {if (xen_pv_domain ()) { -if (xen_initial_domain () || x86_swiotlb_enable) +if (xen_initial_domain () || +IS_ENABLED (CONFIG_XEN_PCIDEV_FRONTEND ) || + x86_swiotlb_enable)pci_xen_swiotlb_init ();return ; }
drivers/pci/xen-pcifront.c +0 -6
@@ -22,7 +22,6 @@#include <linux/bitops.h> #include <linux/time.h> #include <linux/ktime.h> -#include <linux/swiotlb.h> #include <xen/platform_pci.h> #include <asm/xen/swiotlb-xen.h>
@@ -669,11 +668,6 @@ static int pcifront_connect_and_init_dma(struct pcifront_device *pdev)spin_unlock (&pcifront_dev_lock); -if (!err && !is_swiotlb_active (&pdev->xdev->dev)) { - err =pci_xen_swiotlb_init_late (); -if (err) -dev_err (&pdev->xdev->dev,"Could not setup SWIOTLB!\n" ); - }return err; }
Signature · 1 line
2.39.2
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 5 lines · Christoph Hellwig
Remove the dangerous late initialization of xen-swiotlb in
pci_xen_swiotlb_init_lateand instead just always initialize xen-swiotlb in the boot code ifCONFIG_XEN_PCIDEV_FRONTENDis enabled.Signed-off-by Christoph Hellwig <[email protected]>
Doesn't it mean all the PV guests will basically waste 64MB of RAM by default each if they don't really have PCI devices?
Quoted 94 lines
--- arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------ arch/x86/kernel/pci-dma.c | 25 +++---------------------- drivers/pci/xen-pcifront.c | 6 ------ 3 files changed, 3 insertions(+), 34 deletions(-)arch/x86/include/asm/xen/swiotlb-xen.h +0
-6@@ -2,12 +2,6 @@#ifndef _ASM_X86_SWIOTLB_XEN_H#define _ASM_X86_SWIOTLB_XEN_H -#ifdef CONFIG_SWIOTLB_XEN -extern int pci_xen_swiotlb_init_late (void ); -#else -static inline int pci_xen_swiotlb_init_late (void ) {return -ENXIO ; } -#endif -int xen_swiotlb_fixup (void *buf,unsigned long nslabs); int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits,arch/x86/kernel/pci-dma.c +3
-22@@ -81,27 +81,6 @@ static void __init pci_xen_swiotlb_init(void)if (IS_ENABLED (CONFIG_PCI )) pci_request_acs(); } - -int pci_xen_swiotlb_init_late (void ) -{ -if (dma_ops == &xen_swiotlb_dma_ops) -return 0 ; - -/* we can work with the default swiotlb */ -if (!io_tlb_default_mem.nslabs) { -int rc =swiotlb_init_late (swiotlb_size_or_default (), -GFP_KERNEL , xen_swiotlb_fixup); -if (rc <0 ) -return rc; - } - -/* XXX: this switches the dma ops under live devices! */ - dma_ops = &xen_swiotlb_dma_ops; -if (IS_ENABLED (CONFIG_PCI )) -pci_request_acs (); -return 0 ; -} -EXPORT_SYMBOL_GPL (pci_xen_swiotlb_init_late);#else static inline void __init pci_xen_swiotlb_init (void ) {@@ -111,7 +90,9 @@ static inline void __init pci_xen_swiotlb_init(void)void __init pci_iommu_alloc (void ) {if (xen_pv_domain ()) { -if (xen_initial_domain () || x86_swiotlb_enable) +if (xen_initial_domain () || +IS_ENABLED (CONFIG_XEN_PCIDEV_FRONTEND ) || + x86_swiotlb_enable)pci_xen_swiotlb_init ();return ; }drivers/pci/xen-pcifront.c +0
-6@@ -22,7 +22,6 @@#include <linux/bitops.h> #include <linux/time.h> #include <linux/ktime.h> -#include <linux/swiotlb.h> #include <xen/platform_pci.h> #include <asm/xen/swiotlb-xen.h> @@ -669,11 +668,6 @@ static int pcifront_connect_and_init_dma(struct pcifront_device *pdev)spin_unlock (&pcifront_dev_lock); -if (!err && !is_swiotlb_active (&pdev->xdev->dev)) { - err =pci_xen_swiotlb_init_late (); -if (err) -dev_err (&pdev->xdev->dev,"Could not setup SWIOTLB!\n" ); - }return err; }Signature · 1 line
2.39.2
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 9 lines · Marek Marczykowski-Górecki
Quoted 5 lines · Christoph Hellwig
Remove the dangerous late initialization of xen-swiotlb in
pci_xen_swiotlb_init_lateand instead just always initialize xen-swiotlb in the boot code ifCONFIG_XEN_PCIDEV_FRONTENDis enabled.Signed-off-by Christoph Hellwig <[email protected]>Doesn't it mean all the PV guests will basically waste 64MB of RAM by default each if they don't really have PCI devices?
If CONFIG_XEN_PCIDEV_FRONTEND is enabled, and the kernel's isn't booted with swiotlb=noforce, yes.
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Marek Marczykowski-Górecki
Quoted 4 lines · Christoph Hellwig
Remove the dangerous late initialization of xen-swiotlb in
pci_xen_swiotlb_init_lateand instead just always initialize xen-swiotlb in the boot code ifCONFIG_XEN_PCIDEV_FRONTENDis enabled.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>Doesn't it mean all the PV guests will basically waste 64MB of RAM by default each if they don't really have PCI devices?
If
CONFIG_XEN_PCIDEV_FRONTENDis enabled, and the kernel's isn't booted with swiotlb=noforce, yes.
That's "a bit" unfortunate, since that might be significant part of the VM memory, or if you have a lot of VMs, a significant part of the host memory - it quickly adds up.
While I would say PCI passthrough is not very common for PV guests, can the decision about xen-swiotlb be delayed until you can enumerate xenstore to check if there are any PCI devices connected (and not allocate xen-swiotlb by default if there are none)? This would still not cover the hotplug case (in which case, you'd need to force it with a cmdline), but at least you wouldn't loose much memory just because one of your VMs may use PCI passthrough (so, you have it enabled in your kernel).
Please remember that guest kernel is not always under full control of the host admin, so making guests loose 64MB of RAM always, in default setup isn't good for customers of such VMs...
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 8 lines · Marek Marczykowski-Górecki
While I would say PCI passthrough is not very common for PV guests, can the decision about xen-swiotlb be delayed until you can enumerate xenstore to check if there are any PCI devices connected (and not allocate xen-swiotlb by default if there are none)? This would still not cover the hotplug case (in which case, you'd need to force it with a cmdline), but at least you wouldn't loose much memory just because one of your VMs may use PCI passthrough (so, you have it enabled in your kernel).
How early can we query xenstore? We'd need to do this before setting up DMA for any device.
The alternative would be to finally merge swiotlb-xen into swiotlb, in which case we might be able to do this later. Let me see what I can do there.
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 11 lines · Christoph Hellwig
Quoted 8 lines · Marek Marczykowski-Górecki
While I would say PCI passthrough is not very common for PV guests, can the decision about xen-swiotlb be delayed until you can enumerate xenstore to check if there are any PCI devices connected (and not allocate xen-swiotlb by default if there are none)? This would still not cover the hotplug case (in which case, you'd need to force it with a cmdline), but at least you wouldn't loose much memory just because one of your VMs may use PCI passthrough (so, you have it enabled in your kernel).
How early can we query xenstore? We'd need to do this before setting up DMA for any device.
Not that early. One supported configuration has xenstore not starting for an indefinite period of time after boot.
Quoted 3 lines
The alternative would be to finally merge swiotlb-xen into swiotlb, in which case we might be able to do this later. Let me see what I can do there.
If that is an option, it would be great to reduce the special-cashing.
~Andrew
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 5 lines · Andrew Cooper
Quoted 3 lines
The alternative would be to finally merge swiotlb-xen into swiotlb, in which case we might be able to do this later. Let me see what I can do there.
If that is an option, it would be great to reduce the special-cashing.
I think it's doable, and I've been wanting it for a while. I just need motivated testers, but it seems like I just found at least two :)
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Andrew Cooper
Quoted 3 lines
The alternative would be to finally merge swiotlb-xen into swiotlb, in which case we might be able to do this later. Let me see what I can do there.
If that is an option, it would be great to reduce the special-cashing.
I think it's doable, and I've been wanting it for a while. I just need motivated testers, but it seems like I just found at least two :)
So looking at swiotlb-xen it does these off things where it takes a value generated originally be xen_phys_to_dma, then only does a dma_to_phys to go back and call pfn_valid on the result. Does this make sense, or is it wrong and just works by accident? I.e. is the patch below correct?
drivers/xen/swiotlb-xen.c +5 -7
@@ -90,9 +90,7 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)static int is_xen_swiotlb_buffer (struct device *dev,dma_addr_t dma_addr) { -unsigned long bfn =XEN_PFN_DOWN (dma_to_phys (dev, dma_addr)); -unsigned long xen_pfn =bfn_to_local_pfn (bfn); -phys_addr_t paddr = (phys_addr_t )xen_pfn <<XEN_PAGE_SHIFT ; +phys_addr_t paddr =xen_dma_to_phys (dev, dma_addr);/* If the address is outside our domain, it CAN * have the same virtual address as another address
@@ -234,7 +232,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, done:if (!dev_is_dma_coherent (dev) && !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) { -if (pfn_valid (PFN_DOWN (dma_to_phys (dev, dev_addr)))) +if (pfn_valid (PFN_DOWN (phys)))arch_sync_dma_for_device (phys, size, dir);else xen_dma_sync_for_device (dev, dev_addr, size, dir);
@@ -258,7 +256,7 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,BUG_ON (dir ==DMA_NONE );if (!dev_is_dma_coherent (hwdev) && !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) { -if (pfn_valid (PFN_DOWN (dma_to_phys (hwdev, dev_addr)))) +if (pfn_valid (PFN_DOWN (paddr)))arch_sync_dma_for_cpu (paddr, size, dir);else xen_dma_sync_for_cpu (hwdev, dev_addr, size, dir);
@@ -276,7 +274,7 @@ xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr,phys_addr_t paddr =xen_dma_to_phys (dev, dma_addr);if (!dev_is_dma_coherent (dev)) { -if (pfn_valid (PFN_DOWN (dma_to_phys (dev, dma_addr)))) +if (pfn_valid (PFN_DOWN (paddr)))arch_sync_dma_for_cpu (paddr, size, dir);else xen_dma_sync_for_cpu (dev, dma_addr, size, dir);
@@ -296,7 +294,7 @@ xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr,swiotlb_sync_single_for_device (dev, paddr, size, dir);if (!dev_is_dma_coherent (dev)) { -if (pfn_valid (PFN_DOWN (dma_to_phys (dev, dma_addr)))) +if (pfn_valid (PFN_DOWN (paddr)))arch_sync_dma_for_device (paddr, size, dir);else xen_dma_sync_for_device (dev, dma_addr, size, dir);
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Hi Christoph,
Quoted 22 lines · On Sat, 20 May 2023 08:21:03 +0200 Christoph Hellwig <[email protected]> wrote:
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Andrew Cooper
Quoted 3 lines
The alternative would be to finally merge swiotlb-xen into swiotlb, in which case we might be able to do this later. Let me see what I can do there.
If that is an option, it would be great to reduce the special-cashing.
I think it's doable, and I've been wanting it for a while. I just need motivated testers, but it seems like I just found at least two :)
So looking at swiotlb-xen it does these off things where it takes a value generated originally be
xen_phys_to_dma, then only does adma_to_physto go back and callpfn_validon the result. Does this make sense, or is it wrong and just works by accident? I.e. is the patch below correct?drivers/xen/swiotlb-xen.c +0
-0
drivers/xen/swiotlb-xen.c static inline int range_straddles_page_boundary(phys_addr_t p, size_t size) · line 93
Quoted 7 lines
drivers/xen/swiotlb-xen.c +1
-3@@ -90,9 +90,7 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)static int is_xen_swiotlb_buffer (struct device *dev,dma_addr_t dma_addr) { -unsigned long bfn =XEN_PFN_DOWN (dma_to_phys (dev, dma_addr)); -unsigned long xen_pfn =bfn_to_local_pfn (bfn); -phys_addr_t paddr = (phys_addr_t )xen_pfn <<XEN_PAGE_SHIFT ; +phys_addr_t paddr =xen_dma_to_phys (dev, dma_addr);
I'm no big Xen expert, but I think this is wrong. Let's go through it line by line:
- bfn = XEN_PFN_DOWN(dma_to_phys(dev, dma_addr));
Take the DMA address (as seen by devices on the bus), convert it to a physical address (as seen by the CPU on the bus) and shift it right by XEN_PAGE_SHIFT. The result is a Xen machine PFN.
- xen_pfn = bfn_to_local_pfn(bfn);
Take the machine PFN and converts it to a physical PFN.
- paddr = (phys_addr_t)xen_pfn << XEN_PAGE_SHIFT;
Convert the physical PFN to a physical address.
The important thing here is that Xen PV does not have auto-translated physical addresses, so physical address != machine address. Physical addresses in Xen PV domains are "artificial", used by the kernel to index the mem_map array, so a PFN can be easily converted to a struct page pointer and back. However, these addresses are never used by hardware, not even by CPU. The addresses used by the CPU are called machine addresses. There is no address translation between VCPUs and CPUs, because a PV domain runs directly on the CPU. After all, that's why it is called _para_virtualized.
HTH
Petr T
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
In reply to Marek Marczykowski-GóreckiQuoted 12 lines · On Fri, 19 May 2023 12:10:26 +0200 Marek Marczykowski-Górecki…
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Marek Marczykowski-Górecki
Quoted 5 lines · Christoph Hellwig
Remove the dangerous late initialization of xen-swiotlb in
pci_xen_swiotlb_init_lateand instead just always initialize xen-swiotlb in the boot code ifCONFIG_XEN_PCIDEV_FRONTENDis enabled.Signed-off-by Christoph Hellwig <[email protected]>Doesn't it mean all the PV guests will basically waste 64MB of RAM by default each if they don't really have PCI devices?
Quoted 6 lines
Quoted 2 lines
If
CONFIG_XEN_PCIDEV_FRONTENDis enabled, and the kernel's isn't booted with swiotlb=noforce, yes.That's "a bit" unfortunate, since that might be significant part of the VM memory, or if you have a lot of VMs, a significant part of the host memory - it quickly adds up.
I wonder if dynamic swiotlb allocation might also help with this...
Petr T
Juergen Gross
maintainerRe: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
In reply to Marek Marczykowski-GóreckiQuoted 15 lines · Marek Marczykowski-Górecki
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Marek Marczykowski-Górecki
Quoted 4 lines · Christoph Hellwig
Remove the dangerous late initialization of xen-swiotlb in
pci_xen_swiotlb_init_lateand instead just always initialize xen-swiotlb in the boot code ifCONFIG_XEN_PCIDEV_FRONTENDis enabled.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>Doesn't it mean all the PV guests will basically waste 64MB of RAM by default each if they don't really have PCI devices?
If
CONFIG_XEN_PCIDEV_FRONTENDis enabled, and the kernel's isn't booted with swiotlb=noforce, yes.
Quoted 15 lines
That's "a bit" unfortunate, since that might be significant part of the VM memory, or if you have a lot of VMs, a significant part of the host memory - it quickly adds up.
While I would say PCI passthrough is not very common for PV guests, can the decision about xen-swiotlb be delayed until you can enumerate xenstore to check if there are any PCI devices connected (and not allocate xen-swiotlb by default if there are none)? This would still not cover the hotplug case (in which case, you'd need to force it with a cmdline), but at least you wouldn't loose much memory just because one of your VMs may use PCI passthrough (so, you have it enabled in your kernel).
Please remember that guest kernel is not always under full control of the host admin, so making guests loose 64MB of RAM always, in default setup isn't good for customers of such VMs...
In normal cases PCI passthrough in PV guests requires to start the guest with e820_host=1. So it should be rather easy to limit allocating the 64MB in PV guests to the cases where the memory map has non-RAM regions especially in the first 1MB of the memory.
This will cover even hotplug cases. The only case not covered would be a guest started with e820_host=1 even if no PCI passthrough was planned. But this should be rather rare (at least I hope so).
Juergen
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 8 lines · Juergen Gross
In normal cases PCI passthrough in PV guests requires to start the guest with e820_host=1. So it should be rather easy to limit allocating the 64MB in PV guests to the cases where the memory map has non-RAM regions especially in the first 1MB of the memory.
This will cover even hotplug cases. The only case not covered would be a guest started with e820_host=1 even if no PCI passthrough was planned. But this should be rather rare (at least I hope so).
So is this an ACK for the patch and can we go ahead with it?
(I'd still like to merge swiotlb-xen into swiotlb eventually, but it's probably not going to happen this merge window)
Juergen Gross
maintainerRe: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 11 lines · Christoph Hellwig
Quoted 8 lines · Juergen Gross
In normal cases PCI passthrough in PV guests requires to start the guest with e820_host=1. So it should be rather easy to limit allocating the 64MB in PV guests to the cases where the memory map has non-RAM regions especially in the first 1MB of the memory.
This will cover even hotplug cases. The only case not covered would be a guest started with e820_host=1 even if no PCI passthrough was planned. But this should be rather rare (at least I hope so).
So is this an ACK for the patch and can we go ahead with it?
As long as above mentioned check of the E820 map is done, yes.
If you want I can send a diff to be folded into your patch on Monday.
Quoted 3 lines
(I'd still like to merge swiotlb-xen into swiotlb eventually, but it's probably not going to happen this merge window)
Would be nice.
Juergen
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Quoted 8 lines · Juergen Gross
Quoted 4 lines
Quoted 2 lines
guest started with e820_host=1 even if no PCI passthrough was planned. But this should be rather rare (at least I hope so).
So is this an ACK for the patch and can we go ahead with it?
As long as above mentioned check of the E820 map is done, yes.
If you want I can send a diff to be folded into your patch on Monday.
Yes, that would be great!
Juergen Gross
maintainerRe: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
In reply to Juergen GrossQuoted 11 lines · Juergen Gross
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Juergen Gross
In normal cases PCI passthrough in PV guests requires to start the guest with e820_host=1. So it should be rather easy to limit allocating the 64MB in PV guests to the cases where the memory map has non-RAM regions especially in the first 1MB of the memory.
This will cover even hotplug cases. The only case not covered would be a guest started with e820_host=1 even if no PCI passthrough was planned. But this should be rather rare (at least I hope so).
Quoted 5 lines
Quoted 1 line
So is this an ACK for the patch and can we go ahead with it?
As long as above mentioned check of the E820 map is done, yes.
If you want I can send a diff to be folded into your patch on Monday.
Attached is a patch for adding a new flag xen_pv_pci_possible. You can either add the patch to your series or merge it into your patch 2.
You need to modify your patch like this:
@@ -111,7 +90,10 @@ static inline void __init pci_xen_swiotlb_init(void)
void __init pci_iommu_alloc(void)
{
if (xen_pv_domain()) {
- if (xen_initial_domain() || x86_swiotlb_enable) + if (xen_initial_domain() ||
+ (IS_ENABLED(CONFIG_XEN_PCIDEV_FRONTEND) &&
+ xen_pv_pci_possible) ||
+ x86_swiotlb_enable)
pci_xen_swiotlb_init();
return;
}
Juergen
From 7e84a88243b57bc90d1ef6bd42661f499886e659 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 12 Jun 2023 09:57:18 +0200
Subject: [PATCH] xen/pci: add flag for PCI passthrough being possible
When running as a Xen PV guests passed through PCI devices only have a chance to work if the Xen supplied memory map has some PCI space reserved.
Add a flag xen_pv_pci_possible which will be set in early boot in case the memory map has at least one area with the type E820_TYPE_RESERVED.
--- arch/x86/xen/setup.c | 6 ++++++ include/xen/xen.h | 6 ++++++ 2 files changed, 12 insertions(+)
arch/x86/xen/setup.c +6 -0
@@ -43,6 +43,9 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;/* Number of pages released from the initial allocation. */ unsigned long xen_released_pages; +/* Memory map would allow PCI passthrough. */ +bool xen_pv_pci_possible; +/* E820 map used during setting up memory. */ static struct e820_table xen_e820_table__initdata ;
@@ -804,6 +807,9 @@ char * __init xen_memory_setup(void) chunk_size = size; type = xen_e820_table.entries[i].type; +if (type ==E820_TYPE_RESERVED ) + xen_pv_pci_possible = true; +if (type ==E820_TYPE_RAM ) {if (addr < mem_end) { chunk_size =min (size, mem_end - addr);
include/xen/xen.h +6 -0
@@ -29,6 +29,12 @@ extern bool xen_pvh;extern uint32_t xen_start_flags; +#ifdef CONFIG_XEN_PV +extern bool xen_pv_pci_possible; +#else +#define xen_pv_pci_possible 0 +#endif +#include <xen/interface/hvm/start_info.h> extern struct hvm_start_info pvh_start_info;
Signature · 1 line
2.35.3
Re: [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Thank you. I'll queue it up as a separate patch.
PATCH 3/4 drm/nouveau: stop using is_swiotlb_active
In reply to Christoph HellwigDrivers have no business looking into dma-mapping internals and check what backend is used. Unfortunstely the DRM core is still broken and tries to do plain page allocations instead of using DMA API allocators by default and uses various bandaids on when to use dma_alloc_coherent.
Switch nouveau to use the same (broken) scheme as amdgpu and radeon to remove the last driver user of is_swiotlb_active.
--- drivers/gpu/drm/nouveau/nouveau_ttm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/nouveau_ttm.c +3 -7
@@ -24,9 +24,9 @@*/ #include <linux/limits.h> -#include <linux/swiotlb.h> #include <drm/ttm/ttm_range_manager.h> +#include <drm/drm_cache.h> #include "nouveau_drv.h" #include "nouveau_gem.h"
@@ -265,7 +265,6 @@ nouveau_ttm_init(struct nouveau_drm *drm)struct nvkm_pci *pci = device->pci;struct nvif_mmu *mmu = &drm->client.mmu;struct drm_device *dev = drm->dev; -bool need_swiotlb = false;int typei, ret; ret =nouveau_ttm_init_host (drm,0 );
@@ -300,13 +299,10 @@ nouveau_ttm_init(struct nouveau_drm *drm) drm->agp.cma = pci->agp.cma; } -#if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 ) - need_swiotlb =is_swiotlb_active (dev->dev); -#endif - ret =ttm_device_init (&drm->ttm.bdev, &nouveau_bo_driver, drm->dev->dev, dev->anon_inode->i_mapping, - dev->vma_offset_manager, need_swiotlb, + dev->vma_offset_manager, +drm_need_swiotlb (drm->client.mmu.dmabits), drm->client.mmu.dmabits <=32 );if (ret) {NV_ERROR (drm,"error initialising bo driver, %d\n" , ret);
Signature · 1 line
2.39.2
Re: [PATCH 3/4] drm/nouveau: stop using is_swiotlb_active
Thanks for getting to this!
Quoted 52 lines · Christoph Hellwig
Drivers have no business looking into dma-mapping internals and check what backend is used. Unfortunstely the DRM core is still broken and tries to do plain page allocations instead of using DMA API allocators by default and uses various bandaids on when to use
dma_alloc_coherent.Switch nouveau to use the same (broken) scheme as amdgpu and radeon to remove the last driver user of
is_swiotlb_active.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_ttm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/gpu/drm/nouveau/nouveau_ttm.c +3
-7@@ -24,9 +24,9 @@*/ #include <linux/limits.h> -#include <linux/swiotlb.h> #include <drm/ttm/ttm_range_manager.h> +#include <drm/drm_cache.h> #include "nouveau_drv.h" #include "nouveau_gem.h" @@ -265,7 +265,6 @@ nouveau_ttm_init(struct nouveau_drm *drm)struct nvkm_pci *pci = device->pci;struct nvif_mmu *mmu = &drm->client.mmu;struct drm_device *dev = drm->dev; -bool need_swiotlb = false;int typei, ret; ret =nouveau_ttm_init_host (drm,0 );@@ -300,13 +299,10 @@ nouveau_ttm_init(struct nouveau_drm *drm) drm->agp.cma = pci->agp.cma; } -#if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 ) - need_swiotlb =is_swiotlb_active (dev->dev); -#endif - ret =ttm_device_init (&drm->ttm.bdev, &nouveau_bo_driver, drm->dev->dev, dev->anon_inode->i_mapping, - dev->vma_offset_manager, need_swiotlb, + dev->vma_offset_manager, +drm_need_swiotlb (drm->client.mmu.dmabits), drm->client.mmu.dmabits <=32 );if (ret) {NV_ERROR (drm,"error initialising bo driver, %d\n" , ret);
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat
Re: [PATCH 3/4] drm/nouveau: stop using is_swiotlb_active
Quoted 3 lines · Lyude Paul
Reviewed-by Lyude Paul <[email protected]>Thanks for getting to this!
I've tentantively queued this up in the dma-mapping for-next tree. Let me know if you'd prefer it to go through the nouveau tree.
PATCH 4/4 swiotlb: unexport is_swiotlb_active
In reply to Christoph HellwigDrivers have no business looking at dma-mapping or swiotlb internals.
--- kernel/dma/swiotlb.c | 1 - 1 file changed, 1 deletion(-)
kernel/dma/swiotlb.c +0 -1
@@ -921,7 +921,6 @@ bool is_swiotlb_active(struct device *dev)return mem && mem->nslabs; } -EXPORT_SYMBOL_GPL (is_swiotlb_active);#ifdef CONFIG_DEBUG_FS
Signature · 1 line
2.39.2