History

crypto: api - permit users to specify numa node of acomp hardware

For a Linux server with NUMA, there are possibly multiple (de)compressors which are either local or remote to some NUMA node. Some drivers will automatically use the (de)compressor near the CPU calling acomp_alloc(). However, it is not necessarily correct because users who send acomp_req could be from different NUMA node with the CPU which allocates acomp. Just like kernel has kmalloc() and kmalloc_node(), here crypto can have same support.

Barry Song committed 6 years ago

Commit 7bc13b51 parent 3347c8a5 files · +62 −13Browse files

Unified · Split

5 files
  1. crypto/acompress.c +8 −0
  2. crypto/api.c +15 −9
  3. crypto/internal.h +19 −4
  4. include/crypto/acompress.h +18 −0
  5. include/linux/crypto.h +2 −0
crypto/acompress.c+8−0
@@ -109,6 +109,14 @@ struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type, · 108 unmodified lines
109}109}
110EXPORT_SYMBOL_GPL(crypto_alloc_acomp);110EXPORT_SYMBOL_GPL(crypto_alloc_acomp);
111 111
112struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type,
113 u32 mask, int node)
114{
115 return crypto_alloc_tfm_node(alg_name, &crypto_acomp_type, type, mask,
116 node);
117}
118EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node);
119
112struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)120struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
113{121{
114 struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);122 struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
crypto/api.c+15−9
@@ -433,8 +433,9 @@ err: · 432 unmodified lines
433}433}
434EXPORT_SYMBOL_GPL(crypto_alloc_base);434EXPORT_SYMBOL_GPL(crypto_alloc_base);
435 435
436void *crypto_create_tfm(struct crypto_alg *alg,436void *crypto_create_tfm_node(struct crypto_alg *alg,
437 const struct crypto_type *frontend)437 const struct crypto_type *frontend,
438 int node)
438{439{
439 char *mem;440 char *mem;
440 struct crypto_tfm *tfm = NULL;441 struct crypto_tfm *tfm = NULL;
@@ -445,12 +446,13 @@ void *crypto_create_tfm(struct crypto_alg *alg, · 4 unmodified lines
445 tfmsize = frontend->tfmsize;446 tfmsize = frontend->tfmsize;
446 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg);447 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg);
447 448
448 mem = kzalloc(total, GFP_KERNEL);449 mem = kzalloc_node(total, GFP_KERNEL, node);
449 if (mem == NULL)450 if (mem == NULL)
450 goto out_err;451 goto out_err;
451 452
452 tfm = (struct crypto_tfm *)(mem + tfmsize);453 tfm = (struct crypto_tfm *)(mem + tfmsize);
453 tfm->__crt_alg = alg;454 tfm->__crt_alg = alg;
455 tfm->node = node;
454 456
455 err = frontend->init_tfm(tfm);457 err = frontend->init_tfm(tfm);
456 if (err)458 if (err)
@@ -472,7 +474,7 @@ out_err: · 15 unmodified lines
472out:474out:
473 return mem;475 return mem;
474}476}
475EXPORT_SYMBOL_GPL(crypto_create_tfm);477EXPORT_SYMBOL_GPL(crypto_create_tfm_node);
476 478
477struct crypto_alg *crypto_find_alg(const char *alg_name,479struct crypto_alg *crypto_find_alg(const char *alg_name,
478 const struct crypto_type *frontend,480 const struct crypto_type *frontend,
@@ -490,11 +492,13 @@ struct crypto_alg *crypto_find_alg(const char *alg_name, · 11 unmodified lines
490EXPORT_SYMBOL_GPL(crypto_find_alg);492EXPORT_SYMBOL_GPL(crypto_find_alg);
491 493
492/*494/*
493 * crypto_alloc_tfm - Locate algorithm and allocate transform495 * crypto_alloc_tfm_node - Locate algorithm and allocate transform
494 * @alg_name: Name of algorithm496 * @alg_name: Name of algorithm
495 * @frontend: Frontend algorithm type497 * @frontend: Frontend algorithm type
496 * @type: Type of algorithm498 * @type: Type of algorithm
497 * @mask: Mask for type comparison499 * @mask: Mask for type comparison
500 * @node: NUMA node in which users desire to put requests, if node is
501 * NUMA_NO_NODE, it means users have no special requirement.
498 *502 *
499 * crypto_alloc_tfm() will first attempt to locate an already loaded503 * crypto_alloc_tfm() will first attempt to locate an already loaded
500 * algorithm. If that fails and the kernel supports dynamically loadable504 * algorithm. If that fails and the kernel supports dynamically loadable
@@ -509,8 +513,10 @@ EXPORT_SYMBOL_GPL(crypto_find_alg); · 8 unmodified lines
509 *513 *
510 * In case of error the return value is an error pointer.514 * In case of error the return value is an error pointer.
511 */515 */
512void *crypto_alloc_tfm(const char *alg_name,516
513 const struct crypto_type *frontend, u32 type, u32 mask)517void *crypto_alloc_tfm_node(const char *alg_name,
518 const struct crypto_type *frontend, u32 type, u32 mask,
519 int node)
514{520{
515 void *tfm;521 void *tfm;
516 int err;522 int err;
@@ -524,7 +530,7 @@ void *crypto_alloc_tfm(const char *alg_name, · 7 unmodified lines
524 goto err;530 goto err;
525 }531 }
526 532
527 tfm = crypto_create_tfm(alg, frontend);533 tfm = crypto_create_tfm_node(alg, frontend, node);
528 if (!IS_ERR(tfm))534 if (!IS_ERR(tfm))
529 return tfm;535 return tfm;
530 536
@@ -542,7 +548,7 @@ err: · 11 unmodified lines
542 548
543 return ERR_PTR(err);549 return ERR_PTR(err);
544}550}
545EXPORT_SYMBOL_GPL(crypto_alloc_tfm);551EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node);
546 552
547/*553/*
548 * crypto_destroy_tfm - Free crypto transform554 * crypto_destroy_tfm - Free crypto transform
crypto/internal.h+19−4
@@ -68,13 +68,28 @@ void crypto_remove_final(struct list_head *list); · 67 unmodified lines
68void crypto_shoot_alg(struct crypto_alg *alg);68void crypto_shoot_alg(struct crypto_alg *alg);
69struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,69struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
70 u32 mask);70 u32 mask);
71void *crypto_create_tfm(struct crypto_alg *alg,71void *crypto_create_tfm_node(struct crypto_alg *alg,
72 const struct crypto_type *frontend);72 const struct crypto_type *frontend, int node);
73
74static inline void *crypto_create_tfm(struct crypto_alg *alg,
75 const struct crypto_type *frontend)
76{
77 return crypto_create_tfm_node(alg, frontend, NUMA_NO_NODE);
78}
79
73struct crypto_alg *crypto_find_alg(const char *alg_name,80struct crypto_alg *crypto_find_alg(const char *alg_name,
74 const struct crypto_type *frontend,81 const struct crypto_type *frontend,
75 u32 type, u32 mask);82 u32 type, u32 mask);
76void *crypto_alloc_tfm(const char *alg_name,83
77 const struct crypto_type *frontend, u32 type, u32 mask);84void *crypto_alloc_tfm_node(const char *alg_name,
85 const struct crypto_type *frontend, u32 type, u32 mask,
86 int node);
87
88static inline void *crypto_alloc_tfm(const char *alg_name,
89 const struct crypto_type *frontend, u32 type, u32 mask)
90{
91 return crypto_alloc_tfm_node(alg_name, frontend, type, mask, NUMA_NO_NODE);
92}
78 93
79int crypto_probing_notify(unsigned long val, void *v);94int crypto_probing_notify(unsigned long val, void *v);
80 95
include/crypto/acompress.h+18−0
@@ -106,6 +106,24 @@ struct acomp_alg { · 105 unmodified lines
106 */106 */
107struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,107struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
108 u32 mask);108 u32 mask);
109/**
110 * crypto_alloc_acomp_node() -- allocate ACOMPRESS tfm handle with desired NUMA node
111 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
112 * compression algorithm e.g. "deflate"
113 * @type: specifies the type of the algorithm
114 * @mask: specifies the mask for the algorithm
115 * @node: specifies the NUMA node the ZIP hardware belongs to
116 *
117 * Allocate a handle for a compression algorithm. Drivers should try to use
118 * (de)compressors on the specified NUMA node.
119 * The returned struct crypto_acomp is the handle that is required for any
120 * subsequent API invocation for the compression operations.
121 *
122 * Return: allocated handle in case of success; IS_ERR() is true in case
123 * of an error, PTR_ERR() returns the error code.
124 */
125struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type,
126 u32 mask, int node);
109 127
110static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)128static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
111{129{
include/linux/crypto.h+2−0
@@ -594,6 +594,8 @@ int crypto_has_alg(const char *name, u32 type, u32 mask); · 593 unmodified lines
594struct crypto_tfm {594struct crypto_tfm {
595 595
596 u32 crt_flags;596 u32 crt_flags;
597
598 int node;
597 599
598 void (*exit)(struct crypto_tfm *tfm);600 void (*exit)(struct crypto_tfm *tfm);
599 601