From patchwork Tue Sep 26 23:40:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 13399720 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 22367E7F144 for ; Tue, 26 Sep 2023 23:41:05 +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: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sW6f2jQYeWJqlJvAAtiHuE2Q3tNU0C7Ew/+dH990UEg=; b=m+CxDqJV6gD5IVGP23BqvyzRLC bxPmTxIQ4yUbSsryvSDpj0tLWWWxkDEzclMTVUUcJPJpxig6ZRZcJObhbYkkuoT2Pg2oZGNAXpQfc f+d5R3uwy1evhuS5jbNpyPrPalIONT6YZzk/7SaZXd2YoL+UEB9Ul4S91aXbS6n8QeSo5ip1H8P60 6nRTIwxJROD/E4+sxjVgZfa7UIea9/1ClKeSMbx2Uf1E5sY+rZcnNedRzBZ3dpXiQj8jZmK2fVYh1 xQobnzEz/bQabCMu8pq/AIUV54Gc8Ci8CaDa7klJV6fpWngRnyueURuq+dsVE/Ne5bR3ptI2BAvJJ NW9MzOgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlHfO-00HBj6-3A; Tue, 26 Sep 2023 23:40:34 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlHf7-00HBcS-0O for linux-arm-kernel@lists.infradead.org; Tue, 26 Sep 2023 23:40:19 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81d85aae7cso20636331276.0 for ; Tue, 26 Sep 2023 16:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695771614; x=1696376414; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Qevun5/yY9+JK3ZHPWuRVz7IcDpyIACFdYtKkR+rLD4=; b=B2jJaY6Elz8byCMpYufkXDf4CMAxhMF1YrIzcKFV2wcfqxsS5u5bGGRUiveveV6I9u 5JBlNF+OuldMhjcu+JT1qpuYIs9zedRgEs2xjoF/g5lz5d+Ept2VsqpmAJOHwo2f6Stl h7NU728Oz7srMTeoCD2E9eRAauYA6owjz4ZpSxRXe5gstB4kh8gF/HjTsoEaO7GhFhmM lXZONzY+VgQwJ6QZ95UIU6rMssDGTY8qV+VN9WMSmrNt1PA9zTl27iYb0BSwW3NJZtJt hLKKVwPJ0+AaqA+O4TURzdlnu2ar1xzH/QZJmxoPZvb861cyTryuBJt6s1TTGgEky9BP 9NHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695771614; x=1696376414; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qevun5/yY9+JK3ZHPWuRVz7IcDpyIACFdYtKkR+rLD4=; b=NxpZ/11ecwNt3b9Ym4VhWra2Pw/6wYzMyowglTgnG4bQdI8CxD68oqraCLay4NFD1L KIbHpEipe+7rjkcD377Yyb2szpcAXdMPWgYTqnLnzs3pnxhCGoYE9JrSd3C7HvCP7All 8BooCPvTc2jM80ln3QfIAbH8sHlNzEO8n2BKQoDa1uFkl/lvC6qgJNOc7J7ih8RRESzR TbcFYzHKGoaneP0CQp3BVUs/xi6j/buFtBGE78iVqvIqloBT75v5TJzO9/PtQzcZwpsg s2utc1YaoujZWE68vSAcu/VeemJW5GMQQEl8kLB2BxbjFGd31KAwG+YANfdwz5aGNMCg zo1Q== X-Gm-Message-State: AOJu0Yzhm8IH3Jw9ULgk1vBihdlNBGKAwHYaNoZlfuwbmisYK6LoWtdG N37gquLtyubWIRImv/SSG3hsMNNrz5PX X-Google-Smtp-Source: AGHT+IEetmKobj2HvrfP5UmgYOr+yV8c5JH7C8utm5y5aVOqCwA2WWM3hZUA8gTkdds5ZVhPcUCGyps/w76l X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:20a1]) (user=rananta job=sendgmr) by 2002:a05:6902:4f2:b0:ca3:3341:6315 with SMTP id w18-20020a05690204f200b00ca333416315mr8256ybs.0.1695771614584; Tue, 26 Sep 2023 16:40:14 -0700 (PDT) Date: Tue, 26 Sep 2023 23:40:00 +0000 In-Reply-To: <20230926234008.2348607-1-rananta@google.com> Mime-Version: 1.0 References: <20230926234008.2348607-1-rananta@google.com> X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230926234008.2348607-4-rananta@google.com> Subject: [PATCH v6 03/11] KVM: arm64: PMU: Clear PM{C,I}NTEN{SET,CLR} and PMOVS{SET,CLR} on vCPU reset From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier Cc: Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_164017_155583_54C4125D X-CRM114-Status: GOOD ( 15.12 ) 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 From: Reiji Watanabe On vCPU reset, PMCNTEN{SET,CLR}_EL0, PMINTEN{SET,CLR}_EL1, and PMOVS{SET,CLR}_EL1 for a vCPU are reset by reset_pmu_reg(). This function clears RAZ bits of those registers corresponding to unimplemented event counters on the vCPU, and sets bits corresponding to implemented event counters to a predefined pseudo UNKNOWN value (some bits are set to 1). The function identifies (un)implemented event counters on the vCPU based on the PMCR_EL0.N value on the host. Using the host value for this would be problematic when KVM supports letting userspace set PMCR_EL0.N to a value different from the host value (some of the RAZ bits of those registers could end up being set to 1). Fix this by clearing the registers so that it can ensure that all the RAZ bits are cleared even when the PMCR_EL0.N value for the vCPU is different from the host value. Use reset_val() to do this instead of fixing reset_pmu_reg(), and remove reset_pmu_reg(), as it is no longer used. Signed-off-by: Reiji Watanabe Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/kvm/sys_regs.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index e92ec810d4494..ffd123fae30d6 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -717,25 +717,6 @@ static unsigned int pmu_visibility(const struct kvm_vcpu *vcpu, return REG_HIDDEN; } -static u64 reset_pmu_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) -{ - u64 n, mask = BIT(ARMV8_PMU_CYCLE_IDX); - - /* No PMU available, any PMU reg may UNDEF... */ - if (!kvm_arm_support_pmu_v3()) - return 0; - - n = read_sysreg(pmcr_el0) >> ARMV8_PMU_PMCR_N_SHIFT; - n &= ARMV8_PMU_PMCR_N_MASK; - if (n) - mask |= GENMASK(n - 1, 0); - - reset_unknown(vcpu, r); - __vcpu_sys_reg(vcpu, r->reg) &= mask; - - return __vcpu_sys_reg(vcpu, r->reg); -} - static u64 reset_pmevcntr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { reset_unknown(vcpu, r); @@ -1115,7 +1096,7 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, trap_wcr, reset_wcr, 0, 0, get_wcr, set_wcr } #define PMU_SYS_REG(name) \ - SYS_DESC(SYS_##name), .reset = reset_pmu_reg, \ + SYS_DESC(SYS_##name), .reset = reset_val, \ .visibility = pmu_visibility /* Macro to expand the PMEVCNTRn_EL0 register */