From patchwork Wed Mar 8 20:53:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9611989 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 DCD4B6016C for ; Wed, 8 Mar 2017 21:30:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD0E72863F for ; Wed, 8 Mar 2017 21:30:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEAB728642; Wed, 8 Mar 2017 21:30:35 +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 24A122863F for ; Wed, 8 Mar 2017 21:30:35 +0000 (UTC) Received: from localhost ([::1]:58540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cljAI-0001B3-4P for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Mar 2017 16:30:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clj7A-00078N-C0 for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clj77-0005oU-5g for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:20 -0500 Received: from mail-dm3nam03on0081.outbound.protection.outlook.com ([104.47.41.81]:25600 helo=NAM03-DM3-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 1clj76-0005oL-Ud for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:27:17 -0500 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=/IE7/ZmSxAUHaXWbG2kw86P3EAl05aoxe+IzeAMaFgo=; b=OJ6qrk/6qr9Vd33fvIA5Qz2KI64zn8rRtMMnzSBOL6by2LBp/ifMbdwiWta6sl8eISgcO6Zy0nirX2rUFbnbenVWMJh6hncJM2UoS5P+Cd+zd6nqeNHsTwBNIeI+72mMXSpuUaS6J0pCJEU37b50NfGWPiUcpNR1P9of3bpsfTg= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by DM5PR12MB1610.namprd12.prod.outlook.com (10.172.40.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Wed, 8 Mar 2017 20:54:06 +0000 From: Brijesh Singh To: , , , , , , , , Date: Wed, 8 Mar 2017 15:53:59 -0500 Message-ID: <148900643904.27090.8331322427122591841.stgit@brijesh-build-machine> In-Reply-To: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> References: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR15CA0010.namprd15.prod.outlook.com (10.173.207.148) To DM5PR12MB1610.namprd12.prod.outlook.com (10.172.40.16) X-MS-Office365-Filtering-Correlation-Id: 32e14612-420e-4498-396a-08d4666542ee X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:DM5PR12MB1610; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1610; 3:FAJ1ZjuU1p2vGMz0QZH/S+ZWtfw6NAfn7ma4cwQg/8tQr31xWlYu8CdXVoFgprqm7cePR1glb2cC7pO9/TNv931AYsB3f2VJpyBMArDpXrGpri1AJwedpEABn2ihp/lDOGG30pWd8K4mhA3j8T6gJU534EQJMzRigXa27bIO6FTsrAo982T34AvYd7LeesRwHaYRCbR9NQHDgts879Tyc8S6zTfuXyPHUvf5q7TdLbnyjIh6X0qUajs61iADM5TkcCi5B6jIgNk+UjOnU/krtYdx5Fa5zKtf1YVCN0R8k0M=; 25:lP92Evbvp9ERbcD8BdqMKsR5D9xinfyEUIDlYqEcRfjwHT9zp3CnNXeBP7drHNJV7VwupEvIrIB3VdFUnNh/XWJAKmFQP08L8LhCv1cZbzQpgxXJcG1d/GPnh0/MS5BsaWME8BByLKscrypa4KIXziKPFcT1bVh3Sv07mrXpgMfgzRQYeqm6oUuxvr+56SMjlYEI6UG6R27Ci4W1SOyMYqXHdxL3EwarVzQWO4gS5LuljeS4oE+cxq+fFQeMZapNne6rinG0zDiDa/wjlk2HE8YkbbG16s4CiD94ulEKOm4144PvPbFknK8sbhcFATCCCnB62sq5hgXjRKlI3pfEJdWxOAhmVK7cePOGpeXFMTJWkw2vv2IzcuNf2wsat0k7Hqq/y/CaJlAbyrPKDnF+hYyT87Badcv+pJCJisc1LfqMI3OjlekVatt+biAkuubphM2orXOBqUwZlgxuIHMXhg== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1610; 31:YSqFfViH2LneMtbshQGsypamGaNzUtkwnv15ZYjgfjzlEUM9T1+oJ5GQJas4FoowdxtbZVZEFngRSXo5Gv4t/jnjp2y9Erd3dC/MMym9gjCGGne+yJqYpwIn6Uq3eR5v3SLHrO1AvZ3VwmVqkJPhVxiUYhW36iAgp2mNn2Iq8Mh84wa6KPW9VXW3somFjWoSNUuiQxhbqCqlm6FWlWSfJF230oElesGTULnKi5zxZVH1MOb47ykNriQyoZ9BeB5P; 20:Q5HbVppM4eBh+YXARczBkf/iG3VximEV1Vjs2GRVaXhjUj+CTB4MaqaM7QHWzXd0una0RDgN3SD1swBFWdb7SGgu0H5eHfuou+iYEH14ocNMaaDyLfa+l/0DmTLbdQ7p9YH8+B/J/qz5OzV1dzDZWzsrMGEn/0B9I68qqLeEJbxbiZxuJZL8wAf7Yu4/MVY2VLwTOxbgFrGzKMQ3KgOPLfQmkzBiXYMgs35BHFLsy9IYGsbstH6JpMZ4wqaEDegGXEmzmKu1hvoTTrbyJrLjMc4R/qlfOp5E0lfkUzglw7SDKG36EnjDcDB5YPs0ksHLYxr3gRy5ehYgw+dcmC1e1w58vow2DyKJizs7W6Z5JKljBBuSjwPKBDdYeJevtulneYR2jY0woDip6CYZbai1gnWhkx5vykjJlzCSI0Vt2nkh0vNkk4n+dHXYTvnYTjKxch53R8vHbstBC66h2CE7OJlvPUj3FVUeRVwcHL+XyPoqGOG/+025BSMOUF0wJ1dk X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123558025)(20161123564025)(6072148); SRVR:DM5PR12MB1610; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1610; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1610; 4:g3L/WQ8MS9HEuOu3v2TRttafawcyrPCsxBE5zuIjMvx+lTwskOl9QyVOlbA3h31nPl95s5jPCrHHDY+l+2ZT/jdEtwdjBa3tdLH9BFREeKdulgPgSs3cNhIP6dPDJ00PMxXFUxi+POdh/SlV/ekBLtsfWsD7UsTPgyWmDNRZryOl3HUjtWWZ5QlvHPjMRjqZ+ZEpgO2FImDSAobCHmTU9zHzkF95Awt7ZTwWfk6hnMIKSTdN9O1+KDUIUIMnpJ+EzoSr/QyfwrndMwB2qID1VTAOBhw7S6NT6AkZJzYPcKslRrQbgJd9PgLY1SyMAe6VMv51srUf3UyNpx3eoiyItT9BbAZQebNh1wkJ6P01SBSzZtvPtvQzw20333EcwWfHPkjkW++1fI198ejs1G85Ss5N0iFi+Cu5XcD1GG+Ftl0n7GDmOG8ni4vKYHyDOlRSTR8T4PPiVEGQzIWfQ8/oO82fWy/dwzcay3Mdp4W/0aEOo0hCm2uN4SmhKQXZO4amt1nosEjOJBXua5e9WOCbj7oLNAguFJxw5jSK6fxERvGIq/IUml3P0GxPMVPQcYCOcf4+35kL8JUNFK2r9uWPlvM5Nv/COiqK2WHa9L+l2BAN6kR6UJeAoXR/n0Wjr7Nxm0PCYeq4BAfPcrQ5cwQnzza70LRH7RlkUEVnZgiupuY= X-Forefront-PRVS: 02408926C4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(39840400002)(39860400002)(39450400003)(39850400002)(39410400002)(305945005)(47776003)(5660300001)(33646002)(6666003)(6116002)(3846002)(66066001)(2906002)(90366009)(2201001)(6486002)(7736002)(77096006)(81166006)(230700001)(8676002)(2950100002)(33716001)(86362001)(103116003)(38730400002)(83506001)(42186005)(25786008)(54906002)(50986999)(76176999)(54356999)(9686003)(53936002)(189998001)(50466002)(4326008)(23676002)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1610; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNjEwOzIzOjM3UmtBejRMQkhTNnAzYll6ZGR2eXl6Nkp4?= =?utf-8?B?MjU1aHNZU25tZUVpdytSNWlOdG5paGRzUU1ySkJSNVRCQVhES0NFLzY5UjRB?= =?utf-8?B?ZU9QZFFqZ0J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o=; 5:k8dkA/wdE+AnWuFjUGw0RY6T901frykNU8jfM+DLF+GlWW30L1VGBwZ1gBG1w56570S0vzB61xCBEaQgGTq0yniIPKCz3aQxZz+PlbIU9+6Yv259nSLFgNJRv8ISA/AZTCzj7kGCDtcM77mtz9K+VGju2FbDWrbIjSc9EHBdb7o=; 24:G/t4vnl27bwxzVtIYXYPMX/m9qKSRrb+WsGfkj/K9MJbOJi8IzAXa5IhoSf230WZvh6qgO20B4LL9Pj7S1FvYy4AIFRmJlMgDb64CH+6cZw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1610; 7:93HvwkUJaC4J5aD/94YQZOKO9oWn0TY6ufiLXIrHjNiWoF2YKKLv1sU1FeqG8nB62NNmYLD3kNrIZKc8RT/AAyK2XrFQf1gTAd1HF9wjA5CsvmNj6bbpBTqwxAkGEmssQkyJRlaWF8XgHspImYuby3xEAe3Lw8TQnfumlKxUif/VWapAQyWePDB5KKp9Gmo7KoFyjV6VfcSgPUNFE+XbGiVTSSDgsiu48nLg/VgItEpBjTSCQryhiqlgQifviNhr3DTUy1zGgX6ea/bSp1HsCSfKlu/uKRPpbat+p70FCNutN2+/8gNbYRe6VDA4EVPz0wc4U5C/eAaT9JJXdErSDw==; 20:PdnvqmO8aL9+ug51pcUY8W7k75Uf/0uDImSUqszbbbUyf0h+9LwL1hCvNnSw3Gj45qjE7o8vC/2DJZ9UrwdPk5kvlHxqTayV189Ykjde7x1oX7jxtVaEn8NxKdbfKAbFm2iP4cMGIFfn58FxGD5iho1ALUKqY73bTE328xhUTsBuFOYcShgcpu5jjopy3ozZNHoMywYxoSx6KaIbukq0iDBXTOhry7bMgt/7e/jpg0p0LzQ9c94WAqvcEcYIFiTZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2017 20:54:06.3908 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1610 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.41.81 Subject: [Qemu-devel] [RFC PATCH v4 16/20] 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: Thomas.Lendacky@amd.com, brijesh.singh@amd.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 | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/sev.c b/sev.c index f8d822d..52b75e3 100644 --- a/sev.c +++ b/sev.c @@ -350,16 +350,49 @@ err: } static int +sev_debug_encrypt(SEVState *s, uint8_t *dst, const uint8_t *src, uint32_t len) +{ + int ret, error; + struct kvm_sev_dbg *dbg; + + if (!s) { + return 1; + } + + 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, &error); + if (ret) { + fprintf(stderr, "failed DBG_ENCRYPT %d (%#x)\n", ret, error); + goto err; + } + +err: + 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_memcrypt_get_handle(); - if (sev_get_current_state(s) == SEV_STATE_LAUNCHING) { + if (attrs.debug) { + return sev_debug_encrypt(s, dst, src, len); + } else if (sev_get_current_state(s) == SEV_STATE_LAUNCHING) { memcpy(dst, src, len); return sev_launch_update_data(s, dst, len); + } else { + return 1; } - - return 1; } static int