From nobody Fri Jun 16 06:23:02 2023 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 4Qj8Gv2TvHz4fK1t; Fri, 16 Jun 2023 06:23:03 +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 4Qj8Gv1Nmxz3w4g; Fri, 16 Jun 2023 06:23:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896583; 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=j2EGhL/LF9jIRODXoYdKIwsx1FlHGF3H2zoxfNGDi1o=; b=R8vhdSdiuLLbjbgx7Rzp3L2f3v//r8EfWJApnD8M86/52OosBR3OLpdottdvmr649N/+kX qa71raVs659xlEj5Qk6s4zNsm5/LYnIIK5s7oRZ1dJxbglWHObwsu38HBmSgWgADogGJln MRBSvOtxoWZOeB8XrnphO9w5UfPTPAdp6IHiOcri4XmrEEnKpaMKQLyHnMze2ifF4dsR+v 9poSVGp7Est309KfXbysbNeh0y7W1nZ58Gw53MOddHeEo5up0oVq9Mzw9qssgHDLhPZ82V pESj2EbfO7U1pNH3yi3Zg+tDaM3GJ0GQp0gXwTDkk2zuEjseq3VuhcP3pbkzcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896583; 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=j2EGhL/LF9jIRODXoYdKIwsx1FlHGF3H2zoxfNGDi1o=; b=mhFoCX3BXr6BqxrdS1iV4KuZomRjaOebNostpHEr7dy0TWf6JJvwGu/W17FTo5tgOaphkP qLuNIKapvDRg/RY5l6EEKBCAPd59U2TDcJhVsIQwIjSz9ADVihj++EEZVKou7RYLE9N2Iu 49kNpxykklzQp67MYWeVIx/bluVX2zXh9G3CjeF4AcJsXFpuG1cjeHhdhu/qZboP6zrOOP RJHCIWvBboqiBUlTZTvr75c39AJ60r2QbWMx8qmixFZPviwAPZw1wUupWyZ7azeinzJZGI QwL4+Q305TtiPt70cCBWXrhq8/e3mHtbMbjJbyqj2ZqaOITalN5hrjylGgkbjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686896583; a=rsa-sha256; cv=none; b=JBdlYR1iPpgXaaoP9qRLfMVOiehdiC8JWh5Wxkw0ZLsjE1Um1p/FEw7DCa+79lnqDnd0oK wuUIVR537Eq2ycz6Er+Eg9AbdW6QbsYex0TmDH3dMuz3l+zENldm/spTHvxQoJiJYCUn9o 2YZ16jG4OTlXsX/NPVJj70nR5klkqEaHFWF3Y/5pec+TEQRug9MHhXHrgtTvTvRjVJMjVp lifULBDs6aUvW30108SqQUv1GKWCjNF3FkYyWP4svRGBNBZT/gMOYjKCH2m//mNfLYJfuu WqhHTlXDvGdJ0Jq+mBWD61lPrvt4F6sdFdjBiL56fgGzj57JcZ7Vuy7E1XXafQ== 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 4Qj8Gv05zPzHZ1; Fri, 16 Jun 2023 06:23:03 +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 35G6N2ee051603; Fri, 16 Jun 2023 06:23:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35G6N2KX051602; Fri, 16 Jun 2023 06:23:02 GMT (envelope-from git) Date: Fri, 16 Jun 2023 06:23:02 GMT Message-Id: <202306160623.35G6N2KX051602@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: e09778575817 - main - bhyve: add basic TPM emulation struct 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e09778575817badd574389382317b46b4213ecf4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=e09778575817badd574389382317b46b4213ecf4 commit e09778575817badd574389382317b46b4213ecf4 Author: Corvin Köhne AuthorDate: 2023-05-15 11:49:42 +0000 Commit: Corvin Köhne CommitDate: 2023-06-16 06:18:39 +0000 bhyve: add basic TPM emulation struct This struct will be used to implement various TPM emulations like a TPM passthrough or a virtual TPM. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40454 --- usr.sbin/bhyve/tpm_device.c | 29 +++++++++++++++++++++++++++++ usr.sbin/bhyve/tpm_emul.h | 22 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/usr.sbin/bhyve/tpm_device.c b/usr.sbin/bhyve/tpm_device.c index e48f9df14701..3a847cc53a9b 100644 --- a/usr.sbin/bhyve/tpm_device.c +++ b/usr.sbin/bhyve/tpm_device.c @@ -17,13 +17,18 @@ #include "acpi_device.h" #include "config.h" #include "tpm_device.h" +#include "tpm_emul.h" #define TPM_ACPI_DEVICE_NAME "TPM" #define TPM_ACPI_HARDWARE_ID "MSFT0101" +SET_DECLARE(tpm_emul_set, struct tpm_emul); + struct tpm_device { struct vmctx *vm_ctx; struct acpi_device *acpi_dev; + struct tpm_emul *emul; + void *emul_sc; }; static const struct acpi_device_emul tpm_acpi_device_emul = { @@ -37,6 +42,9 @@ tpm_device_destroy(struct tpm_device *const dev) if (dev == NULL) return; + if (dev->emul != NULL && dev->emul->deinit != NULL) + dev->emul->deinit(dev->emul_sc); + acpi_device_destroy(dev->acpi_dev); free(dev); } @@ -46,6 +54,7 @@ tpm_device_create(struct tpm_device **const new_dev, struct vmctx *const vm_ctx, nvlist_t *const nvl) { struct tpm_device *dev = NULL; + struct tpm_emul **ppemul; const char *value; int error; @@ -75,6 +84,26 @@ tpm_device_create(struct tpm_device **const new_dev, struct vmctx *const vm_ctx, if (error) goto err_out; + value = get_config_value_node(nvl, "type"); + assert(value != NULL); + SET_FOREACH(ppemul, tpm_emul_set) { + if (strcmp(value, (*ppemul)->name)) + continue; + dev->emul = *ppemul; + break; + } + if (dev->emul == NULL) { + warnx("TPM emulation \"%s\" not found", value); + error = EINVAL; + goto err_out; + } + + if (dev->emul->init) { + error = dev->emul->init(&dev->emul_sc, nvl); + if (error) + goto err_out; + } + *new_dev = dev; return (0); diff --git a/usr.sbin/bhyve/tpm_emul.h b/usr.sbin/bhyve/tpm_emul.h new file mode 100644 index 000000000000..f75c0318d37e --- /dev/null +++ b/usr.sbin/bhyve/tpm_emul.h @@ -0,0 +1,22 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#pragma once + +#include + +#include "config.h" + +struct tpm_device; + +struct tpm_emul { + const char *name; + + int (*init)(void **sc, nvlist_t *nvl); + void (*deinit)(void *sc); +}; +#define TPM_EMUL_SET(x) DATA_SET(tpm_emul_set, x)