Skip to content

Commit 4c87917

Browse files
klassertherbertx
authored andcommitted
padata: Check for valid padata instance on start
This patch introduces the PADATA_INVALID flag which is checked on padata start. This will be used to mark a padata instance as invalid, if the padata cpumask does not intersect with the active cpumask. we change padata_start to return an error if the PADATA_INVALID is set. Also we adapt the only padata user, pcrypt to this change. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7e3de7b commit 4c87917

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎crypto/pcrypt.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static struct crypto_template pcrypt_tmpl = {
385385

386386
static int __init pcrypt_init(void)
387387
{
388+
int err = -ENOMEM;
388389
encwq = create_workqueue("pencrypt");
389390
if (!encwq)
390391
goto err;
@@ -400,14 +401,22 @@ static int __init pcrypt_init(void)
400401

401402
pcrypt_dec_padata = padata_alloc(cpu_possible_mask, decwq);
402403
if (!pcrypt_dec_padata)
403-
goto err_free_padata;
404+
goto err_free_enc_padata;
404405

405-
padata_start(pcrypt_enc_padata);
406-
padata_start(pcrypt_dec_padata);
406+
err = padata_start(pcrypt_enc_padata);
407+
if (err)
408+
goto err_free_dec_padata;
409+
410+
err = padata_start(pcrypt_dec_padata);
411+
if (err)
412+
goto err_free_dec_padata;
407413

408414
return crypto_register_template(&pcrypt_tmpl);
409415

410-
err_free_padata:
416+
err_free_dec_padata:
417+
padata_free(pcrypt_dec_padata);
418+
419+
err_free_enc_padata:
411420
padata_free(pcrypt_enc_padata);
412421

413422
err_destroy_decwq:
@@ -417,7 +426,7 @@ static int __init pcrypt_init(void)
417426
destroy_workqueue(encwq);
418427

419428
err:
420-
return -ENOMEM;
429+
return err;
421430
}
422431

423432
static void __exit pcrypt_exit(void)

‎include/linux/padata.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct padata_instance {
126126
u8 flags;
127127
#define PADATA_INIT 1
128128
#define PADATA_RESET 2
129+
#define PADATA_INVALID 4
129130
};
130131

131132
extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
@@ -138,6 +139,6 @@ extern int padata_set_cpumask(struct padata_instance *pinst,
138139
cpumask_var_t cpumask);
139140
extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
140141
extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
141-
extern void padata_start(struct padata_instance *pinst);
142+
extern int padata_start(struct padata_instance *pinst);
142143
extern void padata_stop(struct padata_instance *pinst);
143144
#endif

‎kernel/padata.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ static void padata_flush_queues(struct parallel_data *pd)
485485
BUG_ON(atomic_read(&pd->refcnt) != 0);
486486
}
487487

488+
static void __padata_start(struct padata_instance *pinst)
489+
{
490+
pinst->flags |= PADATA_INIT;
491+
}
492+
488493
/* Replace the internal control stucture with a new one. */
489494
static void padata_replace(struct padata_instance *pinst,
490495
struct parallel_data *pd_new)
@@ -619,11 +624,20 @@ EXPORT_SYMBOL(padata_remove_cpu);
619624
*
620625
* @pinst: padata instance to start
621626
*/
622-
void padata_start(struct padata_instance *pinst)
627+
int padata_start(struct padata_instance *pinst)
623628
{
629+
int err = 0;
630+
624631
mutex_lock(&pinst->lock);
625-
pinst->flags |= PADATA_INIT;
632+
633+
if (pinst->flags & PADATA_INVALID)
634+
err =-EINVAL;
635+
636+
__padata_start(pinst);
637+
626638
mutex_unlock(&pinst->lock);
639+
640+
return err;
627641
}
628642
EXPORT_SYMBOL(padata_start);
629643

0 commit comments

Comments
 (0)