Skip to contentSkip to conversation

target/i386/sev: Housekeeping SEV + measured Linux SEV guest

PATCH Applied Philippe Mathieu-Daudé 4 participants 54 messages Oct 2, 2021 – Oct 8, 2021

Subsystems (2)

v3 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover target/i386/sev: Housekeeping SEV + measured Linux SEV guest

Hi,

While testing James & Dov patch:
https://www.mail-archive.com/[email protected]/msg810571.html
I wasted some time trying to figure out how OVMF was supposed to behave until realizing the binary I was using was built without SEV support... Then wrote this series to help other developers to not hit the same problem.

Since v2:
- Rebased on top of SGX
- Addressed review comments from Markus / David
- Included/rebased 'Measured Linux SEV guest' from Dov [1]
- Added orphean MAINTAINERS section

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Supersedes: <[email protected]>

Dov Murik (2):
sev/i386: Introduce sev_add_kernel_loader_hashes for measured linux
boot
x86/sev: generate SEV kernel loader hashes in x86_load_linux

Dr. David Alan Gilbert (1):
target/i386/sev: sev_get_attestation_report use g_autofree

Philippe Mathieu-Daudé (19):
qapi/misc-target: Wrap long 'SEV Attestation Report' long lines qapi/misc-target: Group SEV QAPI definitions target/i386/kvm: Introduce i386_softmmu_kvm Meson source set target/i386/kvm: Restrict SEV stubs to x86 architecture target/i386/monitor: Return QMP error when SEV is disabled in build target/i386/cpu: Add missing 'qapi/error.h' header target/i386/sev_i386.h: Remove unused headers target/i386/sev: Remove sev_get_me_mask() target/i386/sev: Mark unreachable code with g_assert_not_reached() target/i386/sev: Restrict SEV to system emulation target/i386/sev: Declare system-specific functions in 'sev_i386.h' target/i386/sev: Remove stubs by using code elision target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c target/i386/sev: Move qmp_query_sev_capabilities() to sev.c target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c
monitor: Restrict 'info sev' to x86 targets
MAINTAINERS: Cover AMD SEV files

 qapi/misc-target.json                 |  77 ++++----
 include/monitor/hmp-target.h          |   1 +
 include/monitor/hmp.h                 |   1 -
 include/sysemu/sev.h                  |  20 +-
 target/i386/sev_i386.h                |  32 +--
 hw/i386/pc_sysfw.c                    |   2 +-
 hw/i386/x86.c                         |  25 ++-
 target/i386/cpu.c                     |  17 +-
 {accel => target/i386}/kvm/sev-stub.c |   0
 target/i386/monitor.c                 |  92 +--------
 target/i386/sev-stub.c                |  83 --------
 target/i386/sev-sysemu-stub.c         |  70 +++++++
 target/i386/sev.c                     | 268 +++++++++++++++++++++++---
 MAINTAINERS                           |   7 +
 accel/kvm/meson.build                 |   1 -
 target/i386/kvm/meson.build           |   8 +-
 target/i386/meson.build               |   4 +-
 17 files changed, 438 insertions(+), 270 deletions(-)
 rename {accel => target/i386}/kvm/sev-stub.c (100%)
 delete mode 100644 target/i386/sev-stub.c
 create mode 100644 target/i386/sev-sysemu-stub.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH v3 1/22 qapi/misc-target: Wrap long 'SEV Attestation Report' long lines

Wrap long lines before 70 characters for legibility.

---
 qapi/misc-target.json | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
qapi/misc-target.json +10 -7
index 594fbd1577f..ae5577e0390 100644
@@ -300,8 +300,8 @@
 ##
 # @SevAttestationReport:
 #
-# The struct describes attestation report for a Secure Encrypted Virtualization
-# feature.
+# The struct describes attestation report for a Secure Encrypted
+# Virtualization feature.
 #
 # @data:  guest attestation report (base64 encoded)
 #
@@ -315,10 +315,11 @@
 ##
 # @query-sev-attestation-report:
 #
-# This command is used to get the SEV attestation report, and is supported on AMD
-# X86 platforms only.
+# This command is used to get the SEV attestation report, and is
+# supported on AMD X86 platforms only.
 #
-# @mnonce: a random 16 bytes value encoded in base64 (it will be included in report)
+# @mnonce: a random 16 bytes value encoded in base64 (it will be
+#          included in report)
 #
 # Returns: SevAttestationReport objects.
 #
@@ -326,11 +327,13 @@
 #
 # Example:
 #
-# -> { "execute" : "query-sev-attestation-report", "arguments": { "mnonce": "aaaaaaa" } }
+# -> { "execute" : "query-sev-attestation-report",
+#                  "arguments": { "mnonce": "aaaaaaa" } }
 # <- { "return" : { "data": "aaaaaaaabbbddddd"} }
 #
 ##
-{ 'command': 'query-sev-attestation-report', 'data': { 'mnonce': 'str' },
+{ 'command': 'query-sev-attestation-report',
+  'data': { 'mnonce': 'str' },
   'returns': 'SevAttestationReport',
   'if': 'TARGET_I386' }
 
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 1/22
#2 lore raw

Re: [PATCH v3 01/22] qapi/misc-target: Wrap long 'SEV Attestation Report' long lines

Quoted 46 lines · Philippe Mathieu-Daudé

Wrap long lines before 70 characters for legibility.

---
  qapi/misc-target.json | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
qapi/misc-target.json +7 -6
index 594fbd1577f..ae5577e0390 100644
@@ -300,8 +300,8 @@
  ##
  # @SevAttestationReport:
  #
-# The struct describes attestation report for a Secure Encrypted Virtualization
-# feature.
+# The struct describes attestation report for a Secure Encrypted
+# Virtualization feature.
  #
  # @data:  guest attestation report (base64 encoded)
  #
@@ -315,10 +315,11 @@
  ##
  # @query-sev-attestation-report:
  #
-# This command is used to get the SEV attestation report, and is supported on AMD
-# X86 platforms only.
+# This command is used to get the SEV attestation report, and is
+# supported on AMD X86 platforms only.
  #
-# @mnonce: a random 16 bytes value encoded in base64 (it will be included in report)
+# @mnonce: a random 16 bytes value encoded in base64 (it will be
+#          included in report)
  #
  # Returns: SevAttestationReport objects.
  #
@@ -326,11 +327,13 @@
  #
  # Example:
  #
-# -> { "execute" : "query-sev-attestation-report", "arguments": { "mnonce": "aaaaaaa" } }
+# -> { "execute" : "query-sev-attestation-report",

qapi/misc-target.json line 339

Quoted 10 lines
qapi/misc-target.json +3 -1
+#                  "arguments": { "mnonce": "aaaaaaa" } }
  # <- { "return" : { "data": "aaaaaaaabbbddddd"} }
  #
  ##
-{ 'command': 'query-sev-attestation-report', 'data': { 'mnonce': 'str' },
+{ 'command': 'query-sev-attestation-report',
+  'data': { 'mnonce': 'str' },
    'returns': 'SevAttestationReport',
    'if': 'TARGET_I386' }
 
#3 lore raw

PATCH v3 2/22 qapi/misc-target: Group SEV QAPI definitions

In reply to Philippe Mathieu-Daudé

There is already a section with various SEV commands / types, so move the SEV guest attestation together.

---
 qapi/misc-target.json | 80 +++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 40 deletions(-)
qapi/misc-target.json +40 -40
index ae5577e0390..5aa2b95b7d4 100644
@@ -229,6 +229,46 @@
   'data': { 'packet-header': 'str', 'secret': 'str', '*gpa': 'uint64' },
   'if': 'TARGET_I386' }
 
+##
+# @SevAttestationReport:
+#
+# The struct describes attestation report for a Secure Encrypted
+# Virtualization feature.
+#
+# @data:  guest attestation report (base64 encoded)
+#
+#
+# Since: 6.1
+##
+{ 'struct': 'SevAttestationReport',
+  'data': { 'data': 'str'},
+  'if': 'TARGET_I386' }
+
+##
+# @query-sev-attestation-report:
+#
+# This command is used to get the SEV attestation report, and is
+# supported on AMD X86 platforms only.
+#
+# @mnonce: a random 16 bytes value encoded in base64 (it will be
+#          included in report)
+#
+# Returns: SevAttestationReport objects.
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute" : "query-sev-attestation-report",
+#                  "arguments": { "mnonce": "aaaaaaa" } }
+# <- { "return" : { "data": "aaaaaaaabbbddddd"} }
+#
+##
+{ 'command': 'query-sev-attestation-report',
+  'data': { 'mnonce': 'str' },
+  'returns': 'SevAttestationReport',
+  'if': 'TARGET_I386' }
+
 ##
 # @dump-skeys:
 #
@@ -297,46 +337,6 @@
   'if': 'TARGET_ARM' }
 
 
-##
-# @SevAttestationReport:
-#
-# The struct describes attestation report for a Secure Encrypted
-# Virtualization feature.
-#
-# @data:  guest attestation report (base64 encoded)
-#
-#
-# Since: 6.1
-##
-{ 'struct': 'SevAttestationReport',
-  'data': { 'data': 'str'},
-  'if': 'TARGET_I386' }
-
-##
-# @query-sev-attestation-report:
-#
-# This command is used to get the SEV attestation report, and is
-# supported on AMD X86 platforms only.
-#
-# @mnonce: a random 16 bytes value encoded in base64 (it will be
-#          included in report)
-#
-# Returns: SevAttestationReport objects.
-#
-# Since: 6.1
-#
-# Example:
-#
-# -> { "execute" : "query-sev-attestation-report",
-#                  "arguments": { "mnonce": "aaaaaaa" } }
-# <- { "return" : { "data": "aaaaaaaabbbddddd"} }
-#
-##
-{ 'command': 'query-sev-attestation-report',
-  'data': { 'mnonce': 'str' },
-  'returns': 'SevAttestationReport',
-  'if': 'TARGET_I386' }
-
 ##
 # @SGXInfo:
 #
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 2/22
#4 lore raw

Re: [PATCH v3 02/22] qapi/misc-target: Group SEV QAPI definitions

Quoted 97 lines · Philippe Mathieu-Daudé

There is already a section with various SEV commands / types, so move the SEV guest attestation together.

---
  qapi/misc-target.json | 80 +++++++++++++++++++++----------------------
  1 file changed, 40 insertions(+), 40 deletions(-)
qapi/misc-target.json +40 -33
index ae5577e0390..5aa2b95b7d4 100644
@@ -229,6 +229,46 @@
    'data': { 'packet-header': 'str', 'secret': 'str', '*gpa': 'uint64' },
    'if': 'TARGET_I386' }
 
+##
+# @SevAttestationReport:
+#
+# The struct describes attestation report for a Secure Encrypted
+# Virtualization feature.
+#
+# @data:  guest attestation report (base64 encoded)
+#
+#
+# Since: 6.1
+##
+{ 'struct': 'SevAttestationReport',
+  'data': { 'data': 'str'},
+  'if': 'TARGET_I386' }
+
+##
+# @query-sev-attestation-report:
+#
+# This command is used to get the SEV attestation report, and is
+# supported on AMD X86 platforms only.
+#
+# @mnonce: a random 16 bytes value encoded in base64 (it will be
+#          included in report)
+#
+# Returns: SevAttestationReport objects.
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute" : "query-sev-attestation-report",
+#                  "arguments": { "mnonce": "aaaaaaa" } }
+# <- { "return" : { "data": "aaaaaaaabbbddddd"} }
+#
+##
+{ 'command': 'query-sev-attestation-report',
+  'data': { 'mnonce': 'str' },
+  'returns': 'SevAttestationReport',
+  'if': 'TARGET_I386' }
+
  ##
  # @dump-skeys:
  #
@@ -297,46 +337,6 @@
    'if': 'TARGET_ARM' }
 
 
-##
-# @SevAttestationReport:
-#
-# The struct describes attestation report for a Secure Encrypted
-# Virtualization feature.
-#
-# @data:  guest attestation report (base64 encoded)
-#
-#
-# Since: 6.1
-##
-{ 'struct': 'SevAttestationReport',
-  'data': { 'data': 'str'},
-  'if': 'TARGET_I386' }
-
-##
-# @query-sev-attestation-report:
-#
-# This command is used to get the SEV attestation report, and is
-# supported on AMD X86 platforms only.
-#
-# @mnonce: a random 16 bytes value encoded in base64 (it will be
-#          included in report)
-#
-# Returns: SevAttestationReport objects.
-#
-# Since: 6.1
-#
-# Example:
-#
-# -> { "execute" : "query-sev-attestation-report",
-#                  "arguments": { "mnonce": "aaaaaaa" } }
-# <- { "return" : { "data": "aaaaaaaabbbddddd"} }

qapi/misc-target.json line 342

Quoted 10 lines
qapi/misc-target.json +0 -7
-#
-##
-{ 'command': 'query-sev-attestation-report',
-  'data': { 'mnonce': 'str' },
-  'returns': 'SevAttestationReport',
-  'if': 'TARGET_I386' }
-
  ##
  # @SGXInfo:
  #
#5 lore raw

PATCH v3 3/22 target/i386/kvm: Introduce i386_softmmu_kvm Meson source set

In reply to Philippe Mathieu-Daudé

Introduce the i386_softmmu_kvm Meson source set to be able to add features dependent on CONFIG_KVM.

---
 target/i386/kvm/meson.build | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
target/i386/kvm/meson.build +5 -1
index 0a533411cab..b1c76957c76 100644
@@ -1,8 +1,12 @@
 i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
 
-i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files(
+i386_softmmu_kvm_ss = ss.source_set()
+
+i386_softmmu_kvm_ss.add(files(
   'kvm.c',
   'kvm-cpu.c',
 ))
 
 i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
+
+i386_softmmu_ss.add_all(when: 'CONFIG_KVM', if_true: i386_softmmu_kvm_ss)
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 3/22
#6 lore raw

Re: [PATCH v3 03/22] target/i386/kvm: Introduce i386_softmmu_kvm Meson source set

Quoted 17 lines · Philippe Mathieu-Daudé

Introduce the i386_softmmu_kvm Meson source set to be able to add features dependent on CONFIG_KVM.

---
  target/i386/kvm/meson.build | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
target/i386/kvm/meson.build +0 -1
index 0a533411cab..b1c76957c76 100644
@@ -1,8 +1,12 @@
  i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
 
-i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files(

target/i386/kvm/meson.build line 12

Quoted 10 lines
target/i386/kvm/meson.build +5 -0
+i386_softmmu_kvm_ss = ss.source_set()
+
+i386_softmmu_kvm_ss.add(files(
    'kvm.c',
    'kvm-cpu.c',
  ))
 
  i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
+
+i386_softmmu_ss.add_all(when: 'CONFIG_KVM', if_true: i386_softmmu_kvm_ss)
#7 lore raw

PATCH v3 4/22 target/i386/kvm: Restrict SEV stubs to x86 architecture

In reply to Philippe Mathieu-Daudé

SEV is x86-specific, no need to add its stub to other architectures. Move the stub file to target/i386/kvm/.

---
 {accel => target/i386}/kvm/sev-stub.c | 0
 accel/kvm/meson.build                 | 1 -
 target/i386/kvm/meson.build           | 2 ++
 3 files changed, 2 insertions(+), 1 deletion(-)
 rename {accel => target/i386}/kvm/sev-stub.c (100%)
target/i386/kvm/sev-stub.c renamed from accel/kvm/sev-stub.c +0 -0
similarity index 100%
rename from accel/kvm/sev-stub.c
rename to target/i386/kvm/sev-stub.c
accel/kvm/meson.build +0 -1
index 8d219bea507..397a1fe1fd1 100644
@@ -3,6 +3,5 @@
   'kvm-all.c',
   'kvm-accel-ops.c',
 ))
-kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
 
 specific_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
target/i386/kvm/meson.build +2 -0
index b1c76957c76..736df8b72e3 100644
@@ -7,6 +7,8 @@
   'kvm-cpu.c',
 ))
 
+i386_softmmu_kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
+
 i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
 
 i386_softmmu_ss.add_all(when: 'CONFIG_KVM', if_true: i386_softmmu_kvm_ss)
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 4/22
#8 lore raw

Re: [PATCH v3 04/22] target/i386/kvm: Restrict SEV stubs to x86 architecture

Quoted 32 lines · Philippe Mathieu-Daudé

SEV is x86-specific, no need to add its stub to other architectures. Move the stub file to target/i386/kvm/.

---
  {accel => target/i386}/kvm/sev-stub.c | 0
  accel/kvm/meson.build                 | 1 -
  target/i386/kvm/meson.build           | 2 ++
  3 files changed, 2 insertions(+), 1 deletion(-)

rename {accel => target/i386}/kvm/sev-stub.c (100%)

target/i386/kvm/sev-stub.c renamed from accel/kvm/sev-stub.c +0 -0
similarity index 100%
rename from accel/kvm/sev-stub.c
rename to target/i386/kvm/sev-stub.c
accel/kvm/meson.build +0 -1
index 8d219bea507..397a1fe1fd1 100644
@@ -3,6 +3,5 @@
    'kvm-all.c',
    'kvm-accel-ops.c',
  ))
-kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
 
  specific_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
target/i386/kvm/meson.build +0 -0
index b1c76957c76..736df8b72e3 100644

target/i386/kvm/meson.build line 14

Quoted 8 lines
target/i386/kvm/meson.build +2 -0
@@ -7,6 +7,8 @@
    'kvm-cpu.c',
  ))
 
+i386_softmmu_kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
+
  i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
 
  i386_softmmu_ss.add_all(when: 'CONFIG_KVM', if_true: i386_softmmu_kvm_ss)
#9 lore raw

PATCH v3 5/22 target/i386/monitor: Return QMP error when SEV is disabled in build

In reply to Philippe Mathieu-Daudé

If the management layer tries to inject a secret, it gets an empty response in case the binary built without SEV:

  { "execute": "sev-inject-launch-secret",
    "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
  }
  {
      "return": {
      }
  }

Make it clearer by returning an error, mentioning the feature is disabled:

  { "execute": "sev-inject-launch-secret",
    "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
  }
  {
      "error": {
          "class": "GenericError",
          "desc": "this feature or command is not currently supported"
      }
  }
---
 target/i386/monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
target/i386/monitor.c +5 -0
index 196c1c9e77f..a9f85acd473 100644
@@ -28,6 +28,7 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qerror.h"
 #include "sysemu/kvm.h"
 #include "sysemu/sev.h"
 #include "qapi/error.h"
@@ -743,6 +744,10 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,
                                   bool has_gpa, uint64_t gpa,
                                   Error **errp)
 {
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
     if (!has_gpa) {
         uint8_t *data;
         struct sev_secret_area *area;
Signature · 1 line
2.31.1
maintainer
#10 lore raw

Re: [PATCH v3 05/22] target/i386/monitor: Return QMP error when SEV is disabled in build

Quoted 45 lines · Philippe Mathieu-Daudé

If the management layer tries to inject a secret, it gets an empty response in case the binary built without SEV:

   { "execute": "sev-inject-launch-secret",
     "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "return": {
       }
   }

Make it clearer by returning an error, mentioning the feature is disabled:

   { "execute": "sev-inject-launch-secret",
     "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "error": {
           "class": "GenericError",
           "desc": "this feature or command is not currently supported"
       }
   }
---
  target/i386/monitor.c | 5 +++++
  1 file changed, 5 insertions(+)
target/i386/monitor.c +1 -0
index 196c1c9e77f..a9f85acd473 100644
@@ -28,6 +28,7 @@
  #include "monitor/hmp-target.h"
  #include "monitor/hmp.h"
  #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qerror.h"
  #include "sysemu/kvm.h"
  #include "sysemu/sev.h"
  #include "qapi/error.h"

target/i386/monitor.c void qmp_sev_inject_launch_secret(const char *packet_hdr, · line 753

Quoted 10 lines
target/i386/monitor.c +4 -0
@@ -743,6 +744,10 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,
                                    bool has_gpa, uint64_t gpa,
                                    Error **errp)
  {
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
      if (!has_gpa) {
          uint8_t *data;
          struct sev_secret_area *area;

This should be done in the sev_inject_launch_secret stub instead, I think. Or if you do it here, you can remove the "if (!sev_guest)" conditional in the non-stub version.

Paolo

#11 lore raw

Re: [PATCH v3 05/22] target/i386/monitor: Return QMP error when SEV is disabled in build

Quoted 55 lines · Paolo Bonzini
Quoted 54 lines · Philippe Mathieu-Daudé

If the management layer tries to inject a secret, it gets an empty response in case the binary built without SEV:

   { "execute": "sev-inject-launch-secret", "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "return": {
       }
   }

Make it clearer by returning an error, mentioning the feature is disabled:

   { "execute": "sev-inject-launch-secret",
     "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "error": {
           "class": "GenericError",
           "desc": "this feature or command is not currently supported" }
   }

---
  target/i386/monitor.c | 5 +++++

  1 file changed, 5 insertions(+)
target/i386/monitor.c +5 -0
index 196c1c9e77f..a9f85acd473 100644
@@ -28,6 +28,7 @@
   #include "monitor/hmp-target.h"
   #include "monitor/hmp.h"
   #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qerror.h"
   #include "sysemu/kvm.h"
   #include "sysemu/sev.h"
   #include "qapi/error.h"
@@ -743,6 +744,10 @@ void qmp_sev_inject_launch_secret(const char
 *packet_hdr,
                                     bool has_gpa, uint64_t gpa,
                                     Error **errp)
   {
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
Quoted 8 lines
Quoted 4 lines
target/i386/monitor.c +0 -0
       if (!has_gpa) {
           uint8_t *data;

          struct sev_secret_area *area;

This should be done in the sev_inject_launch_secret stub instead, I think.  Or if you do it here, you can remove the "if (!sev_guest)" conditional in the non-stub version.

This part is not related to SEV builtin; what we want to avoid here is management layer to try to inject secret while the guest hasn't been started with SEV (IOW 'no memory encryption requested for KVM).

Maybe this error message is more explicit?

error_setg(errp, "Guest is not using memory encryption");

Or:

error_setg(errp, "Guest is not using SEV");

#12 lore raw

Re: [PATCH v3 05/22] target/i386/monitor: Return QMP error when SEV is disabled in build

Quoted 69 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Quoted 55 lines · Paolo Bonzini
Quoted 54 lines · Philippe Mathieu-Daudé

If the management layer tries to inject a secret, it gets an empty response in case the binary built without SEV:

   { "execute": "sev-inject-launch-secret", "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "return": {
       }
   }

Make it clearer by returning an error, mentioning the feature is disabled:

   { "execute": "sev-inject-launch-secret",
     "arguments": { "packet-header": "mypkt", "secret": "mypass", "gpa": 4294959104 }
   }
   {
       "error": {
           "class": "GenericError",
           "desc": "this feature or command is not currently supported" }
   }

---
  target/i386/monitor.c | 5 +++++

  1 file changed, 5 insertions(+)
target/i386/monitor.c +5 -0
index 196c1c9e77f..a9f85acd473 100644
@@ -28,6 +28,7 @@
   #include "monitor/hmp-target.h"
   #include "monitor/hmp.h"
   #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qerror.h"
   #include "sysemu/kvm.h"
   #include "sysemu/sev.h"
   #include "qapi/error.h"
@@ -743,6 +744,10 @@ void qmp_sev_inject_launch_secret(const char
 *packet_hdr,
                                     bool has_gpa, uint64_t gpa,
                                     Error **errp)
   {
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
Quoted 8 lines
Quoted 4 lines
target/i386/monitor.c +0 -0
       if (!has_gpa) {
           uint8_t *data;

          struct sev_secret_area *area;

This should be done in the sev_inject_launch_secret stub instead, I think.  Or if you do it here, you can remove the "if (!sev_guest)" conditional in the non-stub version.

This part is not related to SEV builtin; what we want to avoid here is management layer to try to inject secret while the guest hasn't been started with SEV (IOW 'no memory encryption requested for KVM).

Quoted 7 lines

Maybe this error message is more explicit?

error_setg(errp, "Guest is not using memory encryption");

Or:

error_setg(errp, "Guest is not using SEV");

This is better; there's a separate feature called memory encryption, so we don't want to confuse things.

Dave

Quoted 1 line
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#13 lore raw

PATCH v3 6/22 target/i386/cpu: Add missing 'qapi/error.h' header

In reply to Philippe Mathieu-Daudé

Commit 00b81053244 ("target-i386: Remove assert_no_error usage") forgot to add the "qapi/error.h" for &error_abort, add it now.

---
 target/i386/cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/cpu.c +1 -0
index cacec605bf1..e169a01713d 100644
@@ -27,6 +27,7 @@
 #include "sysemu/hvf.h"
 #include "kvm/kvm_i386.h"
 #include "sev_i386.h"
+#include "qapi/error.h"
 #include "qapi/qapi-visit-machine.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qapi-commands-machine-target.h"
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 6/22
#14 lore raw

Re: [PATCH v3 06/22] target/i386/cpu: Add missing 'qapi/error.h' header

Quoted 16 lines · Philippe Mathieu-Daudé

Commit 00b81053244 ("target-i386: Remove assert_no_error usage") forgot to add the "qapi/error.h" for &error_abort, add it now.

---
  target/i386/cpu.c | 1 +
  1 file changed, 1 insertion(+)
target/i386/cpu.c +0 -0
index cacec605bf1..e169a01713d 100644

target/i386/cpu.c line 33

Quoted 7 lines
target/i386/cpu.c +1 -0
@@ -27,6 +27,7 @@
  #include "sysemu/hvf.h"
  #include "kvm/kvm_i386.h"
  #include "sev_i386.h"
+#include "qapi/error.h"
  #include "qapi/qapi-visit-machine.h"
  #include "qapi/qmp/qerror.h"
  #include "qapi/qapi-commands-machine-target.h"
#15 lore raw

PATCH v3 7/22 target/i386/sev_i386.h: Remove unused headers

In reply to Philippe Mathieu-Daudé

Declarations don't require these headers, remove them.

---
 target/i386/sev_i386.h | 4 ----
 target/i386/sev-stub.c | 1 +
 2 files changed, 1 insertion(+), 4 deletions(-)
target/i386/sev_i386.h +0 -4
index ae6d8404787..f4223f1febf 100644
@@ -14,11 +14,7 @@
 #ifndef QEMU_SEV_I386_H
 #define QEMU_SEV_I386_H
 
-#include "qom/object.h"
-#include "qapi/error.h"
-#include "sysemu/kvm.h"
 #include "sysemu/sev.h"
-#include "qemu/error-report.h"
 #include "qapi/qapi-types-misc-target.h"
 
 #define SEV_POLICY_NODBG        0x1
target/i386/sev-stub.c +1 -0
index 0227cb51778..d91c2ece784 100644
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "sev_i386.h"
 
 SevInfo *sev_get_info(void)
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 7/22
#16 lore raw

Re: [PATCH v3 07/22] target/i386/sev_i386.h: Remove unused headers

Quoted 31 lines · Philippe Mathieu-Daudé

Declarations don't require these headers, remove them.

---
  target/i386/sev_i386.h | 4 ----
  target/i386/sev-stub.c | 1 +
  2 files changed, 1 insertion(+), 4 deletions(-)
target/i386/sev_i386.h +0 -4
index ae6d8404787..f4223f1febf 100644
@@ -14,11 +14,7 @@
  #ifndef QEMU_SEV_I386_H
  #define QEMU_SEV_I386_H
 
-#include "qom/object.h"
-#include "qapi/error.h"
-#include "sysemu/kvm.h"
  #include "sysemu/sev.h"
-#include "qemu/error-report.h"
  #include "qapi/qapi-types-misc-target.h"
 
  #define SEV_POLICY_NODBG        0x1
target/i386/sev-stub.c +0 -0
index 0227cb51778..d91c2ece784 100644

target/i386/sev-stub.c line 18

Quoted 7 lines
target/i386/sev-stub.c +1 -0
@@ -12,6 +12,7 @@
   */
 
  #include "qemu/osdep.h"
+#include "qapi/error.h"
  #include "sev_i386.h"
 
  SevInfo *sev_get_info(void)
#17 lore raw

PATCH v3 8/22 target/i386/sev: Remove sev_get_me_mask()

In reply to Philippe Mathieu-Daudé

Unused dead code makes review harder, so remove it.

---
 target/i386/sev_i386.h | 1 -
 target/i386/sev-stub.c | 5 -----
 target/i386/sev.c      | 9 ---------
 3 files changed, 15 deletions(-)
target/i386/sev_i386.h +0 -1
index f4223f1febf..afa19a0a161 100644
@@ -25,7 +25,6 @@
 #define SEV_POLICY_SEV          0x20
 
 extern bool sev_es_enabled(void);
-extern uint64_t sev_get_me_mask(void);
 extern SevInfo *sev_get_info(void);
 extern uint32_t sev_get_cbit_position(void);
 extern uint32_t sev_get_reduced_phys_bits(void);
target/i386/sev-stub.c +0 -5
index d91c2ece784..eb0c89bf2be 100644
@@ -25,11 +25,6 @@ bool sev_enabled(void)
     return false;
 }
 
