linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Balbir Singh <bsingharora@gmail.com>
Cc: Torsten Duwe <duwe@lst.de>, Michael Ellerman <mpe@ellerman.id.au>,
	Jiri Kosina <jkosina@suse.cz>, Miroslav Benes <mbenes@suse.cz>,
	Jessica Yu <jeyu@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	live-patching@vger.kernel.org
Subject: Re: [PATCH v8 8/8] livepatch: Detect offset for the ftrace location during build
Date: Fri, 12 Feb 2016 17:45:17 +0100	[thread overview]
Message-ID: <20160212164517.GO12548@pathway.suse.cz> (raw)
In-Reply-To: <1455293609.16012.9.camel@gmail.com>

On Sat 2016-02-13 03:13:29, Balbir Singh wrote:
> On Thu, 2016-01-28 at 16:32 +0100, Torsten Duwe wrote:
> > From: Petr Mladek <pmladek@suse.com>
> > 
> > Livepatch works on x86_64 and s390 only when the ftrace call
> > is at the very beginning of the function. But PPC is different.
> > We need to handle TOC and save LR there before calling the
> > global ftrace handler.
> > 
> > Now, the problem is that the extra operations have different
> > length on PPC depending on the used gcc version. It is
> > 4 instructions (16 bytes) before gcc-6 and only 3 instructions
> > (12 bytes) with gcc-6.
> > 
> > This patch tries to detect the offset a generic way during
> > build. It assumes that the offset of the ftrace location
> > is the same for all functions. It modifies the existing
> > recordmcount tool that is able to find read mcount locations
> > directly from the object files. It adds an option -p
> > to print the first found offset.
> > 
> > The recordmcount tool is then used in the kernel/livepatch
> > subdirectory to generate a header file. It defines
> > a constant that is used to compute the ftrace location
> > from the function address.
> > 
> > Finally, we have to enable the C implementation of the
> > recordmcount tool to be used on PPC and S390. It seems
> > to work fine there. It should be more reliable because
> > it reads the standardized elf structures. The old perl
> > implementation uses rather complex regular expressions
> > to parse objdump output and is therefore much more tricky.
> 
> I'm still missing something, I'm getting offset as 8
>
> When I run, I get
> 
> scripts/recordmcount -p kernel/livepatch/core.o 
> #define KLP_FTRACE_LOCATION 8
> 
> scripts/recordmcount -p kernel/livepatch/ftrace-test.o 
> #define KLP_FTRACE_LOCATION 8
> 
> My sample fails as well, since the expected offset is 16.
> I guess the script is being run against a not so good
> test.

I guess that you used a broken gcc and cheated the check
to pass the compilation. Did you, please?

The test used to detect the offset is using a minimalistic
function is is afftected by the gcc bug.

The patch below might be used to cheat the offset check as well.

Torsten, please mention this somewhere if you, just by chance,
send a new version of the patchset.

>From f6a438a3f2f60cc1acc859b41d0cc9259c9a331e Mon Sep 17 00:00:00 2001
From: root <root@c79.arch.suse.de>
Date: Tue, 2 Feb 2016 15:35:06 +0100
Subject: [PATCH 2/2] livepatch: Make sure the TOC is handled when detecting
 ftrace location

There seems to be a bug in gcc on PPC. It does not handle TOC
if the function does not access global variables or functions
by default. But it should when profiling is enabled.

This patch works around this problem by adding a call
to a global function.

This patch is for testing only!
---
 kernel/livepatch/ftrace-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/livepatch/ftrace-test.c b/kernel/livepatch/ftrace-test.c
index 22f0c54bf7b3..a3b7aabb67e5 100644
--- a/kernel/livepatch/ftrace-test.c
+++ b/kernel/livepatch/ftrace-test.c
@@ -1,6 +1,9 @@
 /* Sample code to figure out mcount location offset */
+#include <linux/printk.h>
+
 
 int test(int a)
 {
+	printk("%d\n", a);
 	return ++a;
 }
-- 
1.8.5.6

  reply	other threads:[~2016-02-12 16:45 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 17:29 [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) Torsten Duwe
2016-01-28 15:32 ` [PATCH v8 8/8] livepatch: Detect offset for the ftrace location during build Torsten Duwe
2016-02-12 16:13   ` Balbir Singh
2016-02-12 16:45     ` Petr Mladek [this message]
2016-02-13  1:33       ` Balbir Singh
2016-02-16  5:47       ` Kamalesh Babulal
2016-02-16  8:23         ` Torsten Duwe
2016-02-16 10:30           ` Kamalesh Babulal
2016-02-16 10:39             ` Torsten Duwe
2016-02-16 13:57               ` Petr Mladek
2016-02-17  3:08                 ` Michael Ellerman
2016-02-23 17:00                   ` Torsten Duwe
2016-02-24  6:37                     ` Balbir Singh
2016-02-24  6:55                       ` Balbir Singh
2016-02-24  9:23                         ` Torsten Duwe
2016-02-24 11:22                           ` Balbir Singh
2016-02-24  7:51                     ` Kamalesh Babulal
2016-02-10 16:21 ` [PATCH v8 1/8] ppc64 (le): prepare for -mprofile-kernel Torsten Duwe
2016-02-17 10:55   ` Michael Ellerman
2016-02-17 11:30     ` Torsten Duwe
2016-02-17 11:39       ` Michael Ellerman
2016-02-10 16:22 ` [PATCH v8 2/8] ppc64le FTRACE_WITH_REGS implementation Torsten Duwe
2016-02-10 16:22 ` [PATCH v8 3/8] ppc use ftrace_modify_all_code default Torsten Duwe
2016-02-10 16:25 ` [PATCH v8 4/8] ppc64 ftrace_with_regs configuration variables Torsten Duwe
2016-02-11  7:48   ` Balbir Singh
2016-02-11  8:39     ` Kamalesh Babulal
2016-02-11  9:35       ` Balbir Singh
2016-02-11 13:00         ` Murali Sampath
2016-02-11 13:00         ` Murali Sampath
2016-02-11  8:42     ` Torsten Duwe
2016-02-11  9:34       ` Balbir Singh
2016-02-15 10:27       ` Michael Ellerman
2016-02-15 12:56         ` Jiri Kosina
2016-02-15 14:04         ` Torsten Duwe
2016-02-15 22:21           ` Torsten Duwe
2016-02-16  4:53             ` Balbir Singh
2016-02-16 10:09           ` Michael Ellerman
2016-02-16 10:35             ` Torsten Duwe
2016-02-10 16:27 ` [PATCH v8 5/8] ppc64 ftrace_with_regs: disable profiling for some files Torsten Duwe
2016-02-10 16:34 ` [PATCH v8 6/8] Implement kernel live patching for ppc64le (ABIv2) Torsten Duwe
2016-02-11  9:01   ` Miroslav Benes
2016-02-10 16:36 ` [PATCH v8 7/8] Enable LIVEPATCH to be configured on ppc64le and add livepatch.o if it is selected Torsten Duwe
2016-02-11  6:18 ` [PATCH v8 0/8] ftrace with regs + live patching for ppc64 LE (ABI v2) Balbir Singh
2016-02-11  8:38   ` Torsten Duwe

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=20160212164517.GO12548@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=bsingharora@gmail.com \
    --cc=duwe@lst.de \
    --cc=jeyu@redhat.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mpe@ellerman.id.au \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).