From patchwork Thu Jun 20 16:38:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 11007423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E76A713AF for ; Thu, 20 Jun 2019 16:38:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7E6728812 for ; Thu, 20 Jun 2019 16:38:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC30C28816; Thu, 20 Jun 2019 16:38:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D15128812 for ; Thu, 20 Jun 2019 16:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732190AbfFTQiw (ORCPT ); Thu, 20 Jun 2019 12:38:52 -0400 Received: from mail-eopbgr770049.outbound.protection.outlook.com ([40.107.77.49]:36184 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732143AbfFTQiw (ORCPT ); Thu, 20 Jun 2019 12:38:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3TZs3VI+qUHHfH/aANMBDcYc2qnIppUMhF4OcQXhCDE=; b=pzWJWpKxta7uBNAtub1nQ3QeisDSwsiCM9YJUAzWSLDi6DW7tncct2Gd5QAVzO4qoNvjWmM8oaJD2z29etLsD0HiapGNBfA16yB7ur1I7aMEiU9uuBX827sQsjmpDll0cHTdQZfrADLLiF0u0XOD2seEV8PDnqdz5sQWzVEXBNI= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB3401.namprd12.prod.outlook.com (20.178.198.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1987.11; Thu, 20 Jun 2019 16:38:49 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::b9c1:b235:fff3:dba2]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::b9c1:b235:fff3:dba2%6]) with mapi id 15.20.1987.014; Thu, 20 Jun 2019 16:38:49 +0000 From: "Singh, Brijesh" To: "kvm@vger.kernel.org" CC: "Singh, Brijesh" Subject: [RFC PATCH v2 00/11] Add AMD SEV guest live migration support Thread-Topic: [RFC PATCH v2 00/11] Add AMD SEV guest live migration support Thread-Index: AQHVJ4ajMp5z1g+GPEmk1ZhGsIPh4g== Date: Thu, 20 Jun 2019 16:38:49 +0000 Message-ID: <20190620163832.5451-1-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DM5PR15CA0055.namprd15.prod.outlook.com (2603:10b6:3:ae::17) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 90b2c70b-260e-425e-c14f-08d6f59dc563 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:DM6PR12MB3401; x-ms-traffictypediagnostic: DM6PR12MB3401: x-ms-exchange-purlcount: 2 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0074BBE012 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(346002)(376002)(39860400002)(396003)(136003)(199004)(189003)(305945005)(6116002)(36756003)(478600001)(25786009)(966005)(50226002)(14454004)(8936002)(4326008)(1730700003)(8676002)(86362001)(68736007)(5660300002)(316002)(81166006)(1076003)(81156014)(256004)(14444005)(66476007)(66556008)(53936002)(99286004)(2501003)(6916009)(71190400001)(7736002)(186003)(73956011)(71200400001)(66946007)(66446008)(26005)(64756008)(2906002)(2351001)(3846002)(66066001)(6436002)(102836004)(5640700003)(6486002)(476003)(2616005)(6306002)(386003)(6506007)(6512007)(52116002)(486006);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3401;H:DM6PR12MB2682.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: a+mfB0Tl9/RBmZYUQkZRDYiKd49GoJc8KIlt2siowJDaS4dGpvoU+m8KilWghOjupt97Ea3hWmUAidJclN2pcuzHGfG4THXYGvMdX7DHCgE9zjiInHNhBDQ1qVoHkwZYFGrc80wj3ppPMtvik676o7+Rj0PwAYywoSatFVejXRWVwr9ZodfGae0vq1+PPgI7IRgaU3DDSDOzZih4q6wStQ+NElgS8nKj1oKjUdZ5nEBPx2ow9i9pD7in0fkfnqB1U4BHnbFCWLTUGrI9eaoEZHYve3fVXVDJNDTWcNF22DKvbBVZMvX8aAwHMhj6P7OfzlzRSqwgGJcCLjXW+FUwuKcITt8fUUMPhqtY3c09c+E1XWgtg8ejvfwhkvYGpIkAiOpxqedTTfsncyo/A2pDvTfySmnLCqR+S4n84DtkT9A= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90b2c70b-260e-425e-c14f-08d6f59dc563 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jun 2019 16:38:49.5580 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: sbrijesh@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3401 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The series add support for AMD SEV guest live migration commands. To protect the confidentiality of an SEV protected guest memory while in transit we need to use the SEV commands defined in SEV API spec [1]. SEV guest VMs have the concept of private and shared memory. Private memory is encrypted with the guest-specific key, while shared memory may be encrypted with hypervisor key. The commands provided by the SEV FW are meant to be used for the private memory only. The patch series introduces a new hypercall. The guest OS can use this hypercall to notify the page encryption status. If the page is encrypted with guest specific-key then we use SEV command during the migration. If page is not encrypted then fallback to default. The patch adds new ioctls KVM_{SET,GET}_PAGE_ENC_BITMAP. The ioctl can be used by the qemu to get the page encrypted bitmap. Qemu can consult this bitmap during the migration to know whether the page is encrypted. [1] https://developer.amd.com/wp-content/resources/55766.PDF While implementing the migration I stumbled on the follow question: - Since there is a guest OS changes required to support the migration, so how do we know whether guest OS is updated? Should we extend KVM capabilities/feature bits to check this? TODO: - reset the bitmap on guest reboot. The complete tree with patch is available at: https://github.com/codomania/kvm/tree/sev-migration-rfc-v2 Changes since v1: - Add support to share the page encryption between the source and target machine. - Fix review feedbacks from Tom Lendacky. - Add check to limit the session blob length. - Update KVM_GET_PAGE_ENC_BITMAP icotl to use the base_gfn instead of the memory slot when querying the bitmap. Brijesh Singh (11): KVM: SVM: Add KVM_SEV SEND_START command KVM: SVM: Add KVM_SEND_UPDATE_DATA command KVM: SVM: Add KVM_SEV_SEND_FINISH command KVM: SVM: Add support for KVM_SEV_RECEIVE_START command KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command KVM: x86: Add AMD SEV specific Hypercall3 KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall KVM: x86: Introduce KVM_GET_PAGE_ENC_BITMAP ioctl mm: x86: Invoke hypercall when page encryption status is changed KVM: x86: Introduce KVM_SET_PAGE_ENC_BITMAP ioctl .../virtual/kvm/amd-memory-encryption.rst | 120 ++++ Documentation/virtual/kvm/hypercalls.txt | 14 + arch/x86/include/asm/kvm_host.h | 4 + arch/x86/include/asm/kvm_para.h | 12 + arch/x86/include/asm/mem_encrypt.h | 3 + arch/x86/kvm/svm.c | 573 +++++++++++++++++- arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 29 + arch/x86/mm/mem_encrypt.c | 45 +- arch/x86/mm/pageattr.c | 15 + include/uapi/linux/kvm.h | 52 ++ include/uapi/linux/kvm_para.h | 1 + 12 files changed, 864 insertions(+), 5 deletions(-)