-uint64_t sev_get_me_mask(void)
-{
-    return ~0;
-}
-
 uint32_t sev_get_cbit_position(void)
 {
     return 0;
target/i386/sev.c +0 -9
index fa7210473a6..c88cd808410 100644
@@ -64,7 +64,6 @@ struct SevGuestState {
     uint8_t api_major;
     uint8_t api_minor;
     uint8_t build_id;
-    uint64_t me_mask;
     int sev_fd;
     SevState state;
     gchar *measurement;
@@ -362,12 +361,6 @@ sev_es_enabled(void)
     return sev_enabled() && (sev_guest->policy & SEV_POLICY_ES);
 }
 
-uint64_t
-sev_get_me_mask(void)
-{
-    return sev_guest ? sev_guest->me_mask : ~0;
-}
-
 uint32_t
 sev_get_cbit_position(void)
 {
@@ -804,8 +797,6 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
         goto err;
     }
 
-    sev->me_mask = ~(1UL << sev->cbitpos);
-
     devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
     sev->sev_fd = open(devname, O_RDWR);
     if (sev->sev_fd < 0) {
Signature · 1 line
2.31.1
maintainer
#18 lore raw

Re: [PATCH v3 08/22] target/i386/sev: Remove sev_get_me_mask()

Quoted 66 lines · Philippe Mathieu-Daudé

Unused dead code makes review harder, so remove it.

---
  target/i386/sev_i386.h | 1 -
  target/i386/sev-stub.c | 5 -----
  target/i386/sev.c      | 9 ---------
  3 files changed, 15 deletions(-)
target/i386/sev_i386.h +0 -1
index f4223f1febf..afa19a0a161 100644
@@ -25,7 +25,6 @@
  #define SEV_POLICY_SEV          0x20
 
  extern bool sev_es_enabled(void);
-extern uint64_t sev_get_me_mask(void);
  extern SevInfo *sev_get_info(void);
  extern uint32_t sev_get_cbit_position(void);
  extern uint32_t sev_get_reduced_phys_bits(void);
target/i386/sev-stub.c +0 -5
index d91c2ece784..eb0c89bf2be 100644
@@ -25,11 +25,6 @@ bool sev_enabled(void)
      return false;
  }
 
-uint64_t sev_get_me_mask(void)
-{
-    return ~0;
-}
-
  uint32_t sev_get_cbit_position(void)
  {
      return 0;
target/i386/sev.c +0 -7
index fa7210473a6..c88cd808410 100644
@@ -64,7 +64,6 @@ struct SevGuestState {
      uint8_t api_major;
      uint8_t api_minor;
      uint8_t build_id;
-    uint64_t me_mask;
      int sev_fd;
      SevState state;
      gchar *measurement;
@@ -362,12 +361,6 @@ sev_es_enabled(void)
      return sev_enabled() && (sev_guest->policy & SEV_POLICY_ES);
  }
 
-uint64_t
-sev_get_me_mask(void)
-{
-    return sev_guest ? sev_guest->me_mask : ~0;
-}
-
  uint32_t
  sev_get_cbit_position(void)
  {

target/i386/sev.c int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 802

Quoted 8 lines
target/i386/sev.c +0 -2
@@ -804,8 +797,6 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
          goto err;
      }
 
-    sev->me_mask = ~(1UL << sev->cbitpos);
-
      devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
      sev->sev_fd = open(devname, O_RDWR);
      if (sev->sev_fd < 0) {

RB

maintainer Reviewed-by on v3 8/22
#19 lore raw

Re: [PATCH v3 08/22] target/i386/sev: Remove sev_get_me_mask()

In reply to Philippe Mathieu-Daudé
Quoted 66 lines · Philippe Mathieu-Daudé

Unused dead code makes review harder, so remove it.

---
  target/i386/sev_i386.h | 1 -
  target/i386/sev-stub.c | 5 -----
  target/i386/sev.c      | 9 ---------
  3 files changed, 15 deletions(-)
target/i386/sev_i386.h +0 -1
index f4223f1febf..afa19a0a161 100644
@@ -25,7 +25,6 @@
  #define SEV_POLICY_SEV          0x20
 
  extern bool sev_es_enabled(void);
-extern uint64_t sev_get_me_mask(void);
  extern SevInfo *sev_get_info(void);
  extern uint32_t sev_get_cbit_position(void);
  extern uint32_t sev_get_reduced_phys_bits(void);
target/i386/sev-stub.c +0 -5
index d91c2ece784..eb0c89bf2be 100644
@@ -25,11 +25,6 @@ bool sev_enabled(void)
      return false;
  }
 
-uint64_t sev_get_me_mask(void)
-{
-    return ~0;
-}
-
  uint32_t sev_get_cbit_position(void)
  {
      return 0;
target/i386/sev.c +0 -7
index fa7210473a6..c88cd808410 100644
@@ -64,7 +64,6 @@ struct SevGuestState {
      uint8_t api_major;
      uint8_t api_minor;
      uint8_t build_id;
-    uint64_t me_mask;
      int sev_fd;
      SevState state;
      gchar *measurement;
@@ -362,12 +361,6 @@ sev_es_enabled(void)
      return sev_enabled() && (sev_guest->policy & SEV_POLICY_ES);
  }
 
-uint64_t
-sev_get_me_mask(void)
-{
-    return sev_guest ? sev_guest->me_mask : ~0;
-}
-
  uint32_t
  sev_get_cbit_position(void)
  {

target/i386/sev.c int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 802

Quoted 8 lines
target/i386/sev.c +0 -2
@@ -804,8 +797,6 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
          goto err;
      }
 
-    sev->me_mask = ~(1UL << sev->cbitpos);
-
      devname = object_property_get_str(OBJECT(sev), "sev-device", NULL);
      sev->sev_fd = open(devname, O_RDWR);
      if (sev->sev_fd < 0) {
#20 lore raw

PATCH v3 9/22 target/i386/sev: Mark unreachable code with g_assert_not_reached()

In reply to Philippe Mathieu-Daudé

The unique sev_encrypt_flash() invocation (in pc_system_flash_map) is protected by the "if (sev_enabled())" check, so is not reacheable.
Replace the abort() call in sev_es_save_reset_vector() by g_assert_not_reached() which meaning is clearer.

---
 target/i386/sev-stub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/sev-stub.c +2 -2
index eb0c89bf2be..4668365fd3e 100644
@@ -54,7 +54,7 @@ int sev_inject_launch_secret(const char *hdr, const char *secret,
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
 {
-    return 0;
+    g_assert_not_reached();
 }
 
 bool sev_es_enabled(void)
@@ -68,7 +68,7 @@ void sev_es_set_reset_vector(CPUState *cpu)
 
 int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
 {
-    abort();
+    g_assert_not_reached();
 }
 
 SevAttestationReport *
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 9/22
#21 lore raw

Re: [PATCH v3 09/22] target/i386/sev: Mark unreachable code with g_assert_not_reached()

Quoted 27 lines · Philippe Mathieu-Daudé

The unique sev_encrypt_flash() invocation (in pc_system_flash_map) is protected by the "if (sev_enabled())" check, so is not reacheable.
Replace the abort() call in sev_es_save_reset_vector() by g_assert_not_reached() which meaning is clearer.

---
  target/i386/sev-stub.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/sev-stub.c +1 -1
index eb0c89bf2be..4668365fd3e 100644
@@ -54,7 +54,7 @@ int sev_inject_launch_secret(const char *hdr, const char *secret,
 
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
  {
-    return 0;
+    g_assert_not_reached();
  }
 
  bool sev_es_enabled(void)

target/i386/sev-stub.c void sev_es_set_reset_vector(CPUState *cpu) · line 74

Quoted 8 lines
target/i386/sev-stub.c +1 -1
@@ -68,7 +68,7 @@ void sev_es_set_reset_vector(CPUState *cpu)
 
  int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
  {
-    abort();
+    g_assert_not_reached();
  }
 
  SevAttestationReport *
#22 lore raw

PATCH v3 10/22 target/i386/sev: sev_get_attestation_report use g_autofree

In reply to Philippe Mathieu-Daudé

From: "Dr. David Alan Gilbert" <[email protected]>

Removes a whole bunch of g_free's and a goto.

Message-Id: <[email protected]>

---
 target/i386/sev.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
target/i386/sev.c +3 -8
index c88cd808410..aefbef4bb63 100644
@@ -493,8 +493,8 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
     struct kvm_sev_attestation_report input = {};
     SevAttestationReport *report = NULL;
     SevGuestState *sev = sev_guest;
-    guchar *data;
-    guchar *buf;
+    g_autofree guchar *data = NULL;
+    g_autofree guchar *buf = NULL;
     gsize len;
     int err = 0, ret;
 
@@ -514,7 +514,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
     if (len != sizeof(input.mnonce)) {
         error_setg(errp, "SEV: mnonce must be %zu bytes (got %" G_GSIZE_FORMAT ")",
                 sizeof(input.mnonce), len);
-        g_free(buf);
         return NULL;
     }
 
@@ -525,7 +524,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
         if (err != SEV_RET_INVALID_LEN) {
             error_setg(errp, "failed to query the attestation report length "
                     "ret=%d fw_err=%d (%s)", ret, err, fw_error_to_str(err));
-            g_free(buf);
             return NULL;
         }
     }
@@ -540,7 +538,7 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
     if (ret) {
         error_setg_errno(errp, errno, "Failed to get attestation report"
                 " ret=%d fw_err=%d (%s)", ret, err, fw_error_to_str(err));
-        goto e_free_data;
+        return NULL;
     }
 
     report = g_new0(SevAttestationReport, 1);
@@ -548,9 +546,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
 
     trace_kvm_sev_attestation_report(mnonce, report->data);
 
-e_free_data:
-    g_free(data);
-    g_free(buf);
     return report;
 }
 
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 10/22
#23 lore raw

Re: [PATCH v3 10/22] target/i386/sev: sev_get_attestation_report use g_autofree

Quoted 55 lines · Philippe Mathieu-Daudé

From: "Dr. David Alan Gilbert" <[email protected]>

Removes a whole bunch of g_free's and a goto.

Message-Id: <[email protected]>

---
  target/i386/sev.c | 11 +++--------
  1 file changed, 3 insertions(+), 8 deletions(-)
target/i386/sev.c +3 -5
index c88cd808410..aefbef4bb63 100644
@@ -493,8 +493,8 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
      struct kvm_sev_attestation_report input = {};
      SevAttestationReport *report = NULL;
      SevGuestState *sev = sev_guest;
-    guchar *data;
-    guchar *buf;
+    g_autofree guchar *data = NULL;
+    g_autofree guchar *buf = NULL;
      gsize len;
      int err = 0, ret;
 
@@ -514,7 +514,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
      if (len != sizeof(input.mnonce)) {
          error_setg(errp, "SEV: mnonce must be %zu bytes (got %" G_GSIZE_FORMAT ")",
                  sizeof(input.mnonce), len);
-        g_free(buf);
          return NULL;
      }
 
@@ -525,7 +524,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
          if (err != SEV_RET_INVALID_LEN) {
              error_setg(errp, "failed to query the attestation report length "
                      "ret=%d fw_err=%d (%s)", ret, err, fw_error_to_str(err));
-            g_free(buf);
              return NULL;
          }
      }
@@ -540,7 +538,7 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
      if (ret) {
          error_setg_errno(errp, errno, "Failed to get attestation report"
                  " ret=%d fw_err=%d (%s)", ret, err, fw_error_to_str(err));
-        goto e_free_data;
+        return NULL;
      }
 
      report = g_new0(SevAttestationReport, 1);

target/i386/sev.c sev_get_attestation_report(const char *mnonce, Error **errp) · line 551

Quoted 9 lines
target/i386/sev.c +0 -3
@@ -548,9 +546,6 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
 
      trace_kvm_sev_attestation_report(mnonce, report->data);
 
-e_free_data:
-    g_free(data);
-    g_free(buf);
      return report;
  }
 
#24 lore raw

PATCH v3 11/22 target/i386/sev: Restrict SEV to system emulation

In reply to Philippe Mathieu-Daudé

SEV is irrelevant on user emulation, so restrict it to sysemu. Some stubs are still required because used in cpu.c by x86_register_cpudef_types(), so move the sysemu specific stubs to sev-sysemu-stub.c instead. This will allow us to simplify monitor.c (which is not available in user emulation) in the next commit.

---
 target/i386/sev-stub.c        | 43 -------------------------
 target/i386/sev-sysemu-stub.c | 60 +++++++++++++++++++++++++++++++++++
 target/i386/meson.build       |  4 ++-
 3 files changed, 63 insertions(+), 44 deletions(-)
 create mode 100644 target/i386/sev-sysemu-stub.c
target/i386/sev-stub.c +0 -43
index 4668365fd3e..8eae5d2fa8d 100644
@@ -15,11 +15,6 @@
 #include "qapi/error.h"
 #include "sev_i386.h"
 
-SevInfo *sev_get_info(void)
-{
-    return NULL;
-}
-
 bool sev_enabled(void)
 {
     return false;
@@ -35,45 +30,7 @@ uint32_t sev_get_reduced_phys_bits(void)
     return 0;
 }
 
-char *sev_get_launch_measurement(void)
-{
-    return NULL;
-}
-
-SevCapability *sev_get_capabilities(Error **errp)
-{
-    error_setg(errp, "SEV is not available in this QEMU");
-    return NULL;
-}
-
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp)
-{
-    return 1;
-}
-
-int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
-{
-    g_assert_not_reached();
-}
-
 bool sev_es_enabled(void)
 {
     return false;
 }
-
-void sev_es_set_reset_vector(CPUState *cpu)
-{
-}
-
-int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
-{
-    g_assert_not_reached();
-}
-
-SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp)
-{
-    error_setg(errp, "SEV is not available in this QEMU");
-    return NULL;
-}
target/i386/sev-sysemu-stub.c new file +60 -0

60 lines not on this page · raw message

target/i386/meson.build +3 -1
index dac19ec00d4..a4f45c3ec1d 100644
@@ -6,7 +6,7 @@
   'xsave_helper.c',
   'cpu-dump.c',
 ))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c', 'sev.c'), if_false: files('sev-stub.c'))
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false: files('sev-stub.c'))
 
 # x86 cpu type
 i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))
@@ -20,6 +20,8 @@
   'monitor.c',
   'cpu-sysemu.c',
 ))
+i386_softmmu_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-sysemu-stub.c'))
+
 i386_user_ss = ss.source_set()
 
 subdir('kvm')
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 11/22
#25 lore raw

Re: [PATCH v3 11/22] target/i386/sev: Restrict SEV to system emulation

Quoted 158 lines · Philippe Mathieu-Daudé

SEV is irrelevant on user emulation, so restrict it to sysemu. Some stubs are still required because used in cpu.c by x86_register_cpudef_types(), so move the sysemu specific stubs to sev-sysemu-stub.c instead. This will allow us to simplify monitor.c (which is not available in user emulation) in the next commit.

---
  target/i386/sev-stub.c        | 43 -------------------------
  target/i386/sev-sysemu-stub.c | 60 +++++++++++++++++++++++++++++++++++
  target/i386/meson.build       |  4 ++-
  3 files changed, 63 insertions(+), 44 deletions(-)

create mode 100644 target/i386/sev-sysemu-stub.c

target/i386/sev-stub.c +0 -43
index 4668365fd3e..8eae5d2fa8d 100644
@@ -15,11 +15,6 @@
  #include "qapi/error.h"
  #include "sev_i386.h"
 
-SevInfo *sev_get_info(void)
-{
-    return NULL;
-}
-
  bool sev_enabled(void)
  {
      return false;
@@ -35,45 +30,7 @@ uint32_t sev_get_reduced_phys_bits(void)
      return 0;
  }
 
-char *sev_get_launch_measurement(void)
-{
-    return NULL;
-}
-
-SevCapability *sev_get_capabilities(Error **errp)
-{
-    error_setg(errp, "SEV is not available in this QEMU");
-    return NULL;
-}
-
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp)
-{
-    return 1;
-}
-
-int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
-{
-    g_assert_not_reached();
-}
-
  bool sev_es_enabled(void)
  {
      return false;
  }
