Refactor TPM event log code
Subsystems (2)
cover Refactor TPM event log code
This patchset implements the proposal from Jarkko Sakkinen [1]. I have included the feedback from Nayna Jain about the function naming.
[1] https://lkml.kernel.org/r/[email protected]
Thiebaud Weksteen (3):
tpm: Move eventlog files to a subdirectory
tpm: Move shared eventlog functions to common.c
tpm: Move eventlog declarations to its own header
drivers/char/tpm/Makefile | 10 +-
.../{tpm_eventlog_acpi.c => eventlog/acpi.c} | 2 +-
drivers/char/tpm/eventlog/common.c | 196 +++++++++++++++++
drivers/char/tpm/eventlog/common.h | 35 +++
.../{tpm_eventlog_efi.c => eventlog/efi.c} | 2 +-
.../tpm/{tpm_eventlog_of.c => eventlog/of.c} | 2 +-
.../tpm/{tpm1_eventlog.c => eventlog/tpm1.c} | 200 ++----------------
.../tpm/{tpm2_eventlog.c => eventlog/tpm2.c} | 3 +-
drivers/char/tpm/tpm.h | 27 ---
9 files changed, 258 insertions(+), 219 deletions(-)
rename drivers/char/tpm/{tpm_eventlog_acpi.c => eventlog/acpi.c} (99%)
create mode 100644 drivers/char/tpm/eventlog/common.c
create mode 100644 drivers/char/tpm/eventlog/common.h
rename drivers/char/tpm/{tpm_eventlog_efi.c => eventlog/efi.c} (98%)
rename drivers/char/tpm/{tpm_eventlog_of.c => eventlog/of.c} (99%)
rename drivers/char/tpm/{tpm1_eventlog.c => eventlog/tpm1.c} (58%)
rename drivers/char/tpm/{tpm2_eventlog.c => eventlog/tpm2.c} (99%)Signature · 1 line
2.17.0.484.g0c8726318c-goog
PATCH 1/3 tpm: Move eventlog files to a subdirectory
---
drivers/char/tpm/Makefile | 8 ++++----
drivers/char/tpm/{tpm_eventlog_acpi.c => eventlog/acpi.c} | 2 +-
drivers/char/tpm/{tpm_eventlog_efi.c => eventlog/efi.c} | 2 +-
drivers/char/tpm/{tpm_eventlog_of.c => eventlog/of.c} | 2 +-
drivers/char/tpm/{tpm1_eventlog.c => eventlog/tpm1.c} | 2 +-
drivers/char/tpm/{tpm2_eventlog.c => eventlog/tpm2.c} | 2 +-
6 files changed, 9 insertions(+), 9 deletions(-)
rename drivers/char/tpm/{tpm_eventlog_acpi.c => eventlog/acpi.c} (99%)
rename drivers/char/tpm/{tpm_eventlog_efi.c => eventlog/efi.c} (98%)
rename drivers/char/tpm/{tpm_eventlog_of.c => eventlog/of.c} (99%)
rename drivers/char/tpm/{tpm1_eventlog.c => eventlog/tpm1.c} (99%)
rename drivers/char/tpm/{tpm2_eventlog.c => eventlog/tpm2.c} (99%)drivers/char/tpm/Makefile +4 -4
@@ -4,11 +4,11 @@ # obj-$(CONFIG_TCG_TPM) += tpm.o tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ - tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \ + tpm-dev-common.o tpmrm-dev.o eventlog/tpm1.o eventlog/tpm2.o \ tpm2-space.o -tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_eventlog_acpi.o -tpm-$(CONFIG_EFI) += tpm_eventlog_efi.o -tpm-$(CONFIG_OF) += tpm_eventlog_of.o +tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o +tpm-$(CONFIG_EFI) += eventlog/efi.o +tpm-$(CONFIG_OF) += eventlog/of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o obj-$(CONFIG_TCG_TIS) += tpm_tis.o obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
drivers/char/tpm/eventlog/acpi.c renamed from drivers/char/tpm/tpm_eventlog_acpi.c +1 -1
@@ -27,7 +27,7 @@#include <linux/acpi.h> #include <linux/tpm_eventlog.h> -#include "tpm.h" +#include "../tpm.h" struct acpi_tcpa {struct acpi_table_header hdr;
drivers/char/tpm/eventlog/efi.c renamed from drivers/char/tpm/tpm_eventlog_efi.c +1 -1
@@ -14,7 +14,7 @@#include <linux/efi.h> #include <linux/tpm_eventlog.h> -#include "tpm.h" +#include "../tpm.h" /* read binary bios log from EFI configuration table */ int tpm_read_log_efi (struct tpm_chip *chip)
drivers/char/tpm/eventlog/of.c renamed from drivers/char/tpm/tpm_eventlog_of.c +1 -1
@@ -19,7 +19,7 @@#include <linux/of.h> #include <linux/tpm_eventlog.h> -#include "tpm.h" +#include "../tpm.h" int tpm_read_log_of (struct tpm_chip *chip) {
drivers/char/tpm/eventlog/tpm1.c renamed from drivers/char/tpm/tpm1_eventlog.c +1 -1
@@ -28,7 +28,7 @@#include <linux/slab.h> #include <linux/tpm_eventlog.h> -#include "tpm.h" +#include "../tpm.h" static const char * tcpa_event_type_strings[] = {
drivers/char/tpm/eventlog/tpm2.c renamed from drivers/char/tpm/tpm2_eventlog.c +1 -1
@@ -23,7 +23,7 @@#include <linux/slab.h> #include <linux/tpm_eventlog.h> -#include "tpm.h" +#include "../tpm.h" /* * calc_tpm2_event_size() - calculate the event size, where event
Signature · 1 line
2.17.0.484.g0c8726318c-goog
PATCH 2/3 tpm: Move shared eventlog functions to common.c
In reply to Thiebaud WeksteenFunctions and structures specific to TPM1 are renamed from tpm* to tpm1*.
--- drivers/char/tpm/Makefile | 4 +- drivers/char/tpm/eventlog/common.c | 195 ++++++++++++++++++++++++++++ drivers/char/tpm/eventlog/tpm1.c | 197 +++-------------------------- drivers/char/tpm/tpm.h | 2 + 4 files changed, 214 insertions(+), 184 deletions(-) create mode 100644 drivers/char/tpm/eventlog/common.c
drivers/char/tpm/Makefile +2 -2
@@ -4,8 +4,8 @@ # obj-$(CONFIG_TCG_TPM) += tpm.o tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ - tpm-dev-common.o tpmrm-dev.o eventlog/tpm1.o eventlog/tpm2.o \ - tpm2-space.o + tpm-dev-common.o tpmrm-dev.o eventlog/common.o eventlog/tpm1.o \ + eventlog/tpm2.o tpm2-space.o tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o tpm-$(CONFIG_EFI) += eventlog/efi.o tpm-$(CONFIG_OF) += eventlog/of.o
drivers/char/tpm/eventlog/common.c new file +195 -0
195 lines not on this page · raw message
drivers/char/tpm/eventlog/tpm1.c +15 -182
233 lines not on this page · raw message
drivers/char/tpm/tpm.h +2 -0
@@ -580,6 +580,8 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc,int tpm2_commit_space (struct tpm_chip *chip,struct tpm_space *space,u32 cc,u8 *buf,size_t *bufsiz); +extern const struct seq_operations tpm1_ascii_b_measurements_seqops; +extern const struct seq_operations tpm1_binary_b_measurements_seqops;extern const struct seq_operations tpm2_binary_b_measurements_seqops;#if defined(CONFIG_ACPI )
Signature · 1 line
2.17.0.484.g0c8726318c-goog
PATCH 3/3 tpm: Move eventlog declarations to its own header
In reply to Thiebaud WeksteenReduce the size of tpm.h by moving eventlog declarations to a separate header.
--- drivers/char/tpm/eventlog/common.c | 1 + drivers/char/tpm/eventlog/common.h | 35 ++++++++++++++++++++++++++++++ drivers/char/tpm/eventlog/tpm1.c | 1 + drivers/char/tpm/eventlog/tpm2.c | 1 + drivers/char/tpm/tpm.h | 29 ------------------------- 5 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 drivers/char/tpm/eventlog/common.h
drivers/char/tpm/eventlog/common.c +1 -0
@@ -25,6 +25,7 @@#include <linux/tpm_eventlog.h> #include "../tpm.h" +#include "common.h" static int tpm_bios_measurements_open(struct inode *inode,
drivers/char/tpm/eventlog/common.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef __TPM_EVENTLOG_COMMON_H__ +#define __TPM_EVENTLOG_COMMON_H__ + +#include "../tpm.h" + +extern const struct seq_operations tpm1_ascii_b_measurements_seqops; +extern const struct seq_operations tpm1_binary_b_measurements_seqops; +extern const struct seq_operations tpm2_binary_b_measurements_seqops; + +#if defined(CONFIG_ACPI ) +int tpm_read_log_acpi (struct tpm_chip *chip); +#else +static inline int tpm_read_log_acpi (struct tpm_chip *chip) +{ +return -ENODEV ; +} +#endif +#if defined(CONFIG_OF ) +int tpm_read_log_of (struct tpm_chip *chip); +#else +static inline int tpm_read_log_of (struct tpm_chip *chip) +{ +return -ENODEV ; +} +#endif +#if defined(CONFIG_EFI ) +int tpm_read_log_efi (struct tpm_chip *chip); +#else +static inline int tpm_read_log_efi (struct tpm_chip *chip) +{ +return -ENODEV ; +} +#endif + +#endif
drivers/char/tpm/eventlog/tpm1.c +1 -0
@@ -29,6 +29,7 @@#include <linux/tpm_eventlog.h> #include "../tpm.h" +#include "common.h" static const char * tcpa_event_type_strings[] = {
drivers/char/tpm/eventlog/tpm2.c +1 -0
@@ -24,6 +24,7 @@#include <linux/tpm_eventlog.h> #include "../tpm.h" +#include "common.h" /* * calc_tpm2_event_size() - calculate the event size, where event
drivers/char/tpm/tpm.h +0 -29
@@ -580,35 +580,6 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc,int tpm2_commit_space (struct tpm_chip *chip,struct tpm_space *space,u32 cc,u8 *buf,size_t *bufsiz); -extern const struct seq_operations tpm1_ascii_b_measurements_seqops; -extern const struct seq_operations tpm1_binary_b_measurements_seqops; -extern const struct seq_operations tpm2_binary_b_measurements_seqops; - -#if defined(CONFIG_ACPI ) -int tpm_read_log_acpi (struct tpm_chip *chip); -#else -static inline int tpm_read_log_acpi (struct tpm_chip *chip) -{ -return -ENODEV ; -} -#endif -#if defined(CONFIG_OF ) -int tpm_read_log_of (struct tpm_chip *chip); -#else -static inline int tpm_read_log_of (struct tpm_chip *chip) -{ -return -ENODEV ; -} -#endif -#if defined(CONFIG_EFI ) -int tpm_read_log_efi (struct tpm_chip *chip); -#else -static inline int tpm_read_log_efi (struct tpm_chip *chip) -{ -return -ENODEV ; -} -#endif -int tpm_bios_log_setup (struct tpm_chip *chip);void tpm_bios_log_teardown (struct tpm_chip *chip);#endif
Signature · 1 line
2.17.0.484.g0c8726318c-goog
kbuild test robot
build botRe: [PATCH 1/3] tpm: Move eventlog files to a subdirectory
In reply to Thiebaud WeksteenThank you for the patch! Perhaps something to improve:
Hi Thiebaud,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on v4.16 next-20180411]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Thiebaud-Weksteen/tpm-Move-eventlog-files-to-a-subdirectory/20180412-045224
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
>> drivers/char/tpm/eventlog/of.c:59:37: sparse: incorrect type in argument 1 (different base types) @@ expected restricted __be32 const [usertype] *p @@ got unsignrestricted __be32 const [usertype] *p @@ drivers/char/tpm/eventlog/of.c:59:37: expected restricted __be32 const [usertype] *p drivers/char/tpm/eventlog/of.c:59:37: got unsigned int const [usertype] *[assigned] sizep >> drivers/char/tpm/eventlog/of.c:60:37: sparse: incorrect type in argument 1 (different base types) @@ expected restricted __be64 const [usertype] *p @@ got unsigned lonrestricted __be64 const [usertype] *p @@
drivers/char/tpm/eventlog/of.c:60:37: expected restricted __be64 const [usertype] *p
drivers/char/tpm/eventlog/of.c:60:37: got unsigned long long const [usertype] *[assigned] basep
vim +59 drivers/char/tpm/eventlog/of.c
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 23
02ae13828 drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 24 int tpm_read_log_of(struct tpm_chip *chip)
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 25 {
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 26 struct device_node *np;
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 27 const u32 *sizep;
d72c39114 drivers/char/tpm/tpm_of.c Hon Ching \(Vicky\ Lo 2015-06-17 28) const u64 *basep;
748935eeb drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 29 struct tpm_bios_log *log;
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 30 u32 size;
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 31 u64 base;
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 32
748935eeb drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 33 log = &chip->log;
0cf577a03 drivers/char/tpm/tpm_of.c Jason Gunthorpe 2016-11-19 34 if (chip->dev.parent && chip->dev.parent->of_node)
ed4fdb4f5 drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 35 np = chip->dev.parent->of_node;
79eec5b94 drivers/char/tpm/tpm_of.c Colin Ian King 2016-11-15 36 else
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 37 return -ENODEV;
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 38
b5d0ebc99 drivers/char/tpm/tpm_of.c Enric Balletbo i Serra 2017-06-27 39 if (of_property_read_bool(np, "powered-while-suspended"))
b5d0ebc99 drivers/char/tpm/tpm_of.c Enric Balletbo i Serra 2017-06-27 40 chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
b5d0ebc99 drivers/char/tpm/tpm_of.c Enric Balletbo i Serra 2017-06-27 41
c5df39262 drivers/char/tpm/tpm_of.c Ashley Lai 2012-08-14 42 sizep = of_get_property(np, "linux,sml-size", NULL);
0cf577a03 drivers/char/tpm/tpm_of.c Jason Gunthorpe 2016-11-19 43 basep = of_get_property(np, "linux,sml-base", NULL);
0cf577a03 drivers/char/tpm/tpm_of.c Jason Gunthorpe 2016-11-19 44 if (sizep == NULL && basep == NULL)
0cf577a03 drivers/char/tpm/tpm_of.c Jason Gunthorpe 2016-11-19 45 return -ENODEV;
0cf577a03 drivers/char/tpm/tpm_of.c Jason Gunthorpe 2016-11-19 46 if (sizep == NULL || basep == NULL)
5efae7d6b drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 47 return -EIO;
5efae7d6b drivers/char/tpm/tpm_of.c Nayna Jain 2016-11-14 48
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 49 /*
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 50 * For both vtpm/tpm, firmware has log addr and log size in big
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 51 * endian format. But in case of vtpm, there is a method called
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 52 * sml-handover which is run during kernel init even before
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 53 * device tree is setup. This sml-handover function takes care
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 54 * of endianness and writes to sml-base and sml-size in little
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 55 * endian format. For this reason, vtpm doesn't need conversion
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 56 * but physical tpm needs the conversion.
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 57 */
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 58 if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 @59 size = be32_to_cpup(sizep);
e46e22f12 drivers/char/tpm/tpm_of.c Nayna Jain 2017-01-23 @60 base = be64_to_cpup(basep);:::::: The code at line 59 was first introduced by commit
:::::: e46e22f12b19f0068b02afcf6edb716b4f49934f tpm: enhance read_log_of() to support Physical TPM event log
:::::: TO: Nayna Jain <[email protected]> :::::: CC: Jarkko Sakkinen <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 4 lines · Thiebaud Weksteen
This patchset implements the proposal from Jarkko Sakkinen [1]. I have included the feedback from Nayna Jain about the function naming.
You could add suggested-by to these commits.
/Jarkko
Re: [PATCH 3/3] tpm: Move eventlog declarations to its own header
In reply to Thiebaud WeksteenQuoted 4 lines · Thiebaud Weksteen
Reduce the size of
tpm.hby moving eventlog declarations to a separate header.Signed-off-by Thiebaud Weksteen <[email protected]>
Will be fine with suggested-by added.
/Jarkko
Re: [PATCH 3/3] tpm: Move eventlog declarations to its own header
Quoted 7 lines · Jarkko Sakkinen
Quoted 4 lines · Thiebaud Weksteen
Reduce the size of
tpm.hby moving eventlog declarations to a separate header.Signed-off-by Thiebaud Weksteen <[email protected]>Will be fine with suggested-by added.
I don't see anything else to complain in subsequent patches.
Fix kbuild issue and add suggested-by tags and I can move on to testing. Thanks!
/Jarkko