Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625AbdF2A1Z (ORCPT ); Wed, 28 Jun 2017 20:27:25 -0400 Received: from mga01.intel.com ([192.55.52.88]:5259 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551AbdF2A1V (ORCPT ); Wed, 28 Jun 2017 20:27:21 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,278,1496127600"; d="scan'208";a="120076264" Subject: Re: [PATCH] perf/core: generate overflow signal when samples are dropped (WAS: Re: [REGRESSION] perf/core: PMU interrupts dropped if we entered the kernel in the "skid" region) To: Kyle Huey , Mark Rutland Cc: Vince Weaver , Ingo Molnar , "Peter Zijlstra (Intel)" , stable@vger.kernel.org, Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Namhyung Kim , Stephane Eranian , Thomas Gleixner , acme@kernel.org, jolsa@kernel.org, kan.liang@intel.com, Will Deacon , gregkh@linuxfoundation.org, "Robert O'Callahan" , open list , yao.jin@intel.com References: <2256f9b5-1277-c4b1-1472-61a10cd1db9a@linux.intel.com> <20170628101248.GB5981@leverpostej> <20170628105600.GC5981@leverpostej> <20170628174900.GG8252@leverpostej> From: "Jin, Yao" Message-ID: Date: Thu, 29 Jun 2017 08:27:15 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2225 Lines: 60 On 6/29/2017 6:55 AM, Kyle Huey wrote: > On Wed, Jun 28, 2017 at 10:49 AM, Mark Rutland wrote: >> On Wed, Jun 28, 2017 at 09:48:27AM -0700, Kyle Huey wrote: >>> On Wed, Jun 28, 2017 at 3:56 AM, Mark Rutland wrote: >>>> @@ -6101,6 +6116,12 @@ void perf_prepare_sample(struct perf_event_header *header, >>>> struct perf_output_handle handle; >>>> struct perf_event_header header; >>>> >>>> + /* >>>> + * For security, drop the skid kernel samples if necessary. >>>> + */ >>>> + if (!sample_is_allowed(event, regs)) >>>> + return ret; >>> Just a bare return here. >> Ugh, yes. Sorry about that. I'll fix that up. >> >> [...] >> >>> I can confirm that with that fixed to compile, this patch fixes rr. >> Thanks for giving this a go. >> >> Having thought about this some more, I think Vince does make a good >> point that throwing away samples is liable to break stuff, e.g. that >> which only relies on (non-sensitive) samples. >> >> It still seems wrong to make up data, though. >> >> Maybe for exclude_kernel && !exclude_user events we can always generate >> samples from the user regs, rather than the exception regs. That's going >> to be closer to what the user wants, regardless. I'll take a look >> tomorrow. > I'm not very familiar with the kernel internals, but the reason I > didn't suggest this originally is it seems like it will be difficult > to determine what the "correct" userspace registers are. For example, > what happens if a performance counter is fixed to a given tid, the > interrupt fires during a context switch from that task to another that > is not being monitored, and the kernel is far enough along in the > context switch that the current task struct has been switched out? > Reporting the new task's registers seems as bad as reporting the > kernel's registers. But maybe this is easier than I imagine for > whatever reason. > > Something to think about. > > - Kyle Yes, I think so. The skid interrupt may be triggered at a wrong context and return wrong indications (e.g. wrong regs) to userspace. So that's why I think the *skid* interrupt had better be dropped. Thanks Jin Yao