xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] swiotlb-xen init fixes
@ 2021-05-12 20:18 Stefano Stabellini
  2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Stefano Stabellini @ 2021-05-12 20:18 UTC (permalink / raw)
  To: xen-devel; +Cc: sstabellini, boris.ostrovsky, jgross, hch

Hi all,

This short patch series comes with a preparation patch and 2 unrelated
fixes to swiotlb-xen initialization.


Christoph Hellwig (1):
      arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required

Stefano Stabellini (2):
      xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h
      xen/swiotlb: check if the swiotlb has already been initialized

 arch/arm/xen/mm.c             | 20 +++++++-------------
 arch/arm64/mm/init.c          |  3 ++-
 drivers/xen/swiotlb-xen.c     |  5 +++++
 include/xen/arm/swiotlb-xen.h | 15 ++++++++++++++-
 4 files changed, 28 insertions(+), 15 deletions(-)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h
  2021-05-12 20:18 [PATCH v2 0/3] swiotlb-xen init fixes Stefano Stabellini
@ 2021-05-12 20:18 ` Stefano Stabellini
  2021-05-13  6:10   ` Christoph Hellwig
  2021-05-14  9:59   ` Juergen Gross
  2021-05-12 20:18 ` [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required Stefano Stabellini
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Stefano Stabellini @ 2021-05-12 20:18 UTC (permalink / raw)
  To: xen-devel; +Cc: sstabellini, boris.ostrovsky, jgross, hch, Stefano Stabellini

From: Stefano Stabellini <stefano.stabellini@xilinx.com>

Move xen_swiotlb_detect to a static inline function to make it available
to !CONFIG_XEN builds.

CC: boris.ostrovsky@oracle.com
CC: jgross@suse.com
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

---
Changes in v2:
- patch split
---
 arch/arm/xen/mm.c             | 12 ------------
 include/xen/arm/swiotlb-xen.h | 15 ++++++++++++++-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index f8f07469d259..223b1151fd7d 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -135,18 +135,6 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
 	return;
 }
 
