From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D87F3B83EC for ; Sun, 24 May 2026 23:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779666657; cv=none; b=fOpcZz/USjEkWANE6wwt4K+ktIgHtvTnvE39uJJMZXO2lGTR/F/ymu9pj3hCTDrwjKfnSdAzt43e45yr9F6AgKoAEhfCfoXpEBVSqDp2oKe1KGnsBWoWk5EY58RrFnX1XH9ue67DPnLYiYUIIVgUX9zsEQBp5GYEQ7LZq9XYSG8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779666657; c=relaxed/simple; bh=I7SegwAIOnn8Zt1SWPZf8rhhwlN2a4741JSURcMiDOw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WWnr+WNxeRVJAIyQNDLhFsUjKQQQ8ayy3+aEn7IwsHzzIP4mAaExmrUAoN6zltCBfFwTY/0zQMeZa6e8tnKivQqEvQHYz70/u8dtbv9oavoJ5f6YOdSTwiNubRPTNjHBdhn5d9QuEQBHJdiEOtRLgWK90GehhbhALb7HQkJ4WuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=bzDU8MgZ; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="bzDU8MgZ" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-44e5624c053so5397775f8f.2 for ; Sun, 24 May 2026 16:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779666654; x=1780271454; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sEd9trovmFOEJuYQnYpCKWBckKvvMl+JmjSp64a8XTE=; b=bzDU8MgZd5a9/D+mmIT47q+jzXwQgIqHosG/qplwe7BthAo0TfKSgmKLSzb/aq5opX bHpMLEMBhHg0axBMkQt6q4uVONkbgOGMjUXtSuQLgDoCtCMiCPXVzbzGa/I7aVpNbj4J yy6PvF3SS+LQ0xKK10i9Hx2t9NPWFvU+1VMRGsck1zrcDQgsucEDSTFlj93IUbhass2d SBaGHfxXItxTQn8b4LuiOPNANfP+s7NxpgyUsz6n3C4sq9Ec6F+9A2IwRXfukTsFDr2u 3FNEuJAEp01v7NHS5tbGvopaN/8ucQsckNIXfzhiIrM7RBAy62DeiUNn4Yvx7Ym3nQyD Dg9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779666654; x=1780271454; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sEd9trovmFOEJuYQnYpCKWBckKvvMl+JmjSp64a8XTE=; b=orGJZgfshC3tMag1bTBPqGxwfzhTp1PJi6xBQoMfU6AGGv2hF4IVT1EWzVrfTGEYfp K4k0XqBlfW9xf/5GvR+gILRHDP7rsHcaKWOuW67UgB0vIx9BDjGTP05QIUxu2Z6qgt+p NjmGJiutTL/CFTw6amLnmlVycrwlyeWsdhEzMmJsEzPDdIohCzptwQHXEIvKOe9Xu5+e 86d1ind55B85YdudYie29oBUbNFp0wdKgBiLOkGRrkufvvnE3c4p8u5WtRWhS7r5vHgz aOnwxHNxPPq5nLWldZTz60BPDiSmZ7N/Mm7U/6Knfdp6R4BjXh4I1iQzT1n61o6WtvNC 1lNQ== X-Forwarded-Encrypted: i=1; AFNElJ+qk+hc0sMr0wyXHHjx27VUIErfFQ+e4gREtPnUwgjgz8zilHv5foqNC4zimJfu07ttds8I8FwHlbCChqM=@vger.kernel.org X-Gm-Message-State: AOJu0YyEq8sf2mhoNsT93aBe/21b/OZB3H8d8ntpDh7103CxmrpTqoBK rehv62u/z7RlTR3spcZH7ZHNy6AF/XTZq57IV7X4lpj+CP8h7qSba4yCJLqBhmqH/70= X-Gm-Gg: Acq92OFAv9zjZms0f/6y/zRLw5TYManOZ4qdJn0qvhH4AaSBxzqikL/WF0PSz774EIJ C/jPgeR3OZ0N9ccvF7o55gtwQpXmiooqpSVEA1MK0j/6EKcUztInaU+memVv4jPwbqouXdansVw SrJOc06ot+zmUGisabw+RMGOU7RI1POQxe33+9L8qr53GcSNfqyhKd3eT3mD62Y8nOywF/25hMx T8lm6ax/TSrulJfpt8unRyx+6KJ6xUwiktd77YQ1S+Lbxm4vCJIGjt0MWrlvnQQ5AF+9Lgr5UCG 81yMSUQoRU3dSWP58Qcld4rVvUTBa3eKk+c8wjBy8mk268xWqQk2sIKuJIC+5bbw+HFLG5ccHyv Wm2F237fiOJxfACPd5QOUkIzrekYsIfnuIboxVo5Iv/eJJrRmL+5Hbo/1/H/oqr2XAxXRtSgAq7 eIjtMuAdHejkFGcyRR83JnUXQ= X-Received: by 2002:a05:6000:1848:b0:43c:f583:126a with SMTP id ffacd0b85a97d-45eb3681dd5mr21176568f8f.14.1779666653913; Sun, 24 May 2026 16:50:53 -0700 (PDT) Received: from [127.0.0.1] ([2804:1bc4:224:7800:585c:db3a:fcb:e21f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6c9de2dsm21698074f8f.4.2026.05.24.16.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2026 16:50:53 -0700 (PDT) From: Marcos Paulo de Souza Date: Sun, 24 May 2026 20:50:32 -0300 Subject: [PATCH 3/4] selftests: livepatch: Adapt mod_target module to pass on 4.12 kernels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260524-livepatch-unload-on-fail-v1-3-7465de7f741d@suse.com> References: <20260524-livepatch-unload-on-fail-v1-0-7465de7f741d@suse.com> In-Reply-To: <20260524-livepatch-unload-on-fail-v1-0-7465de7f741d@suse.com> To: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan Cc: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Marcos Paulo de Souza , marcos@mpdesouza.com X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1779666636; l=7263; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=I7SegwAIOnn8Zt1SWPZf8rhhwlN2a4741JSURcMiDOw=; b=1uJcE2ihxX9xMhy8tFuu81DedgR/I+bCRVHF3aRExvGqRtd/379RSWq8vg8SYgCqJCQYEGxLY ycGoA8VvjToC/kRcqnAweBnCbRu6ekcKcQTE24TaC5HIl81w+75k/cd X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= Use the stable module_param_cb API instead of proc_fs for exposing module state. This approach is compatible with kernel 4.12 and later. The end result is the same: the module has a function that shows a string, which is later livepatched to show a different string. The only difference is that the file being checked is now a module parameter instead of a procfs entry. Signed-off-by: Marcos Paulo de Souza --- tools/testing/selftests/livepatch/functions.sh | 1 + .../testing/selftests/livepatch/test-livepatch.sh | 23 +++++++++++----------- .../livepatch/test_modules/test_klp_mod_patch.c | 11 +++++------ .../livepatch/test_modules/test_klp_mod_target.c | 22 ++++++++++----------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh index 25f137003865..c8c99851c3a2 100644 --- a/tools/testing/selftests/livepatch/functions.sh +++ b/tools/testing/selftests/livepatch/functions.sh @@ -7,6 +7,7 @@ MAX_RETRIES=600 RETRY_INTERVAL=".1" # seconds SYSFS_KERNEL_DIR="/sys/kernel" +SYSFS_MODULE_DIR="/sys/module" SYSFS_KLP_DIR="$SYSFS_KERNEL_DIR/livepatch" SYSFS_DEBUG_DIR="$SYSFS_KERNEL_DIR/debug" SYSFS_KPROBES_DIR="$SYSFS_DEBUG_DIR/kprobes" diff --git a/tools/testing/selftests/livepatch/test-livepatch.sh b/tools/testing/selftests/livepatch/test-livepatch.sh index c44c5341a2f1..06aacf0f4dc7 100755 --- a/tools/testing/selftests/livepatch/test-livepatch.sh +++ b/tools/testing/selftests/livepatch/test-livepatch.sh @@ -198,26 +198,25 @@ livepatch: '$MOD_REPLACE': unpatching complete % rmmod $MOD_REPLACE" -# - load a target module that provides /proc/test_klp_mod_target with -# original output -# - load a livepatch that patches the target module's show function -# - verify the proc entry returns livepatched output +# - load a target module with module_param_cb get data with original output +# - load a livepatch that patches the target module's get function +# - verify the parameter get function returns the livepatched output # - disable and unload the livepatch -# - verify the proc entry returns original output again +# - verify the parameter get function returns the original output again # - unload the target module start_test "module function patching" load_mod $MOD_TARGET -if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then +if [[ "$(cat $SYSFS_MODULE_DIR/$MOD_TARGET/parameters/klp_mod_arg)" != "$MOD_TARGET: original output" ]] ; then echo -e "FAIL\n\n" die "livepatch kselftest(s) failed" fi load_lp $MOD_TARGET_PATCH -if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then +if [[ "$(cat $SYSFS_MODULE_DIR/$MOD_TARGET/parameters/klp_mod_arg)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then echo -e "FAIL\n\n" die "livepatch kselftest(s) failed" fi @@ -225,7 +224,7 @@ fi disable_lp $MOD_TARGET_PATCH unload_lp $MOD_TARGET_PATCH -if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then +if [[ "$(cat $SYSFS_MODULE_DIR/$MOD_TARGET/parameters/klp_mod_arg)" != "$MOD_TARGET: original output" ]] ; then echo -e "FAIL\n\n" die "livepatch kselftest(s) failed" fi @@ -252,9 +251,9 @@ $MOD_TARGET: test_klp_mod_target_exit" # - load a livepatch that targets a not-yet-loaded module # - load the target module: klp_module_coming patches it immediately -# - verify the proc entry returns livepatched output +# - verify the parameter get function returns the livepatched output # - disable and unload the livepatch -# - verify the proc entry returns original output again +# - verify the parameter get function returns the original output again # - unload the target module start_test "module function patching (livepatch first)" @@ -262,7 +261,7 @@ start_test "module function patching (livepatch first)" load_lp $MOD_TARGET_PATCH load_mod $MOD_TARGET -if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then +if [[ "$(cat $SYSFS_MODULE_DIR/$MOD_TARGET/parameters/klp_mod_arg)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then echo -e "FAIL\n\n" die "livepatch kselftest(s) failed" fi @@ -270,7 +269,7 @@ fi disable_lp $MOD_TARGET_PATCH unload_lp $MOD_TARGET_PATCH -if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then +if [[ "$(cat $SYSFS_MODULE_DIR/$MOD_TARGET/parameters/klp_mod_arg)" != "$MOD_TARGET: original output" ]] ; then echo -e "FAIL\n\n" die "livepatch kselftest(s) failed" fi diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_mod_patch.c b/tools/testing/selftests/livepatch/test_modules/test_klp_mod_patch.c index 6725b4720365..ab56e57c02a8 100644 --- a/tools/testing/selftests/livepatch/test_modules/test_klp_mod_patch.c +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_mod_patch.c @@ -8,17 +8,16 @@ #include #include -static int livepatch_mod_target_show(struct seq_file *m, void *v) +static int livepatch_mod_target_get(char *buffer, const struct kernel_param *kp) { - seq_printf(m, "%s: %s\n", THIS_MODULE->name, - "this has been live patched"); - return 0; + return sprintf(buffer, "%s: %s\n", THIS_MODULE->name, + "this has been live patched"); } static struct klp_func funcs[] = { { - .old_name = "test_klp_mod_target_show", - .new_func = livepatch_mod_target_show, + .old_name = "test_klp_mod_target_get", + .new_func = livepatch_mod_target_get, }, {}, }; diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_mod_target.c b/tools/testing/selftests/livepatch/test_modules/test_klp_mod_target.c index 9643984d2402..1382a266825f 100644 --- a/tools/testing/selftests/livepatch/test_modules/test_klp_mod_target.c +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_mod_target.c @@ -5,31 +5,29 @@ #include #include -#include -#include +#include -static struct proc_dir_entry *pde; - -static noinline int test_klp_mod_target_show(struct seq_file *m, void *v) +static noinline int test_klp_mod_target_get(char *buffer, const struct kernel_param *kp) { - seq_printf(m, "%s: %s\n", THIS_MODULE->name, "original output"); - return 0; + return sprintf(buffer, "%s: %s\n", THIS_MODULE->name, "original output"); } +static const struct kernel_param_ops test_klp_mod_target_ops = { + .get = test_klp_mod_target_get, +}; + +module_param_cb(klp_mod_arg, &test_klp_mod_target_ops, NULL, 0444); +MODULE_PARM_DESC(klp_mod_arg, "The value of this argument will be livepatched"); + static int test_klp_mod_target_init(void) { pr_info("%s\n", __func__); - pde = proc_create_single("test_klp_mod_target", 0, NULL, - test_klp_mod_target_show); - if (!pde) - return -ENOMEM; return 0; } static void test_klp_mod_target_exit(void) { pr_info("%s\n", __func__); - proc_remove(pde); } module_init(test_klp_mod_target_init); -- 2.54.0