Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4690488pxj; Wed, 12 May 2021 10:59:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbwXvtTaVHDPMP2RgZ1weQKJdiE828Fsh4jHmS1ZQYrTxZCBUiqsqsWLZ+ZuCwq4Em/LDh X-Received: by 2002:a17:906:4d50:: with SMTP id b16mr39009297ejv.53.1620842341714; Wed, 12 May 2021 10:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842341; cv=none; d=google.com; s=arc-20160816; b=XXm0C0sS6Yy1YpmZa0g/uI50R/XRELATRezeages/kxxQgTNCk+3ApOiREpP7PmJsO 64gwqAJPqERZtJheF7xXKBERfZmFPUREnKEiCd+nGOSl8So8mxfdbdsXMYqplNYd2zZz 4U8Bg7lAbhm9SEajO/9Pq2+WVHpj2lI3KUY0QbEDps+H5Ir9EsQ0BT0w+LIxyHvgvI49 UnioLYeHQ2SLtg4RIVcIVJyRqmub4ozRpQfUSIeEXNQnIzFfHfyKN3Om+ASatPZmCnoH aU0l6Z3UpNKH/W38aVDbaogWIXMUFzyV+S7Gf8W0FrQRj68jLvP0tttgNQxJ0mZBbhKJ m/sw== 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=bmX+FlkpANPUXPholaRkYzdDfZ4BmuL5qYdQA+VVadM=; b=hhMipJFeuS/2kYenl4TtXFmTAQRZ+KL2lBScYK+W8p1iU/phyvC920GpoU0Ab3gyLn Ap1FcPI8AxJRcGDEOpJ0DjTl2lfv6B6ov3CPHq/PHzKYtTnaSKC95WpiZg2eHo+LorTt IWWIuczdagtbw1/wZBHEN4Crdr1FhXvHonjBTL9UFVjKJJ8N+LaiC4Sc0vpWp5I0G1oH sp8sy4+HIj+hDsOEXTAEVtAkQZG2pqv9CqD3ln0U+2+grQmpHBumzuWdOJE/gwUTMe42 unvB8G3wHJtCbI9Vhn6ZNdd/m98tctAV4q6WgpE0m1pmfU5JcsNwtja2O2tUlW0DDOyE 4cug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CnuwtWkx; 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 i17si563879ejv.384.2021.05.12.10.58.37; Wed, 12 May 2021 10:59:01 -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=CnuwtWkx; 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 S1349804AbhELRqg (ORCPT + 99 others); Wed, 12 May 2021 13:46:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:53914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240588AbhELQSY (ORCPT ); Wed, 12 May 2021 12:18:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 37D1161454; Wed, 12 May 2021 15:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834276; bh=rttTnCwfjfmsnLPiV/CV+L0rzLaFEhlGgmiokshtVH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CnuwtWkxeJ4amdn24dPJWPmURj0AqPEA38uIeoVpn6Aa4seqeM2xbtQOHdSr4fnyT 60wcO0voqwlx8Y3clxbDawXTLeZB9dtCPw1gJI9PekTXeEl8rlNuNPbgLO9BubalKD jvfDSr1BIHFy9Ad6LFnx93i0rB74N0b5L+ji7hpo= 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.11 478/601] KVM: PPC: Book3S HV P9: Restore host CTRL SPR after guest exit Date: Wed, 12 May 2021 16:49:15 +0200 Message-Id: <20210512144843.585572573@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 6f612d240392..138556cb559d 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3709,7 +3709,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