{"id":816830,"url":"http://patchwork.ozlabs.org/api/patches/816830/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170921120415.241151389@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170921120415.241151389@redhat.com>","list_archive_url":null,"date":"2017-09-21T12:03:43","name":"[2/2] qemu: kvm: support RT_PRIO_HC hypercall","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"7a7dbf87f45398d450d6a1868a1c94be63596f0f","submitter":{"id":2826,"url":"http://patchwork.ozlabs.org/api/people/2826/?format=json","name":"Marcelo Tosatti","email":"mtosatti@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170921120415.241151389@redhat.com/mbox/","series":[{"id":4364,"url":"http://patchwork.ozlabs.org/api/series/4364/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4364","date":"2017-09-21T12:03:42","name":"support RT_PRIO_HC hypercall","version":1,"mbox":"http://patchwork.ozlabs.org/series/4364/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816830/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816830/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=mtosatti@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyb5L17fCz9t43\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 22:09:42 +1000 (AEST)","from localhost ([::1]:53380 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dv0IW-00036Y-4I\n\tfor incoming@patchwork.ozlabs.org; Thu, 21 Sep 2017 08:09:40 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38589)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <mtosatti@redhat.com>) id 1dv0Ej-0000y5-MX\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <mtosatti@redhat.com>) id 1dv0Ed-0007ev-Hq\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:45 -0400","from mx1.redhat.com ([209.132.183.28]:50414)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <mtosatti@redhat.com>) id 1dv0Ed-0007eY-3P\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:05:39 -0400","from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 1F709883DF;\n\tThu, 21 Sep 2017 12:05:38 +0000 (UTC)","from amt.cnet (ovpn-116-16.gru2.redhat.com [10.97.116.16])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 3D42A614F9;\n\tThu, 21 Sep 2017 12:05:34 +0000 (UTC)","from amt.cnet (localhost [127.0.0.1])\n\tby amt.cnet (Postfix) with ESMTP id 472FB105058;\n\tThu, 21 Sep 2017 09:05:10 -0300 (BRT)","(from marcelo@localhost)\n\tby amt.cnet (8.14.7/8.14.7/Submit) id v8LC5AEg008875;\n\tThu, 21 Sep 2017 09:05:10 -0300"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 1F709883DF","Message-Id":"<20170921120415.241151389@redhat.com>","User-Agent":"quilt/0.60-1","Date":"Thu, 21 Sep 2017 09:03:43 -0300","From":"Marcelo Tosatti <mtosatti@redhat.com>","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\n\t(mx1.redhat.com [10.5.110.26]);\n\tThu, 21 Sep 2017 12:05:38 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[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":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Marcelo Tosatti <mtosatti@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Add the following CPU options:\n\nallow-rt-prio-hc: allow guest to execute hypercall to change vcpu \nthread priority.\n\nrt-prio: SCHED_FIFO priority to be used when that hypercall is invoked.\n\nSee kernel patchset for details about this hypercall.\n\nSigned-off-by: Marcelo Tosatti <mtosatti@redhat.com>\n\n---\n target/i386/cpu.c |    2 ++\n target/i386/cpu.h |    4 ++++\n target/i386/kvm.c |   23 +++++++++++++++++++++++\n 3 files changed, 29 insertions(+)","diff":"Index: qemu-fifoprio/target/i386/cpu.c\n===================================================================\n--- qemu-fifoprio.orig/target/i386/cpu.c\n+++ qemu-fifoprio/target/i386/cpu.c\n@@ -4106,6 +4106,8 @@ static Property x86_cpu_properties[] = {\n                      false),\n     DEFINE_PROP_BOOL(\"vmware-cpuid-freq\", X86CPU, vmware_cpuid_freq, true),\n     DEFINE_PROP_BOOL(\"tcg-cpuid\", X86CPU, expose_tcg, true),\n+    DEFINE_PROP_BOOL(\"allow-rt-prio-hc\", X86CPU, allow_rt_prio_hc, false),\n+    DEFINE_PROP_UINT32(\"rt-prio\", X86CPU, rt_prio_hc, 0),\n     DEFINE_PROP_END_OF_LIST()\n };\n \nIndex: qemu-fifoprio/target/i386/cpu.h\n===================================================================\n--- qemu-fifoprio.orig/target/i386/cpu.h\n+++ qemu-fifoprio/target/i386/cpu.h\n@@ -1215,6 +1215,7 @@ struct X86CPU {\n     bool hyperv_runtime;\n     bool hyperv_synic;\n     bool hyperv_stimer;\n+    bool allow_rt_prio_hc;\n     bool check_cpuid;\n     bool enforce_cpuid;\n     bool expose_kvm;\n@@ -1270,6 +1271,9 @@ struct X86CPU {\n     /* Number of physical address bits supported */\n     uint32_t phys_bits;\n \n+    /* RT priority of VCPU thread, when hypercall is invoked by guest */\n+    uint32_t rt_prio_hc;\n+\n     /* in order to simplify APIC support, we leave this pointer to the\n        user */\n     struct DeviceState *apic_state;\nIndex: qemu-fifoprio/target/i386/kvm.c\n===================================================================\n--- qemu-fifoprio.orig/target/i386/kvm.c\n+++ qemu-fifoprio/target/i386/kvm.c\n@@ -673,6 +673,28 @@ static int hyperv_handle_properties(CPUS\n \n static Error *invtsc_mig_blocker;\n \n+static int enable_allow_rt_prio_hc(CPUState *cs)\n+{\n+    int ret;\n+    struct kvm_vcpu_rt_prio rt_prio;\n+    X86CPU *cpu = X86_CPU(cs);\n+\n+    if (!kvm_check_extension(kvm_state, KVM_CAP_VCPU_RT_PRIO_HC)) {\n+        fprintf(stderr, \"RT prio hypercall not supported by kernel\\n\");\n+        return -ENOSYS;\n+    }\n+\n+    rt_prio.sched_priority = cpu->rt_prio_hc;\n+    rt_prio.enabled = 1;\n+\n+    ret = kvm_vcpu_ioctl(cs, KVM_ENABLE_VCPU_RT_PRIO_HC, &rt_prio);\n+    if (ret) {\n+        fprintf(stderr, \"RT prio hypercall failed, ret=%d\\n\", ret);\n+    }\n+\n+    return ret;\n+}\n+\n #define KVM_MAX_CPUID_ENTRIES  100\n \n int kvm_arch_init_vcpu(CPUState *cs)\n@@ -758,6 +780,12 @@ int kvm_arch_init_vcpu(CPUState *cs)\n         has_msr_hv_hypercall = true;\n     }\n \n+    if (cpu->allow_rt_prio_hc) {\n+        if (enable_allow_rt_prio_hc(cs)) {\n+            abort();\n+        }\n+    }\n+\n     if (cpu->expose_kvm) {\n         memcpy(signature, \"KVMKVMKVM\\0\\0\\0\", 12);\n         c = &cpuid_data.entries[cpuid_i++];\n","prefixes":["2/2"]}