Skip to contentSkip to conversation

acpi: Make TPM version configurable.

PATCH Superseded Jennifer Herbert 3 participants 14 messages Apr 25, 2023 – May 3, 2023

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover acpi: Make TPM version configurable.

This patch makes the TPM version, for which the ACPI library probes, configurable.
Find following version 3 of this patche series. Appoliges for it taking so long, and my previous version missing some changes I intended to share.

Have renamed the TPM_CRB constants to better match the TPM specification. (They where previously trying to stay consistent with the TIS code)
Have moved some ACPI register locations to acpi2_0.h to such that both TPM register offsets are defined together, so that their relation can be better understood. Have also added additional comments to explain these constants.

Changed the defaults, such that it will act exactly as is current, (which is to attempt to probe for TPM 1.2) unless explicitly set to no TPM or TPM 2, so not to regress anything.
Addressed veriouse style issues.
Moved tpm_version field up in acpi_config for better alignment.

Add a new xenstore key 'tpm_version', which xenopsd is setting to 2. If not set, it defaults to '1' probing for tpm 1.2 as before.

A note on the use of CRB: QEMU implements both TIS and CRB interfaces for TPM2. We use this CRB interface as defined by the TCG PTP specification,
as it is thought to be the more modern interface and preferred for the TPM2.0 only world.
TIS is PC specific, implemented with an ISA bus device in QEMU, whereas I think CRB is more generic and would be suitable for
use on other platforms like ARM. While I read here is some confusion about the Mobile CRB specification regrading locality, I don't think this is a problem for our use case. However, should someone decide they need to use TIS with TPM2, I don't believe this patch series would exclude the option for this to be added later, since struct acpi_config does allow a TIS to be supplied instead of CRB for version 2.

Jennifer Herbert (2):
acpi: Make TPM version configurable.
acpi: Add TPM2 interface definition.

 docs/misc/xenstore-paths.pandoc |  10 +++
 tools/firmware/hvmloader/util.c |  28 +++++++--
 tools/libacpi/Makefile          |   3 +-
 tools/libacpi/acpi2_0.h         |  32 ++++++++++
 tools/libacpi/build.c           | 106 +++++++++++++++++++++++---------
 tools/libacpi/libacpi.h         |   4 +-
 tools/libacpi/ssdt_tpm2.asl     |  36 +++++++++++
 7 files changed, 183 insertions(+), 36 deletions(-)
 create mode 100644 tools/libacpi/ssdt_tpm2.asl
Signature · 1 line
2.39.1
#1 lore raw

PATCH v3 1/2 acpi: Make TPM version configurable.

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

---
 docs/misc/xenstore-paths.pandoc |  9 +++++
 tools/firmware/hvmloader/util.c | 19 ++++++---
 tools/libacpi/build.c           | 69 +++++++++++++++++++--------------
 tools/libacpi/libacpi.h         |  3 +-
 4 files changed, 64 insertions(+), 36 deletions(-)
docs/misc/xenstore-paths.pandoc +9 -0
index 5cd5c8a3b9..e67e164855 100644
@@ -269,6 +269,15 @@ at the guest physical address in HVM_PARAM_VM_GENERATION_ID_ADDR.
 See Microsoft's "Virtual Machine Generation ID" specification for the
 circumstances where the generation ID needs to be changed.
 
+
+#### ~/platform/tpm_version = INTEGER [HVM,INTERNAL]
+
+The TPM version to be probed for.
+
+A value of 1 indicates to probe for TPM 1.2.
+A value of 0 or an invalid value will result in no TPM being probed.
+If unset, a default of 1 is assumed.
+
 ### Frontend device paths
 
 Paravirtual device frontends are generally specified by their own
tools/firmware/hvmloader/util.c +14 -5
index 581b35e5cf..f39a8e584f 100644
@@ -994,13 +994,22 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_laptop_slate", "0"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_LAPTOP_SLATE;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
-                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
-                            ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
-                            ACPI_HAS_8042 | ACPI_HAS_CMOS_RTC);
+    config->table_flags |= (ACPI_HAS_IOAPIC | ACPI_HAS_WAET |
+                            ACPI_HAS_PMTIMER | ACPI_HAS_BUTTONS |
+                            ACPI_HAS_VGA | ACPI_HAS_8042 |
+                            ACPI_HAS_CMOS_RTC);
     config->acpi_revision = 4;
 
-    config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
+    s = xenstore_read("platform/tpm_version", "1");
+    config->tpm_version = strtoll(s, NULL, 0);
+
+    switch( config->tpm_version )
+    {
+    case 1:
+        config->table_flags |= ACPI_HAS_TPM;
+        config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
+        break;
+    }
 
     config->numa.nr_vmemranges = nr_vmemranges;
     config->numa.nr_vnodes = nr_vnodes;
tools/libacpi/build.c +39 -30

77 lines not on this page · raw message

tools/libacpi/libacpi.h +2 -1
index a2efd23b0b..f69452401f 100644
@@ -27,7 +27,7 @@
 #define ACPI_HAS_SSDT_PM           (1<<4)
 #define ACPI_HAS_SSDT_S3           (1<<5)
 #define ACPI_HAS_SSDT_S4           (1<<6)
-#define ACPI_HAS_TCPA              (1<<7)
+#define ACPI_HAS_TPM               (1<<7)
 #define ACPI_HAS_IOAPIC            (1<<8)
 #define ACPI_HAS_WAET              (1<<9)
 #define ACPI_HAS_PMTIMER           (1<<10)
@@ -66,6 +66,7 @@ struct acpi_config {
 
     uint32_t table_flags;
     uint8_t acpi_revision;
+    uint8_t tpm_version;
 
     uint64_t vm_gid[2];
     unsigned long vm_gid_addr; /* OUT parameter */
Signature · 1 line
2.39.1
Reviewed-by on v3 1/2
#2 lore raw

Hi, Jennifer,

Quoted 7 lines · Jennifer Herbert

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

...

Quoted 3 lines
tools/libacpi/build.c +0 -0
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,

...

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 9 lines
tools/libacpi/build.c +2 -6
+        switch ( config->tpm_version )
         {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */

This shouldn't be reached, since tpm_version == 0 won't have ACPI_HAS_TPM set. Still, do you want to make it a break or drop the case to avoid falling through to the TPM1.2 code?

Looks good though.

Thanks,
Jason

#3 lore raw
Quoted 24 lines · Jason Andryuk

Hi, Jennifer,

Quoted 6 lines · Jennifer Herbert

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

...

Quoted 3 lines
tools/libacpi/build.c +0 -0
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,

...

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 9 lines
tools/libacpi/build.c +2 -6
+        switch ( config->tpm_version )
          {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */
Quoted 3 lines

This shouldn't be reached, since tpm_version == 0 won't have ACPI_HAS_TPM set. Still, do you want to make it a break or drop the case to avoid falling through to the TPM1.2 code?

So there was concerns in v2 about backward compatilibity before of this area of code.  The exact nature of the concern was vauge, so I made this very conservative.   This was intended to mitigate agaist this code being run, but with the structure being set up with something other then  the code in tools/firmware/hvmloader/util.c.  Any such alaternate code would set the tpm flag, but not know about the version field, and so leave it at zero.  In this case, dropping into 1.2 probing would be the correct solution.

As you say, in the use cases I'm farmiliar with, this would not get reached, so shoudn't affect anything.
Haveing a break or dropping the case would result in it silently ignoring the 'invalid' tpm configuration, so if not compatibilty mode, I'd personally prefer some sort of assert, although i'm not sure how best to do that in this code.

-jenny

Quoted 6 lines

Looks good though.

Thanks,
Jason

#4 lore raw
Quoted 40 lines · Jennifer Herbert
Quoted 24 lines · Jason Andryuk

Hi, Jennifer,

Quoted 6 lines · Jennifer Herbert

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

...

Quoted 3 lines
tools/libacpi/build.c +0 -0
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,

...

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 9 lines
tools/libacpi/build.c +2 -6
+        switch ( config->tpm_version )
          {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */
Quoted 3 lines

This shouldn't be reached, since tpm_version == 0 won't have ACPI_HAS_TPM set. Still, do you want to make it a break or drop the case to avoid falling through to the TPM1.2 code?

So there was concerns in v2 about backward compatilibity before of this area of code. The exact nature of the concern was vauge, so I made this
very conservative. This was intended to mitigate agaist this code
being run, but with the structure being set up with something other then the code in tools/firmware/hvmloader/util.c. Any such alaternate code would set the tpm flag, but not know about the version field, and so leave it at zero. In this case, dropping into 1.2 probing would be the correct solution.

Quoted 6 lines

As you say, in the use cases I'm farmiliar with, this would not get reached, so shoudn't affect anything.
Haveing a break or dropping the case would result in it silently ignoring the 'invalid' tpm configuration, so if not compatibilty mode, I'd personally prefer some sort of assert, although i'm not sure how best to do that in this code.

Ok, sounds good to leave it as you wrote it here. The split of hvmloader and libacpi requires the backwards compatible approach inside libacpi.

Thanks,
Jason

#5 lore raw
In reply to Jennifer Herbert
Quoted 5 lines · Jennifer Herbert

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

Quoted 7 lines
---
 docs/misc/xenstore-paths.pandoc |  9 +++++
 tools/firmware/hvmloader/util.c | 19 ++++++---
 tools/libacpi/build.c           | 69 +++++++++++++++++++--------------
 tools/libacpi/libacpi.h         |  3 +-
 4 files changed, 64 insertions(+), 36 deletions(-)

Please can you get used to providing a brief rev log somewhere here?

Quoted 9 lines
tools/firmware/hvmloader/util.c +0 -3
@@ -994,13 +994,22 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_laptop_slate", "0"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_LAPTOP_SLATE;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
-                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
-                            ACPI_HAS_BUTTONS | ACPI_HAS_VGA |

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1004

Quoted 10 lines
tools/firmware/hvmloader/util.c +6 -2
-                            ACPI_HAS_8042 | ACPI_HAS_CMOS_RTC);
+    config->table_flags |= (ACPI_HAS_IOAPIC | ACPI_HAS_WAET |
+                            ACPI_HAS_PMTIMER | ACPI_HAS_BUTTONS |
+                            ACPI_HAS_VGA | ACPI_HAS_8042 |
+                            ACPI_HAS_CMOS_RTC);
     config->acpi_revision = 4;
 
-    config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
+    s = xenstore_read("platform/tpm_version", "1");
+    config->tpm_version = strtoll(s, NULL, 0);

Due to field width, someone specifying 257 will also get a 1.2 TPM, if I'm not mistaken.

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1006

Quoted 1 line
tools/firmware/hvmloader/util.c +1 -0
+    switch( config->tpm_version )

Nit: Style (missing blank).

Quoted 32 lines
tools/libacpi/build.c +2 -23
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
         memcpy(ssdt, ssdt_laptop_slate, sizeof(ssdt_laptop_slate));
         table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
     }
-
-    /* TPM TCPA and SSDT. */
-    if ( (config->table_flags & ACPI_HAS_TCPA) &&
-         (config->tis_hdr[0] != 0 && config->tis_hdr[0] != 0xffff) &&
-         (config->tis_hdr[1] != 0 && config->tis_hdr[1] != 0xffff) )
+    /* TPM and its SSDT. */
+    if ( config->table_flags & ACPI_HAS_TPM )
     {
-        ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_tpm), 16);
-        if (!ssdt) return -1;
-        memcpy(ssdt, ssdt_tpm, sizeof(ssdt_tpm));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
-
-        tcpa = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_tcpa), 16);
-        if (!tcpa) return -1;
-        memset(tcpa, 0, sizeof(*tcpa));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, tcpa);
-
-        tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
-        tcpa->header.length    = sizeof(*tcpa);
-        tcpa->header.revision  = ACPI_2_0_TCPA_REVISION;
-        fixed_strcpy(tcpa->header.oem_id, ACPI_OEM_ID);
-        fixed_strcpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID);
-        tcpa->header.oem_revision = ACPI_OEM_REVISION;
-        tcpa->header.creator_id   = ACPI_CREATOR_ID;
-        tcpa->header.creator_revision = ACPI_CREATOR_REVISION;

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 10 lines
tools/libacpi/build.c +2 -7
-        if ( (lasa = ctxt->mem_ops.alloc(ctxt, ACPI_2_0_TCPA_LAML_SIZE, 16)) != NULL )
+        switch ( config->tpm_version )
         {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */

Along the lines of what Jason said: Unless this is known to be needed for anything, I'd prefer if it was omitted.

Jan

#6 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Jennifer Herbert

This patch makes the TPM version, for which the ACPI libary probes, configurable. If acpi_config.tpm_verison is set to 1, it indicates that 1.2 (TCPA) should be probed. I have also added to hvmloader an option to allow setting this new config, which can be triggered by setting the platform/tpm_version xenstore key.

Quoted 8 lines
Quoted 7 lines
---
  docs/misc/xenstore-paths.pandoc |  9 +++++
  tools/firmware/hvmloader/util.c | 19 ++++++---
  tools/libacpi/build.c           | 69 +++++++++++++++++++--------------
  tools/libacpi/libacpi.h         |  3 +-
  4 files changed, 64 insertions(+), 36 deletions(-)

Please can you get used to providing a brief rev log somewhere here?

Yes, ok.

Quoted 16 lines
Quoted 16 lines
tools/firmware/hvmloader/util.c +4 -4
@@ -994,13 +994,22 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
      if ( !strncmp(xenstore_read("platform/acpi_laptop_slate", "0"), "1", 1)  )
          config->table_flags |= ACPI_HAS_SSDT_LAPTOP_SLATE;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
-                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
-                            ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
-                            ACPI_HAS_8042 | ACPI_HAS_CMOS_RTC);
+    config->table_flags |= (ACPI_HAS_IOAPIC | ACPI_HAS_WAET |
+                            ACPI_HAS_PMTIMER | ACPI_HAS_BUTTONS |
+                            ACPI_HAS_VGA | ACPI_HAS_8042 |
+                            ACPI_HAS_CMOS_RTC);
      config->acpi_revision = 4;
 
