From 8005d59933b8278e0a778a637fa767765b4d72f9 Mon Sep 17 00:00:00 2001 From: Konstantin Dorfman Date: Tue, 18 Aug 2020 18:11:05 +0300 Subject: [PATCH] soc: qcom: add disable/enable SPSS SSR ioctl() During SPSS firmware update by fota, SPSS SSR causes cryptographic erase of Secure Processor user data. To mitigate this, instead of related SSR, platform reboot requested during fota update. In the end of fota update, SPSS SSR re-enabled. This change adds ioctl() to update internal driver configuration (functionally disable or enable SSR). Change-Id: I1d8362b4691e1a335f7f1f29bc2358d3f9b1cb21 Signed-off-by: Konstantin Dorfman Signed-off-by: Nurit Lichtenstein --- drivers/soc/qcom/spss_utils.c | 24 +++++++++++++++++++++++- include/uapi/linux/spss_utils.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/spss_utils.c b/drivers/soc/qcom/spss_utils.c index 6343986e6b0b..4dc78a7898dd 100644 --- a/drivers/soc/qcom/spss_utils.c +++ b/drivers/soc/qcom/spss_utils.c @@ -34,6 +34,7 @@ #include /* SZ_4K */ #include /* copy_from_user() */ #include /* wait_for_completion_timeout() */ +#include /* kernel_restart() */ #include #include @@ -84,6 +85,7 @@ static u32 saved_apps_cmac[NUM_UEFI_APPS][CMAC_SIZE_IN_DWORDS]; static u32 iar_state; static bool is_iar_enabled; +static bool ssr_disabled_flag; static void __iomem *cmac_mem; static size_t cmac_mem_size = SZ_4K; /* XPU align to 4KB */ @@ -598,9 +600,23 @@ static long spss_utils_ioctl(struct file *file, return ret; break; + case SPSS_IOC_SET_SSR_STATE: + /* check input params */ + if (size != sizeof(uint32_t)) { + pr_err("cmd [0x%x] invalid size [0x%x]\n", cmd, size); + return -EINVAL; + } + + if (is_iar_active) { + memcpy(&ssr_disabled_flag, data, size); + pr_debug("SSR disabled state updated to: %d\n", + ssr_disabled_flag); + } + break; + default: pr_err("invalid ioctl cmd [0x%x]\n", cmd); - return -EINVAL; + return -ENOIOCTLCMD; } return 0; @@ -1116,6 +1132,10 @@ static int spss_utils_pil_callback(struct notifier_block *nb, break; case SUBSYS_BEFORE_POWERUP: pr_debug("[SUBSYS_BEFORE_POWERUP] event.\n"); + if (is_iar_active && ssr_disabled_flag) { + pr_warn("SPSS SSR disabled, requesting reboot\n"); + kernel_restart("SPSS SSR disabled, requesting reboot"); + } break; case SUBSYS_AFTER_POWERUP: pr_debug("[SUBSYS_AFTER_POWERUP] event.\n"); @@ -1233,6 +1253,8 @@ static int spss_probe(struct platform_device *pdev) } mutex_init(&event_lock); + ssr_disabled_flag = false; + pr_info("Probe completed successfully, [%s].\n", firmware_name); return 0; diff --git a/include/uapi/linux/spss_utils.h b/include/uapi/linux/spss_utils.h index 2c58f90aaa11..0220a2af477d 100644 --- a/include/uapi/linux/spss_utils.h +++ b/include/uapi/linux/spss_utils.h @@ -78,4 +78,7 @@ struct spss_ioc_is_signaled { #define SPSS_IOC_IS_EVENT_SIGNALED \ _IOWR(SPSS_IOC_MAGIC, 4, struct spss_ioc_is_signaled) +#define SPSS_IOC_SET_SSR_STATE \ + _IOWR(SPSS_IOC_MAGIC, 5, __u32) + #endif /* _UAPI_SPSS_UTILS_H_ */