-
-void sev_es_set_reset_vector(CPUState *cpu)
-{
-}
-
-int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
-{
-    g_assert_not_reached();
-}
-
-SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp)
-{
-    error_setg(errp, "SEV is not available in this QEMU");
-    return NULL;
-}
target/i386/sev-sysemu-stub.c new file +60 -0
new file mode 100644
index 00000000000..d556b4f091f
@@ -0,0 +1,60 @@
+/*
+ * QEMU SEV system stub
+ *
+ * Copyright Advanced Micro Devices 2018
+ *
+ * Authors:
+ *      Brijesh Singh <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/error.h"
+#include "sev_i386.h"
+
+SevInfo *sev_get_info(void)
+{
+    return NULL;
+}
+
+char *sev_get_launch_measurement(void)
+{
+    return NULL;
+}
+
+SevCapability *sev_get_capabilities(Error **errp)
+{
+    error_setg(errp, "SEV is not available in this QEMU");
+    return NULL;
+}
+
+int sev_inject_launch_secret(const char *hdr, const char *secret,
+                             uint64_t gpa, Error **errp)
+{
+    return 1;
+}
+
+int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
+{
+    g_assert_not_reached();
+}
+
+void sev_es_set_reset_vector(CPUState *cpu)
+{
+}
+
+int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
+{
+    g_assert_not_reached();
+}
+
+SevAttestationReport *sev_get_attestation_report(const char *mnonce,
+                                                 Error **errp)
+{
+    error_setg(errp, "SEV is not available in this QEMU");
+    return NULL;
+}
target/i386/meson.build +1 -1
index dac19ec00d4..a4f45c3ec1d 100644
@@ -6,7 +6,7 @@
    'xsave_helper.c',
    'cpu-dump.c',
  ))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c', 'sev.c'), if_false: files('sev-stub.c'))
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false: files('sev-stub.c'))
 
  # x86 cpu type
  i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))

target/i386/meson.build line 27

Quoted 8 lines
target/i386/meson.build +2 -0
@@ -20,6 +20,8 @@
    'monitor.c',
    'cpu-sysemu.c',
  ))
+i386_softmmu_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-sysemu-stub.c'))
+
  i386_user_ss = ss.source_set()
 
  subdir('kvm')
#26 lore raw

PATCH v3 12/22 target/i386/sev: Declare system-specific functions in 'sev_i386.h'

In reply to Philippe Mathieu-Daudé

While prefixed with sysemu, 'sysemu/sev.h' contains the architecture specific declarations. The system specific parts are declared in 'sev_i386.h'.

---
 include/sysemu/sev.h   | 6 ------
 target/i386/sev_i386.h | 7 +++++++
 hw/i386/pc_sysfw.c     | 2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)
include/sysemu/sev.h +0 -6
index 94d821d737c..a329ed75c1c 100644
@@ -18,11 +18,5 @@
 
 bool sev_enabled(void);
 int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
-int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp);
-
-int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
-void sev_es_set_reset_vector(CPUState *cpu);
 
 #endif
target/i386/sev_i386.h +7 -0
index afa19a0a161..0798ab3519a 100644
@@ -33,4 +33,11 @@ extern SevCapability *sev_get_capabilities(Error **errp);
 extern SevAttestationReport *
 sev_get_attestation_report(const char *mnonce, Error **errp);
 
+int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
+int sev_inject_launch_secret(const char *hdr, const char *secret,
+                             uint64_t gpa, Error **errp);
+
+int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
+void sev_es_set_reset_vector(CPUState *cpu);
+
 #endif
hw/i386/pc_sysfw.c +1 -1
index 68d6b1f783e..0b202138b66 100644
@@ -37,7 +37,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/block/flash.h"
 #include "sysemu/kvm.h"
-#include "sysemu/sev.h"
+#include "sev_i386.h"
 
 #define FLASH_SECTOR_SIZE 4096
 
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 12/22
#27 lore raw

Re: [PATCH v3 12/22] target/i386/sev: Declare system-specific functions in 'sev_i386.h'

Quoted 3 lines · Philippe Mathieu-Daudé

While prefixed with sysemu, 'sysemu/sev.h' contains the architecture specific declarations. The system specific parts are declared in 'sev_i386.h'.

While outside target/i386, 'sysemu/sev.h' contains some architecture specific declarations. Move them to 'sev_i386.h'.

Otherwise,

Paolo

Quoted 53 lines
---
  include/sysemu/sev.h   | 6 ------
  target/i386/sev_i386.h | 7 +++++++
  hw/i386/pc_sysfw.c     | 2 +-
  3 files changed, 8 insertions(+), 7 deletions(-)
include/sysemu/sev.h +0 -6
index 94d821d737c..a329ed75c1c 100644
@@ -18,11 +18,5 @@
 
  bool sev_enabled(void);
  int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
-int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp);
-
-int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
-void sev_es_set_reset_vector(CPUState *cpu);
 
  #endif
target/i386/sev_i386.h +7 -0
index afa19a0a161..0798ab3519a 100644
@@ -33,4 +33,11 @@ extern SevCapability *sev_get_capabilities(Error **errp);
  extern SevAttestationReport *
  sev_get_attestation_report(const char *mnonce, Error **errp);
 
+int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
+int sev_inject_launch_secret(const char *hdr, const char *secret,
+                             uint64_t gpa, Error **errp);
+
+int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
+void sev_es_set_reset_vector(CPUState *cpu);
+
  #endif
hw/i386/pc_sysfw.c +1 -1
index 68d6b1f783e..0b202138b66 100644
@@ -37,7 +37,7 @@
  #include "hw/qdev-properties.h"
  #include "hw/block/flash.h"
  #include "sysemu/kvm.h"
-#include "sysemu/sev.h"
+#include "sev_i386.h"
 
  #define FLASH_SECTOR_SIZE 4096
 
#28 lore raw

PATCH v3 13/22 target/i386/sev: Remove stubs by using code elision

In reply to Philippe Mathieu-Daudé

Only declare sev_enabled() and sev_es_enabled() when CONFIG_SEV is set, to allow the compiler to elide unused code. Remove unnecessary stubs.

---
 include/sysemu/sev.h    | 14 +++++++++++++-
 target/i386/sev_i386.h  |  3 ---
 target/i386/cpu.c       | 16 +++++++++-------
 target/i386/sev-stub.c  | 36 ------------------------------------
 target/i386/meson.build |  2 +-
 5 files changed, 23 insertions(+), 48 deletions(-)
 delete mode 100644 target/i386/sev-stub.c
include/sysemu/sev.h +13 -1
index a329ed75c1c..f5c625bb3b3 100644
@@ -14,9 +14,21 @@
 #ifndef QEMU_SEV_H
 #define QEMU_SEV_H
 
-#include "sysemu/kvm.h"
+#ifndef CONFIG_USER_ONLY
+#include CONFIG_DEVICES /* CONFIG_SEV */
+#endif
 
+#ifdef CONFIG_SEV
 bool sev_enabled(void);
+bool sev_es_enabled(void);
+#else
+#define sev_enabled() 0
+#define sev_es_enabled() 0
+#endif
+
+uint32_t sev_get_cbit_position(void);
+uint32_t sev_get_reduced_phys_bits(void);
+
 int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
 
 #endif
target/i386/sev_i386.h +0 -3
index 0798ab3519a..2d9a1a0112e 100644
@@ -24,10 +24,7 @@
 #define SEV_POLICY_DOMAIN       0x10
 #define SEV_POLICY_SEV          0x20
 
-extern bool sev_es_enabled(void);
 extern SevInfo *sev_get_info(void);
-extern uint32_t sev_get_cbit_position(void);
-extern uint32_t sev_get_reduced_phys_bits(void);
 extern char *sev_get_launch_measurement(void);
 extern SevCapability *sev_get_capabilities(Error **errp);
 extern SevAttestationReport *
target/i386/cpu.c +9 -7
index e169a01713d..27992bdc9f8 100644
@@ -25,8 +25,8 @@
 #include "tcg/helper-tcg.h"
 #include "sysemu/reset.h"
 #include "sysemu/hvf.h"
+#include "sysemu/sev.h"
 #include "kvm/kvm_i386.h"
-#include "sev_i386.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-machine.h"
 #include "qapi/qmp/qerror.h"
@@ -38,6 +38,7 @@
 #include "exec/address-spaces.h"
 #include "hw/boards.h"
 #include "hw/i386/sgx-epc.h"
+#include "sev_i386.h"
 #endif
 
 #include "disas/capstone.h"
@@ -5764,12 +5765,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         *edx = 0;
         break;
     case 0x8000001F:
-        *eax = sev_enabled() ? 0x2 : 0;
-        *eax |= sev_es_enabled() ? 0x8 : 0;
-        *ebx = sev_get_cbit_position();
-        *ebx |= sev_get_reduced_phys_bits() << 6;
-        *ecx = 0;
-        *edx = 0;
+        *eax = *ebx = *ecx = *edx = 0;
+        if (sev_enabled()) {
+            *eax = 0x2;
+            *eax |= sev_es_enabled() ? 0x8 : 0;
+            *ebx = sev_get_cbit_position();
+            *ebx |= sev_get_reduced_phys_bits() << 6;
+        }
         break;
     default:
         /* reserved values: zero */
target/i386/sev-stub.c deleted +0 -36
deleted file mode 100644
index 8eae5d2fa8d..00000000000
@@ -1,36 +0,0 @@
-/*
- * QEMU SEV stub
- *
- * Copyright Advanced Micro Devices 2018
- *
- * Authors:
- *      Brijesh Singh <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include "qapi/error.h"
-#include "sev_i386.h"
-
-bool sev_enabled(void)
-{
-    return false;
-}
-
-uint32_t sev_get_cbit_position(void)
-{
-    return 0;
-}
-
-uint32_t sev_get_reduced_phys_bits(void)
-{
-    return 0;
-}
-
-bool sev_es_enabled(void)
-{
-    return false;
-}
target/i386/meson.build +1 -1
index a4f45c3ec1d..ae38dc95635 100644
@@ -6,7 +6,7 @@
   'xsave_helper.c',
   'cpu-dump.c',
 ))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false: files('sev-stub.c'))
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'))
 
 # x86 cpu type
 i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))
Signature · 1 line
2.31.1
maintainer
#29 lore raw

Re: [PATCH v3 13/22] target/i386/sev: Remove stubs by using code elision

Quoted 24 lines · Philippe Mathieu-Daudé

Only declare sev_enabled() and sev_es_enabled() when CONFIG_SEV is set, to allow the compiler to elide unused code. Remove unnecessary stubs.

---
  include/sysemu/sev.h    | 14 +++++++++++++-
  target/i386/sev_i386.h  |  3 ---
  target/i386/cpu.c       | 16 +++++++++-------
  target/i386/sev-stub.c  | 36 ------------------------------------
  target/i386/meson.build |  2 +-
  5 files changed, 23 insertions(+), 48 deletions(-)

delete mode 100644 target/i386/sev-stub.c

include/sysemu/sev.h +1 -1
index a329ed75c1c..f5c625bb3b3 100644
@@ -14,9 +14,21 @@
  #ifndef QEMU_SEV_H
  #define QEMU_SEV_H
 
-#include "sysemu/kvm.h"
+#ifndef CONFIG_USER_ONLY

include/sysemu/sev.h line 27

Quoted 10 lines
include/sysemu/sev.h +8 -0
+#include CONFIG_DEVICES /* CONFIG_SEV */
+#endif
 
+#ifdef CONFIG_SEV
  bool sev_enabled(void);
+bool sev_es_enabled(void);
+#else
+#define sev_enabled() 0
+#define sev_es_enabled() 0
+#endif

This means that sev.h can only be included from target-specific files.

An alternative could be:

#ifdef NEED_CPU_H

# include CONFIG_DEVICES
#endif

#if defined NEED_CPU_H && !defined CONFIG_SEV

# define sev_enabled() 0
# define sev_es_enabled() 0
#else
bool sev_enabled(void);
bool sev_es_enabled(void);
#endif

... but in fact sysemu/sev.h _is_ only used from x86-specific files. So should it be moved to include/hw/i386, and even merged with target/i386/sev_i386.h? Do we need two files?

Thanks,

Paolo

Quoted 119 lines
include/sysemu/sev.h +3 -0
+uint32_t sev_get_cbit_position(void);
+uint32_t sev_get_reduced_phys_bits(void);
+
  int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
 
  #endif
target/i386/sev_i386.h +0 -3
index 0798ab3519a..2d9a1a0112e 100644
@@ -24,10 +24,7 @@
  #define SEV_POLICY_DOMAIN       0x10
  #define SEV_POLICY_SEV          0x20
 
-extern bool sev_es_enabled(void);
  extern SevInfo *sev_get_info(void);
-extern uint32_t sev_get_cbit_position(void);
-extern uint32_t sev_get_reduced_phys_bits(void);
  extern char *sev_get_launch_measurement(void);
  extern SevCapability *sev_get_capabilities(Error **errp);
  extern SevAttestationReport *
target/i386/cpu.c +9 -7
index e169a01713d..27992bdc9f8 100644
@@ -25,8 +25,8 @@
  #include "tcg/helper-tcg.h"
  #include "sysemu/reset.h"
  #include "sysemu/hvf.h"
+#include "sysemu/sev.h"
  #include "kvm/kvm_i386.h"
-#include "sev_i386.h"
  #include "qapi/error.h"
  #include "qapi/qapi-visit-machine.h"
  #include "qapi/qmp/qerror.h"
@@ -38,6 +38,7 @@
  #include "exec/address-spaces.h"
  #include "hw/boards.h"
  #include "hw/i386/sgx-epc.h"
+#include "sev_i386.h"
  #endif
 
  #include "disas/capstone.h"
@@ -5764,12 +5765,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
          *edx = 0;
          break;
      case 0x8000001F:
-        *eax = sev_enabled() ? 0x2 : 0;
-        *eax |= sev_es_enabled() ? 0x8 : 0;
-        *ebx = sev_get_cbit_position();
-        *ebx |= sev_get_reduced_phys_bits() << 6;
-        *ecx = 0;
-        *edx = 0;
+        *eax = *ebx = *ecx = *edx = 0;
+        if (sev_enabled()) {
+            *eax = 0x2;
+            *eax |= sev_es_enabled() ? 0x8 : 0;
+            *ebx = sev_get_cbit_position();
+            *ebx |= sev_get_reduced_phys_bits() << 6;
+        }
          break;
      default:
          /* reserved values: zero */
target/i386/sev-stub.c deleted +0 -36
deleted file mode 100644
index 8eae5d2fa8d..00000000000
@@ -1,36 +0,0 @@
-/*
- * QEMU SEV stub
- *
- * Copyright Advanced Micro Devices 2018
- *
- * Authors:
- *      Brijesh Singh <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include "qapi/error.h"
-#include "sev_i386.h"
-
-bool sev_enabled(void)
-{
-    return false;
-}
-
-uint32_t sev_get_cbit_position(void)
-{
-    return 0;
-}
-
-uint32_t sev_get_reduced_phys_bits(void)
-{
-    return 0;
-}
-
-bool sev_es_enabled(void)
-{
-    return false;
-}
target/i386/meson.build +1 -1
index a4f45c3ec1d..ae38dc95635 100644
@@ -6,7 +6,7 @@
    'xsave_helper.c',
    'cpu-dump.c',
  ))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false: files('sev-stub.c'))
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'))
 
  # x86 cpu type
  i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))
#30 lore raw

Re: [PATCH v3 13/22] target/i386/sev: Remove stubs by using code elision

Quoted 36 lines · Paolo Bonzini
Quoted 27 lines · Philippe Mathieu-Daudé

Only declare sev_enabled() and sev_es_enabled() when CONFIG_SEV is set, to allow the compiler to elide unused code. Remove unnecessary stubs.

---
  include/sysemu/sev.h    | 14 +++++++++++++- target/i386/sev_i386.h  |  3 ---
  target/i386/cpu.c       | 16 +++++++++------- target/i386/sev-stub.c  | 36 ------------------------------------ target/i386/meson.build |  2 +-

  5 files changed, 23 insertions(+), 48 deletions(-)

  delete mode 100644 target/i386/sev-stub.c

include/sysemu/sev.h +0 -0
index a329ed75c1c..f5c625bb3b3 100644
@@ -14,9 +14,21 @@
   #ifndef QEMU_SEV_H
   #define QEMU_SEV_H

  -#include "sysemu/kvm.h"

include/sysemu/sev.h +3 -0
+#ifndef CONFIG_USER_ONLY
+#include CONFIG_DEVICES /* CONFIG_SEV */
+#endif

  +#ifdef CONFIG_SEV
  bool sev_enabled(void);

include/sysemu/sev.h line 27

Quoted 5 lines
include/sysemu/sev.h +5 -0
+bool sev_es_enabled(void);
+#else
+#define sev_enabled() 0
+#define sev_es_enabled() 0
+#endif

This means that sev.h can only be included from target-specific files.

Quoted 4 lines

An alternative could be:

#ifdef NEED_CPU_H

# include CONFIG_DEVICES

<command-line>: fatal error: x86_64-linux-user-config-devices.h: No such file or directory

Quoted 10 lines

#endif

#if defined NEED_CPU_H && !defined CONFIG_SEV

# define sev_enabled() 0
# define sev_es_enabled() 0
#else
bool sev_enabled(void);
bool sev_es_enabled(void);
#endif
Quoted 3 lines

... but in fact sysemu/sev.h _is_ only used from x86-specific files. So should it be moved to include/hw/i386, and even merged with target/i386/sev_i386.h?  Do we need two files?

