From patchwork Tue Feb 27 17:52:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10245933 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 E16FC60362 for ; Tue, 27 Feb 2018 18:02:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D00B428514 for ; Tue, 27 Feb 2018 18:02:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3031285E1; Tue, 27 Feb 2018 18:02:30 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham 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 679DD28514 for ; Tue, 27 Feb 2018 18:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751793AbeB0SC3 (ORCPT ); Tue, 27 Feb 2018 13:02:29 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38744 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751728AbeB0SBS (ORCPT ); Tue, 27 Feb 2018 13:01:18 -0500 Received: by mail-pf0-f195.google.com with SMTP id d26so8269101pfn.5; Tue, 27 Feb 2018 10:01:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R9Q34qtkES6MVKabYTUlriA2cN8VzgrMuOjZ86tvTRo=; b=bL7/MyPsrnPleTgzVktWyTjV+JV7SerROGX9ZJqAEIWe4Q46FivxNE52Ii85YWYrpS 10KtYFrSGq4YFLGR7Ntf/F5l120X2YlprUaI5Fyhz3SNp5CGiaelKR7XlUAURbtg8HVw qIiCT0J+bARCTY5GwQZQXXF5Dflxhuku08iymxnZYzWO76P97+7FUT/1ad9/Vs+N8000 fy8OA/586UthGLyhbzXEwdnaKUN0pQI4ly+6I5sDD3rhtp2g2tTe3eCUOAAvmJgXu3ER inVH+oW7Qb0ywhPwR0BurEqTy2koVxM755IK//FGAHyab3c9WISaGzEYZtyxG6+mbonG FAEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R9Q34qtkES6MVKabYTUlriA2cN8VzgrMuOjZ86tvTRo=; b=H9a92EQ2L3xPbimsfPYc1jBFFqUCfO4BR5z23wBYk4KhY0Sfq+K06FlRU7Xuvg2Ufh 3pr5Nh2h7W1m8AM6W/Wihrya/yCehvCYuGW31R3tjQGztjVVzTiDGxEjM8o+ETOxYcJd BSu1EIPI9biIxezTnyiqiHgwY8nbUI9khL6NmkwA4rMIUY0qKveLAgHr2qI96fXwTq4N gfO844thMJp3GUYOfEkBZHt3db5I2ISStBYniTpk7Eprowczb2ccUhM3tHrtSPlcDtKp pHW3zdXg1qFAqvfw0Bm6CdeXVKuNqd2U6b2ISf0PfLM7+creauAf3uKkuDxSZ37SOTnt ceGQ== X-Gm-Message-State: APf1xPBe4WmICBPeNFAJ4HsT0csNv/PSgs13NagUtoA3cM0khdLltnTA 2Rzzd0IqOtLhECnxWcxeqo8= X-Google-Smtp-Source: AH8x226MZpxEbM5JaN3AiIYE+KSzLVqLRtYI7Bc02wqt0a623dUH9nNlvRSI6wwUDOxWZElUX9Z1/Q== X-Received: by 10.99.38.67 with SMTP id m64mr11896550pgm.2.1519754478470; Tue, 27 Feb 2018 10:01:18 -0800 (PST) Received: from simonLocalRHEL7.x64 ([101.80.181.226]) by smtp.gmail.com with ESMTPSA id m83sm24360910pfk.107.2018.02.27.10.01.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 10:01:17 -0800 (PST) From: wei.guo.simon@gmail.com To: linuxppc-dev@lists.ozlabs.org Cc: Paul Mackerras , kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, Simon Guo Subject: [PATCH v2 16/30] KVM: PPC: Book3S PR: add math support for PR KVM HTM Date: Wed, 28 Feb 2018 01:52:24 +0800 Message-Id: <1519753958-11756-6-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1519753958-11756-1-git-send-email-wei.guo.simon@gmail.com> References: <1519753958-11756-1-git-send-email-wei.guo.simon@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Simon Guo The math registers will be saved into vcpu->arch.fp/vr and corresponding vcpu->arch.fp_tm/vr_tm area. We flush or giveup the math regs into vcpu->arch.fp/vr before saving transaction. After transaction is restored, the math regs will be loaded back into regs. If there is a FP/VEC/VSX unavailable exception during transaction active state, the math checkpoint content might be incorrect and we need to do treclaim./load the correct checkpoint val/trechkpt. sequence to retry the transaction. That will make our solution complicated. To solve this issue, we always make the hardware guest MSR math bits (shadow_msr) consistent with the MSR val which guest sees (kvmppc_get_msr()) when guest msr is with tm enabled. Then all FP/VEC/VSX unavailable exception can be delivered to guest and guest handles the exception by itself. Signed-off-by: Simon Guo --- arch/powerpc/kvm/book3s_pr.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index ac9d58f..2fcc059 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -310,6 +310,28 @@ static inline void kvmppc_restore_tm_sprs(struct kvm_vcpu *vcpu) tm_disable(); } +/* loadup math bits which is enabled at kvmppc_get_msr() but not enabled at + * hardware. + */ +static void kvmppc_handle_lost_math_exts(struct kvm_vcpu *vcpu) +{ + ulong exit_nr; + ulong ext_diff = (kvmppc_get_msr(vcpu) & ~vcpu->arch.guest_owned_ext) & + (MSR_FP | MSR_VEC | MSR_VSX); + + if (!ext_diff) + return; + + if (ext_diff == MSR_FP) + exit_nr = BOOK3S_INTERRUPT_FP_UNAVAIL; + else if (ext_diff == MSR_VEC) + exit_nr = BOOK3S_INTERRUPT_ALTIVEC; + else + exit_nr = BOOK3S_INTERRUPT_VSX; + + kvmppc_handle_ext(vcpu, exit_nr, ext_diff); +} + void kvmppc_save_tm_pr(struct kvm_vcpu *vcpu) { if (!(MSR_TM_ACTIVE(kvmppc_get_msr(vcpu)))) { @@ -317,6 +339,8 @@ void kvmppc_save_tm_pr(struct kvm_vcpu *vcpu) return; } + kvmppc_giveup_ext(vcpu, MSR_VSX); + preempt_disable(); _kvmppc_save_tm_pr(vcpu, mfmsr()); preempt_enable(); @@ -326,12 +350,18 @@ void kvmppc_restore_tm_pr(struct kvm_vcpu *vcpu) { if (!MSR_TM_ACTIVE(kvmppc_get_msr(vcpu))) { kvmppc_restore_tm_sprs(vcpu); + if (kvmppc_get_msr(vcpu) & MSR_TM) + kvmppc_handle_lost_math_exts(vcpu); return; } preempt_disable(); _kvmppc_restore_tm_pr(vcpu, kvmppc_get_msr(vcpu)); preempt_enable(); + + if (kvmppc_get_msr(vcpu) & MSR_TM) + kvmppc_handle_lost_math_exts(vcpu); + } #endif @@ -479,6 +509,9 @@ static void kvmppc_set_msr_pr(struct kvm_vcpu *vcpu, u64 msr) /* Preload FPU if it's enabled */ if (kvmppc_get_msr(vcpu) & MSR_FP) kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP); + + if (kvmppc_get_msr(vcpu) & MSR_TM) + kvmppc_handle_lost_math_exts(vcpu); } void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr)