From patchwork Tue Sep 13 14:47:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329583 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 D914A60231 for ; Tue, 13 Sep 2016 17:16:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C45AB29085 for ; Tue, 13 Sep 2016 17:16:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8DBA29475; Tue, 13 Sep 2016 17:16:23 +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 04ACB29085 for ; Tue, 13 Sep 2016 17:16:23 +0000 (UTC) Received: from localhost ([::1]:50421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjrJm-0006gy-6G for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 13:16:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjqSm-0003lv-54 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:21:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjqSg-00042f-Eg for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:21:35 -0400 Received: from mail-bn3nam01on0051.outbound.protection.outlook.com ([104.47.33.51]:20960 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjqSg-000428-6f for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:21:30 -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=SD1YCQypVEitabQJyfyjP2Yg+ekCrz9N0vfVXsZX/y8=; b=OUYKeaOnwh7h+aFaDhJrOoI3HskamD6g6w4+8P1fyVGgnunuWdbqDdtoYipUXFQQDJgeH3fFmPacgA5qbacrZut4yfJQyqn7RvyLwCL4F+l5N0zZpW0giah6K9hUSyvSx75QmWlMmCIu5AiJPD/1/CvNXznjjyFM6gFGVr8bLC8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BY2PR12MB0663.namprd12.prod.outlook.com (10.163.113.152) 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:48:03 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:47:58 -0400 Message-ID: <147377807842.11859.9369429600797537189.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: BLUPR08CA0056.namprd08.prod.outlook.com (10.141.200.36) To BY2PR12MB0663.namprd12.prod.outlook.com (10.163.113.152) X-MS-Office365-Filtering-Correlation-Id: 5c569434-109a-41af-1d89-08d3dbe4f81f X-Microsoft-Exchange-Diagnostics: 1; BY2PR12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P5a7eh0Say8L6Zhva63OWw9wNoxiLBlThHhk7MHIidv8pb/rACq1MnBDjRV5oTrUYvZSyw87KBUBYYhbsI4+PZ/xDuCa+98sH3i74sR94t14N5+JDzwq6r97mxatdAypHvrsmAWDRc1Vv9stPqmRjJrCfHWHG5mDeCw/IUoTL9ySRkDJQTrMu X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0663; 31:PTCxP2SkPlqGXO3+q7A8bHyTjVET+uHz8aCMkf0/1kctI6RuhSZ+fgfPkhNm506pWVgsfruCTWElWwc2MiimB+KIMoDNCQuv517Qd4JXn33xibpH0jwrTkKjiXvcuLCLwkl8E72xhI4ZnvUobPmiTVT5RNzih6TvKkb/LwUKkNfyfDfcPrO0syN66qYjxWuCxdV6RZNxNDr0nEJ4GwAvPaW4VcVIQcowBnk6z8YiCRs=; 20:Mf/FyqSmOQd2xJPIg6jf7cfCv/7+vQdf4OYI0B3cIX1WMQUGmStd4YW8E4Is5Yh0d8rCd2VlH3sFi7CLXd07ZwzLd+WXqq1/pOTMt73o3oW19I2CtiMPSddU3bC0KQwHA1j05tCJWFcfpEsWn2Q8TPSk7w1xg5gMOfpBpt6AgxxPVhXwQQgBj7RqWKSD+VFPwZ5oi7aLABNFP1FiFE3hnlbuLHuShfLo18+kJjkpXLU1rqgViH+kOMEOeTki7pEFI4b+P4PpLVogDMJjJjXpD9MufKkRsul9FFbKtiif+zjtJRMPEyx+hrGysbJJDafL/GAEzW5MgTMA9UuQ4P4gNbAXCizQpSMRcEq6KlJ6sgp2ryX46/8hv5ZiNcm2rSXQ22X8sMTih8ZllotVcWKJudc+amEHogke5lOulswEnAinfupqdnXVPxYXiXBfkyW6xV0R7vIlmkCTjZgNkQWr9UmImKhHqzqxZ5m96r0dzAD+vKRg0iZ5F+tk0nxFp0dR 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)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BY2PR12MB0663; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0663; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0663; 4:oMsP74VgZiQQKj+4zwnmMkr3DgUY0PBS2Grj31kdHnEHuqH14Hl+JBgA5oKATxtUCbiD91CIB/oY/ReMQI30c/bGcXY0sREeYy4bWS/7cKYNDs+ql27NacThklotSMGpBY9Zj3No4lfpKJK5vLEbqT1XQ9MPovMqXbw0IE7ObaFpPBuEi20UlK/BHR+JlPwUux69nw51O9eDMUD91sYwwr+xN2R/TkzxPFKBhGVmz5ru9u77L3JEyFnl6TawrOldK24okZ44xUM7KJtZuZQtaqkOasHshDzknDPebq3mY+OdVbI2wqmsbq2ZOL1JoZL72wAVL5CqLKujD9/NoyWsf7gZVMBz/M9crxcXaGyBv9rKhYBgUYMGcWAB+g+1/MeWDQhhr9BQzv4qKUTZgkeuynnV1zlVf1OA3RVQ4BpOog8cmet9imlqi5zKeB0oG9Bu X-Forefront-PRVS: 0064B3273C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(209900001)(199003)(189002)(33646002)(47776003)(103116003)(66066001)(83506001)(105586002)(229853001)(50466002)(42186005)(2950100001)(5001770100001)(15975445007)(230700001)(2201001)(86362001)(97736004)(77096005)(4001350100001)(107886002)(7846002)(9686002)(81166006)(68736007)(76176999)(8676002)(50986999)(81156014)(7736002)(54356999)(19580405001)(19580395003)(189998001)(101416001)(92566002)(5660300001)(106356001)(6116002)(305945005)(586003)(15395725005)(23676002)(2906002)(3846002)(33716001)(217873001)(6606295002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0663; 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: =?utf-8?B?MTtCWTJQUjEyT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DTU0zb2I4WTZ1eHVFVVlz?= =?utf-8?Q?lBPEo94vgPj4O?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0663; 6:EfkWUJDjJH99HYhTt7NfgAfLXNd45HpfxcngzMO1D3OHSda0EYadb0xMZ5GypBADRvS4mWMGk+lFW+aw36d5t84m9i2o9Yuo8Uteudee8/CrLALAJZg33IK3pCR0IhUxmBv+GvUSaouPyrHy9RuxiNg8MlRFC0Hy4g3Wi+oJvJOHfjROunV7Bv1yG2pZu6Wp3ThS6QaP/eL9CrdWwMjKMIB7CIlfDVM+6QoTbD2KxIOnUK9kxuPjtKfRtaO977iiAJYD6MehiqpQOyvJILdvAUSWKLxZJzvV8j2e0yMBJYpiS3CyPGKD5Nayaar/55OQHklztCxPPd6h+hH+qdGpQw==; 5:FhwiGp+9C5bJc1eKoChn+JznItQRjVtHXCqJoihCNNCfeY5jtyHdhonwHIagCwo5ojbjhs3K91fFPL4xpMliVgWYNOKuJxf1/PJfZDpB/cRgv915G5TvI8ZefeacOhZsKhlB9yRl4sg/8WuWgIhrzg==; 24:Yt6Cum2s+noepCwi38Ngz6gI2DeduN0mY/yvxABZLD7g8gbi8uTH78IeeKwYySPLnXsbWl5s+eBTyWCxp0urZnQx1eikZng2H1THV6d11Yo=; 7:BCJqFdpb4urZYMjVYikK17en3TmjM7w8bnShULF9YU2FVtKA272HikTQidYQBZhJaOXma+GWWWqE/IUPKzj07qxmYrUGcvc9tKde3eoGa8bCXCqRxUnPZ8WIt1/t4ZWIDTE6sWa6ZCect2TQWWofCEeP8Gl+1wQ9KD4clS7OP3FHklijKscDVL63yTkRkaiefi7TrMS9mAQyZMaXgyu+D/fFUKa1yS8fOWvtzkTpaCm6OGwvDzUftJF/qFE6NQfN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0663; 20:f61H8kv/4JJJ+h0kxjqw870OSdwB6QkWLLguryZEKpX9qjZVhZt40uRsVYBh0N+3s8wUQY1BOjCQ7GLidpETB/Is41YEfNWjHo7Rb/A+wSj4zGRg7xtJL5LAhQZUglasjSI7A0QaWF9Uba2ztpdjvwPt7tzk2tYzx8Hhx0YEopOpSmsCMa67b4QtDpKTlL6eG1rqjJFdQZdGTNpOnWVofma8TQZ5bCkUUdD3mYkz/RP3uTl7w/mgE3UsU4DsIZGS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:48:03.9027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0663 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.33.51 Subject: [Qemu-devel] [RFC PATCH v1 07/22] sev: add SEV launch start 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The SEV LAUNCH_START commands is used to initiated the process to launch a guest into SEV-enabled mode. The various parameters needed during this command should be provided through the SEV configuration file. For more information on command structure see [1] [1] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Spec.pdf The following kvm RFC patches defines and implements this command http://marc.info/?l=kvm&m=147190852423972&w=2 http://marc.info/?l=kvm&m=147190946024236&w=2 Signed-off-by: Brijesh Singh --- include/sysemu/sev.h | 7 ++++++ sev.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 0ee8aff..b8a7afa 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -23,5 +23,12 @@ */ int sev_init(KVMState *kvm_state); +/** + * kvm_sev_guest_start - initiate the process to launch a guest into SEV mode. + * + * Returns: 0 on success, or 1 on failure. + */ +int kvm_sev_guest_start(void); + #endif diff --git a/sev.c b/sev.c index 2d71ca6..40a126a 100644 --- a/sev.c +++ b/sev.c @@ -46,6 +46,10 @@ do { } while (0) #endif +enum { + SEV_LAUNCH_START = 0x1, +}; + struct SEVInfo { uint8_t state; /* guest current state */ uint8_t type; /* guest type (encrypted, unencrypted) */ @@ -271,12 +275,63 @@ int sev_init(KVMState *kvm_state) goto err; } - /* call SEV launch start APIs based on guest type */ - - return 0; + return kvm_sev_guest_start(); err: free(sev_info); sev_info = NULL; return 1; } +static int sev_launch_start(void) +{ + int ret; + SEVInfo *s = sev_info; + struct kvm_sev_issue_cmd input; + struct kvm_sev_launch_start *start = s->launch_start; + + input.cmd = KVM_SEV_LAUNCH_START; + input.opaque = (__u64)start; + ret = kvm_vm_ioctl(kvm_state, KVM_SEV_ISSUE_CMD, &input); + if (ret) { + fprintf(stderr, "SEV: launch start failed ret=%d(%#010x)\n", + ret, input.ret_code); + exit(EXIT_FAILURE); + } + + s->state = SEV_LAUNCH_START; + + DPRINTF("SEV: Launch Started\n"); + return 0; +} + +int kvm_sev_guest_start(void) +{ + SEVInfo *s = sev_info; + + if (!s) { + return 1; + } + + /* Guest launch is in progress */ + if (s->state == SEV_LAUNCH_START) { + return 1; + } + + if (s->type == UNENCRYPTED_GUEST) { + /* If we are requested to launch the guest which need to accepts the + * unencrypted images then use the LAUNCH_* command. + */ + + /* parse the config file to get the parameters */ + if (!s->launch_start && + (parse_sev_cfg(s, LAUNCH_OPTS, cfg_file) || !s->launch_start)) { + fprintf(stderr, "SEV: failed to get SEV LAUNCH parameters\n"); + exit(EXIT_FAILURE); + } + + return sev_launch_start(); + } + + return 1; +} +