From patchwork Tue Sep 13 14:48:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9329497 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 C3F4260231 for ; Tue, 13 Sep 2016 17:05:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFEA529340 for ; Tue, 13 Sep 2016 17:05:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A35EB29529; Tue, 13 Sep 2016 17:05:59 +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 E2EB52957E for ; Tue, 13 Sep 2016 17:05:58 +0000 (UTC) Received: from localhost ([::1]:50342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjr9i-0006Rw-3Z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Sep 2016 13:05:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjqTG-0004CU-51 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:22:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjqTA-0004v1-95 for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:22:05 -0400 Received: from mail-bn3nam01on0066.outbound.protection.outlook.com ([104.47.33.66]:38168 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjqTA-0004u5-3d for qemu-devel@nongnu.org; Tue, 13 Sep 2016 12:22:00 -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=DveReDuDbjqbgyYoTsQzeufYcX6EZczXKQBmLQai2AQ=; b=Z8N0kx+m7aRJJwhXuZtvN1vIShFhOJfippDHeQZi9D7F/WblR37Z5yB2B6pDA03GdVUoXO7V1bAP+XKSP4zt4M5OadTNrUNeYntGrGWuK6440IeG5AZXR/3qqZ1tHbBEffMHu9Kx1JLccqXvT7JEnlol2XyMeNdnNHsi4jP8y2k= 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:54 +0000 From: Brijesh Singh To: , , , , , , , , Date: Tue, 13 Sep 2016 10:48:50 -0400 Message-ID: <147377813040.11859.5268138025433994743.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: SN1PR17CA0015.namprd17.prod.outlook.com (10.169.33.153) To BY2PR12MB0663.namprd12.prod.outlook.com (10.163.113.152) X-MS-Office365-Filtering-Correlation-Id: b618de87-5ed5-443c-b3c9-08d3dbe515d3 X-Microsoft-Exchange-Diagnostics: 1; B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nPcX3OYnI=; 20:kPpY0OjEefJp08z4Yu75XWRcrAV202pQb9hh7XHgQPozZfFZ6xp5nElB/75W56ov4QCCGn/3uF7mNZFXoGRhmHzBlalynjuHEE08DifS+Zvok7ymJj9x0pbj51kOhZsAO5APbAmF08r2uzxmL+NoF/zo7jNqFzU4c4yMi5ACYBcagSKZ+f1QrYMfSr4q1esOJIslmPaqMY1kATXoZEgHkOhlL5lnQ1grmAiNPdggExw1AGubvOAQUrEhxM9O+/tE4kyPGKRNvQLF8brWWU6QVC0BtDkQqIkk3SHuICbBNhidaCr7BpZW06UCewkrKAWpaZk/ggl6BoOvtv7aWijLQToycuUg4rXKCqGpnyW3bR1bUHziAkt0al81N5jEK0a9LQIwV9kZn2DXqrIvkcG1obbKFR6EyWJyRLkUMnMOEHyDGsZl+cKeLmxlIg/ffz/nvpeZDdNsW35A+1fjIwem1ievvjuFP/aalsV/xMmiwp5XMx74dR69zEug+6w91x4y 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:OJEsxhr3KSePfZMvbnsxmpB8UrbVq9qfgxa6UMz3ITplmP/F343bA79TQK63Z4i/u3Yhzaxzb/ogiAEqKwE4RkTisJ4faqA6uMyuFKgYwmr17V5h803K3e7r/qRYlei/yxAJEQ1rtGPZgVYWDI+ICJ5I1mYatKszDBGs48KM+XwSw4WKfdkLlF+DPBtnzVdqAv9z3E+ZynLUhJEUNBeL5Iyjr48rhxMcCpxce4Peub7rxORbNsK73SKxpmCBtl2h8kd2p38wMVkTlTAdXOyfm1i/8qiHpQmaT+FfYXkd8KmqpFidrfgsD2zeonEkldqY7+pFXnldR81xgatjeLFEuJeiqXT4hE91Va3dKrce3YIgWH615Y2hbjuG7BfZgad9e0XEP0HwpATv2gbRLG36CskIXTHYUZ/6YWudMfgQtKBVm7TSdfykIjPSOQO0YTFN 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?MTtCWTJQUjEyTUIwNjYzOzIzOmUrWHgrNXNjNmRZS01QbVBkRkV4aGU1WHA1?= =?utf-8?B?Sm5sRnlGM21ScWUzQmFVdHhNOUR0VXhCdWRraThmV3lHOThaNDdpVktjMmhq?= =?utf-8?B?ODBPdnlhTFh3RnE2WWpGcGQ5M3ZxOGFJdnFGcll1RXoybktFNkRkc0VsZXRO?= =?utf-8?B?cW40dWZwV2psTDdnaXpuaEhmWFpjTUZCVkJicHJ3VTBUc2hZV1VEUU1zNFo2?= =?utf-8?B?NTYxVTgyT0JwR0NVdW5leDA0SHJ1RzRlODJ4UTBOYnYxdWVhOHprTklxVHly?= =?utf-8?B?NVVxYXNDUkEyMmRPbkQxUmpHR3F2OEJDMEtVc0RDKzRYNmRsVnJFcHlMbnZD?= =?utf-8?B?ZnRHSUpFMGpvRVNhZUFvUG9WY1NLRjJGTGp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1RoalFbVSOrEVRC7MZAa1Wri6CLf23qPgf+XScjDBOkgFKuO0L5ATuIjbe4X4NW+xXIlkjVIYt6u8C/hOIexu5mO5ix3B7jo1FAK/7CYMhzXM4yhGcpX5D5I02ERg==; 24:k0TRlYbDpzyahUxsaCPhFFhgyiHx1H0ttUk7w0UJymQUAfP6YSswS6TIFugXlUiFViv4pEN7JnUrCE025w0RoQ2QewGzrhujUT983V4i09c=; 7:OZEoAub4h4q5igRrf+CMbdSsUH3C5Oj6VluZUXdd6fEEt4pTIR4JRJZChvesn9X8GMbzKSryt1YvILgR32njQNvEGa1bAlfGqbahHXOJRohr/AXbtSIn4Y/KCtHzXwK/RXhMDL2+V16sZgT9L3ykWFTCKgPD/vD5Pal+ZPxgubGi4pB59+hDe76rcp+ujLOemo6rXZbVOyWYUDjHOTi16RkSjCxdnXu59fS660qvCVzOo1D/QVu4fcT34MrPGKI+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0663; 20:A9a976sXlYLjOINNm3HuPQQzP6T2NZSTCNAymWFRLhn8gSOyEM+Uu7FEhYWdpYtROUWO7AFSF6mn6wH1SB/FFAGK03GSMrhadZVWg5F0zPp0/AmzXiSkTXjz26BeiVpq9rYHVKANf6OFQ7Kfvfo2yBrUt5vaqwkR6gbQYYRoDtOcaO7gnmZvvGoj29RQI3niKzw06qlAUTiruXg8LU0n2mlbmePBgwIXbogKikbxs7NQna5v0Ao195CmQRnzULQj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2016 14:48:54.1614 (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.66 Subject: [Qemu-devel] [RFC PATCH v1 12/22] sev: add SEV guest status 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 command is used for querying SEV status for this guest. For more information see [1], section 6.10 [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=147190852423972&w=2 Signed-off-by: Brijesh Singh --- include/sysemu/sev.h | 18 ++++++++++++++++++ sev.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index a505d75..e8fa62f 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,6 +16,15 @@ #include "sysemu/kvm.h" +typedef enum SevState { + SEV_STATE_INVALID = 0x0, + SEV_STATE_LAUNCHING, + SEV_STATE_RECEIVING, + SEV_STATE_SENDING, + SEV_STATE_RUNNING, + SEV_STATE_MAX, +} SevState; + /** * sev_init - initialize Secure Encrypted Virtualization on this guest * @kvm_state - KVM handle @@ -75,4 +84,13 @@ int kvm_sev_dbg_decrypt(uint8_t *dest, const uint8_t *src, uint32_t len); */ int kvm_sev_dbg_encrypt(uint8_t *dest, const uint8_t *src, uint32_t len); +/** + * kvm_sev_get_status - get the guest status in SEV mode. + * @state - guest SEV state + * @str - verbatim string literal (buffer must be allocated by caller) + * + * Returns: 0 on success and @state will be contain current guest state. + */ +int kvm_sev_get_status(SevState *state, char *str); + #endif diff --git a/sev.c b/sev.c index 4e5da84..508eff2 100644 --- a/sev.c +++ b/sev.c @@ -59,6 +59,15 @@ struct SEVInfo { struct kvm_sev_launch_finish *launch_finish; }; +const char *sev_state_msg[] = { + "error", + "launching", + "receiving", + "sending", + "running", + "unknown", +}; + typedef struct SEVInfo SEVInfo; static SEVInfo *sev_info; static const char *cfg_file; @@ -478,3 +487,28 @@ int kvm_sev_dbg_encrypt(uint8_t *dst, const uint8_t *src, uint32_t len) DPRINTF("SEV: DBG_ENCRYPT dst %p src %p sz %d\n", dst, src, len); return 0; } + +int kvm_sev_get_status(SevState *state, char *msg) +{ + int ret; + struct kvm_sev_guest_status status; + struct kvm_sev_issue_cmd input; + + input.cmd = KVM_SEV_GUEST_STATUS; + input.opaque = (unsigned long)&status; + ret = kvm_vm_ioctl(kvm_state, KVM_SEV_ISSUE_CMD, &input); + if (ret) { + fprintf(stderr, "SEV: guest_status failed ret=%d(%#010x)\n", + ret, input.ret_code); + return 1; + } + + *state = status.state; + if (msg) { + strcpy(msg, sev_state_msg[*state]); + } + + DPRINTF("SEV: GUEST_STATUS state %#x (%s)\n", *state, + sev_state_msg[*state]); + return 0; +}