From 80e1dce1b02da3a64d33e06b2b3715167d7b4771 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 8 Mar 2018 11:34:59 +0100 Subject: [PATCH] nova: abandon hypervisor_info_page ROM replace by platform_info ROM supposed to exist on all supported kernels. Fixes #2710 --- repos/base-nova/src/core/platform.cc | 28 +++++++---------- repos/base-nova/src/test/platform/main.cc | 11 +++---- repos/gems/run/sculpt.run | 2 +- repos/gems/run/sculpt/deploy_runtime.config | 2 +- .../os/src/drivers/timer/nova/time_source.cc | 9 +++--- .../recipes/raw/vbox5-nova-sculpt/init.config | 8 ++--- repos/ports/run/seoul.inc | 2 +- repos/ports/src/app/seoul/main.cc | 30 ++++++++----------- repos/ports/src/virtualbox/spec/nova/sup.cc | 30 +++++++++++-------- repos/ports/src/virtualbox5/spec/nova/sup.cc | 30 +++++++++++-------- 10 files changed, 77 insertions(+), 75 deletions(-) diff --git a/repos/base-nova/src/core/platform.cc b/repos/base-nova/src/core/platform.cc index 97697d0d3..0f6808607 100644 --- a/repos/base-nova/src/core/platform.cc +++ b/repos/base-nova/src/core/platform.cc @@ -673,6 +673,16 @@ Platform::Platform() : xml.attribute("pitch", boot_fb->aux); }); }); + xml.node("hardware", [&] () { + xml.node("features", [&] () { + xml.attribute("svm", hip->has_feature_svm()); + xml.attribute("vmx", hip->has_feature_vmx()); + }); + xml.node("tsc", [&] () { + xml.attribute("invariant", cpuid_invariant_tsc()); + xml.attribute("freq_khz" , hip->tsc_freq); + }); + }); }); unmap_local(__main_thread_utcb, core_local_addr, pages); @@ -683,24 +693,6 @@ Platform::Platform() : "platform_info")); } - /* export hypervisor info page as ROM module */ - { - void * phys_ptr = nullptr; - ram_alloc()->alloc_aligned(get_page_size(), &phys_ptr, get_page_size_log2()); - - addr_t const phys_addr = reinterpret_cast(phys_ptr); - addr_t const core_local_addr = _map_pages(phys_addr, 1); - - memcpy(reinterpret_cast(core_local_addr), hip, get_page_size()); - - unmap_local(__main_thread_utcb, core_local_addr, 1); - region_alloc()->free(reinterpret_cast(core_local_addr), get_page_size()); - - _rom_fs.insert(new (core_mem_alloc()) - Rom_module(phys_addr, get_page_size(), - "hypervisor_info_page")); - } - /* core log as ROM module */ { void * phys_ptr = nullptr; diff --git a/repos/base-nova/src/test/platform/main.cc b/repos/base-nova/src/test/platform/main.cc index 4d75a90ff..a08abcf5f 100644 --- a/repos/base-nova/src/test/platform/main.cc +++ b/repos/base-nova/src/test/platform/main.cc @@ -269,8 +269,9 @@ void test_revoke(Genode::Env &env) void test_pat(Genode::Env &env) { /* read out the tsc frequenzy once */ - Genode::Attached_rom_dataspace _ds(env, "hypervisor_info_page"); - Nova::Hip * const hip = _ds.local_addr(); + Attached_rom_dataspace const platform_info (env, "platform_info"); + Xml_node const hardware = platform_info.xml().sub_node("hardware"); + uint64_t const tsc_freq = hardware.sub_node("tsc").attribute_value("freq_khz", 1ULL); enum { DS_ORDER = 12, PAGE_4K = 12 }; @@ -348,12 +349,12 @@ void test_pat(Genode::Env &env) Trace::Timestamp diff_run = map_run > remap_run ? map_run - remap_run : remap_run - map_run; - if (check_pat && diff_run * 100 / hip->tsc_freq) { + if (check_pat && diff_run * 100 / tsc_freq) { failed ++; error("map=", Hex(map_run), " remap=", Hex(remap_run), " --> " - "diff=", Hex(diff_run), " freq_tsc=", hip->tsc_freq, " ", - diff_run * 1000 / hip->tsc_freq, " us"); + "diff=", Hex(diff_run), " freq_tsc=", tsc_freq, " ", + diff_run * 1000 / tsc_freq, " us"); } Nova::revoke(Nova::Mem_crd(remap_addr >> PAGE_4K, DS_ORDER, all)); diff --git a/repos/gems/run/sculpt.run b/repos/gems/run/sculpt.run index 793473c43..c5887ed38 100644 --- a/repos/gems/run/sculpt.run +++ b/repos/gems/run/sculpt.run @@ -622,7 +622,7 @@ append depot_deploy_config { - + diff --git a/repos/gems/run/sculpt/deploy_runtime.config b/repos/gems/run/sculpt/deploy_runtime.config index ec278d127..96cd8b848 100644 --- a/repos/gems/run/sculpt/deploy_runtime.config +++ b/repos/gems/run/sculpt/deploy_runtime.config @@ -98,7 +98,7 @@ - + diff --git a/repos/os/src/drivers/timer/nova/time_source.cc b/repos/os/src/drivers/timer/nova/time_source.cc index a92ba0da1..869a840cb 100644 --- a/repos/os/src/drivers/timer/nova/time_source.cc +++ b/repos/os/src/drivers/timer/nova/time_source.cc @@ -27,10 +27,11 @@ using namespace Nova; Timer::Time_source::Time_source(Env &env) : Threaded_time_source(env) { - /* read out the tsc frequenzy once */ - Attached_rom_dataspace _ds(env, "hypervisor_info_page"); - Nova::Hip * const hip = _ds.local_addr(); - _tsc_khz = hip->tsc_freq; + /* read out the tsc frequency once */ + Attached_rom_dataspace const platform_info { env, "platform_info" }; + Xml_node const hardware = platform_info.xml().sub_node("hardware"); + hardware.sub_node("tsc").attribute("freq_khz").value(&_tsc_khz); + start(); } diff --git a/repos/ports/recipes/raw/vbox5-nova-sculpt/init.config b/repos/ports/recipes/raw/vbox5-nova-sculpt/init.config index 02c392ac6..c417bd40a 100755 --- a/repos/ports/recipes/raw/vbox5-nova-sculpt/init.config +++ b/repos/ports/recipes/raw/vbox5-nova-sculpt/init.config @@ -24,8 +24,8 @@ - - + + @@ -63,8 +63,8 @@ - - + + diff --git a/repos/ports/run/seoul.inc b/repos/ports/run/seoul.inc index 96f664824..65870f4cd 100644 --- a/repos/ports/run/seoul.inc +++ b/repos/ports/run/seoul.inc @@ -259,7 +259,7 @@ append_if $use_framebuffer config { append_if $use_genode_iso config { - + } append config { diff --git a/repos/ports/src/app/seoul/main.cc b/repos/ports/src/app/seoul/main.cc index a3e4736d2..ea4d30312 100644 --- a/repos/ports/src/app/seoul/main.cc +++ b/repos/ports/src/app/seoul/main.cc @@ -728,8 +728,6 @@ class Vcpu_dispatcher : public Vcpu_handler, VCpu *unsynchronized_vcpu, Guest_memory &guest_memory, Synced_motherboard &motherboard, - bool has_svm, - bool has_vmx, Vmm::Vcpu_thread *vcpu_thread, Genode::Cpu_session *cpu_session, Genode::Affinity::Location &location) @@ -748,6 +746,13 @@ class Vcpu_dispatcher : public Vcpu_handler, Mtd const mtd_cpuid(Mtd::EIP | Mtd::ACDB | Mtd::IRQ); Mtd const mtd_irq(Mtd::IRQ); + /* detect virtualization extension */ + Attached_rom_dataspace const info(env, "platform_info"); + Genode::Xml_node const features = info.xml().sub_node("hardware").sub_node("features"); + + bool const has_svm = features.attribute_value("svm", false); + bool const has_vmx = features.attribute_value("vmx", false); + /* * Register vCPU event handlers */ @@ -874,9 +879,7 @@ class Machine : public StaticReceiver Genode::Env &_env; Genode::Heap &_heap; - Attached_rom_dataspace _hip_rom = { _env, "hypervisor_info_page" }; Genode::Cpu_connection _cpu_session = { _env, "Seoul vCPUs", Genode::Cpu_session::PRIORITY_LIMIT / 16 }; - Hip * const _hip; Clock _clock; Genode::Lock _motherboard_lock; Motherboard _unsynchronized_motherboard; @@ -981,16 +984,10 @@ class Machine : public StaticReceiver } Vcpu_dispatcher *vcpu_dispatcher = - new Vcpu_dispatcher(_motherboard_lock, - _env, - msg.vcpu, - _guest_memory, - _motherboard, - _hip->has_feature_svm(), - _hip->has_feature_vmx(), - vcpu_thread, - &_cpu_session, - location); + new Vcpu_dispatcher(_motherboard_lock, _env, + msg.vcpu, _guest_memory, + _motherboard, vcpu_thread, + &_cpu_session, location); msg.value = vcpu_dispatcher->sel_sm_ec(); return true; @@ -1240,10 +1237,9 @@ class Machine : public StaticReceiver Guest_memory &guest_memory, bool colocate) : _env(env), _heap(heap), - _hip(_hip_rom.local_addr()), - _clock(_hip->tsc_freq*1000), + _clock(Attached_rom_dataspace(env, "platform_info").xml().sub_node("hardware").sub_node("tsc").attribute_value("freq_khz", 0ULL) * 1000ULL), _motherboard_lock(Genode::Lock::LOCKED), - _unsynchronized_motherboard(&_clock, _hip), + _unsynchronized_motherboard(&_clock, nullptr), _motherboard(_motherboard_lock, &_unsynchronized_motherboard), _timeouts(_timeouts_lock, &_unsynchronized_timeouts), _guest_memory(guest_memory), diff --git a/repos/ports/src/virtualbox/spec/nova/sup.cc b/repos/ports/src/virtualbox/spec/nova/sup.cc index ccbb5e9cd..d16792abc 100644 --- a/repos/ports/src/virtualbox/spec/nova/sup.cc +++ b/repos/ports/src/virtualbox/spec/nova/sup.cc @@ -65,21 +65,22 @@ static Vcpu_handler *lookup_vcpu_handler(unsigned int cpu_id) /* Genode specific function */ -Nova::Hip &hip_rom() +Genode::Xml_node platform_rom() { - static Genode::Attached_rom_dataspace hip_rom(genode_env(), - "hypervisor_info_page"); - return *hip_rom.local_addr(); + static Genode::Attached_rom_dataspace const platform(genode_env(), + "platform_info"); + return platform.xml().sub_node("hardware"); } void SUPR3QueryHWACCLonGenodeSupport(VM * pVM) { try { - pVM->hm.s.svm.fSupported = hip_rom().has_feature_svm(); - pVM->hm.s.vmx.fSupported = hip_rom().has_feature_vmx(); + Genode::Xml_node const features = platform_rom().sub_node("features"); + pVM->hm.s.svm.fSupported = features.attribute_value("svm", false); + pVM->hm.s.vmx.fSupported = features.attribute_value("vmx", false); - if (hip_rom().has_feature_svm() || hip_rom().has_feature_vmx()) { - Genode::log("Using ", hip_rom().has_feature_svm() ? "SVM" : "VMX", + if (pVM->hm.s.svm.fSupported || pVM->hm.s.vmx.fSupported) { + Genode::log("Using ", pVM->hm.s.svm.fSupported ? "SVM" : "VMX", " virtualization extension."); return; } @@ -195,7 +196,8 @@ uint64_t genode_cpu_hz() if (!cpu_freq) { try { - cpu_freq = hip_rom().tsc_freq * 1000; + platform_rom().sub_node("tsc").attribute("freq_khz").value(&cpu_freq); + cpu_freq *= 1000ULL; } catch (...) { Genode::error("could not read out CPU frequency"); Genode::Lock lock; @@ -290,20 +292,24 @@ bool create_emt_vcpu(pthread_t * pthread, size_t stack, Genode::Affinity::Location location, unsigned int cpu_id, const char * name) { - if (!hip_rom().has_feature_vmx() && !hip_rom().has_feature_svm()) + Genode::Xml_node const features = platform_rom().sub_node("features"); + bool const svm = features.attribute_value("svm", false); + bool const vmx = features.attribute_value("vmx", false); + + if (!svm && !vmx) return false; static Genode::Pd_connection pd_vcpus(genode_env(), "VM"); Vcpu_handler *vcpu_handler = 0; - if (hip_rom().has_feature_vmx()) + if (vmx) vcpu_handler = new (0x10) Vcpu_handler_vmx(genode_env(), stack, attr, start_routine, arg, cpu_session, location, cpu_id, name, pd_vcpus); - if (hip_rom().has_feature_svm()) + if (svm) vcpu_handler = new (0x10) Vcpu_handler_svm(genode_env(), stack, attr, start_routine, arg, cpu_session, location, diff --git a/repos/ports/src/virtualbox5/spec/nova/sup.cc b/repos/ports/src/virtualbox5/spec/nova/sup.cc index 94202c70b..89c85584b 100644 --- a/repos/ports/src/virtualbox5/spec/nova/sup.cc +++ b/repos/ports/src/virtualbox5/spec/nova/sup.cc @@ -180,22 +180,23 @@ HRESULT genode_setup_machine(ComObjPtr machine) /* Genode specific function */ -Nova::Hip &hip_rom() +Genode::Xml_node platform_rom() { - static Genode::Attached_rom_dataspace hip_rom(genode_env(), - "hypervisor_info_page"); - return *hip_rom.local_addr(); + static Genode::Attached_rom_dataspace const platform(genode_env(), + "platform_info"); + return platform.xml().sub_node("hardware"); } void SUPR3QueryHWACCLonGenodeSupport(VM * pVM) { try { - pVM->hm.s.svm.fSupported = hip_rom().has_feature_svm(); - pVM->hm.s.vmx.fSupported = hip_rom().has_feature_vmx(); + Genode::Xml_node const features = platform_rom().sub_node("features"); + pVM->hm.s.svm.fSupported = features.attribute_value("svm", false); + pVM->hm.s.vmx.fSupported = features.attribute_value("vmx", false); - if (hip_rom().has_feature_svm() || hip_rom().has_feature_vmx()) { - Genode::log("Using ", hip_rom().has_feature_svm() ? "SVM" : "VMX", + if (pVM->hm.s.svm.fSupported || pVM->hm.s.vmx.fSupported) { + Genode::log("Using ", pVM->hm.s.svm.fSupported ? "SVM" : "VMX", " virtualization extension."); return; } @@ -690,7 +691,8 @@ uint64_t genode_cpu_hz() if (!cpu_freq) { try { - cpu_freq = hip_rom().tsc_freq * 1000; + platform_rom().sub_node("tsc").attribute("freq_khz").value(&cpu_freq); + cpu_freq *= 1000ULL; } catch (...) { Genode::error("could not read out CPU frequency"); Genode::Lock lock; @@ -776,20 +778,24 @@ bool create_emt_vcpu(pthread_t * pthread, ::size_t stack, Genode::Affinity::Location location, unsigned int cpu_id, const char * name) { - if (!hip_rom().has_feature_vmx() && !hip_rom().has_feature_svm()) + Genode::Xml_node const features = platform_rom().sub_node("features"); + bool const svm = features.attribute_value("svm", false); + bool const vmx = features.attribute_value("vmx", false); + + if (!svm && !vmx) return false; static Genode::Pd_connection pd_vcpus(genode_env(), "VM"); Vcpu_handler *vcpu_handler = 0; - if (hip_rom().has_feature_vmx()) + if (vmx) vcpu_handler = new (0x10) Vcpu_handler_vmx(genode_env(), stack, attr, start_routine, arg, cpu_session, location, cpu_id, name, pd_vcpus); - if (hip_rom().has_feature_svm()) + if (svm) vcpu_handler = new (0x10) Vcpu_handler_svm(genode_env(), stack, attr, start_routine, arg, cpu_session, location,