Commit 2f257402 authored by Jarkko Sakkinen's avatar Jarkko Sakkinen

tpm: remove TPM_TRANSMIT_UNLOCKED flag

Added locking as part of tpm_try_get_ops() and tpm_put_ops() as they are
anyway used in most of the call sites except in tpmrm_release() where we
take the locks manually.
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
Tested-by: default avatarAlexander Steffen <Alexander.Steffen@infineon.com>
parent 2677ca98
...@@ -58,6 +58,7 @@ int tpm_try_get_ops(struct tpm_chip *chip) ...@@ -58,6 +58,7 @@ int tpm_try_get_ops(struct tpm_chip *chip)
if (!chip->ops) if (!chip->ops)
goto out_lock; goto out_lock;
mutex_lock(&chip->tpm_mutex);
return 0; return 0;
out_lock: out_lock:
up_read(&chip->ops_sem); up_read(&chip->ops_sem);
...@@ -75,6 +76,7 @@ EXPORT_SYMBOL_GPL(tpm_try_get_ops); ...@@ -75,6 +76,7 @@ EXPORT_SYMBOL_GPL(tpm_try_get_ops);
*/ */
void tpm_put_ops(struct tpm_chip *chip) void tpm_put_ops(struct tpm_chip *chip)
{ {
mutex_unlock(&chip->tpm_mutex);
up_read(&chip->ops_sem); up_read(&chip->ops_sem);
put_device(&chip->dev); put_device(&chip->dev);
} }
......
...@@ -33,7 +33,6 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space, ...@@ -33,7 +33,6 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
struct tpm_header *header = (void *)buf; struct tpm_header *header = (void *)buf;
ssize_t ret, len; ssize_t ret, len;
mutex_lock(&chip->tpm_mutex);
ret = tpm2_prepare_space(chip, space, buf, bufsiz); ret = tpm2_prepare_space(chip, space, buf, bufsiz);
/* If the command is not implemented by the TPM, synthesize a /* If the command is not implemented by the TPM, synthesize a
* response with a TPM2_RC_COMMAND_CODE return for user-space. * response with a TPM2_RC_COMMAND_CODE return for user-space.
...@@ -46,18 +45,16 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space, ...@@ -46,18 +45,16 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
ret = sizeof(*header); ret = sizeof(*header);
} }
if (ret) if (ret)
goto out_lock; goto out_rc;
len = tpm_transmit(chip, buf, bufsiz, TPM_TRANSMIT_UNLOCKED); len = tpm_transmit(chip, buf, bufsiz, 0);
if (len < 0) if (len < 0)
ret = len; ret = len;
if (!ret) if (!ret)
ret = tpm2_commit_space(chip, space, buf, &len); ret = tpm2_commit_space(chip, space, buf, &len);
out_lock: out_rc:
mutex_unlock(&chip->tpm_mutex);
return ret ? ret : len; return ret ? ret : len;
} }
......
...@@ -236,10 +236,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz, ...@@ -236,10 +236,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
memcpy(save, buf, save_size); memcpy(save, buf, save_size);
for (;;) { for (;;) {
if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
!(flags & TPM_TRANSMIT_NESTED))
mutex_lock(&chip->tpm_mutex);
if (chip->ops->clk_enable != NULL) if (chip->ops->clk_enable != NULL)
chip->ops->clk_enable(chip, true); chip->ops->clk_enable(chip, true);
...@@ -266,10 +262,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz, ...@@ -266,10 +262,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
if (chip->ops->clk_enable != NULL) if (chip->ops->clk_enable != NULL)
chip->ops->clk_enable(chip, false); chip->ops->clk_enable(chip, false);
if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
!(flags & TPM_TRANSMIT_NESTED))
mutex_unlock(&chip->tpm_mutex);
if (ret < 0) if (ret < 0)
break; break;
rc = be32_to_cpu(header->return_code); rc = be32_to_cpu(header->return_code);
......
...@@ -488,14 +488,10 @@ extern struct idr dev_nums_idr; ...@@ -488,14 +488,10 @@ extern struct idr dev_nums_idr;
/** /**
* enum tpm_transmit_flags - flags for tpm_transmit() * enum tpm_transmit_flags - flags for tpm_transmit()
* *
* @TPM_TRANSMIT_UNLOCKED: do not lock the chip * %TPM_TRANSMIT_NESTED: discard setup steps (power management, locality)
* @TPM_TRANSMIT_NESTED: discard setup steps (power management,
* locality) including locking (i.e. implicit
* UNLOCKED)
*/ */
enum tpm_transmit_flags { enum tpm_transmit_flags {
TPM_TRANSMIT_UNLOCKED = BIT(0), TPM_TRANSMIT_NESTED = BIT(0),
TPM_TRANSMIT_NESTED = BIT(1),
}; };
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz, ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
......
...@@ -652,17 +652,12 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, ...@@ -652,17 +652,12 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
u32 blob_handle; u32 blob_handle;
int rc; int rc;
mutex_lock(&chip->tpm_mutex); rc = tpm2_load_cmd(chip, payload, options, &blob_handle, 0);
rc = tpm2_load_cmd(chip, payload, options, &blob_handle,
TPM_TRANSMIT_UNLOCKED);
if (rc) if (rc)
goto out; return rc;
rc = tpm2_unseal_cmd(chip, payload, options, blob_handle, rc = tpm2_unseal_cmd(chip, payload, options, blob_handle, 0);
TPM_TRANSMIT_UNLOCKED); tpm2_flush_context_cmd(chip, blob_handle, 0);
tpm2_flush_context_cmd(chip, blob_handle, TPM_TRANSMIT_UNLOCKED);
out:
mutex_unlock(&chip->tpm_mutex);
return rc; return rc;
} }
......
...@@ -38,8 +38,7 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *space) ...@@ -38,8 +38,7 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *space)
for (i = 0; i < ARRAY_SIZE(space->session_tbl); i++) { for (i = 0; i < ARRAY_SIZE(space->session_tbl); i++) {
if (space->session_tbl[i]) if (space->session_tbl[i])
tpm2_flush_context_cmd(chip, space->session_tbl[i], tpm2_flush_context_cmd(chip, space->session_tbl[i], 0);
TPM_TRANSMIT_UNLOCKED);
} }
} }
...@@ -83,7 +82,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf, ...@@ -83,7 +82,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size); body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size);
tpm_buf_append(&tbuf, &buf[*offset], body_size); tpm_buf_append(&tbuf, &buf[*offset], body_size);
rc = tpm_transmit_cmd(chip, &tbuf, 4, TPM_TRANSMIT_UNLOCKED, NULL); rc = tpm_transmit_cmd(chip, &tbuf, 4, 0, NULL);
if (rc < 0) { if (rc < 0) {
dev_warn(&chip->dev, "%s: failed with a system error %d\n", dev_warn(&chip->dev, "%s: failed with a system error %d\n",
__func__, rc); __func__, rc);
...@@ -131,7 +130,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf, ...@@ -131,7 +130,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
tpm_buf_append_u32(&tbuf, handle); tpm_buf_append_u32(&tbuf, handle);
rc = tpm_transmit_cmd(chip, &tbuf, 0, TPM_TRANSMIT_UNLOCKED, NULL); rc = tpm_transmit_cmd(chip, &tbuf, 0, 0, NULL);
if (rc < 0) { if (rc < 0) {
dev_warn(&chip->dev, "%s: failed with a system error %d\n", dev_warn(&chip->dev, "%s: failed with a system error %d\n",
__func__, rc); __func__, rc);
...@@ -167,8 +166,7 @@ void tpm2_flush_space(struct tpm_chip *chip) ...@@ -167,8 +166,7 @@ void tpm2_flush_space(struct tpm_chip *chip)
for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++) for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
if (space->context_tbl[i] && ~space->context_tbl[i]) if (space->context_tbl[i] && ~space->context_tbl[i])
tpm2_flush_context_cmd(chip, space->context_tbl[i], tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
TPM_TRANSMIT_UNLOCKED);
tpm2_flush_sessions(chip, space); tpm2_flush_sessions(chip, space);
} }
...@@ -416,7 +414,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp, ...@@ -416,7 +414,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
return 0; return 0;
out_no_slots: out_no_slots:
tpm2_flush_context_cmd(chip, phandle, TPM_TRANSMIT_UNLOCKED); tpm2_flush_context_cmd(chip, phandle, 0);
dev_warn(&chip->dev, "%s: out of slots for 0x%08X\n", __func__, dev_warn(&chip->dev, "%s: out of slots for 0x%08X\n", __func__,
phandle); phandle);
return -ENOMEM; return -ENOMEM;
...@@ -503,8 +501,7 @@ static int tpm2_save_space(struct tpm_chip *chip) ...@@ -503,8 +501,7 @@ static int tpm2_save_space(struct tpm_chip *chip)
} else if (rc) } else if (rc)
return rc; return rc;
tpm2_flush_context_cmd(chip, space->context_tbl[i], tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
TPM_TRANSMIT_UNLOCKED);
space->context_tbl[i] = ~0; space->context_tbl[i] = ~0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment