Re: [v5][PATCH] livepatch/ppc: Enable livepatching on powerpc
From: Petr Mladek
Date: Tue Mar 08 2016 - 11:03:17 EST
On Tue 2016-03-08 18:33:57, Balbir Singh wrote:
> Changelog v5:
> 1. Removed the mini-stack frame created for klp_return_helper.
> As a result of the mini-stack frame, function with > 8
> arguments could not be patched
> 2. Removed camel casing in the comments
I tested this patch and it fails when I call a patched printk()
from a module.
You might try it with the test patch below. It is a bit twisted
because it calls the patched printk from livepatch_cmdline_proc_show()
that it added by the same patch module. Please, look at
livepatch_cmdline_proc_show(), it does:
static int count;
if (!count++)
trace_printk("%s\n", "this has been live patched");
else
printk("%s\n", "this has been live patched");
It means that calls only trace_printk() when called first time.
It calls the patched printk when called second time.
I have tested it the following way:
# booted kernel with the changes below
# applied the patch:
$> modprobe livepatch-sample
# trigger the pached printk()
$>cat /sys/kernel/livepatch/livepatch_sample/enabled
1
# look into both dmesg and trace buffer
$> dmesg | tail -n 1
[ 727.537307] patch enabled: 1
$> cat /sys/kernel/debug/tracing/trace | tail -n 1
cat-3588 [003] .... 727.537448: livepatch_printk: patch enabled: 1
# trigger livepatch_cmdline_proc_show() 1st time
c79:~ # cat /proc/cmdline
this has been live patched
# the message appeared only in trace buffer
$> dmesg | tail -n 1
[ 727.537307] patch enabled: 1
c79:~ # cat /sys/kernel/debug/tracing/trace | tail -n 1
cat-3511 [000] .... 862.958383: livepatch_cmdline_proc_show: this has been live patched
# trigger livepatch_cmdline_proc_show() 2nd time
c79:~ # cat /proc/cmdline
!!! KABOOM !!!
It is becaused it tried to call the patched printk()?
Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0xc0000000023f014c
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=2048 NUMA pSeries
Modules linked in: livepatch_sample af_packet dm_mod rtc_generic e1000 ext4 crc16 mbcache jbd2 sr_mod cdrom sd_mod ibmvscsi scsi_transport_srp sg scsi_mod autofs4
CPU: 1 PID: 3514 Comm: cat Tainted: G K 4.5.0-rc7-11-default+ #110
task: c000000003e60e20 ti: c000000003d38000 task.ti: c000000003d38000
NIP: c0000000023f014c LR: c0000000023f014c CTR: c0000000001a72c0
REGS: c000000003d3b930 TRAP: 0400 Tainted: G K (4.5.0-rc7-11-default+)
MSR: 8000000010009033 <SF,EE,ME,IR,DR,RI,LE> CR: 28222022 XER: 20000000
CFAR: c000000000009e9c SOFTE: 1
GPR00: c0000000023f014c c000000003d3bbb0 c000000000fae100 0000000000000000
GPR04: c0000000fea60038 000000000000000c 0000000068637461 0000000000000068
GPR08: 0000000000000000 c000000003e627cc c000000003e60e20 d0000000023f0308
GPR12: 0000000000002200 c000000007e80300 0000000010020360 0000000000010000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000010000300000 c0000000035bf540 0000000000010000 c000000003d3be00
GPR24: c0000000035b8500 0000000000000000 fffffffffffff000 c000000003d3bc58
GPR28: 0000010000300000 c0000000035bf500 d0000000023f0578 d0000000023f0558
NIP [c0000000023f014c] 0xc0000000023f014c
LR [c0000000023f014c] 0xc0000000023f014c
Call Trace:
[c000000003d3bbb0] [c0000000023f014c] 0xc0000000023f014c (unreliable)
[c000000003d3bc30] [c000000000009e88] klp_return_helper+0x0/0x18
[c000000003d3bcd0] [c00000000034798c] proc_reg_read+0x8c/0xd0
[c000000003d3bd00] [c0000000002b7fbc] __vfs_read+0x4c/0x160
[c000000003d3bd90] [c0000000002b9318] vfs_read+0xa8/0x1c0
[c000000003d3bde0] [c0000000002ba61c] SyS_read+0x6c/0x110
[c000000003d3be30] [c000000000009204] system_call+0x38/0xb4
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
---[ end trace 17a32fcaa99f5af5 ]---
Here is the patch that I used: