summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch')
-rw-r--r--meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch182
1 files changed, 0 insertions, 182 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch b/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch
deleted file mode 100644
index 8670b8a0d3..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch
+++ /dev/null
@@ -1,182 +0,0 @@
1From b8322aaa2f31995e1b7b776e7efae68416573bc3 Mon Sep 17 00:00:00 2001
2From: Amarnath Valluri <amarnath.valluri@intel.com>
3Date: Wed, 29 Mar 2017 15:36:47 +0300
4Subject: [PATCH 09/12] tpm-passthrough: move reusable code to utils
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
10Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
11Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
12
13Upstream-Status: Backport [4a3d80980ebf71d8faf9d0ce2e2e23bdda5728df]
14---
15 hw/tpm/tpm_passthrough.c | 64 ++++--------------------------------------------
16 hw/tpm/tpm_util.c | 25 +++++++++++++++++++
17 hw/tpm/tpm_util.h | 4 +++
18 3 files changed, 34 insertions(+), 59 deletions(-)
19
20diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
21index 22d3460550..e6ace28b04 100644
22--- a/hw/tpm/tpm_passthrough.c
23+++ b/hw/tpm/tpm_passthrough.c
24@@ -68,27 +68,6 @@ typedef struct TPMPassthruState TPMPassthruState;
25
26 static void tpm_passthrough_cancel_cmd(TPMBackend *tb);
27
28-static int tpm_passthrough_unix_write(int fd, const uint8_t *buf, uint32_t len)
29-{
30- int ret, remain;
31-
32- remain = len;
33- while (remain > 0) {
34- ret = write(fd, buf, remain);
35- if (ret < 0) {
36- if (errno != EINTR && errno != EAGAIN) {
37- return -1;
38- }
39- } else if (ret == 0) {
40- break;
41- } else {
42- buf += ret;
43- remain -= ret;
44- }
45- }
46- return len - remain;
47-}
48-
49 static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len)
50 {
51 int ret;
52@@ -102,45 +81,12 @@ static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len)
53 }
54 return ret;
55 }
56-
57-static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf)
58-{
59- struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)buf;
60-
61- return be32_to_cpu(resp->len);
62-}
63-
64-/*
65- * Write an error message in the given output buffer.
66- */
67-static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
68-{
69- if (out_len >= sizeof(struct tpm_resp_hdr)) {
70- struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;
71-
72- resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
73- resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));
74- resp->errcode = cpu_to_be32(TPM_FAIL);
75- }
76-}
77-
78-static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len)
79-{
80- struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;
81-
82- if (in_len >= sizeof(*hdr)) {
83- return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);
84- }
85-
86- return false;
87-}
88-
89 static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
90 const uint8_t *in, uint32_t in_len,
91 uint8_t *out, uint32_t out_len,
92 bool *selftest_done)
93 {
94- int ret;
95+ ssize_t ret;
96 bool is_selftest;
97 const struct tpm_resp_hdr *hdr;
98
99@@ -148,9 +94,9 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
100 tpm_pt->tpm_executing = true;
101 *selftest_done = false;
102
103- is_selftest = tpm_passthrough_is_selftest(in, in_len);
104+ is_selftest = tpm_util_is_selftest(in, in_len);
105
106- ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len);
107+ ret = qemu_write_full(tpm_pt->tpm_fd, (const void *)in, (size_t)in_len);
108 if (ret != in_len) {
109 if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) {
110 error_report("tpm_passthrough: error while transmitting data "
111@@ -170,7 +116,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
112 strerror(errno), errno);
113 }
114 } else if (ret < sizeof(struct tpm_resp_hdr) ||
115- tpm_passthrough_get_size_from_buffer(out) != ret) {
116+ be32_to_cpu(((struct tpm_resp_hdr *)out)->len) != ret) {
117 ret = -1;
118 error_report("tpm_passthrough: received invalid response "
119 "packet from TPM");
120@@ -183,7 +129,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
121
122 err_exit:
123 if (ret < 0) {
124- tpm_write_fatal_error_response(out, out_len);
125+ tpm_util_write_fatal_error_response(out, out_len);
126 }
127
128 tpm_pt->tpm_executing = false;
129diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
130index 7b35429725..fb929f6e92 100644
131--- a/hw/tpm/tpm_util.c
132+++ b/hw/tpm/tpm_util.c
133@@ -24,6 +24,31 @@
134 #include "tpm_int.h"
135
136 /*
137+ * Write an error message in the given output buffer.
138+ */
139+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len)
140+{
141+ if (out_len >= sizeof(struct tpm_resp_hdr)) {
142+ struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;
143+
144+ resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
145+ resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));
146+ resp->errcode = cpu_to_be32(TPM_FAIL);
147+ }
148+}
149+
150+bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len)
151+{
152+ struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;
153+
154+ if (in_len >= sizeof(*hdr)) {
155+ return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);
156+ }
157+
158+ return false;
159+}
160+
161+/*
162 * A basic test of a TPM device. We expect a well formatted response header
163 * (error response is fine) within one second.
164 */
165diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h
166index df76245e6e..2f7c96146d 100644
167--- a/hw/tpm/tpm_util.h
168+++ b/hw/tpm/tpm_util.h
169@@ -24,6 +24,10 @@
170
171 #include "sysemu/tpm_backend.h"
172
173+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len);
174+
175+bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len);
176+
177 int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);
178
179 #endif /* TPM_TPM_UTIL_H */
180--
1812.11.0
182