From patchwork Wed May 23 07:02:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guo X-Patchwork-Id: 918872 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rQv21qQHz9s15 for ; Wed, 23 May 2018 18:40:14 +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="bIHBH2DA"; 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 40rQv20GVKzF0lh for ; Wed, 23 May 2018 18:40:14 +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="bIHBH2DA"; 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::241; helo=mail-pl0-x241.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="bIHBH2DA"; dkim-atps=neutral Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (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 40rPkv0XXRzDrnr for ; Wed, 23 May 2018 17:48:07 +1000 (AEST) Received: by mail-pl0-x241.google.com with SMTP id w19-v6so12509062plq.4 for ; Wed, 23 May 2018 00:48:06 -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=bIHBH2DAjRdSPkqY7T8dZirNhwxsjIknUlmsgrZlpErM+tYkSGt0Tu7CLgtGj3tREN YBmxIAcimmgPnLQjQwkD0RX82ZzRK8oreuigV1J1Dl+1RHKWhI3NoyevJTufH40IdzyW l5ptG1hbpqit/kJghc8ciVYBXNEBmB929kEMqlFcqmlXxZu4Isz3p8+4quLISkndIJgX MWmP8iGOARz2Hlg6yS/jqp0aQwVz666xiLRUMsJ2ohf4eNI9nvfmllaqy03A1YBLHf7+ aMU6fDoJ0rtXLETgaFX1IBdFyWN0Nc88DwA+Tl454FU5lc5K1GXHGCFWfAwZdhDmg6G8 Z0ag== 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=Xw+KKyO1jM0BOIRviBN0HrvLuNTUXpkabvU4A43SReJdwEpb2465g+MlAwf/+FN/lj CXS7lX4XKE/15hWTS9Wl9w7qHhuuMKbo50qWfAgmcxzrD2U02ORBJ6/CZckIfKJ+uDlo oaDWvn9iIXGSz/b0c8yWiliYL62+Ja83riBoSur1+M8s8hiWjdQ3DFpOkDLN0B3mFN+D l7xamJyVx4XoV5XZ6ZDKGyp5VLu12E1Z0c8T9mUboUfq3zNHH1nJelPN8grrH5HS7lqM PzVVD/Tr46i/a4e0GQsdqI55yjfHbjDqC5rtLQmzwKSIA1fyPH9wTgMAJHVTgaXSkAv4 nVQg== X-Gm-Message-State: ALKqPwe/pqC0Kp1Y9EXiu4VhLY7oFrrR7sMFMOpZFkW3wHmMgtHqcAR+ eSeISQqDziIaZeY7KcKkJFC0VA== X-Google-Smtp-Source: AB8JxZq5WhAWkKjSrtQ1FLe439//wCrluPxff3/4ry77M7CFfaILwDIOCqZUQqnT9dWw4wsiOF2k0A== X-Received: by 2002:a17:902:5952:: with SMTP id e18-v6mr1863402plj.351.1527061685193; Wed, 23 May 2018 00:48:05 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 00:48:04 -0700 (PDT) From: wei.guo.simon@gmail.com To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 19/29] KVM: PPC: Book3S PR: enable NV reg restore for reading TM SPR at guest privilege state Date: Wed, 23 May 2018 15:02:02 +0800 Message-Id: <1527058932-7434-20-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> 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: