From patchwork Wed Mar 10 04:40:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rijo Thomas X-Patchwork-Id: 396879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74CCFC433E9 for ; Wed, 10 Mar 2021 04:44:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 532F564FEF for ; Wed, 10 Mar 2021 04:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232217AbhCJEkx (ORCPT ); Tue, 9 Mar 2021 23:40:53 -0500 Received: from mail-bn7nam10on2073.outbound.protection.outlook.com ([40.107.92.73]:26721 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232191AbhCJEke (ORCPT ); Tue, 9 Mar 2021 23:40:34 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cimfSXlQvyEaQ9yc98dq2MB1mRgzCZ3twCFyjii9yAfRGEM3glscSknd7XZAwnqbn4IqfcpovxDQiKWjdZHEEQAf83EjFh5uLSosA0+S5YTjoOWw0fh8SRMrOnDUl57IpIrvRM0NlEvg9rRdMsdBIgoT4Yu2eYT5N2OynXVrUDnA+7OMyxlVWNdLJ8w+iOeu6cZpxnJQ2017WsNM/etHZcsUuyrG8/XL04qhWcTjJ3O1v9EEmFYSv9MeTVXpYa6y9+3h9p1J04KIUHJCNzyP6vFBHB1FZSLe+43m0WD0FJYTCf8DQzxPaqcCMW6CJkmwBgUktEJLG7vo5Hh0H/pXZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EPl6QTO809v7FQVSPOpW9fte9x6JzqJXKza9Z5Va3Z0=; b=EhWAFohj/ZsTiZbAzz0I5u1nwvY21c6qX4ABYy+URBnS0XM+6bOM0SffQPweXJGmr82m6wiJWIveOuQDRkbAKYM/H6xPGLuc/cQf2atNG2ilRVOfWWPIYMtBTcDn3X06/BwynwUwPQkEoEtdudSxVd0beF01uzSjuFaFyvSvB/1IB1CijsLWv8x8y6coFtjvhmXUBjy26MYJLogyWXcxuaCwqTz1cU+loe7U5mB8Gk318VGkP6KYI5q+TQtU4071Y+YS/Aq1Gg6QWxh//1kgmwcapDExXSHRpdMIbmgNRpdqbCz37lcZh9NIoHUm7NZxxudQv/xBtiuFObXvQR6eUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EPl6QTO809v7FQVSPOpW9fte9x6JzqJXKza9Z5Va3Z0=; b=BSnLY6a2dfwe39fX0vYiSCSfyzxfA52LQoaXRehkax3L+Au147EEP3VGi0HODqZofxgg9Yb8/6Uq7e7yhS1nyKwFb9BnxfKlXAIVQfVjJQlIybI4IHQBOpo+cggqjb4q1mdqSiD7nbpRm5p/q9kOUlpLLjMJcvy8Fco7ETNmFpQ= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4719.namprd12.prod.outlook.com (2603:10b6:805:e9::25) by SN6PR12MB2846.namprd12.prod.outlook.com (2603:10b6:805:70::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Wed, 10 Mar 2021 04:40:32 +0000 Received: from SN6PR12MB4719.namprd12.prod.outlook.com ([fe80::c32:245b:4812:ee03]) by SN6PR12MB4719.namprd12.prod.outlook.com ([fe80::c32:245b:4812:ee03%3]) with mapi id 15.20.3912.030; Wed, 10 Mar 2021 04:40:32 +0000 From: Rijo Thomas To: Tom Lendacky , John Allen , Herbert Xu , "David S . Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Rijo Thomas , Mythri Pandeshwara krishna , Devaraj Rangasamy , Jens Wiklander , Ard Biesheuvel Subject: [PATCH v2 1/2] crypto: ccp - reduce tee command status polling interval from 5ms to 1ms Date: Wed, 10 Mar 2021 10:10:00 +0530 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.156.251] X-ClientProxiedBy: MA1PR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::19) To SN6PR12MB4719.namprd12.prod.outlook.com (2603:10b6:805:e9::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from andbang6.amd.com (165.204.156.251) by MA1PR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Wed, 10 Mar 2021 04:40:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 083078e2-405e-44d7-d464-08d8e37ea3d4 X-MS-TrafficTypeDiagnostic: SN6PR12MB2846: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IgK8xjXWEh/epaoSvqHtvCUK5f94NIpILZ9LoePqKM+/HJxXN9uMr+Y2icWEv3bTkzLrZ7jFpLXc3SCGPu50dXTQhFff3aB/2hvziVI78Yihk2hx4Y1aDn0G+4SA6/fdwOWfQSq/zRvJMxDf10hYgGTYggDzmYK/n7uVegaZ3RpzO7hAT+pRFEcg5gzUna9V3eEnIcHdpk4qJm3Rw4c1FuMGP7iNHdm04U5a2mcMsCY5WyClqqUcXETfQZZHBUJQLBTPkaQEZRghpcprMnT0pirp6ITfAdkMcmSauMJS6PoNU230D2Rj/kVGmYV7Vmk4+PYJDYNAmTDWG5WfTAHSDhHRZHBypI5fbVRbCEd3ZC2qv7B+t9pGQtcLfCAfAdAIaFgDdNmf4oldeY6NSxBCRuMozIN1OIWyu3TWWckdsyX1wWjB8OyXoLPWoz/F37NovPepwev5BYcU/QReCU5IpX/5khmwcdDUeV599jXTd8coqoUCgNGfey/dM6mx6mZXFgTLL1faszgilwr+AEctGg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4719.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(136003)(346002)(39860400002)(376002)(956004)(316002)(2616005)(66556008)(6486002)(6666004)(66476007)(2906002)(86362001)(36756003)(8936002)(66946007)(8676002)(83380400001)(52116002)(7696005)(26005)(4326008)(16526019)(110136005)(54906003)(478600001)(186003)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: A4iGhDK3aUuho1fpGgAQWSDDz2Vl/3X4mmMYA2GGKrOfkvK8QtNe07ttv6Bx/kpMUUvXUcN0e2nhU3891XtiKZ3ZsC9qy+6EmpTlxZ5G7jCgGck6S1rW8BaOwmm029CPcU8Ru6JJPYIaO370k/yYB7UBuFKywuxcw1FVbmI5Yfs4L7PS07ajdc045b+iHEetfewfPCGjnS7CSPuTSFqfFyJdOz0yofhGl4i0rmzMXi7CK7onGFd0tKNl+l1YJxDJPdJXI1YAZjEK7eDMnYv8Fwwp1OYfctRkxd5giZnlT/gzyg4hcn47WhKCscGtRm9H7aI70rpfyvXSht/56JOm7XOJwk3HqRJ01/SvHnD3fNgizVyLikkBRd8u7cTvEgBFoSenFmcry8it2DIvCSKoguD9I2saiH2DcPyRxYhBYl5x29LRSy6TbDLaGt5z49GLpiNBT8q/ycusIquYWBuHlL+JKVWgYQKYhRM7A7FMl7oE7ozYKsc4GUfK8OGTAN7/tb8Xv2laLUGn6SYY4nDh+1+Uo2uO/chxLi5TMZ4UvIqLqS6FivCH0za575coI5+M6vbp5P1jKhLFHxyDppwcp345nIC+3JPN9CosGKC30HKfb2enwMKzwzT7vqHIM6DFetZ7XYR65uOWDqjDUbjhLVSF0P18noQpO9bGcSGk+i2Z2FjOkVPF+Ypj3pms1TgcccL8limUiq2MzCP3d3dNbkyTOCGActNEajDLkdrjqCtqYmdXMqWXPw1VT1G6StjxSaend/P+QXlBizOVHw6H084KCEKC0WZRdaolem6dDVYEWei3JI8ZRN2iE7pUGHFD5ADr3mTPTDoOudYVhTZRIzmfOs78AbcKObmg3zaLN1/qX4d3OH2pk8w+xmLpNT67u3msoGSHW45zZsQU0Z5/Sy9x98NSrc2RlMMZkgsaswNdounI+A8X5jUq2nPF9rKvta+w/CCBorzTUwvEQf/q0d5nOTNXSw5FivVzbTLP2H8Pto4WhSnwgr11uuqokpQFcDEYXstlUXotmrSmS+Nhy68sWo51lcEv2XoSwTZuoZ9xr2KRnUU06tOYQLUYtFfjog242silebgDCckK0TweGKphGMahuzbBYZ9hWlERTgp1c92foBcYYVVxiJfFQusuLs6M1i6CixRnjD5YPtD1KwDBgySb2K0TkXHZFFem8fxMw1GfgA30TNC1b83W1hGSeMoPfM8h131Dhqa2JnS82kxOyRmPkBnMEkQfK08N9NvJdNDxtx0M0j4ptLIpWeC6ZpVh89IBQUd+OhAoXGvGLgQXvRMeN/QwmpfV2ihsmsQitbDtltOTSur8qTrqiQMB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 083078e2-405e-44d7-d464-08d8e37ea3d4 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4719.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2021 04:40:32.8003 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0V3aCswgAIWsun2lKYNjT9rVQqw3ZeVGq/JMtF2wAxdkB1nUh32DMRpoX2IgCGrq9YraFhhbiKy2CVqO3fmfpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2846 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The PSP TEE device driver polls the command status variable every 5ms to check for command completion. Reduce this time to 1ms so that there is an improvement in driver response time to clients which submit TEE commands. Reviewed-by: Devaraj Rangasamy Signed-off-by: Rijo Thomas --- drivers/crypto/ccp/tee-dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index 5e697a90ea7f..910b71df2aef 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -5,7 +5,7 @@ * Author: Rijo Thomas * Author: Devaraj Rangasamy * - * Copyright 2019 Advanced Micro Devices, Inc. + * Copyright (C) 2019,2021 Advanced Micro Devices, Inc. */ #include @@ -309,14 +309,14 @@ static int tee_wait_cmd_completion(struct psp_tee_device *tee, struct tee_ring_cmd *resp, unsigned int timeout) { - /* ~5ms sleep per loop => nloop = timeout * 200 */ - int nloop = timeout * 200; + /* ~1ms sleep per loop => nloop = timeout * 1000 */ + int nloop = timeout * 1000; while (--nloop) { if (resp->cmd_state == TEE_CMD_STATE_COMPLETED) return 0; - usleep_range(5000, 5100); + usleep_range(1000, 1100); } dev_err(tee->dev, "tee: command 0x%x timed out, disabling PSP\n", From patchwork Wed Mar 10 04:40:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rijo Thomas X-Patchwork-Id: 396878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 940F5C4332E for ; Wed, 10 Mar 2021 04:44:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76DB864F7D for ; Wed, 10 Mar 2021 04:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232244AbhCJEky (ORCPT ); Tue, 9 Mar 2021 23:40:54 -0500 Received: from mail-bn7nam10on2054.outbound.protection.outlook.com ([40.107.92.54]:51296 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232199AbhCJEki (ORCPT ); Tue, 9 Mar 2021 23:40:38 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g+8L5NlwQUfGeNKWJ6Xa2/0VREx+ND9xfPouXZMi2fkokCd1OHtuVyWnZ7rHUCw72uAO1rDYkbf31tTCH05O6zEYk/mE3s7ZPCndOqiad4saK5Uvb9Y7u3FSOlmrh7XsGNn4dn7wJcCy7vwnxOc5vRVvDnnaliah2ypayZLMpoxkBOLH3AMfJX9gedE46Z1E+lyZLI2ukraCo8bYUDaoQF8Z9pAzCEL6mdK+4dv9XfPCVrf6IvkavukGP9v0KGxI1hOjBrltmU/erl6RpYHXNZAJOIcVHAPXJ76JkqIzftky9+h/mYZP+AdbOptKjLxNPY9rPFbcnZB/K5/EdFzQZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=THybtUkGUS4Sll6Zhx0VQ1voNN3+HShjvLn1Pyre+Mk=; b=XkkEl+qYgUekpR42NxfR75pTozZtjTEtsViAqL3aokWCmuLYEM+tY3mR4G+JFe6WO2QuPdpynW+ioCqjJBcmUE9+wY0HLDNdqU4h4FHJTWYnEkUTvEBflN7NZXHI4U/lB/fVOJPvUZdFIQbJRF5l92LlPqHz71SV8VisEbEgbtAvQo+0RoHhsH69bsSr55GgEPt2f09EMBCz0GKLTm71QueTyJDwgmeojXR9XHMTKq7//XeseYxgGEI29T+KEKPxvxpWnbX4iMy7r+LJ6k4seTiwjHNjKzNRqxsqYoQiW7MJIqJZuNqIGLQk4Yi+rUEvygkxQAZ942YASsZ1n5HDpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=THybtUkGUS4Sll6Zhx0VQ1voNN3+HShjvLn1Pyre+Mk=; b=i6gqcTTu9UQ5GCOVnCokSPatjS72n/nLEChG/FFdbc7fJYMS5JOOmbAGEPjdmVta2ULttv68xum1qFR68yE9H+mqHhmiPx95RwxoEj9mVkyPAAabs8WOkTfO6yMqeMUQv35wplgOZbOysgE28DaYKvFE9Ctvk1UkhuLOZK4oSIU= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4719.namprd12.prod.outlook.com (2603:10b6:805:e9::25) by SN6PR12MB2846.namprd12.prod.outlook.com (2603:10b6:805:70::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Wed, 10 Mar 2021 04:40:36 +0000 Received: from SN6PR12MB4719.namprd12.prod.outlook.com ([fe80::c32:245b:4812:ee03]) by SN6PR12MB4719.namprd12.prod.outlook.com ([fe80::c32:245b:4812:ee03%3]) with mapi id 15.20.3912.030; Wed, 10 Mar 2021 04:40:36 +0000 From: Rijo Thomas To: Tom Lendacky , John Allen , Herbert Xu , "David S . Miller" , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Rijo Thomas , Mythri Pandeshwara krishna , Devaraj Rangasamy , Jens Wiklander , Ard Biesheuvel Subject: [PATCH v2 2/2] crypto: ccp - fix command queuing to TEE ring buffer Date: Wed, 10 Mar 2021 10:10:01 +0530 Message-Id: <9844166d38b59d82e3d6c41401086d10dd38d77b.1615350846.git.Rijo-john.Thomas@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.156.251] X-ClientProxiedBy: MA1PR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::19) To SN6PR12MB4719.namprd12.prod.outlook.com (2603:10b6:805:e9::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from andbang6.amd.com (165.204.156.251) by MA1PR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Wed, 10 Mar 2021 04:40:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6edbc741-6b03-44c2-fbaf-08d8e37ea5f0 X-MS-TrafficTypeDiagnostic: SN6PR12MB2846: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EKzP4m8OeowH58Syao0Br9mDXe7pDXnjJis7CeIRTQO5kKtkg3lT686ZD+AHcJvEWFcqeb8H8FEOfMT6xFHBYyLgnaSml+N8bkyOJzSCh4iZhWz9Nk8OK1HW2ubNyKXvZdD0d2Xj/ycdE5r48qprp67VnSaZ5ZQFIy9iYPi4wf/JpfE9VTRIpYR6VJ7VMUnBdmnywi1B68JVMXRq7lB1bA57kFXANkNu0LOf8jHRiTgpHzgMVAI/y0RHkjLEPSABROLB1xdNupwaYNuKgDNY2nSKfXehiDnhZp/hHDy987PFheJtX409Ywf1ccsMEwUksDrgVWDw27p5RXkb3BSHhE2aCKhBNZ/Ip80eaTVHaGo5CjLWNbHOoLRBZ31sekaEPLo4dtmXVCjuUVfiLpKG2DoK76JYf/LJGwMZphX9Vbb/4pL2FSNySeShB/iQZsVocj6aVIkaYAYWMaFwx5s7cD7nwQDuwP8JHc9v0mOQZiynF0Wtesh4+BoM8m6MPz3+Dj98TQDR34VvIT2qlRasPQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4719.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(136003)(346002)(39860400002)(376002)(956004)(316002)(2616005)(66556008)(6486002)(6666004)(66476007)(2906002)(86362001)(36756003)(8936002)(66946007)(8676002)(83380400001)(52116002)(7696005)(26005)(4326008)(16526019)(110136005)(54906003)(478600001)(186003)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CzRK82obBkRPiU7cUb/7suhlz7cd63XtAAO8M4hO5KVy38VeCtpRm2denc6jMlFxfqO9M0pe+AxIXIukbWYXvEXBOc9cQ1y8hPP8q+K49QQ3JWh2ZiOSaD6vtD/4J2WbLFVmEBnLpx+/U/uRbai8vF45tAGoAuyHqa7k4Y667cikpX8zMHZ9YtSpmQne42uS3Yik20yGpK72wbY4QjU+cyUJKKLsqG9i4rXzkxhJyt+oEucIvL8yjHrNvF0vseVQ2pC5WwDv5aNkX3thIOR0RBolXBv688r23ceO+CnRjouQWvy2IKByzIHVYiEGiW6b5uu907tFipAe7JvUssnCeMZcDS7IoJs8ZpfCU0gs7Vxm+C2IXQoXeH2fDtQhm8WGQmId4GKsIjJQ4KjKgejEz/vtFvgFcG1nG1RGtzQMJ8124Qdvq7iqQ3VSfO8LvLKDUCn+jhaZePBQ/PQwEHYzua2UbIq5caQDkAD42Y0B9o0kx7HSaqSkjH5UeKDgUbQTrR16q2rUzyKHLEXBSNflGI/8Q4t8kNmUGQsMGJcUeo5IFTw8xc7u/PAG5IpenNKc0K2tL31aweIhoJ7InkYkd8tj5/hKqWGuelE5nPCGK096E5zpgDcgmPA2TZqKT6o5y0RHX9ZVYZh/tcdkbX/0lvoFZp7y3gcgXFd38Ao5o2SRy+xBphcC274HULC5MRwUDXDoJDn8KV6UEFsSytQF18Y0j0L6cyYbEV4QGPykxK4qQdN7zigrHQgC8jQJXoLccRJ79OOJdU22BB2NpV/x0Jg7MzpuxPvJ6/6IoNzh9k7fnSgd0h5wR+CT1JGSVA1cYJnYDsvur6o6y4uZ0TsGax96RYmtIXoTubPovw7rC3jKMzsCxrmwdI6mGdBjO6wfURP/RXff3MQbBaZJM7Yar7J7TGrf2PHRafFrTpbaIf232zPPyP0pYzIQmHwt3H15BdKe+YYvti34f4TL3rASTRDg43Pf/D/Y8n9fgWYdOpqIAqPGYPH1DA3j9yiBAdSPfLBhlqIfqki4G08h8ACcylnoeWTKUFAeumD9NCSP9W45hLDT+j3Xjcw+zMVlll2iFTSlKuLJN5g1a5YAkc6vs9RmDBCJtZu7JiiyhOmJpq1lV8luKAO+IxpPOJvBpueFSXWCDtfY4yai0HE8iGQP8jl1a9AkyFxmSwZjFvJ2v8M9hkg4ax7zIgJi8RxgzDvB1hXbZTkGvKYU7aw5eSC1C6GRn+mU/FLpJEa5h9UH6oZ0nqfqaK+C3xI0gUJAIcpADDeBZIIZUQ+TDgsCPwWssTEmx6ojVCxnAkCkOTFQXjZFk8C84+rgUfyHiFlxAzpY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6edbc741-6b03-44c2-fbaf-08d8e37ea5f0 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4719.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2021 04:40:36.5541 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: emH2aigERIlbBUumK1G5+3El+yIHvj+RQ47uS1F1adXEZu1uux/1xtSFAQuBW6O/50FOJKPWYLETE2ZHLSLV/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2846 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Multiple threads or clients can submit a command to the TEE ring buffer. This patch helps to synchronize command submission to the ring. One thread shall write a command to a TEE ring buffer entry only if: - Trusted OS has notified that the TEE command for the given entry has been processed and driver has copied the TEE response into client buffer. - The command entry is empty and can be written into. After a command has been written to the TEE ring buffer, the global wptr (mutex protected) shall be incremented for use by next client. If PSP became unresponsive while processing TEE request from a client, then further command submission to queue will be disabled. Fixes: 33960acccfbd (crypto: ccp - add TEE support for Raven Ridge) Signed-off-by: Rijo Thomas --- drivers/crypto/ccp/tee-dev.c | 49 +++++++++++++++++++++++++----------- drivers/crypto/ccp/tee-dev.h | 20 +++++++++++++-- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index 910b71df2aef..8cade4775115 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -36,6 +36,7 @@ static int tee_alloc_ring(struct psp_tee_device *tee, int ring_size) if (!start_addr) return -ENOMEM; + memset(start_addr, 0x0, ring_size); rb_mgr->ring_start = start_addr; rb_mgr->ring_size = ring_size; rb_mgr->ring_pa = __psp_pa(start_addr); @@ -244,41 +245,54 @@ static int tee_submit_cmd(struct psp_tee_device *tee, enum tee_cmd_id cmd_id, void *buf, size_t len, struct tee_ring_cmd **resp) { struct tee_ring_cmd *cmd; - u32 rptr, wptr; int nloop = 1000, ret = 0; + u32 rptr; *resp = NULL; mutex_lock(&tee->rb_mgr.mutex); - wptr = tee->rb_mgr.wptr; - - /* Check if ring buffer is full */ + /* Loop until empty entry found in ring buffer */ do { + /* Get pointer to ring buffer command entry */ + cmd = (struct tee_ring_cmd *) + (tee->rb_mgr.ring_start + tee->rb_mgr.wptr); + rptr = ioread32(tee->io_regs + tee->vdata->ring_rptr_reg); - if (!(wptr + sizeof(struct tee_ring_cmd) == rptr)) + /* Check if ring buffer is full or command entry is waiting + * for response from TEE + */ + if (!(tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || + cmd->flag == CMD_WAITING_FOR_RESPONSE)) break; - dev_info(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", - rptr, wptr); + dev_dbg(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", + rptr, tee->rb_mgr.wptr); - /* Wait if ring buffer is full */ + /* Wait if ring buffer is full or TEE is processing data */ mutex_unlock(&tee->rb_mgr.mutex); schedule_timeout_interruptible(msecs_to_jiffies(10)); mutex_lock(&tee->rb_mgr.mutex); } while (--nloop); - if (!nloop && (wptr + sizeof(struct tee_ring_cmd) == rptr)) { - dev_err(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", - rptr, wptr); + if (!nloop && + (tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || + cmd->flag == CMD_WAITING_FOR_RESPONSE)) { + dev_err(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u response flag %u\n", + rptr, tee->rb_mgr.wptr, cmd->flag); ret = -EBUSY; goto unlock; } - /* Pointer to empty data entry in ring buffer */ - cmd = (struct tee_ring_cmd *)(tee->rb_mgr.ring_start + wptr); + /* Do not submit command if PSP got disabled while processing any + * command in another thread + */ + if (psp_dead == true) { + ret = -EBUSY; + goto unlock; + } /* Write command data into ring buffer */ cmd->cmd_id = cmd_id; @@ -286,6 +300,9 @@ static int tee_submit_cmd(struct psp_tee_device *tee, enum tee_cmd_id cmd_id, memset(&cmd->buf[0], 0, sizeof(cmd->buf)); memcpy(&cmd->buf[0], buf, len); + /* Indicate driver is waiting for response */ + cmd->flag = CMD_WAITING_FOR_RESPONSE; + /* Update local copy of write pointer */ tee->rb_mgr.wptr += sizeof(struct tee_ring_cmd); if (tee->rb_mgr.wptr >= tee->rb_mgr.ring_size) @@ -353,12 +370,16 @@ int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len, return ret; ret = tee_wait_cmd_completion(tee, resp, TEE_DEFAULT_TIMEOUT); - if (ret) + if (ret) { + resp->flag = CMD_RESPONSE_TIMEDOUT; return ret; + } memcpy(buf, &resp->buf[0], len); *status = resp->status; + resp->flag = CMD_RESPONSE_COPIED; + return 0; } EXPORT_SYMBOL(psp_tee_process_cmd); diff --git a/drivers/crypto/ccp/tee-dev.h b/drivers/crypto/ccp/tee-dev.h index f09960112115..49d26158b71e 100644 --- a/drivers/crypto/ccp/tee-dev.h +++ b/drivers/crypto/ccp/tee-dev.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: MIT */ /* - * Copyright 2019 Advanced Micro Devices, Inc. + * Copyright (C) 2019,2021 Advanced Micro Devices, Inc. * * Author: Rijo Thomas * Author: Devaraj Rangasamy @@ -18,7 +18,7 @@ #include #define TEE_DEFAULT_TIMEOUT 10 -#define MAX_BUFFER_SIZE 992 +#define MAX_BUFFER_SIZE 988 /** * enum tee_ring_cmd_id - TEE interface commands for ring buffer configuration @@ -81,6 +81,20 @@ enum tee_cmd_state { TEE_CMD_STATE_COMPLETED, }; +/** + * enum cmd_resp_state - TEE command's response status maintained by driver + * @CMD_RESPONSE_INVALID: initial state when no command is written to ring + * @CMD_WAITING_FOR_RESPONSE: driver waiting for response from TEE + * @CMD_RESPONSE_TIMEDOUT: failed to get response from TEE + * @CMD_RESPONSE_COPIED: driver has copied response from TEE + */ +enum cmd_resp_state { + CMD_RESPONSE_INVALID, + CMD_WAITING_FOR_RESPONSE, + CMD_RESPONSE_TIMEDOUT, + CMD_RESPONSE_COPIED, +}; + /** * struct tee_ring_cmd - Structure of the command buffer in TEE ring * @cmd_id: refers to &enum tee_cmd_id. Command id for the ring buffer @@ -91,6 +105,7 @@ enum tee_cmd_state { * @pdata: private data (currently unused) * @res1: reserved region * @buf: TEE command specific buffer + * @flag: refers to &enum cmd_resp_state */ struct tee_ring_cmd { u32 cmd_id; @@ -100,6 +115,7 @@ struct tee_ring_cmd { u64 pdata; u32 res1[2]; u8 buf[MAX_BUFFER_SIZE]; + u32 flag; /* Total size: 1024 bytes */ } __packed;