Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp831697ybg; Mon, 1 Jun 2020 15:58:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI0Or1IJImEP84lrwd8x41N17UxpubaOwibNLr9nFvp85GXka5HwV1xbJrkXRSXb11vjwH X-Received: by 2002:a17:907:10d1:: with SMTP id rv17mr16929036ejb.51.1591052309622; Mon, 01 Jun 2020 15:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591052309; cv=none; d=google.com; s=arc-20160816; b=t80KA/n5LYj22c29hxuMq/xnS23Y0GHRw3Bbb2GM8RDfjVaOm9CFx383eGp2B2ssB6 Q0K1FcqBP2KCTNLjacpiFUYTc10xMzbcYrhdVuIEw7cNvCFGemO5Cd7tJAlWrtlkDsg/ 7f3r5BWV/6GHlQvZyWsE27OqTQdcMbH8SpsknKDr/jSORkr36yig15e0mcqnFrzWPz+i WyGpv7PeJf3R+nUQ5rWBIIv8+rNKMbz0JwwjEzdxy5P8133DL+jF9MftU4IkhmwIfvPx z+Q3TFz4f4dJPtG0KNb2w14gLWnU/bZz5p37QlpjanhO+wjLv6Guo+IVEqNlTpU+W6Sm uLXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ahBMXlLUd844T91f3aGesWzPLvREUhRkr0Fgcws0YGs=; b=ElfoL5VdUC2bWDnES2hhpICGTGVsZLvn9zdC5lSXAciJVspbiGtJoT3+sIsTEoBQcS IxGMzULvD+SlKbL8cPFgcm4FMb9qEZTckycc5Nj7C46okRMSmO2VgTUCDYPN8Rs8VDVU c3DsOrY4rh2xwccwEGzHKul9z2ehqOihgOmxkgWRfGPNwWB/pm1VzE045ucxR0dFuBRb YRoMd+6pM5DWBm8unqlGaor6pwR5OubZvnIE/HV7Wu8P4mDF3Qg4G2UxxvBycL5oTncD dEhQYgF2HYMAlhU20OwXe4fSS6iGf49AFfAVMNYqp0oCAFwUB/5WxQx/2FVmsY5NSbY7 aKYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="fE40P/Ga"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o22si524203ejh.73.2020.06.01.15.58.06; Mon, 01 Jun 2020 15:58:29 -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; dkim=pass header.i=@chromium.org header.s=google header.b="fE40P/Ga"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728954AbgFAWyU (ORCPT + 99 others); Mon, 1 Jun 2020 18:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728474AbgFAWyT (ORCPT ); Mon, 1 Jun 2020 18:54:19 -0400 Received: from mail-vs1-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D905FC03E96B for ; Mon, 1 Jun 2020 15:54:17 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id r10so910609vsa.12 for ; Mon, 01 Jun 2020 15:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ahBMXlLUd844T91f3aGesWzPLvREUhRkr0Fgcws0YGs=; b=fE40P/GaA/oeYfZvFFTM420T8Kn7sVmkFjI7Qoy0bvihR4lmVHQUDbxoCW8m2JzSuj CYOn8agMAC73Y21kyw43VwgR2EToUMJXfHZ3OHfVQwIlMjT6c2ctwCKWkTS063a7GUxk +cnqb/McO2igW/hXGaTuSyE91w8VGgwOWJfbk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ahBMXlLUd844T91f3aGesWzPLvREUhRkr0Fgcws0YGs=; b=W7ZZewvgIPltDdFme1lAD/9H3nRx8EMtxYqwYChWKLTtAiD44+zJHDYEEnRgR4wMSI f3dW7K+nOzApan7jJlSEcOZ1SBEwIpQ8++GFss591i7VDbUx3/LZDW0TAkQomk4n7kaV ZeLqjqNahDU7KLcg4sqEjnMSRaNUbvOMZjVuf0ymPwAvVXg258rkC8mbxj0w5mrz8XYq Bo7KKXgUIsQAnBWuBH/0MwCJ/lGaGizLq+1SnE/mYbk1NQfJem+QXf7A28o8XLV2aksg JBPNvd2/1UwhXvZ/7wWaAwtPSGfnGADyzSaS/YDeYuGuEUQ2m25Zr1SKL9YfQrWwplPk gz4g== X-Gm-Message-State: AOAM531EAJzq0iLurUMQtLdBctonRo4R/nZKNyF2XLk4jFhk0q9wbgV6 BFOQaZBZDhHb20nZrj8WMPho2vfGU78= X-Received: by 2002:a05:6102:10a:: with SMTP id z10mr16187911vsq.131.1591052056437; Mon, 01 Jun 2020 15:54:16 -0700 (PDT) Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com. [209.85.217.45]) by smtp.gmail.com with ESMTPSA id t131sm146650vkc.32.2020.06.01.15.54.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Jun 2020 15:54:15 -0700 (PDT) Received: by mail-vs1-f45.google.com with SMTP id z13so907259vsn.10 for ; Mon, 01 Jun 2020 15:54:15 -0700 (PDT) X-Received: by 2002:a67:1703:: with SMTP id 3mr16545948vsx.169.1591052054915; Mon, 01 Jun 2020 15:54:14 -0700 (PDT) MIME-Version: 1.0 References: <20200528151912.1.Id689a39ce8d1ec6f29f4287277ad977ff4f57d7d@changeid> <20200601014646.GA794847@linux.intel.com> In-Reply-To: <20200601014646.GA794847@linux.intel.com> From: Doug Anderson Date: Mon, 1 Jun 2020 15:54:03 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tpm_tis_spi: Don't send anything during flow control To: Jarkko Sakkinen Cc: Peter Huewe , Andrey Pronin , Stephen Boyd , Arnd Bergmann , Greg Kroah-Hartman , Jason Gunthorpe , linux-integrity@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sun, May 31, 2020 at 6:47 PM Jarkko Sakkinen wrote: > > On Thu, May 28, 2020 at 03:19:30PM -0700, Douglas Anderson wrote: > > 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. > > > > 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; > > - > > Why this should be removed? As far as I can tell the only purpose of that was to make sure we were sending 0. Specifically "tx_buf" "rx_buf" both point to "phy->iobuf" so setting the first byte to 0 here made sure that we weren't sending out "random" data but were instead sending a 0. After my change "tx_buf" is NULL so we don't need to do this--the controller should take charge of sending nothing on the lines (AKA sending a zero). Does that answer your question, or were you worried about us needing to init iobuf[0] to 0 in some other case? -Doug