Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4594972imm; Mon, 18 Jun 2018 18:39:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLe4UjZYsOP1PTWICZPAznBzaKrL8pxeZGd1LQi0LszW+G127X64N2N6SG+vwT8y3Bs62+x X-Received: by 2002:a63:3641:: with SMTP id d62-v6mr12671323pga.18.1529372399207; Mon, 18 Jun 2018 18:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529372399; cv=none; d=google.com; s=arc-20160816; b=lmivKwvsvs9aMN5XUmmwCnQp+k4RV5IW/Oo8eehWNMscJ6mQHDOserCoA1uPV3bLdF 6zQEcT+5btlYeFa8yT3jTkcY+8yNwKTOqXx07UiqfpB/DD1g+u2Tb6aK7E7NDI6xhEkt T+E0qDzRVZwWawn+lqrY59s5QwiuLddWM1nPL8vEQZynGwTU3kxf/ZH+p7Ggkm4MhnRn 71rOmWYN7eqYhZmYmMBPtQkzfs4tt+z7zahB+ClVAhLzUOty6OFIAlR80gJSXmLwGY4A EypaKik6cnxlWtCOr6TLbYYgnuxg49mpgcM26IEuj3D+HIL8GdQK+PPU8/ADt7MT2WHO wKwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=LOW2cOL9Hsl9IfH3EfBIQtYkitcgaffUXxi8IbOkTVo=; b=kunMpmNaNw+7023vHsQMz5oUgArM8Z+9iVywPGPt31V0CbhuXGvJPKRVq3t80LK97X Tjy779XFLK87Xzr+Bc7ba/j/IMc1EMCHM7tcSxCp9p6DoaxDrHuCnznyL9Uilm0nvEOK HcnNLDFFglxWbsveSyNNycthte0zK4lE1n6xpUpNAchuySS5WB6QnkyBLgXQluDvhKzP 7nHtJ0mXrRUKrc8adkJjXOIkryBphbwdZsPRoihiEdBjh4Jn8NPkHC3GiT4Vm7lisIIy x3eaoabVzgsP2kEkIj42Xo9J9tEWPGX62azBXoRG8jGBfw6kY463TWoWEU4ztjON84W6 CZkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16-v6si12793494pgv.409.2018.06.18.18.39.45; Mon, 18 Jun 2018 18:39:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937004AbeFSBjI (ORCPT + 99 others); Mon, 18 Jun 2018 21:39:08 -0400 Received: from mga06.intel.com ([134.134.136.31]:6000 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934880AbeFSBjG (ORCPT ); Mon, 18 Jun 2018 21:39:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2018 18:39:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,241,1526367600"; d="scan'208";a="58771875" Received: from yjin15-mobl.ccr.corp.intel.com (HELO [10.239.161.30]) ([10.239.161.30]) by fmsmga002.fm.intel.com with ESMTP; 18 Jun 2018 18:39:03 -0700 Subject: Re: [PATCH v1 1/2] perf/core: Use sysctl to turn on/off dropping leaked kernel samples To: Peter Zijlstra Cc: Mark Rutland , acme@kernel.org, jolsa@kernel.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, me@kylehuey.com, Linux-kernel@vger.kernel.org, vincent.weaver@maine.edu, will.deacon@arm.com, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com References: <1529057003-2212-1-git-send-email-yao.jin@linux.intel.com> <1529057003-2212-2-git-send-email-yao.jin@linux.intel.com> <20180615113608.6m74sm7gpl5p6oqe@lakrids.cambridge.arm.com> <52c75f12-1f91-405d-0b05-0aa6a9c09306@linux.intel.com> <20180618104522.GI2458@hirez.programming.kicks-ass.net> From: "Jin, Yao" Message-ID: Date: Tue, 19 Jun 2018 09:39:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180618104522.GI2458@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/18/2018 6:45 PM, Peter Zijlstra wrote: > On Mon, Jun 18, 2018 at 02:55:32PM +0800, Jin, Yao wrote: >> Thanks for providing the patch. I understand this approach. >> >> In my opinion, the skid window is from counter overflow to interrupt >> delivered. While if the skid window is too *big* (e.g. user -> kernel), it >> should be not very useful. So personally, I'd prefer to drop the samples. > > I really don't get your insitence on dropping the sample. Dropping > samples is bad. Furthermore, doing what Mark suggests actually improves > the result by reducing the skid, if the event happened before we entered > (as it damn well should) then the user regs, which point at the entry > site, are a better approximation than our in-kernel set. > > So not only do you not loose the sample, you actually get a better > sample. > OK, that's fine, thanks! I guess Mark will post this patch, right? Anyway looks we don't need following patch (0-stuffing sample->ip to indicate perf tool that it is a leak sample), right? diff --git a/kernel/events/core.c b/kernel/events/core.c index 80cca2b..628b515 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6361,6 +6361,21 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) return callchain ?: &__empty_callchain; } +static bool sample_is_leaked(struct perf_event *event, struct pt_regs *regs) +{ + /* + * Due to interrupt latency (AKA "skid"), we may enter the + * kernel before taking an overflow, even if the PMU is only + * counting user events. + * To avoid leaking information to userspace, we must always + * reject kernel samples when exclude_kernel is set. + */ + if (event->attr.exclude_kernel && !user_mode(regs)) + return true; + + return false; +} + void perf_prepare_sample(struct perf_event_header *header, struct perf_sample_data *data, struct perf_event *event, @@ -6480,6 +6495,9 @@ void perf_prepare_sample(struct perf_event_header *header, if (sample_type & PERF_SAMPLE_PHYS_ADDR) data->phys_addr = perf_virt_to_phys(data->addr); + + if (sample_is_leaked(event, regs)) + data->ip = 0; } static void __always_inline diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index bfa60bc..1bfb697 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -404,6 +404,7 @@ struct events_stats { u64 total_aux_lost; u64 total_aux_partial; u64 total_invalid_chains; + u64 total_dropped_samples; u32 nr_events[PERF_RECORD_HEADER_MAX]; u32 nr_non_filtered_samples; u32 nr_lost_warned; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8b93693..ec923f1 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1269,6 +1269,12 @@ static int machines__deliver_event(struct machines *machines, ++evlist->stats.nr_unprocessable_samples; return 0; } + + if (sample->ip == 0) { + /* Drop the leaked kernel samples */ + ++evlist->stats.total_dropped_samples; + return 0; + } return perf_evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); case PERF_RECORD_MMAP: return tool->mmap(tool, event, sample, machine); Thanks Jin Yao