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
109109 }
110110 EXPORT_SYMBOL_GPL(crypto_alloc_acomp);
111111
112+struct 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+}
118+EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node);
119+
112120 struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
113121 {
114122 struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
crypto/api.c+15−9
@@ -433,8 +433,9 @@ err: · 432 unmodified lines
433433 }
434434 EXPORT_SYMBOL_GPL(crypto_alloc_base);
435435
436−void *crypto_create_tfm(struct crypto_alg *alg,
437− const struct crypto_type *frontend)
436+void *crypto_create_tfm_node(struct crypto_alg *alg,
437+ const struct crypto_type *frontend,
438+ int node)
438439 {
439440 char *mem;
440441 struct crypto_tfm *tfm = NULL;
@@ -445,12 +446,13 @@ void *crypto_create_tfm(struct crypto_alg *alg, · 4 unmodified lines
445446 tfmsize = frontend->tfmsize;
446447 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg);
447448
448− mem = kzalloc(total, GFP_KERNEL);
449+ mem = kzalloc_node(total, GFP_KERNEL, node);
449450 if (mem == NULL)
450451 goto out_err;
451452
452453 tfm = (struct crypto_tfm *)(mem + tfmsize);
453454 tfm->__crt_alg = alg;
455+ tfm->node = node;
454456
455457 err = frontend->init_tfm(tfm);
456458 if (err)
@@ -472,7 +474,7 @@ out_err: · 15 unmodified lines
472474 out:
473475 return mem;
474476 }
475−EXPORT_SYMBOL_GPL(crypto_create_tfm);
477+EXPORT_SYMBOL_GPL(crypto_create_tfm_node);
476478
477479 struct crypto_alg *crypto_find_alg(const char *alg_name,
478480 const struct crypto_type *frontend,
@@ -490,11 +492,13 @@ struct crypto_alg *crypto_find_alg(const char *alg_name, · 11 unmodified lines
490492 EXPORT_SYMBOL_GPL(crypto_find_alg);
491493
492494 /*
493− * crypto_alloc_tfm - Locate algorithm and allocate transform
495+ * crypto_alloc_tfm_node - Locate algorithm and allocate transform
494496 * @alg_name: Name of algorithm
495497 * @frontend: Frontend algorithm type
496498 * @type: Type of algorithm
497499 * @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.
498502 *
499503 * crypto_alloc_tfm() will first attempt to locate an already loaded
500504 * algorithm. If that fails and the kernel supports dynamically loadable
@@ -509,8 +513,10 @@ EXPORT_SYMBOL_GPL(crypto_find_alg); · 8 unmodified lines
509513 *
510514 * In case of error the return value is an error pointer.
511515 */
512−void *crypto_alloc_tfm(const char *alg_name,
513− const struct crypto_type *frontend, u32 type, u32 mask)
516+
517+void *crypto_alloc_tfm_node(const char *alg_name,
518+ const struct crypto_type *frontend, u32 type, u32 mask,
519+ int node)
514520 {
515521 void *tfm;
516522 int err;
@@ -524,7 +530,7 @@ void *crypto_alloc_tfm(const char *alg_name, · 7 unmodified lines
524530 goto err;
525531 }
526532
527− tfm = crypto_create_tfm(alg, frontend);
533+ tfm = crypto_create_tfm_node(alg, frontend, node);
528534 if (!IS_ERR(tfm))
529535 return tfm;
530536
@@ -542,7 +548,7 @@ err: · 11 unmodified lines
542548
543549 return ERR_PTR(err);
544550 }
545−EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
551+EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node);
546552
547553 /*
548554 * 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
6868 void crypto_shoot_alg(struct crypto_alg *alg);
6969 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
7070 u32 mask);
71−void *crypto_create_tfm(struct crypto_alg *alg,
72− const struct crypto_type *frontend);
71+void *crypto_create_tfm_node(struct crypto_alg *alg,
72+ const struct crypto_type *frontend, int node);
73+
74+static 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+
7380 struct crypto_alg *crypto_find_alg(const char *alg_name,
7481 const struct crypto_type *frontend,
7582 u32 type, u32 mask);
76−void *crypto_alloc_tfm(const char *alg_name,
77− const struct crypto_type *frontend, u32 type, u32 mask);
83+
84+void *crypto_alloc_tfm_node(const char *alg_name,
85+ const struct crypto_type *frontend, u32 type, u32 mask,
86+ int node);
87+
88+static 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+}
7893
7994 int crypto_probing_notify(unsigned long val, void *v);
8095
include/crypto/acompress.h+18−0
@@ -106,6 +106,24 @@ struct acomp_alg { · 105 unmodified lines
106106 */
107107 struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
108108 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+ */
125+struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type,
126+ u32 mask, int node);
109127
110128 static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
111129 {
include/linux/crypto.h+2−0
@@ -594,6 +594,8 @@ int crypto_has_alg(const char *name, u32 type, u32 mask); · 593 unmodified lines
594594 struct crypto_tfm {
595595
596596 u32 crt_flags;
597+
598+ int node;
597599
598600 void (*exit)(struct crypto_tfm *tfm);
599601