Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4744077pxj; Wed, 12 May 2021 12:12:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMgszbH5US7Xq19YiqbBHCHZRzQ/3FujiDItE0ISzbfsuGAJJgIJ2hAQ7kPbDNtakYBwX7 X-Received: by 2002:a17:907:1b02:: with SMTP id mp2mr38829630ejc.196.1620846765740; Wed, 12 May 2021 12:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620846765; cv=none; d=google.com; s=arc-20160816; b=CI49T7qZBotXdYQ2hK7OZrPnad9DypCp16kNuo5LtNggrH5TQRqGTF3hlAB7QLJiZO ZigZ9kneCugwPJONvmN6RTSTDYB0i6TsqTS3laPE7B7Gf8nnSVTsToRXxws1Kjj4r+Ko Hd1QUYi4Liq3R1fldJyd7UcBa/glss/GX+g12+ABeleyyW28t076tgL3wTdSfjUzuk+s CevQewXxZf0ne+v+37mk8T86D7tL7pPvXo0ZMsRm6endHSveS5OiCq3lCbT9alGrnDff 0RbJPAno/kPc02Hq3esz2Jit4HdF8lIGMrso/anM9iObgCeoE5NtOMS1lJoGS/JXf5At nbpw== 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=N5+zk7J6N3oqAU4Ne8wgjGkpp0EbUMy85ztiiUdbh5A=; b=N+TdbuPKZMjqg+l9uLx4AvtPtRz9zK5zxPQdrvOiH31USSmz1NpC8ieR6ypS9LVal9 1p7coolh5ZUwhHCLS7pP2sCyWp3EZJJcW0BZx+y/2wQI1X+RN86MFOV8At0auUotllsj bWNflHngtDFvQdZdw8QW4ivTv90qF9LzpkCmTfDkXpUyFX9uIcH158Vqkf7ws08tNfz2 QmyahPScVnBYO+puc4PbAtkZzV7zd32sc/dnmjeBeUVueMS1dqi2idQrBT4snBaqG83f xEGCDYt6XOygWQy7rdmVMtb7MH8ulf7UzJ7y7niLBB6EpZE4S4F2E+p8RUfVwuV0vtmB i3Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bLH8ee7M; 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 r9si414638ejr.730.2021.05.12.12.12.21; Wed, 12 May 2021 12:12:45 -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=bLH8ee7M; 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 S244370AbhELTGK (ORCPT + 99 others); Wed, 12 May 2021 15:06:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:35834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244287AbhELQmv (ORCPT ); Wed, 12 May 2021 12:42:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 58DC461D42; Wed, 12 May 2021 16:12:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835937; bh=PWaRI9EWYhzIGjtpdkfvAHCGvfDcD6puNDKoN9z9ALc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bLH8ee7MuiqnutFrjX9AewsyyiPWoKUxb28C8dXOdk9ENpJTjBW0yFTjruGrupL3z RoDc5OJLn54NT78Ds42teYNaElOpik3XHZx0zC6jUD+kw2C5fUA33TFX9mDD2jFT9f ntfx4lDnLnxGZk8wqXTUvTTZ9KnjY6zojuMs0NvA= 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.12 544/677] KVM: PPC: Book3S HV P9: Restore host CTRL SPR after guest exit Date: Wed, 12 May 2021 16:49:50 +0200 Message-Id: <20210512144855.443743709@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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 13bad6bf4c95..208a053c9adf 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3728,7 +3728,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