lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170824085628.h322ipomh4u4zpwh@hirez.programming.kicks-ass.net>
Date:   Thu, 24 Aug 2017 10:56:29 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Michael Ellerman <mpe@...erman.id.au>
Cc:     kan.liang@...el.com, mingo@...hat.com,
        linux-kernel@...r.kernel.org, acme@...nel.org, jolsa@...hat.com,
        tglx@...utronix.de, eranian@...gle.com, ak@...ux.intel.com,
        maddy@...ux.vnet.ibm.com
Subject: Re: [PATCH V6] perf: Add PERF_SAMPLE_PHYS_ADDR

On Thu, Aug 24, 2017 at 11:26:17AM +1000, Michael Ellerman wrote:
> Peter Zijlstra <peterz@...radead.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.

You can limit it to those that include a PMU that supports data->addr,
which is book3s, whatever that gets you.

> 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.

Yeah, gup fast should work for you.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