From patchwork Thu Sep 21 12:03:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 9963803 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 26284600C5 for ; Thu, 21 Sep 2017 12:10:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17C222949D for ; Thu, 21 Sep 2017 12:10:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CD45294A2; Thu, 21 Sep 2017 12:10: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=unavailable 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 A5AF42949D for ; Thu, 21 Sep 2017 12:10:17 +0000 (UTC) Received: from localhost ([::1]:53380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv0J6-00036Y-Bh for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Sep 2017 08:10:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv0Ej-0000y5-MX for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv0Ed-0007ev-Hq for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dv0Ed-0007eY-3P for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F709883DF; Thu, 21 Sep 2017 12:05:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1F709883DF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mtosatti@redhat.com Received: from amt.cnet (ovpn-116-16.gru2.redhat.com [10.97.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D42A614F9; Thu, 21 Sep 2017 12:05:34 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 472FB105058; Thu, 21 Sep 2017 09:05:10 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id v8LC5AEg008875; Thu, 21 Sep 2017 09:05:10 -0300 Message-Id: <20170921120415.241151389@redhat.com> User-Agent: quilt/0.60-1 Date: Thu, 21 Sep 2017 09:03:43 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20170921120341.590850215@redhat.com> Content-Disposition: inline; filename=qemu-toggle-kvmrt-prio X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 21 Sep 2017 12:05:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [patch 2/2] qemu: kvm: support RT_PRIO_HC hypercall 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: Marcelo Tosatti Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add the following CPU options: allow-rt-prio-hc: allow guest to execute hypercall to change vcpu thread priority. rt-prio: SCHED_FIFO priority to be used when that hypercall is invoked. See kernel patchset for details about this hypercall. Signed-off-by: Marcelo Tosatti --- target/i386/cpu.c | 2 ++ target/i386/cpu.h | 4 ++++ target/i386/kvm.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) Index: qemu-fifoprio/target/i386/cpu.c =================================================================== --- qemu-fifoprio.orig/target/i386/cpu.c +++ qemu-fifoprio/target/i386/cpu.c @@ -4106,6 +4106,8 @@ static Property x86_cpu_properties[] = { false), DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true), DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true), + DEFINE_PROP_BOOL("allow-rt-prio-hc", X86CPU, allow_rt_prio_hc, false), + DEFINE_PROP_UINT32("rt-prio", X86CPU, rt_prio_hc, 0), DEFINE_PROP_END_OF_LIST() }; Index: qemu-fifoprio/target/i386/cpu.h =================================================================== --- qemu-fifoprio.orig/target/i386/cpu.h +++ qemu-fifoprio/target/i386/cpu.h @@ -1215,6 +1215,7 @@ struct X86CPU { bool hyperv_runtime; bool hyperv_synic; bool hyperv_stimer; + bool allow_rt_prio_hc; bool check_cpuid; bool enforce_cpuid; bool expose_kvm; @@ -1270,6 +1271,9 @@ struct X86CPU { /* Number of physical address bits supported */ uint32_t phys_bits; + /* RT priority of VCPU thread, when hypercall is invoked by guest */ + uint32_t rt_prio_hc; + /* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; Index: qemu-fifoprio/target/i386/kvm.c =================================================================== --- qemu-fifoprio.orig/target/i386/kvm.c +++ qemu-fifoprio/target/i386/kvm.c @@ -673,6 +673,28 @@ static int hyperv_handle_properties(CPUS static Error *invtsc_mig_blocker; +static int enable_allow_rt_prio_hc(CPUState *cs) +{ + int ret; + struct kvm_vcpu_rt_prio rt_prio; + X86CPU *cpu = X86_CPU(cs); + + if (!kvm_check_extension(kvm_state, KVM_CAP_VCPU_RT_PRIO_HC)) { + fprintf(stderr, "RT prio hypercall not supported by kernel\n"); + return -ENOSYS; + } + + rt_prio.sched_priority = cpu->rt_prio_hc; + rt_prio.enabled = 1; + + ret = kvm_vcpu_ioctl(cs, KVM_ENABLE_VCPU_RT_PRIO_HC, &rt_prio); + if (ret) { + fprintf(stderr, "RT prio hypercall failed, ret=%d\n", ret); + } + + return ret; +} + #define KVM_MAX_CPUID_ENTRIES 100 int kvm_arch_init_vcpu(CPUState *cs) @@ -758,6 +780,12 @@ int kvm_arch_init_vcpu(CPUState *cs) has_msr_hv_hypercall = true; } + if (cpu->allow_rt_prio_hc) { + if (enable_allow_rt_prio_hc(cs)) { + abort(); + } + } + if (cpu->expose_kvm) { memcpy(signature, "KVMKVMKVM\0\0\0", 12); c = &cpuid_data.entries[cpuid_i++];