From nobody Tue Feb 10 04:14:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623307606; cv=none; d=zohomail.com; s=zohoarc; b=IcCxQ1E+KhTHMKUMUDGX16HXbVHlJhmcXlPGyGDhrz2Z0C4stU/qz/g0codLIBtJt7uOMMgakLFf5+64lF8crP6z7P8Vk0MSRFVUJ0gToSYiyeUlexco35A5sYAtJSglC3cmFoi9w1GrNAzL1tKakPlgyYZA4J8xsafEJUr5Lfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623307606; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=3dVHGUrDmml8HUud+bRTuXjOS6AbsjG7OqruqOvXxLA=; b=NVcTjTCsMywAGuNZZdNGNs3SFaNZAqLOQS1nqodRZ1TTuOck/gnOjSycL4rD7SZ4FOCUQh7rEa35FRp59klCfgrFgbb5Fes+2uL/k+knY0oXzSLlm5S+lGGoyA+w7UFq5EykCK0xDKyOyRM6RYjJ/qAxzdPVCnv9HybU9vcpsOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1623307606682828.7461034885704; Wed, 9 Jun 2021 23:46:46 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-502-pNGLZYudM_q_gn2v28DNtw-1; Thu, 10 Jun 2021 02:46:43 -0400 Received: by mail-wr1-f69.google.com with SMTP id r17-20020a5d52d10000b0290119976473fcso417965wrv.15 for ; Wed, 09 Jun 2021 23:46:43 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (235.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.235]) by smtp.gmail.com with ESMTPSA id u7sm2717164wrt.18.2021.06.09.23.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 23:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623307605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3dVHGUrDmml8HUud+bRTuXjOS6AbsjG7OqruqOvXxLA=; b=YuTmH01Z9JCLINqt4JGkuBSNw9o8grMeJExGYYxNTPIeAaeEbAK1EumA5aQt5IUhtMMchA eIiF97ayTRTWVduzB3A21RHoNQPd7HUsK4jOZ70ePx64EbJ1KMWvPVE9PvXQrtYf4C94xI YV3BVLVX3phhChEeoanLpB1QsFkP0PQ= X-MC-Unique: pNGLZYudM_q_gn2v28DNtw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3dVHGUrDmml8HUud+bRTuXjOS6AbsjG7OqruqOvXxLA=; b=nKlBjxSW8yFv8RrQ3T9tjS7uqAJ0cSbL0E9JNyE0HXKe4UP67B5sMzsHH4UlS8wyus oOTQ4qu2Y7C/gHpSIKLBlY0DDLd5UbLUIa2xA2yIQFz/edKn5YhE+UFqnnuh4DXIPo9R w0GLKe91lLJwt20BN3uyrkDL65B57ZB/8pemWCpt1q0SfUjKxGC4HE9NdXYTA5H+5v3q jCGGNSn7PaE3oZi0E7jK/THwdu9gZLc9Fk4qyTA+cvyffbMkUSma6A7FW4ULlLCoZlwn RPe8lGKgLmKSt7XqortUY4B/ohn/audlqR2WRGzHeGGWJV3mXv8vRkxhPgOmXsxjFWIc Vx7A== X-Gm-Message-State: AOAM530ayy8TZMkc2YwbAIZL4ph5F1H3aqXvVN+p0Y/XdzNFemqgdW15 fhtH/sSLD4PVrJ40kdrpp229stSggWWZhXCMr2q00PLHZebVHBnJD6j6sgCf5WLY7xz/UJC6/E/ Lt2DE4ySkGYEfuw== X-Received: by 2002:a05:600c:5112:: with SMTP id o18mr3244263wms.15.1623307602232; Wed, 09 Jun 2021 23:46:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3lYL97rKIpPn8OrukcXxgeN2hegkXzMDV7tnIlcGGlFmAze2J7KUSbNCYzgsmohTVtaA40A== X-Received: by 2002:a05:600c:5112:: with SMTP id o18mr3244249wms.15.1623307602019; Wed, 09 Jun 2021 23:46:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , Connor Kuehl , Markus Armbruster , Brijesh Singh , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 10/11] target/i386/monitor: Move SEV specific commands to sev.c Date: Thu, 10 Jun 2021 08:45:55 +0200 Message-Id: <20210610064556.1421620-11-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610064556.1421620-1-philmd@redhat.com> References: <20210610064556.1421620-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Having the HMP/QMP commands defined in monitor.c makes the stubs rather complicated when SEV is not built in. To simplify, move the SEV functions to sev.c, and remove a layer of stubs. Also make it clearer when SEV is not built in, so developers don't try to enable it when it is not enablable: - before: (qemu) info sev SEV is not enabled - after: (qemu) info sev SEV is not available in this QEMU Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/monitor.c | 96 ---------------------------------- target/i386/sev-sysemu-stub.c | 29 +++++++---- target/i386/sev.c | 97 +++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 106 deletions(-) diff --git a/target/i386/monitor.c b/target/i386/monitor.c index c83cca80dc2..af3501095e5 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -28,11 +28,8 @@ #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" -#include "sev_i386.h" #include "qapi/qapi-commands-misc-target.h" #include "qapi/qapi-commands-misc.h" #include "hw/i386/pc.h" @@ -675,96 +672,3 @@ void hmp_info_io_apic(Monitor *mon, const QDict *qdict) monitor_printf(mon, "This command is obsolete and will be " "removed soon. Please use 'info pic' instead.\n"); } - -SevInfo *qmp_query_sev(Error **errp) -{ - SevInfo *info; - - info =3D 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 =3D 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); -} - -SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp) -{ - char *data; - SevLaunchMeasureInfo *info; - - data =3D sev_get_launch_measurement(); - if (!data) { - error_setg(errp, "Measurement is not available"); - return NULL; - } - - info =3D g_malloc0(sizeof(*info)); - info->data =3D data; - - return info; -} - -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 =3D (struct sev_secret_area *)data; - gpa =3D area->base; - } - - 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); -} diff --git a/target/i386/sev-sysemu-stub.c b/target/i386/sev-sysemu-stub.c index d556b4f091f..7a35f0432b2 100644 --- a/target/i386/sev-sysemu-stub.c +++ b/target/i386/sev-sysemu-stub.c @@ -12,30 +12,35 @@ */ =20 #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" =20 -SevInfo *sev_get_info(void) +SevInfo *qmp_query_sev(Error **errp) { + error_setg(errp, QERR_UNSUPPORTED); return NULL; } =20 -char *sev_get_launch_measurement(void) +SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp) { + error_setg(errp, QERR_UNSUPPORTED); return NULL; } =20 -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; } =20 -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 *s= ecret, + bool has_gpa, uint64_t gpa, Error **errp) { - return 1; + error_setg(errp, QERR_UNSUPPORTED); } =20 int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp) @@ -52,9 +57,13 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t f= lash_size) g_assert_not_reached(); } =20 -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; } + +void hmp_info_sev(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "SEV is not available in this QEMU\n"); +} diff --git a/target/i386/sev.c b/target/i386/sev.c index 791804954e9..b4d7c41d3fb 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -27,10 +27,14 @@ #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" #include "hw/i386/pc.h" =20 @@ -1070,3 +1074,96 @@ sev_register_types(void) } =20 type_init(sev_register_types); + +SevInfo *qmp_query_sev(Error **errp) +{ + SevInfo *info; + + info =3D 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 =3D 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); +} + +SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp) +{ + char *data; + SevLaunchMeasureInfo *info; + + data =3D sev_get_launch_measurement(); + if (!data) { + error_setg(errp, "Measurement is not available"); + return NULL; + } + + info =3D g_malloc0(sizeof(*info)); + info->data =3D data; + + return info; +} + +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 =3D (struct sev_secret_area *)data; + gpa =3D area->base; + } + + 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); +} --=20 2.31.1