All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 0/3] vTPM/aarch64 ACPI support
@ 2020-06-22 14:06 Eric Auger
  2020-06-22 14:06 ` [PATCH v7 1/3] acpi: Some build_tpm2() code reshape Eric Auger
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Auger @ 2020-06-22 14:06 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, stefanb, qemu-devel, qemu-arm,
	peter.maydell, mst, imammedo
  Cc: thuth, lersek, drjones, shannon.zhaosl, marcandre.lureau, philmd, ardb

Those patches bring MMIO TPM TIS ACPI support in machvirt.

On ARM, the TPM2 table is added when the TPM TIS sysbus
device is dynamically instantiated in machvirt.

Also the TPM2 device object is described in the DSDT.

Many thanks to Ard for his support.

Tested with LUKS partition automatic decryption. Also
tested with new bios-tables-test dedicated tests,
sent separately.

Best Regards

Eric

This series can be found at:
https://github.com/eauger/qemu/tree/v5.0-tpm-acpi-v7

History:

v6 -> v7:
- Collected Stefan and Igor's R-bs
- Eventually removed Acpi20TPM2 struct
- Updated the reference to the spec v1.2 rev8

v5 -> v6:
- added reference to the spec
- add some comments about LAML and LASA fields which are
  strangely undocumented in the spec for TPM2.0. So I kept
  the decision to keep the Acpi20TPM2 struct for documentation
  purpose.

v4 -> v5:
- Move of build_tpm2() in the generic acpi code was upstreamed
  but this does not correspond to latest proposed version.
- Rebase on top of edfcb1f21a

v3 -> v4:
- some rework in build_tpm2() as suggested by Igor
- Restored tpm presence check in acpi_dsdt_add_tpm()
- add the doc related patch

v2 -> v3:
- Rebase on top of Stefan's
  "acpi: tpm: Do not build TCPA table for TPM 2"
- brings conversion to build_append

v1 -> v2:
- move build_tpm2() in the generic code (Michael)
- collect Stefan's R-b on 3/3

Eric Auger (3):
  acpi: Some build_tpm2() code reshape
  arm/acpi: Add the TPM2.0 device under the DSDT
  docs/specs/tpm: ACPI boot now supported for TPM/ARM

 docs/specs/tpm.rst          |  2 --
 include/hw/acpi/acpi-defs.h | 18 -------------
 hw/acpi/aml-build.c         | 51 +++++++++++++++++++++++--------------
 hw/arm/virt-acpi-build.c    | 34 +++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 39 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v7 1/3] acpi: Some build_tpm2() code reshape
  2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
@ 2020-06-22 14:06 ` Eric Auger
  2020-06-22 14:06 ` [PATCH v7 2/3] arm/acpi: Add the TPM2.0 device under the DSDT Eric Auger
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Auger @ 2020-06-22 14:06 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, stefanb, qemu-devel, qemu-arm,
	peter.maydell, mst, imammedo
  Cc: thuth, lersek, drjones, shannon.zhaosl, marcandre.lureau, philmd, ardb

Remove any reference to Acpi20TPM2 and adopt an implementation
similar to build_ghes_v2().

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Suggested-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

---

v6 -> v7:
- eventually removed Acpi20TPM2 struct
- updated the reference to the spec v1.2 rev8

v5 -> v6:
- add reference to the spec + comment about LAML and LASA fields
- also moved LASA intro comment above build_append_int_noprefix()
  as requested by Igor
---
 include/hw/acpi/acpi-defs.h | 18 -------------
 hw/acpi/aml-build.c         | 51 +++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 3be9ab5049..38a42f409a 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -465,24 +465,6 @@ struct Acpi20Tcpa {
 } QEMU_PACKED;
 typedef struct Acpi20Tcpa Acpi20Tcpa;
 
-/*
- * TPM2
- *
- * Following Version 1.2, Revision 8 of specs:
- * https://trustedcomputinggroup.org/tcg-acpi-specification/
- */
-struct Acpi20TPM2 {
-    ACPI_TABLE_HEADER_DEF
-    uint16_t platform_class;
-    uint16_t reserved;
-    uint64_t control_area_address;
-    uint32_t start_method;
-    uint8_t start_method_params[12];
-    uint32_t log_area_minimum_length;
-    uint64_t log_area_start_address;
-} QEMU_PACKED;
-typedef struct Acpi20TPM2 Acpi20TPM2;
-
 /* DMAR - DMA Remapping table r2.2 */
 struct AcpiTableDmar {
     ACPI_TABLE_HEADER_DEF
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 2cb7b991ef..f6fbc9b95d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1878,48 +1878,61 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+/*
+ * build_tpm2 - Build the TPM2 table as specified in
+ * table 7: TCG Hardware Interface Description Table Format for TPM 2.0
+ * of TCG ACPI Specification, Family “1.2” and “2.0”, Version 1.2, Rev 8
+ */
 void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
 {
-    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
-    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
-    unsigned log_addr_offset =
-        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
     uint8_t start_method_params[12] = {};
+    unsigned log_addr_offset, tpm2_start;
+    uint64_t control_area_start_address;
     TPMIf *tpmif = tpm_find();
+    uint32_t start_method;
+    void *tpm2_ptr;
 
-    /* platform class */
+    tpm2_start = table_data->len;
+    tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
+
+    /* Platform Class */
     build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2);
-    /* reserved */
+    /* Reserved */
     build_append_int_noprefix(table_data, 0, 2);
     if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
-        /* address of control area */
-        build_append_int_noprefix(table_data, 0, 8);
-        /* start method */
-        build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO, 4);
+        control_area_start_address = 0;
+        start_method = TPM2_START_METHOD_MMIO;
     } else if (TPM_IS_CRB(tpmif)) {
-        build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8);
-        build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4);
+        control_area_start_address = TPM_CRB_ADDR_CTRL;
+        start_method = TPM2_START_METHOD_CRB;
     } else {
-        g_warn_if_reached();
+        g_assert_not_reached();
     }
+    /* Address of Control Area */
+    build_append_int_noprefix(table_data, control_area_start_address, 8);
+    /* Start Method */
+    build_append_int_noprefix(table_data, start_method, 4);
 
-    /* platform specific parameters */
-    g_array_append_vals(table_data, &start_method_params, 12);
+    /* Platform Specific Parameters */
+    g_array_append_vals(table_data, &start_method_params,
+                        ARRAY_SIZE(start_method_params));
 
-    /* log area minimum length */
+    /* Log Area Minimum Length */
     build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4);
 
     acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
     bios_linker_loader_alloc(linker, ACPI_BUILD_TPMLOG_FILE, tcpalog, 1,
                              false);
 
-    /* log area start address to be filled by Guest linker */
+    log_addr_offset = table_data->len;
+
+    /* Log Area Start Address to be filled by Guest linker */
     build_append_int_noprefix(table_data, 0, 8);
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
-                                   log_addr_offset, log_addr_size,
+                                   log_addr_offset, 8,
                                    ACPI_BUILD_TPMLOG_FILE, 0);
     build_header(linker, table_data,
-                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+                 tpm2_ptr, "TPM2", table_data->len - tpm2_start, 4, NULL, NULL);
 }
 
 /* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v7 2/3] arm/acpi: Add the TPM2.0 device under the DSDT
  2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
  2020-06-22 14:06 ` [PATCH v7 1/3] acpi: Some build_tpm2() code reshape Eric Auger
