From 273b99c30ab10f614a6a16223337f11746e4b227 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 26 Jul 2021 09:27:15 -0700 Subject: [PATCH] ANDROID: scsi: ufs: add vendor hook to override key reprogramming Some hardware has a way to restore all keyslots at once that is significantly faster than restoring each keyslot individually, as is done by blk_ksm_reprogram_all_keys(). Add a hook "android_rvh_ufs_reprogram_all_keys" that allows overriding the restoration of all keyslots after UFS reset. This may sleep, so this must be a "restricted" Android vendor hook rather than a regular one. Note that currently this functionality can't be upstreamed, as support for the hardware that needs it would need to be upstreamed first. (cherry picked from commit e2e063f5074e2e14a96875e5e5670314a41e1c34) Bug: 160883801 Bug: 181905172 Bug: 241106918 Signed-off-by: Eric Biggers Signed-off-by: Kenny Root Change-Id: I0b25393a5131941f085892560e08a64e63cd1369 --- drivers/android/vendor_hooks.c | 1 + drivers/ufs/core/ufshcd-crypto.c | 9 ++++++++- include/trace/hooks/ufshcd.h | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index a1ad4ca56e5c..24a4c2b700c6 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -130,6 +130,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_si_mem_available_adjust); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_si_meminfo_adjust); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_si_meminfo_adjust_shmem); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_fill_prdt); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_ufs_reprogram_all_keys); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_prepare_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_update_sysfs); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_command); diff --git a/drivers/ufs/core/ufshcd-crypto.c b/drivers/ufs/core/ufshcd-crypto.c index 7d3a3e228db0..439c29a1a380 100644 --- a/drivers/ufs/core/ufshcd-crypto.c +++ b/drivers/ufs/core/ufshcd-crypto.c @@ -6,6 +6,9 @@ #include #include "ufshcd-crypto.h" +#undef CREATE_TRACE_POINTS +#include + /* Blk-crypto modes supported by UFS crypto */ static const struct ufs_crypto_alg_entry { enum ufs_crypto_alg ufs_alg; @@ -116,11 +119,15 @@ static int ufshcd_crypto_keyslot_evict(struct blk_crypto_profile *profile, */ bool ufshcd_crypto_enable(struct ufs_hba *hba) { + int err = -EOPNOTSUPP; + if (!(hba->caps & UFSHCD_CAP_CRYPTO)) return false; /* Reset might clear all keys, so reprogram all the keys. */ - blk_crypto_reprogram_all_keys(&hba->crypto_profile); + trace_android_rvh_ufs_reprogram_all_keys(hba, &err); + if (err == -EOPNOTSUPP) + blk_crypto_reprogram_all_keys(&hba->crypto_profile); if (hba->quirks & UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE) return false; diff --git a/include/trace/hooks/ufshcd.h b/include/trace/hooks/ufshcd.h index c2aceeba6f47..519ae55ac2e8 100644 --- a/include/trace/hooks/ufshcd.h +++ b/include/trace/hooks/ufshcd.h @@ -22,6 +22,10 @@ DECLARE_HOOK(android_vh_ufs_fill_prdt, unsigned int segments, int *err), TP_ARGS(hba, lrbp, segments, err)); +DECLARE_RESTRICTED_HOOK(android_rvh_ufs_reprogram_all_keys, + TP_PROTO(struct ufs_hba *hba, int *err), + TP_ARGS(hba, err), 1); + DECLARE_HOOK(android_vh_ufs_prepare_command, TP_PROTO(struct ufs_hba *hba, struct request *rq, struct ufshcd_lrb *lrbp, int *err),