From nobody Fri Dec 19 04:37:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35E29263F2B for ; Tue, 8 Apr 2025 08:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101144; cv=none; b=JBWTeql+pPwm89QqEBf00P4ATVYnzSEeYfhkTnZg5eZfpbQQySE5/laXCKbUxQh483uJcfVqQoth3rL0k5EJlJZPp5TY8BDCdQ7rihtkLvS/675o9zcxdoNzy8mxVr0D+PE1yywc21HRQrODZyHGWTIsg2LRUTYWbchXG5SoJWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101144; c=relaxed/simple; bh=5MM8pORZWnScwf6ewALVw4cjhS6Azxp4msVUGK1bi68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TEjt7eHsy12Bzj33helk1XEMhFQYSS+yOaSpL3MXp2eC83NzAkumR6qW5ce+uXAlFHXcLXFs/Yi+IQgxlTnR8TjNSjtbYn9zbZr2xLJoeGqoygDABQOetnVrDPMBjW/F/QyqtXNZ7VWn/Aj8yV/nF0Ci7pxSE/YbPpNtH2FGbhE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Do/tZspE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Do/tZspE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zjSC2fEEv9F3kmldtv2lcizGFa35FlkMCGJDC9bTagU=; b=Do/tZspEyQj8VsJGb4oT+KoEgIcWTSrdgmjxjMvfqfSnbEDAgn+WdNONxJnrBqHXzOujox j/L/f++4VH5WRD8JG6avRr9RANosaCVsdQacNHcPrIMLqJZCWZv4+J1I5r17CjNQAlap6Z jnvjnnSyFaRIsrWCqCSSCf/t4y6uE10= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-TUtIWLaGNW6avatWCtm8xw-1; Tue, 08 Apr 2025 04:32:18 -0400 X-MC-Unique: TUtIWLaGNW6avatWCtm8xw-1 X-Mimecast-MFC-AGG-ID: TUtIWLaGNW6avatWCtm8xw_1744101138 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43cf172ffe1so43655965e9.3 for ; Tue, 08 Apr 2025 01:32:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101137; x=1744705937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zjSC2fEEv9F3kmldtv2lcizGFa35FlkMCGJDC9bTagU=; b=YhCz2+Bqj/QzjLuNIWMg9+yikOVXiUMuJhCbOm9Y1qvDTdQ8//y/0VzKwNbt23mtk3 Y73Vo3+M5k7TYcv6NRTz2OQhW7ShsmrjqG/a3i6YnwBMA8BZ+tDJUJ+kZdcgDcfMoYC0 jeivlxjnVtPuCr7aGjZ7nod+xeTYTMi04FkjftHown67RlOU85pDBaPW89YLnfrX7UBF IV1T1+QAlC530J0r2cOLg5awGGBll0o6tq2Z48YS9O5pabOn5XU3e6z8Sps5zXoOC9EP Vt6H/7AJ21FdMZS70HL+nCcws4bfQ8kT8E7jq8yxAGCd1YNVp7iDCg//GPrQfTAo80e+ q0Lg== X-Forwarded-Encrypted: i=1; AJvYcCWxVn3fklAQ/VaWTCefl9NEw4jsJT1+6jC0S3pZ49bIn662lMDGOZeJOJs6YFVcH/R5p+3FpfjYHkMpsis=@vger.kernel.org X-Gm-Message-State: AOJu0YyGwXHSeeKglMTfvHm/4fKQBM0rWS6nUoKR4LNEfDh+Lgc6LeAw XnX4nRzVncMvfWDhITw48IBIwVY7k8juxbegjCoVEzu37hV14z2ct1XCfoc+W4fObm7iv6qwaJI wdHaMLDGbSnFEFMDSwISu3AOejtA38AY0rSBWLxqaNGfT4L9y9RESn63Du6BIxA== X-Gm-Gg: ASbGncu2+SD5ANifHv2I0IzkAF4T1CswK5ixcGeB9THvwpxKdOnrH2x9LgoVE1l5i4p Hw9OVfwkGI77l9JFifenwwbC5KpBy5CRGhbPfrcXWqTXNducWoJJ7t5oTLEw/iie5cZVslgraf+ K5FQzoPKVvepbuyEepK8zZlFuC0XMh5O8/OxAv/Bvkv8UUgPmdeWQ4vSE9b8WfR23KA/c7Sp16x gVB1iNQOTZJepFTXwIGMkurZ8Ptdy72kxaYCYfhlOpitmFu3QFXapg+mQu6f/hJBYrMwJ8/NvTy 1rJfLKma7AG/bMhubkRGZuQ3aELhbnqmCkNpmXL3kxDZdaRaC4kq20UyXWJN4m2FMQ== X-Received: by 2002:a05:600c:3549:b0:43c:e481:3353 with SMTP id 5b1f17b1804b1-43ecf90aae2mr165784645e9.17.1744101137404; Tue, 08 Apr 2025 01:32:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1jLFoe9t+FYg7K9VMsmfzan32hNxAZLIXvfWMRelSw02WoNY+Bh5SYNrx5pWATENrhHoAVg== X-Received: by 2002:a05:600c:3549:b0:43c:e481:3353 with SMTP id 5b1f17b1804b1-43ecf90aae2mr165784005e9.17.1744101136729; Tue, 08 Apr 2025 01:32:16 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec342827fsm155384365e9.6.2025.04.08.01.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:15 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 1/4] tpm: add buf_size parameter in the .send callback Date: Tue, 8 Apr 2025 10:32:05 +0200 Message-ID: <20250408083208.43512-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella In preparation for the next commit, add a new `buf_size` parameter to the `.send` callback in `tpm_class_ops` which contains the entire buffer size. In this patch it is pretty much ignored by all drivers, but it will be used in the next patch. Also rename the previous parameter `len` to `cmd_len` in the declaration to make it clear that it contains the length in bytes of the command stored in the buffer. The semantics don't change and it can be used as before by drivers. This is an optimization since the drivers could get it from the header, but let's avoid duplicating code. While we are here, resolve a checkpatch warning: WARNING: Unnecessary space before function pointer arguments #66: FILE: include/linux/tpm.h:90: + int (*send) (struct tpm_chip *chip, u8 *buf, size_t cmd_len, Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- I'm not sure about 3 things about this patch: 1. Since `buf_size` is pretty much ignored, is it better to merge this patch with the next one? I kept it separate because we touch all the drivers here, so I think it's better to have this change in a separate patch to make it clear that we are not touching anything in the drivers, but I'm open to merge it if you prefer. 2. I avoided changing the previous parameter in the drivers (`len` or `count`) to keep the changes minimal, but if you prefer I can use `cmd_len` everywhere. 3. Fix the checkpatch warning mentioned in the description. Thanks, Stefano --- include/linux/tpm.h | 3 ++- drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm-interface.c | 2 +- drivers/char/tpm/tpm_atmel.c | 3 ++- drivers/char/tpm/tpm_crb.c | 2 +- drivers/char/tpm/tpm_ftpm_tee.c | 4 +++- drivers/char/tpm/tpm_i2c_atmel.c | 3 ++- drivers/char/tpm/tpm_i2c_infineon.c | 3 ++- drivers/char/tpm/tpm_i2c_nuvoton.c | 3 ++- drivers/char/tpm/tpm_ibmvtpm.c | 6 ++++-- drivers/char/tpm/tpm_infineon.c | 3 ++- drivers/char/tpm/tpm_nsc.c | 3 ++- drivers/char/tpm/tpm_svsm.c | 3 ++- drivers/char/tpm/tpm_tis_core.c | 3 ++- drivers/char/tpm/tpm_tis_i2c_cr50.c | 6 ++++-- drivers/char/tpm/tpm_vtpm_proxy.c | 4 +++- drivers/char/tpm/xen-tpmfront.c | 3 ++- 17 files changed, 37 insertions(+), 19 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 6c3125300c00..2e38edd5838c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -87,7 +87,8 @@ struct tpm_class_ops { const u8 req_complete_val; bool (*req_canceled)(struct tpm_chip *chip, u8 status); int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len); - int (*send) (struct tpm_chip *chip, u8 *buf, size_t len); + int (*send)(struct tpm_chip *chip, u8 *buf, size_t cmd_len, + size_t buf_size); void (*cancel) (struct tpm_chip *chip); u8 (*status) (struct tpm_chip *chip); void (*update_timeouts)(struct tpm_chip *chip, diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp= 24/st33zp24.c index c0771980bc2f..3de68bca1740 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -300,7 +300,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *= dev_id) * send TPM commands through the I2C bus. */ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, - size_t len) + size_t len, size_t buf_size) { struct st33zp24_dev *tpm_dev =3D dev_get_drvdata(&chip->dev); u32 status, i, size, ordinal; diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interf= ace.c index 8d7e4da6ed53..3b6ddcdb4051 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -106,7 +106,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, = void *buf, size_t bufsiz) return -E2BIG; } =20 - rc =3D chip->ops->send(chip, buf, count); + rc =3D chip->ops->send(chip, buf, count, bufsiz); if (rc < 0) { if (rc !=3D -EPIPE) dev_err(&chip->dev, diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c index 54a0360a3c95..5733168bfc26 100644 --- a/drivers/char/tpm/tpm_atmel.c +++ b/drivers/char/tpm/tpm_atmel.c @@ -148,7 +148,8 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf= , size_t count) return size; } =20 -static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_atmel_priv *priv =3D dev_get_drvdata(&chip->dev); int i; diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 876edf2705ab..38f765a44a97 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -426,7 +426,7 @@ static int tpm_crb_smc_start(struct device *dev, unsign= ed long func_id) } #endif =20 -static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len, size_t buf= _size) { struct crb_priv *priv =3D dev_get_drvdata(&chip->dev); int rc =3D 0; diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_te= e.c index 53ba28ccd5d3..637cc8b6599e 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -64,12 +64,14 @@ static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, = u8 *buf, size_t count) * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h * @buf: the buffer to send. * @len: the number of bytes to send. + * @buf_size: the size of the buffer. * * Return: * In case of success, returns 0. * On failure, -errno */ -static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct ftpm_tee_private *pvt_data =3D dev_get_drvdata(chip->dev.parent); size_t resp_len; diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_at= mel.c index d1d27fdfe523..572f97cb9e89 100644 --- a/drivers/char/tpm/tpm_i2c_atmel.c +++ b/drivers/char/tpm/tpm_i2c_atmel.c @@ -37,7 +37,8 @@ struct priv_data { u8 buffer[sizeof(struct tpm_header) + 25]; }; =20 -static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct priv_data *priv =3D dev_get_drvdata(&chip->dev); struct i2c_client *client =3D to_i2c_client(chip->dev.parent); diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c= _infineon.c index 81d8a78dc655..25d6ae3a4cc1 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -514,7 +514,8 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *= buf, size_t count) return size; } =20 -static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { int rc, status; ssize_t burstcnt; diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_= nuvoton.c index 3c3ee5f551db..169078ce6ac4 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -350,7 +350,8 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *= buf, size_t count) * tpm.c can skip polling for the data to be available as the interrupt is * waited for here */ -static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct priv_data *priv =3D dev_get_drvdata(&chip->dev); struct device *dev =3D chip->dev.parent; diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index 76d048f63d55..660a7f9da1d8 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -191,13 +191,15 @@ static int tpm_ibmvtpm_resume(struct device *dev) * tpm_ibmvtpm_send() - Send a TPM command * @chip: tpm chip struct * @buf: buffer contains data to send - * @count: size of buffer + * @count: length of the command + * @buf_size: size of the buffer * * Return: * 0 on success, * -errno on error */ -static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct ibmvtpm_dev *ibmvtpm =3D dev_get_drvdata(&chip->dev); bool retry =3D true; diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineo= n.c index 2d2ae37153ba..7896fdacd156 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -312,7 +312,8 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf= , size_t count) return -EIO; } =20 -static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) +static int tpm_inf_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { int i; int ret; diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 0f62bbc940da..12aedef3c50e 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -178,7 +178,8 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf= , size_t count) return size; } =20 -static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) +static int tpm_nsc_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_nsc_priv *priv =3D dev_get_drvdata(&chip->dev); u8 data; diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index b9242c9eab87..b8aa7eb567de 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -25,7 +25,8 @@ struct tpm_svsm_priv { void *buffer; }; =20 -static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct tpm_svsm_priv *priv =3D dev_get_drvdata(&chip->dev); int ret; diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_cor= e.c index ed0d3d8449b3..5641a73ce280 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -580,7 +580,8 @@ static int tpm_tis_send_main(struct tpm_chip *chip, con= st u8 *buf, size_t len) return rc; } =20 -static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { int rc, irq; struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis= _i2c_cr50.c index 3b55a7b05c46..1914b368472d 100644 --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c @@ -546,13 +546,15 @@ static int tpm_cr50_i2c_tis_recv(struct tpm_chip *chi= p, u8 *buf, size_t buf_len) * tpm_cr50_i2c_tis_send() - TPM transmission callback. * @chip: A TPM chip. * @buf: Buffer to send. - * @len: Buffer length. + * @len: Command length. + * @buf_size: Buffer size. * * Return: * - 0: Success. * - -errno: A POSIX error code. */ -static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t le= n) +static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t le= n, + size_t buf_size) { size_t burstcnt, limit, sent =3D 0; u8 tpm_go[4] =3D { TPM_STS_GO }; diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_= proxy.c index 8fe4a01eea12..beaa84428b49 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -322,11 +322,13 @@ static int vtpm_proxy_is_driver_command(struct tpm_ch= ip *chip, * @chip: tpm chip to use * @buf: send buffer * @count: bytes to send + * @buf_size: size of the buffer * * Return: * 0 in case of success, negative error value otherwise. */ -static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t c= ount) +static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t c= ount, + size_t buf_size) { struct proxy_dev *proxy_dev =3D dev_get_drvdata(&chip->dev); =20 diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfron= t.c index 80cca3b83b22..66a4dbb4a4d8 100644 --- a/drivers/char/tpm/xen-tpmfront.c +++ b/drivers/char/tpm/xen-tpmfront.c @@ -131,7 +131,8 @@ static size_t shr_data_offset(struct vtpm_shared_page *= shr) return struct_size(shr, extra_pages, shr->nr_extra_pages); } =20 -static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_private *priv =3D dev_get_drvdata(&chip->dev); struct vtpm_shared_page *shr =3D priv->shr; --=20 2.49.0 From nobody Fri Dec 19 04:37:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBDAF2641C6 for ; Tue, 8 Apr 2025 08:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101147; cv=none; b=Ui3JknRfhoW0tl1tKkgyPQGar8hGKXzgrDXquvFT6Mz081aZ3BjP3XTt4w51qepR7g+x8fsaI0Nacbw5wOGwBylSy3kuQl31r5woCCchUAOIwtBs6iTWh2XIJquUvJ7jJyLLZlhaEsNjokKMHibLz4nK8bkYCFJ5V6OGny9zyPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101147; c=relaxed/simple; bh=WvbgwlAGGsl+4IleITMI6e4y/KHe7f57c66lAWpy3NI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0+6As4D0UwJvix7cIBRSJHb4p2qy4ROWw9FYIH3I6TuqkIRPOjoEfBtIafljUN68YlPsDB34k4b0K+F2APXm2cVvCTzGIPuHe6SIe1oLzqUnHBWKEE49jwAa6RHZJ9hc/e5X8j3+z0j/GPRVZZ6dZzrhY91fHvB/gLgCg2J/hs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QzYIbl3l; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QzYIbl3l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDE/YZIPCEEz/h330X/plomZy4BudCgqspAc85dgVok=; b=QzYIbl3lvtm3aKVhR8N6vqyZcmVUPaBGR6S1oYXEaPRHX7m3zN89lrKRnW5kIiQCIpIv7m WUfC3sdtPLnMQ0LSEw0xnHM2yDomt4jA61TGaLhNGxRh3+/eCaKDZLsfStufrVqNTk9YCp Hx+fahkvYDTAMfP5iifjmk7w4j62KMs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-X8DMtTk6Oz2vdMnqLRvuBQ-1; Tue, 08 Apr 2025 04:32:23 -0400 X-MC-Unique: X8DMtTk6Oz2vdMnqLRvuBQ-1 X-Mimecast-MFC-AGG-ID: X8DMtTk6Oz2vdMnqLRvuBQ_1744101142 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43d51bd9b45so36341715e9.1 for ; Tue, 08 Apr 2025 01:32:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101142; x=1744705942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QDE/YZIPCEEz/h330X/plomZy4BudCgqspAc85dgVok=; b=SsbEZFOGSTGFoXMrQ0IsFP0ftEwqpfH4kFuiEULxNx+JHRUyFPKYmAg/WGzGYSU80C LMOLxYV/mIWwQfQjDJIyDUSEJAHsBBAfY9z1XYFtcjaCAdjI9PDQMspEtWmOqQIOX/cB Gzr1+d1mXGOJo4YEd4c679UxVUbjaRXrRDS8ddK7vM9JMm7/I058zubUHTNCy6Osk3B+ 1FzVn1Ulqr0UDem6QQR5mD0+o/RY2DcJPgHHxW3wKjn5ZHUiFgeG8sXkg8TntXFfYxVZ OqxC0vdmYF69B9o4I9zlhlvcxhQxKwl4oT1YZSl24p9Q8n1K38316ZVnMLo6mym6MJCz /V8Q== X-Forwarded-Encrypted: i=1; AJvYcCWiY+aupYBoF2bPPF/CDxgSGGDyZ4Fy8IVB2J1iNcR8rwWV7Sb8csId0ufVUjDursxSO5YmwBcwipGXPaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxykFYuQRkWxB5TqXKH+6J0Cq2OmMLUZOPUaCDdeeBkpzv1gjFB tNIIuqbYQX/sZucnGuNS+UlH+nvBFGp+IO8dJ9e4rKvc3L2UwJAD11lJp6rOVg2q+n9DK/LJiWz tKZlbhHRR9H+TdqCFLrdicYBGIHy+HyCaFUpx1nBzjEpE/0gKgbdVg8rwu7wg9srYXOSryA== X-Gm-Gg: ASbGnctjg+FAv6NOGOR/TYDKfCvavw0+uZ0XuntLdVfmknn38O9NoFTUnCwJAuRKPIE QwtD+JTtalOak3gscCA3SNJ8LoRR28pyfZhXjl7VpfewmIG+kUk+VG6MQSJUuX3JihHUpqKTcCT hTu6xWj5NQyH+3UVToCrsTwPI2B/2uAXlaDr27ASlatKP/q3teh/BVhfaiMmhJLac/vGc8yMIo4 5Ue2LW8RBUm4oYNf3oyZlqxWzteFRWnaQ8QxA9aluD0EsHDodgvIC+Ejb9tWvx2r2N0sd5s5v+3 3k13qvrLuRCOASPAZf2GRfwJrEQqsMQWDm0s48yDMX0db40W8ux4hsAkxAj1VRS0Tw== X-Received: by 2002:a05:600c:1e13:b0:439:8c80:6af4 with SMTP id 5b1f17b1804b1-43ecf8d0b48mr141342885e9.19.1744101141993; Tue, 08 Apr 2025 01:32:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQhp1MgrEqOjc+4MW66KZXrp62NtlwXCuZ1w3QWz8IsRQIARyOk/4wlryzdly6gRSlx08ezQ== X-Received: by 2002:a05:600c:1e13:b0:439:8c80:6af4 with SMTP id 5b1f17b1804b1-43ecf8d0b48mr141342355e9.19.1744101141383; Tue, 08 Apr 2025 01:32:21 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c3009680dsm14051923f8f.7.2025.04.08.01.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:20 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 2/4] tpm: support devices with synchronous send() Date: Tue, 8 Apr 2025 10:32:06 +0200 Message-ID: <20250408083208.43512-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella Some devices do not support interrupts and provide a single synchronous operation to send the command and receive the response on the same buffer. Currently, these types of drivers must use an internal buffer where they temporarily store the response between .send() and recv() calls. Introduce a new flag (TPM_CHIP_FLAG_SYNC) to support synchronous send(). If that flag is set by the driver, tpm_try_transmit() will use the send() callback to send the command and receive the response on the same buffer synchronously. In that case send() return the number of bytes of the response on success, or -errno on failure. Suggested-by: Jason Gunthorpe Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- include/linux/tpm.h | 1 + drivers/char/tpm/tpm-interface.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 2e38edd5838c..0e9746dc9d30 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -350,6 +350,7 @@ enum tpm_chip_flags { TPM_CHIP_FLAG_SUSPENDED =3D BIT(8), TPM_CHIP_FLAG_HWRNG_DISABLED =3D BIT(9), TPM_CHIP_FLAG_DISABLE =3D BIT(10), + TPM_CHIP_FLAG_SYNC =3D BIT(11), }; =20 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interf= ace.c index 3b6ddcdb4051..9fbe84b5a131 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -114,8 +114,17 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,= void *buf, size_t bufsiz) return rc; } =20 - /* A sanity check. send() should just return zero on success e.g. - * not the command length. + /* Synchronous devices return the response directly during the send() + * call in the same buffer. + */ + if (chip->flags & TPM_CHIP_FLAG_SYNC) { + len =3D rc; + rc =3D 0; + goto out_send_sync; + } + + /* A sanity check. send() of asynchronous devices should just return + * zero on success e.g. not the command length. */ if (rc > 0) { dev_warn(&chip->dev, @@ -151,7 +160,10 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,= void *buf, size_t bufsiz) if (len < 0) { rc =3D len; dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); - } else if (len < TPM_HEADER_SIZE || len !=3D be32_to_cpu(header->length)) + return rc; + } +out_send_sync: + if (len < TPM_HEADER_SIZE || len !=3D be32_to_cpu(header->length)) rc =3D -EFAULT; =20 return rc ? rc : len; --=20 2.49.0 From nobody Fri Dec 19 04:37:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4810C264615 for ; Tue, 8 Apr 2025 08:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101152; cv=none; b=FyotqXT9NtrKyg+2013PubpLsGpnccXq2YfNOoMIjKS1s/SN+5fKqasPYGNNwbDpnGwiLsx8L4VgQyi4GHCtGErPliZJF0bHPHDUsF8lUdpAcl1Kfk0QdUPaRwyqslJpFi1f7t8gbqDDDEhLLR4CXck/rmK1F3wQqYxWr5kjc4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101152; c=relaxed/simple; bh=U1qC/sy3KM3pFlSOrOxYv2VmI/J+Xj4HkqFlDY7nkB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J9tNrF3vxCXRRdYfj+nQZqitcPmDZKJJrrnmFe1eqbhPHVnk4ZfjxBEgb0LcufwunSqAsAdufzCOkQo2tufCTlS7LcbAtWPI+dQGY3FgbJmjrutrkrHWl3YpXlWqNepIuCViWHRLkSAFgKjo25PEQLCuPkOUkd91LKXzyLFlgBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ra7NiWGY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ra7NiWGY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0jjogm03xe8uH9FEbFpCE/wwTjsk8lbbHkAYLp5l0W8=; b=Ra7NiWGY0V4yEsseV5LOEAtiUvOTi+cknemd1ClGoKoo244WO5z3bkB9TiJoyu4OpVSeJd 1x4Ji27kZQtk1zEEJ6gUxFUXkPvAff8AIro/Zrmcm7Go7r0ziH1D8Bi79+bS9uTJz8ujk7 BAMgEZqq62VPgdeRMljK2BRClxjHyrg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-4QdoPkt2PfGjeOWtwAyaXg-1; Tue, 08 Apr 2025 04:32:28 -0400 X-MC-Unique: 4QdoPkt2PfGjeOWtwAyaXg-1 X-Mimecast-MFC-AGG-ID: 4QdoPkt2PfGjeOWtwAyaXg_1744101147 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43947a0919aso37696855e9.0 for ; Tue, 08 Apr 2025 01:32:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101147; x=1744705947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0jjogm03xe8uH9FEbFpCE/wwTjsk8lbbHkAYLp5l0W8=; b=cbQkdWcgeGAQJfP6YsWp2EiUoaajPt2wA+Nar0lLNSmUUkxhD4+O5gkGKmDZd5CBep CxxwNPjroJ3Cf3E+aCPbr63uIWizHQPLdfu/wM8GJlI2dqe6DU+UnrR+olS5NTPadQIy /5lpgilH68WpTTvccbw1wzsfCfMS7s5MpFsIWuXQ319QpkTsP0pkpvqZe9jxpBlVueIb 4zNLYcaKPfTBmzaGctinncP06AsOXQVzxLL6XVmn9xIsY9ynLRcxCU8bnJ8ENsKOXVLt zveiaOiNgPd4GGGoIMk5HFM5GnbKIwKtj5UOT57mEGaTE+8VSQ7dyhN4L6BtAax4iqZw ibNg== X-Forwarded-Encrypted: i=1; AJvYcCX8VC9jZHsa6/sVyQVVaqpjdkPZD7L0/Cg6D5PuwYw9cU6xYkVxmhZM4GKfd9tZFEI8AY/c4C51uqFgjRs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1mQz1WXjb7t+kWBEEQWU9ZM5e7PHvhtUt/SJaJYgwPbm/uRlA 3g/FgaKAdONoVOogKcGAYyqMxZI3lGEVFWc1BOCDZcxYkoloS/vbWa5C6w1Nm1lmN+v5XTUbXGB ISnoKbz9N3RvNU+VKAnpRpQj0JX2nRPLp5ekLkL+75z4eY1HxoS8D84268T/+Mw== X-Gm-Gg: ASbGncsi82PuR4G2z3lN8tqu83By6fGFp72ufWoszQbN1yYivhmB20VBhrt1l7g9Rhu DH2AbBecLtITfUQ+0MZtZvCzn3jG4W9Hg6eYg9G3L3nfGWXyBLAmjDk3LeuxOJnq1HrsCFUdIbC +X+FjnD+OZlHTZSCbbdixCQwohekRw6cA1y6NBrNTgROg9QJTrtMOjQ83oTD+uvrWbBAqSB3hCn O4jflC4ujoZV/euT/sdC+BTtVOrvQs0xs2Q2LjGIoTc/TjUvATlCI1TJG7tDX8X/Q5rcWuuZMHF 1FuUES/8IEOL5+28PxPJd3wbaXq2NlNm1E6cJlbVZ2mbxqhRPlOL6CPFmA942WfIVA== X-Received: by 2002:a05:600c:3489:b0:43c:f87c:24ce with SMTP id 5b1f17b1804b1-43ecf9c77ecmr122637465e9.21.1744101146618; Tue, 08 Apr 2025 01:32:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGO0mHtfU6tjdIaTwIU3mFKYSEAXTq1PTv+mq26VUWkOFRfaSqPIV+zWD9QaZteOnlwamweeA== X-Received: by 2002:a05:600c:3489:b0:43c:f87c:24ce with SMTP id 5b1f17b1804b1-43ecf9c77ecmr122637075e9.21.1744101146092; Tue, 08 Apr 2025 01:32:26 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c3020d661sm14565216f8f.66.2025.04.08.01.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:25 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 3/4] tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC Date: Tue, 8 Apr 2025 10:32:07 +0200 Message-ID: <20250408083208.43512-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella This driver does not support interrupts, and receiving the response is synchronous with sending the command. So we can set TPM_CHIP_FLAG_SYNC to support synchronous send() and return responses in the same buffer used for commands. This way we don't need the 4KB internal buffer used to cache the response before .send() and .recv(). Also we don't need to implement recv() op. Signed-off-by: Stefano Garzarella --- @Jens @Sumit can you test/review this patch again since we changed the core a bit adding TPM_CHIP_FLAG_SYNC instead of send_recv() op? Thanks, Stefano v2: - set TPM_CHIP_FLAG_SYNC and support it in the new send() - removed Jens' T-b v1: - added Jens' T-b --- drivers/char/tpm/tpm_ftpm_tee.h | 4 --- drivers/char/tpm/tpm_ftpm_tee.c | 64 ++++++++++----------------------- 2 files changed, 19 insertions(+), 49 deletions(-) diff --git a/drivers/char/tpm/tpm_ftpm_tee.h b/drivers/char/tpm/tpm_ftpm_te= e.h index e39903b7ea07..8d5c3f0d2879 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.h +++ b/drivers/char/tpm/tpm_ftpm_tee.h @@ -22,16 +22,12 @@ * struct ftpm_tee_private - fTPM's private data * @chip: struct tpm_chip instance registered with tpm framework. * @session: fTPM TA session identifier. - * @resp_len: cached response buffer length. - * @resp_buf: cached response buffer. * @ctx: TEE context handler. * @shm: Memory pool shared with fTPM TA in TEE. */ struct ftpm_tee_private { struct tpm_chip *chip; u32 session; - size_t resp_len; - u8 resp_buf[MAX_RESPONSE_SIZE]; struct tee_context *ctx; struct tee_shm *shm; }; diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_te= e.c index 637cc8b6599e..b9adc040ca6d 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -31,46 +31,18 @@ static const uuid_t ftpm_ta_uuid =3D 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96); =20 /** - * ftpm_tee_tpm_op_recv() - retrieve fTPM response. - * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h. - * @buf: the buffer to store data. - * @count: the number of bytes to read. - * - * Return: - * In case of success the number of bytes received. - * On failure, -errno. - */ -static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t cou= nt) -{ - struct ftpm_tee_private *pvt_data =3D dev_get_drvdata(chip->dev.parent); - size_t len; - - len =3D pvt_data->resp_len; - if (count < len) { - dev_err(&chip->dev, - "%s: Invalid size in recv: count=3D%zd, resp_len=3D%zd\n", - __func__, count, len); - return -EIO; - } - - memcpy(buf, pvt_data->resp_buf, len); - pvt_data->resp_len =3D 0; - - return len; -} - -/** - * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memor= y. + * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory + * and retrieve the response. * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h - * @buf: the buffer to send. - * @len: the number of bytes to send. + * @buf: the buffer to send and to store the response. + * @cmd_len: the number of bytes to send. * @buf_size: the size of the buffer. * * Return: - * In case of success, returns 0. + * In case of success, returns the number of bytes received. * On failure, -errno */ -static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, +static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t cmd= _len, size_t buf_size) { struct ftpm_tee_private *pvt_data =3D dev_get_drvdata(chip->dev.parent); @@ -82,16 +54,15 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, = u8 *buf, size_t len, struct tee_param command_params[4]; struct tee_shm *shm =3D pvt_data->shm; =20 - if (len > MAX_COMMAND_SIZE) { + if (cmd_len > MAX_COMMAND_SIZE) { dev_err(&chip->dev, "%s: len=3D%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n", - __func__, len); + __func__, cmd_len); return -EIO; } =20 memset(&transceive_args, 0, sizeof(transceive_args)); memset(command_params, 0, sizeof(command_params)); - pvt_data->resp_len =3D 0; =20 /* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */ transceive_args =3D (struct tee_ioctl_invoke_arg) { @@ -105,7 +76,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u= 8 *buf, size_t len, .attr =3D TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT, .u.memref =3D { .shm =3D shm, - .size =3D len, + .size =3D cmd_len, .shm_offs =3D 0, }, }; @@ -117,7 +88,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u= 8 *buf, size_t len, return PTR_ERR(temp_buf); } memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE)); - memcpy(temp_buf, buf, len); + memcpy(temp_buf, buf, cmd_len); =20 command_params[1] =3D (struct tee_param) { .attr =3D TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT, @@ -158,17 +129,20 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip= , u8 *buf, size_t len, __func__, resp_len); return -EIO; } + if (resp_len > buf_size) { + dev_err(&chip->dev, + "%s: resp_len=3D%zd exceeds buf_size=3D%zd\n", + __func__, resp_len, buf_size); + return -EIO; + } =20 - /* sanity checks look good, cache the response */ - memcpy(pvt_data->resp_buf, temp_buf, resp_len); - pvt_data->resp_len =3D resp_len; + memcpy(buf, temp_buf, resp_len); =20 - return 0; + return resp_len; } =20 static const struct tpm_class_ops ftpm_tee_tpm_ops =3D { .flags =3D TPM_OPS_AUTO_STARTUP, - .recv =3D ftpm_tee_tpm_op_recv, .send =3D ftpm_tee_tpm_op_send, }; =20 @@ -253,7 +227,7 @@ static int ftpm_tee_probe(struct device *dev) } =20 pvt_data->chip =3D chip; - pvt_data->chip->flags |=3D TPM_CHIP_FLAG_TPM2; + pvt_data->chip->flags |=3D TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_SYNC; =20 /* Create a character device for the fTPM */ rc =3D tpm_chip_register(pvt_data->chip); --=20 2.49.0 From nobody Fri Dec 19 04:37:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7D60264624 for ; Tue, 8 Apr 2025 08:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101156; cv=none; b=AAUaKTD5Jdm5ttf7BkSzJoROc7WJyY5LX7To++ddagR9kZKSL2XfrWcHRynNVj0FDHj98UdRUPsccxk5mXuhiUDDjFFCPlz60sYmBUyzCxb3gsvfs42LdP5p0yUU/nNtLizgrHnnpH/NQ0E/8ztABJciRLhzpKGjMuOguu0sXSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101156; c=relaxed/simple; bh=dUF2TBEutX2KGJiQNuMfxIqRjcPoQb9fYtWfjZ52S5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8QExOq+JSWII6mVKTWnRAiSS4E8Cr9p50e7PS614+dmiM35D2J+FcrrY5fF6DNYZx/Lfn0lCX/rUMr+HzRyX1revj90mo+fjYkAjiw0OafV8XUr/UbDHonrIlFdnACKeF79oka6vGOj2cJluEkVyHw2MT2bbOLwXhuaWIfM0vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MS5Jnv/t; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MS5Jnv/t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+UWgpwscQp73PyDMRD5EZKbcQGdo2l2UKgmDSHNPifY=; b=MS5Jnv/tvC2qH9QsF8wHAoyeYxPPj6MrI0UxHZt+hZMqX6cwVr1OB4iJZcCbAsolkUrpg8 bQEK8Dm/McrHeGIv2hy/iseI9R+KTvk8u6PkJpPieA3uTx5IFauEGv7b3zKrDUvGh/kJ+G aSmBGL/TDFGjZrbqtgipBxcUOFFN9hY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-juz7l6JANjq1PvnabMtnCA-1; Tue, 08 Apr 2025 04:32:32 -0400 X-MC-Unique: juz7l6JANjq1PvnabMtnCA-1 X-Mimecast-MFC-AGG-ID: juz7l6JANjq1PvnabMtnCA_1744101151 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43ceb011ea5so35197395e9.2 for ; Tue, 08 Apr 2025 01:32:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101151; x=1744705951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+UWgpwscQp73PyDMRD5EZKbcQGdo2l2UKgmDSHNPifY=; b=ao569+C/qZhyzfTd5Usy77QWrpTfdvH91U1NEdkfyyLJGJLyH9XqdmKKxrArQhThg2 EkamNbsZBb+Oq0N/yA7l852Ov+pKY+eWse2QOMlXYvSNcQWklypAaDjk9ubwpwf3rUVR 3c9Il6HGmE55LBFLOVv5K4DXs0ZUtBiTWP22wt57HFCdBLH1thIyUJKxDEksigcSCLw7 x3MO8DQb/2gomZ/5xM6IHj0q5RXXj18VA34nMGaPQi9D3aYggZggPPx+MafukXbDWDYD KeNSAPwMSFC+1jiZh1/A8/W00/2lTJ7WEki4vYMpqBlk0BZ6mckWSGehf8ma0L8+bPVM S0pg== X-Forwarded-Encrypted: i=1; AJvYcCU5fK/cFw8MB/fpDg83HcwJZr49qH55zhfaVLAhFlM0aanz2Y76bhB3gWHxNrPIOAIAJiy4OeMDeLrhl2Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwhTjXRQqfT9WqwOg2d+Z0IvYNKiRYyDCYQi8NeVOT/4ZVhw7EC kOvHgxuYC4BBu0a9M9Z3NsUc0BLRlSdA5Ppy2rTaSlEZqbkGabN9i2CINDO34pUc2uw+xPGi9oq S8zhwYj6Eh4TCDhN0E/DsSHKyXnaTszL2YdBtbTXFs6umdkT4e7C3GJKKF9Lymg== X-Gm-Gg: ASbGnct6rYz56bUaF8EP/kGm3F0LW477JLSwzouHLtIfyecoC8+Y2GlnSYFUucBLu0I RTChjVTOQNjzvDI9bpUg9BTFD6IKkO3Pur5lP8Tpjx0/BrFq4kRscE3+57Y7yfw5tWX8m5VXqkG zGUHeqdG01kWNCu7DMQTlNRXSXi+rtv2p12MAkyB5s81+RJ3Zj1Se8UMWZlCj7N3gckKNExxIGj eGBX0Mizw5JwVLiTpbbn1iOX8DcoPMjSs8XLDMA/oB8fr10wXAoNEXPPlTgYfQDAQ9UY8rGwTL1 EWzOwCH0iFG//dKecLihOdQJfcgCIxZpNelyXUA21IeTvtjPZMRHFlO9llF4xhjnUQ== X-Received: by 2002:a05:600c:1384:b0:43c:fffc:7886 with SMTP id 5b1f17b1804b1-43ecf85f216mr158235555e9.8.1744101151420; Tue, 08 Apr 2025 01:32:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHz2ZKXaEi+HUCetPqQ0pAcpS8InkZmoD9d7JUgJGma+dknJFHnGD8z9oUR2s/51/65NGDLdw== X-Received: by 2002:a05:600c:1384:b0:43c:fffc:7886 with SMTP id 5b1f17b1804b1-43ecf85f216mr158235025e9.8.1744101150843; Tue, 08 Apr 2025 01:32:30 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec17b1352sm154886505e9.37.2025.04.08.01.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:30 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 4/4] tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC Date: Tue, 8 Apr 2025 10:32:08 +0200 Message-ID: <20250408083208.43512-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella This driver does not support interrupts, and receiving the response is synchronous with sending the command. So we can set TPM_CHIP_FLAG_SYNC to support synchronous send() and return responses in the same buffer used for commands. This way we don't need to implement recv() op. Keep using the same pre-allocated buffer to avoid having to allocate it for each command. We need the buffer to have the header required by the SVSM protocol and the command contiguous in memory. Signed-off-by: Stefano Garzarella --- drivers/char/tpm/tpm_svsm.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index b8aa7eb567de..547d4c4f7a53 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -25,38 +25,32 @@ struct tpm_svsm_priv { void *buffer; }; =20 -static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len, +static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t cmd_len, size_t buf_size) { struct tpm_svsm_priv *priv =3D dev_get_drvdata(&chip->dev); int ret; =20 - ret =3D svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, len); + ret =3D svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, cmd_len); if (ret) return ret; =20 /* * The SVSM call uses the same buffer for the command and for the - * response, so after this call, the buffer will contain the response - * that can be used by .recv() op. + * response, so after this call, the buffer will contain the response. + * + * Note: we have to use an internal buffer because the device in SVSM + * expects the svsm_vtpm header + data to be physically contiguous. */ - return snp_svsm_vtpm_send_command(priv->buffer); -} - -static int tpm_svsm_recv(struct tpm_chip *chip, u8 *buf, size_t len) -{ - struct tpm_svsm_priv *priv =3D dev_get_drvdata(&chip->dev); + ret =3D snp_svsm_vtpm_send_command(priv->buffer); + if (ret) + return ret; =20 - /* - * The internal buffer contains the response after we send the command - * to SVSM. - */ - return svsm_vtpm_cmd_response_parse(priv->buffer, buf, len); + return svsm_vtpm_cmd_response_parse(priv->buffer, buf, buf_size); } =20 static struct tpm_class_ops tpm_chip_ops =3D { .flags =3D TPM_OPS_AUTO_STARTUP, - .recv =3D tpm_svsm_recv, .send =3D tpm_svsm_send, }; =20 @@ -88,6 +82,7 @@ static int __init tpm_svsm_probe(struct platform_device *= pdev) =20 dev_set_drvdata(&chip->dev, priv); =20 + chip->flags |=3D TPM_CHIP_FLAG_SYNC; err =3D tpm2_probe(chip); if (err) return err; --=20 2.49.0