From: "Nadav Har'El" Subject: Re: Nested VMX - L1 hangs on running L2 Date: Wed, 27 Jul 2011 14:51:00 +0300 Message-ID: <20110727115100.GA23118@fermat.math.technion.ac.il> References: <20110708184053.GA23958@stratus.com> <20110718182628.GB5324@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Bandan Das , KVM Mailing List , Marcelo Tosatti To: Zachary Amsden Return-path: Received: from mailgw12.technion.ac.il ([132.68.225.12]:58357 "EHLO mailgw12.technion.ac.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753108Ab1G0MBg (ORCPT ); Wed, 27 Jul 2011 08:01:36 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Jul 20, 2011, Zachary Amsden wrote about "Re: Nested VMX - L1 h= angs on running L2": > > > No, both patches are wrong. > > >=20 > kvm_get_msr(vcpu,=A0MSR_IA32_TSC,=A0&tsc) should always return the L1= TSC, > regardless of the setting of any MSR bitmap. The reason why is that i= t > is being called by the L0 hypervisor kernel, which handles only > interactions with the L1 MSRs. guest_read_tsc() (called by the above get_msr) currently does this: static u64 guest_read_tsc(void) { u64 host_tsc, tsc_offset; rdtscll(host_tsc); tsc_offset =3D vmcs_read64(TSC_OFFSET); return host_tsc + tsc_offset; } I guess you'd want this to change to something like: tsc_offset =3D is_guest_mode(vcpu) ?=20 vmx->nested.vmcs01_tsc_offset : vmcs_read64(TSC_OFFSET); But I still am not convinced that that would be right.... E.g., imagine the case where L1 uses TSC_OFFSETING and but doesn't trap TSC MSR read. The SDM says (if I understand it correctly) that thi= s TSC MSR read will not exit (because L1 doesn't trap it) but *will* do the e= xtra offsetting. In this case, the original code (using vmcs02's TSC_OFFSET = which is the sum of that of vmcs01 and vmcs12), is correct, and the new code = will be incorrect. Or am I misunderstanding the SDM? Can you tell me in which case the original code would return incorrect results to a guest (L1 or L2) doing anything MSR-related? I'm assuming that some code in KVM also uses kvm_read_msr and assumes i= t gets the TSC value for L1, not for the guest currently running (L2 or L= 1). I don't understand why it needs to assume that... Why would it be wrong= to return L2's TSC, and just remember that *changing* the L2 TSC really me= ans changing the L1 TSC offset (vmcs01_tsc_offset), not vmcs12.tsc_offset w= hich we can't touch? Thanks, Nadav. --=20 Nadav Har'El | Wednesday, Jul 27 2011, 25 Tamm= uz 5771 nyh@math.technion.ac.il |----------------------------------= ------- Phone +972-523-790466, ICQ 13349191 |You may only be one person to the = world, http://nadav.harel.org.il |but may also be the world to one p= erson.