No clue, I don't think we need. Brijesh?

Quoted 64 lines

Thanks,

Paolo

Quoted 59 lines
include/sysemu/sev.h +3 -0
+uint32_t sev_get_cbit_position(void);
+uint32_t sev_get_reduced_phys_bits(void);
+

  int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); #endif

target/i386/sev_i386.h +0 -2
index 0798ab3519a..2d9a1a0112e 100644
@@ -24,10 +24,7 @@
   #define SEV_POLICY_DOMAIN       0x10
   #define SEV_POLICY_SEV          0x20
   -extern bool sev_es_enabled(void);
   extern SevInfo *sev_get_info(void);
-extern uint32_t sev_get_cbit_position(void);
-extern uint32_t sev_get_reduced_phys_bits(void);
   extern char *sev_get_launch_measurement(void);
   extern SevCapability *sev_get_capabilities(Error **errp);

  extern SevAttestationReport *

target/i386/cpu.c +2 -1
index e169a01713d..27992bdc9f8 100644
@@ -25,8 +25,8 @@
   #include "tcg/helper-tcg.h"
   #include "sysemu/reset.h"
   #include "sysemu/hvf.h"
+#include "sysemu/sev.h"
   #include "kvm/kvm_i386.h"
-#include "sev_i386.h"
   #include "qapi/error.h"
   #include "qapi/qapi-visit-machine.h"
   #include "qapi/qmp/qerror.h"
@@ -38,6 +38,7 @@
   #include "exec/address-spaces.h"
   #include "hw/boards.h"
   #include "hw/i386/sgx-epc.h"
+#include "sev_i386.h"
   #endif
     #include "disas/capstone.h"
@@ -5764,12 +5765,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t
 index, uint32_t count,
           *edx = 0;
           break;

      case 0x8000001F:
-        *eax = sev_enabled() ? 0x2 : 0;
-        *eax |= sev_es_enabled() ? 0x8 : 0; -        *ebx = sev_get_cbit_position();
-        *ebx |= sev_get_reduced_phys_bits() << 6; -        *ecx = 0;
-        *edx = 0;
+        *eax = *ebx = *ecx = *edx = 0;
+        if (sev_enabled()) {
+            *eax = 0x2;
+            *eax |= sev_es_enabled() ? 0x8 : 0; +            *ebx = sev_get_cbit_position(); +            *ebx |= sev_get_reduced_phys_bits() << 6; +        }
          break;

#31 lore raw

Re: [PATCH v3 13/22] target/i386/sev: Remove stubs by using code elision

Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 35 lines · Paolo Bonzini
Quoted 27 lines · Philippe Mathieu-Daudé

Only declare sev_enabled() and sev_es_enabled() when CONFIG_SEV is set, to allow the compiler to elide unused code. Remove unnecessary stubs.

---
  include/sysemu/sev.h    | 14 +++++++++++++- target/i386/sev_i386.h  |  3 ---
  target/i386/cpu.c       | 16 +++++++++------- target/i386/sev-stub.c  | 36 ------------------------------------ target/i386/meson.build |  2 +-

  5 files changed, 23 insertions(+), 48 deletions(-)

  delete mode 100644 target/i386/sev-stub.c

include/sysemu/sev.h +0 -0
index a329ed75c1c..f5c625bb3b3 100644
@@ -14,9 +14,21 @@
   #ifndef QEMU_SEV_H
   #define QEMU_SEV_H

  -#include "sysemu/kvm.h"

include/sysemu/sev.h +3 -0
+#ifndef CONFIG_USER_ONLY
+#include CONFIG_DEVICES /* CONFIG_SEV */
+#endif

  +#ifdef CONFIG_SEV
  bool sev_enabled(void);

include/sysemu/sev.h line 27

Quoted 5 lines
include/sysemu/sev.h +5 -0
+bool sev_es_enabled(void);
+#else
+#define sev_enabled() 0
+#define sev_es_enabled() 0
+#endif

This means that sev.h can only be included from target-specific files.

Quoted 4 lines

An alternative could be:

#ifdef NEED_CPU_H

# include CONFIG_DEVICES

<command-line>: fatal error: x86_64-linux-user-config-devices.h: No such file or directory

Quoted 10 lines

#endif

#if defined NEED_CPU_H && !defined CONFIG_SEV

# define sev_enabled() 0
# define sev_es_enabled() 0
#else
bool sev_enabled(void);
bool sev_es_enabled(void);
#endif
Quoted 4 lines
Quoted 3 lines

... but in fact sysemu/sev.h _is_ only used from x86-specific files. So should it be moved to include/hw/i386, and even merged with target/i386/sev_i386.h?  Do we need two files?

No clue, I don't think we need. Brijesh?

Sorry for the late reply, we do not need two files and it can be easily merged.

thanks

#32 lore raw

PATCH v3 14/22 target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c

In reply to Philippe Mathieu-Daudé

Move qmp_query_sev_attestation_report() from monitor.c to sev.c and make sev_get_attestation_report() static. We don't need the stub anymore, remove it.

---
 target/i386/sev_i386.h        |  2 --
 target/i386/monitor.c         |  6 ------
 target/i386/sev-sysemu-stub.c |  7 ++++---
 target/i386/sev.c             | 12 ++++++++++--
 4 files changed, 14 insertions(+), 13 deletions(-)
target/i386/sev_i386.h +0 -2
index 2d9a1a0112e..5f367f78eb7 100644
@@ -27,8 +27,6 @@
 extern SevInfo *sev_get_info(void);
 extern char *sev_get_launch_measurement(void);
 extern SevCapability *sev_get_capabilities(Error **errp);
-extern SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp);
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -6
index a9f85acd473..c05d70252a2 100644
@@ -764,12 +764,6 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,
     sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
 }
 
-SevAttestationReport *
-qmp_query_sev_attestation_report(const char *mnonce, Error **errp)
-{
-    return sev_get_attestation_report(mnonce, errp);
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +4 -3
index d556b4f091f..813b9a6a03b 100644
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
 #include "qapi/error.h"
 #include "sev_i386.h"
 
@@ -52,9 +53,9 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
     g_assert_not_reached();
 }
 
-SevAttestationReport *sev_get_attestation_report(const char *mnonce,
-                                                 Error **errp)
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
 {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);
     return NULL;
 }
target/i386/sev.c +10 -2
index aefbef4bb63..91a217bbb85 100644
@@ -31,6 +31,8 @@
 #include "migration/blocker.h"
 #include "qom/object.h"
 #include "monitor/monitor.h"
+#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
 #include "exec/confidential-guest-support.h"
 #include "hw/i386/pc.h"
 
@@ -487,8 +489,8 @@ out:
     return cap;
 }
 
-SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp)
+static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
+                                                        Error **errp)
 {
     struct kvm_sev_attestation_report input = {};
     SevAttestationReport *report = NULL;
@@ -549,6 +551,12 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
     return report;
 }
 
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
+{
+    return sev_get_attestation_report(mnonce, errp);
+}
+
 static int
 sev_read_file_base64(const char *filename, guchar **data, gsize *len)
 {
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 14/22
#33 lore raw

Re: [PATCH v3 14/22] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c

Quoted 5 lines · Philippe Mathieu-Daudé

Move qmp_query_sev_attestation_report() from monitor.c to sev.c and make sev_get_attestation_report() static. We don't need the stub anymore, remove it.

This was done on purpose, but I have no objection to changing it this way. We might in fact remove the indirection for SGX as well, and/or even move the implementation of the monitor commands from target/i386 to hw/i386 (the monitor is sysemu-specific).

Thanks,

Paolo

Quoted 99 lines
  target/i386/sev_i386.h        |  2 --
  target/i386/monitor.c         |  6 ------
  target/i386/sev-sysemu-stub.c |  7 ++++---
  target/i386/sev.c             | 12 ++++++++++--
  4 files changed, 14 insertions(+), 13 deletions(-)
target/i386/sev_i386.h +0 -2
index 2d9a1a0112e..5f367f78eb7 100644
@@ -27,8 +27,6 @@
  extern SevInfo *sev_get_info(void);
  extern char *sev_get_launch_measurement(void);
  extern SevCapability *sev_get_capabilities(Error **errp);
-extern SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp);
 
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
  int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -6
index a9f85acd473..c05d70252a2 100644
@@ -764,12 +764,6 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,
      sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
  }
 
-SevAttestationReport *
-qmp_query_sev_attestation_report(const char *mnonce, Error **errp)
-{
-    return sev_get_attestation_report(mnonce, errp);
-}
-
  SGXInfo *qmp_query_sgx(Error **errp)
  {
      return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +4 -3
index d556b4f091f..813b9a6a03b 100644
@@ -13,6 +13,7 @@
 
  #include "qemu/osdep.h"
  #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
  #include "qapi/error.h"
  #include "sev_i386.h"
 
@@ -52,9 +53,9 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
      g_assert_not_reached();
  }
 
-SevAttestationReport *sev_get_attestation_report(const char *mnonce,
-                                                 Error **errp)
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
  {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);
      return NULL;
  }
target/i386/sev.c +10 -2
index aefbef4bb63..91a217bbb85 100644
@@ -31,6 +31,8 @@
  #include "migration/blocker.h"
  #include "qom/object.h"
  #include "monitor/monitor.h"
+#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
  #include "exec/confidential-guest-support.h"
  #include "hw/i386/pc.h"
 
@@ -487,8 +489,8 @@ out:
      return cap;
  }
 
-SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp)
+static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
+                                                        Error **errp)
  {
      struct kvm_sev_attestation_report input = {};
      SevAttestationReport *report = NULL;
@@ -549,6 +551,12 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
      return report;
  }
 
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
+{
+    return sev_get_attestation_report(mnonce, errp);
+}
+
  static int
  sev_read_file_base64(const char *filename, guchar **data, gsize *len)
  {
#34 lore raw

Re: [PATCH v3 14/22] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c

Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Philippe Mathieu-Daudé

Move qmp_query_sev_attestation_report() from monitor.c to sev.c and make sev_get_attestation_report() static. We don't need the stub anymore, remove it.

This was done on purpose, but I have no objection to changing it this way.  We might in fact remove the indirection for SGX as well, and/or even move the implementation of the monitor commands from target/i386 to hw/i386 (the monitor is sysemu-specific).

OK about SGX, but in another series, this one is already painful enough.

Not sure about moving monitor to hw/, some commands expose hw info (like info pic) but some others expose architectural features (like info sev).

Quoted 6 lines

Thanks,

Paolo

#35 lore raw

Re: [PATCH v3 14/22] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c

In reply to Philippe Mathieu-Daudé
Quoted 55 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Move qmp_query_sev_attestation_report() from monitor.c to sev.c and make sev_get_attestation_report() static. We don't need the stub anymore, remove it.

---
 target/i386/sev_i386.h        |  2 --
 target/i386/monitor.c         |  6 ------
 target/i386/sev-sysemu-stub.c |  7 ++++---
 target/i386/sev.c             | 12 ++++++++++--
 4 files changed, 14 insertions(+), 13 deletions(-)
target/i386/sev_i386.h +0 -2
index 2d9a1a0112e..5f367f78eb7 100644
@@ -27,8 +27,6 @@
 extern SevInfo *sev_get_info(void);
 extern char *sev_get_launch_measurement(void);
 extern SevCapability *sev_get_capabilities(Error **errp);
-extern SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp);
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -6
index a9f85acd473..c05d70252a2 100644
@@ -764,12 +764,6 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,
     sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
 }
 
-SevAttestationReport *
-qmp_query_sev_attestation_report(const char *mnonce, Error **errp)
-{
-    return sev_get_attestation_report(mnonce, errp);
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +1 -0
index d556b4f091f..813b9a6a03b 100644
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
 #include "qapi/error.h"
 #include "sev_i386.h"
 

target/i386/sev-sysemu-stub.c int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size) · line 59

Quoted 10 lines
target/i386/sev-sysemu-stub.c +3 -3
@@ -52,9 +53,9 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
     g_assert_not_reached();
 }
 
-SevAttestationReport *sev_get_attestation_report(const char *mnonce,
-                                                 Error **errp)
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
 {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);

I did like that message making it clear the reason it was unsupported was this build, rather than lack of host support or not enabling it.

Dave

Quoted 42 lines
target/i386/sev-sysemu-stub.c +0 -0
     return NULL;
 }
target/i386/sev.c +10 -2
index aefbef4bb63..91a217bbb85 100644
@@ -31,6 +31,8 @@
 #include "migration/blocker.h"
 #include "qom/object.h"
 #include "monitor/monitor.h"
+#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qmp/qerror.h"
 #include "exec/confidential-guest-support.h"
 #include "hw/i386/pc.h"
 
@@ -487,8 +489,8 @@ out:
     return cap;
 }
 
-SevAttestationReport *
-sev_get_attestation_report(const char *mnonce, Error **errp)
+static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
+                                                        Error **errp)
 {
     struct kvm_sev_attestation_report input = {};
     SevAttestationReport *report = NULL;
@@ -549,6 +551,12 @@ sev_get_attestation_report(const char *mnonce, Error **errp)
     return report;
 }
 
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
+{
+    return sev_get_attestation_report(mnonce, errp);
+}
+
 static int
 sev_read_file_base64(const char *filename, guchar **data, gsize *len)
 {
Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#36 lore raw

Re: [PATCH v3 14/22] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c

Quoted 13 lines · Dr. David Alan Gilbert
Quoted 11 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Move qmp_query_sev_attestation_report() from monitor.c to sev.c and make sev_get_attestation_report() static. We don't need the stub anymore, remove it.

---
 target/i386/sev_i386.h        |  2 --
 target/i386/monitor.c         |  6 ------
 target/i386/sev-sysemu-stub.c |  7 ++++---
 target/i386/sev.c             | 12 ++++++++++--
 4 files changed, 14 insertions(+), 13 deletions(-)
Quoted 10 lines

target/i386/sev-sysemu-stub.c int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size) · line 59

Quoted 7 lines
target/i386/sev-sysemu-stub.c +3 -3
-SevAttestationReport *sev_get_attestation_report(const char *mnonce,
-                                                 Error **errp)
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
+                                                       Error **errp)
 {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);

I did like that message making it clear the reason it was unsupported was this build, rather than lack of host support or not enabling it.

Yep, no reason to change it, besides, QERR_UNSUPPORTED is deprecated since 2015! (commit 4629ed1e989):

/*
* These macros will go away, please don't use in new code, and do not
* add new ones!
*/

I suppose this is a rebase mistake, thanks for catching it!

Phil.

#37 lore raw

PATCH v3 15/22 target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c

In reply to Philippe Mathieu-Daudé

Move qmp_sev_inject_launch_secret() from monitor.c to sev.c and make sev_inject_launch_secret() static. We don't need the stub anymore, remove it.

---
 target/i386/monitor.c         | 31 -------------------------------
 target/i386/sev-sysemu-stub.c |  6 +++---
 target/i386/sev.c             | 31 +++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 34 deletions(-)
target/i386/monitor.c +0 -31
index c05d70252a2..188203da6f2 100644
@@ -733,37 +733,6 @@ SevCapability *qmp_query_sev_capabilities(Error **errp)
     return sev_get_capabilities(errp);
 }
 
