From patchwork Wed Nov 1 21:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10037627 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 6EC98603B5 for ; Wed, 1 Nov 2017 22:08:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 606AA283FF for ; Wed, 1 Nov 2017 22:08:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5495728C18; Wed, 1 Nov 2017 22:08:05 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBEBF283FF for ; Wed, 1 Nov 2017 22:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933321AbdKAWHp (ORCPT ); Wed, 1 Nov 2017 18:07:45 -0400 Received: from mail-bn3nam01on0043.outbound.protection.outlook.com ([104.47.33.43]:12256 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933504AbdKAVRA (ORCPT ); Wed, 1 Nov 2017 17:17: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=SINkEqTZzJtq8kWSGXNKz/TNnRgcIi+370r80w0zk2U=; b=Gf8NAm42Y01TwY43pEuLTLlYAqW29H/Re4C+KwwzUpxy7gzmUgw5/yGkKSmf3KiDp/JqWo97LSP/rXeG+qFOjobIaqgLzi/qpoQOmu/g/bPqnoz0SCb0GPrucEOB7gV6FKbiW/I+tjyIzQFdMjagAXXz+2WTmTJ4uyTt4EDilXs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Wed, 1 Nov 2017 21:16:45 +0000 From: Brijesh Singh To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bp@alien8.de, Brijesh Singh , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Borislav Petkov , Herbert Xu , Gary Hook , Tom Lendacky , linux-crypto@vger.kernel.org Subject: [Part2 PATCH v7 14/38] crypto: ccp: Implement SEV_FACTORY_RESET ioctl command Date: Wed, 1 Nov 2017 16:15:59 -0500 Message-Id: <20171101211623.71496-15-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171101211623.71496-1-brijesh.singh@amd.com> References: <20171101211623.71496-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR06CA0064.namprd06.prod.outlook.com (2603:10b6:3:37::26) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1292578-7d4b-40b4-9d0a-08d5216ddb51 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(2017052603199); SRVR:D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9ezxBqxstbkhYjNvcjNuVhkzqaiFMyElPUKN73NTCWHxHfi1vUtKjlqc7ndaZST8eEUyUMvtABrVie/PNsOTYt00UO/B0LWP84r7DZ6MUWRIWF6K2u+ddoUztRn9GB+ydi37GkU80TLtprUzXRBRhd8dn4YwzFhKw+klZXcpuasPTmhu8zs6Tm3Nzbx+s77W9yogm0m8libkV7J1RDLcsZhAmWVJTwvs7TXES0eI7cJC2fdaTegYoykenbuYIDP5oCOahb6llYTWKGtwJF4QEO1xW9ePl2MlY3CgfG+9IN5rQ4723fkENh3C2DVR6FQ6V8KqtfObJp6ErQq43z284jvX6EPEfY1i2h4wxmOxDJyqG6Qe4xa2DQu/6MKE2HGi5ThxMot4DsoyaqzQfv+rP; 4:zQ28IQkjA7EyrSIhwP1sMWADSf+LkjmLmSCat2qEIBh/j+UxnsPv8pRDMpt667+tpCroevQX4ALn0Sx+1X/MBPABtfKafP6u28p2zYAMAhZzGLJx8Z+g90tiIxKzzGu+yGTdF+bsAUaBsPmLYpJy26D7qbX6YcEJbOJWy8+/11Z7gc6XN6bYDdxMlonMgiQa2jLzz7T3ULTYXmR57s91I5dynjz9RYpxuWvo3T+NB0Q9n4II0197mBYGFdsIKsG1gv0MJUErgMzt9matip4vSjgqV3QEFsp1W16FC+4vjO2W20zBThe/N6iaaXq7Hey2qIRWCrsEfFTNRiv4ceYNaQ== X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3231020)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 0478C23FE0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(189002)(199003)(1076002)(6116002)(97736004)(66066001)(50466002)(3846002)(25786009)(4326008)(54906003)(316002)(8676002)(47776003)(36756003)(23676003)(50986999)(478600001)(81156014)(81166006)(105586002)(53416004)(53936002)(189998001)(106356001)(2906002)(16526018)(2870700001)(76176999)(33646002)(305945005)(7736002)(86362001)(5660300001)(6486002)(101416001)(50226002)(68736007)(8936002)(2950100002)(6666003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:wsp141597wss.amd.com; 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?MTtETTJQUjEyTUIwMTU1OzIzOjV1MEE2TFVPNm9Sa3I5aVBZNFdhZndjd3dN?= =?utf-8?B?V1d0S29COERTRzNzemhjbFZ1T1VPSGxqU01DY3hzZGVWWWxYbDhLWnhYQWIv?= =?utf-8?B?VVdvN1haN0pKZE5ybE1CT3JiK0FIbXllcVRTcDZFK2kwWTQ3d0UwL2swQ2di?= =?utf-8?B?V0dxcVJxL21iNnJJVkZYaWZOQjZiZzlIZmNVUS9NcWpKQUE1UlRxT3I2Sk1Y?= =?utf-8?B?Ty9GU3ZmUHFDYzFOMTZhNTVxQUM4N3JVUjJ1MFZFS3MyUDFjaDRXSU5NUmt1?= =?utf-8?B?SEYvQW5RSmQySWtNbDdKREpNeGsvNUFjSmI3WjdrUHBYemlvMDhvTTVRZG92?= =?utf-8?B?YWY5VFJ1SHJyaXBLN0EyZDgzT1JyOFFhUmdQNnI5T2RyYTI0NmpycFN4b0xY?= =?utf-8?B?WU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nlXZ6Hg/HtNR3FvcsmeBr2zt+2NLWO5xDtGuKzwQpWgFM5okXcYNBS84ITGxg11cHOZTA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:yFJ5SjMoofbDcNKaNZ8ku6+6nI7DZGXQAeahsX7vSNMVePiXB3tWToIQ2zfLlKwQQ3PCG11aQjPeERb8F2zcoiLFzCneUhkS+t84XybG4nVAUu8icno4ih82yC6Ky3p0Bi1p36yhs4p7y1Oq/QeWV2W6txjTwifhSYmwnCZnWGvz0CpbglQsc++I0uzXaVosGpt779o6HpL4Bp46zJFyf0uGB8SILn3o9QxHtGKbVZP90CA1NlmqpSkZYrdS95Kq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 21:16:45.1097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1292578-7d4b-40b4-9d0a-08d5216ddb51 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SEV_FACTORY_RESET command can be used by the platform owner to reset the non-volatile SEV related data. The command is defined in SEV spec section 5.4 Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Borislav Petkov Cc: Herbert Xu Cc: Gary Hook Cc: Tom Lendacky Cc: linux-crypto@vger.kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Improvements-by: Borislav Petkov Signed-off-by: Brijesh Singh Acked-by: Gary R Hook Acked-by: needs to go away too if you send a new revision with --- drivers/crypto/ccp/psp-dev.c | 70 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index c61ca16096ca..a757bd1c34e8 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -235,9 +235,77 @@ static int sev_platform_shutdown(int *error) return rc; } +static int sev_platform_state(int *state, int *error) +{ + int rc; + + rc = __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS, + psp_master->sev_status, error); + if (rc) + return rc; + + *state = psp_master->sev_status->state; + return rc; +} + +static int sev_ioctl_do_reset(struct sev_issue_cmd *argp) +{ + int state, rc; + + rc = sev_platform_state(&state, &argp->error); + if (rc) + return rc; + + if (state == SEV_STATE_WORKING) { + argp->error = SEV_RET_INVALID_PLATFORM_STATE; + return -EBUSY; + } + + if (state == SEV_STATE_INIT) { + rc = __sev_platform_shutdown_locked(&argp->error); + if (rc) + return rc; + } + + return __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET, 0, &argp->error); +} + static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) { - return -ENOTTY; + void __user *argp = (void __user *)arg; + struct sev_issue_cmd input; + int ret = -EFAULT; + + if (!psp_master) + return -ENODEV; + + if (ioctl != SEV_ISSUE_CMD) + return -EINVAL; + + if (copy_from_user(&input, argp, sizeof(struct sev_issue_cmd))) + return -EFAULT; + + if (input.cmd > SEV_MAX) + return -EINVAL; + + mutex_lock(&sev_cmd_mutex); + + switch (input.cmd) { + + case SEV_FACTORY_RESET: + ret = sev_ioctl_do_reset(&input); + break; + default: + ret = -EINVAL; + goto out; + } + + if (copy_to_user(argp, &input, sizeof(struct sev_issue_cmd))) + ret = -EFAULT; +out: + mutex_unlock(&sev_cmd_mutex); + + return ret; } static const struct file_operations sev_fops = {