mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Peter Zijlstra <peterz@infradead.org>, 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, maddy@linux.vnet.ibm.com
Subject: Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR
Date: Thu, 24 Aug 2017 11:26:17 +1000	[thread overview]
Message-ID: <87378hycw6.fsf@concordia.ellerman.id.au> (raw)
In-Reply-To: <20170823143308.v27pgjagxjyd65ci@hirez.programming.kicks-ass.net>

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

  parent reply	other threads:[~2017-08-24  1:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 14:22 kan.liang
2017-08-23 14:33 ` Peter Zijlstra
2017-08-23 14:39   ` Peter Zijlstra
2017-08-23 17:00     ` Stephane Eranian
2017-08-31 16:44       ` Arnaldo Carvalho de Melo
2017-08-23 18:01     ` Liang, Kan
2017-08-23 18:26       ` Peter Zijlstra
2017-08-24  1:26   ` Michael Ellerman [this message]
2017-08-24  8:56     ` Peter Zijlstra
2017-08-24  9:52       ` Michael Ellerman

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=87378hycw6.fsf@concordia.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®