[PATCH] dmaengine: async_xor, fix zero address issue when xor highmem page

Subsystems: asynchronous transfers/transforms (ioat) api, crypto api, the rest

STALE5309d

3 messages, 2 authors, 2012-01-26 · open the first message on its own page

[PATCH] dmaengine: async_xor, fix zero address issue when xor highmem page

From: <hidden>
Date: 2011-12-27 07:19:31

From: Forrest shi <redacted>

	we may do_sync_xor high mem pages, in this case, page_address will
        return zero address which cause a failure.

	this patch uses kmap_atomic before xor the pages and kunmap_atomic
        after it.

	Signed-off-by: b29237@freescale.com [off-list ref]
---
 crypto/async_tx/async_xor.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/crypto/async_tx/async_xor.c b/crypto/async_tx/async_xor.c
index bc28337..5b416d1 100644
--- a/crypto/async_tx/async_xor.c
+++ b/crypto/async_tx/async_xor.c
@@ -26,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/dma-mapping.h>
 #include <linux/raid/xor.h>
 #include <linux/async_tx.h>
@@ -126,7 +127,7 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
 	    int src_cnt, size_t len, struct async_submit_ctl *submit)
 {
 	int i;
-	int xor_src_cnt = 0;
+	int xor_src_cnt = 0, kmap_cnt=0;
 	int src_off = 0;
 	void *dest_buf;
 	void **srcs;
@@ -138,11 +139,13 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
 
 	/* convert to buffer pointers */
 	for (i = 0; i < src_cnt; i++)
-		if (src_list[i])
-			srcs[xor_src_cnt++] = page_address(src_list[i]) + offset;
+		if (src_list[i]) {
+			srcs[xor_src_cnt++] = kmap_atomic(src_list[i], KM_USER1) + offset;
+		}
+	kmap_cnt = xor_src_cnt;
 	src_cnt = xor_src_cnt;
 	/* set destination address */
-	dest_buf = page_address(dest) + offset;
+	dest_buf = kmap_atomic(dest, KM_USER0) + offset;
 
 	if (submit->flags & ASYNC_TX_XOR_ZERO_DST)
 		memset(dest_buf, 0, len);
@@ -157,6 +160,11 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
 		src_off += xor_src_cnt;
 	}
 
+	kunmap_atomic(dest_buf, KM_USER0);
+	for (i = 0; i < kmap_cnt; i++) 
+		if (src_list[i])
+			kunmap_atomic(srcs[i], KM_USER1);
+
 	async_tx_sync_epilog(submit);
 }
 
-- 
1.7.0.4

RE: [PATCH] dmaengine: async_xor, fix zero address issue when xor highmem page

From: Shi Xuelin-B29237 <hidden>
Date: 2012-01-11 07:51:48

Hello Dan Williams,

Do you have any comment about this patch?

Thanks,
Forrest

