All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-01-26 16:10 ` Tianyu Lan
  0 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

Hyper-V Isolation VM may fail to allocate swiotlb bounce buffer due
to there is no enough contiguous memory from 0 to 4G in some cases.
Current swiotlb code allocate bounce buffer in the low end memory.
This patchset adds a switch "swiotlb_alloc_from_low_pages" and it's
set to true by default. Platform may clear it if necessary. Devices
in Hyper-V Isolation VM may use memory above 4G as DMA memory and set
the switch to false in order to avoid no enough contiguous memory in
low end address space.

Tianyu Lan (2):
  Swiotlb: Add swiotlb_alloc_from_low_pages switch
  x86/hyperv: Set swiotlb_alloc_from_low_pages to false

 arch/x86/kernel/cpu/mshyperv.c |  1 +
 include/linux/swiotlb.h        |  1 +
 kernel/dma/swiotlb.c           | 13 +++++++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

-- 
2.25.1


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

* [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-01-26 16:10 ` Tianyu Lan
  0 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: parri.andrea, thomas.lendacky, linux-hyperv, Tianyu Lan,
	konrad.wilk, linux-kernel, iommu, brijesh.singh, vkuznets, hch

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

Hyper-V Isolation VM may fail to allocate swiotlb bounce buffer due
to there is no enough contiguous memory from 0 to 4G in some cases.
Current swiotlb code allocate bounce buffer in the low end memory.
This patchset adds a switch "swiotlb_alloc_from_low_pages" and it's
set to true by default. Platform may clear it if necessary. Devices
in Hyper-V Isolation VM may use memory above 4G as DMA memory and set
the switch to false in order to avoid no enough contiguous memory in
low end address space.

Tianyu Lan (2):
  Swiotlb: Add swiotlb_alloc_from_low_pages switch
  x86/hyperv: Set swiotlb_alloc_from_low_pages to false

 arch/x86/kernel/cpu/mshyperv.c |  1 +
 include/linux/swiotlb.h        |  1 +
 kernel/dma/swiotlb.c           | 13 +++++++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 1/2] Swiotlb: Add swiotlb_alloc_from_low_pages switch
  2022-01-26 16:10 ` Tianyu Lan
@ 2022-01-26 16:10   ` Tianyu Lan
  -1 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

Hyper-V Isolation VM and AMD SEV VM uses swiotlb bounce buffer to
share memory with hypervisor. Current swiotlb bounce buffer is only
allocated from 0 to ARCH_LOW_ADDRESS_LIMIT which is default to
0xffffffffUL. Isolation VM and AMD SEV VM needs 1G bounce buffer at most.
This will fail when there is not enough contiguous memory from 0 to 4G
address space and devices also may use memory above 4G address space as
DMA memory. Expose swiotlb_alloc_from_low_pages and platform mey set it
to false when it's not necessary to limit bounce buffer from 0 to 4G memory.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 include/linux/swiotlb.h |  1 +
 kernel/dma/swiotlb.c    | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d5..55c178e8eee0 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -191,5 +191,6 @@ static inline bool is_swiotlb_for_alloc(struct device *dev)
 #endif /* CONFIG_DMA_RESTRICTED_POOL */
 
 extern phys_addr_t swiotlb_unencrypted_base;
+extern bool swiotlb_alloc_from_low_pages;
 
 #endif /* __LINUX_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f1e7ea160b43..159fef80f3db 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -73,6 +73,12 @@ enum swiotlb_force swiotlb_force;
 
 struct io_tlb_mem io_tlb_default_mem;
 
