From patchwork Mon May 21 04:09:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guo X-Patchwork-Id: 917389 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40q6wT62tfz9s2k for ; Mon, 21 May 2018 15:36:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eWRF5Ded"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40q6wT4Lz1zF153 for ; Mon, 21 May 2018 15:36:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eWRF5Ded"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c01::243; helo=mail-pl0-x243.google.com; envelope-from=wei.guo.simon@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eWRF5Ded"; dkim-atps=neutral Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40q5nz0kcgzF0cy for ; Mon, 21 May 2018 14:46:15 +1000 (AEST) Received: by mail-pl0-x243.google.com with SMTP id c41-v6so8035763plj.10 for ; Sun, 20 May 2018 21:46:15 -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=yfMmCVJ4THRB1vQYubP2tfD3Q3cJXG6RVJiHEJBC+J4=; b=eWRF5DedGnz1JEdUHymxm9gNTRPyMEwdOoRix+425lJIxDSYDzL67AqwArLAnEG9lq m1oOhfN+Jfb73YiyeSReWD9ct06DNPaUeffgbmOiBGEIkqb5Fa6lv0VxuslDviwXOU14 bDaSTe9oVLXoXcb5oDpOn1FHneh9oOMC/qWqRRV2Nfgyf7IivmGrJNI6+IfW7ZLfyV3S ykiBml4bSKur4GJ6q9D14+5ga0WGB2upUQl2SioJbOxSmtpfAw2sS1bBMjsL1mWyre4x +XvfQjWWZNYdXBwV5Apx+nvZLFEvR5EeATzuDEGcnxPGi2ApquilPav2wjjK/7ZInrzC edhw== 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=yfMmCVJ4THRB1vQYubP2tfD3Q3cJXG6RVJiHEJBC+J4=; b=M626PuhZYy/ByRc8W2u6f1P1KFjtQCSvrgQd0w/ZAFHXBRMgn+2iKESPIjMp48B4CN XNmq6GqiwnIZkEs83wnnaSuzJM41ZEBxaj/P1rwxm9eNliJpOlmxwD2sE/rJmyug8Sen CI4EN5K8A7/vzTau6QSO4W5xGire3z9z/F99gzz8oZBNLk5/iklE+mGi++XfB1FgtYyj fV1/1Oh6kWpwsGBP/MLhphhCaUf4i7dTftr540IES6cJ/3sMi+9y81TGa3ytRyC7GrD9 Bmw/smmK4Fn/VdrUH0X2hE4YUZArhHNFmta7m3vt45suP+Y8y85DkmgqjPgczz3k5Klx 1nRA== X-Gm-Message-State: ALKqPwdQrY+mfxcKBTgSLgKpuBCt1gLl/0a0wWzq0a7lh9wT33NQI+Xr NRmht0VHOEcbRdLq6Fs6uyhDfA== X-Google-Smtp-Source: AB8JxZq+9RwiNUOmVSk3ipq2p1ktfC1OjNPQPX/3GdBBVX5An1gnMnQRWKvN4gCGhRWTKw376mH+Vg== X-Received: by 2002:a17:902:903:: with SMTP id 3-v6mr19100706plm.377.1526877973198; Sun, 20 May 2018 21:46:13 -0700 (PDT) Received: from simonLocalRHEL7.cn.ibm.com ([112.73.0.89]) by smtp.gmail.com with ESMTPSA id t14-v6sm24575514pfa.31.2018.05.20.21.46.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 21:46:12 -0700 (PDT) From: wei.guo.simon@gmail.com To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3 19/29] KVM: PPC: Book3S PR: enable NV reg restore for reading TM SPR at guest privilege state Date: Mon, 21 May 2018 12:09:36 +0800 Message-Id: <1526875786-10372-20-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526875786-10372-1-git-send-email-wei.guo.simon@gmail.com> References: <1526875786-10372-1-git-send-email-wei.guo.simon@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Guo , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 9becca1..9a72460 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -989,6 +989,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; } @@ -1350,8 +1362,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: