From patchwork Tue Feb 27 17:52:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10245917 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 EF8EE60362 for ; Tue, 27 Feb 2018 18:01:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E046D28A31 for ; Tue, 27 Feb 2018 18:01:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4CB528A44; Tue, 27 Feb 2018 18:01:41 +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 75C7F28A31 for ; Tue, 27 Feb 2018 18:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751857AbeB0SBk (ORCPT ); Tue, 27 Feb 2018 13:01:40 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:45903 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751608AbeB0SBf (ORCPT ); Tue, 27 Feb 2018 13:01:35 -0500 Received: by mail-pl0-f67.google.com with SMTP id v9-v6so9828304plp.12; Tue, 27 Feb 2018 10:01: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=SqpCmCNcnniY6Nt1khQ0Bw5HDYGj8Zk+miGdYgd9uhA=; b=hPRN7EASgMCXbCnfr/7SpJGR2WOG08CJStcgPLBAq3GM3Q/agVIAVTqvmZgibAlbGa /1XYJMOdamrXwx0wiuMl8y12hdA6ECi6sN3NfifK5hIPTkNp3H9ImAX/Bi+peS1Qdozm qvPEo3pJ/NIFvEAdWyG5Wd7a27MoHmvgHjeRHO7Nd/G3TI95NEoY/bEYTQ8a+2q8JkWt uCZySzOZ8KXyq+X+5aRSD0THga/M0Nc8BHWLXr5Ln07TVyOH7lEfqprSqXRjPBNvB92m jiv0OwwIN36R3MPuT6vRq8hLivIdRjP2V/m0J/xqXC7wNzXr9cWs8YQE4hxKZg97ouAF kvMw== 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=SqpCmCNcnniY6Nt1khQ0Bw5HDYGj8Zk+miGdYgd9uhA=; b=daoDpybQyeWjmX/efUhNARk+TnEi3GPbW9rSHdbHfsBAE8nZu4sdRYhDvdr+KfwTeC kIsmzJFiJnZdgt9cFoeuPgf/BJaHh5f/DwsEXnKGdkvgnYNDdFxyQeEzEV6v3A2vXRyn SDH6jMM1RUJxTysobT37UvpDjr+YTedBHlIkvGSC85pgmEV8DWIvKGxzYeWj9bTvf3E9 CNfxU6A8dRRy/Y8UOQIX/h/6HKXSfL7AeEU+sxJ1ZErK3lEf1RdpNGey7WpdVnILz5Mb 4KYCHmpuI6x+0YqFfz1eHM8Qm6D7L9gfNNZ9fYBIKIbg/WFJTuHfX4awdJY/f1CWrzXP mwsw== X-Gm-Message-State: APf1xPB5lUQ9xfeMgjwp0yFMGkMlq4F4Cu7V85dYdnZhjQj27xNMdC8L 6mQwhZLu6s03/79qo757a5k= X-Google-Smtp-Source: AH8x227nZxztFRy8q5yDuBxkMQEX0kDQ4ja6ZQRQ5Eq94BygtBpwm/WL7iU4St7eaFymJiaycmqY2Q== X-Received: by 2002:a17:902:d909:: with SMTP id c9-v6mr14996645plz.34.1519754494601; Tue, 27 Feb 2018 10:01:34 -0800 (PST) Received: from simonLocalRHEL7.x64 ([101.80.181.226]) by smtp.gmail.com with ESMTPSA id m83sm24360910pfk.107.2018.02.27.10.01.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 10:01:34 -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 23/30] KVM: PPC: Book3S PR: add guard code to prevent returning to guest with PR=0 and Transactional state Date: Wed, 28 Feb 2018 01:52:31 +0800 Message-Id: <1519753958-11756-13-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 PR KVM doesn't support transaction memory at guest privilege state. This patch adds a check at setting guest msr, so that we can never return to guest with PR=0 and TS=0b10. A tabort will be emulated to indicate this and fail transaction immediately. Signed-off-by: Simon Guo --- arch/powerpc/include/uapi/asm/tm.h | 2 +- arch/powerpc/kvm/book3s.h | 6 ++++++ arch/powerpc/kvm/book3s_emulate.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 13 ++++++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/tm.h b/arch/powerpc/include/uapi/asm/tm.h index e1bf0e2..e2947c9 100644 --- a/arch/powerpc/include/uapi/asm/tm.h +++ b/arch/powerpc/include/uapi/asm/tm.h @@ -13,7 +13,7 @@ #define TM_CAUSE_TLBI 0xdc #define TM_CAUSE_FAC_UNAV 0xda #define TM_CAUSE_SYSCALL 0xd8 -#define TM_CAUSE_MISC 0xd6 /* future use */ +#define TM_CAUSE_PRIV_T 0xd6 #define TM_CAUSE_SIGNAL 0xd4 #define TM_CAUSE_ALIGNMENT 0xd2 #define TM_CAUSE_EMULATE 0xd0 diff --git a/arch/powerpc/kvm/book3s.h b/arch/powerpc/kvm/book3s.h index d2b3ec0..7aaa302 100644 --- a/arch/powerpc/kvm/book3s.h +++ b/arch/powerpc/kvm/book3s.h @@ -32,4 +32,10 @@ extern int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, extern int kvmppc_book3s_init_pr(void); extern void kvmppc_book3s_exit_pr(void); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +extern void kvmppc_emulate_tabort(struct kvm_vcpu *vcpu, int ra_val); +#else +static inline void kvmppc_emulate_tabort(struct kvm_vcpu *vcpu, int ra_val) {} +#endif + #endif diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c index 5656cdf..6c5ef8c 100644 --- a/arch/powerpc/kvm/book3s_emulate.c +++ b/arch/powerpc/kvm/book3s_emulate.c @@ -199,7 +199,7 @@ static void kvmppc_emulate_trchkpt(struct kvm_vcpu *vcpu) } /* emulate tabort. at guest privilege state */ -static void kvmppc_emulate_tabort(struct kvm_vcpu *vcpu, int ra_val) +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 diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index f77a004..29ec92e 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -457,12 +457,23 @@ static void kvm_set_spte_hva_pr(struct kvm *kvm, unsigned long hva, pte_t pte) static void kvmppc_set_msr_pr(struct kvm_vcpu *vcpu, u64 msr) { - ulong old_msr = kvmppc_get_msr(vcpu); + ulong old_msr; #ifdef EXIT_DEBUG printk(KERN_INFO "KVM: Set MSR to 0x%llx\n", msr); #endif +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + /* We should never target guest MSR to TS=10 && PR=0, + * since we always fail transaction for guest privilege + * state. + */ + if (!(msr & MSR_PR) && MSR_TM_TRANSACTIONAL(msr)) + kvmppc_emulate_tabort(vcpu, + TM_CAUSE_PRIV_T | TM_CAUSE_PERSISTENT); +#endif + + old_msr = kvmppc_get_msr(vcpu); msr &= to_book3s(vcpu)->msr_mask; kvmppc_set_msr_fast(vcpu, msr); kvmppc_recalc_shadow_msr(vcpu);