Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752353AbdIGXPV (ORCPT ); Thu, 7 Sep 2017 19:15:21 -0400 Received: from mail-sn1nam01on0066.outbound.protection.outlook.com ([104.47.32.66]:55568 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750836AbdIGXPT (ORCPT ); Thu, 7 Sep 2017 19:15:19 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Subject: Re: [RFC Part2 PATCH v3 02/26] crypto: ccp: Add Platform Security Processor (PSP) device support To: Brijesh Singh , Borislav Petkov References: <20170724200303.12197-1-brijesh.singh@amd.com> <20170724200303.12197-3-brijesh.singh@amd.com> <20170907142737.g4aot7xatyopdfwp@pd.tnic> <9de7139f-676e-e671-13a1-cbc5170cc816@amd.com> Cc: 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" , linux-crypto@vger.kernel.org From: Gary R Hook Message-ID: <54fe8467-0fba-d4a8-84d4-ecd62299a53b@amd.com> Date: Thu, 7 Sep 2017 18:15:55 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <9de7139f-676e-e671-13a1-cbc5170cc816@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR1701CA0008.namprd17.prod.outlook.com (10.172.58.18) To CY4PR12MB1320.namprd12.prod.outlook.com (10.168.168.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 62a795b2-0e7f-4034-fc65-08d4f6464d51 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:CY4PR12MB1320; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1320;3:QvaA6RZJeDdX8yY/M7BbJXrwpPr4FXJyJ1xNIeDQznyA1w3/8tcfD5iFTgcKWcgjAAROL2DsURhnflOJLEmD1tV+LO1jQXkBda9zU4xzGs5q6kETWlG5HU33Fsg2cAu2zW1WWZaqsK+fIOvdntF8VBf5/bbFOypwcA7Vev6txDx9PDb/SDs6f0FowsMUm1yYZ/Ma0mv6inqSjQT+98vXtGcgvcQFfHUsuxJ1pXvRXYgiDwoMkE07xy+T59KSADPr;25:7i19AfYWgUtuEPGanZ1VHvjfrKSGBWrJSIxSFrY+pHQc2dx5AKBue8RCGe1oTXNfJGXDmHTfpDrl6nAHm9F3QEAYMrDHNhZy6nZb0DmvCAAxdDN8f2y1fDCiRZraqmnW8Dw513BCryBLaWSDmdx+LxTgkpfn3LK6TlOODGAG98GAL3ySUmbdvBS2hc298XbU8qtCjtDmtR80WXeuQl8shCg8GKr/6BUI5ooAzdr4SfHjJA6a0GCNIU4SdAjj7/EMI9vcwpsz/+w4ULo8BASCuSZhfhH/+vwVCPB0eOQwCKk6J4fsOXlvdNMswvOPgxN03oKBhnlQDM8Pvq/fWXlRxQ==;31:fX6GRNpVR9EEeBK5oJp39hOQw8roewDq1UEK/EPnAicQdLlciV/CEdRncqVy9559Q8wkold7plLRC4wpmm4/uspTTO9zjk04GYpWHjdx+it3FsWzCln3K0xWV4Ww0MYzBayfespyIKhFe1RxZIHHTxqc24SyK/WxSXENtj8HsquSMPuW9AP2OZ7JpywEGKcDdl7/8+TmSk3TATPAl646EaQOzTko0/yPcYuaIwuf0vA= X-MS-TrafficTypeDiagnostic: CY4PR12MB1320: X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1320;20:+a1aj19A3QEi2oKRc7R8kGy+WwbJAAYYXVMm3Lg+uf2KErSZr8oDasgMPbBakiZ8gTBT8tpTuVJ8LbcPuN6w52rYyR9rzNyCjLEVsdVFfwxHs4xnYU1RLBz6zWYou4bhVtWfEYg/pje8JJ5HwWjVlbviocJ+60F290jfEk2GxS7WdZ9Pmmvvai5cK3XRpOOmhqb/Hu63Btdw/1RAS4/R5kanXRds+c8i9J5JOU+jjL847Ctscxf3lLzbF1GbuIAXsJmfwCELB9C2m+FKz6pyGkkuagCcaIaQipB8INI9MnRInLWHOi3u02jRt5KeUaF87gOvFhmFjAAw53PgR1CXQGyJshPAH4jK+x1Gj6v7VGqk5emeVDWdI5LTqJEe3tjpIhJeJrmbxyIzEpoeLKk+hxjRSXynzRgTxWEiqSVj1pb6n/sVK1kR6HII1Hr82nQKcbu+uY1P+ag4qP5yIMcaUpslfk9Fmgx2kARtY+5dtMj0SY9sj724MiBBx4Typjrx;4:gRFHYfxxk9y3tQHssNJZkXtF++EYnlEWnGJjAqe/Xa8UikoZbCdSK8yI5Y/E+ikfMff0q1dvrSyclarwdp50cvXhHRQTemiSDHpgEIFylqGMkTcAn5ewOCNdblwQUALL3WmSA8pdgdGb16ulGqUo3gBfjHJtro8DEENEMzc2xG1xFog5D3DlTXqvQYoYYjfjijwdt6jFIz1vTC6bJbtLslAJMcSu/o/bkJc8Jg5n8AG6pfmcF6xIbgYUaIwvc831CV+maVu+YICP1DwuWiBCOWend16xxf4/3lzhaAxlLl8= 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)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR12MB1320;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR12MB1320; X-Forefront-PRVS: 04238CD941 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(6009001)(39860400002)(199003)(377454003)(24454002)(189002)(4001350100001)(93886005)(66066001)(15650500001)(65956001)(7736002)(65806001)(33646002)(23676002)(305945005)(81156014)(72206003)(81166006)(2950100002)(83506001)(6666003)(97736004)(76176999)(54356999)(31686004)(50466002)(189998001)(8676002)(478600001)(2906002)(229853002)(25786009)(50986999)(8936002)(65826007)(4326008)(36756003)(90366009)(6486002)(53936002)(101416001)(105586002)(106356001)(68736007)(64126003)(86362001)(3846002)(7416002)(47776003)(230700001)(53546010)(6116002)(54906002)(31696002)(5660300001)(6246003)(42186005)(77096006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1320;H:[10.236.19.127];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMzIwOzIzOkFYVW9wcmJZajJRVEMxS2hvVDZnNXd0TXNT?= =?utf-8?B?MjI5MDRnSEZoQU9sRnlOL2dRekZzOWdVSVVHR213M2Y4eDdKYjBCNU0vYTZL?= =?utf-8?B?WXFvakIrZkgweDVlcldIRlliYkdaTmlkVWExZ0VDczF4U2xUMmk3TTJpanRq?= =?utf-8?B?WWQzUlFFL1ptTGNrR1R5b0ZZalhJOUJKSVUxdmdmeVMzcHpwZENhT3N2NDFa?= =?utf-8?B?Y2ZKNk5VTWxDYU9TaUsyVVZSTFZKZm1tdEkzU3d6TUNWc2tDV3lqNEl2R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.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2017 23:15:15.7382 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1320 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6414 Lines: 256 On 09/07/2017 05:19 PM, Brijesh Singh wrote: > 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. I would prefer that we not shorten this. The prior incarnation, ccp_alloc_struct(), has/had been around for a while. And there are a number of similarly named allocation functions in the driver that we like to keep sorted. If anything, it should be more explanatory, IMO. > > .... > >> >> 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