Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp9754rwr; Tue, 25 Apr 2023 16:40:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ZLLLjsQHcvz1cH2iX3H55xGESbqbmayt2Ze+7uZBalg9DOplnY6fB+Z2J4xrKiEZL2gf25 X-Received: by 2002:aa7:8896:0:b0:63c:6485:d5fd with SMTP id z22-20020aa78896000000b0063c6485d5fdmr26668605pfe.2.1682466016420; Tue, 25 Apr 2023 16:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682466016; cv=none; d=google.com; s=arc-20160816; b=chwldQ+qHe789K5ZWxjKz5V3ZP9vJ2PI+lJggznwd4jdtj3FFGuefX0GtK6ukZYRA+ vW4ZE9jGxiCZfREGkzxrNIr8mvCvAyazbuiwibcg363jgWjvWMS4haRis7nYBV+DG7EJ DtEk0c1LHfKEqBEyk+A4TSKOcpFp6jB0ZNM1/cmggXRS7Ra17MV84OpDae0lOBADLz+I Mq7XaYvqlql/7zpVC1QBo9B+rauRNRsB7zYj6Qxx04FxTItagpSFSgtZhveXaMg4etWB 9h5HCLxxTdmis5Aha+pW6Ryvo9mFFbBRxavFKkvUvSgBe3qvjnpURP0596vLBs/zKF0K 3RwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=U53MOP0+b33Fl+B9u63+9vRYoTLt+qmlWDuk/XaSGOU=; b=pjFAIKP+U39Jf9nLeASAFwD+ysGomIbkS3wBbxfZNhAKNTEOSEIvbGiBXZrdDZ9Hip Q50/VBzShMZDgu1C64d5RsrQHgfjGTmZWdOPbHc+y5W1ir+84SwT1S43ZMSKMDoYANI8 t2w7pt7vQpQORjG8OZO2wkiqD3V3W5dbx4400TTnDyBVfzdu7zyCgOykVLoW53Fz5KlP xuAEalog80/QRP7qlSElSBiD2jtHYzivKfvSD2zYTHK5MfcDZwV8oyPG0wHFGR61UHTR ynYhJC4CgXO/UyhLfnsFfjX/bgl8D5ctr2gsXCCZl4kyejfkZNY2r0G+u8Ya8CwKFLzX vWCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IvyVDNCD; 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 v202-20020a6361d3000000b00519d4818029si14825657pgb.152.2023.04.25.16.40.03; Tue, 25 Apr 2023 16:40:16 -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=IvyVDNCD; 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 S236393AbjDYXee (ORCPT + 99 others); Tue, 25 Apr 2023 19:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231391AbjDYXec (ORCPT ); Tue, 25 Apr 2023 19:34:32 -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 A6964C17A; Tue, 25 Apr 2023 16:34:31 -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 34038631FF; Tue, 25 Apr 2023 23:34:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B055C433EF; Tue, 25 Apr 2023 23:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682465670; bh=K1s+noYHRNni1Pq8/RE/Mli4hvd2z61+wK3Y1vv2LyM=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=IvyVDNCDCp2/r5VUoQebr/oJMDXprGJWwwUPukWZJTyggmDDXq2zfulSb8y5dg3S+ ity3qLWMdUtRj2O7fQVWOoUcT6wIbHMuf5Ng9ZXVSeKwxpDcNgPO9nBj9c5fJNsRzQ 1/wPHzv7d4OYTly4E7Vb1DB7MAIbXJ0WkaJVZ5LYE2Ycl+kztWZAYZ8gF1e3OSzYWT 45lUd9QwH9I3gSxrpKHJARTqNcEVu68C50jshkFFkizf0AE5nmIcDTQ0XTurTuV+ou Cf4JFjB++Jc/5fT8ylTV0sTaSUooMn3ENKxf/NVHnCBghFauxj735kaHOEmrMx+t/3 tnwGYgaMPdoTw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 26 Apr 2023 02:34:25 +0300 Message-Id: Cc: "Thorsten Leemhuis" , "James Bottomley" , "Vlastimil Babka" , "Peter Huewe" , "Jason Gunthorpe" , "Jan Dabros" , , "LKML" , , "Dominik Brodowski" , "Herbert Xu" , "Linus Torvalds" , "Johannes Altmanninger" Subject: Re: [REGRESSION] suspend to ram fails in 6.2-rc1 due to tpm errors From: "Jarkko Sakkinen" To: "Jarkko Sakkinen" , "Jason A. Donenfeld" X-Mailer: aerc 0.14.0 References: <7ebab1ff-48f1-2737-f0d3-25c72666d041@leemhuis.info> <4268d0ac-278a-28e4-66d1-e0347f011f46@leemhuis.info> In-Reply-To: X-Spam-Status: No, score=-4.6 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 Sun Apr 23, 2023 at 6:34 PM EEST, Jarkko Sakkinen wrote: > On Fri Apr 21, 2023 at 9:27 PM EEST, Jason A. Donenfeld wrote: > > Did you use the patch I sent you and suspend and resume according to > > the instructions I gave you? If not, I don't have much to add. > > Finally, I got it reproduced at my side with TPM 1.2: > > [ 0.379677] tpm_tis 00:00: 1.2 TPM (device-id 0x1, rev-id 1) > [ 32.453447] tpm tpm0: tpm_transmit: tpm_recv: error -5 > [ 33.450601] tpm tpm0: Unable to read header > [ 33.450607] tpm tpm0: tpm_transmit: tpm_recv: error -62 > > I'll look at this further after I've sent v6.3 PR. OK, so this gives the exact tpm_transmit call where it fails: $ sudo bpftrace -e 'kprobe:tpm_transmit { @[kstack] =3D count(); }' [sudo] password for jarkko: Attaching 1 probe... ^C @[ tpm_transmit+1 tpm1_pcr_read+177 tpm1_do_selftest+287 tpm_tis_resume+443 pnp_bus_resume+102 dpm_run_callback+81 device_resume+173 dpm_resume+238 dpm_resume_end+17 suspend_devices_and_enter+473 enter_state+563 pm_suspend+68 state_store+43 kobj_attr_store+15 sysfs_kf_write+59 kernfs_fop_write_iter+304 vfs_write+590 ksys_write+115 __x64_sys_write+25 do_syscall_64+88 entry_SYSCALL_64_after_hwframe+114 ]: 1 @[ tpm_transmit+1 tpm1_do_selftest+179 tpm_tis_resume+443 pnp_bus_resume+102 dpm_run_callback+81 device_resume+173 dpm_resume+238 dpm_resume_end+17 suspend_devices_and_enter+473 enter_state+563 pm_suspend+68 state_store+43 kobj_attr_store+15 sysfs_kf_write+59 kernfs_fop_write_iter+304 vfs_write+590 ksys_write+115 __x64_sys_write+25 do_syscall_64+88 entry_SYSCALL_64_after_hwframe+114 ]: 1 @[ tpm_transmit+1 tpm1_pm_suspend+203 tpm_pm_suspend+131 __pnp_bus_suspend+65 pnp_bus_suspend+19 dpm_run_callback+81 __device_suspend+329 dpm_suspend+432 dpm_suspend_start+155 suspend_devices_and_enter+370 enter_state+563 pm_suspend+68 state_store+43 kobj_attr_store+15 sysfs_kf_write+59 kernfs_fop_write_iter+304 vfs_write+590 ksys_write+115 __x64_sys_write+25 do_syscall_64+88 entry_SYSCALL_64_after_hwframe+114 ]: 1 @[ tpm_transmit+1 tpm1_get_random+206 tpm_get_random+70 tpm_hwrng_read+21 hwrng_fillfn+234 kthread+230 ret_from_fork+41 ]: 75897 So it is the very first PCR read in tpm1_do_selftest. There is a bug at plain sight in tpm1_tis_resume(): before tpm_tis_resume() calls tpm1_do_selftest(), it only requests and relinquishes locality. This is not sufficient: it should also disable clkrun protocol. tpm1_do_selftest() is called also during the driver initialization successfully, the difference being that clkrun protocol is disabled. I'm compiling now a kernel with a test fix that calls tpm_chip_start() and tpm_chip_stop() as a substitute for request/relinquish locality. These should be used anyway instead of ad-hoc code. BR, Jarkko BR, Jarkko