Quoted 5 lines

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1004

Quoted 3 lines
tools/firmware/hvmloader/util.c +2 -1
-    config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
+    s = xenstore_read("platform/tpm_version", "1");
+    config->tpm_version = strtoll(s, NULL, 0);

Due to field width, someone specifying 257 will also get a 1.2 TPM, if I'm not mistaken.

Seems likely.   And i few other wacky values would give you 1.2 as well I'd think.   There could also be trailing junk on the version number.

I was a bit phased by the lack of any real error cases in hvmloader_acpi_build_tables.  It seemed the approch was if you put in junk, you'll get something, but possibly not what your expecting.

Do I take it you'd prefer it to only accept a strict '1' for 1.2 and any other value would result in no TPM being probed?  Or is it only the overflow cases your concerned about?

Quoted 2 lines

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1006

Quoted 1 line
tools/firmware/hvmloader/util.c +1 -0
+    switch( config->tpm_version )

Nit: Style (missing blank).

yup

Quoted 36 lines
Quoted 36 lines
tools/libacpi/build.c +3 -25
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
          memcpy(ssdt, ssdt_laptop_slate, sizeof(ssdt_laptop_slate));
          table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
      }
-
-    /* TPM TCPA and SSDT. */
-    if ( (config->table_flags & ACPI_HAS_TCPA) &&
-         (config->tis_hdr[0] != 0 && config->tis_hdr[0] != 0xffff) &&
-         (config->tis_hdr[1] != 0 && config->tis_hdr[1] != 0xffff) )
+    /* TPM and its SSDT. */
+    if ( config->table_flags & ACPI_HAS_TPM )
      {
-        ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_tpm), 16);
-        if (!ssdt) return -1;
-        memcpy(ssdt, ssdt_tpm, sizeof(ssdt_tpm));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
-
-        tcpa = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_tcpa), 16);
-        if (!tcpa) return -1;
-        memset(tcpa, 0, sizeof(*tcpa));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, tcpa);
-
-        tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
-        tcpa->header.length    = sizeof(*tcpa);
-        tcpa->header.revision  = ACPI_2_0_TCPA_REVISION;
-        fixed_strcpy(tcpa->header.oem_id, ACPI_OEM_ID);
-        fixed_strcpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID);
-        tcpa->header.oem_revision = ACPI_OEM_REVISION;
-        tcpa->header.creator_id   = ACPI_CREATOR_ID;
-        tcpa->header.creator_revision = ACPI_CREATOR_REVISION;
-        if ( (lasa = ctxt->mem_ops.alloc(ctxt, ACPI_2_0_TCPA_LAML_SIZE, 16)) != NULL )
+        switch ( config->tpm_version )
          {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
Quoted 8 lines

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 6 lines
tools/libacpi/build.c +1 -5
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */

Along the lines of what Jason said: Unless this is known to be needed for anything, I'd prefer if it was omitted.

I'm not awair of anything, but your comment 2 lines down  from version 2 made me think you knew of some.  So if your happy with me removing this line, I am!

Quoted 1 line

Jan

#7 lore raw
Quoted 27 lines · Jennifer Herbert
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Jennifer Herbert
tools/firmware/hvmloader/util.c +4 -4
@@ -994,13 +994,22 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
      if ( !strncmp(xenstore_read("platform/acpi_laptop_slate", "0"), "1", 1)  )
          config->table_flags |= ACPI_HAS_SSDT_LAPTOP_SLATE;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
-                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
-                            ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
-                            ACPI_HAS_8042 | ACPI_HAS_CMOS_RTC);
+    config->table_flags |= (ACPI_HAS_IOAPIC | ACPI_HAS_WAET |
+                            ACPI_HAS_PMTIMER | ACPI_HAS_BUTTONS |
+                            ACPI_HAS_VGA | ACPI_HAS_8042 |
+                            ACPI_HAS_CMOS_RTC);
      config->acpi_revision = 4;
 
