Skip to content

Commit 29bcff7

Browse files
Yufen Yuliu-song-6
authored andcommitted
md/raid5: add new xor function to support different page offset
raid5 will call async_xor() and async_xor_val() to compute xor. For now, both of them require the common src/dst page offset. But, we want them to support different src/dst page offset for following shared page. Here, adding two new function async_xor_offs() and async_xor_val_offs() respectively for async_xor() and async_xor_val(). Signed-off-by: Yufen Yu <yuyufen@huawei.com> Signed-off-by: Song Liu <songliubraving@fb.com>
1 parent 248728d commit 29bcff7

2 files changed

Lines changed: 114 additions & 17 deletions

File tree

‎crypto/async_tx/async_xor.c‎

Lines changed: 103 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ do_async_xor(struct dma_chan *chan, struct dmaengine_unmap_data *unmap,
9797
}
9898

9999
static void
100-
do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
100+
do_sync_xor_offs(struct page *dest, unsigned int offset,
101+
struct page **src_list, unsigned int *src_offs,
101102
int src_cnt, size_t len, struct async_submit_ctl *submit)
102103
{
103104
int i;
@@ -114,7 +115,8 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
114115
/* convert to buffer pointers */
115116
for (i = 0; i < src_cnt; i++)
116117
if (src_list[i])
117-
srcs[xor_src_cnt++] = page_address(src_list[i]) + offset;
118+
srcs[xor_src_cnt++] = page_address(src_list[i]) +
119+
(src_offs ? src_offs[i] : offset);
118120
src_cnt = xor_src_cnt;
119121
/* set destination address */
120122
dest_buf = page_address(dest) + offset;
@@ -135,11 +137,31 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
135137
async_tx_sync_epilog(submit);
136138
}
137139

140+
static inline bool
141+
dma_xor_aligned_offsets(struct dma_device *device, unsigned int offset,
142+
unsigned int *src_offs, int src_cnt, int len)
143+
{
144+
int i;
145+
146+
if (!is_dma_xor_aligned(device, offset, 0, len))
147+
return false;
148+
149+
if (!src_offs)
150+
return true;
151+
152+
for (i = 0; i < src_cnt; i++) {
153+
if (!is_dma_xor_aligned(device, src_offs[i], 0, len))
154+
return false;
155+
}
156+
return true;
157+
}
158+
138159
/**
139-
* async_xor - attempt to xor a set of blocks with a dma engine.
160+
* async_xor_offs - attempt to xor a set of blocks with a dma engine.
140161
* @dest: destination page
162+
* @offset: dst offset to start transaction
141163
* @src_list: array of source pages
142-
* @offset: common src/dst offset to start transaction
164+
* @src_offs: array of source pages offset, NULL means common src/dst offset
143165
* @src_cnt: number of source pages
144166
* @len: length in bytes
145167
* @submit: submission / completion modifiers
@@ -157,8 +179,9 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
157179
* is not specified.
158180
*/
159181
struct dma_async_tx_descriptor *
160-
async_xor(struct page *dest, struct page **src_list, unsigned int offset,
161-
int src_cnt, size_t len, struct async_submit_ctl *submit)
182+
async_xor_offs(struct page *dest, unsigned int offset,
183+
struct page **src_list, unsigned int *src_offs,
184+
int src_cnt, size_t len, struct async_submit_ctl *submit)
162185
{
163186
struct dma_chan *chan = async_tx_find_channel(submit, DMA_XOR,
164187
&dest, 1, src_list,
@@ -171,7 +194,8 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
171194
if (device)
172195
unmap = dmaengine_get_unmap_data(device->dev, src_cnt+1, GFP_NOWAIT);
173196

174-
if (unmap && is_dma_xor_aligned(device, offset, 0, len)) {
197+
if (unmap && dma_xor_aligned_offsets(device, offset,
198+
src_offs, src_cnt, len)) {
175199
struct dma_async_tx_descriptor *tx;
176200
int i, j;
177201

@@ -184,7 +208,8 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
184208
continue;
185209
unmap->to_cnt++;
186210
unmap->addr[j++] = dma_map_page(device->dev, src_list[i],
187-
offset, len, DMA_TO_DEVICE);
211+
src_offs ? src_offs[i] : offset,
212+
len, DMA_TO_DEVICE);
188213
}
189214

190215
/* map it bidirectional as it may be re-used as a source */
@@ -213,11 +238,42 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
213238
/* wait for any prerequisite operations */
214239
async_tx_quiesce(&submit->depend_tx);
215240

216-
do_sync_xor(dest, src_list, offset, src_cnt, len, submit);
241+
do_sync_xor_offs(dest, offset, src_list, src_offs,
242+
src_cnt, len, submit);
217243

218244
return NULL;
219245
}
220246
}
247+
EXPORT_SYMBOL_GPL(async_xor_offs);
248+
249+
/**
250+
* async_xor - attempt to xor a set of blocks with a dma engine.
251+
* @dest: destination page
252+
* @src_list: array of source pages
253+
* @offset: common src/dst offset to start transaction
254+
* @src_cnt: number of source pages
255+
* @len: length in bytes
256+
* @submit: submission / completion modifiers
257+
*
258+
* honored flags: ASYNC_TX_ACK, ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DST
259+
*
260+
* xor_blocks always uses the dest as a source so the
261+
* ASYNC_TX_XOR_ZERO_DST flag must be set to not include dest data in
262+
* the calculation. The assumption with dma eninges is that they only
263+
* use the destination buffer as a source when it is explicity specified
264+
* in the source list.
265+
*
266+
* src_list note: if the dest is also a source it must be at index zero.
267+
* The contents of this array will be overwritten if a scribble region
268+
* is not specified.
269+
*/
270+
struct dma_async_tx_descriptor *
271+
async_xor(struct page *dest, struct page **src_list, unsigned int offset,
272+
int src_cnt, size_t len, struct async_submit_ctl *submit)
273+
{
274+
return async_xor_offs(dest, offset, src_list, NULL,
275+
src_cnt, len, submit);
276+
}
221277
EXPORT_SYMBOL_GPL(async_xor);
222278

