Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1013341pxb; Thu, 9 Sep 2021 18:00:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcLIhkfkhT/lIsAd+2jokIbwBaz6dHHk/lgKl3Qk9nDzlsI3JPH3iS8HM0so9Evjwq2Yep X-Received: by 2002:a6b:5911:: with SMTP id n17mr4959709iob.180.1631235641557; Thu, 09 Sep 2021 18:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631235641; cv=none; d=google.com; s=arc-20160816; b=wnkgXRRPtFzKnz70ZmEEL0/tvmscx1HbPs+dUjHzKCZQX9mHiIPSaropEhnTqa8Gi4 atlMaHiZ3VHs0qZ3GzuFEG+21F2RvXej8ufx4lzIVEmP5SXIjLhqN+m/k7s6UDyLGbyo 05uAvXzMb/g3xq//HwdqbVy7dqtO2lZ7Gz8laDpVkLhHF4r1lRwNtzrLV35OmK/t81XZ /Js6R+Puc92yf5worTlo9KGekia+ko+CQLKTSe1IttELUbnmZn69a/A+89qQLBdab7MB 8T2lOnoWrNNooBRFkGkPvzDFGjUCAbABGz9zgXaecxJ8XjPtJtSJH4hWODYC+6XWu3bd ELYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1QCyXSPVNTgxUWqFZiQddFkS7840ZE4SP9G32MojaoA=; b=EtnnplCKwI4qqt53YgQIZpa+VLVSN/BJcdXULjvhhswurmcBhjxXRx1OTbq53VCg/U JgXTHZarHqk7gTnTmJP5IPi3M+LBDXbK2pY+zsDAsbjbyB1eRCqkk8wmKbHdzJ08HUVu c3bnBUOGc0LbO549AjQuJgsnAO04HekXUNKSBQFbUf6ddtDa2YzmGLyHap9b9PBZpzen cCiiDwuKDONlbmA2YXUyvluY3EnPcC9M2QpqRGPWYR4fpLa2eyTMQ/JqfwYebosBKEmq A23vpoRjSJd3y8ItezOqeDkadjHGDwS3PYerx4VV/N7N0AsQ0v9oJOZnCwIw8p9lGXc7 W58A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YjjoatPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si3922307jaj.63.2021.09.09.18.00.29; Thu, 09 Sep 2021 18:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YjjoatPc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233435AbhIJBAm (ORCPT + 99 others); Thu, 9 Sep 2021 21:00:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:48926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232441AbhIJAX3 (ORCPT ); Thu, 9 Sep 2021 20:23:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 802BB60FDA; Fri, 10 Sep 2021 00:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631233339; bh=ZCjjhDPW4hbvxCl8WPvpItKvzm7Kyi1xKV2fbxD9wyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YjjoatPctpfRuj9q2AAOG5xKKCi23oMR722Ibbz1ShnmnZKiSSdLYEQf10My5VXqr MP1oaoif4AV6ixKs2gxaI+qT3yy39Oehh2Fqpb7P1ODVzMKfA9b1HfhLdbFEmcRqg7 hxSUzsBkYLtMNXhEqBIaqpnU3mmtcLqUTLLYKtV+oL77YZjQ1uETPdW3v+NwnUnaSj 6/6v5exwqbEsFt1HIcaNde+RyTDobO5rrnIsnR2EBu7AWp4if3Br96rP6Si78A7RPe sMoQWwOzqvCOqNEgzS8SToeyLCAQelrDDKLrLYx/JNI21gbrntPOcNmzjiqSl9K6l0 Gbr735ChZnn2w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nicholas Piggin , Michael Ellerman , Sasha Levin , kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 5.4 27/37] KVM: PPC: Book3S HV P9: Fixes for TM softpatch interrupt NIP Date: Thu, 9 Sep 2021 20:21:32 -0400 Message-Id: <20210910002143.175731-27-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910002143.175731-1-sashal@kernel.org> References: <20210910002143.175731-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit 4782e0cd0d184d727ad3b0cfe20d1d44d9f98239 ] The softpatch interrupt sets HSRR0 to the faulting instruction +4, so it should subtract 4 for the faulting instruction address in the case it is a TM softpatch interrupt (the instruction was not executed) and it was not emulated. Signed-off-by: Nicholas Piggin Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210811160134.904987-4-npiggin@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_hv_tm.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_tm.c b/arch/powerpc/kvm/book3s_hv_tm.c index cc90b8b82329..e7c36f8bf205 100644 --- a/arch/powerpc/kvm/book3s_hv_tm.c +++ b/arch/powerpc/kvm/book3s_hv_tm.c @@ -46,6 +46,15 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) u64 newmsr, bescr; int ra, rs; + /* + * The TM softpatch interrupt sets NIP to the instruction following + * the faulting instruction, which is not executed. Rewind nip to the + * faulting instruction so it looks like a normal synchronous + * interrupt, then update nip in the places where the instruction is + * emulated. + */ + vcpu->arch.regs.nip -= 4; + /* * rfid, rfebb, and mtmsrd encode bit 31 = 0 since it's a reserved bit * in these instructions, so masking bit 31 out doesn't change these @@ -67,7 +76,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) (newmsr & MSR_TM))); newmsr = sanitize_msr(newmsr); vcpu->arch.shregs.msr = newmsr; - vcpu->arch.cfar = vcpu->arch.regs.nip - 4; + vcpu->arch.cfar = vcpu->arch.regs.nip; vcpu->arch.regs.nip = vcpu->arch.shregs.srr0; return RESUME_GUEST; @@ -100,7 +109,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) vcpu->arch.bescr = bescr; msr = (msr & ~MSR_TS_MASK) | MSR_TS_T; vcpu->arch.shregs.msr = msr; - vcpu->arch.cfar = vcpu->arch.regs.nip - 4; + vcpu->arch.cfar = vcpu->arch.regs.nip; vcpu->arch.regs.nip = vcpu->arch.ebbrr; return RESUME_GUEST; @@ -116,6 +125,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) newmsr = (newmsr & ~MSR_LE) | (msr & MSR_LE); newmsr = sanitize_msr(newmsr); vcpu->arch.shregs.msr = newmsr; + vcpu->arch.regs.nip += 4; return RESUME_GUEST; /* ignore bit 31, see comment above */ @@ -152,6 +162,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) msr = (msr & ~MSR_TS_MASK) | MSR_TS_S; } vcpu->arch.shregs.msr = msr; + vcpu->arch.regs.nip += 4; return RESUME_GUEST; /* ignore bit 31, see comment above */ @@ -189,6 +200,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) vcpu->arch.regs.ccr = (vcpu->arch.regs.ccr & 0x0fffffff) | (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 29); vcpu->arch.shregs.msr &= ~MSR_TS_MASK; + vcpu->arch.regs.nip += 4; return RESUME_GUEST; /* ignore bit 31, see comment above */ @@ -220,6 +232,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) vcpu->arch.regs.ccr = (vcpu->arch.regs.ccr & 0x0fffffff) | (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 29); vcpu->arch.shregs.msr = msr | MSR_TS_S; + vcpu->arch.regs.nip += 4; return RESUME_GUEST; } -- 2.30.2