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 branch 'next-tpm' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security

Pull TPM updates from James Morris:
"Here are the TPM updates from Jarkko for v4.14, which I've placed in
their own branch (next-tpm). I ended up cherry-picking them as other
changes had been made in Jarkko's branch after he sent me his original
pull request.

I plan on maintaining a separate branch for TPM (and other security
subsystems) from now on.

From Jarkko: 'Not much this time except a few fixes'"

* 'next-tpm' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
tpm: ibmvtpm: simplify crq initialization and document crq format
tpm: replace msleep() with usleep_range() in TPM 1.2/2.0 generic drivers
Documentation: tpm: add powered-while-suspended binding documentation
tpm: tpm_crb: constify acpi_device_id.
tpm: vtpm: constify vio_device_id

+89 -52
+6
Documentation/devicetree/bindings/security/tpm/tpm-i2c.txt
··· 8 8 the firmware event log 9 9 - linux,sml-size : size of the memory allocated for the firmware event log 10 10 11 + Optional properties: 12 + 13 + - powered-while-suspended: present when the TPM is left powered on between 14 + suspend and resume (makes the suspend/resume 15 + callbacks do nothing). 16 + 11 17 Example (for OpenPower Systems with Nuvoton TPM 2.0 on I2C) 12 18 ---------------------------------------------------------- 13 19
+5 -5
drivers/char/tpm/tpm-interface.c
··· 455 455 goto out; 456 456 } 457 457 458 - msleep(TPM_TIMEOUT); /* CHECK */ 458 + tpm_msleep(TPM_TIMEOUT); 459 459 rmb(); 460 460 } while (time_before(jiffies, stop)); 461 461 ··· 970 970 dev_info( 971 971 &chip->dev, HW_ERR 972 972 "TPM command timed out during continue self test"); 973 - msleep(delay_msec); 973 + tpm_msleep(delay_msec); 974 974 continue; 975 975 } 976 976 ··· 985 985 } 986 986 if (rc != TPM_WARN_DOING_SELFTEST) 987 987 return rc; 988 - msleep(delay_msec); 988 + tpm_msleep(delay_msec); 989 989 } while (--loops > 0); 990 990 991 991 return rc; ··· 1085 1085 } 1086 1086 } else { 1087 1087 do { 1088 - msleep(TPM_TIMEOUT); 1088 + tpm_msleep(TPM_TIMEOUT); 1089 1089 status = chip->ops->status(chip); 1090 1090 if ((status & mask) == mask) 1091 1091 return 0; ··· 1150 1150 */ 1151 1151 if (rc != TPM_WARN_RETRY) 1152 1152 break; 1153 - msleep(TPM_TIMEOUT_RETRY); 1153 + tpm_msleep(TPM_TIMEOUT_RETRY); 1154 1154 } 1155 1155 1156 1156 if (rc)
+8 -1
drivers/char/tpm/tpm.h
··· 50 50 51 51 enum tpm_timeout { 52 52 TPM_TIMEOUT = 5, /* msecs */ 53 - TPM_TIMEOUT_RETRY = 100 /* msecs */ 53 + TPM_TIMEOUT_RETRY = 100, /* msecs */ 54 + TPM_TIMEOUT_RANGE_US = 300 /* usecs */ 54 55 }; 55 56 56 57 /* TPM addresses */ ··· 527 526 int tpm_pm_resume(struct device *dev); 528 527 int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, 529 528 wait_queue_head_t *queue, bool check_cancel); 529 + 530 + static inline void tpm_msleep(unsigned int delay_msec) 531 + { 532 + usleep_range(delay_msec * 1000, 533 + (delay_msec * 1000) + TPM_TIMEOUT_RANGE_US); 534 + }; 530 535 531 536 struct tpm_chip *tpm_chip_find_get(int chip_num); 532 537 __must_check int tpm_try_get_ops(struct tpm_chip *chip);
+1 -1
drivers/char/tpm/tpm2-cmd.c
··· 899 899 if (rc != TPM2_RC_TESTING) 900 900 break; 901 901 902 - msleep(delay_msec); 902 + tpm_msleep(delay_msec); 903 903 } 904 904 905 905 return rc;
+1 -1
drivers/char/tpm/tpm_crb.c
··· 665 665 SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL) 666 666 }; 667 667 668 - static struct acpi_device_id crb_device_ids[] = { 668 + static const struct acpi_device_id crb_device_ids[] = { 669 669 {"MSFT0101", 0}, 670 670 {"", 0}, 671 671 };
+61 -37
drivers/char/tpm/tpm_ibmvtpm.c
··· 32 32 33 33 static const char tpm_ibmvtpm_driver_name[] = "tpm_ibmvtpm"; 34 34 35 - static struct vio_device_id tpm_ibmvtpm_device_table[] = { 35 + static const struct vio_device_id tpm_ibmvtpm_device_table[] = { 36 36 { "IBM,vtpm", "IBM,vtpm"}, 37 37 { "", "" } 38 38 }; 39 39 MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table); 40 40 41 41 /** 42 + * 43 + * ibmvtpm_send_crq_word - Send a CRQ request 44 + * @vdev: vio device struct 45 + * @w1: pre-constructed first word of tpm crq (second word is reserved) 46 + * 47 + * Return: 48 + * 0 - Success 49 + * Non-zero - Failure 50 + */ 51 + static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1) 52 + { 53 + return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, 0); 54 + } 55 + 56 + /** 57 + * 42 58 * ibmvtpm_send_crq - Send a CRQ request 43 59 * 44 60 * @vdev: vio device struct 45 - * @w1: first word 46 - * @w2: second word 61 + * @valid: Valid field 62 + * @msg: Type field 63 + * @len: Length field 64 + * @data: Data field 65 + * 66 + * The ibmvtpm crq is defined as follows: 67 + * 68 + * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 69 + * ----------------------------------------------------------------------- 70 + * Word0 | Valid | Type | Length | Data 71 + * ----------------------------------------------------------------------- 72 + * Word1 | Reserved 73 + * ----------------------------------------------------------------------- 74 + * 75 + * Which matches the following structure (on bigendian host): 76 + * 77 + * struct ibmvtpm_crq { 78 + * u8 valid; 79 + * u8 msg; 80 + * __be16 len; 81 + * __be32 data; 82 + * __be64 reserved; 83 + * } __attribute__((packed, aligned(8))); 84 + * 85 + * However, the value is passed in a register so just compute the numeric value 86 + * to load into the register avoiding byteswap altogether. Endian only affects 87 + * memory loads and stores - registers are internally represented the same. 47 88 * 48 89 * Return: 49 - * 0 -Sucess 90 + * 0 (H_SUCCESS) - Success 50 91 * Non-zero - Failure 51 92 */ 52 - static int ibmvtpm_send_crq(struct vio_dev *vdev, u64 w1, u64 w2) 93 + static int ibmvtpm_send_crq(struct vio_dev *vdev, 94 + u8 valid, u8 msg, u16 len, u32 data) 53 95 { 54 - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, w1, w2); 96 + u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len << 32) | 97 + (u64)data; 98 + return ibmvtpm_send_crq_word(vdev, w1); 55 99 } 56 100 57 101 /** ··· 153 109 static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) 154 110 { 155 111 struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev); 156 - struct ibmvtpm_crq crq; 157 - __be64 *word = (__be64 *)&crq; 158 112 int rc, sig; 159 113 160 114 if (!ibmvtpm->rtce_buf) { ··· 179 137 spin_lock(&ibmvtpm->rtce_lock); 180 138 ibmvtpm->res_len = 0; 181 139 memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count); 182 - crq.valid = (u8)IBMVTPM_VALID_CMD; 183 - crq.msg = (u8)VTPM_TPM_COMMAND; 184 - crq.len = cpu_to_be16(count); 185 - crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle); 186 140 187 141 /* 188 142 * set the processing flag before the Hcall, since we may get the ··· 186 148 */ 187 149 ibmvtpm->tpm_processing_cmd = true; 188 150 189 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]), 190 - be64_to_cpu(word[1])); 151 + rc = ibmvtpm_send_crq(ibmvtpm->vdev, 152 + IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND, 153 + count, ibmvtpm->rtce_dma_handle); 191 154 if (rc != H_SUCCESS) { 192 155 dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc); 193 156 rc = 0; ··· 221 182 */ 222 183 static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) 223 184 { 224 - struct ibmvtpm_crq crq; 225 - u64 *buf = (u64 *) &crq; 226 185 int rc; 227 186 228 - crq.valid = (u8)IBMVTPM_VALID_CMD; 229 - crq.msg = (u8)VTPM_GET_RTCE_BUFFER_SIZE; 230 - 231 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]), 232 - cpu_to_be64(buf[1])); 187 + rc = ibmvtpm_send_crq(ibmvtpm->vdev, 188 + IBMVTPM_VALID_CMD, VTPM_GET_RTCE_BUFFER_SIZE, 0, 0); 233 189 if (rc != H_SUCCESS) 234 190 dev_err(ibmvtpm->dev, 235 191 "ibmvtpm_crq_get_rtce_size failed rc=%d\n", rc); ··· 244 210 */ 245 211 static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm) 246 212 { 247 - struct ibmvtpm_crq crq; 248 - u64 *buf = (u64 *) &crq; 249 213 int rc; 250 214 251 - crq.valid = (u8)IBMVTPM_VALID_CMD; 252 - crq.msg = (u8)VTPM_GET_VERSION; 253 - 254 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]), 255 - cpu_to_be64(buf[1])); 215 + rc = ibmvtpm_send_crq(ibmvtpm->vdev, 216 + IBMVTPM_VALID_CMD, VTPM_GET_VERSION, 0, 0); 256 217 if (rc != H_SUCCESS) 257 218 dev_err(ibmvtpm->dev, 258 219 "ibmvtpm_crq_get_version failed rc=%d\n", rc); ··· 267 238 { 268 239 int rc; 269 240 270 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_COMP_CMD, 0); 241 + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_COMP_CMD); 271 242 if (rc != H_SUCCESS) 272 243 dev_err(ibmvtpm->dev, 273 244 "ibmvtpm_crq_send_init_complete failed rc=%d\n", rc); ··· 287 258 { 288 259 int rc; 289 260 290 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, INIT_CRQ_CMD, 0); 261 + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD); 291 262 if (rc != H_SUCCESS) 292 263 dev_err(ibmvtpm->dev, 293 264 "ibmvtpm_crq_send_init failed rc=%d\n", rc); ··· 369 340 { 370 341 struct tpm_chip *chip = dev_get_drvdata(dev); 371 342 struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev); 372 - struct ibmvtpm_crq crq; 373 - u64 *buf = (u64 *) &crq; 374 343 int rc = 0; 375 344 376 - crq.valid = (u8)IBMVTPM_VALID_CMD; 377 - crq.msg = (u8)VTPM_PREPARE_TO_SUSPEND; 378 - 379 - rc = ibmvtpm_send_crq(ibmvtpm->vdev, cpu_to_be64(buf[0]), 380 - cpu_to_be64(buf[1])); 345 + rc = ibmvtpm_send_crq(ibmvtpm->vdev, 346 + IBMVTPM_VALID_CMD, VTPM_PREPARE_TO_SUSPEND, 0, 0); 381 347 if (rc != H_SUCCESS) 382 348 dev_err(ibmvtpm->dev, 383 349 "tpm_ibmvtpm_suspend failed rc=%d\n", rc);
+3 -3
drivers/char/tpm/tpm_infineon.c
··· 191 191 /* check the status-register if wait_for_bit is set */ 192 192 if (status & 1 << wait_for_bit) 193 193 break; 194 - msleep(TPM_MSLEEP_TIME); 194 + tpm_msleep(TPM_MSLEEP_TIME); 195 195 } 196 196 if (i == TPM_MAX_TRIES) { /* timeout occurs */ 197 197 if (wait_for_bit == STAT_XFE) ··· 226 226 wait_and_send(chip, TPM_CTRL_WTX); 227 227 wait_and_send(chip, 0x00); 228 228 wait_and_send(chip, 0x00); 229 - msleep(TPM_WTX_MSLEEP_TIME); 229 + tpm_msleep(TPM_WTX_MSLEEP_TIME); 230 230 } 231 231 232 232 static void tpm_wtx_abort(struct tpm_chip *chip) ··· 237 237 wait_and_send(chip, 0x00); 238 238 wait_and_send(chip, 0x00); 239 239 number_of_wtx = 0; 240 - msleep(TPM_WTX_MSLEEP_TIME); 240 + tpm_msleep(TPM_WTX_MSLEEP_TIME); 241 241 } 242 242 243 243 static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
+4 -4
drivers/char/tpm/tpm_tis_core.c
··· 51 51 52 52 if (access & TPM_ACCESS_VALID) 53 53 return 0; 54 - msleep(TPM_TIMEOUT); 54 + tpm_msleep(TPM_TIMEOUT); 55 55 } while (time_before(jiffies, stop)); 56 56 return -1; 57 57 } ··· 117 117 do { 118 118 if (check_locality(chip, l)) 119 119 return l; 120 - msleep(TPM_TIMEOUT); 120 + tpm_msleep(TPM_TIMEOUT); 121 121 } while (time_before(jiffies, stop)); 122 122 } 123 123 return -1; ··· 164 164 burstcnt = (value >> 8) & 0xFFFF; 165 165 if (burstcnt) 166 166 return burstcnt; 167 - msleep(TPM_TIMEOUT); 167 + tpm_msleep(TPM_TIMEOUT); 168 168 } while (time_before(jiffies, stop)); 169 169 return -EBUSY; 170 170 } ··· 396 396 priv->irq = irq; 397 397 chip->flags |= TPM_CHIP_FLAG_IRQ; 398 398 if (!priv->irq_tested) 399 - msleep(1); 399 + tpm_msleep(1); 400 400 if (!priv->irq_tested) 401 401 disable_interrupts(chip); 402 402 priv->irq_tested = true;