xref: /aosp_15_r20/external/linux-kselftest/tools/testing/selftests/livepatch/test-callbacks.sh (revision 053f45be4e351dfd5e965df293cd45b779f579ee)
1*053f45beSAndroid Build Coastguard Worker#!/bin/bash
2*053f45beSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0
3*053f45beSAndroid Build Coastguard Worker# Copyright (C) 2018 Joe Lawrence <[email protected]>
4*053f45beSAndroid Build Coastguard Worker
5*053f45beSAndroid Build Coastguard Worker. $(dirname $0)/functions.sh
6*053f45beSAndroid Build Coastguard Worker
7*053f45beSAndroid Build Coastguard WorkerMOD_LIVEPATCH=test_klp_callbacks_demo
8*053f45beSAndroid Build Coastguard WorkerMOD_LIVEPATCH2=test_klp_callbacks_demo2
9*053f45beSAndroid Build Coastguard WorkerMOD_TARGET=test_klp_callbacks_mod
10*053f45beSAndroid Build Coastguard WorkerMOD_TARGET_BUSY=test_klp_callbacks_busy
11*053f45beSAndroid Build Coastguard Worker
12*053f45beSAndroid Build Coastguard Workersetup_config
13*053f45beSAndroid Build Coastguard Worker
14*053f45beSAndroid Build Coastguard Worker
15*053f45beSAndroid Build Coastguard Worker# Test a combination of loading a kernel module and a livepatch that
16*053f45beSAndroid Build Coastguard Worker# patches a function in the first module.  Load the target module
17*053f45beSAndroid Build Coastguard Worker# before the livepatch module.  Unload them in the same order.
18*053f45beSAndroid Build Coastguard Worker#
19*053f45beSAndroid Build Coastguard Worker# - On livepatch enable, before the livepatch transition starts,
20*053f45beSAndroid Build Coastguard Worker#   pre-patch callbacks are executed for vmlinux and $MOD_TARGET (those
21*053f45beSAndroid Build Coastguard Worker#   klp_objects currently loaded).  After klp_objects are patched
22*053f45beSAndroid Build Coastguard Worker#   according to the klp_patch, their post-patch callbacks run and the
23*053f45beSAndroid Build Coastguard Worker#   transition completes.
24*053f45beSAndroid Build Coastguard Worker#
25*053f45beSAndroid Build Coastguard Worker# - Similarly, on livepatch disable, pre-patch callbacks run before the
26*053f45beSAndroid Build Coastguard Worker#   unpatching transition starts.  klp_objects are reverted, post-patch
27*053f45beSAndroid Build Coastguard Worker#   callbacks execute and the transition completes.
28*053f45beSAndroid Build Coastguard Worker
29*053f45beSAndroid Build Coastguard Workerstart_test "target module before livepatch"
30*053f45beSAndroid Build Coastguard Worker
31*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
32*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
33*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
34*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
35*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
36*053f45beSAndroid Build Coastguard Worker
37*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_TARGET
38*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
39*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH
40*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
41*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
42*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
43*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
44*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
45*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
46*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
47*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
48*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
49*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
50*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
51*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
52*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
53*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
54*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
55*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
56*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
57*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
58*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH
59*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
60*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit"
61*053f45beSAndroid Build Coastguard Worker
62*053f45beSAndroid Build Coastguard Worker
63*053f45beSAndroid Build Coastguard Worker# This test is similar to the previous test, but (un)load the livepatch
64*053f45beSAndroid Build Coastguard Worker# module before the target kernel module.  This tests the livepatch
65*053f45beSAndroid Build Coastguard Worker# core's module_coming handler.
66*053f45beSAndroid Build Coastguard Worker#
67*053f45beSAndroid Build Coastguard Worker# - On livepatch enable, only pre/post-patch callbacks are executed for
68*053f45beSAndroid Build Coastguard Worker#   currently loaded klp_objects, in this case, vmlinux.
69*053f45beSAndroid Build Coastguard Worker#
70*053f45beSAndroid Build Coastguard Worker# - When a targeted module is subsequently loaded, only its
71*053f45beSAndroid Build Coastguard Worker#   pre/post-patch callbacks are executed.
72*053f45beSAndroid Build Coastguard Worker#
73*053f45beSAndroid Build Coastguard Worker# - On livepatch disable, all currently loaded klp_objects' (vmlinux and
74*053f45beSAndroid Build Coastguard Worker#   $MOD_TARGET) pre/post-unpatch callbacks are executed.
75*053f45beSAndroid Build Coastguard Worker
76*053f45beSAndroid Build Coastguard Workerstart_test "module_coming notifier"
77*053f45beSAndroid Build Coastguard Worker
78*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
79*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
80*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
81*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
82*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
83*053f45beSAndroid Build Coastguard Worker
84*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
85*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
86*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
87*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
88*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
89*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
90*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
91*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
92*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_TARGET
93*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch '$MOD_LIVEPATCH' to loading module '$MOD_TARGET'
94*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
95*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
96*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
97*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
98*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
99*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
100*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
101*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
102*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
103*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
104*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
105*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
106*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH
107*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
108*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit"
109*053f45beSAndroid Build Coastguard Worker
110*053f45beSAndroid Build Coastguard Worker
111*053f45beSAndroid Build Coastguard Worker# Test loading the livepatch after a targeted kernel module, then unload
112*053f45beSAndroid Build Coastguard Worker# the kernel module before disabling the livepatch.  This tests the
113*053f45beSAndroid Build Coastguard Worker# livepatch core's module_going handler.
114*053f45beSAndroid Build Coastguard Worker#
115*053f45beSAndroid Build Coastguard Worker# - First load a target module, then the livepatch.
116*053f45beSAndroid Build Coastguard Worker#
117*053f45beSAndroid Build Coastguard Worker# - When a target module is unloaded, the livepatch is only reverted
118*053f45beSAndroid Build Coastguard Worker#   from that klp_object ($MOD_TARGET).  As such, only its pre and
119*053f45beSAndroid Build Coastguard Worker#   post-unpatch callbacks are executed when this occurs.
120*053f45beSAndroid Build Coastguard Worker#
121*053f45beSAndroid Build Coastguard Worker# - When the livepatch is disabled, pre and post-unpatch callbacks are
122*053f45beSAndroid Build Coastguard Worker#   run for the remaining klp_object, vmlinux.
123*053f45beSAndroid Build Coastguard Worker
124*053f45beSAndroid Build Coastguard Workerstart_test "module_going notifier"
125*053f45beSAndroid Build Coastguard Worker
126*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
127*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
128*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
129*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
130*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
131*053f45beSAndroid Build Coastguard Worker
132*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_TARGET
133*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
134*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH
135*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
136*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
137*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
138*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
139*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
140*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
141*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
142*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET -> [MODULE_STATE_LIVE] Normal state
143*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
144*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
145*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit
146*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
147*053f45beSAndroid Build Coastguard Workerlivepatch: reverting patch '$MOD_LIVEPATCH' on unloading module '$MOD_TARGET'
148*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
149*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
150*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
151*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
152*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
153*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
154*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
155*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
156*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
157*053f45beSAndroid Build Coastguard Worker
158*053f45beSAndroid Build Coastguard Worker
159*053f45beSAndroid Build Coastguard Worker# This test is similar to the previous test, however the livepatch is
160*053f45beSAndroid Build Coastguard Worker# loaded first.  This tests the livepatch core's module_coming and
161*053f45beSAndroid Build Coastguard Worker# module_going handlers.
162*053f45beSAndroid Build Coastguard Worker#
163*053f45beSAndroid Build Coastguard Worker# - First load the livepatch.
164*053f45beSAndroid Build Coastguard Worker#
165*053f45beSAndroid Build Coastguard Worker# - When a targeted kernel module is subsequently loaded, only its
166*053f45beSAndroid Build Coastguard Worker#   pre/post-patch callbacks are executed.
167*053f45beSAndroid Build Coastguard Worker#
168*053f45beSAndroid Build Coastguard Worker# - When the target module is unloaded, the livepatch is only reverted
169*053f45beSAndroid Build Coastguard Worker#   from the $MOD_TARGET klp_object.  As such, only pre and
170*053f45beSAndroid Build Coastguard Worker#   post-unpatch callbacks are executed when this occurs.
171*053f45beSAndroid Build Coastguard Worker
172*053f45beSAndroid Build Coastguard Workerstart_test "module_coming and module_going notifiers"
173*053f45beSAndroid Build Coastguard Worker
174*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
175*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
176*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
177*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
178*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
179*053f45beSAndroid Build Coastguard Worker
180*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
181*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
182*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
183*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
184*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
185*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
186*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
187*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
188*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_TARGET
189*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch '$MOD_LIVEPATCH' to loading module '$MOD_TARGET'
190*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
191*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
192*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
193*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
194*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit
195*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
196*053f45beSAndroid Build Coastguard Workerlivepatch: reverting patch '$MOD_LIVEPATCH' on unloading module '$MOD_TARGET'
197*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
198*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
199*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
200*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
201*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
202*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
203*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
204*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
205*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
206*053f45beSAndroid Build Coastguard Worker
207*053f45beSAndroid Build Coastguard Worker
208*053f45beSAndroid Build Coastguard Worker# A simple test of loading a livepatch without one of its patch target
209*053f45beSAndroid Build Coastguard Worker# klp_objects ever loaded ($MOD_TARGET).
210*053f45beSAndroid Build Coastguard Worker#
211*053f45beSAndroid Build Coastguard Worker# - Load the livepatch.
212*053f45beSAndroid Build Coastguard Worker#
213*053f45beSAndroid Build Coastguard Worker# - As expected, only pre/post-(un)patch handlers are executed for
214*053f45beSAndroid Build Coastguard Worker#   vmlinux.
215*053f45beSAndroid Build Coastguard Worker
216*053f45beSAndroid Build Coastguard Workerstart_test "target module not present"
217*053f45beSAndroid Build Coastguard Worker
218*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
219*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
220*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
221*053f45beSAndroid Build Coastguard Worker
222*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
223*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
224*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
225*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
226*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
227*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
228*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
229*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
230*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
231*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
232*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
233*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
234*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
235*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
236*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
237*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
238*053f45beSAndroid Build Coastguard Worker
239*053f45beSAndroid Build Coastguard Worker
240*053f45beSAndroid Build Coastguard Worker# Test a scenario where a vmlinux pre-patch callback returns a non-zero
241*053f45beSAndroid Build Coastguard Worker# status (ie, failure).
242*053f45beSAndroid Build Coastguard Worker#
243*053f45beSAndroid Build Coastguard Worker# - First load a target module.
244*053f45beSAndroid Build Coastguard Worker#
245*053f45beSAndroid Build Coastguard Worker# - Load the livepatch module, setting its 'pre_patch_ret' value to -19
246*053f45beSAndroid Build Coastguard Worker#   (-ENODEV).  When its vmlinux pre-patch callback executes, this
247*053f45beSAndroid Build Coastguard Worker#   status code will propagate back to the module-loading subsystem.
248*053f45beSAndroid Build Coastguard Worker#   The result is that the insmod command refuses to load the livepatch
249*053f45beSAndroid Build Coastguard Worker#   module.
250*053f45beSAndroid Build Coastguard Worker
251*053f45beSAndroid Build Coastguard Workerstart_test "pre-patch callback -ENODEV"
252*053f45beSAndroid Build Coastguard Worker
253*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
254*053f45beSAndroid Build Coastguard Workerload_failing_mod $MOD_LIVEPATCH pre_patch_ret=-19
255*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
256*053f45beSAndroid Build Coastguard Worker
257*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_TARGET
258*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
259*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH pre_patch_ret=-19
260*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
261*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
262*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: pre_patch_callback: vmlinux
263*053f45beSAndroid Build Coastguard Workerlivepatch: pre-patch callback failed for object 'vmlinux'
264*053f45beSAndroid Build Coastguard Workerlivepatch: failed to enable patch '$MOD_LIVEPATCH'
265*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch
266*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
267*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
268*053f45beSAndroid Build Coastguard Workermodprobe: ERROR: could not insert '$MOD_LIVEPATCH': No such device
269*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
270*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit"
271*053f45beSAndroid Build Coastguard Worker
272*053f45beSAndroid Build Coastguard Worker
273*053f45beSAndroid Build Coastguard Worker# Similar to the previous test, setup a livepatch such that its vmlinux
274*053f45beSAndroid Build Coastguard Worker# pre-patch callback returns success.  However, when a targeted kernel
275*053f45beSAndroid Build Coastguard Worker# module is later loaded, have the livepatch return a failing status
276*053f45beSAndroid Build Coastguard Worker# code.
277*053f45beSAndroid Build Coastguard Worker#
278*053f45beSAndroid Build Coastguard Worker# - Load the livepatch, vmlinux pre-patch callback succeeds.
279*053f45beSAndroid Build Coastguard Worker#
280*053f45beSAndroid Build Coastguard Worker# - Set a trap so subsequent pre-patch callbacks to this livepatch will
281*053f45beSAndroid Build Coastguard Worker#   return -ENODEV.
282*053f45beSAndroid Build Coastguard Worker#
283*053f45beSAndroid Build Coastguard Worker# - The livepatch pre-patch callback for subsequently loaded target
284*053f45beSAndroid Build Coastguard Worker#   modules will return failure, so the module loader refuses to load
285*053f45beSAndroid Build Coastguard Worker#   the kernel module.  No post-patch or pre/post-unpatch callbacks are
286*053f45beSAndroid Build Coastguard Worker#   executed for this klp_object.
287*053f45beSAndroid Build Coastguard Worker#
288*053f45beSAndroid Build Coastguard Worker# - Pre/post-unpatch callbacks are run for the vmlinux klp_object.
289*053f45beSAndroid Build Coastguard Worker
290*053f45beSAndroid Build Coastguard Workerstart_test "module_coming + pre-patch callback -ENODEV"
291*053f45beSAndroid Build Coastguard Worker
292*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
293*053f45beSAndroid Build Coastguard Workerset_pre_patch_ret $MOD_LIVEPATCH -19
294*053f45beSAndroid Build Coastguard Workerload_failing_mod $MOD_TARGET
295*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
296*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
297*053f45beSAndroid Build Coastguard Worker
298*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
299*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
300*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
301*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
302*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
303*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
304*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
305*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
306*053f45beSAndroid Build Coastguard Worker% echo -19 > /sys/module/$MOD_LIVEPATCH/parameters/pre_patch_ret
307*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_TARGET
308*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch '$MOD_LIVEPATCH' to loading module '$MOD_TARGET'
309*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
310*053f45beSAndroid Build Coastguard Workerlivepatch: pre-patch callback failed for object '$MOD_TARGET'
311*053f45beSAndroid Build Coastguard Workerlivepatch: patch '$MOD_LIVEPATCH' failed for module '$MOD_TARGET', refusing to load module '$MOD_TARGET'
312*053f45beSAndroid Build Coastguard Workermodprobe: ERROR: could not insert '$MOD_TARGET': No such device
313*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
314*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
315*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
316*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
317*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
318*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
319*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
320*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
321*053f45beSAndroid Build Coastguard Worker
322*053f45beSAndroid Build Coastguard Worker
323*053f45beSAndroid Build Coastguard Worker# Test loading multiple targeted kernel modules.  This test-case is
324*053f45beSAndroid Build Coastguard Worker# mainly for comparing with the next test-case.
325*053f45beSAndroid Build Coastguard Worker#
326*053f45beSAndroid Build Coastguard Worker# - Load a target "busy" kernel module which kicks off a worker function
327*053f45beSAndroid Build Coastguard Worker#   that immediately exits.
328*053f45beSAndroid Build Coastguard Worker#
329*053f45beSAndroid Build Coastguard Worker# - Proceed with loading the livepatch and another ordinary target
330*053f45beSAndroid Build Coastguard Worker#   module.  Post-patch callbacks are executed and the transition
331*053f45beSAndroid Build Coastguard Worker#   completes quickly.
332*053f45beSAndroid Build Coastguard Worker
333*053f45beSAndroid Build Coastguard Workerstart_test "multiple target modules"
334*053f45beSAndroid Build Coastguard Worker
335*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET_BUSY block_transition=N
336*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
337*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
338*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
339*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
340*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
341*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET_BUSY
342*053f45beSAndroid Build Coastguard Worker
343*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_TARGET_BUSY block_transition=N
344*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_init
345*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: busymod_work_func enter
346*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: busymod_work_func exit
347*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH
348*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
349*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
350*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
351*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
352*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
353*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
354*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
355*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
356*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
357*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_TARGET
358*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch '$MOD_LIVEPATCH' to loading module '$MOD_TARGET'
359*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
360*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
361*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
362*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
363*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit
364*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
365*053f45beSAndroid Build Coastguard Workerlivepatch: reverting patch '$MOD_LIVEPATCH' on unloading module '$MOD_TARGET'
366*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
367*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
368*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
369*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
370*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
371*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
372*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
373*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
374*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
375*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
376*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH
377*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET_BUSY
378*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_exit"
379*053f45beSAndroid Build Coastguard Worker
380*053f45beSAndroid Build Coastguard Worker
381*053f45beSAndroid Build Coastguard Worker# A similar test as the previous one, but force the "busy" kernel module
382*053f45beSAndroid Build Coastguard Worker# to block the livepatch transition.
383*053f45beSAndroid Build Coastguard Worker#
384*053f45beSAndroid Build Coastguard Worker# The livepatching core will refuse to patch a task that is currently
385*053f45beSAndroid Build Coastguard Worker# executing a to-be-patched function -- the consistency model stalls the
386*053f45beSAndroid Build Coastguard Worker# current patch transition until this safety-check is met.  Test a
387*053f45beSAndroid Build Coastguard Worker# scenario where one of a livepatch's target klp_objects sits on such a
388*053f45beSAndroid Build Coastguard Worker# function for a long time.  Meanwhile, load and unload other target
389*053f45beSAndroid Build Coastguard Worker# kernel modules while the livepatch transition is in progress.
390*053f45beSAndroid Build Coastguard Worker#
391*053f45beSAndroid Build Coastguard Worker# - Load the "busy" kernel module, this time make its work function loop
392*053f45beSAndroid Build Coastguard Worker#
393*053f45beSAndroid Build Coastguard Worker# - Meanwhile, the livepatch is loaded.  Notice that the patch
394*053f45beSAndroid Build Coastguard Worker#   transition does not complete as the targeted "busy" module is
395*053f45beSAndroid Build Coastguard Worker#   sitting on a to-be-patched function.
396*053f45beSAndroid Build Coastguard Worker#
397*053f45beSAndroid Build Coastguard Worker# - Load a second target module (this one is an ordinary idle kernel
398*053f45beSAndroid Build Coastguard Worker#   module).  Note that *no* post-patch callbacks will be executed while
399*053f45beSAndroid Build Coastguard Worker#   the livepatch is still in transition.
400*053f45beSAndroid Build Coastguard Worker#
401*053f45beSAndroid Build Coastguard Worker# - Request an unload of the simple kernel module.  The patch is still
402*053f45beSAndroid Build Coastguard Worker#   transitioning, so its pre-unpatch callbacks are skipped.
403*053f45beSAndroid Build Coastguard Worker#
404*053f45beSAndroid Build Coastguard Worker# - Finally the livepatch is disabled.  Since none of the patch's
405*053f45beSAndroid Build Coastguard Worker#   klp_object's post-patch callbacks executed, the remaining
406*053f45beSAndroid Build Coastguard Worker#   klp_object's pre-unpatch callbacks are skipped.
407*053f45beSAndroid Build Coastguard Worker
408*053f45beSAndroid Build Coastguard Workerstart_test "busy target module"
409*053f45beSAndroid Build Coastguard Worker
410*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET_BUSY block_transition=Y
411*053f45beSAndroid Build Coastguard Workerload_lp_nowait $MOD_LIVEPATCH
412*053f45beSAndroid Build Coastguard Worker
413*053f45beSAndroid Build Coastguard Worker# Wait until the livepatch reports in-transition state, i.e. that it's
414*053f45beSAndroid Build Coastguard Worker# stalled on $MOD_TARGET_BUSY::busymod_work_func()
415*053f45beSAndroid Build Coastguard Workerloop_until 'grep -q '^1$' /sys/kernel/livepatch/$MOD_LIVEPATCH/transition' ||
416*053f45beSAndroid Build Coastguard Worker	die "failed to stall transition"
417*053f45beSAndroid Build Coastguard Worker
418*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET
419*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET
420*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
421*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
422*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET_BUSY
423*053f45beSAndroid Build Coastguard Worker
424*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_TARGET_BUSY block_transition=Y
425*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_init
426*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: busymod_work_func enter
427*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH
428*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
429*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
430*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
431*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
432*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
433*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_TARGET
434*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch '$MOD_LIVEPATCH' to loading module '$MOD_TARGET'
435*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: $MOD_TARGET -> [MODULE_STATE_COMING] Full formed, running module_init
436*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_init
437*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET
438*053f45beSAndroid Build Coastguard Worker$MOD_TARGET: ${MOD_TARGET}_exit
439*053f45beSAndroid Build Coastguard Workerlivepatch: reverting patch '$MOD_LIVEPATCH' on unloading module '$MOD_TARGET'
440*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET -> [MODULE_STATE_GOING] Going away
441*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
442*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': reversing transition from patching to unpatching
443*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
444*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
445*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
446*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: $MOD_TARGET_BUSY -> [MODULE_STATE_LIVE] Normal state
447*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
448*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH
449*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_TARGET_BUSY
450*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: busymod_work_func exit
451*053f45beSAndroid Build Coastguard Worker$MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_exit"
452*053f45beSAndroid Build Coastguard Worker
453*053f45beSAndroid Build Coastguard Worker
454*053f45beSAndroid Build Coastguard Worker# Test loading multiple livepatches.  This test-case is mainly for comparing
455*053f45beSAndroid Build Coastguard Worker# with the next test-case.
456*053f45beSAndroid Build Coastguard Worker#
457*053f45beSAndroid Build Coastguard Worker# - Load and unload two livepatches, pre and post (un)patch callbacks
458*053f45beSAndroid Build Coastguard Worker#   execute as each patch progresses through its (un)patching
459*053f45beSAndroid Build Coastguard Worker#   transition.
460*053f45beSAndroid Build Coastguard Worker
461*053f45beSAndroid Build Coastguard Workerstart_test "multiple livepatches"
462*053f45beSAndroid Build Coastguard Worker
463*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
464*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH2
465*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH2
466*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH
467*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH2
468*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
469*053f45beSAndroid Build Coastguard Worker
470*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
471*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
472*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
473*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
474*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
475*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
476*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
477*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
478*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH2
479*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH2'
480*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': initializing patching transition
481*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: pre_patch_callback: vmlinux
482*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': starting patching transition
483*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': completing patching transition
484*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: post_patch_callback: vmlinux
485*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': patching complete
486*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
487*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
488*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
489*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': starting unpatching transition
490*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': completing unpatching transition
491*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
492*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': unpatching complete
493*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
494*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
495*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
496*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition
497*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition
498*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_unpatch_callback: vmlinux
499*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': unpatching complete
500*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH2
501*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
502*053f45beSAndroid Build Coastguard Worker
503*053f45beSAndroid Build Coastguard Worker
504*053f45beSAndroid Build Coastguard Worker# Load multiple livepatches, but the second as an 'atomic-replace'
505*053f45beSAndroid Build Coastguard Worker# patch.  When the latter loads, the original livepatch should be
506*053f45beSAndroid Build Coastguard Worker# disabled and *none* of its pre/post-unpatch callbacks executed.  On
507*053f45beSAndroid Build Coastguard Worker# the other hand, when the atomic-replace livepatch is disabled, its
508*053f45beSAndroid Build Coastguard Worker# pre/post-unpatch callbacks *should* be executed.
509*053f45beSAndroid Build Coastguard Worker#
510*053f45beSAndroid Build Coastguard Worker# - Load and unload two livepatches, the second of which has its
511*053f45beSAndroid Build Coastguard Worker#   .replace flag set true.
512*053f45beSAndroid Build Coastguard Worker#
513*053f45beSAndroid Build Coastguard Worker# - Pre and post patch callbacks are executed for both livepatches.
514*053f45beSAndroid Build Coastguard Worker#
515*053f45beSAndroid Build Coastguard Worker# - Once the atomic replace module is loaded, only its pre and post
516*053f45beSAndroid Build Coastguard Worker#   unpatch callbacks are executed.
517*053f45beSAndroid Build Coastguard Worker
518*053f45beSAndroid Build Coastguard Workerstart_test "atomic replace"
519*053f45beSAndroid Build Coastguard Worker
520*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH
521*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH2 replace=1
522*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH2
523*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH2
524*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH
525*053f45beSAndroid Build Coastguard Worker
526*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH
527*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH'
528*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition
529*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: pre_patch_callback: vmlinux
530*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition
531*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition
532*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH: post_patch_callback: vmlinux
533*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete
534*053f45beSAndroid Build Coastguard Worker% modprobe $MOD_LIVEPATCH2 replace=1
535*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH2'
536*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': initializing patching transition
537*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: pre_patch_callback: vmlinux
538*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': starting patching transition
539*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': completing patching transition
540*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: post_patch_callback: vmlinux
541*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': patching complete
542*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
543*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
544*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
545*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': starting unpatching transition
546*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': completing unpatching transition
547*053f45beSAndroid Build Coastguard Worker$MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
548*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH2': unpatching complete
549*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH2
550*053f45beSAndroid Build Coastguard Worker% rmmod $MOD_LIVEPATCH"
551*053f45beSAndroid Build Coastguard Worker
552*053f45beSAndroid Build Coastguard Worker
553*053f45beSAndroid Build Coastguard Workerexit 0
554