Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1718752
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR |
| Date | 2017-08-24 03:30 +0200 |
| Message-ID | <uhP85-87D-5@gated-at.bofh.it> (permalink) |
| References | <uhEPn-1DV-17@gated-at.bofh.it> <uhEZ3-1Jk-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Peter Zijlstra <peterz@infradead.org> writes:
>> diff --git a/kernel/events/core.c b/kernel/events/core.c
>> index d704e23..b991af3 100644
>> --- a/kernel/events/core.c
>> +++ b/kernel/events/core.c
>> @@ -6027,6 +6033,38 @@ void perf_output_sample(struct perf_output_handle *handle,
>> }
>> }
>>
>> +static u64 perf_virt_to_phys(u64 virt)
>> +{
>> + u64 phys_addr = 0;
>> + struct page *p = NULL;
>> +
>> + if (!virt)
>> + return 0;
>> +
>> + if (virt >= TASK_SIZE) {
>> + /* If it's vmalloc()d memory, leave phys_addr as 0 */
>> + if (virt_addr_valid(virt) &&
>> + !(virt >= VMALLOC_START && virt < VMALLOC_END))
>> + phys_addr = (u64)virt_to_phys((void *)(uintptr_t)virt);
>> + } 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(virt, 1, 0, &p) == 1))
>> + phys_addr = page_to_phys(p) + virt % PAGE_SIZE;
>> +
>> + if (p)
>> + put_page(p);
>> + }
>> +
>> + return phys_addr;
>> +}
>
> Michael, does this work for PPC as is?
I think so.
We have about 8 MMUs and 32-bit and 64-bit so it's a bit hard to say for
sure.
I'm pretty sure virt_addr_valid() will exclude everything except the
linear mapping for us, so the vmalloc check is redundant but that's
fine. So that looks safe AFAICS.
I'm not an expert on GUP fast, but AFAIK there's nothing special
required for us.
cheers
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang@intel.com - 2017-08-23 16:30 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Peter Zijlstra <peterz@infradead.org> - 2017-08-23 16:40 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Peter Zijlstra <peterz@infradead.org> - 2017-08-23 16:50 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Stephane Eranian <eranian@google.com> - 2017-08-23 19:10 +0200
RE: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR "Liang, Kan" <kan.liang@intel.com> - 2017-08-23 20:20 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Peter Zijlstra <peterz@infradead.org> - 2017-08-23 20:30 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Michael Ellerman <mpe@ellerman.id.au> - 2017-08-24 03:30 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Peter Zijlstra <peterz@infradead.org> - 2017-08-24 11:00 +0200
Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR Michael Ellerman <mpe@ellerman.id.au> - 2017-08-24 12:00 +0200
csiph-web