Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4623979pxj; Wed, 12 May 2021 09:28:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSgnsVfMDgW4KVYG5SsKRCP+HHXSoAll23T35BaCE8AoHeG0RucTv96d5vJyBUx3MklBSL X-Received: by 2002:a17:907:ea0:: with SMTP id ho32mr13205108ejc.396.1620836908301; Wed, 12 May 2021 09:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836908; cv=none; d=google.com; s=arc-20160816; b=w2yG7TMsxzlC9ZrB5sbLlK5CeFIR0GXeFp6bazlwqOuIWsrgvFr9StkP+VDgYydgSh KxtxJFu31wRpHC0TrSq5IVJP/vqG5o80MBJFEAbn+Rn4H71xYXQe9een5y7M2x3Pc9dm wAuyi8woaxierZbX1NWIJ+XcPl4axHayjglaxBQ8ZrLldqIY6NGf+t2E/vfkDkKYXbA0 Zz2GEjaqtizP9cZ+Xo7iwTHhCCFUyQ0xSikYFUOTM6CSWKcCReX7Kto+swa/w2+HZsnE R79t6znj1pP29h2FcDEuW0LNksX51u3QsTnIxqa8uDD+kghtZ+aVTaUxAe3/rmU4IWKi Ql4A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fp3UZSi1VTreJkSUqSWncc2tg4H0g9ANRhL4Nswo2q8=; b=xHogCUMlSp+8xQb+5RSv+jMw9/Monejv0KcPI/Kl2mkb2B88H1VOtUAeVqyAYsTAtn fYDqShoyf49WnB6w7M2IKoWaoum2H1rp5dPiSEjXuWJIK9dxZru1oe6iEdLeXREo5N0i ofncoJdso4p+w7C5awEm+HKt28YetCrWptkR0uaXgPLk21BoXc5YwtWpySG20vAyC1Ob zROExJlELLl5EIna65xP5tbBjkGAQsvnJyEJ05EBCqbc7sTyF2qgMdfPbZnPvEydezl2 iGu1RGZON4g3Q1mcRkx5W4mDoBaqxSsJ+/Qskfb9XXC13AMLdAqo5c/LeTw5Bu2okmbg pc/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FVdAs9qW; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i26si97259edr.106.2021.05.12.09.28.04; Wed, 12 May 2021 09:28:28 -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=@linuxfoundation.org header.s=korg header.b=FVdAs9qW; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241005AbhELQ0N (ORCPT + 99 others); Wed, 12 May 2021 12:26:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:57086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236402AbhELPhw (ORCPT ); Wed, 12 May 2021 11:37:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E40E61996; Wed, 12 May 2021 15:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832776; bh=Wie/7pys/9J5iebK+whbE4Qn73jktWCzEvtCi61917Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FVdAs9qWrUyv1hFYwW785I42ZbBwROR25Spd9SMO5u32qEa8HT4z053/ZYDlQXCD1 KCeuY1qYg1rrbFG8N6KCwbijPtTHLLiGwyCCCWyTU+3RPTR7bYkZNnyAla3jBIbf3C Ff5zC3J11zjzxctS79CMPLOBxOj8tKdqaOoc3JSc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Piggin , Michael Ellerman , Sasha Levin Subject: [PATCH 5.10 419/530] KVM: PPC: Book3S HV P9: Restore host CTRL SPR after guest exit Date: Wed, 12 May 2021 16:48:49 +0200 Message-Id: <20210512144833.544630218@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit 5088eb4092df12d701af8e0e92860b7186365279 ] The host CTRL (runlatch) value is not restored after guest exit. The host CTRL should always be 1 except in CPU idle code, so this can result in the host running with runlatch clear, and potentially switching to a different vCPU which then runs with runlatch clear as well. This has little effect on P9 machines, CTRL is only responsible for some PMU counter logic in the host and so other than corner cases of software relying on that, or explicitly reading the runlatch value (Linux does not appear to be affected but it's possible non-Linux guests could be), there should be no execution correctness problem, though it could be used as a covert channel between guests. There may be microcontrollers, firmware or monitoring tools that sample the runlatch value out-of-band, however since the register is writable by guests, these values would (should) not be relied upon for correct operation of the host, so suboptimal performance or incorrect reporting should be the worst problem. Fixes: 95a6432ce9038 ("KVM: PPC: Book3S HV: Streamlined guest entry/exit path on P9 for radix guests") Signed-off-by: Nicholas Piggin Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210412014845.1517916-2-npiggin@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_hv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index e3b1839fc251..280f7992ae99 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3697,7 +3697,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, vcpu->arch.dec_expires = dec + tb; vcpu->cpu = -1; vcpu->arch.thread_cpu = -1; + /* Save guest CTRL register, set runlatch to 1 */ vcpu->arch.ctrl = mfspr(SPRN_CTRLF); + if (!(vcpu->arch.ctrl & 1)) + mtspr(SPRN_CTRLT, vcpu->arch.ctrl | 1); vcpu->arch.iamr = mfspr(SPRN_IAMR); vcpu->arch.pspb = mfspr(SPRN_PSPB); -- 2.30.2