+/*
+ * Get IO TLB memory from the low pages if swiotlb_alloc_from_low_pages
+ * is set.
+ */
+bool swiotlb_alloc_from_low_pages = true;
+
 phys_addr_t swiotlb_unencrypted_base;
 
 /*
@@ -284,8 +290,11 @@ swiotlb_init(int verbose)
 	if (swiotlb_force == SWIOTLB_NO_FORCE)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	if (swiotlb_alloc_from_low_pages)
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
-- 
2.25.1


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

* [PATCH 1/2] Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-01-26 16:10   ` Tianyu Lan
  0 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: parri.andrea, thomas.lendacky, linux-hyperv, Tianyu Lan,
	konrad.wilk, linux-kernel, iommu, brijesh.singh, vkuznets, hch

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

Hyper-V Isolation VM and AMD SEV VM uses swiotlb bounce buffer to
share memory with hypervisor. Current swiotlb bounce buffer is only
allocated from 0 to ARCH_LOW_ADDRESS_LIMIT which is default to
0xffffffffUL. Isolation VM and AMD SEV VM needs 1G bounce buffer at most.
This will fail when there is not enough contiguous memory from 0 to 4G
address space and devices also may use memory above 4G address space as
DMA memory. Expose swiotlb_alloc_from_low_pages and platform mey set it
to false when it's not necessary to limit bounce buffer from 0 to 4G memory.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 include/linux/swiotlb.h |  1 +
 kernel/dma/swiotlb.c    | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d5..55c178e8eee0 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -191,5 +191,6 @@ static inline bool is_swiotlb_for_alloc(struct device *dev)
 #endif /* CONFIG_DMA_RESTRICTED_POOL */
 
 extern phys_addr_t swiotlb_unencrypted_base;
+extern bool swiotlb_alloc_from_low_pages;
 
 #endif /* __LINUX_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f1e7ea160b43..159fef80f3db 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -73,6 +73,12 @@ enum swiotlb_force swiotlb_force;
 
 struct io_tlb_mem io_tlb_default_mem;
 
+/*
+ * Get IO TLB memory from the low pages if swiotlb_alloc_from_low_pages
+ * is set.
+ */
+bool swiotlb_alloc_from_low_pages = true;
+
 phys_addr_t swiotlb_unencrypted_base;
 
 /*
@@ -284,8 +290,11 @@ swiotlb_init(int verbose)
 	if (swiotlb_force == SWIOTLB_NO_FORCE)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	if (swiotlb_alloc_from_low_pages)
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 2/2] x86/hyperv: Set swiotlb_alloc_from_low_pages to false
  2022-01-26 16:10 ` Tianyu Lan
@ 2022-01-26 16:10   ` Tianyu Lan
  -1 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

In Hyper-V Isolation VM, swiotlb bnounce buffer size maybe 1G at most
and there maybe no enough memory from 0 to 4G according to memory layout.
Devices in Isolation VM can use memory above 4G as DMA memory. Set swiotlb_
alloc_from_low_pages to false in Isolation VM.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 arch/x86/kernel/cpu/mshyperv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 5a99f993e639..80a0423ac75d 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -343,6 +343,7 @@ static void __init ms_hyperv_init_platform(void)
 		 * use swiotlb bounce buffer for dma transaction.
 		 */
 		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_alloc_from_low_pages = false;
 #endif
 	}
 
-- 
2.25.1


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

* [PATCH 2/2] x86/hyperv: Set swiotlb_alloc_from_low_pages to false
@ 2022-01-26 16:10   ` Tianyu Lan
  0 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-01-26 16:10 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley
  Cc: parri.andrea, thomas.lendacky, linux-hyperv, Tianyu Lan,
	konrad.wilk, linux-kernel, iommu, brijesh.singh, vkuznets, hch

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

In Hyper-V Isolation VM, swiotlb bnounce buffer size maybe 1G at most
and there maybe no enough memory from 0 to 4G according to memory layout.
Devices in Isolation VM can use memory above 4G as DMA memory. Set swiotlb_
alloc_from_low_pages to false in Isolation VM.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 arch/x86/kernel/cpu/mshyperv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 5a99f993e639..80a0423ac75d 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -343,6 +343,7 @@ static void __init ms_hyperv_init_platform(void)
 		 * use swiotlb bounce buffer for dma transaction.
 		 */
 		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_alloc_from_low_pages = false;
 #endif
 	}
 
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* RE: [PATCH 1/2] Swiotlb: Add swiotlb_alloc_from_low_pages switch
  2022-01-26 16:10   ` Tianyu Lan
@ 2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
  -1 siblings, 0 replies; 16+ messages in thread
From: Michael Kelley (LINUX) @ 2022-01-28 17:44 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, hch,
	m.szyprowski, robin.murphy
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

