Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3950061pxb; Mon, 30 Aug 2021 14:42:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOtWCkn8xsF/ZA+8QO19hp1vceUcLUSQBMWHH6ZwEYsoAcgTvEphWSFXBSwNnSjYf7VH/n X-Received: by 2002:a17:906:39d5:: with SMTP id i21mr27149474eje.529.1630359750338; Mon, 30 Aug 2021 14:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630359750; cv=none; d=google.com; s=arc-20160816; b=CFAqnaIPW8KTBtTyoOCTbmxv/JucufkukRrAfyVGkkIDMhEDd4vvlpbq6cVPOeSZ/k YJ0S9H/Q9mOFxlApnnHya9XHkoEyMuMyg83vK6u7Es/H8hi8M+kAqMRzhMWlHlU0z1lK 8vyguZsh8KEphSwH1ssgYWBUzYA85wLQ1tkWziNFCaDIppQeFVTcyz9a7UrPLh8ySjXB bGKhJA/4RsD2QrcyvlIbjPXzHMA73oDO9GN8sH/AEB0LVsGmeWg40uEPuPygUL3gutuA bN0c1k1Gi/a29AdIQtEGQgviRFdfM5XiWhTj+84Ia9Q+a28b2Rs5uJA5CVKj9PrdJ4gW 9ulQ== 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=gxNsN3JR3wvMNYOPhsJlXnAPJgXUz9O/gatdt6hHt98=; b=NFInF8gC/+xu+8RXL9iTszPlV/XeHuWE+ezwoNQKnjZ2ea/eTQ1QrVjlZfXKwEm9T8 i2/yW0a6S288UcIVFwREgnTeoi4P4BcBxkZdiRu9W/AwebsCBMRe1j34BsC4kzq+yWVO PgKNg2OtpNFhLNa6bqL7FNWxFnBUeNUovlTQz78U/CoxiLEox+a024vhC6aGEm4IDFfd iOp6W2z3n91+W8p7Rp6QJ28OGwwBzC/oVVgC9muEy4/6g6B2TzbBa5yrvKoVJxWr79fi PTSsmeFZTUAeGlkszdXK7SvM5Mc4sUyokfvsRF5oBAr0XPvkwG3L1CUWbPUH8tkqQ2ce 6syw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hak1fDsY; 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 ne10si7661263ejc.93.2021.08.30.14.42.06; Mon, 30 Aug 2021 14:42:30 -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=Hak1fDsY; 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 S238266AbhH3Vlm (ORCPT + 99 others); Mon, 30 Aug 2021 17:41:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:56558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237296AbhH3Vlm (ORCPT ); Mon, 30 Aug 2021 17:41:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2D38D60F42; Mon, 30 Aug 2021 21:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630359648; bh=SzO1R52+ZB+6kqt/cDT852NMK8dI6tMtqvLALi8Kxds=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Hak1fDsYnfPaKFY1JIjEueAOgawlGC0S2HgsT97Y8rpGcjSvaFpNwXHXD3JUvKXLw TquSc+bthbdVlt6WazZOFj4Dt6V/lKOKw0VPsEJFEoW5paMbnL83/EAWrBjErok/00 1vEl7BZFe7nyTDYqVDhPrLPqKIQIXRFI/ZXPw+OxmReX2fYoa/vRp2dW0mOa7/vfDG 5ipEzepz188NXry20yFlekCBMmQtKALtS1jsMs/TnQ4J5SUHxF2X1tDtH+vrOhLyq3 3DCfw7T4mDZCsLGxazIc9/qJi1m/aOFs/0VXH9uNKeF1TuoItD5ZYvmy92CI3vSaB0 UewWKMCWv48hA== Received: by mail-ej1-f52.google.com with SMTP id ia27so34166528ejc.10; Mon, 30 Aug 2021 14:40:48 -0700 (PDT) X-Gm-Message-State: AOAM530YHPI8Qn3jF0ltSLn3vvEs008MKM14MASaJB2JSgxgUzVQ/UtH 8vBl9xQGVfQpfW1SJKhWLnwj8PC1mmPyxdHiUg== X-Received: by 2002:a17:906:8cd:: with SMTP id o13mr27805604eje.341.1630359646777; Mon, 30 Aug 2021 14:40:46 -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> <20210830085106.GF4353@worktop.programming.kicks-ass.net> <0b794c5-5988-c79d-7bb-11533ed92a9@maine.edu> In-Reply-To: <0b794c5-5988-c79d-7bb-11533ed92a9@maine.edu> From: Rob Herring Date: Mon, 30 Aug 2021 16:40:34 -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: Peter Zijlstra , Andy Lutomirski , 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 30, 2021 at 3:21 PM Vince Weaver wrote: > > On Mon, 30 Aug 2021, Peter Zijlstra wrote: > > > There's just not much we can do to validate the usage, fundamentally at > > RDPMC time we're not running any kernel code, so we can't validate the > > conditions under which we're called. > > > > I suppose one way would be to create a mode where RDPMC is disabled but > > emulated -- which completely voids the reason for using RDPMC in the > > first place (performance), but would allow us to validate the usage. > > > > Fundamentally, we must call RDPMC only for events that are currently > > actuve on *this* CPU. Currently we rely on userspace to DTRT and if it > > doesn't we have no way of knowing and it gets to keep the pieces. > > yes, though it would be nice for cases where things will never work (such > as process-attach? I think even if pinned to the same CPU that won't > work?) Maybe somehow the mmap page could be set in a way to indicate we > should fall back to the syscall. Maybe set pc->index to an invalid value > so we can use the existing syscall fallback code. > > We could force every userspace program to know allthe unsupoorted cases > but it seems like it could be easier and less failure-prone to centralize > this in the kernel. > > I was looking into maybe creating a patch for this but the magic perf > mmap page implementation is complex enough that I'm not sure I'm qualified > to mess with it. There's now an implementation in libperf[1]. perf_evsel__read() will use it[2] and fallback to read() call if necessary (but will still happily give you wrong values if reading on the wrong CPU). Rob [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/perf/mmap.c#n302 [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/perf/evsel.c#n305