* unexport swiotlb_active v2
@ 2023-06-12 14:25 Christoph Hellwig
2023-06-12 14:25 ` [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-12 14:25 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
Hi all,
this little series removes the last swiotlb API exposed to modules.
Changes since v1:
- add a patch from Juergen to export if the e820 table indicates Xen PV
PCI is enabled
- slightly reorganize the logic to check if swiotlb is needed for
Xen/x86
- drop the already merged nouveau patch
Diffstat:
arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------
arch/x86/kernel/pci-dma.c | 29 +++++++----------------------
arch/x86/xen/setup.c | 6 ++++++
drivers/pci/xen-pcifront.c | 6 ------
include/xen/xen.h | 6 ++++++
kernel/dma/swiotlb.c | 1 -
6 files changed, 19 insertions(+), 35 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible
2023-06-12 14:25 unexport swiotlb_active v2 Christoph Hellwig
@ 2023-06-12 14:25 ` Christoph Hellwig
2023-06-12 14:25 ` [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-12 14:25 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
From: Juergen Gross <jgross@suse.com>
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.
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/x86/xen/setup.c | 6 ++++++
include/xen/xen.h | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index c2be3efb2ba0fa..716f76c4141651 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -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);
diff --git a/include/xen/xen.h b/include/xen/xen.h
index 0efeb652f9b8fb..5eb0a974a11e7e 100644
--- a/include/xen/xen.h
+++ b/include/xen/xen.h
@@ -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;
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling
2023-06-12 14:25 unexport swiotlb_active v2 Christoph Hellwig
2023-06-12 14:25 ` [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible Christoph Hellwig
@ 2023-06-12 14:25 ` Christoph Hellwig
2023-06-27 7:19 ` Juergen Gross
2023-06-12 14:25 ` [PATCH 3/3] swiotlb: unexport is_swiotlb_active Christoph Hellwig
2023-06-19 9:19 ` unexport swiotlb_active v2 Christoph Hellwig
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-12 14:25 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
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 and Xen PV PCI is possible.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------
arch/x86/kernel/pci-dma.c | 29 +++++++-------------------
drivers/pci/xen-pcifront.c | 6 ------
3 files changed, 7 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 de6be0a3965ee4..f323d83e40a70b 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,9 +72,15 @@ static inline void __init pci_swiotlb_detect(void)
#endif /* CONFIG_SWIOTLB */
#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb_enabled(void)
+{
+ return xen_initial_domain() || x86_swiotlb_enable ||
+ (IS_ENABLED(CONFIG_XEN_PCIDEV_FRONTEND) && xen_pv_pci_possible);
+}
+
static void __init pci_xen_swiotlb_init(void)
{
- if (!xen_initial_domain() && !x86_swiotlb_enable)
+ if (!xen_swiotlb_enabled())
return;
x86_swiotlb_enable = true;
x86_swiotlb_flags |= SWIOTLB_ANY;
@@ -83,27 +89,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)
{
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] swiotlb: unexport is_swiotlb_active
2023-06-12 14:25 unexport swiotlb_active v2 Christoph Hellwig
2023-06-12 14:25 ` [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible Christoph Hellwig
2023-06-12 14:25 ` [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling Christoph Hellwig
@ 2023-06-12 14:25 ` Christoph Hellwig
2023-06-27 7:19 ` Juergen Gross
2023-06-19 9:19 ` unexport swiotlb_active v2 Christoph Hellwig
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-12 14:25 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
Drivers have no business looking at dma-mapping or swiotlb internals.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/swiotlb.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 775f7bb10ab184..1891faa3a6952e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -932,7 +932,6 @@ bool is_swiotlb_active(struct device *dev)
return mem && mem->nslabs;
}
-EXPORT_SYMBOL_GPL(is_swiotlb_active);
#ifdef CONFIG_DEBUG_FS
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: unexport swiotlb_active v2
2023-06-12 14:25 unexport swiotlb_active v2 Christoph Hellwig
` (2 preceding siblings ...)
2023-06-12 14:25 ` [PATCH 3/3] swiotlb: unexport is_swiotlb_active Christoph Hellwig
@ 2023-06-19 9:19 ` Christoph Hellwig
2023-06-27 17:18 ` Petr Tesařík
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-19 9:19 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
Any comments? I'd really like to finish this off this merge window..
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling
2023-06-12 14:25 ` [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling Christoph Hellwig
@ 2023-06-27 7:19 ` Juergen Gross
0 siblings, 0 replies; 8+ messages in thread
From: Juergen Gross @ 2023-06-27 7:19 UTC (permalink / raw)
To: Christoph Hellwig, Stefano Stabellini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
[-- Attachment #1.1.1: Type: text/plain, Size: 391 bytes --]
On 12.06.23 16:25, 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 and Xen PV PCI is possible.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] swiotlb: unexport is_swiotlb_active
2023-06-12 14:25 ` [PATCH 3/3] swiotlb: unexport is_swiotlb_active Christoph Hellwig
@ 2023-06-27 7:19 ` Juergen Gross
0 siblings, 0 replies; 8+ messages in thread
From: Juergen Gross @ 2023-06-27 7:19 UTC (permalink / raw)
To: Christoph Hellwig, Stefano Stabellini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: xen-devel, iommu, linux-kernel
[-- Attachment #1.1.1: Type: text/plain, Size: 234 bytes --]
On 12.06.23 16:25, Christoph Hellwig wrote:
> Drivers have no business looking at dma-mapping or swiotlb internals.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: unexport swiotlb_active v2
2023-06-19 9:19 ` unexport swiotlb_active v2 Christoph Hellwig
@ 2023-06-27 17:18 ` Petr Tesařík
0 siblings, 0 replies; 8+ messages in thread
From: Petr Tesařík @ 2023-06-27 17:18 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Juergen Gross, Stefano Stabellini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, xen-devel,
iommu, linux-kernel
On Mon, 19 Jun 2023 11:19:41 +0200
Christoph Hellwig <hch@lst.de> wrote:
> Any comments? I'd really like to finish this off this merge window..
Let me second this request. My dynamic SWIOTLB patch series also has a
dependence on this.
Petr T
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-06-27 17:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 14:25 unexport swiotlb_active v2 Christoph Hellwig
2023-06-12 14:25 ` [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible Christoph Hellwig
2023-06-12 14:25 ` [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling Christoph Hellwig
2023-06-27 7:19 ` Juergen Gross
2023-06-12 14:25 ` [PATCH 3/3] swiotlb: unexport is_swiotlb_active Christoph Hellwig
2023-06-27 7:19 ` Juergen Gross
2023-06-19 9:19 ` unexport swiotlb_active v2 Christoph Hellwig
2023-06-27 17:18 ` Petr Tesařík
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).