Re: [POC 5/7] livepatch: Convert klp module callbacks tests into livepatch module tests

2023-11-10 Thread kernel test robot
Hi Petr,

kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes linus/master v6.6 next-20231110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Petr-Mladek/livepatch-Add-callbacks-for-introducing-and-removing-states/2023-014906
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:
https://lore.kernel.org/r/20231110170428.6664-6-pmladek%40suse.com
patch subject: [POC 5/7] livepatch: Convert klp module callbacks tests into 
livepatch module tests
config: s390-defconfig 
(https://download.01.org/0day-ci/archive/2023/20230928.ui5nizht-...@intel.com/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/2023/20230928.ui5nizht-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/20230928.ui5nizht-...@intel.com/

All errors (new ones prefixed by >>):

>> make[5]: *** No rule to make target 'lib/livepatch/test_klp_speaker2.o', 
>> needed by 'lib/livepatch/'.
>> make[5]: *** No rule to make target 
>> 'lib/livepatch/test_klp_speaker_livepatch2.o', needed by 'lib/livepatch/'.
   make[5]: *** [scripts/Makefile.build:243: lib/livepatch/test_klp_speaker.o] 
Error 1
   make[5]: *** [scripts/Makefile.build:243: 
lib/livepatch/test_klp_speaker_livepatch.o] Error 1
   make[5]: Target 'lib/livepatch/' not remade because of errors.

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki



[POC 5/7] livepatch: Convert klp module callbacks tests into livepatch module tests

2023-11-10 Thread Petr Mladek
The original livepatch callbacks has been obsoleted by the livepatch
state callbacks.

The important difference is that the original callbacks were associated
with the livepatched object. The state callbacks are associated with
the livepatch states which are associated with the livepatch.

As a result, some per-object callbacks functionality could not be
preserved with the new per-state callbacks. Namely, it is not
possible to change a state when a livepatched module is loaded
or unloaded. This usecase it considered rare and not worth
the complexity.

Instead, the callback self-tests are transformed into testing
the new state callbacks. Some tests do not use the callbacks
any longer. But they still test some basic scenarios which
is not tested by other tests.

Many features are added to the test_klp_speaker module:

  - The parameter "welcome" allows to call the livepatched
function speaker_welcome.

  - The parameter "waiting_welcome" allows to a trigger
a workqueue work which might busy wait in a livepatched
function and block the transition.

It requires storing pointer to speaker_wait_and_welcome()
so that the original one could be called from the livepatch.

Alternative solution would be to livepatch
speaker_wait_and_welcome() but it would require passing
pointer to the completion structure from the livepatched module.

Another tricky part is the initialization of the work structure.
It must be initialized in the module init() callback so that it can
be flushed in the exit() callback even when it was not used. But
it must be initialized also in waiting_welcome_set() because
the module parameter callbacks are proceed before calling
the module init() callback.

  - The same sources are used to build two target modules.
The livepatched functions have versioned names. It makes it easier
to distinguish messages printed by this functions and the livepatched
variants.

It is solved by using macro for definition of the functions.

Many features are added also into the livepatch module:

   - The parameter "add_applause" allows to add "[APPLAUSE " string
 into the message printed by speaker_welcome(). The string
 is stored in a shadow variable which is:

   - associated with a state.
   - allocated and initialized to "[] " in setup() state callback.
   - set to "[APPLAUSE ]" in enable() state callback.
   - set back to "[] " in disable() state callback.
   - freed in release() state callback.

 Allows testing state callbacks. It even allows to distinguish
 the state after setup() and enable() callbacks.

   - The parameter "setup_ret" allow to force a negative return
 value to the callback allocation the shadow variable.

   - The parameter "noreplace" allows to disable patch.replace
 parameter and install the livepatch in parallel with
 others.

   - The same sources are used for building two livepatches.
 It allows writing tests with more livepatches.

 The livepatched functions are versioned. Both livepatches
 can livepatch both speaker test modules.

 But they use the same shadow variable for storing
 the "add_applause" feature. It allows testing passing
 the states and shadow variables with atomic replace.

 But obviously, "add_applause" parameter could no be
 used for both livepatches when they are loaded in parallel
 using the "noreplace" parameter.

Finally, remove the obsolete and unused "callback" test modules
and livepatches.

TODO:

   - Debug why "waiting_welcome" does not block the transition.
 The livepatched function is not on the stack from unknown
 reasons. See the comments in test-module.h for more details.

   - Better organize the tests. test-module.sh combines
 tests of various aspects which might better be suited
 somewhere else.

 As a first step, test-callbacks.sh has been renamed
 to test-modules.sh. But there still might be a better name.

   - Split this huge patch. Add the various features and tests
 in more steps.

Signed-off-by: Petr Mladek 
---
 lib/livepatch/Makefile|   6 +-
 lib/livepatch/test_klp_callbacks_busy.c   |  70 ---
 lib/livepatch/test_klp_callbacks_demo.c   | 121 
 lib/livepatch/test_klp_callbacks_demo2.c  |  93 ---
 lib/livepatch/test_klp_callbacks_mod.c|  24 -
 lib/livepatch/test_klp_speaker.c  | 153 -
 lib/livepatch/test_klp_speaker_livepatch.c| 209 ++-
 tools/testing/selftests/livepatch/Makefile|   2 +-
 .../testing/selftests/livepatch/functions.sh  |  29 +
 .../selftests/livepatch/test-callbacks.sh | 553 --
 .../selftests/livepatch/test-modules.sh   | 539 +
 11 files changed, 929 insertions(+), 870 deletions(-)
 delete mode 100644 lib/livepatch/test_klp_callbacks_busy.c
 delete mode 100644 lib/livepatch/test_klp_callbacks_demo.c
 delete mode 100644