From: Kyle Spiers <ksspiers@google.com>
To: dan.j.williams@intel.com
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
keescook@chromium.org, vinod.koul@intel.com,
ray.jui@broadcom.com, anup.patel@broadcom.com,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Kyle Spiers <ksspiers@google.com>
Subject: [PATCH] async_pq: Remove VLA usage
Date: Thu, 3 May 2018 15:57:16 -0700 [thread overview]
Message-ID: <20180503225716.154235-1-ksspiers@google.com> (raw)
In the quest to remove VLAs from the kernel[1], this moves the
allocation of coefs and blocks from the stack to being kmalloc()ed.
[1] https://lkml.org/lkml/2018/3/7/621
Signed-off-by: Kyle Spiers <ksspiers@google.com>
---
crypto/async_tx/async_pq.c | 18 ++++++++++++++----
crypto/async_tx/raid6test.c | 8 +++++++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/crypto/async_tx/async_pq.c b/crypto/async_tx/async_pq.c
index 56bd612927ab..af1912313a23 100644
--- a/crypto/async_tx/async_pq.c
+++ b/crypto/async_tx/async_pq.c
@@ -194,9 +194,9 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
(src_cnt <= dma_maxpq(device, 0) ||
dma_maxpq(device, DMA_PREP_CONTINUE) > 0) &&
is_dma_pq_aligned(device, offset, 0, len)) {
- struct dma_async_tx_descriptor *tx;
+ struct dma_async_tx_descriptor *tx = NULL;
enum dma_ctrl_flags dma_flags = 0;
- unsigned char coefs[src_cnt];
+ unsigned char *coefs;
int i, j;
/* run the p+q asynchronously */
@@ -207,6 +207,9 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
* sources and update the coefficients accordingly
*/
unmap->len = len;
+ coefs = kmalloc_array(src_cnt, sizeof(*coefs), GFP_KERNEL);
+ if (!coefs)
+ goto out;
for (i = 0, j = 0; i < src_cnt; i++) {
if (blocks[i] == NULL)
continue;
@@ -240,7 +243,9 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
}
tx = do_async_gen_syndrome(chan, coefs, j, unmap, dma_flags, submit);
+out:
dmaengine_unmap_put(unmap);
+ kfree(coefs);
return tx;
}
@@ -298,8 +303,8 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
{
struct dma_chan *chan = pq_val_chan(submit, blocks, disks, len);
struct dma_device *device = chan ? chan->device : NULL;
- struct dma_async_tx_descriptor *tx;
- unsigned char coefs[disks-2];
+ struct dma_async_tx_descriptor *tx = NULL;
+ unsigned char *coefs = NULL;
enum dma_ctrl_flags dma_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
struct dmaengine_unmap_data *unmap = NULL;
@@ -318,6 +323,9 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
__func__, disks, len);
unmap->len = len;
+ coefs = kmalloc_array(disks - 2, sizeof(*coefs), GFP_KERNEL);
+ if (!coefs)
+ goto out;
for (i = 0; i < disks-2; i++)
if (likely(blocks[i])) {
unmap->addr[j] = dma_map_page(dev, blocks[i],
@@ -423,6 +431,8 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
async_tx_sync_epilog(submit);
tx = NULL;
}
+out:
+ kfree(coefs);
dmaengine_unmap_put(unmap);
return tx;
diff --git a/crypto/async_tx/raid6test.c b/crypto/async_tx/raid6test.c
index dad95f45b88f..ea036b531ef2 100644
--- a/crypto/async_tx/raid6test.c
+++ b/crypto/async_tx/raid6test.c
@@ -81,11 +81,16 @@ static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, stru
init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
} else {
- struct page *blocks[disks];
+ struct page **blocks;
struct page *dest;
int count = 0;
int i;
+ blocks = kmalloc_array(disks, sizeof(*blocks),
+ GFP_KERNEL);
+ if (!blocks)
+ return;
+
/* data+Q failure. Reconstruct data from P,
* then rebuild syndrome
*/
@@ -101,6 +106,7 @@ static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, stru
init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
+ kfree(blocks);
}
} else {
if (failb == disks-2) {
--
2.17.0.441.gb46fe60e1d-goog
next reply other threads:[~2018-05-03 22:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-03 22:57 Kyle Spiers [this message]
2018-05-03 23:32 ` [PATCH] async_pq: Remove VLA usage Kees Cook
2018-05-04 18:25 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180503225716.154235-1-ksspiers@google.com \
--to=ksspiers@google.com \
--cc=anup.patel@broadcom.com \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ray.jui@broadcom.com \
--cc=vinod.koul@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.