diff mbox series

[rdma-next,12/13] nvme: Add crypto profile at nvme controller

Message ID efc8dc5952baa096a14db1761f84a5ab2e76654a.1673873422.git.leon@kernel.org (mailing list archive)
State Changes Requested
Headers show
Series Add RDMA inline crypto support | expand

Commit Message

Leon Romanovsky Jan. 16, 2023, 1:05 p.m. UTC
From: Israel Rukshin <israelr@nvidia.com>

The crypto profile will be filled by the transport drivers. This
is a preparation patch for adding support of inline encryption
at nvme-rdma driver.

Signed-off-by: Israel Rukshin <israelr@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
---
 drivers/nvme/host/core.c | 3 +++
 drivers/nvme/host/nvme.h | 4 ++++
 2 files changed, 7 insertions(+)

Comments

Chaitanya Kulkarni Jan. 17, 2023, 12:31 a.m. UTC | #1
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 51a9880db6ce..f09e4e0216b3 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1928,6 +1928,9 @@ static void nvme_update_disk_info(struct gendisk *disk,
>   			capacity = 0;
>   	}
>   
> +	if (ctrl->crypto_enable)
> +		blk_crypto_register(&ctrl->crypto_profile, disk->queue);
> +
>   	set_capacity_and_notify(disk, capacity);
>   
>   	nvme_config_discard(disk, ns);
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 424c8a467a0c..591380f53744 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -16,6 +16,7 @@
>   #include <linux/rcupdate.h>
>   #include <linux/wait.h>
>   #include <linux/t10-pi.h>
> +#include <linux/blk-crypto-profile.h>
>   
>   #include <trace/events/block.h>
>   
> @@ -374,6 +375,9 @@ struct nvme_ctrl {
>   
>   	enum nvme_ctrl_type cntrltype;
>   	enum nvme_dctype dctype;
> +
> +	bool crypto_enable;

why not decalre crypto_profile a pointer, allocate that at init
controller and NULL check against that pointer instead of using
an extra variable crypto_enable ?

e.g. :-

	if (ctrl->crypto_profile)
		blk_crypto_register(ctrl->crypto_profile, disk->queue);

> +	struct blk_crypto_profile crypto_profile;

you are increasing the size of struct nvme_ctrl unconditionally,
why not guard above with CONFIG_BLK_INLINE_ENCRYPTION ?

-ck
Leon Romanovsky Jan. 17, 2023, 11:59 a.m. UTC | #2
On Tue, Jan 17, 2023 at 12:31:22AM +0000, Chaitanya Kulkarni wrote:
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 51a9880db6ce..f09e4e0216b3 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -1928,6 +1928,9 @@ static void nvme_update_disk_info(struct gendisk *disk,
> >   			capacity = 0;
> >   	}
> >   
> > +	if (ctrl->crypto_enable)
> > +		blk_crypto_register(&ctrl->crypto_profile, disk->queue);
> > +
> >   	set_capacity_and_notify(disk, capacity);
> >   
> >   	nvme_config_discard(disk, ns);
> > diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> > index 424c8a467a0c..591380f53744 100644
> > --- a/drivers/nvme/host/nvme.h
> > +++ b/drivers/nvme/host/nvme.h
> > @@ -16,6 +16,7 @@
> >   #include <linux/rcupdate.h>
> >   #include <linux/wait.h>
> >   #include <linux/t10-pi.h>
> > +#include <linux/blk-crypto-profile.h>
> >   
> >   #include <trace/events/block.h>
> >   
> > @@ -374,6 +375,9 @@ struct nvme_ctrl {
> >   
> >   	enum nvme_ctrl_type cntrltype;
> >   	enum nvme_dctype dctype;
> > +
> > +	bool crypto_enable;
> 
> why not decalre crypto_profile a pointer, allocate that at init
> controller and NULL check against that pointer instead of using
> an extra variable crypto_enable ?

The embedded struct allows us to rely on container_of() macro.

   377 static int nvme_rdma_crypto_keyslot_program(struct blk_crypto_profile *profile,
   378                                             const struct blk_crypto_key *key,
   379                                             unsigned int slot)
   380 {
   381         struct nvme_ctrl *nctrl =
   382                 container_of(profile, struct nvme_ctrl, crypto_profile);

> 
> e.g. :-
> 
> 	if (ctrl->crypto_profile)
> 		blk_crypto_register(ctrl->crypto_profile, disk->queue);
> 
> > +	struct blk_crypto_profile crypto_profile;
> 
> you are increasing the size of struct nvme_ctrl unconditionally,
> why not guard above with CONFIG_BLK_INLINE_ENCRYPTION ?

We can do it.

Thanks

> 
> -ck
>
diff mbox series

Patch

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 51a9880db6ce..f09e4e0216b3 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1928,6 +1928,9 @@  static void nvme_update_disk_info(struct gendisk *disk,
 			capacity = 0;
 	}
 
+	if (ctrl->crypto_enable)
+		blk_crypto_register(&ctrl->crypto_profile, disk->queue);
+
 	set_capacity_and_notify(disk, capacity);
 
 	nvme_config_discard(disk, ns);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 424c8a467a0c..591380f53744 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -16,6 +16,7 @@ 
 #include <linux/rcupdate.h>
 #include <linux/wait.h>
 #include <linux/t10-pi.h>
+#include <linux/blk-crypto-profile.h>
 
 #include <trace/events/block.h>
 
@@ -374,6 +375,9 @@  struct nvme_ctrl {
 
 	enum nvme_ctrl_type cntrltype;
 	enum nvme_dctype dctype;
+
+	bool crypto_enable;
+	struct blk_crypto_profile crypto_profile;
 };
 
 enum nvme_iopolicy {