summaryrefslogtreecommitdiff
path: root/Kernel/Arch
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-04-03 16:58:36 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-03 23:20:33 +0200
commit8d96525b9d4a8d0502876952658a51b0aa2af445 (patch)
tree693115d4620d624c9a715a5c43f799160c11bbc6 /Kernel/Arch
parentf6181cd47e7121dd571915527c1c831ce1468d1d (diff)
downloadserenity-8d96525b9d4a8d0502876952658a51b0aa2af445.zip
Kernel: Move hypervisor vendor ID string to ProcessorInfo
This will make it possible to expose it in /proc/cpuinfo. :^)
Diffstat (limited to 'Kernel/Arch')
-rw-r--r--Kernel/Arch/x86/ProcessorInfo.h3
-rw-r--r--Kernel/Arch/x86/common/Processor.cpp14
-rw-r--r--Kernel/Arch/x86/common/ProcessorInfo.cpp35
3 files changed, 31 insertions, 21 deletions
diff --git a/Kernel/Arch/x86/ProcessorInfo.h b/Kernel/Arch/x86/ProcessorInfo.h
index e2d4473312..44ac12244d 100644
--- a/Kernel/Arch/x86/ProcessorInfo.h
+++ b/Kernel/Arch/x86/ProcessorInfo.h
@@ -21,6 +21,7 @@ public:
ProcessorInfo(Processor const& processor);
StringView vendor_id_string() const { return m_vendor_id_string->view(); }
+ StringView hypervisor_vendor_id_string() const { return m_hypervisor_vendor_id_string->view(); }
StringView brand_string() const { return m_brand_string->view(); }
StringView features_string() const { return m_features_string->view(); }
u32 display_model() const { return m_display_model; }
@@ -33,10 +34,12 @@ public:
private:
static NonnullOwnPtr<KString> build_vendor_id_string();
+ static NonnullOwnPtr<KString> build_hypervisor_vendor_id_string(Processor const&);
static NonnullOwnPtr<KString> build_brand_string();
static NonnullOwnPtr<KString> build_features_string(Processor const&);
NonnullOwnPtr<KString> m_vendor_id_string;
+ NonnullOwnPtr<KString> m_hypervisor_vendor_id_string;
NonnullOwnPtr<KString> m_brand_string;
NonnullOwnPtr<KString> m_features_string;
u32 m_display_model { 0 };
diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp
index 15c5be3e28..941e172eac 100644
--- a/Kernel/Arch/x86/common/Processor.cpp
+++ b/Kernel/Arch/x86/common/Processor.cpp
@@ -676,18 +676,10 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu)
UNMAP_AFTER_INIT void Processor::detect_hypervisor()
{
CPUID hypervisor_leaf_range(0x40000000);
+ auto hypervisor_vendor_id_string = m_info->hypervisor_vendor_id_string();
+ dmesgln("CPU[{}]: CPUID hypervisor signature '{}' ({:#x} {:#x} {:#x}), max leaf {:#x}", current_id(), hypervisor_vendor_id_string, hypervisor_leaf_range.ebx(), hypervisor_leaf_range.ecx(), hypervisor_leaf_range.edx(), hypervisor_leaf_range.eax());
- // Get signature of hypervisor.
- alignas(sizeof(u32)) char hypervisor_signature_buffer[13];
- *reinterpret_cast<u32*>(hypervisor_signature_buffer) = hypervisor_leaf_range.ebx();
- *reinterpret_cast<u32*>(hypervisor_signature_buffer + 4) = hypervisor_leaf_range.ecx();
- *reinterpret_cast<u32*>(hypervisor_signature_buffer + 8) = hypervisor_leaf_range.edx();
- hypervisor_signature_buffer[12] = '\0';
- StringView hypervisor_signature(hypervisor_signature_buffer);
-
- dmesgln("CPU[{}]: CPUID hypervisor signature '{}' ({:#x} {:#x} {:#x}), max leaf {:#x}", current_id(), hypervisor_signature, hypervisor_leaf_range.ebx(), hypervisor_leaf_range.ecx(), hypervisor_leaf_range.edx(), hypervisor_leaf_range.eax());
-
- if (hypervisor_signature == "Microsoft Hv"sv)
+ if (hypervisor_vendor_id_string == "Microsoft Hv"sv)
detect_hypervisor_hyperv(hypervisor_leaf_range);
}
diff --git a/Kernel/Arch/x86/common/ProcessorInfo.cpp b/Kernel/Arch/x86/common/ProcessorInfo.cpp
index 5c6d0056a1..99e28bd49a 100644
--- a/Kernel/Arch/x86/common/ProcessorInfo.cpp
+++ b/Kernel/Arch/x86/common/ProcessorInfo.cpp
@@ -14,6 +14,7 @@ namespace Kernel {
ProcessorInfo::ProcessorInfo(Processor const& processor)
: m_vendor_id_string(build_vendor_id_string())
+ , m_hypervisor_vendor_id_string(build_hypervisor_vendor_id_string(processor))
, m_brand_string(build_brand_string())
, m_features_string(build_features_string(processor))
{
@@ -35,21 +36,35 @@ ProcessorInfo::ProcessorInfo(Processor const& processor)
m_display_model = model;
}
}
+static void emit_u32(StringBuilder& builder, u32 value)
+{
+ builder.appendff("{:c}{:c}{:c}{:c}",
+ value & 0xff,
+ (value >> 8) & 0xff,
+ (value >> 16) & 0xff,
+ (value >> 24) & 0xff);
+};
NonnullOwnPtr<KString> ProcessorInfo::build_vendor_id_string()
{
CPUID cpuid(0);
StringBuilder builder;
- auto emit_u32 = [&](u32 value) {
- builder.appendff("{:c}{:c}{:c}{:c}",
- value & 0xff,
- (value >> 8) & 0xff,
- (value >> 16) & 0xff,
- (value >> 24) & 0xff);
- };
- emit_u32(cpuid.ebx());
- emit_u32(cpuid.edx());
- emit_u32(cpuid.ecx());
+ emit_u32(builder, cpuid.ebx());
+ emit_u32(builder, cpuid.edx());
+ emit_u32(builder, cpuid.ecx());
+ return KString::must_create(builder.string_view());
+}
+
+NonnullOwnPtr<KString> ProcessorInfo::build_hypervisor_vendor_id_string(Processor const& processor)
+{
+ if (!processor.has_feature(CPUFeature::HYPERVISOR))
+ return KString::must_create({});
+
+ CPUID cpuid(0x40000000);
+ StringBuilder builder;
+ emit_u32(builder, cpuid.ebx());
+ emit_u32(builder, cpuid.ecx());
+ emit_u32(builder, cpuid.edx());
return KString::must_create(builder.string_view());
}