public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"oprofile-list@lists.sourceforge.net" 
	<oprofile-list@lists.sourceforge.net>,
	"tdm.rhbz@gmail.com" <tdm.rhbz@gmail.com>
Subject: Re: [PATCH] oprofile, x86: allow backtrace for 32bit apps under 64bit kernel
Date: Mon, 20 Sep 2010 12:44:15 +0200	[thread overview]
Message-ID: <20100920104415.GO13563@erda.amd.com> (raw)
In-Reply-To: <1284380117-6857-1-git-send-email-jolsa@redhat.com>

On 13.09.10 08:15:17, Jiri Olsa wrote:
> hi,
> 
> adding support for backtrace of ia32 applications under 64bit kernels.
> 
> wbr,
> jirka
> 
> 
> 
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> Signed-off-by: Tom Marshall <tdm.rhbz@gmail.com>
> ---
>  arch/x86/oprofile/backtrace.c |   42 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 42 insertions(+), 0 deletions(-)

Jirka,

see my comments below.

Please, provide a more meaningful commit message.

> 
> diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
> index 3855096..3e443ad 100644
> --- a/arch/x86/oprofile/backtrace.c
> +++ b/arch/x86/oprofile/backtrace.c
> @@ -73,6 +73,38 @@ static struct frame_head *dump_user_backtrace(struct frame_head *head)
>  	return bufhead[0].bp;
>  }
>  
> +#ifdef CONFIG_X86_64
> +struct frame_head_32 {
> +	__u32 ebp;
> +	__u32 ret;
> +} __attribute__((packed));

There exists already struct stack_frame_ia32.

Please, also change the code to reuse struct stack_frame for 64 bit
processes.

> +
> +static struct frame_head *
> +dump_user_backtrace_32(struct frame_head *head)
> +{
> +	struct frame_head_32 bufhead_32[2];
> +	unsigned long bp, ret;
> +
> +	/* Also check accessibility of one struct frame_head beyond */
> +	if (!access_ok(VERIFY_READ, head, sizeof(bufhead_32)))
> +		return NULL;
> +	if (__copy_from_user_inatomic(bufhead_32, head, sizeof(bufhead_32)))
> +		return NULL;
> +
> +	bp  = bufhead_32[0].ebp;
> +	ret = bufhead_32[0].ret;
> +
> +	oprofile_add_trace(ret);
> +
> +	/* frame pointers should strictly progress back up the stack
> +	* (towards higher addresses) */
> +	if (head >= (struct frame_head *) bp)

You are mixing up struct frame_head and struct frame_head_32 here.

> +		return NULL;
> +
> +	return (struct frame_head *) bp;
> +}
> +#endif
> +
>  void
>  x86_backtrace(struct pt_regs * const regs, unsigned int depth)
>  {
> @@ -86,6 +118,16 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
>  		return;
>  	}
>  
> +#ifdef CONFIG_X86_64

Rather use CONFIG_COMPAT here.

> +	if (current && test_thread_flag(TIF_IA32)) {
> +		/* User process is 32-bit */
> +		head = (struct frame_head *)(regs->bp & 0xffffffff);

Same is provided with compat_ptr().

> +		while (depth-- && head)
> +			head = dump_user_backtrace_32(head);
> +		return;
> +	}
> +#endif

Please avoid inline macros and make this an inline function (maybe
x86_backtrace_32) with a function stub for the !CONFIG_COMPAT case.

If possible, try to avoid duplicate code for 32 and 64 bit backtraces.

Thanks,

-Robert

> +
>  	while (depth-- && head)
>  		head = dump_user_backtrace(head);
>  }
> -- 
> 1.7.1
> 
> 

-- 
Advanced Micro Devices, Inc.
Operating System Research Center


      reply	other threads:[~2010-09-20 10:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 12:15 [PATCH] oprofile, x86: allow backtrace for 32bit apps under 64bit kernel Jiri Olsa
2010-09-20 10:44 ` Robert Richter [this message]

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=20100920104415.GO13563@erda.amd.com \
    --to=robert.richter@amd.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oprofile-list@lists.sourceforge.net \
    --cc=tdm.rhbz@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox