Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932672AbdIGWTp (ORCPT ); Thu, 7 Sep 2017 18:19:45 -0400 Received: from mail-bn3nam01on0044.outbound.protection.outlook.com ([104.47.33.44]:24736 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932647AbdIGWTl (ORCPT ); Thu, 7 Sep 2017 18:19:41 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Cc: brijesh.singh@amd.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Thomas Gleixner , Joerg Roedel , "Michael S . Tsirkin" , Paolo Bonzini , =?UTF-8?B?XCJSYWRpbSBLcsSNbcOhxZlcIg==?= , Tom Lendacky , Herbert Xu , "David S . Miller" , Gary Hook , linux-crypto@vger.kernel.org Subject: Re: [RFC Part2 PATCH v3 02/26] crypto: ccp: Add Platform Security Processor (PSP) device support To: Borislav Petkov References: <20170724200303.12197-1-brijesh.singh@amd.com> <20170724200303.12197-3-brijesh.singh@amd.com> <20170907142737.g4aot7xatyopdfwp@pd.tnic> From: Brijesh Singh Message-ID: <9de7139f-676e-e671-13a1-cbc5170cc816@amd.com> Date: Thu, 7 Sep 2017 17:19:32 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170907142737.g4aot7xatyopdfwp@pd.tnic> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0004.namprd17.prod.outlook.com (2603:10b6:404:65::14) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2ddf8e3f-eb29-49ce-521f-08d4f63e86dc X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1;DM2PR12MB0155;3:p72OLdB3GQMoiMp1ip3M2O7lD6j5P7pdihsqO7vON5F0qMEvY0+fa6WLror0WrxV+g78w3fAykUZMHoWLyEFiIHavjFGOMcfkiG2e31GIiZnkFU4ABfbvPH+l65jF2AG7LhBi4RscU2X4DdYn5nk5KygAB/on1RTmDs2ka3i0phpwcbQtWo/dRRx4zBXOV9EYHBd0+HJR4pD1NV4te0smBf/8gSEG8FEIO5/3rygCYNGEqJJHz7L99Q7JQVzrI4t;25:6QyvstQKeFhlciQkZ25SoCnylo2QgbVSRswgrxoKwD5AWGO+PV4qABlAeFbpVOh/ixkCTLyQRCoI9oWAqHsgdURJYmno86+w8mdrnbwd+dKKDqWehneBDqhhloZGZYNNZ8Q9yEezQbRz0kNG0FsF3V/FWMm8/8fAqpSV0I3illkaLy1Wz/bVfZFqlnJ6EXuxXyjVn1O+3/O227seap6rwnOWJ0NYhTR+i4DgclL42weeCqpRpS8/o6XA70HkEcx3TBP+6rpAQkuVIcCOJC732idYNIWJm/H3P/9gji4nEikwAqITXAPFJaj1uTXbJPfBPC0FVmPbCr/pqgE6u++l4A==;31:BecxieCv1sD7VpGnxv5K4ZPuxgKrfkhkIn6YbD41FcJ94p5Nvgu4HKtyIeuOj6Sa0n4laPK8UfzK8gFtkvko5B+DdF+SyXs7zADxfBt0FSIyqie34tssBtNYTx0lVl+EjEBKs7TGtr6l0HWsN7Ja3fR2bImjKUOlThy7EjIa4zxE+mvumcR/E312GaSxWaUA8bxTADR4NjgbGd1f1G4I5WeyWi+d/MeLU0du8j8NSgA= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1;DM2PR12MB0155;20:lzHsd0xPwiwhtolVzhEGfBfZt1+9oR/m+nBNOgPxu7GOEoot+qnIoD2RYmuyw7II3c+CabhpGhjXp6Oeu31uaDXfq9uaVflL8TKjt7WVbAFUyfbl7bgHK2Ivf+phv+2dCnTPFEyhbijDlP7FN+GkjK4ZJA26WARzqSCKwH3a3VRjJZmS2ERTXutikUT09NjpRxk0CwMt/ozQCOqcgGl7lp+VCt7yBDA/mVt8keSrtw4KFZaTvcOzTJb3Oj9AVMmeca3wny2qKw8og0oYkcUCNonqhwJr77/a5l8aAftAXNLSGPRDeKER+BgrsZn1+vX2IIT1vfXaSBu8R101HxpzyvsstwBeWXsHWvZh2WmYrDJ1ocOt7zcIV+Bv64N42x9ADrRFEqjnenEknTAhLy2HrAMf2UdXXioD7aF5EFsmT73KEiWbcYVfWqvtsdjQol59+e1b0ZgmqcqjcjjMz4kqWyfEYlOiSFfojiVMs3WsVJayCgji/7984x02E5BO0e6N;4:oFS1AjNUDT2U75lyXnrAP13gOpxhZSAHAaIPZx8B2+n/h1ieS39ELBHSq3A+egs5sGdBgb5jUVYGaPrOPqHENrU6kJFIzNoA0xXNorhMEaG/vnqjbSNq4pNPvy4zNI3QKr9fsgI6g495MKIEdIY7NOsr5PsrOpoyL8wPm4L+xnBck0mM6Q6vlAGcNSQ2cjjEIOABdDs8Dr+GB7DBZApBJ2jimhSJGIYXitm5dEnPd7hM5FEC/yjp1oTvWFuZuJOvEXfURCBFIlCa2K9yza+FsJbxD5RzIEmZL/UZX5XQSP4= X-Exchange-Antispam-Report-Test: UriScan:(192374486261705); 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)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(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: 04238CD941 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6049001)(39860400002)(24454002)(189002)(199003)(377454003)(230700001)(15650500001)(31686004)(33646002)(54906002)(50466002)(6246003)(110136004)(53936002)(42186005)(31696002)(105586002)(5660300001)(106356001)(7416002)(65826007)(64126003)(8936002)(81166006)(81156014)(47776003)(8676002)(68736007)(36756003)(305945005)(101416001)(23676002)(4001350100001)(2906002)(229853002)(65806001)(65956001)(66066001)(2950100002)(6116002)(6666003)(83506001)(97736004)(6916009)(7736002)(54356999)(77096006)(6486002)(50986999)(3846002)(76176999)(189998001)(86362001)(25786009)(478600001)(4326008)(53546010);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR12MB0155;H:[10.236.136.62];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTJQUjEyTUIwMTU1OzIzOm82ODBFM3ArVmZ0dlVnN1ZYRkp6ei9CQzcv?= =?utf-8?B?TGZjbzRNblpLVVc2MFZRMzZKZlQvWTBYRm81SWFNZzFaZHNQWmt6R1kza0Fk?= =?utf-8?B?emI3VThlUjNnVndmeG9wZ3o1YXo1N3B2MmVrdVhPQ1Q1THN3bGNoRzdpQnRB?= =?utf-8?B?dllJV1lKNUhPTVVucXRRcklzR3VhWGgzSnpnb1JQOG1wT3d5dDhteE81UEc1?= =?utf-8?B?L0VubEtaaWZxZm1kaExNd3hPS0ZkSWM0dUkwaytERzRHTGF3bWkxUEZuVm1P?= =?utf-8?B?cV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2YeXUjNaTN4mSPjWehSfe4Cfm1LgwuVMt2ThdZZi2Ff1bWTynFlV4P2uc2QX3URSqnawA3jttyl8TxzKFfcJ1K5/5QAneQ3K1U7d7ipvjRP8lCQFRTBvqQUvotx+5mLaYCvZjemDHJ/Iy9Sur1gJ85/pC+iBfUA==;5:GWtnh4+1AblQh6el2nv+ElcgGm82kYpJhLszO1ZQO4EOiFN6EcV6T1thtWNgNyd1tfbmqR50/aWyEbHZXveC4SCWbggnlg75t5aE0HUd4Y7PVHVA1XcnZDDT7yhNEszYbg7eQK4NUIlNOhTisLWRxA==;24:NenLDpemrIbr8pHjobkhZq/6M4gy5uPqz5mlJZO+YUtFi2Dj1pJnoL2gSz0fbtOdH72gs1enPNf4Aqk6TtWX23TsjeuGjKtKFgnwKBTcmlI=;7:fmzBiiNB7dMp4cDmWJvpIQhQL9nE8NasdLhn1v8uNiilWsrykjBV9MnAA5+I5Se7p6mPY2WCGzmm3m2tLcvtig21zN1Q7IV6J6KH6L5c+4bw7oHLRQT3wTDeNnuzLIq4CGELhM0ZKFNNHY+KvbobjuzoXeyz/RFq7lbRCwDKb/xjsrjghcYWbrXZAJtlwM2LpzPMp0fcJGg8OK/vZVfgWLTXVSHtcSx3YdAFNTcpJ4E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM2PR12MB0155;20:8lDNB3Sie0ARNS6S3Mbki+tsAm3vRJeaWai47d3Gd+X2AsnsUOrQHLBg3zSWWCDLL475hANGDDD/sec8t8xZtigwHae8T3ursX+4Z+uqRPRqBbZj+DRYe7lMLfeB30tj5U+kMsiqt6tc8jyLY9pUhR4y7LbPiWk9zOFcskfANx/ityQCv9Dy7DPzs+kyWF7FqTzo5knf1nQarTOWk96ro6wzUem+J9bjMJvQkRSSj0/h469gj6N2ecantQXfzluF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2017 22:19:36.2231 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5690 Lines: 246 Hi Boris, On 09/07/2017 09:27 AM, Borislav Petkov wrote: ... > > The commit message above reads better to me as the help text than what > you have here. > > Also, in order to make it easier for the user, I think we'll need a > CONFIG_AMD_MEM_ENCRYPT_SEV or so and make that depend on CONFIG_KVM_AMD, > this above and all the other pieces that are needed. Just so that when > the user builds such a kernel, all is enabled and not her having to go > look for what else is needed. > > And then put the sev code behind that config option. Depending on how > ugly it gets... > I will add more detail in the help text. I will look into adding some depends. ... >> + >> +void psp_add_device(struct psp_device *psp) > > That function is needlessly global and should be static, AFAICT. > > Better yet, it is called only once and its body is trivial so you can > completely get rid of it and meld it into the callsite. > Agreed, will do. ..... >> + >> +static struct psp_device *psp_alloc_struct(struct sp_device *sp) > > "psp_alloc()" is enough I guess. > I was trying to adhere to the existing ccp-dev.c function naming conversion. .... > > static. > > Please audit all your functions in the psp pile and make them static if > not needed outside of their compilation unit. > Will do. >> +{ >> + unsigned int status; >> + irqreturn_t ret = IRQ_HANDLED; >> + struct psp_device *psp = data; > > Please sort function local variables declaration in a reverse christmas > tree order: > > longest_variable_name; > shorter_var_name; > even_shorter; > i; > Got it, will do >> + >> + /* read the interrupt status */ >> + status = ioread32(psp->io_regs + PSP_P2CMSG_INTSTS); >> + >> + /* invoke subdevice interrupt handlers */ >> + if (status) { >> + if (psp->sev_irq_handler) >> + ret = psp->sev_irq_handler(irq, psp->sev_irq_data); >> + if (psp->tee_irq_handler) >> + ret = psp->tee_irq_handler(irq, psp->tee_irq_data); >> + } >> + >> + /* clear the interrupt status */ >> + iowrite32(status, psp->io_regs + PSP_P2CMSG_INTSTS); > > We're clearing the status by writing the same value back?!? Shouldn't > that be: > > iowrite32(0, psp->io_regs + PSP_P2CMSG_INTSTS); > Actually the SW should write "1" to clear the bit. To make it clear, I can use value 1 and add comment. > Below I see > > iowrite32(0xffffffff, psp->io_regs + PSP_P2CMSG_INTSTS); > > which is supposed to clear IRQs. Btw, you can write that: > > iowrite32(-1, psp->io_regs + PSP_P2CMSG_INTSTS); > Sure, I will do that ... ... >> + >> + sp_set_psp_master(sp); > > So this function is called only once and declared somewhere else. You > could simply do here: > > if (sp->set_psp_master_device) > sp->set_psp_master_device(sp); > > and get rid of one more global function. Sure I can do that. .... >> + /* Enable interrupt */ >> + dev_dbg(dev, "Enabling interrupts ...\n"); >> + iowrite32(7, psp->io_regs + PSP_P2CMSG_INTEN); > > Uh, a magic "7"! Exciting! > > I wonder what that means and whether it could be a define with an > explanatory name instead. Ditto for the other values... > I will try to define some macro instead of hard coded values. .... >> + >> +int psp_dev_resume(struct sp_device *sp) >> +{ >> + return 0; >> +} >> + >> +int psp_dev_suspend(struct sp_device *sp, pm_message_t state) >> +{ >> + return 0; >> +} > > Those last two are completely useless. Delete them pls. > We don't have any PM support, I agree will delete it. ... >> +int psp_request_sev_irq(struct psp_device *psp, irq_handler_t handler, >> + void *data) >> +{ >> + psp->sev_irq_data = data; >> + psp->sev_irq_handler = handler; >> + >> + return 0; >> +} >> + >> +int psp_free_sev_irq(struct psp_device *psp, void *data) >> +{ >> + if (psp->sev_irq_handler) { >> + psp->sev_irq_data = NULL; >> + psp->sev_irq_handler = NULL; >> + } >> + >> + return 0; >> +} > > Both void. Please do not return values from functions which are simply > void functions by design. > thanks, will fix it. ... >> +int psp_request_sev_irq(struct psp_device *psp, irq_handler_t handler, >> + void *data); >> +int psp_free_sev_irq(struct psp_device *psp, void *data); >> + >> +int psp_request_tee_irq(struct psp_device *psp, irq_handler_t handler, >> + void *data); > > Let them stick out. okay ... > >> +int psp_free_tee_irq(struct psp_device *psp, void *data); >> + >> +struct psp_device *psp_get_master_device(void); >> + >> +extern const struct psp_vdata psp_entry; >> + >> +#endif /* __PSP_DEV_H */ >> diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c > > So this file is called sp-dev and the other psp-dev. Confusing. > > And in general, why isn't the whole thing a single psp-dev and you can > save yourself all the registering blabla and have a single driver for > the whole PSP functionality? > > Distros will have to enable everything anyway and the whole CCP/PSP code > is only a couple of KBs so you can just as well put it all into a single > driver. Hm. > PSP provides the interface for communicating with SEV and TEE FWs. I choose to add generic PSP interface first then plug the SEV FW support. The TEE commands may be totally different from SEV FW commands hence I tried to put all the SEV specific changes into one place and adhere to current ccp file naming convention. At high level, AMD-SP (AMD Secure Processor) (i.e CCP driver) will provide the support for CCP, SEV and TEE FW commands. +--- CCP | AMD-SP --| | +--- SEV | | +---- PSP ---* | +---- TEE -Brijesh