Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp88233pxb; Thu, 12 Aug 2021 11:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwp6KLz7iDlYeXVZ/U8xcMKX47Kk3ARrSJBT8c63wzC/wnd5x63qECowjVFkzWriyeqSDux X-Received: by 2002:a92:4b01:: with SMTP id m1mr1562802ilg.50.1628792713486; Thu, 12 Aug 2021 11:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628792713; cv=none; d=google.com; s=arc-20160816; b=Bwr98b/7EAFRtSg4WbW1N3QWGg+vNa1cWddeKl6uujkwyK2P24KDzCvFWwOn5cQvdT cChN5es3oCKs2nvr9yu8Diwb9uhspyTv4xMWqGC7JgaikaKpQqdlexW2guULx2qP4deR 7Dk54UwBTckZ49FizzsXKI6MtAVY31p8XMGX4xnvSZErDuxVR4Qm0aSSTnpcgDkOxBoQ ZmvYFB8wjmf+fXJDOSvOTSfgIIFW67SqqCCM9nCydAcYznfk9Hgm8h+VjbGPAZxrXqy7 3cNgqYMn3FHwW3ChgP9H+qYWJzFu/VrJ5LJh6/Jt/jd4EE+bu1YjoRmotnn3O0dsTgKl q6xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=BTP/DqMnmN/FFdVWCyk3iF8tdRwVuE1XPvk/T7uWZjM=; b=ryYviChMMgli2/54rgA2/ErM0cdmx1DDiQ3w2uDJqNysc80j0jR5Nqf4NOVMqWtQaf 7gkj/fcfwvV8X4+kMwA7bUKpXJ5n4XBqO/JTfQN3y57cOzGY0F0wRkjKRQC84vvzxfcW 4wscSxgWdwLh6T6M+tSSwZEIxt8VPHoYjgrLXrat+WeXybYAc1IPbBxqNigSzBwMoQd6 vrAir25VDBBcGoFIzJPjKBVy0iVUHLRZZPTU0IzSawAmzJsv42vIZCivykQPd/0rUx4F mjzY3Pk9n+diIF8nHI9mmOrlOsc25wziYyOg0XfQcLSsDZG7mTRLvzGRIlEPVq0eJD0l x57A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pt+GzlIW; 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 p9si4356478ilo.104.2021.08.12.11.24.46; Thu, 12 Aug 2021 11:25:13 -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=pt+GzlIW; 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 S233482AbhHLQvJ (ORCPT + 99 others); Thu, 12 Aug 2021 12:51:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:35644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233442AbhHLQvJ (ORCPT ); Thu, 12 Aug 2021 12:51:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EEEB160F57; Thu, 12 Aug 2021 16:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628787043; bh=MMQsxh6VWVq+fupL985dZZlxsg7x7bCSJmg0HZ5KAPI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=pt+GzlIWPUjvN1FKuS5Y2/IT/zDean7E5jRFJMDVSdForr8hHIkFcvxvIgA1VLxr5 pCdN8z00KhbjHiAA4irL4DFIfFrkNwygyuY6uBv6V0rRCvfnV7XcHbYbAXxI8zlFIh WNC2/eOQy6Ql9nKTNxoA2m4yhbJ9AMxX2IE3nBrOUc9czsoAkh5+522i9Ls1Bd80x9 QEgqgWdXXx0HGNZa5q968gd6UF/+4XrH/jdFZi0de4rMIeXbG23lCX51NKut68f/NO muWhaLjjPWfBhhYuJqCvFaZlkfmA0nxNijwNi0WjY+k+ywxi/JjQy1Ejfvu4bKjIzQ obGlL6971gNAw== Subject: Re: [RFC 2/3] perf/x86: Control RDPMC access from .enable() hook To: Rob Herring , Peter Zijlstra , Mark Rutland , Will Deacon , Kan Liang Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-perf-users@vger.kernel.org References: <20210728230230.1911468-1-robh@kernel.org> <20210728230230.1911468-3-robh@kernel.org> From: Andy Lutomirski Message-ID: Date: Thu, 12 Aug 2021 09:50:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210728230230.1911468-3-robh@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. 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. > - on_each_cpu(cr4_update_pce, NULL, 1); > + on_each_cpu(x86_pmu_set_user_access_ipi, NULL, 1); Here too. > 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? > > /* > -- > 2.27.0 >