tpm: Split hw/ vs backends/
v2 cover tpm: Split hw/ vs backends/
Hi,
Yesterday I started to review some vTPM patches and got very confused by the files under hw/tpm/. In particular after running:
$ git grep TYPE_TPM_BACKEND backends/tpm.c:188: .name = TYPE_TPM_BACKEND, hw/tpm/tpm_emulator.c:985: .parent = TYPE_TPM_BACKEND, hw/tpm/tpm_passthrough.c:393: .parent = TYPE_TPM_BACKEND, include/sysemu/tpm_backend.h:21:#define TYPE_TPM_BACKEND "tpm-backend"
As there is no particular reason to keep this mixed, clean it up.
Since v1:
- Amended docs/ changes
- Renamed Kconfig TPM_BACKEND variable
- Move backend files under backends/tpm/ (Marc-André & Stefan)
- Fix x86-64 build error (patchew)
Philippe Mathieu-Daudé (11):
docs/specs/tpm: Correct header path name
backends: Add TPM files into their own directory
hw/tpm: Rename TPMDEV as TPM_BACKEND in Kconfig
hw/tpm: Do not include 'qemu/osdep.h' in header
hw/tpm: Include missing 'qemu/option.h' header
hw/tpm: Move 'hw/acpi/tpm.h' inclusion from header to sources hw/tpm: Remove unnecessary 'tpm_int.h' header inclusion hw/tpm: Move few declarations from 'tpm_util.h' to 'tpm_int.h' hw/tpm: Move DEFINE_PROP_TPMBE() macro to 'tmp_prop.h' local header hw/tpm: Make 'tpm_util.h' publicly accessible as "sysemu/tpm_util.h"
tpm: Move backend code under the 'backends/' directory
docs/specs/tpm.rst | 14 +++++------
Makefile | 2 +-
Makefile.objs | 1 +
{hw => backends}/tpm/tpm_int.h | 19 +++++++++++---
{hw => backends}/tpm/tpm_ioctl.h | 0
hw/tpm/tpm_ppi.h | 1 -
hw/tpm/tpm_prop.h | 31 +++++++++++++++++++++++
hw/tpm/tpm_tis.h | 1 -
{hw/tpm => include/sysemu}/tpm_util.h | 19 +++-----------
backends/{tpm.c => tpm/tpm_backend.c} | 0
{hw => backends}/tpm/tpm_emulator.c | 2 +-
{hw => backends}/tpm/tpm_passthrough.c | 2 +-
{hw => backends}/tpm/tpm_util.c | 2 +-
hw/tpm/tpm_crb.c | 4 +--
hw/tpm/tpm_ppi.c | 1 +
hw/tpm/tpm_spapr.c | 4 +--
hw/tpm/tpm_tis_common.c | 4 +--
hw/tpm/tpm_tis_isa.c | 3 ++-
hw/tpm/tpm_tis_sysbus.c | 3 ++-
tests/qtest/tpm-emu.c | 2 +-
MAINTAINERS | 2 +-
backends/Kconfig | 1 +
backends/Makefile.objs | 2 +-
backends/tpm/Kconfig | 14 +++++++++++
backends/tpm/Makefile.objs | 4 +++
backends/tpm/trace-events | 33 +++++++++++++++++++++++++
hw/tpm/Kconfig | 21 +++-------------
hw/tpm/Makefile.objs | 3 ---
hw/tpm/trace-events | 34 +-------------------------
29 files changed, 132 insertions(+), 97 deletions(-)
rename {hw => backends}/tpm/tpm_int.h (81%)
rename {hw => backends}/tpm/tpm_ioctl.h (100%)
create mode 100644 hw/tpm/tpm_prop.h
rename {hw/tpm => include/sysemu}/tpm_util.h (80%)
rename backends/{tpm.c => tpm/tpm_backend.c} (100%)
rename {hw => backends}/tpm/tpm_emulator.c (99%)
rename {hw => backends}/tpm/tpm_passthrough.c (99%)
rename {hw => backends}/tpm/tpm_util.c (99%)
create mode 100644 backends/Kconfig
create mode 100644 backends/tpm/Kconfig
create mode 100644 backends/tpm/Makefile.objs
create mode 100644 backends/tpm/trace-eventsSignature · 1 line
2.21.3
PATCH v2 1/11 docs/specs/tpm: Correct header path name
Commit 8dc6701722 introduce the documentation but an incorrect path name was used. Fix that.
--- docs/specs/tpm.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
docs/specs/tpm.rst +1 -1
@@ -199,8 +199,8 @@ to be used with the passthrough backend or the swtpm backend. QEMU files related to TPM backends: - ``backends/tpm.c`` + - ``include/sysemu/tpm.h`` - ``include/sysemu/tpm_backend.h`` - - ``include/sysemu/tpm_backend_int.h`` The QEMU TPM passthrough device -------------------------------
Signature · 1 line
2.21.3
Re: [PATCH v2 01/11] docs/specs/tpm: Correct header path name
Quoted 4 lines · Philippe Mathieu-Daudé
Commit
8dc6701722introduce the documentation but an incorrect path name was used. Fix that.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 18 lines
--- docs/specs/tpm.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)docs/specs/tpm.rst +1
-1@@ -199,8 +199,8 @@ to be used with the passthrough backend or the swtpm backend. QEMU files related to TPM backends: - ``backends/tpm.c`` + - ``include/sysemu/tpm.h`` - ``include/sysemu/tpm_backend.h`` - - ``include/sysemu/tpm_backend_int.h`` The QEMU TPM passthrough device -------------------------------
PATCH v2 2/11 backends: Add TPM files into their own directory
In reply to Philippe Mathieu-DaudéAs we will have various TPM backend files, it is cleaner to use a single directory.
---
backends/{tpm.c => tpm/tpm_backend.c} | 0
MAINTAINERS | 2 +-
backends/Makefile.objs | 2 +-
backends/tpm/Makefile.objs | 1 +
4 files changed, 3 insertions(+), 2 deletions(-)
rename backends/{tpm.c => tpm/tpm_backend.c} (100%)
create mode 100644 backends/tpm/Makefile.objsbackends/tpm/tpm_backend.c renamed from backends/tpm.c +0 -0
MAINTAINERS +1 -1
@@ -2385,7 +2385,7 @@ F: hw/tpm/* F: include/hw/acpi/tpm.h F: include/sysemu/tpm* F: qapi/tpm.json -F: backends/tpm.c +F: backends/tpm/ F: tests/qtest/*tpm* T: git https://github.com/stefanberger/qemu-tpm.git tpm-next
backends/Makefile.objs +1 -1
@@ -1,7 +1,7 @@ common-obj-y += rng.o rng-egd.o rng-builtin.o common-obj-$(CONFIG_POSIX) += rng-random.o -common-obj-$(CONFIG_TPM) += tpm.o +common-obj-$(CONFIG_TPM) += tpm/ common-obj-y += hostmem.o hostmem-ram.o common-obj-$(CONFIG_POSIX) += hostmem-file.o
backends/tpm/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +common-obj-y += tpm_backend.o
Signature · 1 line
2.21.3
Re: [PATCH v2 02/11] backends: Add TPM files into their own directory
Quoted 5 lines · Philippe Mathieu-Daudé
As we will have various TPM backend files, it is cleaner to use a single directory.
Suggested-by Stefan Berger <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 46 lines
--- backends/{tpm.c => tpm/tpm_backend.c} | 0 MAINTAINERS | 2 +- backends/Makefile.objs | 2 +- backends/tpm/Makefile.objs | 1 + 4 files changed, 3 insertions(+), 2 deletions(-)rename
backends/{tpm.c=>tpm/tpm_backend.c} (100%) create mode 100644 backends/tpm/Makefile.objsbackends/tpm/tpm_backend.c renamed from backends/tpm.c +0
-0MAINTAINERS +1
-1@@ -2385,7 +2385,7 @@ F: hw/tpm/* F: include/hw/acpi/tpm.h F: include/sysemu/tpm* F: qapi/tpm.json -F: backends/tpm.c +F: backends/tpm/ F: tests/qtest/*tpm* T: git https://github.com/stefanberger/qemu-tpm.git tpm-nextbackends/Makefile.objs +1
-1@@ -1,7 +1,7 @@ common-obj-y += rng.o rng-egd.o rng-builtin.o common-obj-$(CONFIG_POSIX) += rng-random.o -common-obj-$(CONFIG_TPM) += tpm.o +common-obj-$(CONFIG_TPM) += tpm/ common-obj-y += hostmem.o hostmem-ram.o common-obj-$(CONFIG_POSIX) += hostmem-file.obackends/tpm/Makefile.objs new file +1
-0@@ -0,0 +1 @@ +common-obj-y += tpm_backend.o
PATCH v2 3/11 hw/tpm: Rename TPMDEV as TPM_BACKEND in Kconfig
In reply to Philippe Mathieu-DaudéThe TPMDEV describe TPM backends. Use the TPM_BACKEND config name which is self-explicit.
--- hw/tpm/Kconfig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/tpm/Kconfig +6 -6
@@ -1,4 +1,4 @@ -config TPMDEV +config TPM_BACKEND bool depends on TPM
@@ -15,26 +15,26 @@ config TPM_TIS_SYSBUS config TPM_TIS bool depends on TPM - select TPMDEV + select TPM_BACKEND config TPM_CRB bool depends on TPM && PC - select TPMDEV + select TPM_BACKEND config TPM_PASSTHROUGH bool default y # FIXME: should check for x86 host as well - depends on TPMDEV && LINUX + depends on TPM_BACKEND && LINUX config TPM_EMULATOR bool default y - depends on TPMDEV + depends on TPM_BACKEND config TPM_SPAPR bool default y depends on TPM && PSERIES - select TPMDEV + select TPM_BACKEND
Signature · 1 line
2.21.3
Re: [PATCH v2 03/11] hw/tpm: Rename TPMDEV as TPM_BACKEND in Kconfig
Quoted 4 lines · Philippe Mathieu-Daudé
The TPMDEV describe TPM backends. Use the
TPM_BACKENDconfig name which is self-explicit.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 46 lines
--- hw/tpm/Kconfig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/tpm/Kconfig +6
-6@@ -1,4 +1,4 @@ -config TPMDEV +config TPM_BACKEND bool depends on TPM@@ -15,26 +15,26 @@ config TPM_TIS_SYSBUS config TPM_TIS bool depends on TPM - select TPMDEV + select TPM_BACKEND config TPM_CRB bool depends on TPM && PC - select TPMDEV + select TPM_BACKEND config TPM_PASSTHROUGH bool default y # FIXME: should check for x86 host as well - depends on TPMDEV && LINUX + depends on TPM_BACKEND && LINUX config TPM_EMULATOR bool default y - depends on TPMDEV + depends on TPM_BACKEND config TPM_SPAPR bool default y depends on TPM && PSERIES - select TPMDEV + select TPM_BACKEND
PATCH v2 4/11 hw/tpm: Do not include 'qemu/osdep.h' in header
In reply to Philippe Mathieu-DaudéFrom CODING_STYLE.rst:
Do not include "qemu/osdep.h" from header files since the .c file will have already included it.
Remove "qemu/osdep.h" from "tpm_tis.h".
--- hw/tpm/tpm_tis.h | 1 - 1 file changed, 1 deletion(-)
hw/tpm/tpm_tis.h +0 -1
@@ -24,7 +24,6 @@#ifndef TPM_TPM_TIS_H #define TPM_TPM_TIS_H -#include "qemu/osdep.h" #include "sysemu/tpm_backend.h" #include "tpm_ppi.h"
Signature · 1 line
2.21.3
PATCH v2 5/11 hw/tpm: Include missing 'qemu/option.h' header
In reply to Philippe Mathieu-DaudéFiles using the TPM_STANDARD_CMDLINE_OPTS macro declared in "tpm_int.h" will use QEMU_OPT_STRING definition declared in "qemu/option.h".
--- hw/tpm/tpm_int.h | 2 ++ 1 file changed, 2 insertions(+)
hw/tpm/tpm_int.h +2 -0
@@ -12,6 +12,8 @@#ifndef TPM_TPM_INT_H #define TPM_TPM_INT_H +#include "qemu/option.h" +#define TPM_STANDARD_CMDLINE_OPTS \ { \ .name = "type", \
Signature · 1 line
2.21.3
PATCH v2 6/11 hw/tpm: Move 'hw/acpi/tpm.h' inclusion from header to sources
In reply to Philippe Mathieu-DaudéNothing in "tpm_ppi.h" require declarations from "hw/acpi/tpm.h". Reduce dependencies and include it only in the files requiring it.
--- hw/tpm/tpm_ppi.h | 1 - hw/tpm/tpm_ppi.c | 1 + hw/tpm/tpm_tis_isa.c | 1 + hw/tpm/tpm_tis_sysbus.c | 1 + 4 files changed, 3 insertions(+), 1 deletion(-)
hw/tpm/tpm_ppi.h +0 -1
@@ -12,7 +12,6 @@ #ifndef TPM_TPM_PPI_H #define TPM_TPM_PPI_H -#include "hw/acpi/tpm.h" #include "exec/address-spaces.h" typedef struct TPMPPI {
hw/tpm/tpm_ppi.c +1 -0
@@ -17,6 +17,7 @@#include "cpu.h" #include "sysemu/memory_mapping.h" #include "migration/vmstate.h" +#include "hw/acpi/tpm.h" #include "tpm_ppi.h" #include "trace.h"
hw/tpm/tpm_tis_isa.c +1 -0
@@ -26,6 +26,7 @@#include "hw/isa/isa.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" +#include "hw/acpi/tpm.h" #include "tpm_util.h" #include "tpm_tis.h"
hw/tpm/tpm_tis_sysbus.c +1 -0
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" +#include "hw/acpi/tpm.h" #include "tpm_util.h" #include "hw/sysbus.h" #include "tpm_tis.h"
Signature · 1 line
2.21.3
PATCH v2 7/11 hw/tpm: Remove unnecessary 'tpm_int.h' header inclusion
In reply to Philippe Mathieu-DaudéRemove unnecessary 'tpm_int.h' header inclusion.
--- hw/tpm/tpm_crb.c | 1 - hw/tpm/tpm_spapr.c | 1 - hw/tpm/tpm_tis_common.c | 1 - 3 files changed, 3 deletions(-)
hw/tpm/tpm_crb.c +0 -1
@@ -25,7 +25,6 @@#include "migration/vmstate.h" #include "sysemu/tpm_backend.h" #include "sysemu/reset.h" -#include "tpm_int.h" #include "tpm_util.h" #include "tpm_ppi.h" #include "trace.h"
hw/tpm/tpm_spapr.c +0 -1
@@ -20,7 +20,6 @@#include "migration/vmstate.h" #include "sysemu/tpm_backend.h" -#include "tpm_int.h" #include "tpm_util.h" #include "hw/ppc/spapr.h"
hw/tpm/tpm_tis_common.c +0 -1
@@ -33,7 +33,6 @@#include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "sysemu/tpm_backend.h" -#include "tpm_int.h" #include "tpm_util.h" #include "tpm_ppi.h" #include "trace.h"
Signature · 1 line
2.21.3
PATCH v2 8/11 hw/tpm: Move few declarations from 'tpm_util.h' to 'tpm_int.h'
In reply to Philippe Mathieu-DaudéWe are going to make "tpm_util.h" publicly accessible by moving it to the include/ directory in a pair of commits. Keep declarations internals to hw/tpm/ in "tpm_int.h".
--- hw/tpm/tpm_int.h | 11 +++++++++++ hw/tpm/tpm_util.h | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-)
hw/tpm/tpm_int.h +11 -0
@@ -13,6 +13,7 @@#define TPM_TPM_INT_H #include "qemu/option.h" +#include "sysemu/tpm.h" #define TPM_STANDARD_CMDLINE_OPTS \ { \
@@ -74,4 +75,14 @@ struct tpm_resp_hdr {#define TPM_RC_FAILURE 0x101#define TPM_RC_LOCALITY 0x907 +int tpm_util_get_buffer_size (int tpm_fd,TPMVersion tpm_version, +size_t *buffersize); + +typedef struct TPMSizedBuffer { +uint32_t size; +uint8_t *buffer; +}TPMSizedBuffer ; + +void tpm_sized_buffer_reset (TPMSizedBuffer *tsb); +#endif /* TPM_TPM_INT_H */
hw/tpm/tpm_util.h +0 -10
@@ -66,19 +66,9 @@ static inline void tpm_cmd_set_error(void *b, uint32_t error)stl_be_p (b +6 , error); } -int tpm_util_get_buffer_size (int tpm_fd,TPMVersion tpm_version, -size_t *buffersize); -#define DEFINE_PROP_TPMBE (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *) -typedef struct TPMSizedBuffer { -uint32_t size; -uint8_t *buffer; -}TPMSizedBuffer ; - -void tpm_sized_buffer_reset (TPMSizedBuffer *tsb); -void tpm_util_show_buffer (const unsigned char *buffer,size_t buffer_size,const char *string);
Signature · 1 line
2.21.3
PATCH v2 9/11 hw/tpm: Move DEFINE_PROP_TPMBE() macro to 'tmp_prop.h' local header
In reply to Philippe Mathieu-DaudéWe are going to make "tpm_util.h" publicly accessible by moving it to the include/ directory in the next commit. The DEFINE_PROP_TPMBE() macro is only meaningful for the TPM hardware files (in hw/tpm/), so keep this macro in a local header.
--- hw/tpm/tpm_prop.h | 31 +++++++++++++++++++++++++++++++ hw/tpm/tpm_util.h | 3 --- hw/tpm/tpm_crb.c | 1 + hw/tpm/tpm_spapr.c | 1 + hw/tpm/tpm_tis_isa.c | 2 +- hw/tpm/tpm_tis_sysbus.c | 2 +- 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 hw/tpm/tpm_prop.h
hw/tpm/tpm_prop.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* TPM utility functions +* +* Copyright (c) 2010 - 2015 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* This library 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; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#ifndef HW_TPM_PROP_H +#define HW_TPM_PROP_H + +#include "sysemu/tpm_backend.h" +#include "hw/qdev-properties.h" + +#define DEFINE_PROP_TPMBE (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *) + +#endif /* HW_TPM_PROP_H */
hw/tpm/tpm_util.h +0 -3
@@ -66,9 +66,6 @@ static inline void tpm_cmd_set_error(void *b, uint32_t error)stl_be_p (b +6 , error); } -#define DEFINE_PROP_TPMBE (_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *) -void tpm_util_show_buffer (const unsigned char *buffer,size_t buffer_size,const char *string);
hw/tpm/tpm_crb.c +1 -0
@@ -25,6 +25,7 @@#include "migration/vmstate.h" #include "sysemu/tpm_backend.h" #include "sysemu/reset.h" +#include "tpm_prop.h" #include "tpm_util.h" #include "tpm_ppi.h" #include "trace.h"
hw/tpm/tpm_spapr.c +1 -0
@@ -21,6 +21,7 @@#include "sysemu/tpm_backend.h" #include "tpm_util.h" +#include "tpm_prop.h" #include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h"
hw/tpm/tpm_tis_isa.c +1 -1
@@ -27,7 +27,7 @@#include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "hw/acpi/tpm.h" -#include "tpm_util.h" +#include "tpm_prop.h" #include "tpm_tis.h" typedef struct TPMStateISA {
hw/tpm/tpm_tis_sysbus.c +1 -1
@@ -26,7 +26,7 @@#include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "hw/acpi/tpm.h" -#include "tpm_util.h" +#include "tpm_prop.h" #include "hw/sysbus.h" #include "tpm_tis.h"
Signature · 1 line
2.21.3
PATCH v2 10/11 hw/tpm: Make 'tpm_util.h' publicly accessible as "sysemu/tpm_util.h"
In reply to Philippe Mathieu-DaudéWe are going to split the TPM backends from the TPM emulated hardware in the next commit. Make the TPM util helpers accessible by moving local "tpm_util.h" to global "sysemu/tpm_util.h".
---
docs/specs/tpm.rst | 4 ++--
{hw/tpm => include/sysemu}/tpm_util.h | 6 +++---
hw/tpm/tpm_crb.c | 2 +-
hw/tpm/tpm_emulator.c | 2 +-
hw/tpm/tpm_passthrough.c | 2 +-
hw/tpm/tpm_spapr.c | 2 +-
hw/tpm/tpm_tis_common.c | 2 +-
hw/tpm/tpm_util.c | 2 +-
8 files changed, 11 insertions(+), 11 deletions(-)
rename {hw/tpm => include/sysemu}/tpm_util.h (95%)docs/specs/tpm.rst +2 -2
@@ -234,7 +234,7 @@ PCRs. QEMU files related to the TPM passthrough device: - ``hw/tpm/tpm_passthrough.c`` - ``hw/tpm/tpm_util.c`` - - ``hw/tpm/tpm_util.h`` + - ``include/sysemu/tpm_util.h`` Command line to start QEMU with the TPM passthrough device using the host's
@@ -294,7 +294,7 @@ command. QEMU files related to the TPM emulator device: - ``hw/tpm/tpm_emulator.c`` - ``hw/tpm/tpm_util.c`` - - ``hw/tpm/tpm_util.h`` + - ``include/sysemu/tpm_util.h`` The following commands start the swtpm with a UnixIO control channel over a socket interface. They do not need to be run as root.
include/sysemu/tpm_util.h renamed from hw/tpm/tpm_util.h +3 -3
@@ -19,8 +19,8 @@* License along with this library; if not, see <http://www.gnu.org/licenses/> */ -#ifndef TPM_TPM_UTIL_H -#define TPM_TPM_UTIL_H +#ifndef SYSEMU_TPM_UTIL_H +#define SYSEMU_TPM_UTIL_H #include "sysemu/tpm.h" #include "qemu/bswap.h"
@@ -69,4 +69,4 @@ static inline void tpm_cmd_set_error(void *b, uint32_t error)void tpm_util_show_buffer (const unsigned char *buffer,size_t buffer_size,const char *string); -#endif /* TPM_TPM_UTIL_H */ +#endif /* SYSEMU_TPM_UTIL_H */
hw/tpm/tpm_crb.c +1 -1
@@ -24,9 +24,9 @@#include "hw/acpi/tpm.h" #include "migration/vmstate.h" #include "sysemu/tpm_backend.h" +#include "sysemu/tpm_util.h" #include "sysemu/reset.h" #include "tpm_prop.h" -#include "tpm_util.h" #include "tpm_ppi.h" #include "trace.h"
hw/tpm/tpm_emulator.c +1 -1
@@ -32,8 +32,8 @@#include "qemu/sockets.h" #include "io/channel-socket.h" #include "sysemu/tpm_backend.h" +#include "sysemu/tpm_util.h" #include "tpm_int.h" -#include "tpm_util.h" #include "tpm_ioctl.h" #include "migration/blocker.h" #include "migration/vmstate.h"
hw/tpm/tpm_passthrough.c +1 -1
@@ -28,10 +28,10 @@#include "qemu/module.h" #include "qemu/sockets.h" #include "sysemu/tpm_backend.h" +#include "sysemu/tpm_util.h" #include "tpm_int.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-tpm.h" -#include "tpm_util.h" #include "trace.h" #define TYPE_TPM_PASSTHROUGH "tpm-passthrough"
hw/tpm/tpm_spapr.c +1 -1
@@ -20,7 +20,7 @@#include "migration/vmstate.h" #include "sysemu/tpm_backend.h" -#include "tpm_util.h" +#include "sysemu/tpm_util.h" #include "tpm_prop.h" #include "hw/ppc/spapr.h"
hw/tpm/tpm_tis_common.c +1 -1
@@ -33,7 +33,7 @@#include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "sysemu/tpm_backend.h" -#include "tpm_util.h" +#include "sysemu/tpm_util.h" #include "tpm_ppi.h" #include "trace.h"
hw/tpm/tpm_util.c +1 -1
@@ -23,11 +23,11 @@#include "qemu/error-report.h" #include "qapi/error.h" #include "qapi/visitor.h" -#include "tpm_util.h" #include "tpm_int.h" #include "exec/memory.h" #include "hw/qdev-properties.h" #include "sysemu/tpm_backend.h" +#include "sysemu/tpm_util.h" #include "trace.h" /* tpm backend property */
Signature · 1 line
2.21.3
RFC PATCH v2 11/11 tpm: Move backend code under the 'backends/' directory
In reply to Philippe Mathieu-DaudéTPM subsytem is split into backends (see commit f4ede81eed2) and frontends (see i.e. 3676bc69b35). Keep the emulated hardware 'frontends' under hw/tpm/, but move the backends in the backends/tpm/ directory.
---
RFC due to a FIXME in tpm_tis_common.c, it usesTRACE_TPM_UTIL_SHOW_BUFFER which is now generated
by backends/tpm/trace-events...
docs/specs/tpm.rst | 8 +++---
Makefile | 2 +-
Makefile.objs | 1 +
{hw => backends}/tpm/tpm_int.h | 6 ++---
{hw => backends}/tpm/tpm_ioctl.h | 0
{hw => backends}/tpm/tpm_emulator.c | 0
{hw => backends}/tpm/tpm_passthrough.c | 0
{hw => backends}/tpm/tpm_util.c | 0
hw/tpm/tpm_tis_common.c | 1 +
tests/qtest/tpm-emu.c | 2 +-
backends/Kconfig | 1 +
backends/tpm/Kconfig | 14 +++++++++++
backends/tpm/Makefile.objs | 3 +++
backends/tpm/trace-events | 33 +++++++++++++++++++++++++
hw/tpm/Kconfig | 15 ------------
hw/tpm/Makefile.objs | 3 ---
hw/tpm/trace-events | 34 +-------------------------
17 files changed, 63 insertions(+), 60 deletions(-)
rename {hw => backends}/tpm/tpm_int.h (96%)
rename {hw => backends}/tpm/tpm_ioctl.h (100%)
rename {hw => backends}/tpm/tpm_emulator.c (100%)
rename {hw => backends}/tpm/tpm_passthrough.c (100%)
rename {hw => backends}/tpm/tpm_util.c (100%)
create mode 100644 backends/Kconfig
create mode 100644 backends/tpm/Kconfig
create mode 100644 backends/tpm/trace-eventsdocs/specs/tpm.rst +4 -4
@@ -232,8 +232,8 @@ Integrity Measurement Architecture (IMA), are not expecting to share PCRs. QEMU files related to the TPM passthrough device: - - ``hw/tpm/tpm_passthrough.c`` - - ``hw/tpm/tpm_util.c`` + - ``backends/tpm/tpm_passthrough.c`` + - ``backends/tpm/tpm_util.c`` - ``include/sysemu/tpm_util.h``
@@ -292,8 +292,8 @@ instrumented to initialize a TPM 1.2 or TPM 2 device using this command. QEMU files related to the TPM emulator device: - - ``hw/tpm/tpm_emulator.c`` - - ``hw/tpm/tpm_util.c`` + - ``backends/tpm/tpm_emulator.c`` + - ``backends/tpm/tpm_util.c`` - ``include/sysemu/tpm_util.h`` The following commands start the swtpm with a UnixIO control channel over
Makefile +1 -1
@@ -418,7 +418,7 @@ MINIKCONF_ARGS = \ CONFIG_LINUX=$(CONFIG_LINUX) \ CONFIG_PVRDMA=$(CONFIG_PVRDMA) -MINIKCONF_INPUTS = $(SRC_PATH)/Kconfig.host $(SRC_PATH)/hw/Kconfig +MINIKCONF_INPUTS = $(SRC_PATH)/Kconfig.host $(SRC_PATH)/backends/Kconfig $(SRC_PATH)/hw/Kconfig MINIKCONF_DEPS = $(MINIKCONF_INPUTS) $(wildcard $(SRC_PATH)/hw/*/Kconfig) MINIKCONF = $(PYTHON) $(SRC_PATH)/scripts/minikconf.py \
Makefile.objs +1 -0
@@ -125,6 +125,7 @@ trace-events-subdirs = trace-events-subdirs += accel/kvm trace-events-subdirs += accel/tcg trace-events-subdirs += backends +trace-events-subdirs += backends/tpm trace-events-subdirs += crypto trace-events-subdirs += monitor ifeq ($(CONFIG_USER_ONLY),y)
backends/tpm/tpm_int.h renamed from hw/tpm/tpm_int.h +3 -3
@@ -9,8 +9,8 @@* This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ -#ifndef TPM_TPM_INT_H -#define TPM_TPM_INT_H +#ifndef BACKENDS_TPM_INT_H +#define BACKENDS_TPM_INT_H #include "qemu/option.h" #include "sysemu/tpm.h"
@@ -85,4 +85,4 @@ typedef struct TPMSizedBuffer {void tpm_sized_buffer_reset (TPMSizedBuffer *tsb); -#endif /* TPM_TPM_INT_H */ +#endif /* BACKENDS_TPM_INT_H */
backends/tpm/tpm_ioctl.h renamed from hw/tpm/tpm_ioctl.h +0 -0
backends/tpm/tpm_emulator.c renamed from hw/tpm/tpm_emulator.c +0 -0
backends/tpm/tpm_passthrough.c renamed from hw/tpm/tpm_passthrough.c +0 -0
backends/tpm/tpm_util.c renamed from hw/tpm/tpm_util.c +0 -0
hw/tpm/tpm_tis_common.c +1 -0
@@ -36,6 +36,7 @@#include "sysemu/tpm_util.h" #include "tpm_ppi.h" #include "trace.h" +#include "../backends/tpm/trace.h" /* FIXME TRACE_TPM_UTIL_SHOW_BUFFER */ #include "tpm_tis.h"
tests/qtest/tpm-emu.c +1 -1
@@ -13,7 +13,7 @@#include "qemu/osdep.h" #include <glib/gstdio.h> -#include "hw/tpm/tpm_ioctl.h" +#include "backends/tpm/tpm_ioctl.h" #include "io/channel-socket.h" #include "qapi/error.h" #include "tpm-emu.h"
backends/Kconfig new file +1 -0
@@ -0,0 +1 @@ +source tpm/Kconfig
backends/tpm/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config TPM_BACKEND + bool + depends on TPM + +config TPM_PASSTHROUGH + bool + default y + # FIXME: should check for x86 host as well + depends on TPM_BACKEND && LINUX + +config TPM_EMULATOR + bool + default y + depends on TPM_BACKEND
backends/tpm/Makefile.objs +3 -0
@@ -1 +1,4 @@ common-obj-y += tpm_backend.o +common-obj-y += tpm_util.o +common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o +common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o
backends/tpm/trace-events new file +33 -0
@@ -0,0 +1,33 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# tpm_passthrough.c +tpm_passthrough_handle_request(void *cmd) "processing command %p" +tpm_passthrough_reset(void) "reset" + +# tpm_util.c +tpm_util_get_buffer_size_hdr_len(uint32_t len, size_t expected) "tpm_resp->hdr.len = %u, expected = %zu" +tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, expected = %zu" +tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" +tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" +tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" +tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" + +# tpm_emulator.c +tpm_emulator_set_locality(uint8_t locty) "setting locality to %d" +tpm_emulator_handle_request(void) "processing TPM command" +tpm_emulator_probe_caps(uint64_t caps) "capabilities: 0x%"PRIx64 +tpm_emulator_set_buffer_size(uint32_t buffersize, uint32_t minsize, uint32_t maxsize) "buffer size: %u, min: %u, max: %u" +tpm_emulator_startup_tpm_resume(bool is_resume, size_t buffersize) "is_resume: %d, buffer size: %zu" +tpm_emulator_get_tpm_established_flag(uint8_t flag) "got established flag: %d" +tpm_emulator_cancel_cmd_not_supt(void) "Backend does not support CANCEL_TPM_CMD" +tpm_emulator_handle_device_opts_tpm12(void) "TPM Version 1.2" +tpm_emulator_handle_device_opts_tpm2(void) "TPM Version 2" +tpm_emulator_handle_device_opts_unspec(void) "TPM Version Unspecified" +tpm_emulator_handle_device_opts_startup_error(void) "Startup error" +tpm_emulator_get_state_blob(uint8_t type, uint32_t size, uint32_t flags) "got state blob type %d, %u bytes, flags 0x%08x" +tpm_emulator_set_state_blob(uint8_t type, uint32_t size, uint32_t flags) "set state blob type %d, %u bytes, flags 0x%08x" +tpm_emulator_set_state_blobs(void) "setting state blobs" +tpm_emulator_set_state_blobs_error(const char *msg) "error while setting state blobs: %s" +tpm_emulator_set_state_blobs_done(void) "Done setting state blobs" +tpm_emulator_pre_save(void) "" +tpm_emulator_inst_init(void) ""
hw/tpm/Kconfig +0 -15
@@ -1,7 +1,3 @@ -config TPM_BACKEND - bool - depends on TPM - config TPM_TIS_ISA bool depends on TPM && ISA_BUS
@@ -22,17 +18,6 @@ config TPM_CRB depends on TPM && PC select TPM_BACKEND -config TPM_PASSTHROUGH - bool - default y - # FIXME: should check for x86 host as well - depends on TPM_BACKEND && LINUX - -config TPM_EMULATOR - bool - default y - depends on TPM_BACKEND - config TPM_SPAPR bool default y
hw/tpm/Makefile.objs +0 -3
@@ -1,9 +1,6 @@ -common-obj-$(CONFIG_TPM) += tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o common-obj-$(CONFIG_TPM_TIS_ISA) += tpm_tis_isa.o common-obj-$(CONFIG_TPM_TIS_SYSBUS) += tpm_tis_sysbus.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o -common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o obj-$(CONFIG_TPM_SPAPR) += tpm_spapr.o
hw/tpm/trace-events +1 -33
@@ -4,38 +4,6 @@ tpm_crb_mmio_read(uint64_t addr, unsigned size, uint32_t val) "CRB read 0x%016" PRIx64 " len:%u val: 0x%" PRIx32 tpm_crb_mmio_write(uint64_t addr, unsigned size, uint32_t val) "CRB write 0x%016" PRIx64 " len:%u val: 0x%" PRIx32 -# tpm_passthrough.c -tpm_passthrough_handle_request(void *cmd) "processing command %p" -tpm_passthrough_reset(void) "reset" - -# tpm_util.c -tpm_util_get_buffer_size_hdr_len(uint32_t len, size_t expected) "tpm_resp->hdr.len = %u, expected = %zu" -tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, expected = %zu" -tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" -tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" -tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" -tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" - -# tpm_emulator.c -tpm_emulator_set_locality(uint8_t locty) "setting locality to %d" -tpm_emulator_handle_request(void) "processing TPM command" -tpm_emulator_probe_caps(uint64_t caps) "capabilities: 0x%"PRIx64 -tpm_emulator_set_buffer_size(uint32_t buffersize, uint32_t minsize, uint32_t maxsize) "buffer size: %u, min: %u, max: %u" -tpm_emulator_startup_tpm_resume(bool is_resume, size_t buffersize) "is_resume: %d, buffer size: %zu" -tpm_emulator_get_tpm_established_flag(uint8_t flag) "got established flag: %d" -tpm_emulator_cancel_cmd_not_supt(void) "Backend does not support CANCEL_TPM_CMD" -tpm_emulator_handle_device_opts_tpm12(void) "TPM Version 1.2" -tpm_emulator_handle_device_opts_tpm2(void) "TPM Version 2" -tpm_emulator_handle_device_opts_unspec(void) "TPM Version Unspecified" -tpm_emulator_handle_device_opts_startup_error(void) "Startup error" -tpm_emulator_get_state_blob(uint8_t type, uint32_t size, uint32_t flags) "got state blob type %d, %u bytes, flags 0x%08x" -tpm_emulator_set_state_blob(uint8_t type, uint32_t size, uint32_t flags) "set state blob type %d, %u bytes, flags 0x%08x" -tpm_emulator_set_state_blobs(void) "setting state blobs" -tpm_emulator_set_state_blobs_error(const char *msg) "error while setting state blobs: %s" -tpm_emulator_set_state_blobs_done(void) "Done setting state blobs" -tpm_emulator_pre_save(void) "" -tpm_emulator_inst_init(void) "" - # tpm_tis.c tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d"
@@ -56,7 +24,7 @@ tpm_tis_pre_save(uint8_t locty, uint32_t rw_offset) "locty: %d, rw_offset = %u" # tpm_ppi.c tpm_ppi_memset(uint8_t *ptr, size_t size) "memset: %p %zu" -# hw/tpm/tpm_spapr.c +# tpm_spapr.c tpm_spapr_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" tpm_spapr_do_crq(uint8_t raw1, uint8_t raw2) "1st 2 bytes in CRQ: 0x%02x 0x%02x" tpm_spapr_do_crq_crq_result(void) "SPAPR_VTPM_INIT_CRQ_RESULT"
Signature · 1 line
2.21.3
Quoted 6 lines · Philippe Mathieu-Daudé
Hi,
Yesterday I started to review some vTPM patches and got very confused by the files under hw/tpm/. In particular after running:
Quoted 7 lines
$ git grep TYPE_TPM_BACKEND backends/tpm.c:188: .name = TYPE_TPM_BACKEND, hw/tpm/tpm_emulator.c:985: .parent = TYPE_TPM_BACKEND, hw/tpm/tpm_passthrough.c:393: .parent = TYPE_TPM_BACKEND, include/sysemu/tpm_backend.h:21:#define TYPE_TPM_BACKEND "tpm-backend"As there is no particular reason to keep this mixed, clean it up.
THANK YOU for the cleanup.
Stefan
Paolo Bonzini
AppliedQuoted 67 lines · Philippe Mathieu-Daudé
Hi,
Yesterday I started to review some vTPM patches and got very confused by the files under hw/tpm/. In particular after running:
$ git grep TYPE_TPM_BACKEND backends/tpm.c:188: .name = TYPE_TPM_BACKEND, hw/tpm/tpm_emulator.c:985: .parent = TYPE_TPM_BACKEND, hw/tpm/tpm_passthrough.c:393: .parent = TYPE_TPM_BACKEND, include/sysemu/tpm_backend.h:21:#define TYPE_TPM_BACKEND "tpm-backend"As there is no particular reason to keep this mixed, clean it up.
Since v1:
- Amended docs/ changes
- RenamedKconfigTPM_BACKENDvariable
- Move backend files under backends/tpm/ (Marc-André & Stefan)
- Fix x86-64 build error (patchew)Philippe Mathieu-Daudé (11):
docs/specs/tpm: Correct header path name
backends: Add TPM files into their own directory
hw/tpm: Rename TPMDEV asTPM_BACKENDinKconfig
hw/tpm: Do not include 'qemu/osdep.h' in header
hw/tpm: Include missing 'qemu/option.h' header
hw/tpm: Move 'hw/acpi/tpm.h' inclusion from header to sources hw/tpm: Remove unnecessary 'tpm_int.h' header inclusion hw/tpm: Move few declarations from 'tpm_util.h' to 'tpm_int.h' hw/tpm: MoveDEFINE_PROP_TPMBE()macro to 'tmp_prop.h' local header hw/tpm: Make 'tpm_util.h' publicly accessible as "sysemu/tpm_util.h"
tpm: Move backend code under the 'backends/' directorydocs/specs/tpm.rst | 14 +++++------ Makefile | 2 +- Makefile.objs | 1 + {hw => backends}/tpm/tpm_int.h | 19 +++++++++++--- {hw => backends}/tpm/tpm_ioctl.h | 0 hw/tpm/tpm_ppi.h | 1 - hw/tpm/tpm_prop.h | 31 +++++++++++++++++++++++ hw/tpm/tpm_tis.h | 1 - {hw/tpm => include/sysemu}/tpm_util.h | 19 +++----------- backends/{tpm.c => tpm/tpm_backend.c} | 0 {hw => backends}/tpm/tpm_emulator.c | 2 +- {hw => backends}/tpm/tpm_passthrough.c | 2 +- {hw => backends}/tpm/tpm_util.c | 2 +- hw/tpm/tpm_crb.c | 4 +-- hw/tpm/tpm_ppi.c | 1 + hw/tpm/tpm_spapr.c | 4 +-- hw/tpm/tpm_tis_common.c | 4 +-- hw/tpm/tpm_tis_isa.c | 3 ++- hw/tpm/tpm_tis_sysbus.c | 3 ++- tests/qtest/tpm-emu.c | 2 +- MAINTAINERS | 2 +- backends/Kconfig | 1 + backends/Makefile.objs | 2 +- backends/tpm/Kconfig | 14 +++++++++++ backends/tpm/Makefile.objs | 4 +++ backends/tpm/trace-events | 33 +++++++++++++++++++++++++ hw/tpm/Kconfig | 21 +++------------- hw/tpm/Makefile.objs | 3 --- hw/tpm/trace-events | 34 +------------------------- 29 files changed, 132 insertions(+), 97 deletions(-) rename {hw => backends}/tpm/tpm_int.h (81%) rename {hw => backends}/tpm/tpm_ioctl.h (100%) create mode 100644 hw/tpm/tpm_prop.h rename {hw/tpm => include/sysemu}/tpm_util.h (80%)
Quoted 9 lines
rename backends/{tpm.c => tpm/tpm_backend.c} (100%)
rename {hw => backends}/tpm/tpm_emulator.c (99%)
rename {hw => backends}/tpm/tpm_passthrough.c (99%)
rename {hw => backends}/tpm/tpm_util.c (99%)
create mode 100644 backends/Kconfig
create mode 100644 backends/tpm/Kconfig
create mode 100644 backends/tpm/Makefile.objs
create mode 100644 backends/tpm/trace-eventsQueued, thanks.
Paolo