From: Tianyu Lan <ltykernel@gmail.com> Sent: Wednesday, January 26, 2022 8:11 AM
> 
> Hyper-V Isolation VM and AMD SEV VM uses swiotlb bounce buffer to
> share memory with hypervisor. Current swiotlb bounce buffer is only
> allocated from 0 to ARCH_LOW_ADDRESS_LIMIT which is default to
> 0xffffffffUL. Isolation VM and AMD SEV VM needs 1G bounce buffer at most.
> This will fail when there is not enough contiguous memory from 0 to 4G
> address space and devices also may use memory above 4G address space as
> DMA memory. Expose swiotlb_alloc_from_low_pages and platform mey set it
> to false when it's not necessary to limit bounce buffer from 0 to 4G memory.
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  include/linux/swiotlb.h |  1 +
>  kernel/dma/swiotlb.c    | 13 +++++++++++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index f6c3638255d5..55c178e8eee0 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -191,5 +191,6 @@ static inline bool is_swiotlb_for_alloc(struct device *dev)
>  #endif /* CONFIG_DMA_RESTRICTED_POOL */
> 
>  extern phys_addr_t swiotlb_unencrypted_base;
> +extern bool swiotlb_alloc_from_low_pages;
> 
>  #endif /* __LINUX_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index f1e7ea160b43..159fef80f3db 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -73,6 +73,12 @@ enum swiotlb_force swiotlb_force;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> +/*
> + * Get IO TLB memory from the low pages if swiotlb_alloc_from_low_pages
> + * is set.
> + */
> +bool swiotlb_alloc_from_low_pages = true;
> +
>  phys_addr_t swiotlb_unencrypted_base;
> 
>  /*
> @@ -284,8 +290,11 @@ swiotlb_init(int verbose)
>  	if (swiotlb_force == SWIOTLB_NO_FORCE)
>  		return;
> 
> -	/* Get IO TLB memory from the low pages */
> -	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
> +	if (swiotlb_alloc_from_low_pages)
> +		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
> +	else
> +		tlb = memblock_alloc(bytes, PAGE_SIZE);
> +
>  	if (!tlb)
>  		goto fail;
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> --
> 2.25.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


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

* RE: [PATCH 1/2] Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 16+ messages in thread
From: Michael Kelley (LINUX) via iommu @ 2022-01-28 17:44 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, hch,
	m.szyprowski, robin.murphy
  Cc: parri.andrea, thomas.lendacky, linux-hyperv, Tianyu Lan,
	konrad.wilk, linux-kernel, iommu, brijesh.singh, vkuznets, hch

