From patchwork Mon Dec 6 17:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12694936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78230C433EF for ; Mon, 6 Dec 2021 17:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=qyKK8w09UxoQVxrGHgwZORfFg45Hb2PTRpppki41EEQ=; b=zBjnCE3xRVm77a c7xJQlxxJyP8TcAfzH1+zzro/XbL8Q08JjOrGjrxuI6P37JssRFEI66kaO7fJCpSthLNxRHFxPvt8 BBGvetyODiF7gY46IGnB7bUu9ehWkev7evsCdxZ7woV0f1cFHRKNk4FFrewgaOZ7BJL9cWrydWY5/ Qy+QDwpJAVCxHmxyd6JeJBB/5LgExeMF5HK2o0fVjo99ttFh5k9GX2c8zqL8VwWRIl5waYunW92aX Hvmee8/bazlphgU4Lh3hLeX3wBMY7i7xcHh/F65SdPsdqepY6i7a9EtqS3fgeNXx2MeSjEJRgJPKp SgxqM8H25yTycy+wh4oA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muHPw-004xaz-Tj; Mon, 06 Dec 2021 17:04:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muHNq-004wld-Ma for linux-arm-kernel@lists.infradead.org; Mon, 06 Dec 2021 17:02:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C5CB1042; Mon, 6 Dec 2021 09:02:33 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DAB9D3F73B; Mon, 6 Dec 2021 09:02:31 -0800 (PST) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: peter.maydell@linaro.org, tglx@linutronix.de, mingo@redhat.com Subject: [PATCH v2 0/4] KVM: arm64: Improve PMU support on heterogeneous systems Date: Mon, 6 Dec 2021 17:02:19 +0000 Message-Id: <20211206170223.309789-1-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_090234_820374_34FB8021 X-CRM114-Status: GOOD ( 17.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org (CC'ing Peter Maydell in case this might be of interest to qemu) The series can be found on a branch at [1], and the kvmtool support at [2]. The kvmtool patches are also on the mailing list [3] and haven't changed since v1. Detailed explanation of the issue and symptoms that the patches attempt to correct can be found in the cover letter for v1 [4]. A brief summary of the problem is that on heterogeneous systems KVM will always use the same PMU for creating the VCPU events for *all* VCPUs regardless of the physical CPU on which the VCPU is running, leading to events suddenly stopping and resuming in the guest as the VCPU thread gets migrated across different CPUs. This series proposes to fix this behaviour by allowing the user to specify which physical PMU is used when creating the VCPU events needed for guest PMU emulation. When the PMU is set, KVM will refuse to the VCPU on a physical which is not part of the supported CPUs for the specified PMU. The default behaviour stays the same - without userspace setting the PMU, events will stop counting if the VCPU is scheduled on the wrong CPU. Changes since v1: - Rebased on top of v5.16-rc4 - Implemented review comments: protect iterating through the list of PMUs with a mutex, documentation changes, initialize vcpu-arch.supported_cpus to cpu_possible_mask, changed vcpu->arch.cpu_not_supported to a VCPU flag, set exit reason to KVM_EXIT_FAIL_ENTRY and populate fail_entry when the VCPU is run on a CPU not in the PMU's supported cpumask. Many thanks for the review! [1] https://gitlab.arm.com/linux-arm/linux-ae/-/tree/pmu-big-little-fix-v2 [2] https://gitlab.arm.com/linux-arm/kvmtool-ae/-/tree/pmu-big-little-fix-v1 [3] https://www.spinics.net/lists/arm-kernel/msg933584.html [4] https://www.spinics.net/lists/arm-kernel/msg933579.html Alexandru Elisei (4): perf: Fix wrong name in comment for struct perf_cpu_context KVM: arm64: Keep a list of probed PMUs KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_SET_PMU attribute KVM: arm64: Refuse to run VCPU if the PMU doesn't match the physical CPU Documentation/virt/kvm/devices/vcpu.rst | 29 +++++++++++ arch/arm64/include/asm/kvm_host.h | 12 +++++ arch/arm64/include/uapi/asm/kvm.h | 4 ++ arch/arm64/kvm/arm.c | 19 ++++++++ arch/arm64/kvm/pmu-emul.c | 64 +++++++++++++++++++++++-- include/kvm/arm_pmu.h | 6 +++ include/linux/perf_event.h | 2 +- tools/arch/arm64/include/uapi/asm/kvm.h | 1 + 8 files changed, 132 insertions(+), 5 deletions(-)