From patchwork Tue Feb 27 17:52:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon X-Patchwork-Id: 10245907 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 14B8460362 for ; Tue, 27 Feb 2018 18:01:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06A9528A31 for ; Tue, 27 Feb 2018 18:01:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFAD128A46; Tue, 27 Feb 2018 18:01:29 +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 86F2028A31 for ; Tue, 27 Feb 2018 18:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbeB0SB2 (ORCPT ); Tue, 27 Feb 2018 13:01:28 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36241 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751669AbeB0SB0 (ORCPT ); Tue, 27 Feb 2018 13:01:26 -0500 Received: by mail-pf0-f194.google.com with SMTP id 68so8271905pfx.3; Tue, 27 Feb 2018 10:01:26 -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=kNhRhm75USLpccaEHOs5YsyXm+lXayXue7Vn9epS/a4=; b=pYqGAZhKwqGgtci7MJDa1olFzkSHWkGteg+Zz1vruSrvt5Xikkz1oX+XS7NEHV6oB6 SRE+DB9Powaem6sGGKRrDmpN6Tb2KO99eg8nu7rmF2GTaFQuFz4gCnzlfeDgokE0+OxK 4zQfy28WWGzwfqNDYtpU03TD2jAGa/DyRzGQeut6Tm8gcC86zMHzdQkZIGqRbNuOoCE9 vpChNlbn1VLlwpJ/6eJ+Gjd+U0x4I/q3+iWhoFX7WLPPdfZwyyyyFkZMMzBQeeSuQzNP 6N112JdRekIMAA78To/MTEbd7daZlXz+NU05z0SuVeQ/isAYErk7PXsyX6NT/+HmFd+4 oQfw== 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=kNhRhm75USLpccaEHOs5YsyXm+lXayXue7Vn9epS/a4=; b=tH1CGRzR/RevitgO4cP0GTZUkRP70oCtQUKUH1LEZ6KyZn6b/jw/EBndvWM0NIE+O3 nvG3s/qjTcuj+XylOfxMfxREPDENDPpHYfRZSsr+DJ5Z4TW1G4ynIrKTB93FgbM0qT8V Yu60lDZKklfT0tRHNwyjOhYDDdyvhbLf3pXLlEFFhmV6fErkrW9LZ9pW7v7WHFnMqpCN 4WwGPtSX9bn2SyJkZWfCtVfbZ0OXYOVL+/hq1xttAeruN2VgU6C4U+PAHJ+Qn1X8afgW SoEBz+uXLDozyisG83jl/oq1GqO1ytv2d4ygCnFze7+hqU9gcEiCc6DdQlprkW6epxM2 tOgQ== X-Gm-Message-State: APf1xPAs5/sHbQ/CAa+lj12RPF0MhqkkpcikspC/b9VL0TMG2SYILNtS qizUdJ2oiisy1rvryGLo5F0= X-Google-Smtp-Source: AH8x226njH+QrW8e70UmhC/xwXsQybW5P2bbQru3XWrlayy+EySREUehdJXhKRp4WbgfYDEn1hLdPg== X-Received: by 10.101.99.205 with SMTP id n13mr12129994pgv.345.1519754485670; Tue, 27 Feb 2018 10:01:25 -0800 (PST) Received: from simonLocalRHEL7.x64 ([101.80.181.226]) by smtp.gmail.com with ESMTPSA id m83sm24360910pfk.107.2018.02.27.10.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 10:01:25 -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 19/30] KVM: PPC: Book3S PR: enable NV reg restore for reading TM SPR at guest privilege state Date: Wed, 28 Feb 2018 01:52:27 +0800 Message-Id: <1519753958-11756-9-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 kvmppc_handle_fac() will not update NV GPRs and thus it can return with GUEST_RESUME. However PR KVM guest always disables MSR_TM bit at privilege state. If PR privilege guest are trying to read TM SPRs, it will trigger TM facility unavailable exception and fall into kvmppc_handle_fac(). Then the emulation will be done by kvmppc_core_emulate_mfspr_pr(). The mfspr instruction can include a RT with NV reg. So it is necessary to restore NV GPRs at this case, to reflect the update to NV RT. This patch make kvmppc_handle_fac() return GUEST_RESUME_NV at TM fac exception and with guest privilege state. Signed-off-by: Simon Guo Reviewed-by: Paul Mackerras --- arch/powerpc/kvm/book3s_pr.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 82e1a74..f31f9de 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -998,6 +998,18 @@ static int kvmppc_handle_fac(struct kvm_vcpu *vcpu, ulong fac) break; } +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + /* Since we disabled MSR_TM at privilege state, the mfspr instruction + * for TM spr can trigger TM fac unavailable. In this case, the + * emulation is handled by kvmppc_emulate_fac(), which invokes + * kvmppc_emulate_mfspr() finally. But note the mfspr can include + * RT for NV registers. So it need to restore those NV reg to reflect + * the update. + */ + if ((fac == FSCR_TM_LG) && !(kvmppc_get_msr(vcpu) & MSR_PR)) + return RESUME_GUEST_NV; +#endif + return RESUME_GUEST; } @@ -1359,8 +1371,7 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, } #ifdef CONFIG_PPC_BOOK3S_64 case BOOK3S_INTERRUPT_FAC_UNAVAIL: - kvmppc_handle_fac(vcpu, vcpu->arch.shadow_fscr >> 56); - r = RESUME_GUEST; + r = kvmppc_handle_fac(vcpu, vcpu->arch.shadow_fscr >> 56); break; #endif case BOOK3S_INTERRUPT_MACHINE_CHECK: