From nobody Mon Feb 9 19:25:46 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