* [PATCH] x86/cacheinfo: fix a -Wtype-limits warning
@ 2019-06-05 19:40 Qian Cai
2019-06-05 20:07 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: Qian Cai @ 2019-06-05 19:40 UTC (permalink / raw)
To: tglx, mingo, bp; +Cc: hpa, x86, linux-kernel, Qian Cai
cpuinfo_x86.x86_model is an unsigned type, so compares it against zero
will generate a compilation warning,
arch/x86/kernel/cpu/cacheinfo.c: In function
'cacheinfo_amd_init_llc_id':
arch/x86/kernel/cpu/cacheinfo.c:662:19: warning: comparison is always
true due to limited range of data type [-Wtype-limits]
Signed-off-by: Qian Cai <cai@lca.pw>
---
arch/x86/kernel/cpu/cacheinfo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
index 395d46f78582..c7503be92f35 100644
--- a/arch/x86/kernel/cpu/cacheinfo.c
+++ b/arch/x86/kernel/cpu/cacheinfo.c
@@ -658,8 +658,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
if (c->x86 < 0x17) {
/* LLC is at the node level. */
per_cpu(cpu_llc_id, cpu) = node_id;
- } else if (c->x86 == 0x17 &&
- c->x86_model >= 0 && c->x86_model <= 0x1F) {
+ } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) {
/*
* LLC is at the core complex level.
* Core complex ID is ApicId[3] for these processors.
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/cacheinfo: fix a -Wtype-limits warning
2019-06-05 19:40 [PATCH] x86/cacheinfo: fix a -Wtype-limits warning Qian Cai
@ 2019-06-05 20:07 ` Sean Christopherson
2019-06-19 17:01 ` Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2019-06-05 20:07 UTC (permalink / raw)
To: Qian Cai; +Cc: tglx, mingo, bp, hpa, x86, linux-kernel
On Wed, Jun 05, 2019 at 03:40:54PM -0400, Qian Cai wrote:
> cpuinfo_x86.x86_model is an unsigned type, so compares it against zero
> will generate a compilation warning,
>
> arch/x86/kernel/cpu/cacheinfo.c: In function
> 'cacheinfo_amd_init_llc_id':
> arch/x86/kernel/cpu/cacheinfo.c:662:19: warning: comparison is always
> true due to limited range of data type [-Wtype-limits]
>
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
> arch/x86/kernel/cpu/cacheinfo.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
> index 395d46f78582..c7503be92f35 100644
> --- a/arch/x86/kernel/cpu/cacheinfo.c
> +++ b/arch/x86/kernel/cpu/cacheinfo.c
> @@ -658,8 +658,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
> if (c->x86 < 0x17) {
> /* LLC is at the node level. */
> per_cpu(cpu_llc_id, cpu) = node_id;
> - } else if (c->x86 == 0x17 &&
> - c->x86_model >= 0 && c->x86_model <= 0x1F) {
> + } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) {
Might be worth calling out in the changelog that 'c->x86 == 0x17' is true
if and only if c->x86_model was explicitly set by cpu_detect(), i.e. the
patch is correct even if the original intent was a misguided attempt to
check that x86_model has been set.
Fixes: 68091ee7ac3c ("x86/CPU/AMD: Calculate last level cache ID from number of sharing threads")
Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
> /*
> * LLC is at the core complex level.
> * Core complex ID is ApicId[3] for these processors.
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/cacheinfo: fix a -Wtype-limits warning
2019-06-05 20:07 ` Sean Christopherson
@ 2019-06-19 17:01 ` Borislav Petkov
2019-06-19 17:12 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2019-06-19 17:01 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Qian Cai, tglx, mingo, hpa, x86, linux-kernel
On Wed, Jun 05, 2019 at 01:07:04PM -0700, Sean Christopherson wrote:
> Might be worth calling out in the changelog that 'c->x86 == 0x17' is true
> if and only if c->x86_model was explicitly set by cpu_detect(), i.e. the
> patch is correct even if the original intent was a misguided attempt to
> check that x86_model has been set.
Are you thinking about some sick virt scenario where base CPUID level is < 1?
In this particular case, there's a guard at the beginning of
cacheinfo_amd_init_llc_id():
if (!cpuid_edx(0x80000006))
return;
but if there's CPUs which have CPUID 0x80000006 but base CPUID level is
< 1, then that's their problem.
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/cacheinfo: fix a -Wtype-limits warning
2019-06-19 17:01 ` Borislav Petkov
@ 2019-06-19 17:12 ` Sean Christopherson
2019-06-19 17:18 ` Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2019-06-19 17:12 UTC (permalink / raw)
To: Borislav Petkov; +Cc: Qian Cai, tglx, mingo, hpa, x86, linux-kernel
On Wed, Jun 19, 2019 at 07:01:27PM +0200, Borislav Petkov wrote:
> On Wed, Jun 05, 2019 at 01:07:04PM -0700, Sean Christopherson wrote:
> > Might be worth calling out in the changelog that 'c->x86 == 0x17' is true
> > if and only if c->x86_model was explicitly set by cpu_detect(), i.e. the
> > patch is correct even if the original intent was a misguided attempt to
> > check that x86_model has been set.
>
> Are you thinking about some sick virt scenario where base CPUID level is < 1?
Ha, no. My comment was that it'd be worth explaining that the original
'c->x86_model >= 0' check was completely bogus, even if the intent was
something like 'c->x86_model != 0'.
> In this particular case, there's a guard at the beginning of
> cacheinfo_amd_init_llc_id():
>
> if (!cpuid_edx(0x80000006))
> return;
>
> but if there's CPUs which have CPUID 0x80000006 but base CPUID level is
> < 1, then that's their problem.
>
> --
> Regards/Gruss,
> Boris.
>
> Good mailing practices for 400: avoid top-posting and trim the reply.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/cacheinfo: fix a -Wtype-limits warning
2019-06-19 17:12 ` Sean Christopherson
@ 2019-06-19 17:18 ` Borislav Petkov
0 siblings, 0 replies; 5+ messages in thread
From: Borislav Petkov @ 2019-06-19 17:18 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Qian Cai, tglx, mingo, hpa, x86, linux-kernel
On Wed, Jun 19, 2019 at 10:12:49AM -0700, Sean Christopherson wrote:
> Ha, no. My comment was that it'd be worth explaining that the original
> 'c->x86_model >= 0' check was completely bogus, even if the intent was
> something like 'c->x86_model != 0'.
Nah, the intent was, I believe, to convert a model range into a
conditional. If ->x86_model is not set we have bigger problems.
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-19 17:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 19:40 [PATCH] x86/cacheinfo: fix a -Wtype-limits warning Qian Cai
2019-06-05 20:07 ` Sean Christopherson
2019-06-19 17:01 ` Borislav Petkov
2019-06-19 17:12 ` Sean Christopherson
2019-06-19 17:18 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).