From patchwork Thu Apr 20 16:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675686 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 91D32C77B73 for ; Thu, 20 Apr 2023 16:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbjDTQcJ (ORCPT ); Thu, 20 Apr 2023 12:32:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbjDTQcH (ORCPT ); Thu, 20 Apr 2023 12:32:07 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC3EE60; Thu, 20 Apr 2023 09:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f8He5kvcahhzvUmdWcD34foyPxxxrtJnB4tPVsAAtwLJWXPJsxYYn0XVlmB3QoWTQNubWcW7kmUAI6RvMrbywn4gSSOOkGpQlA1L6qo1Ns3FymoOtg4RyK1UWOiG2U/LMTh9tVVDPNRRttWDPvXK2MziK468yWOcIkCxfTGi5YCMVvNUx0w9QRZ8uivk2yuvpCRBaZdop7qkj7gvjZdzLoPdc15bkmiAz5Oq6C/O3i9t/e/TfDc67QDFgpUgMWu5D8W6FDWvI7o/mc/Q+lGy4JOkOS/EoU3gMVVEwdL9tSHeKhtmXKm61wkQwkiMv0lz7uPhXyPKEjMlZPfglu3UBQ== 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=tT9pMXjLl6E+ougnM0VBeecJpTqYTp3ifuOyQ+Nqe0I=; b=i9ZsG6/wvfwc2feY36bU4CftRfnyfIJ1CgzmUP+cRkaenbuGMA9/MKbEYpSd8PwAFD1gq9PxzkLW89EGg8iKtYQ94/lP1wYibBVpi7Ey2rrqVkTF/yDE7phbFRWMh2eQjAgkL4Ekv6Q/54W+MjBpEVekO/7Qnj6vO5Ch0Q0obso0SrdpF278aa97L9j7KuDMJkWd9hbbewF93bsNJd5j5u1vTUTI2tAjBXfm3UIkwRDIbKsbW5NnUS+xqtoHt3SaB/Hno9W9om9AeGGJ/IGlty/vDQ9ZzYILU5FGEt6dxjfHMvN2FSA8ZBcYm4GbTHGT9yh9j9MQOIJpI8ZAdFcNmA== 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=tT9pMXjLl6E+ougnM0VBeecJpTqYTp3ifuOyQ+Nqe0I=; b=zuRZSb3jnwPj3ehMJVV8Kn6bCStFa+jfjpWaHpNN+ArakT9KbjChlqCf7upsEi1N19Xk9Bgp5g+zvANrCjRQrZ5j4AuOd2x7g1glUHsFOIWS2eniPTW70q4mjXRk/QMWYGrtobBH7BXkYc3x+bTM6rCI/RLUg54ur7xiOfTinhI= Received: from DS7PR03CA0340.namprd03.prod.outlook.com (2603:10b6:8:55::21) by SN7PR12MB6716.namprd12.prod.outlook.com (2603:10b6:806:270::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Thu, 20 Apr 2023 16:32:04 +0000 Received: from DM6NAM11FT113.eop-nam11.prod.protection.outlook.com (2603:10b6:8:55:cafe::6f) by DS7PR03CA0340.outlook.office365.com (2603:10b6:8:55::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +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 DM6NAM11FT113.mail.protection.outlook.com (10.13.173.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:03 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:31:58 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 01/10] crypto: ccp: Rename macro for security attributes Date: Thu, 20 Apr 2023 11:31:29 -0500 Message-ID: <20230420163140.14940-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT113:EE_|SN7PR12MB6716:EE_ X-MS-Office365-Filtering-Correlation-Id: 65426dd3-990a-4cc3-da14-08db41bcc5de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cOOAiOYyihBA4HrCWvoLsGyWy35D05UkMYiU0Q2zijZw1MIxAOIG7OaGeyKchB99rtuirHFimUb9lJ+InXcrV8iCEt7vuFFqDWXxKZRu/r+VA7KuxY/uEzrRvzDA/RtdPX+3m/L0PsUfvASsNE5Fj/LfX//yaaym61EJzlzNLvd49UIsRpg+QPlF3+LR0EQ24nP3pOTB8VgoOBpB38Z6l6BN9yr13FmOzxADt0VR4y7O0/UBIWjhlFKoF7L1Zg6neu1CvWniYrzU/uGrf5JvGHbHCduvy5J/TcH+kflAtr1UydDNZELHHupNOfwYIIQepnaY3r5BT0GuQVN23rZ3T5wPbpUoCyovk2Een2dBIJTv6GDMSzpAMnb1eDofPKWL1jzAtGI7v62rmOvAcZ5ltWIj3gr1t4Fls8oqODhFxAODey7IMruq+tKOWrwg1GF1F3dGvpZExLg12SggjrEJ8KArpajNF2WmvRNQWQcsEcnKuAbpN798A24CFlx6Q+sz08kNaPMcgaQV+xX0SysTv+BFW1VOmytzG1IiB4htV91ZMeV8feviF9Ydujw5wX7uvS32bOmL4uW39vjklavIV7yx6QvDIAhTpf6Z/UwkPsvbdE8DBBu95+sfDHDr2WH/raGd8rshcUavORgG6uDI4Vb6EYDHjYESbjAVB7tBhongvbKsWxuqTvVqn+eFFOp4YE8GwDR79ArMyKZw2oWUSQeVAeYq2WjwjXj3EC8mZRI= 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)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(6636002)(478600001)(6666004)(8936002)(8676002)(316002)(41300700001)(82740400003)(4326008)(70206006)(70586007)(40480700001)(54906003)(110136005)(81166007)(356005)(186003)(40460700003)(15650500001)(2906002)(16526019)(36756003)(426003)(83380400001)(1076003)(26005)(86362001)(336012)(47076005)(82310400005)(36860700001)(5660300002)(2616005)(7696005)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:03.1649 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65426dd3-990a-4cc3-da14-08db41bcc5de 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: DM6NAM11FT113.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6716 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. Signed-off-by: Mario Limonciello --- 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 aa15bc4cac2b..85e3dc8853e2 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 Thu Apr 20 16:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675967 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 F016FC77B72 for ; Thu, 20 Apr 2023 16:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbjDTQcI (ORCPT ); Thu, 20 Apr 2023 12:32:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232605AbjDTQcH (ORCPT ); Thu, 20 Apr 2023 12:32:07 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2083.outbound.protection.outlook.com [40.107.92.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B55210DA; Thu, 20 Apr 2023 09:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EaMybteynNZ8Fq9I4rvl22LguMwuBTzvBQAJusI9IXyIP/zH8aEJ8/O7lDIAgx9hlBQ659A6zxvdywVtT2kvlYMuz9rQAM5wb5JaLCXqa3pYqIPEV2U2dFo2miYK0IwD1iK/OUyVw0jwwihGK/JbNfYD6uMbRIkKSiB36hLm8pziIaSYBYcd83uyM/zo2RqkNEuLNmCaTYGHbKJv+bULeseJLh94r/TqSga/TKk4L8zkZycRROJ9VtIHW/Fvlo5d9YZNGhn9iDf8hCrN0fe8V+W5UAZwAkJE7+Ln9uFK5qfl9euNd6tCZv00J5DOZLXz904V6QrEkutVgrLDpkTSiA== 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=De/v1LOvw5LzDRNbq4X/mZpXgCayIOs5BnbBcv4n6uA=; b=RYhXYQ3+xjizORPkpMj1W6+meSTG0EwkCdkXk414f7jkT7VmbjmHOsE82ga0sc5B6JysL2bQFLIYJwcb0vQ1Hf26V4QsQYgHAVMigAdnBR1J6a3+6xpoCQV6cYN+PfpZkumOwHgeOxcYsLjy0ftGV8n+Ier9pajuswsHyVlKLsb/WYtwICuqhFx20959T3gF1m4sueOS+KxpEjSbx2qhkfPdtkLQfje93V/UaPdp/dXiJnDSnDnBjIH7efQ3k5SWKdHdv66k/JO7tc+aVKYxhhqRYBJ/1/FIlkmYbQ8t6gJQbiv4VpvHm5Ng8uZZJPFARlHhezZHKePyVIDkGTeFhw== 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=De/v1LOvw5LzDRNbq4X/mZpXgCayIOs5BnbBcv4n6uA=; b=R7yu90jmnoBBAOXFES+rDaS2E3eG4Ht6wAcIGmpdEt9tob3P84woFMGupVcCPzpG5V+WHcbkVG9VkWJUte2hNfHFodqdbVwt1KsWtvB1MUC8GT5o0s3gkhENttG1BfiSfdW1FhSb/fAFAGnxf+xnWJOqq1G/fNLDKbkWwjK6uho= Received: from DM6PR07CA0121.namprd07.prod.outlook.com (2603:10b6:5:330::33) by DM4PR12MB6206.namprd12.prod.outlook.com (2603:10b6:8:a7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:04 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::e) by DM6PR07CA0121.outlook.office365.com (2603:10b6:5:330::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +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 DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:03 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:31:59 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 02/10] crypto: ccp: Add support for displaying PSP firmware versions Date: Thu, 20 Apr 2023 11:31:30 -0500 Message-ID: <20230420163140.14940-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT027:EE_|DM4PR12MB6206:EE_ X-MS-Office365-Filtering-Correlation-Id: 63db6666-7bc1-48ea-7a6c-08db41bcc653 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WWfZTLwYLV+r73ckYhWujG20v4diKqcFWlGmJ3Zl56A6bPZ9VigRCgxZrywOAxYwqBuuHipDk8iI3Nuzu69RbXmOhjm/RQEVqiiAyIweSUSEPF4izoyL9dm2LZdEmqLtnQIFKjqjpNHsfniRcOGeI/vzBhVgfiBaNT/jCai2BvmUBe1/esLH1QMoLmB+pnackxJGJiMlbcqn34j3Cc7uO0zRQKM/+GggRIkCjPMCPJWhgLUZ2K1YQRqLTwXpaUKmqXHp+AF0TYI1CGIl+8MbwtAgG+lrUazKmJtb1ygVJKFCm7GSYtUoiINgoNIqx65F8PP2vfNixL04EMr1HjxapoVP25huKES/yNmeWBBYAI6lKHjCqFiG7Mrkf1u4kJ8Jbi+D5vUxejGH3ZgJAdqtqbeRfqYapcfn4Z5oXf0DWdFnxTVKs/quTcCPedyQ1Hon2WMkl2vlLKotdNwq1BCh1USS53glH5TtUSZP9fo7HfcxYexpwRRpD7g43iH8g8aokTMb5V+7C8s1IrCeOvVglzbn+Oj7d5cgGtbsMoYGki6cptwwOkxsGg8S4gUl4RSSz5fgHWqKFS4cpuw5O8jUAAPnt7bQmPwEN6d5ABhiU/9m7Pt6MNvAA4VquqS7IG+jx+8rWg9SVC9Eo1YDJe9qdrQjxv8sKhF9cNmihAUEUcAb4dVf8jcudjO9EDRrcuzq/ZwyzRAm5zYGX4f/dn72FxpKGCqBjYO6lHqcNpq+ceA= 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)(346002)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(4326008)(316002)(110136005)(54906003)(6636002)(70586007)(70206006)(40460700003)(186003)(16526019)(1076003)(26005)(47076005)(36860700001)(2616005)(336012)(426003)(83380400001)(40480700001)(5660300002)(41300700001)(8676002)(82310400005)(8936002)(478600001)(7696005)(6666004)(82740400003)(36756003)(86362001)(2906002)(81166007)(356005)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:03.9292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63db6666-7bc1-48ea-7a6c-08db41bcc653 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: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6206 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. Signed-off-by: Mario Limonciello --- Documentation/ABI/testing/sysfs-driver-ccp | 18 +++++++ drivers/crypto/ccp/sp-dev.h | 2 + drivers/crypto/ccp/sp-pci.c | 58 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-driver-ccp b/Documentation/ABI/testing/sysfs-driver-ccp index 7aded9b75553..ee6b787eee7a 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 1253a0217985..76c32ee6bd65 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 85e3dc8853e2..4d729aa1b260 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 @@ -88,8 +89,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(GENMASK(31, 24), val), \ + FIELD_GET(GENMASK(23, 16), val), \ + FIELD_GET(GENMASK(15, 8), val), \ + FIELD_GET(GENMASK(7, 0), 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 (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 Thu Apr 20 16:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675965 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 E1B30C77B73 for ; Thu, 20 Apr 2023 16:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234440AbjDTQcM (ORCPT ); Thu, 20 Apr 2023 12:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233174AbjDTQcJ (ORCPT ); Thu, 20 Apr 2023 12:32:09 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2050.outbound.protection.outlook.com [40.107.94.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B667B10F1; Thu, 20 Apr 2023 09:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RCWw4LmYEwkJsX3iI2d7HjXLCJvlOq20hCdQ7isZwTyzHHTfrVaWWKztBjFLDZwkcg3x/ft1wPSdVAWRPJ1285kVTpw166EypGQGZyq4EvdvmK/mCbrLEUugon6EsnqWLJsl/DU2JpPiWzyGzo+Zrd/MkgmgSqgekmEG/L3HN23k3WUVLRAYYsG0llbybb82gCfWLxOIQYClrrXad+0AwEmsu4SkWS1bTRxHEz4+cRqfd104xq4Ba4hjtg6vTBiVTgOagZPuJ5An5oWWcmCKvtxV3V7sCtgdlw64juBYGVbNjWSv6zfZVq3sWNmu30mFk4mWRCKAfpUcgyOX5I+tsw== 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=U13fFXEM07lJGuyTMo7PvjJrJ/WZmstRJ6eJu+3aEtM=; b=FgCKTHbWGKZGhS8FmYH/J6mzs9x08hzI1RoNGPc/PNsIvE1I5hHwLQlSBMitjBXm7x3o5VfLcbmIVyGQ+lWwRbdttE6PoZGsfMvpG4EGFR0u1XGTFznZIqmdd1gvaWXyGQFLMYdLpMbq+esV1pnUwO5a5mZn2h44qsnFRaH4zXtsR2J1Ms4FZNVLZQAaCATB1QRZLGE0sLh9lsoSpW4oCu/6KzfoyypwXgOPcYxdOoM6OJFQqGvZnm3NO77QyzGD5NDjDZB1eEutf5BJYnzYRjgNguo0Isl9QtzM6OgkHpcD2bOmzyliglPdp/odekV8/W3GHh0OZ53T088LA9d/OQ== 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=U13fFXEM07lJGuyTMo7PvjJrJ/WZmstRJ6eJu+3aEtM=; b=PIYhXMxUBfwsKa8vT5tEzrX0bRHT3AC82jPLxNuL4MB2f4u2OaV26xNBSt/6FlFGizuPPyDO10ULmYsyKJsenQ3R9Asj21vl1ExxkxQcc/cP/gKoAWeu3R0qZXp5RoXm2H58pt5IftvgTCzwklGkok97c8dpUWO57W01aUggFEw= Received: from DS7PR03CA0352.namprd03.prod.outlook.com (2603:10b6:8:55::32) by MN2PR12MB4317.namprd12.prod.outlook.com (2603:10b6:208:1d0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:04 +0000 Received: from DM6NAM11FT113.eop-nam11.prod.protection.outlook.com (2603:10b6:8:55:cafe::c2) by DS7PR03CA0352.outlook.office365.com (2603:10b6:8:55::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +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 DM6NAM11FT113.mail.protection.outlook.com (10.13.173.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:32:00 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 03/10] crypto: ccp: Add bootloader and TEE version offsets Date: Thu, 20 Apr 2023 11:31:31 -0500 Message-ID: <20230420163140.14940-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT113:EE_|MN2PR12MB4317:EE_ X-MS-Office365-Filtering-Correlation-Id: 7eeceb28-acab-4aea-0a90-08db41bcc694 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A1b2SOhOFPhiWaPPTqnkhZFM+b20jh8kyTRWr1erXbwEBHHsc4nYDoizSRUmxz1KeWgqVISyo9s9T2BnlZ/1B1Hd5yLn9nG4DihWYzVy4AGcr2bb3qIfFRnQdKncHBUvfOcGasFOGSuWRmAWOpIAO354G/8ww7X+YGIsa17kWHi1jupBJGL5/DNpTxpCT4Xe1VmQuzMwZOtAEt6I8e7ofilKaABqD0no4J3BAFMbpvyiAyTbGWiJfc/Mk2Pff73uCUlZ0917J+JHzbdVAqdCqih8Xy+hR2zE+zJl+0i2q/E4kBv/Wd5SFnVczyEMfhy8Gza5FdgLzWGSXBQoW+MY6llMLVkoJAfo2n4Dym5hk8a2Fz0CbPqjej3qgwk8Kb42dPbpKe31nr9iA0dABMjNKbeDIstb76Euh/d4PVd/c8QFSxzy63qcBymfh4aQIV5Ho41JnEm3jCorv6TvCLnmP99Sj/0liP34c393ZuFNDfqMwEKRFhIpmAPaVk0TwBjr/fhZQLTctcezwsWqNVkWv0B1522atnDmiU/FOyc+r9KYAgzT/n6bPifmE/JB7s1LxgcGRXYApoqZ1uG/bYkBB+KEhJvZvYhN+jIaKJgsEbgQ1jyAhikowDVF+TrW9Ir11LMYTq1VwhCKpvtKx8mHWdNx0fyzT/uYMEDug+2tVP3fstyzuowVE9H2RBB5Zsv1rgBQwSfar9W47hytxFLuY8ejS1KTbEnIFkv1O/qOP88= 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)(396003)(376002)(39860400002)(136003)(451199021)(40470700004)(46966006)(36840700001)(86362001)(186003)(16526019)(426003)(336012)(41300700001)(81166007)(356005)(1076003)(82740400003)(316002)(40480700001)(4326008)(26005)(6666004)(7696005)(83380400001)(47076005)(82310400005)(36860700001)(2616005)(478600001)(36756003)(40460700003)(110136005)(8676002)(8936002)(5660300002)(70586007)(70206006)(2906002)(6636002)(54906003)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:04.3523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7eeceb28-acab-4aea-0a90-08db41bcc694 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: DM6NAM11FT113.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4317 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. Signed-off-by: Mario Limonciello --- 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 4d729aa1b260..460f3ee12fb6 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -417,6 +417,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 platform_access_vdata pa_v1 = { @@ -429,6 +430,7 @@ static const struct platform_access_vdata pa_v1 = { 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 */ @@ -436,6 +438,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 */ @@ -444,6 +447,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 */ @@ -452,6 +456,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 Thu Apr 20 16:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675966 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 AE838C77B76 for ; Thu, 20 Apr 2023 16:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233569AbjDTQcJ (ORCPT ); Thu, 20 Apr 2023 12:32:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbjDTQcI (ORCPT ); Thu, 20 Apr 2023 12:32:08 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D418A3; Thu, 20 Apr 2023 09:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VBKfCzlENg/md0N29FDW804u2yGMhWLAotd6pyQDcN6i9eHz9ztNNG9M1LMl94P6DvAXMD0AsjDVNnFxS82OZWqXsVHgif2k5PPko7RFxhWmE7CLXuPgjjF0Cowf6OHZphvCLrCUEb34VAYvD2L5YWnRwx4/bQyF6Gonj/RdPala6xYLvV+/Qxmb1I58gOhNpzeB2XxdTBKxGoyxb5/nXLTo1ngK5sOl7qE8rYMQaHrxhgzm2VpvqDw176PRJAkr+4bqAaaSyNTsFt0mmomK4Xfzx1QMH/jLJdWASjofqz8snI9lYFeX8lgWVM6acvrxXxz8BT8jmlF4q/vNDpopnw== 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=uCK3UFN7kfeIWQFj87Ev9Xsr6tgtpWCv/5cTFSUBohk=; b=VBQGXmOZim+qpg7h1ceoIJjFLQ62sIX1a7r+970pWtCQE01s0OXL1VVkDDAQuULglAoJZb4nZIJ92LZsBfQ0T/ycCtHY7kUtzULm8oFsV9xBELjP8Yvle8rf41bFpwBYDXqBwOVXbI68hUmc9m0lQHngwnl8ele47ZKcFocgOvpGw/v21wXiw7VMayEjOywHeAhmN/vxA3w0fb/PJzvYaLhNdLRfobrlbqxjy5ExpoyShDCRJewYVrknOQ01wuCleQUUH3Sp06/AeAjYLDjPR1aZriYFhC9NZucnWGlXqXEyjTJDjLBR57icu2g8G9YooaTjX2sN3gxa3YCIdwHFrA== 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=uCK3UFN7kfeIWQFj87Ev9Xsr6tgtpWCv/5cTFSUBohk=; b=IMt9MAyo4rgaX7w73ZWHSNnw/geSKkWtjzBTdirvbTOav2wNkYcg10hBrN3puD8FgJjxcwt4WA3C5mHa7l8JoiyT6HSti2jxfoSV642uSQPYp8EWGwgzBQgsNFmwBsrT6SXZqc9J7GmnVUQ4fzDt0DBaS4zUwx4sSTtbusv9fW8= Received: from DM6PR07CA0104.namprd07.prod.outlook.com (2603:10b6:5:330::30) by PH0PR12MB8821.namprd12.prod.outlook.com (2603:10b6:510:28d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:04 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::d2) by DM6PR07CA0104.outlook.office365.com (2603:10b6:5:330::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +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 DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:04 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:32:01 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 04/10] crypto: ccp: move setting PSP master to earlier in the init Date: Thu, 20 Apr 2023 11:31:32 -0500 Message-ID: <20230420163140.14940-5-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT027:EE_|PH0PR12MB8821:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a47368a-4877-46a4-4dbf-08db41bcc6a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jX6McMOvfkHF83uHpdyl0wE8ztJyJ6OrG/VcUSauMe0G0YrdFvmHY0kZM9kian7ok/koLGrWni24ndjUucURECGpmRiSoflPM6IHBEVUKt8y3yrhU7qGIKW4s4ZU26hwTgk7TQC3Hk75cB1kjFP09LkRX5uk6aXEJoiinM3sZDuUmX6vl6CLdNXRCeLloG6DhGDKH1kKbK10Qp3rBtiEn+l6cc/pH/R1d/1UgZi5CEv7tgvYlhhqfWo9X1ga1FLIVjl4VMD7XpgBnvwm3PorNYf/JUz6qit1FAqX3x1Wn140mZ2YnkV6HLod5H6yeiLvAtM6VRz4xqikUGGqz5N04ew9LnISratO18gUN0DggeBsmhWYKF58tE3T27JNiLAou3c+iMvRmRXzSqOnu3sMRDFirlX2CTtHZ4jEsK+vhhqkDA4AYqVys4TOI3nPkirj9fUuz7awSGFYR+TdVvX3aPq1GuSX18H1cbNwRenmgX4d1fHU0uT58/ma+2IzMCYAcjnSU/GvlSajmMD+IHBaAS28TTbL5PgyqFAm68xh6VLOOFjkfqfHN388GfKo9qdCOl4bMek714inSbsPwwRfCwwSkZ58GVoL3akqaShkIEaq7ZEWF2/PF4CD8YBP50F4Wu4spxDxb1GK6s9WLwUH3mC3YzpSUoP1fs4RnEgJjLF7bZXVdmrFi9U4Av7hIyXzWehEBKc6Z79WchxCeTLs3DzJZzOcYAowL7l5RsgxIjo= 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)(136003)(39860400002)(396003)(451199021)(46966006)(36840700001)(40470700004)(7696005)(356005)(6666004)(478600001)(54906003)(6636002)(426003)(336012)(82310400005)(26005)(186003)(1076003)(110136005)(4744005)(44832011)(5660300002)(2906002)(70586007)(70206006)(41300700001)(16526019)(4326008)(8936002)(8676002)(2616005)(40480700001)(36756003)(40460700003)(86362001)(36860700001)(47076005)(316002)(81166007)(83380400001)(82740400003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:04.4917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a47368a-4877-46a4-4dbf-08db41bcc6a9 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: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8821 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. Signed-off-by: Mario Limonciello --- drivers/crypto/ccp/psp-dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index e3d6955d3265..e9136e398174 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); From patchwork Thu Apr 20 16:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675964 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 87BD8C77B7C for ; Thu, 20 Apr 2023 16:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233092AbjDTQcV (ORCPT ); Thu, 20 Apr 2023 12:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234286AbjDTQcM (ORCPT ); Thu, 20 Apr 2023 12:32:12 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2060.outbound.protection.outlook.com [40.107.100.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1BF8E77; Thu, 20 Apr 2023 09:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U2tWb6jzrIhkOsW6jX9+/Kl21piAGOq5WvFitKJOmxf9QI6W7TV25AUs1TyguUY0REBlFyTWZlsmt+MRDmSeEUpl0nyl23vsRjKXKIUnWMg3s+Qi/V4imjEtRdAyCi+3c7PdNCvWFGGy+QtdzbNu0aTrs5Ar5sI0GR8FvSxlingo+05RaKjJJ7/PiOqyCTGC6D/JNfeFuT+r50nABvD+0TmMxwHnB9WsVQ8Yjr4NESX0epX/hiBRYZjs2vBDGwC7YJsG2tNyFPSY3ujgaV3NPnq13NjqJKACg8Ae5RK/f0QvUkZ7qiPrmS8ToU9x9ZSV8vu24ECF1ABhqvyF+nUafA== 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=txvBajt/5EvVuThow0jZ0mElcV+mRhSy/U+22CFaFCA=; b=nTH9Bj08pZZAwYnpo3+AJ1JdsMlOjs/jA2FtVmAlN4O9QIhi8rIf8KbZ3e28YjeK0w8cfzxe3oay2KHsT7nE+XQpshw3++Ws4aNVQueW4kCc/VwIRV8fzFGLK8uCK9lxON+QRvgw9WUrPGAWKzww0QTg9lMV1uc5KfVn31ql7CrVxXBzsAUDTKgqBgNetUsl/eJFdLXK+HHnMSgoUpEAeLLF7fzGnCizlDLgOnwMR5lTTz8ao+IIbWkmqtciXBlwCNXegOUWGF2ijPt8gjPX1Yrc26XUG9+qQFNoBs4+RBBB+TvBly41zp9oN33DA47N2RSBNGYYl+TVwRLxT49NhQ== 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=txvBajt/5EvVuThow0jZ0mElcV+mRhSy/U+22CFaFCA=; b=I+uEJV6BhumlJGxGBEIyEtWbN0LZOnHsHGsvvtZwU9TjXXre7PotYvPtKLPp3gi1lVhft6ItJtDd8WTMzl8VHYJuI4zaUptyhGSbeLl0KZRf+5636vw3zvz3DY7lr7kArPLeLLA2Ot88WNzHQ7/qdrgeA0MTBlse1YYb/VBb7GU= Received: from DM6PR07CA0110.namprd07.prod.outlook.com (2603:10b6:5:330::26) by DM8PR12MB5461.namprd12.prod.outlook.com (2603:10b6:8:3a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:05 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::7b) by DM6PR07CA0110.outlook.office365.com (2603:10b6:5:330::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:05 +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 DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 16:32:05 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:32:04 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 05/10] crypto: ccp: Add support for fetching a nonce for dynamic boost control Date: Thu, 20 Apr 2023 11:31:33 -0500 Message-ID: <20230420163140.14940-6-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT027:EE_|DM8PR12MB5461:EE_ X-MS-Office365-Filtering-Correlation-Id: 1061e206-a3e7-4471-f849-08db41bcc716 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mj98IwE3Ma84hY/Y9ZrftsdfU0+uvprFnRVOf3Vl6mrbWZWhCWsW1g+cJkIf+gPrB13Pa3Pi4PmVqzrudqho8Czwwruiwj655jLn7I9INoCUi3+EAj3fWrIv5u6mbdFccoV3ZlFcesdiJYdSlwyiHWwxFs7L+ucoDF3VYx5P6g4XbBp5xBDNB4Lm8Z6Dvxr0xvZlvj6tnemmxUmIIDlEMj/CQ1QqPM2du//S5pI3bK6NKfbFccuIPjCL9Be1efDObNGBKhGsBLUkFvPrRk+waRqJnNDG5/FGfNcovT/DtQuULYaEA64/X1HrWbZB10KKsjBWQANFGq8EuC8SlAUdqTHhjST3J1Mu/CK6BJLW8nH93LBKEz7ho46Q1n408u1Mxx3oxXo/8QYWEePvKw5+ytuOgY3J5GfzwAP3EW0Uo+Hu3mRbidtqvSpu6T9cAlQX2nnE0vjjHw+KU6ngwl+XPvkrCvs/EhV5vT5LGNN9SHz4oC1o74g9WTRFLnmNXobdx2oDEO1KH49ExSVk0K9xDREw/7whSjcrEis22xJr0DHPTzKkRfjSkyqPdBtbb6B34oVkOAcCStj9draYTOejesplhuNm9yZmQiijvrJPMKMwBOnKEijdHmkBytpJYn6Xa2LRc+DTTl0GkxeQ+YHZ5bJ5yH/3j1W7MRis3f5I4fQeTFkvUDTZaT+vwNwasDwNghUL8DqeS/YNKXFYvlxl4TnyyqtAYkrCxJw2GE67K+Q= 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)(396003)(39860400002)(376002)(451199021)(40470700004)(46966006)(36840700001)(6636002)(54906003)(47076005)(83380400001)(478600001)(36860700001)(2616005)(7696005)(40480700001)(1076003)(26005)(6666004)(316002)(4326008)(356005)(110136005)(186003)(336012)(426003)(70206006)(82740400003)(70586007)(16526019)(44832011)(5660300002)(8936002)(2906002)(30864003)(8676002)(66899021)(40460700003)(81166007)(41300700001)(86362001)(82310400005)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:05.2104 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1061e206-a3e7-4471-f849-08db41bcc716 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: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5461 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. Signed-off-by: Mario Limonciello --- 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 f6196495e862..aa0ba2d17e1e 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 000000000000..7afeca903136 --- /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; +} + +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 000000000000..1c3a0a078d15 --- /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 e9136e398174..15cc7bfe663d 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) @@ -214,6 +221,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 505e4bdeaca8..8a4de69399c5 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 76c32ee6bd65..2329ad524b49 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 460f3ee12fb6..595c8e395f29 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -451,6 +451,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 75da8f5f7ad8..53b4a1df5180 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 000000000000..d032f78934e2 --- /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 Thu Apr 20 16:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675684 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 7666EC77B76 for ; Thu, 20 Apr 2023 16:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbjDTQcW (ORCPT ); Thu, 20 Apr 2023 12:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234580AbjDTQcR (ORCPT ); Thu, 20 Apr 2023 12:32:17 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2089.outbound.protection.outlook.com [40.107.96.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FD491711; Thu, 20 Apr 2023 09:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kih4XmTveQjRZXe3GTqoZ7vJOtrfXKkEFIU1L9fVNfNGRNfwaBVPSztkAKXgKy82sJfH9+IYl3gQjOQfy10jEx+h59ob0b/MoeAputLtggnygsr2dAY6eCTt4ci8Hdr87kfmYkwPYBmDp6vYbTn/Bzi9IWYHaYBfjhX+cOvjPwdSG+aD3PrudBOjDqQQVCRSFA5MaTxySCn2iK12Wryw5U6T+R9vOSH2cHAMQrUg/ZjPr377ISgbXPs0EYzkhyCwZD1aZGYxdlBGMTVkdAxFFm7e9Z3B+aOTKM/Ywod/RlYpaFSoERfcGhDWeT5dxfEloRrp3G55CeWA6ArAe4eJxg== 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=/AxmwsspBY+a02inqk/oy2ghT7n4ZQQaI56gq4KLeQM=; b=DGuMH1Ryvto9z9k9IGX91Mpsum433NVt2UDPPALJoCSZUabNodCAfV0HderaA7GlCGlTORhNoyGcbYIGL+NlFWud27L4X4A5oFSoWKsHPD2MmPf2LIJ5sOBvlhH+CCtaXhwjoy6EjbTIRRhYL4OtcOotqCnJ5f5jZeHCwg4E6/rKlpRSPPvyg0GPYnjGhVppC3mZX95wHWzw/7rx9k7+9Fs1JTHS3r6D0lRD6hJ+w5hOgRDf0x2on5WoQwWtaut8Bbz82NhnHsIooHSgIZQz02W+M2LnNyQvaAySM9iSkt47c3MZcLIqfhRffxl3GGEjBM93pphgCdpHUmcjIjMQsA== 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=/AxmwsspBY+a02inqk/oy2ghT7n4ZQQaI56gq4KLeQM=; b=h7V9aiF7EF7war79wg0aX8nHQjxj6Hz8WOTEfu/Mc02icp4liSaBDmtTIXSbCJd0WiWHefpy/Pl757qESaFPAm9T3xrN2w+QvhydpL01t9xiHvNg1B9st+oc7XOza5g+nHe+tl3IZIDfm7iFNhN+pkBgkXG64m9MlZkEqkPDBNQ= Received: from DS7PR05CA0074.namprd05.prod.outlook.com (2603:10b6:8:57::22) by MN2PR12MB4189.namprd12.prod.outlook.com (2603:10b6:208:1d8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:08 +0000 Received: from DM6NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:8:57:cafe::28) by DS7PR05CA0074.outlook.office365.com (2603:10b6:8:57::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.11 via Frontend Transport; Thu, 20 Apr 2023 16:32:06 +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 DM6NAM11FT016.mail.protection.outlook.com (10.13.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.26 via Frontend Transport; Thu, 20 Apr 2023 16:32:06 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:32:05 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 06/10] crypto: ccp: Add support for setting user ID for dynamic boost control Date: Thu, 20 Apr 2023 11:31:34 -0500 Message-ID: <20230420163140.14940-7-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT016:EE_|MN2PR12MB4189:EE_ X-MS-Office365-Filtering-Correlation-Id: 1985492f-a8e6-4a81-ef99-08db41bcc7f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OBfuZLkIge9ouGWLWuL1ACXaXFG95EPa5fLdZTZsTaMt2QnyaJVVdE3vPjvPydeZNgCfhFVnefX4fammxrm2oGBKZbAArbht7W18kgCxxetfD4jpMdYOVFhiPHk08pdo5jzOtNJq16ga0FMC5h0JZw6y08KoTODRlPm0QPJK+2l9cHpNKYKw030ennoTZHITHo8apzXYULJe0OTFiHgxf5IAHPKF6FT7nIHlz3GAtC9lNoSQIQwrOrJYLicaA6Ps14IM6zCEvTMHH297TD550IvlsJie+xiHkUIGNEIIEjlBhoWBW3T38bE7aifbvyNJxqjONf7TNoEpgWaNQKdoXFO7zV3XkBratakYfAI4/hwNdBdNbVoUVZFmER3kpuMmCvizwbNnbg/Nayf/lmoNgYo5qKbavBflaUvfsIt6ek4zKfxAw07eihLsXQEidYn9+YI98bHFwRCNVAMQkrszvBvhXRtrm23DqVhPGbPOmPNflTV+4BH+UkwH2zY4+UgR+w8Tr0jFNp746EIhmPLn3U9yY/ZG+x0BMzQIbLeVXbILUh6L87AZ/5SpICW6skDP3dqbekGN2D9V/TektZ+tYbuEBHaJv1D3UPz9eNDJdjxmGM1b6v2uDL8qkVCLr+dBpmBPqpGCyLvGGBhvd5y8zHhvXHWEwmJrZqZ7CiYP/4XXjTa2z4F8H8VkrAvK57G4BqaUvWauMGjLSwm08rYhVj3ysozG8M7IZIh0piDaduk= 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)(396003)(376002)(346002)(136003)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(2906002)(41300700001)(5660300002)(8676002)(70586007)(70206006)(4326008)(316002)(110136005)(8936002)(44832011)(54906003)(6636002)(478600001)(7696005)(40460700003)(356005)(6666004)(40480700001)(26005)(1076003)(426003)(47076005)(83380400001)(2616005)(336012)(36860700001)(82740400003)(82310400005)(36756003)(16526019)(186003)(86362001)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:06.6847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1985492f-a8e6-4a81-ef99-08db41bcc7f7 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: DM6NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4189 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 it's future communications. Add support for another IOCTL call to let userspace software set this up. Signed-off-by: Mario Limonciello --- 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 7afeca903136..ca7ec528536b 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 1c3a0a078d15..156435100076 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 53b4a1df5180..18b9e0f0cb03 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 d032f78934e2..7443c78ede19 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 Thu Apr 20 16:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 675683 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 820DFC77B72 for ; Thu, 20 Apr 2023 16:32:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233899AbjDTQcc (ORCPT ); Thu, 20 Apr 2023 12:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbjDTQcU (ORCPT ); Thu, 20 Apr 2023 12:32:20 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2059.outbound.protection.outlook.com [40.107.93.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F4059210B; Thu, 20 Apr 2023 09:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oe8Be30s8/LjXuBcWqG7fN+14fSheNoJdt2L9+bBD7zJSRwfvQ7sQGxAMrzOuFB4iMqjd2APHMtGzmLTNOUgIqmHziZDcOkEB6rmwc2VoYckeRIdLd5aLL8TaWhFPOYQXcb2tXKxXUdveYrCQtHxQkh7hBUoqsXVEbwSMjKv9xTXn5MaVeoxnzaZ7LBggw58ZXXGFWJKk2qUHAVF7B5UqRUCRQRZz3pM5ydaC4fcJ2JeFxRVS7nzOm7dNaz0q9fCyeJfWp4dL4PbfxJP4pfxNHlKBrX9w3j/U0PVC0OtKL1tlulBs8zaQ+7zKTpQN+DBDDdzQYefd3v1A0YKJ9IvEg== 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=aS8JSioac+K5cQTdnoc+oQ3hySJkWDuNq/W398kLq/w=; b=W43JVBBzk7dQk74QSo9XHamyTWbFvcQRWfjav+ubm7vv/KW/OwNV5Iga4oFbs90U2LrB+rGuOHQut1N2YCwvQ0dL1p5yMuX9pqNjGICN39TTnNbBGoZEs5zxKn1XfE59LTI1bUpXtnQ6qWRVXz8Gc+cId9FLhU8fKTGqR3fOUFX8TEex6X4SpOYaY64dVXLkfu9MksG2niatiuyw0uxt4X6eW/JG7FvPIIISdC4K4kpsr9Ql0Mw1qZFk3PZ1VTd1abbhrfCcKrwfZbME/CUBh6DyHJSVEfZqve78L1VT7hdLYIEpSqxjlelgXiAgQv+njEHbVcyl+hiYFw7phaSFxA== 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=aS8JSioac+K5cQTdnoc+oQ3hySJkWDuNq/W398kLq/w=; b=44kW31epMaf1vAggFsU7k+MmE5yK3fvhSe1lqVsFVeZZ6o+EbKiL03YN+bBZVgojMMngAnkbvToKBzgT6QB2Y1cicBjbO+Od4A41q2Y6koOQVMYVZ+Y4oLSlOPoUdWaO8vydigCOfzL3hBAZNzfBVoJsez8HItn/HKTcTOninGI= Received: from DS7P222CA0003.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::19) by IA0PR12MB8747.namprd12.prod.outlook.com (2603:10b6:208:48b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 16:32:09 +0000 Received: from DM6NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::55) by DS7P222CA0003.outlook.office365.com (2603:10b6:8:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.24 via Frontend Transport; Thu, 20 Apr 2023 16:32:09 +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 DM6NAM11FT044.mail.protection.outlook.com (10.13.173.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.23 via Frontend Transport; Thu, 20 Apr 2023 16:32:08 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 20 Apr 2023 11:32:07 -0500 From: Mario Limonciello To: Herbert Xu , Tom Lendacky , John Allen CC: "David S . Miller" , Mario Limonciello , , Subject: [PATCH 07/10] crypto: ccp: Add support for getting and setting DBC parameters Date: Thu, 20 Apr 2023 11:31:35 -0500 Message-ID: <20230420163140.14940-8-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230420163140.14940-1-mario.limonciello@amd.com> References: <20230420163140.14940-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: DM6NAM11FT044:EE_|IA0PR12MB8747:EE_ X-MS-Office365-Filtering-Correlation-Id: d08542e4-88e1-4a20-d4aa-08db41bcc8e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dNEai4bTp0iPBLp1xtXnHx6Z3t1XmCoxWpp5eBmoY5cZh3DfiT7iQ6RICsDpvw+Oq57WJdGqOzgLYjHJsfflWBTlyZZkIz6XkJXOg2cdYL8ur2BeVECQgHDhvaDKY652Hwcv8BN/6eSrzHW9R82aKdJcI/BWN579oFs7eDX8CZs45IBfXC/jCOHelotb6+MtzSAOd0cZoBpLN59uEsYHiYgwyWgruolTfySo8wZEODJqTNgu4wy120q7KOskJS3YmBs0Jz1/CosrLnWDufDE+uzIaPIVOaxcrLVT6w4Mjiuk5oGz33ZRemF4SI5+gfGG245JsHcFgFNatW4+q/3mN6QcnCPE40uPwia0OT/2IzXeHOBu3sqd57zCOlMBCjb84p5m+xFjby88E8jx2TRfo4YjbpkWt6R2w6gHoCxMssQtp4kd/12mn7iNbbBUX6AtgsUR1jAkB2Rp+IQEWH0m6eHIQ9fnAq7CfKBXgo2I1Z/vyZudEwukxVTblTSllNSIdNKHAokqoB+aGYAcIgs6uPUYo1yWIfLe2wmgnMbO+pC5doqZ+46DH/VWoaHbF3pD4yG7M2V5NCYfa6aB+deKqcChqJWuUGXaXGNNZvPXCIIwmR/VXfa49FWR4LEvim6quZFkgmkdCoDPsMqRnncGM8hTt1L9ArGeeBxsK3iGpj92GMqr3PHBlTUx79VQ/GMUniYxTZhqKx1J8Rkt66KNBE+1dT9NMy4xmDVx3EBKCks= 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)(396003)(376002)(136003)(451199021)(36840700001)(40470700004)(46966006)(40460700003)(36756003)(44832011)(2906002)(41300700001)(8936002)(8676002)(5660300002)(316002)(40480700001)(86362001)(70206006)(70586007)(82310400005)(356005)(81166007)(82740400003)(4326008)(83380400001)(47076005)(36860700001)(336012)(426003)(2616005)(1076003)(186003)(6636002)(110136005)(26005)(54906003)(7696005)(478600001)(16526019)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 16:32:08.2438 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d08542e4-88e1-4a20-d4aa-08db41bcc8e5 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: DM6NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8747 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. Signed-off-by: Mario Limonciello --- 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 ca7ec528536b..89976d6b9109 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 156435100076..e963099ca38e 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 18b9e0f0cb03..c1dc87fc536b 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 7443c78ede19..b3845a9ff5fd 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__ */