diff mbox series

[v7,13/26] qmp: add query-sev command

Message ID 20180207160638.98872-13-brijesh.singh@amd.com
State New
Headers show
Series [v7,01/26] memattrs: add debug attribute | expand

Commit Message

Brijesh Singh Feb. 7, 2018, 4:06 p.m. UTC
The QMP query command can used to retrieve the SEV information when
memory encryption is enabled on AMD platform.

Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 qapi-schema.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 qmp.c            | 16 ++++++++++++++++
 2 files changed, 63 insertions(+)

Comments

Eric Blake Feb. 7, 2018, 4:22 p.m. UTC | #1
On 02/07/2018 10:06 AM, Brijesh Singh wrote:
> The QMP query command can used to retrieve the SEV information when
> memory encryption is enabled on AMD platform.
> 
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---

> +##
> +# @SevInfo:
> +#
> +# Information about SEV support
> +#
> +# @enabled: true if SEV is active
> +#
> +# @api_major: SEV API major version

New QMP structures should prefer '-' over '_'; this should be 'api-major'.

> +#
> +# @api_minor: SEV API minor version
> +#
> +# @build_id: SEV FW build id

and so on.

> +#
> +# @policy: SEV policy value
> +#
> +# @state: SEV guest state
> +#
> +# Since: 2.12
> +##
> +{ 'struct': 'SevInfo',
> +    'data': { 'enabled': 'bool',
> +              'api_major': 'uint8',
> +              'api_minor' : 'uint8',
> +              'build_id' : 'uint8',
> +              'policy' : 'uint32',
> +              'state' : 'str'
> +            }
> +}
> +
> +##
> +# @query-sev:
> +#
> +# Returns information about SEV

It would be worth expanding the acronym here, for someone that is 
reading the documentation but not familiar with the term.

> +#
> +# Returns: @SevInfo
> +#
> +# Since: 2.12
> +#
> +# Example:
> +#
> +# -> { "execute": "query-sev" }
> +# <- { "return": { "enabled": true, "api-major" : 0, "api-minor" : 0,
> +#                  "build-id" : 0, "policy" : 0, "state" : "running" } }

This example does not match the spelling you used in the struct above, 
but DOES match what the spelling should be.
Brijesh Singh Feb. 7, 2018, 4:36 p.m. UTC | #2
On 2/7/18 10:22 AM, Eric Blake wrote:
>> +#
>> +# @enabled: true if SEV is active
>> +#
>> +# @api_major: SEV API major version
>
> New QMP structures should prefer '-' over '_'; this should be
> 'api-major'.

I will fix it. thanks

....

>> +##
>> +# @query-sev:
>> +#
>> +# Returns information about SEV
>
> It would be worth expanding the acronym here, for someone that is
> reading the documentation but not familiar with the term.
>

Will do.
diff mbox series

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 5c06745c7927..447ebb15266e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3189,3 +3189,50 @@ 
 # Since: 2.11
 ##
 { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
+
+##
+# @SevInfo:
+#
+# Information about SEV support
+#
+# @enabled: true if SEV is active
+#
+# @api_major: SEV API major version
+#
+# @api_minor: SEV API minor version
+#
+# @build_id: SEV FW build id
+#
+# @policy: SEV policy value
+#
+# @state: SEV guest state
+#
+# Since: 2.12
+##
+{ 'struct': 'SevInfo',
+    'data': { 'enabled': 'bool',
+              'api_major': 'uint8',
+              'api_minor' : 'uint8',
+              'build_id' : 'uint8',
+              'policy' : 'uint32',
+              'state' : 'str'
+            }
+}
+
+##
+# @query-sev:
+#
+# Returns information about SEV
+#
+# Returns: @SevInfo
+#
+# Since: 2.12
+#
+# Example:
+#
+# -> { "execute": "query-sev" }
+# <- { "return": { "enabled": true, "api-major" : 0, "api-minor" : 0,
+#                  "build-id" : 0, "policy" : 0, "state" : "running" } }
+#
+##
+{ 'command': 'query-sev', 'returns': 'SevInfo' }
diff --git a/qmp.c b/qmp.c
index 52cfd2d81c0f..1a5cfad09dd0 100644
--- a/qmp.c
+++ b/qmp.c
@@ -37,6 +37,7 @@ 
 #include "qom/object_interfaces.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "sysemu/sev.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -717,3 +718,18 @@  MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 
     return mem_info;
 }
+
+SevInfo *qmp_query_sev(Error **errp)
+{
+    SevInfo *info = g_malloc0(sizeof(*info));
+
+    info->enabled = sev_enabled();
+    if (info->enabled) {
+        sev_get_fw_version(&info->api_major,
+                           &info->api_minor, &info->build_id);
+        sev_get_policy(&info->policy);
+        sev_get_current_state(&info->state);
+    }
+
+    return info;
+}