Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
ANDROID: mmc: MMC crypto API
Make mmc core able to use the blk-crypto framework for inline encryption. This patch introduces a pointer to struct keyslot_manager to struct mmc_host, and handles setting up the request_queue for devices using that keyslot_manager appropriately. It also inits struct mmc_request's inline encryption fields before it's passed to mmc_host::ops->request. Users of the core code in host/ (e.g. cqhci.c) should initialize the keyslot_manager in struct mmc_host appropriately, if they want to support inline encryption. They should also handle any inline encryption related work necessary when mmc_host::ops->request is called. This patch is only compile tested, as I don't have a device to actually test these patches. Enable CONFIG_MMC_CRYPTO to test Bug: 153512828 Bug: 144046242 Change-Id: I6f98ffadfa6e39d7fdc3752b069210ad97babd8b Co-developed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Satya Tangirala <satyat@google.com>
- Loading branch information
Satya Tangirala
committed
Apr 23, 2020
1 parent
5f5805e
commit 555cf12eb672727979bc7b7840c7503f3de27220
Showing
9 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
| /* | ||
| * Copyright 2020 Google LLC | ||
| */ | ||
|
|
||
| #include <linux/blk-crypto.h> | ||
| #include <linux/blkdev.h> | ||
| #include <linux/keyslot-manager.h> | ||
| #include <linux/mmc/host.h> | ||
|
|
||
| #include "core.h" | ||
| #include "queue.h" | ||
|
|
||
| void mmc_crypto_setup_queue(struct mmc_host *host, struct request_queue *q) | ||
| { | ||
| if (host->caps2 & MMC_CAP2_CRYPTO) | ||
| q->ksm = host->ksm; | ||
| } | ||
| EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue); | ||
|
|
||
| void mmc_crypto_free_host(struct mmc_host *host) | ||
| { | ||
| keyslot_manager_destroy(host->ksm); | ||
| } | ||
|
|
||
| void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq) | ||
| { | ||
| struct request *req = mmc_queue_req_to_req(mqrq); | ||
| struct mmc_request *mrq = &mqrq->brq.mrq; | ||
| const struct bio_crypt_ctx *bc; | ||
|
|
||
| if (!bio_crypt_should_process(req)) | ||
| return; | ||
|
|
||
| bc = req->bio->bi_crypt_context; | ||
| mrq->crypto_key_slot = bc->bc_keyslot; | ||
| mrq->data_unit_num = bc->bc_dun[0]; | ||
| mrq->crypto_key = bc->bc_key; | ||
| } | ||
| EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| /* | ||
| * Copyright 2020 Google LLC | ||
| */ | ||
|
|
||
| #ifndef _MMC_CORE_CRYPTO_H | ||
| #define _MMC_CORE_CRYPTO_H | ||
|
|
||
| struct mmc_host; | ||
| struct mmc_queue_req; | ||
| struct request; | ||
| struct request_queue; | ||
|
|
||
| #ifdef CONFIG_MMC_CRYPTO | ||
|
|
||
| void mmc_crypto_setup_queue(struct mmc_host *host, struct request_queue *q); | ||
|
|
||
| void mmc_crypto_free_host(struct mmc_host *host); | ||
|
|
||
| void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq); | ||
|
|
||
| #else /* CONFIG_MMC_CRYPTO */ | ||
|
|
||
| static inline void mmc_crypto_setup_queue(struct mmc_host *host, | ||
| struct request_queue *q) { } | ||
|
|
||
| static inline void mmc_crypto_free_host(struct mmc_host *host) { } | ||
|
|
||
| static inline void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq) { } | ||
|
|
||
| #endif /* CONFIG_MMC_CRYPTO */ | ||
|
|
||
| #endif /* _MMC_CORE_CRYPTO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters