Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2017…
Browse files Browse the repository at this point in the history
…-12-15-1' into staging

Merge tpm 2017/12/15 v1

# gpg: Signature made Fri 15 Dec 2017 04:44:15 GMT
# gpg:                using RSA key 0x75AD65802A0B4211
# gpg: Good signature from "Stefan Berger <[email protected]>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: B818 B9CA DF90 89C2 D5CE  C66B 75AD 6580 2A0B 4211

* remotes/stefanberger/tags/pull-tpm-2017-12-15-1: (32 commits)
  tpm: tpm_passthrough: Fail startup if FE buffer size < BE buffer size
  tpm: tpm_emulator: get and set buffer size of device
  tpm: tpm_passthrough: Read the buffer size from the host device
  tpm: pull tpm_util_request() out of tpm_util_test()
  tpm: Move getting TPM buffer size to backends
  tpm: remove tpm_register_model()
  tpm-tis: use DEFINE_PROP_TPMBE
  qdev: add DEFINE_PROP_TPMBE
  tpm-tis: check that at most one TPM device exists
  tpm-tis: remove redundant 'tpm_tis:' in error messages
  tpm-emulator: add a FIXME comment about blocking cancel
  acpi: change TPM TIS data conditions
  tpm: add tpm_cmd_get_size() to tpm_util
  tpm: add TPM interface to lookup TPM version
  tpm: lookup the the TPM interface instead of TIS device
  tpm: rename qemu_find_tpm() -> qemu_find_tpm_be()
  tpm-tis: simplify header inclusion
  tpm-passthrough: workaround a possible race
  tpm-passthrough: simplify create()
  tpm-passthrough: make it safer to destroy after creation
  ...

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Dec 17, 2017
2 parents 38d1b31 + 683c4b7 commit 411ad78
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 266 deletions.
92 changes: 35 additions & 57 deletions backends/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "sysemu/tpm.h"
#include "hw/tpm/tpm_int.h"
#include "qemu/thread.h"
#include "qemu/main-loop.h"

static void tpm_backend_request_completed_bh(void *opaque)
{
TPMBackend *s = TPM_BACKEND(opaque);
TPMIfClass *tic = TPM_IF_GET_CLASS(s->tpmif);

tic->request_completed(s->tpmif);
}

static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
{
TPMBackend *s = TPM_BACKEND(user_data);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

assert(k->handle_request != NULL);
k->handle_request(s, (TPMBackendCmd *)data);

qemu_bh_schedule(s->bh);
}

static void tpm_backend_thread_end(TPMBackend *s)
Expand All @@ -44,15 +53,22 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)
return k->type;
}

int tpm_backend_init(TPMBackend *s, TPMState *state)
int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp)
{
s->tpm_state = state;
if (s->tpmif) {
error_setg(errp, "TPM backend '%s' is already initialized", s->id);
return -1;
}

s->tpmif = tpmif;
object_ref(OBJECT(tpmif));

s->had_startup_error = false;

return 0;
}

int tpm_backend_startup_tpm(TPMBackend *s)
int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize)
{
int res = 0;
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
Expand All @@ -63,7 +79,7 @@ int tpm_backend_startup_tpm(TPMBackend *s)
s->thread_pool = g_thread_pool_new(tpm_backend_worker_thread, s, 1, TRUE,
NULL);

res = k->startup_tpm ? k->startup_tpm(s) : 0;
res = k->startup_tpm ? k->startup_tpm(s, buffersize) : 0;

s->had_startup_error = (res != 0);

Expand Down Expand Up @@ -97,8 +113,6 @@ void tpm_backend_cancel_cmd(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

assert(k->cancel_cmd);

k->cancel_cmd(s);
}

Expand All @@ -122,80 +136,44 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

assert(k->get_tpm_version);

return k->get_tpm_version(s);
}

TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
size_t tpm_backend_get_buffer_size(TPMBackend *s)
{
TPMInfo *info = g_new0(TPMInfo, 1);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

info->id = g_strdup(s->id);
info->model = s->fe_model;
if (k->get_tpm_options) {
info->options = k->get_tpm_options(s);
}

return info;
return k->get_buffer_size(s);
}

static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
{
TPMBackend *s = TPM_BACKEND(obj);

return s->opened;
}

void tpm_backend_open(TPMBackend *s, Error **errp)
{
object_property_set_bool(OBJECT(s), true, "opened", errp);
}

