From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: KVM: x86: limit PIT timer frequency Date: Mon, 06 Jan 2014 18:49:28 +0100 Message-ID: <52CAECA8.1020207@web.de> References: <20140106140002.GA24790@amt.cnet> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kcoWFosLLT7eqJqbSp2UCsemVSjo7fUNH" Cc: Paolo Bonzini To: Marcelo Tosatti , kvm-devel Return-path: Received: from mout.web.de ([212.227.15.14]:56167 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755204AbaAFRtf (ORCPT ); Mon, 6 Jan 2014 12:49:35 -0500 Received: from mchn199C.mchp.siemens.de ([95.157.58.223]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0Ljaiq-1VOgYn2jai-00bbx8 for ; Mon, 06 Jan 2014 18:49:34 +0100 In-Reply-To: <20140106140002.GA24790@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --kcoWFosLLT7eqJqbSp2UCsemVSjo7fUNH Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2014-01-06 15:00, Marcelo Tosatti wrote: >=20 >=20 > Limit PIT timer frequency similarly to the limit applied by=20 > LAPIC timer. >=20 > Cc: stable@kernel.org > Signed-off-by: Marcelo Tosatti >=20 > 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 @@ > =20 > #include "irq.h" > #include "i8254.h" > +#include "x86.h" > =20 > #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 =3D 1; > =20 > + /* > + * 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 =3D 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 =3D 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) > =20 > -static unsigned int min_timer_period_us =3D 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, u= 32 val) > { > *((u32 *) (apic->regs + reg_off)) =3D 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 =3D 0; > module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR); > =20 > +unsigned int min_timer_period_us =3D 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; > =20 > +extern unsigned int min_timer_period_us; > + > extern struct static_key kvm_no_apic_vcpu; > #endif >=20 Indeed, required here as well. Reviewed-by: Jan Kiszka 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 --kcoWFosLLT7eqJqbSp2UCsemVSjo7fUNH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlLK7KwACgkQitSsb3rl5xSjQQCaAj+g+RqdJ4mOQdupTIxSLoM9 e84An1GSAmS++aRAdJEgghekq1nMVxIz =HTFe -----END PGP SIGNATURE----- --kcoWFosLLT7eqJqbSp2UCsemVSjo7fUNH--