From: Paolo Bonzini <pbonzini@redhat.com>
To: Brijesh Singh <brijesh.singh@amd.com>,
ehabkost@redhat.com, crosthwaite.peter@gmail.com,
armbru@redhat.com, mst@redhat.com, p.fedin@samsung.com,
qemu-devel@nongnu.org, lcapitulino@redhat.com, rth@twiddle.net
Subject: Re: [Qemu-devel] [RFC PATCH v1 21/22] hw: add pre and post system reset callback
Date: Wed, 14 Sep 2016 00:47:33 +0200 [thread overview]
Message-ID: <6cddaa11-66ff-9f90-3c99-09f34fd814e5@redhat.com> (raw)
In-Reply-To: <147377821533.11859.9325768460158473728.stgit@brijesh-build-machine>
On 13/09/2016 16:50, Brijesh Singh wrote:
> This patch adds methods to register a callback in qemu_system_reset().
>
> - qemu_register_pre_reset() : function will be called just after
> entering into qemu_system_reset().
> - qemu_register_post_reset(): function will be called just before
> exiting from the qemu_system_reset().
>
> A qemu_system_reset() causes loader to reload the OS images into guest
> memory. In case of SEV-enabled guest we need to call the SEV launch start
> command before loader copies any data into guest RAM and similarly SEV
> launch finish command should be executed after we finished copying the
> data into guest memory.
>
> These callback will allow us to hook the SEV launch START and FINISH
> commands into qemu_system_reset() handlder to start and finalize the SEV
> guest launch process.
>
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
I would just put the SEV hook in qemu_system_reset().
You can use a new file sev-stub.c with an empty implementation of
kvm_sev_guest_start and kvm_sev_guest_finish.
Paolo
> ---
> include/hw/hw.h | 2 ++
> sev.c | 14 ++++++++++++++
> vl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 61 insertions(+)
>
> diff --git a/include/hw/hw.h b/include/hw/hw.h
> index 3669ebd..31dcf9f 100644
> --- a/include/hw/hw.h
> +++ b/include/hw/hw.h
> @@ -17,6 +17,8 @@ typedef void QEMUResetHandler(void *opaque);
>
> void qemu_register_reset(QEMUResetHandler *func, void *opaque);
> void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
> +void qemu_register_pre_reset(QEMUResetHandler *func, void *opaque);
> +void qemu_register_post_reset(QEMUResetHandler *func, void *opaque);
>
> void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>
> diff --git a/sev.c b/sev.c
> index c1135c4..141f9d6 100644
> --- a/sev.c
> +++ b/sev.c
> @@ -35,6 +35,7 @@
> #include "qemu/event_notifier.h"
> #include "trace.h"
> #include "hw/irq.h"
> +#include "hw/hw.h"
>
> //#define DEBUG_SEV
>
> @@ -257,6 +258,16 @@ static int parse_sev_cfg(SEVInfo *s, int type, const char *filename)
>
> }
>
> +static void sev_pre_reset_handler(void *data)
> +{
> + kvm_sev_guest_start();
> +}
> +
> +static void sev_post_reset_handler(void *data)
> +{
> + kvm_sev_guest_finish();
> +}
> +
> int sev_init(KVMState *kvm_state)
> {
> QemuOpts *opts;
> @@ -287,6 +298,9 @@ int sev_init(KVMState *kvm_state)
> goto err;
> }
>
> + qemu_register_pre_reset(sev_pre_reset_handler, sev_info);
> + qemu_register_post_reset(sev_post_reset_handler, sev_info);
> +
> return kvm_sev_guest_start();
> err:
> free(sev_info);
> diff --git a/vl.c b/vl.c
> index 22b8eba..5923c73 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -25,6 +25,7 @@
> #include "qemu-version.h"
> #include "qemu/cutils.h"
> #include "qemu/help_option.h"
> +#include "sysemu/sev.h"
>
> #ifdef CONFIG_SECCOMP
> #include "sysemu/seccomp.h"
> @@ -1630,6 +1631,10 @@ static NotifierList suspend_notifiers =
> static NotifierList wakeup_notifiers =
> NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
> static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
> +static QTAILQ_HEAD(pre_reset_handlers, QEMUResetEntry) pre_reset_handlers =
> + QTAILQ_HEAD_INITIALIZER(pre_reset_handlers);
> +static QTAILQ_HEAD(post_reset_handlers, QEMUResetEntry)
> + post_reset_handlers = QTAILQ_HEAD_INITIALIZER(post_reset_handlers);
>
> int qemu_shutdown_requested_get(void)
> {
> @@ -1733,12 +1738,51 @@ void qemu_devices_reset(void)
> }
> }
>
> +void qemu_register_pre_reset(QEMUResetHandler *func, void *opaque)
> +{
> + QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
> +
> + re->func = func;
> + re->opaque = opaque;
> + QTAILQ_INSERT_TAIL(&pre_reset_handlers, re, entry);
> +}
> +
> +static void qemu_system_pre_reset(void)
> +{
> + QEMUResetEntry *re, *nre;
> +
> + /* call pre_reset handler */
> + QTAILQ_FOREACH_SAFE(re, &pre_reset_handlers, entry, nre) {
> + re->func(re->opaque);
> + }
> +}
> +
> +void qemu_register_post_reset(QEMUResetHandler *func, void *opaque)
> +{
> + QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
> +
> + re->func = func;
> + re->opaque = opaque;
> + QTAILQ_INSERT_TAIL(&post_reset_handlers, re, entry);
> +}
> +
> +static void qemu_system_post_reset(void)
> +{
> + QEMUResetEntry *re, *nre;
> +
> + /* call post reset handler */
> + QTAILQ_FOREACH_SAFE(re, &post_reset_handlers, entry, nre) {
> + re->func(re->opaque);
> + }
> +}
> +
> void qemu_system_reset(bool report)
> {
> MachineClass *mc;
>
> mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
>
> + qemu_system_pre_reset();
> cpu_synchronize_all_states();
>
> if (mc && mc->reset) {
> @@ -1750,6 +1794,7 @@ void qemu_system_reset(bool report)
> qapi_event_send_reset(&error_abort);
> }
> cpu_synchronize_all_post_reset();
> + qemu_system_post_reset();
> }
>
> void qemu_system_guest_panicked(void)
>
>
>
next prev parent reply other threads:[~2016-09-13 22:48 UTC|newest]
Thread overview: 125+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 14:46 [Qemu-devel] [RFC PATCH v1 00/22] x86: Secure Encrypted Virtualization (AMD) Brijesh Singh
2016-09-13 14:46 ` [Qemu-devel] [RFC PATCH v1 01/22] exec: add guest RAM read/write ops Brijesh Singh
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 02/22] cpu-common: add debug version of physical memory read/write Brijesh Singh
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 03/22] monitor: use debug version of physical memory read api Brijesh Singh
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 04/22] memattrs: add SEV debug attrs Brijesh Singh
2016-09-13 23:00 ` Paolo Bonzini
2016-09-14 20:30 ` Brijesh Singh
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 05/22] i386: add new option to enable SEV guest Brijesh Singh
2016-09-13 22:41 ` Paolo Bonzini
2016-09-14 8:41 ` Daniel P. Berrange
2016-09-14 9:11 ` Paolo Bonzini
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 06/22] sev: add initial SEV support Brijesh Singh
2016-09-13 15:58 ` Eduardo Habkost
2016-09-13 19:54 ` Brijesh Singh
2016-09-13 20:10 ` Michael S. Tsirkin
2016-09-13 22:00 ` Eduardo Habkost
2016-09-14 8:30 ` Daniel P. Berrange
2016-09-14 11:54 ` Eduardo Habkost
2016-09-14 11:58 ` Daniel P. Berrange
2016-09-14 16:10 ` Brijesh Singh
2016-09-14 16:13 ` Daniel P. Berrange
2016-09-14 16:20 ` Michael S. Tsirkin
2016-09-14 18:46 ` Brijesh Singh
2016-09-14 20:23 ` Michael S. Tsirkin
2016-09-14 8:37 ` Daniel P. Berrange
2016-09-13 14:47 ` [Qemu-devel] [RFC PATCH v1 07/22] sev: add SEV launch start command Brijesh Singh
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 08/22] sev: add SEV launch update command Brijesh Singh
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 09/22] sev: add SEV launch finish command Brijesh Singh
2016-09-13 22:15 ` Eduardo Habkost
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 10/22] sev: add SEV debug decrypt command Brijesh Singh
2016-09-14 2:28 ` Michael S. Tsirkin
2016-09-14 8:57 ` Paolo Bonzini
2016-09-14 13:05 ` Michael S. Tsirkin
2016-09-14 13:07 ` Paolo Bonzini
2016-09-14 13:23 ` Daniel P. Berrange
2016-09-14 13:32 ` Michael S. Tsirkin
2016-09-14 13:37 ` Daniel P. Berrange
2016-09-14 13:50 ` Michael S. Tsirkin
2016-09-14 14:08 ` Eduardo Habkost
2016-09-14 14:14 ` Paolo Bonzini
2016-09-14 14:38 ` Michael S. Tsirkin
2016-09-14 15:17 ` Michael S. Tsirkin
2016-09-14 14:15 ` Daniel P. Berrange
2016-09-14 14:48 ` Michael S. Tsirkin
2016-09-14 15:06 ` Daniel P. Berrange
2016-09-14 15:46 ` Michael S. Tsirkin
2016-09-14 17:35 ` Eduardo Habkost
2016-09-14 22:05 ` Michael S. Tsirkin
2016-09-15 14:58 ` Eduardo Habkost
2016-09-14 13:27 ` [Qemu-devel] [PATCH v2] virtio_pci: Limit DMA mask to 44 bits for legacy virtio devices Michael S. Tsirkin
2016-09-14 13:36 ` [Qemu-devel] [RFC PATCH v1 10/22] sev: add SEV debug decrypt command Brijesh Singh
2016-09-14 13:48 ` Michael S. Tsirkin
2016-09-14 14:19 ` Paolo Bonzini
2016-09-14 15:02 ` Michael S. Tsirkin
2016-09-14 16:53 ` Paolo Bonzini
2016-09-14 18:15 ` Michael S. Tsirkin
2016-09-14 18:45 ` Paolo Bonzini
2016-09-14 19:24 ` Michael S. Tsirkin
2016-09-14 19:58 ` Paolo Bonzini
2016-09-14 20:36 ` Michael S. Tsirkin
2016-09-14 20:44 ` Paolo Bonzini
2016-09-14 21:25 ` Brijesh Singh
2016-09-14 21:38 ` Michael S. Tsirkin
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 11/22] sev: add SEV debug encrypt command Brijesh Singh
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 12/22] sev: add SEV guest status command Brijesh Singh
2016-09-13 14:48 ` [Qemu-devel] [RFC PATCH v1 13/22] hmp: update 'info kvm' to display SEV status Brijesh Singh
2016-09-13 16:09 ` Eric Blake
2016-09-14 16:16 ` Brijesh Singh
2016-09-15 4:13 ` Michael S. Tsirkin
2016-09-13 23:01 ` Paolo Bonzini
2016-09-13 14:49 ` [Qemu-devel] [RFC PATCH v1 14/22] sev: provide SEV-enabled guest RAM read/write ops Brijesh Singh
2016-09-13 14:49 ` [Qemu-devel] [RFC PATCH v1 15/22] i386: sev: register RAM read/write ops for BIOS and PC.RAM region Brijesh Singh
2016-09-13 23:05 ` Paolo Bonzini
2016-09-14 20:59 ` Brijesh Singh
2016-09-14 21:00 ` Paolo Bonzini
2016-09-14 21:47 ` Brijesh Singh
2016-09-14 21:52 ` Paolo Bonzini
2016-09-14 22:06 ` Brijesh Singh
2016-09-14 22:17 ` Paolo Bonzini
2016-09-14 22:26 ` Brijesh Singh
2016-09-15 14:13 ` Brijesh Singh
2016-09-15 15:19 ` Paolo Bonzini
2016-09-13 14:49 ` [Qemu-devel] [RFC PATCH v1 17/22] target-i386: add cpuid Fn8000_001f Brijesh Singh
2016-09-13 23:07 ` Paolo Bonzini
2016-09-21 16:20 ` Brijesh Singh
2016-09-21 16:24 ` Paolo Bonzini
2016-09-21 18:21 ` Eduardo Habkost
2016-09-13 14:49 ` [Qemu-devel] [RFC PATCH v1 18/22] i386: clear C-bit in SEV guest page table walk Brijesh Singh
2016-09-13 14:49 ` [Qemu-devel] [RFC PATCH v1 19/22] exec: set debug attribute in SEV-enabled guest Brijesh Singh
2016-09-13 23:06 ` Paolo Bonzini
2016-09-13 14:50 ` [Qemu-devel] [RFC PATCH v1 20/22] fw_cfg: sev: disable dma in real mode Brijesh Singh
2016-09-13 18:39 ` Michael S. Tsirkin
2016-09-13 20:46 ` Brijesh Singh
2016-09-13 20:55 ` Michael S. Tsirkin
2016-09-13 22:53 ` Paolo Bonzini
2016-09-14 2:33 ` Michael S. Tsirkin
2016-09-14 8:58 ` Paolo Bonzini
2016-09-21 18:00 ` [Qemu-devel] [RFC PATCH v1 20/22] fw_cfg: sev: disable dma in real mode Message-ID: <20160921205731-mutt-send-email-mst@kernel.org> Michael S. Tsirkin
2016-09-14 12:09 ` [Qemu-devel] [RFC PATCH v1 20/22] fw_cfg: sev: disable dma in real mode Eduardo Habkost
2016-09-14 13:01 ` Paolo Bonzini
2016-09-14 13:14 ` Michael S. Tsirkin
2016-09-14 13:51 ` Eduardo Habkost
2016-09-14 16:10 ` Michael S. Tsirkin
2016-09-14 17:25 ` Eduardo Habkost
2016-09-21 18:03 ` Michael S. Tsirkin
2016-09-21 18:19 ` Brijesh Singh
2016-09-13 14:50 ` [Qemu-devel] [RFC PATCH v1 21/22] hw: add pre and post system reset callback Brijesh Singh
2016-09-13 22:47 ` Paolo Bonzini [this message]
2016-09-14 16:19 ` Brijesh Singh
2016-09-13 14:50 ` [Qemu-devel] [RFC PATCH v1 22/22] loader: reload bios image on ROM reset in SEV-enabled guest Brijesh Singh
2016-09-13 18:47 ` Michael S. Tsirkin
2016-09-13 22:59 ` Paolo Bonzini
2016-09-14 2:38 ` Michael S. Tsirkin
2016-09-14 20:29 ` Brijesh Singh
2016-09-14 20:38 ` Paolo Bonzini
2016-09-14 21:09 ` Michael S. Tsirkin
2016-09-14 21:11 ` Paolo Bonzini
2016-09-14 21:24 ` Brijesh Singh
2016-09-13 15:20 ` [Qemu-devel] [RFC PATCH v1 00/22] x86: Secure Encrypted Virtualization (AMD) Eduardo Habkost
[not found] ` <147377816978.11859.942423377333907417.stgit@brijesh-build-machine>
2016-09-13 18:37 ` [Qemu-devel] [RFC PATCH v1 16/22] i386: pc: load OS images at fixed location in SEV-enabled guest Michael S. Tsirkin
2016-09-21 15:55 ` Brijesh Singh
2016-09-21 15:58 ` Paolo Bonzini
2016-09-21 16:08 ` Brijesh Singh
2016-09-21 16:17 ` Paolo Bonzini
2016-09-14 2:55 ` [Qemu-devel] [RFC PATCH v1 00/22] x86: Secure Encrypted Virtualization (AMD) Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cddaa11-66ff-9f90-3c99-09f34fd814e5@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=brijesh.singh@amd.com \
--cc=crosthwaite.peter@gmail.com \
--cc=ehabkost@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mst@redhat.com \
--cc=p.fedin@samsung.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).