[Xen-devel] [PATCH v6] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-09 Thread Wang Xiaoming
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M now.
While in different platform and different requirement this seems improper.
So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE
to io_tlb_default_size which can configure by kernel cmdline.
This can meet different requirement.

Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
---
patch v1 make this change at Kconfig
which needs to edit the .config manually.
https://lkml.org/lkml/2015/1/25/571

patch v2 only change IO_TLB_SEGSIZE configurable.
https://lkml.org/lkml/2015/2/5/812

patch v3 parsing io_tlb_segsize and
io_tlb_default_size independently.
https://lkml.org/lkml/2015/2/15/217

patch v4 hasn't validated the data from
command line.
https://lkml.org/lkml/2015/2/17/114

patch v5 fix the postion of 'force'.
https://lkml.org/lkml/2015/3/3/84

 Documentation/kernel-parameters.txt  |5 +-
 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 +--
 include/linux/swiotlb.h  |8 +--
 lib/swiotlb.c|   99 ++
 6 files changed, 87 insertions(+), 35 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 4df73da..8463ef4 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3438,10 +3438,13 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
it if 0 is given (See Documentation/cgroups/memory.txt)
 
swiotlb=[ARM,IA-64,PPC,MIPS,X86]
-   Format: { int | force }
+   Format: { int,force,int,int}
int -- Number of I/O TLB slabs
force -- force using of bounce buffers even if they
 wouldn't be automatically used by the kernel
+   int -- Maximum allowable number of contiguous slabs 
to map
+   int -- The size of SW-MMU mapped.
+   Use ',' to seperate them.
 
switches=   [HW,M68k]
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c 
b/arch/mips/cavium-octeon/dma-octeon.c
index 3778655..a521af6 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
swiotlbsize = 64 * (120);
 #endif
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/arch/mips/netlogic/common/nlm-dma.c 
b/arch/mips/netlogic/common/nlm-dma.c
index f3d4ae8..eeffa8f 100644
--- a/arch/mips/netlogic/common/nlm-dma.c
+++ b/arch/mips/netlogic/common/nlm-dma.c
@@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
swiotlbsize = 1  20; /* 1 MB for now */
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad41..3b3e9fe 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long 
nslabs)
dma_addr_t dma_handle;
phys_addr_t p = virt_to_phys(buf);
 
