From nobody Fri Sep 09 13:25:50 2022 X-Original-To: dev-commits-src-branches@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 4MPGvz06Knz4bPS5; Fri, 9 Sep 2022 13:25:51 +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 4MPGvy6flMz3flG; Fri, 9 Sep 2022 13:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662729950; 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=soROXieg5/TW0ZAoHa7tQ/OlUQ2OKWp3icCGmYRIo/s=; b=LZKNg8RaxBP104te9cKkI78Obl4iYB55Dzh28GFQGQHw3PRSNB/yGpWWXVhJc+A6behMQq Fo5NHS0sZtegMRtyHPWCMQTjNng20e7rsv9JvEbZZofjqxxjD409R2OZ2WUtyPF5NGkpEB fTYx80Z/SbCZYd9+OG2Yu7JWmDUqLnr+Onrt7xHwvJqvfa9YSeDlydS8jOwro5rlGOR8jh FifMpRamgYDpBOng8ZmxK5h0pYQ/FeqjsQsbmJnrc5S0O+YZ0hO8Pf+THMNajDewmcux6a 0Id7kJTejP3/DrsgpeHZWM/nHtAKwiwZe2cYI3+7Lg9Pt+7KsnECxTABRRe8Vw== 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 4MPGvy5gFvz1DBq; Fri, 9 Sep 2022 13:25:50 +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 289DPoSK057028; Fri, 9 Sep 2022 13:25:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 289DPoNj057027; Fri, 9 Sep 2022 13:25:50 GMT (envelope-from git) Date: Fri, 9 Sep 2022 13:25:50 GMT Message-Id: <202209091325.289DPoNj057027@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Kornel=20Dul=C4=99ba?= Subject: git: cbe3966fb9c9 - stable/13 - tpm: Fix entropy harvesting logic List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: cbe3966fb9c9990bdc66798e18b180d1712d95b9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662729950; 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=soROXieg5/TW0ZAoHa7tQ/OlUQ2OKWp3icCGmYRIo/s=; b=GUwPnhacBibGKIiaLh27usf03jzjI6wMh7a8Y3/rou8B8prZww77y94ITxiv4vpfPrv9NE H0EUpJJkzlHfj85HqyecsGn3dRhZLAfoje1KcVAOrnO5h1PeGsPI6VOh+A042OB4dkyQka cx+bL6YGAN3f9RomLtAQkeFSC9FtX6rvafxNgU9qMGMIwUqvhUNkQ1haNrpC0pWIoyshID GgT+c+zorJIcOwEz89oCi7yIY3kuMw4IUJzOzJGqxXSxtgF0A2T2DDYGpca4Zsbtyx+Rrh aKZWWxHRRdTcUVs/8gaC33v68C8iV1KaCJ9UMMWGDZF37ETsu/dtwePWCanDOg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662729950; a=rsa-sha256; cv=none; b=lvCNBmRiJEPi8/de3+WWBUVkhQC10weSu5/VtLwcFJMOQ2giVLRDCgPWGMMsmg8EDzA5Z1 KThxE2h37pRZ+KyFUSmz17RF0Ga6/RLLx6etYMRxcAcPodKCA7dCLh0VYExQ638R2WKhLN mJ0Nx00OEdgczvDslvGwH14Sq13MxMXQ+Nm0UOzQ4F4P6UxDMZAZXrFzit/1g4Zc01JLmP CgPkZxLG1cceemJmjGhUfL2FTkzNuRwyK0Q1mzVj8B+cDgh9i+oBHy1EnOJV/2UVS06RxX zNHYacGdfQuHpmihUd+caIfFKE8s0uwEKabmPp4f4Rk+HiaS5VX61KAA/6Yj9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kd: URL: https://cgit.FreeBSD.org/src/commit/?id=cbe3966fb9c9990bdc66798e18b180d1712d95b9 commit cbe3966fb9c9990bdc66798e18b180d1712d95b9 Author: Kornel Dulęba AuthorDate: 2022-09-02 11:07:03 +0000 Commit: Kornel Dulęba CommitDate: 2022-09-09 12:35:16 +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 (cherry picked from commit e23ad9c4ba2d2fd235fc3dc988ca422ef4e7ca3b) --- 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 eeddad85009d..ccd1c9cb25be 100644 --- a/sys/dev/tpm/tpm20.c +++ b/sys/dev/tpm/tpm20.c @@ -39,14 +39,14 @@ __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_DECLARE(M_TPM20); 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); @@ -195,11 +195,6 @@ tpm20_init(struct tpm_sc *sc) sx_init(&sc->dev_lock, "TPM driver lock"); 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); @@ -212,6 +207,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); } @@ -221,7 +222,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) @@ -246,13 +248,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]; @@ -293,7 +294,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 bafbd93dc136..fd1ab55a65e3 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 @@ -123,8 +124,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);