-#define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
-struct sev_secret_area {
-    uint32_t base;
-    uint32_t size;
-};
-
-void qmp_sev_inject_launch_secret(const char *packet_hdr,
-                                  const char *secret,
-                                  bool has_gpa, uint64_t gpa,
-                                  Error **errp)
-{
-    if (!sev_enabled()) {
-        error_setg(errp, QERR_UNSUPPORTED);
-        return;
-    }
-    if (!has_gpa) {
-        uint8_t *data;
-        struct sev_secret_area *area;
-
-        if (!pc_system_ovmf_table_find(SEV_SECRET_GUID, &data, NULL)) {
-            error_setg(errp, "SEV: no secret area found in OVMF,"
-                       " gpa must be specified.");
-            return;
-        }
-        area = (struct sev_secret_area *)data;
-        gpa = area->base;
-    }
-
-    sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +3 -3
index 813b9a6a03b..66b69540aa5 100644
@@ -33,10 +33,10 @@ SevCapability *sev_get_capabilities(Error **errp)
     return NULL;
 }
 
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp)
+void qmp_sev_inject_launch_secret(const char *packet_header, const char *secret,
+                                  bool has_gpa, uint64_t gpa, Error **errp)
 {
-    return 1;
+    error_setg(errp, QERR_UNSUPPORTED);
 }
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
target/i386/sev.c +31 -0
index 91a217bbb85..2198d550be2 100644
@@ -949,6 +949,37 @@ int sev_inject_launch_secret(const char *packet_hdr, const char *secret,
     return 0;
 }
 
+#define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
+struct sev_secret_area {
+    uint32_t base;
+    uint32_t size;
+};
+
+void qmp_sev_inject_launch_secret(const char *packet_hdr,
+                                  const char *secret,
+                                  bool has_gpa, uint64_t gpa,
+                                  Error **errp)
+{
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
+    if (!has_gpa) {
+        uint8_t *data;
+        struct sev_secret_area *area;
+
+        if (!pc_system_ovmf_table_find(SEV_SECRET_GUID, &data, NULL)) {
+            error_setg(errp, "SEV: no secret area found in OVMF,"
+                       " gpa must be specified.");
+            return;
+        }
+        area = (struct sev_secret_area *)data;
+        gpa = area->base;
+    }
+
+    sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
+}
+
 static int
 sev_es_parse_reset_block(SevInfoBlock *info, uint32_t *addr)
 {
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 15/22
#38 lore raw

Re: [PATCH v3 15/22] target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c

Quoted 104 lines · Philippe Mathieu-Daudé

Move qmp_sev_inject_launch_secret() from monitor.c to sev.c and make sev_inject_launch_secret() static. We don't need the stub anymore, remove it.

---
  target/i386/monitor.c         | 31 -------------------------------
  target/i386/sev-sysemu-stub.c |  6 +++---
  target/i386/sev.c             | 31 +++++++++++++++++++++++++++++++
  3 files changed, 34 insertions(+), 34 deletions(-)
target/i386/monitor.c +0 -31
index c05d70252a2..188203da6f2 100644
@@ -733,37 +733,6 @@ SevCapability *qmp_query_sev_capabilities(Error **errp)
      return sev_get_capabilities(errp);
  }
 
-#define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
-struct sev_secret_area {
-    uint32_t base;
-    uint32_t size;
-};
-
-void qmp_sev_inject_launch_secret(const char *packet_hdr,
-                                  const char *secret,
-                                  bool has_gpa, uint64_t gpa,
-                                  Error **errp)
-{
-    if (!sev_enabled()) {
-        error_setg(errp, QERR_UNSUPPORTED);
-        return;
-    }
-    if (!has_gpa) {
-        uint8_t *data;
-        struct sev_secret_area *area;
-
-        if (!pc_system_ovmf_table_find(SEV_SECRET_GUID, &data, NULL)) {
-            error_setg(errp, "SEV: no secret area found in OVMF,"
-                       " gpa must be specified.");
-            return;
-        }
-        area = (struct sev_secret_area *)data;
-        gpa = area->base;
-    }
-
-    sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
-}
-
  SGXInfo *qmp_query_sgx(Error **errp)
  {
      return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +3 -3
index 813b9a6a03b..66b69540aa5 100644
@@ -33,10 +33,10 @@ SevCapability *sev_get_capabilities(Error **errp)
      return NULL;
  }
 
-int sev_inject_launch_secret(const char *hdr, const char *secret,
-                             uint64_t gpa, Error **errp)
+void qmp_sev_inject_launch_secret(const char *packet_header, const char *secret,
+                                  bool has_gpa, uint64_t gpa, Error **errp)
  {
-    return 1;
+    error_setg(errp, QERR_UNSUPPORTED);
  }
 
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp)
target/i386/sev.c +24 -0
index 91a217bbb85..2198d550be2 100644
@@ -949,6 +949,37 @@ int sev_inject_launch_secret(const char *packet_hdr, const char *secret,
      return 0;
  }
 
+#define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
+struct sev_secret_area {
+    uint32_t base;
+    uint32_t size;
+};
+
+void qmp_sev_inject_launch_secret(const char *packet_hdr,
+                                  const char *secret,
+                                  bool has_gpa, uint64_t gpa,
+                                  Error **errp)
+{
+    if (!sev_enabled()) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return;
+    }
+    if (!has_gpa) {
+        uint8_t *data;
+        struct sev_secret_area *area;
+
+        if (!pc_system_ovmf_table_find(SEV_SECRET_GUID, &data, NULL)) {
+            error_setg(errp, "SEV: no secret area found in OVMF,"
+                       " gpa must be specified.");
+            return;
+        }

target/i386/sev.c int sev_inject_launch_secret(const char *packet_hdr, const char *secret, · line 985

Quoted 10 lines
target/i386/sev.c +7 -0
+        area = (struct sev_secret_area *)data;
+        gpa = area->base;
+    }
+
+    sev_inject_launch_secret(packet_hdr, secret, gpa, errp);
+}
+
  static int
  sev_es_parse_reset_block(SevInfoBlock *info, uint32_t *addr)
  {

Ok, this indirectly addresses my comment on patch 5.

#39 lore raw

PATCH v3 16/22 target/i386/sev: Move qmp_query_sev_capabilities() to sev.c

In reply to Philippe Mathieu-Daudé

Move qmp_query_sev_capabilities() from monitor.c to sev.c and make sev_get_capabilities() static. We don't need the stub anymore, remove it.

---
 target/i386/sev_i386.h        | 1 -
 target/i386/monitor.c         | 5 -----
 target/i386/sev-sysemu-stub.c | 4 ++--
 target/i386/sev.c             | 8 ++++++--
 4 files changed, 8 insertions(+), 10 deletions(-)
target/i386/sev_i386.h +0 -1
index 5f367f78eb7..8d9388d8c5c 100644
@@ -26,7 +26,6 @@
 
 extern SevInfo *sev_get_info(void);
 extern char *sev_get_launch_measurement(void);
-extern SevCapability *sev_get_capabilities(Error **errp);
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -5
index 188203da6f2..da36522fa15 100644
@@ -728,11 +728,6 @@ SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
     return info;
 }
 
-SevCapability *qmp_query_sev_capabilities(Error **errp)
-{
-    return sev_get_capabilities(errp);
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +2 -2
index 66b69540aa5..cc486a1afbe 100644
@@ -27,9 +27,9 @@ char *sev_get_launch_measurement(void)
     return NULL;
 }
 
-SevCapability *sev_get_capabilities(Error **errp)
+SevCapability *qmp_query_sev_capabilities(Error **errp)
 {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);
     return NULL;
 }
 
target/i386/sev.c +6 -2
index 2198d550be2..fce007d6749 100644
@@ -438,8 +438,7 @@ e_free:
     return 1;
 }
 
-SevCapability *
-sev_get_capabilities(Error **errp)
+static SevCapability *sev_get_capabilities(Error **errp)
 {
     SevCapability *cap = NULL;
     guchar *pdh_data = NULL;
@@ -489,6 +488,11 @@ out:
     return cap;
 }
 
+SevCapability *qmp_query_sev_capabilities(Error **errp)
+{
+    return sev_get_capabilities(errp);
+}
+
 static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
                                                         Error **errp)
 {
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 16/22
#40 lore raw

Re: [PATCH v3 16/22] target/i386/sev: Move qmp_query_sev_capabilities() to sev.c

Quoted 73 lines · Philippe Mathieu-Daudé

Move qmp_query_sev_capabilities() from monitor.c to sev.c and make sev_get_capabilities() static. We don't need the stub anymore, remove it.

---
  target/i386/sev_i386.h        | 1 -
  target/i386/monitor.c         | 5 -----
  target/i386/sev-sysemu-stub.c | 4 ++--
  target/i386/sev.c             | 8 ++++++--
  4 files changed, 8 insertions(+), 10 deletions(-)
target/i386/sev_i386.h +0 -1
index 5f367f78eb7..8d9388d8c5c 100644
@@ -26,7 +26,6 @@
 
  extern SevInfo *sev_get_info(void);
  extern char *sev_get_launch_measurement(void);
-extern SevCapability *sev_get_capabilities(Error **errp);
 
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
  int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -5
index 188203da6f2..da36522fa15 100644
@@ -728,11 +728,6 @@ SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
      return info;
  }
 
-SevCapability *qmp_query_sev_capabilities(Error **errp)
-{
-    return sev_get_capabilities(errp);
-}
-
  SGXInfo *qmp_query_sgx(Error **errp)
  {
      return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +2 -2
index 66b69540aa5..cc486a1afbe 100644
@@ -27,9 +27,9 @@ char *sev_get_launch_measurement(void)
      return NULL;
  }
 
-SevCapability *sev_get_capabilities(Error **errp)
+SevCapability *qmp_query_sev_capabilities(Error **errp)
  {
-    error_setg(errp, "SEV is not available in this QEMU");
+    error_setg(errp, QERR_UNSUPPORTED);
      return NULL;
  }
 
target/i386/sev.c +1 -2
index 2198d550be2..fce007d6749 100644
@@ -438,8 +438,7 @@ e_free:
      return 1;
  }
 
-SevCapability *
-sev_get_capabilities(Error **errp)
+static SevCapability *sev_get_capabilities(Error **errp)
  {
      SevCapability *cap = NULL;
      guchar *pdh_data = NULL;
@@ -489,6 +488,11 @@ out:
      return cap;

target/i386/sev.c out: · line 498

Quoted 10 lines
target/i386/sev.c +5 -0
  }
 
+SevCapability *qmp_query_sev_capabilities(Error **errp)
+{
+    return sev_get_capabilities(errp);
+}
+
  static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
                                                          Error **errp)
  {
#41 lore raw

PATCH v3 17/22 target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c

In reply to Philippe Mathieu-Daudé

Move qmp_query_sev_launch_measure() from monitor.c to sev.c and make sev_get_launch_measurement() static. We don't need the stub anymore, remove it.

---
 target/i386/sev_i386.h        |  1 -
 target/i386/monitor.c         | 17 -----------------
 target/i386/sev-sysemu-stub.c |  3 ++-
 target/i386/sev.c             | 20 ++++++++++++++++++--
 4 files changed, 20 insertions(+), 21 deletions(-)
target/i386/sev_i386.h +0 -1
index 8d9388d8c5c..1699376ad87 100644
@@ -25,7 +25,6 @@
 #define SEV_POLICY_SEV          0x20
 
 extern SevInfo *sev_get_info(void);
-extern char *sev_get_launch_measurement(void);
 
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -17
index da36522fa15..0b38e970c73 100644
@@ -711,23 +711,6 @@ void hmp_info_sev(Monitor *mon, const QDict *qdict)
     qapi_free_SevInfo(info);
 }
 
-SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
-{
-    char *data;
-    SevLaunchMeasureInfo *info;
-
-    data = sev_get_launch_measurement();
-    if (!data) {
-        error_setg(errp, "Measurement is not available");
-        return NULL;
-    }
-
-    info = g_malloc0(sizeof(*info));
-    info->data = data;
-
-    return info;
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +2 -1
index cc486a1afbe..355391c16c4 100644
@@ -22,8 +22,9 @@ SevInfo *sev_get_info(void)
     return NULL;
 }
 
-char *sev_get_launch_measurement(void)
+SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
 {
+    error_setg(errp, QERR_UNSUPPORTED);
     return NULL;
 }
 
target/i386/sev.c +18 -2
index fce007d6749..8e9cce62196 100644
@@ -718,8 +718,7 @@ free_measurement:
     g_free(measurement);
 }
 
-char *
-sev_get_launch_measurement(void)
+static char *sev_get_launch_measurement(void)
 {
     if (sev_guest &&
         sev_guest->state >= SEV_STATE_LAUNCH_SECRET) {
@@ -729,6 +728,23 @@ sev_get_launch_measurement(void)
     return NULL;
 }
 
+SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
+{
+    char *data;
+    SevLaunchMeasureInfo *info;
+
+    data = sev_get_launch_measurement();
+    if (!data) {
+        error_setg(errp, "Measurement is not available");
+        return NULL;
+    }
+
+    info = g_malloc0(sizeof(*info));
+    info->data = data;
+
+    return info;
+}
+
 static Notifier sev_machine_done_notify = {
     .notify = sev_launch_get_measure,
 };
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 17/22
#42 lore raw

Re: [PATCH v3 17/22] target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c

Quoted 96 lines · Philippe Mathieu-Daudé

Move qmp_query_sev_launch_measure() from monitor.c to sev.c and make sev_get_launch_measurement() static. We don't need the stub anymore, remove it.

---
  target/i386/sev_i386.h        |  1 -
  target/i386/monitor.c         | 17 -----------------
  target/i386/sev-sysemu-stub.c |  3 ++-
  target/i386/sev.c             | 20 ++++++++++++++++++--
  4 files changed, 20 insertions(+), 21 deletions(-)
target/i386/sev_i386.h +0 -1
index 8d9388d8c5c..1699376ad87 100644
@@ -25,7 +25,6 @@
  #define SEV_POLICY_SEV          0x20
 
  extern SevInfo *sev_get_info(void);
-extern char *sev_get_launch_measurement(void);
 
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
  int sev_inject_launch_secret(const char *hdr, const char *secret,
target/i386/monitor.c +0 -17
index da36522fa15..0b38e970c73 100644
@@ -711,23 +711,6 @@ void hmp_info_sev(Monitor *mon, const QDict *qdict)
      qapi_free_SevInfo(info);
  }
 
-SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
-{
-    char *data;
-    SevLaunchMeasureInfo *info;
-
-    data = sev_get_launch_measurement();
-    if (!data) {
-        error_setg(errp, "Measurement is not available");
-        return NULL;
-    }
-
-    info = g_malloc0(sizeof(*info));
-    info->data = data;
-
-    return info;
-}
-
  SGXInfo *qmp_query_sgx(Error **errp)
  {
      return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +2 -1
index cc486a1afbe..355391c16c4 100644
@@ -22,8 +22,9 @@ SevInfo *sev_get_info(void)
      return NULL;
  }
 
-char *sev_get_launch_measurement(void)
+SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
  {
+    error_setg(errp, QERR_UNSUPPORTED);
      return NULL;
  }
 
target/i386/sev.c +11 -2
index fce007d6749..8e9cce62196 100644
@@ -718,8 +718,7 @@ free_measurement:
      g_free(measurement);
  }
 
