Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1764058pxb; Thu, 16 Sep 2021 15:12:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykrFD6b3PCDGEVidaAduHr653tBu07+5/RtywZ6fufshNd/NOo/U5fS2by05P0yHm8n5zm X-Received: by 2002:a92:b109:: with SMTP id t9mr5435633ilh.176.1631830371933; Thu, 16 Sep 2021 15:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631830371; cv=none; d=google.com; s=arc-20160816; b=OXrlL62ykv1ZBbBRWLHCV0mEMo6e9OvM+Xzf0ldiWqjdSg9yTHLpQ6rvwbPV/1HIQ5 ewmn+4P4a/Fz53RsPlasknWiSUSTdTuDTKsETvyfXbeqc4N73UdI4TwU3a0aeY/BWkGV gD9uImlG3PDxQ339GZO9Rj2lv03Jwq4kXQ1AnJBKQWJ/BCJOc77Hy8BYS1sc31UGblSf M8Elu8rMmH4X77xSf4v4slsPnllmWb6TlqcRhnHbNs6qKhS/HFgv9ENwwxxa+y1+Yfkk zgJUjG8b7RLmY1ikC2BNxgker+tK0iHnYbCqudlk2Cn29Jb014k+dF6Z1VwVCP5LW7Wy hE6g== 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=CuOtYJAalqc3FIA+E557/IgIwy3i+6XVvGkrju+o3kk=; b=j9f7KlhuSqC/ESQWg0Xmf9k0hjgWJPbZFbIh0M8Ph4dasfKH+3bxIuJ1pT1dn6kyvL j8WAL1PxVy2Cemz2nlqoJVsk0Y9JDiUvxx28wTc6PA8N8RQUjWvOi1mMVz4O4IZHWjgb wgQ7h1DuR28NScjedVr1v0c1APuxKTgvdshRCnfcxlHpJKiDm4QpgDXPCOmVNmwy1NY7 5AgQrWBx12zCcULvF+MSD4UNirzL/KDishyZd2Ma4BDuT4/iUx804aRC8hfivsMII/va c1Feyzrmzrk/TeDK0uiR7XX/fjPYaTgpFJW3gZEi0CYlrN+C2z4UzQyh1fedMaNby0sB JppQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q7wgQzsq; 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 q35si3735906jac.78.2021.09.16.15.12.39; Thu, 16 Sep 2021 15:12:51 -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=q7wgQzsq; 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 S1343977AbhIPQoX (ORCPT + 99 others); Thu, 16 Sep 2021 12:44:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:51484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244165AbhIPQhT (ORCPT ); Thu, 16 Sep 2021 12:37:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E656E619E9; Thu, 16 Sep 2021 16:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809336; bh=aaHFX5AtXmX41TNJvCmzmG1Vf2/ebzzgyTftDK4TVfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q7wgQzsqFlFdpzzVykKac1W/JV6xBX/YuzlQn3LBTTUBxKUnkyG0YuuCdCIQRK2hY d9gXutn5W4AjjNAIBSZlORkkph4mKX2/63zMX1Ysu3fx7XuKE4hkhB+Qwx1cugR+hb 6Sq30ZWEuwyjsI1kGFx8cbf8dEOf/quDv/sG+Opw= 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.13 118/380] KVM: PPC: Book3S HV Nested: Reflect guest PMU in-use to L0 when guest SPRs are live Date: Thu, 16 Sep 2021 17:57:55 +0200 Message-Id: <20210916155808.047658073@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 395f98158e81..890fbf4baf15 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -3687,6 +3688,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); @@ -3823,6 +3836,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