From patchwork Tue Mar 2 20:48:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dov Murik X-Patchwork-Id: 12112237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 993D5C433E0 for ; Tue, 2 Mar 2021 21:04:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18E7A64F23 for ; Tue, 2 Mar 2021 21:04:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18E7A64F23 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHCBq-0002Fa-1l for qemu-devel@archiver.kernel.org; Tue, 02 Mar 2021 16:04:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHBx5-000211-Sm for qemu-devel@nongnu.org; Tue, 02 Mar 2021 15:49:07 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32602 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHBws-00089d-Iq for qemu-devel@nongnu.org; Tue, 02 Mar 2021 15:49:05 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 122Kj1i6020855; Tue, 2 Mar 2021 15:48:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=4b7gCV47XUV2KpXJjH0Ddco1GnBVILBnVnOdpnsotJE=; b=ekWIde5EIGIG8ESCnuW0gYAq7VUvx3RMOammkovqnU6+DVDBPRQtRg4Y6tNw2hTm0nXk oM2Ck+GTXPjaCumX5Z5CrB7IG/pXrQPpR2+N9c12HNXBK4cKSr3n4506OvvVucMcgt3m iHP5EJC3+mDeonMJTwaAAPKYs5/zAA67fVqxwm2ZSUftwI29xNzZzvyXmPtJJB+a73Vq cf4mnTPHr1r9w9G7oSM/jMJuVzMpe6rVZ4tyd7+rkRliQHiqlR2H1ZyZGxQoRzV+Q9nv nyW/4bR1HJ2PW+LqHGKWziKGdQZpCwjdIjrY0SZkx0adMAFNPMrC9VeVx+Lk1juk//yc Ig== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 371vnsr4sp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 15:48:37 -0500 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 122Kk2Gf025109; Tue, 2 Mar 2021 15:48:36 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com with ESMTP id 371vnsr4q8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 15:48:36 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 122KkqMA028086; Tue, 2 Mar 2021 20:48:34 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma01dal.us.ibm.com with ESMTP id 371qmuagug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 20:48:34 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 122KmW9p40698236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Mar 2021 20:48:33 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D88F528064; Tue, 2 Mar 2021 20:48:32 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B0C0928058; Tue, 2 Mar 2021 20:48:32 +0000 (GMT) Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 2 Mar 2021 20:48:32 +0000 (GMT) From: Dov Murik To: qemu-devel@nongnu.org Subject: [RFC PATCH 17/26] migration: Stop VM after loading confidential RAM Date: Tue, 2 Mar 2021 15:48:13 -0500 Message-Id: <20210302204822.81901-18-dovmurik@linux.vnet.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210302204822.81901-1-dovmurik@linux.vnet.ibm.com> References: <20210302204822.81901-1-dovmurik@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.761 definitions=2021-03-02_08:2021-03-01, 2021-03-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 adultscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103020156 Received-SPF: none client-ip=148.163.158.5; envelope-from=dovmurik@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Lendacky , Ashish Kalra , Brijesh Singh , Eduardo Habkost , Juan Quintela , Richard Henderson , James Bottomley , Jon Grimm , Tobin Feldman-Fitzthum , Dov Murik , "Dr. David Alan Gilbert" , Hubertus Franke , Tobin Feldman-Fitzthum , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Register a dummy device state (EndOfConfidentialRAMState) with high priority so it is the first device which is loaded in the target. The post_load handler of this device stops the VM, which makes things easier when loading devices' states which expect the VM not to be running at the same time. Signed-off-by: Dov Murik --- migration/confidential-ram.h | 2 ++ migration/confidential-ram.c | 31 +++++++++++++++++++++++++++++++ softmmu/runstate.c | 1 + target/i386/sev.c | 2 ++ 4 files changed, 36 insertions(+) diff --git a/migration/confidential-ram.h b/migration/confidential-ram.h index 9a1027bdaf..2822c5ee3d 100644 --- a/migration/confidential-ram.h +++ b/migration/confidential-ram.h @@ -18,4 +18,6 @@ int cgs_mh_save_encrypted_page(QEMUFile *f, ram_addr_t src_gpa, uint32_t size, int cgs_mh_load_encrypted_page(QEMUFile *f, ram_addr_t dest_gpa); +void register_end_of_confidential_ram(void); + #endif diff --git a/migration/confidential-ram.c b/migration/confidential-ram.c index 0b821af774..982cf9b874 100644 --- a/migration/confidential-ram.c +++ b/migration/confidential-ram.c @@ -8,6 +8,8 @@ #include "io/channel.h" #include "qapi/error.h" #include "exec/memory.h" +#include "migration/vmstate.h" +#include "sysemu/runstate.h" #include "trace.h" #include "confidential-ram.h" @@ -225,3 +227,32 @@ int cgs_mh_load_encrypted_page(QEMUFile *f, ram_addr_t dest_gpa) } return ret; } + +typedef struct { + bool dummy; +} EndOfConfidentialRAMState; + +static EndOfConfidentialRAMState end_of_confidential_ram_state = { .dummy = false }; + +static int end_of_confidential_ram_post_load(void *opaque, int version_id) +{ + vm_stop(RUN_STATE_INMIGRATE); + return 0; +} + +static const VMStateDescription vmstate_end_of_confidential_ram = { + .name = "end-of-confidential-ram", + .priority = MIG_PRI_GICV3, /* TODO define new (higher) priority level */ + .version_id = 1, + .post_load = end_of_confidential_ram_post_load, + .fields = (VMStateField[]) { + VMSTATE_BOOL(dummy, EndOfConfidentialRAMState), + VMSTATE_END_OF_LIST() + }, +}; + +void register_end_of_confidential_ram(void) +{ + vmstate_register(NULL, 0, &vmstate_end_of_confidential_ram, + &end_of_confidential_ram_state); +} diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 2874417b61..193413246d 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -131,6 +131,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, + { RUN_STATE_RUNNING, RUN_STATE_INMIGRATE }, { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, diff --git a/target/i386/sev.c b/target/i386/sev.c index 0f414df02f..da2d0cc699 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -33,6 +33,7 @@ #include "exec/address-spaces.h" #include "monitor/monitor.h" #include "exec/confidential-guest-support.h" +#include "migration/confidential-ram.h" #include "hw/i386/pc.h" #define TYPE_SEV_GUEST "sev-guest" @@ -1011,6 +1012,7 @@ static void sev_register_types(void) { type_register_static(&sev_guest_info); + register_end_of_confidential_ram(); } type_init(sev_register_types);