From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
Jessica Yu <jeyu@redhat.com>, Jiri Kosina <jikos@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>
Subject: [PATCH 3/3] livepatch: add shadow variable sample program
Date: Thu, 1 Jun 2017 14:25:26 -0400 [thread overview]
Message-ID: <1496341526-19061-4-git-send-email-joe.lawrence@redhat.com> (raw)
In-Reply-To: <1496341526-19061-1-git-send-email-joe.lawrence@redhat.com>
Modify the sample livepatch to demonstrate the shadow variable API.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
samples/livepatch/livepatch-sample.c | 39 +++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/samples/livepatch/livepatch-sample.c b/samples/livepatch/livepatch-sample.c
index 84795223f15f..e0236750cefb 100644
--- a/samples/livepatch/livepatch-sample.c
+++ b/samples/livepatch/livepatch-sample.c
@@ -25,26 +25,57 @@
/*
* This (dumb) live patch overrides the function that prints the
- * kernel boot cmdline when /proc/cmdline is read.
+ * kernel boot cmdline when /proc/cmdline is read. It also
+ * demonstrates a contrived shadow-variable usage.
*
* Example:
*
* $ cat /proc/cmdline
* <your cmdline>
+ * current=<current task pointer> count=<shadow variable counter>
*
* $ insmod livepatch-sample.ko
* $ cat /proc/cmdline
* this has been live patched
+ * current=ffff8800331c9540 count=1
+ * $ cat /proc/cmdline
+ * this has been live patched
+ * current=ffff8800331c9540 count=2
*
* $ echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled
* $ cat /proc/cmdline
* <your cmdline>
*/
+static LIST_HEAD(shadow_list);
+
+struct task_ctr {
+ struct list_head list;
+ int count;
+};
+
#include <linux/seq_file.h>
+#include <linux/slab.h>
static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
{
+ struct task_ctr *nd;
+
+ nd = klp_shadow_get(current, "task_ctr");
+ if (!nd) {
+ nd = kzalloc(sizeof(*nd), GFP_KERNEL);
+ if (nd) {
+ list_add(&nd->list, &shadow_list);
+ klp_shadow_attach(current, "task_ctr", GFP_KERNEL, nd);
+ }
+ }
+
seq_printf(m, "%s\n", "this has been live patched");
+
+ if (nd) {
+ nd->count++;
+ seq_printf(m, "current=%p count=%d\n", current, nd->count);
+ }
+
return 0;
}
@@ -99,6 +130,12 @@ static int livepatch_init(void)
static void livepatch_exit(void)
{
+ struct task_ctr *nd, *tmp;
+
+ list_for_each_entry_safe(nd, tmp, &shadow_list, list) {
+ list_del(&nd->list);
+ kfree(nd);
+ }
WARN_ON(klp_unregister_patch(&patch));
}
--
1.8.3.1
next prev parent reply other threads:[~2017-06-01 18:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-01 18:25 [PATCH 0/3] livepatch: add shadow variable API Joe Lawrence
2017-06-01 18:25 ` [PATCH 1/3] livepatch: introduce " Joe Lawrence
2017-06-08 16:49 ` Josh Poimboeuf
2017-06-09 15:36 ` Joe Lawrence
2017-06-09 18:34 ` Josh Poimboeuf
2017-06-12 13:49 ` Joe Lawrence
2017-06-14 12:59 ` Petr Mladek
2017-06-14 13:17 ` Josh Poimboeuf
2017-06-14 14:26 ` Petr Mladek
2017-06-19 16:09 ` Miroslav Benes
2017-06-01 18:25 ` [PATCH 2/3] livepatch: add shadow variable documentation Joe Lawrence
2017-06-14 13:10 ` Petr Mladek
2017-06-01 18:25 ` Joe Lawrence [this message]
2017-06-09 18:38 ` [PATCH 3/3] livepatch: add shadow variable sample program Josh Poimboeuf
2017-06-09 19:05 ` Joe Lawrence
2017-06-13 11:00 ` Miroslav Benes
2017-06-13 17:32 ` Joe Lawrence
2017-06-14 7:45 ` Miroslav Benes
2017-06-14 14:21 ` Petr Mladek
2017-06-14 14:57 ` Josh Poimboeuf
2017-06-15 10:59 ` Petr Mladek
2017-06-15 13:49 ` Josh Poimboeuf
[not found] ` <20170615143800.d6f5p5bdm4ueecly@redhat.com>
2017-06-15 15:23 ` Josh Poimboeuf
2017-06-19 16:56 ` Miroslav Benes
2017-06-30 20:32 ` Josh Poimboeuf
2017-07-01 6:53 ` Miroslav Benes
2017-06-14 15:15 ` Joe Lawrence
2017-06-19 16:43 ` Miroslav Benes
2017-06-01 20:05 ` [PATCH 0/3] livepatch: add shadow variable API Jiri Kosina
2017-06-01 20:23 ` Joe Lawrence
2017-06-01 20:32 ` Jiri Kosina
2017-06-13 10:19 ` Miroslav Benes
2017-06-13 17:29 ` Joe Lawrence
2017-06-14 8:02 ` Miroslav Benes
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=1496341526-19061-4-git-send-email-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=jeyu@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.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®