-char *
-sev_get_launch_measurement(void)
+static char *sev_get_launch_measurement(void)
  {
      if (sev_guest &&
          sev_guest->state >= SEV_STATE_LAUNCH_SECRET) {
@@ -729,6 +728,23 @@ sev_get_launch_measurement(void)
      return NULL;
  }
 
+SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
+{
+    char *data;
+    SevLaunchMeasureInfo *info;
+
+    data = sev_get_launch_measurement();
+    if (!data) {
+        error_setg(errp, "Measurement is not available");
+        return NULL;
+    }

target/i386/sev.c sev_get_launch_measurement(void) · line 750

Quoted 10 lines
target/i386/sev.c +7 -0
+
+    info = g_malloc0(sizeof(*info));
+    info->data = data;
+
+    return info;
+}
+
  static Notifier sev_machine_done_notify = {
      .notify = sev_launch_get_measure,
  };
#43 lore raw

PATCH v3 18/22 target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c

In reply to Philippe Mathieu-Daudé

Move qmp_query_sev() & hmp_info_sev()() from monitor.c to sev.c and make sev_get_info() static. We don't need the stub anymore, remove it. Add a stub for hmp_info_sev().

---
 target/i386/sev_i386.h        |  3 ---
 target/i386/monitor.c         | 38 +---------------------------------
 target/i386/sev-sysemu-stub.c | 10 ++++++++-
 target/i386/sev.c             | 39 +++++++++++++++++++++++++++++++++--
 4 files changed, 47 insertions(+), 43 deletions(-)
target/i386/sev_i386.h +0 -3
index 1699376ad87..15a959d6174 100644
@@ -15,7 +15,6 @@
 #define QEMU_SEV_I386_H
 
 #include "sysemu/sev.h"
-#include "qapi/qapi-types-misc-target.h"
 
 #define SEV_POLICY_NODBG        0x1
 #define SEV_POLICY_NOKS         0x2
@@ -24,8 +23,6 @@
 #define SEV_POLICY_DOMAIN       0x10
 #define SEV_POLICY_SEV          0x20
 
-extern SevInfo *sev_get_info(void);
-
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
                              uint64_t gpa, Error **errp);
target/i386/monitor.c +1 -37
index 0b38e970c73..890870b252d 100644
@@ -28,11 +28,9 @@
 #include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qerror.h"
+//#include "qapi/qmp/qerror.h"
 #include "sysemu/kvm.h"
-#include "sysemu/sev.h"
 #include "qapi/error.h"
-#include "sev_i386.h"
 #include "qapi/qapi-commands-misc-target.h"
 #include "qapi/qapi-commands-misc.h"
 #include "hw/i386/pc.h"
@@ -677,40 +675,6 @@ void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
                    "removed soon. Please use 'info pic' instead.\n");
 }
 
-SevInfo *qmp_query_sev(Error **errp)
-{
-    SevInfo *info;
-
-    info = sev_get_info();
-    if (!info) {
-        error_setg(errp, "SEV feature is not available");
-        return NULL;
-    }
-
-    return info;
-}
-
-void hmp_info_sev(Monitor *mon, const QDict *qdict)
-{
-    SevInfo *info = sev_get_info();
-
-    if (info && info->enabled) {
-        monitor_printf(mon, "handle: %d\n", info->handle);
-        monitor_printf(mon, "state: %s\n", SevState_str(info->state));
-        monitor_printf(mon, "build: %d\n", info->build_id);
-        monitor_printf(mon, "api version: %d.%d\n",
-                       info->api_major, info->api_minor);
-        monitor_printf(mon, "debug: %s\n",
-                       info->policy & SEV_POLICY_NODBG ? "off" : "on");
-        monitor_printf(mon, "key-sharing: %s\n",
-                       info->policy & SEV_POLICY_NOKS ? "off" : "on");
-    } else {
-        monitor_printf(mon, "SEV is not enabled\n");
-    }
-
-    qapi_free_SevInfo(info);
-}
-
 SGXInfo *qmp_query_sgx(Error **errp)
 {
     return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +9 -1
index 355391c16c4..1836b32e4fc 100644
@@ -12,13 +12,16 @@
  */
 
 #include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
 #include "qapi/qapi-commands-misc-target.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/error.h"
 #include "sev_i386.h"
 
-SevInfo *sev_get_info(void)
+SevInfo *qmp_query_sev(Error **errp)
 {
+    error_setg(errp, QERR_UNSUPPORTED);
     return NULL;
 }
 
@@ -60,3 +63,8 @@ SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
     error_setg(errp, QERR_UNSUPPORTED);
     return NULL;
 }
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SEV is not available in this QEMU\n");
+}
target/i386/sev.c +37 -2
index 8e9cce62196..7caaa117ff7 100644
@@ -27,10 +27,12 @@
 #include "sev_i386.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/runstate.h"
+#include "sysemu/sev.h"
 #include "trace.h"
 #include "migration/blocker.h"
 #include "qom/object.h"
 #include "monitor/monitor.h"
+#include "monitor/hmp.h"
 #include "qapi/qapi-commands-misc-target.h"
 #include "qapi/qmp/qerror.h"
 #include "exec/confidential-guest-support.h"
@@ -375,8 +377,7 @@ sev_get_reduced_phys_bits(void)
     return sev_guest ? sev_guest->reduced_phys_bits : 0;
 }
 
-SevInfo *
-sev_get_info(void)
+static SevInfo *sev_get_info(void)
 {
     SevInfo *info;
 
@@ -395,6 +396,40 @@ sev_get_info(void)
     return info;
 }
 
+SevInfo *qmp_query_sev(Error **errp)
+{
+    SevInfo *info;
+
+    info = sev_get_info();
+    if (!info) {
+        error_setg(errp, "SEV feature is not available");
+        return NULL;
+    }
+
+    return info;
+}
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    SevInfo *info = sev_get_info();
+
+    if (info && info->enabled) {
+        monitor_printf(mon, "handle: %d\n", info->handle);
+        monitor_printf(mon, "state: %s\n", SevState_str(info->state));
+        monitor_printf(mon, "build: %d\n", info->build_id);
+        monitor_printf(mon, "api version: %d.%d\n",
+                       info->api_major, info->api_minor);
+        monitor_printf(mon, "debug: %s\n",
+                       info->policy & SEV_POLICY_NODBG ? "off" : "on");
+        monitor_printf(mon, "key-sharing: %s\n",
+                       info->policy & SEV_POLICY_NOKS ? "off" : "on");
+    } else {
+        monitor_printf(mon, "SEV is not enabled\n");
+    }
+
+    qapi_free_SevInfo(info);
+}
+
 static int
 sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
                  size_t *cert_chain_len, Error **errp)
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 18/22
#44 lore raw

Re: [PATCH v3 18/22] target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c

Quoted 181 lines · Philippe Mathieu-Daudé

Move qmp_query_sev() & hmp_info_sev()() from monitor.c to sev.c and make sev_get_info() static. We don't need the stub anymore, remove it. Add a stub for hmp_info_sev().

---
  target/i386/sev_i386.h        |  3 ---
  target/i386/monitor.c         | 38 +---------------------------------
  target/i386/sev-sysemu-stub.c | 10 ++++++++-
  target/i386/sev.c             | 39 +++++++++++++++++++++++++++++++++--
  4 files changed, 47 insertions(+), 43 deletions(-)
target/i386/sev_i386.h +0 -3
index 1699376ad87..15a959d6174 100644
@@ -15,7 +15,6 @@
  #define QEMU_SEV_I386_H
 
  #include "sysemu/sev.h"
-#include "qapi/qapi-types-misc-target.h"
 
  #define SEV_POLICY_NODBG        0x1
  #define SEV_POLICY_NOKS         0x2
@@ -24,8 +23,6 @@
  #define SEV_POLICY_DOMAIN       0x10
  #define SEV_POLICY_SEV          0x20
 
-extern SevInfo *sev_get_info(void);
-
  int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
  int sev_inject_launch_secret(const char *hdr, const char *secret,
                               uint64_t gpa, Error **errp);
target/i386/monitor.c +1 -37
index 0b38e970c73..890870b252d 100644
@@ -28,11 +28,9 @@
  #include "monitor/hmp-target.h"
  #include "monitor/hmp.h"
  #include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qerror.h"
+//#include "qapi/qmp/qerror.h"
  #include "sysemu/kvm.h"
-#include "sysemu/sev.h"
  #include "qapi/error.h"
-#include "sev_i386.h"
  #include "qapi/qapi-commands-misc-target.h"
  #include "qapi/qapi-commands-misc.h"
  #include "hw/i386/pc.h"
@@ -677,40 +675,6 @@ void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
                     "removed soon. Please use 'info pic' instead.\n");
  }
 
-SevInfo *qmp_query_sev(Error **errp)
-{
-    SevInfo *info;
-
-    info = sev_get_info();
-    if (!info) {
-        error_setg(errp, "SEV feature is not available");
-        return NULL;
-    }
-
-    return info;
-}
-
-void hmp_info_sev(Monitor *mon, const QDict *qdict)
-{
-    SevInfo *info = sev_get_info();
-
-    if (info && info->enabled) {
-        monitor_printf(mon, "handle: %d\n", info->handle);
-        monitor_printf(mon, "state: %s\n", SevState_str(info->state));
-        monitor_printf(mon, "build: %d\n", info->build_id);
-        monitor_printf(mon, "api version: %d.%d\n",
-                       info->api_major, info->api_minor);
-        monitor_printf(mon, "debug: %s\n",
-                       info->policy & SEV_POLICY_NODBG ? "off" : "on");
-        monitor_printf(mon, "key-sharing: %s\n",
-                       info->policy & SEV_POLICY_NOKS ? "off" : "on");
-    } else {
-        monitor_printf(mon, "SEV is not enabled\n");
-    }
-
-    qapi_free_SevInfo(info);
-}
-
  SGXInfo *qmp_query_sgx(Error **errp)
  {
      return sgx_get_info(errp);
target/i386/sev-sysemu-stub.c +9 -1
index 355391c16c4..1836b32e4fc 100644
@@ -12,13 +12,16 @@
   */
 
  #include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
  #include "qapi/qapi-commands-misc-target.h"
  #include "qapi/qmp/qerror.h"
  #include "qapi/error.h"
  #include "sev_i386.h"
 
-SevInfo *sev_get_info(void)
+SevInfo *qmp_query_sev(Error **errp)
  {
+    error_setg(errp, QERR_UNSUPPORTED);
      return NULL;
  }
 
@@ -60,3 +63,8 @@ SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
      error_setg(errp, QERR_UNSUPPORTED);
      return NULL;
  }
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SEV is not available in this QEMU\n");
+}
target/i386/sev.c +30 -2
index 8e9cce62196..7caaa117ff7 100644
@@ -27,10 +27,12 @@
  #include "sev_i386.h"
  #include "sysemu/sysemu.h"
  #include "sysemu/runstate.h"
+#include "sysemu/sev.h"
  #include "trace.h"
  #include "migration/blocker.h"
  #include "qom/object.h"
  #include "monitor/monitor.h"
+#include "monitor/hmp.h"
  #include "qapi/qapi-commands-misc-target.h"
  #include "qapi/qmp/qerror.h"
  #include "exec/confidential-guest-support.h"
@@ -375,8 +377,7 @@ sev_get_reduced_phys_bits(void)
      return sev_guest ? sev_guest->reduced_phys_bits : 0;
  }
 
-SevInfo *
-sev_get_info(void)
+static SevInfo *sev_get_info(void)
  {
      SevInfo *info;
 
@@ -395,6 +396,40 @@ sev_get_info(void)
      return info;
  }
 
+SevInfo *qmp_query_sev(Error **errp)
+{
+    SevInfo *info;
+
+    info = sev_get_info();
+    if (!info) {
+        error_setg(errp, "SEV feature is not available");
+        return NULL;
+    }
+
+    return info;
+}
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    SevInfo *info = sev_get_info();
+
+    if (info && info->enabled) {
+        monitor_printf(mon, "handle: %d\n", info->handle);
+        monitor_printf(mon, "state: %s\n", SevState_str(info->state));
+        monitor_printf(mon, "build: %d\n", info->build_id);
+        monitor_printf(mon, "api version: %d.%d\n",
+                       info->api_major, info->api_minor);
+        monitor_printf(mon, "debug: %s\n",
+                       info->policy & SEV_POLICY_NODBG ? "off" : "on");
+        monitor_printf(mon, "key-sharing: %s\n",
+                       info->policy & SEV_POLICY_NOKS ? "off" : "on");

target/i386/sev.c sev_get_info(void) · line 435

Quoted 10 lines
target/i386/sev.c +7 -0
+    } else {
+        monitor_printf(mon, "SEV is not enabled\n");
+    }
+
+    qapi_free_SevInfo(info);
+}
+
  static int
  sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
                   size_t *cert_chain_len, Error **errp)
#45 lore raw

PATCH v3 19/22 monitor: Restrict 'info sev' to x86 targets

In reply to Philippe Mathieu-Daudé
---
 include/monitor/hmp-target.h  | 1 +
 include/monitor/hmp.h         | 1 -
 target/i386/sev-sysemu-stub.c | 2 +-
 target/i386/sev.c             | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)
include/monitor/hmp-target.h +1 -0
index dc53add7eef..96956d0fc41 100644
@@ -49,6 +49,7 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
 void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
+void hmp_info_sev(Monitor *mon, const QDict *qdict);
 void hmp_info_sgx(Monitor *mon, const QDict *qdict);
 
 #endif /* MONITOR_HMP_TARGET_H */
include/monitor/hmp.h +0 -1
index 3baa1058e2c..6bc27639e01 100644
@@ -124,7 +124,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict *qdict);
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);
-void hmp_info_sev(Monitor *mon, const QDict *qdict);
 void hmp_info_replay(Monitor *mon, const QDict *qdict);
 void hmp_replay_break(Monitor *mon, const QDict *qdict);
 void hmp_replay_delete_break(Monitor *mon, const QDict *qdict);
target/i386/sev-sysemu-stub.c +1 -1
index 1836b32e4fc..b2a4033a030 100644
@@ -13,7 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
 #include "qapi/qapi-commands-misc-target.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/error.h"
target/i386/sev.c +1 -1
index 7caaa117ff7..c6d8fc52eb2 100644
@@ -32,7 +32,7 @@
 #include "migration/blocker.h"
 #include "qom/object.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
 #include "qapi/qapi-commands-misc-target.h"
 #include "qapi/qmp/qerror.h"
 #include "exec/confidential-guest-support.h"
Signature · 1 line
2.31.1
maintainer Reviewed-by on v3 19/22
#46 lore raw

Re: [PATCH v3 19/22] monitor: Restrict 'info sev' to x86 targets

Quoted 51 lines · Philippe Mathieu-Daudé
---
  include/monitor/hmp-target.h  | 1 +
  include/monitor/hmp.h         | 1 -
  target/i386/sev-sysemu-stub.c | 2 +-
  target/i386/sev.c             | 2 +-
  4 files changed, 3 insertions(+), 3 deletions(-)
include/monitor/hmp-target.h +1 -0
index dc53add7eef..96956d0fc41 100644
@@ -49,6 +49,7 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict);
  void hmp_mce(Monitor *mon, const QDict *qdict);
  void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
  void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
+void hmp_info_sev(Monitor *mon, const QDict *qdict);
  void hmp_info_sgx(Monitor *mon, const QDict *qdict);
 
  #endif /* MONITOR_HMP_TARGET_H */
include/monitor/hmp.h +0 -1
index 3baa1058e2c..6bc27639e01 100644
@@ -124,7 +124,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict *qdict);
  void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
  void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
  void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);
-void hmp_info_sev(Monitor *mon, const QDict *qdict);
  void hmp_info_replay(Monitor *mon, const QDict *qdict);
  void hmp_replay_break(Monitor *mon, const QDict *qdict);
  void hmp_replay_delete_break(Monitor *mon, const QDict *qdict);
target/i386/sev-sysemu-stub.c +1 -1
index 1836b32e4fc..b2a4033a030 100644
@@ -13,7 +13,7 @@
 
  #include "qemu/osdep.h"
  #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
  #include "qapi/qapi-commands-misc-target.h"
  #include "qapi/qmp/qerror.h"
  #include "qapi/error.h"
target/i386/sev.c +0 -0
index 7caaa117ff7..c6d8fc52eb2 100644

target/i386/sev.c line 38

Quoted 8 lines
target/i386/sev.c +1 -1
@@ -32,7 +32,7 @@
  #include "migration/blocker.h"
  #include "qom/object.h"
  #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
  #include "qapi/qapi-commands-misc-target.h"
  #include "qapi/qmp/qerror.h"
  #include "exec/confidential-guest-support.h"

