mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li Bin <huawei.libin@huawei.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>,
	Seth Jennings <sjenning@redhat.com>,
	Jiri Kosina <jkosina@suse.cz>, Vojtech Pavlik <vojtech@suse.cz>
Cc: <live-patching@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<xiexiuqi@huawei.com>, <huawei.libin@huawei.com>
Subject: [PATCH] livepatch: add sysfs interface /sys/kernel/livepatch/state
Date: Wed, 17 Jun 2015 14:31:11 +0800	[thread overview]
Message-ID: <1434522671-31951-1-git-send-email-huawei.libin@huawei.com> (raw)

The added sysfs interface /sys/kernel/livepatch/state is read-only,
it shows the patches that have been applied, incluing the stack index
and the state of each patch.

$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			enabled
-----------------------------------------------

$ echo 0 > /sys/kernel/livepatch/klp_test3/enabled
$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			disabled
-----------------------------------------------

Signed-off-by: Li Bin <huawei.libin@huawei.com>
---
 Documentation/ABI/testing/sysfs-kernel-livepatch |    9 +++++
 kernel/livepatch/core.c                          |   41 +++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
index 5bf42a8..01c64da 100644
--- a/Documentation/ABI/testing/sysfs-kernel-livepatch
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -8,6 +8,15 @@ Description:
 		The /sys/kernel/livepatch directory contains subdirectories for
 		each loaded live patch module.
 
+What:		/sys/kernel/livepatch/state
+Date:		Jun 2015
+KernelVersion:	4.1.0	
+Contact:	live-patching@vger.kernel.org
+Description:
+		The state file is read-only and shows the patches that have
+		been applied, including the patch stack index and state of
+		each patch. 
+
 What:		/sys/kernel/livepatch/<patch>
 Date:		Nov 2014
 KernelVersion:	3.19.0
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3f9f1d6..5d004f3 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -604,6 +604,7 @@ EXPORT_SYMBOL_GPL(klp_enable_patch);
  * Sysfs Interface
  *
  * /sys/kernel/livepatch
+ * /sys/kernel/livepatch/state
  * /sys/kernel/livepatch/<patch>
  * /sys/kernel/livepatch/<patch>/enabled
  * /sys/kernel/livepatch/<patch>/<object>
@@ -1008,6 +1009,36 @@ static struct notifier_block klp_module_nb = {
 	.priority = INT_MIN+1, /* called late but before ftrace notifier */
 };
 
+static ssize_t state_show(struct kobject *kobj,
+			    struct kobj_attribute *attr, char *buf)
+{
+	struct klp_patch *patch;
+	unsigned long size = 0;
+	int index = 0;
+	size += snprintf(buf+size, PAGE_SIZE-size-1, "%-5s\t%-26s\t%-8s\n", "Index", "Patch", "State");
+	size += snprintf(buf+size, PAGE_SIZE-size-1, "-----------------------------------------------\n");
+	mutex_lock(&klp_mutex);
+	list_for_each_entry(patch, &klp_patches, list) {
+		size += snprintf(buf+size, PAGE_SIZE-size-1, "%-5d\t%-26s\t%-8s\n",
+			++index, patch->mod->name, patch->state ? "enabled" : "disabled");
+	}
+	mutex_unlock(&klp_mutex);
+	size += snprintf(buf+size, PAGE_SIZE-size-1, "-----------------------------------------------\n");
+
+	return size;
+}
+static struct kobj_attribute state_kobj_attr = __ATTR_RO(state);
+
+static struct attribute *klp_top_attrs[] = {
+	&state_kobj_attr.attr,
+	NULL
+};
+
+static struct kobj_type klp_ktype_top = {
+	.sysfs_ops = &kobj_sysfs_ops,
+	.default_attrs = klp_top_attrs,
+};
+
 static int klp_init(void)
 {
 	int ret;
@@ -1022,12 +1053,20 @@ static int klp_init(void)
 	if (ret)
 		return ret;
 
-	klp_root_kobj = kobject_create_and_add("livepatch", kernel_kobj);
+	klp_root_kobj = kzalloc(sizeof(*klp_root_kobj), GFP_KERNEL);
 	if (!klp_root_kobj) {
 		ret = -ENOMEM;
 		goto unregister;
 	}
 
+	ret = kobject_init_and_add(klp_root_kobj, &klp_ktype_top,
+			kernel_kobj, "livepatch");
+	if (ret) {
+		kobject_put(klp_root_kobj);
+		klp_root_kobj = NULL;
+		goto unregister;
+	}
+
 	return 0;
 
 unregister:
-- 
1.7.7


             reply	other threads:[~2015-06-17  6:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17  6:31 Li Bin [this message]
2015-06-17  8:13 ` Miroslav Benes
2015-06-17  9:19   ` Li Bin
2015-06-17 13:20     ` Miroslav Benes
2015-06-18  1:59       ` Li Bin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434522671-31951-1-git-send-email-huawei.libin@huawei.com \
    --to=huawei.libin@huawei.com \
    --cc=jkosina@suse.cz \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=sjenning@redhat.com \
    --cc=vojtech@suse.cz \
    --cc=xiexiuqi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®