Quoted 5 lines

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1004

Quoted 3 lines
tools/firmware/hvmloader/util.c +2 -1
-    config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
+    s = xenstore_read("platform/tpm_version", "1");
+    config->tpm_version = strtoll(s, NULL, 0);

Due to field width, someone specifying 257 will also get a 1.2 TPM, if I'm not mistaken.

Seems likely.   And i few other wacky values would give you 1.2 as well I'd think.   There could also be trailing junk on the version number.

Quoted 7 lines

I was a bit phased by the lack of any real error cases in hvmloader_acpi_build_tables.  It seemed the approch was if you put in junk, you'll get something, but possibly not what your expecting.

Do I take it you'd prefer it to only accept a strict '1' for 1.2 and any other value would result in no TPM being probed?  Or is it only the overflow cases your concerned about?

Iirc xs convention is that numeric values can be spelled out in arbitrary ways. So limiting to strictly "1" may be too restrictive. Anything that evaluates to 1 without overflow nor trailing junk ought to be taken to mean 1, I think.

Quoted 45 lines
Quoted 36 lines
Quoted 36 lines
tools/libacpi/build.c +3 -25
@@ -409,38 +409,47 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
          memcpy(ssdt, ssdt_laptop_slate, sizeof(ssdt_laptop_slate));
          table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
      }
