From: Israel Rukshin <israelr@xxxxxxxxxx> Add an API to manage Data Encryption Keys (DEKs). The API allows creating and destroying a DEK. DEKs allow encryption and decryption of transmitted data and are used in MKeys for crypto operations. A crypto setter for the MKey configuration API will be added in the following commit. Signed-off-by: Israel Rukshin <israelr@xxxxxxxxxx> Reviewed-by: Max Gurtovoy <mgurtovoy@xxxxxxxxxx> Signed-off-by: Leon Romanovsky <leon@xxxxxxxxxx> --- drivers/infiniband/core/device.c | 2 ++ drivers/infiniband/core/verbs.c | 32 +++++++++++++++++++++++++++ include/rdma/crypto.h | 38 ++++++++++++++++++++++++++++++++ include/rdma/ib_verbs.h | 3 +++ 4 files changed, 75 insertions(+) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index a666847bd714..b2016725c3d8 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -2615,6 +2615,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops) SET_DEVICE_OP(dev_ops, create_ah); SET_DEVICE_OP(dev_ops, create_counters); SET_DEVICE_OP(dev_ops, create_cq); + SET_DEVICE_OP(dev_ops, create_dek); SET_DEVICE_OP(dev_ops, create_flow); SET_DEVICE_OP(dev_ops, create_qp); SET_DEVICE_OP(dev_ops, create_rwq_ind_table); @@ -2632,6 +2633,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops) SET_DEVICE_OP(dev_ops, destroy_ah); SET_DEVICE_OP(dev_ops, destroy_counters); SET_DEVICE_OP(dev_ops, destroy_cq); + SET_DEVICE_OP(dev_ops, destroy_dek); SET_DEVICE_OP(dev_ops, destroy_flow); SET_DEVICE_OP(dev_ops, destroy_flow_action); SET_DEVICE_OP(dev_ops, destroy_qp); diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 26b021f43ba4..03633d706106 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2306,6 +2306,38 @@ struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd, } EXPORT_SYMBOL(ib_alloc_mr_integrity); +/** + * ib_create_dek - Create a DEK (Data Encryption Key) associated with the + * specific protection domain. + * @pd: The protection domain associated with the DEK. + * @attr: The attributes of the DEK. + * + * Return: Allocated DEK in case of success; IS_ERR() is true in case of an + * error, PTR_ERR() returns the error code. + */ +struct ib_dek *ib_create_dek(struct ib_pd *pd, struct ib_dek_attr *attr) +{ + struct ib_device *device = pd->device; + + if (!device->ops.create_dek || !device->ops.destroy_dek) + return ERR_PTR(-EOPNOTSUPP); + + return device->ops.create_dek(pd, attr); +} +EXPORT_SYMBOL(ib_create_dek); + +/** + * ib_destroy_dek - Destroys the specified DEK. + * @dek: The DEK to destroy. + */ +void ib_destroy_dek(struct ib_dek *dek) +{ + struct ib_device *device = dek->pd->device; + + device->ops.destroy_dek(dek); +} +EXPORT_SYMBOL(ib_destroy_dek); + /* Multicast groups */ static bool is_valid_mcast_lid(struct ib_qp *qp, u16 lid) diff --git a/include/rdma/crypto.h b/include/rdma/crypto.h index 4779eacb000e..cdf287c94737 100644 --- a/include/rdma/crypto.h +++ b/include/rdma/crypto.h @@ -34,4 +34,42 @@ struct ib_crypto_caps { u32 max_num_deks; }; +/** + * enum ib_crypto_key_type - Cryptographic key types + * @IB_CRYPTO_KEY_TYPE_AES_XTS: Key of type AES-XTS, which can be used when + * IB_CRYPTO_AES_XTS is supported. + */ +enum ib_crypto_key_type { + IB_CRYPTO_KEY_TYPE_AES_XTS, +}; + +/** + * struct ib_dek_attr - Parameters for DEK (Data Encryption Key) + * @key_blob: the key blob that will be used for encryption and decryption of + * transmitted data. Actual size and layout of this field depends on the + * provided key_type and key_blob_size. + * The layout of AES_XTS key is: key1_128b + key2_128b or key1_256b + + * key2_256b. + * @key_blob_size: size of the key blob in bytes. + * @key_type: specific cryptographic key type. + */ +struct ib_dek_attr { + const void *key_blob; + u32 key_blob_size; + enum ib_crypto_key_type key_type; +}; + +/** + * struct ib_dek - Data Encryption Key + * @pd: The protection domain associated with the DEK. + * @id: DEK identifier. + */ +struct ib_dek { + struct ib_pd *pd; + u32 id; +}; + +struct ib_dek *ib_create_dek(struct ib_pd *pd, struct ib_dek_attr *attr); +void ib_destroy_dek(struct ib_dek *dek); + #endif /* _RDMA_CRYPTO_H_ */ diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 83be7e49c5f7..5fb42d553ca1 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2512,6 +2512,9 @@ struct ib_device_ops { struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd, u32 max_num_data_sg, u32 max_num_meta_sg); + struct ib_dek *(*create_dek)(struct ib_pd *pd, + struct ib_dek_attr *attr); + void (*destroy_dek)(struct ib_dek *dek); int (*advise_mr)(struct ib_pd *pd, enum ib_uverbs_advise_mr_advice advice, u32 flags, struct ib_sge *sg_list, u32 num_sge, -- 2.39.0