From nobody Fri Dec 19 19:17:10 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 EBA8124728E for ; Mon, 14 Apr 2025 14:57:20 +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=1744642642; cv=none; b=ZNqULARuhZ//csYqNeLS+yCPMyOl92Pda65KWmqCeOX+hR6m2LrKqE+N/wDG8dziMP5Dczr6qcYoLabJORAubUJeU1QUVB3WZf0nHNl912UCGHwaNELQ27pqDHhKA0szhBzv1DlN40hLrLVeS962ULRE0DrrDVIuxSK6vEw3268= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744642642; c=relaxed/simple; bh=6r+MscL49X6maR2bi1z1YeY7IVYIxDyEwomnrbpDzKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hamfTuJ4oYoTCk9JJQ/aiUjFeZ6y+XIwKnCuFb6jQmSh9AkTuf8MC3pwt4mnIpoaRLz8XnplZPpBczxExB8hbNPws+8j88iRoNQW24fLp+9QzMS6gRVRjfuDwxRqTS9vt9jsWo1jSozGs9UT2mtFAsyASIYinRjbxV1rJnoLCUc= 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=UdNsV2mk; 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="UdNsV2mk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744642639; 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=u+GxiDq9Oeu84I44/bSM7g+y4sCBZzfShQDAFCXqXxc=; b=UdNsV2mkdRdyBKoconlRTfymv3W81CLtLPuKMW3ByBLV5nY6ULPOJpHf0YdsTj1zdS+t1t CrmOtCzMkPXxllVKnQ7keIXzBTidRHzV+lceSj3mVsQ2DhKw9rfJIU/ZkA9LuXsCb9kDc/ m45IoottGFICezTcdr6F4jENiRAx2NY= 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-231-yU2IgmMVNraXJN4xonWjIw-1; Mon, 14 Apr 2025 10:57:12 -0400 X-MC-Unique: yU2IgmMVNraXJN4xonWjIw-1 X-Mimecast-MFC-AGG-ID: yU2IgmMVNraXJN4xonWjIw_1744642632 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43efa869b19so31223165e9.2 for ; Mon, 14 Apr 2025 07:57:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744642631; x=1745247431; 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=u+GxiDq9Oeu84I44/bSM7g+y4sCBZzfShQDAFCXqXxc=; b=onRQpBrcfY7ANI2I3z5uGDFFi1JKanCUxIy8XbVag+Yk98gOhEkH6+bRbhzZlPG1ZJ 2Zl5c2Cu9Vw0s5q4YL35rSeFz1uzopRq24rFkpJir8inpIltOaYMcvnpqKWXE1P6ip4G YPht8PtrT3rLxdr0t5emo2JQaW/VUuVUW+xQKUbz0CH2EZpRuHEvbsOvN7t7z1W4aKAC TetULMgE2awU8Hc/HWVsakQSRb4+1PKVeP/VDmVENTyMledONCARgmT4XMezDJWEkXTj vZKbLZRAzFASgAV1U6eXvHFnGWef4e5c9nIp8CkY3Xghmqa7J6Pxf9VwImdKfJO63oqo dCIg== X-Forwarded-Encrypted: i=1; AJvYcCVLuyayKzoczV2jsmNgXjBE9GcfxHaL+nTed5y4Ja2//r0E0X9Lm8rbMqOJGnSfvki3VQrg0PN11rPMjw4=@vger.kernel.org X-Gm-Message-State: AOJu0YygTAlzz+k0Y8xP8YVNtiPtxRokltB0PhTMYF6nF1LJYQghWAx0 h2nYi3H8xLR/Hm4udM8FqEA7bwSh+eoYQca4ryZcRFJNioa9SA993ZAsd44cZDuLgcTdQ2KoJ7s aDeqxxfx4EuZz/WJHX4swIw2yQAmfzcxEFtPyGUk4yz6C/XHpTVRl8fKK1N0rxQ== X-Gm-Gg: ASbGncsuYhh4LGb6gbSDDHhueDPDYl8BpKbMZYxj8vnYR1yxMEGBxckU661dR0bBch9 5nsGk92zkBQMPnNdSZ9C06ugoqJ3CNsNecaoORXpDxK4b50s8teaxeZ6RB3emIQZf4rojFczF4m cESpd+Tzbj7IDbE+7QB478b7tfv+ndeKLeedQl0o3B+hjDno44QXr5q25q0Sp4FUe9/066pqhSR RBWctoLCGRCxBeuYYHyb48cgVLBZbY0CLFflxNn6zvR37sgN9nM+iF5ghXn7hJRIE/iGWKF+1fu uiiga8ZZuSS+RuZXyFoUWLt7 X-Received: by 2002:a05:600c:83c6:b0:43d:b85:1831 with SMTP id 5b1f17b1804b1-43f3a7d8c5emr128943795e9.0.1744642631379; Mon, 14 Apr 2025 07:57:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMJZBIx+/EwzQ9PG5BtJJaimgSLS04n/sa4gv1gKmvfpjXPmKVNK/ThDGYLgGVYdFO3jU0Uw== X-Received: by 2002:a05:600c:83c6:b0:43d:b85:1831 with SMTP id 5b1f17b1804b1-43f3a7d8c5emr128943315e9.0.1744642630708; Mon, 14 Apr 2025 07:57:10 -0700 (PDT) Received: from localhost.localdomain ([193.207.151.40]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f207c914csm179889795e9.39.2025.04.14.07.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 07:57:09 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Christophe Leroy , Peter Huewe , Alexandre Belloni , Jens Wiklander , Claudiu Beznea , Naveen N Rao , Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Nicolas Ferre , Michael Ellerman , Madhavan Srinivasan , James Bottomley , linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sumit Garg , linux-kernel@vger.kernel.org, Jason Gunthorpe , Stefano Garzarella Subject: [PATCH v3 1/4] tpm: add buf_size parameter in the .send callback Date: Mon, 14 Apr 2025 16:56:50 +0200 Message-ID: <20250414145653.239081-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250414145653.239081-1-sgarzare@redhat.com> References: <20250414145653.239081-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 --- 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 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 Fri Dec 19 19:17:10 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 3585C2749C5 for ; Mon, 14 Apr 2025 14:57:28 +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=1744642650; cv=none; b=GSZyEluYIdHme+CieaIBzXCJrAn8MA2BlpzVgdxhNeFbEXTwaoTXUhkiHIqWian2wbBb2BshQPbart1qf62OAjYEvZtdBqH8Q/JfQX7vSE5p1RjKOEylHfGz7v82YcvoUwqZCl/gFbJ1RcMmM0x2cVtQ4H3wmuKU/Xnyn0GlR6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744642650; c=relaxed/simple; bh=R4QnQFcPiz+4K8ZI7WgD12ZMOQhjXOvc9mMXJ8CRwMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=grg1XOaCdcEb9OqeZ2F9eokC2u9vZEJFyl1oXnSyE+J8qKMs4qWNHeGBbYt0gmtRypL8hoH+sb3ke0UQMR4qemTjQtpsCA9nBN7pbSJsG0knS2NhP3Sf+hGqm5nndDjFcsrliitNa2WvWi/MLFucwk3A01Z/2IgraZsGartn1kY= 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=UvzyCt7g; 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="UvzyCt7g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744642648; 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=8R/1ZeDKDjc3H414LGRfrF2tWtTtWCHG2fr+aJnFmy8=; b=UvzyCt7g3/pOXYSXOSNh8t3iQY9bMQkCVUcIy8vDw9+R9UyrHRZgAFEYxsF1xP3tYjga5n S/qjlMaeJTbIGQlOq/tQ8RyuwljOQpkZD9iiDn9JL8YPUMqLJgoWowo4BiMJ+PawPpsf5K Qx4x5YD6USa3a+P4l7Yxbl+ChdYdMDU= 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-21--MJrkHQJOIqeTirOTkKFAg-1; Mon, 14 Apr 2025 10:57:20 -0400 X-MC-Unique: -MJrkHQJOIqeTirOTkKFAg-1 X-Mimecast-MFC-AGG-ID: -MJrkHQJOIqeTirOTkKFAg_1744642639 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-39c30f26e31so2988626f8f.3 for ; Mon, 14 Apr 2025 07:57:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744642639; x=1745247439; 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=8R/1ZeDKDjc3H414LGRfrF2tWtTtWCHG2fr+aJnFmy8=; b=t8V54yoDgztgQ7KoNpSIDG2chyDdh4BdAaHxWERUGyh31fR/Qp3xSHtDQ5QaDGcrz3 doc+Je6vwFqkW1HLyZ/RaqXVv17k3nlEPQBUCRmK7Mh/VootNATBwj2iRc8M7lAXz7/E eKWQVYlv7N9lKZpkAp+Bat9xsJo8viNlOtTvoxDJAIQVvayxseFiidaH/n5Iu2UchwA8 8ORzdRtSZgQSWaR5GI48yJ2J2xPPYdsfv7vBfg7rtMqDS9GZ2HimNOlCeoIR2/cz4Xln Una1kDXnjGjy6koTKzmGJQ6oPQhDcfYeebkOGSdjwcadTomMse9RsXq4jwYTVrrJYzJK uPPw== X-Forwarded-Encrypted: i=1; AJvYcCW9ZSudGmj2vcH0VZXZIg9bv9QwbznQtgS/61Xn9wtVAZQn3rbWDSWBG4F+dITifBAOChhlypW9O+3MhDk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5DjHBueNRXh38mm0VUgAaM8mBOm3fmteSXsZmO8kpcRsOqOSZ NOp9lcAxOT9RamH3OhG3IoNdzA6YxTL6is6OKKME8793Din1eVUQqe0P3G6CITHk0+q9mHmJyE8 PGn8LkoIFVDIFtlgBcSi2b+TCmemtTTjhznSMOG7qoGW2crjGgEZhPNNHe50U7Q== X-Gm-Gg: ASbGncvmea5kwCisBqR7IUDbDpKhR3f28Z7mg0IivdjQCcr0nWVyEwyhcLmkUpsmV4R YMbUTCnAFYhPZ7B9jaCqnNbXwFEETJsdSIGfXPLOb9iUHbvxUh6Hdm/+5UphX6uKHFVx4zZN/11 kGrikTGOHmNNCSTvq2cw/VlpDhLQyZj4sZSVg0gP0ZwhQpIA9YFguybASElaNtUt3C/fYATg3AH cWT2A1T5OXsgqWL4L7nBrpSpVfyIGcs+hQSoycyXBmdV20uVlyQlcJS1a7KXpISttraDVfSG10m ExMSEURjgz1xNHEdGrwGzT7x X-Received: by 2002:a05:6000:1787:b0:390:fc5a:91c8 with SMTP id ffacd0b85a97d-39eaaed2015mr9037544f8f.53.1744642639385; Mon, 14 Apr 2025 07:57:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHztG+erjxi0kPl4f2XqgvwdUxEBu7vsO7NjlFZ0D8kctkVzUnk4g2BZgxZgM+ahM52VN9G9g== X-Received: by 2002:a05:6000:1787:b0:390:fc5a:91c8 with SMTP id ffacd0b85a97d-39eaaed2015mr9037507f8f.53.1744642638681; Mon, 14 Apr 2025 07:57:18 -0700 (PDT) Received: from localhost.localdomain ([193.207.151.40]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43cce3sm11395582f8f.74.2025.04.14.07.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 07:57:16 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Christophe Leroy , Peter Huewe , Alexandre Belloni , Jens Wiklander , Claudiu Beznea , Naveen N Rao , Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Nicolas Ferre , Michael Ellerman , Madhavan Srinivasan , James Bottomley , linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sumit Garg , linux-kernel@vger.kernel.org, Jason Gunthorpe , Stefano Garzarella Subject: [PATCH v3 2/4] tpm: support devices with synchronous send() Date: Mon, 14 Apr 2025 16:56:51 +0200 Message-ID: <20250414145653.239081-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250414145653.239081-1-sgarzare@redhat.com> References: <20250414145653.239081-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 Reviewed-by: Jarkko Sakkinen --- 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 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..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 Fri Dec 19 19:17:10 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 2F8BF2749D7 for ; Mon, 14 Apr 2025 14:57:31 +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=1744642653; cv=none; b=P404m/p6nApKzhBhGcQCzIZ3gobksamrScp3mFLgWaJ2/2qkbR0sbyvWQaQwqqQ0nF/iFYkRepTyo7wkfg6Y3CWvKp49TVgb6s6BhvjYwbOwVuc+/SYqq0qTBUHO4TRKHNe3uDx2TEWY5qUTXS672VUBDeBeaNu+Y/H53zwiyAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744642653; c=relaxed/simple; bh=yLXeVtssmPoVnRDUsg/jEOLxV2If2elooLpqCpX8IfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CO7Itx34mdkSq0Q1/6Ktp3fOt0jBV/T8ZXgGc3QceVHOch/SjYT2TJpfR6b5JZrM9+AbNDhkzbPLWDgIi5hFa8z1CMQrNtycqaubKVoYTE8L7nhEMQkNvnjiPTUy0kfI9coIfy+/K0Fkt+bjQKKlAVqNetcSSoblwR7T8efL0rM= 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=Q0fogwiy; 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="Q0fogwiy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744642650; 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=TEdsN0QQfHEZyuRksboskfejhwkQQL9RrSRK2ZgyfhY=; b=Q0fogwiylEOVQya4t6+GueMZswIe3WiwMeVZwKWaDyR2QbRBA01pz/3VPKZEE2a+9oGfPp Thd4NzK8+KUuLtLlXetUs3AU259VlFbG1z9yZyBGhDpJG4MoCwyN5iG6CuMBK23y15S6fu tY1nYucO+lRTwSdoSD0Af4tOTXh0UyI= 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-562-pquG7t_NNtiDgFPCv2fSAA-1; Mon, 14 Apr 2025 10:57:28 -0400 X-MC-Unique: pquG7t_NNtiDgFPCv2fSAA-1 X-Mimecast-MFC-AGG-ID: pquG7t_NNtiDgFPCv2fSAA_1744642647 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3912d9848a7so2692814f8f.0 for ; Mon, 14 Apr 2025 07:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744642647; x=1745247447; 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=TEdsN0QQfHEZyuRksboskfejhwkQQL9RrSRK2ZgyfhY=; b=XSeN0p+ESX9knY3FXAWDaimGWk+JkIotS9HBny7zJov0IHj3/Og3mw8nMuDX+b5SU1 6YGgs1WCdVE9meGmetQVvZrz9TgmhUWBP2PSvXTyZqqPZVEYa5TA3//JX2+ECa0sjikA zXXiJ4gjONBST5FjrqGtfnhfLREJgnGJXBzjp1joPfZk1ugbI0CsXi87Q/9mfatTM31Z YAO8ap+nAZ1CwPFcTYsrS82G0cSh+H0lP+ZkV7VGlHdPLNvLGTi7U3brSAVlc6jdMd+B fepaA5QYlIpk6rz+RTT1vusGERBrtrE1f/NCWGnVtHewkfIrlH5YcCh4Tpe67FM0WrNR 8O0w== X-Forwarded-Encrypted: i=1; AJvYcCXMPH9d8frTeFPS4UpTsvvkIgrw6hq/mmcqpJ19AnBsHMvoIqg7d6YmcQ3P5a3MdLoxiLVyr3fzyut70iY=@vger.kernel.org X-Gm-Message-State: AOJu0YyX2AGC3r7Jh+eAGAyHsbcev34fST+Z2R766AglaV9netTYS7+R Xpg/vJNYlvXJkyjkuJhgzVfkF7IWpid6dw5cJWH/EaQ9gyie0haiCp1p3/rK+cmcnGNNVa0zP8l 9QoHt2/R/NJo2oLW4iz8eiOePu7vJVmnVwO41URcgUdcVgGouvSzzuE6qAyTjhw== X-Gm-Gg: ASbGncvuxIsqGndWItbOKR56wvU1paQ7s0e8waYMfqweXVL/tqIxqCFOR6Qmqc9f3JP ISIYOEX6G8vTiQ7W5tiglA+gcaS/5Zlk2FlabDlnmXpmhXu3hTXBNASJQ+5nMLz+otxaB4weS0Y +3LBxXnyhTBrYvWiVd5kHgIDfrhfWiVMaHaxtX28m6hamlbHhY3UgIIjJUADoV23Y+JVFrW8mER /uh+2jvvGNQ9612CMfbfKzCB3lBTLnUV3JIPPtbvsQqmlnV1w6WVV4UpM/w3zi7lN0RxGVOftkQ Ha8N3Qe5FT4bUlwZ3n1fNtEs X-Received: by 2002:a05:600c:3c84:b0:439:91c7:895a with SMTP id 5b1f17b1804b1-43f2ea651bcmr156784575e9.7.1744642647218; Mon, 14 Apr 2025 07:57:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEApvHF30zJot3Tdd63G9ANE7NhVcm3CdypTeNAQ4xjY84TRnswJTqy6gQmM2qCnJiia7ICYg== X-Received: by 2002:a05:600c:3c84:b0:439:91c7:895a with SMTP id 5b1f17b1804b1-43f2ea651bcmr156784335e9.7.1744642646611; Mon, 14 Apr 2025 07:57:26 -0700 (PDT) Received: from localhost.localdomain ([193.207.151.40]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae9797aasm11333393f8f.56.2025.04.14.07.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 07:57:24 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Christophe Leroy , Peter Huewe , Alexandre Belloni , Jens Wiklander , Claudiu Beznea , Naveen N Rao , Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Nicolas Ferre , Michael Ellerman , Madhavan Srinivasan , James Bottomley , linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sumit Garg , linux-kernel@vger.kernel.org, Jason Gunthorpe , Stefano Garzarella Subject: [PATCH v3 3/4] tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC Date: Mon, 14 Apr 2025 16:56:52 +0200 Message-ID: <20250414145653.239081-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250414145653.239081-1-sgarzare@redhat.com> References: <20250414145653.239081-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 Reviewed-by: Sumit Garg --- 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 19:17:10 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 CCB89274FDC for ; Mon, 14 Apr 2025 14: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=1744642658; cv=none; b=OOamRO6W+MPiwz1cFa5oZtRqEh1kClnKwXVwmO4MI0/k8H+UiNmiP7xcB7sseCIanno38TT5rCcGl43zbMPAwV84lX0AxEigGCB9kgvjQIWKR7Nnls8lJR6kE2KXyHuhErqBF6i0OfuyUI2vVf8rxJtSo3cT/cYjXRiA3QRFda4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744642658; c=relaxed/simple; bh=5uey/9jBuQQ0FWhgq32xA/AF8acy1iMqMDMOkX+Q4lM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OPus3rAfDa/oqw2BXz8R5F4Ysxb8KZQXxyV4EcMTB+U3cVl0GRCyktrNZEePOjZgv8rukcoFpre+J+8YZ7MhN4Nr1vPzBa1yEc9KUm29Mk9vNUNcvgA857mF12qEOecjIzcB9mJfehkNXPtwFpZCB/VaqTnV3yOXl2LlBy+C/+4= 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=SmAjw0qe; 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="SmAjw0qe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744642655; 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=5sa1KMzPVUbpw2KNCiE/Fawx4j9zSiPJcyY6hcGjqFI=; b=SmAjw0qeqIUu2EF+eByzCgFnDdH69Y6XPNuhx03CVuPJ6r/cb2fjx+7pesP9px2Nv7p6G/ YKly0gXhTOBbw6MJtd1w+Iag6O3dkBj1FliCeyJgfCDlmiKmk1Li3yc9x/AAHFvRLTRz53 AeYV0B7PyEwRU+owPqI2PTyj8+CTJ+U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-XlCvf57-PNClaxNoFwxN3w-1; Mon, 14 Apr 2025 10:57:34 -0400 X-MC-Unique: XlCvf57-PNClaxNoFwxN3w-1 X-Mimecast-MFC-AGG-ID: XlCvf57-PNClaxNoFwxN3w_1744642654 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3913f97d115so2206847f8f.0 for ; Mon, 14 Apr 2025 07:57:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744642653; x=1745247453; 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=5sa1KMzPVUbpw2KNCiE/Fawx4j9zSiPJcyY6hcGjqFI=; b=UP/jAMtP2CAFtz7vhRsN66VU7L1SdMWf8Bn9wibIXpBeQSK7M5hNrBP4hAYr2pyEo9 tyAcp7J9oilHWyAdVZVy525fc8YKuZcuATgU73T8o+lpolMAwlN+O8zVG+qOFzOSxQee ptAIr4Kdr2JR7t2dq0O/25+pKlY1idIunPNJze5iw1eNpv/TzeF1ar+kf+09670g4F0O NkQd863Etnl9xilRuClUhB6d7C0q4xon4jUHM3veG6x5pUBYEQZYbGCrZX1qk2H6iTZo rKVGqMrgVQqOZWyTxy56J8cwVs3SWtH/zxy3ofsSrsiVVF0i8ibhuZgUc1d2Qx4lFJ4u fyMw== X-Forwarded-Encrypted: i=1; AJvYcCUF4BC88ecWr5fmuIUnGhuuIGF95YdXkaoJJn3yYSjC7sYShZPekgu6LocIYhmc1L3boIWAHqH8sT5SgzY=@vger.kernel.org X-Gm-Message-State: AOJu0YxhNOjkPrMeHxSOG5YjycPgyWF4FPzF9SK++LFHYd66nWGEjw6d 747/pDhjZJDBJaDMrN26hcpodtMk+l/6DnRmMdXgW0EljAguriOUv6AYu1w1fprA+jOx2hNsN0t flRagT1Q5Cuc9l1BkfJXDxURYZQmf4wBpiB3ZnEDl+lxLF1Kaxk1AnleFugF+9w== X-Gm-Gg: ASbGncvNt5st8KiVQjC/X3ErHb+GqnxTm565lzSX/rVaJE71Gq1hbudBVR6Xtg7GzcN Uzo9q2b4hz+N7Gf7rxk/eyCG4sgLCqRbH+f+Xo4EqHN9MhZby0n4EOKZ9FjEv7sfJZKNqNJ6MiU 4zEoCqT57Ci2vUmbdlvxsYDeE6zIyax0/UGwa/PeDCeWD7wZYLR6DMG/Zfd396fptG5U2JYd8H0 f+wxzeYLUOUhKsEYMrc4jEHGX+iqP4Z2I11gNkzmIj4RerDrVP5aH+z8zbgNRQ2FoqYH/cVZD23 +WOZuz/dKbVtBNOOTpNxqZry X-Received: by 2002:a5d:5f56:0:b0:390:e535:8750 with SMTP id ffacd0b85a97d-39e6e48846dmr9576039f8f.9.1744642653500; Mon, 14 Apr 2025 07:57:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUePoA8CXCKRWtYvnKKIInk/j0CbqjuJ2mLiXYjmccJQ4ZcE+fLBnmyZcdyCqfwL3pNjKyHg== X-Received: by 2002:a5d:5f56:0:b0:390:e535:8750 with SMTP id ffacd0b85a97d-39e6e48846dmr9576006f8f.9.1744642652841; Mon, 14 Apr 2025 07:57:32 -0700 (PDT) Received: from localhost.localdomain ([193.207.151.40]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eaf43cdfdsm11483858f8f.61.2025.04.14.07.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 07:57:32 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Christophe Leroy , Peter Huewe , Alexandre Belloni , Jens Wiklander , Claudiu Beznea , Naveen N Rao , Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Nicolas Ferre , Michael Ellerman , Madhavan Srinivasan , James Bottomley , linux-integrity@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sumit Garg , linux-kernel@vger.kernel.org, Jason Gunthorpe , Stefano Garzarella Subject: [PATCH v3 4/4] tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC Date: Mon, 14 Apr 2025 16:56:53 +0200 Message-ID: <20250414145653.239081-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250414145653.239081-1-sgarzare@redhat.com> References: <20250414145653.239081-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 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