From patchwork Tue Nov 1 15:54:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9407615 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 87459600C8 for ; Tue, 1 Nov 2016 16:14:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75EF8299A5 for ; Tue, 1 Nov 2016 16:14:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A38C29A62; Tue, 1 Nov 2016 16:14:56 +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 BE831299A5 for ; Tue, 1 Nov 2016 16:14:55 +0000 (UTC) Received: from localhost ([::1]:49011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1biA-000680-V8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Nov 2016 12:14:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1bOL-0006Fq-Cw for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:54:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1bOG-000422-BP for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:54:25 -0400 Received: from mail-cys01nam02on0086.outbound.protection.outlook.com ([104.47.37.86]:12384 helo=NAM02-CY1-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 1c1bOG-00041l-3S for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:54:20 -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=rwwkAbmbey4MIIYOHgfibCqw8XUfnLdji4Sifcrj3yk=; b=wYF+XhtGdUfet6xpBZyoJH5t4QqZwLpZz8IEykfAlW06/SLa4mveMsADf3WVcrD7iFhZqoj4zruX707zAQnLiGSvVIxKZuE5oz3sFOT1su4z423XQHEhCtsPJLPvLV+m7sBURM1q5PTVMMko5o5YsfOcxgJZ0l1UiBeL3GVCqfw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by SN1PR12MB0670.namprd12.prod.outlook.com (10.163.208.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Tue, 1 Nov 2016 15:54:18 +0000 From: Brijesh Singh To: , , , , , , , , , Date: Tue, 1 Nov 2016 11:54:15 -0400 Message-ID: <147801565526.18237.9087833269089838528.stgit@brijesh-build-machine> In-Reply-To: <147801550845.18237.12915616525154608660.stgit@brijesh-build-machine> References: <147801550845.18237.12915616525154608660.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR0501CA0002.namprd05.prod.outlook.com (10.163.126.140) To SN1PR12MB0670.namprd12.prod.outlook.com (10.163.208.28) X-MS-Office365-Filtering-Correlation-Id: ffc7babb-b51e-4aa4-9d84-08d4026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B3JFb3tuf8yuIDAPLf7w75QZPNEyHukiX071gxsHJAuUjihLuVC1p4MQ2jMjjJb66Hkj1dZQYqvMK6pMVzS5bvoNCAgLWnVJpSdhZis/kfy2tVPitpEstyL7KCHBhU3t/Ep9qfBPf/PTOZgWt/G1+ODmiCmEeQQIw== X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0670; 31:tzXa6WmQz92/74nI6/KxoHIo1uFsMV5Uf3oHe1hq/avvPWXurGMJRsUN+jwRawce9gNQuwfNIwJB8wprcablhuHFPTbLiLXLy//WxjSDrfkeKtzfPV6DKkRcqRolyPdlnehcUTWJMLhrtZIWYm4z7ZE43aE1y4Mj5GwNbkbnANrWGphTmJMla7JoT40rpzVJSR6tqTl3MbVXEExMzKWdWVcoikw1Z9a5To+CfAgN9cIK4JvSjqv+WRHycovLI+fV; 20:F6b9JR9dvFyao6vaJqJM2xA7PTjE5egEPfftqX9LxZ2svNiE6qVq4697E1jFRUU7qQ6dImfQmXWSczP0Wmu+jbW1X2gm+G1StexRdFMnZctbfYz5MrkX/Sshy5d6lTjtmy3soqcO1sn9BsfRRV/EQii3aCkMWAPxirGPTirbbH/Gx38ijDHS0IQbtxCgwtAgxdeo0MqRoPR9Qod3ZxoUIDreJeXh/jT7l7Bs4XTSjsmhmNYmONLdD61H3Di5+rNAh4Y/thnvwExuocDemxHvfwBM8sIS4lKhOl5F4PK2Mf1iBKb478TjCXaZ2IrWBVvk58jSYu5Q0hTHctbtN2FLHMEQhihfhRh6N6F+94wgdeyBRGpWOV7vNIp6lqppFLqo0Dxdf4zXjlSxMJxWeVPuOHXW2CBGJNIxtcowBkhs4zPdrpGCmRK0kC/+79Qm5L9x0QhXILJVB4cwjxeb+XBMI6Z9UJQKzs5S2T8Tx5G97+UH2xK3UsM8qnCvKdIREjlt 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)(10201501046)(3002001)(6055026); SRVR:SN1PR12MB0670; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0670; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0670; 4:+H/9O5ZKSPOwQ2bEPDHeqEbKHsCYyoITOMgBztrZaK4vqwfjFRP3kH7a9dBynjGPgi4ElGY2dugFjlu2byEGjNTAaLCbUzhSZOEogru1MM6TfMDgMsmhuQv07uQdNhRfgclHCJDrFuTsEERk2N6DvkY5xFRbnPUOvjlxOCL1FLaoDH4vGNguk9Rd+v73M7KDxxHinQc1+Vgp34LQd9G2V9nQ9mP55eoApRWThLuF6WmL1HVfAEdQFso00hbdWyPA+6ba5FR1W9s4eaza7Tgcxtcek5oyIik/l3jiiV6rVA0ABidyPB480HxnaWoijFmVkamA+lgr0Gmb2Rq3BrizoWrvGFmVu5u8gxYGcoV1jGKFPp/vnd/MNo134NH2ngvOGRa+gkazWs4qgDVxxs1c6xt9yIvwDWstBdErPGk1R5/vkkrap5UuYfZBZzSOffW/v7tRCNX34tvez/oJauM4wA== X-Forefront-PRVS: 01136D2D90 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(189002)(106356001)(586003)(5001770100001)(77096005)(4326007)(33646002)(54356999)(105586002)(103116003)(76176999)(3846002)(50986999)(92566002)(23676002)(5660300001)(97736004)(4001350100001)(6116002)(42186005)(7416002)(229853001)(101416001)(19580395003)(19580405001)(66066001)(68736007)(189998001)(305945005)(2906002)(230700001)(7846002)(7736002)(50466002)(47776003)(2950100002)(6666003)(33716001)(83506001)(9686002)(86362001)(8676002)(2201001)(81156014)(81166006)(921003)(1121003)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0670; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =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Od2PyIOsNDOWSMgGCQEyOkoQ=; 20:HmvLXX7GUL78fFyEuV5Q4CjRoFu1+yO2c/HziT2o27KIh7M0ESmqx/jbfoiprFZAp65s3eBHzoHifPp5gDKFE2pJ17LXrFDj3QOeYEMrjakgXYjlMb/OjnTHI06e8/yW74RI6ijMQ8jhBdKms5iECvXYBq9pAJdqqoDS4Xk0Fk5dvLkW/d7ek8bOFmw3uCE62y5wxAt03hvZ7fj5SoiBjN0Zz1po4KhSHzOmaj+UN11k5jmPvaQF3dGk4TE4iyqh X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2016 15:54:18.1278 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0670 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.86 Subject: [Qemu-devel] [RFC PATCH v3 14/18] sev: add DEBUG_ENCRYPT command 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: , Cc: brijesh.ksingh@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The command is used to encrypt a region of guest memory for debug. The command will be used by gdbserver when writing the data into guest memory for debug purposes (e.g setting breakpoint) A typical usage looks like: cpu_memory_rw_debug cpu_physical_memory_rw_debug_internal sev_debug_encrypt Signed-off-by: Brijesh Singh --- sev.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/sev.c b/sev.c index f690a86..1a579ca 100644 --- a/sev.c +++ b/sev.c @@ -351,18 +351,41 @@ sev_debug_decrypt(SEVState *s, uint8_t *dst, const uint8_t *src, uint32_t len) } static int +sev_debug_encrypt(SEVState *s, uint8_t *dst, const uint8_t *src, uint32_t len) +{ + int ret; + struct kvm_sev_dbg_encrypt *dbg; + + dbg = g_malloc0(sizeof(*dbg)); + if (!dbg) { + return 1; + } + + dbg->src_addr = (unsigned long)src; + dbg->dst_addr = (unsigned long)dst; + dbg->length = len; + + ret = sev_ioctl(KVM_SEV_DBG_ENCRYPT, dbg); + DPRINTF("SEV: debug encrypt src %#lx dst %#lx len %#x\n", + (unsigned long)src, (unsigned long)dst, len); + g_free(dbg); + + return ret; +} + +static int sev_mem_write(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs) { SEVState *s = kvm_memory_encryption_get_handle(); - assert(s != NULL && s->state != SEV_STATE_INVALID); + assert(attrs.debug || (s != NULL && s->state != SEV_STATE_INVALID)); if (s->state == SEV_STATE_LAUNCHING) { memcpy(dst, src, len); return sev_launch_update(s, dst, len); } - return 0; + return sev_debug_encrypt(s, dst, src, len); } static int @@ -486,7 +509,7 @@ sev_guest_mem_enc(void *handle, uint8_t *dst, const uint8_t *src, uint32_t len) assert(s != NULL && s->state != SEV_STATE_INVALID); /* use SEV debug command to decrypt memory */ - return 1; + return sev_debug_encrypt((SEVState *)handle, dst, src, len); } bool