Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp217265rdb; Mon, 18 Sep 2023 12:48:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH879jYwhGvYtpLTTy5aOCKDpQNRapAI0nzfgs4t92x5k2FFlXK7KeZuBK47jMI8MdD+AzH X-Received: by 2002:a17:902:bf02:b0:1c3:188c:a347 with SMTP id bi2-20020a170902bf0200b001c3188ca347mr9671179plb.54.1695066536287; Mon, 18 Sep 2023 12:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695066536; cv=none; d=google.com; s=arc-20160816; b=wtsIVSPlvoBldWJSXHApSNAN3+uY6PSve73286x3pyzRkkfUOtNzesN6nQnTQLdY1U G+t1KDz3co+mtP1MwPwHE1QKhwOdw2IxTznXnTEO2IHV2wLYMK4jL8v3WkXhppfgxJzv IRyqQ5m3OxroBVWtI5yKcQNDH1nrpIkTO2ldPXXm0COrEmA2hBsA6sWy85reSuY140Yd Qgdi+N7hY+l3U/cg6FQ9snEMLbwC8JWVz7ig9gmF27FsAaRKLWCRCmqQetMbeCNSBIYO Z7UPtaZSkR4oPg/S5PZ+8Xl/Of2t9TD+BcDHzUAYJuYX1c4HkXl3LfDBAIRzQ4gVa+KU /SKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UAIfwvZ+63Hgn0zk0yrYnb3ogYKWcNYJOySoDjwnNsI=; fh=3gzflrAh7o/i17NGInydiTBnDCwh/Z81V//wXZ8lKL4=; b=K+skApKMssO9Hwj738JlyzWMDVUFtO/SpBKuwsHqGQSZSHuq6qH7o5iJCE4LCmO+Z9 0u2dON2GTxQJBJ9w3wfYOzl83uQu7ZiGccxCZvX6P6ZEfj7ns2GZiqLaRgk/W0kzZovK lF4XRkMazQQTSgql2KJFdZE/oiRKBOJ9EjpO6vnuGtL8VO2yZzUlPYbglEc1psPn3wuq nXFiSR24qOV8z5iL4/A/QEnN2bOoD6iAJL2sD2QvsA9SkA93DL45hoLi/U29kfsjoOfQ xzcYDov5SUFCYsgwk3p8jRU3shdviysPq+Jvleg6UOtBRT8Ub8mXy6Q+JABiaw/QzaUW 7MSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lGZ6+5Tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c5-20020a170902d48500b001bbb8324bd5si8580430plg.479.2023.09.18.12.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:48:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lGZ6+5Tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 9CB2F80BDE0C; Mon, 18 Sep 2023 10:02:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231409AbjIRRCr (ORCPT + 99 others); Mon, 18 Sep 2023 13:02:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjIRRCi (ORCPT ); Mon, 18 Sep 2023 13:02:38 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8817599 for ; Mon, 18 Sep 2023 10:02:32 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-34fc9b461b6so2265ab.1 for ; Mon, 18 Sep 2023 10:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695056552; x=1695661352; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UAIfwvZ+63Hgn0zk0yrYnb3ogYKWcNYJOySoDjwnNsI=; b=lGZ6+5Tv3bFq2sxiYKnEHQ27wAK0lSkPh+93NjFZPex139bJNe6jFLwJ5flfliF+/i HBx4VqaeEtFVR/BbTN7454JthT8OsjMVBGz0hCEaaXGte9ZGrjia/FnoIOTbIlHuSiwv eBJfqhsjOClMD5e+U4UBFCFbizdbi+PGgna/vuecfEYF3QkCINu42sdE6r+aDoqYxU/3 cbM0b1VzVIigQxwzL4+1XcB8fw7VzH1Y6UXl3WCoHOWJ1EPKwJZuzPTK4W8Ctpa0j9gp 0yyfTXx88pwlLT2y4c5Rr9Bh/0DU0XzromfHMNwhNkiHdnXWlVv158AyHgdmX6ddCC6x fQ+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695056552; x=1695661352; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UAIfwvZ+63Hgn0zk0yrYnb3ogYKWcNYJOySoDjwnNsI=; b=NK14fmZbaUqKFR2HKQEk4z6zzTQcMr7gHyDAkFE//8EAgI5zcIXpLp086tPcgrXNB+ VG4/yIEA6mPbXyudipQn2ad/6wtAr2o1t6amOkYRgFqeV6/RhmCgfLERx9fgjqNf46mc Lj6oFfG21i79ET2pl6ilYR1Tsmke7r4HTIABxpsKDKj7Tn3/nKAHeaWWiyQe9R5rb/6Y 4ljfu+cn5vAAheVhPxs3LDxtAhrNLS2o8GHKcr5nLVKOuqNiorOiG+nWuLTE1+FVwQv9 7FI1U5PyA6t0FzdB6stTHzpEgVPsHiAJegF/8EKczS9G0cVoJot7xl+HUqXBYbymTv8F peYA== X-Gm-Message-State: AOJu0YwLJYwWQQEQ6HpdY5vEmeYsPLrmzmYF7XKjX5QuefLCJd5yfYB+ wcFgJHTHZ3KVvYMc01Cv60BfRM0UsCACCNL6rzy2VQ== X-Received: by 2002:a05:6e02:144e:b0:34c:acb5:11bd with SMTP id p14-20020a056e02144e00b0034cacb511bdmr598183ilo.16.1695056551832; Mon, 18 Sep 2023 10:02:31 -0700 (PDT) MIME-Version: 1.0 References: <20230817003029.3073210-1-rananta@google.com> <20230817003029.3073210-9-rananta@google.com> <6dc460d2-c7fb-e299-b0a3-55b43de31555@redhat.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 18 Sep 2023 10:02:20 -0700 Message-ID: Subject: Re: [PATCH v5 08/12] KVM: arm64: PMU: Allow userspace to limit PMCR_EL0.N for the guest To: Oliver Upton Cc: Shaoqin Huang , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 10:02:58 -0700 (PDT) On Fri, Sep 15, 2023 at 1:36=E2=80=AFPM Oliver Upton wrote: > > 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 =3D vcpu->kvm; > > > > > + u64 new_n, mutable_mask; > > > > > + int ret =3D 0; > > > > > + > > > > > + new_n =3D FIELD_GET(ARMV8_PMU_PMCR_N, val); > > > > > + > > > > > + mutex_lock(&kvm->arch.config_lock); > > > > > + if (unlikely(new_n !=3D kvm->arch.pmcr_n)) { > > > > > + /* > > > > > + * The vCPU can't have more counters than the PMU > > > > > + * hardware implements. > > > > > + */ > > > > > + if (new_n <=3D kvm->arch.pmcr_n_limit) > > > > > + kvm->arch.pmcr_n =3D new_n; > > > > > + else > > > > > + ret =3D -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 <=3D kvm->arch.pmcr_n_limit) > > > > kvm->arch.pmcr_n =3D new_n; > > > > else > > > > ret =3D -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 vcp= u'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 <=3D kvm->arch.pmcr_n_limit), it can decrease one c= hecking > > statement. > > How about we just do away with branch hints in the first place? This is > _not_ a hot path. > Sounds good to me. Thank you. Raghavendra > -- > Thanks, > Oliver