blob: ddb81766b134b949a6b9ab89c34eb66fecd9f0d2 [file] [log] [blame]
AnilKumar Chimatae78789a2017-04-07 12:18:46 -07001Introduction:
2=============
3Storage encryption has been one of the most required feature from security
4point of view. QTI based storage encryption solution uses general purpose
5crypto engine. While this kind of solution provide a decent amount of
6performance, it falls short as storage speed is improving significantly
7continuously. To overcome performance degradation, newer chips are going to
8have Inline Crypto Engine (ICE) embedded into storage device. ICE is supposed
9to meet the line speed of storage devices.
10
11Hardware Description
12====================
13ICE is a HW block that is embedded into storage device such as UFS/eMMC. By
14default, ICE works in bypass mode i.e. ICE HW does not perform any crypto
15operation on data to be processed by storage device. If required, ICE can be
16configured to perform crypto operation in one direction (i.e. either encryption
17or decryption) or in both direction(both encryption & decryption).
18
19When a switch between the operation modes(plain to crypto or crypto to plain)
20is desired for a particular partition, SW must complete all transactions for
21that particular partition before switching the crypto mode i.e. no crypto, one
22direction crypto or both direction crypto operation. Requests for other
23partitions are not impacted due to crypto mode switch.
24
25ICE HW currently supports AES128/256 bit ECB & XTS mode encryption algorithms.
26
27Keys for crypto operations are loaded from SW. Keys are stored in a lookup
28table(LUT) located inside ICE HW. Maximum of 32 keys can be loaded in ICE key
29LUT. A Key inside the LUT can be referred using a key index.
30
31SW Description
32==============
33ICE HW has catagorized ICE registers in 2 groups: those which can be accessed by
34only secure side i.e. TZ and those which can be accessed by non-secure side such
35as HLOS as well. This requires that ICE driver to be split in two pieces: one
36running from TZ space and another from HLOS space.
37
38ICE driver from TZ would configure keys as requested by HLOS side.
39
40ICE driver on HLOS side is responsible for initialization of ICE HW.
41
42SW Architecture Diagram
43=======================
44Following are all the components involved in the ICE driver for control path:
45
46+++++++++++++++++++++++++++++++++++++++++
47+ App layer +
48+++++++++++++++++++++++++++++++++++++++++
49+ System layer +
50+ ++++++++ +++++++ +
51+ + VOLD + + PFM + +
52+ ++++++++ +++++++ +
53+ || || +
54+ || || +
55+ \/ \/ +
56+ ++++++++++++++ +
57+ + LibQSEECom + +
58+ ++++++++++++++ +
59+++++++++++++++++++++++++++++++++++++++++
60+ Kernel + +++++++++++++++++
61+ + + KMS +
62+ +++++++ +++++++++++ +++++++++++ + +++++++++++++++++
63+ + ICE + + Storage + + QSEECom + + + ICE Driver +
64+++++++++++++++++++++++++++++++++++++++++ <===> +++++++++++++++++
65 || ||
66 || ||
67 \/ \/
68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69+ Storage Device +
70+ ++++++++++++++ +
71+ + ICE HW + +
72+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73
74Use Cases:
75----------
76a) Device bootup
77ICE HW is detected during bootup time and corresponding probe function is
78called. ICE driver parses its data from device tree node. ICE HW and storage
79HW are tightly coupled. Storage device probing is dependent upon ICE device
80probing. ICE driver configures all the required registers to put the ICE HW
81in bypass mode.
82
83b) Configuring keys
84Currently, there are couple of use cases to configure the keys.
85
861) Full Disk Encryption(FDE)
87System layer(VOLD) at invocation of apps layer would call libqseecom to create
88the encryption key. Libqseecom calls qseecom driver to communicate with KMS
89module on the secure side i.e. TZ. KMS would call ICE driver on the TZ side to
90create and set the keys in ICE HW. At the end of transaction, VOLD would have
91key index of key LUT where encryption key is present.
92
932) Per File Encryption (PFE)
94Per File Manager(PFM) calls QSEECom api to create the key. PFM has a peer comp-
95onent(PFT) at kernel layer which gets the corresponding key index from PFM.
96
97Following are all the components involved in the ICE driver for data path:
98
99+++++++++++++++++++++++++++++++++++++++++
100+ App layer +
101+++++++++++++++++++++++++++++++++++++++++
102+ VFS +
103+---------------------------------------+
104+ File System (EXT4) +
105+---------------------------------------+
106+ Block Layer +
107+ --------------------------------------+
108+ +++++++ +
109+ dm-req-crypt => + PFT + +
110+ +++++++ +
111+ +
112+---------------------------------------+
113+ +++++++++++ +++++++ +
114+ + Storage + + ICE + +
115+++++++++++++++++++++++++++++++++++++++++
116+ || +
117+ || (Storage Req with +
118+ \/ ICE parameters ) +
119+++++++++++++++++++++++++++++++++++++++++
120+ Storage Device +
121+ ++++++++++++++ +
122+ + ICE HW + +
123+++++++++++++++++++++++++++++++++++++++++
124
125c) Data transaction
126Once the crypto key has been configured, VOLD/PFM creates device mapping for
127data partition. As part of device mapping VOLD passes key index, crypto
128algorithm, mode and key length to dm layer. In case of PFE, keys are provided
129by PFT as and when request is processed by dm-req-crypt. When any application
130needs to read/write data, it would go through DM layer which would add crypto
131information, provided by VOLD/PFT, to Request. For each Request, Storage driver
132would ask ICE driver to configure crypto part of request. ICE driver extracts
133crypto data from Request structure and provide it to storage driver which would
134finally dispatch request to storage device.
135
136d) Error Handling
137Due to issue # 1 mentioned in "Known Issues", ICE driver does not register for
138any interrupt. However, it enables sources of interrupt for ICE HW. After each
139data transaction, Storage driver receives transaction completion event. As part
140of event handling, storage driver calls ICE driver to check if any of ICE
141interrupt status is set. If yes, storage driver returns error to upper layer.
142
143Error handling would be changed in future chips.
144
145Interfaces
146==========
147ICE driver exposes interfaces for storage driver to :
1481. Get the global instance of ICE driver
1492. Get the implemented interfaces of the particular ice instance
1503. Initialize the ICE HW
1514. Reset the ICE HW
1525. Resume/Suspend the ICE HW
1536. Get the Crypto configuration for the data request for storage
1547. Check if current data transaction has generated any interrupt
155
156Driver Parameters
157=================
158This driver is built and statically linked into the kernel; therefore,
159there are no module parameters supported by this driver.
160
161There are no kernel command line parameters supported by this driver.
162
163Power Management
164================
165ICE driver does not do power management on its own as it is part of storage
166hardware. Whenever storage driver receives request for power collapse/suspend
167resume, it would call ICE driver which exposes APIs for Storage HW. ICE HW
168during power collapse or reset, wipes crypto configuration data. When ICE
169driver receives request to resume, it would ask ICE driver on TZ side to
170restore the configuration. ICE driver does not do anything as part of power
171collapse or suspend event.
172
173Interface:
174==========
175ICE driver exposes following APIs for storage driver to use:
176
177int (*init)(struct platform_device *, void *, ice_success_cb, ice_error_cb);
178 -- This function is invoked by storage controller during initialization of
179 storage controller. Storage controller would provide success and error call
180 backs which would be invoked asynchronously once ICE HW init is done.
181
182int (*reset)(struct platform_device *);
183 -- ICE HW reset as part of storage controller reset. When storage controller
184 received reset command, it would call reset on ICE HW. As of now, ICE HW
185 does not need to do anything as part of reset.
186
187int (*resume)(struct platform_device *);
188 -- ICE HW while going to reset, wipes all crypto keys and other data from ICE
189 HW. ICE driver would reconfigure those data as part of resume operation.
190
191int (*suspend)(struct platform_device *);
192 -- This API would be called by storage driver when storage device is going to
193 suspend mode. As of today, ICE driver does not do anything to handle suspend.
194
195int (*config)(struct platform_device *, struct request* , struct ice_data_setting*);
196 -- Storage driver would call this interface to get all crypto data required to
197 perform crypto operation.
198
199int (*status)(struct platform_device *);
200 -- Storage driver would call this interface to check if previous data transfer
201 generated any error.
202
203Config options
204==============
205This driver is enabled by the kernel config option CONFIG_CRYPTO_DEV_MSM_ICE.
206
207Dependencies
208============
209ICE driver depends upon corresponding ICE driver on TZ side to function
210appropriately.
211
212Known Issues
213============
2141. ICE HW emits 0s even if it has generated an interrupt
215This issue has significant impact on how ICE interrupts are handled. Currently,
216ICE driver does not register for any of the ICE interrupts but enables the
217sources of interrupt. Once storage driver asks to check the status of interrupt,
218it reads and clears the clear status and provide read status to storage driver.
219This mechanism though not optimal but prevents filesystem curruption.
220This issue has been fixed in newer chips.
221
2222. ICE HW wipes all crypto data during power collapse
223This issue necessiate that ICE driver on TZ side store the crypto material
224which is not required in the case of general purpose crypto engine.
225This issue has been fixed in newer chips.
226
227Further Improvements
228====================
229Currently, Due to PFE use case, ICE driver is dependent upon dm-req-crypt to
230provide the keys as part of request structure. This couples ICE driver with
231dm-req-crypt based solution. It is under discussion to expose an IOCTL based
232and registeration based interface APIs from ICE driver. ICE driver would use
233these two interfaces to find out if any key exists for current request. If
234yes, choose the right key index received from IOCTL or registeration based
235APIs. If not, dont set any crypto parameter in the request.