@ 2020-06-22 14:06 ` Eric Auger
  2020-06-22 14:06 ` [PATCH v7 3/3] docs/specs/tpm: ACPI boot now supported for TPM/ARM Eric Auger
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Auger @ 2020-06-22 14:06 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, stefanb, qemu-devel, qemu-arm,
	peter.maydell, mst, imammedo
  Cc: thuth, lersek, drjones, shannon.zhaosl, marcandre.lureau, philmd, ardb

In case it is dynamically instantiated, add the TPM 2.0 device object
under the DSDT table in the ACPI namespace. Its HID is MSFT0101
while its current resource settings (CRS) property is initialized
with the guest physical address and MMIO size of the device.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

---

v3 -> v4:
- check the presence of the tpm in acpi_dsdt_add_tpm
  as it was done in v2

v2 -> v3:
- use SYS_BUS_DEVICE() instead of
  (SysBusDevice *)object_dynamic_cast(OBJECT())

v1 -> v2:
- use memory_region_size
- fix mingw compilation issue by casting to uint32_t
- added Stefan's R-b
---
 hw/arm/virt-acpi-build.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index ca31f70f7f..1384a2cf2a 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -46,6 +46,7 @@
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
 #include "hw/mem/nvdimm.h"
+#include "hw/platform-bus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
 #include "sysemu/tpm.h"
