Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1353146

Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc

From Torsten Duwe <duwe@lst.de>
Newsgroups linux.kernel
Subject Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc
Date 2016-03-08 16:40 +0100
Message-ID <rarTQ-2Ho-5@gated-at.bofh.it> (permalink)
References <rakpj-6eV-5@gated-at.bofh.it> <rannc-87S-15@gated-at.bofh.it> <raql6-1Bi-59@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Mar 09, 2016 at 12:52:03AM +1100, Balbir Singh wrote:
> 
> On 08/03/16 21:45, Torsten Duwe wrote:
> > To be fair, my last mail still was not 100% correct, but the conclusion

Wrote a correction to the correction. It should be clear now. Please nag me
if it isn't clear why klp_return_helper and its stack frame is needed.

> > that the mini frame is not needed at all is invalid. Please leave it as it
> > was, I'm working on a test / demonstrator for how to handle these.
> Why, the magic will be in the patched function? Please share the test/demonstrator

Here it comes...

> > NAKed-by: Torsten Duwe <duwe@suse.de>
> Why? For using CR+4 or removing the frame? Or you believe there is a better way to
> handle this that work, IOW what is broken?

The stack frame removal. You're risking a memory access or jump into nirvana
or and endless loop.

klp_return_helper will do the right thing, and functions like e.g. printk
I would live patch like this (untested :-) :

------------------------8<----------------------
#include <stdarg.h>

/* compile using "-ffixed-r14"! */
register unsigned long pass_TOC asm("r14");

/*
 * Function pre-prologue to pop the klp_return_helper
 * mini stack frame. The saved r2 TOC value is read and
 * passed in pass_TOC (r14), the original LR is passed
 * in r0 and the LR itself. R12 is updated appropriately
 * for local TOC recalculation.
 */
extern void caller(void) asm("printk");
void caller(void)
{
  asm("ld %0,24(1)" : "=r" (pass_TOC));
  asm("addi 1,1,32");
  asm("addi 12,12,(real_printk-printk)@l");
  asm("ld 0,16(1)\n\tmtlr 0");
  asm("b real_printk");
}

extern int vprintk_default(const char *fmt, va_list args);

extern int printk(const char *fmt, ...) asm("real_printk");
int printk(const char *fmt, ...)
{
        va_list args;
        int r;

        va_start(args, fmt);

        r = vprintk_default(fmt, args);

        va_end(args);

	asm("mr 2,%0" : : "r" (pass_TOC));
        return r;
}
------------------------8<----------------------
Signed-off-by: Torsten Duwe <duwe@suse.de>

As you can see, the extra effort for args on the stack is limited.

	Torsten

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Balbir Singh <bsingharora@gmail.com> - 2016-03-08 08:40 +0100
  Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Torsten Duwe <duwe@lst.de> - 2016-03-08 11:50 +0100
    Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Balbir Singh <bsingharora@gmail.com> - 2016-03-08 15:00 +0100
      Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Torsten Duwe <duwe@lst.de> - 2016-03-08 16:40 +0100
        Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Balbir Singh <bsingharora@gmail.com> - 2016-03-09 04:50 +0100
        Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Petr Mladek <pmladek@suse.com> - 2016-03-09 17:20 +0100
          Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Torsten Duwe <duwe@lst.de> - 2016-03-09 18:30 +0100
  Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Petr Mladek <pmladek@suse.com> - 2016-03-08 17:10 +0100
    Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc Balbir Singh <bsingharora@gmail.com> - 2016-03-09 04:40 +0100

csiph-web