Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2185932rdb; Mon, 9 Oct 2023 16:11:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTw+UDkuzMj5QxSFd61nMHJwZxVphxBk6kgQf4sNLGBqMnstWuGZoptxW4nTZaAbD2LeYe X-Received: by 2002:a05:6358:590d:b0:14a:ddb8:9a12 with SMTP id g13-20020a056358590d00b0014addb89a12mr21370305rwf.6.1696893091011; Mon, 09 Oct 2023 16:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696893090; cv=none; d=google.com; s=arc-20160816; b=VORlXjy4hUaKCBDlCcVDONCORtYQVcCQ4M1atY7P9PbIzvZCfzV1PuIdxV65hEcJPT MbMswvYKnOrobpNSL4TSAxJH/VJf1V8yni13gHp2GkNWFy6dB4LjCB8BRtZpNd3QUl7N WZ72fFea2uaPf9t1yiibBrWcYhv3Uh/e0TGr6pHRo5xqXmJGjmfvFn7RsY+kiRTNcMMZ MyF1/+92Mfr9NeqYpcW2BDtbMJ99Wdj3bcyBNNg5hi0CTkvSKkcCx4Q7vcxN5b6nGIfw nFh/GC+1mmsaFJJRknqwHs9v6wlJN5imQA0npAH4Gbb83hbTUZ3/7W5WIhhnpUQ+40Qj YiDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=JVCCYYHAr8CSZ5MG69SHY7zRH5V9FX2+QRsBdoTJR7I=; fh=nSGf6E5bqeZ4+WG1wtUl4dHMM2T+/oX4atvC7v39NTU=; b=qCSHDus9/+cmaDyBskHV8Cp7mrMAnOSOS00WJwYLS7PoZQujg2LWmYIIU2x+klJwzQ czr/uYfocxapiFrSHVzKWV1NtT5UJCywFPkEO74Aiz/Q/9qm0zFZDwN56dcRbUDl6WAJ MFW7fnTi7RREfNducfXBa/phFxbn1ZU/3Jz007Be9LGdbZT6jcXZ/3+SmwPLSCSn/UTi iEQpYFCBgC/8dJRDTDswa2FqgHunMq6tjjamqxsVRarCaaT/hLc93QB2sljGMzlb9oVs 3DCqOp6s84EXGDqKedsWIaqnxfjLLXTkFeEI2Lx9NhRlldVNLUu+1TpXCJMdZCJaL8EM yWvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pGGEoyVS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b0055391572218si10072073pgv.26.2023.10.09.16.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:11:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pGGEoyVS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A7784802F6A9; Mon, 9 Oct 2023 16:11:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379165AbjJIXKw (ORCPT + 99 others); Mon, 9 Oct 2023 19:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379098AbjJIXKH (ORCPT ); Mon, 9 Oct 2023 19:10:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D34DD7C for ; Mon, 9 Oct 2023 16:09:08 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81e9981ff4so6623740276.3 for ; Mon, 09 Oct 2023 16:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696892947; x=1697497747; darn=vger.kernel.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=pGGEoyVSbHTYDM8EyC8DsP/zCCo/mHiUpartxl9Cy99L3obtUaSTvgZ7VkrUBn/sOz H7IVng/CFw6/iwMGxSHRCuMHmyxQs7MYn1oj3TOxvWyq2DS8yiTUhCbNAbx5m1ufekrT suuH2tCvkrHWHaJi7jERrs+Hf6WjEMqAE4ceKpvYbkTgfq/3VokTvP/X3sVDkvuhWa/J w2bWLI4xvvXwS1WliSDq6bjwrJVHhminN176Zr6k7HDydzdu+VrbuX7cqw8lJrnq6O+a xDoKu4W3tMh3Qo2GiNoXQ9GBf8Va0OUspSn5oxQyYQcgI35lOE/vmOxgwrrcnEd+o9NB L3eQ== 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=eNgF/ElPvq/ujKBpkW1S7c1oLN60u12t9HPJ6fcB4FmhlbZMaXxw9OioXUlYm7UP+G 55FQ+EmJhNCODQyWy5xakatGZc4tkrtJQWe+1bKHZz7jzsuCkO5GxO9qr201VMdKt8Dr NXwfV5z+E/RfDldLQdj/2IjaSEVzV7hM6+u3WZaJbfQx22TLX/LBDTbZHA1+Piba4Ire IBJyietDq8kGXIH0FQQWQu8YxYpq4H3uPXJYN3ejeYaBFbG/YaI0YftPOclEp/8PfvOA l/SkoXF+6+Dysu/z2Ytsw5C99k9/hmfnglJmS6ejQSfZfhT6vo3uuddgnqyB1fFDYfTf ttig== X-Gm-Message-State: AOJu0YxK4FAlpGY+Gn3egcRfqxZezeGN5P9k6nhdZy9zNM04s6pt+Qse 9HmobzlP48hTk3WswdX3HcffFGOzCFsv 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 16:11:27 -0700 (PDT) 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 */ -- 2.42.0.609.gbb76f46606-goog