Support for TPM command line options
This patch adds support for TPM command line options.
The command line options supported here are
./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
-device tpm-tis,tpmdev=<id>,id=<other id>
and
./qemu-... -tpmdev help
where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').
Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.
Monitor support for 'info tpm' has been added. It for example prints the
following:
(qemu) info tpm
TPM devices:
tpm0: model=tpm-tis
\ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-27 21:47:49 +04:00
|
|
|
/*
|
|
|
|
* Public TPM functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2013 IBM Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Berger <stefanb@us.ibm.com>
|
|
|
|
*
|
|
|
|
* 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 QEMU_TPM_H
|
|
|
|
#define QEMU_TPM_H
|
|
|
|
|
2018-02-11 12:36:01 +03:00
|
|
|
#include "qapi/qapi-types-tpm.h"
|
2017-10-24 15:20:42 +03:00
|
|
|
#include "qom/object.h"
|
Support for TPM command line options
This patch adds support for TPM command line options.
The command line options supported here are
./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
-device tpm-tis,tpmdev=<id>,id=<other id>
and
./qemu-... -tpmdev help
where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').
Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.
Monitor support for 'info tpm' has been added. It for example prints the
following:
(qemu) info tpm
TPM devices:
tpm0: model=tpm-tis
\ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-27 21:47:49 +04:00
|
|
|
|
2021-06-15 17:21:20 +03:00
|
|
|
#ifdef CONFIG_TPM
|
|
|
|
|
Support for TPM command line options
This patch adds support for TPM command line options.
The command line options supported here are
./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
-device tpm-tis,tpmdev=<id>,id=<other id>
and
./qemu-... -tpmdev help
where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').
Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.
Monitor support for 'info tpm' has been added. It for example prints the
following:
(qemu) info tpm
TPM devices:
tpm0: model=tpm-tis
\ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-27 21:47:49 +04:00
|
|
|
int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
|
Revert "tpm: Clean up error reporting in tpm_init_tpmdev()"
This reverts commit d10e05f15d5c3dd5e5cc59c5dfff460d89d48580.
We report some -tpmdev failures, but then continue as if all was fine.
Reproducer:
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -chardev null,id=tpm0 -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0
qemu-system-x86_64: -tpmdev emulator,id=tpm0,chardev=chrtpm: tpm-emulator: tpm chardev 'chrtpm' not found.
qemu-system-x86_64: -tpmdev emulator,id=tpm0,chardev=chrtpm: tpm-emulator: Could not cleanly shutdown the TPM: No such file or directory
QEMU 5.0.90 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: -device tpm-tis,tpmdev=tpm0: Property 'tpm-tis.tpmdev' can't find value 'tpm0'
$ echo $?
1
This is a regression caused by commit d10e05f15d "tpm: Clean up error
reporting in tpm_init_tpmdev()". It's incomplete: be->create(opts)
continues to use error_report(), and we don't set an error when it
fails.
I figure converting the create() methods to Error would make some
sense, but I'm not sure it's worth the effort right now. Revert the
broken commit instead, and add a comment to tpm_init_tpmdev().
Straightforward conflict in tpm.c resolved.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-07-23 14:58:44 +03:00
|
|
|
int tpm_init(void);
|
Support for TPM command line options
This patch adds support for TPM command line options.
The command line options supported here are
./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
-device tpm-tis,tpmdev=<id>,id=<other id>
and
./qemu-... -tpmdev help
where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').
Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.
Monitor support for 'info tpm' has been added. It for example prints the
following:
(qemu) info tpm
TPM devices:
tpm0: model=tpm-tis
\ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-27 21:47:49 +04:00
|
|
|
void tpm_cleanup(void);
|
|
|
|
|
2017-11-06 21:39:15 +03:00
|
|
|
typedef enum TPMVersion {
|
2015-05-26 23:51:05 +03:00
|
|
|
TPM_VERSION_UNSPEC = 0,
|
|
|
|
TPM_VERSION_1_2 = 1,
|
|
|
|
TPM_VERSION_2_0 = 2,
|
|
|
|
} TPMVersion;
|
|
|
|
|
2017-11-06 21:38:59 +03:00
|
|
|
#define TYPE_TPM_IF "tpm-if"
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct TPMIfClass TPMIfClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(TPMIfClass, TPM_IF,
|
|
|
|
TYPE_TPM_IF)
|
2017-11-06 21:38:59 +03:00
|
|
|
#define TPM_IF(obj) \
|
|
|
|
INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
|
|
|
|
|
2018-12-04 17:20:06 +03:00
|
|
|
typedef struct TPMIf TPMIf;
|
2017-11-06 21:38:59 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct TPMIfClass {
|
2017-11-06 21:38:59 +03:00
|
|
|
InterfaceClass parent_class;
|
|
|
|
|
2017-11-06 21:39:04 +03:00
|
|
|
enum TpmModel model;
|
2018-01-29 21:33:06 +03:00
|
|
|
void (*request_completed)(TPMIf *obj, int ret);
|
2017-11-06 21:39:16 +03:00
|
|
|
enum TPMVersion (*get_version)(TPMIf *obj);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2017-11-06 21:38:59 +03:00
|
|
|
|
2020-03-05 19:51:40 +03:00
|
|
|
#define TYPE_TPM_TIS_ISA "tpm-tis"
|
2020-03-05 19:51:44 +03:00
|
|
|
#define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"
|
2018-01-29 21:33:07 +03:00
|
|
|
#define TYPE_TPM_CRB "tpm-crb"
|
2020-01-21 18:29:32 +03:00
|
|
|
#define TYPE_TPM_SPAPR "tpm-spapr"
|
tpm: Add support for TPM device over I2C bus
Qemu already supports devices attached to ISA and sysbus. This drop adds
support for the I2C bus attached TPM devices. I2C model only supports
TPM2 protocol.
This commit includes changes for the common code.
- Added I2C emulation model. Logic was added in the model to temporarily
cache the data as I2C interface works per byte basis.
- New tpm type "tpm-tis-i2c" added for I2C support. The user has to
provide this string on command line.
Testing:
TPM I2C device module is tested using SWTPM (software based TPM
package). Qemu uses the rainier machine and is connected to swtpm over
the socket interface.
The command to start swtpm is as follows:
$ swtpm socket --tpmstate dir=/tmp/mytpm1 \
--ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock \
--tpm2 --log level=100
The command to start qemu is as follows:
$ qemu-system-arm -M rainier-bmc -nographic \
-kernel ${IMAGEPATH}/fitImage-linux.bin \
-dtb ${IMAGEPATH}/aspeed-bmc-ibm-rainier.dtb \
-initrd ${IMAGEPATH}/obmc-phosphor-initramfs.rootfs.cpio.xz \
-drive file=${IMAGEPATH}/obmc-phosphor-image.rootfs.wic.qcow2,if=sd,index=2 \
-net nic -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443 \
-chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e
Signed-off-by: Ninad Palsule <ninad@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Tested-by: Joel Stanley <joel@jms.id.au>
Message-id: 20230414220754.1191476-4-ninadpalsule@us.ibm.com
2023-04-15 01:07:54 +03:00
|
|
|
#define TYPE_TPM_TIS_I2C "tpm-tis-i2c"
|
2014-08-12 00:33:36 +04:00
|
|
|
|
2020-03-05 19:51:40 +03:00
|
|
|
#define TPM_IS_TIS_ISA(chr) \
|
|
|
|
object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
|
2020-06-01 12:57:36 +03:00
|
|
|
#define TPM_IS_TIS_SYSBUS(chr) \
|
|
|
|
object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
|
2018-01-29 21:33:07 +03:00
|
|
|
#define TPM_IS_CRB(chr) \
|
|
|
|
object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
|
2020-01-21 18:29:32 +03:00
|
|
|
#define TPM_IS_SPAPR(chr) \
|
|
|
|
object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)
|
tpm: Add support for TPM device over I2C bus
Qemu already supports devices attached to ISA and sysbus. This drop adds
support for the I2C bus attached TPM devices. I2C model only supports
TPM2 protocol.
This commit includes changes for the common code.
- Added I2C emulation model. Logic was added in the model to temporarily
cache the data as I2C interface works per byte basis.
- New tpm type "tpm-tis-i2c" added for I2C support. The user has to
provide this string on command line.
Testing:
TPM I2C device module is tested using SWTPM (software based TPM
package). Qemu uses the rainier machine and is connected to swtpm over
the socket interface.
The command to start swtpm is as follows:
$ swtpm socket --tpmstate dir=/tmp/mytpm1 \
--ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock \
--tpm2 --log level=100
The command to start qemu is as follows:
$ qemu-system-arm -M rainier-bmc -nographic \
-kernel ${IMAGEPATH}/fitImage-linux.bin \
-dtb ${IMAGEPATH}/aspeed-bmc-ibm-rainier.dtb \
-initrd ${IMAGEPATH}/obmc-phosphor-initramfs.rootfs.cpio.xz \
-drive file=${IMAGEPATH}/obmc-phosphor-image.rootfs.wic.qcow2,if=sd,index=2 \
-net nic -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443 \
-chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis-i2c,tpmdev=tpm0,bus=aspeed.i2c.bus.12,address=0x2e
Signed-off-by: Ninad Palsule <ninad@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Tested-by: Joel Stanley <joel@jms.id.au>
Message-id: 20230414220754.1191476-4-ninadpalsule@us.ibm.com
2023-04-15 01:07:54 +03:00
|
|
|
#define TPM_IS_TIS_I2C(chr) \
|
|
|
|
object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_I2C)
|
2017-11-06 21:39:18 +03:00
|
|
|
|
2017-11-06 21:39:15 +03:00
|
|
|
/* returns NULL unless there is exactly one TPM device */
|
|
|
|
static inline TPMIf *tpm_find(void)
|
2014-08-12 00:33:36 +04:00
|
|
|
{
|
2017-11-06 21:39:15 +03:00
|
|
|
Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL);
|
|
|
|
|
|
|
|
return TPM_IF(obj);
|
|
|
|
}
|
2015-05-26 23:51:07 +03:00
|
|
|
|
2017-11-06 21:39:15 +03:00
|
|
|
static inline TPMVersion tpm_get_version(TPMIf *ti)
|
|
|
|
{
|
|
|
|
if (!ti) {
|
|
|
|
return TPM_VERSION_UNSPEC;
|
2015-05-26 23:51:07 +03:00
|
|
|
}
|
2017-11-06 21:39:15 +03:00
|
|
|
|
2017-11-06 21:39:16 +03:00
|
|
|
return TPM_IF_GET_CLASS(ti)->get_version(ti);
|
2014-08-12 00:33:36 +04:00
|
|
|
}
|
|
|
|
|
2021-06-15 17:21:20 +03:00
|
|
|
#else /* CONFIG_TPM */
|
|
|
|
|
|
|
|
#define tpm_init() (0)
|
|
|
|
#define tpm_cleanup()
|
|
|
|
|
2022-05-06 16:25:09 +03:00
|
|
|
/* needed for an alignment check in non-tpm code */
|
|
|
|
static inline Object *TPM_IS_CRB(Object *obj)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-15 17:21:20 +03:00
|
|
|
#endif /* CONFIG_TPM */
|
|
|
|
|
Support for TPM command line options
This patch adds support for TPM command line options.
The command line options supported here are
./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
-device tpm-tis,tpmdev=<id>,id=<other id>
and
./qemu-... -tpmdev help
where the latter works similar to -soundhw help and shows a list of
available TPM backends (for example 'passthrough').
Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriverOpts structure if the VM can be started or
'NULL' if not enough or bad parameters were provided.
Monitor support for 'info tpm' has been added. It for example prints the
following:
(qemu) info tpm
TPM devices:
tpm0: model=tpm-tis
\ tpm0: type=passthrough,path=/dev/tpm0,cancel-path=/sys/devices/pnp0/00:09/cancel
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Message-id: 1361987275-26289-2-git-send-email-stefanb@linux.vnet.ibm.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-27 21:47:49 +04:00
|
|
|
#endif /* QEMU_TPM_H */
|