-int xen_swiotlb_detect(void)
-{
-	if (!xen_domain())
-		return 0;
-	if (xen_feature(XENFEAT_direct_mapped))
-		return 1;
-	/* legacy case */
-	if (!xen_feature(XENFEAT_not_direct_mapped) && xen_initial_domain())
-		return 1;
-	return 0;
-}
-
 static int __init xen_mm_init(void)
 {
 	struct gnttab_cache_flush cflush;
diff --git a/include/xen/arm/swiotlb-xen.h b/include/xen/arm/swiotlb-xen.h
index 2994fe6031a0..33336ab58afc 100644
--- a/include/xen/arm/swiotlb-xen.h
+++ b/include/xen/arm/swiotlb-xen.h
@@ -2,6 +2,19 @@
 #ifndef _ASM_ARM_SWIOTLB_XEN_H
 #define _ASM_ARM_SWIOTLB_XEN_H
 
-extern int xen_swiotlb_detect(void);
+#include <xen/features.h>
+#include <xen/xen.h>
+
+static inline int xen_swiotlb_detect(void)
+{
+	if (!xen_domain())
+		return 0;
+	if (xen_feature(XENFEAT_direct_mapped))
+		return 1;
+	/* legacy case */
+	if (!xen_feature(XENFEAT_not_direct_mapped) && xen_initial_domain())
+		return 1;
+	return 0;
+}
 
 #endif /* _ASM_ARM_SWIOTLB_XEN_H */
-- 
2.17.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required
  2021-05-12 20:18 [PATCH v2 0/3] swiotlb-xen init fixes Stefano Stabellini
  2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
@ 2021-05-12 20:18 ` Stefano Stabellini
  2021-05-14 10:00   ` Juergen Gross
  2021-05-14 10:29   ` Catalin Marinas
  2021-05-12 20:18 ` [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized Stefano Stabellini
  2021-05-14 13:56 ` [PATCH v2 0/3] swiotlb-xen init fixes Juergen Gross
  3 siblings, 2 replies; 10+ messages in thread
From: Stefano Stabellini @ 2021-05-12 20:18 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, boris.ostrovsky, jgross, hch, catalin.marinas, will,
	linux-arm-kernel, Stefano Stabellini

From: Christoph Hellwig <hch@lst.de>

Although SWIOTLB_NO_FORCE is meant to allow later calls to swiotlb_init,
today dma_direct_map_page returns error if SWIOTLB_NO_FORCE.

For now, without a larger overhaul of SWIOTLB_NO_FORCE, the best we can
do is to avoid setting SWIOTLB_NO_FORCE in mem_init when we know that it
is going to be required later (e.g. Xen requires it).

CC: boris.ostrovsky@oracle.com
CC: jgross@suse.com
CC: catalin.marinas@arm.com
CC: will@kernel.org
CC: linux-arm-kernel@lists.infradead.org
Fixes: 2726bf3ff252 ("swiotlb: Make SWIOTLB_NO_FORCE perform no allocation")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

---
Changes in v2:
- patch split
---
 arch/arm64/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 16a2b2b1c54d..e55409caaee3 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -43,6 +43,7 @@
 #include <linux/sizes.h>
 #include <asm/tlb.h>
 #include <asm/alternative.h>
+#include <asm/xen/swiotlb-xen.h>
 
 /*
  * We need to be able to catch inadvertent references to memstart_addr
@@ -482,7 +483,7 @@ void __init mem_init(void)
 	if (swiotlb_force == SWIOTLB_FORCE ||
 	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
 		swiotlb_init(1);
-	else
+	else if (!xen_swiotlb_detect())
 		swiotlb_force = SWIOTLB_NO_FORCE;
 
 	set_max_mapnr(max_pfn - PHYS_PFN_OFFSET);
-- 
2.17.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized
  2021-05-12 20:18 [PATCH v2 0/3] swiotlb-xen init fixes Stefano Stabellini
  2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
  2021-05-12 20:18 ` [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required Stefano Stabellini
@ 2021-05-12 20:18 ` Stefano Stabellini
  2021-05-13  6:11   ` Christoph Hellwig
  2021-05-14 13:56 ` [PATCH v2 0/3] swiotlb-xen init fixes Juergen Gross
  3 siblings, 1 reply; 10+ messages in thread
From: Stefano Stabellini @ 2021-05-12 20:18 UTC (permalink / raw)
  To: xen-devel; +Cc: sstabellini, boris.ostrovsky, jgross, hch, Stefano Stabellini

From: Stefano Stabellini <stefano.stabellini@xilinx.com>

xen_swiotlb_init calls swiotlb_late_init_with_tbl, which fails with
-ENOMEM if the swiotlb has already been initialized.

Add an explicit check io_tlb_default_mem != NULL at the beginning of
xen_swiotlb_init. If the swiotlb is already initialized print a warning
and return -EEXIST.

On x86, the error propagates.

On ARM, we don't actually need a special swiotlb buffer (yet), any
buffer would do. So ignore the error and continue.

CC: boris.ostrovsky@oracle.com
CC: jgross@suse.com
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Boris Ostrovsky <boris.ostrvsky@oracle.com>
---
Changes in v2:
- use pr_warn
- add reviewed-by
---
 arch/arm/xen/mm.c         | 8 +++++++-
 drivers/xen/swiotlb-xen.c | 5 +++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 223b1151fd7d..a7e54a087b80 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -138,9 +138,15 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
 static int __init xen_mm_init(void)
 {
 	struct gnttab_cache_flush cflush;
+	int rc;
+
 	if (!xen_swiotlb_detect())
 		return 0;
-	xen_swiotlb_init();
+
+	rc = xen_swiotlb_init();
+	/* we can work with the default swiotlb */
+	if (rc < 0 && rc != -EEXIST)
+		return rc;
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 4c89afc0df62..24d11861ac7d 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,6 +164,11 @@ int __ref xen_swiotlb_init(void)
 	int rc = -ENOMEM;
 	char *start;
 
+	if (io_tlb_default_mem != NULL) {
+		pr_warn("swiotlb buffer already initialized\n");
+		return -EEXIST;
+	}
+
 retry:
 	m_ret = XEN_SWIOTLB_ENOMEM;
 	order = get_order(bytes);
-- 
2.17.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h
  2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
@ 2021-05-13  6:10   ` Christoph Hellwig
  2021-05-14  9:59   ` Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2021-05-13  6:10 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel, boris.ostrovsky, jgross, hch, Stefano Stabellini

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized
  2021-05-12 20:18 ` [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized Stefano Stabellini
@ 2021-05-13  6:11   ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2021-05-13  6:11 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel, boris.ostrovsky, jgross, hch, Stefano Stabellini

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h
  2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
  2021-05-13  6:10   ` Christoph Hellwig
@ 2021-05-14  9:59   ` Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2021-05-14  9:59 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel; +Cc: boris.ostrovsky, hch, Stefano Stabellini


[-- Attachment #1.1.1: Type: text/plain, Size: 403 bytes --]

On 12.05.21 22:18, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@xilinx.com>
> 
> Move xen_swiotlb_detect to a static inline function to make it available
> to !CONFIG_XEN builds.
> 
> CC: boris.ostrovsky@oracle.com
> CC: jgross@suse.com
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required
  2021-05-12 20:18 ` [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required Stefano Stabellini
@ 2021-05-14 10:00   ` Juergen Gross
  2021-05-14 10:29   ` Catalin Marinas
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2021-05-14 10:00 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: boris.ostrovsky, hch, catalin.marinas, will, linux-arm-kernel,
	Stefano Stabellini


[-- Attachment #1.1.1: Type: text/plain, Size: 860 bytes --]

On 12.05.21 22:18, Stefano Stabellini wrote:
> From: Christoph Hellwig <hch@lst.de>
> 
> Although SWIOTLB_NO_FORCE is meant to allow later calls to swiotlb_init,
> today dma_direct_map_page returns error if SWIOTLB_NO_FORCE.
> 
> For now, without a larger overhaul of SWIOTLB_NO_FORCE, the best we can
> do is to avoid setting SWIOTLB_NO_FORCE in mem_init when we know that it
> is going to be required later (e.g. Xen requires it).
> 
> CC: boris.ostrovsky@oracle.com
> CC: jgross@suse.com
> CC: catalin.marinas@arm.com
> CC: will@kernel.org
> CC: linux-arm-kernel@lists.infradead.org
> Fixes: 2726bf3ff252 ("swiotlb: Make SWIOTLB_NO_FORCE perform no allocation")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required
  2021-05-12 20:18 ` [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required Stefano Stabellini
  2021-05-14 10:00   ` Juergen Gross
@ 2021-05-14 10:29   ` Catalin Marinas
  1 sibling, 0 replies; 10+ messages in thread
From: Catalin Marinas @ 2021-05-14 10:29 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel, boris.ostrovsky, jgross, hch, will, linux-arm-kernel,
	Stefano Stabellini

On Wed, May 12, 2021 at 01:18:22PM -0700, Stefano Stabellini wrote:
> From: Christoph Hellwig <hch@lst.de>
> 
> Although SWIOTLB_NO_FORCE is meant to allow later calls to swiotlb_init,
> today dma_direct_map_page returns error if SWIOTLB_NO_FORCE.
> 
> For now, without a larger overhaul of SWIOTLB_NO_FORCE, the best we can
> do is to avoid setting SWIOTLB_NO_FORCE in mem_init when we know that it
> is going to be required later (e.g. Xen requires it).
> 
> CC: boris.ostrovsky@oracle.com
> CC: jgross@suse.com
> CC: catalin.marinas@arm.com
> CC: will@kernel.org
> CC: linux-arm-kernel@lists.infradead.org
> Fixes: 2726bf3ff252 ("swiotlb: Make SWIOTLB_NO_FORCE perform no allocation")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/3] swiotlb-xen init fixes
  2021-05-12 20:18 [PATCH v2 0/3] swiotlb-xen init fixes Stefano Stabellini
                   ` (2 preceding siblings ...)
  2021-05-12 20:18 ` [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized Stefano Stabellini
@ 2021-05-14 13:56 ` Juergen Gross
  3 siblings, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2021-05-14 13:56 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel; +Cc: boris.ostrovsky, hch


[-- Attachment #1.1.1: Type: text/plain, Size: 779 bytes --]

On 12.05.21 22:18, Stefano Stabellini wrote:
> Hi all,
> 
> This short patch series comes with a preparation patch and 2 unrelated
> fixes to swiotlb-xen initialization.
> 
> 
> Christoph Hellwig (1):
>        arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required
> 
> Stefano Stabellini (2):
>        xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h
>        xen/swiotlb: check if the swiotlb has already been initialized
> 
>   arch/arm/xen/mm.c             | 20 +++++++-------------
>   arch/arm64/mm/init.c          |  3 ++-
>   drivers/xen/swiotlb-xen.c     |  5 +++++
>   include/xen/arm/swiotlb-xen.h | 15 ++++++++++++++-
>   4 files changed, 28 insertions(+), 15 deletions(-)
> 

Series pushed to xen/tip.git for-linus-5.13b


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-05-14 13:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 20:18 [PATCH v2 0/3] swiotlb-xen init fixes Stefano Stabellini
2021-05-12 20:18 ` [PATCH v2 1/3] xen/arm: move xen_swiotlb_detect to arm/swiotlb-xen.h Stefano Stabellini
2021-05-13  6:10   ` Christoph Hellwig
2021-05-14  9:59   ` Juergen Gross
2021-05-12 20:18 ` [PATCH v2 2/3] arm64: do not set SWIOTLB_NO_FORCE when swiotlb is required Stefano Stabellini
2021-05-14 10:00   ` Juergen Gross
2021-05-14 10:29   ` Catalin Marinas
2021-05-12 20:18 ` [PATCH v2 3/3] xen/swiotlb: check if the swiotlb has already been initialized Stefano Stabellini
2021-05-13  6:11   ` Christoph Hellwig
2021-05-14 13:56 ` [PATCH v2 0/3] swiotlb-xen init fixes Juergen Gross

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).