-   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) + PAGE_SHIFT;
+   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
i = 0;
do {
-   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
do {
rc = xen_create_contiguous_region(
@@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
 {
if (!nr_tbl) {
xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
-   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
+   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
} else
xen_io_tlb_nslabs = nr_tbl;
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e7a018e..13506db 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -8,13 +8,7 @@ struct dma_attrs;
 struct scatterlist;
 
 extern int swiotlb_force;
-
-/*
- * Maximum allowable number of contiguous slabs to map

Re: [Xen-devel] [PATCH v5] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-08 Thread Wang, Xiaoming


 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Friday, March 6, 2015 11:20 PM
 To: Wang, Xiaoming
 Cc: Jan Beulich; l...@aserp2030.oracle.com; zh...@aserp2030.oracle.com;
 ch...@chris-wilson.co.uk; david.vra...@citrix.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; li...@horizon.com; Liu, Chuansheng; Zhang,
 Dongxing; takahiro.aka...@linaro.org; a...@linux-foundation.org; linux-
 m...@linux-mips.org; r...@linux-mips.org; xen-de...@lists.xenproject.org;
 boris.ostrov...@oracle.com; d.kasat...@samsung.com; pebo...@tiscali.nl;
 linux-ker...@vger.kernel.org; jkos...@suse.cz
 Subject: Re: [PATCH v5] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
 . snip..
 
  Format: { int,force,int,int} is suitable I think.
  And fixing  force is follow the code design previously in
 setup_io_tlb_npages.
 
 It is a bug. It should have been smart enough to deal with the 'force' being 
 in
 any order.
 
 If you are willing to make a patch to fix this - either folded into this 
 patch I
 am responding to or as a seperate one - that would be most excellent!
 
OK, I will try to make a patch to deal with the 'force'  in any order.
 However, I can also do it - but my plate is full so it will take me some time 
 to
 get to it.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-05 Thread Wang, Xiaoming
Dear Jan

 -Original Message-
 From: Jan Beulich [mailto:jbeul...@suse.com]
 Sent: Thursday, March 5, 2015 5:00 PM
 To: Wang, Xiaoming
 Cc: l...@aserp2030.oracle.com; zh...@aserp2030.oracle.com; chris@chris-
 wilson.co.uk; david.vra...@citrix.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; li...@horizon.com; Liu, Chuansheng; Zhang,
 Dongxing; takahiro.aka...@linaro.org; a...@linux-foundation.org; linux-
 m...@linux-mips.org; r...@linux-mips.org; xen-de...@lists.xenproject.org;
 boris.ostrov...@oracle.com; Konrad RzeszutekWilk;
 d.kasat...@samsung.com; pebo...@tiscali.nl; linux-ker...@vger.kernel.org
 Subject: RE: [PATCH v5] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
  On 05.03.15 at 09:52, xiaoming.w...@intel.com wrote:
  From: Jan Beulich [mailto:jbeul...@suse.com]
  Sent: Thursday, March 5, 2015 4:40 PM
   On 05.03.15 at 04:53, xiaoming.w...@intel.com wrote:
   From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
   Sent: Thursday, March 5, 2015 3:43 AM On Tue, Mar 03, 2015 at
   04:11:09PM +0800, Wang Xiaoming wrote:
@@ -101,13 +119,32 @@ setup_io_tlb_npages(char *str)  {
  if (isdigit(*str)) {
  io_tlb_nslabs = simple_strtoul(str, str, 0);
- /* avoid tail segment of size  IO_TLB_SEGSIZE */
- io_tlb_nslabs = ALIGN(io_tlb_nslabs,
 IO_TLB_SEGSIZE);
  }
  if (*str == ',')
  ++str;
- if (!strcmp(str, force))
+ if (!strncmp(str, force, 5)) {
  swiotlb_force = 1;
+ str += 5;
+ }
  
   So the format is now:
  
   Format: { int | force | int | int}
  
   which means I can do
   32,22323,force
  
   Or
   force,32
  
   Or
   32,force
  
   If I use Format: { int,force,int,int} 32,22323,force can't
   acceptable.
   There are three  int  here, if there are out of order, that will
   cause confuse.
   Only 32,force,32323
   Or   32,,32323,2322
   Or   ,,323222,3232
   Are available.
 
  You need to make sure that all previously valid variants are still
  usable,
  i.e.
  force alone, a number alone, force,number and number,force. How
  many variants you want to support with your additions is mostly up to
  you; I'd recommend permitting force in any position.
 
  I don't think it's suitable to accept that force in any position.
  If we defined Format: { int,force,int,int} force must be
  located in second position.
  And we add comment for each int also.
  Every position may be defined specifically.
 
 As said, with the old format allowing force in either first or second 
 position,
 you have to at least accept that in the new version too.
 Accepting force in any position would be a (desirable) courtesy to the user.
 
I have checked the code and do some test.

First | in Format  means *or*  in Documentation/kernel-parameters.txt
For example:
acpi=   [HW,ACPI,X86]
Advanced Configuration and Power Interface
Format: { force | off | strict | noirq | rsdt }

acpi_sci=   [HW,ACPI] ACPI System Control Interrupt trigger mode
Format: { level | edge | high | low }

Second the code in lib/swiotlb.c can't realize the function that
force in either first or second position with the Format
   swiotlb=[ARM,IA-64,PPC,MIPS,X86]
   Format: { int | force }
   int -- Number of I/O TLB slabs

I test with parameter
BOARD_KERNEL_CMDLINE += swiotlb=force,500
The result is io_tlb_nslabs=32768, swiotlb_force=0x0,
io_tlb_nslabs=32768 because that if io_tlb_nslabs can't get from 
early_param(swiotlb, setup_io_tlb_npages);
It will be valued at swiotlb_init with default.
So both  int  and force can't recognized with original code below.

static int __init
setup_io_tlb_npages(char *str)
{
if (isdigit(*str)) {
io_tlb_nslabs = simple_strtoul(str, str, 0);
/* avoid tail segment of size  IO_TLB_SEGSIZE */
io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
}
if (*str == ',')
++str;
if (!strcmp(str, force))
swiotlb_force = 1;

return 0;
}
early_param(swiotlb, setup_io_tlb_npages);

So we can't use Format: { int | force | int | int} any more
as there are four parameters.
Format: { int,force,int,int} is suitable I think.
And fixing  force is follow the code design previously in setup_io_tlb_npages.

 Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-05 Thread Wang, Xiaoming
Dear Jan

 -Original Message-
 From: Jan Beulich [mailto:jbeul...@suse.com]
 Sent: Thursday, March 5, 2015 4:40 PM
 To: Wang, Xiaoming
 Cc: l...@aserp2030.oracle.com; zh...@aserp2030.oracle.com; chris@chris-
 wilson.co.uk; david.vra...@citrix.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; li...@horizon.com; Liu, Chuansheng; Zhang,
 Dongxing; takahiro.aka...@linaro.org; a...@linux-foundation.org; linux-
 m...@linux-mips.org; r...@linux-mips.org; xen-de...@lists.xenproject.org;
 boris.ostrov...@oracle.com; Konrad Rzeszutek Wilk;
 d.kasat...@samsung.com; pebo...@tiscali.nl; linux-ker...@vger.kernel.org
 Subject: RE: [PATCH v5] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
  On 05.03.15 at 04:53, xiaoming.w...@intel.com wrote:
  From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
  Sent: Thursday, March 5, 2015 3:43 AM On Tue, Mar 03, 2015 at
  04:11:09PM +0800, Wang Xiaoming wrote:
   @@ -101,13 +119,32 @@ setup_io_tlb_npages(char *str)  {
if (isdigit(*str)) {
io_tlb_nslabs = simple_strtoul(str, str, 0);
   -/* avoid tail segment of size  IO_TLB_SEGSIZE */
   -io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
}
if (*str == ',')
++str;
   -if (!strcmp(str, force))
   +if (!strncmp(str, force, 5)) {
swiotlb_force = 1;
   +str += 5;
   +}
 
  So the format is now:
 
 Format: { int | force | int | int}
 
  which means I can do
 32,22323,force
 
  Or
 force,32
 
  Or
 32,force
 
  If I use Format: { int,force,int,int} 32,22323,force can't
  acceptable.
  There are three  int  here, if there are out of order, that will
  cause confuse.
  Only32,force,32323
  Or  32,,32323,2322
  Or  ,,323222,3232
  Are available.
 
 You need to make sure that all previously valid variants are still usable, 
 i.e.
 force alone, a number alone, force,number and number,force. How
 many variants you want to support with your additions is mostly up to you;
 I'd recommend permitting force in any position.
 
I don't think it's suitable to accept that force in any position.
If we defined Format: { int,force,int,int}
force must be located in second position. 
And we add comment for each int also.
Every position may be defined specifically.

 Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-04 Thread Wang, Xiaoming

 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Thursday, March 5, 2015 3:43 AM
 To: Wang, Xiaoming
 Cc: ch...@chris-wilson.co.uk; david.vra...@citrix.com;
 lau...@codeaurora.org; heiko.carst...@de.ibm.com; li...@horizon.com;
 l...@aserp2030.oracle.com; Liu, Chuansheng; zh...@aserp2030.oracle.com;
 Zhang, Dongxing; takahiro.aka...@linaro.org; a...@linux-foundation.org;
 linux-m...@linux-mips.org; r...@linux-mips.org; xen-
 de...@lists.xenproject.org; boris.ostrov...@oracle.com;
 d.kasat...@samsung.com; pebo...@tiscali.nl; linux-ker...@vger.kernel.org;
 jbeul...@suse.com
 Subject: Re: [PATCH v5] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
 On Tue, Mar 03, 2015 at 04:11:09PM +0800, Wang Xiaoming wrote:
  The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
  And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M now.
  While in different platform and different requirement this seems improper.
  So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and
  IO_TLB_DEFAULT_SIZE to io_tlb_default_size which can configure by
 kernel cmdline.
  This can meet different requirement.
 
  Signed-off-by: Chuansheng Liu chuansheng@intel.com
  Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
  Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
  ---
  patch v1 make this change at Kconfig
  which needs to edit the .config manually.
  https://lkml.org/lkml/2015/1/25/571
 
  patch v2 only change IO_TLB_SEGSIZE configurable.
  https://lkml.org/lkml/2015/2/5/812
 
  patch v3 parsing io_tlb_segsize and
  io_tlb_default_size independently.
  https://lkml.org/lkml/2015/2/15/217
 
  patch v4 hasn't validated the data from command line.
 
 Thank you for redoing this per review.
 
  https://lkml.org/lkml/2015/2/17/114
 
   Documentation/kernel-parameters.txt  |9 -
   arch/mips/cavium-octeon/dma-octeon.c |2 +-
   arch/mips/netlogic/common/nlm-dma.c  |2 +-
   drivers/xen/swiotlb-xen.c|6 +--
   include/linux/swiotlb.h  |8 +---
   lib/swiotlb.c|   68 
  +-
   6 files changed, 65 insertions(+), 30 deletions(-)
 
  diff --git a/Documentation/kernel-parameters.txt
  b/Documentation/kernel-parameters.txt
  index 4df73da..1f50e86 100644
  --- a/Documentation/kernel-parameters.txt
  +++ b/Documentation/kernel-parameters.txt
  @@ -3438,10 +3438,17 @@ bytes respectively. Such letter suffixes can
 also be entirely omitted.
  it if 0 is given (See
 Documentation/cgroups/memory.txt)
 
  swiotlb=[ARM,IA-64,PPC,MIPS,X86]
  -   Format: { int | force }
  +   Format: { int | force | int | int}
 ,
 
 s/|/,/
 
How about change the Format to 
Format: { int,force,int,int}
Force the parameter input  in consecutive order.
 
  int -- Number of I/O TLB slabs
  force -- force using of bounce buffers even if they
   wouldn't be automatically used by the kernel
  +   int -- Maximum allowable number of contiguous
 slabs to map
  +   int -- The size of SW-MMU mapped.
  +   Using , to separate them one by one.
 
 Use ',' to seperate them.
 
  +   Example:
  +   BOARD_KERNEL_CMDLINE +=
 swiotlb=32768,force,512,268435456
  +   io_tlb_nslabs=32768, swiotlb_force=1,
  +   io_tlb_segsize=512, io_tlb_default_size=268435456
 
 I think you can remove the example - and just have it in the C code.
 
 
  switches=   [HW,M68k]
 
  diff --git a/arch/mips/cavium-octeon/dma-octeon.c
  b/arch/mips/cavium-octeon/dma-octeon.c
  index 3778655..a521af6 100644
  --- a/arch/mips/cavium-octeon/dma-octeon.c
  +++ b/arch/mips/cavium-octeon/dma-octeon.c
  @@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
  swiotlbsize = 64 * (120);
   #endif
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff --git a/arch/mips/netlogic/common/nlm-dma.c
  b/arch/mips/netlogic/common/nlm-dma.c
  index f3d4ae8..eeffa8f 100644
  --- a/arch/mips/netlogic/common/nlm-dma.c
  +++ b/arch/mips/netlogic/common/nlm-dma.c
  @@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
  swiotlbsize = 1  20; /* 1 MB for now */
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff

[Xen-devel] [PATCH v5] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-03-03 Thread Wang Xiaoming
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M now.
While in different platform and different requirement this seems improper.
So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE
to io_tlb_default_size which can configure by kernel cmdline.
This can meet different requirement.

Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
---
patch v1 make this change at Kconfig
which needs to edit the .config manually.
https://lkml.org/lkml/2015/1/25/571

patch v2 only change IO_TLB_SEGSIZE configurable.
https://lkml.org/lkml/2015/2/5/812

patch v3 parsing io_tlb_segsize and 
io_tlb_default_size independently.
https://lkml.org/lkml/2015/2/15/217

patch v4 hasn't validated the data from
command line.
https://lkml.org/lkml/2015/2/17/114

 Documentation/kernel-parameters.txt  |9 -
 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 +--
 include/linux/swiotlb.h  |8 +---
 lib/swiotlb.c|   68 +-
 6 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 4df73da..1f50e86 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3438,10 +3438,17 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
it if 0 is given (See Documentation/cgroups/memory.txt)
 
swiotlb=[ARM,IA-64,PPC,MIPS,X86]
-   Format: { int | force }
+   Format: { int | force | int | int}
int -- Number of I/O TLB slabs
force -- force using of bounce buffers even if they
 wouldn't be automatically used by the kernel
+   int -- Maximum allowable number of contiguous slabs 
to map
+   int -- The size of SW-MMU mapped.
+   Using , to separate them one by one.
+   Example:
+   BOARD_KERNEL_CMDLINE += 
swiotlb=32768,force,512,268435456
+   io_tlb_nslabs=32768, swiotlb_force=1, 
+   io_tlb_segsize=512, io_tlb_default_size=268435456
 
switches=   [HW,M68k]
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c 
b/arch/mips/cavium-octeon/dma-octeon.c
index 3778655..a521af6 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
swiotlbsize = 64 * (120);
 #endif
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/arch/mips/netlogic/common/nlm-dma.c 
b/arch/mips/netlogic/common/nlm-dma.c
index f3d4ae8..eeffa8f 100644
--- a/arch/mips/netlogic/common/nlm-dma.c
+++ b/arch/mips/netlogic/common/nlm-dma.c
@@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
swiotlbsize = 1  20; /* 1 MB for now */
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad41..3b3e9fe 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long 
nslabs)
dma_addr_t dma_handle;
phys_addr_t p = virt_to_phys(buf);
 
-   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) + PAGE_SHIFT;
+   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
i = 0;
do {
-   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
do {
rc = xen_create_contiguous_region(
@@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
 {
if (!nr_tbl) {
xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
-   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
+   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
} else
xen_io_tlb_nslabs = nr_tbl;
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e7a018e..13506db 100644

Re: [Xen-devel] [PATCH v4] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-02-18 Thread Wang, Xiaoming
Dear Jan

 -Original Message-
 From: Jan Beulich [mailto:jbeul...@suse.com]
 Sent: Wednesday, February 18, 2015 5:35 PM
 To: Wang, Xiaoming
 Cc: ch...@chris-wilson.co.uk; david.vra...@citrix.com;
 lau...@codeaurora.org; heiko.carst...@de.ibm.com; li...@horizon.com;
 Liu, Chuansheng; Zhang, Dongxing; takahiro.aka...@linaro.org;
 a...@linux-foundation.org; linux-m...@linux-mips.org; ralf@linux-
 mips.org; xen-de...@lists.xenproject.org; boris.ostrov...@oracle.com;
 konrad.w...@oracle.com; d.kasat...@samsung.com; pebo...@tiscali.nl;
 linux-ker...@vger.kernel.org
 Subject: RE: [Xen-devel] [PATCH v4] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
  On 18.02.15 at 10:09, xiaoming.w...@intel.com wrote:
  From: Jan Beulich [mailto:jbeul...@suse.com]
  Sent: Tuesday, February 17, 2015 6:09 PM
   On 17.02.15 at 07:51, xiaoming.w...@intel.com wrote:
   --- a/Documentation/kernel-parameters.txt
   +++ b/Documentation/kernel-parameters.txt
   @@ -3438,10 +3438,12 @@ bytes respectively. Such letter suffixes
   can also be entirely omitted.
it if 0 is given (See
  Documentation/cgroups/memory.txt)
  
swiotlb=[ARM,IA-64,PPC,MIPS,X86]
   -Format: { int | force }
   +Format: { int | force | int | int}
int -- Number of I/O TLB slabs
force -- force using of bounce buffers even if 
   they
 wouldn't be automatically used by the 
   kernel
   +int -- Maximum allowable number of contiguous
  slabs to map
   +int -- The size of SW-MMU mapped.
 
  This makes no sense - the new numbers added aren't position
  independent (nor were the previous int and force).
 
  Use ,  can separate them one by one.
  We do it at lib/swiotlb.c
 
 Right, but the documentation above doesn't say so.
 
OK, I will add some comments on next patch version.
  Also you are (supposedly) removing all uses of IO_TLB_DEFAULT_SIZE,
  yet you don't seem to remove the definition itself.
 
  I have change all uses of IO_TLB_DEFAULT_SIZE to io_tlb_default_size
  in lib/swiotlb.c
 
 Then are there any left elsewhere? If not, again - why don't you remove the
 definition of IO_TLB_DEFAULT_SIZE?
 
There hasn't any IO_TLB_DEFAULT_SIZE left.
I check the code IO_TLB_DEFAULT_SIZE only used in lib/swiotlb.c.
And I have removed the definition of IO_TLB_DEFAULT_SIZE, in my patch

@@ -120,15 +146,13 @@ unsigned long swiotlb_nr_tbl(void)  }  
EXPORT_SYMBOL_GPL(swiotlb_nr_tbl);
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL20)

  Finally - are arbitrary numbers really okay for the newly added
  command line options? I.e. shouldn't you add some checking of their
 validity?
 
  I have validity these code is OK.
  Example:
  BOARD_KERNEL_CMDLINE += swiotlb=, ,512,268435456 Io_tlb_segsize has
  been changed from 128 to 512 Io_tlb_default_size has been changed from
  64M to 268435456  (256M)
 
 I specifically said arbitrary numbers, which in particular includes zero and
 non-power-of-2 values. If there are any restrictions on which numbers can
 validly be passed here (and it very much looks like there are), such
 restrictions should be enforced imo.
 
OK, we will validate for these variables' value in next patch version.
 Jan
Xiaoming

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-02-18 Thread Wang, Xiaoming
Dear Jan

 -Original Message-
 From: Jan Beulich [mailto:jbeul...@suse.com]
 Sent: Tuesday, February 17, 2015 6:09 PM
 To: Wang, Xiaoming
 Cc: ch...@chris-wilson.co.uk; david.vra...@citrix.com;
 lau...@codeaurora.org; heiko.carst...@de.ibm.com; li...@horizon.com;
 Liu, Chuansheng; Zhang, Dongxing; takahiro.aka...@linaro.org;
 a...@linux-foundation.org; linux-m...@linux-mips.org; ralf@linux-
 mips.org; xen-de...@lists.xenproject.org; boris.ostrov...@oracle.com;
 konrad.w...@oracle.com; d.kasat...@samsung.com; pebo...@tiscali.nl;
 linux-ker...@vger.kernel.org
 Subject: Re: [Xen-devel] [PATCH v4] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
  On 17.02.15 at 07:51, xiaoming.w...@intel.com wrote:
  --- a/Documentation/kernel-parameters.txt
  +++ b/Documentation/kernel-parameters.txt
  @@ -3438,10 +3438,12 @@ bytes respectively. Such letter suffixes can
  also be entirely omitted.
  it if 0 is given (See
 Documentation/cgroups/memory.txt)
 
  swiotlb=[ARM,IA-64,PPC,MIPS,X86]
  -   Format: { int | force }
  +   Format: { int | force | int | int}
  int -- Number of I/O TLB slabs
  force -- force using of bounce buffers even if they
   wouldn't be automatically used by the kernel
  +   int -- Maximum allowable number of contiguous
 slabs to map
  +   int -- The size of SW-MMU mapped.
 
 This makes no sense - the new numbers added aren't position independent
 (nor were the previous int and force).
 
Use ,  can separate them one by one.
We do it at lib/swiotlb.c
 Also you are (supposedly) removing all uses of IO_TLB_DEFAULT_SIZE, yet
 you don't seem to remove the definition itself.
 
I have change all uses of IO_TLB_DEFAULT_SIZE to io_tlb_default_size in 
lib/swiotlb.c
 Finally - are arbitrary numbers really okay for the newly added command line
 options? I.e. shouldn't you add some checking of their validity?
 
I have validity these code is OK.
Example:
BOARD_KERNEL_CMDLINE += swiotlb=, ,512,268435456
Io_tlb_segsize has been changed from 128 to 512
Io_tlb_default_size has been changed from 64M to 268435456  (256M)

 Jan
Xiaoming.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v3] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-02-16 Thread Wang, Xiaoming
Dear Wilk

 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Tuesday, February 17, 2015 6:13 AM
 To: Wang, Xiaoming
 Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
 david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
 ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
 foundation.org; li...@horizon.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
 takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk; pebo...@tiscali.nl; Liu,
 Chuansheng; Zhang, Dongxing
 Subject: Re: [PATCH v3] modify the IO_TLB_SEGSIZE and
 IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-
 IOMMU.
 
 On Mon, Feb 16, 2015 at 10:38:18AM +0800, Wang Xiaoming wrote:
  The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
  And the maximum of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M.
  While in different platform and different requirement this seems improper.
  So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and
  IO_TLB_DEFAULT_SIZE to io_tlb_default_size which can configure by
 BOARD_KERNEL_CMDLINE in BoardConfig.mk.
 
 Thsi patch does not have anything in BoardConfig.mk. Perhaps remove this.
 
 Got a couple of things below:
  This can meet different requirement.
 
  Signed-off-by: Chuansheng Liu chuansheng@intel.com
  Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
  Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
  ---
  patch v1 make this change at Kconfig
  which needs to edit the .config manually.
  https://lkml.org/lkml/2015/1/25/571
 
  patch v2 only change IO_TLB_SEGSIZE configurable
  https://lkml.org/lkml/2015/2/5/812
 
   arch/mips/cavium-octeon/dma-octeon.c |2 +-
   arch/mips/netlogic/common/nlm-dma.c  |2 +-
   drivers/xen/swiotlb-xen.c|6 ++--
   include/linux/swiotlb.h  |8 +
   lib/swiotlb.c|   58 
  +-
   5 files changed, 49 insertions(+), 27 deletions(-)
 
  diff --git a/arch/mips/cavium-octeon/dma-octeon.c
  b/arch/mips/cavium-octeon/dma-octeon.c
  index 3778655..a521af6 100644
  --- a/arch/mips/cavium-octeon/dma-octeon.c
  +++ b/arch/mips/cavium-octeon/dma-octeon.c
  @@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
  swiotlbsize = 64 * (120);
   #endif
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff --git a/arch/mips/netlogic/common/nlm-dma.c
  b/arch/mips/netlogic/common/nlm-dma.c
  index f3d4ae8..eeffa8f 100644
  --- a/arch/mips/netlogic/common/nlm-dma.c
  +++ b/arch/mips/netlogic/common/nlm-dma.c
  @@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
  swiotlbsize = 1  20; /* 1 MB for now */
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
  index 810ad41..3b3e9fe 100644
  --- a/drivers/xen/swiotlb-xen.c
  +++ b/drivers/xen/swiotlb-xen.c
  @@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size,
 unsigned long nslabs)
  dma_addr_t dma_handle;
  phys_addr_t p = virt_to_phys(buf);
 
  -   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) +
 PAGE_SHIFT;
  +   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
  i = 0;
  do {
  -   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
  +   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
  do {
  rc = xen_create_contiguous_region( @@ -187,7
 +187,7 @@ static
  unsigned long xen_set_nslabs(unsigned long nr_tbl)  {
  if (!nr_tbl) {
  xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
  -   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs,
 IO_TLB_SEGSIZE);
  +   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
  } else
  xen_io_tlb_nslabs = nr_tbl;
 
  diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index
  e7a018e..13506db 100644
  --- a/include/linux/swiotlb.h
  +++ b/include/linux/swiotlb.h
  @@ -8,13 +8,7 @@ struct dma_attrs;
   struct scatterlist;
 
   extern int swiotlb_force;
  -
  -/*
  - * Maximum allowable number of contiguous slabs to map,
  - * must be a power of 2.  What is the appropriate value ?
  - * The complexity of {map,unmap}_single is linearly dependent on this
 value.
  - */
  -#define IO_TLB_SEGSIZE 128
  +extern int io_tlb_segsize;
 
   /*
* log of the size of each IO TLB slab.  The number of slabs is
  command line diff --git a/lib/swiotlb.c b/lib

[Xen-devel] [PATCH v4] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-02-16 Thread Wang Xiaoming
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M.
While in different platform and different requirement this seems improper.
So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE
to io_tlb_default_size which can configure by kernel cmdline.
This can meet different requirement.

Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
---
patch v1 make this change at Kconfig
which needs to edit the .config manually.
https://lkml.org/lkml/2015/1/25/571

patch v2 only change IO_TLB_SEGSIZE configurable
https://lkml.org/lkml/2015/2/5/812

patch v3 parsing io_tlb_segsize and 
io_tlb_default_size independently
https://lkml.org/lkml/2015/2/15/217

 Documentation/kernel-parameters.txt  |4 ++-
 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 ++--
 include/linux/swiotlb.h  |8 +
 lib/swiotlb.c|   57 --
 6 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 4df73da..dd03ff0 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3438,10 +3438,12 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
it if 0 is given (See Documentation/cgroups/memory.txt)
 
swiotlb=[ARM,IA-64,PPC,MIPS,X86]
-   Format: { int | force }
+   Format: { int | force | int | int}
int -- Number of I/O TLB slabs
force -- force using of bounce buffers even if they
 wouldn't be automatically used by the kernel
+   int -- Maximum allowable number of contiguous slabs 
to map
+   int -- The size of SW-MMU mapped.
 
switches=   [HW,M68k]
 
diff --git a/arch/mips/cavium-octeon/dma-octeon.c 
b/arch/mips/cavium-octeon/dma-octeon.c
index 3778655..a521af6 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
swiotlbsize = 64 * (120);
 #endif
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/arch/mips/netlogic/common/nlm-dma.c 
b/arch/mips/netlogic/common/nlm-dma.c
index f3d4ae8..eeffa8f 100644
--- a/arch/mips/netlogic/common/nlm-dma.c
+++ b/arch/mips/netlogic/common/nlm-dma.c
@@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
swiotlbsize = 1  20; /* 1 MB for now */
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad41..3b3e9fe 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long 
nslabs)
dma_addr_t dma_handle;
phys_addr_t p = virt_to_phys(buf);
 
-   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) + PAGE_SHIFT;
+   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
i = 0;
do {
-   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
do {
rc = xen_create_contiguous_region(
@@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
 {
if (!nr_tbl) {
xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
-   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
+   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
} else
xen_io_tlb_nslabs = nr_tbl;
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e7a018e..13506db 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -8,13 +8,7 @@ struct dma_attrs;
 struct scatterlist;
 
 extern int swiotlb_force;
-
-/*
- * Maximum allowable number of contiguous slabs to map,
- * must be a power of 2.  What is the appropriate value ?
- * The complexity of {map,unmap}_single is linearly dependent on this value.
- */
-#define IO_TLB_SEGSIZE 128
+extern int io_tlb_segsize;
 
 /*
  * log

[Xen-devel] [PATCH v3] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.

2015-02-15 Thread Wang Xiaoming
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
And the maximum of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M.
While in different platform and different requirement this seems improper.
So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE to 
io_tlb_default_size which can configure by BOARD_KERNEL_CMDLINE in 
BoardConfig.mk.
This can meet different requirement.

Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
---
patch v1 make this change at Kconfig
which needs to edit the .config manually.
https://lkml.org/lkml/2015/1/25/571

patch v2 only change IO_TLB_SEGSIZE configurable
https://lkml.org/lkml/2015/2/5/812

 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 ++--
 include/linux/swiotlb.h  |8 +
 lib/swiotlb.c|   58 +-
 5 files changed, 49 insertions(+), 27 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c 
b/arch/mips/cavium-octeon/dma-octeon.c
index 3778655..a521af6 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
swiotlbsize = 64 * (120);
 #endif
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/arch/mips/netlogic/common/nlm-dma.c 
b/arch/mips/netlogic/common/nlm-dma.c
index f3d4ae8..eeffa8f 100644
--- a/arch/mips/netlogic/common/nlm-dma.c
+++ b/arch/mips/netlogic/common/nlm-dma.c
@@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
swiotlbsize = 1  20; /* 1 MB for now */
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad41..3b3e9fe 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long 
nslabs)
dma_addr_t dma_handle;
phys_addr_t p = virt_to_phys(buf);
 
-   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) + PAGE_SHIFT;
+   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
i = 0;
do {
-   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
do {
rc = xen_create_contiguous_region(
@@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
 {
if (!nr_tbl) {
xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
-   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
+   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
} else
xen_io_tlb_nslabs = nr_tbl;
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e7a018e..13506db 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -8,13 +8,7 @@ struct dma_attrs;
 struct scatterlist;
 
 extern int swiotlb_force;
-
-/*
- * Maximum allowable number of contiguous slabs to map,
- * must be a power of 2.  What is the appropriate value ?
- * The complexity of {map,unmap}_single is linearly dependent on this value.
- */
-#define IO_TLB_SEGSIZE 128
+extern int io_tlb_segsize;
 
 /*
  * log of the size of each IO TLB slab.  The number of slabs is command line
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 4abda07..1db5fc8 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -56,6 +56,15 @@
 int swiotlb_force;
 
 /*
+ * Maximum allowable number of contiguous slabs to map,
+ * must be a power of 2.  What is the appropriate value ?
+ * define io_tlb_segsize as a parameter
+ * which can be changed dynamically in config file for special usage.
+ * The complexity of {map,unmap}_single is linearly dependent on this value.
+ */
+int io_tlb_segsize = 128;
+
+/*
  * Used to do a quick range check in swiotlb_tbl_unmap_single and
  * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by 
this
  * API.
@@ -97,12 +106,20 @@ static DEFINE_SPINLOCK(io_tlb_lock);
 static int late_alloc;
 
 static int __init
+setup_io_tlb_segsize(char *str)
+{
+   get_option(str, io_tlb_segsize);
+   return 0;
+}
+__setup(io_tlb_segsize=, setup_io_tlb_segsize);
+
+static int __init
 setup_io_tlb_npages(char *str

Re: [Xen-devel] [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize configurable as flexible requirement about SW-IOMMU.

2015-02-11 Thread Wang, Xiaoming
Dear David

 -Original Message-
 From: David Vrabel [mailto:david.vra...@citrix.com]
 Sent: Tuesday, February 10, 2015 5:46 PM
 To: Wang, Xiaoming; Konrad Rzeszutek Wilk
 Cc: linux-m...@linux-mips.org; pebo...@tiscali.nl; Zhang, Dongxing;
 lau...@codeaurora.org; d.kasat...@samsung.com;
 heiko.carst...@de.ibm.com; linux-ker...@vger.kernel.org; ralf@linux-
 mips.org; ch...@chris-wilson.co.uk; takahiro.aka...@linaro.org;
 david.vra...@citrix.com; li...@horizon.com; xen-
 de...@lists.xenproject.org; boris.ostrov...@oracle.com; Liu, Chuansheng;
 a...@linux-foundation.org
 Subject: Re: [Xen-devel] [PATCH] modify the IO_TLB_SEGSIZE to
 io_tlb_segsize configurable as flexible requirement about SW-IOMMU.
 
 On 06/02/15 00:10, Wang, Xiaoming wrote:
 
 
  -Original Message-
  From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
  Sent: Friday, February 6, 2015 3:33 AM
  To: Wang, Xiaoming
  Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
  david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
  ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
  foundation.org; li...@horizon.com; lau...@codeaurora.org;
  heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
  takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk;
  pebo...@tiscali.nl; Liu, Chuansheng; Zhang, Dongxing
  Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
  configurable as flexible requirement about SW-IOMMU.
 
  On Fri, Feb 06, 2015 at 07:01:14AM +0800, xiaomin1 wrote:
  The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
  While in different platform and different requirements this seems
 improper.
  So modify the IO_TLB_SEGSIZE to io_tlb_segsize as configurable is
  make
  sense.
 
  More details please. What is the issue you are hitting?
 
  Example:
  If 1M bytes are requied. There has an error like.
 
 Instead of allowing the bouncing of such large buffers, could the gadget
 driver be modified to submit the buffers to the hardware in smaller chunks?
 
 David

Our target is try to make IO_TLB_SEGSIZE configurable.
Neither 256 bytes  or 1M bytes seems suitable value, I think.
It's better to use the tactics something like
kmem_cache_create  in kmalloc function.
But SW-IOMMU seems more lighter.
So we choose variable rather than function.

Xiaoming.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize configurable as flexible requirement about SW-IOMMU.

2015-02-09 Thread Wang, Xiaoming
Dear Wilk:

 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Monday, February 9, 2015 11:36 PM
 To: Wang, Xiaoming
 Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
 david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
 ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
 foundation.org; li...@horizon.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
 takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk; pebo...@tiscali.nl; Liu,
 Chuansheng; Zhang, Dongxing
 Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
 configurable as flexible requirement about SW-IOMMU.
 
 On Mon, Feb 09, 2015 at 02:13:30AM +, Wang, Xiaoming wrote:
  Dear Wilk:
 
   -Original Message-
   From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
   Sent: Saturday, February 7, 2015 2:12 AM
   To: Wang, Xiaoming
   Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
   david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
   ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
   foundation.org; li...@horizon.com; lau...@codeaurora.org;
   heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
   takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk;
   pebo...@tiscali.nl; Liu, Chuansheng; Zhang, Dongxing
   Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
   configurable as flexible requirement about SW-IOMMU.
  
   On Fri, Feb 06, 2015 at 12:10:15AM +, Wang, Xiaoming wrote:
   
   
 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Friday, February 6, 2015 3:33 AM
 To: Wang, Xiaoming
 Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
 david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
 ker...@vger.kernel.org; xen-de...@lists.xenproject.org;
 akpm@linux- foundation.org; li...@horizon.com;
 lau...@codeaurora.org; heiko.carst...@de.ibm.com;
 d.kasat...@samsung.com; takahiro.aka...@linaro.org;
 ch...@chris-wilson.co.uk; pebo...@tiscali.nl; Liu, Chuansheng;
 Zhang, Dongxing
 Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
 configurable as flexible requirement about SW-IOMMU.

 On Fri, Feb 06, 2015 at 07:01:14AM +0800, xiaomin1 wrote:
  The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
  While in different platform and different requirements this
  seems
   improper.
  So modify the IO_TLB_SEGSIZE to io_tlb_segsize as configurable
  is make
 sense.

 More details please. What is the issue you are hitting?

Example:
If 1M bytes are requied. There has an error like.
  
   Ok, but even with 1MB size - you only have 64 'slots' (if you
   allocate an 64MB buffer). And the other 'slots' can be fragmented so
   you might still not have enough 1MB chunks available.
  
   Do you have some thoughts on how that would be addressed?
  
  Yes,
  If IO_TLB_SEGSIZE is 128 the slabs is 32K/128 = 256 While
  IO_TLB_SEGSIZE is 512 the slabs is 32K/512 =64 (for 1M).
  So it is dilemma between slabs and segsize.
 
 Right.
  I have a thought how about modifying the IO_TLB_DEFAULT_SIZE to
  io_tlb_default_size  configurable too?
 
 It would seem that 'io_tlb_default_size' should be influenced by the
 'io_tlb_segsize' - as in have some calculation that would come up with the
 best value (if there is one?)
 
I am not sure if the 256 number of slabs is a standard .
If so there has a fixed calculation between 'io_tlb_default_size' and 
'io_tlb_segsize'

But if 'io_tlb_default_size' is limited as 64M in some platforms,
while the max segsize is required as 1M, we have to sacrifice the slabs to meet 
segsize.
So leaving  'io_tlb_default_size' and 'io_tlb_segsize' independent is better, I 
think.

  Because of the multivariate requirement.
 
[   31.474769] dwc3_otg :00:16.0:
   dwc3_intel_byt_notify_charger_type():
 dwc3_intel_byt_notify_charger_type:
   invalid SDP current!
[   31.554077] android_work: sent uevent USB_STATE=CONNECTED
[   31.564244] android_usb gadget: high-speed config #1: android
[   31.571468] android_work: sent uevent USB_STATE=CONFIGURED
[   31.942738] DMA: Out of SW-IOMMU space for 1048576 bytes at
 device
   gadget
[   31.950345] Kernel panic - not syncing: DMA: Random memory could
 be
   DMA written
[   31.950345]
[   31.960170] CPU: 1 PID: 172 Comm: droidboot Tainted: GW
   3.10.20-x86_64_byt-g1077f87 #2
[   31.970086] Hardware name: Intel Corp. VALLEYVIEW C0
   PLATFORM/BYT-T FFD8, BIOS BLADE_21.X64.0004.R14.1412311144
   FFD8_X64_R_2014_12_31_1151 12/31/2014
[   31.985053]  0010 880136c2fc98 82967d45
   880136c2fd10
[   31.993327]  82961761 0008 880136c2fd20
   880136c2fcc0
[   32.001590]  829618fb 0002 820aeff9
   8d8c
[   32.009871

Re: [Xen-devel] [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize configurable as flexible requirement about SW-IOMMU.

2015-02-08 Thread Wang, Xiaoming
Dear Wilk:

 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Saturday, February 7, 2015 2:12 AM
 To: Wang, Xiaoming
 Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
 david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
 ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
 foundation.org; li...@horizon.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
 takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk; pebo...@tiscali.nl; Liu,
 Chuansheng; Zhang, Dongxing
 Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
 configurable as flexible requirement about SW-IOMMU.
 
 On Fri, Feb 06, 2015 at 12:10:15AM +, Wang, Xiaoming wrote:
 
 
   -Original Message-
   From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
   Sent: Friday, February 6, 2015 3:33 AM
   To: Wang, Xiaoming
   Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
   david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
   ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
   foundation.org; li...@horizon.com; lau...@codeaurora.org;
   heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
   takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk;
   pebo...@tiscali.nl; Liu, Chuansheng; Zhang, Dongxing
   Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
   configurable as flexible requirement about SW-IOMMU.
  
   On Fri, Feb 06, 2015 at 07:01:14AM +0800, xiaomin1 wrote:
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
While in different platform and different requirements this seems
 improper.
So modify the IO_TLB_SEGSIZE to io_tlb_segsize as configurable is
make
   sense.
  
   More details please. What is the issue you are hitting?
  
  Example:
  If 1M bytes are requied. There has an error like.
 
 Ok, but even with 1MB size - you only have 64 'slots' (if you allocate an 64MB
 buffer). And the other 'slots' can be fragmented so you might still not have
 enough 1MB chunks available.
 
 Do you have some thoughts on how that would be addressed?
 
Yes, 
If IO_TLB_SEGSIZE is 128 the slabs is 32K/128 = 256
While IO_TLB_SEGSIZE is 512 the slabs is 32K/512 =64 (for 1M).
So it is dilemma between slabs and segsize.
I have a thought how about modifying the IO_TLB_DEFAULT_SIZE to 
io_tlb_default_size  configurable too?
Because of the multivariate requirement.

  [   31.474769] dwc3_otg :00:16.0:
 dwc3_intel_byt_notify_charger_type(): dwc3_intel_byt_notify_charger_type:
 invalid SDP current!
  [   31.554077] android_work: sent uevent USB_STATE=CONNECTED
  [   31.564244] android_usb gadget: high-speed config #1: android
  [   31.571468] android_work: sent uevent USB_STATE=CONFIGURED
  [   31.942738] DMA: Out of SW-IOMMU space for 1048576 bytes at device
 gadget
  [   31.950345] Kernel panic - not syncing: DMA: Random memory could be
 DMA written
  [   31.950345]
  [   31.960170] CPU: 1 PID: 172 Comm: droidboot Tainted: GW
 3.10.20-x86_64_byt-g1077f87 #2
  [   31.970086] Hardware name: Intel Corp. VALLEYVIEW C0
 PLATFORM/BYT-T FFD8, BIOS BLADE_21.X64.0004.R14.1412311144
 FFD8_X64_R_2014_12_31_1151 12/31/2014
  [   31.985053]  0010 880136c2fc98 82967d45
 880136c2fd10
  [   31.993327]  82961761 0008 880136c2fd20
 880136c2fcc0
  [   32.001590]  829618fb 0002 820aeff9
 8d8c
  [   32.009871] Call Trace:
  [   32.012610]  [82967d45] dump_stack+0x19/0x1b
  [   32.018353]  [82961761] panic+0xc8/0x1d6
  [   32.023707]  [829618fb] ? printk+0x55/0x57
  [   32.029258]  [820aeff9] ? console_unlock+0x1f9/0x460
  [   32.035772]  [82347cbe] swiotlb_map_page+0x12e/0x140
  [   32.042283]  [82599d4d]
 usb_gadget_map_request+0x16d/0x220
  [   32.049387]  [8255ce89] dwc3_gadget_ep_queue+0x229/0x460
  [   32.056297]  [825b4624] ffs_epfile_io.isra.96+0x3e4/0x520
  [   32.063296]  [820e438d] ? get_parent_ip+0xd/0x50
  [   32.069427]  [82975a61] ? sub_preempt_count+0x71/0x100
  [   32.076142]  [825b47b8] ffs_epfile_read+0x28/0x30
  [   32.082370]  [821b6b8c] vfs_read+0x9c/0x170
  [   32.088014]  [821b765d] SyS_read+0x4d/0xa0
  [   32.093562]  [8297b179] ia32_do_call+0x13/0x13
   
Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: xiaomin1 xiaoming.w...@intel.com
---
 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 +++---
 include/linux/swiotlb.h  |8 +--
 lib/swiotlb.c|   39 
--
 5 files changed, 34 insertions(+), 23 deletions(-)
   
diff --git a/arch/mips/cavium-octeon/dma-octeon.c
b/arch

Re: [Xen-devel] [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize configurable as flexible requirement about SW-IOMMU.

2015-02-05 Thread Wang, Xiaoming


 -Original Message-
 From: Konrad Rzeszutek Wilk [mailto:konrad.w...@oracle.com]
 Sent: Friday, February 6, 2015 3:33 AM
 To: Wang, Xiaoming
 Cc: r...@linux-mips.org; boris.ostrov...@oracle.com;
 david.vra...@citrix.com; linux-m...@linux-mips.org; linux-
 ker...@vger.kernel.org; xen-de...@lists.xenproject.org; akpm@linux-
 foundation.org; li...@horizon.com; lau...@codeaurora.org;
 heiko.carst...@de.ibm.com; d.kasat...@samsung.com;
 takahiro.aka...@linaro.org; ch...@chris-wilson.co.uk; pebo...@tiscali.nl; Liu,
 Chuansheng; Zhang, Dongxing
 Subject: Re: [PATCH] modify the IO_TLB_SEGSIZE to io_tlb_segsize
 configurable as flexible requirement about SW-IOMMU.
 
 On Fri, Feb 06, 2015 at 07:01:14AM +0800, xiaomin1 wrote:
  The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
  While in different platform and different requirements this seems improper.
  So modify the IO_TLB_SEGSIZE to io_tlb_segsize as configurable is make
 sense.
 
 More details please. What is the issue you are hitting?
 
Example:
If 1M bytes are requied. There has an error like.
[   31.474769] dwc3_otg :00:16.0: dwc3_intel_byt_notify_charger_type(): 
dwc3_intel_byt_notify_charger_type: invalid SDP current!
[   31.554077] android_work: sent uevent USB_STATE=CONNECTED
[   31.564244] android_usb gadget: high-speed config #1: android
[   31.571468] android_work: sent uevent USB_STATE=CONFIGURED
[   31.942738] DMA: Out of SW-IOMMU space for 1048576 bytes at device gadget
[   31.950345] Kernel panic - not syncing: DMA: Random memory could be DMA 
written
[   31.950345] 
[   31.960170] CPU: 1 PID: 172 Comm: droidboot Tainted: GW
3.10.20-x86_64_byt-g1077f87 #2
[   31.970086] Hardware name: Intel Corp. VALLEYVIEW C0 PLATFORM/BYT-T FFD8, 
BIOS BLADE_21.X64.0004.R14.1412311144 FFD8_X64_R_2014_12_31_1151 12/31/2014
[   31.985053]  0010 880136c2fc98 82967d45 
880136c2fd10
[   31.993327]  82961761 0008 880136c2fd20 
880136c2fcc0
[   32.001590]  829618fb 0002 820aeff9 
8d8c
[   32.009871] Call Trace:
[   32.012610]  [82967d45] dump_stack+0x19/0x1b
[   32.018353]  [82961761] panic+0xc8/0x1d6
[   32.023707]  [829618fb] ? printk+0x55/0x57
[   32.029258]  [820aeff9] ? console_unlock+0x1f9/0x460
[   32.035772]  [82347cbe] swiotlb_map_page+0x12e/0x140
[   32.042283]  [82599d4d] usb_gadget_map_request+0x16d/0x220
[   32.049387]  [8255ce89] dwc3_gadget_ep_queue+0x229/0x460
[   32.056297]  [825b4624] ffs_epfile_io.isra.96+0x3e4/0x520
[   32.063296]  [820e438d] ? get_parent_ip+0xd/0x50
[   32.069427]  [82975a61] ? sub_preempt_count+0x71/0x100
[   32.076142]  [825b47b8] ffs_epfile_read+0x28/0x30
[   32.082370]  [821b6b8c] vfs_read+0x9c/0x170
[   32.088014]  [821b765d] SyS_read+0x4d/0xa0
[   32.093562]  [8297b179] ia32_do_call+0x13/0x13
 
  Signed-off-by: Chuansheng Liu chuansheng@intel.com
  Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
  Signed-off-by: xiaomin1 xiaoming.w...@intel.com
  ---
   arch/mips/cavium-octeon/dma-octeon.c |2 +-
   arch/mips/netlogic/common/nlm-dma.c  |2 +-
   drivers/xen/swiotlb-xen.c|6 +++---
   include/linux/swiotlb.h  |8 +--
   lib/swiotlb.c|   39 
  --
   5 files changed, 34 insertions(+), 23 deletions(-)
 
  diff --git a/arch/mips/cavium-octeon/dma-octeon.c
  b/arch/mips/cavium-octeon/dma-octeon.c
  index 3778655..a521af6 100644
  --- a/arch/mips/cavium-octeon/dma-octeon.c
  +++ b/arch/mips/cavium-octeon/dma-octeon.c
  @@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
  swiotlbsize = 64 * (120);
   #endif
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff --git a/arch/mips/netlogic/common/nlm-dma.c
  b/arch/mips/netlogic/common/nlm-dma.c
  index f3d4ae8..eeffa8f 100644
  --- a/arch/mips/netlogic/common/nlm-dma.c
  +++ b/arch/mips/netlogic/common/nlm-dma.c
  @@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
  swiotlbsize = 1  20; /* 1 MB for now */
  swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
  -   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
  +   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
  swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
  nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
  diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
  index 810ad41..3b3e9fe 100644
  --- a/drivers/xen/swiotlb-xen.c
  +++ b/drivers/xen/swiotlb-xen.c
  @@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size,
 unsigned long nslabs)
  dma_addr_t dma_handle;
  phys_addr_t p

[Xen-devel] [PATCH v2] modify the IO_TLB_SEGSIZE to io_tlb_segsize configurable as flexible requirement about SW-IOMMU.

2015-02-05 Thread Wang Xiaoming
The maximum of SW-IOMMU is limited to 2^11*128 = 256K.
While in different platform and different requirements this seems improper.
So modifing the IO_TLB_SEGSIZE to io_tlb_segsize which can
configure by kernel cmdline.

Signed-off-by: Chuansheng Liu chuansheng@intel.com
Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com
Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com
---
patch v1 make this change at Kconfig 
which needs to edit the .config manually.
https://lkml.org/lkml/2015/1/25/571

 arch/mips/cavium-octeon/dma-octeon.c |2 +-
 arch/mips/netlogic/common/nlm-dma.c  |2 +-
 drivers/xen/swiotlb-xen.c|6 +++---
 include/linux/swiotlb.h  |8 +--
 lib/swiotlb.c|   39 --
 5 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c 
b/arch/mips/cavium-octeon/dma-octeon.c
index 3778655..a521af6 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void)
swiotlbsize = 64 * (120);
 #endif
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/arch/mips/netlogic/common/nlm-dma.c 
b/arch/mips/netlogic/common/nlm-dma.c
index f3d4ae8..eeffa8f 100644
--- a/arch/mips/netlogic/common/nlm-dma.c
+++ b/arch/mips/netlogic/common/nlm-dma.c
@@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void)
 
swiotlbsize = 1  20; /* 1 MB for now */
swiotlb_nslabs = swiotlbsize  IO_TLB_SHIFT;
-   swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
+   swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize);
swiotlbsize = swiotlb_nslabs  IO_TLB_SHIFT;
 
nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad41..3b3e9fe 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long 
nslabs)
dma_addr_t dma_handle;
phys_addr_t p = virt_to_phys(buf);
 
-   dma_bits = get_order(IO_TLB_SEGSIZE  IO_TLB_SHIFT) + PAGE_SHIFT;
+   dma_bits = get_order(io_tlb_segsize  IO_TLB_SHIFT) + PAGE_SHIFT;
 
i = 0;
do {
-   int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+   int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize);
 
do {
rc = xen_create_contiguous_region(
@@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
 {
if (!nr_tbl) {
xen_io_tlb_nslabs = (64 * 1024 * 1024  IO_TLB_SHIFT);
-   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
+   xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize);
} else
xen_io_tlb_nslabs = nr_tbl;
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index e7a018e..13506db 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -8,13 +8,7 @@ struct dma_attrs;
 struct scatterlist;
 
 extern int swiotlb_force;
-
-/*
- * Maximum allowable number of contiguous slabs to map,
- * must be a power of 2.  What is the appropriate value ?
- * The complexity of {map,unmap}_single is linearly dependent on this value.
- */
-#define IO_TLB_SEGSIZE 128
+extern int io_tlb_segsize;
 
 /*
  * log of the size of each IO TLB slab.  The number of slabs is command line
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 4abda07..50c415a 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -56,6 +56,15 @@
 int swiotlb_force;
 
 /*
+ * Maximum allowable number of contiguous slabs to map,
+ * must be a power of 2.  What is the appropriate value ?
+ * define io_tlb_segsize as a parameter
+ * which can be changed dynamically in config file for special usage.
+ * The complexity of {map,unmap}_single is linearly dependent on this value.
+ */
+int io_tlb_segsize = 128;
+
+/*
  * Used to do a quick range check in swiotlb_tbl_unmap_single and
  * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by 
this
  * API.
@@ -97,12 +106,20 @@ static DEFINE_SPINLOCK(io_tlb_lock);
 static int late_alloc;
 
 static int __init
+setup_io_tlb_segsize(char *str)
+{
+   get_option(str, io_tlb_segsize);
+   return 0;
+}
+__setup(io_tlb_segsize=, setup_io_tlb_segsize);
+
+static int __init
 setup_io_tlb_npages(char *str)
 {
if (isdigit(*str)) {
io_tlb_nslabs = simple_strtoul(str, str, 0);
-   /* avoid tail segment of size  IO_TLB_SEGSIZE */
-   io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
+   /* avoid tail segment of size