From nobody Fri Sep 02 11:19:45 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MJwRj3BdJz4bmnF; Fri, 2 Sep 2022 11:19:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MJwRj2gxFz40CB; Fri, 2 Sep 2022 11:19:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662117585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IixzPB2FBIK4K2ZMEH94r4QgdXH+UkayqS0pRfwbnW8=; b=iBqhj2IXoWN1wNBYoLt2Ozm2wWtWiXctm8IF7Hoo0fhXFC5A+J+BsJQK33Ccf+IefezXRk Gm+8BRK5V1GFgvtJIcnLWeYKJPiwEao1qNwMovaV+otUMZJqBc07uq+rZCOs11X84Dh3A1 l9MtsFUXg8oQG52jGdFntE18Du2A1ZagtsePzP4o4CggKxEeuWbUdDlU3gT/yL1ytsBhda nNxiFbtnGVsFpqJaRo9liytDIgfZ6j411qQhPdIgF4n3CHR52DzKfruxFZbhUI8RmYhDV8 B0C4HbPaS4FVjPKCLiMMjmUYbvhZ23JNrL8qZEYhRfJN71xqJr8L65l9EXZNDA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MJwRj1hDPznjl; Fri, 2 Sep 2022 11:19:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 282BJj2D046132; Fri, 2 Sep 2022 11:19:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 282BJjOT046131; Fri, 2 Sep 2022 11:19:45 GMT (envelope-from git) Date: Fri, 2 Sep 2022 11:19:45 GMT Message-Id: <202209021119.282BJjOT046131@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Kornel=20Dul=C4=99ba?= Subject: git: e23ad9c4ba2d - main - tpm: Fix entropy harvesting logic List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kd X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e23ad9c4ba2d2fd235fc3dc988ca422ef4e7ca3b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662117585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IixzPB2FBIK4K2ZMEH94r4QgdXH+UkayqS0pRfwbnW8=; b=rn704w5VRUzh1aexlxfm9yEpMFuWT0xP4UTclZklaLA60uxvUbTWMCQH9iBV8JOZ41GHQX FrHuCzQIYrSyeDjesDSBmzKdpXHFkvRVTD6GqARoBL3CPbtWqf83Ri5eKxLBIuuy7VNMqT UVTbtMc2yMI7ZtMi03RxkI4EFBE/W2pJfqKH3ru9mjXQNnYA168q3VYPMG93wLaEj6zcLP mfWQS7nJ4QvnyhNr1+cSlVEICIJTTzK86Wv0uwac6WZZjxV9Ew79AZhmIKAA8SjOP06YTB TjexIaCLYJ8usuFkTbYH9MBzHg7ynt7d2ILGaJBYem3u76jKpBz/n5UNaJOUXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662117585; a=rsa-sha256; cv=none; b=KCL+FnTv0zXh4WeV/7NbZwSKGke6qbQmkz/0FFL9+oM+/ST6T4CpGL48d8Z0yvZiW0UPMi 6o9xK+6MCtSOB7Enu7IgsButasf+LxKSR1hK0WoyDg36PblpWwmw8gVUpInYdKRohSlN+a Eury9+un9wRD9rRbBzf4TdVp4T2kr5U53zl9/bzD/FpPfJSuerHLUBNBnCcIITOhjK1zen DTVWWyC2PzsrxWVQKnkblpZKfhf1HTZq3QooLJgp9wljkIwQscl+j0b6RBKELRgxAeeICq /fQi/I6HU0FUYYQfYeBHniXLzvfExCi8VqhDizpeIIP4FUhfZ0BK87RdIrDQ+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kd: URL: https://cgit.FreeBSD.org/src/commit/?id=e23ad9c4ba2d2fd235fc3dc988ca422ef4e7ca3b commit e23ad9c4ba2d2fd235fc3dc988ca422ef4e7ca3b Author: Kornel Dulęba AuthorDate: 2022-09-02 11:07:03 +0000 Commit: Kornel Dulęba CommitDate: 2022-09-02 11:09:41 +0000 tpm: Fix entropy harvesting logic Use a taskqueue instead of a callout. Callout functions mustn't sleep, where as the TPM driver uses a sx lock in order to serialize accesses to the device. Since the entropy harvesting feature is not enabled by default, this commit should not bring any functional changes to the GENERIC kernel. Approved by: mw(mentor) Sponsored by: Stormshield Obtained from: Semihalf MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D36412 --- sys/dev/tpm/tpm20.c | 24 +++++++++++++----------- sys/dev/tpm/tpm20.h | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c index 68a30cfb51dd..3f444176732c 100644 --- a/sys/dev/tpm/tpm20.c +++ b/sys/dev/tpm/tpm20.c @@ -39,13 +39,13 @@ __FBSDID("$FreeBSD$"); * we don't want to execute this too often * as the chip is likely to be used by others too. */ -#define TPM_HARVEST_INTERVAL 10000000 +#define TPM_HARVEST_INTERVAL 10 MALLOC_DEFINE(M_TPM20, "tpm_buffer", "buffer for tpm 2.0 driver"); static void tpm20_discard_buffer(void *arg); #ifdef TPM_HARVEST -static void tpm20_harvest(void *arg); +static void tpm20_harvest(void *arg, int unused); #endif static int tpm20_save_state(device_t dev, bool suspend); @@ -192,11 +192,6 @@ tpm20_init(struct tpm_sc *sc) cv_init(&sc->buf_cv, "TPM buffer cv"); callout_init(&sc->discard_buffer_callout, 1); -#ifdef TPM_HARVEST - sc->harvest_ticks = TPM_HARVEST_INTERVAL / tick; - callout_init(&sc->harvest_callout, 1); - callout_reset(&sc->harvest_callout, 0, tpm20_harvest, sc); -#endif sc->pending_data_length = 0; make_dev_args_init(&args); @@ -209,6 +204,12 @@ tpm20_init(struct tpm_sc *sc) if (result != 0) tpm20_release(sc); +#ifdef TPM_HARVEST + TIMEOUT_TASK_INIT(taskqueue_thread, &sc->harvest_task, 0, + tpm20_harvest, sc); + taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0); +#endif + return (result); } @@ -218,7 +219,8 @@ tpm20_release(struct tpm_sc *sc) { #ifdef TPM_HARVEST - callout_drain(&sc->harvest_callout); + if (device_is_attached(sc->dev)) + taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task); #endif if (sc->buf != NULL) @@ -243,13 +245,12 @@ tpm20_shutdown(device_t dev) } #ifdef TPM_HARVEST - /* * Get TPM_HARVEST_SIZE random bytes and add them * into system entropy pool. */ static void -tpm20_harvest(void *arg) +tpm20_harvest(void *arg, int unused) { struct tpm_sc *sc; unsigned char entropy[TPM_HARVEST_SIZE]; @@ -290,7 +291,8 @@ tpm20_harvest(void *arg) if (entropy_size > 0) random_harvest_queue(entropy, entropy_size, RANDOM_PURE_TPM); - callout_reset(&sc->harvest_callout, sc->harvest_ticks, tpm20_harvest, sc); + taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, + hz * TPM_HARVEST_INTERVAL); } #endif /* TPM_HARVEST */ diff --git a/sys/dev/tpm/tpm20.h b/sys/dev/tpm/tpm20.h index 6911ca0cb6fe..bda4987120b0 100644 --- a/sys/dev/tpm/tpm20.h +++ b/sys/dev/tpm/tpm20.h @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -125,8 +126,7 @@ struct tpm_sc { struct callout discard_buffer_callout; #ifdef TPM_HARVEST - struct callout harvest_callout; - int harvest_ticks; + struct timeout_task harvest_task; #endif int (*transmit)(struct tpm_sc *, size_t);