-
-    /* TPM TCPA and SSDT. */
-    if ( (config->table_flags & ACPI_HAS_TCPA) &&
-         (config->tis_hdr[0] != 0 && config->tis_hdr[0] != 0xffff) &&
-         (config->tis_hdr[1] != 0 && config->tis_hdr[1] != 0xffff) )
+    /* TPM and its SSDT. */
+    if ( config->table_flags & ACPI_HAS_TPM )
      {
-        ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_tpm), 16);
-        if (!ssdt) return -1;
-        memcpy(ssdt, ssdt_tpm, sizeof(ssdt_tpm));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
-
-        tcpa = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_tcpa), 16);
-        if (!tcpa) return -1;
-        memset(tcpa, 0, sizeof(*tcpa));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, tcpa);
-
-        tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
-        tcpa->header.length    = sizeof(*tcpa);
-        tcpa->header.revision  = ACPI_2_0_TCPA_REVISION;
-        fixed_strcpy(tcpa->header.oem_id, ACPI_OEM_ID);
-        fixed_strcpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID);
-        tcpa->header.oem_revision = ACPI_OEM_REVISION;
-        tcpa->header.creator_id   = ACPI_CREATOR_ID;
-        tcpa->header.creator_revision = ACPI_CREATOR_REVISION;
-        if ( (lasa = ctxt->mem_ops.alloc(ctxt, ACPI_2_0_TCPA_LAML_SIZE, 16)) != NULL )
+        switch ( config->tpm_version )
          {
-            tcpa->lasa = ctxt->mem_ops.v2p(ctxt, lasa);
Quoted 8 lines

tools/libacpi/build.c static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 417

Quoted 6 lines
tools/libacpi/build.c +1 -5
-            tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
-            memset(lasa, 0, tcpa->laml);
-            set_checksum(tcpa,
-                         offsetof(struct acpi_header, checksum),
-                         tcpa->header.length);
+        case 0: /* Assume legacy code wanted tpm 1.2 */

Along the lines of what Jason said: Unless this is known to be needed for anything, I'd prefer if it was omitted.

Quoted 3 lines

I'm not awair of anything, but your comment 2 lines down  from version 2 made me think you knew of some.  So if your happy with me removing this line, I am!

I'm afraid I can't make the connection to that comment (assuming I fished out the right one). In any event, especially with Jason's observation that ACPI_HAS_TPM won't be set alongside ->tpm_version being zero, I see no use for keeping the "case 0:".

Jan

#8 lore raw

PATCH v3 2/2 acpi: Add TPM2 interface definition.

In reply to Jennifer Herbert

This patch introduces an optional TPM 2 interface definition to the ACPI table, which is to be used as part of a vTPM 2 implementation.

---
 docs/misc/xenstore-paths.pandoc |  3 ++-
 tools/firmware/hvmloader/util.c |  9 ++++++++
 tools/libacpi/Makefile          |  3 ++-
 tools/libacpi/acpi2_0.h         | 32 +++++++++++++++++++++++++++
 tools/libacpi/build.c           | 39 +++++++++++++++++++++++++++++++++
 tools/libacpi/libacpi.h         |  1 +
 tools/libacpi/ssdt_tpm2.asl     | 36 ++++++++++++++++++++++++++++++
 7 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 tools/libacpi/ssdt_tpm2.asl
docs/misc/xenstore-paths.pandoc +2 -1
index e67e164855..bffb8ea544 100644
@@ -274,7 +274,8 @@ circumstances where the generation ID needs to be changed.
 
 The TPM version to be probed for.
 
-A value of 1 indicates to probe for TPM 1.2.
+A value of 1 indicates to probe for TPM 1.2, whereas a value of 2
+indicates that a TPM 2.0 using CRB should be probed.
 A value of 0 or an invalid value will result in no TPM being probed.
 If unset, a default of 1 is assumed.
 
tools/firmware/hvmloader/util.c +9 -0
index f39a8e584f..51272530fe 100644
@@ -1009,6 +1009,15 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
         config->table_flags |= ACPI_HAS_TPM;
         config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
         break;
+
+    case 2:
+        config->table_flags |= ACPI_HAS_TPM;
+        config->crb_id = (uint16_t *)TPM_CRB_INTF_ID;
+
+        mem_hole_populate_ram(TPM_LOG_AREA_ADDRESS >> PAGE_SHIFT,
+                              TPM_LOG_SIZE >> PAGE_SHIFT);
+        memset((void *)TPM_LOG_AREA_ADDRESS, 0, TPM_LOG_SIZE);
+        break;
     }
 
     config->numa.nr_vmemranges = nr_vmemranges;
tools/libacpi/Makefile +2 -1
index 60860eaa00..23278f6a61 100644
@@ -25,7 +25,8 @@ C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c dsdt_pvh
 C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c
 DSDT_FILES ?= $(C_SRC-y)
 C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))
-H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h ssdt_tpm.h ssdt_laptop_slate.h)
+H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h)
+H_SRC += $(addprefix $(ACPI_BUILD_DIR)/, ssdt_tpm.h ssdt_tpm2.h ssdt_laptop_slate.h)
 
 MKDSDT_CFLAGS-$(CONFIG_ARM_64) = -DCONFIG_ARM_64
 MKDSDT_CFLAGS-$(CONFIG_X86) = -DCONFIG_X86
tools/libacpi/acpi2_0.h +32 -0
index 2619ba32db..19a43d4b2e 100644
@@ -121,6 +121,36 @@ struct acpi_20_tcpa {
 };
 #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
 
+/*
+ * TPM2
+ */
+struct acpi_20_tpm2 {
+    struct acpi_header header;
+    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;
+};
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_START_METHOD_CRB       7
+
+/* TPM register I/O Mapped region, location of which defined in the
+ * TCG PC Client Platform TPM Profile Specification for TPM 2.0.
+ * See table 9 - Only Locality 0 is used here. This is emulated by QEMU.
+ * Definition of Register space is found in table 12.
+ */
+#define TPM_REGISTER_BASE           0xFED40000
+#define TPM_CRB_CTRL_REQ            (TPM_REGISTER_BASE  + 0x40)
+#define TPM_CRB_INTF_ID             (TPM_REGISTER_BASE  + 0x30)
+
+#define TPM_LOG_AREA_ADDRESS        0xFED50000
+
+#define TPM_LOG_AREA_MINIMUM_SIZE   (64 << 10)
+#define TPM_LOG_SIZE                (64 << 10)
+
 /*
  * Fixed ACPI Description Table Structure (FADT) in ACPI 1.0.
  */
