Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'tpmdd-next-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd

Pull tpm updates from Jarkko Sakkinen:
"Quite a few commits but nothing really that would be worth of spending
too much time for, or would want to emphasize in particular"

* tag 'tpmdd-next-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
tpm_crb_ffa: handle tpm busy return code
tpm_crb_ffa: Remove memset usage
tpm_crb_ffa: Fix typos in function name
tpm: Check for completion after timeout
tpm: Use of_reserved_mem_region_to_resource() for "memory-region"
tpm: Replace scnprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show functions
tpm_crb_ffa: Remove unused export
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
firmware: arm_ffa: Change initcall level of ffa_init() to rootfs_initcall
tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC
tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC
tpm: support devices with synchronous send()
tpm: add bufsiz parameter in the .send callback

+199 -152
+8
Documentation/admin-guide/kernel-parameters.txt
··· 7214 7214 causing a major performance hit, and the space where 7215 7215 machines are deployed is by other means guarded. 7216 7216 7217 + tpm_crb_ffa.busy_timeout_ms= [ARM64,TPM] 7218 + Maximum time in milliseconds to retry sending a message 7219 + to the TPM service before giving up. This parameter controls 7220 + how long the system will continue retrying when the TPM 7221 + service is busy. 7222 + Format: <unsigned int> 7223 + Default: 2000 (2 seconds) 7224 + 7217 7225 tpm_suspend_pcr=[HW,TPM] 7218 7226 Format: integer pcr id 7219 7227 Specify that at suspend time, the tpm driver
+1 -7
drivers/char/tpm/eventlog/of.c
··· 24 24 25 25 static int tpm_read_log_memory_region(struct tpm_chip *chip) 26 26 { 27 - struct device_node *node; 28 27 struct resource res; 29 28 int rc; 30 29 31 - node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0); 32 - if (!node) 33 - return -ENODEV; 34 - 35 - rc = of_address_to_resource(node, 0, &res); 36 - of_node_put(node); 30 + rc = of_reserved_mem_region_to_resource(chip->dev.parent->of_node, 0, &res); 37 31 if (rc) 38 32 return rc; 39 33
+1 -1
drivers/char/tpm/st33zp24/st33zp24.c
··· 300 300 * send TPM commands through the I2C bus. 301 301 */ 302 302 static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, 303 - size_t len) 303 + size_t bufsiz, size_t len) 304 304 { 305 305 struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev); 306 306 u32 status, i, size, ordinal;
+33 -6
drivers/char/tpm/tpm-interface.c
··· 82 82 return chip->ops->req_canceled(chip, status); 83 83 } 84 84 85 + static bool tpm_transmit_completed(u8 status, struct tpm_chip *chip) 86 + { 87 + u8 status_masked = status & chip->ops->req_complete_mask; 88 + 89 + return status_masked == chip->ops->req_complete_val; 90 + } 91 + 85 92 static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) 86 93 { 87 94 struct tpm_header *header = buf; ··· 113 106 return -E2BIG; 114 107 } 115 108 116 - rc = chip->ops->send(chip, buf, count); 109 + rc = chip->ops->send(chip, buf, bufsiz, count); 117 110 if (rc < 0) { 118 111 if (rc != -EPIPE) 119 112 dev_err(&chip->dev, ··· 121 114 return rc; 122 115 } 123 116 124 - /* A sanity check. send() should just return zero on success e.g. 125 - * not the command length. 117 + /* 118 + * Synchronous devices return the response directly during the send() 119 + * call in the same buffer. 120 + */ 121 + if (chip->flags & TPM_CHIP_FLAG_SYNC) { 122 + len = rc; 123 + rc = 0; 124 + goto out_sync; 125 + } 126 + 127 + /* 128 + * A sanity check. send() of asynchronous devices should just return 129 + * zero on success e.g. not the command length. 126 130 */ 127 131 if (rc > 0) { 128 132 dev_warn(&chip->dev, ··· 147 129 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); 148 130 do { 149 131 u8 status = tpm_chip_status(chip); 150 - if ((status & chip->ops->req_complete_mask) == 151 - chip->ops->req_complete_val) 132 + if (tpm_transmit_completed(status, chip)) 152 133 goto out_recv; 153 134 154 135 if (tpm_chip_req_canceled(chip, status)) { ··· 159 142 rmb(); 160 143 } while (time_before(jiffies, stop)); 161 144 145 + /* 146 + * Check for completion one more time, just in case the device reported 147 + * it while the driver was sleeping in the busy loop above. 148 + */ 149 + if (tpm_transmit_completed(tpm_chip_status(chip), chip)) 150 + goto out_recv; 151 + 162 152 tpm_chip_cancel(chip); 163 153 dev_err(&chip->dev, "Operation Timed out\n"); 164 154 return -ETIME; ··· 175 151 if (len < 0) { 176 152 rc = len; 177 153 dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); 178 - } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) 154 + return rc; 155 + } 156 + out_sync: 157 + if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) 179 158 rc = -EFAULT; 180 159 181 160 return rc ? rc : len;
+2 -1
drivers/char/tpm/tpm_atmel.c
··· 148 148 return size; 149 149 } 150 150 151 - static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count) 151 + static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 152 + size_t count) 152 153 { 153 154 struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev); 154 155 int i;
+1 -1
drivers/char/tpm/tpm_crb.c
··· 426 426 } 427 427 #endif 428 428 429 - static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len) 429 + static int crb_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, size_t len) 430 430 { 431 431 struct crb_priv *priv = dev_get_drvdata(&chip->dev); 432 432 int rc = 0;
+66 -28
drivers/char/tpm/tpm_crb_ffa.c
··· 10 10 #define pr_fmt(fmt) "CRB_FFA: " fmt 11 11 12 12 #include <linux/arm_ffa.h> 13 + #include <linux/delay.h> 14 + #include <linux/moduleparam.h> 13 15 #include "tpm_crb_ffa.h" 16 + 17 + static unsigned int busy_timeout_ms = 2000; 18 + 19 + module_param(busy_timeout_ms, uint, 0644); 20 + MODULE_PARM_DESC(busy_timeout_ms, 21 + "Maximum time in ms to retry before giving up on busy"); 14 22 15 23 /* TPM service function status codes */ 16 24 #define CRB_FFA_OK 0x05000001 ··· 123 115 }; 124 116 125 117 static struct tpm_crb_ffa *tpm_crb_ffa; 118 + static struct ffa_driver tpm_crb_ffa_driver; 126 119 127 120 static int tpm_crb_ffa_to_linux_errno(int errno) 128 121 { ··· 177 168 */ 178 169 int tpm_crb_ffa_init(void) 179 170 { 171 + int ret = 0; 172 + 173 + if (!IS_MODULE(CONFIG_TCG_ARM_CRB_FFA)) { 174 + ret = ffa_register(&tpm_crb_ffa_driver); 175 + if (ret) { 176 + tpm_crb_ffa = ERR_PTR(-ENODEV); 177 + return ret; 178 + } 179 + } 180 + 180 181 if (!tpm_crb_ffa) 181 - return -ENOENT; 182 + ret = -ENOENT; 182 183 183 184 if (IS_ERR_VALUE(tpm_crb_ffa)) 184 - return -ENODEV; 185 + ret = -ENODEV; 185 186 186 - return 0; 187 + return ret; 187 188 } 188 189 EXPORT_SYMBOL_GPL(tpm_crb_ffa_init); 189 190 190 - static int __tpm_crb_ffa_send_recieve(unsigned long func_id, 191 - unsigned long a0, 192 - unsigned long a1, 193 - unsigned long a2) 191 + static int __tpm_crb_ffa_try_send_receive(unsigned long func_id, 192 + unsigned long a0, unsigned long a1, 193 + unsigned long a2) 194 194 { 195 195 const struct ffa_msg_ops *msg_ops; 196 196 int ret; 197 197 198 - if (!tpm_crb_ffa) 199 - return -ENOENT; 200 - 201 198 msg_ops = tpm_crb_ffa->ffa_dev->ops->msg_ops; 202 199 203 200 if (ffa_partition_supports_direct_req2_recv(tpm_crb_ffa->ffa_dev)) { 204 - memset(&tpm_crb_ffa->direct_msg_data2, 0x00, 205 - sizeof(struct ffa_send_direct_data2)); 206 - 207 - tpm_crb_ffa->direct_msg_data2.data[0] = func_id; 208 - tpm_crb_ffa->direct_msg_data2.data[1] = a0; 209 - tpm_crb_ffa->direct_msg_data2.data[2] = a1; 210 - tpm_crb_ffa->direct_msg_data2.data[3] = a2; 201 + tpm_crb_ffa->direct_msg_data2 = (struct ffa_send_direct_data2){ 202 + .data = { func_id, a0, a1, a2 }, 203 + }; 211 204 212 205 ret = msg_ops->sync_send_receive2(tpm_crb_ffa->ffa_dev, 213 206 &tpm_crb_ffa->direct_msg_data2); 214 207 if (!ret) 215 208 ret = tpm_crb_ffa_to_linux_errno(tpm_crb_ffa->direct_msg_data2.data[0]); 216 209 } else { 217 - memset(&tpm_crb_ffa->direct_msg_data, 0x00, 218 - sizeof(struct ffa_send_direct_data)); 219 - 220 - tpm_crb_ffa->direct_msg_data.data1 = func_id; 221 - tpm_crb_ffa->direct_msg_data.data2 = a0; 222 - tpm_crb_ffa->direct_msg_data.data3 = a1; 223 - tpm_crb_ffa->direct_msg_data.data4 = a2; 210 + tpm_crb_ffa->direct_msg_data = (struct ffa_send_direct_data){ 211 + .data1 = func_id, 212 + .data2 = a0, 213 + .data3 = a1, 214 + .data4 = a2, 215 + }; 224 216 225 217 ret = msg_ops->sync_send_receive(tpm_crb_ffa->ffa_dev, 226 218 &tpm_crb_ffa->direct_msg_data); ··· 229 219 ret = tpm_crb_ffa_to_linux_errno(tpm_crb_ffa->direct_msg_data.data1); 230 220 } 231 221 222 + return ret; 223 + } 224 + 225 + static int __tpm_crb_ffa_send_receive(unsigned long func_id, unsigned long a0, 226 + unsigned long a1, unsigned long a2) 227 + { 228 + ktime_t start, stop; 229 + int ret; 230 + 231 + if (!tpm_crb_ffa) 232 + return -ENOENT; 233 + 234 + start = ktime_get(); 235 + stop = ktime_add(start, ms_to_ktime(busy_timeout_ms)); 236 + 237 + for (;;) { 238 + ret = __tpm_crb_ffa_try_send_receive(func_id, a0, a1, a2); 239 + if (ret != -EBUSY) 240 + break; 241 + 242 + usleep_range(50, 100); 243 + if (ktime_after(ktime_get(), stop)) { 244 + dev_warn(&tpm_crb_ffa->ffa_dev->dev, 245 + "Busy retry timed out\n"); 246 + break; 247 + } 248 + } 232 249 233 250 return ret; 234 251 } ··· 273 236 * 274 237 * Return: 0 on success, negative error code on failure. 275 238 */ 276 - int tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor) 239 + static int tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor) 277 240 { 278 241 int rc; 279 242 ··· 288 251 289 252 guard(mutex)(&tpm_crb_ffa->msg_data_lock); 290 253 291 - rc = __tpm_crb_ffa_send_recieve(CRB_FFA_GET_INTERFACE_VERSION, 0x00, 0x00, 0x00); 254 + rc = __tpm_crb_ffa_send_receive(CRB_FFA_GET_INTERFACE_VERSION, 0x00, 0x00, 0x00); 292 255 if (!rc) { 293 256 if (ffa_partition_supports_direct_req2_recv(tpm_crb_ffa->ffa_dev)) { 294 257 *major = CRB_FFA_MAJOR_VERSION(tpm_crb_ffa->direct_msg_data2.data[1]); ··· 301 264 302 265 return rc; 303 266 } 304 - EXPORT_SYMBOL_GPL(tpm_crb_ffa_get_interface_version); 305 267 306 268 /** 307 269 * tpm_crb_ffa_start() - signals the TPM that a field has changed in the CRB ··· 325 289 326 290 guard(mutex)(&tpm_crb_ffa->msg_data_lock); 327 291 328 - return __tpm_crb_ffa_send_recieve(CRB_FFA_START, request_type, locality, 0x00); 292 + return __tpm_crb_ffa_send_receive(CRB_FFA_START, request_type, locality, 0x00); 329 293 } 330 294 EXPORT_SYMBOL_GPL(tpm_crb_ffa_start); 331 295 ··· 405 369 .id_table = tpm_crb_ffa_device_id, 406 370 }; 407 371 372 + #ifdef MODULE 408 373 module_ffa_driver(tpm_crb_ffa_driver); 374 + #endif 409 375 410 376 MODULE_AUTHOR("Arm"); 411 377 MODULE_DESCRIPTION("TPM CRB FFA driver");
-2
drivers/char/tpm/tpm_crb_ffa.h
··· 11 11 12 12 #if IS_REACHABLE(CONFIG_TCG_ARM_CRB_FFA) 13 13 int tpm_crb_ffa_init(void); 14 - int tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor); 15 14 int tpm_crb_ffa_start(int request_type, int locality); 16 15 #else 17 16 static inline int tpm_crb_ffa_init(void) { return 0; } 18 - static inline int tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor) { return 0; } 19 17 static inline int tpm_crb_ffa_start(int request_type, int locality) { return 0; } 20 18 #endif 21 19
+21 -45
drivers/char/tpm/tpm_ftpm_tee.c
··· 31 31 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96); 32 32 33 33 /** 34 - * ftpm_tee_tpm_op_recv() - retrieve fTPM response. 35 - * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h. 36 - * @buf: the buffer to store data. 37 - * @count: the number of bytes to read. 38 - * 39 - * Return: 40 - * In case of success the number of bytes received. 41 - * On failure, -errno. 42 - */ 43 - static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count) 44 - { 45 - struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); 46 - size_t len; 47 - 48 - len = pvt_data->resp_len; 49 - if (count < len) { 50 - dev_err(&chip->dev, 51 - "%s: Invalid size in recv: count=%zd, resp_len=%zd\n", 52 - __func__, count, len); 53 - return -EIO; 54 - } 55 - 56 - memcpy(buf, pvt_data->resp_buf, len); 57 - pvt_data->resp_len = 0; 58 - 59 - return len; 60 - } 61 - 62 - /** 63 - * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory. 34 + * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory 35 + * and retrieve the response. 64 36 * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h 65 - * @buf: the buffer to send. 66 - * @len: the number of bytes to send. 37 + * @buf: the buffer to send and to store the response. 38 + * @bufsiz: the size of the buffer. 39 + * @cmd_len: the number of bytes to send. 67 40 * 68 41 * Return: 69 - * In case of success, returns 0. 42 + * In case of success, returns the number of bytes received. 70 43 * On failure, -errno 71 44 */ 72 - static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len) 45 + static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 46 + size_t cmd_len) 73 47 { 74 48 struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); 75 49 size_t resp_len; ··· 54 80 struct tee_param command_params[4]; 55 81 struct tee_shm *shm = pvt_data->shm; 56 82 57 - if (len > MAX_COMMAND_SIZE) { 83 + if (cmd_len > MAX_COMMAND_SIZE) { 58 84 dev_err(&chip->dev, 59 85 "%s: len=%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n", 60 - __func__, len); 86 + __func__, cmd_len); 61 87 return -EIO; 62 88 } 63 89 64 90 memset(&transceive_args, 0, sizeof(transceive_args)); 65 91 memset(command_params, 0, sizeof(command_params)); 66 - pvt_data->resp_len = 0; 67 92 68 93 /* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */ 69 94 transceive_args = (struct tee_ioctl_invoke_arg) { ··· 76 103 .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT, 77 104 .u.memref = { 78 105 .shm = shm, 79 - .size = len, 106 + .size = cmd_len, 80 107 .shm_offs = 0, 81 108 }, 82 109 }; ··· 88 115 return PTR_ERR(temp_buf); 89 116 } 90 117 memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE)); 91 - memcpy(temp_buf, buf, len); 118 + memcpy(temp_buf, buf, cmd_len); 92 119 93 120 command_params[1] = (struct tee_param) { 94 121 .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT, ··· 129 156 __func__, resp_len); 130 157 return -EIO; 131 158 } 159 + if (resp_len > bufsiz) { 160 + dev_err(&chip->dev, 161 + "%s: resp_len=%zd exceeds bufsiz=%zd\n", 162 + __func__, resp_len, bufsiz); 163 + return -EIO; 164 + } 132 165 133 - /* sanity checks look good, cache the response */ 134 - memcpy(pvt_data->resp_buf, temp_buf, resp_len); 135 - pvt_data->resp_len = resp_len; 166 + memcpy(buf, temp_buf, resp_len); 136 167 137 - return 0; 168 + return resp_len; 138 169 } 139 170 140 171 static const struct tpm_class_ops ftpm_tee_tpm_ops = { 141 172 .flags = TPM_OPS_AUTO_STARTUP, 142 - .recv = ftpm_tee_tpm_op_recv, 143 173 .send = ftpm_tee_tpm_op_send, 144 174 }; 145 175 ··· 227 251 } 228 252 229 253 pvt_data->chip = chip; 230 - pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2; 254 + pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_SYNC; 231 255 232 256 /* Create a character device for the fTPM */ 233 257 rc = tpm_chip_register(pvt_data->chip);
-4
drivers/char/tpm/tpm_ftpm_tee.h
··· 22 22 * struct ftpm_tee_private - fTPM's private data 23 23 * @chip: struct tpm_chip instance registered with tpm framework. 24 24 * @session: fTPM TA session identifier. 25 - * @resp_len: cached response buffer length. 26 - * @resp_buf: cached response buffer. 27 25 * @ctx: TEE context handler. 28 26 * @shm: Memory pool shared with fTPM TA in TEE. 29 27 */ 30 28 struct ftpm_tee_private { 31 29 struct tpm_chip *chip; 32 30 u32 session; 33 - size_t resp_len; 34 - u8 resp_buf[MAX_RESPONSE_SIZE]; 35 31 struct tee_context *ctx; 36 32 struct tee_shm *shm; 37 33 };
+2 -1
drivers/char/tpm/tpm_i2c_atmel.c
··· 37 37 u8 buffer[sizeof(struct tpm_header) + 25]; 38 38 }; 39 39 40 - static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len) 40 + static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 41 + size_t len) 41 42 { 42 43 struct priv_data *priv = dev_get_drvdata(&chip->dev); 43 44 struct i2c_client *client = to_i2c_client(chip->dev.parent);
+2 -1
drivers/char/tpm/tpm_i2c_infineon.c
··· 514 514 return size; 515 515 } 516 516 517 - static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) 517 + static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 518 + size_t len) 518 519 { 519 520 int rc, status; 520 521 ssize_t burstcnt;
+2 -1
drivers/char/tpm/tpm_i2c_nuvoton.c
··· 350 350 * tpm.c can skip polling for the data to be available as the interrupt is 351 351 * waited for here 352 352 */ 353 - static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) 353 + static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 354 + size_t len) 354 355 { 355 356 struct priv_data *priv = dev_get_drvdata(&chip->dev); 356 357 struct device *dev = chip->dev.parent;
+4 -2
drivers/char/tpm/tpm_ibmvtpm.c
··· 191 191 * tpm_ibmvtpm_send() - Send a TPM command 192 192 * @chip: tpm chip struct 193 193 * @buf: buffer contains data to send 194 - * @count: size of buffer 194 + * @bufsiz: size of the buffer 195 + * @count: length of the command 195 196 * 196 197 * Return: 197 198 * 0 on success, 198 199 * -errno on error 199 200 */ 200 - static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) 201 + static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 202 + size_t count) 201 203 { 202 204 struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev); 203 205 bool retry = true;
+2 -1
drivers/char/tpm/tpm_infineon.c
··· 312 312 return -EIO; 313 313 } 314 314 315 - static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) 315 + static int tpm_inf_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 316 + size_t count) 316 317 { 317 318 int i; 318 319 int ret;
+2 -1
drivers/char/tpm/tpm_nsc.c
··· 178 178 return size; 179 179 } 180 180 181 - static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) 181 + static int tpm_nsc_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 182 + size_t count) 182 183 { 183 184 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev); 184 185 u8 data;
+25 -27
drivers/char/tpm/tpm_ppi.c
··· 52 52 { 53 53 struct tpm_chip *chip = to_tpm_chip(dev); 54 54 55 - return scnprintf(buf, PAGE_SIZE, "%s\n", chip->ppi_version); 55 + return sysfs_emit(buf, "%s\n", chip->ppi_version); 56 56 } 57 57 58 58 static ssize_t tpm_show_ppi_request(struct device *dev, ··· 87 87 else { 88 88 req = obj->package.elements[1].integer.value; 89 89 if (tpm_ppi_req_has_parameter(req)) 90 - size = scnprintf(buf, PAGE_SIZE, 91 - "%llu %llu\n", req, 92 - obj->package.elements[2].integer.value); 90 + size = sysfs_emit(buf, "%llu %llu\n", req, 91 + obj->package.elements[2].integer.value); 93 92 else 94 - size = scnprintf(buf, PAGE_SIZE, 95 - "%llu\n", req); 93 + size = sysfs_emit(buf, "%llu\n", req); 96 94 } 97 95 } else if (obj->package.count == 2 && 98 96 obj->package.elements[0].type == ACPI_TYPE_INTEGER && ··· 98 100 if (obj->package.elements[0].integer.value) 99 101 size = -EFAULT; 100 102 else 101 - size = scnprintf(buf, PAGE_SIZE, "%llu\n", 102 - obj->package.elements[1].integer.value); 103 + size = sysfs_emit(buf, "%llu\n", 104 + obj->package.elements[1].integer.value); 103 105 } 104 106 105 107 ACPI_FREE(obj); ··· 209 211 } 210 212 211 213 if (ret < ARRAY_SIZE(info) - 1) 212 - status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, info[ret]); 214 + status = sysfs_emit(buf, "%d: %s\n", ret, info[ret]); 213 215 else 214 - status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, 215 - info[ARRAY_SIZE(info)-1]); 216 + status = sysfs_emit(buf, "%d: %s\n", ret, 217 + info[ARRAY_SIZE(info) - 1]); 216 218 return status; 217 219 } 218 220 ··· 253 255 res = ret_obj[2].integer.value; 254 256 if (req) { 255 257 if (res == 0) 256 - status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, 257 - "0: Success"); 258 + status = sysfs_emit(buf, "%llu %s\n", req, 259 + "0: Success"); 258 260 else if (res == 0xFFFFFFF0) 259 - status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, 260 - "0xFFFFFFF0: User Abort"); 261 + status = sysfs_emit(buf, "%llu %s\n", req, 262 + "0xFFFFFFF0: User Abort"); 261 263 else if (res == 0xFFFFFFF1) 262 - status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, 263 - "0xFFFFFFF1: BIOS Failure"); 264 + status = sysfs_emit(buf, "%llu %s\n", req, 265 + "0xFFFFFFF1: BIOS Failure"); 264 266 else if (res >= 1 && res <= 0x00000FFF) 265 - status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n", 266 - req, res, "Corresponding TPM error"); 267 + status = sysfs_emit(buf, "%llu %llu: %s\n", 268 + req, res, "Corresponding TPM error"); 267 269 else 268 - status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n", 269 - req, res, "Error"); 270 + status = sysfs_emit(buf, "%llu %llu: %s\n", 271 + req, res, "Error"); 270 272 } else { 271 - status = scnprintf(buf, PAGE_SIZE, "%llu: %s\n", 272 - req, "No Recent Request"); 273 + status = sysfs_emit(buf, "%llu: %s\n", 274 + req, "No Recent Request"); 273 275 } 274 276 275 277 cleanup: ··· 282 284 { 283 285 int i; 284 286 u32 ret; 285 - char *str = buf; 287 + int len = 0; 286 288 union acpi_object *obj, tmp; 287 289 union acpi_object argv = ACPI_INIT_DSM_ARGV4(1, &tmp); 288 290 ··· 312 314 } 313 315 314 316 if (ret > 0 && ret < ARRAY_SIZE(info)) 315 - str += scnprintf(str, PAGE_SIZE, "%d %d: %s\n", 316 - i, ret, info[ret]); 317 + len += sysfs_emit_at(buf, len, "%d %d: %s\n", 318 + i, ret, info[ret]); 317 319 } 318 320 319 - return str - buf; 321 + return len; 320 322 } 321 323 322 324 static ssize_t tpm_show_ppi_tcg_operations(struct device *dev,
+12 -16
drivers/char/tpm/tpm_svsm.c
··· 25 25 void *buffer; 26 26 }; 27 27 28 - static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len) 28 + static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 29 + size_t cmd_len) 29 30 { 30 31 struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); 31 32 int ret; 32 33 33 - ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, len); 34 + ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, cmd_len); 34 35 if (ret) 35 36 return ret; 36 37 37 38 /* 38 39 * The SVSM call uses the same buffer for the command and for the 39 - * response, so after this call, the buffer will contain the response 40 - * that can be used by .recv() op. 40 + * response, so after this call, the buffer will contain the response. 41 + * 42 + * Note: we have to use an internal buffer because the device in SVSM 43 + * expects the svsm_vtpm header + data to be physically contiguous. 41 44 */ 42 - return snp_svsm_vtpm_send_command(priv->buffer); 43 - } 45 + ret = snp_svsm_vtpm_send_command(priv->buffer); 46 + if (ret) 47 + return ret; 44 48 45 - static int tpm_svsm_recv(struct tpm_chip *chip, u8 *buf, size_t len) 46 - { 47 - struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); 48 - 49 - /* 50 - * The internal buffer contains the response after we send the command 51 - * to SVSM. 52 - */ 53 - return svsm_vtpm_cmd_response_parse(priv->buffer, buf, len); 49 + return svsm_vtpm_cmd_response_parse(priv->buffer, buf, bufsiz); 54 50 } 55 51 56 52 static struct tpm_class_ops tpm_chip_ops = { 57 53 .flags = TPM_OPS_AUTO_STARTUP, 58 - .recv = tpm_svsm_recv, 59 54 .send = tpm_svsm_send, 60 55 }; 61 56 ··· 79 84 80 85 dev_set_drvdata(&chip->dev, priv); 81 86 87 + chip->flags |= TPM_CHIP_FLAG_SYNC; 82 88 err = tpm2_probe(chip); 83 89 if (err) 84 90 return err;
+2 -1
drivers/char/tpm/tpm_tis_core.c
··· 580 580 return rc; 581 581 } 582 582 583 - static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) 583 + static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 584 + size_t len) 584 585 { 585 586 int rc, irq; 586 587 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
+4 -2
drivers/char/tpm/tpm_tis_i2c_cr50.c
··· 546 546 * tpm_cr50_i2c_tis_send() - TPM transmission callback. 547 547 * @chip: A TPM chip. 548 548 * @buf: Buffer to send. 549 - * @len: Buffer length. 549 + * @bufsiz: Buffer size. 550 + * @len: Command length. 550 551 * 551 552 * Return: 552 553 * - 0: Success. 553 554 * - -errno: A POSIX error code. 554 555 */ 555 - static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) 556 + static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 557 + size_t len) 556 558 { 557 559 size_t burstcnt, limit, sent = 0; 558 560 u8 tpm_go[4] = { TPM_STS_GO };
+3 -1
drivers/char/tpm/tpm_vtpm_proxy.c
··· 321 321 * 322 322 * @chip: tpm chip to use 323 323 * @buf: send buffer 324 + * @bufsiz: size of the buffer 324 325 * @count: bytes to send 325 326 * 326 327 * Return: 327 328 * 0 in case of success, negative error value otherwise. 328 329 */ 329 - static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count) 330 + static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 331 + size_t count) 330 332 { 331 333 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); 332 334
+2 -1
drivers/char/tpm/xen-tpmfront.c
··· 131 131 return struct_size(shr, extra_pages, shr->nr_extra_pages); 132 132 } 133 133 134 - static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) 134 + static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 135 + size_t count) 135 136 { 136 137 struct tpm_private *priv = dev_get_drvdata(&chip->dev); 137 138 struct vtpm_shared_page *shr = priv->shr;
+1 -1
drivers/firmware/arm_ffa/driver.c
··· 2059 2059 kfree(drv_info); 2060 2060 return ret; 2061 2061 } 2062 - module_init(ffa_init); 2062 + rootfs_initcall(ffa_init); 2063 2063 2064 2064 static void __exit ffa_exit(void) 2065 2065 {
+3 -1
include/linux/tpm.h
··· 87 87 const u8 req_complete_val; 88 88 bool (*req_canceled)(struct tpm_chip *chip, u8 status); 89 89 int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len); 90 - int (*send) (struct tpm_chip *chip, u8 *buf, size_t len); 90 + int (*send)(struct tpm_chip *chip, u8 *buf, size_t bufsiz, 91 + size_t cmd_len); 91 92 void (*cancel) (struct tpm_chip *chip); 92 93 u8 (*status) (struct tpm_chip *chip); 93 94 void (*update_timeouts)(struct tpm_chip *chip, ··· 351 350 TPM_CHIP_FLAG_SUSPENDED = BIT(8), 352 351 TPM_CHIP_FLAG_HWRNG_DISABLED = BIT(9), 353 352 TPM_CHIP_FLAG_DISABLE = BIT(10), 353 + TPM_CHIP_FLAG_SYNC = BIT(11), 354 354 }; 355 355 356 356 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)