From patchwork Mon Jun 5 17:59:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2875757vqr; Mon, 5 Jun 2023 11:27:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6njJKLJfhy6zeB7ydhbzCKO7rqq1LrXxo29V/SwScrI3hjzLF9khQi49t+r++UIw/va098 X-Received: by 2002:a17:902:6509:b0:1af:bbfd:1c07 with SMTP id b9-20020a170902650900b001afbbfd1c07mr8064937plk.57.1685989670188; Mon, 05 Jun 2023 11:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685989670; cv=none; d=google.com; s=arc-20160816; b=TgVTtC+Kjh4nSpSpBxR2TzQJ+x1qyMGOaNC4lilntKRL5IksT+NQkz0IthrAM+2GYR doJ9jdlznFvQNOkNpKn0+V6t4O1CaOeJFVZJ6fn7Ly6xRdWjw9yXvVPjH48GVmuiB0d8 vMt/3q3qvmf0AHzfWBUg2k4tsEix3fmhSmQ5iJLVifdqwBRKCS0JP61V5mDPnXiYmegP 4yiiPxnoWYc2wJEqx2frxf48JTejgjM79hm0iUkWyY1+bv9++n+IfoQpNcmCGLpMVs9m LUoChUAgaNRADjp+6B6n/9evjYqVphK3cCEpGlR5CYOI94LHFXfiUOHVDt/mA4/9fwIm nLpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lhIvdsY1fmzgl4mlwx9ldBWMXg48hj3vrnGED3H/TbQ=; b=BTrvs/DfJHGIxE4WixAovLO0nA2yoWU5QYvWb9qHsKwA79o6ykJ2r0F53x0b7AZd3i ramWmxUxsjxAozrEP78qmTakfcRe9ayM3qPhBcf+AfcVxTeaz/lz2pCEz2VBpSmrdCoL CwcNlvWmIQ/Dy/XAgTYR3iD5q8VSRXFsCBaaAO4pPbJGDCKy1CxMGQIpAOXbkc1wd2xo PSudi4ObRdcHtG9Lc/usJf4xaM/rhwSqnERUcVTAyR4MjzN8boFux2Vtue3joXj6WmwN v+6CmESFfyZIZ4Z5pp4gJqe3BRqHKyjca/iFQbLGZQtz3WXO7MtPNMLlHk5BX4hzaG7l LzrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=STzSKAPq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902a38100b001ac2ff9fbf8si5553475pla.403.2023.06.05.11.27.34; Mon, 05 Jun 2023 11:27:50 -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=fail header.i=@infineon.com header.s=IFXMAIL header.b=STzSKAPq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233705AbjFESAS (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjFESAL (ORCPT ); Mon, 5 Jun 2023 14:00:11 -0400 Received: from smtp2.infineon.com (smtp2.infineon.com [IPv6:2a00:18f0:1e00:4::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66602D3; Mon, 5 Jun 2023 11:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988010; x=1717524010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=unN7GipSX//PB49ZOaB1Vh0lCsSkaIGKdO4Lzy+O6v0=; b=STzSKAPqj5lHk2fwDHS8N+VvYAUrgzmw1F7345Lpe6AcscqXRZlACb/X SKvVkhVTH78GQjxbvD35EUhj0MeWtztak7VUhdGg0DJxujd7ga80pXVbF GL4Q+2nGFWJfAZbRBYMXqVM7lneVw7Oj90hcajcYY3715ls/gFHEIwCcz g=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="40773232" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="40773232" Received: from unknown (HELO MUCSE803.infineon.com) ([172.23.29.29]) by smtp2.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:08 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE803.infineon.com (172.23.29.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:08 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:08 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 1/4] tpm_tis: Explicitly check for error code Date: Mon, 5 Jun 2023 19:59:56 +0200 Message-ID: <20230605175959.2131-2-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767888304179760733?= X-GMAIL-MSGID: =?utf-8?q?1767888304179760733?= recv_data either returns the number of received bytes, or a negative value representing an error code. Adding the return value directly to the total number of received bytes therefore looks a little weird, since it might add a negative error code to a sum of bytes. The following check for size < expected usually makes the function return ETIME in that case, so it does not cause too many problems in practice. But to make the code look cleaner and because the caller might still be interested in the original error code, explicitly check for the presence of an error code and pass that through. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm_tis_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 558144fa707a..aaaa136044ae 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -363,8 +363,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } - size += recv_data(chip, &buf[TPM_HEADER_SIZE], - expected - TPM_HEADER_SIZE); + rc = recv_data(chip, &buf[TPM_HEADER_SIZE], + expected - TPM_HEADER_SIZE); + if (rc < 0) { + size = rc; + goto out; + } + size += rc; if (size < expected) { dev_err(&chip->dev, "Unable to read remainder of result\n"); size = -ETIME; From patchwork Mon Jun 5 17:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2861393vqr; Mon, 5 Jun 2023 11:03:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4fXucPKr7ZrxRPkEd8/HpdiMYqTyb/YZhuRLFYRnuab8HU7hmilbK+/3p5WDrcDasHRlGS X-Received: by 2002:a05:6a00:2353:b0:648:8c0d:6e4e with SMTP id j19-20020a056a00235300b006488c0d6e4emr433758pfj.19.1685988193391; Mon, 05 Jun 2023 11:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685988193; cv=none; d=google.com; s=arc-20160816; b=zFmsUBkMlB7UGVHTV3wvhKYWMnEmho1CtLgju2H56FNpeTxF9UIIN+fE0j051VZSlR EJ+cddOdYDt4/+Fd7NWO+Mb5yR2nmfBwWgO1qLSxlQgNfHZyqOxCf8TMz6dqQn2Rzfol 9RJrHiMBx5axsOTIUPl7cqt+WB6solnaql/9uLqA4J9rmtiWsb5yUINPwxSVab/ImaNo 06/i1HCzztnN86y1DXs/tTFXaBksHbEdSuWZN88zl1Ld6t43UdUjfL4xd1yA3+gGHrL7 KrPOffXQtIn2ZJwsnzZ3bVBo/KOZhKAbXJ+T6VqJz7xI8kuZ2o+kSI+BQjmBZ3Y2Js1y PSZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EqTJmYrZMev0F8vWNbuIMvFQRIJM9hTAtdrTRdNayhw=; b=TiLrNgXVRyIFE1FcfBS2TjS2NKub769QtuiHk9oRKPCE3zZDeL97P6gSzK9Dz6ACM+ u21pPM6t2B8nR7sHAP1S9C3yROYBso2VIngvuvcU0iC9O8jrrgOaMD2TcvR/sTqm3fzq 0kTbOiH9QM/bpA1frZDgW8ZrwheDnJWzVSb90BeqYKFo9oXtN29rFskgimbSAeJtsP6E K6x3CQcCA/jHrg7q5YYtauS/Dp6dHg0GoH9TTUO0eNwQZtjGvcmAFT8M79dnSCec9Tr2 vGn7VFOCN0d3rhz6jG4xjyLYCF3724oaopeBbFSGIDnNkW6/kUKMhmzIZ7ApVFfnedJv 7Y4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=nFQPneGt; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a26-20020aa794ba000000b0064d2a385c1csi5665133pfl.252.2023.06.05.11.02.58; Mon, 05 Jun 2023 11:03:13 -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=fail header.i=@infineon.com header.s=IFXMAIL header.b=nFQPneGt; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233511AbjFESAW (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjFESAM (ORCPT ); Mon, 5 Jun 2023 14:00:12 -0400 Received: from smtp11.infineon.com (smtp11.infineon.com [IPv6:2a00:18f0:1e00:4::5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC864F1; Mon, 5 Jun 2023 11:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988011; x=1717524011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=89MCpdG+JGXZTxJwkWPn/J+rl3u69O0nt8q8tvWyKNM=; b=nFQPneGteeYZdHM9WhK5PtnP5+kZPzwN56kRiYfX2VPlYvJFoRaMGQbS gl8ae5xwM4mdCLrulJEbOAQx0YEvdyi7mEJPgasRgaO8VvpsMBqsFB9Tx DEo9rELqEdS60rqlpEqxbzSZFIyvmQviag/ENB1L5w0QibbdP7YHqxU7v c=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="17446835" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="17446835" Received: from unknown (HELO MUCSE822.infineon.com) ([172.23.29.53]) by smtp11.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:09 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE822.infineon.com (172.23.29.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:09 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:08 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 2/4] tpm_tis: Move CRC check to generic send routine Date: Mon, 5 Jun 2023 19:59:57 +0200 Message-ID: <20230605175959.2131-3-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767886756145459630?= X-GMAIL-MSGID: =?utf-8?q?1767886756145459630?= The CRC functionality is initialized before tpm_tis_core, so it can be used on all code paths within the module. Therefore, move the CRC check to the generic send routine, that also contains all other checks for successful command transmission, so that all those checks are in one place. Also, this ensures that tpm_tis_ready is called when a CRC failure is detected, to clear the invalid data from the TPM, which did not happen previously. Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index aaaa136044ae..5ddaf24518be 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -466,6 +466,12 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) goto out_err; } + rc = tpm_tis_verify_crc(priv, len, buf); + if (rc < 0) { + dev_err(&chip->dev, "CRC mismatch for command.\n"); + goto out_err; + } + return 0; out_err: @@ -510,12 +516,6 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) if (rc < 0) return rc; - rc = tpm_tis_verify_crc(priv, len, buf); - if (rc < 0) { - dev_err(&chip->dev, "CRC mismatch for command.\n"); - return rc; - } - /* go and do it */ rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO); if (rc < 0) From patchwork Mon Jun 5 17:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2861388vqr; Mon, 5 Jun 2023 11:03:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7iTjZJQgUJxnodzrkJlXoV7GUu4+jIK44+6XM/7AUZL+RKh/BSKq5kCuUG2CDK3nm4JNAT X-Received: by 2002:a05:6a00:98c:b0:63d:2d99:2e7c with SMTP id u12-20020a056a00098c00b0063d2d992e7cmr657048pfg.0.1685988193053; Mon, 05 Jun 2023 11:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685988193; cv=none; d=google.com; s=arc-20160816; b=xcs+oNO929PrmzzCCMmMK0YUfZew9kICBOk+fTbupf+IyXbIcRrBLk0a9MTm2yzdr0 mmru+XeLrNrLfLSvHlLpIWfPBBvorArrvkzn7LJkocq74ahXJEnnbX6oYvRyKtEu0w6+ az9qRoT1iVfxEYTn5sg3IGs/I1rmxc9K/DgU8gTBWg8zhD/StgzPnD873tQSiAHbADve iLkTMNsDHTpss5argNQ5HA+j+mCdmhBoCwNXLYEsWLidSNbFfT80fgWB/2mvswgghAMt WuSsCHv/4BNWi2YA97aiilm9w9MYwx5NuSia6IvKba9n41UDmM2/sPxok+nGI2Qd9ZNT khkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3rxigAc3tgJoRVzWXUTVmobUCPLN7d6KxUKlnCix0gU=; b=PMl2NESf+FzimiVG/iSIk+U2x4tic3UOMoZV6/8CgL0Qey/Hzspuvd0Yf2KiBRfuEW NagB5o5ILSVqU4pTFQkCDmZdPjtAmy/wGOUM3RlHDnrGWglNkE+4M4UZns3nLCOGg8H3 oPw4lAy50QNAdUVqPHWvqhHxiNO+Q/uUKXou6ZTSSU2Yv+LHJIpbm6CZJ1HscTO0LQV1 bPicKnBkzb7hyQO10zuUveKBxIxfsE4eKZwGXMS0HPjPHEGt3qkztx0ZO48HeT0seYWr 8C1Oy+rjen8KtZdaUt+KlaYMc4x2ZMOVUmSEJ0d7nTQwx5VsiXznT24XZCSyWkhOuHqi DBYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=Kh7b07vr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v128-20020a626186000000b0064d32440768si4228379pfb.138.2023.06.05.11.02.58; Mon, 05 Jun 2023 11:03:13 -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=fail header.i=@infineon.com header.s=IFXMAIL header.b=Kh7b07vr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234593AbjFESA2 (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbjFESAN (ORCPT ); Mon, 5 Jun 2023 14:00:13 -0400 Received: from smtp14.infineon.com (smtp14.infineon.com [IPv6:2a00:18f0:1e00:4::6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2478F4; Mon, 5 Jun 2023 11:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988012; x=1717524012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hFaUtOwj7HlaUrYMRdzAtkuiOEy12Jko8agUx6FjxuM=; b=Kh7b07vrMVWbo3Ke+QyxpIODxw32fxvDzaHbUkNCDkvAgj0AyInaLGXE nvieU1jMBlYeOLv7gpVoC55VW5Gxso4MdPLgCH3kniJygdsGVIGInI2Q3 1fwr9c+r3xldgXMt3l4wGZu7+Ly/rmUqknJORJo1WYSP1FHs28GIgMLBN o=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="15904205" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="15904205" Received: from unknown (HELO MUCSE819.infineon.com) ([172.23.29.45]) by smtp14.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:10 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE819.infineon.com (172.23.29.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:09 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:08 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 3/4] tpm_tis: Use responseRetry to recover from data transfer errors Date: Mon, 5 Jun 2023 19:59:58 +0200 Message-ID: <20230605175959.2131-4-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767886755653533995?= X-GMAIL-MSGID: =?utf-8?q?1767886755653533995?= TPM responses may become damaged during transmission, for example due to bit flips on the wire. Instead of aborting when detecting such issues, the responseRetry functionality can be used to make the TPM retransmit its response and receive it again without errors. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm_tis_core.c | 40 ++++++++++++++++++++++++++------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 5ddaf24518be..a08768e55803 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -345,11 +345,6 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) u32 expected; int rc; - if (count < TPM_HEADER_SIZE) { - size = -EIO; - goto out; - } - size = recv_data(chip, buf, TPM_HEADER_SIZE); /* read first 10 bytes, including tag, paramsize, and result */ if (size < TPM_HEADER_SIZE) { @@ -382,7 +377,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } status = tpm_tis_status(chip); - if (status & TPM_STS_DATA_AVAIL) { /* retry? */ + if (status & TPM_STS_DATA_AVAIL) { dev_err(&chip->dev, "Error left over data\n"); size = -EIO; goto out; @@ -396,10 +391,39 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) } out: - tpm_tis_ready(chip); return size; } +static int tpm_tis_recv_with_retries(struct tpm_chip *chip, u8 *buf, size_t count) +{ + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + unsigned int try; + int rc = 0; + + if (count < TPM_HEADER_SIZE) { + rc = -EIO; + goto out; + } + + for (try = 0; try < TPM_RETRY; try++) { + rc = tpm_tis_recv(chip, buf, count); + + if (rc == -EIO) { + /* Data transfer errors, indicated by EIO, can be + * recovered by rereading the response. + */ + tpm_tis_write8(priv, TPM_STS(priv->locality), + TPM_STS_RESPONSE_RETRY); + } else { + break; + } + } + +out: + tpm_tis_ready(chip); + return rc; +} + /* * If interrupts are used (signaled by an irq set in the vendor structure) * tpm.c can skip polling for the data to be available as the interrupt is @@ -986,7 +1010,7 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value) static const struct tpm_class_ops tpm_tis = { .flags = TPM_OPS_AUTO_STARTUP, .status = tpm_tis_status, - .recv = tpm_tis_recv, + .recv = tpm_tis_recv_with_retries, .send = tpm_tis_send, .cancel = tpm_tis_ready, .update_timeouts = tpm_tis_update_timeouts, diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index e978f457fd4d..8458cd4a84ec 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -34,6 +34,7 @@ enum tis_status { TPM_STS_GO = 0x20, TPM_STS_DATA_AVAIL = 0x10, TPM_STS_DATA_EXPECT = 0x08, + TPM_STS_RESPONSE_RETRY = 0x02, TPM_STS_READ_ZERO = 0x23, /* bits that must be zero on read */ }; From patchwork Mon Jun 5 17:59:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 103435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2878312vqr; Mon, 5 Jun 2023 11:32:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ggVdrNStOaAII5T1wdPL0v37JVwu4VjSW8+8NV2Cln9LWHuNuvjlcSQuKPBsPaBYUBHuy X-Received: by 2002:a05:6a20:115:b0:111:c8a6:88ca with SMTP id 21-20020a056a20011500b00111c8a688camr3468637pzr.58.1685989952743; Mon, 05 Jun 2023 11:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685989952; cv=none; d=google.com; s=arc-20160816; b=ES5uIAr+9fIw++VwunHRbFasrzTqFdAW3RffB91o1hWdvmLBWXqDp4BKODDrUGMEJt 68rZaS1c3B9QGJY6VEq1l1ARsgYOMiRiqlT3CmetfMAjVKCRt1TTsAGVGrCBYFxtb2N1 +ZEONzYs5TjcWO7LKuteetmoWyAA2TElNqL+5S5sqD3TxVEAAlqZbjGKK8g38EaWz0lG R023Jyt/Y6hHZdC+u6Q30gJhvO/bk8wl47oGS7rjAlct8W7T6Xw8gGjtQsDjIx0GnHaq 5B064FG7xUMClzkTOqEK08fI7yffnpv9uWayb0wS6S/S6pJJdo0GGVms8s1rANnC0D71 f5mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y48qn1exMGtuPXIINonrkdSm1vvkhA4TAan01YmNdSI=; b=FF8iAywrX19TJ6wJhFugs6aBB7t6FcHXxJbCqiDD5Y6yG03NUzejH2CGQ1XzoGsWiO 9/A5LI9VHgtKyuqNa63E5u66yvbN/3M2DjzPXsCaJgzi3ADO+njglssi/zUV7fGaBMlu H6INFHH2VNFieYD3WGw32CeK8Rb3Mxr3VNGVaae3azVnEv3l23fz4/EWQa7tUYaNqo4F TI+DEE1+qMHVJrf5vBNfbPEbrnjDLBhpgkQa3vLf5zrsx3c5gB+LtUOdAd+lE2BpSR0n B+VYjtiWLZI0dXfu/Bq7w5rjD5fIehs3a3QquHIfm3AKt2VnuB6yF4UsgQg3lW/o4lv0 es8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=nMXCo8CX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a636f0d000000b0054033bf35easi5895411pgc.269.2023.06.05.11.32.20; Mon, 05 Jun 2023 11:32:32 -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=fail header.i=@infineon.com header.s=IFXMAIL header.b=nMXCo8CX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234370AbjFESAZ (ORCPT + 99 others); Mon, 5 Jun 2023 14:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbjFESAN (ORCPT ); Mon, 5 Jun 2023 14:00:13 -0400 Received: from smtp14.infineon.com (smtp14.infineon.com [IPv6:2a00:18f0:1e00:4::6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC423F9; Mon, 5 Jun 2023 11:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1685988012; x=1717524012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xcXJAmG61qBDUJlBGCtCv2jhORoDcv/wLfQldALvPrI=; b=nMXCo8CXy5I5EEaDpABG2A/Tw4t09po6IunzbAQrO+9jGwe5DVIPmHCP LlYHDPZ7K50ojyVKyCF5YCQyejLSTjUjKwhIaH7N5FlOVT5CfOFul9y1Y yaRMdD5Z7iTmBgzQ2CuQtZR5fgcw5TSBk+4w05eQe2P+HvYrE7MTTnq1L A=; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="15904206" X-IronPort-AV: E=Sophos;i="6.00,218,1681164000"; d="scan'208";a="15904206" Received: from unknown (HELO MUCSE814.infineon.com) ([172.23.29.40]) by smtp14.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 20:00:10 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE814.infineon.com (172.23.29.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:09 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 5 Jun 2023 20:00:09 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v2 4/4] tpm_tis: Resend command to recover from data transfer errors Date: Mon, 5 Jun 2023 19:59:59 +0200 Message-ID: <20230605175959.2131-5-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230605175959.2131-1-Alexander.Steffen@infineon.com> References: <20230605175959.2131-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE804.infineon.com (172.23.29.30) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767888600888733029?= X-GMAIL-MSGID: =?utf-8?q?1767888600888733029?= Similar to the transmission of TPM responses, also the transmission of TPM commands may become corrupted. Instead of aborting when detecting such issues, try resending the command again. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm_tis_core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index a08768e55803..47073cc79b51 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -535,10 +535,18 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) int rc; u32 ordinal; unsigned long dur; + unsigned int try; - rc = tpm_tis_send_data(chip, buf, len); - if (rc < 0) - return rc; + for (try = 0; try < TPM_RETRY; try++) { + rc = tpm_tis_send_data(chip, buf, len); + if (rc >= 0) { + /* Data transfer done successfully */ + break; + } else if (rc != -EIO) { + /* Data transfer failed, not recoverable */ + return rc; + } + } /* go and do it */ rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);