summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch')
-rw-r--r--meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch293
1 files changed, 0 insertions, 293 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch b/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch
deleted file mode 100644
index 6d79ac4d63..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch
+++ /dev/null
@@ -1,293 +0,0 @@
1From 5f698395b5de1ab2826f5aad99d757ce31d7c95f Mon Sep 17 00:00:00 2001
2From: Amarnath Valluri <amarnath.valluri@intel.com>
3Date: Mon, 6 Mar 2017 00:10:10 +0200
4Subject: [PATCH 07/12] tpm backend: Add new api to read backend TpmInfo
5
6TPM configuration options are backend implementation details and shall not be
7part of base TPMBackend object, and these shall not be accessed directly outside
8of the class, hence added a new interface method, get_tpm_options() to
9TPMDriverOps., which shall be implemented by the derived classes to return
10configured tpm options.
11
12A new tpm backend api - tpm_backend_query_tpm() which uses _get_tpm_options() to
13prepare TpmInfo.
14
15Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
16Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
17
18Upstream-Status: Backport[f59864ba3aedd26aef7c84545cc1e565caccebf7]
19---
20 backends/tpm.c | 15 +++++++++++--
21 hw/tpm/tpm_passthrough.c | 51 +++++++++++++++++++++++++++-----------------
22 include/sysemu/tpm_backend.h | 15 +++++++++++--
23 tpm.c | 32 +--------------------------
24 4 files changed, 59 insertions(+), 54 deletions(-)
25
26diff --git a/backends/tpm.c b/backends/tpm.c
27index 8911597fab..de313c9d5a 100644
28--- a/backends/tpm.c
29+++ b/backends/tpm.c
30@@ -142,6 +142,19 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
31 return k->ops->get_tpm_version(s);
32 }
33
34+TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
35+{
36+ TPMInfo *info = g_new0(TPMInfo, 1);
37+ TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
38+
39+ info->id = g_strdup(s->id);
40+ info->model = s->fe_model;
41+ info->options = k->ops->get_tpm_options ?
42+ k->ops->get_tpm_options(s) : NULL;
43+
44+ return info;
45+}
46+
47 static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
48 {
49 TPMBackend *s = TPM_BACKEND(obj);
50@@ -196,8 +209,6 @@ static void tpm_backend_instance_finalize(Object *obj)
51 TPMBackend *s = TPM_BACKEND(obj);
52
53 g_free(s->id);
54- g_free(s->path);
55- g_free(s->cancel_path);
56 tpm_backend_thread_end(s);
57 }
58
59diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
60index 4c21e52b7c..84fc49a4d3 100644
61--- a/hw/tpm/tpm_passthrough.c
62+++ b/hw/tpm/tpm_passthrough.c
63@@ -30,6 +30,7 @@
64 #include "tpm_int.h"
65 #include "hw/hw.h"
66 #include "hw/i386/pc.h"
67+#include "qapi/clone-visitor.h"
68 #include "tpm_tis.h"
69 #include "tpm_util.h"
70
71@@ -49,7 +50,8 @@
72 struct TPMPassthruState {
73 TPMBackend parent;
74
75- char *tpm_dev;
76+ TPMPassthroughOptions *options;
77+ const char *tpm_dev;
78 int tpm_fd;
79 bool tpm_executing;
80 bool tpm_op_canceled;
81@@ -296,15 +298,14 @@ static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb)
82 * in Documentation/ABI/stable/sysfs-class-tpm.
83 * From /dev/tpm0 create /sys/class/misc/tpm0/device/cancel
84 */
85-static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
86+static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)
87 {
88- TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
89 int fd = -1;
90 char *dev;
91 char path[PATH_MAX];
92
93- if (tb->cancel_path) {
94- fd = qemu_open(tb->cancel_path, O_WRONLY);
95+ if (tpm_pt->options->cancel_path) {
96+ fd = qemu_open(tpm_pt->options->cancel_path, O_WRONLY);
97 if (fd < 0) {
98 error_report("Could not open TPM cancel path : %s",
99 strerror(errno));
100@@ -319,7 +320,7 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
101 dev) < sizeof(path)) {
102 fd = qemu_open(path, O_WRONLY);
103 if (fd >= 0) {
104- tb->cancel_path = g_strdup(path);
105+ tpm_pt->options->cancel_path = g_strdup(path);
106 } else {
107 error_report("tpm_passthrough: Could not open TPM cancel "
108 "path %s : %s", path, strerror(errno));
109@@ -339,17 +340,18 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)
110 const char *value;
111
112 value = qemu_opt_get(opts, "cancel-path");
113- tb->cancel_path = g_strdup(value);
114+ if (value) {
115+ tpm_pt->options->cancel_path = g_strdup(value);
116+ tpm_pt->options->has_cancel_path = true;
117+ }
118
119 value = qemu_opt_get(opts, "path");
120- if (!value) {
121- value = TPM_PASSTHROUGH_DEFAULT_DEVICE;
122+ if (value) {
123+ tpm_pt->options->has_path = true;
124+ tpm_pt->options->path = g_strdup(value);
125 }
126
127- tpm_pt->tpm_dev = g_strdup(value);
128-
129- tb->path = g_strdup(tpm_pt->tpm_dev);
130-
131+ tpm_pt->tpm_dev = value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE;
132 tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR);
133 if (tpm_pt->tpm_fd < 0) {
134 error_report("Cannot access TPM device using '%s': %s",
135@@ -370,10 +372,8 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)
136 tpm_pt->tpm_fd = -1;
137
138 err_free_parameters:
139- g_free(tb->path);
140- tb->path = NULL;
141-
142- g_free(tpm_pt->tpm_dev);
143+ qapi_free_TPMPassthroughOptions(tpm_pt->options);
144+ tpm_pt->options = NULL;
145 tpm_pt->tpm_dev = NULL;
146
147 return 1;
148@@ -391,7 +391,7 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id)
149 goto err_exit;
150 }
151
152- tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tb);
153+ tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tpm_pt);
154 if (tpm_pt->cancel_fd < 0) {
155 goto err_exit;
156 }
157@@ -404,6 +404,17 @@ err_exit:
158 return NULL;
159 }
160
161+static TpmTypeOptions *tpm_passthrough_get_tpm_options(TPMBackend *tb)
162+{
163+ TpmTypeOptions *options = g_new0(TpmTypeOptions, 1);
164+
165+ options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH;
166+ options->u.passthrough.data = QAPI_CLONE(TPMPassthroughOptions,
167+ TPM_PASSTHROUGH(tb)->options);
168+
169+ return options;
170+}
171+
172 static const QemuOptDesc tpm_passthrough_cmdline_opts[] = {
173 TPM_STANDARD_CMDLINE_OPTS,
174 {
175@@ -430,12 +441,14 @@ static const TPMDriverOps tpm_passthrough_driver = {
176 .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag,
177 .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag,
178 .get_tpm_version = tpm_passthrough_get_tpm_version,
179+ .get_tpm_options = tpm_passthrough_get_tpm_options,
180 };
181
182 static void tpm_passthrough_inst_init(Object *obj)
183 {
184 TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
185
186+ tpm_pt->options = g_new0(TPMPassthroughOptions, 1);
187 tpm_pt->tpm_fd = -1;
188 tpm_pt->cancel_fd = -1;
189 }
190@@ -448,7 +461,7 @@ static void tpm_passthrough_inst_finalize(Object *obj)
191
192 qemu_close(tpm_pt->tpm_fd);
193 qemu_close(tpm_pt->cancel_fd);
194- g_free(tpm_pt->tpm_dev);
195+ qapi_free_TPMPassthroughOptions(tpm_pt->options);
196 }
197
198 static void tpm_passthrough_class_init(ObjectClass *klass, void *data)
199diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
200index 9ea707253a..e96c1918cc 100644
201--- a/include/sysemu/tpm_backend.h
202+++ b/include/sysemu/tpm_backend.h
203@@ -49,10 +49,9 @@ struct TPMBackend {
204 TPMRecvDataCB *recv_data_callback;
205 bool had_startup_error;
206
207+ /* <public> */
208 char *id;
209 enum TpmModel fe_model;
210- char *path;
211- char *cancel_path;
212
213 QLIST_ENTRY(TPMBackend) list;
214 };
215@@ -96,6 +95,8 @@ struct TPMDriverOps {
216 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
217
218 TPMVersion (*get_tpm_version)(TPMBackend *t);
219+
220+ TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
221 };
222
223
224@@ -214,6 +215,16 @@ void tpm_backend_open(TPMBackend *s, Error **errp);
225 */
226 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
227
228+/**
229+ * tpm_backend_query_tpm:
230+ * @s: the backend
231+ *
232+ * Query backend tpm info
233+ *
234+ * Returns newly allocated TPMInfo
235+ */
236+TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
237+
238 TPMBackend *qemu_find_tpm(const char *id);
239
240 const TPMDriverOps *tpm_get_backend_driver(const char *type);
241diff --git a/tpm.c b/tpm.c
242index 9f4f37da50..cac400ef3e 100644
243--- a/tpm.c
244+++ b/tpm.c
245@@ -203,36 +203,6 @@ static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type)
246 return be_drivers[type];
247 }
248
249-static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)
250-{
251- TPMInfo *res = g_new0(TPMInfo, 1);
252- TPMPassthroughOptions *tpo;
253-
254- res->id = g_strdup(drv->id);
255- res->model = drv->fe_model;
256- res->options = g_new0(TpmTypeOptions, 1);
257-
258- switch (tpm_backend_get_type(drv)) {
259- case TPM_TYPE_PASSTHROUGH:
260- res->options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH;
261- tpo = g_new0(TPMPassthroughOptions, 1);
262- res->options->u.passthrough.data = tpo;
263- if (drv->path) {
264- tpo->path = g_strdup(drv->path);
265- tpo->has_path = true;
266- }
267- if (drv->cancel_path) {
268- tpo->cancel_path = g_strdup(drv->cancel_path);
269- tpo->has_cancel_path = true;
270- }
271- break;
272- case TPM_TYPE__MAX:
273- break;
274- }
275-
276- return res;
277-}
278-
279 /*
280 * Walk the list of active TPM backends and collect information about them
281 * following the schema description in qapi-schema.json.
282@@ -247,7 +217,7 @@ TPMInfoList *qmp_query_tpm(Error **errp)
283 continue;
284 }
285 info = g_new0(TPMInfoList, 1);
286- info->value = qmp_query_tpm_inst(drv);
287+ info->value = tpm_backend_query_tpm(drv);
288
289 if (!cur_item) {
290 head = cur_item = info;
291--
2922.11.0
293