Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp554565rwb; Wed, 9 Nov 2022 06:06:46 -0800 (PST) X-Google-Smtp-Source: AMsMyM5Kg1KfqQVWRZebZ4124IWRIqf5fE09FQt+9L0mWpIKADDXQmPH7S3cBEHU5n2v9HQwf7RD X-Received: by 2002:a17:90b:188:b0:214:3036:4e68 with SMTP id t8-20020a17090b018800b0021430364e68mr39381920pjs.234.1668002806300; Wed, 09 Nov 2022 06:06:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668002806; cv=none; d=google.com; s=arc-20160816; b=nqXrFKkfBCSScKZ7a775x85KxVXmC9QvvXYMDO+bzuP0SrM9qTCtqbyDbUGoKB1Xx+ PI3ouP67bJY3B71hrQ6zhjP46+vgxiD3mdN8OYSuH2mT6+e9fXAnVDFjWkmL8+6+jUf9 LYpFDwdm2a/PSZxc4UAOZrJ8WYiVY6Dse6Hj9bZiX6Xfp5qsAqHy9CEnpKLO8eHvYfXJ OT+O2gojecVgV07K/R637/u/7kCqL0UdUuTWiGxyO5OK/7KAa6e0hAJ0ROIMlc7JBWhC 6W9TbpRrdo8ysp1wQK19Ju9g+PxesxpetL5WF92hDO/TZLXHET6Q9xxnedA8r4wIAx5d bRNA== 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=ldyqt2mSXXrEosQOvqIK5dNWaqrseYntTJhs+D88oGk=; b=FMtKNHATupae379jqx71tUd5DAU1JAPOyPiUXGxiJiEQgm3V0+FsYK1D/rijZ7YWh8 Q+Fy6m4TQDNZOHm51IT5rrqfRJUSWSbLZ93H2h3NpAa/8QtHGSTWgj+onbc4AmBZGitU lZCNtD3Nhxp1qzkbw9X9pHOHv6/SLnH60GQp+CrxG5hPtM+BHh1FXxXTQ//jwDkCkDlx 7O8iRmAD5x3EwRQC6mdlCAZUdHlE4W3h3EgPfakORYOrW3xBPPtXFPUr6SLonqJCly8M CARCaDkaqtmhhTpMcLCtviFHSSb0qeF1kVRdoJezNLV0K9ps2n/bb0aPATfY2FFQnKiK 264w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ex9WzbT9; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a170902e5c700b001869c588d5asi21827485plf.110.2022.11.09.06.06.33; Wed, 09 Nov 2022 06:06:46 -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=@gmail.com header.s=20210112 header.b=ex9WzbT9; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbiKINmd (ORCPT + 93 others); Wed, 9 Nov 2022 08:42:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiKINmb (ORCPT ); Wed, 9 Nov 2022 08:42:31 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 875EA233A3; Wed, 9 Nov 2022 05:42:30 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id f37so25644363lfv.8; Wed, 09 Nov 2022 05:42:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ldyqt2mSXXrEosQOvqIK5dNWaqrseYntTJhs+D88oGk=; b=ex9WzbT962IPus2/cssqm29tzXLBUJLZc40PlJ+tkwm69kc1nFLEifs9mte7yOWvyW ihAGElQGpsU8v56l7Prjuaf4i7o5sSuNA77p5+7QCYEWW0zyvUVIJ86otEj69E+RxqNN NVZKCiYAJld1YSIWXqJZCHkcGxaS5Vo84LWazoT1VdOdHbaAhzKXLCg96vzmBsa9w0yc UPFrhFixcjBUbOV/Jt1BOYPZoZzNCjiHb7/9W3ezznIAIFsl5M8w+/icOYyV+7aJXx1Z /A728BlfGK/mf4GU3fqioXMQlIuNIouIe8uRrExFp+PF3rycwcxecboLyaumB/egy/sB SFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ldyqt2mSXXrEosQOvqIK5dNWaqrseYntTJhs+D88oGk=; b=YcVXzvwX02AXXTNe1kolpc4mkGyjwmH9LCwohQGLI94r9t3I/Mdn9HdzJ61f8+N4Yn yZbmPCT/XLZw4kKP+dqBgIUN3rNvAUiZ1HmVs0bsMGHtA8BIBKPszrZAfAy+qzhMEyVG PQjpL74IaAG2ldiTwbtfsvYdjQXjV7QhZush0rr9bPNNTQbCIsTERY7X6uLgg0VU4wOR quHG+9VeqHClWxKFj968vnMltmTcABHViSm9u5nbqQ/J7hT/QsY+WL9cicTJSJGQtgUv AaJxqaq1jX3jBD2CbtvjYXX0NaKqLcWE3nKKOTQrYhyawy4dSfHm3bET/6u+vn8kYzFU a95Q== X-Gm-Message-State: ACrzQf1Of7TDvaNm+ogbTwTSbhtk+Sqqi71lJZtT+FQrLSd+jsxx7Cp7 mw5bSkBYXEzgdzrd2Ds3dPw= X-Received: by 2002:ac2:5c4e:0:b0:4ab:db5d:10ee with SMTP id s14-20020ac25c4e000000b004abdb5d10eemr20180736lfp.142.1668001348804; Wed, 09 Nov 2022 05:42:28 -0800 (PST) Received: from curiosity ([5.188.167.245]) by smtp.gmail.com with ESMTPSA id du9-20020a056512298900b0049465afdd38sm2232452lfb.108.2022.11.09.05.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 05:42:27 -0800 (PST) Date: Wed, 9 Nov 2022 16:42:27 +0300 From: Sergey Matyukevich To: Atish Patra Cc: linux-kernel@vger.kernel.org, Albert Ou , 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 , Will Deacon Subject: Re: [RFC 4/9] RISC-V: KVM: Improve privilege mode filtering for perf Message-ID: References: <20220718170205.2972215-1-atishp@rivosinc.com> <20220718170205.2972215-5-atishp@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220718170205.2972215-5-atishp@rivosinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Hi Atish, > 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. > > Improve the privilege mode filtering by using the event specific > config1 field. ... [snip] > +static unsigned long pmu_sbi_get_filter_flags(struct perf_event *event) > +{ > + unsigned long cflags = 0; > + bool guest_events = false; > + > + if (event->attr.config1 & RISCV_KVM_PMU_CONFIG1_GUEST_EVENTS) > + guest_events = true; > + if (event->attr.exclude_kernel) > + cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_VSINH : SBI_PMU_CFG_FLAG_SET_SINH; IIUC we should inhibit host counting if we want guest events: cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_SINH : SBI_PMU_CFG_FLAG_SET_VSINH; > + if (event->attr.exclude_user) > + cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_VUINH : SBI_PMU_CFG_FLAG_SET_UINH; Same here. > + if (guest_events && event->attr.exclude_hv) > + cflags |= SBI_PMU_CFG_FLAG_SET_SINH; > + if (event->attr.exclude_host) > + cflags |= SBI_PMU_CFG_FLAG_SET_UINH | SBI_PMU_CFG_FLAG_SET_SINH; > + if (event->attr.exclude_guest) > + cflags |= SBI_PMU_CFG_FLAG_SET_VSINH | SBI_PMU_CFG_FLAG_SET_VUINH; > + > + return cflags; > +} Regards, Sergey