@@ -364,6 +365,38 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
+    MemoryRegion *sbdev_mr;
+    hwaddr tpm_base;
+
+    if (!sbdev) {
+        return;
+    }
+
+    tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
+    assert(tpm_base != -1);
+
+    tpm_base += pbus_base;
+
+    sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
+
+    Aml *dev = aml_device("TPM0");
+    aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+    Aml *crs = aml_resource_template();
+    aml_append(crs,
+               aml_memory32_fixed(tpm_base,
+                                  (uint32_t)memory_region_size(sbdev_mr),
+                                  AML_READ_WRITE));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
@@ -762,6 +795,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     }
 
     acpi_dsdt_add_power_button(scope);
+    acpi_dsdt_add_tpm(scope, vms);
 
     aml_append(dsdt, scope);
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v7 3/3] docs/specs/tpm: ACPI boot now supported for TPM/ARM
  2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
  2020-06-22 14:06 ` [PATCH v7 1/3] acpi: Some build_tpm2() code reshape Eric Auger
  2020-06-22 14:06 ` [PATCH v7 2/3] arm/acpi: Add the TPM2.0 device under the DSDT Eric Auger
@ 2020-06-22 14:06 ` Eric Auger
  2020-06-24 12:53 ` [PATCH v7 0/3] vTPM/aarch64 ACPI support Ard Biesheuvel
  2020-06-25 13:34 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Auger @ 2020-06-22 14:06 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, stefanb, qemu-devel, qemu-arm,
	peter.maydell, mst, imammedo
  Cc: thuth, lersek, drjones, shannon.zhaosl, marcandre.lureau, philmd, ardb

ACPI boot now is supported. Let's remove the comment
saying it is not.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---
 docs/specs/tpm.rst | 2 --
 1 file changed, 2 deletions(-)

diff --git a/docs/specs/tpm.rst b/docs/specs/tpm.rst
index 5e61238bc5..eeeb93730a 100644
--- a/docs/specs/tpm.rst
+++ b/docs/specs/tpm.rst
@@ -346,8 +346,6 @@ In case an Arm virt machine is emulated, use the following command line:
     -drive if=pflash,format=raw,file=flash0.img,readonly \
     -drive if=pflash,format=raw,file=flash1.img
 
-  On Arm, ACPI boot with TPM is not yet supported.
-
 In case SeaBIOS is used as firmware, it should show the TPM menu item
 after entering the menu with 'ESC'.
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v7 0/3] vTPM/aarch64 ACPI support
  2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
                   ` (2 preceding siblings ...)
  2020-06-22 14:06 ` [PATCH v7 3/3] docs/specs/tpm: ACPI boot now supported for TPM/ARM Eric Auger
