Merge tpm 2021/09/01 v1
-----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEuBi5yt+QicLVzsZrda1lgCoLQhEFAmEvbmcACgkQda1lgCoL QhEmtggAgWR8p/4awhUoTscEkLBoilxJATTZBkxbN8NrRYmOIIn29QShhEDhvuG9 t6ch0DrJuSVMISTnMHtE5XJKBBD8vFS04SaD4Op8NgOyKTd2fQSXx6SyqgQVK0ui zfZFjcjam9i+onIGVCSoUkGRL5GMOTougTh4SwMndR9sL9cn7lUQEJZbk7kS1II6 5r6uvKPtY4fyvxsi0wcHOYFSeajJfQOVZkav7JCnvuXiiCjQzZw2Aadsvrkmt3Y4 oaOTiOvYWJhNqFhWSuyY7gS4E4fjShwr3UuOcsmKUTu56Uf2GgdA9w4+AfZJQSxG C1Vi+u5J8+oZzVHna9T1lRKQ5wLfCA== =IprO -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2021-09-01-1' into staging Merge tpm 2021/09/01 v1 # gpg: Signature made Wed 01 Sep 2021 13:13:27 BST # gpg: using RSA key B818B9CADF9089C2D5CEC66B75AD65802A0B4211 # gpg: Good signature from "Stefan Berger <stefanb@linux.vnet.ibm.com>" [unknown] # 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-2021-09-01-1: tests: acpi: tpm1.2: Add expected TPM 1.2 ACPI blobs tests: acpi: Add test cases for TPM 1.2 with TCPA table tests: Use QMP to check whether a TPM device model is available tests: acpi: prepare for new TPM 1.2 related tables tests: tpm: Create TPM 1.2 response in TPM emulator tests: acpi: tpm2: Add the renamed ACPI files and drop old ones tests: Add suffix 'tpm2' or 'tpm12' to ACPI table files tests: acpi: Prepare for renaming of TPM2 related ACPI files tests: Add tpm_version field to TPMTestState and fill it tests: Rename TestState to TPMTestState Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
59a89510b6
BIN
tests/data/acpi/q35/DSDT.tis.tpm12
Normal file
BIN
tests/data/acpi/q35/DSDT.tis.tpm12
Normal file
Binary file not shown.
BIN
tests/data/acpi/q35/TCPA.tis.tpm12
Normal file
BIN
tests/data/acpi/q35/TCPA.tis.tpm12
Normal file
Binary file not shown.
@ -1092,16 +1092,16 @@ static void test_acpi_piix4_tcg_numamem(void)
|
||||
uint64_t tpm_tis_base_addr;
|
||||
|
||||
static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
|
||||
uint64_t base)
|
||||
uint64_t base, enum TPMVersion tpm_version)
|
||||
{
|
||||
#ifdef CONFIG_TPM
|
||||
gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
|
||||
machine, tpm_if);
|
||||
char *tmp_path = g_dir_make_tmp(tmp_dir_name, NULL);
|
||||
TestState test;
|
||||
TPMTestState test;
|
||||
test_data data;
|
||||
GThread *thread;
|
||||
char *args, *variant = g_strdup_printf(".%s", tpm_if);
|
||||
const char *suffix = tpm_version == TPM_VERSION_2_0 ? "tpm2" : "tpm12";
|
||||
char *args, *variant = g_strdup_printf(".%s.%s", tpm_if, suffix);
|
||||
|
||||
tpm_tis_base_addr = base;
|
||||
|
||||
@ -1113,6 +1113,7 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
|
||||
g_mutex_init(&test.data_mutex);
|
||||
g_cond_init(&test.data_cond);
|
||||
test.data_cond_signal = false;
|
||||
test.tpm_version = tpm_version;
|
||||
|
||||
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
|
||||
tpm_emu_test_wait_cond(&test);
|
||||
@ -1138,14 +1139,16 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
|
||||
g_free(tmp_dir_name);
|
||||
g_free(args);
|
||||
free_test_data(&data);
|
||||
#else
|
||||
g_test_skip("TPM disabled");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_acpi_q35_tcg_tpm_tis(void)
|
||||
static void test_acpi_q35_tcg_tpm2_tis(void)
|
||||
{
|
||||
test_acpi_tcg_tpm("q35", "tis", 0xFED40000);
|
||||
test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_2_0);
|
||||
}
|
||||
|
||||
static void test_acpi_q35_tcg_tpm12_tis(void)
|
||||
{
|
||||
test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_1_2);
|
||||
}
|
||||
|
||||
static void test_acpi_tcg_dimm_pxm(const char *machine)
|
||||
@ -1516,7 +1519,10 @@ int main(int argc, char *argv[])
|
||||
return ret;
|
||||
}
|
||||
qtest_add_func("acpi/q35/oem-fields", test_acpi_oem_fields_q35);
|
||||
qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
|
||||
if (tpm_model_is_available("-machine q35", "tpm-tis")) {
|
||||
qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm2_tis);
|
||||
qtest_add_func("acpi/q35/tpm12-tis", test_acpi_q35_tcg_tpm12_tis);
|
||||
}
|
||||
qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
|
||||
qtest_add_func("acpi/oem-fields", test_acpi_oem_fields_pc);
|
||||
qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
|
||||
|
@ -26,7 +26,7 @@ uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
|
||||
|
||||
static void tpm_crb_test(const void *data)
|
||||
{
|
||||
const TestState *s = data;
|
||||
const TPMTestState *s = data;
|
||||
uint32_t intfid = readl(TPM_CRB_ADDR_BASE + A_CRB_INTF_ID);
|
||||
uint32_t csize = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_CMD_SIZE);
|
||||
uint64_t caddr = readq(TPM_CRB_ADDR_BASE + A_CRB_CTRL_CMD_LADDR);
|
||||
@ -145,7 +145,7 @@ int main(int argc, char **argv)
|
||||
int ret;
|
||||
char *args, *tmp_path = g_dir_make_tmp("qemu-tpm-crb-test.XXXXXX", NULL);
|
||||
GThread *thread;
|
||||
TestState test;
|
||||
TPMTestState test;
|
||||
|
||||
module_call_init(MODULE_INIT_QOM);
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
@ -156,6 +156,7 @@ int main(int argc, char **argv)
|
||||
g_mutex_init(&test.data_mutex);
|
||||
g_cond_init(&test.data_cond);
|
||||
test.data_cond_signal = false;
|
||||
test.tpm_version = TPM_VERSION_2_0;
|
||||
|
||||
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
|
||||
tpm_emu_test_wait_cond(&test);
|
||||
|
@ -16,9 +16,11 @@
|
||||
#include "backends/tpm/tpm_ioctl.h"
|
||||
#include "io/channel-socket.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
#include "tpm-emu.h"
|
||||
|
||||
void tpm_emu_test_wait_cond(TestState *s)
|
||||
void tpm_emu_test_wait_cond(TPMTestState *s)
|
||||
{
|
||||
gint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
|
||||
|
||||
@ -36,7 +38,7 @@ void tpm_emu_test_wait_cond(TestState *s)
|
||||
|
||||
static void *tpm_emu_tpm_thread(void *data)
|
||||
{
|
||||
TestState *s = data;
|
||||
TPMTestState *s = data;
|
||||
QIOChannel *ioc = s->tpm_ioc;
|
||||
|
||||
s->tpm_msg = g_new(struct tpm_hdr, 1);
|
||||
@ -56,9 +58,21 @@ static void *tpm_emu_tpm_thread(void *data)
|
||||
s->tpm_msg->code = be32_to_cpu(s->tpm_msg->code);
|
||||
|
||||
/* reply error */
|
||||
switch (s->tpm_version) {
|
||||
case TPM_VERSION_2_0:
|
||||
s->tpm_msg->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
|
||||
s->tpm_msg->len = cpu_to_be32(sizeof(struct tpm_hdr));
|
||||
s->tpm_msg->code = cpu_to_be32(TPM_RC_FAILURE);
|
||||
break;
|
||||
case TPM_VERSION_1_2:
|
||||
s->tpm_msg->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
|
||||
s->tpm_msg->len = cpu_to_be32(sizeof(struct tpm_hdr));
|
||||
s->tpm_msg->code = cpu_to_be32(TPM_FAIL);
|
||||
break;
|
||||
default:
|
||||
g_debug("unsupport TPM version %u", s->tpm_version);
|
||||
g_assert_not_reached();
|
||||
}
|
||||
qio_channel_write(ioc, (char *)s->tpm_msg, be32_to_cpu(s->tpm_msg->len),
|
||||
&error_abort);
|
||||
}
|
||||
@ -71,7 +85,7 @@ static void *tpm_emu_tpm_thread(void *data)
|
||||
|
||||
void *tpm_emu_ctrl_thread(void *data)
|
||||
{
|
||||
TestState *s = data;
|
||||
TPMTestState *s = data;
|
||||
QIOChannelSocket *lioc = qio_channel_socket_new();
|
||||
QIOChannel *ioc;
|
||||
|
||||
@ -180,3 +194,39 @@ void *tpm_emu_ctrl_thread(void *data)
|
||||
object_unref(OBJECT(lioc));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool tpm_model_is_available(const char *args, const char *tpm_if)
|
||||
{
|
||||
QTestState *qts;
|
||||
QDict *rsp_tpm;
|
||||
bool ret = false;
|
||||
|
||||
qts = qtest_init(args);
|
||||
if (!qts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rsp_tpm = qtest_qmp(qts, "{ 'execute': 'query-tpm'}");
|
||||
if (!qdict_haskey(rsp_tpm, "error")) {
|
||||
QDict *rsp_models = qtest_qmp(qts,
|
||||
"{ 'execute': 'query-tpm-models'}");
|
||||
if (qdict_haskey(rsp_models, "return")) {
|
||||
QList *models = qdict_get_qlist(rsp_models, "return");
|
||||
QListEntry *e;
|
||||
|
||||
QLIST_FOREACH_ENTRY(models, e) {
|
||||
QString *s = qobject_to(QString, qlist_entry_obj(e));
|
||||
const char *ename = qstring_get_str(s);
|
||||
if (!strcmp(ename, tpm_if)) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
qobject_unref(rsp_models);
|
||||
}
|
||||
qobject_unref(rsp_tpm);
|
||||
qtest_quit(qts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -16,8 +16,13 @@
|
||||
#define TPM_RC_FAILURE 0x101
|
||||
#define TPM2_ST_NO_SESSIONS 0x8001
|
||||
|
||||
#define TPM_FAIL 9
|
||||
#define TPM_TAG_RSP_COMMAND 0xc4
|
||||
|
||||
#include "qemu/sockets.h"
|
||||
#include "io/channel.h"
|
||||
#include "sysemu/tpm.h"
|
||||
#include "libqos/libqtest.h"
|
||||
|
||||
struct tpm_hdr {
|
||||
uint16_t tag;
|
||||
@ -26,7 +31,14 @@ struct tpm_hdr {
|
||||
char buffer[];
|
||||
} QEMU_PACKED;
|
||||
|
||||
typedef struct TestState {
|
||||
#ifndef CONFIG_TPM
|
||||
enum TPMVersion {
|
||||
TPM_VERSION_1_2 = 1,
|
||||
TPM_VERSION_2_0 = 2,
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef struct TPMTestState {
|
||||
GMutex data_mutex;
|
||||
GCond data_cond;
|
||||
bool data_cond_signal;
|
||||
@ -34,9 +46,11 @@ typedef struct TestState {
|
||||
QIOChannel *tpm_ioc;
|
||||
GThread *emu_tpm_thread;
|
||||
struct tpm_hdr *tpm_msg;
|
||||
} TestState;
|
||||
enum TPMVersion tpm_version;
|
||||
} TPMTestState;
|
||||
|
||||
void tpm_emu_test_wait_cond(TestState *s);
|
||||
void tpm_emu_test_wait_cond(TPMTestState *s);
|
||||
void *tpm_emu_ctrl_thread(void *data);
|
||||
bool tpm_model_is_available(const char *args, const char *tpm_if);
|
||||
|
||||
#endif /* TESTS_TPM_EMU_H */
|
||||
|
@ -33,7 +33,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
char *tmp_path = g_dir_make_tmp("qemu-tpm-tis-device-test.XXXXXX", NULL);
|
||||
GThread *thread;
|
||||
TestState test;
|
||||
TPMTestState test;
|
||||
char *args;
|
||||
int ret;
|
||||
|
||||
@ -46,6 +46,7 @@ int main(int argc, char **argv)
|
||||
g_mutex_init(&test.data_mutex);
|
||||
g_cond_init(&test.data_cond);
|
||||
test.data_cond_signal = false;
|
||||
test.tpm_version = TPM_VERSION_2_0;
|
||||
|
||||
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
|
||||
tpm_emu_test_wait_cond(&test);
|
||||
|
@ -29,7 +29,7 @@ int main(int argc, char **argv)
|
||||
int ret;
|
||||
char *args, *tmp_path = g_dir_make_tmp("qemu-tpm-tis-test.XXXXXX", NULL);
|
||||
GThread *thread;
|
||||
TestState test;
|
||||
TPMTestState test;
|
||||
|
||||
module_call_init(MODULE_INIT_QOM);
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
@ -40,6 +40,7 @@ int main(int argc, char **argv)
|
||||
g_mutex_init(&test.data_mutex);
|
||||
g_cond_init(&test.data_cond);
|
||||
test.data_cond_signal = false;
|
||||
test.tpm_version = TPM_VERSION_2_0;
|
||||
|
||||
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
|
||||
tpm_emu_test_wait_cond(&test);
|
||||
|
@ -373,7 +373,7 @@ void tpm_tis_test_check_access_reg_release(const void *data)
|
||||
*/
|
||||
void tpm_tis_test_check_transmit(const void *data)
|
||||
{
|
||||
const TestState *s = data;
|
||||
const TPMTestState *s = data;
|
||||
uint8_t access;
|
||||
uint32_t sts;
|
||||
uint16_t bcount;
|
||||
|
Loading…
Reference in New Issue
Block a user