From: Pu Wen <puwen@hygon.cn>
To: <bp@alien8.de>, <tglx@linutronix.de>, <mingo@redhat.com>,
<hpa@zytor.com>, <x86@kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Pu Wen <puwen@hygon.cn>
Subject: [PATCH] x86/cpu: Avoid endless loop to get the number of cache leaves
Date: Mon, 5 Nov 2018 20:53:45 +0800 [thread overview]
Message-ID: <1541422425-5855-1-git-send-email-puwen@hygon.cn> (raw)
To get the number of cache leaves on AMD or Hygon platform, it should
get the value of cpuid leaf 0x8000001d. But on certain broken platform
such as a not fullly implemented virtual platform(Xen, for example),
the value of the cpuid leaf will nerver be CTYPE_NULL, so the kernel
will run into an endless loop.
To fix this problem, add a new enum type CTYPE_MAX to limit the maximum
cpuid accessing.
Signed-off-by: Pu Wen <puwen@hygon.cn>
---
arch/x86/kernel/cpu/cacheinfo.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
index dc1b934..7bd167f 100644
--- a/arch/x86/kernel/cpu/cacheinfo.c
+++ b/arch/x86/kernel/cpu/cacheinfo.c
@@ -121,7 +121,8 @@ enum _cache_type {
CTYPE_NULL = 0,
CTYPE_DATA = 1,
CTYPE_INST = 2,
- CTYPE_UNIFIED = 3
+ CTYPE_UNIFIED = 3,
+ CTYPE_MAX = 4
};
union _cpuid4_leaf_eax {
@@ -640,7 +641,7 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c)
/* Do cpuid(op) loop to find out num_cache_leaves */
cpuid_count(op, i, &eax, &ebx, &ecx, &edx);
cache_eax.full = eax;
- } while (cache_eax.split.type != CTYPE_NULL);
+ } while (cache_eax.split.type != CTYPE_NULL && i != CTYPE_MAX);
return i;
}
--
2.7.4
next reply other threads:[~2018-11-05 13:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-05 12:53 Pu Wen [this message]
2018-11-15 17:21 ` Borislav Petkov
2018-12-08 2:46 ` Pu Wen
2018-12-08 11:12 ` 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=1541422425-5855-1-git-send-email-puwen@hygon.cn \
--to=puwen@hygon.cn \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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®