static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp)
TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
{
TPMBackend *s = TPM_BACKEND(obj);
TPMInfo *info = g_new0(TPMInfo, 1);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
Error *local_err = NULL;

if (value == s->opened) {
return;
}

if (!value && s->opened) {
error_setg(errp, QERR_PERMISSION_DENIED);
return;
}
TPMIfClass *tic = TPM_IF_GET_CLASS(s->tpmif);

if (k->opened) {
k->opened(s, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
}
info->id = g_strdup(s->id);
info->model = tic->model;
info->options = k->get_tpm_options(s);

s->opened = true;
return info;
}

static void tpm_backend_instance_init(Object *obj)
{
TPMBackend *s = TPM_BACKEND(obj);

object_property_add_bool(obj, "opened",
tpm_backend_prop_get_opened,
tpm_backend_prop_set_opened,
NULL);
s->fe_model = -1;
s->bh = qemu_bh_new(tpm_backend_request_completed_bh, s);
}

static void tpm_backend_instance_finalize(Object *obj)
{
TPMBackend *s = TPM_BACKEND(obj);

object_unref(OBJECT(s->tpmif));
g_free(s->id);
tpm_backend_thread_end(s);
qemu_bh_delete(s->bh);
}

static const TypeInfo tpm_backend_info = {
Expand Down
64 changes: 64 additions & 0 deletions hw/core/qdev-properties-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "net/hub.h"
#include "qapi/visitor.h"
#include "chardev/char-fe.h"
#include "sysemu/tpm_backend.h"
#include "sysemu/iothread.h"

static void get_pointer(Object *obj, Visitor *v, Property *prop,
Expand Down Expand Up @@ -236,6 +237,69 @@ const PropertyInfo qdev_prop_chr = {
.release = release_chr,
};

/* --- character device --- */

static void get_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
DeviceState *dev = DEVICE(obj);
TPMBackend **be = qdev_get_prop_ptr(dev, opaque);
char *p;

p = g_strdup(*be ? (*be)->id : "");
visit_type_str(v, name, &p, errp);
g_free(p);
}

static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
DeviceState *dev = DEVICE(obj);
Error *local_err = NULL;
Property *prop = opaque;
TPMBackend *s, **be = qdev_get_prop_ptr(dev, prop);
char *str;

if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
return;
}

visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}

s = qemu_find_tpm_be(str);
if (s == NULL) {
error_setg(errp, "Property '%s.%s' can't find value '%s'",
object_get_typename(obj), prop->name, str);
} else if (tpm_backend_init(s, TPM_IF(obj), errp) == 0) {
*be = s; /* weak reference, avoid cyclic ref */
}
g_free(str);
}

static void release_tpm(Object *obj, const char *name, void *opaque)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
TPMBackend **be = qdev_get_prop_ptr(dev, prop);

if (*be) {
tpm_backend_reset(*be);
}
}

const PropertyInfo qdev_prop_tpm = {
.name = "str",
.description = "ID of a tpm to use as a backend",
.get = get_tpm,
.set = set_tpm,
.release = release_tpm,
};

/* --- netdev device --- */
static void get_netdev(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
Expand Down
14 changes: 9 additions & 5 deletions hw/i386/acpi-build.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
}

info->has_hpet = hpet_find();
info->tpm_version = tpm_get_version();
info->tpm_version = tpm_get_version(tpm_find());
info->pvpanic_port = pvpanic_port();
info->applesmc_io_base = applesmc_port();
}
Expand Down Expand Up @@ -2038,7 +2038,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
}
}

if (misc->tpm_version != TPM_VERSION_UNSPEC) {
if (TPM_IS_TIS(tpm_find())) {
aml_append(crs, aml_memory32_fixed(TPM_TIS_ADDR_BASE,
TPM_TIS_ADDR_SIZE, AML_READ_WRITE));
}
Expand Down Expand Up @@ -2204,7 +2204,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
/* Scan all PCI buses. Generate tables to support hotplug. */
build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);

if (misc->tpm_version != TPM_VERSION_UNSPEC) {
if (TPM_IS_TIS(tpm_find())) {
dev = aml_device("ISA.TPM");
aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31")));
aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
Expand Down Expand Up @@ -2281,8 +2281,12 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);

tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
tpm2_ptr->control_area_address = cpu_to_le64(0);
tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
if (TPM_IS_TIS(tpm_find())) {
tpm2_ptr->control_area_address = cpu_to_le64(0);
tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
} else {
g_warn_if_reached();
}

build_header(linker, table_data,
(void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
Expand Down
Loading

0 comments on commit 411ad78

Please sign in to comment.