Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751831AbdHVRHz (ORCPT ); Tue, 22 Aug 2017 13:07:55 -0400 Received: from merlin.infradead.org ([205.233.59.134]:57676 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbdHVRHy (ORCPT ); Tue, 22 Aug 2017 13:07:54 -0400 Date: Tue, 22 Aug 2017 19:07:36 +0200 From: Peter Zijlstra To: kan.liang@intel.com Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, acme@kernel.org, jolsa@redhat.com, tglx@linutronix.de, eranian@google.com, ak@linux.intel.com Subject: Re: [PATCH V5] perf: Add PERF_SAMPLE_PHYS_ADDR Message-ID: <20170822170736.GI32112@worktop.programming.kicks-ass.net> References: <1502993843-6837-1-git-send-email-kan.liang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1502993843-6837-1-git-send-email-kan.liang@intel.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1869 Lines: 55 On Thu, Aug 17, 2017 at 02:17:23PM -0400, kan.liang@intel.com wrote: > diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c > index a322fed..f0e8d9c 100644 > --- a/arch/x86/events/intel/ds.c > +++ b/arch/x86/events/intel/ds.c > @@ -1065,6 +1065,35 @@ static inline u64 intel_hsw_transaction(struct pebs_record_skl *pebs) > return txn; > } > > +static u64 dla_to_phys(u64 dla) > +{ > + u64 phys_addr = 0; > + struct page *p = NULL; > + > + if (dla >= TASK_SIZE) { > + /* If it's vmalloc()d memory, leave phys_addr as 0 */ > + if (virt_addr_valid(dla) && > + !(dla >= VMALLOC_START && dla < VMALLOC_END)) > + phys_addr = (u64)virt_to_phys((void *)(uintptr_t)dla); > + } else { > + /* > + * Walking the pages tables for user address. > + * Interrupts are disabled, so it prevents any tear down > + * of the page tables. > + * Try IRQ-safe __get_user_pages_fast first. > + * If failed, leave phys_addr as 0. > + */ > + if ((current->mm != NULL) && > + (__get_user_pages_fast(dla, 1, 0, &p) == 1)) > + phys_addr = page_to_phys(p) + dla % PAGE_SIZE; > + > + if (p) > + put_page(p); > + } > + > + return phys_addr; > +} Is this in any way x86 specific? AFAICT this should work in generic code as long as data->addr is provided. > static void setup_pebs_sample_data(struct perf_event *event, > struct pt_regs *iregs, void *__pebs, > struct perf_sample_data *data, > @@ -1179,6 +1208,9 @@ static void setup_pebs_sample_data(struct perf_event *event, > x86_pmu.intel_cap.pebs_format >= 1) > data->addr = pebs->dla; > > + if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0)) > + data->phys_addr = dla_to_phys(data->addr); > + > if (x86_pmu.intel_cap.pebs_format >= 2) { > /* Only set the TSX weight when no memory weight. */ > if ((sample_type & PERF_SAMPLE_WEIGHT) && !fll)