Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3032136rdg; Tue, 17 Oct 2023 02:25:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEn5GoXhHuUknwp/Kfl0IaVq/7zlwe6kfH4Fhwhtcz+RbHm/ItB+fqSMX/gYY5Vs/EeoNKD X-Received: by 2002:a25:7613:0:b0:d9a:dfd2:cce3 with SMTP id r19-20020a257613000000b00d9adfd2cce3mr1662266ybc.58.1697534700227; Tue, 17 Oct 2023 02:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697534700; cv=none; d=google.com; s=arc-20160816; b=bWirSjr9E9aeaUedugJC/cYh+Ijk6fsZoNJuyLNyorEatwsP4azNgjC2/vP2JPBw3s 08jJn6k+Uxb3smvocG9DyPaeH0XbdB8JS2AvlKfgoapll+4T3glvZ3acn/D/ttQ4D65r h/w4oz4y6M+xisQ8PJBtuewReVZ3mH3EEMwSDMsd90wC/NmqVAo+jYl22NGRXabVrrK+ n1NyZ1bst0JLdhSuhGHGskiIZzQvKBPcf5EcTYWmU+lRcMzmbT6agZkiMcn6HSNujBIM mEWY7UTQguUqqI3BqZmpB3W1Bd2MiIbhyk2j8WWYeVkbgw0OIQE7YrOPevS//+loSIks a79A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xLOip3bfQykwpAa56t2wUVTHXUXOa2fVoIje1MZOWNk=; fh=R115E4X91sa+EM9CUee3+h/l/fX/SqqSSHmWqJWgRwc=; b=Wzm9om+QpPWBuKIEiHXemAHcpsdgfYN26pv0boNBcRRwdDq/VDj9bWuHyEbdF7qIsk C6SxjHGETkrVSugVt7JP77+dUedVuz1S0ARxgSDdI3h9ZC4Cc4p91VVhZqW6Pn+q3oFz vt5EshYyfotEl1tcYvU7YkuQGbQ9mAvvxAFNPPsAlGgguVSnB6QwVNZ9Tye0i0kUFr3v v+D5CzcYkivHctK5+RQzRUtp8ncLGBehZbkDe/0M39sm7u2hSnRP5gVcQT3KQ0PScWR4 xAK1p1hypBVGbbw2AEV0IgQSl5YMQ+wHt+MKIXYcUi/nqoDHvVveWH0kQyKCrpBmzoXy zynQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YFD4hMGH; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bw9-20020a056a02048900b00553800fe4dcsi1546073pgb.583.2023.10.17.02.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:25:00 -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=@redhat.com header.s=mimecast20190719 header.b=YFD4hMGH; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B391B802FDF7; Tue, 17 Oct 2023 02:24:57 -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 S234840AbjJQJYl (ORCPT + 99 others); Tue, 17 Oct 2023 05:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234835AbjJQJYg (ORCPT ); Tue, 17 Oct 2023 05:24:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C66398 for ; Tue, 17 Oct 2023 02:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697534632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xLOip3bfQykwpAa56t2wUVTHXUXOa2fVoIje1MZOWNk=; b=YFD4hMGHXy2AbMRZhwR69T1u6Iqq6xXMM2w+bLvA8KPMI6aUU8F3WpWUSLpbTb2rbN4Y74 f8eUCk2L44+X9yqaveTuAxbgKzsJPTvTeSCDFX9yeK0OKoCIJ4t69XB3ZjuQFFWcQCHtRD hGGSJ/1/6Xfu1RqLYWqkBlPn/famhAc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-xAAIvu6hOhiDeqpeG3tftA-1; Tue, 17 Oct 2023 05:23:51 -0400 X-MC-Unique: xAAIvu6hOhiDeqpeG3tftA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7740bc7ad6fso695567485a.1 for ; Tue, 17 Oct 2023 02:23:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697534630; x=1698139430; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xLOip3bfQykwpAa56t2wUVTHXUXOa2fVoIje1MZOWNk=; b=LPfZVJl7gQbxRuUMgTK7NewZMQleZgC/51Flbgr3dIvkLK/B2iSA5S0MoES6aQmlfa nlML8AC4v69k2+mubWmG2+NuBgjgcoj/yMcaHJYuWHJV3h/xkiiuSc2zKZxhFpsT7sUQ k7Tyh4otoGl6lJ0rESmw4ZrxoLxAGBET4lmV6Ppm+JS5ixdH4JpEEpXEalhhX826xxvC +BNmCHSYzFGqKHvepOVFbxXOyqCtHe1sTTWWl25eFl/5upG8hbX4caZYmk8h6SUjmgLn pLhJjCBHMGbGI+qnfVIpX53p88HLSYcikAudTOKwHA33t+eZaNg+K4kxa5Hj0e9y9IbG ps+g== X-Gm-Message-State: AOJu0YzCQi6vSBf1JkdAmg9vKPb+eMmsm4mmfaqjijcuoG0YMi4uj63/ iJUsFJnmM9+UW3CaX3pQCyojPXdVVjt0/u2vCc7wKXUQ77HUnrM9lRyr1abwcL9Exw7SS2qiuAx LO/54Szkf+m9Yx+drTCq163y3T0ffo1YZ X-Received: by 2002:a05:620a:8010:b0:774:1e8f:222d with SMTP id ee16-20020a05620a801000b007741e8f222dmr1598583qkb.62.1697534630687; Tue, 17 Oct 2023 02:23:50 -0700 (PDT) X-Received: by 2002:a05:620a:8010:b0:774:1e8f:222d with SMTP id ee16-20020a05620a801000b007741e8f222dmr1598569qkb.62.1697534630430; Tue, 17 Oct 2023 02:23:50 -0700 (PDT) Received: from [192.168.43.95] ([37.170.237.139]) by smtp.gmail.com with ESMTPSA id y12-20020a37e30c000000b0076f058f5834sm488223qki.61.2023.10.17.02.23.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 02:23:49 -0700 (PDT) Message-ID: <34959db4-01e9-8c1e-110e-c52701e2fb19@redhat.com> Date: Tue, 17 Oct 2023 11:23:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v7 03/12] KVM: arm64: PMU: Clear PM{C,I}NTEN{SET,CLR} and PMOVS{SET,CLR} on vCPU reset Content-Language: en-US To: Raghavendra Rao Ananta Cc: Oliver Upton , Marc Zyngier , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-4-rananta@google.com> <53546f35-f2cc-4c75-171c-26719550f7df@redhat.com> From: Eric Auger In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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]); Tue, 17 Oct 2023 02:24:57 -0700 (PDT) Hi, On 10/16/23 23:28, Raghavendra Rao Ananta wrote: > On Mon, Oct 16, 2023 at 12:45 PM Eric Auger wrote: >> >> Hi Raghavendra, >> >> On 10/10/23 01:08, Raghavendra Rao Ananta wrote: >>> 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(). >> PMOVS{SET,CLR}_EL0? > Ah, yes. It should be PMOVS{SET,CLR}_EL0. > >>> 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. >> do you intend to restore the 'unknown' behavior at some point? >> > I believe Reiji's (original author) intention was to keep them > cleared, which would still imply an 'unknown' behavior. Do you think > there's an issue with this? Then why do we bother using reset_unknown in the other places if clearing the bits is enough here? Thanks Eric > > Thank you. > Raghavendra >> Thanks >> >> Eric >>> >>> 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 */ >> >