@@ -431,6 +461,7 @@ struct acpi_20_slit {
 #define ACPI_2_0_RSDT_SIGNATURE ASCII32('R','S','D','T')
 #define ACPI_2_0_XSDT_SIGNATURE ASCII32('X','S','D','T')
 #define ACPI_2_0_TCPA_SIGNATURE ASCII32('T','C','P','A')
+#define ACPI_2_0_TPM2_SIGNATURE ASCII32('T','P','M','2')
 #define ACPI_2_0_HPET_SIGNATURE ASCII32('H','P','E','T')
 #define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')
 #define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')
@@ -444,6 +475,7 @@ struct acpi_20_slit {
 #define ACPI_2_0_RSDT_REVISION 0x01
 #define ACPI_2_0_XSDT_REVISION 0x01
 #define ACPI_2_0_TCPA_REVISION 0x02
+#define ACPI_2_0_TPM2_REVISION 0x04
 #define ACPI_2_0_HPET_REVISION 0x01
 #define ACPI_2_0_WAET_REVISION 0x01
 #define ACPI_1_0_FADT_REVISION 0x01
tools/libacpi/build.c +39 -0
index 716cb49624..359a4dbba4 100644
@@ -19,6 +19,7 @@
 #include "ssdt_s3.h"
 #include "ssdt_s4.h"
 #include "ssdt_tpm.h"
+#include "ssdt_tpm2.h"
 #include "ssdt_pm.h"
 #include "ssdt_laptop_slate.h"
 #include <xen/hvm/hvm_info_table.h>
@@ -352,6 +353,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
     struct acpi_20_tcpa *tcpa;
     unsigned char *ssdt;
     void *lasa;
+    struct acpi_20_tpm2 *tpm2;
 
     /* MADT. */
     if ( (config->hvminfo->nr_vcpus > 1) || config->hvminfo->apic_mode )
@@ -450,6 +452,43 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
                              tcpa->header.length);
             }
             break;
+
+        case 2:
+            /* Check VID stored in bits 37:32 (3rd 16 bit word) of CRB
+             * identifier register.  See table 16 of TCG PC client platform
+             * TPM profile specification for TPM 2.0.
+             */
+            if ( config->crb_id[2] == 0 || config->crb_id[2] == 0xffff )
+                break;
+
+            ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_tpm2), 16);
+            if (!ssdt) return -1;
+            memcpy(ssdt, ssdt_tpm2, sizeof(ssdt_tpm2));
+            table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
+
+            tpm2 = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_tpm2), 16);
+            if (!tpm2) return -1;
+            memset(tpm2, 0, sizeof(*tpm2));
+            table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, tpm2);
+
+            tpm2->header.signature = ACPI_2_0_TPM2_SIGNATURE;
+            tpm2->header.length    = sizeof(*tpm2);
+            tpm2->header.revision  = ACPI_2_0_TPM2_REVISION;
+            fixed_strcpy(tpm2->header.oem_id, ACPI_OEM_ID);
+            fixed_strcpy(tpm2->header.oem_table_id, ACPI_OEM_TABLE_ID);
+            tpm2->header.oem_revision = ACPI_OEM_REVISION;
+            tpm2->header.creator_id   = ACPI_CREATOR_ID;
+            tpm2->header.creator_revision = ACPI_CREATOR_REVISION;
+            tpm2->platform_class = TPM2_ACPI_CLASS_CLIENT;
+            tpm2->control_area_address = TPM_CRB_CTRL_REQ;
+            tpm2->start_method = TPM2_START_METHOD_CRB;
+            tpm2->log_area_minimum_length = TPM_LOG_AREA_MINIMUM_SIZE;
+            tpm2->log_area_start_address = TPM_LOG_AREA_ADDRESS;
+
+            set_checksum(tpm2,
+                         offsetof(struct acpi_header, checksum),
+                         tpm2->header.length);
+            break;
         }
     }
 
tools/libacpi/libacpi.h +1 -0
index f69452401f..0d19f9fc4d 100644
@@ -80,6 +80,7 @@ struct acpi_config {
     const struct hvm_info_table *hvminfo;
 
     const uint16_t *tis_hdr;
+    const uint16_t *crb_id;
 
     /*
      * Address where acpi_info should be placed.
tools/libacpi/ssdt_tpm2.asl new file +36 -0
new file mode 100644
index 0000000000..1801c338df
@@ -0,0 +1,36 @@
+/*
+ * ssdt_tpm2.asl
+ *
+ * Copyright (c) 2018-2022, Citrix Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+/* SSDT for TPM CRB Interface for Xen with Qemu device model. */
+
+DefinitionBlock ("SSDT_TPM2.aml", "SSDT", 2, "Xen", "HVM", 0)
+{
+    Device (TPM)
+    {
+        Name (_HID, "MSFT0101" /* TPM 2.0 Security Device */)  // _HID: Hardware ID
+        Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
+        {
+            Memory32Fixed (ReadWrite,
+                0xFED40000,         // Address Base
+                0x00001000,         // Address Length
+                )
+        })
+        Method (_STA, 0, NotSerialized)  // _STA: Status
+        {
+            Return (0x0F)
+        }
+    }
+}
Signature · 1 line
2.39.1
Reviewed-by on v3 2/2
#9 lore raw

Re: [PATCH v3 2/2] acpi: Add TPM2 interface definition.

Quoted 6 lines · Jennifer Herbert

This patch introduces an optional TPM 2 interface definition to the ACPI table, which is to be used as part of a vTPM 2 implementation.

---

...

Quoted 6 lines
tools/firmware/hvmloader/util.c +0 -0
index f39a8e584f..51272530fe 100644
@@ -1009,6 +1009,15 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
         config->table_flags |= ACPI_HAS_TPM;

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1019

Quoted 10 lines
tools/firmware/hvmloader/util.c +8 -0
         config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
         break;
+
+    case 2:
+        config->table_flags |= ACPI_HAS_TPM;
+        config->crb_id = (uint16_t *)TPM_CRB_INTF_ID;
+
+        mem_hole_populate_ram(TPM_LOG_AREA_ADDRESS >> PAGE_SHIFT,
+                              TPM_LOG_SIZE >> PAGE_SHIFT);
+        memset((void *)TPM_LOG_AREA_ADDRESS, 0, TPM_LOG_SIZE);

