Message ID | 20230228024439.27156-1-mario.limonciello@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2774503wrd; Mon, 27 Feb 2023 18:54:20 -0800 (PST) X-Google-Smtp-Source: AK7set8hGUrgsVauW47C5lNeVL4FRQ+DrB7iXX2SuDtN1jaL6alBn5B5JdUOpOUJnRAmXQDVmHTk X-Received: by 2002:a17:906:cf90:b0:8b1:811e:cd30 with SMTP id um16-20020a170906cf9000b008b1811ecd30mr923823ejb.22.1677552860427; Mon, 27 Feb 2023 18:54:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677552860; cv=pass; d=google.com; s=arc-20160816; b=C0Xvi6KqYs4m88wsVE5KEmM2kDKhPge1QMhwMUXZK9gwD0SR2rG+9cR8CvoIkDZ+gH yjOPMmvWCBhdJt81ltByZN8Ftoy/GiUKzLIPs+G/A/mXGfE5o1T3tz46z0o8jneKluwL 3swwT+0ns8C0wgVlxCZVyu5KUJ9Oc3xSsqz87kNORACpDYQrhQ0OgbIhXXQgO+8TngEQ g6IrEzteotO0j5djslbUfQZ1tmwfvtl9G1X5//BeAqsdl+yT28iQSGnWjJWe6anuI2Di 5YSyfr8T7v03vhPJgqmsK3oo4grFmV2RB5bDJcGcDymO+p9AUc8nrrnh4/SmuQtQu3Ua 1ThA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kMuqSUFpwCCh68Vv8mNo2yUfJpXu45dnqhCaoPih7hE=; b=MSenIgWxd7eXPj8NF7N2keTyowAqbK4qC8X7dmuoD0wxRO6Vx5n5DYRRTkGLZD3V+V UCM1cjS/hAV+jACcZcNNy8VEfwgHgJe+Zf1LWTKN8pfidtAueT5LTQ3wyfkyCOTBEC3+ A2pOgmCnxbbFPfpph+rcnEz5rI7m1YmVj7BXL7QmdghmiYgDiWwO/vnda17swO2jfGk3 9KF0s7M5O0BxlvWs03GV4r8xE56V1p+oqqLIiflVDp4Wblc6HwgrjwWB2g34Zgm6Ngbl FS9XFQ8OH/zuS9YAWD6r4cnfBKtl8Wzogwj+9KSGcjssLtRhH4G4oJhGMDqv5SUhLBDQ zhgg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pZuAAAM7; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a170906144600b008deaca3a01csi9928153ejc.221.2023.02.27.18.53.58; Mon, 27 Feb 2023 18:54:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pZuAAAM7; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjB1Co6 (ORCPT <rfc822;liqunnana@gmail.com> + 99 others); Mon, 27 Feb 2023 21:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjB1Co5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 27 Feb 2023 21:44:57 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2054.outbound.protection.outlook.com [40.107.101.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBEA61167F; Mon, 27 Feb 2023 18:44:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DT/dxPnA26eyKVvII5UvbghL4CgAoa1fptTBmD6Pl1fhFmbVF0efq19XVcsHD4gwfugiazM/cSqDLWEKYWjSTbtIfFEG5kgqjI4gi1zJVF7Y/BSB20eCm+b4Wnx0kP07wVO/Fr8gahGmahClK3IoO1aUQFUNvrpItm95PUzLv1C1CN93KSmY6jwjVBtN/IILP25PgUMqpT4uzO+Z8JU5kR3Q+arwWgb3ymZZ7Oc12RHdh8b0AyJg3lRgHkAjTVrkaY/s1CnY9RaaMu2WnJXGFhnyaCAi2D5Z6Gw9w6Sahjo9ulKkgfos2JiHFZwl/pdSbXQ/hGiPHyNsz3pFAIcRkg== 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=kMuqSUFpwCCh68Vv8mNo2yUfJpXu45dnqhCaoPih7hE=; b=TFQ5zQ8d3hP5EijpLILXXGl3dTrOK42e4aegaRvz+qyxVkY6ekB6jwtyDEpY+bIb3VNMepw/XX+jPlfvX1arE7QJ4xhCaMNghEo+J0mei/TcxlT6veTH2HFfqTVMEd+a4Tg0BOMu2/OeidN4DFbqxPS7z5USnfUyZL5NioOpibs/98HP5WbmdT6r2ogFjYBV8EN97mridQ0alhzTw0qESo/9M8Ll1QrLLkILp807KHNNhHWuuKiD8HQDaFHiQbZzoyqH4PyLtP+MMEVfeGn68zh1fimTdgzAVzv7zgKeY3DB7EFZIqcf7eAV1BGA+CqQHsCOnuv4DJSVuKq1A7qryg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gmx.de 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=kMuqSUFpwCCh68Vv8mNo2yUfJpXu45dnqhCaoPih7hE=; b=pZuAAAM7X1Da6OZZ5x4OPzwhI/MnGoRHLSiCVOEwkHVW7txTshH8aQjnOxpAAc/z4XHeYirfxj4zAl8r56A6I0mntJyjfeTT+g62bpYcvYcLdkHaeMdcGxuDn6Y1D/7CpaQzA710wvlygt9yDH7ZPPRxFvyUZv1hdZvqI4zNQXk= Received: from BN0PR04CA0170.namprd04.prod.outlook.com (2603:10b6:408:eb::25) by MW3PR12MB4346.namprd12.prod.outlook.com (2603:10b6:303:58::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.26; Tue, 28 Feb 2023 02:44:52 +0000 Received: from BN8NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:408:eb:cafe::1d) by BN0PR04CA0170.outlook.office365.com (2603:10b6:408:eb::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29 via Frontend Transport; Tue, 28 Feb 2023 02:44:52 +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 BN8NAM11FT035.mail.protection.outlook.com (10.13.177.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.17 via Frontend Transport; Tue, 28 Feb 2023 02:44:51 +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; Mon, 27 Feb 2023 20:44:50 -0600 From: Mario Limonciello <mario.limonciello@amd.com> To: Peter Huewe <peterhuewe@gmx.de>, Jarkko Sakkinen <jarkko@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>, Dominik Brodowski <linux@dominikbrodowski.net>, Herbert Xu <herbert@gondor.apana.org.au> CC: Mario Limonciello <mario.limonciello@amd.com>, <stable@vger.kernel.org>, Thorsten Leemhuis <regressions@leemhuis.info>, James Bottomley <James.Bottomley@hansenpartnership.com>, <reach622@mailcuk.com>, Bell <1138267643@qq.com>, "Jason A . Donenfeld" <Jason@zx2c4.com>, <linux-integrity@vger.kernel.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v3] tpm: disable hwrng for fTPM on some AMD designs Date: Mon, 27 Feb 2023 20:44:39 -0600 Message-ID: <20230228024439.27156-1-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT035:EE_|MW3PR12MB4346:EE_ X-MS-Office365-Filtering-Correlation-Id: 91b5ea4e-9528-4774-02bb-08db1935c437 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: luXoMr2yoDbXgNNGxl98mn49bpudG9ScOppez/7spEotKj73fzzlKTs/bG32BAcRshQ3glrvl3POoQ8qnXUHX7sOIVOiSSAquSv09eu13xsU1HyI0QCAbQJLxK8Fd3bh7fU3JmytI7hvOCOll3vI2TtQJ4AOtpg+fVBtf/UAPcMZ//ZKnXl6CqN2HJ8jf7sBEX2YOg9mHUFAJXfNuo6EfgtygYqlyiEKfNKrNAycuGj+IEtIFGiOKqao2GItHltMsp43vjmHIpaeJBJ+++b5NzPX8X40MSVG8lqVHVpzNfMd1Ca0Ucvl2F6OAFyehzuQAndkj6T9bTEXpOVf1MJcYvI9Di1Ix6SaQ5aFuWMdV6x7A2T754eu4C2os9yK56ip3NQNjc9W9lXkRDVm5QN1p/KmcUwCR0pc+DTAKw5e8ZbmDHtDCw6a9IT8NzINPDw30hC4Mb/2k5gjAqeViLqaFx0KMzDFGE2cbxShGx8f3bnAzP3IQ7uEDlb1Ehh8fOvm21VBkjlsZipz50dKtt1x9ym00xCOfnwAObhhzbgYoa+X1f3MupUE9+hpdOvblTUF97LDyQBY2HioXBSyUdcnethxu0Kbvgihm2tlOmT7BhMQKAZ+XZUOBsDCSEc0ae8P9IFks9RPbn0g2DpO/BQk4bb8SDsJTsM1kh/nq9Hd2t5NkCyhPszaG5D2mz/tjd9ZWzCazJS75hAHMZJJTjFx7qVhk/Q2E9PeNq5ZAfyfvupYufzEpldIsKcDT339PdL4ZiHnSWnZP9ZFdFyic4X12g== 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:(13230025)(4636009)(346002)(396003)(136003)(376002)(39860400002)(451199018)(46966006)(36840700001)(40470700004)(82310400005)(110136005)(86362001)(36756003)(54906003)(966005)(186003)(40460700003)(5660300002)(16526019)(41300700001)(2906002)(44832011)(36860700001)(8936002)(6666004)(4326008)(8676002)(1076003)(70206006)(70586007)(2616005)(47076005)(478600001)(7416002)(26005)(40480700001)(7696005)(426003)(336012)(356005)(82740400003)(316002)(83380400001)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2023 02:44:51.8489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91b5ea4e-9528-4774-02bb-08db1935c437 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: BN8NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4346 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759041668043894943?= X-GMAIL-MSGID: =?utf-8?q?1759041668043894943?= |
Series |
[v3] tpm: disable hwrng for fTPM on some AMD designs
|
|
Commit Message
Mario Limonciello
Feb. 28, 2023, 2:44 a.m. UTC
AMD has issued an advisory indicating that having fTPM enabled in BIOS can cause "stuttering" in the OS. This issue has been fixed in newer versions of the fTPM firmware, but it's up to system designers to decide whether to distribute it. This issue has existed for a while, but is more prevalent starting with kernel 6.1 because commit b006c439d58db ("hwrng: core - start hwrng kthread also for untrusted sources") started to use the fTPM for hwrng by default. However, all uses of /dev/hwrng result in unacceptable stuttering. So, simply disable registration of the defective hwrng when detecting these faulty fTPM versions. As this is caused by faulty firmware, it is plausible that such a problem could also be reproduced by other TPM interactions, but this hasn't been shown by any user's testing or reports. It is hypothesized to be triggered more frequently by the use of the RNG because userspace software will fetch random numbers regularly. Intentionally continue to register other TPM functionality so that users that rely upon PCR measurements or any storage of data will still have access to it. If it's found later that another TPM functionality is exacerbating this problem a module parameter it can be turned off entirely and a module parameter can be introduced to allow users who rely upon fTPM functionality to turn it on even though this problem is present. Link: https://www.amd.com/en/support/kb/faq/pa-410 Link: https://bugzilla.kernel.org/show_bug.cgi?id=216989 Link: https://lore.kernel.org/all/20230209153120.261904-1-Jason@zx2c4.com/ Fixes: b006c439d58d ("hwrng: core - start hwrng kthread also for untrusted sources") Cc: stable@vger.kernel.org Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Thorsten Leemhuis <regressions@leemhuis.info> Cc: James Bottomley <James.Bottomley@hansenpartnership.com> Tested-by: reach622@mailcuk.com Tested-by: Bell <1138267643@qq.com> Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v2->v3: * Revert extra curl braces back to behavior in v1 * Remove needless goto * Pick up 2 tested tags --- drivers/char/tpm/tpm-chip.c | 60 +++++++++++++++++++++++++++++- drivers/char/tpm/tpm.h | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-)
Comments
On Mon, Feb 27, 2023 at 08:44:39PM -0600, Mario Limonciello wrote: > AMD has issued an advisory indicating that having fTPM enabled in > BIOS can cause "stuttering" in the OS. This issue has been fixed > in newer versions of the fTPM firmware, but it's up to system > designers to decide whether to distribute it. > > This issue has existed for a while, but is more prevalent starting > with kernel 6.1 because commit b006c439d58db ("hwrng: core - start > hwrng kthread also for untrusted sources") started to use the fTPM > for hwrng by default. However, all uses of /dev/hwrng result in > unacceptable stuttering. > > So, simply disable registration of the defective hwrng when detecting > these faulty fTPM versions. As this is caused by faulty firmware, it > is plausible that such a problem could also be reproduced by other TPM > interactions, but this hasn't been shown by any user's testing or reports. > > It is hypothesized to be triggered more frequently by the use of the RNG > because userspace software will fetch random numbers regularly. > > Intentionally continue to register other TPM functionality so that users > that rely upon PCR measurements or any storage of data will still have > access to it. If it's found later that another TPM functionality is > exacerbating this problem a module parameter it can be turned off entirely > and a module parameter can be introduced to allow users who rely upon > fTPM functionality to turn it on even though this problem is present. > > Link: https://www.amd.com/en/support/kb/faq/pa-410 > Link: https://bugzilla.kernel.org/show_bug.cgi?id=216989 > Link: https://lore.kernel.org/all/20230209153120.261904-1-Jason@zx2c4.com/ > Fixes: b006c439d58d ("hwrng: core - start hwrng kthread also for untrusted sources") > Cc: stable@vger.kernel.org > Cc: Jarkko Sakkinen <jarkko@kernel.org> > Cc: Thorsten Leemhuis <regressions@leemhuis.info> > Cc: James Bottomley <James.Bottomley@hansenpartnership.com> > Tested-by: reach622@mailcuk.com > Tested-by: Bell <1138267643@qq.com> > Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> > --- > v2->v3: > * Revert extra curl braces back to behavior in v1 > * Remove needless goto > * Pick up 2 tested tags > --- > drivers/char/tpm/tpm-chip.c | 60 +++++++++++++++++++++++++++++- > drivers/char/tpm/tpm.h | 73 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 132 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index 741d8f3e8fb3..c467eeae9973 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -512,6 +512,63 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) > return 0; > } > > +/* > + * Some AMD fTPM versions may cause stutter > + * https://www.amd.com/en/support/kb/faq/pa-410 > + * > + * Fixes are available in two series of fTPM firmware: > + * 6.x.y.z series: 6.0.18.6 + > + * 3.x.y.z series: 3.57.y.5 + > + */ > +static bool tpm_amd_is_rng_defective(struct tpm_chip *chip) > +{ > + u32 val1, val2; > + u64 version; > + int ret; > + > + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) > + return false; > + > + ret = tpm_request_locality(chip); > + if (ret) > + return false; > + > + ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val1, NULL); > + if (ret) > + goto release; > + if (val1 != 0x414D4400U /* AMD */) { > + ret = -ENODEV; > + goto release; > + } > + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_1, &val1, NULL); > + if (ret) > + goto release; > + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_2, &val2, NULL); > + > +release: > + tpm_relinquish_locality(chip); > + > + if (ret) > + return false; > + > + version = ((u64)val1 << 32) | val2; > + if ((version >> 48) == 6) { > + if (version >= 0x0006000000180006ULL) > + return false; > + } else if ((version >> 48) == 3) { > + if (version >= 0x0003005700000005ULL) > + return false; > + } else { > + return false; > + } > + > + dev_warn(&chip->dev, > + "AMD fTPM version 0x%llx causes system stutter; hwrng disabled\n", > + version); > + > + return true; > +} > + > static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) > { > struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); > @@ -521,7 +578,8 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) > > static int tpm_add_hwrng(struct tpm_chip *chip) > { > - if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip)) > + if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) || > + tpm_amd_is_rng_defective(chip)) > return 0; > > snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h > index 24ee4e1cc452..830014a26609 100644 > --- a/drivers/char/tpm/tpm.h > +++ b/drivers/char/tpm/tpm.h > @@ -150,6 +150,79 @@ enum tpm_sub_capabilities { > TPM_CAP_PROP_TIS_DURATION = 0x120, > }; > > +enum tpm2_pt_props { > + TPM2_PT_NONE = 0x00000000, > + TPM2_PT_GROUP = 0x00000100, > + TPM2_PT_FIXED = TPM2_PT_GROUP * 1, > + TPM2_PT_FAMILY_INDICATOR = TPM2_PT_FIXED + 0, > + TPM2_PT_LEVEL = TPM2_PT_FIXED + 1, > + TPM2_PT_REVISION = TPM2_PT_FIXED + 2, > + TPM2_PT_DAY_OF_YEAR = TPM2_PT_FIXED + 3, > + TPM2_PT_YEAR = TPM2_PT_FIXED + 4, > + TPM2_PT_MANUFACTURER = TPM2_PT_FIXED + 5, > + TPM2_PT_VENDOR_STRING_1 = TPM2_PT_FIXED + 6, > + TPM2_PT_VENDOR_STRING_2 = TPM2_PT_FIXED + 7, > + TPM2_PT_VENDOR_STRING_3 = TPM2_PT_FIXED + 8, > + TPM2_PT_VENDOR_STRING_4 = TPM2_PT_FIXED + 9, > + TPM2_PT_VENDOR_TPM_TYPE = TPM2_PT_FIXED + 10, > + TPM2_PT_FIRMWARE_VERSION_1 = TPM2_PT_FIXED + 11, > + TPM2_PT_FIRMWARE_VERSION_2 = TPM2_PT_FIXED + 12, > + TPM2_PT_INPUT_BUFFER = TPM2_PT_FIXED + 13, > + TPM2_PT_HR_TRANSIENT_MIN = TPM2_PT_FIXED + 14, > + TPM2_PT_HR_PERSISTENT_MIN = TPM2_PT_FIXED + 15, > + TPM2_PT_HR_LOADED_MIN = TPM2_PT_FIXED + 16, > + TPM2_PT_ACTIVE_SESSIONS_MAX = TPM2_PT_FIXED + 17, > + TPM2_PT_PCR_COUNT = TPM2_PT_FIXED + 18, > + TPM2_PT_PCR_SELECT_MIN = TPM2_PT_FIXED + 19, > + TPM2_PT_CONTEXT_GAP_MAX = TPM2_PT_FIXED + 20, > + TPM2_PT_NV_COUNTERS_MAX = TPM2_PT_FIXED + 22, > + TPM2_PT_NV_INDEX_MAX = TPM2_PT_FIXED + 23, > + TPM2_PT_MEMORY = TPM2_PT_FIXED + 24, > + TPM2_PT_CLOCK_UPDATE = TPM2_PT_FIXED + 25, > + TPM2_PT_CONTEXT_HASH = TPM2_PT_FIXED + 26, > + TPM2_PT_CONTEXT_SYM = TPM2_PT_FIXED + 27, > + TPM2_PT_CONTEXT_SYM_SIZE = TPM2_PT_FIXED + 28, > + TPM2_PT_ORDERLY_COUNT = TPM2_PT_FIXED + 29, > + TPM2_PT_MAX_COMMAND_SIZE = TPM2_PT_FIXED + 30, > + TPM2_PT_MAX_RESPONSE_SIZE = TPM2_PT_FIXED + 31, > + TPM2_PT_MAX_DIGEST = TPM2_PT_FIXED + 32, > + TPM2_PT_MAX_OBJECT_CONTEXT = TPM2_PT_FIXED + 33, > + TPM2_PT_MAX_SESSION_CONTEXT = TPM2_PT_FIXED + 34, > + TPM2_PT_PS_FAMILY_INDICATOR = TPM2_PT_FIXED + 35, > + TPM2_PT_PS_LEVEL = TPM2_PT_FIXED + 36, > + TPM2_PT_PS_REVISION = TPM2_PT_FIXED + 37, > + TPM2_PT_PS_DAY_OF_YEAR = TPM2_PT_FIXED + 38, > + TPM2_PT_PS_YEAR = TPM2_PT_FIXED + 39, > + TPM2_PT_SPLIT_MAX = TPM2_PT_FIXED + 40, > + TPM2_PT_TOTAL_COMMANDS = TPM2_PT_FIXED + 41, > + TPM2_PT_LIBRARY_COMMANDS = TPM2_PT_FIXED + 42, > + TPM2_PT_VENDOR_COMMANDS = TPM2_PT_FIXED + 43, > + TPM2_PT_NV_BUFFER_MAX = TPM2_PT_FIXED + 44, > + TPM2_PT_MODES = TPM2_PT_FIXED + 45, > + TPM2_PT_MAX_CAP_BUFFER = TPM2_PT_FIXED + 46, > + TPM2_PT_VAR = TPM2_PT_GROUP * 2, > + TPM2_PT_PERMANENT = TPM2_PT_VAR + 0, > + TPM2_PT_STARTUP_CLEAR = TPM2_PT_VAR + 1, > + TPM2_PT_HR_NV_INDEX = TPM2_PT_VAR + 2, > + TPM2_PT_HR_LOADED = TPM2_PT_VAR + 3, > + TPM2_PT_HR_LOADED_AVAIL = TPM2_PT_VAR + 4, > + TPM2_PT_HR_ACTIVE = TPM2_PT_VAR + 5, > + TPM2_PT_HR_ACTIVE_AVAIL = TPM2_PT_VAR + 6, > + TPM2_PT_HR_TRANSIENT_AVAIL = TPM2_PT_VAR + 7, > + TPM2_PT_HR_PERSISTENT = TPM2_PT_VAR + 8, > + TPM2_PT_HR_PERSISTENT_AVAIL = TPM2_PT_VAR + 9, > + TPM2_PT_NV_COUNTERS = TPM2_PT_VAR + 10, > + TPM2_PT_NV_COUNTERS_AVAIL = TPM2_PT_VAR + 11, > + TPM2_PT_ALGORITHM_SET = TPM2_PT_VAR + 12, > + TPM2_PT_LOADED_CURVES = TPM2_PT_VAR + 13, > + TPM2_PT_LOCKOUT_COUNTER = TPM2_PT_VAR + 14, > + TPM2_PT_MAX_AUTH_FAIL = TPM2_PT_VAR + 15, > + TPM2_PT_LOCKOUT_INTERVAL = TPM2_PT_VAR + 16, > + TPM2_PT_LOCKOUT_RECOVERY = TPM2_PT_VAR + 17, > + TPM2_PT_NV_WRITE_RECOVERY = TPM2_PT_VAR + 18, > + TPM2_PT_AUDIT_COUNTER_0 = TPM2_PT_VAR + 19, > + TPM2_PT_AUDIT_COUNTER_1 = TPM2_PT_VAR + 20, > +}; > > /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 > * bytes, but 128 is still a relatively large number of random bytes and > -- > 2.34.1 > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> BR, Jarkko
Linux regression tracking (Thorsten Leemhuis)
March 8, 2023, 9:42 a.m. UTC |
#2
Addressed
Unaddressed
Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting for once, to make this easily accessible to everyone. Jarkko, thx for reviewing and picking below fix up. Are you planning to send this to Linus anytime soon, now that the patch was a few days in next? It would be good to get this 6.1 regression finally fixed, it already took way longer then the time frame Documentation/process/handling-regressions.rst outlines for a case like this. But well, that's how it is sometimes... Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) -- Everything you wanna know about Linux kernel regression tracking: https://linux-regtracking.leemhuis.info/about/#tldr If I did something stupid, please tell me, as explained on that page. On 28.02.23 04:10, Jarkko Sakkinen wrote: > On Mon, Feb 27, 2023 at 08:44:39PM -0600, Mario Limonciello wrote: >> AMD has issued an advisory indicating that having fTPM enabled in >> BIOS can cause "stuttering" in the OS. This issue has been fixed >> in newer versions of the fTPM firmware, but it's up to system >> designers to decide whether to distribute it. >> >> This issue has existed for a while, but is more prevalent starting >> with kernel 6.1 because commit b006c439d58db ("hwrng: core - start >> hwrng kthread also for untrusted sources") started to use the fTPM >> for hwrng by default. However, all uses of /dev/hwrng result in >> unacceptable stuttering. >> >> So, simply disable registration of the defective hwrng when detecting >> these faulty fTPM versions. As this is caused by faulty firmware, it >> is plausible that such a problem could also be reproduced by other TPM >> interactions, but this hasn't been shown by any user's testing or reports. >> >> It is hypothesized to be triggered more frequently by the use of the RNG >> because userspace software will fetch random numbers regularly. >> >> Intentionally continue to register other TPM functionality so that users >> that rely upon PCR measurements or any storage of data will still have >> access to it. If it's found later that another TPM functionality is >> exacerbating this problem a module parameter it can be turned off entirely >> and a module parameter can be introduced to allow users who rely upon >> fTPM functionality to turn it on even though this problem is present. >> >> Link: https://www.amd.com/en/support/kb/faq/pa-410 >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216989 >> Link: https://lore.kernel.org/all/20230209153120.261904-1-Jason@zx2c4.com/ >> Fixes: b006c439d58d ("hwrng: core - start hwrng kthread also for untrusted sources") >> Cc: stable@vger.kernel.org >> Cc: Jarkko Sakkinen <jarkko@kernel.org> >> Cc: Thorsten Leemhuis <regressions@leemhuis.info> >> Cc: James Bottomley <James.Bottomley@hansenpartnership.com> >> Tested-by: reach622@mailcuk.com >> Tested-by: Bell <1138267643@qq.com> >> Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com> >> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> >> --- >> v2->v3: >> * Revert extra curl braces back to behavior in v1 >> * Remove needless goto >> * Pick up 2 tested tags >> --- >> drivers/char/tpm/tpm-chip.c | 60 +++++++++++++++++++++++++++++- >> drivers/char/tpm/tpm.h | 73 +++++++++++++++++++++++++++++++++++++ >> 2 files changed, 132 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >> index 741d8f3e8fb3..c467eeae9973 100644 >> --- a/drivers/char/tpm/tpm-chip.c >> +++ b/drivers/char/tpm/tpm-chip.c >> @@ -512,6 +512,63 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) >> return 0; >> } >> >> +/* >> + * Some AMD fTPM versions may cause stutter >> + * https://www.amd.com/en/support/kb/faq/pa-410 >> + * >> + * Fixes are available in two series of fTPM firmware: >> + * 6.x.y.z series: 6.0.18.6 + >> + * 3.x.y.z series: 3.57.y.5 + >> + */ >> +static bool tpm_amd_is_rng_defective(struct tpm_chip *chip) >> +{ >> + u32 val1, val2; >> + u64 version; >> + int ret; >> + >> + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) >> + return false; >> + >> + ret = tpm_request_locality(chip); >> + if (ret) >> + return false; >> + >> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val1, NULL); >> + if (ret) >> + goto release; >> + if (val1 != 0x414D4400U /* AMD */) { >> + ret = -ENODEV; >> + goto release; >> + } >> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_1, &val1, NULL); >> + if (ret) >> + goto release; >> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_2, &val2, NULL); >> + >> +release: >> + tpm_relinquish_locality(chip); >> + >> + if (ret) >> + return false; >> + >> + version = ((u64)val1 << 32) | val2; >> + if ((version >> 48) == 6) { >> + if (version >= 0x0006000000180006ULL) >> + return false; >> + } else if ((version >> 48) == 3) { >> + if (version >= 0x0003005700000005ULL) >> + return false; >> + } else { >> + return false; >> + } >> + >> + dev_warn(&chip->dev, >> + "AMD fTPM version 0x%llx causes system stutter; hwrng disabled\n", >> + version); >> + >> + return true; >> +} >> + >> static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) >> { >> struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); >> @@ -521,7 +578,8 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) >> >> static int tpm_add_hwrng(struct tpm_chip *chip) >> { >> - if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip)) >> + if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) || >> + tpm_amd_is_rng_defective(chip)) >> return 0; >> >> snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), >> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h >> index 24ee4e1cc452..830014a26609 100644 >> --- a/drivers/char/tpm/tpm.h >> +++ b/drivers/char/tpm/tpm.h >> @@ -150,6 +150,79 @@ enum tpm_sub_capabilities { >> TPM_CAP_PROP_TIS_DURATION = 0x120, >> }; >> >> +enum tpm2_pt_props { >> + TPM2_PT_NONE = 0x00000000, >> + TPM2_PT_GROUP = 0x00000100, >> + TPM2_PT_FIXED = TPM2_PT_GROUP * 1, >> + TPM2_PT_FAMILY_INDICATOR = TPM2_PT_FIXED + 0, >> + TPM2_PT_LEVEL = TPM2_PT_FIXED + 1, >> + TPM2_PT_REVISION = TPM2_PT_FIXED + 2, >> + TPM2_PT_DAY_OF_YEAR = TPM2_PT_FIXED + 3, >> + TPM2_PT_YEAR = TPM2_PT_FIXED + 4, >> + TPM2_PT_MANUFACTURER = TPM2_PT_FIXED + 5, >> + TPM2_PT_VENDOR_STRING_1 = TPM2_PT_FIXED + 6, >> + TPM2_PT_VENDOR_STRING_2 = TPM2_PT_FIXED + 7, >> + TPM2_PT_VENDOR_STRING_3 = TPM2_PT_FIXED + 8, >> + TPM2_PT_VENDOR_STRING_4 = TPM2_PT_FIXED + 9, >> + TPM2_PT_VENDOR_TPM_TYPE = TPM2_PT_FIXED + 10, >> + TPM2_PT_FIRMWARE_VERSION_1 = TPM2_PT_FIXED + 11, >> + TPM2_PT_FIRMWARE_VERSION_2 = TPM2_PT_FIXED + 12, >> + TPM2_PT_INPUT_BUFFER = TPM2_PT_FIXED + 13, >> + TPM2_PT_HR_TRANSIENT_MIN = TPM2_PT_FIXED + 14, >> + TPM2_PT_HR_PERSISTENT_MIN = TPM2_PT_FIXED + 15, >> + TPM2_PT_HR_LOADED_MIN = TPM2_PT_FIXED + 16, >> + TPM2_PT_ACTIVE_SESSIONS_MAX = TPM2_PT_FIXED + 17, >> + TPM2_PT_PCR_COUNT = TPM2_PT_FIXED + 18, >> + TPM2_PT_PCR_SELECT_MIN = TPM2_PT_FIXED + 19, >> + TPM2_PT_CONTEXT_GAP_MAX = TPM2_PT_FIXED + 20, >> + TPM2_PT_NV_COUNTERS_MAX = TPM2_PT_FIXED + 22, >> + TPM2_PT_NV_INDEX_MAX = TPM2_PT_FIXED + 23, >> + TPM2_PT_MEMORY = TPM2_PT_FIXED + 24, >> + TPM2_PT_CLOCK_UPDATE = TPM2_PT_FIXED + 25, >> + TPM2_PT_CONTEXT_HASH = TPM2_PT_FIXED + 26, >> + TPM2_PT_CONTEXT_SYM = TPM2_PT_FIXED + 27, >> + TPM2_PT_CONTEXT_SYM_SIZE = TPM2_PT_FIXED + 28, >> + TPM2_PT_ORDERLY_COUNT = TPM2_PT_FIXED + 29, >> + TPM2_PT_MAX_COMMAND_SIZE = TPM2_PT_FIXED + 30, >> + TPM2_PT_MAX_RESPONSE_SIZE = TPM2_PT_FIXED + 31, >> + TPM2_PT_MAX_DIGEST = TPM2_PT_FIXED + 32, >> + TPM2_PT_MAX_OBJECT_CONTEXT = TPM2_PT_FIXED + 33, >> + TPM2_PT_MAX_SESSION_CONTEXT = TPM2_PT_FIXED + 34, >> + TPM2_PT_PS_FAMILY_INDICATOR = TPM2_PT_FIXED + 35, >> + TPM2_PT_PS_LEVEL = TPM2_PT_FIXED + 36, >> + TPM2_PT_PS_REVISION = TPM2_PT_FIXED + 37, >> + TPM2_PT_PS_DAY_OF_YEAR = TPM2_PT_FIXED + 38, >> + TPM2_PT_PS_YEAR = TPM2_PT_FIXED + 39, >> + TPM2_PT_SPLIT_MAX = TPM2_PT_FIXED + 40, >> + TPM2_PT_TOTAL_COMMANDS = TPM2_PT_FIXED + 41, >> + TPM2_PT_LIBRARY_COMMANDS = TPM2_PT_FIXED + 42, >> + TPM2_PT_VENDOR_COMMANDS = TPM2_PT_FIXED + 43, >> + TPM2_PT_NV_BUFFER_MAX = TPM2_PT_FIXED + 44, >> + TPM2_PT_MODES = TPM2_PT_FIXED + 45, >> + TPM2_PT_MAX_CAP_BUFFER = TPM2_PT_FIXED + 46, >> + TPM2_PT_VAR = TPM2_PT_GROUP * 2, >> + TPM2_PT_PERMANENT = TPM2_PT_VAR + 0, >> + TPM2_PT_STARTUP_CLEAR = TPM2_PT_VAR + 1, >> + TPM2_PT_HR_NV_INDEX = TPM2_PT_VAR + 2, >> + TPM2_PT_HR_LOADED = TPM2_PT_VAR + 3, >> + TPM2_PT_HR_LOADED_AVAIL = TPM2_PT_VAR + 4, >> + TPM2_PT_HR_ACTIVE = TPM2_PT_VAR + 5, >> + TPM2_PT_HR_ACTIVE_AVAIL = TPM2_PT_VAR + 6, >> + TPM2_PT_HR_TRANSIENT_AVAIL = TPM2_PT_VAR + 7, >> + TPM2_PT_HR_PERSISTENT = TPM2_PT_VAR + 8, >> + TPM2_PT_HR_PERSISTENT_AVAIL = TPM2_PT_VAR + 9, >> + TPM2_PT_NV_COUNTERS = TPM2_PT_VAR + 10, >> + TPM2_PT_NV_COUNTERS_AVAIL = TPM2_PT_VAR + 11, >> + TPM2_PT_ALGORITHM_SET = TPM2_PT_VAR + 12, >> + TPM2_PT_LOADED_CURVES = TPM2_PT_VAR + 13, >> + TPM2_PT_LOCKOUT_COUNTER = TPM2_PT_VAR + 14, >> + TPM2_PT_MAX_AUTH_FAIL = TPM2_PT_VAR + 15, >> + TPM2_PT_LOCKOUT_INTERVAL = TPM2_PT_VAR + 16, >> + TPM2_PT_LOCKOUT_RECOVERY = TPM2_PT_VAR + 17, >> + TPM2_PT_NV_WRITE_RECOVERY = TPM2_PT_VAR + 18, >> + TPM2_PT_AUDIT_COUNTER_0 = TPM2_PT_VAR + 19, >> + TPM2_PT_AUDIT_COUNTER_1 = TPM2_PT_VAR + 20, >> +}; >> >> /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 >> * bytes, but 128 is still a relatively large number of random bytes and >> -- >> 2.34.1 >> > > > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> > > BR, Jarkko
Linux regression tracking (Thorsten Leemhuis)
March 10, 2023, 5:43 p.m. UTC |
#3
Addressed
Unaddressed
[adding Linux to the list of recipients] On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting > for once, to make this easily accessible to everyone. > > Jarkko, thx for reviewing and picking below fix up. Are you planning to > send this to Linus anytime soon, now that the patch was a few days in > next? It would be good to get this 6.1 regression finally fixed, it > already took way longer then the time frame > Documentation/process/handling-regressions.rst outlines for a case like > this. But well, that's how it is sometimes... Linus, would you consider picking this fix up directly from here or from linux-next (8699d5244e37)? It's been in the latter for 9 days now afaics. And the issue seems to bug more than just one or two users, so it IMHO would be good to get this finally resolved. Jarkko didn't reply to my inquiry, guess something else keeps him busy. Ciao, Thorsten > On 28.02.23 04:10, Jarkko Sakkinen wrote: >> On Mon, Feb 27, 2023 at 08:44:39PM -0600, Mario Limonciello wrote: >>> AMD has issued an advisory indicating that having fTPM enabled in >>> BIOS can cause "stuttering" in the OS. This issue has been fixed >>> in newer versions of the fTPM firmware, but it's up to system >>> designers to decide whether to distribute it. >>> >>> This issue has existed for a while, but is more prevalent starting >>> with kernel 6.1 because commit b006c439d58db ("hwrng: core - start >>> hwrng kthread also for untrusted sources") started to use the fTPM >>> for hwrng by default. However, all uses of /dev/hwrng result in >>> unacceptable stuttering. >>> >>> So, simply disable registration of the defective hwrng when detecting >>> these faulty fTPM versions. As this is caused by faulty firmware, it >>> is plausible that such a problem could also be reproduced by other TPM >>> interactions, but this hasn't been shown by any user's testing or reports. >>> >>> It is hypothesized to be triggered more frequently by the use of the RNG >>> because userspace software will fetch random numbers regularly. >>> >>> Intentionally continue to register other TPM functionality so that users >>> that rely upon PCR measurements or any storage of data will still have >>> access to it. If it's found later that another TPM functionality is >>> exacerbating this problem a module parameter it can be turned off entirely >>> and a module parameter can be introduced to allow users who rely upon >>> fTPM functionality to turn it on even though this problem is present. >>> >>> Link: https://www.amd.com/en/support/kb/faq/pa-410 >>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216989 >>> Link: https://lore.kernel.org/all/20230209153120.261904-1-Jason@zx2c4.com/ >>> Fixes: b006c439d58d ("hwrng: core - start hwrng kthread also for untrusted sources") >>> Cc: stable@vger.kernel.org >>> Cc: Jarkko Sakkinen <jarkko@kernel.org> >>> Cc: Thorsten Leemhuis <regressions@leemhuis.info> >>> Cc: James Bottomley <James.Bottomley@hansenpartnership.com> >>> Tested-by: reach622@mailcuk.com >>> Tested-by: Bell <1138267643@qq.com> >>> Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com> >>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> >>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> >>> --- >>> v2->v3: >>> * Revert extra curl braces back to behavior in v1 >>> * Remove needless goto >>> * Pick up 2 tested tags >>> --- >>> drivers/char/tpm/tpm-chip.c | 60 +++++++++++++++++++++++++++++- >>> drivers/char/tpm/tpm.h | 73 +++++++++++++++++++++++++++++++++++++ >>> 2 files changed, 132 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >>> index 741d8f3e8fb3..c467eeae9973 100644 >>> --- a/drivers/char/tpm/tpm-chip.c >>> +++ b/drivers/char/tpm/tpm-chip.c >>> @@ -512,6 +512,63 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) >>> return 0; >>> } >>> >>> +/* >>> + * Some AMD fTPM versions may cause stutter >>> + * https://www.amd.com/en/support/kb/faq/pa-410 >>> + * >>> + * Fixes are available in two series of fTPM firmware: >>> + * 6.x.y.z series: 6.0.18.6 + >>> + * 3.x.y.z series: 3.57.y.5 + >>> + */ >>> +static bool tpm_amd_is_rng_defective(struct tpm_chip *chip) >>> +{ >>> + u32 val1, val2; >>> + u64 version; >>> + int ret; >>> + >>> + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) >>> + return false; >>> + >>> + ret = tpm_request_locality(chip); >>> + if (ret) >>> + return false; >>> + >>> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val1, NULL); >>> + if (ret) >>> + goto release; >>> + if (val1 != 0x414D4400U /* AMD */) { >>> + ret = -ENODEV; >>> + goto release; >>> + } >>> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_1, &val1, NULL); >>> + if (ret) >>> + goto release; >>> + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_2, &val2, NULL); >>> + >>> +release: >>> + tpm_relinquish_locality(chip); >>> + >>> + if (ret) >>> + return false; >>> + >>> + version = ((u64)val1 << 32) | val2; >>> + if ((version >> 48) == 6) { >>> + if (version >= 0x0006000000180006ULL) >>> + return false; >>> + } else if ((version >> 48) == 3) { >>> + if (version >= 0x0003005700000005ULL) >>> + return false; >>> + } else { >>> + return false; >>> + } >>> + >>> + dev_warn(&chip->dev, >>> + "AMD fTPM version 0x%llx causes system stutter; hwrng disabled\n", >>> + version); >>> + >>> + return true; >>> +} >>> + >>> static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) >>> { >>> struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); >>> @@ -521,7 +578,8 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) >>> >>> static int tpm_add_hwrng(struct tpm_chip *chip) >>> { >>> - if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip)) >>> + if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) || >>> + tpm_amd_is_rng_defective(chip)) >>> return 0; >>> >>> snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), >>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h >>> index 24ee4e1cc452..830014a26609 100644 >>> --- a/drivers/char/tpm/tpm.h >>> +++ b/drivers/char/tpm/tpm.h >>> @@ -150,6 +150,79 @@ enum tpm_sub_capabilities { >>> TPM_CAP_PROP_TIS_DURATION = 0x120, >>> }; >>> >>> +enum tpm2_pt_props { >>> + TPM2_PT_NONE = 0x00000000, >>> + TPM2_PT_GROUP = 0x00000100, >>> + TPM2_PT_FIXED = TPM2_PT_GROUP * 1, >>> + TPM2_PT_FAMILY_INDICATOR = TPM2_PT_FIXED + 0, >>> + TPM2_PT_LEVEL = TPM2_PT_FIXED + 1, >>> + TPM2_PT_REVISION = TPM2_PT_FIXED + 2, >>> + TPM2_PT_DAY_OF_YEAR = TPM2_PT_FIXED + 3, >>> + TPM2_PT_YEAR = TPM2_PT_FIXED + 4, >>> + TPM2_PT_MANUFACTURER = TPM2_PT_FIXED + 5, >>> + TPM2_PT_VENDOR_STRING_1 = TPM2_PT_FIXED + 6, >>> + TPM2_PT_VENDOR_STRING_2 = TPM2_PT_FIXED + 7, >>> + TPM2_PT_VENDOR_STRING_3 = TPM2_PT_FIXED + 8, >>> + TPM2_PT_VENDOR_STRING_4 = TPM2_PT_FIXED + 9, >>> + TPM2_PT_VENDOR_TPM_TYPE = TPM2_PT_FIXED + 10, >>> + TPM2_PT_FIRMWARE_VERSION_1 = TPM2_PT_FIXED + 11, >>> + TPM2_PT_FIRMWARE_VERSION_2 = TPM2_PT_FIXED + 12, >>> + TPM2_PT_INPUT_BUFFER = TPM2_PT_FIXED + 13, >>> + TPM2_PT_HR_TRANSIENT_MIN = TPM2_PT_FIXED + 14, >>> + TPM2_PT_HR_PERSISTENT_MIN = TPM2_PT_FIXED + 15, >>> + TPM2_PT_HR_LOADED_MIN = TPM2_PT_FIXED + 16, >>> + TPM2_PT_ACTIVE_SESSIONS_MAX = TPM2_PT_FIXED + 17, >>> + TPM2_PT_PCR_COUNT = TPM2_PT_FIXED + 18, >>> + TPM2_PT_PCR_SELECT_MIN = TPM2_PT_FIXED + 19, >>> + TPM2_PT_CONTEXT_GAP_MAX = TPM2_PT_FIXED + 20, >>> + TPM2_PT_NV_COUNTERS_MAX = TPM2_PT_FIXED + 22, >>> + TPM2_PT_NV_INDEX_MAX = TPM2_PT_FIXED + 23, >>> + TPM2_PT_MEMORY = TPM2_PT_FIXED + 24, >>> + TPM2_PT_CLOCK_UPDATE = TPM2_PT_FIXED + 25, >>> + TPM2_PT_CONTEXT_HASH = TPM2_PT_FIXED + 26, >>> + TPM2_PT_CONTEXT_SYM = TPM2_PT_FIXED + 27, >>> + TPM2_PT_CONTEXT_SYM_SIZE = TPM2_PT_FIXED + 28, >>> + TPM2_PT_ORDERLY_COUNT = TPM2_PT_FIXED + 29, >>> + TPM2_PT_MAX_COMMAND_SIZE = TPM2_PT_FIXED + 30, >>> + TPM2_PT_MAX_RESPONSE_SIZE = TPM2_PT_FIXED + 31, >>> + TPM2_PT_MAX_DIGEST = TPM2_PT_FIXED + 32, >>> + TPM2_PT_MAX_OBJECT_CONTEXT = TPM2_PT_FIXED + 33, >>> + TPM2_PT_MAX_SESSION_CONTEXT = TPM2_PT_FIXED + 34, >>> + TPM2_PT_PS_FAMILY_INDICATOR = TPM2_PT_FIXED + 35, >>> + TPM2_PT_PS_LEVEL = TPM2_PT_FIXED + 36, >>> + TPM2_PT_PS_REVISION = TPM2_PT_FIXED + 37, >>> + TPM2_PT_PS_DAY_OF_YEAR = TPM2_PT_FIXED + 38, >>> + TPM2_PT_PS_YEAR = TPM2_PT_FIXED + 39, >>> + TPM2_PT_SPLIT_MAX = TPM2_PT_FIXED + 40, >>> + TPM2_PT_TOTAL_COMMANDS = TPM2_PT_FIXED + 41, >>> + TPM2_PT_LIBRARY_COMMANDS = TPM2_PT_FIXED + 42, >>> + TPM2_PT_VENDOR_COMMANDS = TPM2_PT_FIXED + 43, >>> + TPM2_PT_NV_BUFFER_MAX = TPM2_PT_FIXED + 44, >>> + TPM2_PT_MODES = TPM2_PT_FIXED + 45, >>> + TPM2_PT_MAX_CAP_BUFFER = TPM2_PT_FIXED + 46, >>> + TPM2_PT_VAR = TPM2_PT_GROUP * 2, >>> + TPM2_PT_PERMANENT = TPM2_PT_VAR + 0, >>> + TPM2_PT_STARTUP_CLEAR = TPM2_PT_VAR + 1, >>> + TPM2_PT_HR_NV_INDEX = TPM2_PT_VAR + 2, >>> + TPM2_PT_HR_LOADED = TPM2_PT_VAR + 3, >>> + TPM2_PT_HR_LOADED_AVAIL = TPM2_PT_VAR + 4, >>> + TPM2_PT_HR_ACTIVE = TPM2_PT_VAR + 5, >>> + TPM2_PT_HR_ACTIVE_AVAIL = TPM2_PT_VAR + 6, >>> + TPM2_PT_HR_TRANSIENT_AVAIL = TPM2_PT_VAR + 7, >>> + TPM2_PT_HR_PERSISTENT = TPM2_PT_VAR + 8, >>> + TPM2_PT_HR_PERSISTENT_AVAIL = TPM2_PT_VAR + 9, >>> + TPM2_PT_NV_COUNTERS = TPM2_PT_VAR + 10, >>> + TPM2_PT_NV_COUNTERS_AVAIL = TPM2_PT_VAR + 11, >>> + TPM2_PT_ALGORITHM_SET = TPM2_PT_VAR + 12, >>> + TPM2_PT_LOADED_CURVES = TPM2_PT_VAR + 13, >>> + TPM2_PT_LOCKOUT_COUNTER = TPM2_PT_VAR + 14, >>> + TPM2_PT_MAX_AUTH_FAIL = TPM2_PT_VAR + 15, >>> + TPM2_PT_LOCKOUT_INTERVAL = TPM2_PT_VAR + 16, >>> + TPM2_PT_LOCKOUT_RECOVERY = TPM2_PT_VAR + 17, >>> + TPM2_PT_NV_WRITE_RECOVERY = TPM2_PT_VAR + 18, >>> + TPM2_PT_AUDIT_COUNTER_0 = TPM2_PT_VAR + 19, >>> + TPM2_PT_AUDIT_COUNTER_1 = TPM2_PT_VAR + 20, >>> +}; >>> >>> /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 >>> * bytes, but 128 is still a relatively large number of random bytes and >>> -- >>> 2.34.1 >>> >> >> >> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> >> >> BR, Jarkko
On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: > [adding Linux to the list of recipients] > > On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: > > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting > > for once, to make this easily accessible to everyone. > > > > Jarkko, thx for reviewing and picking below fix up. Are you planning to > > send this to Linus anytime soon, now that the patch was a few days in > > next? It would be good to get this 6.1 regression finally fixed, it > > already took way longer then the time frame > > Documentation/process/handling-regressions.rst outlines for a case like > > this. But well, that's how it is sometimes... > > Linus, would you consider picking this fix up directly from here or from > linux-next (8699d5244e37)? It's been in the latter for 9 days now > afaics. And the issue seems to bug more than just one or two users, so > it IMHO would be good to get this finally resolved. > > Jarkko didn't reply to my inquiry, guess something else keeps him busy. That's a bit arrogant. You emailed only 4 days ago. I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. BR, Jarkko
On Sun, Mar 12, 2023 at 03:35:08AM +0200, Jarkko Sakkinen wrote: > On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: > > [adding Linux to the list of recipients] > > > > On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: > > > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting > > > for once, to make this easily accessible to everyone. > > > > > > Jarkko, thx for reviewing and picking below fix up. Are you planning to > > > send this to Linus anytime soon, now that the patch was a few days in > > > next? It would be good to get this 6.1 regression finally fixed, it > > > already took way longer then the time frame > > > Documentation/process/handling-regressions.rst outlines for a case like > > > this. But well, that's how it is sometimes... > > > > Linus, would you consider picking this fix up directly from here or from > > linux-next (8699d5244e37)? It's been in the latter for 9 days now > > afaics. And the issue seems to bug more than just one or two users, so > > it IMHO would be good to get this finally resolved. > > > > Jarkko didn't reply to my inquiry, guess something else keeps him busy. > > That's a bit arrogant. You emailed only 4 days ago. > > I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. If this is about slow response with kernel bugzilla: it is not *enforced* part of the process. If it was, I would use it. Since it isn't, I don't really want to add any extra weight to my workflow. It's not only extra time but also it is not documented how exactly and in detail you would use it. For email we have all that documented. And when you don't have guidelines, then it is too flakky to use properly. BR, Jarkko
On 3/12/23, Jarkko Sakkinen <jarkko@kernel.org> wrote: > On Sun, Mar 12, 2023 at 03:35:08AM +0200, Jarkko Sakkinen wrote: >> On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: >> > [adding Linux to the list of recipients] >> > >> > On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: >> > > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting >> > > for once, to make this easily accessible to everyone. >> > > >> > > Jarkko, thx for reviewing and picking below fix up. Are you planning >> > > to >> > > send this to Linus anytime soon, now that the patch was a few days in >> > > next? It would be good to get this 6.1 regression finally fixed, it >> > > already took way longer then the time frame >> > > Documentation/process/handling-regressions.rst outlines for a case >> > > like >> > > this. But well, that's how it is sometimes... >> > >> > Linus, would you consider picking this fix up directly from here or >> > from >> > linux-next (8699d5244e37)? It's been in the latter for 9 days now >> > afaics. And the issue seems to bug more than just one or two users, so >> > it IMHO would be good to get this finally resolved. >> > >> > Jarkko didn't reply to my inquiry, guess something else keeps him busy. >> >> That's a bit arrogant. You emailed only 4 days ago. >> >> I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. > > If this is about slow response with kernel bugzilla: it is not *enforced* > part of the process. If it was, I would use it. Since it isn't, I don't > really want to add any extra weight to my workflow. > > It's not only extra time but also it is not documented how exactly and in > detail you would use it. For email we have all that documented. And when > you don't have guidelines, then it is too flakky to use properly. No interest in wading into a process argument. But if you're able to send this for rc3, please please do so. Users keep getting hit by this, some email me directly, and I keep replying saying the fix should be released any day now. So let's make that happen.
On Sun, Mar 12, 2023 at 02:49:17AM +0100, Jason A. Donenfeld wrote: > On 3/12/23, Jarkko Sakkinen <jarkko@kernel.org> wrote: > > On Sun, Mar 12, 2023 at 03:35:08AM +0200, Jarkko Sakkinen wrote: > >> On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: > >> > [adding Linux to the list of recipients] > >> > > >> > On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: > >> > > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting > >> > > for once, to make this easily accessible to everyone. > >> > > > >> > > Jarkko, thx for reviewing and picking below fix up. Are you planning > >> > > to > >> > > send this to Linus anytime soon, now that the patch was a few days in > >> > > next? It would be good to get this 6.1 regression finally fixed, it > >> > > already took way longer then the time frame > >> > > Documentation/process/handling-regressions.rst outlines for a case > >> > > like > >> > > this. But well, that's how it is sometimes... > >> > > >> > Linus, would you consider picking this fix up directly from here or > >> > from > >> > linux-next (8699d5244e37)? It's been in the latter for 9 days now > >> > afaics. And the issue seems to bug more than just one or two users, so > >> > it IMHO would be good to get this finally resolved. > >> > > >> > Jarkko didn't reply to my inquiry, guess something else keeps him busy. > >> > >> That's a bit arrogant. You emailed only 4 days ago. > >> > >> I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. > > > > If this is about slow response with kernel bugzilla: it is not *enforced* > > part of the process. If it was, I would use it. Since it isn't, I don't > > really want to add any extra weight to my workflow. > > > > It's not only extra time but also it is not documented how exactly and in > > detail you would use it. For email we have all that documented. And when > > you don't have guidelines, then it is too flakky to use properly. > > No interest in wading into a process argument. But if you're able to > send this for rc3, please please do so. Users keep getting hit by > this, some email me directly, and I keep replying saying the fix > should be released any day now. So let's make that happen. Sure, that shouldn't be a problem. I'll queue this for rc3. BR, Jarkko
On Sun, Mar 12, 2023 at 03:55:03AM +0200, Jarkko Sakkinen wrote: > On Sun, Mar 12, 2023 at 02:49:17AM +0100, Jason A. Donenfeld wrote: > > On 3/12/23, Jarkko Sakkinen <jarkko@kernel.org> wrote: > > > On Sun, Mar 12, 2023 at 03:35:08AM +0200, Jarkko Sakkinen wrote: > > >> On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: > > >> > [adding Linux to the list of recipients] > > >> > > > >> > On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: > > >> > > Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting > > >> > > for once, to make this easily accessible to everyone. > > >> > > > > >> > > Jarkko, thx for reviewing and picking below fix up. Are you planning > > >> > > to > > >> > > send this to Linus anytime soon, now that the patch was a few days in > > >> > > next? It would be good to get this 6.1 regression finally fixed, it > > >> > > already took way longer then the time frame > > >> > > Documentation/process/handling-regressions.rst outlines for a case > > >> > > like > > >> > > this. But well, that's how it is sometimes... > > >> > > > >> > Linus, would you consider picking this fix up directly from here or > > >> > from > > >> > linux-next (8699d5244e37)? It's been in the latter for 9 days now > > >> > afaics. And the issue seems to bug more than just one or two users, so > > >> > it IMHO would be good to get this finally resolved. > > >> > > > >> > Jarkko didn't reply to my inquiry, guess something else keeps him busy. > > >> > > >> That's a bit arrogant. You emailed only 4 days ago. > > >> > > >> I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. > > > > > > If this is about slow response with kernel bugzilla: it is not *enforced* > > > part of the process. If it was, I would use it. Since it isn't, I don't > > > really want to add any extra weight to my workflow. > > > > > > It's not only extra time but also it is not documented how exactly and in > > > detail you would use it. For email we have all that documented. And when > > > you don't have guidelines, then it is too flakky to use properly. > > > > No interest in wading into a process argument. But if you're able to > > send this for rc3, please please do so. Users keep getting hit by > > this, some email me directly, and I keep replying saying the fix > > should be released any day now. So let's make that happen. > > Sure, that shouldn't be a problem. I'll queue this for rc3. Considering "the process argument": I'm just saying that we have user facing service that is not properly documented to the maintainers, that's all. BR, Jarkko
Linux regression tracking (Thorsten Leemhuis)
March 12, 2023, 10:35 a.m. UTC |
#9
Addressed
Unaddressed
On 12.03.23 02:35, Jarkko Sakkinen wrote: > On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: >> [adding Linux to the list of recipients] >> >> On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: >>> Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting >>> for once, to make this easily accessible to everyone. >>> >>> Jarkko, thx for reviewing and picking below fix up. Are you planning to >>> send this to Linus anytime soon, now that the patch was a few days in >>> next? It would be good to get this 6.1 regression finally fixed, it >>> already took way longer then the time frame >>> Documentation/process/handling-regressions.rst outlines for a case like >>> this. But well, that's how it is sometimes... >> >> Linus, would you consider picking this fix up directly from here or from >> linux-next (8699d5244e37)? It's been in the latter for 9 days now >> afaics. And the issue seems to bug more than just one or two users, so >> it IMHO would be good to get this finally resolved. >> >> Jarkko didn't reply to my inquiry, guess something else keeps him busy. > > That's a bit arrogant. You emailed only 4 days ago. My deepest apologies if that "guess something else keeps him busy" triggered your response, what I wanted to say is "I don't consider the lack of a response a problem, that's how it is for all of us sometimes". Sorry, that might not have been the best way to express that. If my prodding itself was the cause: well, I think that's what I should do in this case. That stance developed quickly when I started doing regression tracking, as I noticed one thing: Image a regression caused by a commit merged for 5.11-rc1 is reported a day or two after 5.11-rc7 is released. Imagine further a fix is posted for review two or three days after 5.11-rc8 is out. From what I noticed quite a few of those fixes (not all of course) make it to mainline in time for the release of 5.11. But the picture looked totally different when the fix was posted for review shortly *after* 5.11 was out, as I noticed quite a few of those were only mainlined 9 or 10 weeks later for 5.13-rc1 (and only then can be backported to 5.11.y and 5.12.y). [above was just a hypothetical example with the worst timing to illustrate the core problem, the timelines are different in case of the fTPM issue] From my understanding of things that's not how it should be (unless there are strong reasons in the individual case). That's why I'm working against that. Still working on optimizing when/how I ask, as I'm not yet happy with how I do that. Don't worry, I use my best judgment in that process; if the fix is complex and the next merge window is near, I might let it slip – OTOH if it's something that apparently bugs quite a few people, I prod developers and maintainers more quickly & often, like I did in this case. In the end situations like the one outlined above lead me to writing the section "Prioritize work on fixing regressions" in Documentation/process/handling-regressions.rst ( https://docs.kernel.org/process/handling-regressions.html ). Greg acked it; Linus never commented on it, not sure if he looked at it when he merged that. But I have no idea how developers actually have seen it and/or take it seriously. But from what I saw it already helped somewhat. > I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. From later in this thread I see that you plan to do that now, thus: many thx! Ciao, Thorsten
Linux regression tracking (Thorsten Leemhuis)
March 12, 2023, 10:40 a.m. UTC |
#10
Addressed
Unaddressed
On 12.03.23 02:42, Jarkko Sakkinen wrote: > On Sun, Mar 12, 2023 at 03:35:08AM +0200, Jarkko Sakkinen wrote: >> On Fri, Mar 10, 2023 at 06:43:47PM +0100, Thorsten Leemhuis wrote: >>> [adding Linux to the list of recipients] >>> >>> On 08.03.23 10:42, Linux regression tracking (Thorsten Leemhuis) wrote: >>>> Hi, Thorsten here, the Linux kernel's regression tracker. Top-posting >>>> for once, to make this easily accessible to everyone. >>>> >>>> Jarkko, thx for reviewing and picking below fix up. Are you planning to >>>> send this to Linus anytime soon, now that the patch was a few days in >>>> next? It would be good to get this 6.1 regression finally fixed, it >>>> already took way longer then the time frame >>>> Documentation/process/handling-regressions.rst outlines for a case like >>>> this. But well, that's how it is sometimes... >>> >>> Linus, would you consider picking this fix up directly from here or from >>> linux-next (8699d5244e37)? It's been in the latter for 9 days now >>> afaics. And the issue seems to bug more than just one or two users, so >>> it IMHO would be good to get this finally resolved. >>> >>> Jarkko didn't reply to my inquiry, guess something else keeps him busy. >> >> That's a bit arrogant. You emailed only 4 days ago. >> >> I'm open to do PR for rc3 with the fix, if it cannot wait to v6.4 pr. > > If this is about slow response with kernel bugzilla: [...] Not at all, I don't care if developers use bugzilla or ignore it, as long as the regression itself it dealt with. Fun fact: I actually wanted to get rid of bugzilla for developers/ subsystems that didn't opt-in, but then another plan came up. See https://lwn.net/Articles/910740/ Ciao, Thorsten
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 741d8f3e8fb3..c467eeae9973 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -512,6 +512,63 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) return 0; } +/* + * Some AMD fTPM versions may cause stutter + * https://www.amd.com/en/support/kb/faq/pa-410 + * + * Fixes are available in two series of fTPM firmware: + * 6.x.y.z series: 6.0.18.6 + + * 3.x.y.z series: 3.57.y.5 + + */ +static bool tpm_amd_is_rng_defective(struct tpm_chip *chip) +{ + u32 val1, val2; + u64 version; + int ret; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) + return false; + + ret = tpm_request_locality(chip); + if (ret) + return false; + + ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val1, NULL); + if (ret) + goto release; + if (val1 != 0x414D4400U /* AMD */) { + ret = -ENODEV; + goto release; + } + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_1, &val1, NULL); + if (ret) + goto release; + ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_2, &val2, NULL); + +release: + tpm_relinquish_locality(chip); + + if (ret) + return false; + + version = ((u64)val1 << 32) | val2; + if ((version >> 48) == 6) { + if (version >= 0x0006000000180006ULL) + return false; + } else if ((version >> 48) == 3) { + if (version >= 0x0003005700000005ULL) + return false; + } else { + return false; + } + + dev_warn(&chip->dev, + "AMD fTPM version 0x%llx causes system stutter; hwrng disabled\n", + version); + + return true; +} + static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) { struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); @@ -521,7 +578,8 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) static int tpm_add_hwrng(struct tpm_chip *chip) { - if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip)) + if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) || + tpm_amd_is_rng_defective(chip)) return 0; snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 24ee4e1cc452..830014a26609 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -150,6 +150,79 @@ enum tpm_sub_capabilities { TPM_CAP_PROP_TIS_DURATION = 0x120, }; +enum tpm2_pt_props { + TPM2_PT_NONE = 0x00000000, + TPM2_PT_GROUP = 0x00000100, + TPM2_PT_FIXED = TPM2_PT_GROUP * 1, + TPM2_PT_FAMILY_INDICATOR = TPM2_PT_FIXED + 0, + TPM2_PT_LEVEL = TPM2_PT_FIXED + 1, + TPM2_PT_REVISION = TPM2_PT_FIXED + 2, + TPM2_PT_DAY_OF_YEAR = TPM2_PT_FIXED + 3, + TPM2_PT_YEAR = TPM2_PT_FIXED + 4, + TPM2_PT_MANUFACTURER = TPM2_PT_FIXED + 5, + TPM2_PT_VENDOR_STRING_1 = TPM2_PT_FIXED + 6, + TPM2_PT_VENDOR_STRING_2 = TPM2_PT_FIXED + 7, + TPM2_PT_VENDOR_STRING_3 = TPM2_PT_FIXED + 8, + TPM2_PT_VENDOR_STRING_4 = TPM2_PT_FIXED + 9, + TPM2_PT_VENDOR_TPM_TYPE = TPM2_PT_FIXED + 10, + TPM2_PT_FIRMWARE_VERSION_1 = TPM2_PT_FIXED + 11, + TPM2_PT_FIRMWARE_VERSION_2 = TPM2_PT_FIXED + 12, + TPM2_PT_INPUT_BUFFER = TPM2_PT_FIXED + 13, + TPM2_PT_HR_TRANSIENT_MIN = TPM2_PT_FIXED + 14, + TPM2_PT_HR_PERSISTENT_MIN = TPM2_PT_FIXED + 15, + TPM2_PT_HR_LOADED_MIN = TPM2_PT_FIXED + 16, + TPM2_PT_ACTIVE_SESSIONS_MAX = TPM2_PT_FIXED + 17, + TPM2_PT_PCR_COUNT = TPM2_PT_FIXED + 18, + TPM2_PT_PCR_SELECT_MIN = TPM2_PT_FIXED + 19, + TPM2_PT_CONTEXT_GAP_MAX = TPM2_PT_FIXED + 20, + TPM2_PT_NV_COUNTERS_MAX = TPM2_PT_FIXED + 22, + TPM2_PT_NV_INDEX_MAX = TPM2_PT_FIXED + 23, + TPM2_PT_MEMORY = TPM2_PT_FIXED + 24, + TPM2_PT_CLOCK_UPDATE = TPM2_PT_FIXED + 25, + TPM2_PT_CONTEXT_HASH = TPM2_PT_FIXED + 26, + TPM2_PT_CONTEXT_SYM = TPM2_PT_FIXED + 27, + TPM2_PT_CONTEXT_SYM_SIZE = TPM2_PT_FIXED + 28, + TPM2_PT_ORDERLY_COUNT = TPM2_PT_FIXED + 29, + TPM2_PT_MAX_COMMAND_SIZE = TPM2_PT_FIXED + 30, + TPM2_PT_MAX_RESPONSE_SIZE = TPM2_PT_FIXED + 31, + TPM2_PT_MAX_DIGEST = TPM2_PT_FIXED + 32, + TPM2_PT_MAX_OBJECT_CONTEXT = TPM2_PT_FIXED + 33, + TPM2_PT_MAX_SESSION_CONTEXT = TPM2_PT_FIXED + 34, + TPM2_PT_PS_FAMILY_INDICATOR = TPM2_PT_FIXED + 35, + TPM2_PT_PS_LEVEL = TPM2_PT_FIXED + 36, + TPM2_PT_PS_REVISION = TPM2_PT_FIXED + 37, + TPM2_PT_PS_DAY_OF_YEAR = TPM2_PT_FIXED + 38, + TPM2_PT_PS_YEAR = TPM2_PT_FIXED + 39, + TPM2_PT_SPLIT_MAX = TPM2_PT_FIXED + 40, + TPM2_PT_TOTAL_COMMANDS = TPM2_PT_FIXED + 41, + TPM2_PT_LIBRARY_COMMANDS = TPM2_PT_FIXED + 42, + TPM2_PT_VENDOR_COMMANDS = TPM2_PT_FIXED + 43, + TPM2_PT_NV_BUFFER_MAX = TPM2_PT_FIXED + 44, + TPM2_PT_MODES = TPM2_PT_FIXED + 45, + TPM2_PT_MAX_CAP_BUFFER = TPM2_PT_FIXED + 46, + TPM2_PT_VAR = TPM2_PT_GROUP * 2, + TPM2_PT_PERMANENT = TPM2_PT_VAR + 0, + TPM2_PT_STARTUP_CLEAR = TPM2_PT_VAR + 1, + TPM2_PT_HR_NV_INDEX = TPM2_PT_VAR + 2, + TPM2_PT_HR_LOADED = TPM2_PT_VAR + 3, + TPM2_PT_HR_LOADED_AVAIL = TPM2_PT_VAR + 4, + TPM2_PT_HR_ACTIVE = TPM2_PT_VAR + 5, + TPM2_PT_HR_ACTIVE_AVAIL = TPM2_PT_VAR + 6, + TPM2_PT_HR_TRANSIENT_AVAIL = TPM2_PT_VAR + 7, + TPM2_PT_HR_PERSISTENT = TPM2_PT_VAR + 8, + TPM2_PT_HR_PERSISTENT_AVAIL = TPM2_PT_VAR + 9, + TPM2_PT_NV_COUNTERS = TPM2_PT_VAR + 10, + TPM2_PT_NV_COUNTERS_AVAIL = TPM2_PT_VAR + 11, + TPM2_PT_ALGORITHM_SET = TPM2_PT_VAR + 12, + TPM2_PT_LOADED_CURVES = TPM2_PT_VAR + 13, + TPM2_PT_LOCKOUT_COUNTER = TPM2_PT_VAR + 14, + TPM2_PT_MAX_AUTH_FAIL = TPM2_PT_VAR + 15, + TPM2_PT_LOCKOUT_INTERVAL = TPM2_PT_VAR + 16, + TPM2_PT_LOCKOUT_RECOVERY = TPM2_PT_VAR + 17, + TPM2_PT_NV_WRITE_RECOVERY = TPM2_PT_VAR + 18, + TPM2_PT_AUDIT_COUNTER_0 = TPM2_PT_VAR + 19, + TPM2_PT_AUDIT_COUNTER_1 = TPM2_PT_VAR + 20, +}; /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 * bytes, but 128 is still a relatively large number of random bytes and