From: Tianyu Lan <ltykernel@gmail.com> Sent: Wednesday, January 26, 2022 8:11 AM
> 
> Hyper-V Isolation VM and AMD SEV VM uses swiotlb bounce buffer to
> share memory with hypervisor. Current swiotlb bounce buffer is only
> allocated from 0 to ARCH_LOW_ADDRESS_LIMIT which is default to
> 0xffffffffUL. Isolation VM and AMD SEV VM needs 1G bounce buffer at most.
> This will fail when there is not enough contiguous memory from 0 to 4G
> address space and devices also may use memory above 4G address space as
> DMA memory. Expose swiotlb_alloc_from_low_pages and platform mey set it
> to false when it's not necessary to limit bounce buffer from 0 to 4G memory.
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  include/linux/swiotlb.h |  1 +
>  kernel/dma/swiotlb.c    | 13 +++++++++++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index f6c3638255d5..55c178e8eee0 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -191,5 +191,6 @@ static inline bool is_swiotlb_for_alloc(struct device *dev)
>  #endif /* CONFIG_DMA_RESTRICTED_POOL */
> 
>  extern phys_addr_t swiotlb_unencrypted_base;
> +extern bool swiotlb_alloc_from_low_pages;
> 
>  #endif /* __LINUX_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index f1e7ea160b43..159fef80f3db 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -73,6 +73,12 @@ enum swiotlb_force swiotlb_force;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> +/*
> + * Get IO TLB memory from the low pages if swiotlb_alloc_from_low_pages
> + * is set.
> + */
> +bool swiotlb_alloc_from_low_pages = true;
> +
>  phys_addr_t swiotlb_unencrypted_base;
> 
>  /*
> @@ -284,8 +290,11 @@ swiotlb_init(int verbose)
>  	if (swiotlb_force == SWIOTLB_NO_FORCE)
>  		return;
> 
> -	/* Get IO TLB memory from the low pages */
> -	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
> +	if (swiotlb_alloc_from_low_pages)
> +		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
> +	else
> +		tlb = memblock_alloc(bytes, PAGE_SIZE);
> +
>  	if (!tlb)
>  		goto fail;
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> --
> 2.25.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* RE: [PATCH 2/2] x86/hyperv: Set swiotlb_alloc_from_low_pages to false
  2022-01-26 16:10   ` Tianyu Lan
@ 2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
  -1 siblings, 0 replies; 16+ messages in thread
From: Michael Kelley (LINUX) @ 2022-01-28 17:44 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, hch,
	m.szyprowski, robin.murphy
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

From: Tianyu Lan <ltykernel@gmail.com> Sent: Wednesday, January 26, 2022 8:11 AM
> 
> In Hyper-V Isolation VM, swiotlb bnounce buffer size maybe 1G at most
> and there maybe no enough memory from 0 to 4G according to memory layout.
> Devices in Isolation VM can use memory above 4G as DMA memory. Set swiotlb_
> alloc_from_low_pages to false in Isolation VM.
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  arch/x86/kernel/cpu/mshyperv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 5a99f993e639..80a0423ac75d 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -343,6 +343,7 @@ static void __init ms_hyperv_init_platform(void)
>  		 * use swiotlb bounce buffer for dma transaction.
>  		 */
>  		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_alloc_from_low_pages = false;
>  #endif
>  	}
> 
> --
> 2.25.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


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

* RE: [PATCH 2/2] x86/hyperv: Set swiotlb_alloc_from_low_pages to false
@ 2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 16+ messages in thread
From: Michael Kelley (LINUX) via iommu @ 2022-01-28 17:44 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, hch,
	m.szyprowski, robin.murphy
  Cc: parri.andrea, thomas.lendacky, linux-hyperv, Tianyu Lan,
	konrad.wilk, linux-kernel, iommu, brijesh.singh, vkuznets, hch

From: Tianyu Lan <ltykernel@gmail.com> Sent: Wednesday, January 26, 2022 8:11 AM
> 
> In Hyper-V Isolation VM, swiotlb bnounce buffer size maybe 1G at most
> and there maybe no enough memory from 0 to 4G according to memory layout.
> Devices in Isolation VM can use memory above 4G as DMA memory. Set swiotlb_
> alloc_from_low_pages to false in Isolation VM.
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  arch/x86/kernel/cpu/mshyperv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 5a99f993e639..80a0423ac75d 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -343,6 +343,7 @@ static void __init ms_hyperv_init_platform(void)
>  		 * use swiotlb bounce buffer for dma transaction.
>  		 */
>  		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_alloc_from_low_pages = false;
>  #endif
>  	}
> 
> --
> 2.25.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
  2022-01-26 16:10 ` Tianyu Lan
@ 2022-02-02  8:12   ` Christoph Hellwig
  -1 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2022-02-02  8:12 UTC (permalink / raw)
  To: Tianyu Lan
  Cc: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, hch, m.szyprowski, robin.murphy,
	michael.h.kelley, Tianyu Lan, iommu, linux-hyperv, linux-kernel,
	vkuznets, brijesh.singh, konrad.wilk, hch, parri.andrea,
	thomas.lendacky

I think this interface is a little too hacky.  In the end all the
non-trusted hypervisor schemes (including the per-device swiotlb one)
can allocate the memory from everywhere and want for force use of
swiotlb.  I think we need some kind of proper interface for that instead
of setting all kinds of global variables.

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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-02-02  8:12   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2022-02-02  8:12 UTC (permalink / raw)
  To: Tianyu Lan
  Cc: linux-hyperv, brijesh.singh, dave.hansen, hpa, kys, hch, hch,
	wei.liu, sthemmin, x86, decui, michael.h.kelley, mingo,
	parri.andrea, thomas.lendacky, Tianyu Lan, konrad.wilk, haiyangz,
	bp, tglx, linux-kernel, iommu, vkuznets, robin.murphy

I think this interface is a little too hacky.  In the end all the
non-trusted hypervisor schemes (including the per-device swiotlb one)
can allocate the memory from everywhere and want for force use of
swiotlb.  I think we need some kind of proper interface for that instead
of setting all kinds of global variables.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
  2022-02-02  8:12   ` Christoph Hellwig
