From patchwork Thu Feb 2 17:47:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 9552835 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 4545860424 for ; Thu, 2 Feb 2017 17:59:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 381822849D for ; Thu, 2 Feb 2017 17:59:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CE68284A5; Thu, 2 Feb 2017 17:59:54 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD5552849D for ; Thu, 2 Feb 2017 17:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752202AbdBBR7m (ORCPT ); Thu, 2 Feb 2017 12:59:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752385AbdBBR64 (ORCPT ); Thu, 2 Feb 2017 12:58:56 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 272DC7EBA4; Thu, 2 Feb 2017 17:58:57 +0000 (UTC) Received: from amt.cnet (vpn1-4-135.gru2.redhat.com [10.97.4.135]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12Hwu06004845; Thu, 2 Feb 2017 12:58:56 -0500 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 96A251009BB; Thu, 2 Feb 2017 15:50:11 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id v12HoBQg013430; Thu, 2 Feb 2017 15:50:11 -0200 Message-Id: <20170202174921.983532379@redhat.com> User-Agent: quilt/0.60-1 Date: Thu, 02 Feb 2017 15:47:58 -0200 From: Marcelo Tosatti To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paolo Bonzini , Radim Krcmar , "Rafael J. Wysocki" , Viresh Kumar , Marcelo Tosatti Subject: [patch 3/3] KVM: x86: frequency change hypercalls References: <20170202174755.946578704@redhat.com> Content-Disposition: inline; filename=kvm-cpufreq-api X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 02 Feb 2017 17:58:57 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement min/max/up/down frequency change KVM hypercalls. To be used by DPDK implementation. Also allow such hypercalls from guest userspace. Signed-off-by: Marcelo Tosatti --- Documentation/virtual/kvm/hypercalls.txt | 45 +++++++++++++++++++ arch/x86/kvm/x86.c | 71 ++++++++++++++++++++++++++++++- include/uapi/linux/kvm_para.h | 5 ++ 3 files changed, 120 insertions(+), 1 deletion(-) Index: kvm-pvfreq/arch/x86/kvm/x86.c =================================================================== --- kvm-pvfreq.orig/arch/x86/kvm/x86.c 2017-02-02 11:17:17.063756725 -0200 +++ kvm-pvfreq/arch/x86/kvm/x86.c 2017-02-02 11:17:17.822752510 -0200 @@ -6219,10 +6219,58 @@ kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu); } +#ifdef CONFIG_CPU_FREQ_GOV_USERSPACE +/* call into cpufreq-userspace governor */ +static int kvm_pvfreq_up(struct kvm_vcpu *vcpu) +{ + int ret; + int cpu = get_cpu(); + + ret = cpufreq_userspace_freq_up(cpu); + put_cpu(); + + return ret; +} + +static int kvm_pvfreq_down(struct kvm_vcpu *vcpu) +{ + int ret; + int cpu = get_cpu(); + + ret = cpufreq_userspace_freq_down(cpu); + put_cpu(); + + return ret; +} + +static int kvm_pvfreq_max(struct kvm_vcpu *vcpu) +{ + int ret; + int cpu = get_cpu(); + + ret = cpufreq_userspace_freq_max(cpu); + put_cpu(); + + return ret; +} + +static int kvm_pvfreq_min(struct kvm_vcpu *vcpu) +{ + int ret; + int cpu = get_cpu(); + + ret = cpufreq_userspace_freq_min(cpu); + put_cpu(); + + return ret; +} +#endif + int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) { unsigned long nr, a0, a1, a2, a3, ret; int op_64_bit, r; + bool cpl_check; r = kvm_skip_emulated_instruction(vcpu); @@ -6246,7 +6294,13 @@ a3 &= 0xFFFFFFFF; } - if (kvm_x86_ops->get_cpl(vcpu) != 0) { + cpl_check = true; + if (nr == KVM_HC_FREQ_UP || nr == KVM_HC_FREQ_DOWN || + nr == KVM_HC_FREQ_MIN || nr == KVM_HC_FREQ_MAX) + if (vcpu->arch.allow_freq_hypercall == true) + cpl_check = false; + + if (cpl_check == true && kvm_x86_ops->get_cpl(vcpu) != 0) { ret = -KVM_EPERM; goto out; } @@ -6262,6 +6316,21 @@ case KVM_HC_CLOCK_PAIRING: ret = kvm_pv_clock_pairing(vcpu, a0, a1); break; +#ifdef CONFIG_CPU_FREQ_GOV_USERSPACE + case KVM_HC_FREQ_UP: + ret = kvm_pvfreq_up(vcpu); + break; + case KVM_HC_FREQ_DOWN: + ret = kvm_pvfreq_down(vcpu); + break; + case KVM_HC_FREQ_MAX: + ret = kvm_pvfreq_max(vcpu); + break; + case KVM_HC_FREQ_MIN: + ret = kvm_pvfreq_min(vcpu); + break; +#endif + default: ret = -KVM_ENOSYS; break; Index: kvm-pvfreq/include/uapi/linux/kvm_para.h =================================================================== --- kvm-pvfreq.orig/include/uapi/linux/kvm_para.h 2017-02-02 10:51:53.741217306 -0200 +++ kvm-pvfreq/include/uapi/linux/kvm_para.h 2017-02-02 11:17:17.824752499 -0200 @@ -25,6 +25,11 @@ #define KVM_HC_MIPS_EXIT_VM 7 #define KVM_HC_MIPS_CONSOLE_OUTPUT 8 #define KVM_HC_CLOCK_PAIRING 9 +#define KVM_HC_FREQ_UP 10 +#define KVM_HC_FREQ_DOWN 11 +#define KVM_HC_FREQ_MAX 12 +#define KVM_HC_FREQ_MIN 13 + /* * hypercalls use architecture specific Index: kvm-pvfreq/Documentation/virtual/kvm/hypercalls.txt =================================================================== --- kvm-pvfreq.orig/Documentation/virtual/kvm/hypercalls.txt 2017-02-02 10:51:53.741217306 -0200 +++ kvm-pvfreq/Documentation/virtual/kvm/hypercalls.txt 2017-02-02 15:29:24.401692793 -0200 @@ -116,3 +116,48 @@ Returns KVM_EOPNOTSUPP if the host does not use TSC clocksource, or if clock type is different than KVM_CLOCK_PAIRING_WALLCLOCK. + +7. KVM_HC_FREQ_UP +----------------- + +Architecture: x86 +Status: active +Purpose: Hypercall used to increase frequency to the next +higher frequency. +Usage example: DPDK power aware applications, that run on +isolated CPUs. No input argument, returns 0 if success, +1 if already at lowest frequency, error otherwise. + +8. KVM_HC_FREQ_DOWN +--------------------- + +Architecture: x86 +Status: active +Purpose: Hypercall used to decrease frequency to the next +lower frequency. +Usage example: DPDK power aware applications, that run on +isolated CPUs. No input argument, returns 0 if success, +1 if already at lowest frequency, negative error otherwise. + +9. KVM_HC_FREQ_MIN +------------------- + +Architecture: x86 +Status: active +Purpose: Hypercall used to decrease frequency to the +minimum frequency. +Usage example: DPDK power aware applications, that run +on isolated CPUs. No input argument, returns 0 if success +error otherwise. + +10. KVM_HC_FREQ_MAX +------------------- + +Architecture: x86 +Status: active +Purpose: Hypercall used to increase frequency to the +maximum frequency. +Usage example: DPDK power aware applications, that run +on isolated CPUs. No input argument, returns 0 if success +error otherwise. +