223279
static int page_is_zero(struct page *p, unsigned int offset, size_t len)
@@ -237,10 +293,11 @@ xor_val_chan(struct async_submit_ctl *submit, struct page *dest,
237293
}
238294

239295
/**
240-
* async_xor_val - attempt a xor parity check with a dma engine.
296+
* async_xor_val_offs - attempt a xor parity check with a dma engine.
241297
* @dest: destination page used if the xor is performed synchronously
298+
* @offset: des offset in pages to start transaction
242299
* @src_list: array of source pages
243-
* @offset: offset in pages to start transaction
300+
* @src_offs: array of source pages offset, NULL means common src/det offset
244301
* @src_cnt: number of source pages
245302
* @len: length in bytes
246303
* @result: 0 if sum == 0 else non-zero
@@ -253,9 +310,10 @@ xor_val_chan(struct async_submit_ctl *submit, struct page *dest,
253310
* is not specified.
254311
*/
255312
struct dma_async_tx_descriptor *
256-
async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
257-
int src_cnt, size_t len, enum sum_check_flags *result,
258-
struct async_submit_ctl *submit)
313+
async_xor_val_offs(struct page *dest, unsigned int offset,
314+
struct page **src_list, unsigned int *src_offs,
315+
int src_cnt, size_t len, enum sum_check_flags *result,
316+
struct async_submit_ctl *submit)
259317
{
260318
struct dma_chan *chan = xor_val_chan(submit, dest, src_list, src_cnt, len);
261319
struct dma_device *device = chan ? chan->device : NULL;
@@ -268,7 +326,7 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
268326
unmap = dmaengine_get_unmap_data(device->dev, src_cnt, GFP_NOWAIT);
269327

270328
if (unmap && src_cnt <= device->max_xor &&
271-
is_dma_xor_aligned(device, offset, 0, len)) {
329+
dma_xor_aligned_offsets(device, offset, src_offs, src_cnt, len)) {
272330
unsigned long dma_prep_flags = 0;
273331
int i;
274332

@@ -281,7 +339,8 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
281339

282340
for (i = 0; i < src_cnt; i++) {
283341
unmap->addr[i] = dma_map_page(device->dev, src_list[i],
284-
offset, len, DMA_TO_DEVICE);
342+
src_offs ? src_offs[i] : offset,
343+
len, DMA_TO_DEVICE);
285344
unmap->to_cnt++;
286345
}
287346
unmap->len = len;
@@ -312,7 +371,8 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
312371
submit->flags |= ASYNC_TX_XOR_DROP_DST;
313372
submit->flags &= ~ASYNC_TX_ACK;
314373

315-
tx = async_xor(dest, src_list, offset, src_cnt, len, submit);
374+
tx = async_xor_offs(dest, offset, src_list, src_offs,
375+
src_cnt, len, submit);
316376

317377
async_tx_quiesce(&tx);
318378

@@ -325,6 +385,32 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
325385

326386
return tx;
327387
}
388+
EXPORT_SYMBOL_GPL(async_xor_val_offs);
389+
390+
/**
391+
* async_xor_val - attempt a xor parity check with a dma engine.
392+
* @dest: destination page used if the xor is performed synchronously
393+
* @src_list: array of source pages
394+
* @offset: offset in pages to start transaction
395+
* @src_cnt: number of source pages
396+
* @len: length in bytes
397+
* @result: 0 if sum == 0 else non-zero
398+
* @submit: submission / completion modifiers
399+
*
400+
* honored flags: ASYNC_TX_ACK
401+
*
402+
* src_list note: if the dest is also a source it must be at index zero.
403+
* The contents of this array will be overwritten if a scribble region
404+
* is not specified.
405+
*/
406+
struct dma_async_tx_descriptor *
407+
async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
408+
int src_cnt, size_t len, enum sum_check_flags *result,
409+
struct async_submit_ctl *submit)
410+
{
411+
return async_xor_val_offs(dest, offset, src_list, NULL, src_cnt,
412+
len, result, submit);
413+
}
328414
EXPORT_SYMBOL_GPL(async_xor_val);
329415

330416
MODULE_AUTHOR("Intel Corporation");

‎include/linux/async_tx.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,22 @@ struct dma_async_tx_descriptor *
162162
async_xor(struct page *dest, struct page **src_list, unsigned int offset,
163163
int src_cnt, size_t len, struct async_submit_ctl *submit);
164164

165+
struct dma_async_tx_descriptor *
166+
async_xor_offs(struct page *dest, unsigned int offset,
167+
struct page **src_list, unsigned int *src_offset,
168+
int src_cnt, size_t len, struct async_submit_ctl *submit);
169+
165170
struct dma_async_tx_descriptor *
166171
async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
167172
int src_cnt, size_t len, enum sum_check_flags *result,
168173
struct async_submit_ctl *submit);
169174

175+
struct dma_async_tx_descriptor *
176+
async_xor_val_offs(struct page *dest, unsigned int offset,
177+
struct page **src_list, unsigned int *src_offset,
178+
int src_cnt, size_t len, enum sum_check_flags *result,
179+
struct async_submit_ctl *submit);
180+
170181
struct dma_async_tx_descriptor *
171182
async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
172183
unsigned int src_offset, size_t len,

0 commit comments

Comments
 (0)