From patchwork Thu Jan 11 02:53:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 858746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="amwmJveI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zH9Sg332Gz9t34 for ; Thu, 11 Jan 2018 13:54:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753107AbeAKCyK (ORCPT ); Wed, 10 Jan 2018 21:54:10 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:46682 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753040AbeAKCyJ (ORCPT ); Wed, 10 Jan 2018 21:54:09 -0500 Received: by mail-pf0-f193.google.com with SMTP id y5so123645pff.13 for ; Wed, 10 Jan 2018 18:54:09 -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; bh=oFVM55TUTtW2z1kQmvNJc1rxKxOw8QGmCO+dwANjQ30=; b=amwmJveIiPWkQVfNv4+zHOjBsUHqBtj+4dwBOst7/vZ8qNHZwyYUS6lmsrTnVvZ60B sMLY6M9oeuHkVwRCDfWlPKGhq0cKZnw+pIsLUvFBrrMB6PI4dKXGBosMkzj3KZhdC0og nfNC1g1W9AlJuuF6i4H6uoheDyoSXd02zzspPJAh3OBvs58KNdwHsg3yFNjLDYRJpzWe DyMU59pYSU0uaV8XhhG3oYMonEssNrp5mJFWO41+xbhexVNiowx0ZF3XCQk/+oe58THH Dt6Kg6B6M3WuotivEfMxIk77hj7dvFyeibLzmAtkzQc6HxRw7kyfQiWuExA1i+JwhMct m6ow== 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; bh=oFVM55TUTtW2z1kQmvNJc1rxKxOw8QGmCO+dwANjQ30=; b=eqErG+rcbCkMoW3rZwEs0H+0SUXahQmuYrsk5hP5xfYoTF1TxSO5Yosv5H/9NrOA83 m+tWVnYE2gDQdcW3f6ve5yklrd47GwPP5YY+nWSAAqL9nW2mx6/jJGORR2i5ycjqGsx1 hY4AfFpsJESwXxL65LB5tfdiJZOuCTs5OwIDYKnBofxWJeGkwgrULIHlD2INP0u14SAl yQYPpt5KLkkRsZtV0mg/KXXM167X05O0bM5tPFxDXHxcJnJz92AWR3FNecS6/6R8kRV/ 8C/zABX6zzOt2Zp5y6Utrl/2lwjFAFOx0gDjnnOoqpO0lNxZ4o3YYt3sztN1aDpTDdnC nuow== X-Gm-Message-State: AKGB3mKoemmE9MVILuaOArg3Y2sTcxcAyoBeM7kXefb4TxUHj9G2kdX4 P703hVcBpOut7dp50g2G+NNViDyH X-Google-Smtp-Source: ACJfBovzHrAxdWlMvRz9JhI1O0S0K0RyQZ3EDYkJebFoNwqj2SD3GKAG4Ide2XpuuTIMwaGIaMZsuQ== X-Received: by 10.159.255.6 with SMTP id bi6mr21541697plb.144.1515639248703; Wed, 10 Jan 2018 18:54:08 -0800 (PST) Received: from surajjs1.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id a15sm21001308pfi.55.2018.01.10.18.54.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 18:54:08 -0800 (PST) From: Suraj Jitindar Singh To: kvm-ppc@vger.kernel.org Cc: paulus@ozlabs.org, sjitindarsingh@gmail.com Subject: [PATCH] KVM: PPC: Book3S HV: Skip treclaim if non-transactional in kvmppc_save_tm Date: Thu, 11 Jan 2018 13:53:47 +1100 Message-Id: <20180111025347.1460-1-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org Before entering a guest in fake suspend mode, we perform the setup in such a way that the hrfid instruction will put the processor in the (fake) suspend state. Then on guest exit a treclaim is used to return the processor to the non-transactional state. However if we branch to the exit path before transitioning to guest state (such as hdec_soon) then we come into kvmppc_save_tm in non-transactional state already. The treclaim then causes a tm bad-thing type program exception. To avoid this, when in fake suspend check that the processor is not already in non-transactional state before performing the treclaim, and skip it if that is the case. We perform the treclaim irrespective if not in fake suspend as getting here in non-transactional state would be a bug. Signed-off-by: Suraj Jitindar Singh --- Patch applies on top of series: KVM: PPC: Book3S HV: Transactional memory bug workarounds for POWER9 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 48 +++++++++++++++------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S index adf2da6b2211..e600ef505d20 100644 --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S @@ -3010,15 +3010,34 @@ kvmppc_save_tm: rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 beq 1f /* TM not active in guest. */ - std r1, HSTATE_HOST_R1(r13) - li r3, TM_CAUSE_KVM_RESCHED - BEGIN_FTR_SECTION /* Emulation of the treclaim instruction needs TEXASR before treclaim */ mfspr r6, SPRN_TEXASR std r6, VCPU_ORIG_TEXASR(r9) + /* If doing TM emulation on POWER9 DD2.2, check for fake suspend mode */ + lbz r0, HSTATE_FAKE_SUSPEND(r13) + cmpwi r0, 0 + beq 3f + /* Check if transactional or suspended, skip the treclaim if not */ + rldicl. r8, r8, 64 - MSR_TS_S_LG, 62 + beq 2f + /* Gets us to N trans-state. Fake suspend so registers unmodified */ + li r3, TM_CAUSE_KVM_RESCHED + TRECLAIM(R3) +2: li r0, 0 + stb r0, HSTATE_FAKE_SUSPEND(r13) + mfspr r3, SPRN_PSSCR + /* PSSCR_FAKE_SUSPEND is a write-only bit, but clear it anyway */ + li r0, PSSCR_FAKE_SUSPEND + andc r3, r3, r0 + mtspr SPRN_PSSCR, r3 + b 1f +3: END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_EMUL) + std r1, HSTATE_HOST_R1(r13) + li r3, TM_CAUSE_KVM_RESCHED + /* Clear the MSR RI since r1, r13 are all going to be foobar. */ li r5, 0 mtmsrd r5, 1 @@ -3031,29 +3050,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_EMUL) GET_PACA(r13) std r9, PACATMSCRATCH(r13) - /* If doing TM emulation on POWER9 DD2.2, check for fake suspend mode */ -BEGIN_FTR_SECTION - lbz r9, HSTATE_FAKE_SUSPEND(r13) - cmpwi r9, 0 - beq 2f - /* - * We were in fake suspend, so the treclaim above didn't - * change any registers, therefore we can now use any volatile GPR. - */ - li r5, MSR_RI - mtmsrd r5, 1 - li r0, 0 - stb r0, HSTATE_FAKE_SUSPEND(r13) - mfspr r3, SPRN_PSSCR - /* PSSCR_FAKE_SUSPEND is a write-only bit, but clear it anyway */ - li r0, PSSCR_FAKE_SUSPEND - andc r3, r3, r0 - mtspr SPRN_PSSCR, r3 - ld r9, HSTATE_KVM_VCPU(r13) - b 1f -2: -END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_EMUL) - ld r9, HSTATE_KVM_VCPU(r13) /* Get a few more GPRs free. */