Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2814214rwr; Fri, 21 Apr 2023 14:48:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Zyjog9rZw5JLHHl1XmoUB0JSMWaWW0I3mL/vhfrmLchoD08XMI63BV2/FYje+9Uy5ufuLo X-Received: by 2002:a05:6a21:3288:b0:e9:843:18f3 with SMTP id yt8-20020a056a21328800b000e9084318f3mr8122722pzb.5.1682113684244; Fri, 21 Apr 2023 14:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682113684; cv=none; d=google.com; s=arc-20160816; b=hGNV4YtQysKJXEKQrtlxM1mVerfIuNtO2gHwfaDUH/LO+8wfkhhi2idPJGI9BchC99 ddkH2VuQ60RM9tMKWQoPmwV6S20WoDUarpbIGjxDOm9Fq9n1SqOziutgQBR4+8sJtb8B 7bn4l6txKUTpZy7nVCwOEQCgW25QFIDe4W9PsU5Ritr+Lk6HSAOYaO8LYSx9ZUWGdseu cl8i9CUkEKAwsa1pForGoGGp9XBSt8BsVTtea4tDJ7yBpL2ifsSlcOvdhV/jmIglQeqB Twk5fnQFuraaz3bsEovpJLaXHXeqymVpJYfuc7qXOM+/vLxWaQRTFR9L+smiZJzDMWor qgxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+0slh+vEfd/QJopOKZZYmVIySMg9JKJ+qUyLGZYJxjU=; b=fIh9glys9c/Gk741RpuMeASKWpA25sbvpXSSUEBFsQhlsiZW0+3BFdVbQOT6Usx+j7 D4Zz4XmHvybcRAtYeAelPu9Uw9FnaKQ08Dz4rTKc6uR/tyoHkLwM5OG7ne3rmZ9+TVjD sZmXMrEMFxGwCA5JMW8R3qOpVWWnAGWqxT4AIl4IBDCEhnm9BJQW3y5ShGJV5QyWIwvg PQ9lu4A4CZ5Q4zFBtVFNhGEEWW67SQPEIrw+qranAzTTVJPNOkovAFswnsWVu+sbZK/+ Zl8sCKwFes5g7JWdXBgZpgP30naazbPI0wbrF/aE6oka5bc3nw5mRjdjEPO56aAE42CS P3KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gnG78z7m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h188-20020a6253c5000000b0062d9a5632c1si5159810pfb.359.2023.04.21.14.47.51; Fri, 21 Apr 2023 14:48:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gnG78z7m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233556AbjDUVrD (ORCPT + 99 others); Fri, 21 Apr 2023 17:47:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbjDUVrC (ORCPT ); Fri, 21 Apr 2023 17:47:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1BEA2711; Fri, 21 Apr 2023 14:46:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4961865320; Fri, 21 Apr 2023 21:46:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C1B8C433EF; Fri, 21 Apr 2023 21:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682113603; bh=5jZwlULWqJhakp+S5Nl0zzDSo4Z6CykzB8eI1k6/BNY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gnG78z7mO2C4SYKcQq2mzT/YZ41s1HkB8wHNEPPUJT+gYmzDQ/4prZJWuQQw0kOKT bB8eaHH1kpWXXRLoZ+S1imnUPN59z7QHF7JBUsglcI6mQEZOVxVb4Cv7S/KeX8n7Zi S8//55Y8R3O4fGHL+/Pa5HBL6Ozn4Ir+opHt3b4wMTzD07Y9WomZOo4DjhpHaRad3D EkmKw/K/O7MSMYBtqBKFwe1x5EeVrZue0/5HxuxymjJtbdN6Rv7PvkGoFnxqx7/sKF Hl03If35y7x1V7BKdsKGr0TChqIWIewbog0KGzdi5zyXoGfmx5TXG+hXkUJLJXsG51 UBJ+SswiKPAWA== Date: Sat, 22 Apr 2023 00:46:40 +0300 From: Jarkko Sakkinen To: shaopeijie@cestc.cn Cc: peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tpm_tis_spi: fix:release chip select when flow control fails Message-ID: References: <20230331065625.1977-1-shaopeijie@cestc.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230331065625.1977-1-shaopeijie@cestc.cn> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 31, 2023 at 02:56:25PM +0800, shaopeijie@cestc.cn wrote: > From: Peijie Shao > > The TPM's chip select will leave active after spi_bus_unlock when > flow control timeout, and may interfere other chips sharing the same > spi bus, or may damage them dule to level conflict on MISO pin. > > So the patch deactives the chip select by sending an empty message > with cs_change=0 if flow control fails. > > The reason why flow control timeout for me is unfortunately I got a > damaged TPM chip. It always pull MISO low during cs active(this can > be easily emulated by wire MISO to the ground), not responding anything, > and dmesg shows below: > ... > [ 311.150725] tpm_tis_spi: probe of spi0.0 failed with error -110 > ... We don't really cease to support damaged hardware but it is true that the *software* failure paths should probably be robust enough to deativate chip select. I would rewrite this as "The failure paths in tpm_tis_spi_transfer() do not deactivate chip select. Send an empty message (cs_select == 0) to overcome this." That's all there needs to be. We do not care about broken hardware. > > Signed-off-by: Peijie Shao > --- > drivers/char/tpm/tpm_tis_spi_main.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c > index a0963a3e92bd..5c8ff343761f 100644 > --- a/drivers/char/tpm/tpm_tis_spi_main.c > +++ b/drivers/char/tpm/tpm_tis_spi_main.c > @@ -105,8 +105,19 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, > /* Flow control transfers are receive only */ > spi_xfer.tx_buf = NULL; > ret = phy->flow_control(phy, &spi_xfer); > - if (ret < 0) > + if (ret < 0) { > + /* > + * Release cs pin if the device is not responding, regardless of the reason. > + * Notice cs may alreadly been released if the failure was caused inside > + * spi_sync_locked called by flow_control, in this situation, a pluse may be > + * generated on cs. > + */ Please replace above comment with: /* Deactivate chip select: */ > + memset(&spi_xfer, 0, sizeof(spi_xfer)); > + spi_message_init(&m); > + spi_message_add_tail(&spi_xfer, &m); > + spi_sync_locked(phy->spi_device, &m); > goto exit; > + } > > spi_xfer.cs_change = 0; > spi_xfer.len = transfer_len; > -- > 2.39.1 > > > There's three call sites, why are you taking care of only one of them? I'd consider instead: return 0; exit: memset(&spi_xfer, 0, sizeof(spi_xfer)); spi_message_init(&m); spi_message_add_tail(&spi_xfer, &m); spi_sync_locked(phy->spi_device, &m); spi_bus_unlock(phy->spi_device->master); return ret; } The the rollback would apply to all call sites. BR, Jarkko