This is only a cleanup, isn't it? The #ifdef is already in hmp-commands-info.hx.

Anyway,

but please adjust the commit message in v4.

Paolo

#47 lore raw

Re: [PATCH v3 19/22] monitor: Restrict 'info sev' to x86 targets

Quoted 56 lines · Paolo Bonzini
Quoted 55 lines · Philippe Mathieu-Daudé

---
  include/monitor/hmp-target.h  | 1 +
  include/monitor/hmp.h         | 1 -
  target/i386/sev-sysemu-stub.c | 2 +-
  target/i386/sev.c             | 2 +-

  4 files changed, 3 insertions(+), 3 deletions(-)
include/monitor/hmp-target.h +1 -0
index dc53add7eef..96956d0fc41 100644
@@ -49,6 +49,7 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict);
   void hmp_mce(Monitor *mon, const QDict *qdict);
   void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
   void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
+void hmp_info_sev(Monitor *mon, const QDict *qdict);
   void hmp_info_sgx(Monitor *mon, const QDict *qdict);
     #endif /* MONITOR_HMP_TARGET_H */
include/monitor/hmp.h +0 -1
index 3baa1058e2c..6bc27639e01 100644
@@ -124,7 +124,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict
 *qdict);
   void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
   void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
   void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);
-void hmp_info_sev(Monitor *mon, const QDict *qdict);
   void hmp_info_replay(Monitor *mon, const QDict *qdict);
   void hmp_replay_break(Monitor *mon, const QDict *qdict);

  void hmp_replay_delete_break(Monitor *mon, const QDict *qdict);

target/i386/sev-sysemu-stub.c +1 -1
index 1836b32e4fc..b2a4033a030 100644
@@ -13,7 +13,7 @@
     #include "qemu/osdep.h"
   #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
   #include "qapi/qapi-commands-misc-target.h"
   #include "qapi/qmp/qerror.h"
   #include "qapi/error.h"
target/i386/sev.c +1 -1
index 7caaa117ff7..c6d8fc52eb2 100644
@@ -32,7 +32,7 @@
   #include "migration/blocker.h"
   #include "qom/object.h"
   #include "monitor/monitor.h"
-#include "monitor/hmp.h"
+#include "monitor/hmp-target.h"
Quoted 8 lines

target/i386/sev.c line 38

Quoted 4 lines
target/i386/sev.c +0 -0
   #include "qapi/qapi-commands-misc-target.h"
   #include "qapi/qmp/qerror.h"
   #include "exec/confidential-guest-support.h"

This is only a cleanup, isn't it?  The #ifdef is already in hmp-commands-info.hx.

IIUC the prototype is exposed to all targets, while with this patch, only to the files including "monitor/hmp-target.h".

You are right the command is only added for TARGET_I386 in hmp-commands-info.hx.

Quoted 6 lines

Anyway,

but please adjust the commit message in v4.

OK, thanks.

#48 lore raw

PATCH v3 20/22 sev/i386: Introduce sev_add_kernel_loader_hashes for measured linux boot

In reply to Philippe Mathieu-Daudé

From: Dov Murik <[email protected]>

Add the sev_add_kernel_loader_hashes function to calculate the hashes of the kernel/initrd/cmdline and fill a designated OVMF encrypted hash table area. For this to work, OVMF must support an encrypted area to place the data which is advertised via a special GUID in the OVMF reset table.

The hashes of each of the files is calculated (or the string in the case of the cmdline with trailing '\0' included). Each entry in the hashes table is GUID identified and since they're passed through the sev_encrypt_flash interface, the hashes will be accumulated by the AMD PSP measurement (SEV_LAUNCH_MEASURE).

Message-Id: <[email protected]>

[PMD: Rebased on top of 0021c4765a6]
---
 target/i386/sev_i386.h |  12 ++++
 target/i386/sev.c      | 138 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)
target/i386/sev_i386.h +12 -0
index 15a959d6174..17031cddd37 100644
@@ -23,9 +23,21 @@
 #define SEV_POLICY_DOMAIN       0x10
 #define SEV_POLICY_SEV          0x20
 
+typedef struct SevKernelLoaderContext {
+    char *setup_data;
+    size_t setup_size;
+    char *kernel_data;
+    size_t kernel_size;
+    char *initrd_data;
+    size_t initrd_size;
+    char *cmdline_data;
+    size_t cmdline_size;
+} SevKernelLoaderContext;
+
 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
 int sev_inject_launch_secret(const char *hdr, const char *secret,
                              uint64_t gpa, Error **errp);
+bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp);
 
 int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
 void sev_es_set_reset_vector(CPUState *cpu);
target/i386/sev.c +138 -0

156 lines not on this page · raw message

Signature · 1 line
2.31.1
#49 lore raw

PATCH v3 21/22 x86/sev: generate SEV kernel loader hashes in x86_load_linux

In reply to Philippe Mathieu-Daudé

From: Dov Murik <[email protected]>

If SEV is enabled and a kernel is passed via -kernel, pass the hashes of kernel/initrd/cmdline in an encrypted guest page to OVMF for SEV measured boot.

Message-Id: <[email protected]>

[PMD: Rebased on top of 0021c4765a6]
---
 hw/i386/x86.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
hw/i386/x86.c +24 -1
index 41ef9a84a9f..0c7c054e3a0 100644
@@ -47,6 +47,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/intc/i8259.h"
 #include "hw/rtc/mc146818rtc.h"
+#include "target/i386/sev_i386.h"
 
 #include "hw/acpi/cpu_hotplug.h"
 #include "hw/irq.h"
@@ -780,6 +781,7 @@ void x86_load_linux(X86MachineState *x86ms,
     const char *initrd_filename = machine->initrd_filename;
     const char *dtb_filename = machine->dtb;
     const char *kernel_cmdline = machine->kernel_cmdline;
+    SevKernelLoaderContext sev_load_ctx = {};
 
     /* Align to 16 bytes as a paranoia measure */
     cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
@@ -926,6 +928,8 @@ void x86_load_linux(X86MachineState *x86ms,
     fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1);
     fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
+    sev_load_ctx.cmdline_data = (char *)kernel_cmdline;
+    sev_load_ctx.cmdline_size = strlen(kernel_cmdline) + 1;
 
     if (protocol >= 0x202) {
         stl_p(header + 0x228, cmdline_addr);
@@ -1007,6 +1011,8 @@ void x86_load_linux(X86MachineState *x86ms,
         fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
         fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
         fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
+        sev_load_ctx.initrd_data = initrd_data;
+        sev_load_ctx.initrd_size = initrd_size;
 
         stl_p(header + 0x218, initrd_addr);
         stl_p(header + 0x21c, initrd_size);
@@ -1065,15 +1071,32 @@ void x86_load_linux(X86MachineState *x86ms,
         load_image_size(dtb_filename, setup_data->data, dtb_size);
     }
 
-    memcpy(setup, header, MIN(sizeof(header), setup_size));
+    /*
+     * If we're starting an encrypted VM, it will be OVMF based, which uses the
+     * efi stub for booting and doesn't require any values to be placed in the
+     * kernel header.  We therefore don't update the header so the hash of the
+     * kernel on the other side of the fw_cfg interface matches the hash of the
+     * file the user passed in.
+     */
+    if (!sev_enabled()) {
+        memcpy(setup, header, MIN(sizeof(header), setup_size));
+    }
 
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+    sev_load_ctx.kernel_data = (char *)kernel;
+    sev_load_ctx.kernel_size = kernel_size;
 
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
+    sev_load_ctx.setup_data = (char *)setup;
+    sev_load_ctx.setup_size = setup_size;
+
+    if (sev_enabled()) {
+        sev_add_kernel_loader_hashes(&sev_load_ctx, &error_fatal);
+    }
 
     option_rom[nb_option_roms].bootindex = 0;
     option_rom[nb_option_roms].name = "linuxboot.bin";
Signature · 1 line
2.31.1
#50 lore raw

PATCH v3 22/22 MAINTAINERS: Cover AMD SEV files

In reply to Philippe Mathieu-Daudé

Add an entry to list SEV-related files.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 50435b8d2f5..733a5201e76 100644
@@ -3038,6 +3038,13 @@ F: hw/core/clock-vmstate.c
 F: hw/core/qdev-clock.c
 F: docs/devel/clocks.rst
 
+AMD Secure Encrypted Virtualization (SEV)
+S: Orphan
+F: docs/amd-memory-encryption.txt
+F: target/i386/sev*
+F: target/i386/kvm/sev-stub.c
+F: include/sysemu/sev.h
+
 Usermode Emulation
 ------------------
 Overall usermode emulation
Signature · 1 line
2.31.1
maintainer
#51 lore raw

Re: [PATCH v3 22/22] MAINTAINERS: Cover AMD SEV files

Quoted 12 lines · Philippe Mathieu-Daudé

Add an entry to list SEV-related files.

---
  MAINTAINERS | 7 +++++++
  1 file changed, 7 insertions(+)
MAINTAINERS +0 -0
index 50435b8d2f5..733a5201e76 100644

MAINTAINERS F: hw/core/clock-vmstate.c · line 3046

Quoted 9 lines
MAINTAINERS +6 -0
@@ -3038,6 +3038,13 @@ F: hw/core/clock-vmstate.c
  F: hw/core/qdev-clock.c
  F: docs/devel/clocks.rst
 
+AMD Secure Encrypted Virtualization (SEV)
+S: Orphan
+F: docs/amd-memory-encryption.txt
+F: target/i386/sev*
+F: target/i386/kvm/sev-stub.c
+F: include/sysemu/sev.h

I don't think it qualifies as orphan; it's covered by x86 maintainers.

Paolo

#52 lore raw

Re: [PATCH v3 22/22] MAINTAINERS: Cover AMD SEV files

Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Philippe Mathieu-Daudé

Add an entry to list SEV-related files.

---
  MAINTAINERS | 7 +++++++

  1 file changed, 7 insertions(+)
Quoted 15 lines

MAINTAINERS F: hw/core/clock-vmstate.c · line 3046

Quoted 13 lines
MAINTAINERS +0 -0
index 50435b8d2f5..733a5201e76 100644
@@ -3038,6 +3038,13 @@ F: hw/core/clock-vmstate.c

  F: hw/core/qdev-clock.c
  F: docs/devel/clocks.rst
  +AMD Secure Encrypted Virtualization (SEV)

MAINTAINERS +5 -0
+S: Orphan
+F: docs/amd-memory-encryption.txt
+F: target/i386/sev*
+F: target/i386/kvm/sev-stub.c
+F: include/sysemu/sev.h

I don't think it qualifies as orphan; it's covered by x86 maintainers.

$ ./scripts/get_maintainer.pl -f docs/amd-memory-encryption.txt
get_maintainer.pl: No maintainers found, printing recent contributors.
get_maintainer.pl: Do not blindly cc: them on patches!  Use common sense.
Connor Kuehl <[email protected]> (commit_signer:2/3=67%)
Eduardo Habkost <[email protected]> (commit_signer:2/3=67%)
Tom Lendacky <[email protected]> (commit_signer:2/3=67%)
Laszlo Ersek <[email protected]> (commit_signer:2/3=67%)
Greg Kurz <[email protected]> (commit_signer:1/3=33%)
[email protected] (open list:All patches CC here)
$ ./scripts/get_maintainer.pl -f target/i386/sev.c
get_maintainer.pl: No maintainers found, printing recent contributors.
get_maintainer.pl: Do not blindly cc: them on patches!  Use common sense.
"Philippe Mathieu-Daudé" <[email protected]> (commit_signer:15/29=52%)
"Dr. David Alan Gilbert" <[email protected]> (commit_signer:7/29=24%)
Paolo Bonzini <[email protected]> (commit_signer:7/29=24%)
David Gibson <[email protected]> (commit_signer:7/29=24%)
Eduardo Habkost <[email protected]> (commit_signer:5/29=17%)
[email protected] (open list:All patches CC here)
$ ./scripts/get_maintainer.pl -f target/i386/sev.h
get_maintainer.pl: No maintainers found, printing recent contributors.
get_maintainer.pl: Do not blindly cc: them on patches!  Use common sense.
"Philippe Mathieu-Daudé" <[email protected]> (commit_signer:8/12=67%)
Paolo Bonzini <[email protected]> (commit_signer:4/12=33%)
James Bottomley <[email protected]> (commit_signer:3/12=25%)
"Dr. David Alan Gilbert" <[email protected]> (commit_signer:3/12=25%)
Connor Kuehl <[email protected]> (commit_signer:3/12=25%)
[email protected] (open list:All patches CC here)

I will update the patch to add these files to the "X86 KVM CPUs" section.

Thanks,

Phil.

maintainer Applied
#53 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Hi,

While testing James & Dov patch:
https://www.mail-archive.com/[email protected]/msg810571.html
I wasted some time trying to figure out how OVMF was supposed to behave until realizing the binary I was using was built without SEV support... Then wrote this series to help other developers to not hit the same problem.

Quoted 5 lines

Since v2:
- Rebased on top of SGX
- Addressed review comments from Markus / David
- Included/rebased 'Measured Linux SEV guest' from Dov [1]
- Added orphean MAINTAINERS section

I have queued Dov's patches already, but apart from that the changes from v3 to v4 should be minimal.

Thanks for this work!

Paolo

Quoted 55 lines

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Supersedes: <[email protected]>

Dov Murik (2):
sev/i386: Introduce sev_add_kernel_loader_hashes for measured linux
boot
x86/sev: generate SEV kernel loader hashes in x86_load_linux

Dr. David Alan Gilbert (1):
target/i386/sev: sev_get_attestation_report use g_autofree

Philippe Mathieu-Daudé (19):
qapi/misc-target: Wrap long 'SEV Attestation Report' long lines qapi/misc-target: Group SEV QAPI definitions target/i386/kvm: Introduce i386_softmmu_kvm Meson source set target/i386/kvm: Restrict SEV stubs to x86 architecture target/i386/monitor: Return QMP error when SEV is disabled in build target/i386/cpu: Add missing 'qapi/error.h' header target/i386/sev_i386.h: Remove unused headers target/i386/sev: Remove sev_get_me_mask() target/i386/sev: Mark unreachable code with g_assert_not_reached() target/i386/sev: Restrict SEV to system emulation target/i386/sev: Declare system-specific functions in 'sev_i386.h' target/i386/sev: Remove stubs by using code elision target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c target/i386/sev: Move qmp_query_sev_capabilities() to sev.c target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c
monitor: Restrict 'info sev' to x86 targets
MAINTAINERS: Cover AMD SEV files

  qapi/misc-target.json                 |  77 ++++----
  include/monitor/hmp-target.h          |   1 +
  include/monitor/hmp.h                 |   1 -
  include/sysemu/sev.h                  |  20 +-
  target/i386/sev_i386.h                |  32 +--
  hw/i386/pc_sysfw.c                    |   2 +-
  hw/i386/x86.c                         |  25 ++-
  target/i386/cpu.c                     |  17 +-
  {accel => target/i386}/kvm/sev-stub.c |   0
  target/i386/monitor.c                 |  92 +--------
  target/i386/sev-stub.c                |  83 --------
  target/i386/sev-sysemu-stub.c         |  70 +++++++
  target/i386/sev.c                     | 268 +++++++++++++++++++++++---
  MAINTAINERS                           |   7 +
  accel/kvm/meson.build                 |   1 -
  target/i386/kvm/meson.build           |   8 +-
  target/i386/meson.build               |   4 +-
  17 files changed, 438 insertions(+), 270 deletions(-)

rename {accel => target/i386}/kvm/sev-stub.c (100%) delete mode 100644 target/i386/sev-stub.c create mode 100644 target/i386/sev-sysemu-stub.c