All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Claudio Carvalho <cclaudio@linux.ibm.com>,
	Peter Huewe <peterhuewe@gmx.de>,
	x86@kernel.org, Dov Murik <dovmurik@linux.ibm.com>,
	linux-coco@lists.linux.dev, Dionna Glaze <dionnaglaze@google.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Ingo Molnar <mingo@redhat.com>, Joerg Roedel <jroedel@suse.de>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [RFC PATCH v2 4/6] tpm: add interface to interact with devices based on TCG Simulator
Date: Sat, 1 Mar 2025 03:48:35 +0200	[thread overview]
Message-ID: <Z8JncxQM7Nkit0Q6@kernel.org> (raw)
In-Reply-To: <20250228170720.144739-5-sgarzare@redhat.com>

On Fri, Feb 28, 2025 at 06:07:18PM +0100, Stefano Garzarella wrote:
> This is primarily designed to support an enlightened driver for the

The commit message is half-way cut.

I.e. it lacks the explanation of "this".

> AMD SVSM based vTPM, but it could be used by any TPM driver which
> communicates with a TPM device implemented through the TCG TPM reference
> implementation (https://github.com/TrustedComputingGroup/TPM)
> 
> Co-developed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> Co-developed-by: Claudio Carvalho <cclaudio@linux.ibm.com>
> Signed-off-by: Claudio Carvalho <cclaudio@linux.ibm.com>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> James, Claudio are you fine with the Cdb, Sob?
> The code is based to what was in the initial RFC, but I removed the
> tpm_platform module, moved some code in the header, changed some names,
> etc.
> For these reasons I reset the author but added C-o-b.
> Please, let me know if this is okay or if I need to do anything
> else (reset the author, etc.)
> ---
>  include/linux/tpm_tcgsim.h | 136 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 136 insertions(+)
>  create mode 100644 include/linux/tpm_tcgsim.h
> 
> diff --git a/include/linux/tpm_tcgsim.h b/include/linux/tpm_tcgsim.h
> new file mode 100644
> index 000000000000..bd5b123c393b
> --- /dev/null
> +++ b/include/linux/tpm_tcgsim.h
> @@ -0,0 +1,136 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2023 James.Bottomley@HansenPartnership.com
> + * Copyright (C) 2025 Red Hat, Inc. All Rights Reserved.
> + *
> + * Generic interface usable by TPM drivers interacting with devices
> + * implemented through the TCG Simulator.
> + */
> +#ifndef _TPM_TCGSIM_H_
> +#define _TPM_TCGSIM_H_
> +
> +#include <linux/errno.h>
> +#include <linux/string.h>
> +#include <linux/types.h>
> +
> +/*
> + * The current TCG Simulator TPM commands we support.  The complete list is
> + * in the TcpTpmProtocol header:
> + *
> + * https://github.com/TrustedComputingGroup/TPM/blob/main/TPMCmd/Simulator/include/TpmTcpProtocol.h

We should not be dependent on any out-of-tree headers.

> + */
> +
> +#define TPM_SEND_COMMAND		8
> +#define TPM_SIGNAL_CANCEL_ON		9
> +#define TPM_SIGNAL_CANCEL_OFF		10
> +/*
> + * Any platform specific commands should be placed here and should start
> + * at 0x8000 to avoid clashes with the TCG Simulator protocol.  They should
> + * follow the same self describing buffer format below.
> + */
> +
> +#define TPM_TCGSIM_MAX_BUFFER		4096 /* max req/resp buffer size */
> +
> +/**
> + * struct tpm_req - generic request header for single word command
> + *
> + * @cmd:	The command to send
> + */
> +struct tpm_req {
> +	u32 cmd;
> +} __packed;
> +
> +/**
> + * struct tpm_resp - generic response header
> + *
> + * @size:	The response size (zero if nothing follows)
> + *
> + * Note: most TCG Simulator commands simply return zero here with no indication
> + * of success or failure.
> + */
> +struct tpm_resp {
> +	u32 size;
> +} __packed;
> +
> +/**
> + * struct tpm_send_cmd_req - Structure for a TPM_SEND_COMMAND request
> + *
> + * @hdr:	The request header whit the command (must be TPM_SEND_COMMAND)
> + * @locality:	The locality
> + * @inbuf_size:	The size of the input buffer following
> + * @inbuf:	A buffer of size inbuf_size
> + *
> + * Note that TCG Simulator expects @inbuf_size to be equal to the size of the
> + * specific TPM command, otherwise an TPM_RC_COMMAND_SIZE error is
> + * returned.
> + */
> +struct tpm_send_cmd_req {
> +	struct tpm_req hdr;
> +	u8 locality;
> +	u32 inbuf_size;
> +	u8 inbuf[];
> +} __packed;
> +
> +/**
> + * struct tpm_send_cmd_req - Structure for a TPM_SEND_COMMAND response
> + *
> + * @hdr:	The response header whit the following size
> + * @outbuf:	A buffer of size hdr.size
> + */
> +struct tpm_send_cmd_resp {
> +	struct tpm_resp hdr;
> +	u8 outbuf[];
> +} __packed;
> +
> +/**
> + * tpm_tcgsim_fill_send_cmd() - fill a struct tpm_send_cmd_req to be sent to the
> + * TCG Simulator.
> + * @req: The struct tpm_send_cmd_req to fill
> + * @locality: The locality
> + * @buf: The buffer from where to copy the payload of the command
> + * @len: The size of the buffer
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +static inline int
> +tpm_tcgsim_fill_send_cmd(struct tpm_send_cmd_req *req, u8 locality,
> +			 const u8 *buf, size_t len)
> +{
> +	if (len > TPM_TCGSIM_MAX_BUFFER - sizeof(*req))
> +		return -EINVAL;
> +
> +	req->hdr.cmd = TPM_SEND_COMMAND;
> +	req->locality = locality;
> +	req->inbuf_size = len;
> +
> +	memcpy(req->inbuf, buf, len);
> +
> +	return 0;
> +}
> +
> +/**
> + * tpm_tcgsim_parse_send_cmd() - Parse a struct tpm_send_cmd_resp received from
> + * the TCG Simulator
> + * @resp: The struct tpm_send_cmd_resp to parse
> + * @buf: The buffer where to copy the response
> + * @len: The size of the buffer
> + *
> + * Return: buffer size filled with the response on success, negative error
> + * code on failure.
> + */
> +static inline int
> +tpm_tcgsim_parse_send_cmd(const struct tpm_send_cmd_resp *resp, u8 *buf,
> +			  size_t len)
> +{
> +	if (len < resp->hdr.size)
> +		return -E2BIG;
> +
> +	if (resp->hdr.size > TPM_TCGSIM_MAX_BUFFER - sizeof(*resp))
> +		return -EINVAL;  // Invalid response from the platform TPM
> +
> +	memcpy(buf, resp->outbuf, resp->hdr.size);
> +
> +	return resp->hdr.size;
> +}
> +
> +#endif /* _TPM_TCGSIM_H_ */
> -- 
> 2.48.1
> 

This commit got me lost tbh.

BR, Jarkko

  reply	other threads:[~2025-03-01  1:48 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 17:07 [RFC PATCH v2 0/6] Enlightened vTPM support for SVSM on SEV-SNP Stefano Garzarella
2025-02-28 17:07 ` [RFC PATCH v2 1/6] x86/sev: add SVSM call macros for the vTPM protocol Stefano Garzarella
2025-03-10 11:08   ` Borislav Petkov
2025-03-10 12:13     ` Stefano Garzarella
2025-02-28 17:07 ` [RFC PATCH v2 2/6] x86/sev: add SVSM vTPM probe/send_command functions Stefano Garzarella
2025-03-10 11:30   ` Borislav Petkov
2025-03-10 12:46     ` Stefano Garzarella
2025-03-10 13:27       ` Tom Lendacky
2025-03-10 13:51         ` Borislav Petkov
2025-03-10 13:56           ` Tom Lendacky
2025-03-10 14:02             ` Borislav Petkov
2025-03-10 13:59           ` Stefano Garzarella
2025-03-10 14:04             ` Borislav Petkov
2025-02-28 17:07 ` [RFC PATCH v2 3/6] tpm: add send_recv() ops in tpm_class_ops Stefano Garzarella
2025-03-01  1:45   ` Jarkko Sakkinen
2025-03-03 16:21     ` Stefano Garzarella
2025-03-04 16:56       ` Jarkko Sakkinen
2025-03-04 20:21         ` Jarkko Sakkinen
2025-03-05  9:04           ` Stefano Garzarella
2025-03-05 19:02             ` Jason Gunthorpe
2025-03-06 21:52               ` Jarkko Sakkinen
2025-03-07 15:37                 ` Stefano Garzarella
2025-03-07 16:32                   ` Jarkko Sakkinen
2025-03-06 22:15             ` Jarkko Sakkinen
2025-03-07 15:37               ` Stefano Garzarella
2025-03-03 14:06   ` Tom Lendacky
2025-03-03 17:29     ` Stefano Garzarella
2025-02-28 17:07 ` [RFC PATCH v2 4/6] tpm: add interface to interact with devices based on TCG Simulator Stefano Garzarella
2025-03-01  1:48   ` Jarkko Sakkinen [this message]
2025-03-03 16:41     ` Stefano Garzarella
2025-03-04 15:23     ` Stefano Garzarella
2025-03-04 17:14       ` Jarkko Sakkinen
2025-03-03 14:28   ` Tom Lendacky
2025-03-03 17:30     ` Stefano Garzarella
2025-02-28 17:07 ` [RFC PATCH v2 5/6] tpm: add SNP SVSM vTPM driver Stefano Garzarella
2025-03-01  0:28   ` Jason Gunthorpe
2025-03-03 16:19     ` Stefano Garzarella
2025-03-03 18:24       ` Jason Gunthorpe
2025-03-01  1:51   ` Jarkko Sakkinen
2025-03-01  3:57     ` Dionna Amalie Glaze
2025-03-03 16:46     ` Stefano Garzarella
2025-03-04 17:27       ` Jarkko Sakkinen
2025-03-05  9:07         ` Stefano Garzarella
2025-02-28 17:07 ` [RFC PATCH v2 6/6] x86/sev: register tpm-svsm platform device Stefano Garzarella
2025-03-01  0:30 ` [RFC PATCH v2 0/6] Enlightened vTPM support for SVSM on SEV-SNP Jason Gunthorpe
2025-03-03 16:20   ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z8JncxQM7Nkit0Q6@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=bp@alien8.de \
    --cc=cclaudio@linux.ibm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dionnaglaze@google.com \
    --cc=dovmurik@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=jgg@ziepe.ca \
    --cc=jroedel@suse.de \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterhuewe@gmx.de \
    --cc=sgarzare@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.