Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp352460ybm; Fri, 29 May 2020 01:38:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5z59rI7MKl0KaJDwkyg1K65R75jVHq3/WbuitbRBdQq1WxQXpnkRD8gASQt4d+C5fWijX X-Received: by 2002:a50:a693:: with SMTP id e19mr6832089edc.275.1590741512668; Fri, 29 May 2020 01:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590741512; cv=none; d=google.com; s=arc-20160816; b=m82wti13w9cRayl85mmX9GF8GoUHbAfPvHotA6ssjzdUkneMJIKyxWfjGQEoJKj7qr W6Hrselv8Ds8jYvqS8b9RNYysBSoaB8bOhWL/22cxzFDx39VbrwSi+M5ZKvJhzMpYGWG TrS/U/1psQHv2AbkGw3OcUqU6LoBrk1C+KA139vmhfTIM7spzKc8N0WC16rCBBaFqmsH AUMzS6Y23yodjdZvgp0wYR0rXYwvlvLZezMVv5wqpe1oayOrHOpYtV1bSy7m4t264bcn 9dcZSLGRxdJ6Xk4pxQbSDth9IFxLXRYcXwIvEcpDHRBX2eZF0uXGxkPOdZqfxBfjiGxd m01Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=arvyLgUn+xA0cs/b3trWoF2Q8CFtCCfNLo0jQp00AoA=; b=lQ7gphHP7crRj4U8A6tJsV4uk2y6lTShathuFr0lli3362ccUl0VHFclLBsUBpehnD 1M2bDMtU71yEb1rR/XXN1atgjRZeB/9jYobhz3Dw2lep5LAFYd3JAsITkX5MQKC3tP9l 8uVUi8RBIiadXN2QJRABlsnEFOi/TBpToJHaUBA9ZM5pCROkYT7xN2nTAZyXaiquMQmF imNhJMla3iiL3XYZPZ6cIbhd5nz9OKXwafdG1QRBSr93bdwgxrcgdEXmMQLReIXzWFOF PeZS4m9QF94K2/o5u4EbV6nDIoJiMNby7ug+Yc2a5omZTD+0ccHbBXfzYYMjI75RlHtC ZPTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si206343edt.541.2020.05.29.01.38.08; Fri, 29 May 2020 01:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726549AbgE2Idc (ORCPT + 99 others); Fri, 29 May 2020 04:33:32 -0400 Received: from mx3.molgen.mpg.de ([141.14.17.11]:53477 "EHLO mx1.molgen.mpg.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725681AbgE2Idb (ORCPT ); Fri, 29 May 2020 04:33:31 -0400 Received: from [192.168.0.6] (unknown [95.90.247.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 9D5242002EE2C; Fri, 29 May 2020 10:33:28 +0200 (CEST) Subject: Re: [PATCH] tpm_tis_spi: Don't send anything during flow control To: Douglas Anderson , Peter Huewe , Jarkko Sakkinen Cc: Andrey Pronin , Stephen Boyd , Arnd Bergmann , Greg Kroah-Hartman , Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200528151912.1.Id689a39ce8d1ec6f29f4287277ad977ff4f57d7d@changeid> From: Paul Menzel Message-ID: Date: Fri, 29 May 2020 10:33:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200528151912.1.Id689a39ce8d1ec6f29f4287277ad977ff4f57d7d@changeid> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dear Douglas, Thank you for the patch. Am 29.05.20 um 00:19 schrieb Douglas Anderson: > During flow control we are just reading from the TPM, yet our spi_xfer > has the tx_buf and rx_buf both non-NULL which means we're requesting a > full duplex transfer. > > SPI is always somewhat of a full duplex protocol anyway and in theory > the other side shouldn't really be looking at what we're sending it > during flow control, but it's still a bit ugly to be sending some > "random" data when we shouldn't. > > The default tpm_tis_spi_flow_control() tries to address this by > setting 'phy->iobuf[0] = 0'. This partially avoids the problem of > sending "random" data, but since our tx_buf and rx_buf both point to > the same place I believe there is the potential of us sending the > TPM's previous byte back to it if we hit the retry loop. > > Another flow control implementation, cr50_spi_flow_control(), doesn't > address this at all. > > Let's clean this up and just make the tx_buf NULL before we call > flow_control(). Not only does this ensure that we're not sending any > "random" bytes but it also possibly could make the SPI controller > behave in a slightly more optimal way. > > NOTE: no actual observed problems are fixed by this patch--it's was > just made based on code inspection. s/it's was/it was/ Were you able to test this? Maybe in the “Chromebook QA arsenal”? Are you already running it in production on Google Chrome OS devices? > Signed-off-by: Douglas Anderson > --- > > drivers/char/tpm/tpm_tis_spi_main.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c > index d96755935529..8d2c581a93c6 100644 > --- a/drivers/char/tpm/tpm_tis_spi_main.c > +++ b/drivers/char/tpm/tpm_tis_spi_main.c > @@ -53,8 +53,6 @@ static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, > > if ((phy->iobuf[3] & 0x01) == 0) { > // handle SPI wait states > - phy->iobuf[0] = 0; > - > for (i = 0; i < TPM_RETRY; i++) { > spi_xfer->len = 1; > spi_message_init(&m); > @@ -104,6 +102,8 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, > if (ret < 0) > goto exit; > > + /* Flow control transfers are receive only */ > + spi_xfer.tx_buf = NULL; > ret = phy->flow_control(phy, &spi_xfer); > if (ret < 0) > goto exit; > @@ -113,9 +113,8 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, > spi_xfer.delay.value = 5; > spi_xfer.delay.unit = SPI_DELAY_UNIT_USECS; > > - if (in) { > - spi_xfer.tx_buf = NULL; > - } else if (out) { > + if (out) { > + spi_xfer.tx_buf = phy->iobuf; > spi_xfer.rx_buf = NULL; > memcpy(phy->iobuf, out, transfer_len); > out += transfer_len; Reviewed-by: Paul Menzel Kind regards, Paul