linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Satya Tangirala <satyat@google.com>
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-ext4@vger.kernel.org,
	Barani Muthukumaran <bmuthuku@qti.qualcomm.com>,
	Kuohong Wang <kuohong.wang@mediatek.com>,
	Kim Boojin <boojin.kim@samsung.com>
Subject: Re: [PATCH v8 01/11] block: Keyslot Manager for Inline Encryption
Date: Sun, 15 Mar 2020 13:08:11 -0700	[thread overview]
Message-ID: <20200315200811.GG1055@sol.localdomain> (raw)
In-Reply-To: <20200312080253.3667-2-satyat@google.com>

On Thu, Mar 12, 2020 at 01:02:43AM -0700, Satya Tangirala wrote:
> +/**
> + * blk_ksm_init() - Initialize a keyslot manager
> + * @ksm: The keyslot_manager to initialize.
> + * @dev: Device for runtime power management (NULL if none)
> + * @num_slots: The number of key slots to manage.
> + *
> + * Allocate memory for keyslots and initialize a keyslot manager. Called by
> + * e.g. storage drivers to set up a keyslot manager in their request_queue.
> + *
> + * Return: 0 on success, or else a negative error code.
> + */
> +int blk_ksm_init(struct keyslot_manager *ksm, struct device *dev,
> +		 unsigned int num_slots)
> +{
> +	unsigned int slot;
> +	unsigned int i;
> +
> +	memset(ksm, 0, sizeof(*ksm));
> +
> +	if (num_slots == 0)
> +		return -EINVAL;
> +
> +	ksm->slots = kvcalloc(num_slots, sizeof(ksm->slots[0]), GFP_KERNEL);
> +	if (!ksm->slots)
> +		return -ENOMEM;
> +
> +	ksm->num_slots = num_slots;
> +	ksm->dev = dev;

Seems that now that keyslot_manager::dev is an unconditional field and callers
initialize other fields of the keyslot_manager, the 'dev' parameter should be
removed from blk_ksm_init() and the caller should be responsible for setting
'dev' if they need runtime power management.

> +/**
> + * blk_ksm_get_slot_for_key() - Program a key into a keyslot.
> + * @ksm: The keyslot manager to program the key into.
> + * @key: Pointer to the key object to program, including the raw key, crypto
> + *	 mode, and data unit size.
> + * @keyslot: A pointer to return the pointer of the allocated keyslot.
> + *
> + * Get a keyslot that's been programmed with the specified key.  If one already
> + * exists, return it with incremented refcount.  Otherwise, wait for a keyslot
> + * to become idle and program it.
> + *
> + * Context: Process context. Takes and releases ksm->lock.
> + * Return: BLK_STATUS_OK on success (and keyslot is set to the pointer of the
> + *	   allocated keyslot), and BLK_STATUS_IOERR otherwise (and keyslot is
> + *	   set to NULL).
> + */

There can be other errors besides BLK_STATUS_IOERR returned.

> +/**
> + * blk_ksm_put_slot() - Release a reference to a slot
> + * @slot: The keyslot to release the reference of.
> + *
> + * Context: Any context.
> + */
> +void blk_ksm_put_slot(struct blk_ksm_keyslot *slot)
> +{
> +	struct keyslot_manager *ksm = slot->ksm;
> +	unsigned long flags;
> +
> +	if (!slot)
> +		return;
> +
> +	if (atomic_dec_and_lock_irqsave(&slot->slot_refs,
> +					&ksm->idle_slots_lock, flags)) {
> +		list_add_tail(&slot->idle_slot_node,
> +			      &ksm->idle_slots);

Nit: the arguments to list_add_tail() fit on one line

> diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h
> new file mode 100644
> index 000000000000..7f88ed02faee
> --- /dev/null
> +++ b/include/linux/keyslot-manager.h
> @@ -0,0 +1,108 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright 2019 Google LLC
> + */
> +
> +#ifndef __LINUX_KEYSLOT_MANAGER_H
> +#define __LINUX_KEYSLOT_MANAGER_H
> +
> +#include <linux/bio.h>
> +#include <linux/blk-crypto.h>
> +
> +struct keyslot_manager;
> +
> +/**
> + * struct keyslot_mgmt_ll_ops - functions to manage keyslots in hardware
> + * @keyslot_program:	Program the specified key into the specified slot in the
> + *			inline encryption hardware.
> + * @keyslot_evict:	Evict key from the specified keyslot in the hardware.
> + *			The key is provided so that e.g. dm layers can evict
> + *			keys from the devices that they map over.
> + *			Returns 0 on success, -errno otherwise.
> + *
> + * This structure should be provided by storage device drivers when they set up
> + * a keyslot manager - this structure holds the function ptrs that the keyslot
> + * manager will use to manipulate keyslots in the hardware.
> + */
> +struct keyslot_mgmt_ll_ops {
> +	blk_status_t (*keyslot_program)(struct keyslot_manager *ksm,
> +					const struct blk_crypto_key *key,
> +					unsigned int slot);
> +	int (*keyslot_evict)(struct keyslot_manager *ksm,
> +			     const struct blk_crypto_key *key,
> +			     unsigned int slot);
> +};

As I mentioned on one of the UFS patches, I'm not sure it's better to make
keyslot_program return blk_status_t rather than errno as it did before.
blk_ksm_get_slot_for_key() could just do the translation to blk_status_t.

> +struct keyslot_manager {

Now that the "blk_" prefix has been added to all the functions, perhaps the
actual struct should be renamed to "blk_keyslot_manager" too?
And likewise "blk_keyslot_mgmt_ll_ops".

  reply	other threads:[~2020-03-15 20:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12  8:02 [PATCH v8 00/11] Inline Encryption Support Satya Tangirala
2020-03-12  8:02 ` [PATCH v8 01/11] block: Keyslot Manager for Inline Encryption Satya Tangirala
2020-03-15 20:08   ` Eric Biggers [this message]
2020-03-12  8:02 ` [PATCH v8 02/11] block: Inline encryption support for blk-mq Satya Tangirala
2020-03-19 11:01   ` Christoph Hellwig
2020-03-12  8:02 ` [PATCH v8 03/11] block: Make blk-integrity preclude hardware inline encryption Satya Tangirala
2020-03-15 20:16   ` Eric Biggers
2020-03-19 11:04   ` Christoph Hellwig
2020-03-12  8:02 ` [PATCH v8 04/11] block: blk-crypto-fallback for Inline Encryption Satya Tangirala
2020-03-12  8:02 ` [PATCH v8 05/11] scsi: ufs: UFS driver v2.1 spec crypto additions Satya Tangirala
2020-03-12  8:02 ` [PATCH v8 06/11] scsi: ufs: UFS crypto API Satya Tangirala
2020-03-15 18:24   ` Eric Biggers
2020-03-12  8:02 ` [PATCH v8 07/11] scsi: ufs: Add inline encryption support to UFS Satya Tangirala
2020-03-15 18:38   ` Eric Biggers
2020-03-15 18:48   ` Eric Biggers
2020-03-12  8:02 ` [PATCH v8 08/11] fs: introduce SB_INLINECRYPT Satya Tangirala
2020-03-15 19:05   ` Eric Biggers
2020-03-12  8:02 ` [PATCH v8 09/11] fscrypt: add inline encryption support Satya Tangirala
2020-03-15 17:20   ` Eric Biggers
2020-03-12  8:02 ` [PATCH v8 10/11] f2fs: " Satya Tangirala
2020-03-15 17:16   ` Eric Biggers
2020-03-12  8:02 ` [PATCH v8 11/11] ext4: " Satya Tangirala
2020-03-12 15:43 ` [PATCH v8 00/11] Inline Encryption Support Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200315200811.GG1055@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=bmuthuku@qti.qualcomm.com \
    --cc=boojin.kim@samsung.com \
    --cc=kuohong.wang@mediatek.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=satyat@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).