From patchwork Thu Nov 2 17:10:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 10039029 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 B428160291 for ; Thu, 2 Nov 2017 17:10:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 933282917B for ; Thu, 2 Nov 2017 17:10:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8813929193; Thu, 2 Nov 2017 17:10:47 +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,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 0B34C2917B for ; Thu, 2 Nov 2017 17:10:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755389AbdKBRKb (ORCPT ); Thu, 2 Nov 2017 13:10:31 -0400 Received: from mail.skyhub.de ([5.9.137.197]:52080 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755303AbdKBRK2 (ORCPT ); Thu, 2 Nov 2017 13:10:28 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id miL5RRZA82zQ; Thu, 2 Nov 2017 18:10:26 +0100 (CET) Received: from pd.tnic (p2003008C2F23460091593D637B149CF5.dip0.t-ipconnect.de [IPv6:2003:8c:2f23:4600:9159:3d63:7b14:9cf5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 92E291EC02FF; Thu, 2 Nov 2017 18:10:26 +0100 (CET) Date: Thu, 2 Nov 2017 18:10:17 +0100 From: Borislav Petkov To: Brijesh Singh Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Herbert Xu , Gary Hook , Tom Lendacky , linux-crypto@vger.kernel.org Subject: Re: [Part2 PATCH v7 13/38] crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support Message-ID: <20171102171017.t7auzgm7zqp4ncjb@pd.tnic> References: <20171101211623.71496-1-brijesh.singh@amd.com> <20171101211623.71496-14-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171101211623.71496-14-brijesh.singh@amd.com> User-Agent: NeoMutt/20170609 (1.8.3) 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 On Wed, Nov 01, 2017 at 04:15:58PM -0500, Brijesh Singh wrote: > AMD's new Secure Encrypted Virtualization (SEV) feature allows the > memory contents of virtual machines to be transparently encrypted with a > key unique to the VM. The programming and management of the encryption > keys are handled by the AMD Secure Processor (AMD-SP) which exposes the > commands for these tasks. The complete spec is available at: > > http://support.amd.com/TechDocs/55766_SEV-KM%20API_Specification.pdf > > Extend the AMD-SP driver to provide the following support: > > - an in-kernel API to communicate with the SEV firmware. The API can be > used by the hypervisor to create encryption context for a SEV guest. > > - a userspace IOCTL to manage the platform certificates. > > 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 > --- > drivers/crypto/ccp/psp-dev.c | 350 +++++++++++++++++++++++++++++++++++++++++++ > drivers/crypto/ccp/psp-dev.h | 24 +++ > drivers/crypto/ccp/sp-dev.c | 9 ++ > drivers/crypto/ccp/sp-dev.h | 4 + > include/linux/psp-sev.h | 143 ++++++++++++++++++ > 5 files changed, 530 insertions(+) Some more cleanups: * If sev_data_init is per psp_device, you can simply embed it in the struct psp_device and save yourself the complete allocation. * s/sev_ops_init/sev_misc_init/ because it doesn't do anything ops-like * save some header lines. diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index c61ca16096ca..81c70f9ce23c 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -186,7 +186,7 @@ static int __sev_platform_init_locked(struct sev_data_init *data, int *error) return 0; if (!data) - data = psp->sev_init; + data = &psp->cmd_buf; rc = __sev_do_cmd_locked(SEV_CMD_INIT, data, error); if (rc) @@ -282,7 +282,7 @@ static void sev_exit(struct kref *ref) misc_deregister(&misc_dev->misc); } -static int sev_ops_init(struct psp_device *psp) +static int sev_misc_init(struct psp_device *psp) { struct device *dev = psp->dev; int ret; @@ -319,10 +319,6 @@ static int sev_ops_init(struct psp_device *psp) if (!psp->sev_status) return -ENOMEM; - psp->sev_init = devm_kzalloc(dev, sizeof(*psp->sev_init), GFP_KERNEL); - if (!psp->sev_init) - return -ENOMEM; - init_waitqueue_head(&psp->sev_int_queue); psp->sev_misc = misc_dev; dev_dbg(dev, "registered SEV device\n"); @@ -338,7 +334,7 @@ static int sev_init(struct psp_device *psp) return 1; } - return sev_ops_init(psp); + return sev_misc_init(psp); } int psp_dev_init(struct sp_device *sp) diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index 2236d6749d2e..fa62ff50912b 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -77,7 +77,7 @@ struct psp_device { wait_queue_head_t sev_int_queue; struct sev_misc_dev *sev_misc; struct sev_user_data_status *sev_status; - struct sev_data_init *sev_init; + struct sev_data_init cmd_buf; }; #endif /* __PSP_DEV_H */ diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index fb563248d9a9..d57cd7625a9f 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -626,11 +626,7 @@ sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; static inline int sev_guest_df_flush(int *error) { return -ENODEV; } static inline int -sev_issue_cmd_external_user(struct file *filep, - unsigned int id, void *data, int *error) -{ - return -ENODEV; -} +sev_issue_cmd_external_user(struct file *filep, unsigned int id, void *data, int *error) { return -ENODEV; } #endif /* CONFIG_CRYPTO_DEV_SP_PSP */