linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Erik Bosman <ebn310@few.vu.nl>, Ingo Molnar <mingo@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Kees Cook <keescook@chromium.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Valdis Kletnieks <Valdis.Kletnieks@vt.edu>
Subject: Re: [RFC 5/5] x86,perf: Only allow rdpmc if a perf_event is mapped
Date: Sun, 19 Oct 2014 15:05:42 -0700	[thread overview]
Message-ID: <CALCETrVT9vHjBRRvhTayqfOEebMjyVU9Yw7v80D6EPAmcyREZw@mail.gmail.com> (raw)
In-Reply-To: <20141019213341.GF23531@worktop.programming.kicks-ass.net>

On Oct 19, 2014 2:33 PM, "Peter Zijlstra" <peterz@infradead.org> wrote:
>
> On Sun, Oct 19, 2014 at 01:23:17PM -0700, Andy Lutomirski wrote:
> > On Thu, Oct 16, 2014 at 5:00 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> > > The current cap_user_rdpmc code seems rather confused to me.  On x86,
> > > *all* events set cap_user_rdpmc if the global rdpmc control is set.
> > > But only x86_pmu events define .event_idx, so amd uncore events won't
> > > actually expose their rdpmc index to userspace.
> > >
> > > Would it make more sense to add a flag PERF_X86_EVENT_RDPMC_PERMITTED
> > > that gets set on all events created while rdpmc == 1, to change
> > > x86_pmu_event_idx to do something like:
> > >
> > > if (event->hw.flags & PERF_X86_EVENT_RDPMC_PERMITTED)
> > >   return event->hw.event_base_rdpmc + 1;
> > > else
> > >   return 0;
> > >
> > > and to change arch_perf_update_userpage cap_user_rdpmc to match
> > > PERF_X86_EVENT_RDPMC_PERMITTED?
> > >
> > > Then we could ditch the static key and greatly simplify writes to the
> > > rdpmc flag by just counting PERF_X86_EVENT_RDPMC_PERMITTED events.
> > >
> > > This would be a user-visible change on AMD, and I can't test it.
> > >
> > >
> > > On a semi-related note: would this all be nicer if there were vdso
> > > function __u64 __vdso_perf_event__read_count(int fd, void *userpage)?
> > > This is very easy to do nowadays.  If we got *really* fancy, it would
> > > be possible to have an rdpmc_safe in the vdso, which has some
> > > benefits, although it would be a bit evil and wouldn't work if
> > > userspace tracers like pin are in use.
> > >
> >
> > Also, I don't understand the purpose of cap_user_time.  Wouldn't it be
> > easier to just record the last CLOCK_MONOTONIC time and let the user
> > call __vdso_clock_gettime if they need an updated time?
>
> Because perf doesn't use CLOCK_MONOTONIC. Due to performance
> considerations we used the sched_clock stuff, which tries its best to
> make the best of the TSC without reverting to HPET and the like.
>
> Not to mention that CLOCK_MONOTONIC was not available from NMI context
> until very recently.

I'm only talking about the userspace access to when an event was
enabled and how long it's been running.  I think that's what the
cap_user_time stuff is for.  I don't think those parameters are
touched from NMI, right?

Point taken about sched_clock, though.

>
> Also, things like c73deb6aecda ("perf/x86: Add ability to calculate TSC
> from perf sample timestamps") seem to suggest people actually use TSC
> for things as well.
>
> Now we might change to using the new NMI safe CLOCK_MONOTONIC (with a
> fallback to use the sched_clock stuff on time challenged hardware) in
> order to ease the correlation between other trace thingies, but even
> then it makes sense to have this, having it here and reading the TSC
> within the seqcount loop ensures you've got consistent data and touch
> less cachelines for reading.

True.

OTOH, people (i.e. I) have optimized the crap out of
__vdso_clock_gettime, and __vdso_perf_event_whatever could be
similarly optimized.

--Andy

  reply	other threads:[~2014-10-19 22:06 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-14 22:57 [RFC 0/5] CR4 handling improvements Andy Lutomirski
2014-10-14 22:57 ` [RFC 1/5] x86: Clean up cr4 manipulation Andy Lutomirski
2014-10-16  8:16   ` Peter Zijlstra
2014-10-16 11:18     ` Borislav Petkov
2014-10-16 11:29       ` Borislav Petkov
2014-10-16 15:32         ` Andy Lutomirski
2014-10-16 15:47           ` Borislav Petkov
2014-10-14 22:57 ` [RFC 2/5] x86: Store a per-cpu shadow copy of CR4 Andy Lutomirski
2014-10-16  8:26   ` Peter Zijlstra
2014-10-16 11:49   ` Borislav Petkov
2014-10-16 15:30     ` Andy Lutomirski
2014-10-14 22:57 ` [RFC 3/5] x86: Add a comment clarifying LDT context switching Andy Lutomirski
2014-10-16 15:49   ` Borislav Petkov
2014-10-16 16:21     ` Andy Lutomirski
2014-10-21  5:41       ` Borislav Petkov
2014-10-21  5:44         ` Andy Lutomirski
2014-10-21  6:05           ` Borislav Petkov
2014-10-14 22:57 ` [RFC 4/5] perf: Add pmu callbacks to track event mapping and unmapping Andy Lutomirski
2014-10-14 22:57 ` [RFC 5/5] x86,perf: Only allow rdpmc if a perf_event is mapped Andy Lutomirski
2014-10-16  8:42   ` Peter Zijlstra
2014-10-16 15:37     ` Andy Lutomirski
2014-10-16 15:57     ` Borislav Petkov
2014-10-17  0:00   ` Andy Lutomirski
2014-10-19 20:23     ` Andy Lutomirski
2014-10-19 21:33       ` Peter Zijlstra
2014-10-19 22:05         ` Andy Lutomirski [this message]
2014-10-19 22:20           ` Peter Zijlstra
2014-10-19 22:57             ` Andy Lutomirski
2014-10-20  8:33               ` Peter Zijlstra
2014-10-20 16:49                 ` Andy Lutomirski
2014-10-20 17:39                   ` Andy Lutomirski
2014-10-21  8:59                     ` Peter Zijlstra
2014-10-19 21:35     ` Peter Zijlstra
2014-10-20  0:08       ` Andy Lutomirski
2014-10-20  8:48         ` Peter Zijlstra
2014-10-20  9:24           ` Martin Schwidefsky
2014-10-20 10:51           ` Hendrik Brueckner
2014-10-21  9:14             ` Peter Zijlstra
2014-10-21 15:52               ` Andy Lutomirski
2014-10-21  4:06 ` [RFC 0/5] CR4 handling improvements Vince Weaver
2014-10-21  4:28   ` Andy Lutomirski
2014-10-21 15:00     ` Vince Weaver
2014-10-21 16:04       ` Peter Zijlstra
2014-10-21 17:05         ` Vince Weaver
2014-10-23 11:42           ` Peter Zijlstra
2014-10-24 12:41             ` Vince Weaver
2014-10-24 22:14               ` Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALCETrVT9vHjBRRvhTayqfOEebMjyVU9Yw7v80D6EPAmcyREZw@mail.gmail.com \
    --to=luto@amacapital.net \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=aarcange@redhat.com \
    --cc=acme@kernel.org \
    --cc=ebn310@few.vu.nl \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).