From: Satya Tangirala <satyaprateek2357@gmail.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Eric Biggers <ebiggers@google.com>,
Satya Tangirala <satyaprateek2357@gmail.com>,
Satya Tangirala <satyat@google.com>
Subject: [PATCH v4 1/9] block: introduce blk_ksm_is_empty()
Date: Tue, 6 Jul 2021 22:29:35 -0700 [thread overview]
Message-ID: <20210707052943.3960-2-satyaprateek2357@gmail.com> (raw)
In-Reply-To: <20210707052943.3960-1-satyaprateek2357@gmail.com>
From: Satya Tangirala <satyat@google.com>
This function checks if a given keyslot manager supports any encryption
mode/data unit size combination (and returns true if there is no such
supported combination). Helps clean up code a little.
Signed-off-by: Satya Tangirala <satyat@google.com>
---
block/keyslot-manager.c | 31 +++++++++++++++++++++++++++++++
drivers/md/dm-table.c | 11 +----------
include/linux/keyslot-manager.h | 2 ++
3 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c
index 2c4a55bea6ca..4d0794506d43 100644
--- a/block/keyslot-manager.c
+++ b/block/keyslot-manager.c
@@ -437,6 +437,37 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm)
}
EXPORT_SYMBOL_GPL(blk_ksm_destroy);
+/*
+ * Returns true iff @ksm doesn't support any crypto capabilities if
+ * @dus_allowed_mask were applied to each crypto mode of @ksm.
+ */
+static inline bool blk_ksm_is_empty_mask(struct blk_keyslot_manager *ksm,
+ unsigned long dus_allowed_mask)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) {
+ if (ksm->crypto_modes_supported[i] & dus_allowed_mask)
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * blk_ksm_is_empty() - Checks if the keyslot manager has any crypto
+ * capabilities at all.
+ * @ksm: The input keyslot manager to check
+ *
+ * Return: true if @ksm doesn't have any crypto capabilities at all, and
+ * false otherwise.
+ */
+bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm)
+{
+ return blk_ksm_is_empty_mask(ksm, ~0);
+}
+EXPORT_SYMBOL_GPL(blk_ksm_is_empty);
+
bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q)
{
if (blk_integrity_queue_supports_integrity(q)) {
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index ee47a332b462..29cbfc3e3c4b 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1295,7 +1295,6 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t)
struct blk_keyslot_manager *ksm;
struct dm_target *ti;
unsigned int i;
- bool ksm_is_empty = true;
dksm = kmalloc(sizeof(*dksm), GFP_KERNEL);
if (!dksm)
@@ -1332,15 +1331,7 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t)
* If the new KSM doesn't actually support any crypto modes, we may as
* well represent it with a NULL ksm.
*/
- ksm_is_empty = true;
- for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) {
- if (ksm->crypto_modes_supported[i]) {
- ksm_is_empty = false;
- break;
- }
- }
-
- if (ksm_is_empty) {
+ if (blk_ksm_is_empty(ksm)) {
dm_destroy_keyslot_manager(ksm);
ksm = NULL;
}
diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h
index a27605e2f826..0f09b4f310f7 100644
--- a/include/linux/keyslot-manager.h
+++ b/include/linux/keyslot-manager.h
@@ -106,6 +106,8 @@ void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm);
void blk_ksm_destroy(struct blk_keyslot_manager *ksm);
+bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm);
+
void blk_ksm_intersect_modes(struct blk_keyslot_manager *parent,
const struct blk_keyslot_manager *child);
--
2.25.1
next prev parent reply other threads:[~2021-07-07 5:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-07 5:29 [PATCH v4 0/9] ensure bios aren't split in middle of crypto data unit Satya Tangirala
2021-07-07 5:29 ` Satya Tangirala [this message]
2021-07-23 16:45 ` [PATCH v4 1/9] block: introduce blk_ksm_is_empty() Eric Biggers
2021-07-07 5:29 ` [PATCH v4 2/9] block: blk-crypto: introduce blk_crypto_bio_sectors_alignment() Satya Tangirala
2021-07-23 16:45 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 3/9] block: introduce bio_required_sector_alignment() Satya Tangirala
2021-07-23 16:46 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 4/9] block: keyslot-manager: introduce blk_ksm_restrict_dus_to_queue_limits() Satya Tangirala
2021-07-23 17:08 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 5/9] ufshcd: handle error from blk_ksm_register() Satya Tangirala
2021-07-23 17:13 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 6/9] mmc: " Satya Tangirala
2021-07-07 5:29 ` [PATCH v4 7/9] dm: " Satya Tangirala
2021-07-23 17:26 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 8/9] blk-merge: Ensure bios aren't split in middle of a crypto data unit Satya Tangirala
2021-07-23 18:11 ` Eric Biggers
2021-07-07 5:29 ` [PATCH v4 9/9] block: add WARN_ON_ONCE() to bio_split() for sector alignment Satya Tangirala
2021-07-23 17:30 ` Eric Biggers
2021-07-23 16:49 ` [PATCH v4 0/9] ensure bios aren't split in middle of crypto data unit Eric Biggers
2021-07-23 17:52 ` Eric Biggers
2021-07-24 7:36 ` Christoph Hellwig
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=20210707052943.3960-2-satyaprateek2357@gmail.com \
--to=satyaprateek2357@gmail.com \
--cc=axboe@kernel.dk \
--cc=ebiggers@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@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).