From nobody Sun Apr 28 11:18:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149062485524473.2459137336075; Mon, 27 Mar 2017 07:27:35 -0700 (PDT) Received: from localhost ([::1]:47051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVcL-0007Yz-RN for importer@patchew.org; Mon, 27 Mar 2017 10:27:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVbQ-00071Y-PH for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csVbN-0007Ek-Jc for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:26:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:52123) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csVbN-0007EX-DL for qemu-devel@nongnu.org; Mon, 27 Mar 2017 10:26:33 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D8DBEAD1E; Mon, 27 Mar 2017 14:26:30 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Alexander Graf To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 16:26:50 +0200 Message-Id: <1490624810-44752-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.8.5.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH] i386: Allow monitor / mwait cpuid override X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" KVM allows trap and emulate (read: NOP) of the MONITOR and MWAIT instructions. There is work undergoing to enable actual execution of these inside of KVM, but nobody really wants to expose the feature to the guest by default, as it would eat up all of the host CPU. So today there is no streamlined way to actually notify the guest that it's ok to execute MONITOR / MWAIT, even when we want to explicitly leave the guest in guest context. This patch adds a new -cpu parameter called "mwait" which - when enabled - force enables the MONITOR / MWAIT CPUID flag, even when the underlying accel framework does not explicitly advertise support. With that in place, we can explicitly allow users to specify that they want have the guest execute MONITOR / MWAIT in its idle loop. Signed-off-by: Alexander Graf --- target/i386/cpu.c | 5 +++++ target/i386/cpu.h | 1 + 2 files changed, 6 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7aa7622..c44020b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3460,6 +3460,10 @@ static int x86_cpu_filter_features(X86CPU *cpu) x86_cpu_get_supported_feature_word(w, false); uint32_t requested_features =3D env->features[w]; env->features[w] &=3D host_feat; + if (cpu->expose_monitor && (w =3D=3D FEAT_1_ECX)) { + /* Force monitor feature in */ + env->features[w] |=3D CPUID_EXT_MONITOR; + } cpu->filtered_features[w] =3D requested_features & ~env->features[= w]; if (cpu->filtered_features[w]) { rv =3D 1; @@ -3988,6 +3992,7 @@ static Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), + DEFINE_PROP_BOOL("mwait", X86CPU, expose_monitor, false), DEFINE_PROP_UINT32("phys-bits", X86CPU, phys_bits, 0), DEFINE_PROP_BOOL("host-phys-bits", X86CPU, host_phys_bits, false), DEFINE_PROP_BOOL("fill-mtrr-mask", X86CPU, fill_mtrr_mask, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 07401ad..7400d00 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1214,6 +1214,7 @@ struct X86CPU { bool check_cpuid; bool enforce_cpuid; bool expose_kvm; + bool expose_monitor; bool migratable; bool max_features; /* Enable all supported features automatically */ uint32_t apic_id; --=20 1.8.5.6