Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp655597pxb; Thu, 26 Aug 2021 11:14:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhe7cyIjOQg5kXO7W7sXHEwQRITlnKZPxXVfrOsr4HZ0Spa+LltFM21m8V6MnrZZSUkYYG X-Received: by 2002:a6b:611a:: with SMTP id v26mr4024863iob.93.1630001678591; Thu, 26 Aug 2021 11:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630001678; cv=none; d=google.com; s=arc-20160816; b=JIZIk4qRUOC7E4c/+/OekTC9Zuq3LSIPaZmtOn71NR3RcUw3SpaqkeSJVoWk9nblZm 6tuOVvgrqogwMJ3wdVWSw7/hObYPMN0GdHwv2Kq6/HTvz7opxsgERFVt6DbmBIx5aaTP 2xwDG4xewEBuIxXaHp8806wJVd0eeATRuxJaCFv6Dep4i/NRA4J8PO7SGiFXMO2KBkGP a7SCgcl56D51zVYxqc7MjoFwnY5s8yynDhbz65JOGtlBIv79RDGUGaaCnp/pXpShkTGf ZDR2w2Ybr1ImIzypVh6sGzuKM5S5niM0ZHHiOr6KxP4gKgzrO1mxuvNiSUruTtAqg56o hTJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature; bh=8rzjS9PM5v2tsISg5uJ1DratRPPT42Uqln9bFGV9xVc=; b=KdjLgdiNJB0DNOY/fJ3nh8OiXfP0T5QNwF8qPNv84/NtownlvODykxKhu/j8eJAgYs 89h0a1EAZu1/8G168hQQApqhrzQXSIa3R/hoLEl77HX/LGKIZJxNg+eQ2Afa6Ucom2X5 tX0mwI2NfBhcnEmZiII5TmxRpUuNYfZDeEoK7xBGNICgq8XQ/bm1u2UY+Sj5ZelgB8KR Q9pZZB2bfISl232ZJ5mM/22dkSzJCRL5o76btGosNXN9myjqebW+dymyukW/bK9A70kQ vmbDyXDgdo9GD2Ig1ap9LAwjx8Uyz6TPfnSK6u/7QC2yAzyJdbUc23oQi48G0igba/99 B9IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W0Hd9XkS; 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 v2si3873535ilc.51.2021.08.26.11.14.26; Thu, 26 Aug 2021 11:14:38 -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=W0Hd9XkS; 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 S243288AbhHZSOZ (ORCPT + 99 others); Thu, 26 Aug 2021 14:14:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232729AbhHZSOY (ORCPT ); Thu, 26 Aug 2021 14:14:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2BEDD60F6F; Thu, 26 Aug 2021 18:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630001617; bh=GvW56A0ZymucrY95tyZXDlzIi82R/2MAGmWEC9QRdAo=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=W0Hd9XkSSc6vmGqZ8tWTeocudyEtjLr/ApmiemqwEmFooZXvQKPP1wTkrkheEld12 obpEGAO75IC7VGvhNz0Z2O1wKcpuk2jH6Owkvmse2DrDTc8ajHYLAPy2C7BEp4Xa0P 7o+ket8yNl5w0bLFuCP4RrkIlsFi6YZQb2feFg1eodG93JzTZmDOTnjxzQtiBI8f5r i1v2dZIkTR5sukjPsReS6FALTthMn9Wb3Yvi0xKN3KDj1nMvrFYuwFRcGSFBvTnw4S DE3/F6Q6HFVzRqqaadVg83tOBVUmQafavZb7u9mh8XKygi/p5Yvl8fw4Da2FMFQtgH cVXxsWrZNKeAA== Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 49DC127C0054; Thu, 26 Aug 2021 14:13:35 -0400 (EDT) Received: from imap2 ([10.202.2.52]) by compute6.internal (MEProxy); Thu, 26 Aug 2021 14:13:35 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudduuddguddvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedftehn ugihucfnuhhtohhmihhrshhkihdfuceolhhuthhosehkvghrnhgvlhdrohhrgheqnecugg ftrfgrthhtvghrnheptdfhheettddvtedvtedugfeuuefhtddugedvleevleefvdetleff gfefvdekgeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprghnugihodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudeiudek heeifedvqddvieefudeiiedtkedqlhhuthhopeepkhgvrhhnvghlrdhorhhgsehlihhnuh igrdhluhhtohdruhhs X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2A5E7A03DA1; Thu, 26 Aug 2021 14:13:33 -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: In-Reply-To: References: <20210728230230.1911468-1-robh@kernel.org> <20210728230230.1911468-3-robh@kernel.org> Date: Thu, 26 Aug 2021 11:13:10 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 switch_mm(), > > > move RDPMC access controls to the PMU .enable() hook. The .enable() 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 what > 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 that'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. > > If you intend to have an entire mm have access to RDPMC if an event is > > mapped, then surely access needs to be context switched for the whole > > mm. If you intend to only have the thread to which the event is bound > > have access, then the only reason I see to use IPIs is to revoke access > > on munmap from the wrong thread. But even that latter case could be > > handled with a more targeted approach, not a broadcast to all of mm_cpumask. > > Right, that's what patch 3 does. When we mmap/munmap an event, then > the perf core invokes the callback only on the active contexts in > which the event resides. > > > Can you clarify what the overall intent is and what this particular > > patch is trying to do? > > > > > > > > if (atomic_dec_and_test(&mm->context.perf_rdpmc_allowed)) > > > - on_each_cpu_mask(mm_cpumask(mm), cr4_update_pce, NULL, 1); > > > + on_each_cpu_mask(mm_cpumask(mm), x86_pmu_set_user_access_ipi, NULL, 1); > > > > Here you do something for the whole mm. > > It's just a rename of the callback though. > > > > > > - on_each_cpu(cr4_update_pce, NULL, 1); > > > + on_each_cpu(x86_pmu_set_user_access_ipi, NULL, 1); > > > > Here too. > > It's not just the whole mm here as changing sysfs rdpmc permission is > a global state. Whoops, missed that. > > > > void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > > > struct task_struct *tsk) > > > { > > > @@ -581,10 +556,8 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > > > this_cpu_write(cpu_tlbstate.loaded_mm, next); > > > this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); > > > > > > - if (next != real_prev) { > > > - cr4_update_pce_mm(next); > > > + if (next != real_prev) > > > switch_ldt(real_prev, next); > > > - } > > > } > > > > But if you remove this, then what handles context switching? > > perf. On a context switch, perf is going to context switch the events > and set the access based on an event in the context being mmapped. > Though I guess if rdpmc needs to be enabled without any events opened, > this is not going to work. So maybe I need to keep the > rdpmc_always_available_key and rdpmc_never_available_key cases here. You seem to have a weird combination of per-thread and per-mm stuff going on in this patch, though. Maybe it's all reasonable after patch 3 is applied, but this patch is very hard to review in its current state.