hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/ccree/cc_fips.c
....@@ -1,8 +1,9 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
2
+/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
33
44 #include <linux/kernel.h>
55 #include <linux/fips.h>
6
+#include <linux/notifier.h>
67
78 #include "cc_driver.h"
89 #include "cc_fips.h"
....@@ -11,6 +12,8 @@
1112
1213 struct cc_fips_handle {
1314 struct tasklet_struct tasklet;
15
+ struct notifier_block nb;
16
+ struct cc_drvdata *drvdata;
1417 };
1518
1619 /* The function called once at driver entry point to check
....@@ -46,6 +49,21 @@
4649 cc_iowrite(drvdata, CC_REG(HOST_GPR0), val);
4750 }
4851
52
+/* Push REE side FIPS test failure to TEE side */
53
+static int cc_ree_fips_failure(struct notifier_block *nb, unsigned long unused1,
54
+ void *unused2)
55
+{
56
+ struct cc_fips_handle *fips_h =
57
+ container_of(nb, struct cc_fips_handle, nb);
58
+ struct cc_drvdata *drvdata = fips_h->drvdata;
59
+ struct device *dev = drvdata_to_dev(drvdata);
60
+
61
+ cc_set_ree_fips_status(drvdata, false);
62
+ dev_info(dev, "Notifying TEE of FIPS test failure...\n");
63
+
64
+ return NOTIFY_OK;
65
+}
66
+
4967 void cc_fips_fini(struct cc_drvdata *drvdata)
5068 {
5169 struct cc_fips_handle *fips_h = drvdata->fips_handle;
....@@ -53,10 +71,10 @@
5371 if (drvdata->hw_rev < CC_HW_REV_712 || !fips_h)
5472 return;
5573
74
+ atomic_notifier_chain_unregister(&fips_fail_notif_chain, &fips_h->nb);
75
+
5676 /* Kill tasklet */
5777 tasklet_kill(&fips_h->tasklet);
58
-
59
- kfree(fips_h);
6078 drvdata->fips_handle = NULL;
6179 }
6280
....@@ -102,7 +120,7 @@
102120 cc_tee_handle_fips_error(drvdata);
103121 }
104122
105
- /* after verifing that there is nothing to do,
123
+ /* after verifying that there is nothing to do,
106124 * unmask AXI completion interrupt.
107125 */
108126 val = (CC_REG(HOST_IMR) & ~irq);
....@@ -118,7 +136,7 @@
118136 if (p_drvdata->hw_rev < CC_HW_REV_712)
119137 return 0;
120138
121
- fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL);
139
+ fips_h = devm_kzalloc(dev, sizeof(*fips_h), GFP_KERNEL);
122140 if (!fips_h)
123141 return -ENOMEM;
124142
....@@ -126,6 +144,9 @@
126144
127145 dev_dbg(dev, "Initializing fips tasklet\n");
128146 tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata);
147
+ fips_h->drvdata = p_drvdata;
148
+ fips_h->nb.notifier_call = cc_ree_fips_failure;
149
+ atomic_notifier_chain_register(&fips_fail_notif_chain, &fips_h->nb);
129150
130151 cc_tee_handle_fips_error(p_drvdata);
131152