Skip to content

Commit 04ce9ab

Browse files
committed
async_xor: permit callers to pass in a 'dma/page scribble' region
async_xor() needs space to perform dma and page address conversions. In most cases the code can simply reuse the struct page * array because the size of the native pointer matches the size of a dma/page address. In order to support archs where sizeof(dma_addr_t) is larger than sizeof(struct page *), or to preserve the input parameters, we utilize a memory region passed in by the caller. Since the code is now prepared to handle the case where it cannot perform address conversions on the stack, we no longer need the !HIGHMEM64G dependency in drivers/dma/Kconfig. [ Impact: don't clobber input buffers for address conversions ] Reviewed-by: Andre Noll <maan@systemlinux.org> Acked-by: Maciej Sosnowski <maciej.sosnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent a08abd8 commit 04ce9ab

3 files changed

Lines changed: 58 additions & 47 deletions

File tree

‎Documentation/crypto/async-tx-api.txt‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,42 @@ of an operation.
115115
Perform a xor->copy->xor operation where each operation depends on the
116116
result from the previous operation:
117117

118-
void complete_xor_copy_xor(void *param)
118+
void callback(void *param)
119119
{
120-
printk("complete\n");
120+
struct completion *cmp = param;
121+
122+
complete(cmp);
121123
}
122124

123-
int run_xor_copy_xor(struct page **xor_srcs,
124-
int xor_src_cnt,
125-
struct page *xor_dest,
126-
size_t xor_len,
127-
struct page *copy_src,
128-
struct page *copy_dest,
129-
size_t copy_len)
125+
void run_xor_copy_xor(struct page **xor_srcs,
126+
int xor_src_cnt,
127+
struct page *xor_dest,
128+
size_t xor_len,
129+
struct page *copy_src,
130+
struct page *copy_dest,
131+
size_t copy_len)
130132
{
131133
struct dma_async_tx_descriptor *tx;
134+
addr_conv_t addr_conv[xor_src_cnt];
135+
struct async_submit_ctl submit;
136+
addr_conv_t addr_conv[NDISKS];
137+
struct completion cmp;
138+
139+
init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST, NULL, NULL, NULL,
140+
addr_conv);
141+
tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit)
132142

133-
tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len,
134-
ASYNC_TX_XOR_DROP_DST, NULL, NULL, NULL);
135-
tx = async_memcpy(copy_dest, copy_src, 0, 0, copy_len, tx, NULL, NULL);
136-
tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len,
137-
ASYNC_TX_XOR_DROP_DST | ASYNC_TX_ACK,
138-
tx, complete_xor_copy_xor, NULL);
143+
submit->depend_tx = tx;
144+
tx = async_memcpy(copy_dest, copy_src, 0, 0, copy_len, &submit);
145+
146+
init_completion(&cmp);
147+
init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST | ASYNC_TX_ACK, tx,
148+
callback, &cmp, addr_conv);
149+
tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit);
139150

140151
async_tx_issue_pending_all();
152+
153+
wait_for_completion(&cmp);
141154
}
142155

143156
See include/linux/async_tx.h for more information on the flags. See the

