From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B2EEC71155 for ; Fri, 20 Jun 2025 13:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:content-type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mU6fRW0bf+EYAAFC1zO6IHYHxJSiouX7LXjrsfJfSvc=; b=tQ6T0nBasiQQkDiE/UDpzhlkzp T8FdO+kWY4Ep1u1ODZpVhANq7ebH7lhGRcJfZn/MAq/XXDmLwFLbf2TuecW9KI7kP713qOqrV0YqJ JR32tSzNLdWmGLkzoDIWjIB/VVpjHkI13oiroi3jMjEg1H502iKjohBusRyYHjh7mIYONcG5trU0i Fn3CAix89NPebqvFu4bMeToInRr9yN1ClnoShrYuOlzsVV9RkIxEYZGwGC5RVzOSC3/dEhV9whweh y2nnInldiDPelidrYCfKrUUJ4ngBmb9go1S42cZw6ek2gl/duRPNDJoAtcjm7fm1KAG62jrXLk1Ow J5ahwkQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uSbyP-0000000FkBm-3nm7; Fri, 20 Jun 2025 13:40:05 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uSbU5-0000000Ffon-1H7I for linux-arm-kernel@lists.infradead.org; Fri, 20 Jun 2025 13:08:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750424924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mU6fRW0bf+EYAAFC1zO6IHYHxJSiouX7LXjrsfJfSvc=; b=SUfkFZ6BeyfD56fjPSfaiKBOj/nK4wS1WjQbuAWTHI6JlsIaNEWdh6bpoq23kGnEtqoFx1 C08a2foNW3kqavdi+yeSho8aN8rP9i3aQjEuUDic18q/XL0eZ6FpomEG2cPHwSjZPrit/h DuA54c4Vb5NkvKmO/cXrQCXz6LJIJKA= 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-422-6ynLMzCUPPWPh9PiP-CIGw-1; Fri, 20 Jun 2025 09:08:42 -0400 X-MC-Unique: 6ynLMzCUPPWPh9PiP-CIGw-1 X-Mimecast-MFC-AGG-ID: 6ynLMzCUPPWPh9PiP-CIGw_1750424921 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a50049f8eeso837797f8f.3 for ; Fri, 20 Jun 2025 06:08:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750424921; x=1751029721; 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=mU6fRW0bf+EYAAFC1zO6IHYHxJSiouX7LXjrsfJfSvc=; b=Rxqc3BdhsNZfysWTsf/0azP0+sUkyizLHO71BZdnMjs0b1CftBHP8Ksv7joQnjujku Dn3cY92pEp5wqRZ/clq5LVIl/esaLj6Kf525+hE8J0lNVJgkMe/WwvYGfh/+rdtTEiif aczFQuZUnmO/Ja7qNxRHyE1kWo7djkoL4bS52mLG3h8RmbZAhBwdsnnBzQZD+j7YZqnq 6E+Vq+vHdSN6SZE5BaM2TvwWf7ReBjipqY/YJD7J7PBBzRwEADck3wm2/eMjC6oA1tys Ki/gu1EjpWax+/ucubW+eBcj5A0lzxLDraNcxLSsxa0E4qAtN7HLK2t9jE2xLMPfANf/ +uRg== X-Forwarded-Encrypted: i=1; AJvYcCW9zNZ8MVrSRrN4R16Verm3SPP0wfzq9Yx/dO4ugYZDNEfVfI97fr0sPWgnFuNo/B+x0eqRuYzoGzhNL1ijpSvW@lists.infradead.org X-Gm-Message-State: AOJu0YzAcm/cdbeP++cIzJNRpB/QjvGwmbe8YlJGL96Oej83cXnc2QWk j6frLv2ieg5iNyUuAJ4rt2czAp5tn0eZGAhMxvxOAZbuPtI6cM4Wj4ESfziMm/sLrWcLHrQ6yXv lyEeTXME88LC1l7Hfg60jAM3G4l6DrB74JHhyt6HVuZunyw3i3CmH/IRC9KCzzeDY048ispPpdk Qu X-Gm-Gg: ASbGnctgLyREx7xVaFuL7gSiWH5QYbIjqkbRa8mFtJBKDlltk89DSwXWwIXLpycj55z jgJOYX/HIsZ6r+4E5b8IbgI+WTQVETrIdyr3u/lSZNLM3OrMlF4YyFEWgZuXFg5/J2AloSOUUKq M432u6YbP7qDAgBVk5W6BHE/WYOtA55BFv90RHK8Oovl6NlieoAk59ZO83Vqa5xr3RId8oPgMFW xe8zl0OGHuoJOkfCPxfbe8/O07ig3yD881mfQatgzEYGKWQd1MFl3AWOteztWm5Nw5rnaBvKSCP t///bY29N585SOwa33U4JiSNreJlGBnogUI= X-Received: by 2002:a05:6000:2dc4:b0:3a4:c909:ce16 with SMTP id ffacd0b85a97d-3a6d12e8b9amr2295008f8f.49.1750424921119; Fri, 20 Jun 2025 06:08:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMsc23lsWWlIHXqE+KHJfC+ZldUu1vo9dW8yxZbj2jYFLBGKoFW23IJVfV5e9H69ci92Gx7w== X-Received: by 2002:a05:6000:2dc4:b0:3a4:c909:ce16 with SMTP id ffacd0b85a97d-3a6d12e8b9amr2294941f8f.49.1750424920468; Fri, 20 Jun 2025 06:08:40 -0700 (PDT) Received: from localhost.localdomain ([193.207.146.57]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a6d0f1815dsm2006309f8f.28.2025.06.20.06.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 06:08:39 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-kernel@vger.kernel.org, Nicolas Ferre , Naveen N Rao , Sumit Garg , linux-integrity@vger.kernel.org, Peter Huewe , Jens Wiklander , James Bottomley , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Nicholas Piggin , Jason Gunthorpe , Michael Ellerman , Alexandre Belloni , Claudiu Beznea , Madhavan Srinivasan , Stefano Garzarella Subject: [PATCH v6 2/4] tpm: support devices with synchronous send() Date: Fri, 20 Jun 2025 15:08:08 +0200 Message-ID: <20250620130810.99069-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250620130810.99069-1-sgarzare@redhat.com> References: <20250620130810.99069-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vxHlLZbfd2ZNw7eLH325we58JlZWE7hJGJNcHU52cVE_1750424921 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250620_060845_838743_6FCB9A92 X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 cafe8c283e88..804fbbe3873d 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -351,6 +351,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 816b7c690bc9..512882ac0db1 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -114,8 +114,19 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) return rc; } - /* 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