From: "Orlov, Ivan" <ivan.orlov0322@gmail.com>
To: Jarkko Sakkinen <jarkko@kernel.org>, "Orlov, Ivan" <iorlov@amazon.co.uk>
Cc: "peterhuewe@gmx.de" <peterhuewe@gmx.de>,
"jgg@ziepe.ca" <jgg@ziepe.ca>,
"linux-integrity@vger.kernel.org"
<linux-integrity@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Woodhouse, David" <dwmw@amazon.co.uk>
Subject: Re: [PATCH] tpm: Fix the timeout & use ktime
Date: Fri, 20 Jun 2025 18:19:43 +0100 [thread overview]
Message-ID: <bda377bf-10f8-49d9-8e58-ec957a40e4d7@gmail.com> (raw)
In-Reply-To: <aEm2p-2p3W3Xw5OU@kernel.org>
On 11/06/2025 18:02, Jarkko Sakkinen wrote:
>> Instead, perform the check in the following way:
>>
>> 1. Read the current timestamp
>> 2. Read the completion status. If completed, return the result
>> 3. Sleep
>> 4. Check if the timestamp read at step 1 exceeds the timeout. Return
>> an error if it does
>> 5. Goto 1
>>
>> Also, use ktime instead of jiffes as a more reliable and precise timing
>> source.
>
> "also", i.e. a logically separate change which should be split up to
> a separate patch.
>
Got it, will send this enhancement as a separate patch.
>> + curr_time = ktime_get();
>> u8 status = tpm_chip_status(chip);
>> if ((status & chip->ops->req_complete_mask) ==
>> chip->ops->req_complete_val)
>> @@ -140,7 +149,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
>>
>> tpm_msleep(TPM_TIMEOUT_POLL);
>> rmb();
>> - } while (time_before(jiffies, stop));
>> + } while (ktime_before(curr_time, timeout));
>
>
> Wouldn't it be simpler fix to just check completion after dropping out
> of the loop?
>
yes, this should also solve the problem without taking additional space
on the stack with new vars. Will update in V2, thanks!
> And declare this before tpm_try_transmit():
>
> static bool tpm_transmit_completed(struct tpm_chip *chip)
> {
> u8 status = tpm_chip_status(chip);
>
> return (status & chip->ops->req_complete_mask) == chip->ops->req_complete_val;
> }
>
Cool, will do.
Thanks for the review and sorry for the late reply.
--
Kind regards,
Ivan Orlov
next prev parent reply other threads:[~2025-06-20 17:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 16:25 Orlov, Ivan
2025-06-11 17:02 ` Jarkko Sakkinen
2025-06-20 17:19 ` Orlov, Ivan [this message]
2025-06-20 13:24 ` Jonathan McDowell
2025-06-20 17:23 ` Orlov, Ivan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bda377bf-10f8-49d9-8e58-ec957a40e4d7@gmail.com \
--to=ivan.orlov0322@gmail.com \
--cc=dwmw@amazon.co.uk \
--cc=iorlov@amazon.co.uk \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®