From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 474172DC760; Wed, 30 Apr 2025 15:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746027708; cv=none; b=Vh/29qT+jaNI3BJ9hE1fwEiLGZbZH7rzIxAuYmRUCt3XXWKRUrLfzf1HvGq9KabtZwTlodhK4H/kwZLt2qNS2hi6jY4H5XMs5sFOqFRgt9Az1nGREYvPwPMt8lWMy5d2kV8xKeLsEdrn50WqijT2rJh4+QBzi6RZz26fzfBACLk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746027708; c=relaxed/simple; bh=t3Uy1BtGwRmWTleefFwzwLEd+DTXVI1qrt1CFuU5vhY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IMDdRjsH1NEuE+5JLopP0pB8QkqgMCEhZCyKOPqp26TwBVZ6B9ck3aX7goV4xpd3f1NTu+2uvNT6rUWSeIzkngnjJQAL4jFQ2bhxmoOk2qvT77f24jKfVmwZl6AZL/7IG+y/hkeDWFTyX4RglVThYVIKte+m0WB38YxCZYtRE6k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sYMmM/96; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sYMmM/96" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B85AC4CEE7; Wed, 30 Apr 2025 15:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746027707; bh=t3Uy1BtGwRmWTleefFwzwLEd+DTXVI1qrt1CFuU5vhY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sYMmM/96Ea5WB/UvivqqMgPKi50QLTkUGDOlUIy8mwSv8AYlnTHcebGdMJlGrm5I6 poHKYrdkKnHyAYuUBE7nu1gKhpcHTZbAs1Y1YVsulkzKbrBRtnijB/6VXXw1PYtAzA VnhHz91fh02nYKhlA7IAwQGMLluYkCOJunjViNaP/RcSDb8vEV+RwQcZKG56FgPGwL ZO+FnTUv8Zu59RED36Xj/HRIUw+0S2GL8BAJqk0CO/XglbIgvlCPGyvepALRhEMi01 A29hzM7jzpG0WVStsQYbvZtWvcFXpsm9Wes9S3rIStawxDCGKm+Jx+IyXowYzzzPAL yt4MFdxt2J5WA== Date: Wed, 30 Apr 2025 18:41:43 +0300 From: Jarkko Sakkinen To: Stefano Garzarella 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 Subject: Re: [PATCH v3 2/4] tpm: support devices with synchronous send() Message-ID: References: <20250414145653.239081-1-sgarzare@redhat.com> <20250414145653.239081-3-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250414145653.239081-3-sgarzare@redhat.com> On Mon, Apr 14, 2025 at 04:56:51PM +0200, Stefano Garzarella wrote: > 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 > --- > 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 = BIT(8), > TPM_CHIP_FLAG_HWRNG_DISABLED = BIT(9), > TPM_CHIP_FLAG_DISABLE = BIT(10), > + TPM_CHIP_FLAG_SYNC = BIT(11), > }; > > #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-interface.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; > } > > - /* 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 = rc; > + rc = 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 = len; > dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); > - } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) > + return rc; > + } > +out_sync: > + if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) > rc = -EFAULT; > > return rc ? rc : len; > -- > 2.49.0 > I think this is ok. Reviewed-by: Jarkko Sakkinen BR, Jarkko