Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1633375rwb; Thu, 15 Dec 2022 12:26:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4MaO7h/b8X2/dFJGII+tIg7lsYceshuv3GNcTcuKqpONntEHfbzbpz8nHsIxh+gJExgiJJ X-Received: by 2002:a05:6a20:4f22:b0:af:7ed7:d370 with SMTP id gi34-20020a056a204f2200b000af7ed7d370mr6571686pzb.43.1671135997009; Thu, 15 Dec 2022 12:26:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671135996; cv=none; d=google.com; s=arc-20160816; b=FeOWSy/jlz0VYbAyg+xtV2bO3/Ereduo810e3o8jK5BI8eo+GuW96FcBlb9AniMHEz XNIw/CVn6VoMcMr3kTQjIjAgLF20akY6Yl9FbZa4wadGawrWFFg2T8d6deldKVxsKAKE PHu+iiFYCG2yPwDCIEuaapAkopV7qG3lAvWnJQuYeC8JmDJWiHnNkG6eqTMJk25dwWa7 HfAoKXSdL/2uNcM/wVa1Vz5O08IUe21BLlgkQQFKVwTSXG003b5xobmSX+KGH0szU3wx Yq2s4NQNFtNaoRmEr3fxGyEMw+ZHFfA5XB100+1nByQB4qksT6uz6vdxjgLmzxHEsmzU BTlw== 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:date:dkim-signature; bh=NjjXvQZofmHP3EB2ka+mcBe5Fo+sfmX5OK05R+KJEcQ=; b=VFSvrRG7eHjagnZ3y/sDiNj4VlH/SuniSfzCUc17J4nu7J7wClFSlKsZYu74mwVXeL ubtHM7g/px+odMJ0vQtnka49vR8ECKKYlMvNNqVmKKWoW0R3LHyXdw1vnlmocaZak2SB 7Emq4GC22m6N7Vc1mxX/VUPjVBAqbzvZQ3t6xJWlBZU17apJiXKA9Z/+14IWk79yMWla NJNc8B7PMiOGGrjaajqhwE5zXgCn9sHXj+PCUqagU7nah6LzC4uw1/fd42fxT8TVUook PcyxMpbhoHP8hbu2nY0HBzeWV8376DyuoH3TPhyndQ8E5QWr2sWHZCAwEnsOMogF7LOA F47A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EdgEqLCx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t127-20020a637885000000b00478f0ed0a68si381570pgc.575.2022.12.15.12.26.28; Thu, 15 Dec 2022 12:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EdgEqLCx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbiLOUSM (ORCPT + 69 others); Thu, 15 Dec 2022 15:18:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiLOUSI (ORCPT ); Thu, 15 Dec 2022 15:18:08 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAB1F31EC1; Thu, 15 Dec 2022 12:18:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id F326ECE1D03; Thu, 15 Dec 2022 20:18:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F3BBC433F2; Thu, 15 Dec 2022 20:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671135484; bh=oel0ZlOiiQOwqlbEX/I6OlGQeXzpFhRh/Jy7Mv8nTSY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EdgEqLCxeDXAXzybpNlP+ffQ5ItI5gPQ7CTUCYBo8RvvtRESOQPBALRL+vW1IhqGq BcZmyxEvj93MuMP9mlwbZPusjeAe/v/zLGehtYlDTIuxVTX01PGeaGOZY2+z1I85LG m2h18sYLJRI/iaazBkEwL1ZsU8wM9jjwylN1zJTv9GeSurm08lFsQQroHPuzw2HUqB 1W+cUcwr8AwgyC4B0SmqQlB29+nAVpLTWym2WiveICJE5zAe4KNghI8cyHytPT6neX 9UztJTVoSwuB07T3lj+gERoqWbkO6IicFX0Ri1klvT1FE8TEbZRf/zukRFtKaaErM7 lZNGn8IQTaqcg== Date: Thu, 15 Dec 2022 20:17:52 +0000 From: Conor Dooley To: Atish Patra Cc: linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Sergey Matyukevich , Eric Lin , Will Deacon Subject: Re: [PATCH v2 05/11] RISC-V: KVM: Improve privilege mode filtering for perf Message-ID: References: <20221215170046.2010255-1-atishp@rivosinc.com> <20221215170046.2010255-6-atishp@rivosinc.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Kh96vCh7mb1vJCOA" Content-Disposition: inline In-Reply-To: <20221215170046.2010255-6-atishp@rivosinc.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Kh96vCh7mb1vJCOA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Atish, On Thu, Dec 15, 2022 at 09:00:40AM -0800, Atish Patra wrote: > RISC-V: KVM: Improve privilege mode filtering for perf I almost marked this as "not applicable" in patchwork as I was mislead by the $subject. I know our perf driver is a real mixed bag, but should it not be something more like: "perf: RISC-V: Improve privilege mode filtering for KVM"? It was only when I noticed that the rest of the series had been marked as "Handled Elsewhere" that I realised that this must not be a KVM patch ;) Thanks, Conor > Currently, the host driver doesn't have any method to identify if the > requested perf event is from kvm or bare metal. As KVM runs in HS > mode, there are no separate hypervisor privilege mode to distinguish > between the attributes for guest/host. >=20 > Improve the privilege mode filtering by using the event specific > config1 field. >=20 > Reviewed-by: Andrew Jones > Signed-off-by: Atish Patra > --- > drivers/perf/riscv_pmu_sbi.c | 27 ++++++++++++++++++++++----- > include/linux/perf/riscv_pmu.h | 2 ++ > 2 files changed, 24 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c > index 65d4aa4..df795b7 100644 > --- a/drivers/perf/riscv_pmu_sbi.c > +++ b/drivers/perf/riscv_pmu_sbi.c > @@ -298,6 +298,27 @@ int riscv_pmu_get_hpm_info(u32 *hw_ctr_width, u32 *n= um_hw_ctr) > } > EXPORT_SYMBOL(riscv_pmu_get_hpm_info); > =20 > +static unsigned long pmu_sbi_get_filter_flags(struct perf_event *event) > +{ > + unsigned long cflags =3D 0; > + bool guest_events =3D false; > + > + if (event->attr.config1 & RISCV_KVM_PMU_CONFIG1_GUEST_EVENTS) > + guest_events =3D true; > + if (event->attr.exclude_kernel) > + cflags |=3D guest_events ? SBI_PMU_CFG_FLAG_SET_VSINH : SBI_PMU_CFG_FL= AG_SET_SINH; > + if (event->attr.exclude_user) > + cflags |=3D guest_events ? SBI_PMU_CFG_FLAG_SET_VUINH : SBI_PMU_CFG_FL= AG_SET_UINH; > + if (guest_events && event->attr.exclude_hv) > + cflags |=3D SBI_PMU_CFG_FLAG_SET_SINH; > + if (event->attr.exclude_host) > + cflags |=3D SBI_PMU_CFG_FLAG_SET_UINH | SBI_PMU_CFG_FLAG_SET_SINH; > + if (event->attr.exclude_guest) > + cflags |=3D SBI_PMU_CFG_FLAG_SET_VSINH | SBI_PMU_CFG_FLAG_SET_VUINH; > + > + return cflags; > +} > + > static int pmu_sbi_ctr_get_idx(struct perf_event *event) > { > struct hw_perf_event *hwc =3D &event->hw; > @@ -308,11 +329,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *ev= ent) > uint64_t cbase =3D 0; > unsigned long cflags =3D 0; > =20 > - if (event->attr.exclude_kernel) > - cflags |=3D SBI_PMU_CFG_FLAG_SET_SINH; > - if (event->attr.exclude_user) > - cflags |=3D SBI_PMU_CFG_FLAG_SET_UINH; > - > + cflags =3D pmu_sbi_get_filter_flags(event); > /* retrieve the available counter index */ > #if defined(CONFIG_32BIT) > ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, > diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pm= u.h > index a1c3f77..1c42146 100644 > --- a/include/linux/perf/riscv_pmu.h > +++ b/include/linux/perf/riscv_pmu.h > @@ -26,6 +26,8 @@ > =20 > #define RISCV_PMU_STOP_FLAG_RESET 1 > =20 > +#define RISCV_KVM_PMU_CONFIG1_GUEST_EVENTS 0x1 > + > struct cpu_hw_events { > /* currently enabled events */ > int n_events; > --=20 > 2.25.1 >=20 >=20 --Kh96vCh7mb1vJCOA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCY5uA5wAKCRB4tDGHoIJi 0pnAAP9279BG2bKNaby4m7HVZ0iqkvu0RtJ6SIQ0JPGpdv+p1QEAtd4qbzkPg3u6 Mw7SPMVU7YEk3w/xjU2fqUVQ1eTkxQU= =A5xN -----END PGP SIGNATURE----- --Kh96vCh7mb1vJCOA--