From: Dave Hansen <dave.hansen@intel.com>
To: "Huang, Kai" <kai.huang@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
"jgross@suse.com" <jgross@suse.com>,
"x86@kernel.org" <x86@kernel.org>, "bp@alien8.de" <bp@alien8.de>
Subject: Re: [PATCH 1/4] x86/cpu: Add and use new CPUID region helper
Date: Tue, 2 Apr 2024 10:13:31 -0700 [thread overview]
Message-ID: <e462f223-7986-4e91-89cb-6274b97c3246@intel.com> (raw)
In-Reply-To: <d33b97aecfe09cab31ebf06de3e02b633314ae9d.camel@intel.com>
On 3/25/24 05:24, Huang, Kai wrote:
>
> Nit:
>
>> +
>> +/* Returns true if the leaf exists and @value was populated */
>
> ^ is ?
It's a subtle difference, but I think it's better as I wrote it.
Returning true happens *after* the value _was_ populated.
>> +static inline bool get_cpuid_region_leaf(u32 leaf, enum cpuid_regs_idx reg,
>> + u32 *value)
>> +{
>> + u16 region = leaf >> 16;
>> + u32 regs[4];
>> +
>> + if (cpuid_region_max_leaf(region) < leaf)
>> + return false;
>> +
>> + cpuid(leaf, ®s[CPUID_EAX], ®s[CPUID_EBX],
>> + ®s[CPUID_ECX], ®s[CPUID_EDX]);
>> +
>> + *value = regs[reg];
>> +
>> + return true;
>> +}
>
> I found despite the get_cpuid_region_leaf() returns true/false, the return value
> is never used in this series. Instead, this series uses below pattern:
>
> u32 data = 0; /* explicit initialization */
>
> get_cpuid_region_leaf(leaf, ..., &data);
>
> Which kinda implies the 'data' won't be touched if the requested leaf isn't
> supported I suppose?
>
> Since the return value is never used, should we consider just making this
> function void?
I certainly considered it.
But I do think that get_cpuid_region_leaf() looks a lot more obviously
correct and useful when it explicitly returns what it did, even if the
existing callers don't take advantage of it.
I suspect it generates the same code either way.
next prev parent reply other threads:[~2024-04-02 17:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 17:56 [PATCH 0/4] x86: Add CPUID region helper and clarify Xen startup Dave Hansen
2024-03-22 17:56 ` [PATCH 1/4] x86/cpu: Add and use new CPUID region helper Dave Hansen
2024-03-24 4:38 ` Ingo Molnar
2024-03-25 12:24 ` Huang, Kai
2024-04-02 17:13 ` Dave Hansen [this message]
2024-04-03 10:33 ` Huang, Kai
2024-04-04 23:35 ` Chang S. Bae
2024-03-22 17:56 ` [PATCH 2/4] perf/x86/ibs: Use " Dave Hansen
2024-03-22 17:56 ` [PATCH 3/4] x86/boot: Explicitly pass NX enabling status Dave Hansen
2024-03-25 12:04 ` Huang, Kai
2024-03-22 17:56 ` [PATCH 4/4] x86/xen: Enumerate NX from CPUID directly Dave Hansen
2024-04-03 15:35 [PATCH 0/4] [v2] x86: Add CPUID region helper and clarify Xen startup Dave Hansen
2024-04-03 15:35 ` [PATCH 1/4] x86/cpu: Add and use new CPUID region helper Dave Hansen
2024-04-04 9:04 ` Jürgen Groß
2024-04-08 16:25 ` Borislav Petkov
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=e462f223-7986-4e91-89cb-6274b97c3246@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=jgross@suse.com \
--cc=kai.huang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--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 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®