From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brijesh Singh Subject: [PATCH v5 19/23] sev: Finalize the SEV guest launch flow Date: Wed, 6 Dec 2017 14:03:42 -0600 Message-ID: <20171206200346.116537-20-brijesh.singh@amd.com> References: <20171206200346.116537-1-brijesh.singh@amd.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Alistair Francis , Christian Borntraeger , Cornelia Huck , "Daniel P . Berrange" , "Dr. David Alan Gilbert" , "Edgar E . Iglesias " , Eduardo Habkost , Eric Blake , kvm@vger.kernel.org, Marcel Apfelbaum , Markus Armbruster , "Michael S. Tsirkin" , Paolo Bonzini , Peter Crosthwaite , Peter Maydell , Richard Henderson , Richard Henderson , Stefan Hajnoczi , Thomas Lendacky < To: qemu-devel@nongnu.org Return-path: Received: from mail-sn1nam01on0070.outbound.protection.outlook.com ([104.47.32.70]:10704 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752566AbdLFUFD (ORCPT ); Wed, 6 Dec 2017 15:05:03 -0500 In-Reply-To: <20171206200346.116537-1-brijesh.singh@amd.com> Sender: kvm-owner@vger.kernel.org List-ID: SEV launch flow requires us to issue LAUNCH_FINISH command before guest is ready to run. Cc: Paolo Bonzini Cc: kvm@vger.kernel.org Signed-off-by: Brijesh Singh --- accel/kvm/sev.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/accel/kvm/sev.c b/accel/kvm/sev.c index c0eea371fa06..fbbd99becc0a 100644 --- a/accel/kvm/sev.c +++ b/accel/kvm/sev.c @@ -454,6 +454,35 @@ static Notifier sev_machine_done_notify = { .notify = sev_launch_get_measure, }; +static void +sev_launch_finish(SEVState *s) +{ + int ret, error; + + ret = sev_ioctl(KVM_SEV_LAUNCH_FINISH, 0, &error); + if (ret) { + error_report("%s: LAUNCH_FINISH ret=%d fw_error=%d '%s'", + __func__, ret, error, fw_error_to_str(error)); + exit(1); + } + + s->cur_state = SEV_STATE_RUNNING; + DPRINTF("SEV: LAUNCH_FINISH\n"); +} + +static void +sev_vm_state_change(void *opaque, int running, RunState state) +{ + SEVState *s = opaque; + + if (running) { + /* we are about to resume the guest, finalize the launch flow */ + if (s->cur_state == SEV_STATE_SECRET) { + sev_launch_finish(s); + } + } +} + void * sev_guest_init(const char *id) { @@ -497,6 +526,7 @@ sev_guest_init(const char *id) ram_block_notifier_add(&sev_ram_notifier); qemu_add_machine_init_done_notifier(&sev_machine_done_notify); + qemu_add_vm_change_state_handler(sev_vm_state_change, s); sev_state = s; -- 2.9.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMfwA-0006ZY-Vw for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:05:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMfw7-0002p9-OP for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:04:58 -0500 Received: from mail-sn1nam01on0076.outbound.protection.outlook.com ([104.47.32.76]:59904 helo=NAM01-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMfw7-0002os-HZ for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:04:55 -0500 From: Brijesh Singh Date: Wed, 6 Dec 2017 14:03:42 -0600 Message-Id: <20171206200346.116537-20-brijesh.singh@amd.com> In-Reply-To: <20171206200346.116537-1-brijesh.singh@amd.com> References: <20171206200346.116537-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v5 19/23] sev: Finalize the SEV guest launch flow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alistair Francis , Christian Borntraeger , Cornelia Huck , "Daniel P . Berrange" , "Dr. David Alan Gilbert" , "Edgar E . Iglesias " , Eduardo Habkost , Eric Blake , kvm@vger.kernel.org, Marcel Apfelbaum , Markus Armbruster , "Michael S. Tsirkin" , Paolo Bonzini , Peter Crosthwaite , Peter Maydell , Richard Henderson , Richard Henderson , Stefan Hajnoczi , Thomas Lendacky , Borislav Petkov , Brijesh Singh SEV launch flow requires us to issue LAUNCH_FINISH command before guest is ready to run. Cc: Paolo Bonzini Cc: kvm@vger.kernel.org Signed-off-by: Brijesh Singh --- accel/kvm/sev.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/accel/kvm/sev.c b/accel/kvm/sev.c index c0eea371fa06..fbbd99becc0a 100644 --- a/accel/kvm/sev.c +++ b/accel/kvm/sev.c @@ -454,6 +454,35 @@ static Notifier sev_machine_done_notify = { .notify = sev_launch_get_measure, }; +static void +sev_launch_finish(SEVState *s) +{ + int ret, error; + + ret = sev_ioctl(KVM_SEV_LAUNCH_FINISH, 0, &error); + if (ret) { + error_report("%s: LAUNCH_FINISH ret=%d fw_error=%d '%s'", + __func__, ret, error, fw_error_to_str(error)); + exit(1); + } + + s->cur_state = SEV_STATE_RUNNING; + DPRINTF("SEV: LAUNCH_FINISH\n"); +} + +static void +sev_vm_state_change(void *opaque, int running, RunState state) +{ + SEVState *s = opaque; + + if (running) { + /* we are about to resume the guest, finalize the launch flow */ + if (s->cur_state == SEV_STATE_SECRET) { + sev_launch_finish(s); + } + } +} + void * sev_guest_init(const char *id) { @@ -497,6 +526,7 @@ sev_guest_init(const char *id) ram_block_notifier_add(&sev_ram_notifier); qemu_add_machine_init_done_notifier(&sev_machine_done_notify); + qemu_add_vm_change_state_handler(sev_vm_state_change, s); sev_state = s; -- 2.9.5