TPM_LOG_AREA_ADDRESS is reserved in the e820 table since it is the high memory range after the ACPI data, correct?

Thanks,
Jason

#10 lore raw

Re: [PATCH v3 2/2] acpi: Add TPM2 interface definition.

Quoted 18 lines · Jason Andryuk
Quoted 5 lines · Jennifer Herbert

This patch introduces an optional TPM 2 interface definition to the ACPI table, which is to be used as part of a vTPM 2 implementation.

---

...

Quoted 10 lines
tools/firmware/hvmloader/util.c +2 -0
index f39a8e584f..51272530fe 100644
@@ -1009,6 +1009,15 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
          config->table_flags |= ACPI_HAS_TPM;
          config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
          break;
+
+    case 2:
Quoted 8 lines

tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 1019

Quoted 6 lines
tools/firmware/hvmloader/util.c +6 -0
+        config->table_flags |= ACPI_HAS_TPM;
+        config->crb_id = (uint16_t *)TPM_CRB_INTF_ID;
+
+        mem_hole_populate_ram(TPM_LOG_AREA_ADDRESS >> PAGE_SHIFT,
+                              TPM_LOG_SIZE >> PAGE_SHIFT);
+        memset((void *)TPM_LOG_AREA_ADDRESS, 0, TPM_LOG_SIZE);

TPM_LOG_AREA_ADDRESS is reserved in the e820 table since it is the high memory range after the ACPI data, correct?

This is my understanding yes.  We made sure to put it well clear of the qemu impremnted TPM, just incase it later decided to support more localitie levels,  but still well within the RESERVED area, in the e820.

-jenny

Quoted 5 lines

Thanks,
Jason

Acked-by on v3 2/2
#11 lore raw

Re: [PATCH v3 2/2] acpi: Add TPM2 interface definition.

In reply to Jennifer Herbert