‎crypto/async_tx/async_xor.c‎

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
/* do_async_xor - dma map the pages and perform the xor with an engine */
3434
static __async_inline struct dma_async_tx_descriptor *
3535
do_async_xor(struct dma_chan *chan, struct page *dest, struct page **src_list,
36-
unsigned int offset, int src_cnt, size_t len,
36+
unsigned int offset, int src_cnt, size_t len, dma_addr_t *dma_src,
3737
struct async_submit_ctl *submit)
3838
{
3939
struct dma_device *dma = chan->device;
40-
dma_addr_t *dma_src = (dma_addr_t *) src_list;
4140
struct dma_async_tx_descriptor *tx = NULL;
4241
int src_off = 0;
4342
int i;
@@ -125,9 +124,14 @@ do_sync_xor(struct page *dest, struct page **src_list, unsigned int offset,
125124
int xor_src_cnt;
126125
int src_off = 0;
127126
void *dest_buf;
128-
void **srcs = (void **) src_list;
127+
void **srcs;
129128

130-
/* reuse the 'src_list' array to convert to buffer pointers */
129+
if (submit->scribble)
130+
srcs = submit->scribble;
131+
else
132+
srcs = (void **) src_list;
133+
134+
/* convert to buffer pointers */
131135
for (i = 0; i < src_cnt; i++)
132136
srcs[i] = page_address(src_list[i]) + offset;
133137

@@ -178,17 +182,26 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
178182
struct dma_chan *chan = async_tx_find_channel(submit, DMA_XOR,
179183
&dest, 1, src_list,
180184
src_cnt, len);
185+
dma_addr_t *dma_src = NULL;
186+
181187
BUG_ON(src_cnt <= 1);
182188

183-
if (chan) {
189+
if (submit->scribble)
190+
dma_src = submit->scribble;
191+
else if (sizeof(dma_addr_t) <= sizeof(struct page *))
192+
dma_src = (dma_addr_t *) src_list;
193+
194+
if (dma_src && chan) {
184195
/* run the xor asynchronously */
185196
pr_debug("%s (async): len: %zu\n", __func__, len);
186197

187198
return do_async_xor(chan, dest, src_list, offset, src_cnt, len,
188-
submit);
199+
dma_src, submit);
189200
} else {
190201
/* run the xor synchronously */
191202
pr_debug("%s (sync): len: %zu\n", __func__, len);
203+
WARN_ONCE(chan, "%s: no space for dma address conversion\n",
204+
__func__);
192205

193206
/* in the sync case the dest is an implied source
194207
* (assumes the dest is the first source)
@@ -241,11 +254,16 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
241254
src_cnt, len);
242255
struct dma_device *device = chan ? chan->device : NULL;
243256
struct dma_async_tx_descriptor *tx = NULL;
257+
dma_addr_t *dma_src = NULL;
244258

245259
BUG_ON(src_cnt <= 1);
246260

247-
if (device && src_cnt <= device->max_xor) {
248-
dma_addr_t *dma_src = (dma_addr_t *) src_list;
261+
if (submit->scribble)
262+
dma_src = submit->scribble;
263+
else if (sizeof(dma_addr_t) <= sizeof(struct page *))
264+
dma_src = (dma_addr_t *) src_list;
265+
266+
if (dma_src && device && src_cnt <= device->max_xor) {
249267
unsigned long dma_prep_flags;
250268
int i;
251269

@@ -275,6 +293,9 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
275293
enum async_tx_flags flags_orig = submit->flags;
276294

277295
pr_debug("%s: (sync) len: %zu\n", __func__, len);
296+
WARN_ONCE(device && src_cnt <= device->max_xor,
297+
"%s: no space for dma address conversion\n",
298+
__func__);
278299

279300
submit->flags |= ASYNC_TX_XOR_DROP_DST;
280301
submit->flags &= ~ASYNC_TX_ACK;
@@ -293,29 +314,6 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
293314
}
294315
EXPORT_SYMBOL_GPL(async_xor_val);
295316

296-
static int __init async_xor_init(void)
297-
{
298-
#ifdef CONFIG_DMA_ENGINE
299-
/* To conserve stack space the input src_list (array of page pointers)
300-
* is reused to hold the array of dma addresses passed to the driver.
301-
* This conversion is only possible when dma_addr_t is less than the
302-
* the size of a pointer. HIGHMEM64G is known to violate this
303-
* assumption.
304-
*/
305-
BUILD_BUG_ON(sizeof(dma_addr_t) > sizeof(struct page *));
306-
#endif
307-
308-
return 0;
309-
}
310-
311-
static void __exit async_xor_exit(void)
312-
{
313-
do { } while (0);
314-
}
315-
316-
module_init(async_xor_init);
317-
module_exit(async_xor_exit);
318-
319317
MODULE_AUTHOR("Intel Corporation");
320318
MODULE_DESCRIPTION("asynchronous xor/xor-zero-sum api");
321319
MODULE_LICENSE("GPL");

‎drivers/dma/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
menuconfig DMADEVICES
66
bool "DMA Engine support"
7-
depends on !HIGHMEM64G && HAS_DMA
7+
depends on HAS_DMA
88
help
99
DMA engines can do asynchronous data transfers without
1010
involving the host CPU. Currently, this framework can be

0 commit comments

Comments
 (0)