From patchwork Tue Feb 27 17:52:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10245913 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 63DB660362 for ; Tue, 27 Feb 2018 18:01:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 541A628A3E for ; Tue, 27 Feb 2018 18:01:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4890B28A31; Tue, 27 Feb 2018 18:01: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 2DC0D28A31 for ; Tue, 27 Feb 2018 18:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbeB0SBf (ORCPT ); Tue, 27 Feb 2018 13:01:35 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:33742 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751821AbeB0SBd (ORCPT ); Tue, 27 Feb 2018 13:01:33 -0500 Received: by mail-pl0-f68.google.com with SMTP id c11-v6so8416917plo.0; Tue, 27 Feb 2018 10:01:33 -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=OwSGxb3pbNapDbFsCpjxK8e/LK3+54T24xyC+PJr7tY=; b=FtOY5DcTAciD12OqGQk9IjoBGJm+E1MErVXSkyqQ7wVe6g/bJ9PIclLFOum3H41Bsl mj383YmEtUwEnJs/3tRGbuiVqFz86RrrFYJyCt9Zc5atv4imzKJtVasPXZBR2XcFHokq XXDcbBRREdIaTSlR/eSIA77aUk/6ml30yJf+Fpxyb+H/AP/BkpYuyHw/k0IiKw+8D30z khVe0zSH2catZVCJ8D0RsNViCD/l1xQ4akX7vRw+hGMtAASSjUF5AsSoT6aoBVbU4qha UQZ+Vrnq87evfKZS/uTvyT0XfpiLMCNtvKNs3k5UVKnBdBFeD8voaMQXMGp0nRVD61cu U2lw== 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=OwSGxb3pbNapDbFsCpjxK8e/LK3+54T24xyC+PJr7tY=; b=ehsTGjVzfi8xayNug6GVqffxc2mZvDFn18vDDuOt3wVabOb43mXjgrwwWwaJJ5rza8 dkypNQnTJHO2h4ta1CJX1wJ65IAnAZ52caMkCF/03u3FeCrXOgBP8j7IGvdH5LKBpf3j 342+wckZpJpLZElN33cHTt8m36m5sLv0Jc3WGQbtBh5rn2ZlbjnvoPi52ITEEq4OMghP j3p0i/wf9I+8x+ImQufM8Jh3x2iMBP5KUyXEfrGT97m47Dezmh+6VYna4oadVCeCrAhQ c4CTpaPIEcaeRDxlLr6Cjkh3z+ZwNDRjwAA3OeLEvNh65ychK9mxWcfaTI+/+q/+gSot 60Gw== X-Gm-Message-State: APf1xPB6bceH1LErdfKjc6hg10NmRVWysDdTdpUeWQB0pAZoggU0kXQZ 006na6bqRfmHma0lnszraiQ= X-Google-Smtp-Source: AH8x224m6J+udfW+FjgHwLm2+hRqS4LXyYqTL916KtjQLK4blrTbixOYpjcL6cClh81kjn2mkU+EMg== X-Received: by 2002:a17:902:b58d:: with SMTP id a13-v6mr15344145pls.123.1519754492471; Tue, 27 Feb 2018 10:01:32 -0800 (PST) Received: from simonLocalRHEL7.x64 ([101.80.181.226]) by smtp.gmail.com with ESMTPSA id m83sm24360910pfk.107.2018.02.27.10.01.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 10:01:31 -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 22/30] KVM: PPC: Book3S PR: add emulation for tabort. for privilege guest Date: Wed, 28 Feb 2018 01:52:30 +0800 Message-Id: <1519753958-11756-12-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 Currently privilege guest will be run with TM disabled. Although the privilege guest cannot initiate a new transaction, it can use tabort to terminate its problem state's transaction. So it is still necessary to emulate tabort. for privilege guest. This patch adds emulation for tabort. of privilege guest. Tested with: https://github.com/justdoitqd/publicFiles/blob/master/test_tabort.c Signed-off-by: Simon Guo --- arch/powerpc/kvm/book3s_emulate.c | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c index ec88fbf..5656cdf 100644 --- a/arch/powerpc/kvm/book3s_emulate.c +++ b/arch/powerpc/kvm/book3s_emulate.c @@ -50,6 +50,7 @@ #define OP_31_XOP_SLBMFEE 915 #define OP_31_XOP_TBEGIN 654 +#define OP_31_XOP_TABORT 910 #define OP_31_XOP_TRECLAIM 942 #define OP_31_XOP_TRCHKPT 1006 @@ -196,6 +197,47 @@ static void kvmppc_emulate_trchkpt(struct kvm_vcpu *vcpu) kvmppc_restore_tm_pr(vcpu); preempt_enable(); } + +/* emulate tabort. at guest privilege state */ +static void kvmppc_emulate_tabort(struct kvm_vcpu *vcpu, int ra_val) +{ + /* currently we only emulate tabort. but no emulation of other + * tabort variants since there is no kernel usage of them at + * present. + */ + unsigned long guest_msr = kvmppc_get_msr(vcpu); + + preempt_disable(); + tm_enable(); + tm_abort(ra_val); + + /* CR0 = 0 | MSR[TS] | 0 */ + vcpu->arch.cr = (vcpu->arch.cr & ~(CR0_MASK << CR0_SHIFT)) | + (((guest_msr & MSR_TS_MASK) >> (MSR_TS_S_LG - 1)) + << CR0_SHIFT); + + vcpu->arch.texasr = mfspr(SPRN_TEXASR); + /* failure recording depends on Failure Summary bit, + * and tabort will be treated as nops in non-transactional + * state. + */ + if (!(vcpu->arch.texasr & TEXASR_FS) && + MSR_TM_ACTIVE(guest_msr)) { + vcpu->arch.texasr &= ~(TEXASR_PR | TEXASR_HV); + if (guest_msr & MSR_PR) + vcpu->arch.texasr |= TEXASR_PR; + + if (guest_msr & MSR_HV) + vcpu->arch.texasr |= TEXASR_HV; + + vcpu->arch.tfiar = kvmppc_get_pc(vcpu); + mtspr(SPRN_TEXASR, vcpu->arch.texasr); + mtspr(SPRN_TFIAR, vcpu->arch.tfiar); + } + tm_disable(); + preempt_enable(); +} + #endif int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, @@ -471,6 +513,32 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, emulated = EMULATE_FAIL; break; } + case OP_31_XOP_TABORT: + { + ulong guest_msr = kvmppc_get_msr(vcpu); + unsigned long ra_val = 0; + + if (!cpu_has_feature(CPU_FTR_TM)) + break; + + if (!(kvmppc_get_msr(vcpu) & MSR_TM)) { + kvmppc_trigger_fac_interrupt(vcpu, FSCR_TM_LG); + emulated = EMULATE_AGAIN; + break; + } + + /* only emulate for privilege guest, since problem state + * guest can run with TM enabled and we don't expect to + * trap at here for that case. + */ + WARN_ON(guest_msr & MSR_PR); + + if (ra) + ra_val = kvmppc_get_gpr(vcpu, ra); + + kvmppc_emulate_tabort(vcpu, ra_val); + break; + } case OP_31_XOP_TRECLAIM: { ulong guest_msr = kvmppc_get_msr(vcpu);