Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1690280pxb; Thu, 16 Sep 2021 13:04:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTX9ajNdDjfGoJoUSk8ujLIWIX3PBz3UzoV158YyvH3ti0EDNNXAnl/J8pl6cOkmBF5Gv8 X-Received: by 2002:a5d:914b:: with SMTP id y11mr5849398ioq.6.1631822676633; Thu, 16 Sep 2021 13:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631822676; cv=none; d=google.com; s=arc-20160816; b=kZm44a/yPvoO+z/1mTsihH/PM0XrwhC8h6MUaHDGJr1f1HMWwI/x1moO/brxls/JhP GidI1Atv4gEudEixPwIoRKZkJzPu8bMYl8z8AOAvga/sEQUjehSzvCf2bJzX/iLA30fL llmmBaad3BMntL25aIM+MiXOEAJT8d+a9BAJ5ytiOBzWktCFGz9BFgdztfcEykX31Wwh zFdk9zZeClbqIsoMUDe4R3+1xssd54SR0OtqY8bfjljhLDSTdhxfLsGvLQ2dD4AN5XkD pL007KzuJO0q/SYGexV9l6kmSdZbTbuE8sC/oaXhaPHyy+LxfNawpo3HBpfZoXvy18Os qFmw== 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=R+e2OkGVY4PaAmQrj43KwTaif4tzKIiDVP63iv9VKeI=; b=TJkheHhpsK3SdKmI8NNkKtZD/myayFjZRutNGQ9jSmctS8LMSnXFuTmDB29TQQnHXz nFr51tUix3BRIhXzkjSk+d2FodkcLR8ieSQd6AlgvXBzYOZydhR7j+KgSkj5l5EoVatN 9sljEK3GOqBCuTf3ZKwZNuboC0Ip9gwgINV1DjU3i0QPF9vcS8OPv5a23tVQx9MaUIGo E+nCE2MP8d8U54YKTv4AteVjAB/fFR/PLW7q/L19bUKX7O0dFLSfQAJoiB+adFSCh+pM 0c8fXJCX//syOEKqX9njlI5qbhC/ZCD9XSPkiu3sVTuL5GHBC+V7me25fpq8+kW9VVDk raFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fnn+reKE; 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 s10si3733744ilh.107.2021.09.16.13.04.23; Thu, 16 Sep 2021 13:04:36 -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=Fnn+reKE; 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 S241002AbhIPQOy (ORCPT + 99 others); Thu, 16 Sep 2021 12:14:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:49186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232733AbhIPQIv (ORCPT ); Thu, 16 Sep 2021 12:08:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6591261353; Thu, 16 Sep 2021 16:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808448; bh=TeAuxooOAOSh2SUXL2OIs26O6+aLaUgYa4AgI1Lfyl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fnn+reKEKybp34s8CNEPPsSAcw4EW9GN+Ce51kLRKYaZdJA7XiuXyiQpVSjPlZdnj wLSSMCpjmF0M3i/VPQ0ayj/yO0gYSymAZF5We08us0fdxRWZG9B1hPiU5wpw+CNuLt 7BTL8aUCvoEJmAk0ET9l2fv4RZ2MOZ66J5zN/rFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Piggin , Michael Ellerman , Fabiano Rosas , Sasha Levin Subject: [PATCH 5.10 094/306] KVM: PPC: Book3S HV Nested: Reflect guest PMU in-use to L0 when guest SPRs are live Date: Thu, 16 Sep 2021 17:57:19 +0200 Message-Id: <20210916155757.269990540@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 1782663897945a5cf28e564ba5eed730098e9aa4 ] After the L1 saves its PMU SPRs but before loading the L2's PMU SPRs, switch the pmcregs_in_use field in the L1 lppaca to the value advertised by the L2 in its VPA. On the way out of the L2, set it back after saving the L2 PMU registers (if they were in-use). This transfers the PMU liveness indication between the L1 and L2 at the points where the registers are not live. This fixes the nested HV bug for which a workaround was added to the L0 HV by commit 63279eeb7f93a ("KVM: PPC: Book3S HV: Always save guest pmu for guest capable of nesting"), which explains the problem in detail. That workaround is no longer required for guests that include this bug fix. Fixes: 360cae313702 ("KVM: PPC: Book3S HV: Nested guest entry via hypercall") Signed-off-by: Nicholas Piggin Signed-off-by: Michael Ellerman Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/r/20210811160134.904987-10-npiggin@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/pmc.h | 7 +++++++ arch/powerpc/kvm/book3s_hv.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/powerpc/include/asm/pmc.h b/arch/powerpc/include/asm/pmc.h index c6bbe9778d3c..3c09109e708e 100644 --- a/arch/powerpc/include/asm/pmc.h +++ b/arch/powerpc/include/asm/pmc.h @@ -34,6 +34,13 @@ static inline void ppc_set_pmu_inuse(int inuse) #endif } +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +static inline int ppc_get_pmu_inuse(void) +{ + return get_paca()->pmcregs_in_use; +} +#endif + extern void power4_enable_pmcs(void); #else /* CONFIG_PPC64 */ diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index bd7350a608d4..175967a195c4 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -3619,6 +3620,18 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, cpu_has_feature(CPU_FTR_P9_TM_HV_ASSIST)) kvmppc_restore_tm_hv(vcpu, vcpu->arch.shregs.msr, true); +#ifdef CONFIG_PPC_PSERIES + if (kvmhv_on_pseries()) { + barrier(); + if (vcpu->arch.vpa.pinned_addr) { + struct lppaca *lp = vcpu->arch.vpa.pinned_addr; + get_lppaca()->pmcregs_in_use = lp->pmcregs_in_use; + } else { + get_lppaca()->pmcregs_in_use = 1; + } + barrier(); + } +#endif kvmhv_load_guest_pmu(vcpu); msr_check_and_set(MSR_FP | MSR_VEC | MSR_VSX); @@ -3756,6 +3769,13 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, save_pmu |= nesting_enabled(vcpu->kvm); kvmhv_save_guest_pmu(vcpu, save_pmu); +#ifdef CONFIG_PPC_PSERIES + if (kvmhv_on_pseries()) { + barrier(); + get_lppaca()->pmcregs_in_use = ppc_get_pmu_inuse(); + barrier(); + } +#endif vc->entry_exit_map = 0x101; vc->in_guest = 0; -- 2.30.2