Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3918014pxb; Mon, 30 Aug 2021 14:00:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpt2aDziCwl+rGGp3bF1CB8cjXp4ZtctRPPu6YIF+ENSEjVsbNZ89ddj022JkAxJWTpSix X-Received: by 2002:a6b:2b97:: with SMTP id r145mr20054964ior.193.1630357204293; Mon, 30 Aug 2021 14:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630357204; cv=none; d=google.com; s=arc-20160816; b=0GE7sydxFg+pza/9SRGKcs6tDdGssEBFZL8X9+TPtsuGW9TIlQpxcXvvIycXmX7HfU 0E5fFDnJZ/ieSp9WQc2V93L2CihERAm6XsRj3jxCryqJ6OlOwFtOWVKtafWKm44jNd+E NTyyKX5vBQjdv53R9flTihby8R85g0OO2afZvii6z5lrzXMUBwClhzMfF0NJwX6Hd3ez tReos/r1mDeVgHv5BMdbbszYKrcpplGLrtHeQdYeSkPkp4WMOiudwi0WZ5Z18QVNek5W tmi1pC1Jtu2PNvIal00mdJTLuP9DNZcfCOXvwICJDaBlGIttzqBiW/moGFkv+mF7/aVM nPDw== 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=RFGBG+aAh2nz5E9U/NrxmSYLG9uqwOYCa51Li9WHU+A=; b=ysu68FmwoHL1l9We3aGUjWx6bT43NoHitraUXWyZrdpNEy3ZaD8UZe9mCisFolHscn HgFVIU3d1WxGCEXFfjY3lH9an3sHsMPiMD0/jxIqa4fQ/5BsIXyavWrt/+KxQ6aE9Beu BMZWWf7j/GZhggH4n2IHeoNG4aV7LgrxzgZ8WCPL+Ls35DUyDAlO0D9dYbhhavX35SFH +wY+4/Vm6HAZKND0FOj9QVLXb6W62O+/eTaY16GAyQVbVw0UP51qQ6vpcSE6Wq6ucVFc butb+X/QlzdsaValAhWJJi9+TYPOdMKlMmK6inPIdxVOxf97J/d74wurPGofUgyqTtEM GaUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZW1NbJsa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o4si13591060iom.0.2021.08.30.13.59.53; Mon, 30 Aug 2021 14:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZW1NbJsa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236527AbhH3U7g (ORCPT + 99 others); Mon, 30 Aug 2021 16:59:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:37890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235898AbhH3U7f (ORCPT ); Mon, 30 Aug 2021 16:59:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4D6E461008; Mon, 30 Aug 2021 20:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630357121; bh=sTRehZGcYy+Yc7uLDclFNF91ENgqtbr7oENyFmAL5TU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZW1NbJsaPxeE7G5eUXY+YvTgTHsC5BcI5HhA53AZnIUxN61WucGdEZyNOkwf43dus x8CqUcZxfhKwamEa7FDiPFcDASHJJrVNzQdvXdngPulDRdguLJrxi3xukWuVJ0VP65 zC4ZleNjRs7uufQnxNxNkjNxlD3kzcdEEwFu2BSz8V6eX68/CLMyBDoZ6D6z7ZRzvG LpCLXzfyAPGm0G2af9QzY47U1SeszKGDgZB64C1FFPR9hrFghX/Ez9FWIIqHIHU2+t MLfckrP944o6IXWpOdb6UgCAga/4CD7xaxl6nsAm1bvT0Xh/+hbUGIyXjshbcD9FXW JBYPSqD/arLoQ== Received: by mail-ej1-f51.google.com with SMTP id h9so33982445ejs.4; Mon, 30 Aug 2021 13:58:41 -0700 (PDT) X-Gm-Message-State: AOAM530Pc01oLNv/fBgK8kSJfHvXHBbMV/7CYgJ1h/21R89uumfKQhTX cOafhCTrwmAR/B/znj+VL855I8ah6o7n5BLfsA== X-Received: by 2002:a17:906:1cd0:: with SMTP id i16mr26673334ejh.360.1630357119849; Mon, 30 Aug 2021 13:58:39 -0700 (PDT) MIME-Version: 1.0 References: <20210728230230.1911468-1-robh@kernel.org> <20210728230230.1911468-3-robh@kernel.org> <43b3a838-da8a-4733-9832-f3d5f990ec13@www.fastmail.com> In-Reply-To: From: Rob Herring Date: Mon, 30 Aug 2021 15:58:28 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC 2/3] perf/x86: Control RDPMC access from .enable() hook To: Vince Weaver Cc: Andy Lutomirski , "Peter Zijlstra (Intel)" , Mark Rutland , Will Deacon , Kan Liang , Linux Kernel Mailing List , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , "the arch/x86 maintainers" , "H. Peter Anvin" , Dave Hansen , linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 29, 2021 at 10:06 PM Vince Weaver wr= ote: > > On Fri, 27 Aug 2021, Andy Lutomirski wrote: > > > On Thu, Aug 26, 2021, at 12:09 PM, Rob Herring wrote: > > > > After testing some scenarios and finding perf_event_tests[1], this > > > series isn't going to work for x86 unless rdpmc is restricted to task > > > events only or allowed to segfault on CPU events when read on the > > > wrong CPU rather than just returning garbage. It's been discussed > > > before here[2]. > > > > > > Ultimately, I'm just trying to define the behavior for arm64 where we > > > don't have an existing ABI to maintain and don't have to recreate the > > > mistakes of x86 rdpmc ABI. Tying the access to mmap is messy. As we > > > explicitly request user access on perf_event_open(), I think it may b= e > > > better to just enable access when the event's context is active and > > > ignore mmap(). Maybe you have an opinion there since you added the > > > mmap() part? > > > > That makes sense to me. The mmap() part was always a giant kludge. > > > > There is fundamentally a race, at least if rseq isn=E2=80=99t used: if = you check > > that you=E2=80=99re on the right CPU, do RDPMC, and throw out the resul= t if you > > were on the wrong CPU (determined by looking at the mmap), you still > > would very much prefer not to fault. > > > > Maybe rseq or a vDSO helper is the right solution for ARM. There was a version using rseq[1]. AIUI, that would solve the reading from the wrong CPU problem. I don't think using rseq would change the kernel implementation other than whether we enable events on specific CPUs. > as the author of those perf_event tests for rdpmc, I have to say if ARM > comes up with a cleaner implementation I'd be glad to have x86 transition > to something better. Thanks for chiming in. My plan is to be more restricted in terms of what works, and fail or disable user access for what's not supported. Unless I hear events on specific CPUs is really important, that means only monitoring of a thread on all (for big.LITTLE, all homogeneous) CPUs is supported. That doesn't require a better/cleaner interface. It just means cpu must be -1 for perf_event_open if you want rdpmc. The difference on Arm is just that we can enforce/indicate that. We could also enable CPU events, but abort if read on the wrong CPU. The user in that case either has to control the thread affinity or possibly use rseq. > The rdpmc code is a huge mess and has all kinds of corner cases. I'm not > sure anyone besides the PAPI library tries to use it, and while it's a > nice performance improvement to use rdpmc it is really hard to get things > working right. Yes, I've been reading thru the bugs you reported and related tests. I just wish I found them sooner... > As a PAPI developer we actually have run into the issue where the CPU > switches and we were reporting the wrong results. Also if I recall (it's > been a while) we were having issues where the setup lets you attach to a > process on another CPU for monitoring using the rdpmc interface and it > returns results even though I think that will rarely ever work in > practice. Returning the wrong results is obviously bad for the user, but making that "work" also complicates the kernel implementation. Rob [1] https://x-lore.kernel.org/all/20190611125315.18736-4-raphael.gault@arm.= com/