@ 2022-02-02 13:22     ` Robin Murphy
  -1 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2022-02-02 13:22 UTC (permalink / raw)
  To: Christoph Hellwig, Tianyu Lan
  Cc: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, m.szyprowski, michael.h.kelley,
	Tianyu Lan, iommu, linux-hyperv, linux-kernel, vkuznets,
	brijesh.singh, konrad.wilk, hch, parri.andrea, thomas.lendacky

On 2022-02-02 08:12, Christoph Hellwig wrote:
> I think this interface is a little too hacky.  In the end all the
> non-trusted hypervisor schemes (including the per-device swiotlb one)
> can allocate the memory from everywhere and want for force use of
> swiotlb.  I think we need some kind of proper interface for that instead
> of setting all kinds of global variables.

Right, if platform/hypervisor code knows enough to be able to set magic 
non-standard allocation flags correctly, surely it could equally just 
perform whatever non-standard allocation it needs and call 
swiotlb_init_with_tbl() instead of swiotlb_init().

Robin.

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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-02-02 13:22     ` Robin Murphy
  0 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2022-02-02 13:22 UTC (permalink / raw)
  To: Christoph Hellwig, Tianyu Lan
  Cc: linux-hyperv, brijesh.singh, dave.hansen, hpa, kys, hch, wei.liu,
	sthemmin, x86, decui, michael.h.kelley, mingo, parri.andrea,
	thomas.lendacky, Tianyu Lan, konrad.wilk, haiyangz, bp, tglx,
	linux-kernel, iommu, vkuznets

On 2022-02-02 08:12, Christoph Hellwig wrote:
> I think this interface is a little too hacky.  In the end all the
> non-trusted hypervisor schemes (including the per-device swiotlb one)
> can allocate the memory from everywhere and want for force use of
> swiotlb.  I think we need some kind of proper interface for that instead
> of setting all kinds of global variables.

Right, if platform/hypervisor code knows enough to be able to set magic 
non-standard allocation flags correctly, surely it could equally just 
perform whatever non-standard allocation it needs and call 
swiotlb_init_with_tbl() instead of swiotlb_init().

Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
  2022-02-02  8:12   ` Christoph Hellwig
@ 2022-02-02 14:36     ` Tianyu Lan
  -1 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-02-02 14:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, m.szyprowski, robin.murphy,
	michael.h.kelley, Tianyu Lan, iommu, linux-hyperv, linux-kernel,
	vkuznets, brijesh.singh, konrad.wilk, hch, parri.andrea,
	thomas.lendacky

On 2/2/2022 4:12 PM, Christoph Hellwig wrote:
> I think this interface is a little too hacky.  In the end all the
> non-trusted hypervisor schemes (including the per-device swiotlb one)
> can allocate the memory from everywhere and want for force use of
> swiotlb.  I think we need some kind of proper interface for that instead
> of setting all kinds of global variables.

Hi Christoph:
      Thanks for your review. I draft the following patch to export a
interface swiotlb_set_alloc_from_low_pages(). Could you have a look
whether this looks good for you.

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d5..2b4f92668bc7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -39,6 +39,7 @@ enum swiotlb_force {
  extern void swiotlb_init(int verbose);
  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  unsigned long swiotlb_size_or_default(void);
+void swiotlb_set_alloc_from_low_pages(bool low);
  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  extern int swiotlb_late_init_with_default_size(size_t default_size);
  extern void __init swiotlb_update_mem_attributes(void);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f1e7ea160b43..62bf8b5cc3e4 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -73,6 +73,8 @@ enum swiotlb_force swiotlb_force;

  struct io_tlb_mem io_tlb_default_mem;

+static bool swiotlb_alloc_from_low_pages = true;
+
  phys_addr_t swiotlb_unencrypted_base;

  /*
@@ -116,6 +118,11 @@ void swiotlb_set_max_segment(unsigned int val)
                 max_segment = rounddown(val, PAGE_SIZE);
  }

+void swiotlb_set_alloc_from_low_pages(bool low)
+{
+       swiotlb_alloc_from_low_pages = low;
+}
+
  unsigned long swiotlb_size_or_default(void)
  {
         return default_nslabs << IO_TLB_SHIFT;
@@ -284,8 +291,15 @@ swiotlb_init(int verbose)
         if (swiotlb_force == SWIOTLB_NO_FORCE)
                 return;

-       /* Get IO TLB memory from the low pages */
-       tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       /*
+        * Get IO TLB memory from the low pages if 
swiotlb_alloc_from_low_pages
+        * is set.
+        */
+       if (swiotlb_alloc_from_low_pages)
+               tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       else
+               tlb = memblock_alloc(bytes, PAGE_SIZE);
+
         if (!tlb)
                 goto fail;
         if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))



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

* Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch
@ 2022-02-02 14:36     ` Tianyu Lan
  0 siblings, 0 replies; 16+ messages in thread
From: Tianyu Lan @ 2022-02-02 14:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, brijesh.singh, dave.hansen, hpa, kys, hch, wei.liu,
	sthemmin, x86, decui, michael.h.kelley, mingo, parri.andrea,
	thomas.lendacky, Tianyu Lan, konrad.wilk, haiyangz, bp, tglx,
	linux-kernel, iommu, vkuznets, robin.murphy

On 2/2/2022 4:12 PM, Christoph Hellwig wrote:
> I think this interface is a little too hacky.  In the end all the
> non-trusted hypervisor schemes (including the per-device swiotlb one)
> can allocate the memory from everywhere and want for force use of
> swiotlb.  I think we need some kind of proper interface for that instead
> of setting all kinds of global variables.

Hi Christoph:
      Thanks for your review. I draft the following patch to export a
interface swiotlb_set_alloc_from_low_pages(). Could you have a look
whether this looks good for you.

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d5..2b4f92668bc7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -39,6 +39,7 @@ enum swiotlb_force {
  extern void swiotlb_init(int verbose);
  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  unsigned long swiotlb_size_or_default(void);
+void swiotlb_set_alloc_from_low_pages(bool low);
  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  extern int swiotlb_late_init_with_default_size(size_t default_size);
  extern void __init swiotlb_update_mem_attributes(void);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f1e7ea160b43..62bf8b5cc3e4 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -73,6 +73,8 @@ enum swiotlb_force swiotlb_force;

  struct io_tlb_mem io_tlb_default_mem;

+static bool swiotlb_alloc_from_low_pages = true;
+
  phys_addr_t swiotlb_unencrypted_base;

  /*
@@ -116,6 +118,11 @@ void swiotlb_set_max_segment(unsigned int val)
                 max_segment = rounddown(val, PAGE_SIZE);
  }

+void swiotlb_set_alloc_from_low_pages(bool low)
+{
+       swiotlb_alloc_from_low_pages = low;
+}
+
  unsigned long swiotlb_size_or_default(void)
  {
         return default_nslabs << IO_TLB_SHIFT;
@@ -284,8 +291,15 @@ swiotlb_init(int verbose)
         if (swiotlb_force == SWIOTLB_NO_FORCE)
                 return;

-       /* Get IO TLB memory from the low pages */
-       tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       /*
+        * Get IO TLB memory from the low pages if 
swiotlb_alloc_from_low_pages
+        * is set.
+        */
+       if (swiotlb_alloc_from_low_pages)
+               tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       else
+               tlb = memblock_alloc(bytes, PAGE_SIZE);
+
         if (!tlb)
                 goto fail;
         if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))


_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2022-02-02 14:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 16:10 [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch Tianyu Lan
2022-01-26 16:10 ` Tianyu Lan
2022-01-26 16:10 ` [PATCH 1/2] Swiotlb: " Tianyu Lan
2022-01-26 16:10   ` Tianyu Lan
2022-01-28 17:44   ` Michael Kelley (LINUX)
2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
2022-01-26 16:10 ` [PATCH 2/2] x86/hyperv: Set swiotlb_alloc_from_low_pages to false Tianyu Lan
2022-01-26 16:10   ` Tianyu Lan
2022-01-28 17:44   ` Michael Kelley (LINUX)
2022-01-28 17:44     ` Michael Kelley (LINUX) via iommu
2022-02-02  8:12 ` [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages switch Christoph Hellwig
2022-02-02  8:12   ` Christoph Hellwig
2022-02-02 13:22   ` Robin Murphy
2022-02-02 13:22     ` Robin Murphy
2022-02-02 14:36   ` Tianyu Lan
2022-02-02 14:36     ` Tianyu Lan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.