tools/libacpi/acpi2_0.h struct acpi_20_tcpa { · line 126

Quoted 9 lines · Jennifer Herbert
tools/libacpi/acpi2_0.h +3 -0
@@ -121,6 +121,36 @@ struct acpi_20_tcpa {
 };
 #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
 
+/*
+ * TPM2
+ */

Nit: While I'm willing to accept the comment style violation here as (apparently) intentional, ...

Quoted 8 lines
tools/libacpi/acpi2_0.h +8 -0
+struct acpi_20_tpm2 {
+    struct acpi_header header;
+    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;

tools/libacpi/acpi2_0.h struct acpi_20_tcpa { · line 144

Quoted 10 lines
tools/libacpi/acpi2_0.h +10 -0
+    uint64_t log_area_start_address;
+};
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_START_METHOD_CRB       7
+
+/* TPM register I/O Mapped region, location of which defined in the
+ * TCG PC Client Platform TPM Profile Specification for TPM 2.0.
+ * See table 9 - Only Locality 0 is used here. This is emulated by QEMU.
+ * Definition of Register space is found in table 12.
+ */

... this comment wants adjusting to hypervisor style (/* on its own line), as that looks to be the aimed-at style in this file.

tools/libacpi/acpi2_0.h static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 356

Quoted 5 lines
tools/libacpi/acpi2_0.h +1 -0
@@ -352,6 +353,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
     struct acpi_20_tcpa *tcpa;
     unsigned char *ssdt;
     void *lasa;
+    struct acpi_20_tpm2 *tpm2;

Could I talk you into moving this up by two lines, such that it'll be adjacent to "tcpa"?

tools/libacpi/acpi2_0.h static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 460

Quoted 10 lines
tools/libacpi/acpi2_0.h +6 -0
@@ -450,6 +452,43 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
                              tcpa->header.length);
             }
             break;
+
+        case 2:
+            /* Check VID stored in bits 37:32 (3rd 16 bit word) of CRB
+             * identifier register.  See table 16 of TCG PC client platform
+             * TPM profile specification for TPM 2.0.
+             */

Nit: This comment again wants a style adjustment.

Quoted 8 lines
tools/libacpi/ssdt_tpm2.asl new file +5 -0
@@ -0,0 +1,36 @@
+/*
+ * ssdt_tpm2.asl
+ *
+ * Copyright (c) 2018-2022, Citrix Systems, Inc.
+ *

tools/libacpi/ssdt_tpm2.asl line 15

Quoted 10 lines
tools/libacpi/ssdt_tpm2.asl new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */

While the full conversion to SPDX was done in the hypervisor only so far, I think new tool stack source files would better use the much shorter SPDX equivalent, too.

Then on top of Jason's R-b,

Jan

#12 lore raw

Re: [PATCH v3 2/2] acpi: Add TPM2 interface definition.

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jennifer Herbert
tools/libacpi/acpi2_0.h +0 -0
@@ -121,6 +121,36 @@ struct acpi_20_tcpa {
  };
  #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
 
Quoted 5 lines

tools/libacpi/acpi2_0.h struct acpi_20_tcpa { · line 126

Quoted 3 lines
tools/libacpi/acpi2_0.h +3 -0
+/*
+ * TPM2
+ */

Nit: While I'm willing to accept the comment style violation here as (apparently) intentional, ...

Well, I was trying to keep the file consistant.   As far as I can tell, this styling is used thoughout the file - unless I'm misunderstanding your 'Nit'. (You object to a multi-line coment used for a single line? ) But I'm codes style blind, so just say how you want it.

Quoted 12 lines
Quoted 12 lines
tools/libacpi/acpi2_0.h +12 -0
+struct acpi_20_tpm2 {
+    struct acpi_header header;
+    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;
+};
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_START_METHOD_CRB       7
Quoted 8 lines

tools/libacpi/acpi2_0.h struct acpi_20_tcpa { · line 144

Quoted 6 lines
tools/libacpi/acpi2_0.h +6 -0
+
+/* TPM register I/O Mapped region, location of which defined in the
+ * TCG PC Client Platform TPM Profile Specification for TPM 2.0.
+ * See table 9 - Only Locality 0 is used here. This is emulated by QEMU.
+ * Definition of Register space is found in table 12.
+ */

... this comment wants adjusting to hypervisor style (/* on its own line), as that looks to be the aimed-at style in this file.

Will do.

Quoted 7 lines

tools/libacpi/acpi2_0.h static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 356

Quoted 5 lines
tools/libacpi/acpi2_0.h +1 -0
@@ -352,6 +353,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
      struct acpi_20_tcpa *tcpa;
      unsigned char *ssdt;
      void *lasa;
+    struct acpi_20_tpm2 *tpm2;

Could I talk you into moving this up by two lines, such that it'll be adjacent to "tcpa"?

No problem.

Quoted 11 lines

tools/libacpi/acpi2_0.h static int construct_secondary_tables(struct acpi_ctxt *ctxt, · line 460

Quoted 10 lines
tools/libacpi/acpi2_0.h +6 -0
@@ -450,6 +452,43 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
                               tcpa->header.length);
              }
              break;
+
+        case 2:
+            /* Check VID stored in bits 37:32 (3rd 16 bit word) of CRB
+             * identifier register.  See table 16 of TCG PC client platform
+             * TPM profile specification for TPM 2.0.
+             */

Nit: This comment again wants a style adjustment.

ok

Quoted 13 lines
Quoted 13 lines
tools/libacpi/ssdt_tpm2.asl new file +10 -0
@@ -0,0 +1,36 @@
+/*
+ * ssdt_tpm2.asl
+ *
+ * Copyright (c) 2018-2022, Citrix Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
Quoted 8 lines

tools/libacpi/ssdt_tpm2.asl line 15

Quoted 5 lines
tools/libacpi/ssdt_tpm2.asl new file +5 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */

While the full conversion to SPDX was done in the hypervisor only so far, I think new tool stack source files would better use the much shorter SPDX equivalent, too.

OK, this is where I get a bit confused.  I belive I copied the licence from ssdt_tpm.asl, for consistancy.

So I think i need to use a 'LGPL-2.1-only' but then it says its using exceptions on linking as discribed in LICENSE, but um, which LICENSE file?  So i'm not sure what exception I should be adding. Do you know?

Quoted 4 lines

Then on top of Jason's R-b,

Jan

Thanks,

-jenny

#13 lore raw

Re: [PATCH v3 2/2] acpi: Add TPM2 interface definition.

Quoted 14 lines · Jennifer Herbert
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jennifer Herbert
tools/libacpi/acpi2_0.h +0 -0
@@ -121,6 +121,36 @@ struct acpi_20_tcpa {
  };
  #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
 
Quoted 5 lines

tools/libacpi/acpi2_0.h struct acpi_20_tcpa { · line 126

Quoted 3 lines
tools/libacpi/acpi2_0.h +3 -0
+/*
+ * TPM2
+ */

Nit: While I'm willing to accept the comment style violation here as (apparently) intentional, ...

Quoted 4 lines

Well, I was trying to keep the file consistant.   As far as I can tell, this styling is used thoughout the file - unless I'm misunderstanding your 'Nit'. (You object to a multi-line coment used for a single line? ) But I'm codes style blind, so just say how you want it.

Right - strictly speaking those multi-line comments all ought to be single- line ones, but aiui they're multi-line intentionally so they stand out. Hence - as you say, for consistency - it's okay for this one to follow suit.

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
tools/libacpi/ssdt_tpm2.asl new file +10 -0
@@ -0,0 +1,36 @@
+/*
+ * ssdt_tpm2.asl
+ *
+ * Copyright (c) 2018-2022, Citrix Systems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
Quoted 8 lines

tools/libacpi/ssdt_tpm2.asl line 15

Quoted 5 lines
tools/libacpi/ssdt_tpm2.asl new file +5 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */

While the full conversion to SPDX was done in the hypervisor only so far, I think new tool stack source files would better use the much shorter SPDX equivalent, too.

Quoted 6 lines

OK, this is where I get a bit confused.  I belive I copied the licence from ssdt_tpm.asl, for consistancy.

So I think i need to use a 'LGPL-2.1-only' but then it says its using exceptions on linking as discribed in LICENSE, but um, which LICENSE file?  So i'm not sure what exception I should be adding. Do you know?

First of all I think commit 68823df358e8 ("acpi: Re-license ACPI builder files from GPLv2 to LGPLv2.1") was wrong using LICENSE; I'm pretty sure COPYING was meant instead. And indeed the difference between libacpi's COPYING and LICENCES/LGPL-2.1 look to be formatting plus an extra section at the bottom of the latter; I haven't found any "special exception on linking" anywhere. IOW I think using LGPL-2.1 here is what is wanted (unlike e.g. GPL-2.0-only there's no LGPL-2.1-only afaics), the more that you're contributing a new file (and of course provided you're okay to put the new file under that license).

Jan