* KVM: x86: limit PIT timer frequency
@ 2014-01-06 14:00 Marcelo Tosatti
2014-01-06 17:49 ` Jan Kiszka
2014-01-15 11:44 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2014-01-06 14:00 UTC (permalink / raw)
To: kvm-devel; +Cc: Paolo Bonzini, Jan Kiszka
Limit PIT timer frequency similarly to the limit applied by
LAPIC timer.
Cc: stable@kernel.org
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 412a5aa..518d864 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -37,6 +37,7 @@
#include "irq.h"
#include "i8254.h"
+#include "x86.h"
#ifndef CONFIG_X86_64
#define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
@@ -349,6 +350,23 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
atomic_set(&ps->pending, 0);
ps->irq_ack = 1;
+ /*
+ * Do not allow the guest to program periodic timers with small
+ * interval, since the hrtimers are not throttled by the host
+ * scheduler.
+ */
+ if (ps->is_periodic) {
+ s64 min_period = min_timer_period_us * 1000LL;
+
+ if (ps->period < min_period) {
+ pr_info_ratelimited(
+ "kvm: requested %lld ns "
+ "i8254 timer period limited to %lld ns\n",
+ ps->period, min_period);
+ ps->period = min_period;
+ }
+ }
+
hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
HRTIMER_MODE_ABS);
}
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index dec48bf..7f4dfa6 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -71,9 +71,6 @@
#define VEC_POS(v) ((v) & (32 - 1))
#define REG_POS(v) (((v) >> 5) << 4)
-static unsigned int min_timer_period_us = 500;
-module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
-
static inline void apic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
{
*((u32 *) (apic->regs + reg_off)) = val;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5d004da..d89d51b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -94,6 +94,9 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
static bool ignore_msrs = 0;
module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
+unsigned int min_timer_period_us = 500;
+module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
+
bool kvm_has_tsc_control;
EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
u32 kvm_max_guest_tsc_khz;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 587fb9e..8da5823 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -125,5 +125,7 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
#define KVM_SUPPORTED_XCR0 (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
extern u64 host_xcr0;
+extern unsigned int min_timer_period_us;
+
extern struct static_key kvm_no_apic_vcpu;
#endif
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: KVM: x86: limit PIT timer frequency
2014-01-06 14:00 KVM: x86: limit PIT timer frequency Marcelo Tosatti
@ 2014-01-06 17:49 ` Jan Kiszka
2014-01-15 11:44 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2014-01-06 17:49 UTC (permalink / raw)
To: Marcelo Tosatti, kvm-devel; +Cc: Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 3047 bytes --]
On 2014-01-06 15:00, Marcelo Tosatti wrote:
>
>
> Limit PIT timer frequency similarly to the limit applied by
> LAPIC timer.
>
> Cc: stable@kernel.org
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
> index 412a5aa..518d864 100644
> --- a/arch/x86/kvm/i8254.c
> +++ b/arch/x86/kvm/i8254.c
> @@ -37,6 +37,7 @@
>
> #include "irq.h"
> #include "i8254.h"
> +#include "x86.h"
>
> #ifndef CONFIG_X86_64
> #define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
> @@ -349,6 +350,23 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
> atomic_set(&ps->pending, 0);
> ps->irq_ack = 1;
>
> + /*
> + * Do not allow the guest to program periodic timers with small
> + * interval, since the hrtimers are not throttled by the host
> + * scheduler.
> + */
> + if (ps->is_periodic) {
> + s64 min_period = min_timer_period_us * 1000LL;
> +
> + if (ps->period < min_period) {
> + pr_info_ratelimited(
> + "kvm: requested %lld ns "
> + "i8254 timer period limited to %lld ns\n",
> + ps->period, min_period);
> + ps->period = min_period;
> + }
> + }
> +
> hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
> HRTIMER_MODE_ABS);
> }
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index dec48bf..7f4dfa6 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -71,9 +71,6 @@
> #define VEC_POS(v) ((v) & (32 - 1))
> #define REG_POS(v) (((v) >> 5) << 4)
>
> -static unsigned int min_timer_period_us = 500;
> -module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
> -
> static inline void apic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
> {
> *((u32 *) (apic->regs + reg_off)) = val;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 5d004da..d89d51b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -94,6 +94,9 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
> static bool ignore_msrs = 0;
> module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
>
> +unsigned int min_timer_period_us = 500;
> +module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
> +
> bool kvm_has_tsc_control;
> EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
> u32 kvm_max_guest_tsc_khz;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 587fb9e..8da5823 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -125,5 +125,7 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
> #define KVM_SUPPORTED_XCR0 (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
> extern u64 host_xcr0;
>
> +extern unsigned int min_timer_period_us;
> +
> extern struct static_key kvm_no_apic_vcpu;
> #endif
>
Indeed, required here as well.
Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>
At this chance, I also grep'ed through timer emulations of other archs.
Only MIPS uses a periodic hrtimer, but with a fixed frequency. So we
should be safe for now.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: KVM: x86: limit PIT timer frequency
2014-01-06 14:00 KVM: x86: limit PIT timer frequency Marcelo Tosatti
2014-01-06 17:49 ` Jan Kiszka
@ 2014-01-15 11:44 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2014-01-15 11:44 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm-devel, Jan Kiszka
Il 06/01/2014 15:00, Marcelo Tosatti ha scritto:
>
>
> Limit PIT timer frequency similarly to the limit applied by
> LAPIC timer.
>
> Cc: stable@kernel.org
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
> index 412a5aa..518d864 100644
> --- a/arch/x86/kvm/i8254.c
> +++ b/arch/x86/kvm/i8254.c
> @@ -37,6 +37,7 @@
>
> #include "irq.h"
> #include "i8254.h"
> +#include "x86.h"
>
> #ifndef CONFIG_X86_64
> #define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
> @@ -349,6 +350,23 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
> atomic_set(&ps->pending, 0);
> ps->irq_ack = 1;
>
> + /*
> + * Do not allow the guest to program periodic timers with small
> + * interval, since the hrtimers are not throttled by the host
> + * scheduler.
> + */
> + if (ps->is_periodic) {
> + s64 min_period = min_timer_period_us * 1000LL;
> +
> + if (ps->period < min_period) {
> + pr_info_ratelimited(
> + "kvm: requested %lld ns "
> + "i8254 timer period limited to %lld ns\n",
> + ps->period, min_period);
> + ps->period = min_period;
> + }
> + }
> +
> hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
> HRTIMER_MODE_ABS);
> }
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index dec48bf..7f4dfa6 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -71,9 +71,6 @@
> #define VEC_POS(v) ((v) & (32 - 1))
> #define REG_POS(v) (((v) >> 5) << 4)
>
> -static unsigned int min_timer_period_us = 500;
> -module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
> -
> static inline void apic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
> {
> *((u32 *) (apic->regs + reg_off)) = val;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 5d004da..d89d51b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -94,6 +94,9 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
> static bool ignore_msrs = 0;
> module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
>
> +unsigned int min_timer_period_us = 500;
> +module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
> +
> bool kvm_has_tsc_control;
> EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
> u32 kvm_max_guest_tsc_khz;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 587fb9e..8da5823 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -125,5 +125,7 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
> #define KVM_SUPPORTED_XCR0 (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
> extern u64 host_xcr0;
>
> +extern unsigned int min_timer_period_us;
> +
> extern struct static_key kvm_no_apic_vcpu;
> #endif
>
Applied to kvm/queue, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-15 11:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-06 14:00 KVM: x86: limit PIT timer frequency Marcelo Tosatti
2014-01-06 17:49 ` Jan Kiszka
2014-01-15 11:44 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox