* [PATCH v3 1/5] i386: Eliminate all TPM related code if CONFIG_TPM is not set
2021-06-14 20:09 [PATCH v3 0/5] tpm: Eliminate TPM related code if CONFIG_TPM is not set Philippe Mathieu-Daudé
@ 2021-06-14 20:09 ` Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 2/5] arm: " Philippe Mathieu-Daudé
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:09 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Philippe Mathieu-Daudé,
Stefan Berger, Markus Armbruster, qemu-arm, Igor Mammedov,
Eric Blake, Stefan Berger
From: Stefan Berger <stefanb@linux.ibm.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210614191335.1968807-2-stefanb@linux.ibm.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/i386/acpi-build.c | 20 ++++++++++++++++++++
stubs/tpm.c | 4 ----
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 80bee00da66..796ffc6f5c4 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -107,7 +107,9 @@ typedef struct AcpiPmInfo {
typedef struct AcpiMiscInfo {
bool is_piix4;
bool has_hpet;
+#ifdef CONFIG_TPM
TPMVersion tpm_version;
+#endif
const unsigned char *dsdt_code;
unsigned dsdt_size;
uint16_t pvpanic_port;
@@ -286,7 +288,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
}
info->has_hpet = hpet_find();
+#ifdef CONFIG_TPM
info->tpm_version = tpm_get_version(tpm_find());
+#endif
info->pvpanic_port = pvpanic_port();
info->applesmc_io_base = applesmc_port();
}
@@ -1371,7 +1375,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
uint32_t nr_mem = machine->ram_slots;
int root_bus_limit = 0xFF;
PCIBus *bus = NULL;
+#ifdef CONFIG_TPM
TPMIf *tpm = tpm_find();
+#endif
int i;
VMBusBridge *vmbus_bridge = vmbus_bridge_find();
@@ -1604,10 +1610,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
}
}
+#ifdef CONFIG_TPM
if (TPM_IS_TIS_ISA(tpm_find())) {
aml_append(crs, aml_memory32_fixed(TPM_TIS_ADDR_BASE,
TPM_TIS_ADDR_SIZE, AML_READ_WRITE));
}
+#endif
aml_append(scope, aml_name_decl("_CRS", crs));
/* reserve GPE0 block resources */
@@ -1753,6 +1761,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);
+#ifdef CONFIG_TPM
if (TPM_IS_TIS_ISA(tpm)) {
if (misc->tpm_version == TPM_VERSION_2_0) {
dev = aml_device("TPM");
@@ -1780,11 +1789,13 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
aml_append(scope, dev);
}
+#endif
aml_append(sb_scope, scope);
}
}
+#ifdef CONFIG_TPM
if (TPM_IS_CRB(tpm)) {
dev = aml_device("TPM");
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
@@ -1799,6 +1810,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
aml_append(sb_scope, dev);
}
+#endif
aml_append(dsdt, sb_scope);
@@ -1828,6 +1840,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker, const char *oem_id,
"HPET", sizeof(*hpet), 1, oem_id, oem_table_id);
}
+#ifdef CONFIG_TPM
static void
build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
const char *oem_id, const char *oem_table_id)
@@ -1854,6 +1867,7 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
(void *)(table_data->data + tcpa_start),
"TCPA", sizeof(*tcpa), 2, oem_id, oem_table_id);
}
+#endif
#define HOLE_640K_START (640 * KiB)
#define HOLE_640K_END (1 * MiB)
@@ -2403,6 +2417,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
build_hpet(tables_blob, tables->linker, x86ms->oem_id,
x86ms->oem_table_id);
}
+#ifdef CONFIG_TPM
if (misc.tpm_version != TPM_VERSION_UNSPEC) {
if (misc.tpm_version == TPM_VERSION_1_2) {
acpi_add_table(table_offsets, tables_blob);
@@ -2414,6 +2429,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
x86ms->oem_id, x86ms->oem_table_id);
}
}
+#endif
if (pcms->numa_nodes) {
acpi_add_table(table_offsets, tables_blob);
build_srat(tables_blob, tables->linker, machine);
@@ -2605,8 +2621,10 @@ void acpi_setup(void)
AcpiBuildTables tables;
AcpiBuildState *build_state;
Object *vmgenid_dev;
+#ifdef CONFIG_TPM
TPMIf *tpm;
static FwCfgTPMConfig tpm_config;
+#endif
if (!x86ms->fw_cfg) {
ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
@@ -2638,6 +2656,7 @@ void acpi_setup(void)
acpi_add_rom_blob(acpi_build_update, build_state,
tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE);
+#ifdef CONFIG_TPM
fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
tables.tcpalog->data, acpi_data_len(tables.tcpalog));
@@ -2651,6 +2670,7 @@ void acpi_setup(void)
fw_cfg_add_file(x86ms->fw_cfg, "etc/tpm/config",
&tpm_config, sizeof tpm_config);
}
+#endif
vmgenid_dev = find_vmgenid_dev();
if (vmgenid_dev) {
diff --git a/stubs/tpm.c b/stubs/tpm.c
index 9bded191d9d..22014595a06 100644
--- a/stubs/tpm.c
+++ b/stubs/tpm.c
@@ -33,7 +33,3 @@ TpmModelList *qmp_query_tpm_models(Error **errp)
{
return NULL;
}
-
-void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev)
-{
-}
--
2.31.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/5] arm: Eliminate all TPM related code if CONFIG_TPM is not set
2021-06-14 20:09 [PATCH v3 0/5] tpm: Eliminate TPM related code if CONFIG_TPM is not set Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 1/5] i386: Eliminate all " Philippe Mathieu-Daudé
@ 2021-06-14 20:09 ` Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 3/5] acpi: " Philippe Mathieu-Daudé
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:09 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Philippe Mathieu-Daudé,
Stefan Berger, Markus Armbruster, qemu-arm, Igor Mammedov,
Eric Blake, Stefan Berger
From: Stefan Berger <stefanb@linux.ibm.com>
Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210614191335.1968807-3-stefanb@linux.ibm.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/arm/sysbus-fdt.c | 4 ++++
hw/arm/virt-acpi-build.c | 6 ++++++
hw/arm/virt.c | 2 ++
3 files changed, 12 insertions(+)
diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
index 6b6906f4cfc..48c5fe9bf18 100644
--- a/hw/arm/sysbus-fdt.c
+++ b/hw/arm/sysbus-fdt.c
@@ -437,6 +437,7 @@ static bool vfio_platform_match(SysBusDevice *sbdev,
#endif /* CONFIG_LINUX */
+#ifdef CONFIG_TPM
/*
* add_tpm_tis_fdt_node: Create a DT node for TPM TIS
*
@@ -467,6 +468,7 @@ static int add_tpm_tis_fdt_node(SysBusDevice *sbdev, void *opaque)
g_free(nodename);
return 0;
}
+#endif
static int no_fdt_node(SysBusDevice *sbdev, void *opaque)
{
@@ -488,7 +490,9 @@ static const BindingEntry bindings[] = {
TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node),
VFIO_PLATFORM_BINDING("amd,xgbe-seattle-v1a", add_amd_xgbe_fdt_node),
#endif
+#ifdef CONFIG_TPM
TYPE_BINDING(TYPE_TPM_TIS_SYSBUS, add_tpm_tis_fdt_node),
+#endif
TYPE_BINDING(TYPE_RAMFB_DEVICE, no_fdt_node),
TYPE_BINDING("", NULL), /* last element */
};
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 60fe2e65a76..f1024843ddb 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -205,6 +205,7 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,
aml_append(scope, dev);
}
+#ifdef CONFIG_TPM
static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
{
PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
@@ -236,6 +237,7 @@ static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(scope, dev);
}
+#endif
static void
build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
@@ -642,7 +644,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
}
acpi_dsdt_add_power_button(scope);
+#ifdef CONFIG_TPM
acpi_dsdt_add_tpm(scope, vms);
+#endif
aml_append(dsdt, scope);
@@ -745,11 +749,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
build_iort(tables_blob, tables->linker, vms);
}
+#ifdef CONFIG_TPM
if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
acpi_add_table(table_offsets, tables_blob);
build_tpm2(tables_blob, tables->linker, tables->tcpalog, vms->oem_id,
vms->oem_table_id);
}
+#endif
/* XSDT is pointed to by RSDP */
xsdt = tables_blob->len;
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 840758666d4..9122e22ee0c 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2599,7 +2599,9 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM);
+#ifdef CONFIG_TPM
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
+#endif
mc->block_default_type = IF_VIRTIO;
mc->no_cdrom = 1;
mc->pci_allow_0_address = true;
--
2.31.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 3/5] acpi: Eliminate all TPM related code if CONFIG_TPM is not set
2021-06-14 20:09 [PATCH v3 0/5] tpm: Eliminate TPM related code if CONFIG_TPM is not set Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 1/5] i386: Eliminate all " Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 2/5] arm: " Philippe Mathieu-Daudé
@ 2021-06-14 20:09 ` Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 4/5] sysemu: Make TPM structures inaccessible if CONFIG_TPM is not defined Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build Philippe Mathieu-Daudé
4 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:09 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Philippe Mathieu-Daudé,
Stefan Berger, Markus Armbruster, qemu-arm, Igor Mammedov,
Eric Blake, Stefan Berger
From: Stefan Berger <stefanb@linux.ibm.com>
Cc: M: Michael S. Tsirkin <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210614191335.1968807-4-stefanb@linux.ibm.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/hw/acpi/tpm.h | 4 ++++
hw/acpi/aml-build.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h
index 1a2a57a21f0..559ba6906c8 100644
--- a/include/hw/acpi/tpm.h
+++ b/include/hw/acpi/tpm.h
@@ -21,6 +21,8 @@
#include "hw/acpi/aml-build.h"
#include "sysemu/tpm.h"
+#ifdef CONFIG_TPM
+
#define TPM_TIS_ADDR_BASE 0xFED40000
#define TPM_TIS_ADDR_SIZE 0x5000
@@ -209,4 +211,6 @@ REG32(CRB_DATA_BUFFER, 0x80)
void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev);
+#endif /* CONFIG_TPM */
+
#endif /* HW_ACPI_TPM_H */
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index f0035d2b4a1..d5103e6d7b0 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -2044,6 +2044,7 @@ build_hdr:
"FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
}
+#ifdef CONFIG_TPM
/*
* build_tpm2 - Build the TPM2 table as specified in
* table 7: TCG Hardware Interface Description Table Format for TPM 2.0
@@ -2101,6 +2102,7 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
(void *)(table_data->data + tpm2_start),
"TPM2", table_data->len - tpm2_start, 4, oem_id, oem_table_id);
}
+#endif
Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set, uint32_t io_offset,
uint32_t mmio32_offset, uint64_t mmio64_offset,
--
2.31.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 4/5] sysemu: Make TPM structures inaccessible if CONFIG_TPM is not defined
2021-06-14 20:09 [PATCH v3 0/5] tpm: Eliminate TPM related code if CONFIG_TPM is not set Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2021-06-14 20:09 ` [PATCH v3 3/5] acpi: " Philippe Mathieu-Daudé
@ 2021-06-14 20:09 ` Philippe Mathieu-Daudé
2021-06-14 20:09 ` [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build Philippe Mathieu-Daudé
4 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:09 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Philippe Mathieu-Daudé,
Stefan Berger, Markus Armbruster, qemu-arm, Igor Mammedov,
Eric Blake, Stefan Berger
From: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210614191335.1968807-5-stefanb@linux.ibm.com>
[PMD: Remove tpm_init() / tpm_cleanup() stubs]
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/sysemu/tpm.h | 9 +++++++++
include/sysemu/tpm_backend.h | 6 +++++-
stubs/tpm.c | 10 ----------
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h
index 1a85564e479..68b2206463c 100644
--- a/include/sysemu/tpm.h
+++ b/include/sysemu/tpm.h
@@ -15,6 +15,8 @@
#include "qapi/qapi-types-tpm.h"
#include "qom/object.h"
+#ifdef CONFIG_TPM
+
int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
int tpm_init(void);
void tpm_cleanup(void);
@@ -73,4 +75,11 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
return TPM_IF_GET_CLASS(ti)->get_version(ti);
}
+#else /* CONFIG_TPM */
+
+#define tpm_init() (0)
+#define tpm_cleanup()
+
+#endif /* CONFIG_TPM */
+
#endif /* QEMU_TPM_H */
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 6f078f5f482..8fd3269c117 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -18,6 +18,8 @@
#include "sysemu/tpm.h"
#include "qapi/error.h"
+#ifdef CONFIG_TPM
+
#define TYPE_TPM_BACKEND "tpm-backend"
OBJECT_DECLARE_TYPE(TPMBackend, TPMBackendClass,
TPM_BACKEND)
@@ -209,4 +211,6 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
TPMBackend *qemu_find_tpm_be(const char *id);
-#endif
+#endif /* CONFIG_TPM */
+
+#endif /* TPM_BACKEND_H */
diff --git a/stubs/tpm.c b/stubs/tpm.c
index 22014595a06..e79bd2a6c2d 100644
--- a/stubs/tpm.c
+++ b/stubs/tpm.c
@@ -7,18 +7,8 @@
#include "qemu/osdep.h"
#include "qapi/qapi-commands-tpm.h"
-#include "sysemu/tpm.h"
#include "hw/acpi/tpm.h"
-int tpm_init(void)
-{
- return 0;
-}
-
-void tpm_cleanup(void)
-{
-}
-
TPMInfoList *qmp_query_tpm(Error **errp)
{
return NULL;
--
2.31.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build
2021-06-14 20:09 [PATCH v3 0/5] tpm: Eliminate TPM related code if CONFIG_TPM is not set Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2021-06-14 20:09 ` [PATCH v3 4/5] sysemu: Make TPM structures inaccessible if CONFIG_TPM is not defined Philippe Mathieu-Daudé
@ 2021-06-14 20:09 ` Philippe Mathieu-Daudé
2021-06-14 20:12 ` Philippe Mathieu-Daudé
2021-06-15 8:51 ` Markus Armbruster
4 siblings, 2 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:09 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Philippe Mathieu-Daudé,
Stefan Berger, Markus Armbruster, qemu-arm,
Marc-André Lureau, Igor Mammedov, Eric Blake
When the management layer queries a binary built using --disable-tpm
for TPM devices, it gets confused by getting empty responses:
{ "execute": "query-tpm" }
{
"return": [
]
}
{ "execute": "query-tpm-types" }
{
"return": [
]
}
{ "execute": "query-tpm-models" }
{
"return": [
]
}
To make it clearer by returning an error:
- Make the TPM QAPI schema conditional
- Adapt the HMP command
- Remove stubs which became unnecessary
The management layer now gets a 'CommandNotFound' error:
{ "execute": "query-tpm" }
{
"error": {
"class": "CommandNotFound",
"desc": "The command query-tpm has not been found"
}
}
Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
qapi/tpm.json | 28 +++++++++++++++++++---------
monitor/hmp-cmds.c | 4 ++++
stubs/tpm.c | 25 -------------------------
stubs/meson.build | 1 -
4 files changed, 23 insertions(+), 35 deletions(-)
delete mode 100644 stubs/tpm.c
diff --git a/qapi/tpm.json b/qapi/tpm.json
index 6a10c9ed8d2..75590979fde 100644
--- a/qapi/tpm.json
+++ b/qapi/tpm.json
@@ -17,7 +17,9 @@
#
# Since: 1.5
##
-{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ] }
+{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ],
+ 'if': 'defined(CONFIG_TPM)' }
+
##
# @query-tpm-models:
#
@@ -33,7 +35,8 @@
# <- { "return": [ "tpm-tis", "tpm-crb", "tpm-spapr" ] }
#
##
-{ 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
+{ 'command': 'query-tpm-models', 'returns': ['TpmModel'],
+ 'if': 'defined(CONFIG_TPM)' }
##
# @TpmType:
@@ -46,7 +49,8 @@
#
# Since: 1.5
##
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ] }
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
+ 'if': 'defined(CONFIG_TPM)' }
##
# @query-tpm-types:
@@ -63,7 +67,8 @@
# <- { "return": [ "passthrough", "emulator" ] }
#
##
-{ 'command': 'query-tpm-types', 'returns': ['TpmType'] }
+{ 'command': 'query-tpm-types', 'returns': ['TpmType'],
+ 'if': 'defined(CONFIG_TPM)' }
##
# @TPMPassthroughOptions:
@@ -79,7 +84,8 @@
##
{ 'struct': 'TPMPassthroughOptions',
'data': { '*path': 'str',
- '*cancel-path': 'str' } }
+ '*cancel-path': 'str' },
+ 'if': 'defined(CONFIG_TPM)' }
##
# @TPMEmulatorOptions:
@@ -90,7 +96,8 @@
#
# Since: 2.11
##
-{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' } }
+{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' },
+ 'if': 'defined(CONFIG_TPM)' }
##
# @TpmTypeOptions:
@@ -104,7 +111,8 @@
##
{ 'union': 'TpmTypeOptions',
'data': { 'passthrough' : 'TPMPassthroughOptions',
- 'emulator': 'TPMEmulatorOptions' } }
+ 'emulator': 'TPMEmulatorOptions' },
+ 'if': 'defined(CONFIG_TPM)' }
##
# @TPMInfo:
@@ -122,7 +130,8 @@
{ 'struct': 'TPMInfo',
'data': {'id': 'str',
'model': 'TpmModel',
- 'options': 'TpmTypeOptions' } }
+ 'options': 'TpmTypeOptions' },
+ 'if': 'defined(CONFIG_TPM)' }
##
# @query-tpm:
@@ -152,4 +161,5 @@
# }
#
##
-{ 'command': 'query-tpm', 'returns': ['TPMInfo'] }
+{ 'command': 'query-tpm', 'returns': ['TPMInfo'],
+ 'if': 'defined(CONFIG_TPM)' }
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index d10ee141109..f6cadede40f 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -901,6 +901,9 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict)
void hmp_info_tpm(Monitor *mon, const QDict *qdict)
{
+#ifndef CONFIG_TPM
+ monitor_printf(mon, "TPM device not supported\n");
+#else
TPMInfoList *info_list, *info;
Error *err = NULL;
unsigned int c = 0;
@@ -946,6 +949,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
c++;
}
qapi_free_TPMInfoList(info_list);
+#endif /* CONFIG_TPM */
}
void hmp_quit(Monitor *mon, const QDict *qdict)
diff --git a/stubs/tpm.c b/stubs/tpm.c
deleted file mode 100644
index e79bd2a6c2d..00000000000
--- a/stubs/tpm.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * TPM stubs
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include "qemu/osdep.h"
-#include "qapi/qapi-commands-tpm.h"
-#include "hw/acpi/tpm.h"
-
-TPMInfoList *qmp_query_tpm(Error **errp)
-{
- return NULL;
-}
-
-TpmTypeList *qmp_query_tpm_types(Error **errp)
-{
- return NULL;
-}
-
-TpmModelList *qmp_query_tpm_models(Error **errp)
-{
- return NULL;
-}
diff --git a/stubs/meson.build b/stubs/meson.build
index 65c22c0568c..d4e9549dc99 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -38,7 +38,6 @@
stub_ss.add(files('sysbus.c'))
stub_ss.add(files('target-get-monitor-def.c'))
stub_ss.add(files('target-monitor-defs.c'))
-stub_ss.add(files('tpm.c'))
stub_ss.add(files('trace-control.c'))
stub_ss.add(files('uuid.c'))
stub_ss.add(files('vmgenid.c'))
--
2.31.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build
2021-06-14 20:09 ` [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build Philippe Mathieu-Daudé
@ 2021-06-14 20:12 ` Philippe Mathieu-Daudé
2021-06-14 21:57 ` Stefan Berger
2021-06-15 8:51 ` Markus Armbruster
1 sibling, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-14 20:12 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Stefan Berger, Markus Armbruster, qemu-arm,
Marc-André Lureau, Igor Mammedov, Eric Blake
On 6/14/21 10:09 PM, Philippe Mathieu-Daudé wrote:
> When the management layer queries a binary built using --disable-tpm
> for TPM devices, it gets confused by getting empty responses:
>
> { "execute": "query-tpm" }
> {
> "return": [
> ]
> }
> { "execute": "query-tpm-types" }
> {
> "return": [
> ]
> }
> { "execute": "query-tpm-models" }
> {
> "return": [
> ]
> }
>
> To make it clearer by returning an error:
> - Make the TPM QAPI schema conditional
> - Adapt the HMP command
> - Remove stubs which became unnecessary
>
> The management layer now gets a 'CommandNotFound' error:
>
> { "execute": "query-tpm" }
> {
> "error": {
> "class": "CommandNotFound",
> "desc": "The command query-tpm has not been found"
> }
> }
>
> Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> qapi/tpm.json | 28 +++++++++++++++++++---------
> monitor/hmp-cmds.c | 4 ++++
> stubs/tpm.c | 25 -------------------------
> stubs/meson.build | 1 -
> 4 files changed, 23 insertions(+), 35 deletions(-)
> delete mode 100644 stubs/tpm.c
Grrrr I forgot to commit:
-- >8 --
diff --git a/MAINTAINERS b/MAINTAINERS
index 7d9cd290426..636bf2f5365 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2707,7 +2707,6 @@ TPM
M: Stefan Berger <stefanb@linux.ibm.com>
S: Maintained
F: tpm.c
-F: stubs/tpm.c
F: hw/tpm/*
F: include/hw/acpi/tpm.h
F: include/sysemu/tpm*
---
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build
2021-06-14 20:12 ` Philippe Mathieu-Daudé
@ 2021-06-14 21:57 ` Stefan Berger
2021-06-15 8:52 ` Markus Armbruster
0 siblings, 1 reply; 10+ messages in thread
From: Stefan Berger @ 2021-06-14 21:57 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Michael S. Tsirkin, Stefan Berger, Markus Armbruster, qemu-arm,
Marc-André Lureau, Igor Mammedov, Eric Blake
On 6/14/21 4:12 PM, Philippe Mathieu-Daudé wrote:
>
> Grrrr I forgot to commit:
>
> -- >8 --
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 7d9cd290426..636bf2f5365 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2707,7 +2707,6 @@ TPM
> M: Stefan Berger <stefanb@linux.ibm.com>
> S: Maintained
> F: tpm.c
> -F: stubs/tpm.c
> F: hw/tpm/*
> F: include/hw/acpi/tpm.h
> F: include/sysemu/tpm*
> ---
>
Who is going to upstream the series? I could add this part ...
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build
2021-06-14 21:57 ` Stefan Berger
@ 2021-06-15 8:52 ` Markus Armbruster
0 siblings, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2021-06-15 8:52 UTC (permalink / raw)
To: Stefan Berger
Cc: Stefan Berger, Eric Blake, Michael S. Tsirkin, qemu-devel,
qemu-arm, Igor Mammedov, Marc-André Lureau,
Philippe Mathieu-Daudé
Stefan Berger <stefanb@linux.ibm.com> writes:
> On 6/14/21 4:12 PM, Philippe Mathieu-Daudé wrote:
>>
>> Grrrr I forgot to commit:
>>
>> -- >8 --
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 7d9cd290426..636bf2f5365 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -2707,7 +2707,6 @@ TPM
>> M: Stefan Berger <stefanb@linux.ibm.com>
>> S: Maintained
>> F: tpm.c
>> -F: stubs/tpm.c
>> F: hw/tpm/*
>> F: include/hw/acpi/tpm.h
>> F: include/sysemu/tpm*
>> ---
>>
> Who is going to upstream the series? I could add this part ...
Please do.
Thank you!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build
2021-06-14 20:09 ` [PATCH v3 5/5] tpm: Return QMP error when TPM is disabled in build Philippe Mathieu-Daudé
2021-06-14 20:12 ` Philippe Mathieu-Daudé
@ 2021-06-15 8:51 ` Markus Armbruster
1 sibling, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2021-06-15 8:51 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Stefan Berger, Michael S. Tsirkin, qemu-devel, qemu-arm,
Igor Mammedov, Marc-André Lureau, Eric Blake
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> When the management layer queries a binary built using --disable-tpm
> for TPM devices, it gets confused by getting empty responses:
>
> { "execute": "query-tpm" }
> {
> "return": [
> ]
> }
> { "execute": "query-tpm-types" }
> {
> "return": [
> ]
> }
> { "execute": "query-tpm-models" }
> {
> "return": [
> ]
> }
>
> To make it clearer by returning an error:
> - Make the TPM QAPI schema conditional
All of tpm.json is now 'if': 'defined(CONFIG_TPM)'. Good.
> - Adapt the HMP command
> - Remove stubs which became unnecessary
>
> The management layer now gets a 'CommandNotFound' error:
>
> { "execute": "query-tpm" }
> {
> "error": {
> "class": "CommandNotFound",
> "desc": "The command query-tpm has not been found"
> }
> }
>
> Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> qapi/tpm.json | 28 +++++++++++++++++++---------
> monitor/hmp-cmds.c | 4 ++++
> stubs/tpm.c | 25 -------------------------
> stubs/meson.build | 1 -
> 4 files changed, 23 insertions(+), 35 deletions(-)
> delete mode 100644 stubs/tpm.c
>
> diff --git a/qapi/tpm.json b/qapi/tpm.json
> index 6a10c9ed8d2..75590979fde 100644
> --- a/qapi/tpm.json
> +++ b/qapi/tpm.json
> @@ -17,7 +17,9 @@
> #
> # Since: 1.5
> ##
> -{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ] }
> +{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ],
> + 'if': 'defined(CONFIG_TPM)' }
> +
> ##
> # @query-tpm-models:
> #
> @@ -33,7 +35,8 @@
> # <- { "return": [ "tpm-tis", "tpm-crb", "tpm-spapr" ] }
> #
> ##
> -{ 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
> +{ 'command': 'query-tpm-models', 'returns': ['TpmModel'],
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @TpmType:
> @@ -46,7 +49,8 @@
> #
> # Since: 1.5
> ##
> -{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ] }
> +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @query-tpm-types:
> @@ -63,7 +67,8 @@
> # <- { "return": [ "passthrough", "emulator" ] }
> #
> ##
> -{ 'command': 'query-tpm-types', 'returns': ['TpmType'] }
> +{ 'command': 'query-tpm-types', 'returns': ['TpmType'],
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @TPMPassthroughOptions:
> @@ -79,7 +84,8 @@
> ##
> { 'struct': 'TPMPassthroughOptions',
> 'data': { '*path': 'str',
> - '*cancel-path': 'str' } }
> + '*cancel-path': 'str' },
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @TPMEmulatorOptions:
> @@ -90,7 +96,8 @@
> #
> # Since: 2.11
> ##
> -{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' } }
> +{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' },
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @TpmTypeOptions:
> @@ -104,7 +111,8 @@
> ##
> { 'union': 'TpmTypeOptions',
> 'data': { 'passthrough' : 'TPMPassthroughOptions',
> - 'emulator': 'TPMEmulatorOptions' } }
> + 'emulator': 'TPMEmulatorOptions' },
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @TPMInfo:
> @@ -122,7 +130,8 @@
> { 'struct': 'TPMInfo',
> 'data': {'id': 'str',
> 'model': 'TpmModel',
> - 'options': 'TpmTypeOptions' } }
> + 'options': 'TpmTypeOptions' },
> + 'if': 'defined(CONFIG_TPM)' }
>
> ##
> # @query-tpm:
> @@ -152,4 +161,5 @@
> # }
> #
> ##
> -{ 'command': 'query-tpm', 'returns': ['TPMInfo'] }
> +{ 'command': 'query-tpm', 'returns': ['TPMInfo'],
> + 'if': 'defined(CONFIG_TPM)' }
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index d10ee141109..f6cadede40f 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -901,6 +901,9 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict)
>
> void hmp_info_tpm(Monitor *mon, const QDict *qdict)
> {
> +#ifndef CONFIG_TPM
> + monitor_printf(mon, "TPM device not supported\n");
> +#else
I dislike #ifndef ... #else. Matter of taste.
> TPMInfoList *info_list, *info;
> Error *err = NULL;
> unsigned int c = 0;
> @@ -946,6 +949,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
> c++;
> }
> qapi_free_TPMInfoList(info_list);
> +#endif /* CONFIG_TPM */
> }
>
> void hmp_quit(Monitor *mon, const QDict *qdict)
> diff --git a/stubs/tpm.c b/stubs/tpm.c
> deleted file mode 100644
> index e79bd2a6c2d..00000000000
> --- a/stubs/tpm.c
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -/*
> - * TPM stubs
> - *
> - * This work is licensed under the terms of the GNU GPL, version 2 or later.
> - * See the COPYING file in the top-level directory.
> - */
> -
> -#include "qemu/osdep.h"
> -#include "qapi/qapi-commands-tpm.h"
> -#include "hw/acpi/tpm.h"
> -
> -TPMInfoList *qmp_query_tpm(Error **errp)
> -{
> - return NULL;
> -}
> -
> -TpmTypeList *qmp_query_tpm_types(Error **errp)
> -{
> - return NULL;
> -}
> -
> -TpmModelList *qmp_query_tpm_models(Error **errp)
> -{
> - return NULL;
> -}
> diff --git a/stubs/meson.build b/stubs/meson.build
> index 65c22c0568c..d4e9549dc99 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -38,7 +38,6 @@
> stub_ss.add(files('sysbus.c'))
> stub_ss.add(files('target-get-monitor-def.c'))
> stub_ss.add(files('target-monitor-defs.c'))
> -stub_ss.add(files('tpm.c'))
> stub_ss.add(files('trace-control.c'))
> stub_ss.add(files('uuid.c'))
> stub_ss.add(files('vmgenid.c'))
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread