From patchwork Mon Mar 27 14:26:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 9646897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7620602C8 for ; Mon, 27 Mar 2017 14:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9DB3228C9 for ; Mon, 27 Mar 2017 14:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDDCC283E8; Mon, 27 Mar 2017 14:27:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 42FC8228C9 for ; Mon, 27 Mar 2017 14:27:17 +0000 (UTC) Received: from localhost ([::1]:47048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csVc4-00071q-Dy for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Mar 2017 10:27:16 -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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = env->features[w]; env->features[w] &= host_feat; + if (cpu->expose_monitor && (w == FEAT_1_ECX)) { + /* Force monitor feature in */ + env->features[w] |= CPUID_EXT_MONITOR; + } cpu->filtered_features[w] = requested_features & ~env->features[w]; if (cpu->filtered_features[w]) { rv = 1; @@ -3988,6 +3992,7 @@ static Property x86_cpu_properties[] = { 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;