[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240925064047.95503-2-zhangwarden@gmail.com>
Date: Wed, 25 Sep 2024 14:40:46 +0800
From: Wardenjohn <zhangwarden@...il.com>
To: jpoimboe@...nel.org,
mbenes@...e.cz,
jikos@...nel.org,
pmladek@...e.com,
joe.lawrence@...hat.com
Cc: live-patching@...r.kernel.org,
linux-kernel@...r.kernel.org,
Wardenjohn <zhangwarden@...il.com>
Subject: [PATCH] livepatch: introduce 'stack_order' sysfs interface to klp_patch
This feature can provide livepatch patch order information.
With the order of sysfs interface of one klp_patch, we can
use patch order to find out which function of the patch is
now activate.
After the discussion, we decided that patch-level sysfs
interface is the only accaptable way to introduce this
information.
This feature is like:
cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
means this livepatch_1 module is the 1st klp patch applied.
cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
means this lviepatch_module is the Nth klp patch applied
to the system.
Suggested-by: Petr Mladek <pmladek@...e.com>
Suggested-by: Miroslav Benes <mbenes@...e.cz>
Suggested-by: Josh Poimboeuf <jpoimboe@...nel.org>
Signed-off-by: Wardenjohn <zhangwarden@...il.com>
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ecbc9b6aba3a..914b7cabf8fe 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,
* /sys/kernel/livepatch/<patch>/enabled
* /sys/kernel/livepatch/<patch>/transition
* /sys/kernel/livepatch/<patch>/force
+ * /sys/kernel/livepatch/<patch>/stack_order
* /sys/kernel/livepatch/<patch>/<object>
* /sys/kernel/livepatch/<patch>/<object>/patched
* /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -443,13 +444,37 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
return count;
}
+static ssize_t stack_order_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct klp_patch *patch, *this_patch;
+ int stack_order = 0;
+
+ this_patch = container_of(kobj, struct klp_patch, kobj);
+
+ /* make sure the calculate of patch order correct */
+ mutex_lock(&klp_mutex);
+
+ klp_for_each_patch(patch) {
+ stack_order++;
+ if (patch == this_patch)
+ break;
+ }
+
+ mutex_unlock(&klp_mutex);
+ return sysfs_emit(buf, "%d\n", stack_order);
+}
+
+
static struct kobj_attribute enabled_kobj_attr = __ATTR_RW(enabled);
static struct kobj_attribute transition_kobj_attr = __ATTR_RO(transition);
static struct kobj_attribute force_kobj_attr = __ATTR_WO(force);
+static struct kobj_attribute stack_order_kobj_attr = __ATTR_RO(stack_order);
static struct attribute *klp_patch_attrs[] = {
&enabled_kobj_attr.attr,
&transition_kobj_attr.attr,
&force_kobj_attr.attr,
+ &stack_order_kobj_attr.attr,
NULL
};
ATTRIBUTE_GROUPS(klp_patch);
--
2.18.2
Powered by blists - more mailing lists