From patchwork Tue Feb 27 17:37:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10245863 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 67DD960384 for ; Tue, 27 Feb 2018 17:38:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5787D2879B for ; Tue, 27 Feb 2018 17:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BDEB28A1D; Tue, 27 Feb 2018 17:38:39 +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 C75392879B for ; Tue, 27 Feb 2018 17:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751899AbeB0Rig (ORCPT ); Tue, 27 Feb 2018 12:38:36 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38552 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbeB0Rie (ORCPT ); Tue, 27 Feb 2018 12:38:34 -0500 Received: by mail-pl0-f68.google.com with SMTP id d4so11793563pll.5; Tue, 27 Feb 2018 09:38:34 -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=zC/NLM2YfXm4uygTK1B9NOJ4bxnyUb/qbNkStQUbjOI=; b=L+6oYlT6b3402dqF+OwCLDGj3FwfQivBaYwuOuIBpy6lxb2ZoUiZESJn1eeEAmkqGz phjtWTALzQafnJjWFL1O5IOQ3sYVxZDPYMFmoxuKNVLMuo6qXl22T/BP8ZPrEDRrfkl8 D3H9vrBqbVcDawQUPzBSJXb91Vg5kKn1hg8tfaRnjPhcXYfsQMGebhLUeDEjnXDFAse/ pkxDsbrLnj4Po9lx9gKyolngZLHqCJj1y39G6wWbixfN0WA/qFh0yCeSGwqjC03g4w+b Qz2/iVQ0arg30n2SU7w2l7ktTpktDN0FIS1kHVujawd/nhCHUB/aIrsRqylGriurOyGo g9Ew== 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=zC/NLM2YfXm4uygTK1B9NOJ4bxnyUb/qbNkStQUbjOI=; b=oaV4vGh4R1X6lp4Nc3TrfPIS0ouk/GGDqdpgdUxdWDeTHtCh4fgCEj8qDamAQsHENr DdzuMH7KF0jdRj3UxOTynIzVpwevnOySIswJy9rIVw7eVEHUEzhiPZvjUREvUrYk634A F84vzfwKTishoecQvIJLtqsRM1e1w7x5zHN7enxGBMgsuLaGncUqOon9H/sCtmTEQQhD WtWUbgqCqhLqi0rQbx1uMr9tteKkxOb3tbflLyyfjWFAcsSYe8XNnMO9wsRIUljBip1e B77zW9GESBrfEZbIub4+yGjWdyKLfUzKv2FnD1M4bRBXxCL0t3iCf7tNBgSpWtJbHtLL ZOLQ== X-Gm-Message-State: APf1xPBKhRIUSQPgY+MRU4nugV4ybAiJj7Lh1wlLeP7HbQuz97j7uo2q tEitX1KCRQjGYqbGu0gy14M= X-Google-Smtp-Source: AG47ELu7dLKv/pxbK3Z5wEgByUwFEAfBGhkvusSzMyIQi2ypZkb+2BZCLvHHLx3JY0OgHKk80BU6ZA== X-Received: by 2002:a17:902:5984:: with SMTP id p4-v6mr10642297pli.38.1519753113809; Tue, 27 Feb 2018 09:38:33 -0800 (PST) Received: from simonLocalRHEL7.x64 ([101.80.181.226]) by smtp.gmail.com with ESMTPSA id q87sm14734143pfa.29.2018.02.27.09.38.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 09:38:33 -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 07/30] KVM: PPC: Book3S PR: add C function wrapper for _kvmppc_save/restore_tm() Date: Wed, 28 Feb 2018 01:37:14 +0800 Message-Id: <1519753057-11059-8-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1519753057-11059-1-git-send-email-wei.guo.simon@gmail.com> References: <1519753057-11059-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 Currently _kvmppc_save/restore_tm() APIs can only be invoked from assembly function. This patch adds C function wrappers for them so that they can be safely called from C function. Signed-off-by: Simon Guo --- arch/powerpc/include/asm/asm-prototypes.h | 6 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 8 +-- arch/powerpc/kvm/tm.S | 95 ++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/asm-prototypes.h b/arch/powerpc/include/asm/asm-prototypes.h index 002abfc..b0ccd91 100644 --- a/arch/powerpc/include/asm/asm-prototypes.h +++ b/arch/powerpc/include/asm/asm-prototypes.h @@ -126,7 +126,13 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4, void _mcount(void); unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip); +/* Transaction memory related */ void tm_enable(void); void tm_disable(void); void tm_abort(uint8_t cause); + +struct kvm_vcpu; +void _kvmppc_restore_tm_pr(struct kvm_vcpu *vcpu, u64 guest_msr); +void _kvmppc_save_tm_pr(struct kvm_vcpu *vcpu, u64 guest_msr); + #endif /* _ASM_POWERPC_ASM_PROTOTYPES_H */ diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S index df13cea..4b59424 100644 --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S @@ -790,7 +790,7 @@ BEGIN_FTR_SECTION */ mr r3, r4 ld r4, VCPU_MSR(r3) - bl kvmppc_restore_tm + bl __kvmppc_restore_tm ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif @@ -1735,7 +1735,7 @@ BEGIN_FTR_SECTION */ mr r3, r9 ld r4, VCPU_MSR(r3) - bl kvmppc_save_tm + bl __kvmppc_save_tm ld r9, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif @@ -2596,7 +2596,7 @@ BEGIN_FTR_SECTION */ ld r3, HSTATE_KVM_VCPU(r13) ld r4, VCPU_MSR(r3) - bl kvmppc_save_tm + bl __kvmppc_save_tm END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif @@ -2710,7 +2710,7 @@ BEGIN_FTR_SECTION */ mr r3, r4 ld r4, VCPU_MSR(r3) - bl kvmppc_restore_tm + bl __kvmppc_restore_tm ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif diff --git a/arch/powerpc/kvm/tm.S b/arch/powerpc/kvm/tm.S index 2d6fe5b..269dd11 100644 --- a/arch/powerpc/kvm/tm.S +++ b/arch/powerpc/kvm/tm.S @@ -35,7 +35,7 @@ * This can modify all checkpointed registers, but * restores r1, r2 before exit. */ -_GLOBAL(kvmppc_save_tm) +_GLOBAL(__kvmppc_save_tm) mflr r0 std r0, PPC_LR_STKOFF(r1) @@ -149,6 +149,52 @@ _GLOBAL(kvmppc_save_tm) blr /* + * _kvmppc_save_tm() is a wrapper around __kvmppc_save_tm(), so that it can + * be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_save_tm_pr) + mflr r5 + std r5, PPC_LR_STKOFF(r1) + stdu r1, -SWITCH_FRAME_SIZE(r1) + SAVE_NVGPRS(r1) + + /* save MSR since TM/math bits might be impacted + * by __kvmppc_save_tm(). + */ + mfmsr r5 + SAVE_GPR(5, r1) + + /* also save DSCR/CR so that it can be recovered later */ + mfspr r6, SPRN_DSCR + SAVE_GPR(6, r1) + + mfcr r7 + stw r7, _CCR(r1) + + bl __kvmppc_save_tm + + ld r7, _CCR(r1) + mtcr r7 + + REST_GPR(6, r1) + mtspr SPRN_DSCR, r6 + + /* need preserve current MSR's MSR_TS bits */ + REST_GPR(5, r1) + mfmsr r6 + rldicl r6, r6, 64 - MSR_TS_S_LG, 62 + rldimi r5, r6, MSR_TS_S_LG, 63 - MSR_TS_T_LG + mtmsrd r5 + + REST_NVGPRS(r1) + addi r1, r1, SWITCH_FRAME_SIZE + ld r5, PPC_LR_STKOFF(r1) + mtlr r5 + blr + +EXPORT_SYMBOL_GPL(_kvmppc_save_tm_pr); + +/* * Restore transactional state and TM-related registers. * Called with: * - r3 pointing to the vcpu struct. @@ -158,7 +204,7 @@ _GLOBAL(kvmppc_save_tm) * This potentially modifies all checkpointed registers. * It restores r1, r2 from the PACA. */ -_GLOBAL(kvmppc_restore_tm) +_GLOBAL(__kvmppc_restore_tm) mflr r0 std r0, PPC_LR_STKOFF(r1) @@ -186,6 +232,7 @@ _GLOBAL(kvmppc_restore_tm) rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 beqlr /* TM not active in guest */ std r1, HSTATE_SCRATCH2(r13) + std r3, HSTATE_SCRATCH1(r13) /* Make sure the failure summary is set, otherwise we'll program check * when we trechkpt. It's possible that this might have been not set @@ -262,6 +309,7 @@ _GLOBAL(kvmppc_restore_tm) ld r29, HSTATE_DSCR(r13) mtspr SPRN_DSCR, r29 #endif + ld r3, HSTATE_SCRATCH1(r13) ld r1, HSTATE_SCRATCH2(r13) ld r2, PACATMSCRATCH(r13) @@ -273,4 +321,47 @@ _GLOBAL(kvmppc_restore_tm) mtlr r0 blr +/* + * _kvmppc_restore_tm() is a wrapper around __kvmppc_restore_tm(), so that it + * can be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_restore_tm_pr) + mflr r5 + std r5, PPC_LR_STKOFF(r1) + stdu r1, -SWITCH_FRAME_SIZE(r1) + SAVE_NVGPRS(r1) + + /* save MSR to avoid TM/math bits change */ + mfmsr r5 + SAVE_GPR(5, r1) + + /* also save DSCR/CR so that it can be recovered later */ + mfspr r6, SPRN_DSCR + SAVE_GPR(6, r1) + + mfcr r7 + stw r7, _CCR(r1) + + bl __kvmppc_restore_tm + + ld r7, _CCR(r1) + mtcr r7 + + REST_GPR(6, r1) + mtspr SPRN_DSCR, r6 + + /* need preserve current MSR's MSR_TS bits */ + REST_GPR(5, r1) + mfmsr r6 + rldicl r6, r6, 64 - MSR_TS_S_LG, 62 + rldimi r5, r6, MSR_TS_S_LG, 63 - MSR_TS_T_LG + mtmsrd r5 + + REST_NVGPRS(r1) + addi r1, r1, SWITCH_FRAME_SIZE + ld r5, PPC_LR_STKOFF(r1) + mtlr r5 + blr + +EXPORT_SYMBOL_GPL(_kvmppc_restore_tm_pr); #endif