Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3345006pxv; Sun, 4 Jul 2021 16:08:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxc5mnJ/N+/bZu190SUym2TfRJbi+ZavDQmePOKFnMSW8rP1jEEtDi1WQYnDwY7bzqU4fyb X-Received: by 2002:a92:2a0a:: with SMTP id r10mr8441892ile.274.1625440097145; Sun, 04 Jul 2021 16:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440097; cv=none; d=google.com; s=arc-20160816; b=irULoYG2++rHqOXySy8c6NU8ymQF4Zw8fjETDx+4uzVeP/f3HUa0Jkaad+WxISX7Ui 2fe1Yga9FgF++s5b29cW/eNI3iFftNyMp7FFaYgUKq3MisioWftq2Plfl4SPQM94GW3z AnWDDUee/nAGoqlBHj69y6/0fV6ybCF+WEoCmTXuXOJyClDvbQrhWt+Ed8M2WC8T9Mwg smjoeZ4ZydleATc0zRGqczcd2dLBhA+JZ3AZcgIbDd4c2xravi23gU3AT4UHycYlsKuw xhcGjbCZfcch3XVRVqzDllZXumYohFrPjXOqS7xYazNlncydZeXc+8h6viQtMbgDc4ao 5BXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=17SSexbUhKVFsDWp8oibs6WE9ZZhhlAkVyjWNIs9jmU=; b=q1/Z+244/of5WmAQ44Rpry1k/TwwlyaYrLsFgHQEsw6oziudgfT3EURcmYP36KROuD mJx3lfCism4OtnnFLNAN6ZD5dWqZhgAOWt5+3RV25oeWjOAuB/IKyal+P+iHGhEDGXxN 8XPeMhutspCoV77O9p+Ao0GBkiNQ5d1NVhSrddhmL/xiCHhHDTmaZT1z24wi5DM1i+k1 ce9qOC4+xZy4jRT9SUzaESZvGrl1kEAOCasDyQZg74SqqaQONUgYmR5q6l6FxNI7nHls BT9Ta+qUbZDH0Uj1743KhH8590UBFKlsbomL6rAstjsA5egPN1Faojz9ZFhwFwDumSWG LQ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cl1I3TZ+; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t7si8904029jam.62.2021.07.04.16.08.04; Sun, 04 Jul 2021 16:08:17 -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=@kernel.org header.s=k20201202 header.b=cl1I3TZ+; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbhGDXJk (ORCPT + 99 others); Sun, 4 Jul 2021 19:09:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:47610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbhGDXIa (ORCPT ); Sun, 4 Jul 2021 19:08:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9312C613E5; Sun, 4 Jul 2021 23:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439953; bh=k4A9U8XSbpXM50WX2bk9eqfV52wvOpVIiCKt8c8gujg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cl1I3TZ+YCF35Hj97tff50OR/Mk/k0GPy7geJPMbSRSbDkhSz27sXrsjKV+KIHIjn XWf1455SC5Wy16O395mmQfArVKQ6y3kd5WIrhPgCHa1+zml2pMtIVvhXpQoKrKSpYK J4MZgZBLBjWaOlTvOhf/XliSYkmtjgpH7jRoHNz7FAWaDzl8N+ekkhi7LAy2ypArtT 0wIcQG3qvs9Hsbj8Q7UVBLH4z9QBgVQE2r4gnr0XvHbo+XNE7LdKO+82bGKOcvZv8Q Nh8osPu9xEWL/9IBf3lbcFCSryeMBxYgL8GQ15DnTAuwhTZmCok/JMrk5KBkCVAPbF 84xu36m3Nejfw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marc Zyngier , Jinank Jain , Sasha Levin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH AUTOSEL 5.13 68/85] KVM: arm64: Restore PMU configuration on first run Date: Sun, 4 Jul 2021 19:04:03 -0400 Message-Id: <20210704230420.1488358-68-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit d0c94c49792cf780cbfefe29f81bb8c3b73bc76b ] Restoring a guest with an active virtual PMU results in no perf counters being instanciated on the host side. Not quite what you'd expect from a restore. In order to fix this, force a writeback of PMCR_EL0 on the first run of a vcpu (using a new request so that it happens once the vcpu has been loaded). This will in turn create all the host-side counters that were missing. Reported-by: Jinank Jain Tested-by: Jinank Jain Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/87wnrbylxv.wl-maz@kernel.org Link: https://lore.kernel.org/r/b53dfcf9bbc4db7f96154b1cd5188d72b9766358.camel@amazon.de Signed-off-by: Sasha Levin --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 4 ++++ arch/arm64/kvm/pmu-emul.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 7cd7d5c8c4bc..6336b4309114 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -46,6 +46,7 @@ #define KVM_REQ_VCPU_RESET KVM_ARCH_REQ(2) #define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3) #define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4) +#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5) #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e720148232a0..facf4d41d32a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -689,6 +689,10 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) vgic_v4_load(vcpu); preempt_enable(); } + + if (kvm_check_request(KVM_REQ_RELOAD_PMU, vcpu)) + kvm_pmu_handle_pmcr(vcpu, + __vcpu_sys_reg(vcpu, PMCR_EL0)); } } diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index fd167d4f4215..a0bbb7111f57 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -850,6 +850,9 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu) return -EINVAL; } + /* One-off reload of the PMU on first run */ + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu); + return 0; } -- 2.30.2