Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3346532pxv; Sun, 4 Jul 2021 16:11:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWsOgoHvPTBIUkwJCxmXq3qgq6bv218BZ4YPiloBFqw+B6lQEtktH2go6FyJZ3zk6WSmdj X-Received: by 2002:a92:d209:: with SMTP id y9mr8305013ily.143.1625440276167; Sun, 04 Jul 2021 16:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440276; cv=none; d=google.com; s=arc-20160816; b=jU7/eXzfkM5fjX9dtNr11AvMxpvreafi4N2p4JXKsi2Q+Tofcy0VwJqC5aEtMr7qdF rqitBwd9SRa6AS/hXV6M8Rgy3Dearbyow4Dz0jgmGCnkDrX6LN9pcoxMW1yeV2D2YPmA SAYL3nHQVwVw4r138azdriZlFue7FuGRG8R/D7NyW+VT6OZFJJ/jA9FxofvpbU7s76Ov IVtC5ZTCBU74isLobAneFr4pSTVB0W5Gk5Sh69rBGwWH0UO9SfkyDdizpohNLQxQ154q eS4kCbNLsSz+mbAT5svMxIPtbYqDFrv+TL38oiK55p3NZGRnjLa6hVYH6YToSxeZ026k Li1g== 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=Y0WWi4vTA+xIMt5GwSlckkTL2VVbKDjNRYZy+rcYxZU=; b=sGdiRC1/wfTziLlRVg7PVNmTlFVHZ0zxRkG4EZRKFkv48WV49CGi1Thmobvm9+Ji+w 8L+FUj41oXKwyaaz+j3S+zHbhUR0niEyai3QJ8KzbsjbTqA6TnO4SstX1FY68CDCBzQM /XECZ/x6RDYHhGYvhV3R7UQ+sLIwZRN4nESU1gbkR3jGyY+k/JcPxI9+VmZ9nV0xZCam 07dl7NvYuisvgmOyS6YRinXE+f4cQ/faBuDpUPOcpaQ+70OiiXvIl1IiJgb+mgn35Yqo uiGPQuNSAxRBLnYh6f0Fnv445OoQJsd58IvpkZQWE/KHg2ITc8q9wdOdFvWAcY1zOG+z /uDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aQHnYPSi; 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 k7si11048703ili.32.2021.07.04.16.11.04; Sun, 04 Jul 2021 16:11:16 -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=aQHnYPSi; 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 S232035AbhGDXMJ (ORCPT + 99 others); Sun, 4 Jul 2021 19:12:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:49476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbhGDXKS (ORCPT ); Sun, 4 Jul 2021 19:10:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BA5561416; Sun, 4 Jul 2021 23:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440062; bh=n0UOv8XGqRxE8ABKttXEeMPtQWNfPtRpL6ZYJXVh0uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQHnYPSicyQc6W2yZkUGPX0VqnB/OuxQQKLmwH8neQmUYwY6+q5Ak/OxxPnsWN6Bg Lu2hbjpTz5D6smrXWtQu202NBQO6hdHmiuKVZ+lgdpfHCHPGMmgflSRpGFmCVSPKVk 4uAbmCG0pCYgOobeAXJT39Yg9v2aFxUygrkT8qyuoUOx6HhhMMR4U0u7xc8/xLZrpE 8lC7JFGv23WlDNc6FO5hd6vTanNQ6HrQzv2/Fino167jRHY9Eio6woH50PM+bT4N4o ZOFIN5R8Uo7dg/54tmKI+KgLC9QGWpYVeBAsiuc8MeFBuDgQHxm0+Ny+WMcbEN6rdJ nTr8R40+fnb7A== 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.12 64/80] KVM: arm64: Restore PMU configuration on first run Date: Sun, 4 Jul 2021 19:06:00 -0400 Message-Id: <20210704230616.1489200-64-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org> References: <20210704230616.1489200-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 858c2fcfc043..4e4356add46e 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 7730b81aad6d..8455c5c30116 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -684,6 +684,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 e32c6e139a09..e9699d10d2bd 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