From nobody Wed Dec 17 08:54:19 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 672212749D3 for ; Fri, 9 May 2025 08:57:36 +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=1746781058; cv=none; b=cZha1fZxrBAGzQ3Czm/NjtZvnUpQBN9yqPH80k8+YLz7n4q3OdTz2Rvee8FKsO/3PErAT34E38VsC2SxzCgGlF5/RoxAmyZcMveR1bnXlFuEMaqhiMTAQi2y2Nijupm76dj3GPbZUYS5lExsAJBlQ+smoZih7P/2VHMOJWl+6nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746781058; c=relaxed/simple; bh=CwIU8tcj+L8HFA25cf1cTqoLO7wqS55dyVws9X+LrZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ql/R8/o9qqCYPgHEwYN4ANgGc3XWLOXX4Q4peMj+B8i1vJL8KpHB4deO0ugN75C5G0dF02CG4rtHlThARQVexLfvIAno61jTqNtxRstwWZa2/JXQTUzULzX4OTsNAgdXio7M2pZ9JAWyRqsaGECuPBNqK9n/gvKhsUDeYb83/JE= 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=CxhsZuJL; 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="CxhsZuJL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746781055; 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=1s3Je0ZFPe8U1bt0sD5VWH0wDBbOn/omwkgu7nK9eko=; b=CxhsZuJLB83MF362amo6xZYaoR0OwGLqSb8iqU3LKrGdhhpNJnTG2JnSnCKxFvd5yfi7Zt 4p952Eu9bpESoD0jVaFjXOSLgoQMj8EHbHirYixzijY5UUejcE2qbPFZp7W1HxiqTiasBS rLgslw4QBhcuee4iveYWfnysFNuZKMs= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-HjVdLO9mMveJlPmeIlNblQ-1; Fri, 09 May 2025 04:57:31 -0400 X-MC-Unique: HjVdLO9mMveJlPmeIlNblQ-1 X-Mimecast-MFC-AGG-ID: HjVdLO9mMveJlPmeIlNblQ_1746781051 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ace99fe4282so224758466b.1 for ; Fri, 09 May 2025 01:57:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746781050; x=1747385850; 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=1s3Je0ZFPe8U1bt0sD5VWH0wDBbOn/omwkgu7nK9eko=; b=EyE8N4kXENPvYcIXYzvjNa0XcSWd4PL2357zYfwQMiKJybD+yePAZ4zDovZ4txGmk5 L4StbP8oVZM7XLqTzfvRtbbp3LL3h9dAsai147UFeVk9Z3pDtAI78bTO8sjzfFYll6T9 Dn5XazlS8ahn3bFnYpSGCgN5LMTRC0soa5tc5STsaHPAHhAkXjOwrKeSOhtWAQqtSFpa cxyuot4lV54i8Ba42QqCnzdKMBph3HZvXmNoIv2AKkXI8Qfs0ht1kYnxYx0gr35PP+Xz bG1rzPwqpdr9pasaxAvwQlWsaSlfpsPMIgcyBEbpMRS/UvbKxUantSQGmluqdDagsvM4 TWMQ== X-Forwarded-Encrypted: i=1; AJvYcCXidpedRwPkUp1mxi21UKl/7cdKZWqFecHojLitOE5r33NrHdV+DJWr8JxGArfc/cjOQZ8juevsPdmaiq8=@vger.kernel.org X-Gm-Message-State: AOJu0YyMnoro2AlZPkudP6D6Xxah7cBJxZmExQb9bLZE0Ps0XTLvCRF6 ViZ0I6JDsJR3btfOAe2y+ILJROK7oB0grhj6044fZ+uJ1tVAJYhjwuBReYEPhrz6g1c9IOgsylI Bh0cfv2o5Uz6KemeBv5FOZcBMkNV487Sq1QUh0krvElX+CL8SNyFXIWoB3lK60w== X-Gm-Gg: ASbGnctSJjzttazQlvp3gCHAEKatfRx0fUKjMVksNHds71CVoa9QesRYRqejqfMqClV LMrNbzEHyBOEfhKhwlZj1iDCZ+zHyp18lA1vgNORFfpFzWX3aCKBaTX0n5akfOd8EoD0WtgnG09 I3sql8wun/faQnAxhK9OavVxPsKgwx+QPOI8y9iEi8SW3Rkgb9ROb3VZJ3xwfAfIhsPbm8WG4O8 ZHGRLiGlszxQM3FYgdS90EenSmB+nTq9xpYqJCOaoCsNikmBawixb9dBYSKZELuHJVHKmzFWLMG 4Qatuak4LG4BpSW7Z12ir4AjOQ== X-Received: by 2002:a17:906:c111:b0:ac7:2fbb:ba5 with SMTP id a640c23a62f3a-ad1fca0b654mr675485966b.7.1746781050360; Fri, 09 May 2025 01:57:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHagLstxpWB5hayRxG0xJtF3NJ71NxcNJHJL8yuwox8dKV4UaoASRd63LLbW6wYVNLrCnSs7g== X-Received: by 2002:a17:906:c111:b0:ac7:2fbb:ba5 with SMTP id a640c23a62f3a-ad1fca0b654mr675482266b.7.1746781049648; Fri, 09 May 2025 01:57:29 -0700 (PDT) Received: from localhost.localdomain ([193.207.182.136]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad2193495bdsm117976566b.70.2025.05.09.01.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 May 2025 01:57:28 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-arm-kernel@lists.infradead.org, Peter Huewe , Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, James Bottomley , Jason Gunthorpe , Alexandre Belloni , Madhavan Srinivasan , Naveen N Rao , Jens Wiklander , Nicolas Ferre , linux-integrity@vger.kernel.org, Michael Ellerman , Claudiu Beznea , Nicholas Piggin , Sumit Garg , Stefano Garzarella Subject: [PATCH v4 1/4] tpm: add buf_size parameter in the .send callback Date: Fri, 9 May 2025 10:57:10 +0200 Message-ID: <20250509085713.76851-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250509085713.76851-1-sgarzare@redhat.com> References: <20250509085713.76851-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 `buf_size` 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 `buf_now` 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 cmd_len, Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- 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..7ac390ec89ce 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 4280edf427d6..d3ca5615b6f7 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 Wed Dec 17 08:54:19 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 8C296275864 for ; Fri, 9 May 2025 08:57:41 +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=1746781063; cv=none; b=cMZ0sLsbVKjbWXi7hfwNzMJYBe68X1NZHkCzDQB0+dOZuqmAzHfFH5Ygu3c7xOLmpt4AhHGwbMwUwoYOhhqIAf3tfIayZuPLo8S4xRIHcaztACrW7z2XIdHo9RRf0vEon9pxUsYS60o61LabEN+LQERGnEV2XwhrQoR4RQW/K10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746781063; c=relaxed/simple; bh=zRCxlcH/ra8GADDFcLT7DJcTWYPmd55lgBOJaTcmkfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tN2JiwMAYXsbR1934PhvCXabe/KRDAJRxvmtblzA04CPcEj/IQkzg5JOTAKiabr9OVTUOC2GgbkzNp3KdGkQb+naDEYprAEaCtGh4PIsJR4cW1amiGdFdWm7Xog+5zqGkdh85a9+iFJTyw1+hzwvkNLClMnfrdt9EUEW/eErTTg= 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=X7ipJrnN; 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="X7ipJrnN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746781060; 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=qDWPbShizfOGB/EjWmdUWFa8dOmwyE7Lp4wOXMg3HCo=; b=X7ipJrnN+b0cShn5pfSICSjr+iYRvdtHgxqxnQdZap6z2A3dGA89954tl/4gLxiFydk0Pc Uhix0u122uOCQ+l4zV4Jn0kPu+awz0R0YlvQx3/IMzostE7MjEsAw0nsNxsLIc9+DM7IWA RtVLDvr629H3OT8P+zSoHLF5g6SV3Ek= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-6Yk2EQ_nMY-YnRGlhjRY1Q-1; Fri, 09 May 2025 04:57:37 -0400 X-MC-Unique: 6Yk2EQ_nMY-YnRGlhjRY1Q-1 X-Mimecast-MFC-AGG-ID: 6Yk2EQ_nMY-YnRGlhjRY1Q_1746781057 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ad2200eb1d0so35108466b.3 for ; Fri, 09 May 2025 01:57:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746781056; x=1747385856; 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=qDWPbShizfOGB/EjWmdUWFa8dOmwyE7Lp4wOXMg3HCo=; b=JnyW7gi+yyQK3f6ujjeHT+n8tsr9AUurgZKYVzQYbN/7kd69ZK/CWkuB/0zjR+Uh15 KbVnTvu9pGReiumxvpMMSq7eSwJyQpDop0Fwv8wi0Rp5/mZ45LArcgf/WYjPP3jdMbf3 y3BsV/Z6qLWfWG0la7FR6mQhi6zLL22nVCHHOPrt1NKmCHNmf+2HkIBUs+0KdR8t7Tcd bySgkcwognaedc2caKfR+2ULcU7eh2+RB5/FDXkARoHixCZjlFkFNZMJ82yYaEZecN5M pQB4jZsgPclykrI4zssqKDrXYZOFeqFmsuDZCwt+TBLEOxxCQa9r4I3VwyZLBff5A+rR 7Ytw== X-Forwarded-Encrypted: i=1; AJvYcCVd2ZDEHDoiCO91kKQ97m05RNrFqekEbECYb8vJjPYVNhYap8O0S2rQ7ipqeQftUaKS17QroFVc8bqFSpw=@vger.kernel.org X-Gm-Message-State: AOJu0YxkMJuPRbsh3LGiVLixZ5Yv8fe24Dmo6bfI9/zxq1fQib3PheHl h4YhGelpZblvibR37CwAXoiA+gP3XoksgaPPB3GamMSUlul+teYxDFhI6n01ehKP0wbfRKboeJo PPtcOTn2TYioNW+mlNrBTNf91iUtWOXeSY3w20KvT3bzX9MUdH4EN4+Zd70XSRg== X-Gm-Gg: ASbGnctLnrJvYdtFBHn3I0pHS/sHyPaJx8ghPxXYWdOSlRg2HEQxAnWWK4aV9fSlM2j S7cklAa0Lyy3D9XTSeDsK0FyP19nQd5tClf/oEXsLyild77cP1Mhix3ZmiEc8D8EZYZmh/Uk98P WeUZxh25Mxv+GZXrQ5FFJj1YasrD6kLaN5e+SQpHBU+EkYOn7lw1lEbQyJ7jxJxDJg9Wu9fnU1F z42QwRPIa10VSI+1l6IxTirwYMLQY7Dc6RUi2ikjrRZD0yGuNoedbEdXWHPqEGSk/MMrIAVa8KG DydGjyXGAwEHg5kz0Oqi9lnjSA== X-Received: by 2002:a17:907:6d17:b0:ace:d442:e3a0 with SMTP id a640c23a62f3a-ad2192800admr253473366b.39.1746781056571; Fri, 09 May 2025 01:57:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWC2UI3h5FxOwhQZy5rykHQm7izno8puX6wcw4GMYOzhRsRbgt+ZXqQ0AfZuUWsqn/llgi1A== X-Received: by 2002:a17:907:6d17:b0:ace:d442:e3a0 with SMTP id a640c23a62f3a-ad2192800admr253468866b.39.1746781055796; Fri, 09 May 2025 01:57:35 -0700 (PDT) Received: from localhost.localdomain ([193.207.182.136]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad2197bd37dsm117478266b.124.2025.05.09.01.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 May 2025 01:57:35 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-arm-kernel@lists.infradead.org, Peter Huewe , Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, James Bottomley , Jason Gunthorpe , Alexandre Belloni , Madhavan Srinivasan , Naveen N Rao , Jens Wiklander , Nicolas Ferre , linux-integrity@vger.kernel.org, Michael Ellerman , Claudiu Beznea , Nicholas Piggin , Sumit Garg , Stefano Garzarella Subject: [PATCH v4 2/4] tpm: support devices with synchronous send() Date: Fri, 9 May 2025 10:57:11 +0200 Message-ID: <20250509085713.76851-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250509085713.76851-1-sgarzare@redhat.com> References: <20250509085713.76851-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 7ac390ec89ce..681661c93869 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 3b6ddcdb4051..3dc06836f932 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 Wed Dec 17 08:54:19 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 6C0B427603F for ; Fri, 9 May 2025 08:57:46 +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=1746781068; cv=none; b=nTafRTBpAeQukJjERhBX5PEJXWIQ5LEprK7CiTBWuZECc9WO1TJk5kgGS29n4MOmPTClilIUT2TYMK/gOuA8frG0AWHSFDyQPWNJSlBp6cK4V4HS+p8k816rQJqV/N/tz7SPUOjB3U8Xn8PeOQbbMiBmDu6JwU924tI+UiI0dK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746781068; c=relaxed/simple; bh=TyLjAheVKcgcjzsc1fya4qSms/wCVBF3bmwgWgzQa9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CCdxAdWWFk8/2aWLBKvkCxuRwF6IXvhApqw9GfSTdYk/1rODssEjWZ/ywvy2+IPVusWPqh0Loh/A10WxXrRXzIA/7zxqXOPS3igWGBT8lbS0cxPPNHwpkS7xlkaR+aUJSy+S36/dh3WvzFZfHtVsH6pWEXbWhrw9BMalfELW/gc= 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=STmd3E+I; 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="STmd3E+I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746781065; 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=W3ofDnttG+IcV97+q22PXfMYawWC2pHrgGwgSXYdvb8=; b=STmd3E+IOIVTpbiDq+qAItEz1Koe6fLX3pm1U+6XoIt+7mpEbbrxqsTb7EE50y5WjjSpmR IxQqufFadietGJY7jelmC8JLXxU78OAA2VVCmn6y4diMLlhn+1DOnbb3rbdrr9b4mFnsXf CjiLj1Cyepl3cEbO6aBk2db+ZzEK8oY= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-377-ZSiQMv2kNpmBwcSl2dXtAQ-1; Fri, 09 May 2025 04:57:44 -0400 X-MC-Unique: ZSiQMv2kNpmBwcSl2dXtAQ-1 X-Mimecast-MFC-AGG-ID: ZSiQMv2kNpmBwcSl2dXtAQ_1746781063 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ad212166df4so86969866b.0 for ; Fri, 09 May 2025 01:57:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746781063; x=1747385863; 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=W3ofDnttG+IcV97+q22PXfMYawWC2pHrgGwgSXYdvb8=; b=Ia/FzbFd5ALP/B7Sn2gG3+H/igXfmFI2Nggk2b9E1BPbIjhtrKHUel7zoUoCQpgTIJ 5n5mHRoILvAZrxv8jL2ehupiG6984/IoJbPymOpk2ninE2t/2n6JQUvX6j2gP73TmNko DnMnViqxFLfglw2FPs38p1hLn0j0GYl6/oJaqNzw2V7YdUlgwtOdYkUEt87h2EZfrwrS lMp1LaKb60u4gbEbX3Jhtr3rUh/MB9k/k6h4fkCmqmOW5Ve6+/hDiD13nRueEjQsTNdk SpfRuEeauTr193eYtQ5gWSWpcio3dXtAufV5XA4FVE52B/KzJmrWqcZvmEmpN9DjAL/0 Gtiw== X-Forwarded-Encrypted: i=1; AJvYcCXkd1PxSoPmCl/mHs+GZN0Z7Fr3OiPDgV5nBbmON8p0DlzZQl3qlULt+78Mpf3lpZtWTrn8ZEt80xRGKvo=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0OR9X8CH92q90qByP0yFiaWdz05F+Bt3mbJBtm3IhO8Mn7e0B bMVlTwMdDtnndqs33+bmNJa3L070gw2P6fI9xQOiXAapOd/1FEURqVwxfznZHMmNhTR8UYV+tX5 b2bV67QzOd4gHfqbX/kNGIypUZ26PgNlBWEmdO8XrrS2cJh/APQnqrx3XVLVbUw== X-Gm-Gg: ASbGncvVTfnGNZOlscgUvO6AHKl/Sco4ZWCw9pl3kNxDM1/eCo0VTEGv7b+bwAz1Y2Y geKlmBN7ebcUs7YxC3LhgE4Ejy9PHPzfwbucFHElJc25AuyGhlYdCnGHQNVMrhTgehM6fnZcR+i WIpQ9M6LQj41909Vnb29Gvkz4fzUw3oRb9jdgX7MLeOs1AC7M4etjMDThKdDokCburMkICvf11V RMdQpg9jUA/hS6tMyU++BDLRppxWCXnrNHZY/SZmdVJeZcbYc5KLDFWoijr6nZaelHvPBcy3HTk 2SfbLdeyyIEyIp7gSCvbM/YXgQ== X-Received: by 2002:a17:907:2d11:b0:acf:6bab:5c4f with SMTP id a640c23a62f3a-ad218f8e98fmr216764466b.23.1746781063057; Fri, 09 May 2025 01:57:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMGDwphiNHE/m9JZeYBlYKoN+B4ckHTHfGrZRId6SN32nOHj4ub3aTES86oLCxIEj3HJmHFA== X-Received: by 2002:a17:907:2d11:b0:acf:6bab:5c4f with SMTP id a640c23a62f3a-ad218f8e98fmr216761866b.23.1746781062467; Fri, 09 May 2025 01:57:42 -0700 (PDT) Received: from localhost.localdomain ([193.207.182.136]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad2192c81bfsm120144666b.33.2025.05.09.01.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 May 2025 01:57:41 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-arm-kernel@lists.infradead.org, Peter Huewe , Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, James Bottomley , Jason Gunthorpe , Alexandre Belloni , Madhavan Srinivasan , Naveen N Rao , Jens Wiklander , Nicolas Ferre , linux-integrity@vger.kernel.org, Michael Ellerman , Claudiu Beznea , Nicholas Piggin , Sumit Garg , Stefano Garzarella , Sumit Garg Subject: [PATCH v4 3/4] tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC Date: Fri, 9 May 2025 10:57:12 +0200 Message-ID: <20250509085713.76851-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250509085713.76851-1-sgarzare@redhat.com> References: <20250509085713.76851-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 --- 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 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 Wed Dec 17 08:54:19 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 11DA727511E for ; Fri, 9 May 2025 08:57:53 +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=1746781076; cv=none; b=HB0JSPbfNqd9NqX+o0fyEnFz3V+Oh1LYPvBhYPkjfd46m3Hm8O9a1Wg58PfGSOqBjmTYEXrrwQoZ9JvHYEi4DL/IhJdRN+5D3NVUrWpDqpZw5tc4L4ZEX0sgvHX1gbmNx/qVt5uWNcQOiFCgs14BrcmUBe5akEooGdglGGn6AIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746781076; c=relaxed/simple; bh=OQERegVmsM9QvVsX1j9lmHiktOMTs/IV5jXHkAbPRL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Im9iqc64rdx5lhlh2QvtjM9juq1iPQRIQPZuDKxX+rPGfbfiGSUx1BYCc2sFA9jQa8qsH0P3364Q/SHKY7hjw179Vb2Ekxb5N3pNKtaWjRSMsLk58kTg7M0QnLhqc7RzyEfkVsHC0nJZUnAefqFTrjMF09Pz6IfhBytgFJlMmNQ= 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=LNZ3zYnP; 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="LNZ3zYnP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746781073; 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=6gkeb/9Kdfy78P2DpuPGWOQmqeRSDCl/s8JKK0Bwndg=; b=LNZ3zYnPTEE4GWVZDtd3e63ME+wWsjTxFvWdQ/fDbyrYyBZSLvmwiddfoulpaEG3zGfjwX 7GRvRfcjsCQpDfKndq6qMSscwcFW6rR8+V/Nl4BHWulz4XCrmTsF8K80grEu7xLAyeuvIi F7OIFkbafYmL//UphsfxXMPwkP6DwC0= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-0E9bXF3CM0aJZpDOd4rteg-1; Fri, 09 May 2025 04:57:51 -0400 X-MC-Unique: 0E9bXF3CM0aJZpDOd4rteg-1 X-Mimecast-MFC-AGG-ID: 0E9bXF3CM0aJZpDOd4rteg_1746781071 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ad2200eb1d0so35133466b.3 for ; Fri, 09 May 2025 01:57:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746781070; x=1747385870; 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=6gkeb/9Kdfy78P2DpuPGWOQmqeRSDCl/s8JKK0Bwndg=; b=GvF2oV8kmblTbWOFLYS6x5ODKOybPqVO0egEhYUvm5Hr2m2t+6UEqMgf9DLaqsEkoC pIaLf17QH+S+3eiw/T6NB+xG3mEhKmNANBFdsYDee/f4KJC2l4gFG+Vsn24pBB8c5z8P bKxSmDr/RcC6L16FBca3kJi4zdVPoE68zgWZOwXi5/t8BtjZlB6Z7EyL7lhZeCQPrgpr jjId1JlWFFoGjlXlJAkiDkz2DOs9f66lAqPh/Q9BFwuD1h6wdORsgBQQGhXLKCQar84G VF1JgXvTjlGnKUiP/rL19CedZAdkOIxrvQRFRGHaPYg+A4r3h8lztf9+egKsnsDFSllL XEUQ== X-Forwarded-Encrypted: i=1; AJvYcCU2GyCX9K/VTtBpIQSLmL8a0lBboYvWe0RnVZQGEYghPhIrTR0ga/N8zpV/OxvE8TcA/8IiErdxfDazRE4=@vger.kernel.org X-Gm-Message-State: AOJu0YwH40CuUiWkWTV59QnFeEsLf/3nYSG8GrixlX0rgpIRB8biVjkc 9CJiCzgRXpypvoS0do0hNpV/RO2g5ovk1fdXBDFdHZLb2f7urHzG+25Q2SgaQMpAWfAFd/axHMM NEwq2FrJg/Nl5Lez4fxkmxRcFBoJAOVNBBfTDIGzXE3KXzxBLJgwzWbNYKeFFgA== X-Gm-Gg: ASbGncszhBqTzt9hzoz81sPegybTfgSWT6wqXvagnfODZVJNKy/x/bqPIZpTVMuhqym 4ruDjCg7YI3sAqNE+bLmvl0PQ2f+0sgzo971BOlMDE5xxY7EDa+n8ZMMJQLqYoJZwNJkGp120Bd YAPyuNxjsUFfOj6om1Z8eSyxRXXc19lWtt7eIcBaJNq4zTlVwO3mNj/bRuYlEoNv6BMZzLEXcE/ Uh+i4izKNUTSRRDJipLoEf1QJ0VaJgq4qwoDc7Eag8e+Ptk40zKu3rcNVNjrdS4PD0/1eQoDGph 7HyjBisfEC895jFT4Q3UjlVdaQ== X-Received: by 2002:a17:906:ba90:b0:aca:cda4:9aae with SMTP id a640c23a62f3a-ad21927d0d6mr208672566b.37.1746781070380; Fri, 09 May 2025 01:57:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm/6oRhoG7o/lfsJVdPERf6/D/JJirfP83vdMoj15DtJopabMpuCr2u+MViV0A2cvILTEMug== X-Received: by 2002:a17:906:ba90:b0:aca:cda4:9aae with SMTP id a640c23a62f3a-ad21927d0d6mr208668366b.37.1746781069774; Fri, 09 May 2025 01:57:49 -0700 (PDT) Received: from localhost.localdomain ([193.207.182.136]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad219348781sm119504566b.61.2025.05.09.01.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 May 2025 01:57:49 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-arm-kernel@lists.infradead.org, Peter Huewe , Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, James Bottomley , Jason Gunthorpe , Alexandre Belloni , Madhavan Srinivasan , Naveen N Rao , Jens Wiklander , Nicolas Ferre , linux-integrity@vger.kernel.org, Michael Ellerman , Claudiu Beznea , Nicholas Piggin , Sumit Garg , Stefano Garzarella Subject: [PATCH v4 4/4] tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC Date: Fri, 9 May 2025 10:57:13 +0200 Message-ID: <20250509085713.76851-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250509085713.76851-1-sgarzare@redhat.com> References: <20250509085713.76851-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 --- 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 d3ca5615b6f7..db1983072345 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 @@ -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