From patchwork Thu Sep 7 18:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13376807 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4DFFEC8752 for ; Thu, 7 Sep 2023 18:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344321AbjIGStg (ORCPT ); Thu, 7 Sep 2023 14:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344316AbjIGStf (ORCPT ); Thu, 7 Sep 2023 14:49:35 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2047.outbound.protection.outlook.com [40.107.92.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650479D; Thu, 7 Sep 2023 11:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HExwwfhgFPvpPlyiutojPzlpd6ISrkH4R22MpF4VB6QKdTby7OAdQyiCvdN1c9eaCn/CwN+2ZhXZ7f7EeH+cjmXp/qAB3y6DHrrWUUNNEYd/IHfJcZMllxqPSiZETsI1cFDGGR7rx4m1tj4cxh60rhxLccy+AS0fcD+Qf29XGK1lXe4BIWud0jXky8SlOTNzhF+fRpeaEvUoS+O4iK52qjG7eEKQiknhRywcqeHrl+Zv5EA5KANVlSg3js4fEJ1SmPGQFvJUGu8q9SFmQRqeY43u5y689Th79yoORu72QZWliBS7/4H2JBof6uy2c4YCy0lmEUIwmqaYzuuanSkWbw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QjdjvKP7swsd7+Yvbl98AxprlIDL/qZ4F8ZtV67bsns=; b=Acm9giiO1+zPBklXxfHx5FGgjfWYsWkjzWcYrBuMZDU0e4z19f8PhjIOwnzcOlE6SDmSq3L6jV7PWfKhBrm9Gnc0h+7N8JdhMYvKwrLJ3H8h8Ww5qK4sBh6TLcbLZsQuoGbdrwYKiTFwyc4W1bIiwnRbUl5isXECyZ+BH6DiXRKJY0V5aiouyCF+8sB6KLWozlAdtaobTSlUTFqggxCvzLF4rHHzaaKK0AEw/mEqGiN/SPPvoUB8X42ec++8Xi/KJ7CeiBEEEAhwHc/ONDmp2IMOUYG6ADPEkLjog2UBgflPgxnpEzmCKZjaWlknU96okgWiSfCkDXwqrwUYPV5JtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=QjdjvKP7swsd7+Yvbl98AxprlIDL/qZ4F8ZtV67bsns=; b=gu9h9zmCSm/NRpbzi9ZYXMAgpuohH/fo/lGbf87MGdUO7wG3EACH12TVX8RPsznLJfEyT9glegdimSVElJFLfZU69gHI9MiWZ1Jpavv9h4PEGKH8+Mpanz7KA0Af2ot2qQB/ML58ExZDu10oNTTZEpVBM6TyfDZugiZhauPVLW8= Received: from CH2PR12CA0010.namprd12.prod.outlook.com (2603:10b6:610:57::20) by MW3PR12MB4586.namprd12.prod.outlook.com (2603:10b6:303:53::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30; Thu, 7 Sep 2023 18:49:28 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::a3) by CH2PR12CA0010.outlook.office365.com (2603:10b6:610:57::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30 via Frontend Transport; Thu, 7 Sep 2023 18:49:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Thu, 7 Sep 2023 18:49:28 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 7 Sep 2023 13:49:25 -0500 From: Mario Limonciello To: , CC: , , , , , Mario Limonciello Subject: [PATCH 1/5] crypto: ccp: Move direct access to some PSP registers out of TEE Date: Thu, 7 Sep 2023 13:48:42 -0500 Message-ID: <20230907184846.47598-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907184846.47598-1-mario.limonciello@amd.com> References: <20230907184846.47598-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|MW3PR12MB4586:EE_ X-MS-Office365-Filtering-Correlation-Id: 118b268d-771d-4061-f96a-08dbafd32a2d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nJtdbd+6EVuiGIoc/FOtqGoKgggy56IjzmVc3znHFSdFm9385ZZqoZLvo7Lnx7lpY2M7OaSExmbnlcgImGGsO5zLk1OzCpDreWDXM9PAKpFhQduH8L5d4mjvEcm9qp9J/nAm+H1nXEWuVprgw6STu7JarWtrz2G5Nl2fCmsvKlEwmfDPdlYST97cLLZEV1L7uhpTXdxPISo2R3/Ajgueur/cLYd2oj33gk4XgXaVV1xMH22Y3d1FL8Z6MDqe2dCTZo/B/dCpGuT74O/RZtkfDmjnrbmK2kGA4OqmCfYB5CBoamXflC6aCCCmTfMu6orMkF++hK6wDF8CXLr9oAQ5svaTB+2w6eXgqNW63jOBncv/0PAKfKCG2JDKJqDJS4w/O2npV/l7VXMbiHPbqmpBk80DwDLxpS6qB9McwjEHhQxSuHl/bnGjjdzzZq4/6bjixzCU0baRY58fg9exr5FLkG4t0a8+OYge1j9IxQBY89htuzAAhl9UTPfHDg8g9zPukSb+YTHJj7m/TFpuy//+GSR/KHD0RsM7qHwYY56gI0FZ/GCoae1rGROVfMss/DipiWbqgWk4tKdUtbKuiIizYl+b64n3tkVTRgf/mG23ob+GhWaKmCwlw04wLjZx3dOCnMUOlIWdXKs1AFrr8U2sbYHaWMJ96CgeglCDvVbuHTdlsddIOXVf1wucHg3nTkZQ3O3zGTIMZomUD6Rv2FSmDZX1IAGlX5T7TArH2lNCqlwW5ZIatk6iS2XoP4S4ye1DMM9mcRFvLG5UbaZarjEOPXCF2gvFLB/mlueVaa0UfulO6qJBpGpTUE+F46eBRRcl X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(39860400002)(136003)(376002)(451199024)(186009)(1800799009)(82310400011)(46966006)(40470700004)(36840700001)(82740400003)(356005)(81166007)(70206006)(6666004)(7696005)(40460700003)(36756003)(36860700001)(86362001)(40480700001)(47076005)(1076003)(2616005)(30864003)(26005)(426003)(16526019)(336012)(83380400001)(478600001)(110136005)(41300700001)(70586007)(8936002)(4326008)(8676002)(5660300002)(316002)(2906002)(44832011)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 18:49:28.2892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 118b268d-771d-4061-f96a-08dbafd32a2d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4586 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Tom Lendacky With the PSP mailbox registers supporting more than just TEE, access to them must be maintained and serialized by the PSP device support. Remove TEE support direct access and create an interface in the PSP support where the register access can be controlled/serialized. Signed-off-by: Tom Lendacky Signed-off-by: Mario Limonciello Reviewed-by: Rijo Thomas Tested-by: Rijo Thomas --- drivers/crypto/ccp/psp-dev.c | 60 ++++++++++++++++++++++++++++++++++++ drivers/crypto/ccp/psp-dev.h | 18 +++++++++++ drivers/crypto/ccp/sp-dev.h | 3 ++ drivers/crypto/ccp/sp-pci.c | 18 +++++++---- drivers/crypto/ccp/tee-dev.c | 48 ++++++----------------------- drivers/crypto/ccp/tee-dev.h | 15 ++------- 6 files changed, 104 insertions(+), 58 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index d42d7bc62352..3258c4612e14 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include "sp-dev.h" #include "psp-dev.h" @@ -19,6 +22,62 @@ struct psp_device *psp_master; +#define PSP_C2PMSG_17_CMDRESP_CMD GENMASK(19, 16) + +static int psp_mailbox_poll(const void __iomem *cmdresp_reg, unsigned int *cmdresp, + unsigned int timeout_msecs) +{ + while (true) { + *cmdresp = ioread32(cmdresp_reg); + if (FIELD_GET(PSP_CMDRESP_RESP, *cmdresp)) + return 0; + + if (!timeout_msecs--) + break; + + usleep_range(1000, 1100); + } + + return -ETIMEDOUT; +} + +int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff, + unsigned int timeout_msecs, unsigned int *cmdresp) +{ + void __iomem *cmdresp_reg, *cmdbuff_lo_reg, *cmdbuff_hi_reg; + int ret; + + if (!psp || !psp->vdata || !psp->vdata->cmdresp_reg || + !psp->vdata->cmdbuff_addr_lo_reg || !psp->vdata->cmdbuff_addr_hi_reg) + return -ENODEV; + + cmdresp_reg = psp->io_regs + psp->vdata->cmdresp_reg; + cmdbuff_lo_reg = psp->io_regs + psp->vdata->cmdbuff_addr_lo_reg; + cmdbuff_hi_reg = psp->io_regs + psp->vdata->cmdbuff_addr_hi_reg; + + mutex_lock(&psp->mailbox_mutex); + + /* Ensure mailbox is ready for a command */ + ret = -EBUSY; + if (psp_mailbox_poll(cmdresp_reg, cmdresp, 0)) + goto unlock; + + if (cmdbuff) { + iowrite32(lower_32_bits(__psp_pa(cmdbuff)), cmdbuff_lo_reg); + iowrite32(upper_32_bits(__psp_pa(cmdbuff)), cmdbuff_hi_reg); + } + + *cmdresp = FIELD_PREP(PSP_C2PMSG_17_CMDRESP_CMD, cmd); + iowrite32(*cmdresp, cmdresp_reg); + + ret = psp_mailbox_poll(cmdresp_reg, cmdresp, timeout_msecs); + +unlock: + mutex_unlock(&psp->mailbox_mutex); + + return ret; +} + static struct psp_device *psp_alloc_struct(struct sp_device *sp) { struct device *dev = sp->dev; @@ -164,6 +223,7 @@ int psp_dev_init(struct sp_device *sp) } psp->io_regs = sp->io_map; + mutex_init(&psp->mailbox_mutex); ret = psp_get_capability(psp); if (ret) diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index 8a4de69399c5..d917657c6085 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "sp-dev.h" @@ -33,6 +35,7 @@ struct psp_device { struct sp_device *sp; void __iomem *io_regs; + struct mutex mailbox_mutex; psp_irq_handler_t sev_irq_handler; void *sev_irq_data; @@ -71,4 +74,19 @@ struct psp_device *psp_get_master_device(void); #define PSP_SECURITY_HSP_TPM_AVAILABLE BIT(10) #define PSP_SECURITY_ROM_ARMOR_ENFORCED BIT(11) +/** + * enum psp_cmd - PSP mailbox commands + * @PSP_CMD_TEE_RING_INIT: Initialize TEE ring buffer + * @PSP_CMD_TEE_RING_DESTROY: Destroy TEE ring buffer + * @PSP_CMD_MAX: Maximum command id + */ +enum psp_cmd { + PSP_CMD_TEE_RING_INIT = 1, + PSP_CMD_TEE_RING_DESTROY = 2, + PSP_CMD_MAX = 15, +}; + +int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff, + unsigned int timeout_msecs, unsigned int *cmdresp); + #endif /* __PSP_DEV_H */ diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index 2329ad524b49..c4e125efe6c7 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -71,6 +71,9 @@ struct psp_vdata { const struct sev_vdata *sev; const struct tee_vdata *tee; const struct platform_access_vdata *platform_access; + const unsigned int cmdresp_reg; + const unsigned int cmdbuff_addr_lo_reg; + const unsigned int cmdbuff_addr_hi_reg; const unsigned int feature_reg; const unsigned int inten_reg; const unsigned int intsts_reg; diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index b6ab56abeb68..d1aedc5c1a68 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -418,18 +418,12 @@ static const struct sev_vdata sevv2 = { }; static const struct tee_vdata teev1 = { - .cmdresp_reg = 0x10544, /* C2PMSG_17 */ - .cmdbuff_addr_lo_reg = 0x10548, /* C2PMSG_18 */ - .cmdbuff_addr_hi_reg = 0x1054c, /* C2PMSG_19 */ .ring_wptr_reg = 0x10550, /* C2PMSG_20 */ .ring_rptr_reg = 0x10554, /* C2PMSG_21 */ .info_reg = 0x109e8, /* C2PMSG_58 */ }; static const struct tee_vdata teev2 = { - .cmdresp_reg = 0x10944, /* C2PMSG_17 */ - .cmdbuff_addr_lo_reg = 0x10948, /* C2PMSG_18 */ - .cmdbuff_addr_hi_reg = 0x1094c, /* C2PMSG_19 */ .ring_wptr_reg = 0x10950, /* C2PMSG_20 */ .ring_rptr_reg = 0x10954, /* C2PMSG_21 */ }; @@ -466,6 +460,9 @@ static const struct psp_vdata pspv2 = { static const struct psp_vdata pspv3 = { .tee = &teev1, .platform_access = &pa_v1, + .cmdresp_reg = 0x10544, /* C2PMSG_17 */ + .cmdbuff_addr_lo_reg = 0x10548, /* C2PMSG_18 */ + .cmdbuff_addr_hi_reg = 0x1054c, /* C2PMSG_19 */ .bootloader_info_reg = 0x109ec, /* C2PMSG_59 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ @@ -476,6 +473,9 @@ static const struct psp_vdata pspv3 = { static const struct psp_vdata pspv4 = { .sev = &sevv2, .tee = &teev1, + .cmdresp_reg = 0x10544, /* C2PMSG_17 */ + .cmdbuff_addr_lo_reg = 0x10548, /* C2PMSG_18 */ + .cmdbuff_addr_hi_reg = 0x1054c, /* C2PMSG_19 */ .bootloader_info_reg = 0x109ec, /* C2PMSG_59 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ @@ -485,6 +485,9 @@ static const struct psp_vdata pspv4 = { static const struct psp_vdata pspv5 = { .tee = &teev2, .platform_access = &pa_v2, + .cmdresp_reg = 0x10944, /* C2PMSG_17 */ + .cmdbuff_addr_lo_reg = 0x10948, /* C2PMSG_18 */ + .cmdbuff_addr_hi_reg = 0x1094c, /* C2PMSG_19 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10510, /* P2CMSG_INTEN */ .intsts_reg = 0x10514, /* P2CMSG_INTSTS */ @@ -493,6 +496,9 @@ static const struct psp_vdata pspv5 = { static const struct psp_vdata pspv6 = { .sev = &sevv2, .tee = &teev2, + .cmdresp_reg = 0x10944, /* C2PMSG_17 */ + .cmdbuff_addr_lo_reg = 0x10948, /* C2PMSG_18 */ + .cmdbuff_addr_hi_reg = 0x1094c, /* C2PMSG_19 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10510, /* P2CMSG_INTEN */ .intsts_reg = 0x10514, /* P2CMSG_INTSTS */ diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index 5560bf8329a1..5e1d80724678 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -62,26 +62,6 @@ static void tee_free_ring(struct psp_tee_device *tee) mutex_destroy(&rb_mgr->mutex); } -static int tee_wait_cmd_poll(struct psp_tee_device *tee, unsigned int timeout, - unsigned int *reg) -{ - /* ~10ms sleep per loop => nloop = timeout * 100 */ - int nloop = timeout * 100; - - while (--nloop) { - *reg = ioread32(tee->io_regs + tee->vdata->cmdresp_reg); - if (FIELD_GET(PSP_CMDRESP_RESP, *reg)) - return 0; - - usleep_range(10000, 10100); - } - - dev_err(tee->dev, "tee: command timed out, disabling PSP\n"); - psp_dead = true; - - return -ETIMEDOUT; -} - static struct tee_init_ring_cmd *tee_alloc_cmd_buffer(struct psp_tee_device *tee) { @@ -110,7 +90,6 @@ static int tee_init_ring(struct psp_tee_device *tee) { int ring_size = MAX_RING_BUFFER_ENTRIES * sizeof(struct tee_ring_cmd); struct tee_init_ring_cmd *cmd; - phys_addr_t cmd_buffer; unsigned int reg; int ret; @@ -130,23 +109,15 @@ static int tee_init_ring(struct psp_tee_device *tee) return -ENOMEM; } - cmd_buffer = __psp_pa((void *)cmd); - /* Send command buffer details to Trusted OS by writing to * CPU-PSP message registers */ - - iowrite32(lower_32_bits(cmd_buffer), - tee->io_regs + tee->vdata->cmdbuff_addr_lo_reg); - iowrite32(upper_32_bits(cmd_buffer), - tee->io_regs + tee->vdata->cmdbuff_addr_hi_reg); - iowrite32(TEE_RING_INIT_CMD, - tee->io_regs + tee->vdata->cmdresp_reg); - - ret = tee_wait_cmd_poll(tee, TEE_DEFAULT_TIMEOUT, ®); + ret = psp_mailbox_command(tee->psp, PSP_CMD_TEE_RING_INIT, cmd, + TEE_DEFAULT_CMD_TIMEOUT, ®); if (ret) { - dev_err(tee->dev, "tee: ring init command timed out\n"); + dev_err(tee->dev, "tee: ring init command timed out, disabling TEE support\n"); tee_free_ring(tee); + psp_dead = true; goto free_buf; } @@ -174,12 +145,11 @@ static void tee_destroy_ring(struct psp_tee_device *tee) if (psp_dead) goto free_ring; - iowrite32(TEE_RING_DESTROY_CMD, - tee->io_regs + tee->vdata->cmdresp_reg); - - ret = tee_wait_cmd_poll(tee, TEE_DEFAULT_TIMEOUT, ®); + ret = psp_mailbox_command(tee->psp, PSP_CMD_TEE_RING_DESTROY, NULL, + TEE_DEFAULT_CMD_TIMEOUT, ®); if (ret) { - dev_err(tee->dev, "tee: ring destroy command timed out\n"); + dev_err(tee->dev, "tee: ring destroy command timed out, disabling TEE support\n"); + psp_dead = true; } else if (FIELD_GET(PSP_CMDRESP_STS, reg)) { dev_err(tee->dev, "tee: ring destroy command failed (%#010lx)\n", FIELD_GET(PSP_CMDRESP_STS, reg)); @@ -370,7 +340,7 @@ int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len, if (ret) return ret; - ret = tee_wait_cmd_completion(tee, resp, TEE_DEFAULT_TIMEOUT); + ret = tee_wait_cmd_completion(tee, resp, TEE_DEFAULT_RING_TIMEOUT); if (ret) { resp->flag = CMD_RESPONSE_TIMEDOUT; return ret; diff --git a/drivers/crypto/ccp/tee-dev.h b/drivers/crypto/ccp/tee-dev.h index 49d26158b71e..ea9a2b7c05f5 100644 --- a/drivers/crypto/ccp/tee-dev.h +++ b/drivers/crypto/ccp/tee-dev.h @@ -17,21 +17,10 @@ #include #include -#define TEE_DEFAULT_TIMEOUT 10 +#define TEE_DEFAULT_CMD_TIMEOUT (10 * MSEC_PER_SEC) +#define TEE_DEFAULT_RING_TIMEOUT 10 #define MAX_BUFFER_SIZE 988 -/** - * enum tee_ring_cmd_id - TEE interface commands for ring buffer configuration - * @TEE_RING_INIT_CMD: Initialize ring buffer - * @TEE_RING_DESTROY_CMD: Destroy ring buffer - * @TEE_RING_MAX_CMD: Maximum command id - */ -enum tee_ring_cmd_id { - TEE_RING_INIT_CMD = 0x00010000, - TEE_RING_DESTROY_CMD = 0x00020000, - TEE_RING_MAX_CMD = 0x000F0000, -}; - /** * struct tee_init_ring_cmd - Command to init TEE ring buffer * @low_addr: bits [31:0] of the physical address of ring buffer From patchwork Thu Sep 7 18:48:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13376808 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92DCBEC874D for ; Thu, 7 Sep 2023 18:49:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344323AbjIGSti (ORCPT ); Thu, 7 Sep 2023 14:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344324AbjIGStg (ORCPT ); Thu, 7 Sep 2023 14:49:36 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2051.outbound.protection.outlook.com [40.107.92.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87942B2; Thu, 7 Sep 2023 11:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=diX4bKg9F8hkpxuVVtDiNDG9BG1n4uK/Dt0cZu55JpJy+TjFHz7qI82cOsv1Y1HIfxlemGyCPA4r6Onxd3I/lKkyQRBzgUCMf5t+vIh81WeCnoyoSLymWm0urjAdAShkWje/+/NrOLkNJjlbvPkb4Z5srs4TlYX6HTWAwkhdyiwo7MRznYs5pWDLWrWU/F/N4lf3RkHGo42vhEfckqa6bNtPRdVqzlBvhiXmTxma6kHBYmA2bEcsbsb7qjQ8FjFajFhcOjkjagtNs/L4ZtaV82rlrefDwwoGCqpV0Plm+nsoXclZDLK549L5iW2nYUDteWZZmHQe8LxYCJQcYKlnaA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TdJiPbUYQtU9W2j49ud60rcC0m8WFcBFMQB8d9GdwjU=; b=QxuYdwUg38ZVnpsB0ZCS07bG/vNUub3P0FlT3asnXbp2FOF98uNkAgb1RvTm/SvQe9Ih9kUkkG0e+9sWOW3Z5jPZ7NDhAq6oTY6t7NurqqKe3IWxjIX9FZAiXS6UfQjdxY6BS9ylcQmoSex2AA/PQ1AYZhl7ULEp6YReWEcDBzoiWHp+C/8372vrzhEOhJYobcOxolPXKk882PC7ukvagUiT0GnUJAeLQwb01kA18JzE0c4ywwjymRa1m9VjJySJQsqD+dfDFYGOc6asLt8Stn2S5sR7GsfsG+pLVbPr09wHl0FoA5DnFpLedDPripBJQ1yTXL8n92S9boke/jW31w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=TdJiPbUYQtU9W2j49ud60rcC0m8WFcBFMQB8d9GdwjU=; b=ySxdVlA+v9+qWV6NM4QASNnP4R4UjeGLm2G86iEHbTY94twJVmDhW7OkSG11HZQXX8Omuwz+U8KPMXsivRc5Rb5JLWdQRHWi8KDBlAr2YG+WhwwfTm70j1QfIQI6JdVmQmeeA+XAEVfnzHgrgul/sYUkQNvbeqTx6DBe4cDZt/I= Received: from CH2PR12CA0017.namprd12.prod.outlook.com (2603:10b6:610:57::27) by CY8PR12MB7634.namprd12.prod.outlook.com (2603:10b6:930:9d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30; Thu, 7 Sep 2023 18:49:29 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::3) by CH2PR12CA0017.outlook.office365.com (2603:10b6:610:57::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30 via Frontend Transport; Thu, 7 Sep 2023 18:49:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Thu, 7 Sep 2023 18:49:29 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 7 Sep 2023 13:49:26 -0500 From: Mario Limonciello To: , CC: , , , , , Mario Limonciello Subject: [PATCH 2/5] crypto: ccp: Add support for extended PSP mailbox commands Date: Thu, 7 Sep 2023 13:48:43 -0500 Message-ID: <20230907184846.47598-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907184846.47598-1-mario.limonciello@amd.com> References: <20230907184846.47598-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|CY8PR12MB7634:EE_ X-MS-Office365-Filtering-Correlation-Id: 2be53ce6-04f9-4d14-b866-08dbafd32aae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4k3B/JU91fFvPkaH7XJjItrxr+MLxxV/nQfiqRFc0WbijhIH8P/tPlAy/myA9OiVSeJXDwzY7v56VEPKY+omLyWj40WlpzvYUdwRuGQTYj2ND5cFK+TdV/bYfymZflWXKU5haM++lp6jJRQW6ukclI47eAXh0DVvJdyKD9h7beuy2v+L3P3JBR3Gnoic+WVfFooVdsGh3QSEp7FzV0Ua9DUay5NQYP7cLZr/gd+NTAE+52sXEYCAHbHj/yxGMgbJILvg3Nj4zK3Z7AGO088W+EampNzsUVMwXrrNYANV7MONWEuaAkh/VLNkH4GwSg1ybhV8hkI61+qhTO9nx7iE2TPkK3LyH25mZz9xp7HflGwv4Lsf2S2rbrUbHgJupKn+ycQXErt1u0Ai4KQ50kfc0hiltmFbfM+HYhKMnUbnon1VtqsHEEk/q4DbQKw6+3g68LKpFenwA+03gg1uKFXx2sjkVznTnzo1/drb7TUoLA469i96x+o/YRkgR7hoVV3EZIRW3CeoccyrFP3AHJQL7csVUd8bioAIM0Ursl63VrVlP2xZmClEeNKFwF6Dmx/iwAdC/E6V5fq8nUIuvjy0OWQc5qqJus+ZxlMTpG2vVctFbIoDpAcBxu8E9B17JHO4uqyf+vv7R3+9rfGjZdn3qeCSfGXMmH5Ukjb4F3inY7lZIsiD2xH77sR/Xnpy3N8LHl12THD78tljrJCZsUP/Cw+vS5PdwIm5EBq80NTUDgMVRVqOkoYMHshhE7M5xRv8gsvXFU8N1XJY+jPxgvDW9w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(376002)(39860400002)(136003)(82310400011)(451199024)(1800799009)(186009)(36840700001)(40470700004)(46966006)(44832011)(8676002)(5660300002)(316002)(110136005)(36756003)(70206006)(2906002)(70586007)(54906003)(8936002)(4326008)(41300700001)(40460700003)(16526019)(336012)(1076003)(36860700001)(7696005)(47076005)(26005)(40480700001)(426003)(15650500001)(6666004)(81166007)(356005)(478600001)(83380400001)(2616005)(86362001)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 18:49:29.1329 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2be53ce6-04f9-4d14-b866-08dbafd32aae X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7634 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The PSP mailbox supports a number of extended sub-commands. These subcommands are placed in the header of the buffer sent to the mailbox. Signed-off-by: Mario Limonciello --- drivers/crypto/ccp/psp-dev.c | 24 ++++++++++++++++++++++++ drivers/crypto/ccp/psp-dev.h | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index 3258c4612e14..f9f3b3404f87 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -78,6 +78,30 @@ int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff, return ret; } +int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs, + struct psp_ext_request *req) +{ + unsigned int reg; + int ret; + + print_hex_dump_debug("->psp ", DUMP_PREFIX_OFFSET, 16, 2, req, + req->header.payload_size, false); + + ret = psp_mailbox_command(psp, PSP_CMD_TEE_EXTENDED_CMD, (void *)req, + timeout_msecs, ®); + if (ret) { + return ret; + } else if (FIELD_GET(PSP_CMDRESP_STS, reg)) { + req->header.status = FIELD_GET(PSP_CMDRESP_STS, reg); + return -EIO; + } + + print_hex_dump_debug("<-psp ", DUMP_PREFIX_OFFSET, 16, 2, req, + req->header.payload_size, false); + + return 0; +} + static struct psp_device *psp_alloc_struct(struct sp_device *sp) { struct device *dev = sp->dev; diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index d917657c6085..396a80d846c0 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -78,15 +78,36 @@ struct psp_device *psp_get_master_device(void); * enum psp_cmd - PSP mailbox commands * @PSP_CMD_TEE_RING_INIT: Initialize TEE ring buffer * @PSP_CMD_TEE_RING_DESTROY: Destroy TEE ring buffer + * @PSP_CMD_TEE_EXTENDED_CMD: Extended command * @PSP_CMD_MAX: Maximum command id */ enum psp_cmd { PSP_CMD_TEE_RING_INIT = 1, PSP_CMD_TEE_RING_DESTROY = 2, + PSP_CMD_TEE_EXTENDED_CMD = 14, PSP_CMD_MAX = 15, }; int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff, unsigned int timeout_msecs, unsigned int *cmdresp); +/** + * struct psp_ext_req_buffer_hdr - Structure of the extended command header + * @payload_size: total payload size + * @sub_cmd_id: extended command ID + * @status: status of command execution (out) + */ +struct psp_ext_req_buffer_hdr { + u32 payload_size; + u32 sub_cmd_id; + u32 status; +} __packed; + +struct psp_ext_request { + struct psp_ext_req_buffer_hdr header; + void *buf; +} __packed; + +int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs, + struct psp_ext_request *req); #endif /* __PSP_DEV_H */ From patchwork Thu Sep 7 18:48:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13376809 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F37E5EC8751 for ; Thu, 7 Sep 2023 18:49:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjIGStj (ORCPT ); Thu, 7 Sep 2023 14:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344322AbjIGSth (ORCPT ); Thu, 7 Sep 2023 14:49:37 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83CFCA8; Thu, 7 Sep 2023 11:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FJbVfnUJ8szoEwwxXYhecxR4jN1ZrGVw1DdWtIWwhi9lStzWq9oIcAzcEEYiDPsY/XS17J079O8mHD8l+opsZJbSR/PhsrJk/dmxLaOnc4cc2PmT3ze/dhw608lXEnhC033xIGU8oOLn4CyDO1GP6TqCV83ArPCD52cBIzr2RJ7k4pFbT8gBufaHxssdh7xjL96lHwMtCfmV+WBeCd5b+5sOCS7/1R4Pu47DjfZ0f+Kx5RSJ1YxMs/xO3po1UIZu+MAZ9N89hOGIP00vsQgZyp6ddk1mz3Tl8MTYzPxGfxxOijQxeDcyFwuGkr1dlyOUefS/Oq+OmE8VVYb5C1hn3g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Q2IQE27SmdlUxxU+s78EsdDT5y+56ChsQ7AYlGt0Jao=; b=UFOMba9tcJIeOKVgkeJHjbwpH5BKfX/0/srD01Ajy3ZcxJxL892CWP91c14Sl3VY8DuMMhyuvpLL20+bbhSbk8l7aZPKHgSeq/DgQUkN9yzBZPFfRfx5/mjWgRqPwyeqHDePab0HrlRQKCUoR0Ibt51FAUrFaCYT+w0HUu2W54ZpEy7FjoeuiPs1QhOlb4hbWFGw7fjUBIrk3w0yfHxbcp6C+A93zkA+XL5xkQj0mAGwZsVRPTVTZx9hYMs7l5UR0Zm0xRfxf8IR7vEmCu2Ddc1YSUag1/nrKNoSd/5Hr07H977m7ZMHn2gAhi4IA7Z8kgFJgLdQJGHc2nubT3RqnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=Q2IQE27SmdlUxxU+s78EsdDT5y+56ChsQ7AYlGt0Jao=; b=IycHoL5Gaq34cdKO5xsL1cZtoldQfsRiVhfXoVw8JY+5KNYLrj4/mx+l8yUctt6YZ5/bvwBT8DuHE8mA40WvC+JG9nQLtidWGA0LCXLe4gjhZAHkhsriMAy/agHsQOSzQI8jjaFCF9E7wEfNo8vWamTUMX4UXsiBzt59at3Wc9s= Received: from CH2PR12CA0017.namprd12.prod.outlook.com (2603:10b6:610:57::27) by CY8PR12MB7100.namprd12.prod.outlook.com (2603:10b6:930:60::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Thu, 7 Sep 2023 18:49:30 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::8a) by CH2PR12CA0017.outlook.office365.com (2603:10b6:610:57::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30 via Frontend Transport; Thu, 7 Sep 2023 18:49:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Thu, 7 Sep 2023 18:49:29 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 7 Sep 2023 13:49:27 -0500 From: Mario Limonciello To: , CC: , , , , , Mario Limonciello Subject: [PATCH 3/5] crypto: ccp: Add a communication path abstraction for DBC Date: Thu, 7 Sep 2023 13:48:44 -0500 Message-ID: <20230907184846.47598-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907184846.47598-1-mario.limonciello@amd.com> References: <20230907184846.47598-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|CY8PR12MB7100:EE_ X-MS-Office365-Filtering-Correlation-Id: 489059d0-98cf-4002-c71d-08dbafd32b1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hBhQi5c4VK+LV+fCthf51tVLSnwPFiAkj2/qoB4PLgC/EQmfxinhlgWJoxVQ+3Nl9I9IZS1pcaeOp81V3+aD4EHGpZDSzYaAB0oU9NnnrTGjVb78ORh1mZkylmhH4Y9IFuSEL7SzihW96ImQITiIoxKQasvxu/U/L1e2MHUa9T6IgElTEB0MxolZoQkAi9mERUY0n85kEXwg0V6GpKI4+i/BEWX1UA5mD6fVNw8UmXDv1EynWOFxAGS/kvlhxd3Hmb5bKpGa3IlLJZwCXkB7D+td1zk6Jv7SHqo8A/cUoH7t0HifOlnDm6hfgL/SX9ZLH0a1+BN6xKrEbClqVD+GMj7knM5tTvGN2U0RN5V+BcjaKaomWmmlsvu4GAIOoVKGNzGcQnX6E5uurxZTx3OY1nJ6NE34A1HH7z/5YYVPkR7jDg2AokkZjuLw/oJwEJ+73V5gSqnedChUCaNNZz14wVbkyR7igyFUctBrG6J2SSMUnTcVmGsjXbvJuybyqY/myEKdLimFVRebucj+DGOlPHOQp6+ECUkt8OXcOgOP9zzoxg6umV5U6YR85nt24hfRbXuB69BeHgvjDAytB6cdFgFXjbAXJZ8cuisgtM1Rs6pq5ry4TS8/i/BY+MNwoJ30tHrJZ4Aqqk0pvnro8jk9pH6O73NnCdsRlp0SQKP5kSeMnQK2aLqt8rBrJDw83lkjJTbN5Yp3BJVAUzYvLUWzMTvPWWAqPvJH+HDaEMT9pf2/pPc8t6w99vURUZOAa8gdVyGoEdDvMWjqzN4WaDQoSg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(39860400002)(396003)(346002)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(83380400001)(1076003)(16526019)(26005)(6666004)(44832011)(5660300002)(2616005)(426003)(4326008)(336012)(47076005)(36860700001)(86362001)(8936002)(40480700001)(40460700003)(8676002)(7696005)(41300700001)(81166007)(478600001)(82740400003)(70586007)(36756003)(54906003)(356005)(110136005)(316002)(2906002)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 18:49:29.8673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 489059d0-98cf-4002-c71d-08dbafd32b1e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7100 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org DBC is currently accessed only from the platform access mailbox and a lot of that implementation's communication path is intertwined with DBC. Add an abstraction layer for pointers into the mailbox. No intended functional changes. Signed-off-by: Mario Limonciello --- drivers/crypto/ccp/dbc.c | 37 ++++++++++++++++++------------------- drivers/crypto/ccp/dbc.h | 27 ++++++++------------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index 6f33149ef80d..ebd7279d4001 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -42,17 +42,17 @@ static int send_dbc_cmd(struct psp_dbc_device *dbc_dev, { int ret; - dbc_dev->mbox->req.header.status = 0; + *dbc_dev->result = 0; ret = psp_send_platform_access_msg(msg, (struct psp_request *)dbc_dev->mbox); if (ret == -EIO) { int i; dev_dbg(dbc_dev->dev, "msg 0x%x failed with PSP error: 0x%x\n", - msg, dbc_dev->mbox->req.header.status); + msg, *dbc_dev->result); for (i = 0; error_codes[i].psp; i++) { - if (dbc_dev->mbox->req.header.status == error_codes[i].psp) + if (*dbc_dev->result == error_codes[i].psp) return error_codes[i].ret; } } @@ -64,7 +64,7 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev) { int ret; - dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_nonce); + *dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_nonce); ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_NONCE); if (ret == -EAGAIN) { dev_dbg(dbc_dev->dev, "retrying get nonce\n"); @@ -76,9 +76,9 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev) static int send_dbc_parameter(struct psp_dbc_device *dbc_dev) { - dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_param); + struct dbc_user_param *user_param = (struct dbc_user_param *)dbc_dev->payload; - switch (dbc_dev->mbox->dbc_param.user.msg_index) { + switch (user_param->msg_index) { case PARAM_SET_FMAX_CAP: case PARAM_SET_PWR_CAP: case PARAM_SET_GFX_MODE: @@ -125,8 +125,7 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) switch (cmd) { case DBCIOCNONCE: - if (copy_from_user(&dbc_dev->mbox->dbc_nonce.user, argp, - sizeof(struct dbc_user_nonce))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_nonce))) { ret = -EFAULT; goto unlock; } @@ -135,43 +134,39 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_nonce.user, - sizeof(struct dbc_user_nonce))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_nonce))) { ret = -EFAULT; goto unlock; } break; case DBCIOCUID: - dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_set_uid); - if (copy_from_user(&dbc_dev->mbox->dbc_set_uid.user, argp, - sizeof(struct dbc_user_setuid))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_setuid))) { ret = -EFAULT; goto unlock; } + *dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_setuid); ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_UID); if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_set_uid.user, - sizeof(struct dbc_user_setuid))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_setuid))) { ret = -EFAULT; goto unlock; } break; case DBCIOCPARAM: - if (copy_from_user(&dbc_dev->mbox->dbc_param.user, argp, - sizeof(struct dbc_user_param))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_param))) { ret = -EFAULT; goto unlock; } + *dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_param); ret = send_dbc_parameter(dbc_dev); if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_param.user, - sizeof(struct dbc_user_param))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_param))) { ret = -EFAULT; goto unlock; } @@ -213,6 +208,10 @@ int dbc_dev_init(struct psp_device *psp) psp->dbc_data = dbc_dev; dbc_dev->dev = dev; + dbc_dev->payload_size = &dbc_dev->mbox->pa_req.header.payload_size; + dbc_dev->result = &dbc_dev->mbox->pa_req.header.status; + dbc_dev->payload = &dbc_dev->mbox->pa_req.buf; + dbc_dev->header_size = sizeof(struct psp_req_buffer_hdr); ret = send_dbc_nonce(dbc_dev); if (ret == -EACCES) { diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h index e963099ca38e..184646ee55bb 100644 --- a/drivers/crypto/ccp/dbc.h +++ b/drivers/crypto/ccp/dbc.h @@ -26,28 +26,17 @@ struct psp_dbc_device { struct mutex ioctl_mutex; struct miscdevice char_dev; -}; - -struct dbc_nonce { - struct psp_req_buffer_hdr header; - struct dbc_user_nonce user; -} __packed; -struct dbc_set_uid { - struct psp_req_buffer_hdr header; - struct dbc_user_setuid user; -} __packed; - -struct dbc_param { - struct psp_req_buffer_hdr header; - struct dbc_user_param user; -} __packed; + /* used to abstract communication path */ + bool use_ext; + u32 header_size; + u32 *payload_size; + u32 *result; + void *payload; +}; union dbc_buffer { - struct psp_request req; - struct dbc_nonce dbc_nonce; - struct dbc_set_uid dbc_set_uid; - struct dbc_param dbc_param; + struct psp_request pa_req; }; void dbc_dev_destroy(struct psp_device *psp); From patchwork Thu Sep 7 18:48:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13376810 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8108BEC874D for ; Thu, 7 Sep 2023 18:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344344AbjIGSts (ORCPT ); Thu, 7 Sep 2023 14:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242133AbjIGSti (ORCPT ); Thu, 7 Sep 2023 14:49:38 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2065.outbound.protection.outlook.com [40.107.220.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0490CF; Thu, 7 Sep 2023 11:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rbk06MvtZkAoN9DHb802aDgXXWtnfOnEFGhEKLgXR+r7maUYkfKVrwXy8drMvD9j9AwgksJJUxDpZ7SEQj+JEheEoVJwhXaCoZnUL/BPnkrLwzwoX+XQN7+zIXhkuU7kFzsUcMJo6uo2S0XmzjOMmLdyRVI17dGbq7mvnTGOLfjVBMaTUWNHFAu18MlTl0pwdahjJTALssAS2hdd865HX5fazc16QVbtT8oQMMFKPTOcmqO0aS8d6veMkV6f5M0988sYGKENJYScBCllXfsjYZ0An9ch4xT1k/vAccMECGgvx7d5Hz6BgtpeXiG6tqXEGnFLiKxCxOjehb1UEKLiYQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EbumWYeolBPsI3Sm5htbXd2inrZxxC3FUBCqll0xqzA=; b=AIisX9TmsJhDGM8MQBVPL/sVS6gxccXSUx0Y+JjgJH8iL1Q236YC7cGWSNp+UUEREdAwvuN5EunBM2GbBaU2+w0hS8IAEF9a9w8rZOtzn9jIzpV6oOmFF4dhozMirrfN19VfdD1/draroWujQIuf8Shb/6ugsHMqhxRSl71VRcDKJFHIBOTomnerVJwP48sXjVsgo+4/wyyD8Hg3g1Ay8nSClSbGIMpKnY3LjMggeZSbqqhlobBtE2IE1Kzc6LTpQDR73N2dRMiCQGqLIWX13TrfX/knluV618fj+bg4xvOUPvRB57WVfNxz86dvGvRc/vL1DozKYPZWZRNvUs4Grw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=EbumWYeolBPsI3Sm5htbXd2inrZxxC3FUBCqll0xqzA=; b=TW1kJuplVUeFMSaUjLbeHe7gYClsUHyusf/KLgclXrLvQAhqctU88Q1HJCQ1fM/3+VGNJ0fgKkDbXS0xtMhIV9SuLvzh51FJFJUEsYE5fE83Rx/8LO+z1ud6/rFFIeY8Epthk/ScWZlVvpgEM61IVzynCKqmQlP6mZxXDMTV6aU= Received: from CH2PR12CA0020.namprd12.prod.outlook.com (2603:10b6:610:57::30) by PH7PR12MB6786.namprd12.prod.outlook.com (2603:10b6:510:1ac::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30; Thu, 7 Sep 2023 18:49:31 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::65) by CH2PR12CA0020.outlook.office365.com (2603:10b6:610:57::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30 via Frontend Transport; Thu, 7 Sep 2023 18:49:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Thu, 7 Sep 2023 18:49:30 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 7 Sep 2023 13:49:27 -0500 From: Mario Limonciello To: , CC: , , , , , Mario Limonciello Subject: [PATCH 4/5] crypto: ccp: Add a macro to check capabilities register Date: Thu, 7 Sep 2023 13:48:45 -0500 Message-ID: <20230907184846.47598-5-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907184846.47598-1-mario.limonciello@amd.com> References: <20230907184846.47598-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|PH7PR12MB6786:EE_ X-MS-Office365-Filtering-Correlation-Id: d3930886-9968-4fad-ffb2-08dbafd32b57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j3bc6xOe3QWswppchvWv4qdcrSnPX9nSvHt/WCGcbE3PoKCbcVYlSms3Ekf9HCocdNMbpZQ9m8AKkL3HN44wjRI0xrSjwAWXAeRIWf+z8pxvlcZlJLZFMRb6M5BUSN6qOPYnlMLsKKAnPUmNxe7c59D9r4QaQJ+KS+X5Ezu/Kh2PQ6OiJ6r3MSBkKepW7yq2cB4gX6OyWU++Cb2KvC3JPcLR3xI+eV46V24Nf+AXGOENxEpaLNn0qlLthBQx2Y+t6BjH2Lj5WXIfRbqxpkrMy29Edex12sygsZDW7tGthPDU9Jy1X82UX0c0hIIqIXyGxjumKrlW4hnRhQNdYOQnCNEOPBXhPlG7BMwT1dOCm/ap+V1sOFCAE3oedy63K7mEFnEAnpCqo4qjyxWueLh+rAq7M/ZAiQHFqKJ+o9yQOsbb/th0Al+b2TT++XJn733Rcykgg/02GBa5QdnNIF7aTmiwVsTWM2WiNlRttBF/6igU4TPqLxEnQjhEF9Tn4N+42DoQG9IVTQFNDnjZwlSXnSIWuWtgJECBYcMEshL4UWrJBDz8S46aft1UROlRl22ZieFdHtPI+j0Wn/q1wx9PuA1dgUm8lyTiCIxjHc0kONAX9mIYHpu7lbE/vaiwgiHJGR2q9A3EyczA5RrJfFrSxT5a7tz8dul1QimNBM5Wmnc4Ilz3mOH9khpNJbwzMPCv5zs0WfOAo/sxZOJ0aeMBjkSr1MuSWpgtO9+zo2k06OcFFJHZ4Wv7KVN53Y6J0/F1s2UOuwvAUrAIUx5y36qrCg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(346002)(376002)(136003)(396003)(451199024)(186009)(82310400011)(1800799009)(36840700001)(40470700004)(46966006)(41300700001)(8936002)(83380400001)(40480700001)(44832011)(6666004)(478600001)(2906002)(5660300002)(110136005)(70206006)(70586007)(8676002)(316002)(4326008)(54906003)(2616005)(1076003)(7696005)(16526019)(26005)(40460700003)(36860700001)(426003)(336012)(36756003)(81166007)(356005)(82740400003)(86362001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 18:49:30.2423 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3930886-9968-4fad-ffb2-08dbafd32b57 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6786 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Offsets are checked by the capabilities register in multiple places. To make the code more readable add a macro. Signed-off-by: Mario Limonciello --- drivers/crypto/ccp/psp-dev.c | 6 +++--- drivers/crypto/ccp/sp-dev.h | 1 + drivers/crypto/ccp/sp-pci.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index f9f3b3404f87..5f61b23695d5 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -157,7 +157,7 @@ static unsigned int psp_get_capability(struct psp_device *psp) psp->capability = val; /* Detect if TSME and SME are both enabled */ - if (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING && + if (PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING) && psp->capability & (PSP_SECURITY_TSME_STATUS << PSP_CAPABILITY_PSP_SECURITY_OFFSET) && cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) dev_notice(psp->dev, "psp: Both TSME and SME are active, SME is unnecessary when TSME is active.\n"); @@ -168,7 +168,7 @@ static unsigned int psp_get_capability(struct psp_device *psp) static int psp_check_sev_support(struct psp_device *psp) { /* Check if device supports SEV feature */ - if (!(psp->capability & PSP_CAPABILITY_SEV)) { + if (!PSP_CAPABILITY(psp, SEV)) { dev_dbg(psp->dev, "psp does not support SEV\n"); return -ENODEV; } @@ -179,7 +179,7 @@ static int psp_check_sev_support(struct psp_device *psp) static int psp_check_tee_support(struct psp_device *psp) { /* Check if device supports TEE feature */ - if (!(psp->capability & PSP_CAPABILITY_TEE)) { + if (!PSP_CAPABILITY(psp, TEE)) { dev_dbg(psp->dev, "psp does not support TEE\n"); return -ENODEV; } diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index c4e125efe6c7..03d5b9e04084 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -30,6 +30,7 @@ #define PLATFORM_FEATURE_DBC 0x1 +#define PSP_CAPABILITY(psp, cap) (psp->capability & PSP_CAPABILITY_##cap) #define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat) /* Structure to hold CCP device data */ diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index d1aedc5c1a68..300dda14182b 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -84,7 +84,7 @@ static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *a struct sp_device *sp = dev_get_drvdata(dev); struct psp_device *psp = sp->psp_data; - if (psp && (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING)) + if (psp && PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING)) return 0444; return 0; @@ -135,7 +135,7 @@ static umode_t psp_firmware_is_visible(struct kobject *kobj, struct attribute *a val = ioread32(psp->io_regs + psp->vdata->bootloader_info_reg); if (attr == &dev_attr_tee_version.attr && - psp->capability & PSP_CAPABILITY_TEE && + PSP_CAPABILITY(psp, TEE) && psp->vdata->tee->info_reg) val = ioread32(psp->io_regs + psp->vdata->tee->info_reg); From patchwork Thu Sep 7 18:48:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13376811 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 051A4EC8750 for ; Thu, 7 Sep 2023 18:50:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344367AbjIGSuC (ORCPT ); Thu, 7 Sep 2023 14:50:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344372AbjIGStr (ORCPT ); Thu, 7 Sep 2023 14:49:47 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2072.outbound.protection.outlook.com [40.107.101.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11967E6B; Thu, 7 Sep 2023 11:49:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XvGWJkUqJrT8ZnTsDcWizXVSH837owP4NZFROSizb/X0FPVVtGGt2WQSoakHA23IkRJDoIHPbgWdYhOLj/YiBXY9r8mkih7UH/oVWNuxGH3K8bxTiofvgaRlLvYpMfrOUcY/uT/arhuWZiWtppUYskFc3AFIOeBbLKfTj4cwGJaowjumSYNLdVBzfUMuWR5vvZPfuwiQgOSpwNcg7khCdBTIt90tAUBhclng8dRc176ZMNGb8Cm4mv5B0pY4iCKz5XLF0yW4fIb0gG94+A+uXCKyXzU0fX557HJJqEG3TZ8+NpefAXbmnHnu1jfpdt76/Fdqsv2es3LnsW6JpMHR5g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UP1pTXemuyVGairiicLP5kB3uzt703PKsAd2t4+44Qc=; b=HjCKoXuCKLlbNaHWmy1q61CVMQFazkvAnBT5C55WElo4aZBBTY3My6T5Y/4FCO+nhuXpG3IU148ilCUTeLFlsaBV2Ha6/YCXUfgYOICiVybl68KU1fjglQPvRon4yUd7PoGpZt8U1Cy0uf1UsvdzTeY+VO3tciud/tH1ffV4bssWgy68mgSSxqWg5NHh2pk5JYZNl5S9mM/y1/WsuDV++eG57vUTFzhyWC2sgFn7n8bRAEkW9PWkK0xvcOkyDNN71AGC6opehnNNuZFAUxtHB2RUvH7nKrPPrW5HmisRCA0u2D2xwstuV71nAsmvCRksNdjDXNIz5qqMEu3F5cUaPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=UP1pTXemuyVGairiicLP5kB3uzt703PKsAd2t4+44Qc=; b=rS0pu3BcLse/DJtOMwxf9ThEOEER6G2Vs/Pw74ROgVRKoYij5bvaIRrfuWmGWdKEDlqI0CIoTO+AKoT4MOh7DKVM7uGAEWu7XYcwNcEhQpzk25W/GrulkrnBXiF8KipeUQ0Cch0HOjfzL9uMokxkei+76C3Nn8bETObz24vDnPw= Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by PH7PR12MB9126.namprd12.prod.outlook.com (2603:10b6:510:2f0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.32; Thu, 7 Sep 2023 18:49:32 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:610:57:cafe::68) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30 via Frontend Transport; Thu, 7 Sep 2023 18:49:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Thu, 7 Sep 2023 18:49:31 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 7 Sep 2023 13:49:28 -0500 From: Mario Limonciello To: , CC: , , , , , Mario Limonciello Subject: [PATCH 5/5] crypto: ccp: Add support for DBC over PSP mailbox Date: Thu, 7 Sep 2023 13:48:46 -0500 Message-ID: <20230907184846.47598-6-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907184846.47598-1-mario.limonciello@amd.com> References: <20230907184846.47598-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|PH7PR12MB9126:EE_ X-MS-Office365-Filtering-Correlation-Id: 818f923a-b8ed-4ff4-6e23-08dbafd32c08 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z6OZOc1luKidcPZ2nlbqlfa4QYGQBDGb/Ey33/L3B04b+cemvn7DmZYZIoP4ekmOwX/o0qir177JFzk40iVNbPDBOaEI1tsXvlCTUwbyDJqy7L1F+CBa2tANaJ76ijOL6mi0xC/9y/jH8/WMcvi9LBSCMS304eWB+zT2PdYk4UA/vjU0K4xwXvjmcRczSdFVG9AHgqjJH/RUIgvOLU3cafrgVKcSEMLi4UlHRLO3BoehgKFUyNtllf2yuNou2k3RBNz1f2OUZ7rpW5gDDRIKBAmSiXlfL9E4RU8rUDN6CgW4oMw3WZLPojIPJ0Kq+CfnrJlEzYWUSb3ZiCojVaOafgUEPl2aTbJev7HGrsxNJkqj/XMGyBy37E4jAOLgtdiwcA6j7sO46CSfNfi5pE6qIYNWdpK+iBgjWpKRCkt0YMAt6VzzMvR+QK8NfdJJ7ZS0K7Z4pGNJzzL2IZ0JM8eu6dOtgkJWfIIw31M4FVZwC02ARhurnzVAHij1q8OV8CF6ccGzHbqHuVPQcWiN0q7sqbovWvBBDu3asC88agNeygWsPX19mBnm9Ek74s4CroHdkwbN77TeTdlo1C+C7MWSOon6u4TAKS93IUjIAvbnXbXXahOrIDzsoJbXtw+/wyG0eISH14mM33uvxcUj/fdX76neNZFu3GTR5BwOoMoGJC00u/WLc91tvsFxp8e1IDy7oHgFyanLo6YaV3uz+6P5NvSbv9r6hhw/Qt7Lk8ygCuQ26vTQCaxjfHTI5XRQsg7fit4txrE3sPZrt/0yXDphWw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(346002)(396003)(136003)(376002)(186009)(1800799009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(41300700001)(356005)(478600001)(6666004)(82740400003)(336012)(81166007)(26005)(86362001)(2616005)(83380400001)(1076003)(40460700003)(7696005)(47076005)(15650500001)(36860700001)(40480700001)(16526019)(426003)(70206006)(54906003)(2906002)(316002)(110136005)(70586007)(36756003)(8676002)(5660300002)(8936002)(4326008)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 18:49:31.3986 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 818f923a-b8ed-4ff4-6e23-08dbafd32c08 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9126 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On some SOCs DBC is supported through the PSP mailbox instead of the platform mailbox. This capability is advertised in the PSP capabilities register. Allow using this communication path if supported. Signed-off-by: Mario Limonciello --- drivers/crypto/ccp/dbc.c | 43 +++++++++++++++++++++++++++--------- drivers/crypto/ccp/dbc.h | 2 ++ drivers/crypto/ccp/psp-dev.c | 32 +++++++++++---------------- drivers/crypto/ccp/psp-dev.h | 16 ++++++++++++++ 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index ebd7279d4001..d373caab52f8 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -9,6 +9,7 @@ #include "dbc.h" +#define DBC_DEFAULT_TIMEOUT (10 * MSEC_PER_SEC) struct error_map { u32 psp; int ret; @@ -37,13 +38,28 @@ static struct error_map error_codes[] = { {0x0, 0x0}, }; -static int send_dbc_cmd(struct psp_dbc_device *dbc_dev, - enum psp_platform_access_msg msg) +static inline int send_dbc_cmd_thru_ext(struct psp_dbc_device *dbc_dev, int msg) +{ + dbc_dev->mbox->ext_req.header.sub_cmd_id = msg; + + return psp_extended_mailbox_cmd(dbc_dev->psp, + DBC_DEFAULT_TIMEOUT, + (struct psp_ext_request *)dbc_dev->mbox); +} + +static inline int send_dbc_cmd_thru_pa(struct psp_dbc_device *dbc_dev, int msg) +{ + return psp_send_platform_access_msg(msg, + (struct psp_request *)dbc_dev->mbox); +} + +static int send_dbc_cmd(struct psp_dbc_device *dbc_dev, int msg) { int ret; *dbc_dev->result = 0; - ret = psp_send_platform_access_msg(msg, (struct psp_request *)dbc_dev->mbox); + ret = dbc_dev->use_ext ? send_dbc_cmd_thru_ext(dbc_dev, msg) : + send_dbc_cmd_thru_pa(dbc_dev, msg); if (ret == -EIO) { int i; @@ -192,9 +208,6 @@ int dbc_dev_init(struct psp_device *psp) struct psp_dbc_device *dbc_dev; int ret; - if (!PSP_FEATURE(psp, DBC)) - return 0; - dbc_dev = devm_kzalloc(dev, sizeof(*dbc_dev), GFP_KERNEL); if (!dbc_dev) return -ENOMEM; @@ -208,10 +221,20 @@ int dbc_dev_init(struct psp_device *psp) psp->dbc_data = dbc_dev; dbc_dev->dev = dev; - dbc_dev->payload_size = &dbc_dev->mbox->pa_req.header.payload_size; - dbc_dev->result = &dbc_dev->mbox->pa_req.header.status; - dbc_dev->payload = &dbc_dev->mbox->pa_req.buf; - dbc_dev->header_size = sizeof(struct psp_req_buffer_hdr); + dbc_dev->psp = psp; + + if (PSP_CAPABILITY(psp, DBC_THRU_EXT)) { + dbc_dev->use_ext = true; + dbc_dev->payload_size = &dbc_dev->mbox->ext_req.header.payload_size; + dbc_dev->result = &dbc_dev->mbox->ext_req.header.status; + dbc_dev->payload = &dbc_dev->mbox->ext_req.buf; + dbc_dev->header_size = sizeof(struct psp_ext_req_buffer_hdr); + } else { + dbc_dev->payload_size = &dbc_dev->mbox->pa_req.header.payload_size; + dbc_dev->result = &dbc_dev->mbox->pa_req.header.status; + dbc_dev->payload = &dbc_dev->mbox->pa_req.buf; + dbc_dev->header_size = sizeof(struct psp_req_buffer_hdr); + } ret = send_dbc_nonce(dbc_dev); if (ret == -EACCES) { diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h index 184646ee55bb..e0fecbe92eb1 100644 --- a/drivers/crypto/ccp/dbc.h +++ b/drivers/crypto/ccp/dbc.h @@ -20,6 +20,7 @@ struct psp_dbc_device { struct device *dev; + struct psp_device *psp; union dbc_buffer *mbox; @@ -37,6 +38,7 @@ struct psp_dbc_device { union dbc_buffer { struct psp_request pa_req; + struct psp_ext_request ext_req; }; void dbc_dev_destroy(struct psp_device *psp); diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index 5f61b23695d5..124a2e0c8999 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -187,23 +187,6 @@ static int psp_check_tee_support(struct psp_device *psp) return 0; } -static void psp_init_platform_access(struct psp_device *psp) -{ - int ret; - - ret = platform_access_dev_init(psp); - if (ret) { - dev_warn(psp->dev, "platform access init failed: %d\n", ret); - return; - } - - /* dbc must come after platform access as it tests the feature */ - ret = dbc_dev_init(psp); - if (ret) - dev_warn(psp->dev, "failed to init dynamic boost control: %d\n", - ret); -} - static int psp_init(struct psp_device *psp) { int ret; @@ -220,8 +203,19 @@ static int psp_init(struct psp_device *psp) return ret; } - if (psp->vdata->platform_access) - psp_init_platform_access(psp); + if (psp->vdata->platform_access) { + ret = platform_access_dev_init(psp); + if (ret) + return ret; + } + + /* dbc must come after platform access as it tests the feature */ + if (PSP_FEATURE(psp, DBC) || + PSP_CAPABILITY(psp, DBC_THRU_EXT)) { + ret = dbc_dev_init(psp); + if (ret) + return ret; + } return 0; } diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index 396a80d846c0..ae582ba63729 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "sp-dev.h" @@ -56,6 +57,7 @@ struct psp_device *psp_get_master_device(void); #define PSP_CAPABILITY_SEV BIT(0) #define PSP_CAPABILITY_TEE BIT(1) +#define PSP_CAPABILITY_DBC_THRU_EXT BIT(2) #define PSP_CAPABILITY_PSP_SECURITY_REPORTING BIT(7) #define PSP_CAPABILITY_PSP_SECURITY_OFFSET 8 @@ -108,6 +110,20 @@ struct psp_ext_request { void *buf; } __packed; +/** + * enum psp_sub_cmd - PSP mailbox sub commands + * @PSP_SUB_CMD_DBC_GET_NONCE: Get nonce from DBC + * @PSP_SUB_CMD_DBC_SET_UID: Set UID for DBC + * @PSP_SUB_CMD_DBC_GET_PARAMETER: Get parameter from DBC + * @PSP_SUB_CMD_DBC_SET_PARAMETER: Set parameter for DBC + */ +enum psp_sub_cmd { + PSP_SUB_CMD_DBC_GET_NONCE = PSP_DYNAMIC_BOOST_GET_NONCE, + PSP_SUB_CMD_DBC_SET_UID = PSP_DYNAMIC_BOOST_SET_UID, + PSP_SUB_CMD_DBC_GET_PARAMETER = PSP_DYNAMIC_BOOST_GET_PARAMETER, + PSP_SUB_CMD_DBC_SET_PARAMETER = PSP_DYNAMIC_BOOST_SET_PARAMETER, +}; + int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs, struct psp_ext_request *req); #endif /* __PSP_DEV_H */