From patchwork Mon Oct 9 23:08:49 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: 13414646 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 4C81AE9371F for ; Mon, 9 Oct 2023 23:09:40 +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=c3XDFGt7iOdoFz/SmaLjIkhuzp5zG1f2w7DH0RAan48=; b=4FlrJDdmAQIHw+8UqWCMqkkeLK cmW1mWJ5yFUL1EYwUoGIcIqEFC+H8bx0CwCPLdM5buPco0IB4az94JTDxkEHUWK2k34n3tynprB7Q k3piRhvFNqukw0sVPvuRUhqjovAXIPqV6K4Die+C57oNd01YA1fGL6YbsffKnpG9CTD0sfOtp/tRL 6j96TX8QkjM3RGDhvK5h3aj7oyulQaBtMuFKW56kGNpM9osStD1vivgwUi11CV4RgYZoIsybzfv0m GrQAIVXUs+JtWylCBd3G+3r8JxvLKCGxsNctBA8zginI4U2PBZW7dtq5u2+ONzIppeeZARDOt2efc gJObHA0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpzNC-00Bmn8-24; Mon, 09 Oct 2023 23:09:14 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpzN6-00Bmjm-25 for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 23:09:10 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d815354ea7fso6635643276.1 for ; Mon, 09 Oct 2023 16:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696892947; x=1697497747; 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=JVCCYYHAr8CSZ5MG69SHY7zRH5V9FX2+QRsBdoTJR7I=; b=PpZTglnfwWIz4S1wbgYuEYkJD1CKEYX3O3+sERubjTpxU/tvtUx0ur+PDwH3/Wc+Id WiUcWhkMLaL04WqrVeCyRCLPkt6nBCUyfyT0Jmg19+HGfmT866D4LeLJlbuP+UMNEfIS nUfbHhj1Iq6Gsp7YmkcgTZbsqDndHFMpNTx4LTdxG+sdp7VFvsI/vuS7wljoHW2ISmY4 /f99R7d7cHF4X/TzvEykz5XAal4CSnYduOU8WFTpaI3QdDr5qj15j2Bt92K4qELMWOM+ feBT+tjtuxcCNJZTLEQ2BP5c7jW4yk6k4AJCNtYLmVY1UF2R8ovqedhWMmsX0e8nTWWy uOAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696892947; x=1697497747; 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=JVCCYYHAr8CSZ5MG69SHY7zRH5V9FX2+QRsBdoTJR7I=; b=QhcnRZJI0XVoocn1Hl2Rl3+isM1oatE73GXvhP2hv3l2ftdJ6WqR1ak/N7VF7UUCyo mM1c22fsWdWa2IFUaLNjdhg/bRWTsHMt2RmqzlAubTKWkAo5owMR7EFk8s1xKFKvCQPz YsZNf+Zd/pKkNtKJu54KqZGUjueYqhvW6y9W+o5Os5pXkUyj2VpVfd9bB0d2EHNhMJgy yuIVmN/HuMmc6asxZjUNnjeDDNKN0O/KwyxDEUMX8GTSXUI1AYn03FFm9eMko0QHTY83 Qd4k2M95X1FujqfEf42ftAnKeREgp4cEJFPa5mhWgVUaxzze9/d2aacJrZUZY2ysXt18 PuAQ== X-Gm-Message-State: AOJu0Yx59Aurt1LTa7RlQVkWTzq7FB1dBSAZTfOCCGBxw6T3PT0HXuTS fYt4eTTrVT4Na8SlB/tg/HROcPBqpe71 X-Google-Smtp-Source: AGHT+IHIs4oBYizNBaeSJxR7psR+gQ2uPd5kPXIt+bfHzIRybaO/dEl/UqH/5vlJK0t0Tca8kOKZZSSy04NM X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:20a1]) (user=rananta job=sendgmr) by 2002:a25:d313:0:b0:d7b:92d7:5629 with SMTP id e19-20020a25d313000000b00d7b92d75629mr287651ybf.8.1696892947170; Mon, 09 Oct 2023 16:09:07 -0700 (PDT) Date: Mon, 9 Oct 2023 23:08:49 +0000 In-Reply-To: <20231009230858.3444834-1-rananta@google.com> Mime-Version: 1.0 References: <20231009230858.3444834-1-rananta@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231009230858.3444834-4-rananta@google.com> Subject: [PATCH v7 03/12] 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-20231009_160908_680615_76F618B4 X-CRM114-Status: GOOD ( 15.09 ) 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 818a52e257ed..3dbb7d276b0e 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 */