From patchwork Sat May 27 04:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13257540 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 29776C77B73 for ; Sat, 27 May 2023 04:04:45 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date: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=FLLTP/cf6FSx+fiKHdLpZgCImnumB1anvIbISpix+jk=; b=To+ VDHDvBzpezzkLu27aR2WQzHsoz4nIdJv2kzTPlselbXYTFteVxXaqdFs7XeXpJrttrE9GzQnFHHbD t/ciFOzHEudrbJoSDw8MqgHyG02Bc7Qv9H1P4lixYe+KFCYTKi3pDuJg6mxkMuk3hlNqgjGbOPFK3 XqemfhXPW67y4S3MGqSyIdvJNAsPvxUK4i3/8wLGDoYsoeXaEj1EtcISjJwjsazK43DuzAXe9esXl +DbLxgsCzBiMogaMIDAH7dEb78BS9vdHp1Pelh6hcmZVcbgx9jhadJsBZMnJmT3QhXReNPGp/lHoW P/ny2EhCbWDTn2FEgkgXslSysmbLicA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2lA9-004nw3-1o; Sat, 27 May 2023 04:04:17 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2lA5-004nvF-2I for linux-arm-kernel@lists.infradead.org; Sat, 27 May 2023 04:04:15 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5655d99d636so35732467b3.2 for ; Fri, 26 May 2023 21:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685160252; x=1687752252; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=YRT9I4djHwGzJQpPn1+l49c/6modgMoOAial+YqLhwY=; b=BXGdvFYKQjWbwlSN17LTz40eGsJgSBo4fqWemkL5mGJCJXAyT0xeNbxV/TRJK+aXpQ JVUmwUYsff7pvtBBYyA3OrsQt9YZ8w83aFdUjpVTyZX3WO/aX4llgjGJHlXnvr8ClIL2 Ny8Y/+DpScYAzHZWAw9dUPaKeJPV7MEEVe8emdvbb+qixsoPE9Fyy/xpOie/Q8fhsPdx dlKzYxEGo6DXi0nXTI25DkMe6mjdS1i6xhy0m5XMgSLrCoW3W/k0nvkcp4qF3114VIEV zxzWvYHNpHyC6M17Pyrc76PONyLXZootxLrA36Y7cOwL9NCglA42yxpmOrr3zfOyKqZB ewXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685160252; x=1687752252; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YRT9I4djHwGzJQpPn1+l49c/6modgMoOAial+YqLhwY=; b=LdJjDSi2itfNMHtj0OI4z4dFAqOZES36zhLUjFg5CM+XVbUN34en27XWKw5Quj1/nV 51hW7VsrKJi5lU/NqAZpefuBHHYhRuBVo3PgZELDLEgQx5fJ24tRk3ItBXKnr/op6GdF +0z3ZVHafrjbyucrWsS5TWx9DsY5EbqWQYSWyi4+G7S33HfRIuEKCxO95kj1RreVkn1o xrVAJAa9ieXkE0K6lnnPXVK6gsjqiaI9VJz64bPrTjziersXqjd4v4Ho6kHJdNwRLeKP JC6QZsPkWzgCB9brGG+jaBnhv3z/1go5BTTAyUTam7hNQMXDldGgo/ojSEDkSyBG8kXv qvlQ== X-Gm-Message-State: AC+VfDxtPQau9pPxD0WNqTpTVnXgqys5ideHQdD8HjnUHh5kSp1zjMx7 hXto34CbT1D6Fi7DQpTClyZ3AuovFrY= X-Google-Smtp-Source: ACHHUZ5IekIIpHORjl7x+5hGHkPPeGv1S2EJr5b4ZPxCk+KXklujX1RFIClDi8UTrmkrrJy104dpqISl5+I= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a05:690c:727:b0:565:a43e:23c7 with SMTP id bt7-20020a05690c072700b00565a43e23c7mr2285571ywb.0.1685160252128; Fri, 26 May 2023 21:04:12 -0700 (PDT) Date: Fri, 26 May 2023 21:02:32 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230527040236.1875860-1-reijiw@google.com> Subject: [PATCH 0/4] KVM: arm64: PMU: Fix PMUVer handling on heterogeneous PMU systems From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_210413_771552_7F4175AD X-CRM114-Status: GOOD ( 14.45 ) 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 This series fixes issues with PMUVer handling for a guest with PMU configured on heterogeneous PMU systems. Specifically, it addresses the following two issues. [A] The default value of ID_AA64DFR0_EL1.PMUVer of the vCPU is set to its sanitized value. This could be inappropriate on heterogeneous PMU systems, as arm64_ftr_bits for PMUVer is defined as FTR_EXACT with safe_val == 0 (when ID_AA64DFR0_EL1.PMUVer of all PEs on the host is not uniform, the sanitized value will be 0). [B] KVM uses PMUVer of the PMU hardware that is associated to the guest (kvm->arch.arm_pmu->pmuver) for the guest in some cases, even though userspace might have changed the guest's ID_AA64DFR0_EL1.PMUVer (kvm->arch.dfr0_pmuver.imp). To fix [A], KVM will set the default value of the guest's ID_AA64DFR0_EL1.PMUVer to the PMUVer of the guest's PMU (kvm->arch.arm_pmu->pmuver). To fix [B], KVM will stop using kvm->arch.arm_pmu->pmuver (except for some special cases) and use ID_AA64DFR0_EL1.PMUVer for the guest instead. Patch 1 adds a helper to set a PMU for the guest. This helper will make it easier for the following patches to modify the relevant code. Patch 2 make the default PMU for the guest set on the first vCPU reset. As userspace can get the value of ID_AA64DFR0_EL1 after the initial vCPU reset, this change is to make the default PMUVer value based on the guest's PMU available on the initial vCPU reset. Patch 3 and 4 fix the issue [A] and [B] respectively. The series is based on v6.4-rc3. The patches in this series were originally included as part of [1]. [1] https://lore.kernel.org/all/20230211031506.4159098-1-reijiw@google.com/ Reiji Watanabe (4): KVM: arm64: PMU: Introduce a helper to set the guest's PMU KVM: arm64: PMU: Set the default PMU for the guest on vCPU reset KVM: arm64: PMU: Use PMUVer of the guest's PMU for ID_AA64DFR0.PMUVer KVM: arm64: PMU: Don't use the PMUVer of the PMU set for guest arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/kvm/arm.c | 6 --- arch/arm64/kvm/pmu-emul.c | 73 +++++++++++++++++++++---------- arch/arm64/kvm/reset.c | 20 ++++++--- arch/arm64/kvm/sys_regs.c | 48 +++++++++++++------- include/kvm/arm_pmu.h | 10 ++++- 6 files changed, 106 insertions(+), 53 deletions(-) base-commit: 44c026a73be8038f03dbdeef028b642880cf1511 Reported-by: Reiji Watanabe Signed-off-by: Marc Zyngier