Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5090246rwb; Mon, 21 Nov 2022 16:38:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AKzPsvz/rtPzbVTzQpZO92Fs2GKiRoAIQ/NT4X92/zPsnYTGSUNstb8fmk9TVwQ4HCJO4 X-Received: by 2002:a17:906:3953:b0:78d:39ac:3129 with SMTP id g19-20020a170906395300b0078d39ac3129mr18399452eje.24.1669077525142; Mon, 21 Nov 2022 16:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669077525; cv=none; d=google.com; s=arc-20160816; b=MOH1xn1eqmvC6W7RfIJJ7kL8Trc0Veihg5wOirdnE0tf4OgILW9h3O7W8ixeZ66SKc +idiFOqb1svzIG4Idqjf7aubGV9hyIsiJ1U/H3iB4PdyrW4ubLfGpCmPEYP0f3+g0rmk OxQ0j4F1G3Vqh/IEufEmYSbgWVSw7MNMqxkJC3buCDq1mONaM66acei6ED1/egDth1RD aCfA8x7mGBs4bzpSXkai6yQlTgjg43pyhzEyyiPpGgEbBXwUsOn2C1FexOGURTIK+kWj o3jvTKrHO+J96F4rL6hFB9kgE4PoLwS3VvMujhG6V39BUeifxoG+IZfN8jntvSu4yYBY Scuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8ioT5HWkxXrDzWROXcjL6RfDxD0eZFMTpXcJlr218K8=; b=b/l9UY8mlubD3DNTlOKjJ4hDqAgcy4q950EzSrnxx/LRE5Zt80IZHwKNAgiP8Bv4qX F7DSmUCTH86mC63r2RG3v+mQ3/AiRaS27fN8sZnPoh9tndKZmL9kRNMDDa1bxtMjSF8W v1soby0GkwxpxBDn8PAodtXmysXLlYY+A42a7wZUpWxF0TmBIiB4L+tkQzxEMVuvbCq3 4NWAdPXMbU61U1bhVhzhb3uxAHPNECJ2UowvqcBDXRAVWVV9C8jluoRJZEJJsNCXwNWM rk23W5J1xxF1bt1YDnO+GlYfkSb6DwfHG0ZxyIMzdzT1xuSV+ADwE38CUPSto9cPEg32 +uIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=iYjmeDp3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g23-20020a170906349700b007ad69eba328si2671808ejb.539.2022.11.21.16.38.23; Mon, 21 Nov 2022 16:38:45 -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=@atishpatra.org header.s=google header.b=iYjmeDp3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbiKVAWG (ORCPT + 91 others); Mon, 21 Nov 2022 19:22:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbiKVAWC (ORCPT ); Mon, 21 Nov 2022 19:22:02 -0500 Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6889E09F for ; Mon, 21 Nov 2022 16:22:01 -0800 (PST) Received: by mail-oo1-xc2c.google.com with SMTP id j6-20020a4ab1c6000000b004809a59818cso2045619ooo.0 for ; Mon, 21 Nov 2022 16:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8ioT5HWkxXrDzWROXcjL6RfDxD0eZFMTpXcJlr218K8=; b=iYjmeDp35xqIzxQZueXI5DTZPLBzYLZ5PAM/AQvCGEF1SjrTAhxQ6zziaTWWvV5ylD gm9NdiH5PB24JSy6RsceIWUrOZkmtw1Yn8f+tLuh5EqgCZvzvNDQb4LcyMdSMx85yr42 aPkH2xlJPnvcO8lJA6xc3okcK5790tK9JWuOU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=8ioT5HWkxXrDzWROXcjL6RfDxD0eZFMTpXcJlr218K8=; b=YA/0frB2+jwah2gskXgyz1+ebe7wi6p1PifgWf1P7BnGX1X0XIkwDLQ38hLdAw8eGH mzcLIx/K1oG9CWLBEUfayMcpt5QtIV4I++oQHmhJW80uuAndJJVO9IHASOO4ok8mi7+a lY197Wx0BD+lKhUq5cyI1/wgeHoKHasy5qbz9plW/NbqCKON2G8z491qt16R3cBTsU89 NwkEfnhsTC1OyD5XuMGimKrI9Z4yijIrtY8swx+38057NalwKXYdnDvUA7blk90bnur+ q31aksZ1xGnl4/2vY8l8Qx1S0UWcQ1btZV1xDFrVRHirCCWVi9noKBo0Dg5hv+IYK3F/ wuEg== X-Gm-Message-State: ANoB5pm10vR9cAHHm4O8BU+eZFVXlZeqJGFxOZq38PXxtqdWNPiWiU6Q 5UbPRXiE7FGpGAGsV7sHUxuJyKkZHIF+V3ehGtGy X-Received: by 2002:a4a:c58a:0:b0:49f:4297:5612 with SMTP id x10-20020a4ac58a000000b0049f42975612mr1713954oop.13.1669076520677; Mon, 21 Nov 2022 16:22:00 -0800 (PST) MIME-Version: 1.0 References: <20220718170205.2972215-1-atishp@rivosinc.com> <20220718170205.2972215-5-atishp@rivosinc.com> In-Reply-To: From: Atish Patra Date: Mon, 21 Nov 2022 16:21:49 -0800 Message-ID: Subject: Re: [RFC 4/9] RISC-V: KVM: Improve privilege mode filtering for perf To: Sergey Matyukevich Cc: Atish Patra , linux-kernel@vger.kernel.org, Albert Ou , Anup Patel , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 9, 2022 at 5:42 AM Sergey Matyukevich wrote: > > 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; > guest_events indicate that the user in the guest VM is configured to exclude the kernel i.e. the guest kernel which is running in VS mode. That's why, we have to set SBI_PMU_CFG_FLAG_SET_VSINH To inhibit host counting, the user needs to specify exclude_host and/or exclude_hv which happens below as well. > > + if (event->attr.exclude_user) > > + cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_VUINH : SBI_PMU_CFG_FLAG_SET_UINH; > > Same here. > Same explanation as above. > > + 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 -- Regards, Atish