Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1656320pxb; Fri, 27 Aug 2021 14:15:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFRQ1W+AsgeLSTtXarqgRrWFcxFSBb1cVRmsyGjO2fPT87aUFzJoQcQxLsImgQo1dCSVqj X-Received: by 2002:a17:906:d541:: with SMTP id cr1mr11830313ejc.81.1630098937035; Fri, 27 Aug 2021 14:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630098937; cv=none; d=google.com; s=arc-20160816; b=qf4uYJqFWLXvS8zDHnS6qKy1++mY1tPY1NmJF6S83GR9Km53dvNusclRvH5hAfrCWc sR1sTWkCAJ3m2FopDKxg55hHU0CbTAb9ugzt7L2ooMEcL643FEkBytOX0ssZU+xO89uA p2PzmEdNAHqYKIFcODiYTiZVDs95/Fv0d6iRF7sx1ohEdA21hKOBmbUEWssz3TSTdKGL WWIluNMRJPe07+Tj+nq83PKicZERocmESHTxLv2SZv4Sp3bFoinl2xEGfoVTsFqqq5r7 NqxEY9id37go+mQfSQ/Os5b/qPVPrnTo69GYOsLBMyGUSTMONOmCkvXwR4TDDP7gjiLf NgHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:cc:to:from :date:references:in-reply-to:message-id:mime-version:user-agent :dkim-signature; bh=SYa7IwtKy/hySPEPwhbrAnIr4fljsXfq0PeV1S/c9oE=; b=AUqs33NDdXTDcm9eriMUy2FDTY4dPW+Fci45vnCc6lZAOqOcuOy9ovkl2aN9uiiGRi IHDKWozZfOo5lO1+Gm9lSgQmRkhp1tCGWRDp4G6ezo7Nnp3ptB/4p4QCBeyp8xOPdFp8 vRAKod/dVKjgYJkuycuSWdLl9I7/P4Sf+Y9ssrDiwl28800C1cCcwbqwXrSJRbaxYXJU 11nnlI2AylogTH/Bgs1JjO4Bbw2bHJmrORRL9XR703+H4OpyoWhcsHrCelb8xidWqUPa QjggW6MTC7wpcp4WG85qnyPlUuTHR7Rm5N84DCZ0DYrpv62ggmmq3T/e79SMGZbSe5Rx X+7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Um3Zag09; 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 r24si7408217ejy.432.2021.08.27.14.15.13; Fri, 27 Aug 2021 14:15:37 -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=Um3Zag09; 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 S231845AbhH0VL5 (ORCPT + 99 others); Fri, 27 Aug 2021 17:11:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231570AbhH0VL4 (ORCPT ); Fri, 27 Aug 2021 17:11:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3821B60E78; Fri, 27 Aug 2021 21:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630098667; bh=0J24TIWf8un+7BNgVI6ycuS4d2s9YAG3kZ6HY1i/HO0=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=Um3Zag09FUrqeeBy8h8bw/Dq9pfj83Oac5gjtk2iNXPqrbZRBiHAzbJb6Ne+f9mKF dxwifgj7U1VMFioh1/McZPcjNt/H08BTn5z0UGYzJv70mhfjeQ2qvNQoup2k6dBmmb nEvxJCfcWDQwMYszsMOyv3EwycPOruIhvFILTselPDsguTo956zceTgD5/ac8VzrBv hM75CBvFavx+J1j/gcIwvaFNYmWoKJ1ZzdPCdCa2CUG19Q5MyAVQA4Fuy+EwcsOqUS b9qwAChEu3uLyyUYCgMfP0w0xISCnwPx6KnxRfrgFcPhI+/XMlp/WSw8fkhBIVieNK 3RXhLEbuenPSA== Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 5560927C0054; Fri, 27 Aug 2021 17:11:05 -0400 (EDT) Received: from imap2 ([10.202.2.52]) by compute6.internal (MEProxy); Fri, 27 Aug 2021 17:11:05 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddufedgudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdet nhguhicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenuc ggtffrrghtthgvrhhnpeefheekleetudffieethedtkeegfeevjefgvedugeevgefhtdek jeevhfdutedugfenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhkvghrnhgvlhdroh hrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegr nhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedukeehieefvd dqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinhhugidrlhhu thhordhush X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2F5CAA0378F; Fri, 27 Aug 2021 17:11:03 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1125-g685cec594c-fm-20210825.001-g685cec59 Mime-Version: 1.0 Message-Id: <43b3a838-da8a-4733-9832-f3d5f990ec13@www.fastmail.com> In-Reply-To: References: <20210728230230.1911468-1-robh@kernel.org> <20210728230230.1911468-3-robh@kernel.org> Date: Fri, 27 Aug 2021 14:10:42 -0700 From: "Andy Lutomirski" To: "Rob Herring" Cc: "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 Subject: Re: [RFC 2/3] perf/x86: Control RDPMC access from .enable() hook 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 Thu, Aug 26, 2021, at 12:09 PM, Rob Herring wrote: > On Thu, Aug 26, 2021 at 1:13 PM Andy Lutomirski wrot= e: > > > > > > > > On Thu, Aug 12, 2021, at 11:16 AM, Rob Herring wrote: > > > On Thu, Aug 12, 2021 at 11:50 AM Andy Lutomirski = wrote: > > > > > > > > On 7/28/21 4:02 PM, Rob Herring wrote: > > > > > Rather than controlling RDPMC access behind the scenes from sw= itch_mm(), > > > > > move RDPMC access controls to the PMU .enable() hook. The .ena= ble() hook > > > > > is called whenever the perf CPU or task context changes which = is when > > > > > the RDPMC access may need to change. > > > > > > > > > > This is the first step in moving the RDPMC state tracking out = of the mm > > > > > context to the perf context. > > > > > > > > Is this series supposed to be a user-visible change or not? I'm= confused. > > > > > > It should not be user-visible. Or at least not user-visible for wh= at > > > any user would notice. If an event is not part of the perf context= on > > > another thread sharing the mm, does that thread need rdpmc access?= No > > > access would be a user-visible change, but I struggle with how tha= t's > > > a useful scenario? > > > > > > > This is what I mean by user-visible -- it changes semantics in a way= that a user program could detect. I'm not saying it's a problem, but I= do think you need to document the new semantics. >=20 > 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]. >=20 > 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 be > 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 y= ou check that you=E2=80=99re on the right CPU, do RDPMC, and throw out t= he result if you were on the wrong CPU (determined by looking at the mma= p), you still would very much prefer not to fault. Maybe rseq or a vDSO helper is the right solution for ARM. >=20 > Rob >=20 > [1] https://github.com/deater/perf_event_tests > [2] https://lore.kernel.org/lkml/alpine.DEB.2.21.1901101229010.3358@ma= cbook-air/ >=20