-----Original Message-----
From: Shi Xuelin-B29237=20
Sent: 2011=1B$BG/=1B(B12=1B$B7n=1B(B27=1B$BF|=1B(B 14:31
To: vinod.koul@intel.com; dan.j.williams@intel.com; linuxppc-dev@lists.ozla=
bs.org; linux-kernel@vger.kernel.org; Li Yang-R58472
Cc: Shi Xuelin-B29237
Subject: [PATCH] dmaengine: async_xor, fix zero address issue when xor high=
mem page

From: Forrest shi <redacted>

	we may do_sync_xor high mem pages, in this case, page_address will
        return zero address which cause a failure.

	this patch uses kmap_atomic before xor the pages and kunmap_atomic
        after it.

	Signed-off-by: b29237@freescale.com [off-list ref]
---
 crypto/async_tx/async_xor.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/crypto/async_tx/async_xor.c b/crypto/async_tx/async_xor.c inde=
x bc28337..5b416d1 100644
--- a/crypto/async_tx/async_xor.c
+++ b/crypto/async_tx/async_xor.c
@@ -26,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/dma-mapping.h>
 #include <linux/raid/xor.h>
 #include <linux/async_tx.h>
@@ -126,7 +127,7 @@ do_sync_xor(struct page *dest, struct page **src_list, =
unsigned int offset,
 	    int src_cnt, size_t len, struct async_submit_ctl *submit)  {
 	int i;
-	int xor_src_cnt =3D 0;
+	int xor_src_cnt =3D 0, kmap_cnt=3D0;
 	int src_off =3D 0;
 	void *dest_buf;
 	void **srcs;
@@ -138,11 +139,13 @@ do_sync_xor(struct page *dest, struct page **src_list=
, unsigned int offset,
=20
 	/* convert to buffer pointers */
 	for (i =3D 0; i < src_cnt; i++)
-		if (src_list[i])
-			srcs[xor_src_cnt++] =3D page_address(src_list[i]) + offset;
+		if (src_list[i]) {
+			srcs[xor_src_cnt++] =3D kmap_atomic(src_list[i], KM_USER1) + offset;
+		}
+	kmap_cnt =3D xor_src_cnt;
 	src_cnt =3D xor_src_cnt;
 	/* set destination address */
-	dest_buf =3D page_address(dest) + offset;
+	dest_buf =3D kmap_atomic(dest, KM_USER0) + offset;
=20
 	if (submit->flags & ASYNC_TX_XOR_ZERO_DST)
 		memset(dest_buf, 0, len);
@@ -157,6 +160,11 @@ do_sync_xor(struct page *dest, struct page **src_list,=
 unsigned int offset,
 		src_off +=3D xor_src_cnt;
 	}
=20
+	kunmap_atomic(dest_buf, KM_USER0);
+	for (i =3D 0; i < kmap_cnt; i++)=20
+		if (src_list[i])
+			kunmap_atomic(srcs[i], KM_USER1);
+
 	async_tx_sync_epilog(submit);
 }
=20
--
1.7.0.4

Re: [PATCH] dmaengine: async_xor, fix zero address issue when xor highmem page

From: Dan Williams <hidden>
Date: 2012-01-26 09:12:16

2012/1/10 Shi Xuelin-B29237 [off-list ref]:
Hello Dan Williams,

Do you have any comment about this patch?
Hi, sorrry for the delay.
Thanks,
Forrest

-----Original Message-----
From: Shi Xuelin-B29237
Sent: 2011=E5=B9=B412=E6=9C=8827=E6=97=A5 14:31
To: vinod.koul@intel.com; dan.j.williams@intel.com; linuxppc-dev@lists.oz=
labs.org; linux-kernel@vger.kernel.org; Li Yang-R58472
Cc: Shi Xuelin-B29237
Subject: [PATCH] dmaengine: async_xor, fix zero address issue when xor hi=
ghmem page
From: Forrest shi <redacted>

=C2=A0 =C2=A0 =C2=A0 =C2=A0we may do_sync_xor high mem pages, in this cas=
e, page_address will
=C2=A0 =C2=A0 =C2=A0 =C2=A0return zero address which cause a failure.
In what scenarios do we xor highmem?

In the case of raid we currently always xor on kmalloc'd memory.
=C2=A0 =C2=A0 =C2=A0 =C2=A0this patch uses kmap_atomic before xor the pag=
es and kunmap_atomic
=C2=A0 =C2=A0 =C2=A0 =C2=A0after it.

=C2=A0 =C2=A0 =C2=A0 =C2=A0Signed-off-by: b29237@freescale.com <xuelin.sh=
i@freescale.com>
quoted hunk
---
=C2=A0crypto/async_tx/async_xor.c | =C2=A0 16 ++++++++++++----
=C2=A01 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/crypto/async_tx/async_xor.c b/crypto/async_tx/async_xor.c in=
dex bc28337..5b416d1 100644
quoted hunk
--- a/crypto/async_tx/async_xor.c
+++ b/crypto/async_tx/async_xor.c
@@ -26,6 +26,7 @@
=C2=A0#include <linux/kernel.h>
=C2=A0#include <linux/interrupt.h>
=C2=A0#include <linux/mm.h>
+#include <linux/highmem.h>
=C2=A0#include <linux/dma-mapping.h>
=C2=A0#include <linux/raid/xor.h>
=C2=A0#include <linux/async_tx.h>
@@ -126,7 +127,7 @@ do_sync_xor(struct page *dest, struct page **src_list=
, unsigned int offset,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int src_cnt, size_t len, struct =
async_submit_ctl *submit) =C2=A0{
quoted hunk
=C2=A0 =C2=A0 =C2=A0 =C2=A0int i;
- =C2=A0 =C2=A0 =C2=A0 int xor_src_cnt =3D 0;
+ =C2=A0 =C2=A0 =C2=A0 int xor_src_cnt =3D 0, kmap_cnt=3D0;
=C2=A0 =C2=A0 =C2=A0 =C2=A0int src_off =3D 0;
=C2=A0 =C2=A0 =C2=A0 =C2=A0void *dest_buf;
=C2=A0 =C2=A0 =C2=A0 =C2=A0void **srcs;
@@ -138,11 +139,13 @@ do_sync_xor(struct page *dest, struct page **src_li=
st, unsigned int offset,
=C2=A0 =C2=A0 =C2=A0 =C2=A0/* convert to buffer pointers */
=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < src_cnt; i++)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (src_list[i])
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 srcs[xor_src_cnt++] =3D page_address(src_list[i]) + offset;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (src_list[i]) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 srcs[xor_src_cnt++] =3D kmap_atomic(src_list[i], KM_USER1) + offset;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+ =C2=A0 =C2=A0 =C2=A0 kmap_cnt =3D xor_src_cnt;
I guess this works now that we have stack based kmap_atomic, but on
older kernels you could not simultaneously map that many buffers with
a single kmap slot.  So if you resend, drop the second parameter to
kmap_atomic.

...but unless you have a non md/raid456 use case in mind, or have
patches to convert md/raid to xor straight out of the incoming biovecs
I don't think this patch is needed right?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help