From patchwork Wed May 23 07:02:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10420535 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 DDABB60327 for ; Wed, 23 May 2018 07:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFA8128DBA for ; Wed, 23 May 2018 07:49:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3C3F28EA8; Wed, 23 May 2018 07:49:03 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 3114728DBA for ; Wed, 23 May 2018 07:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932118AbeEWHtB (ORCPT ); Wed, 23 May 2018 03:49:01 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:38843 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754455AbeEWHsO (ORCPT ); Wed, 23 May 2018 03:48:14 -0400 Received: by mail-pg0-f68.google.com with SMTP id n9-v6so9039609pgq.5; Wed, 23 May 2018 00:48:14 -0700 (PDT) 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=at5coJFxVS4j65YzOi0cbujqWgqngkZ6aVJgRf6BU/8=; b=KN3cbWUdH8pmkFIAFEe8W5n6CiucYx/ACeC333h484WT0Oex95kCMciqTrbtPMW9/V YjIltjfYBlqtnBA49bX324HaCwrixXwOO5mxOm5y9cVE9inKvX5pM4HVxOQK0XI9RsJR NAk9Bho4PUpXNPRF5XpGyh6N3IyvCYbwbbuEUomy5jv2EcK8wrAPNJ9mxz18dxva1ia9 kWsfTfOa3WiTYCsN5mUbpmeCEzG9Ygi8m7O3xbR8TZOUqEVyVdy28DPif4M5S/GK0ue3 IcBH2MHPfy09o6ASSZBcRFpfuZpF9LbvbtBQU8xzMCWSX/bBSvZaQ7WhcIWxuXt7u+yl 9kVw== 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=at5coJFxVS4j65YzOi0cbujqWgqngkZ6aVJgRf6BU/8=; b=p3vVA4WJGIPUXG8Jt5eivPoxW/NV/2g3kOAUjbX4EqEiHC31F62ECv51qQKUL+//q+ cnRYiavdfV6loTxnOuyXcqtSEX6Tb+/71/EZQhqehu7v2WWXhaY+elD5BI0ehRsyrtNx d7bsozh3JtqkYy2EfaQXP4DJoS5Rh0+B4SdT/CQazwIexxFb4ue/sxUMgxQVtvU5q0qH Y2sPvJjCoO6cG6WU623tvSaZmOgTs0oleNcwqq8CjfF5bE9IVCGkRmL9dFg8gZg1kHd2 9Mm2oFg02nGYtlMiyQ64xYc+JoTyH7sCRTz3ciACKSSjXYlTqFSpQV+swchJ2z3FUdvS BHKg== X-Gm-Message-State: ALKqPwcWkYYvt/tHlp4m4ZJs1LO5uc7xHjXEJgwQuFFCqQFjD2Oqtx4K gR9fjpUy0jIHDLfxwTo/52o= X-Google-Smtp-Source: AB8JxZrt7MAplE2hOGHDMC8Yd4MbnrMBIdnf0dtj19fMTeNZ7/DbmuywoA2kCCymd4GHvE/OSTMKgg== X-Received: by 2002:a65:6005:: with SMTP id m5-v6mr1452874pgu.241.1527061693505; Wed, 23 May 2018 00:48:13 -0700 (PDT) Received: from simonLocalRHEL7.cn.ibm.com ([112.73.0.89]) by smtp.gmail.com with ESMTPSA id a4-v6sm39079171pfj.19.2018.05.23.00.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 00:48:13 -0700 (PDT) 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 v4 22/29] KVM: PPC: Book3S PR: add emulation for tabort. for privilege guest Date: Wed, 23 May 2018 15:02:05 +0800 Message-Id: <1527058932-7434-23-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527058932-7434-1-git-send-email-wei.guo.simon@gmail.com> References: <1527058932-7434-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 b7530cf..34f910e 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, @@ -468,6 +510,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);