From: "Nikunj A. Dadhania" <nikunj@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
Dionna Amalie Glaze <dionnaglaze@google.com>
Cc: linux-kernel@vger.kernel.org, bp@alien8.de, x86@kernel.org,
tglx@linutronix.de, mingo@redhat.com,
dave.hansen@linux.intel.com, aik@amd.com, stable@vger.kernel.org
Subject: Re: [PATCH] x86/sev: Use TSC_FACTOR for Secure TSC frequency calculation
Date: Wed, 25 Jun 2025 19:33:19 +0530 [thread overview]
Message-ID: <457b00a1-ee0e-4435-9066-8ba587484e0f@amd.com> (raw)
In-Reply-To: <39c23b91-6e5a-033c-e000-c6926b1ea1e4@amd.com>
On 6/25/2025 7:01 PM, Tom Lendacky wrote:
> On 6/24/25 23:55, Nikunj A. Dadhania wrote:
>>
>> Thanks for the review.
>>
>> On 6/25/2025 12:34 AM, Dionna Amalie Glaze wrote:
>>> On Mon, Jun 23, 2025 at 9:17 PM Nikunj A Dadhania <nikunj@amd.com> wrote:
>> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
>> index ffd44712cec0..9e1e8affb5a8 100644
>> --- a/arch/x86/coco/sev/core.c
>> +++ b/arch/x86/coco/sev/core.c
>> @@ -2184,19 +2184,8 @@ void __init snp_secure_tsc_init(void)
>>
>> setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
>> rdmsrq(MSR_AMD64_GUEST_TSC_FREQ, tsc_freq_mhz);
>> - snp_tsc_freq_khz = (unsigned long)(tsc_freq_mhz * 1000);
>> -
>> - /*
>> - * Obtain the mean TSC frequency by decreasing the nominal TSC frequency with
>> - * TSC_FACTOR as documented in the SNP Firmware ABI specification:
>> - *
>> - * GUEST_TSC_FREQ * (1 - (TSC_FACTOR * 0.00001))
>> - *
>> - * which is equivalent to:
>> - *
>> - * GUEST_TSC_FREQ -= (GUEST_TSC_FREQ * TSC_FACTOR) / 100000;
>> - */
>> - snp_tsc_freq_khz -= (snp_tsc_freq_khz * secrets->tsc_factor) / 100000;
>> + snp_tsc_freq_khz = (unsigned long) SNP_SCALE_TSC_FREQ(tsc_freq_mhz * 1000,
>> + secrets->tsc_factor);
>
> I would make any casts live in the macro. Although snp_tsc_freq_khz is a
> u64, right, but is always returned/used as an unsigned long? I'm wondering
> why it isn't defined as an unsigned long? Not sure how everything would look.
The unsigned long requirement came from the calibrate callbacks:
arch/x86/include/asm/x86_init.h:312: unsigned long (*calibrate_cpu)(void);
arch/x86/include/asm/x86_init.h:313: unsigned long (*calibrate_tsc)(void);
But as you suggested we can drop the cast here and securetsc_get_tsc_khz() should
cast the return to unsigned long. I am trying to recall why didn't we do this in the
first place.
@@ -2162,20 +2162,32 @@ void __init snp_secure_tsc_prepare(void)
static unsigned long securetsc_get_tsc_khz(void)
{
- return snp_tsc_freq_khz;
+ return (unsigned long)snp_tsc_freq_khz;
}
And:
- snp_tsc_freq_khz = (unsigned long)(tsc_freq_mhz * 1000);
+ snp_tsc_freq_khz = SNP_SCALE_TSC_FREQ(tsc_freq_mhz * 1000, secrets->tsc_factor);
I will send an updated patch with the above changes.
Regards
Nikunj
prev parent reply other threads:[~2025-06-25 14:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 8:08 [PATCH] x86/sev: Use TSC_FACTOR for Secure TSC frequency calculation Nikunj A Dadhania
2025-06-24 4:13 ` Nikunj A Dadhania
2025-06-24 19:04 ` Dionna Amalie Glaze
2025-06-25 4:55 ` Nikunj A. Dadhania
2025-06-25 13:31 ` Tom Lendacky
2025-06-25 14:03 ` Nikunj A. Dadhania [this message]
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=457b00a1-ee0e-4435-9066-8ba587484e0f@amd.com \
--to=nikunj@amd.com \
--cc=aik@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dionnaglaze@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.