From: Stefan Berger <stefanb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, "Stefan Berger" <stefanb@linux.ibm.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PULL 3/4] tpm_emulator: Use latest tpm_ioctl.h from swtpm project
Date: Tue, 13 Sep 2022 12:59:44 -0400 [thread overview]
Message-ID: <20220913165945.1635016-4-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20220913165945.1635016-1-stefanb@linux.ibm.com>
Use the latest tpm_ioctl.h from upstream swtpm project.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-id: 20220912174741.1542330-2-stefanb@linux.ibm.com
---
backends/tpm/tpm_ioctl.h | 96 +++++++++++++++++++++++++++++++---------
1 file changed, 76 insertions(+), 20 deletions(-)
diff --git a/backends/tpm/tpm_ioctl.h b/backends/tpm/tpm_ioctl.h
index d67bf0283b..e506ef5160 100644
--- a/backends/tpm/tpm_ioctl.h
+++ b/backends/tpm/tpm_ioctl.h
@@ -5,10 +5,15 @@
*
* This file is licensed under the terms of the 3-clause BSD license
*/
+#ifndef _TPM_IOCTL_H_
+#define _TPM_IOCTL_H_
-#ifndef TPM_IOCTL_H
-#define TPM_IOCTL_H
+#if defined(__CYGWIN__)
+# define __USE_LINUX_IOCTL_DEFS
+#endif
+#include <stdint.h>
+#include <sys/types.h>
#ifndef _WIN32
#include <sys/uio.h>
#include <sys/ioctl.h>
@@ -196,6 +201,48 @@ struct ptm_setbuffersize {
} u;
};
+#define PTM_GETINFO_SIZE (3 * 1024)
+/*
+ * PTM_GET_INFO: Get info about the TPM implementation (from libtpms)
+ *
+ * This request allows to indirectly call TPMLIB_GetInfo(flags) and
+ * retrieve information from libtpms.
+ * Only one transaction is currently necessary for returning results
+ * to a client. Therefore, totlength and length will be the same if
+ * offset is 0.
+ */
+struct ptm_getinfo {
+ union {
+ struct {
+ uint64_t flags;
+ uint32_t offset; /* offset from where to read */
+ uint32_t pad; /* 32 bit arch */
+ } req; /* request */
+ struct {
+ ptm_res tpm_result;
+ uint32_t totlength;
+ uint32_t length;
+ char buffer[PTM_GETINFO_SIZE];
+ } resp; /* response */
+ } u;
+};
+
+#define SWTPM_INFO_TPMSPECIFICATION ((uint64_t)1 << 0)
+#define SWTPM_INFO_TPMATTRIBUTES ((uint64_t)1 << 1)
+
+/*
+ * PTM_LOCK_STORAGE: Lock the storage and retry n times
+ */
+struct ptm_lockstorage {
+ union {
+ struct {
+ uint32_t retries; /* number of retries */
+ } req; /* request */
+ struct {
+ ptm_res tpm_result;
+ } resp; /* reponse */
+ } u;
+};
typedef uint64_t ptm_cap;
typedef struct ptm_est ptm_est;
@@ -207,6 +254,8 @@ typedef struct ptm_getstate ptm_getstate;
typedef struct ptm_setstate ptm_setstate;
typedef struct ptm_getconfig ptm_getconfig;
typedef struct ptm_setbuffersize ptm_setbuffersize;
+typedef struct ptm_getinfo ptm_getinfo;
+typedef struct ptm_lockstorage ptm_lockstorage;
/* capability flags returned by PTM_GET_CAPABILITY */
#define PTM_CAP_INIT (1)
@@ -223,6 +272,9 @@ typedef struct ptm_setbuffersize ptm_setbuffersize;
#define PTM_CAP_GET_CONFIG (1 << 11)
#define PTM_CAP_SET_DATAFD (1 << 12)
#define PTM_CAP_SET_BUFFERSIZE (1 << 13)
+#define PTM_CAP_GET_INFO (1 << 14)
+#define PTM_CAP_SEND_COMMAND_HEADER (1 << 15)
+#define PTM_CAP_LOCK_STORAGE (1 << 16)
#ifndef _WIN32
enum {
@@ -243,6 +295,8 @@ enum {
PTM_GET_CONFIG = _IOR('P', 14, ptm_getconfig),
PTM_SET_DATAFD = _IOR('P', 15, ptm_res),
PTM_SET_BUFFERSIZE = _IOWR('P', 16, ptm_setbuffersize),
+ PTM_GET_INFO = _IOWR('P', 17, ptm_getinfo),
+ PTM_LOCK_STORAGE = _IOWR('P', 18, ptm_lockstorage),
};
#endif
@@ -257,23 +311,25 @@ enum {
* and ptm_set_state:u.req.data) are 0xffffffff.
*/
enum {
- CMD_GET_CAPABILITY = 1,
- CMD_INIT,
- CMD_SHUTDOWN,
- CMD_GET_TPMESTABLISHED,
- CMD_SET_LOCALITY,
- CMD_HASH_START,
- CMD_HASH_DATA,
- CMD_HASH_END,
- CMD_CANCEL_TPM_CMD,
- CMD_STORE_VOLATILE,
- CMD_RESET_TPMESTABLISHED,
- CMD_GET_STATEBLOB,
- CMD_SET_STATEBLOB,
- CMD_STOP,
- CMD_GET_CONFIG,
- CMD_SET_DATAFD,
- CMD_SET_BUFFERSIZE,
+ CMD_GET_CAPABILITY = 1, /* 0x01 */
+ CMD_INIT, /* 0x02 */
+ CMD_SHUTDOWN, /* 0x03 */
+ CMD_GET_TPMESTABLISHED, /* 0x04 */
+ CMD_SET_LOCALITY, /* 0x05 */
+ CMD_HASH_START, /* 0x06 */
+ CMD_HASH_DATA, /* 0x07 */
+ CMD_HASH_END, /* 0x08 */
+ CMD_CANCEL_TPM_CMD, /* 0x09 */
+ CMD_STORE_VOLATILE, /* 0x0a */
+ CMD_RESET_TPMESTABLISHED, /* 0x0b */
+ CMD_GET_STATEBLOB, /* 0x0c */
+ CMD_SET_STATEBLOB, /* 0x0d */
+ CMD_STOP, /* 0x0e */
+ CMD_GET_CONFIG, /* 0x0f */
+ CMD_SET_DATAFD, /* 0x10 */
+ CMD_SET_BUFFERSIZE, /* 0x11 */
+ CMD_GET_INFO, /* 0x12 */
+ CMD_LOCK_STORAGE, /* 0x13 */
};
-#endif /* TPM_IOCTL_H */
+#endif /* _TPM_IOCTL_H_ */
--
2.37.2
next prev parent reply other threads:[~2022-09-13 17:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-13 16:59 [PULL 0/4] Merge tpm 2022/09/13 v1 Stefan Berger
2022-09-13 16:59 ` [PULL 1/4] tpm_emulator: Avoid double initialization during migration Stefan Berger
2022-09-13 16:59 ` [PULL 2/4] tpm_crb: Avoid backend startup just before shutdown under Xen Stefan Berger
2022-09-13 16:59 ` Stefan Berger [this message]
2022-09-13 16:59 ` [PULL 4/4] tpm_emulator: Have swtpm relock storage upon migration fall-back Stefan Berger
2022-09-20 16:59 ` [PULL 0/4] Merge tpm 2022/09/13 v1 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220913165945.1635016-4-stefanb@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).