All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: will.deacon@arm.com, mingo@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [BUG] perf: arch_perf_out_copy_user default
Date: Wed, 30 Oct 2013 20:50:28 +0100	[thread overview]
Message-ID: <20131030195013.GA2253@localhost.localdomain> (raw)
In-Reply-To: <20131030143750.GT19466@laptop.lan>

On Wed, Oct 30, 2013 at 03:37:50PM +0100, Peter Zijlstra wrote:
> Hi Frederic,
> 
> I just spotted:
> 
> #ifndef arch_perf_out_copy_user
> #define arch_perf_out_copy_user __copy_from_user_inatomic
> #endif
> 
> vs:
> 
> arch/x86/include/asm/perf_event.h:#define arch_perf_out_copy_user copy_from_user_nmi
> 
> Now the problem is that copy_from_user_nmi() and
> __copy_from_user_inatomic() have different return semantics.
> 
> Furthermore, the macro you use them in DEFINE_OUTPUT_COPY() assumes the
> return value is the amount of memory copied; as also illustrated by
> memcpy_common().
> 
> Trouble is, __copy_from_user_inatomic() returns the number of bytes
> _NOT_ copied.

Aie, sorry about that, I did a wrong assumption indeed.

> 
> With this, my question to Will is, how did your ARM unwind support
> patches ever work? AFAICT they end up using the
> __copy_from_user_inatomic() thing.
> 
> 
> ---
>  kernel/events/internal.h | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/events/internal.h b/kernel/events/internal.h
> index ca6599723be5..d7a0f753e695 100644
> --- a/kernel/events/internal.h
> +++ b/kernel/events/internal.h
> @@ -110,7 +110,8 @@ func_name(struct perf_output_handle *handle,				\
>  	return len;							\
>  }
>  
> -static inline int memcpy_common(void *dst, const void *src, size_t n)
> +static inline unsigned long
> +memcpy_common(void *dst, const void *src, unsigned long n)
>  {
>  	memcpy(dst, src, n);
>  	return n;
> @@ -123,7 +124,19 @@ DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
>  DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
>  
>  #ifndef arch_perf_out_copy_user
> -#define arch_perf_out_copy_user __copy_from_user_inatomic
> +#define arch_perf_out_copy_user arch_perf_out_copy_user
> +
> +static inline unsigned long
> +arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
> +{
> +	unsigned long ret;
> +
> +	pagefault_disable();
> +	ret = __copy_from_user_inatomic(to, from, n);
> +	pagefault_enable();
> +
> +	return n - ret;

Would it make sense to rather make copy_from_user_nmi() to use a return value
pattern that is closer to those of the existing copy_from_user_*() ?

This way we avoid future mistakes of that kind.

Thanks.

> +}
>  #endif
>  
>  DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)

  parent reply	other threads:[~2013-10-30 19:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30 14:37 [BUG] perf: arch_perf_out_copy_user default Peter Zijlstra
2013-10-30 18:44 ` [PATCH] perf: Fix arch_perf_out_copy_user default implementation Peter Zijlstra
2013-10-30 19:29 ` [BUG] perf: arch_perf_out_copy_user default Will Deacon
2013-10-30 19:35   ` Peter Zijlstra
2013-10-30 19:50 ` Frederic Weisbecker [this message]
2013-10-30 20:16   ` Peter Zijlstra
2013-10-30 20:47     ` Frederic Weisbecker
2013-10-30 22:31     ` Will Deacon
2013-11-06 13:19     ` [tip:perf/core] perf: Fix " tip-bot for Peter Zijlstra

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=20131030195013.GA2253@localhost.localdomain \
    --to=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.