From patchwork Fri Jun 23 13:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695904 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 3D850C001B1 for ; Fri, 23 Jun 2023 18:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjFWSbn (ORCPT ); Fri, 23 Jun 2023 14:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbjFWSbm (ORCPT ); Fri, 23 Jun 2023 14:31:42 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2040.outbound.protection.outlook.com [40.107.93.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2F0271F; Fri, 23 Jun 2023 11:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OBh/NMDV1KGdT1DXTsSwvd/lm9iFP7IkJNeBC/tzZRCkA2Dpog8jV5O+6I8DxDABI/5CeR/RHArY2Q59XGL8dic5unLD1J+NtIgwGee47t4IETu6xuRXEfSOTDAeWMuusTa9dxWlXMqQIKuz7BRpvC3DLyI1obtp9oxfizArE6e4eOHVX8sbOXDfnVorFqOh1lNtuvun6NjPXtGNqrJ1WV0kbpT+ABrVjnaytCq+kxGR56RvK7qnC0do0QYIuwM8ndu4/RG+oxw1N0cUS1iLn+szkIs2cGtbC5ULRIUWZ8hD+u207Q1e79ViRWouN3IQ5/lU5xTEl4QpR/iBsHB8Mg== 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=63gLjc6DoFoLBycn3sColfuDTY1sT7xAsRgZo48WJrQ=; b=Vdz+2DI30x1G+ggbCTgToK1cOluHOBhH8kZTLbGDYBN95QREJj+Q+y23y8irC103bSJA5C9PzkFKI6A8RJVgr3SJI/EbwQb4X4Si47K+B/ZChUknilMlF7jvdQdVUVUvwA4IQkpn+mLCVxeSOfEhH6+lFN1jWIA1wpoOjozP+h9JXVgLb7u+19+u/6uOhz1tyLejQ/4pkOijdeMNgdLS+BSRHigI1zMz7ssBSscCSB4dA2GfBY1YROgkz3uW6c6xhHeCKmuy8gTVIugUR3yacbwrmNa8MgdhA7n5bWesULQX2e20LHaklVjzYCtp7pibkMUfAbPqf2F4HnmAwYCOeg== 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=63gLjc6DoFoLBycn3sColfuDTY1sT7xAsRgZo48WJrQ=; b=c5U3wQuR9F4/zi+uIcS9cZ/XftEqzmJaP4lJNr5WtICPiYzsiT49OrmCifv6iKoQKuIy5UL+wCMPHCiSfluvryrGd++a2KhVCyglbIil7EQZkNpm9WIFHR1cWldEHmy97HGaVB7kzQA3C+fB80ndH59FoegBjZJYssS024IcVzs= Received: from BL1P221CA0026.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::27) by DM4PR12MB5150.namprd12.prod.outlook.com (2603:10b6:5:391::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Fri, 23 Jun 2023 18:31:35 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::3a) by BL1P221CA0026.outlook.office365.com (2603:10b6:208:2c5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:34 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:33 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:32 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 01/11] crypto: ccp: Rename macro for security attributes Date: Fri, 23 Jun 2023 08:49:51 -0500 Message-ID: <20230623135001.18672-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|DM4PR12MB5150:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a700fa3-4b81-465c-2f03-08db74181264 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gVvAONk4RLtyyrQ37oRz7q8BTrRv3ZX0y7yEiZgycDsDHbT5dNkU8vFqccXThJxrTPGGiT2H7XTmFaxrmB+9w1q9b/UHemC1N4JBJDbDTSu7m6vs26W+Mo6cL9PIPqfX8ocV7ZCYr5BSg51CJLZtriGH4V6WgjmFY6nsh8ew3elbpW6yJzyzdV/9nZM0NOugzOmQoka3OnoO1hsiMoofTEZhuB9fCum2SvtBbTGTj1EO2k/edv/m+IgeLYmnfRWID5RmA9r4/zDzJfX7MhjPR/BaUY0ic+k9Nn9fkDLrF4DBRbM/Lk3HDzmhi+j54CpxM2o0X1N7UgzyvWfkYja02/lAQ2LOfvYWReOq/DLS3WUaeyVTQ4Zsk8ToY1uAgMqzvOqUUsms/PyNFKQA8e/tcxJtTWy2BZhQibqeAvP4wV1k7s9WJ05/dkcWNX44a5bcz/Sj06MjlnTaKEVDMr6NeE2IZpnutlzCDqoiYW26sRSVkYaurtLJ31hwYt36FYnpmPBipVt5nX/eOncohkI/KghOxWQynXUvfbLPui+fr+KlwtIEvtD/iH8ilQXqIJUGfwn/RZbK+BdZMmtWAQQmeYhrOhChAc6MawsvWQurR/NV+gtreZ8mO9lrm1/pDiQOf88eMweePKc5/5aAZrJGCUwRGBKQteHB5yRgPfJ7mnpZH6eHP7wGX6uE9r3qKAGe/1vKSEPjCeO+DTW3+hhKoD/pQpelcVI2rKVMB8NqCVDSCIuWShKxkiWmk8AjBE3/a+NnuPxupG16aXlgaeneAw== 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:(13230028)(4636009)(346002)(376002)(39860400002)(136003)(396003)(451199021)(40470700004)(36840700001)(46966006)(16526019)(36860700001)(15650500001)(1076003)(36756003)(4326008)(316002)(70206006)(44832011)(70586007)(5660300002)(2906002)(8676002)(8936002)(41300700001)(40460700003)(40480700001)(82740400003)(478600001)(54906003)(7696005)(47076005)(110136005)(86362001)(82310400005)(426003)(26005)(186003)(356005)(81166007)(2616005)(336012)(6666004)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:33.9181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a700fa3-4b81-465c-2f03-08db74181264 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5150 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The attribute_show() macro is only valid for determining the availability of security related sysfs entries. Rename the macro to better show this relationship. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v2->v3: * Pick up tag --- drivers/crypto/ccp/sp-pci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index b603ad9b8341b..c8f075a7f49f8 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -32,7 +32,7 @@ struct sp_pci { }; static struct sp_device *sp_dev_master; -#define attribute_show(name, def) \ +#define security_attribute_show(name, def) \ static ssize_t name##_show(struct device *d, struct device_attribute *attr, \ char *buf) \ { \ @@ -42,24 +42,24 @@ static ssize_t name##_show(struct device *d, struct device_attribute *attr, \ return sysfs_emit(buf, "%d\n", (psp->capability & bit) > 0); \ } -attribute_show(fused_part, FUSED_PART) +security_attribute_show(fused_part, FUSED_PART) static DEVICE_ATTR_RO(fused_part); -attribute_show(debug_lock_on, DEBUG_LOCK_ON) +security_attribute_show(debug_lock_on, DEBUG_LOCK_ON) static DEVICE_ATTR_RO(debug_lock_on); -attribute_show(tsme_status, TSME_STATUS) +security_attribute_show(tsme_status, TSME_STATUS) static DEVICE_ATTR_RO(tsme_status); -attribute_show(anti_rollback_status, ANTI_ROLLBACK_STATUS) +security_attribute_show(anti_rollback_status, ANTI_ROLLBACK_STATUS) static DEVICE_ATTR_RO(anti_rollback_status); -attribute_show(rpmc_production_enabled, RPMC_PRODUCTION_ENABLED) +security_attribute_show(rpmc_production_enabled, RPMC_PRODUCTION_ENABLED) static DEVICE_ATTR_RO(rpmc_production_enabled); -attribute_show(rpmc_spirom_available, RPMC_SPIROM_AVAILABLE) +security_attribute_show(rpmc_spirom_available, RPMC_SPIROM_AVAILABLE) static DEVICE_ATTR_RO(rpmc_spirom_available); -attribute_show(hsp_tpm_available, HSP_TPM_AVAILABLE) +security_attribute_show(hsp_tpm_available, HSP_TPM_AVAILABLE) static DEVICE_ATTR_RO(hsp_tpm_available); -attribute_show(rom_armor_enforced, ROM_ARMOR_ENFORCED) +security_attribute_show(rom_armor_enforced, ROM_ARMOR_ENFORCED) static DEVICE_ATTR_RO(rom_armor_enforced); -static struct attribute *psp_attrs[] = { +static struct attribute *psp_security_attrs[] = { &dev_attr_fused_part.attr, &dev_attr_debug_lock_on.attr, &dev_attr_tsme_status.attr, @@ -83,13 +83,13 @@ static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *a return 0; } -static struct attribute_group psp_attr_group = { - .attrs = psp_attrs, +static struct attribute_group psp_security_attr_group = { + .attrs = psp_security_attrs, .is_visible = psp_security_is_visible, }; static const struct attribute_group *psp_groups[] = { - &psp_attr_group, + &psp_security_attr_group, NULL, }; From patchwork Fri Jun 23 13:49:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695355 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 8172EEB64D7 for ; Fri, 23 Jun 2023 18:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbjFWSbp (ORCPT ); Fri, 23 Jun 2023 14:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbjFWSbm (ORCPT ); Fri, 23 Jun 2023 14:31:42 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2081.outbound.protection.outlook.com [40.107.100.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C5D273D; Fri, 23 Jun 2023 11:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cSj4GL9o/CM1r8L/uoSo2U0W7Ir9gnC3OYU906hLzTGvSuE5Snh+2x8PgvBGjuhkDFMXxzjU9vlmGkKQiiAhGzwDoiw7ce3M+AXZv+aDGz2Yy/gFaGbuA8Wc/WIpyq4Nfxhy4ziAZlJJ4I1Sx/2tq2bnnestOc3ulwpq5qEoL7qQ1+UlFBDrMt6lpz/yBYltPZBk8aJKMowZoJr0+uZJS//sskrWUtx6K53XZuEGIx8n/G1nnytBQz/1kfDY9NkzhbhuQKdxDyWxCp98vLey5hQ6xDh0nSKAE7hUwhwbw8S8wQeNCF2/MB35g8/nQZZAfxC6KEIz2Wq+ZZ8kjAbp6g== 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=DOgWAtmbQ9NKRLIoXi4mJluXR/PtiZR/5JkJirvtQD8=; b=IRgF7s3qvX6h/8DvzrzyRJJtMnk/yQNKTY0bew07L63Vvb/itqx+b8VReYBmjWcA3WzkEyNB7b0Lza2JkBTnI/Gry4gxww6b+A6UL+gzy9INjmXLZd2s3szGvVECdatPOQ+SzcZHFF55dYos8gnj5QB0mtwabDCpOXEZvLCeADyXOslVCrLK2gTkMEnz4kw0dq9Oeke2OB25mx9ipl/nGPd32tQOYzIcZ6Ij7roOeTxXE7qz0hU1pfNjcTvjgRAwjkF7BwBEYPo77zYMX94JnwIDh8L0j0QTO6WVy3s2qE4WRbmFKXJnlomxR0Z8YnknPuLfIGB4jmAVrENjNakaHA== 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=DOgWAtmbQ9NKRLIoXi4mJluXR/PtiZR/5JkJirvtQD8=; b=OJ77BOuUM7i4IuxiSvwauvTQECBSdTBCF0APDh8JQVvYjyoRC1OFaeRfzirtlpR89TcDDzYpLgt+PUad9C4KFuPCa83hIqspw9j7f5p1cdBwETe5A36ntTrYtQNiqmsomtf78e4LIwIDO39STamm6DJRhblF8vdWsyo8pZtGwTU= Received: from BL1P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::9) by BN9PR12MB5368.namprd12.prod.outlook.com (2603:10b6:408:105::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Fri, 23 Jun 2023 18:31:35 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::d) by BL1P221CA0003.outlook.office365.com (2603:10b6:208:2c5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:35 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:35 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:33 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 02/11] crypto: ccp: Add support for displaying PSP firmware versions Date: Fri, 23 Jun 2023 08:49:52 -0500 Message-ID: <20230623135001.18672-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|BN9PR12MB5368:EE_ X-MS-Office365-Filtering-Correlation-Id: a2cd502c-92f6-4499-87d9-08db7418133f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0v2IrpqORLZnjNXe1cgmBUfeO7iGi2qXyvChq2zp+WF+m8CWUV8reCj99F3cItUen3ntCTfJfvPMHYvZb5ZsYuBKrEM6nk2fGLCg2MQjqggi5bZ6V4W8N8uzg/+f6HUV4Xfl93WdAmX5IjsbR9b30d5nNXO6AchFp676bdvCs5VB322UonS5872s3+DZNRk9tI+wHsglAZmJNgzvGjw7Y7W4aUiLDzGwDxFkwod0ZHs4Cs4I7bmNe81gqzBrPck1ZdCH3vaoELt4EBRbc27Qj+2rcfRAEzB/TDJWvptpeVis0qj+wTcDWBIf6p3oogyv3gVAuE/jkpNaNv4Hh8L4UUn1TuxD7bBlOcPXmEMT0WukElG+eQ8RGnM90msldyxFX32zYPbSy5Du0f03BBvBOGtmVrgY/oDU6AxdeRnMUkER/+f2mzmCs7U+JXHeJmfUuqWx+E7WV47C4r1yBq1k0ZVKKMJPAccL4chAAvRtXPa2MApzoMvbMjx2+RUjYBO3RANHZvj2H33tKKOA3nJUuNcsfiMPBkvHwN0H12CulIfC4MgEW8Xsyq/IJWAweyVCqEzU4ITob0JVny7L5x0ZX8g6GraGX0EKFi0pRYx3ydfb6pK0aR2LJXHzsrTcRq8KoaYHdlU9KwEZOuNcZDAnPOYZT/JkhjWmeKqsd2/dIx4OG4O8NLIvZeyurApIQjTO6SemS45sCHT3ARDxn8sOkxLVc2OqJyJCqGKp7509jB7POTu45CgotJGKutwAjOdMEZS4QXHYUosPvqVd3oecjA== 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:(13230028)(4636009)(39860400002)(376002)(346002)(396003)(136003)(451199021)(40470700004)(46966006)(36840700001)(478600001)(6666004)(7696005)(426003)(1076003)(110136005)(5660300002)(83380400001)(54906003)(4326008)(70206006)(70586007)(8676002)(41300700001)(8936002)(336012)(44832011)(36860700001)(186003)(2906002)(47076005)(36756003)(82740400003)(16526019)(26005)(356005)(81166007)(82310400005)(40460700003)(316002)(2616005)(86362001)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:35.3712 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2cd502c-92f6-4499-87d9-08db7418133f 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5368 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org As it's not always obvious what PSP bootloader or TEE version are present in OEM systems, add the ability to get this information from sysfs for supported platforms. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v2->v3: * Pick up tag v1->v2: * Move GENMASK declarations to top of the file * Add comment to support why checking for 0xffffffff --- Documentation/ABI/testing/sysfs-driver-ccp | 18 ++++++ drivers/crypto/ccp/sp-dev.h | 2 + drivers/crypto/ccp/sp-pci.c | 64 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-driver-ccp b/Documentation/ABI/testing/sysfs-driver-ccp index 7aded9b755535..ee6b787eee7a0 100644 --- a/Documentation/ABI/testing/sysfs-driver-ccp +++ b/Documentation/ABI/testing/sysfs-driver-ccp @@ -85,3 +85,21 @@ Description: Possible values: 0: Not enforced 1: Enforced + +What: /sys/bus/pci/devices//bootloader_version +Date: June 2023 +KernelVersion: 6.4 +Contact: mario.limonciello@amd.com +Description: + The /sys/bus/pci/devices//bootloader_version + file reports the firmware version of the AMD AGESA + bootloader. + +What: /sys/bus/pci/devices//tee_version +Date: June 2023 +KernelVersion: 6.4 +Contact: mario.limonciello@amd.com +Description: + The /sys/bus/pci/devices//tee_version + file reports the firmware version of the AMD Trusted + Execution Environment (TEE). diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index 1253a02179858..76c32ee6bd657 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -51,6 +51,7 @@ struct tee_vdata { const unsigned int cmdbuff_addr_hi_reg; const unsigned int ring_wptr_reg; const unsigned int ring_rptr_reg; + const unsigned int info_reg; }; struct platform_access_vdata { @@ -69,6 +70,7 @@ struct psp_vdata { const unsigned int feature_reg; const unsigned int inten_reg; const unsigned int intsts_reg; + const unsigned int bootloader_info_reg; }; /* Structure to hold SP device data */ diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index c8f075a7f49f8..6c93577950c7b 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -8,6 +8,7 @@ * Author: Gary R Hook */ +#include #include #include #include @@ -24,6 +25,12 @@ #include "ccp-dev.h" #include "psp-dev.h" +/* used for version string AA.BB.CC.DD */ +#define AA GENMASK(31, 24) +#define BB GENMASK(23, 16) +#define CC GENMASK(15, 8) +#define DD GENMASK(7, 0) + #define MSIX_VECTORS 2 struct sp_pci { @@ -88,8 +95,65 @@ static struct attribute_group psp_security_attr_group = { .is_visible = psp_security_is_visible, }; +#define version_attribute_show(name, _offset) \ +static ssize_t name##_show(struct device *d, struct device_attribute *attr, \ + char *buf) \ +{ \ + struct sp_device *sp = dev_get_drvdata(d); \ + struct psp_device *psp = sp->psp_data; \ + unsigned int val = ioread32(psp->io_regs + _offset); \ + return sysfs_emit(buf, "%02lx.%02lx.%02lx.%02lx\n", \ + FIELD_GET(AA, val), \ + FIELD_GET(BB, val), \ + FIELD_GET(CC, val), \ + FIELD_GET(DD, val)); \ +} + +version_attribute_show(bootloader_version, psp->vdata->bootloader_info_reg) +static DEVICE_ATTR_RO(bootloader_version); +version_attribute_show(tee_version, psp->vdata->tee->info_reg) +static DEVICE_ATTR_RO(tee_version); + +static struct attribute *psp_firmware_attrs[] = { + &dev_attr_bootloader_version.attr, + &dev_attr_tee_version.attr, + NULL, +}; + +static umode_t psp_firmware_is_visible(struct kobject *kobj, struct attribute *attr, int idx) +{ + struct device *dev = kobj_to_dev(kobj); + struct sp_device *sp = dev_get_drvdata(dev); + struct psp_device *psp = sp->psp_data; + unsigned int val = 0xffffffff; + + if (!psp) + return 0; + + if (attr == &dev_attr_bootloader_version.attr && + psp->vdata->bootloader_info_reg) + val = ioread32(psp->io_regs + psp->vdata->bootloader_info_reg); + + if (attr == &dev_attr_tee_version.attr && + psp->capability & PSP_CAPABILITY_TEE && + psp->vdata->tee->info_reg) + val = ioread32(psp->io_regs + psp->vdata->tee->info_reg); + + /* If platform disallows accessing this register it will be all f's */ + if (val != 0xffffffff) + return 0444; + + return 0; +} + +static struct attribute_group psp_firmware_attr_group = { + .attrs = psp_firmware_attrs, + .is_visible = psp_firmware_is_visible, +}; + static const struct attribute_group *psp_groups[] = { &psp_security_attr_group, + &psp_firmware_attr_group, NULL, }; From patchwork Fri Jun 23 13:49:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695354 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 9DDF5C001DC for ; Fri, 23 Jun 2023 18:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232199AbjFWSbu (ORCPT ); Fri, 23 Jun 2023 14:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231947AbjFWSbn (ORCPT ); Fri, 23 Jun 2023 14:31:43 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2046.outbound.protection.outlook.com [40.107.96.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E2BE2705; Fri, 23 Jun 2023 11:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JhrmSNMpSqOUn5labc0fDi27WPcQf/ywEfo3oprGOJKkrvky+Q3GLSIiy+ooU2DSBQjtxhlBrTGJFUOGZfEfkFncCaL++yUyLN8DEEOqLcIu/c1EWB0DmOpw9SMRl35kUEGnh6uCwGB1hu9X4O7U/c2DXxWfoZj4uqb5PvyBaPuj5MZc1YodLI4fx9aN6sFXY9ub8FF2mE2JZSVnugH26YGRxuXvOGG4T1lL8/xhPnTFNItxBJBMOB+2EQDPEvHkQb2K7mXEpcY/QnA8gEiZby+tXUYXnQHwYA5zEsyRkZH2AyiMbFBjJUqioLsx4IzQeakvqzbYcpqGxsmRnHLUDg== 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=E5S28VEecabCIVQuw9urlYWg3WqJCyLbOGbQs21YvZ8=; b=JhynO+elt7uswoTZLxRMzfj/T3EyiSpHifk1xpRmkgTPvp0IVdAnsXH74GO+MtbtGv4grOq6dhuRdK22SmaBrombcXyj98GYxyEemSnVXjCfrc1ZSDB/ZBbsVRDKETjzY+CxJgwiaLPn47CNxXKxPGTrUNoy2w3N/kyPXhf92Hu7Of2V3sdtqFEdouB60JntoKDiIkAXy++4dzujcS30gy9JE2Tj32eCZjkh2mA92bc5bJshQ7KxKkANLkUAVsA0mYsK3KMV8AQvTSB0qLdtaRpOyOOGVjfMYDXNfe91989h09+cEKgkILpis0lm2KEbwuAniy4rP+HL/fwChKQnFQ== 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=E5S28VEecabCIVQuw9urlYWg3WqJCyLbOGbQs21YvZ8=; b=pt8GxRnMxVsnIC5WJPL5JZph7yz6ASxmZX6ctV7pMnKZo5KzzlEtqKy3MQyEoA2gn8b05/Jmg5AqqqF4O8uv06i11eGzZx5QRQBmCmh7p8OMTUj9YVE3JmsKQUafArHtRctoqj/87Jzp53Oo6kQgAEOFVSBUFt4LloZ3iQWd7sw= Received: from BL1P221CA0024.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::31) by PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Fri, 23 Jun 2023 18:31:36 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::50) by BL1P221CA0024.outlook.office365.com (2603:10b6:208:2c5::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:36 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:36 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:33 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 03/11] crypto: ccp: Add bootloader and TEE version offsets Date: Fri, 23 Jun 2023 08:49:53 -0500 Message-ID: <20230623135001.18672-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|PH7PR12MB5712:EE_ X-MS-Office365-Filtering-Correlation-Id: 520063cf-0e8e-45ba-bc2c-08db741813d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L+KMAOb1k30MVFDXcgEcB+gV60IOJxCQbIJS8qIszDR8oaXyVbhYni6t4HJ9pZRCfVGJ/bcszv/q4xSqVtk/P19PxgTsMC1UvTT4oYT+OHwXV7arFGMKcugn8SlEqTT25DtuBVVovX2mvaxnxvLClqB3HrgFD26ere5L2V5vkNNQKB7AWhHvB2/twuGbg+8CuFhEOBXoYGo/FCcXnW6vF0SxdMqm5+JmY2ud754Oi5Ye2TuMpTeVQ7ZdaTtx1lr/ymtdoABuL9DfBPLY+rLu46jwd+zgnB7JpQVx5FGVUymir78YDsjdbKs0RcSREo7IBeluEMV0vuJoilZH/vx4cDj999nv7x2by8Qor8qJt9q/GqClzKqUa8NjyRP/X81eIY//SDaXK0U5HDvvxU5/HhfqEJfEXXn2vazwG0k9t8D6mkP+Y+nYoopq6wazCe00a9OgCEs/1wyPEOeSBR+2yjY45IK1OYxaqYdw1cP2DdteW/XLqnN2gBAFj61qRA5QCKO9xGIZHPrPTfX45VZDDnFf1QF8HYWPQPIXTQU1xt7UYiBKnx8XLE+nq6azK86pCXrWiCx1vSKJNeyAY6SqyIsJqH+VJeIDWqGxVxjD+QwC3XocjloDv8lL4Ej7wCefd9Nyw+lb+fHGT5S8PK5lKYXpqc1sOT23LJV21kn/LZzoRjNlXXHMyqAtChbOuanb07gbXmjl0uJsLCQrPtWWzuns1WWFqM/vChBPYKeWcyKPE/KSB8RRswsmz9e7wPKPP9d9WT78HA+laJn2iiCrHQ== 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:(13230028)(4636009)(136003)(376002)(396003)(39860400002)(346002)(451199021)(46966006)(36840700001)(40470700004)(16526019)(6666004)(7696005)(82310400005)(83380400001)(186003)(81166007)(356005)(40480700001)(1076003)(336012)(426003)(47076005)(40460700003)(36860700001)(2616005)(36756003)(316002)(4326008)(70206006)(70586007)(2906002)(8936002)(8676002)(26005)(44832011)(86362001)(41300700001)(5660300002)(54906003)(82740400003)(110136005)(478600001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:36.3400 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 520063cf-0e8e-45ba-bc2c-08db741813d5 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5712 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The bootloader and TEE versions are stored in registers that can be accessed from sysfs. This exports the information for recent client and datacenter parts. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v2->v3: * Pick up tag --- drivers/crypto/ccp/sp-pci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index 6c93577950c7b..205b93d229a95 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -423,6 +423,7 @@ static const struct tee_vdata teev1 = { .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 = { @@ -448,6 +449,7 @@ static const struct platform_access_vdata pa_v2 = { static const struct psp_vdata pspv1 = { .sev = &sevv1, + .bootloader_info_reg = 0x105ec, /* C2PMSG_59 */ .feature_reg = 0x105fc, /* C2PMSG_63 */ .inten_reg = 0x10610, /* P2CMSG_INTEN */ .intsts_reg = 0x10614, /* P2CMSG_INTSTS */ @@ -455,6 +457,7 @@ static const struct psp_vdata pspv1 = { static const struct psp_vdata pspv2 = { .sev = &sevv2, + .bootloader_info_reg = 0x109ec, /* C2PMSG_59 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ @@ -463,6 +466,7 @@ static const struct psp_vdata pspv2 = { static const struct psp_vdata pspv3 = { .tee = &teev1, .platform_access = &pa_v1, + .bootloader_info_reg = 0x109ec, /* C2PMSG_59 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ @@ -471,6 +475,7 @@ static const struct psp_vdata pspv3 = { static const struct psp_vdata pspv4 = { .sev = &sevv2, .tee = &teev1, + .bootloader_info_reg = 0x109ec, /* C2PMSG_59 */ .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ From patchwork Fri Jun 23 13:49:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695903 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 9F2E2C001DE for ; Fri, 23 Jun 2023 18:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbjFWSbw (ORCPT ); Fri, 23 Jun 2023 14:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231917AbjFWSbn (ORCPT ); Fri, 23 Jun 2023 14:31:43 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2066.outbound.protection.outlook.com [40.107.223.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8050B2721; Fri, 23 Jun 2023 11:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=chTgOQZ+2qxZFvgcAzJh627/knNR9QSdgNUvFfk1fg1CP+VhK1XympQbCpbhbYMp8xYASCAAmfs4oIth8s2cATiIfuxJb/Hj5GSEeGGxhNgxAQ07MmRK8ONwbOGYrJhCGOOOqu2irNuBzndxMDl1+SiZo9NEcLCkFhOQ7yEaFz8GdnqZoEDbsBd99H7VCn0o0YqL//cxG3nYjY983ivIKXQIg8CEOoswDpotCfC6Z5bM3yDkuwXJhrXJ3/E8X8O7TjxKkjGUZHoeZJXuo47+/05gV4ts0LKRQ3zuzyhS/gRsmR3e64YZJ4DqJK4WDPFnm24ezyas7tn8e7KNfgn10A== 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=NyXvkhFZE6b8we/dZ3sslnP6SIqpIRE+gYH9JUOn+/0=; b=H2fQ3/zfBgn9i0FVhLMSzSAAO7lf7B4QjBwC453IyGB+jLWQyP8lMPcJvAbooiAdYeksgn/Ilv8gj+SssTHmthHQTSeP49REoLFym1bXeESGnfkFurlsf9Pnw4QS8KPSSYF4OFtyl0PM1Ky4+k6qB/Bw/sBPKXwwwAe0HdRNNEo52HwkH9OJXhu25eyRQ+aW0NNshpure9scjgrG+1yD19XL/RhaLyAAdTIv0WEnm5y4qZF41eLIioHj+gK5yhnx/9gGfVxdyzlAYs4p6nAo3y+dDfidW3EmzO4/RbE1AT5YRo/m7Ge7OUphEXYbUGrGVfUtqL05HhK7aaseUWW0BA== 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=NyXvkhFZE6b8we/dZ3sslnP6SIqpIRE+gYH9JUOn+/0=; b=PVqURThiUWp66CnibjwcFitt8SNR6gDzV5PkTnQK3KSdYQK09E2OGOGXvSbKV1CrImej6HtvDjym9QExr9YNUfVpTAWDnbrkJGnPz0l5yBrRlltM9t71sVSyyrwclnP9cMIWdCu+bH4ccjQQMn6O/t1D2kMPEjT3uKTtW0lnmYI= Received: from BL1P221CA0029.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::25) by DM4PR12MB5964.namprd12.prod.outlook.com (2603:10b6:8:6b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Fri, 23 Jun 2023 18:31:37 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::cb) by BL1P221CA0029.outlook.office365.com (2603:10b6:208:2c5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:37 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:37 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:34 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 04/11] crypto: ccp: move setting PSP master to earlier in the init Date: Fri, 23 Jun 2023 08:49:54 -0500 Message-ID: <20230623135001.18672-5-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|DM4PR12MB5964:EE_ X-MS-Office365-Filtering-Correlation-Id: e2c146f3-7add-4c2c-5441-08db7418144f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ofWl9LfbaLGgOo/mBYQ8BvYOtIcaPtD6bHrUdvyAI+8N3NVEtLo3zuXCt+hNpJL2JyZSpbv3HQt1xhMHUETN+9+CximqfrckLQlxUswuxAY9+oGGxnwlNwisaxWjR/XbjNY4EQa759nJXpkFX/7jgNdAfZ+HSv0sOSJ0tjY32whIlIO2dn+V9Rq9boj3/DmOkpn0Bsb4Xkq4RjiDqXa5xFZ1zmouzdlnn9T30E/qk/ITCpxOltzNVPS1oPjAwsC0AB5IGjFEmXqg7wVmmmWFDzEqSPv+mJBB3PWG7c4ZX6JJIW95rLVj47Ex+tvXr6At081Q1VvS7ADulDOJafUq7dV7XwLFtfvLqyR582czEveZvFOUSOBCYXFYc3QLH0jVxPukXAQ5qtlmipOaU4jWBbgrAmnTzWHnVpgMSVSN8l9CIotkSZx3i684KW0ApJ3W8L5tOymrLsUnz40G1mvUf40YmPhCMDos3TFwKpmsK7es5Bnf5IwoN/zQwoOFJI6UQHJACYb8zCqr74iGQjLwb6mX7CORUapLjAAFBtrMCIM0l8ScJ8L2+jGuGfUpV0F4NQRbwShvi3cWHKEbQ+6fzIaasz89mikwjia65Qm2KYoXUi1pbNruB3v6ILNDDo2G8fi9guUFcDY52xr6Y0ZE7DlxO6yItB288JyDw1bYebwWBZUUvFrd53Vot2ryp1JmewZFtuVF1OC8zrO3/OljzsBuUqclMqES/R+xOwb7WtjMlKQPGXDTDYSY3ueH4xaKpYvg/R7FGjPfiyJbYzsGzA== 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:(13230028)(4636009)(136003)(376002)(39860400002)(396003)(346002)(451199021)(46966006)(40470700004)(36840700001)(82310400005)(40460700003)(40480700001)(86362001)(41300700001)(8936002)(70586007)(336012)(70206006)(44832011)(316002)(2616005)(478600001)(47076005)(83380400001)(7696005)(426003)(1076003)(5660300002)(4326008)(186003)(16526019)(26005)(54906003)(110136005)(82740400003)(356005)(81166007)(36860700001)(6666004)(36756003)(2906002)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:37.1368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2c146f3-7add-4c2c-5441-08db7418144f 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5964 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Dynamic boost control needs to use platform access symbols that look for the PSP master as part of initialization. So move the PSP master before psp_init() so that dynamic boost control can be initialized properly. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag v3->v4: * Pick up tag v2->v3: * Clean up master device if psp_init() failed --- drivers/crypto/ccp/psp-dev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index e3d6955d32655..3390f0bd64085 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -173,13 +173,14 @@ int psp_dev_init(struct sp_device *sp) goto e_err; } + /* master device must be set for platform access */ + if (psp->sp->set_psp_master_device) + psp->sp->set_psp_master_device(psp->sp); + ret = psp_init(psp); if (ret) goto e_irq; - if (sp->set_psp_master_device) - sp->set_psp_master_device(sp); - /* Enable interrupt */ iowrite32(-1, psp->io_regs + psp->vdata->inten_reg); @@ -188,6 +189,9 @@ int psp_dev_init(struct sp_device *sp) return 0; e_irq: + if (sp->clear_psp_master_device) + sp->clear_psp_master_device(sp); + sp_free_psp_irq(psp->sp, psp); e_err: sp->psp_data = NULL; From patchwork Fri Jun 23 13:49:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695353 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 771E9EB64DD for ; Fri, 23 Jun 2023 18:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232166AbjFWScK (ORCPT ); Fri, 23 Jun 2023 14:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232102AbjFWSbs (ORCPT ); Fri, 23 Jun 2023 14:31:48 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2086.outbound.protection.outlook.com [40.107.101.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D093D2729; Fri, 23 Jun 2023 11:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=djuzsG1MYumGpSGce2nqn72rc8cILZPV/Es/VUjB9YltiuYYX1O0WKt3EcWwkLTHV85mMXBOQFJK3PkM7gosDW1SlCRDchjgkIWniYJNJN7FJSqwL097dpC0nHZe97AwNK2OAfPdTB3SslW3ZU+KQs8PwEHsJKoY5uCzr4sJiEbNzikXDhu1GHP6ZpPYLSuwxkyTl633t6EIxc2FBu/22mND70C3Gw3Zv3pm7wzWeKa113Mvu7fQIR3sn41V7l5qsJsH/52Eh9dyqYYS/RDopVyqrUutk2VCjXJQkVCHzBglJQAxzi7aSwlFoQbqD+ivnuDrIThdFhF4irpcWjqrNQ== 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=LcKSDg07CXZRDLfL73qKPCaBUuO7BbORSlUSKvxtoYI=; b=ARIU2RxbDruJh4k1rTfMStER/NOR8qst0hLsdoK48ULh1n+Oz7DuvQ7Oj5zIky8W84NHy8C6s41BdIAJ2YXnYUIbY7XZqer+2xQgOuYUiit8xcRVU6bf/rK6+U5rKadVmMR+RWOoatUbycofZ8ri9G0i/gfFYuzHrCysWJQbHnQ0d/SMjrOzKl0KepHchppAIMt1YsGwjyGFhU2cr8qzLFcoKnEAiqpiIhE4vhhG1GP63bkvzJmNhVuclMjM4k7pMD9+kcbI3oEL24njuuFIWJYqgfkDFYaXUxXwDrLArAA39V0yiCIz/Htt34nwhPRjmuUyC6J+7wQstCRe4HAqQQ== 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=LcKSDg07CXZRDLfL73qKPCaBUuO7BbORSlUSKvxtoYI=; b=JGvwhHE6hopHQpMwyAzhZHExRWzQovShh3tTWyBqyb7oI6rNpST9B0rT13rB4WFR7hspYxUUyMHWWKs5ilnbqlsxuVsDBVrMof2G/lrCEm1a8a5Zdbo3MiaVA79iAjItMxfzBfsC6uPa5yXU7nRl1z5CA5J4ZjVr3XPjME4eOKA= Received: from BL1P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::13) by CH3PR12MB9218.namprd12.prod.outlook.com (2603:10b6:610:19f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Fri, 23 Jun 2023 18:31:38 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::dc) by BL1P221CA0025.outlook.office365.com (2603:10b6:208:2c5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:38 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:38 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:35 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 05/11] crypto: ccp: Add support for fetching a nonce for dynamic boost control Date: Fri, 23 Jun 2023 08:49:55 -0500 Message-ID: <20230623135001.18672-6-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|CH3PR12MB9218:EE_ X-MS-Office365-Filtering-Correlation-Id: aebe5c43-1007-45e0-d6e1-08db741814f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HAGccXkuT54iMTKzxiIWHPDPZ6102l4uakZWqWv1kt9MEzsB7wRfsuggF5Cc2fPTKqrm/sAEm33EMxOgkZ6fUlaccuG4Yu6lk6pjtw0QFRFbzGJ4WvjkbTU00T8TsBJpFnEwIJ/EZLhWOEJLfFm85okbt482fYuP+s1ohkHNqXJXesZmZmHKDmE2G6NnwjkX9wH4lKKLyri5yZZ4HsI/u5OH1GA+AYrtH8MZ2KHyVY1SmTmye8TwxQAGqowkWe+g5IBs+PExtlkhKqvtMT6QOpCsFethXDjgQLfwEa2e7R8AzCW0GXKyfo3rNOhyZtGvILvgpmjUzLtRIZ4fPkX6UiKeIm6KwjtJ4L4g8SPtpNGDsM1VJQZqeSdj7p3L6XLFkVT979KIl9MD515e/+XyAoJQbiD3dkJqv2Fh1mLFAU4I+htISfIQiq5YcKT1G8lJbrQL9wY6XI5u9MwivPmjZzAtzWnOoVZshWtBGE5QTWVYmdpKg4qdM4cDATeBrCOFZBJ+SMFstxZIMYaTJaK/oRxv269Ljz0iNEN+5RV1vl+say3PDv5FyVosN1AHTfNOfzknBMXEGhKSYefb9qFhVmBDsAibzAklNpUwfEppXg+FA9NN1+roP+r+6qiJAjL4Pfk86gUl4xx3H1JSflrBlbU4yS0PlDB5G+CNwqia7voa6XKKaCHvj1B4r1Ud5jVb4x3GDkoP6f30SsiXxrBq3UpHpRep7vqrJSjW9UpjFl1OGaqJUFH2YgLM7GAMFB36GYAZZKXSxb0rfmT+d4hQLQ== 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:(13230028)(4636009)(39860400002)(376002)(396003)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(44832011)(2906002)(30864003)(40480700001)(8676002)(8936002)(316002)(41300700001)(5660300002)(66899021)(70206006)(70586007)(4326008)(40460700003)(6666004)(336012)(426003)(82740400003)(7696005)(478600001)(36756003)(82310400005)(186003)(81166007)(356005)(2616005)(16526019)(47076005)(86362001)(83380400001)(110136005)(1076003)(26005)(36860700001)(54906003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:38.2150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aebe5c43-1007-45e0-d6e1-08db741814f3 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9218 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Dynamic Boost Control is a feature offered on AMD client platforms that allows software to request and set power or frequency limits. Only software that has authenticated with the PSP can retrieve or set these limits. Create a character device and ioctl for fetching the nonce. This ioctl supports optionally passing authentication information which will influence how many calls the nonce is valid for. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag * Add a missing static for dbc_fops --- drivers/crypto/ccp/Makefile | 3 +- drivers/crypto/ccp/dbc.c | 191 ++++++++++++++++++++++++++++ drivers/crypto/ccp/dbc.h | 44 +++++++ drivers/crypto/ccp/psp-dev.c | 9 ++ drivers/crypto/ccp/psp-dev.h | 1 + drivers/crypto/ccp/sp-dev.h | 5 + drivers/crypto/ccp/sp-pci.c | 1 + include/linux/psp-platform-access.h | 1 + include/uapi/linux/psp-dbc.h | 67 ++++++++++ 9 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/ccp/dbc.c create mode 100644 drivers/crypto/ccp/dbc.h create mode 100644 include/uapi/linux/psp-dbc.h diff --git a/drivers/crypto/ccp/Makefile b/drivers/crypto/ccp/Makefile index f6196495e862d..aa0ba2d17e1e2 100644 --- a/drivers/crypto/ccp/Makefile +++ b/drivers/crypto/ccp/Makefile @@ -11,7 +11,8 @@ ccp-$(CONFIG_PCI) += sp-pci.o ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \ sev-dev.o \ tee-dev.o \ - platform-access.o + platform-access.o \ + dbc.o obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o ccp-crypto-objs := ccp-crypto-main.o \ diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c new file mode 100644 index 0000000000000..f65e93a81e53f --- /dev/null +++ b/drivers/crypto/ccp/dbc.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * AMD Secure Processor Dynamic Boost Control interface + * + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * + * Author: Mario Limonciello + */ + +#include "dbc.h" + +struct error_map { + u32 psp; + int ret; +}; + +#define DBC_ERROR_ACCESS_DENIED 0x0001 +#define DBC_ERROR_EXCESS_DATA 0x0004 +#define DBC_ERROR_BAD_PARAMETERS 0x0006 +#define DBC_ERROR_BAD_STATE 0x0007 +#define DBC_ERROR_NOT_IMPLEMENTED 0x0009 +#define DBC_ERROR_BUSY 0x000D +#define DBC_ERROR_MESSAGE_FAILURE 0x0307 +#define DBC_ERROR_OVERFLOW 0x300F +#define DBC_ERROR_SIGNATURE_INVALID 0x3072 + +static struct error_map error_codes[] = { + {DBC_ERROR_ACCESS_DENIED, -EACCES}, + {DBC_ERROR_EXCESS_DATA, -E2BIG}, + {DBC_ERROR_BAD_PARAMETERS, -EINVAL}, + {DBC_ERROR_BAD_STATE, -EAGAIN}, + {DBC_ERROR_MESSAGE_FAILURE, -ENOENT}, + {DBC_ERROR_NOT_IMPLEMENTED, -ENOENT}, + {DBC_ERROR_BUSY, -EBUSY}, + {DBC_ERROR_OVERFLOW, -ENFILE}, + {DBC_ERROR_SIGNATURE_INVALID, -EPERM}, + {0x0, 0x0}, +}; + +static int send_dbc_cmd(struct psp_dbc_device *dbc_dev, + enum psp_platform_access_msg msg) +{ + int ret; + + dbc_dev->mbox->req.header.status = 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); + + for (i = 0; error_codes[i].psp; i++) { + if (dbc_dev->mbox->req.header.status == error_codes[i].psp) + return error_codes[i].ret; + } + } + + return ret; +} + +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); + ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_NONCE); + if (ret == -EAGAIN) { + dev_dbg(dbc_dev->dev, "retrying get nonce\n"); + ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_NONCE); + } + + return ret; +} + +void dbc_dev_destroy(struct psp_device *psp) +{ + struct psp_dbc_device *dbc_dev = psp->dbc_data; + + if (!dbc_dev) + return; + + misc_deregister(&dbc_dev->char_dev); + mutex_destroy(&dbc_dev->ioctl_mutex); + psp->dbc_data = NULL; +} + +static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct psp_device *psp_master = psp_get_master_device(); + void __user *argp = (void __user *)arg; + struct psp_dbc_device *dbc_dev; + int ret; + + if (!psp_master || !psp_master->dbc_data) + return -ENODEV; + dbc_dev = psp_master->dbc_data; + + mutex_lock(&dbc_dev->ioctl_mutex); + + switch (cmd) { + case DBCIOCNONCE: + if (copy_from_user(&dbc_dev->mbox->dbc_nonce.user, argp, + sizeof(struct dbc_user_nonce))) { + ret = -EFAULT; + goto unlock; + } + + ret = send_dbc_nonce(dbc_dev); + if (ret) + goto unlock; + + if (copy_to_user(argp, &dbc_dev->mbox->dbc_nonce.user, + sizeof(struct dbc_user_nonce))) { + ret = -EFAULT; + goto unlock; + } + break; + default: + ret = -EINVAL; + + } +unlock: + mutex_unlock(&dbc_dev->ioctl_mutex); + + return ret; +} + +static const struct file_operations dbc_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = dbc_ioctl, +}; + +int dbc_dev_init(struct psp_device *psp) +{ + struct device *dev = psp->dev; + 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; + + BUILD_BUG_ON(sizeof(union dbc_buffer) > PAGE_SIZE); + dbc_dev->mbox = (void *)devm_get_free_pages(dev, GFP_KERNEL, 0); + if (!dbc_dev->mbox) { + ret = -ENOMEM; + goto cleanup_dev; + } + + psp->dbc_data = dbc_dev; + dbc_dev->dev = dev; + + ret = send_dbc_nonce(dbc_dev); + if (ret == -EACCES) { + dev_dbg(dbc_dev->dev, + "dynamic boost control was previously authenticated\n"); + ret = 0; + } + dev_dbg(dbc_dev->dev, "dynamic boost control is %savailable\n", + ret ? "un" : ""); + if (ret) { + ret = 0; + goto cleanup_mbox; + } + + dbc_dev->char_dev.minor = MISC_DYNAMIC_MINOR; + dbc_dev->char_dev.name = "dbc"; + dbc_dev->char_dev.fops = &dbc_fops; + dbc_dev->char_dev.mode = 0600; + ret = misc_register(&dbc_dev->char_dev); + if (ret) + goto cleanup_mbox; + + mutex_init(&dbc_dev->ioctl_mutex); + + return 0; + +cleanup_mbox: + devm_free_pages(dev, (unsigned long)dbc_dev->mbox); + +cleanup_dev: + psp->dbc_data = NULL; + devm_kfree(dev, dbc_dev); + + return ret; +} diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h new file mode 100644 index 0000000000000..1c3a0a078d156 --- /dev/null +++ b/drivers/crypto/ccp/dbc.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AMD Platform Security Processor (PSP) Dynamic Boost Control support + * + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * + * Author: Mario Limonciello + */ + +#ifndef __DBC_H__ +#define __DBC_H__ + +#include + +#include +#include +#include + +#include "psp-dev.h" + +struct psp_dbc_device { + struct device *dev; + + union dbc_buffer *mbox; + + struct mutex ioctl_mutex; + + struct miscdevice char_dev; +}; + +struct dbc_nonce { + struct psp_req_buffer_hdr header; + struct dbc_user_nonce user; +} __packed; + +union dbc_buffer { + struct psp_request req; + struct dbc_nonce dbc_nonce; +}; + +void dbc_dev_destroy(struct psp_device *psp); +int dbc_dev_init(struct psp_device *psp); + +#endif /* __DBC_H */ diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index 3390f0bd64085..d42d7bc623523 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -15,6 +15,7 @@ #include "sev-dev.h" #include "tee-dev.h" #include "platform-access.h" +#include "dbc.h" struct psp_device *psp_master; @@ -112,6 +113,12 @@ static void psp_init_platform_access(struct psp_device *psp) 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) @@ -217,6 +224,8 @@ void psp_dev_destroy(struct sp_device *sp) tee_dev_destroy(psp); + dbc_dev_destroy(psp); + platform_access_dev_destroy(psp); sp_free_psp_irq(sp, psp); diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index 505e4bdeaca84..8a4de69399c59 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -40,6 +40,7 @@ struct psp_device { void *sev_data; void *tee_data; void *platform_access_data; + void *dbc_data; unsigned int capability; }; diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index 76c32ee6bd657..2329ad524b494 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -28,6 +28,10 @@ #define CACHE_NONE 0x00 #define CACHE_WB_NO_ALLOC 0xb7 +#define PLATFORM_FEATURE_DBC 0x1 + +#define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat) + /* Structure to hold CCP device data */ struct ccp_device; struct ccp_vdata { @@ -71,6 +75,7 @@ struct psp_vdata { const unsigned int inten_reg; const unsigned int intsts_reg; const unsigned int bootloader_info_reg; + const unsigned int platform_features; }; /* Structure to hold SP device data */ diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index 205b93d229a95..b6ab56abeb682 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -470,6 +470,7 @@ static const struct psp_vdata pspv3 = { .feature_reg = 0x109fc, /* C2PMSG_63 */ .inten_reg = 0x10690, /* P2CMSG_INTEN */ .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ + .platform_features = PLATFORM_FEATURE_DBC, }; static const struct psp_vdata pspv4 = { diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h index 75da8f5f7ad84..53b4a1df51806 100644 --- a/include/linux/psp-platform-access.h +++ b/include/linux/psp-platform-access.h @@ -8,6 +8,7 @@ enum psp_platform_access_msg { PSP_CMD_NONE = 0x0, PSP_I2C_REQ_BUS_CMD = 0x64, + PSP_DYNAMIC_BOOST_GET_NONCE, }; struct psp_req_buffer_hdr { diff --git a/include/uapi/linux/psp-dbc.h b/include/uapi/linux/psp-dbc.h new file mode 100644 index 0000000000000..d032f78934e27 --- /dev/null +++ b/include/uapi/linux/psp-dbc.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* + * Userspace interface for AMD Dynamic Boost Control (DBC) + * + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * + * Author: Mario Limonciello + */ + +#ifndef __PSP_DBC_USER_H__ +#define __PSP_DBC_USER_H__ + +#include + +/** + * DOC: AMD Dynamic Boost Control (DBC) interface + */ + +#define DBC_NONCE_SIZE 16 +#define DBC_SIG_SIZE 32 + +/** + * struct dbc_user_nonce - Nonce exchange structure (input/output). + * @auth_needed: Whether the PSP should authenticate this request (input). + * 0: no authentication, PSP will return single use nonce. + * 1: authentication: PSP will return multi-use nonce. + * @nonce: 8 byte value used for future authentication (output). + * @signature: Optional 32 byte signature created by software using a + * previous nonce (input). + */ +struct dbc_user_nonce { + __u32 auth_needed; + __u8 nonce[DBC_NONCE_SIZE]; + __u8 signature[DBC_SIG_SIZE]; +} __packed; + +/** + * Dynamic Boost Control (DBC) IOC + * + * possible return codes for all DBC IOCTLs: + * 0: success + * -EINVAL: invalid input + * -E2BIG: excess data passed + * -EFAULT: failed to copy to/from userspace + * -EBUSY: mailbox in recovery or in use + * -ENODEV: driver not bound with PSP device + * -EACCES: request isn't authorized + * -EINVAL: invalid parameter + * -ETIMEDOUT: request timed out + * -EAGAIN: invalid request for state machine + * -ENOENT: not implemented + * -ENFILE: overflow + * -EPERM: invalid signature + * -EIO: unknown error + */ +#define DBC_IOC_TYPE 'D' + +/** + * DBCIOCNONCE - Fetch a nonce from the PSP for authenticating commands. + * If a nonce is fetched without authentication it can only + * be utilized for one command. + * If a nonce is fetched with authentication it can be used + * for multiple requests. + */ +#define DBCIOCNONCE _IOWR(DBC_IOC_TYPE, 0x1, struct dbc_user_nonce) + +#endif /* __PSP_DBC_USER_H__ */ From patchwork Fri Jun 23 13:49:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695902 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 F154EEB64D7 for ; Fri, 23 Jun 2023 18:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231894AbjFWScG (ORCPT ); Fri, 23 Jun 2023 14:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232080AbjFWSbr (ORCPT ); Fri, 23 Jun 2023 14:31:47 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2063.outbound.protection.outlook.com [40.107.93.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7A242727; Fri, 23 Jun 2023 11:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ceBxR+koicDvpRVcf1B+K4PcW24qBvylC8bHoFVV6ZJk3TckXzPDEK1CYARrNmGkbOcJ+p60e3i/55BT+BLiGg1busH/d1+Pe1NkmHYBHXg1WfTPe96o/UGK0jQUbdaybJfzlbcEMgNydV+7z9sTnI1RgqgnVD6S1gltdia7qK6/nIeRrl9IdbZRM7m7/YPGWRxhCbeScsogsb2JNLk5Mp2sxlrjc6OpHpRPRstVN0G7E5eDlZ3/lBa7d1m5ka2h/ebMm7F9J+O7C4UHZ9doFkY0hAVO9JKAl/xLnXyqWc9uqaXdZxNRKPgUksL8HWbBXSB6uR3FEHBaVDFiDAr0ng== 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=YRQ080FMENJAmw6hyBgghw242ayQ8Prt35zVvOq5f7I=; b=D5xosZo9QM1B4dRX+/E0BSpmD7Gr62A58vRa29SCioxw8QnCr9l+YyH1002REunSkKUE7mCW0fbuXBhkNR9X11JXDBr3ERNOf3kMQ8rzN8YelXI0EvfUlVTGNkxtRshNwjCP0OcdSUWAMUgfVNqCDHuDu+RIUcALOsZc9o7IMOwcqI3TyGS1I0JEuqLTwAawv8E/Zso8Tmw0iwrg7pgxKk568dicgnqtpskzh9M8+pbAZ6alrYPOeDkdQd1BysFCN9Wx2zrKGER6kh1UsReQvDk3Q2GqXfYzBKVe3hTrTTDhm8fhtuHJwdhpORedzI6I+fj1odfI3EEYtCfdNbb1Pw== 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=YRQ080FMENJAmw6hyBgghw242ayQ8Prt35zVvOq5f7I=; b=dwyxDCk0eOjf10GG8WC1WAEn9fd/RAHBP41DGG5FMdylDlVdjCh81OKSmP1zcxcAgmipSxiyYLaHmJ9Hc/LQlZ2p/2enYV8Au2ucXbIwSEinePUG/coKEh7i2JNIu0vEtmBVH6cIbK+l7EXxfGA2pcrIoLrywStV14csVPy854g= Received: from BL1P221CA0021.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::17) by LV2PR12MB5846.namprd12.prod.outlook.com (2603:10b6:408:175::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Fri, 23 Jun 2023 18:31:38 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::ed) by BL1P221CA0021.outlook.office365.com (2603:10b6:208:2c5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:38 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:38 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:36 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 06/11] crypto: ccp: Add support for setting user ID for dynamic boost control Date: Fri, 23 Jun 2023 08:49:56 -0500 Message-ID: <20230623135001.18672-7-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|LV2PR12MB5846:EE_ X-MS-Office365-Filtering-Correlation-Id: b8f385ff-5f08-465d-5d81-08db7418153b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X94UDGjzgTliIpAFI8ts1U9RqlptS3LhzHz+mQh0f7RVFwKlfPoVY360LVGr0KRP2lbgF5oM/NegmCWBHTVRUx5Dk0oO3S+hvOZa32+ZgL1PXGkdOoR+7g/ZYENjPlG+HiDB4LDTLo8ZPy/s+ywDg9ok2m9TeWL0O7/Lon8oZRsjhBbg8s16QdFkCGIMHSQFpJKvnWoTMWiqrz/e8v9MNjivo0GatumqTeIznRN2+GazjUR2/asNomCZlR9meZaxACQ2q/MMjUScJryr0AVkjaXxdvu8i1dUtQo0Z8aMU2WwSJ1ceUJlXy+LPhfh5sWP3D2RPdA51+MFfGC4AK87/an9pFi5uTp35euUsTKr6zgn3P2nPiRvAvbpC7cOXYh/+gjRUXwWIJSwz/qME/LPaFo5WomRGYiWRJceIYFxhFu3xb0QvwM0/lsuJgJkVUWqvJBVI0CyRVaMzoIaBt90yrDG3+T38qK+UuxOyJly1pxAlY/U1xdn+sfleutXq7OnHrkoydJWuShkXxuC5ZDh6ySFByXPhcjFzpH5NFi6YH6aygSTalcWNrHh7iDJ5a7NXW1BNYXPNxr1V+uFPxqfK8bOorHpL0Iv1iYf1zdHFwEAELwBdAZzh9XK2u8TBeA9VyFTGGz/2vZEEbwd92sSGmcV3uoVi2fagvmj4Jzgf7Fm5JxPGO5hGlfjs8+WAJMZ4wEHyTwwJB/rIuA7fHe9Elh+8QFmFgKEE8XTiQpF32/sUVNJAg5pSI7kYUdUybQhWpadsQV3fMlePVwsKo1TtQ== 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:(13230028)(4636009)(39860400002)(136003)(376002)(396003)(346002)(451199021)(46966006)(40470700004)(36840700001)(82740400003)(356005)(81166007)(86362001)(47076005)(36860700001)(83380400001)(36756003)(40460700003)(110136005)(54906003)(41300700001)(7696005)(426003)(336012)(6666004)(4326008)(316002)(70206006)(70586007)(2616005)(1076003)(8676002)(8936002)(16526019)(26005)(186003)(2906002)(82310400005)(40480700001)(44832011)(478600001)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:38.6837 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8f385ff-5f08-465d-5d81-08db7418153b 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5846 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org As part of the authentication flow for Dynamic Boost Control, the calling software will need to send a uid used in all of its future communications. Add support for another IOCTL call to let userspace software set this up. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag v1->v2: * Update commit message --- drivers/crypto/ccp/dbc.c | 18 ++++++++++++++++++ drivers/crypto/ccp/dbc.h | 6 ++++++ include/linux/psp-platform-access.h | 1 + include/uapi/linux/psp-dbc.h | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index f65e93a81e53f..c6f5fb3658ca3 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -117,6 +117,24 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 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))) { + ret = -EFAULT; + goto unlock; + } + + 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))) { + ret = -EFAULT; + goto unlock; + } + break; default: ret = -EINVAL; diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h index 1c3a0a078d156..1564351000761 100644 --- a/drivers/crypto/ccp/dbc.h +++ b/drivers/crypto/ccp/dbc.h @@ -33,9 +33,15 @@ struct dbc_nonce { struct dbc_user_nonce user; } __packed; +struct dbc_set_uid { + struct psp_req_buffer_hdr header; + struct dbc_user_setuid user; +} __packed; + union dbc_buffer { struct psp_request req; struct dbc_nonce dbc_nonce; + struct dbc_set_uid dbc_set_uid; }; void dbc_dev_destroy(struct psp_device *psp); diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h index 53b4a1df51806..18b9e0f0cb03b 100644 --- a/include/linux/psp-platform-access.h +++ b/include/linux/psp-platform-access.h @@ -9,6 +9,7 @@ enum psp_platform_access_msg { PSP_CMD_NONE = 0x0, PSP_I2C_REQ_BUS_CMD = 0x64, PSP_DYNAMIC_BOOST_GET_NONCE, + PSP_DYNAMIC_BOOST_SET_UID, }; struct psp_req_buffer_hdr { diff --git a/include/uapi/linux/psp-dbc.h b/include/uapi/linux/psp-dbc.h index d032f78934e27..7443c78ede199 100644 --- a/include/uapi/linux/psp-dbc.h +++ b/include/uapi/linux/psp-dbc.h @@ -18,6 +18,7 @@ #define DBC_NONCE_SIZE 16 #define DBC_SIG_SIZE 32 +#define DBC_UID_SIZE 16 /** * struct dbc_user_nonce - Nonce exchange structure (input/output). @@ -34,6 +35,16 @@ struct dbc_user_nonce { __u8 signature[DBC_SIG_SIZE]; } __packed; +/** + * struct dbc_user_setuid - UID exchange structure (input). + * @uid: 16 byte value representing software identity + * @signature: 32 byte signature created by software using a previous nonce + */ +struct dbc_user_setuid { + __u8 uid[DBC_UID_SIZE]; + __u8 signature[DBC_SIG_SIZE]; +} __packed; + /** * Dynamic Boost Control (DBC) IOC * @@ -64,4 +75,13 @@ struct dbc_user_nonce { */ #define DBCIOCNONCE _IOWR(DBC_IOC_TYPE, 0x1, struct dbc_user_nonce) +/** + * DBCIOCUID - Set the user ID (UID) of a calling process. + * The user ID is 8 bytes long. It must be programmed using a + * 32 byte signature built using the nonce fetched from + * DBCIOCNONCE. + * The UID can only be set once until the system is rebooted. + */ +#define DBCIOCUID _IOW(DBC_IOC_TYPE, 0x2, struct dbc_user_setuid) + #endif /* __PSP_DBC_USER_H__ */ From patchwork Fri Jun 23 13:49:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695901 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 F2E6EC0015E for ; Fri, 23 Jun 2023 18:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232218AbjFWScR (ORCPT ); Fri, 23 Jun 2023 14:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbjFWSbs (ORCPT ); Fri, 23 Jun 2023 14:31:48 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2079.outbound.protection.outlook.com [40.107.223.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B762724; Fri, 23 Jun 2023 11:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R3RjnRjlbnC22ZBL2fyEnMlYQwowcp7VsQqttcbZ5eEcQnvsd0i4udqx2+7G4F92PVjMeMqeaknz2oUV+4mLcNGyb6MJwoFfyhjsYbD1Y5axD6balV3u5b66RHcHwrFsR753ea79D92vwJfgMN4Tkb4kXaWVHgqGc8E/K93uL5h1EGC1bxcQvVF5TbNbVatMgVUNc+MjwHED8n0WVxmg/o+fpzGKHOOTPAIXWkV1lN0P3W75mzyGbIT1lggvbp+n3XOH8JHdoAuHZaVh6Jw3ax7vmVsvEtfZ6+MCXjQgPruqThno5LZpgFLhC4fTsLAX/SWKXg6ax1xT9MkPKihheQ== 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=VJu1uIF/ppRrhvHf5/r5CMoNSxJ7wFkbI8XsrCSl8XY=; b=NvgqRewFKZyyCHDJtS37c4IEjSFBHsdprLN6iDUyd9cJl+GlshN8FpXKsFfXIe6rIdQdrSbnjUVg8X1NMmuu8AV3oDFeUOkafFoQaGH+/KkBn1Hba75X1XUsQT8y6ZhBP4XA60SHkj733qK0Ac/2Zh9OxyxWaWAQMpXTICQFY8nbljblYZILzMN/dKNIxhXbFuSIRlNmY2EO580IZ9j9cc+j31k3FyhhUUMykZ6Wnz/zKNyEfS4epsL1ZAHooLbLKT6Pf6Rbtkv9Su+gRz3gB2lVjBLuFi7P0LTXV4sWWaoiXBY4ueU7phpKBmxDr7O0VaGfW9BLPiw9wCn2evCfjA== 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=VJu1uIF/ppRrhvHf5/r5CMoNSxJ7wFkbI8XsrCSl8XY=; b=oiXHNEab98jU1Eginmyv3fw3vSQ8W/M1NmXULBlJGs9bB401/ZL2Bn3Qx5SoIEmgyYquutrPSqwXchKTIOB6IXNPus6khGaLtCCbjOUreVhQ1ee8/r/1D0KpzkOqE2+rXi0OBfJgzIhlUdbWU8j2M7i/IIGErPWJE+E11F5kMqg= Received: from BL1P221CA0014.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::26) by CH3PR12MB8460.namprd12.prod.outlook.com (2603:10b6:610:156::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Fri, 23 Jun 2023 18:31:39 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::98) by BL1P221CA0014.outlook.office365.com (2603:10b6:208:2c5::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:39 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:39 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:36 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 07/11] crypto: ccp: Add support for getting and setting DBC parameters Date: Fri, 23 Jun 2023 08:49:57 -0500 Message-ID: <20230623135001.18672-8-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|CH3PR12MB8460:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c71102e-354d-45cd-6ed3-08db7418156d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Yu15I+9ZjF/JdxPrX61yUIMjdQqt2c/8xWS0PRKLhqkAcYEzPUMRmClVrok+KJQf5PBjBXk9bo72kJfDvIeYMz+HE+LYkMuYQgvk+gV+BEdoPw41M9e+wPsxSHhgVsaiTBVlC11YdMA8J3AuPoR474+ySUqYZMGVqZoA2/gcz09f6LIkLHrboIm4m5LXQzpl2WJYtuTX19YfWsJ6B3Tb8Th2YjoJp8WMedYNj4j5ivhstihzXGUA994QD0hUdf5GURUjW1bKGviYb73MpJ7MhcSQ/9N6wo+CHjTMzOVnH0xIitw6yqyu3POmmDipW1sZPopHkDiSSZ7CWQCQ608yn29y8lwhyun74KVEl2YMVsgVC+Zy84/CXgvwK9BWiaIpF6wb0X6KU6CBw4Kmufa5bbKEZCFl/Vx8nx9sB8yl0uLoyXaE6RwaDh0RHO7/lM7YQip8E0u1Be0WNq1l+lkASQ4qSxJx6p7gsRD2xqwY4IeFdLrsMkkxdDua9oZXn4wq0xH20wzJEB3vuYXF07kecFLBcnJX1skFELWgwfXTf74qq1tzT+PpTSaMDb77jgxfl4d6sjdLnFj45Tkj6qky2W+88jxvFqavzT4W3apZQu85xLyiU4wouJk+JJqq90/Dz4ecqIP2Pi2Ilk+UqkM4oROO/0KfD1rHlFsD7smJyYNlBGlI4ahR6G8C0ZVGe1L6jTb6KL9AJN8Y4+E0hwmcDS2wPtot/028iTei/dSDq5FAMH8vQjhBgd6roVEF1miXPTDG7+/4/r0ZnDKe4D0bA== 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:(13230028)(4636009)(136003)(346002)(39860400002)(376002)(396003)(451199021)(40470700004)(46966006)(36840700001)(86362001)(2616005)(54906003)(110136005)(478600001)(40480700001)(7696005)(6666004)(186003)(16526019)(41300700001)(4326008)(316002)(83380400001)(47076005)(82310400005)(26005)(426003)(336012)(1076003)(70206006)(70586007)(8936002)(5660300002)(36756003)(44832011)(40460700003)(36860700001)(8676002)(2906002)(81166007)(356005)(82740400003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:39.0275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c71102e-354d-45cd-6ed3-08db7418156d 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8460 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org After software has authenticated a dynamic boost control request, it can fetch and set supported parameters using a selection of messages. Add support for these messages and export the ability to do this to userspace. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag --- drivers/crypto/ccp/dbc.c | 41 ++++++++++++++++++++ drivers/crypto/ccp/dbc.h | 6 +++ include/linux/psp-platform-access.h | 2 + include/uapi/linux/psp-dbc.h | 60 +++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index c6f5fb3658ca3..839ea14b9a853 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -74,6 +74,30 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev) return ret; } +static int send_dbc_parameter(struct psp_dbc_device *dbc_dev) +{ + dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_param); + + switch (dbc_dev->mbox->dbc_param.user.msg_index) { + case PARAM_SET_FMAX_CAP: + case PARAM_SET_PWR_CAP: + case PARAM_SET_GFX_MODE: + return send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_PARAMETER); + case PARAM_GET_FMAX_CAP: + case PARAM_GET_PWR_CAP: + case PARAM_GET_CURR_TEMP: + case PARAM_GET_FMAX_MAX: + case PARAM_GET_FMAX_MIN: + case PARAM_GET_SOC_PWR_MAX: + case PARAM_GET_SOC_PWR_MIN: + case PARAM_GET_SOC_PWR_CUR: + case PARAM_GET_GFX_MODE: + return send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_PARAMETER); + } + + return -EINVAL; +} + void dbc_dev_destroy(struct psp_device *psp) { struct psp_dbc_device *dbc_dev = psp->dbc_data; @@ -135,6 +159,23 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) goto unlock; } break; + case DBCIOCPARAM: + if (copy_from_user(&dbc_dev->mbox->dbc_param.user, argp, + sizeof(struct dbc_user_param))) { + ret = -EFAULT; + goto unlock; + } + + 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))) { + ret = -EFAULT; + goto unlock; + } + break; default: ret = -EINVAL; diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h index 1564351000761..e963099ca38ec 100644 --- a/drivers/crypto/ccp/dbc.h +++ b/drivers/crypto/ccp/dbc.h @@ -38,10 +38,16 @@ struct dbc_set_uid { struct dbc_user_setuid user; } __packed; +struct dbc_param { + struct psp_req_buffer_hdr header; + struct dbc_user_param user; +} __packed; + union dbc_buffer { struct psp_request req; struct dbc_nonce dbc_nonce; struct dbc_set_uid dbc_set_uid; + struct dbc_param dbc_param; }; void dbc_dev_destroy(struct psp_device *psp); diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h index 18b9e0f0cb03b..c1dc87fc536b8 100644 --- a/include/linux/psp-platform-access.h +++ b/include/linux/psp-platform-access.h @@ -10,6 +10,8 @@ enum psp_platform_access_msg { PSP_I2C_REQ_BUS_CMD = 0x64, PSP_DYNAMIC_BOOST_GET_NONCE, PSP_DYNAMIC_BOOST_SET_UID, + PSP_DYNAMIC_BOOST_GET_PARAMETER, + PSP_DYNAMIC_BOOST_SET_PARAMETER, }; struct psp_req_buffer_hdr { diff --git a/include/uapi/linux/psp-dbc.h b/include/uapi/linux/psp-dbc.h index 7443c78ede199..b3845a9ff5fd3 100644 --- a/include/uapi/linux/psp-dbc.h +++ b/include/uapi/linux/psp-dbc.h @@ -45,6 +45,23 @@ struct dbc_user_setuid { __u8 signature[DBC_SIG_SIZE]; } __packed; +/** + * struct dbc_user_param - Parameter exchange structure (input/output). + * @msg_index: Message indicating what parameter to set or get (input) + * @param: 4 byte parameter, units are message specific. (input/output) + * @signature: 32 byte signature. + * - When sending a message this is to be created by software + * using a previous nonce (input) + * - For interpreting results, this signature is updated by the + * PSP to allow software to validate the authenticity of the + * results. + */ +struct dbc_user_param { + __u32 msg_index; + __u32 param; + __u8 signature[DBC_SIG_SIZE]; +} __packed; + /** * Dynamic Boost Control (DBC) IOC * @@ -84,4 +101,47 @@ struct dbc_user_setuid { */ #define DBCIOCUID _IOW(DBC_IOC_TYPE, 0x2, struct dbc_user_setuid) +/** + * DBCIOCPARAM - Set or get a parameter from the PSP. + * This request will only work after DBCIOCUID has successfully + * set the UID of the calling process. + * Whether the parameter is set or get is controlled by the + * message ID in the request. + * This command must be sent using a 32 byte signature built + * using the nonce fetched from DBCIOCNONCE. + * When the command succeeds, the 32 byte signature will be + * updated by the PSP for software to authenticate the results. + */ +#define DBCIOCPARAM _IOWR(DBC_IOC_TYPE, 0x3, struct dbc_user_param) + +/** + * enum dbc_cmd_msg - Messages utilized by DBCIOCPARAM + * @PARAM_GET_FMAX_CAP: Get frequency cap (MHz) + * @PARAM_SET_FMAX_CAP: Set frequency cap (MHz) + * @PARAM_GET_PWR_CAP: Get socket power cap (mW) + * @PARAM_SET_PWR_CAP: Set socket power cap (mW) + * @PARAM_GET_GFX_MODE: Get graphics mode (0/1) + * @PARAM_SET_GFX_MODE: Set graphics mode (0/1) + * @PARAM_GET_CURR_TEMP: Get current temperature (degrees C) + * @PARAM_GET_FMAX_MAX: Get maximum allowed value for frequency (MHz) + * @PARAM_GET_FMAX_MIN: Get minimum allowed value for frequency (MHz) + * @PARAM_GET_SOC_PWR_MAX: Get maximum allowed value for SoC power (mw) + * @PARAM_GET_SOC_PWR_MIN: Get minimum allowed value for SoC power (mw) + * @PARAM_GET_SOC_PWR_CUR: Get current value for SoC Power (mW) + */ +enum dbc_cmd_msg { + PARAM_GET_FMAX_CAP = 0x3, + PARAM_SET_FMAX_CAP = 0x4, + PARAM_GET_PWR_CAP = 0x5, + PARAM_SET_PWR_CAP = 0x6, + PARAM_GET_GFX_MODE = 0x7, + PARAM_SET_GFX_MODE = 0x8, + PARAM_GET_CURR_TEMP = 0x9, + PARAM_GET_FMAX_MAX = 0xA, + PARAM_GET_FMAX_MIN = 0xB, + PARAM_GET_SOC_PWR_MAX = 0xC, + PARAM_GET_SOC_PWR_MIN = 0xD, + PARAM_GET_SOC_PWR_CUR = 0xE, +}; + #endif /* __PSP_DBC_USER_H__ */ From patchwork Fri Jun 23 13:49:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695352 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 2A946EB64D7 for ; Fri, 23 Jun 2023 18:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbjFWScS (ORCPT ); Fri, 23 Jun 2023 14:32:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232135AbjFWSbs (ORCPT ); Fri, 23 Jun 2023 14:31:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2074.outbound.protection.outlook.com [40.107.244.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC7F1272C; Fri, 23 Jun 2023 11:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cJQ4vp2IyL81qApJFf3sVc+MqI9h5vyvx7jbj5AI1SJF23ooVSvCF7zgkSmLoiZDkl0p6OCkQjlPVTg1vsRBspiYb7mrMBGuwIrBgSWDnHlutqgx9yMn6iIu7d2x+lAJVclTEFdEQrawvvJHF52ZYWvrjbOuDzx8JTt74DCsjBTiq0O67TXMYVwNn2o9kpvJ17cWcWho6DTx9oHyPR6CWBY+P+IBM4fDNGmD6NFC7DCIgrY8LotZaI6OU3hYVtSBf2uDc18Dx0nbdI2AnuYugCjLt0Cpfq85XqPwsIL236/5EUftqvYKq4Rzp5FRW6q9a3eIcJA4k6T1f8d3pOfIDQ== 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=V3Yypmip2TtWCDRgZCVF732sfv63Kv0948BfdGKrlts=; b=est/vjAElwCERd/eTz4cRbOP//MQyT3SCwcGWp4RUOq8sYIzr6CcugcK/C3WtEr5XYeNKtSLtXvgHojqzhwIQo2XKEfSh9DmnWUcOcxscXrxG3aN3odI2jzzFvUqSTJn5v3DH6UbjiySDQDFTIc+k2PSKcwOp2S/yzQ957gL+eekZ1itT5CsVMGz5XAVpSJNDHqajhooHica55IkaHRvZVizfBxIyrTFSoHclJuWbhyeGwyRp0cdcwjU+3BQ+/pDY5XduULxZ9sXhvJWbRki+jt5mWokp8ra/WVhz8wR0syuXJV36LychTynbT2nS/v4el++Pnz7GChw09Y02LAWEQ== 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=V3Yypmip2TtWCDRgZCVF732sfv63Kv0948BfdGKrlts=; b=xs1VJggVAJv+W9JIi/q9ScTX1r18siJd2JXSGVcTq395JjJMdiQXC1N7o3L7QUzYb48dXWzvzwEk4ddCjpwkUoWvVzYpO0KPppwn+b85OkwTEWn4/V3SiRsUyPAMWBmi4dV3oo4ecBDC6hwWR5lYSQzUfrPs5sObMNmFiaDnc28= Received: from BL1P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::9) by MW4PR12MB6706.namprd12.prod.outlook.com (2603:10b6:303:1e2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Fri, 23 Jun 2023 18:31:40 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::1a) by BL1P221CA0003.outlook.office365.com (2603:10b6:208:2c5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:39 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:39 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:37 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 08/11] crypto: ccp: Add a sample library for ioctl use Date: Fri, 23 Jun 2023 08:49:58 -0500 Message-ID: <20230623135001.18672-9-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|MW4PR12MB6706:EE_ X-MS-Office365-Filtering-Correlation-Id: dd0ddbf3-14e5-4195-1ca1-08db741815bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NetTSPy6lWI4s1BLI685jNcF3iI1ep0+5pv0sbGW5d0H291VHTiVm3rWGjMJLUzPeQeC20RXeB/yipTzq5CduCkh9UvkIP/SZJf5AdtEsqEM523wtEW5s5VXDTyuPD/9GaV7nN2LFCnXdICDe7mggwOt0Tpfmb+xijqybZhqxJfgRrOhcZv9ZqSJQet3rL1qdXIHj1MYeAQwpfzXzAh/0b0KR+Da3UND5JZbf05I3tTGm7uDZIojBaUjKJfH9M+/WGZOa4uekk+JAFpMz6CjcAjQ624Oe5RPUOUkq1os2H8iMkV87Vsx9DWeaoc4/NG47z0+FPQ4HqK1b+IQ5fcfwe8UaWRlj8gYT3PfJfBVOwPYLM5weIMBt8e+rSLqW29S9PWHKiK/fZNag6lktBP7TwaJ6vkUhWFS+n9dAaIYZ5p4GcplOO0jcR5hIXxlyAD2tYt4WY3GJNga3CXe7ACwCRTCc0bQwrpAnMZhvCR4/4poIFwN1TYlQexe464F2cyeOyqd8/+gsybg0fSPmIc26zU7BAaNLm4HSJFZrtfifkpukkoWCZNveVVAEdbHnjp4CcoGbO99JkHsDPe6gySslh+V1FVtDFUeZ/GNSueqQdqVxF4rD22eAqonai+dQsjrMgXEncXOVp+gHW2jx7J/wR07xjM2z05Lv7FTDWU+dl+/SwJ+i7JN0+nDJscB2ikeCHMXnK5evPkhhmE6wTtp3wFgGRUgfNKZBPCtC2r7PYYlhXMz3zFKSjTlVrKaK7iJO3HmZE76vVXz1wbvi1YcWYI3aCYAV4INnWzYwUcW6bw= 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:(13230028)(4636009)(376002)(39860400002)(396003)(346002)(136003)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(8936002)(5660300002)(44832011)(36860700001)(36756003)(8676002)(81166007)(356005)(82740400003)(2906002)(478600001)(6666004)(16526019)(186003)(40480700001)(110136005)(2616005)(54906003)(86362001)(82310400005)(26005)(7696005)(1076003)(70206006)(70586007)(47076005)(316002)(4326008)(426003)(336012)(41300700001)(36900700001)(309714004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:39.5275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd0ddbf3-14e5-4195-1ca1-08db741815bc 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6706 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add a small shared library that demonstrates the usage of the IOCTL interface. This library can be linked to but, is intended to be loaded and used by higher level languages Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag v3->v4: * New patch --- tools/crypto/ccp/Makefile | 13 +++++++ tools/crypto/ccp/dbc.c | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tools/crypto/ccp/Makefile create mode 100644 tools/crypto/ccp/dbc.c diff --git a/tools/crypto/ccp/Makefile b/tools/crypto/ccp/Makefile new file mode 100644 index 0000000000000..ae4a66d1558a1 --- /dev/null +++ b/tools/crypto/ccp/Makefile @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +CFLAGS += -D__EXPORTED_HEADERS__ -I../../../include/uapi -I../../../include + +TARGET = dbc_library.so + +all: $(TARGET) + +dbc_library.so: dbc.c + $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< + chmod -x $@ + +clean: + $(RM) $(TARGET) diff --git a/tools/crypto/ccp/dbc.c b/tools/crypto/ccp/dbc.c new file mode 100644 index 0000000000000..37e813175642f --- /dev/null +++ b/tools/crypto/ccp/dbc.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * AMD Secure Processor Dynamic Boost Control sample library + * + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * + * Author: Mario Limonciello + */ + +#include +#include +#include + +/* if uapi header isn't installed, this might not yet exist */ +#ifndef __packed +#define __packed __attribute__((packed)) +#endif +#include + +int get_nonce(int fd, void *nonce_out, void *signature) +{ + struct dbc_user_nonce tmp = { + .auth_needed = !!signature, + }; + int ret; + + assert(nonce_out); + + if (signature) + memcpy(tmp.signature, signature, sizeof(tmp.signature)); + + ret = ioctl(fd, DBCIOCNONCE, &tmp); + if (ret) + return ret; + memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce)); + + return 0; +} + +int set_uid(int fd, __u8 *uid, __u8 *signature) +{ + struct dbc_user_setuid tmp; + + assert(uid); + assert(signature); + + memcpy(tmp.uid, uid, sizeof(tmp.uid)); + memcpy(tmp.signature, signature, sizeof(tmp.signature)); + + return ioctl(fd, DBCIOCUID, &tmp); +} + +int process_param(int fd, int msg_index, __u8 *signature, int *data) +{ + struct dbc_user_param tmp = { + .msg_index = msg_index, + .param = *data, + }; + int ret; + + assert(signature); + assert(data); + + memcpy(tmp.signature, signature, sizeof(tmp.signature)); + + ret = ioctl(fd, DBCIOCPARAM, &tmp); + if (ret) + return ret; + + *data = tmp.param; + return 0; +} From patchwork Fri Jun 23 13:49:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695900 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 5D7AEEB64DD for ; Fri, 23 Jun 2023 18:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232302AbjFWScU (ORCPT ); Fri, 23 Jun 2023 14:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232147AbjFWSbs (ORCPT ); Fri, 23 Jun 2023 14:31:48 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2086.outbound.protection.outlook.com [40.107.94.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C96352726; Fri, 23 Jun 2023 11:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzZuqcrTr8a6z51u23N61zS2qzby0yfPE2icT1v1g8BWWBma93OX75HBE7QV1HXX0nj3qp9Ty2X4hVHcIneGymkPvXIESWVWY9/AAPxuGKUaRDQ5DzF9w4fczLjOvbJwgIrouy3BAbAFAxl0eI2Y2TsMnaSnvJwiaNjV+m/BG+sfB379AxrqkNtYunD4erm3fWgimNlPDwzKNN4/v/kKT8ASG6egsYtBRJkBLk2wU10xKnCH1QoKzE7IU7MBF4ByjCGENztoqEYTQGDpAK9a9RgCkbFcdsx0izmKLVO2DVKrYYbnDhZYKd6+wVyWHg7FcyVHyPmEwlEWpekCoGI7dw== 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=XFwlNvtUXHTcR5sspekqsjsKgKPTL3b708AnLTSeL2o=; b=iqHmQpI65DEFSj/3vzQCMaj5LKimzwDxHk7LBDass5Xni5ExZmR0lXkkSCQC3thRrpMyrsHkeeJd7whPXxIA2rcvkTCEsvbBLVUA2uqmdQwSIBo1nVDrarvoL4dy0SAEy8QHaSf3zjC9tCf4TiyBIa+rl3s1RDCEuX24P+hqPp16mT9ISMwAYPEUCn1rfFQZjjcYX6efFKAVEFp8BvpaAYHytsuK++HbRexupBzLnuoDNBHtYF+04gRiTnmm8z+roRh24AfZatXaZkT/W4NYsLYOmgKOraFFhHyUh7h+Ul+Wd83lfcH3N64on/9Ftt9l8YhIo48beL/oD1k2gnj0Zw== 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=XFwlNvtUXHTcR5sspekqsjsKgKPTL3b708AnLTSeL2o=; b=OKn+zy6smyAZ/cPAl5lX68tnfmarWFx8/ZM3kkc6o3TzQXmSJ5Higeb/C/+M01TxMlBgrNknhFZymwYo3xjhVFQXc/UaegiWFHrILs1Lvp5QyW+1r2hNrPq/5Ug0LyBCu4nhJNF2lKRjAaxJTQpLIlUtAD40mVeuG4/SWEXGTBw= Received: from BL1P221CA0009.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::24) by IA1PR12MB8517.namprd12.prod.outlook.com (2603:10b6:208:449::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Fri, 23 Jun 2023 18:31:40 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::f8) by BL1P221CA0009.outlook.office365.com (2603:10b6:208:2c5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:40 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:40 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:38 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 09/11] crypto: ccp: Add a sample python script for Dynamic Boost Control Date: Fri, 23 Jun 2023 08:49:59 -0500 Message-ID: <20230623135001.18672-10-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|IA1PR12MB8517:EE_ X-MS-Office365-Filtering-Correlation-Id: 3432121a-9b21-4a4d-6544-08db74181646 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qcIrE+hpIKmON3y75+vJaxxl33WpgmvJBgtb+bSE0MxpmqcCG47rcTFqOvbb/TM4HaXj/mXyopjLJg7JaVGt+ZK/Q5hJLI3SdzsSSk3xxn8ND+rGY2k2DHeay1yAoNqpW3gD06w7QlD4bjscp1osH7OSFt8tYDI4sUMX12q06fXU3pDHYWa/WmybLzkWUUx/WzmXmD9YAFEd+15Seje+fIJr7ETQBSLpVfuhw0Hrrf9M2Uu0q6717WOnvmmdPiUBJmroxymNGZ132aulU8naVQpDk19MjUQAxKA9Kqs7lXQfnv43n95ycjuDwRv0A+93rGOcTRqHQleoOulCrQ1853PJ90ke5GgJwMH0HnKZpoGxw63W4zNuSdJ7tkKhS93+6fDhZWGUtkCPSTRyT+fJB4eWfAmRo3AN7rzsxUK9ZvgbMSuqi0Tg7RsnUjqQdvLWj94hjxwBMc90XvCFvwgkumP6FU2EGpcBqDLfCyHSlYMIpzdKJhlLEZCYcA61IaPoDewQxA9NHmG9ke82x+cSHvQz1JsJia/kTWINX1PrnU/YeST8Sa5fzzsO35AbS79QOwxzXvdIIVeTcQoe7D8+T+pORPrHra7WEVgjmTXtvWCvz1cAuG9a+EFiNmPv7rlNJug/QyZHZjOYn/efnNg0xiAWWXiluJARDzU97zK3hBMKU5ScQ8sXD3KsJdlyETJImx6KaWTJuU7USzcydwEceNao6/cVjjSWg0kzsUuKRjeFEJwsCu5eOH3fpQ5tLjUDq7L09QdfbfaUG3HUuosAMw== 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:(13230028)(4636009)(39860400002)(346002)(376002)(136003)(396003)(451199021)(40470700004)(36840700001)(46966006)(186003)(16526019)(26005)(1076003)(2616005)(83380400001)(336012)(54906003)(82740400003)(426003)(7696005)(82310400005)(2906002)(478600001)(36860700001)(47076005)(36756003)(6666004)(110136005)(40480700001)(44832011)(70586007)(70206006)(316002)(5660300002)(8676002)(4326008)(41300700001)(81166007)(40460700003)(356005)(8936002)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:40.4337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3432121a-9b21-4a4d-6544-08db74181646 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8517 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Dynamic Boost Control commands are triggered by userspace with an IOCTL interface that userspace will prepare proper buffers for a request. To allow prototyping and testing this interface, add a python3 command line script that loads the dbc_library.so for utilizing the IOCTLs. The signature to use and UID are passed as arguments to this script. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Fix the `get-fmax-min` message which was accidentally checking `PARAM_GET_FMAX_MAX` * Pick up tag v3->v4: * Use library from previous patch instead of python's ioctl interface --- tools/crypto/ccp/.gitignore | 1 + tools/crypto/ccp/dbc.py | 64 +++++++++++++++++ tools/crypto/ccp/dbc_cli.py | 134 ++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 tools/crypto/ccp/.gitignore create mode 100644 tools/crypto/ccp/dbc.py create mode 100755 tools/crypto/ccp/dbc_cli.py diff --git a/tools/crypto/ccp/.gitignore b/tools/crypto/ccp/.gitignore new file mode 100644 index 0000000000000..bee8a64b79a99 --- /dev/null +++ b/tools/crypto/ccp/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/tools/crypto/ccp/dbc.py b/tools/crypto/ccp/dbc.py new file mode 100644 index 0000000000000..3f6a825ffc9e4 --- /dev/null +++ b/tools/crypto/ccp/dbc.py @@ -0,0 +1,64 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 + +import ctypes +import os + +DBC_UID_SIZE = 16 +DBC_NONCE_SIZE = 16 +DBC_SIG_SIZE = 32 + +PARAM_GET_FMAX_CAP = (0x3,) +PARAM_SET_FMAX_CAP = (0x4,) +PARAM_GET_PWR_CAP = (0x5,) +PARAM_SET_PWR_CAP = (0x6,) +PARAM_GET_GFX_MODE = (0x7,) +PARAM_SET_GFX_MODE = (0x8,) +PARAM_GET_CURR_TEMP = (0x9,) +PARAM_GET_FMAX_MAX = (0xA,) +PARAM_GET_FMAX_MIN = (0xB,) +PARAM_GET_SOC_PWR_MAX = (0xC,) +PARAM_GET_SOC_PWR_MIN = (0xD,) +PARAM_GET_SOC_PWR_CUR = (0xE,) + +DEVICE_NODE = "/dev/dbc" + +lib = ctypes.CDLL("./dbc_library.so", mode=ctypes.RTLD_GLOBAL) + + +def handle_error(code): + val = code * -1 + raise OSError(val, os.strerror(val)) + + +def get_nonce(device, signature): + if not device: + raise ValueError("Device required") + buf = ctypes.create_string_buffer(DBC_NONCE_SIZE) + ret = lib.get_nonce(device.fileno(), ctypes.byref(buf), signature) + if ret: + handle_error(ret) + return buf.value + + +def set_uid(device, new_uid, signature): + if not signature: + raise ValueError("Signature required") + if not new_uid: + raise ValueError("UID required") + ret = lib.set_uid(device.fileno(), new_uid, signature) + if ret: + handle_error(ret) + return True + + +def process_param(device, message, signature, data=None): + if not signature: + raise ValueError("Signature required") + if type(message) != tuple: + raise ValueError("Expected message tuple") + arg = ctypes.c_int(data if data else 0) + ret = lib.process_param(device.fileno(), message[0], signature, ctypes.pointer(arg)) + if ret: + handle_error(ret) + return arg, signature diff --git a/tools/crypto/ccp/dbc_cli.py b/tools/crypto/ccp/dbc_cli.py new file mode 100755 index 0000000000000..bf52233fd0380 --- /dev/null +++ b/tools/crypto/ccp/dbc_cli.py @@ -0,0 +1,134 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 +import argparse +import binascii +import os +import errno +from dbc import * + +ERRORS = { + errno.EACCES: "Access is denied", + errno.E2BIG: "Excess data provided", + errno.EINVAL: "Bad parameters", + errno.EAGAIN: "Bad state", + errno.ENOENT: "Not implemented or message failure", + errno.EBUSY: "Busy", + errno.ENFILE: "Overflow", + errno.EPERM: "Signature invalid", +} + +messages = { + "get-fmax-cap": PARAM_GET_FMAX_CAP, + "set-fmax-cap": PARAM_SET_FMAX_CAP, + "get-power-cap": PARAM_GET_PWR_CAP, + "set-power-cap": PARAM_SET_PWR_CAP, + "get-graphics-mode": PARAM_GET_GFX_MODE, + "set-graphics-mode": PARAM_SET_GFX_MODE, + "get-current-temp": PARAM_GET_CURR_TEMP, + "get-fmax-max": PARAM_GET_FMAX_MAX, + "get-fmax-min": PARAM_GET_FMAX_MIN, + "get-soc-power-max": PARAM_GET_SOC_PWR_MAX, + "get-soc-power-min": PARAM_GET_SOC_PWR_MIN, + "get-soc-power-cur": PARAM_GET_SOC_PWR_CUR, +} + + +def _pretty_buffer(ba): + return str(binascii.hexlify(ba, " ")) + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Dynamic Boost control command line interface" + ) + parser.add_argument( + "command", + choices=["get-nonce", "get-param", "set-param", "set-uid"], + help="Command to send", + ) + parser.add_argument("--device", default="/dev/dbc", help="Device to operate") + parser.add_argument("--signature", help="File containing signature for command") + parser.add_argument("--message", choices=messages.keys(), help="Message index") + parser.add_argument("--data", help="Argument to pass to message") + parser.add_argument("--uid", help="File containing UID to pass") + return parser.parse_args() + + +def pretty_error(code): + if code in ERRORS: + print(ERRORS[code]) + else: + print("failed with return code %d" % code) + + +if __name__ == "__main__": + args = parse_args() + data = 0 + sig = None + uid = None + if not os.path.exists(args.device): + raise IOError("Missing device {device}".format(device=args.device)) + if args.signature: + if not os.path.exists(args.signature): + raise ValueError("Invalid signature file %s" % args.signature) + with open(args.signature, "rb") as f: + sig = f.read() + if len(sig) != DBC_SIG_SIZE: + raise ValueError( + "Invalid signature length %d (expected %d)" % (len(sig), DBC_SIG_SIZE) + ) + if args.uid: + if not os.path.exists(args.uid): + raise ValueError("Invalid uid file %s" % args.uid) + with open(args.uid, "rb") as f: + uid = f.read() + if len(uid) != DBC_UID_SIZE: + raise ValueError( + "Invalid UID length %d (expected %d)" % (len(uid), DBC_UID_SIZE) + ) + if args.data: + try: + data = int(args.data, 10) + except ValueError: + data = int(args.data, 16) + + with open(args.device) as d: + if args.command == "get-nonce": + try: + nonce = get_nonce(d, sig) + print("Nonce: %s" % _pretty_buffer(bytes(nonce))) + except OSError as e: + pretty_error(e.errno) + elif args.command == "set-uid": + try: + result = set_uid(d, uid, sig) + if result: + print("Set UID") + except OSError as e: + pretty_error(e.errno) + elif args.command == "get-param": + if not args.message or args.message.startswith("set"): + raise ValueError("Invalid message %s" % args.message) + try: + param, signature = process_param(d, messages[args.message], sig) + print( + "Parameter: {par}, response signature {sig}".format( + par=param, + sig=_pretty_buffer(bytes(signature)), + ) + ) + except OSError as e: + pretty_error(e.errno) + elif args.command == "set-param": + if not args.message or args.message.startswith("get"): + raise ValueError("Invalid message %s" % args.message) + try: + param, signature = process_param(d, messages[args.message], sig, data) + print( + "Parameter: {par}, response signature {sig}".format( + par=param, + sig=_pretty_buffer(bytes(signature)), + ) + ) + except OSError as e: + pretty_error(e.errno) From patchwork Fri Jun 23 13:50:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695899 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 BF422C001DD for ; Fri, 23 Jun 2023 18:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbjFWScX (ORCPT ); Fri, 23 Jun 2023 14:32:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231138AbjFWScF (ORCPT ); Fri, 23 Jun 2023 14:32:05 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2062.outbound.protection.outlook.com [40.107.96.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 418FA2733; Fri, 23 Jun 2023 11:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EvOz6OSzHaUYm1FEA1BVGgVbYUUE4sghJQpqbvF8fJQSlcjh760wKZX0XOBKtpMLgnUyqjq5JXYi7kExvmzoBNFGvHMISweuMdgOMr/pHLjmWwHSH4OZ4Rd8mTZ1Kb9l2vmfjoP1x/JRtmkwwNEgNTq88LcPJGqh0MJDwOE/lR38iXLOS/jy/ht1Xt0yfY0UXcw8HuYYUKeiML7kSjdypHButhfbWPdiPlUXE7cIkkt3jWbiup8GuxfBZJxTTunHzG2lZ+V+NVVzksWLuBRxEJ2dgv6iqJX+2cLRqM0/Ys0ofcbfL1qCtgkm7OC259OE/RKbtiUb8cdrC7R1Jbj9qA== 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=IV39MGD9OTLQbYvEt3RPvCQiYcWrJEvAkB8dBPnnbQs=; b=NqThBd2vZWejjFkHUnLwpXf69RjqEuNI1pkzY2icpReX6AgPtzCRchOCYrRtvi+KOmhSdxwW+DzDDD16JIJT8hYbjAIjMwPqXS71cMn9t+hLZg87v67ZDhTm0KMxsMSLetwanen2jOqAL6nMwLD02FeAinh/AlpUlRO9rJ2Ok77jxUYV0SBWDQBdOS2yk+0Q3knG4n/W7gnNeAQahptUXSiiT+erfVZOqZSXos1YkRlOGIK0WWqDhjyyPhsxIP8euehgGXqaGeNytmXg8nU/qTCtjuzFOIvCBJ6P9y+PiocB4E6oa5SvbYWkoqlC0h5mq1jRrzkbIWDMNyksW14UPQ== 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=IV39MGD9OTLQbYvEt3RPvCQiYcWrJEvAkB8dBPnnbQs=; b=DIFSioGRTXimOdAv8XWigGXDTkbuB8t0lcxQYPm7fUx1GEMiCqlrGBAgLpm17uzBO4oM6RqNGaK6EuNqwg+mVlT2VdcKebjHypsKlMoEc2+DDbu2+LvEAqm8ZxBnCQY0GR4VVpOcblkoOGWMeSzQJ9i2KBV0tKiYPAZNLuB7BQM= Received: from BL1P221CA0026.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::27) by CY8PR12MB7732.namprd12.prod.outlook.com (2603:10b6:930:87::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Fri, 23 Jun 2023 18:31:40 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::b0) by BL1P221CA0026.outlook.office365.com (2603:10b6:208:2c5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:40 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:40 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:38 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 10/11] crypto: ccp: Add unit tests for dynamic boost control Date: Fri, 23 Jun 2023 08:50:00 -0500 Message-ID: <20230623135001.18672-11-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|CY8PR12MB7732:EE_ X-MS-Office365-Filtering-Correlation-Id: c64035a4-35b5-4690-1469-08db74181676 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IcrIKe1nH5hQdAg4v1JPGEzYfruIjHOMi43idSzXOSKH+rdzdPblzlEzX9qxDACDOe4hkOopRJOc1tW8sctRfPONFrspsw48ZgcRNNZdOGamP3RkIPsC3cUBs2CkUW1YjSBF1WnQfFnC4UfuvUDeMGSFdDObZqrfDXnNJV31bqITSdMRpft3Q9GyBLY8Bx+fX0q/gCV3Fqp1Lc7Z2Vj3+HBjt0u27/tPvCXbUJnVxwvqWZE03io3V4N5z9D6DZ8/J7Ub/9PcrsW1jZ2KRw64ltvFacVoJuOnhk/Pf6XejX04BRBCE1ZZ8UAUU6FPJhB2nHeKb6Fp2OgGCzxrip0M1roNFI15kRbx6EhFMU5+adsDf8CsiI/xpS219UnjkuEKd9EI8Yf+TwYYswpEfGUQO/D/kdNUDN/tVkS6poIf3kjNUeKFAe8wVO2PH0uyvp3wSazSkWNr/hQExECZijeidZ8YmZHN/YwRI3kNtz7rtJ8zQwjaIGvotb1jfRZSUZyVq6rxYPmYchK+6kkSp2/GNnpI25qaoCgffXa213Dj0sK8pyrk7W1iAHgsPaSRszGekOh8z7wzRusvZUHvSy20oqjWgN76t+mbbNDzilOAd/9JTrlFjfsz9Kje84csAxnzOUs2WH9xZmvkO7Lfxvf5m2jflS0u+L6Xd2gk9gwTeM9vCTF2Nau7S++w3M+w6/qIZT120KeMIVTdNYqmaJGoKuqRFMLdzyhF2VZ+7MPHxjp5kALGEqk6GkPhPMu81w/HT25B/WpxEnc7Oo3mgycUWg== 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:(13230028)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199021)(46966006)(36840700001)(40470700004)(82310400005)(6666004)(7696005)(40460700003)(86362001)(82740400003)(36860700001)(2616005)(1076003)(186003)(26005)(40480700001)(47076005)(336012)(426003)(36756003)(16526019)(81166007)(356005)(83380400001)(8936002)(8676002)(2906002)(316002)(4326008)(41300700001)(70586007)(70206006)(478600001)(54906003)(110136005)(44832011)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:40.7462 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c64035a4-35b5-4690-1469-08db74181676 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7732 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Interacting with dynamic boost control messages requires the caller to supply a signature. To allow validation of individual dynamic boost control components, introduce a set of tests that can be run. The tests can be run in 3 distinct different environments, and so certain tests will be skipped depending on the environment. 1. Systems that do not support DBC. 2. Production systems that support DBC but are secured silicon. 3. Pre-production systems that support DBC but are unsecured silicon. Unsecured silicon does not validate the signature, and so this allows testing more of the state machine and functionality. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * pick up tag v3->v4: * Adjust for library changes v1->v2: * Update commit message --- tools/crypto/ccp/test_dbc.py | 266 +++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100755 tools/crypto/ccp/test_dbc.py diff --git a/tools/crypto/ccp/test_dbc.py b/tools/crypto/ccp/test_dbc.py new file mode 100755 index 0000000000000..998bb3e3cd040 --- /dev/null +++ b/tools/crypto/ccp/test_dbc.py @@ -0,0 +1,266 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0 +import unittest +import os +import time +import glob +from dbc import * + +# Artificial delay between set commands +SET_DELAY = 0.5 + + +class invalid_param(ctypes.Structure): + _fields_ = [ + ("data", ctypes.c_uint8), + ] + + +def system_is_secured() -> bool: + fused_part = glob.glob("/sys/bus/pci/drivers/ccp/**/fused_part")[0] + if os.path.exists(fused_part): + with open(fused_part, "r") as r: + return int(r.read()) == 1 + return True + + +class DynamicBoostControlTest(unittest.TestCase): + def __init__(self, data) -> None: + self.d = None + self.signature = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + self.uid = "1111111111111111" + super().__init__(data) + + def setUp(self) -> None: + self.d = open(DEVICE_NODE) + return super().setUp() + + def tearDown(self) -> None: + if self.d: + self.d.close() + return super().tearDown() + + +class TestUnsupportedSystem(DynamicBoostControlTest): + def setUp(self) -> None: + if os.path.exists(DEVICE_NODE): + self.skipTest("system is supported") + with self.assertRaises(FileNotFoundError) as error: + super().setUp() + self.assertEqual(error.exception.errno, 2) + + def test_unauthenticated_nonce(self) -> None: + """fetch unauthenticated nonce""" + with self.assertRaises(ValueError) as error: + get_nonce(self.d, None) + + +class TestInvalidIoctls(DynamicBoostControlTest): + def __init__(self, data) -> None: + self.data = invalid_param() + self.data.data = 1 + super().__init__(data) + + def setUp(self) -> None: + if not os.path.exists(DEVICE_NODE): + self.skipTest("system is unsupported") + return super().setUp() + + def test_invalid_nonce_ioctl(self) -> None: + """tries to call get_nonce ioctl with invalid data structures""" + + # 0x1 (get nonce), and invalid data + INVALID1 = IOWR(ord("D"), 0x01, invalid_param) + with self.assertRaises(OSError) as error: + fcntl.ioctl(self.d, INVALID1, self.data, True) + self.assertEqual(error.exception.errno, 22) + + def test_invalid_setuid_ioctl(self) -> None: + """tries to call set_uid ioctl with invalid data structures""" + + # 0x2 (set uid), and invalid data + INVALID2 = IOW(ord("D"), 0x02, invalid_param) + with self.assertRaises(OSError) as error: + fcntl.ioctl(self.d, INVALID2, self.data, True) + self.assertEqual(error.exception.errno, 22) + + def test_invalid_setuid_rw_ioctl(self) -> None: + """tries to call set_uid ioctl with invalid data structures""" + + # 0x2 as RW (set uid), and invalid data + INVALID3 = IOWR(ord("D"), 0x02, invalid_param) + with self.assertRaises(OSError) as error: + fcntl.ioctl(self.d, INVALID3, self.data, True) + self.assertEqual(error.exception.errno, 22) + + def test_invalid_param_ioctl(self) -> None: + """tries to call param ioctl with invalid data structures""" + # 0x3 (param), and invalid data + INVALID4 = IOWR(ord("D"), 0x03, invalid_param) + with self.assertRaises(OSError) as error: + fcntl.ioctl(self.d, INVALID4, self.data, True) + self.assertEqual(error.exception.errno, 22) + + def test_invalid_call_ioctl(self) -> None: + """tries to call the DBC ioctl with invalid data structures""" + # 0x4, and invalid data + INVALID5 = IOWR(ord("D"), 0x04, invalid_param) + with self.assertRaises(OSError) as error: + fcntl.ioctl(self.d, INVALID5, self.data, True) + self.assertEqual(error.exception.errno, 22) + + +class TestInvalidSignature(DynamicBoostControlTest): + def setUp(self) -> None: + if not os.path.exists(DEVICE_NODE): + self.skipTest("system is unsupported") + if not system_is_secured(): + self.skipTest("system is unfused") + return super().setUp() + + def test_unauthenticated_nonce(self) -> None: + """fetch unauthenticated nonce""" + get_nonce(self.d, None) + + def test_multiple_unauthenticated_nonce(self) -> None: + """ensure state machine always returns nonce""" + for count in range(0, 2): + get_nonce(self.d, None) + + def test_authenticated_nonce(self) -> None: + """fetch authenticated nonce""" + with self.assertRaises(OSError) as error: + get_nonce(self.d, self.signature) + self.assertEqual(error.exception.errno, 1) + + def test_set_uid(self) -> None: + """set uid""" + with self.assertRaises(OSError) as error: + set_uid(self.d, self.uid, self.signature) + self.assertEqual(error.exception.errno, 1) + + def test_get_param(self) -> None: + """fetch a parameter""" + with self.assertRaises(OSError) as error: + process_param(self.d, PARAM_GET_SOC_PWR_CUR, self.signature) + self.assertEqual(error.exception.errno, 1) + + def test_set_param(self) -> None: + """set a parameter""" + with self.assertRaises(OSError) as error: + process_param(self.d, PARAM_SET_PWR_CAP, self.signature, 1000) + self.assertEqual(error.exception.errno, 1) + + +class TestUnFusedSystem(DynamicBoostControlTest): + def setup_identity(self) -> None: + """sets up the identity of the caller""" + # if already authenticated these may fail + try: + get_nonce(self.d, None) + except PermissionError: + pass + try: + set_uid(self.d, self.uid, self.signature) + except BlockingIOError: + pass + try: + get_nonce(self.d, self.signature) + except PermissionError: + pass + + def setUp(self) -> None: + if not os.path.exists(DEVICE_NODE): + self.skipTest("system is unsupported") + if system_is_secured(): + self.skipTest("system is fused") + super().setUp() + self.setup_identity() + time.sleep(SET_DELAY) + + def test_get_valid_param(self) -> None: + """fetch all possible parameters""" + # SOC power + soc_power_max = process_param(self.d, PARAM_GET_SOC_PWR_MAX, self.signature) + soc_power_min = process_param(self.d, PARAM_GET_SOC_PWR_MIN, self.signature) + self.assertGreater(soc_power_max.parameter, soc_power_min.parameter) + + # fmax + fmax_max = process_param(self.d, PARAM_GET_FMAX_MAX, self.signature) + fmax_min = process_param(self.d, PARAM_GET_FMAX_MIN, self.signature) + self.assertGreater(fmax_max.parameter, fmax_min.parameter) + + # cap values + keys = { + "fmax-cap": PARAM_GET_FMAX_CAP, + "power-cap": PARAM_GET_PWR_CAP, + "current-temp": PARAM_GET_CURR_TEMP, + "soc-power-cur": PARAM_GET_SOC_PWR_CUR, + } + for k in keys: + result = process_param(self.d, keys[k], self.signature) + self.assertGreater(result.parameter, 0) + + def test_get_invalid_param(self) -> None: + """fetch an invalid parameter""" + try: + set_uid(self.d, self.uid, self.signature) + except OSError: + pass + with self.assertRaises(OSError) as error: + process_param(self.d, (0xF,), self.signature) + self.assertEqual(error.exception.errno, 22) + + def test_set_fmax(self) -> None: + """get/set fmax limit""" + # fetch current + original = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature) + + # set the fmax + target = original.parameter - 100 + process_param(self.d, PARAM_SET_FMAX_CAP, self.signature, target) + time.sleep(SET_DELAY) + new = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature) + self.assertEqual(new.parameter, target) + + # revert back to current + process_param(self.d, PARAM_SET_FMAX_CAP, self.signature, original.parameter) + time.sleep(SET_DELAY) + cur = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature) + self.assertEqual(cur.parameter, original.parameter) + + def test_set_power_cap(self) -> None: + """get/set power cap limit""" + # fetch current + original = process_param(self.d, PARAM_GET_PWR_CAP, self.signature) + + # set the fmax + target = original.parameter - 10 + process_param(self.d, PARAM_SET_PWR_CAP, self.signature, target) + time.sleep(SET_DELAY) + new = process_param(self.d, PARAM_GET_PWR_CAP, self.signature) + self.assertEqual(new.parameter, target) + + # revert back to current + process_param(self.d, PARAM_SET_PWR_CAP, self.signature, original.parameter) + time.sleep(SET_DELAY) + cur = process_param(self.d, PARAM_GET_PWR_CAP, self.signature) + self.assertEqual(cur.parameter, original.parameter) + + def test_set_3d_graphics_mode(self) -> None: + """set/get 3d graphics mode""" + # these aren't currently implemented but may be some day + # they are *expected* to fail + with self.assertRaises(OSError) as error: + process_param(self.d, PARAM_GET_GFX_MODE, self.signature) + self.assertEqual(error.exception.errno, 2) + + time.sleep(SET_DELAY) + + with self.assertRaises(OSError) as error: + process_param(self.d, PARAM_SET_GFX_MODE, self.signature, 1) + self.assertEqual(error.exception.errno, 2) + + +if __name__ == "__main__": + unittest.main() From patchwork Fri Jun 23 13:50:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 695351 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 D52C4C001DC for ; Fri, 23 Jun 2023 18:32:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbjFWScV (ORCPT ); Fri, 23 Jun 2023 14:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbjFWSbs (ORCPT ); Fri, 23 Jun 2023 14:31:48 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2051.outbound.protection.outlook.com [40.107.95.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7D92735; Fri, 23 Jun 2023 11:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KCUaULNxWWAlqQ9xjLo+XGIbrpRt15Jh9GE+Qq9BGT54FmY+xpkhNuYQje53TC54I5btrnznwJ/nnsNGJexvO7jo71LMKe/KHpCStxzZGeHbN741PXC7ao+1gge+xFtwTEymVBTQEEetI/cpcJTPcH6YPbcLNlE6Rhg8v1tFleDycwrUrvlSyirhAaamK+59Vvl6M5uoistQutpo6xDDq0ACruqwHn8x+43PXNXe1+F5ezcXIRrxzNsI0x0uI4MJrkEo+d2l7fnn322MDGVc/EXwVuxnqk4jN6OsuSU1aJ7P5PzBvM1WLEPzdAD8pszQ5VimhBedcCMpgq/cEHeghg== 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=iBofx8nJ065Z/7xjEOQ94FVM8KU6doa7jjFZg/97jkQ=; b=dwLIpR4mA7XCu3hbjEvNOSSv9FN2S2xc7vC/zcd4Od+MjZqNAy7tlhQbSwHqus5jy2yN60f+i3QoqDoYTXt6XZA6yE2zmCyLH2CQJAx8hYAl3APmjbbISJrKli+nHQgCnViVVpppDaybFQ2ID+QhVgHQGjh9fuRtjBGXWwGB1yWy31tDuSsmWb6nP5ly/+yDA6LNFtOD5xE76kos/ajYYNCzF1uaWZAP9YuTYHWMTEtwDyIvgQupP3BAJwLl6OnM+C+1vGAPYpPo5F4fdJ88JSTyoZn9hSsOuc0cVWEsYuE80PuwRnXwxHP6SJO0u9y4ZKs2EsakXxYOveuIEnMVfw== 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=iBofx8nJ065Z/7xjEOQ94FVM8KU6doa7jjFZg/97jkQ=; b=MdsP/8VnbyOp2SoqcrsEn6zt6B1T6viSRqbN/iav5z6iEw8Inh27LUGRFJOipZNKdc9B4X74WED/Y618AJcLrisCsybhSNMUiHoqqQGC9d+2LJYdkk5sCGATxZzz2AcExNiN8/72lkpOpOWCYZpCu/uflzPz9INAX2/MQShVyWU= Received: from BL1P221CA0021.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::17) by MN0PR12MB5714.namprd12.prod.outlook.com (2603:10b6:208:371::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Fri, 23 Jun 2023 18:31:41 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2c5:cafe::64) by BL1P221CA0021.outlook.office365.com (2603:10b6:208:2c5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26 via Frontend Transport; Fri, 23 Jun 2023 18:31:41 +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 BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.17 via Frontend Transport; Fri, 23 Jun 2023 18:31:41 +0000 Received: from SITE-L-T34-2.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.23; Fri, 23 Jun 2023 13:31:39 -0500 From: Mario Limonciello To: Tom Lendacky , John Allen , Herbert Xu CC: "David S . Miller" , , , Mario Limonciello Subject: [PATCH v5 11/11] crypto: ccp: Add Mario to MAINTAINERS Date: Fri, 23 Jun 2023 08:50:01 -0500 Message-ID: <20230623135001.18672-12-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623135001.18672-1-mario.limonciello@amd.com> References: <20230623135001.18672-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|MN0PR12MB5714:EE_ X-MS-Office365-Filtering-Correlation-Id: e562be2a-5fc6-4103-9b06-08db741816bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T9akY4JEQdDR5nCNPygGiUixNjemAYd98nwUrSeSerVUzje4rmkDLlvo5n4LZ1C0ue0MoRyoIF2i+DrSF0fmL2OgzflQcv6WP+noKH+NwdmFp4dcs+VR3cvHr5DLNNmeuw+P2pSK6H0+ehnQpbHahMLUJWlAZtZsFXlT8q1sb8YPMdTDxK6c1BDIF6e1bmIVNLVz0LX5X+nTsoZwP0W+4AHwjAqD40HOrkRMf4NzGgA9ObQyGGSYYxjuDIHO0nIFKkDThffGaR3u6N2gLXjygRa4t8FRkMDPHeI2dQOrVKYbQQ5LyCmx4aMg2bN5e04GnfFsXUiQrqYi6grm2hucTHfcNPTLOuFwlVDGXsHU7mTbFrI8Cs6YJH7YsUTdB2267bEBV0L/TxF8HPIsFIgC1LE1qcH2pgPf3DTGGStiVcbZn6+AEI/Dc4GNNHmNoPtI9NaQ5RcRkLxXildDVHen+pP7VKCSZUjiXD8IRVf10YscVy+bJD/I/YU65vND+zeXO7wAu/70kXSC05Pm1RKvkRqqCX/i9AMKTnuZ4eYbD0SHQrUa+QRZTWkt7ObwZfK8OWEZv+c6PTEBCOeNnk88k2S52cCLhM6BPDZY586Zbn9+wuyYPsjwD9JpIRJ0Q9Qove4LelG3PLHAJtYI1itGs02BSD3mvPGVVGS7kWNIeW22y0yDHaFniVDXyouif9njBU9GSeqrsFsUcP4t9e3PaxNzv4IInU2DeFHuPSL9b2+EAP6QeQQddcrJDSlELshbxK8PEtwyV60nwqF4YdH3Fg== 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:(13230028)(4636009)(346002)(39860400002)(136003)(376002)(396003)(451199021)(46966006)(40470700004)(36840700001)(36756003)(86362001)(186003)(36860700001)(82740400003)(356005)(8676002)(8936002)(81166007)(47076005)(4326008)(83380400001)(426003)(336012)(26005)(16526019)(110136005)(1076003)(316002)(7696005)(6666004)(70586007)(54906003)(2616005)(478600001)(70206006)(44832011)(2906002)(41300700001)(5660300002)(40460700003)(82310400005)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2023 18:31:41.2150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e562be2a-5fc6-4103-9b06-08db741816bd 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: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5714 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org I will maintain the platform access interface and dynamic boost control support. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tag v3->v4: * Add reference to new tools/crypto/ccp/dbc.c --- MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index f2e19f576fecd..709ebc2ebbe2b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -988,6 +988,18 @@ S: Supported F: drivers/crypto/ccp/sev* F: include/uapi/linux/psp-sev.h +AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER - DBC SUPPORT +M: Mario Limonciello +L: linux-crypto@vger.kernel.org +S: Supported +F: drivers/crypto/ccp/dbc.c +F: drivers/crypto/ccp/dbc.h +F: drivers/crypto/ccp/platform-access.c +F: drivers/crypto/ccp/platform-access.h +F: include/uapi/linux/psp-dbc.h +F: tools/crypto/ccp/*.c +F: tools/crypto/ccp/*.py + AMD DISPLAY CORE M: Harry Wentland M: Leo Li