From: Paul Mackerras <paulus@samba.org> To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: Alexander Graf <agraf@suse.de>, Paul Mackerras <paulus@samba.org> Subject: [PATCH 7/8] KVM: PPC: Book3S HV: Fix decrementer timeouts with non-zero TB offset Date: Tue, 25 Mar 2014 10:47:07 +1100 [thread overview] Message-ID: <1395704828-20180-8-git-send-email-paulus@samba.org> (raw) In-Reply-To: <1395704828-20180-1-git-send-email-paulus@samba.org> Commit c7699822bc21 ("KVM: PPC: Book3S HV: Make physical thread 0 do the MMU switching") reordered the guest entry/exit code so that most of the guest register save/restore code happened in guest MMU context. A side effect of that is that the timebase still contains the guest timebase value at the point where we compute and use vcpu->arch.dec_expires, and therefore that is now a guest timebase value rather than a host timebase value. That in turn means that the timeouts computed in kvmppc_set_timer() are wrong if the timebase offset for the guest is non-zero. The consequence of that is things such as "sleep 1" in a guest after migration may sleep for much longer than they should. This fixes the problem by converting between guest and host timebase values as necessary, by adding or subtracting the timebase offset. This also fixes an incorrect comment. Signed-off-by: Paul Mackerras <paulus@samba.org> --- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S index 6c8dca7..0e6d9e5 100644 --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S @@ -833,6 +833,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) * Set the decrementer to the guest decrementer. */ ld r8,VCPU_DEC_EXPIRES(r4) + /* r8 is a host timebase value here, convert to guest TB */ + ld r5,HSTATE_KVM_VCORE(r13) + ld r6,VCORE_TB_OFFSET(r5) + add r8,r8,r6 mftb r7 subf r3,r7,r8 mtspr SPRN_DEC,r3 @@ -1196,6 +1200,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201) mftb r6 extsw r5,r5 add r5,r5,r6 + /* r5 is a guest timebase value here, convert to host TB */ + ld r3,HSTATE_KVM_VCORE(r13) + ld r4,VCORE_TB_OFFSET(r3) + subf r5,r4,r5 std r5,VCPU_DEC_EXPIRES(r9) BEGIN_FTR_SECTION @@ -1471,7 +1479,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) ld r8,VCORE_TB_OFFSET(r5) cmpdi r8,0 beq 17f - mftb r6 /* current host timebase */ + mftb r6 /* current guest timebase */ subf r8,r8,r6 mtspr SPRN_TBU40,r8 /* update upper 40 bits */ mftb r7 /* check if lower 24 bits overflowed */ -- 1.9.rc1
WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org> To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: Alexander Graf <agraf@suse.de>, Paul Mackerras <paulus@samba.org> Subject: [PATCH 7/8] KVM: PPC: Book3S HV: Fix decrementer timeouts with non-zero TB offset Date: Mon, 24 Mar 2014 23:47:07 +0000 [thread overview] Message-ID: <1395704828-20180-8-git-send-email-paulus@samba.org> (raw) In-Reply-To: <1395704828-20180-1-git-send-email-paulus@samba.org> Commit c7699822bc21 ("KVM: PPC: Book3S HV: Make physical thread 0 do the MMU switching") reordered the guest entry/exit code so that most of the guest register save/restore code happened in guest MMU context. A side effect of that is that the timebase still contains the guest timebase value at the point where we compute and use vcpu->arch.dec_expires, and therefore that is now a guest timebase value rather than a host timebase value. That in turn means that the timeouts computed in kvmppc_set_timer() are wrong if the timebase offset for the guest is non-zero. The consequence of that is things such as "sleep 1" in a guest after migration may sleep for much longer than they should. This fixes the problem by converting between guest and host timebase values as necessary, by adding or subtracting the timebase offset. This also fixes an incorrect comment. Signed-off-by: Paul Mackerras <paulus@samba.org> --- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S index 6c8dca7..0e6d9e5 100644 --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S @@ -833,6 +833,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) * Set the decrementer to the guest decrementer. */ ld r8,VCPU_DEC_EXPIRES(r4) + /* r8 is a host timebase value here, convert to guest TB */ + ld r5,HSTATE_KVM_VCORE(r13) + ld r6,VCORE_TB_OFFSET(r5) + add r8,r8,r6 mftb r7 subf r3,r7,r8 mtspr SPRN_DEC,r3 @@ -1196,6 +1200,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201) mftb r6 extsw r5,r5 add r5,r5,r6 + /* r5 is a guest timebase value here, convert to host TB */ + ld r3,HSTATE_KVM_VCORE(r13) + ld r4,VCORE_TB_OFFSET(r3) + subf r5,r4,r5 std r5,VCPU_DEC_EXPIRES(r9) BEGIN_FTR_SECTION @@ -1471,7 +1479,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) ld r8,VCORE_TB_OFFSET(r5) cmpdi r8,0 beq 17f - mftb r6 /* current host timebase */ + mftb r6 /* current guest timebase */ subf r8,r8,r6 mtspr SPRN_TBU40,r8 /* update upper 40 bits */ mftb r7 /* check if lower 24 bits overflowed */ -- 1.9.rc1
next prev parent reply other threads:[~2014-03-24 23:47 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-03-24 23:47 [PATCH 0/8] PPC Book 3S HV-mode KVM updates for 3.15 Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` [PATCH 1/8] KVM: PPC: Book3S HV: Fix KVM hang with CONFIG_KVM_XICS=n Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` [PATCH 2/8] KVM: PPC: Book3S HV: Add transactional memory support Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` [PATCH 3/8] KVM: PPC: Book3S HV: Add get/set_one_reg for new TM state Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-28 5:40 ` [PATCH 1/2] KVM: PPC: Book3S HV: Make TM avoid program check Michael Neuling 2014-03-28 5:40 ` Michael Neuling 2014-03-28 5:40 ` [PATCH 2/2] KVM: PPC: Book3S HV: Add branch label Michael Neuling 2014-03-28 5:40 ` Michael Neuling 2014-03-28 11:08 ` [PATCH 1/2] KVM: PPC: Book3S HV: Make TM avoid program check Paul Mackerras 2014-03-28 11:08 ` Paul Mackerras 2014-03-28 12:14 ` Paolo Bonzini 2014-03-28 12:14 ` Paolo Bonzini 2014-03-24 23:47 ` [PATCH 4/8] KVM: PPC: Book3S: Trim top 4 bits of physical address in RTAS code Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` [PATCH 5/8] KVM: PPC: Book3S HV: Return ENODEV error rather than EIO Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` [PATCH 6/8] KVM: PPC: Book3S HV: Don't use kvm_memslots() in real mode Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras [this message] 2014-03-24 23:47 ` [PATCH 7/8] KVM: PPC: Book3S HV: Fix decrementer timeouts with non-zero TB offset Paul Mackerras 2014-03-24 23:47 ` [PATCH 8/8] KVM: PPC: Book3S HV: Save/restore host PMU registers that are new in POWER8 Paul Mackerras 2014-03-24 23:47 ` Paul Mackerras 2014-03-25 1:39 ` [PATCH 0/8] PPC Book 3S HV-mode KVM updates for 3.15 Scott Wood 2014-03-25 1:39 ` Scott Wood
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1395704828-20180-8-git-send-email-paulus@samba.org \ --to=paulus@samba.org \ --cc=agraf@suse.de \ --cc=kvm-ppc@vger.kernel.org \ --cc=kvm@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.