Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4867588rdb; Fri, 15 Sep 2023 15:07:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxAyWQwhuRkfSpQSnb7q6BXW23IivgzaSkbuyqVWffYf/f5MOdfI0RfxXy8w/YoYZunlt3 X-Received: by 2002:a17:902:6806:b0:1c3:7628:fcb5 with SMTP id h6-20020a170902680600b001c37628fcb5mr2854938plk.62.1694815672700; Fri, 15 Sep 2023 15:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694815672; cv=none; d=google.com; s=arc-20160816; b=EbdSYqJl9nGmQntvEF4rAeCMfePSsr2VobvV4H+W4vSAz+WH/COXpSyou2dF86ck6G FLSwSipPbd+23WzmpPRdjpe+qjRkO/Zu57Tm+uIccSAh5YOaSr9x0qwJkZ2h/cUsXhpB SvMaWRbUfnfow+R/J576Cb5k7hNdxkbuQIDRGSeGozG6V5fThpExYoOKaQ5K6NV7WYDl PqTaz424+0f3zhwS25/b+5IYMD07ZsrsSeXXUB0u0dX5hXZtYCRFGf7X93D876K/5LYj f+xMS0CSklJb7VLiZ5kJs6A4VTbZ7HbW3g2Isp1y7kpF35vzOqSpvQTDtDN/1ENatPJ3 rOnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=Jh8wxRtaCDmNfJKXz9NRQ7CZIQMzCI29C3PoTr8TsLs=; fh=2MC/WzC4KZFz+GR156Ayad46xWDlSzeZJa0LUHR63ho=; b=fhr0Gn6BIfvnPmT/NyFOsuEmhjnOe0uWyjDyk9Ef6heKtW+l/FsQwUnWE9pfe4ZCdx tWyKjEU0Yg0tuKgTsEmw4+CdVjI6ZVIueiLOjcvGXL8PGcEr9aoTMPgnNKKX7t4/kiBR 1MoJ1KfJ0GrIevyx2ZXWocbDRODbbVUgS868pRyXB5xWRZGhl6WEAhNxr/1qmsbUaY9I F91QY2aCR1EnFLAh0Q9LtLXk5yv1dwjByAkXxRayfdYkPzaAO7IY8xpcX12Q8FSVo00k GpLT4XNwi+sOKZ6hUHl30bFdoXPXfXCEr9ZllxypL/xPnw5M/PBW6SGE+hIVbX6U8DZI 2uyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=v0fuP40F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n15-20020a170902d2cf00b001c3bd544f9fsi4168033plc.523.2023.09.15.15.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:07:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=v0fuP40F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2CE17802F70E; Fri, 15 Sep 2023 13:37:13 -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 S236653AbjIOUgd (ORCPT + 99 others); Fri, 15 Sep 2023 16:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237336AbjIOUgZ (ORCPT ); Fri, 15 Sep 2023 16:36:25 -0400 X-Greylist: delayed 2372 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 15 Sep 2023 13:36:16 PDT Received: from out-222.mta1.migadu.com (out-222.mta1.migadu.com [95.215.58.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9445F9 for ; Fri, 15 Sep 2023 13:36:16 -0700 (PDT) Date: Fri, 15 Sep 2023 20:36:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1694810174; 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: in-reply-to:in-reply-to:references:references; bh=Jh8wxRtaCDmNfJKXz9NRQ7CZIQMzCI29C3PoTr8TsLs=; b=v0fuP40FaFR3ghn7RXIwy67Q0K0A9PV4x7M7qmiJj74u7uqOJcrmJy/NRsbpejjUsPsPU4 o8NKRojsEw1KDsPIIQzBTZ71ljSVKKl4nchWZXeaA7gfwOJFxk7ZY/eqk94xQwimORQ6yv FbOt19DOumNoGkOOaXU99v5XYPYZOhU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Shaoqin Huang Cc: Raghavendra Rao Ananta , Marc Zyngier , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , 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 Subject: Re: [PATCH v5 08/12] KVM: arm64: PMU: Allow userspace to limit PMCR_EL0.N for the guest Message-ID: References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-9-rananta@google.com> <6dc460d2-c7fb-e299-b0a3-55b43de31555@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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]); Fri, 15 Sep 2023 13:37:13 -0700 (PDT) On Tue, Aug 22, 2023 at 11:26:23AM +0800, Shaoqin Huang wrote: [...] > > > > +static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, > > > > + u64 val) > > > > +{ > > > > + struct kvm *kvm = vcpu->kvm; > > > > + u64 new_n, mutable_mask; > > > > + int ret = 0; > > > > + > > > > + new_n = FIELD_GET(ARMV8_PMU_PMCR_N, val); > > > > + > > > > + mutex_lock(&kvm->arch.config_lock); > > > > + if (unlikely(new_n != kvm->arch.pmcr_n)) { > > > > + /* > > > > + * The vCPU can't have more counters than the PMU > > > > + * hardware implements. > > > > + */ > > > > + if (new_n <= kvm->arch.pmcr_n_limit) > > > > + kvm->arch.pmcr_n = new_n; > > > > + else > > > > + ret = -EINVAL; > > > > + } > > > > > > Since we have set the default value of pmcr_n, if we want to set a new > > > pmcr_n, shouldn't it be a different value? > > > > > > So how about change the checking to: > > > > > > if (likely(new_n <= kvm->arch.pmcr_n_limit) > > > kvm->arch.pmcr_n = new_n; > > > else > > > ret = -EINVAL; > > > > > > what do you think? > > > > > Sorry, I guess I didn't fully understand your suggestion. Are you > > saying that it's 'likely' that userspace would configure the correct > > value? > > > It depends on how userspace use this api to limit the number of pmcr. I > think what you mean in the code is that userspace need to set every vcpu's > pmcr to the same value, so the `unlikely` here is right, only one vcpu can > change the kvm->arch.pmcr.n, it saves the cpu cycles. > > What suggest above might be wrong. Since I think when userspace want to > limit the number of pmcr, it may just set the new_n on one vcpu, since the > kvm->arch.pmcr_n is a VM-local value, every vcpu can see it, so it's > `likely` the (new_n <= kvm->arch.pmcr_n_limit), it can decrease one checking > statement. How about we just do away with branch hints in the first place? This is _not_ a hot path. -- Thanks, Oliver