@ 2020-06-24 12:53 ` Ard Biesheuvel
  2020-06-25 13:34 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2020-06-24 12:53 UTC (permalink / raw)
  To: Eric Auger
  Cc: Peter Maydell, thuth, Andrew Jones, Michael S. Tsirkin,
	Laszlo Ersek, qemu-devel, Shannon Zhao, qemu-arm,
	marcandre.lureau, imammedo, eric.auger.pro, philmd, stefanb

On Mon, 22 Jun 2020 at 16:06, Eric Auger <eric.auger@redhat.com> wrote:
>
> Those patches bring MMIO TPM TIS ACPI support in machvirt.
>
> On ARM, the TPM2 table is added when the TPM TIS sysbus
> device is dynamically instantiated in machvirt.
>
> Also the TPM2 device object is described in the DSDT.
>
> Many thanks to Ard for his support.
>
> Tested with LUKS partition automatic decryption. Also
> tested with new bios-tables-test dedicated tests,
> sent separately.
>
> Best Regards
>
> Eric
>
> This series can be found at:
> https://github.com/eauger/qemu/tree/v5.0-tpm-acpi-v7
>
> History:
>
> v6 -> v7:
> - Collected Stefan and Igor's R-bs
> - Eventually removed Acpi20TPM2 struct
> - Updated the reference to the spec v1.2 rev8
>
> v5 -> v6:
> - added reference to the spec
> - add some comments about LAML and LASA fields which are
>   strangely undocumented in the spec for TPM2.0. So I kept
>   the decision to keep the Acpi20TPM2 struct for documentation
>   purpose.
>
> v4 -> v5:
> - Move of build_tpm2() in the generic acpi code was upstreamed
>   but this does not correspond to latest proposed version.
> - Rebase on top of edfcb1f21a
>
> v3 -> v4:
> - some rework in build_tpm2() as suggested by Igor
> - Restored tpm presence check in acpi_dsdt_add_tpm()
> - add the doc related patch
>
> v2 -> v3:
> - Rebase on top of Stefan's
>   "acpi: tpm: Do not build TCPA table for TPM 2"
> - brings conversion to build_append
>
> v1 -> v2:
> - move build_tpm2() in the generic code (Michael)
> - collect Stefan's R-b on 3/3
>
> Eric Auger (3):
>   acpi: Some build_tpm2() code reshape
>   arm/acpi: Add the TPM2.0 device under the DSDT
>   docs/specs/tpm: ACPI boot now supported for TPM/ARM
>

For the series

Tested-by: Ard Biesheuvel <ardb@kernel.org>

Thanks!

>  docs/specs/tpm.rst          |  2 --
>  include/hw/acpi/acpi-defs.h | 18 -------------
>  hw/acpi/aml-build.c         | 51 +++++++++++++++++++++++--------------
>  hw/arm/virt-acpi-build.c    | 34 +++++++++++++++++++++++++
>  4 files changed, 66 insertions(+), 39 deletions(-)
>
> --
> 2.20.1
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v7 0/3] vTPM/aarch64 ACPI support
  2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
                   ` (3 preceding siblings ...)
  2020-06-24 12:53 ` [PATCH v7 0/3] vTPM/aarch64 ACPI support Ard Biesheuvel
@ 2020-06-25 13:34 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2020-06-25 13:34 UTC (permalink / raw)
  To: Eric Auger
  Cc: Thomas Huth, Andrew Jones, Michael S. Tsirkin, Laszlo Ersek,
	QEMU Developers, Shannon Zhao, qemu-arm, Marc-André Lureau,
	Igor Mammedov, Eric Auger, Philippe Mathieu-Daudé,
	ardb, Stefan Berger

On Mon, 22 Jun 2020 at 15:06, Eric Auger <eric.auger@redhat.com> wrote:
>
> Those patches bring MMIO TPM TIS ACPI support in machvirt.
>
> On ARM, the TPM2 table is added when the TPM TIS sysbus
> device is dynamically instantiated in machvirt.
>
> Also the TPM2 device object is described in the DSDT.
>
> Many thanks to Ard for his support.
>
> Tested with LUKS partition automatic decryption. Also
> tested with new bios-tables-test dedicated tests,
> sent separately.
>



Applied to target-arm.next, thanks.

-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-25 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 14:06 [PATCH v7 0/3] vTPM/aarch64 ACPI support Eric Auger
2020-06-22 14:06 ` [PATCH v7 1/3] acpi: Some build_tpm2() code reshape Eric Auger
2020-06-22 14:06 ` [PATCH v7 2/3] arm/acpi: Add the TPM2.0 device under the DSDT Eric Auger
2020-06-22 14:06 ` [PATCH v7 3/3] docs/specs/tpm: ACPI boot now supported for TPM/ARM Eric Auger
2020-06-24 12:53 ` [PATCH v7 0/3] vTPM/aarch64 ACPI support Ard Biesheuvel
2020-06-25 13:34 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.