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"
|
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)
|
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()
|
|
|
|
|
|
|
|
#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 */
|