Skip to content

Commit

Permalink
tpm: Return QMP error when TPM is disabled in build
Browse files Browse the repository at this point in the history
When the management layer queries a binary built using --disable-tpm
for TPM devices, it gets confused by getting empty responses:

  { "execute": "query-tpm" }
  {
      "return": [
      ]
  }
  { "execute": "query-tpm-types" }
  {
      "return": [
      ]
  }
  { "execute": "query-tpm-models" }
  {
      "return": [
      ]
  }

To make it clearer by returning an error:
- Make the TPM QAPI schema conditional
  All of tpm.json is now 'if': 'defined(CONFIG_TPM)'.
- Adapt the HMP command
- Remove stubs which became unnecessary

The management layer now gets a 'CommandNotFound' error:

  { "execute": "query-tpm" }
  {
      "error": {
          "class": "CommandNotFound",
          "desc": "The command query-tpm has not been found"
      }
  }

Suggested-by: Marc-André Lureau <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Stefan Berger <[email protected]>
  • Loading branch information
philmd authored and stefanberger committed Jun 15, 2021
1 parent e542b71 commit caff255
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
1 change: 0 additions & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,6 @@ TPM
M: Stefan Berger <[email protected]>
S: Maintained
F: tpm.c
F: stubs/tpm.c
F: hw/tpm/*
F: include/hw/acpi/tpm.h
F: include/sysemu/tpm*
Expand Down
4 changes: 4 additions & 0 deletions monitor/hmp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict)

void hmp_info_tpm(Monitor *mon, const QDict *qdict)
{
#ifdef CONFIG_TPM
TPMInfoList *info_list, *info;
Error *err = NULL;
unsigned int c = 0;
Expand Down Expand Up @@ -946,6 +947,9 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
c++;
}
qapi_free_TPMInfoList(info_list);
#else
monitor_printf(mon, "TPM device not supported\n");
#endif /* CONFIG_TPM */
}

void hmp_quit(Monitor *mon, const QDict *qdict)
Expand Down
28 changes: 19 additions & 9 deletions qapi/tpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#
# Since: 1.5
##
{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ] }
{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ],
'if': 'defined(CONFIG_TPM)' }

##
# @query-tpm-models:
#
Expand All @@ -33,7 +35,8 @@
# <- { "return": [ "tpm-tis", "tpm-crb", "tpm-spapr" ] }
#
##
{ 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
{ 'command': 'query-tpm-models', 'returns': ['TpmModel'],
'if': 'defined(CONFIG_TPM)' }

##
# @TpmType:
Expand All @@ -46,7 +49,8 @@
#
# Since: 1.5
##
{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ] }
{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
'if': 'defined(CONFIG_TPM)' }

##
# @query-tpm-types:
Expand All @@ -63,7 +67,8 @@
# <- { "return": [ "passthrough", "emulator" ] }
#
##
{ 'command': 'query-tpm-types', 'returns': ['TpmType'] }
{ 'command': 'query-tpm-types', 'returns': ['TpmType'],
'if': 'defined(CONFIG_TPM)' }

##
# @TPMPassthroughOptions:
Expand All @@ -79,7 +84,8 @@
##
{ 'struct': 'TPMPassthroughOptions',
'data': { '*path': 'str',
'*cancel-path': 'str' } }
'*cancel-path': 'str' },
'if': 'defined(CONFIG_TPM)' }

##
# @TPMEmulatorOptions:
Expand All @@ -90,7 +96,8 @@
#
# Since: 2.11
##
{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' } }
{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' },
'if': 'defined(CONFIG_TPM)' }

##
# @TpmTypeOptions:
Expand All @@ -104,7 +111,8 @@
##
{ 'union': 'TpmTypeOptions',
'data': { 'passthrough' : 'TPMPassthroughOptions',
'emulator': 'TPMEmulatorOptions' } }
'emulator': 'TPMEmulatorOptions' },
'if': 'defined(CONFIG_TPM)' }

##
# @TPMInfo:
Expand All @@ -122,7 +130,8 @@
{ 'struct': 'TPMInfo',
'data': {'id': 'str',
'model': 'TpmModel',
'options': 'TpmTypeOptions' } }
'options': 'TpmTypeOptions' },
'if': 'defined(CONFIG_TPM)' }

##
# @query-tpm:
Expand Down Expand Up @@ -152,4 +161,5 @@
# }
#
##
{ 'command': 'query-tpm', 'returns': ['TPMInfo'] }
{ 'command': 'query-tpm', 'returns': ['TPMInfo'],
'if': 'defined(CONFIG_TPM)' }
1 change: 0 additions & 1 deletion stubs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ stub_ss.add(files('runstate-check.c'))
stub_ss.add(files('sysbus.c'))
stub_ss.add(files('target-get-monitor-def.c'))
stub_ss.add(files('target-monitor-defs.c'))
stub_ss.add(files('tpm.c'))
stub_ss.add(files('trace-control.c'))
stub_ss.add(files('uuid.c'))
stub_ss.add(files('vmgenid.c'))
Expand Down
25 changes: 0 additions & 25 deletions stubs/tpm.c

This file was deleted.

0 comments on commit caff255

Please sign in to comment.