From nobody Sun Feb 8 15:42:13 2026 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 033AC27C842 for ; Wed, 14 May 2025 13:46:48 +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=1747230411; cv=none; b=PvnmCOvnYeZYFDviYOfLq1WsT3kA8wM/w6qq8rIRHJhmRt5aGHc8nOvQaWRyThws2cFKwVTsKhLpWu3XXS1RNHpsWJZdB2xekvD0PrBqrp0aeEwyqkHV1wWyW4SaOpup8Vr2jgw1Ecf63oZudIY63vDpgMN4t4QlLFzUwZQSIHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747230411; c=relaxed/simple; bh=jbzwujdFwSka37fXOVWs7M2ikfwWiFepjMmj+dUeOB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=reNu5lCIWWmpvNHh/nDTpmyWDvAIWzbkQGZBKVqXy3d8ENadGNE4spqp3inUAG8oyu8gLjH6PePMZLmbanCoxposwg90oLob2t2ICH9psn3o/Bnl1PRziZ1rPQIXLA+FrB74Fi0DXYZtdXqjs2JbjX9wFZGD4gVYDEsUFNQO9/g= 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=JmBT8MWN; 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="JmBT8MWN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747230407; 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=In0iCep6742EFTxP/bkOpZWh7Qqg86OA5FVVLbMh2YI=; b=JmBT8MWNpsEVL0SSBnogQpd7LjAbSbqIsWaWOFZbUZIOeIwx0p6di+18/L2DwJZ7G74i/d 9d0uYyYidIHJAJoz9qioRkSLCFKS6aHRfOtxtKRnu5Q2q7nXuC6Nmjte+L9wPV8Ujdzvu1 WZTsRpCxNSW5TbMk57cJVpiwL06MYkY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-7KT35YD0OcOx34q1bdRB-Q-1; Wed, 14 May 2025 09:46:46 -0400 X-MC-Unique: 7KT35YD0OcOx34q1bdRB-Q-1 X-Mimecast-MFC-AGG-ID: 7KT35YD0OcOx34q1bdRB-Q_1747230405 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a1fa8742a8so2029214f8f.3 for ; Wed, 14 May 2025 06:46:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747230405; x=1747835205; 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=In0iCep6742EFTxP/bkOpZWh7Qqg86OA5FVVLbMh2YI=; b=HZisBOZhtKG7tZAP5DBNbyIj+4rJrB7wDUKgcvwLxMuUbrEz1jS5KFs18XrcC/pngR aF3e4bZkFHun4doxJPEmp3p4tdkkonD6pbQFsU5dtnH3YAneg1SMJIgCzsvLioUJoeBm gDDFeL+VvfUzmkppSXC746l01oQNpepiMYgE2E/xtfr+pNtmpLEh/wisdQOfnjSBDZFq qJ/lbCXQBQg2kbxCA2G1H85auXniSLTlhbhpkEhonAml9hq582tCIfG4FfXaOZVpNy1T qWw4+c5byhT3Qn8mXr9nsVgrhmq/EbD5zHZpVT6zhb3tz/ETJiKtLZCObB8+V+I7Vjt5 Bzyw== X-Forwarded-Encrypted: i=1; AJvYcCUa1BIw7AnxIflToKNnq10WUrK9wADXQQRshtYeXQO848PtNKiVF2Y6RyCZqClRAGrpC0Jwr8FSWW6vhGI=@vger.kernel.org X-Gm-Message-State: AOJu0YwE0hgsRDzq9S11Q+z6EyjpFyX4xmmEPXpTMcnsBNA3qsojWb9M +PND1wD4sWGQCzBTMo8Z+x0W1h4OHT0KU9YwLLLypN7mBGhLAqbbuLpWOznrlJmM5ZhsdgCuNdF cYkS6E9CO5IdDP3ek8LTSYXkhPRmH12u3kcsAzIT7eZtJbmZc1sVbKa81Vv9VuA== X-Gm-Gg: ASbGncv//YxKUZwLkWcY20xMCG1yHgL7EnxWBvLltu9y+tvinh1ABy93OmR297drcOh WtYfY5IbUGj2AJ2w7FNqhDhfFxg+MGXI/b9aoEz7AWdgkiLd/VLYwmSCTSa/ATgeXyKzGnyfOja 66Yw4OZbhjclF96hBLkiizC+0wNhY8fyY8p67L7xrrqDClbCZgG246K7mjAUlaiAp/CcthrQm+Z 1N77euifoAW2eJfnNSOSol+sldU92aoEx0TZncOtEw2XIszn+6/oB/G/TBapSdqK/pEaPh1myWj j1C0pTFjqe/Hgeq+nUw= X-Received: by 2002:a05:6000:40dc:b0:3a0:bcb0:f69c with SMTP id ffacd0b85a97d-3a34969ac5amr3037626f8f.3.1747230405016; Wed, 14 May 2025 06:46:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtrNPm4H/AkqO/zBtAdz5AMTHSrU9q4L691nqvoDwUNg3YCwB9EhfVBL+pb+YhCPlkxWyNTQ== X-Received: by 2002:a05:6000:40dc:b0:3a0:bcb0:f69c with SMTP id ffacd0b85a97d-3a34969ac5amr3037581f8f.3.1747230404368; Wed, 14 May 2025 06:46:44 -0700 (PDT) Received: from stex1.redhat.com ([193.207.148.196]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f58f2fe6sm20138285f8f.58.2025.05.14.06.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 May 2025 06:46:43 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linuxppc-dev@lists.ozlabs.org, Peter Huewe , Jens Wiklander , linux-integrity@vger.kernel.org, Alexandre Belloni , linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Nicholas Piggin , Sumit Garg , James Bottomley , Claudiu Beznea , Madhavan Srinivasan , Jason Gunthorpe , linux-kernel@vger.kernel.org, Christophe Leroy , Naveen N Rao , Michael Ellerman , Stefano Garzarella Subject: [PATCH v5 1/4] tpm: add bufsiz parameter in the .send callback Date: Wed, 14 May 2025 15:46:27 +0200 Message-ID: <20250514134630.137621-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250514134630.137621-1-sgarzare@redhat.com> References: <20250514134630.137621-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 Add a new `bufsiz` parameter to the `.send` callback in `tpm_class_ops`. This parameter will allow drivers to differentiate between the actual command length to send and the total buffer size. Currently `bufsiz` is not used, but it will be used to implement devices with synchronous send() to send the command and receive the response on the same buffer. 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 bufsiz, Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v5: - changed order and parameter names to match tpm_try_transmit() [Jarkko] v4: - rework the commit description [Jarkko] --- 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 9ac9768cc8f7..10917087b70e 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 bufsiz, + size_t cmd_len); 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..2ed7815e4899 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 bufsiz, size_t len) { 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..816b7c690bc9 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, bufsiz, count); 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..f25faf468bba 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 bufsiz, + size_t count) { 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..ed97344f2324 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 bufsiz, size_t = len) { 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..dbad83bf798e 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -63,13 +63,15 @@ static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, = u8 *buf, size_t count) * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memor= y. * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h * @buf: the buffer to send. + * @bufsiz: the size of the buffer. * @len: the number of bytes to send. * * 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 buf= siz, + size_t len) { 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..4f229656a8e2 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 bufsiz, + size_t len) { 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..bdf1f329a679 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 bufsiz, + size_t len) { 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..d44903b29929 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 bufsiz, + size_t len) { 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..4734a69406ce 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 + * @bufsiz: size of the buffer + * @count: length of the command * * 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 bufsiz, + size_t count) { 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..7638b65b851b 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 bufsiz, + size_t count) { int i; int ret; diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 0f62bbc940da..879ac88f5783 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 bufsiz, + size_t count) { 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 4280edf427d6..0847cbf450b4 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 bufsiz, + size_t len) { 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..4b12c4b9da8b 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 bufsiz, + size_t len) { 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..fc6891a0b693 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. + * @bufsiz: Buffer size. + * @len: Command length. * * 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 bu= fsiz, + size_t len) { 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..0818bb517805 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -321,12 +321,14 @@ static int vtpm_proxy_is_driver_command(struct tpm_ch= ip *chip, * * @chip: tpm chip to use * @buf: send buffer + * @bufsiz: size of the buffer * @count: bytes to send * * 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 b= ufsiz, + size_t count) { 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..556bf2256716 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 bufsiz, + size_t count) { struct tpm_private *priv =3D dev_get_drvdata(&chip->dev); struct vtpm_shared_page *shr =3D priv->shr; --=20 2.49.0 From nobody Sun Feb 8 15:42:13 2026 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 8026827A44A for ; Wed, 14 May 2025 13:46:57 +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=1747230419; cv=none; b=soePOkVnaESM7saI/iKXbRhaYBdVJM7MdbNV8sBGczuwoi32pWpZvlST6H//7DgomyQwtZM6oldf4f0yt/U8xb4ZBGSerJ2ZXC30amzCUQz7kDNn1dTcfnPOFT4sLdaHm1jiEQ5gf5kKMS+C5dXilhOkU1uDa9MDH9XBEsl0uVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747230419; c=relaxed/simple; bh=ha8DqHOX2rnYJ73/d/pv6dX8MWM3OBUeyEKEBtDXY4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQlMINOqdYYKP7a13rVJKxv7PWKZqRgkVbELqXYUerHcUY9qszd6SNQy2XEbqbOm/3Q0bKz8iKXDZqGyvgxOhT9CwEpCmxyZ8Hy+1ttTQQkJBejf645pa9dLKkBJ4jm/aCbqdWlrpjwwI942LFdzdZIoCGup8Md3G+IjGoVFcPQ= 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=eAt2jYNN; 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="eAt2jYNN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747230416; 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=HM3A1DQYgNN+uT3lHR2nzVPEIJjvspM419SembxT0i4=; b=eAt2jYNNf18+JaTqvlrV0XVUfHanQ6DpvKTM9W3dC+bSEbEfZQvz2DDjLb2PDphMU8lG8B 20HG29iY83GxYGIr/wpYmnMdntM+741blBg+zrqtUCVpCQNV6q8/KlbVDT3aDJNeqNwv0h +49A7UHSlGkfYlZeIKNSvMh6+7LFcFo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-GGjX5xFpO4OSDr_nfYXRSA-1; Wed, 14 May 2025 09:46:53 -0400 X-MC-Unique: GGjX5xFpO4OSDr_nfYXRSA-1 X-Mimecast-MFC-AGG-ID: GGjX5xFpO4OSDr_nfYXRSA_1747230412 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a0b9bbfa5dso2512909f8f.3 for ; Wed, 14 May 2025 06:46:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747230412; x=1747835212; 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=HM3A1DQYgNN+uT3lHR2nzVPEIJjvspM419SembxT0i4=; b=im0p2Ieu/kwC2jfKKTRo4n1cl3zfiLwrdN5lhb9zGCVZ5jNyQjmw0clxAF21bQ6eoF qVPBj1QWtgdgMlhSbaKjAjNywz4fhnZ1Wzq28UFGMl25t8aRhoz/lxA2gl/lODhxAy00 s8J5JjytUtFDqtfVSGPyMFSolBpCQ4jHrYmGfHPa3gqT297Im1d0yM+DUCj0v/F8YxF0 PH9fEd3zxCT9rQs6fo8LkU1wUPC/I22lWPuT9OJgqslw8hYFFyq5k0hUis2xRnNgpwS5 7/vYgspklmg3M8petCYFA+vL8eUrcz9K64fSkmwikAxNUqKSjZryjS6kwIwHA0cnoX7v 08tA== X-Forwarded-Encrypted: i=1; AJvYcCUfLVC0bUgwIWMIaVyKctsw8copQmJ7OwVHMBgybGfbZiNzoZPvVtdU12fA8wskD24gh3jcw5Pa2dt6nIc=@vger.kernel.org X-Gm-Message-State: AOJu0YxxuCRQOqO46+VDINfNQXg/NdG3U1Pwp2NtCJhadAQHnDMUst/Q Ho4PvQ9OnIboy9iuMdvA2GyFT4NdDKA2gYaFTTm9K2Qwb3J4aLx+Ymjx8JLx8F6Xm9rbg8G9L0+ /Dp0HGK4HAcsSgYTBhowFc3oyUJayw5Jo2W/lzQlyPYhaLm2t5axfBpo9wQWWiQ== X-Gm-Gg: ASbGncs/Qz1/oI+DuhQm//QL5CbhKoTwSbEDT6bPYYTmbChf7TqQVStG2B5+SGJzE8L Km9R0pA8fUbnr1DcXsXXfR81bMcW/b2AaADYrED2YLdyOow8Envo+wpWrK3wZmL5k68L/jnLywi a33DiAMaXjajtmnRvxnyHoQkpDC8M2luVgIrdnFBor8H/yfxYSYEVfu09NAJud5wqNtw7yETst0 3vKopXMArL8W1CriucU96bse0atUpqIHRYy/qf3+4PRaylPgM0wyylDrC03/9lsCJeckiZqyzw4 Tx5dFxsQshcZr7tAAzg= X-Received: by 2002:a05:6000:4285:b0:3a3:447c:c341 with SMTP id ffacd0b85a97d-3a3496c20bbmr3094557f8f.27.1747230412074; Wed, 14 May 2025 06:46:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH78JQgYCZi7PAI6RbgXsNStikuLBd+X8aPd5vCyBuwPC57MACif1PRt1AJ3M7lUf2aeHKigg== X-Received: by 2002:a05:6000:4285:b0:3a3:447c:c341 with SMTP id ffacd0b85a97d-3a3496c20bbmr3094514f8f.27.1747230411506; Wed, 14 May 2025 06:46:51 -0700 (PDT) Received: from stex1.redhat.com ([193.207.148.196]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f58f2a07sm20175282f8f.50.2025.05.14.06.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 May 2025 06:46:50 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linuxppc-dev@lists.ozlabs.org, Peter Huewe , Jens Wiklander , linux-integrity@vger.kernel.org, Alexandre Belloni , linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Nicholas Piggin , Sumit Garg , James Bottomley , Claudiu Beznea , Madhavan Srinivasan , Jason Gunthorpe , linux-kernel@vger.kernel.org, Christophe Leroy , Naveen N Rao , Michael Ellerman , Stefano Garzarella Subject: [PATCH v5 2/4] tpm: support devices with synchronous send() Date: Wed, 14 May 2025 15:46:28 +0200 Message-ID: <20250514134630.137621-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250514134630.137621-1-sgarzare@redhat.com> References: <20250514134630.137621-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 Reviewed-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- v4: - added Jarkko's R-b v3: - fixed comment style [Jarkko] - renamend `out_send_sync` label to `out_sync` [Jarkko] --- include/linux/tpm.h | 1 + drivers/char/tpm/tpm-interface.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 10917087b70e..33f2aa1a75ea 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -351,6 +351,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 816b7c690bc9..512882ac0db1 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -114,8 +114,19 @@ 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_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 +162,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_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 Sun Feb 8 15:42:13 2026 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 BB00627A916 for ; Wed, 14 May 2025 13:47:03 +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=1747230425; cv=none; b=Msa/y3M9yanhmKxothFpflYaXnTczMcQCUmlAupaH/l8U69sidU2d4Dw7oWVXAy4k5ZCICJIa9Ni8PzyA5anfRVfezj0fycpLZMq6ITRYmo2bgOJmZzz60f6qRGIBFLvYKT50SbGFQG4k3Kb1kA0ixyo/wTxsyDLM3WQpUF1Y/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747230425; c=relaxed/simple; bh=upRLbOWOTskpWJQ5/croZAO1F99vBYZo3efafwHLVVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YKObfJU0CuoBveZnbueaLq3z7/PuvDatmcCvL8OjwoOSjCpuOcFLFAfG9bsLV7DWGEy7OmvCe0PbwA2zgYEVL2IwlUDkNwCcCgGNg/gzKUcyEywFXg22HcRkpti8lxlXuKOYBz2SU3o7xxFTQk5mseOgsZFi3/xGSzpbfEzY6sE= 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=MRpjZxui; 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="MRpjZxui" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747230422; 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=3VsEn91YkrzZR4A/Mgdq4+jTVTrvyIrxkItYrsxgKtg=; b=MRpjZxuibD1is8MAH5FXOMnyFcZivPowqbuYHYv6DTTw+vqnLD2fHT6RIXuE7vI1kS7K5K fRSng8WRdvFwaZFh1XjylmZG6XLkYk3+UzsFieXDaHcURJr/wzQMSTVZUJvDlcuxVoUk5G PONU1tvxJmC/nyv+6y4bhLrhWxq3mvM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569--zOZZ04pOE2cePvuHoOTCQ-1; Wed, 14 May 2025 09:47:01 -0400 X-MC-Unique: -zOZZ04pOE2cePvuHoOTCQ-1 X-Mimecast-MFC-AGG-ID: -zOZZ04pOE2cePvuHoOTCQ_1747230420 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a0b7c8b3e2so4423707f8f.1 for ; Wed, 14 May 2025 06:47:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747230420; x=1747835220; 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=3VsEn91YkrzZR4A/Mgdq4+jTVTrvyIrxkItYrsxgKtg=; b=wAQd0Vldncbp+STV+5KCi7ovWG5ghHvJ/QD5IUCsYwoXkb+0wMH4p6AtROlajbWIYt GfZ91VdB3b9Bq0X/bZrkyy0mv12fkXXD0i/iY/Bt/RyFrhDzcUPnuf6QlXqBsp7tmLj0 C4Nii/yZAv8MSBl1g4ND0SzZrV1iWB/4fEP3qjbVqer0WFoS2ttkF7oeDR5aQ11F+nil 6aDlk9gV+Pwhd/qBM4wuHrhxxGCzTwH8ByJSkeIcIoRdCnTVOIT9bysKrtSFeyMdGl2p qExwtPB0TRhg8RynRRvgFQB8ULSqDA2Q4/UHTlsR9aghMDUA2r1HGuk+DUR8dnSfH0po zqMg== X-Forwarded-Encrypted: i=1; AJvYcCWqfCzi+AjITm0SnjNZpSKxzylxWLZySAN2ZIai/O42lFnqu1qemkpno/Fsm8Y5iL66woDip3iAYRWrEHE=@vger.kernel.org X-Gm-Message-State: AOJu0YxWbnrpZECE4lheCNkQ38qaJlAirKy7pTtzUnoNNx+FPjM/hswx hcQHXxDLcVjkXacTmSXbfVKqknEY36ZaJiEznaJMROSwk0oqYrA3wVtkxHDYplSRg68adZ5c09T DiKfF7hF4BWJue0xYxYlvVlzKaQ9hfHA7SmERwf9BZBdsFw+c30TMfp/syawHhA== X-Gm-Gg: ASbGnctlETOdW0LZbKCflpXiBVpmgLJQ11Ox99vkNVdl4SmFkJHLTZAzsHBpkTUZt4f 0BlfcCh4zUxlNipk5Tp+/0IYZR8776HKrkAHD2lFAk+5qDo9ApGLjD3dMU/4NQMPkUJnUBH7twV m3dYBcEzG22A6DofE/eoYzro2mfztbGJa3Oo/HK2DuKTKq2cp+JG2zLmK6WLVOlFRfX/OZkWmc0 AuUhMh6YiCvm1LvPnws+4s1HLX62q+blTb7msioK9RKJa2Zed6stDOnXUzR9FBSx7QA/cADsXwz h63+JdF4m9xbiDqPugw= X-Received: by 2002:a5d:5984:0:b0:39c:1f0e:95af with SMTP id ffacd0b85a97d-3a349692f80mr3135008f8f.3.1747230420268; Wed, 14 May 2025 06:47:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoc6LO6mZQx8sKJqh9QUjXYKR9LRINtpfPETsiwGKeOEbzsErQvmB2khpdwpBUj9goJyxn6Q== X-Received: by 2002:a5d:5984:0:b0:39c:1f0e:95af with SMTP id ffacd0b85a97d-3a349692f80mr3134960f8f.3.1747230419676; Wed, 14 May 2025 06:46:59 -0700 (PDT) Received: from stex1.redhat.com ([193.207.148.196]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f58f396asm20150675f8f.59.2025.05.14.06.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 May 2025 06:46:58 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linuxppc-dev@lists.ozlabs.org, Peter Huewe , Jens Wiklander , linux-integrity@vger.kernel.org, Alexandre Belloni , linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Nicholas Piggin , Sumit Garg , James Bottomley , Claudiu Beznea , Madhavan Srinivasan , Jason Gunthorpe , linux-kernel@vger.kernel.org, Christophe Leroy , Naveen N Rao , Michael Ellerman , Stefano Garzarella , Sumit Garg Subject: [PATCH v5 3/4] tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC Date: Wed, 14 May 2025 15:46:29 +0200 Message-ID: <20250514134630.137621-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250514134630.137621-1-sgarzare@redhat.com> References: <20250514134630.137621-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. Enable synchronous send() with TPM_CHIP_FLAG_SYNC, which implies that ->send() already fills the provided buffer with a response, and ->recv() is not implemented. Reviewed-by: Sumit Garg Signed-off-by: Stefano Garzarella --- v5: - changed order and parameter names to match tpm_try_transmit() [Jarkko] v4: - added Sumit's R-b - reworked commit description [Jarkko] 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 dbad83bf798e..4e63c30aeaf1 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -31,47 +31,19 @@ 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. + * @buf: the buffer to send and to store the response. * @bufsiz: the size of the buffer. - * @len: the number of bytes to send. + * @cmd_len: the number of bytes to send. * * 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 buf= siz, - size_t len) + size_t cmd_len) { struct ftpm_tee_private *pvt_data =3D dev_get_drvdata(chip->dev.parent); size_t resp_len; @@ -82,16 +54,15 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, = u8 *buf, size_t bufsiz, 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 bufsiz, .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 bufsiz, 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 bufsiz, __func__, resp_len); return -EIO; } + if (resp_len > bufsiz) { + dev_err(&chip->dev, + "%s: resp_len=3D%zd exceeds bufsiz=3D%zd\n", + __func__, resp_len, bufsiz); + 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 Sun Feb 8 15:42:13 2026 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 E91E027A916 for ; Wed, 14 May 2025 13:47:10 +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=1747230432; cv=none; b=vFY2KmkDv6FTFHygZ9DShcBLTNOo6hzQ5p25Pm7k7myS++qv/q+AuIAhLkYrBcm6Py8eJYrIR9x0A9Fy57aEg2RsLlfyqsqPAU50+PtARoxQ/kAj9jz9ZxrTWMFI+UqHsBQ8jfp2Uy28psOtm9NZ2/ej7zHIN4Il4Lj25FtU3cQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747230432; c=relaxed/simple; bh=r704CciIs6S8l1HQAxMJ8T5ehpg4WbCdT2WeOTpKhmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PvIqxwSGurXqjEJNXL9OaVhth3sMHaf509UpiAN4rx/HolcMGu3O+1yIAGUcD3TOdexLGLjCxikhzaXxZFeOpQKtX7u7cqQEtx5w/t+MykQ10HuMTGNayEW6ubG+07rGzRtguVpCbDVaCQbb/bybOs+qHGIC+glqDAGJfRKlq+s= 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=FmgYhhnP; 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="FmgYhhnP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747230430; 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=dM1iIgQEOaOLBHShUWBj9x+RovZVG7Za/6uALilylTw=; b=FmgYhhnPiqYtp65Cn3n+JlomuP0/8PLLaiOEam5+ssZ3pvptRumKSr4/6/wO/U7t8zg97m /aa5spLpf+TNUyQwZIXgpwf16YL2DE3nWozWIuMl9/pXhSblfX+E5K8XZki2ViNVsjKZ9d vWHsF87C8suyqpZ4jewvAUTuJjcqSrw= 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-219-iNaPeyMBPuG2DivOuH3orQ-1; Wed, 14 May 2025 09:47:08 -0400 X-MC-Unique: iNaPeyMBPuG2DivOuH3orQ-1 X-Mimecast-MFC-AGG-ID: iNaPeyMBPuG2DivOuH3orQ_1747230428 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43e9b0fd00cso5147065e9.0 for ; Wed, 14 May 2025 06:47:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747230427; x=1747835227; 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=dM1iIgQEOaOLBHShUWBj9x+RovZVG7Za/6uALilylTw=; b=DWoGdrrr00ZNkbt4/yo4klMY2urg1IJaL/P8vUuezsySfcAklWqz4r7HeR6lzuM5IZ cmX/f/0Z+/ONArbFjnrOWMAiYBg3ZKn0q34Cqds63i5xExi6fuOF6IjqDTjuY1tvozHm Dy4oBHKduEECYluXzpRKEo/AdMimSaQttNOCRSJfWdQkdY1pxQOnPmNXMGX1YAKJoLXq ZT8/YZLu2ZK+p2GQlw0k01fmJHM+UspX49STByz682JFb1x1NdkR54ebrrmlO9EdnKHn ZH/IcStJjcB5T2d7GurBYpp1H3Xz1aewC5Dzbl5BYQ2vlQLey8iXtW9SgHEyyiRhVdyO OaNg== X-Forwarded-Encrypted: i=1; AJvYcCUjLlfV+pQ5SLW26cIbbyVFFl31pEFynbKDTBfGYLC4HYbDNffdzNXWWgF9fqjHLz2URMvquVJisZA8Eog=@vger.kernel.org X-Gm-Message-State: AOJu0YytBJzILXY1pHbR+bemKliXT+VUkY6KSAc/8+ey8OAi4FOgMMHB 4058vpfEQW0EakmKrUpZNWRyVMiymHZ+xuYaIZH3lvByxkNGBSS/Ncp/ysItaA6FZgi0hnmxa8L YmMwa8oqJHUv9Qi/Jdn2CWlIoQcuIxWwmBF/hD7Ta4eerHX0Z0Rq9AgwSO0FD3w== X-Gm-Gg: ASbGncu+TNSqs6fc2eqRq+RWOJjk+csRgbmHlN2zFQR8BSiabn+5gCSIt6XK70WQmAm gROSP/I74QxEGgV7HFRQMvkpSGGhQORuzibBVi0MWSn2622eCLaHWZjks6S7XzXDGJQQCT/TqeF Wm7VaYhvRZ8EgFAs38JRmxcO62aX+t+aaVR+c953ehm1adr7gnsn6zXrw5yJ9Fm4fK6jJP28irX 3Sz4qmfo5xnznwykftyZONB5vMnW5YO2f6ZzHsIuofInU+DTMmcPJgokE1OvkL+fViZyHk6y1B8 1V76ZEF/QlC1lg0HyGc= X-Received: by 2002:a05:600c:4f53:b0:439:8878:5029 with SMTP id 5b1f17b1804b1-442f1a0d906mr28926385e9.2.1747230427582; Wed, 14 May 2025 06:47:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQcNilqw5pw/zInUa+0ub8X2j9IE5W786j2MgQiDjsofCPC9ebkToa0QhXEfe/ocJNSBGqaA== X-Received: by 2002:a05:600c:4f53:b0:439:8878:5029 with SMTP id 5b1f17b1804b1-442f1a0d906mr28926015e9.2.1747230426999; Wed, 14 May 2025 06:47:06 -0700 (PDT) Received: from stex1.redhat.com ([193.207.148.196]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442f3380615sm30931135e9.16.2025.05.14.06.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 May 2025 06:47:06 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linuxppc-dev@lists.ozlabs.org, Peter Huewe , Jens Wiklander , linux-integrity@vger.kernel.org, Alexandre Belloni , linux-arm-kernel@lists.infradead.org, Nicolas Ferre , Nicholas Piggin , Sumit Garg , James Bottomley , Claudiu Beznea , Madhavan Srinivasan , Jason Gunthorpe , linux-kernel@vger.kernel.org, Christophe Leroy , Naveen N Rao , Michael Ellerman , Stefano Garzarella Subject: [PATCH v5 4/4] tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC Date: Wed, 14 May 2025 15:46:30 +0200 Message-ID: <20250514134630.137621-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250514134630.137621-1-sgarzare@redhat.com> References: <20250514134630.137621-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. Enable synchronous send() with TPM_CHIP_FLAG_SYNC, which implies that ->send() already fills the provided buffer with a response, and ->recv() is not implemented. 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 --- v5: - changed order and parameter names to match tpm_try_transmit() [Jarkko] v4: - reworked commit description [Jarkko] --- 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 0847cbf450b4..f5ba0f64850b 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -26,37 +26,31 @@ struct tpm_svsm_priv { }; =20 static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz, - size_t len) + size_t cmd_len) { 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, bufsiz); } =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 @@ -85,6 +79,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