Christoph Hellwig
2023-May-18 13:42 UTC
[Nouveau] [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Remove 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. Signed-off-by: Christoph Hellwig <hch at lst.de> --- 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(-) diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h index 77a2d19cc9909e..abde0f44df57dc 100644 --- a/arch/x86/include/asm/xen/swiotlb-xen.h +++ b/arch/x86/include/asm/xen/swiotlb-xen.h @@ -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, diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index f887b08ac5ffe4..c4a7ead9eb674e 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -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; } diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 83c0ab50676dff..11636634ae512f 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -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; } -- 2.39.2
Marek Marczykowski-Górecki
2023-May-18 18:18 UTC
[Nouveau] [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
On Thu, May 18, 2023 at 03:42:51PM +0200, Christoph Hellwig wrote:> Remove 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. > > Signed-off-by: Christoph Hellwig <hch at lst.de>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?> --- > 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(-) > > diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h > index 77a2d19cc9909e..abde0f44df57dc 100644 > --- a/arch/x86/include/asm/xen/swiotlb-xen.h > +++ b/arch/x86/include/asm/xen/swiotlb-xen.h > @@ -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, > diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c > index f887b08ac5ffe4..c4a7ead9eb674e 100644 > --- a/arch/x86/kernel/pci-dma.c > +++ b/arch/x86/kernel/pci-dma.c > @@ -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; > } > diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c > index 83c0ab50676dff..11636634ae512f 100644 > --- a/drivers/pci/xen-pcifront.c > +++ b/drivers/pci/xen-pcifront.c > @@ -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; > } > > -- > 2.39.2 > >-- Best Regards, Marek Marczykowski-G?recki Invisible Things Lab -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: not available URL: <https://lists.freedesktop.org/archives/nouveau/attachments/20230518/99052899/attachment.sig>
Christoph Hellwig
2023-May-19 04:04 UTC
[Nouveau] [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
On Thu, May 18, 2023 at 08:18:39PM +0200, Marek Marczykowski-G?recki wrote:> On Thu, May 18, 2023 at 03:42:51PM +0200, Christoph Hellwig wrote: > > Remove 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. > > > > Signed-off-by: Christoph Hellwig <hch at lst.de> > > 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.
Maybe Matching Threads
- [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
- [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
- [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
- [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
- [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling