From patchwork Tue Sep 13 14:49:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C8616077F for ; Tue, 13 Sep 2016 15:55:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEC78293D2 for ; Tue, 13 Sep 2016 15:55:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF82729409; Tue, 13 Sep 2016 15:55:39 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62FD9293D2 for ; Tue, 13 Sep 2016 15:55:38 +0000 (UTC) Received: from localhost ([::1]:49778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjq3d-0006uG-A5 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 11:55:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpXO-0004Nj-OF for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjpXJ-0001qI-Ne for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:18 -0400 Received: from mail-co1nam03on0076.outbound.protection.outlook.com ([104.47.40.76]:29120 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjpXJ-0001ng-D2 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 11:22:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LQxEDSq+J2853XDbVnDPUxxiEjYq8tXPAioTn69xWUY=; b=mPsDmY3eWt1n0iJjKYa7n/3kotQ2zV6mofj0IQxsmsld26qtxZtVJ4WOp5YKXI68nU8mprVyPDNyH7K00Sav7RZYmMaUwt+t31OGm82iJG5g/Eid/s+0d9Rf3qRmxrNqMVayF1MDKvOiZmYWDPRgMwc+8LFuykIdDdudoV30Vi4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BY2PR12MB0664.namprd12.prod.outlook.com (10.163.113.153) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.619.10; Tue, 13 Sep 2016 14:49:15 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:49:09 -0400 Message-ID: <147377814959.11859.7290655535312541199.stgit@brijesh-build-machine> In-Reply-To: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> References: <147377800565.11859.4411044563640180545.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR08CA0064.namprd08.prod.outlook.com (10.141.200.44) To BY2PR12MB0664.namprd12.prod.outlook.com (10.163.113.153) X-MS-Office365-Filtering-Correlation-Id: 8318442a-7ad9-45fd-b2c1-08d3dbe522cc X-Microsoft-Exchange-Diagnost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vdEZh66sSePem5CZq+PT3XVI4TMJ/QjyA36d8EA=; 20:xQFne96FQmtuNbvYU0L1BimEUhmFTEnEpY0pcqIxn3lIvriStZiskb70Xpa9b+Cm3/ZPtTd4vq+qYTKqSZMlGHhhLorN7C6eMZGYINukzblBN8Oh4PATNj71Q8RqXDF4hJEcdL6HjtWDb/wiHm5GP3wpW+0gj7clLyzFJT7OouYCjCpBkFhCov2ps6iio+0LfNA0Tkz3NQKa7SFbSfyWRt5b2MI5xPIFBpzKFzdiNQvnpKZAfPcDqQJUFNFB4koVc0BvtwZIaAKptpMAO1d62UsYc7h8gsLJy+D04Jyfa+VCArBpQUkLwKYP/stwiQRaHDv9pdmoFOldysLW9s+ureK87NVfPBRt0ernwZ2/t0jWMRx0E+7UtvLWRLSr1w8ge0/6Q6BYhx4LCd02pwpLXxTmfW6W7Ti/dTWVjt2y11dRkvl/2054p68oL3UmLh4DBuhTPZleFvc+yhkLC836Jabz6Q6GgJK0URSwmXCTnNqCAQjiFLI86vvqDDRsLZPz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BY2PR12MB0664; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0664; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0664; 4:CoovsKtRPEH2MTOraF6zjDBBl8zWJ82lvXMg0p9m/oDp89ihNoe0t3QRisA+V1iTKCSy8JyA8a6Yam5WE7PtEYe6ROvycv32vwa0hzXygI5GQ8GTBa8olJhhZyIVL0cmdkeaAzea+Og6ruEdIbPh+52GesORs9usgELX9b16pHcJC1Bnu0uYu8Bppvr1qEOsTHgkr/UwOHsZwGIsvDKN7fSwLxdUITgJw3vNa5zxLPBrQ2azVqzVpCuEmqpNYsyBan7wN0ZmexzIfMyJYkxpMk+ZbXuLpiG8hMtMYZG56dAVa9+JtCDOIzDv2zTlhazYAstRFsSphJ1NFIk6xdWYgmj1DWcJ7R6YBtA5Z/ShOwKbgh+K+rPx1MdLkdq3TVwjIw7S0nzrg9J4penF5dY50QHErA8QbaXil01zBLkR6RPiRTaC8hPl+RH5InSTqofA X-Forefront-PRVS: 0064B3273C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(4001350100001)(92566002)(7846002)(107886002)(97736004)(7736002)(5001770100001)(77096005)(81156014)(9686002)(42186005)(105586002)(2950100001)(8676002)(103116003)(19580395003)(5660300001)(50466002)(81166006)(19580405001)(229853001)(106356001)(33646002)(33716001)(66066001)(101416001)(3846002)(47776003)(76176999)(50986999)(6116002)(2906002)(54356999)(23676002)(189998001)(2201001)(68736007)(230700001)(86362001)(83506001)(305945005)(586003)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0664; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjEyTUIwNjY0OzIzOmJES052YXp0SlNHYWRoNkt6ZXBITG9WM1Fq?= =?utf-8?B?Z1hxYURCbmZacmNpalRWbEM4ZFE0UnRNYk9QNjR1SDZVZ1ZhNG5uOEE4NlFo?= =?utf-8?B?TDVWbFNtNm91b2kzRWVsbFp4aTV1WURkY29RVjBpVkhweFhCUkpRcGVuWkVW?= =?utf-8?B?bjVXc0dKRmxMZ1ZabG5qbXFCQTMyd1Ywa0lPenN1SGtxY2FGSmRhRWNZdVhW?= =?utf-8?B?VE5KNWRGRWUzUVZNWkhEZ2Q5ODk3ZUlERmp3WHVpbjcveWd5RVYyQ0xCQkhN?= =?utf-8?B?ZFkxV01ZWk1KcENJcEUwQmpaa0RqSG80c0tjQ3kxT0Rzazg4K0VXbEVwVzg5?= =?utf-8?B?MTgx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om1ngOFBA==; 24:I79lsALcH5TyGnPZ3Cb79iYHEXKzj3pRQLh0MlIx42Bhgd9QhsLz7Z7TWNlIJv5e4kcwNBagveVJZ23PjQlm8Rkal1JOJVBJOpqZNPTEBao=; 7:6ewo1j79n9VpIPkQu3+UH9rdcufftJL2PZYhNKvfRIWx7pwSkf86GCult0flAKaxzd5ZhfTKOxF6TjtxrxOZP5AWr1MRUpOQWCso8y0N35jyPROIv8mucyLY7Z7YpFzVASYsvqW8z7nSQc+4MMSUcrQANdT6GPtYVijItKPNW1ifi3A6vPCPQphE/dFuOQTRk3Wx53CGgi9z9WlTBjUtl2ugdxvK1jAo1f8FxegOR+HuQdlY9VZTjhg2uSDpxTFd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0664; 20:vM2XpDrff6DfvYbAGeau4YEQ/+XuI2a5Ql51FuoPoiCeAUqvBZtxoA/9FwgRtAnFCeOg9Su8SeF010Ae7Pz/M/L8zDan9PNjc/AUFSR/q9O9Puv4hUUwgHhJRpULx66UmAjqA0J2z87PXRQv3FXyG2upvn0ZJpdmoqzCUGGjIRIwX3Lp8jRrF+sLVdxfmc7TzPIZkS/Ke0QqqH079+9NLr0I+QfXhkHZ6pLzCQ/MKcjSY2r+MG+cp0/4GRMMMZE7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:49:15.5126 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0664 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.40.76 X-Mailman-Approved-At: Tue, 13 Sep 2016 11:45:47 -0400 Subject: [Qemu-devel] [RFC PATCH v1 14/22] sev: provide SEV-enabled guest RAM read/write ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The patch implements kvm_sev_get_ram_ops() which provides guest RAM read/write callback. Depending on the memory attributes and guest launch state, the callback will use SEV launch update or SEV debug commands to read/write into guest memory. Signed-off-by: Brijesh Singh --- include/sysemu/sev.h | 8 ++++++++ sev.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index e8fa62f..ec2dfde 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -15,6 +15,7 @@ #define QEMU_SEV_H #include "sysemu/kvm.h" +#include "exec/memory.h" typedef enum SevState { SEV_STATE_INVALID = 0x0, @@ -93,4 +94,11 @@ int kvm_sev_dbg_encrypt(uint8_t *dest, const uint8_t *src, uint32_t len); */ int kvm_sev_get_status(SevState *state, char *str); +/* + * kvm_sev_get_ram_ops - get MemoryRegionRW ops. + * + * Return NULL on failure. + */ +MemoryRegionRAMReadWriteOps *kvm_sev_get_ram_ops(void); + #endif diff --git a/sev.c b/sev.c index 508eff2..c1135c4 100644 --- a/sev.c +++ b/sev.c @@ -72,6 +72,8 @@ typedef struct SEVInfo SEVInfo; static SEVInfo *sev_info; static const char *cfg_file; +static MemoryRegionRAMReadWriteOps sev_ops; + enum { LAUNCH_OPTS = 0, }; @@ -512,3 +514,47 @@ int kvm_sev_get_status(SevState *state, char *msg) sev_state_msg[*state]); return 0; } + +static inline int sev_read(uint8_t *dst, const uint8_t *src, + uint32_t len, MemTxAttrs attrs) +{ + if (attrs.sev_debug) { + return kvm_sev_dbg_decrypt(dst, src, len); + } + + memcpy(dst, src, len); + return 0; +} + +static inline int sev_write(uint8_t *dst, const uint8_t *src, + uint32_t len, MemTxAttrs attrs) +{ + SEVInfo *s = sev_info; + + /* If we are in SEV launch stage then use launch_update command + * to copy and encrypt the data into guest memory. + */ + if (s->state == SEV_LAUNCH_START) { + memcpy(dst, src, len); /* copy data into guest memory */ + return sev_launch_update(dst, len); /* encrypt the data in-place */ + } + + if (attrs.sev_debug) { + return kvm_sev_dbg_encrypt(dst, src, len); + } + + memcpy(dst, src, len); + return 0; +} + +MemoryRegionRAMReadWriteOps *kvm_sev_get_ram_ops(void) +{ + if (!sev_info) { + return NULL; + } + + sev_ops.read = sev_read; + sev_ops.write = sev_write; + + return &sev_ops; +}