From: Miroslav Benes <mbenes@suse.cz>
To: jpoimboe@redhat.com, jeyu@redhat.com, jikos@kernel.org
Cc: pmladek@suse.com, live-patching@vger.kernel.org,
linux-kernel@vger.kernel.org, Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH 1/3] livepatch: Add force sysfs attribute
Date: Thu, 18 May 2017 14:00:41 +0200 [thread overview]
Message-ID: <20170518120043.7205-2-mbenes@suse.cz> (raw)
In-Reply-To: <20170518120043.7205-1-mbenes@suse.cz>
Add write-only force attribute to livepatch sysfs infrastructure. We can
use it later to force couple of events during a live patching process.
Be it a sending of a fake signal or forcing of the tasks' successful
conversion.
It does not make sense to use the force facility when there is no
transaction running (although there is no harm doing that). Therefore we
limit only to situations when klp_transition_patch variable is set.
Normally, klp_mutex lock should be grabbed, because the variable is
shared. However that would hold the action back unnecessarily because of
waiting for the lock, so we omit the lock here. The resulting race
window is harmless (using force when there is no transaction running).
Signed-off-by: Miroslav Benes <mbenes@suse.cz>
---
Documentation/ABI/testing/sysfs-kernel-livepatch | 9 +++++
kernel/livepatch/core.c | 45 ++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
index d5d39748382f..26e9f58cea9e 100644
--- a/Documentation/ABI/testing/sysfs-kernel-livepatch
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -8,6 +8,15 @@ Contact: live-patching@vger.kernel.org
The /sys/kernel/livepatch directory contains subdirectories for
each loaded live patch module.
+What: /sys/kernel/livepatch/force
+Date: May 2017
+KernelVersion: 4.13.0
+Contact: live-patching@vger.kernel.org
+Description:
+ A write-only attribute that allows administrator to affect the
+ course of an existing transition. A fake signal can be send or
+ tasks TIF can be cleared.
+
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 b9628e43c78f..84f8944704ad 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -437,6 +437,7 @@ EXPORT_SYMBOL_GPL(klp_enable_patch);
* Sysfs Interface
*
* /sys/kernel/livepatch
+ * /sys/kernel/livepatch/force
* /sys/kernel/livepatch/<patch>
* /sys/kernel/livepatch/<patch>/enabled
* /sys/kernel/livepatch/<patch>/transition
@@ -444,6 +445,43 @@ EXPORT_SYMBOL_GPL(klp_enable_patch);
* /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
*/
+static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned long val;
+ int ret;
+
+ ret = kstrtoul(buf, 10, &val);
+ if (ret)
+ return ret;
+
+ /*
+ * klp_mutex lock is not grabbed here intentionally. It is not really
+ * needed. The race window is harmless and grabbing the lock would only
+ * hold the action back.
+ */
+ if (!klp_transition_patch) {
+ pr_info("no patching in progress. Force not allowed\n");
+ return -EINVAL;
+ }
+
+ switch (val) {
+ default:
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static struct kobj_attribute force_kobj_attr = __ATTR_WO(force);
+static struct attribute *klp_attrs[] = {
+ &force_kobj_attr.attr,
+ NULL
+};
+static struct attribute_group klp_sysfs_group = {
+ .attrs = klp_attrs,
+};
+
static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
@@ -954,6 +992,13 @@ static int __init klp_init(void)
if (!klp_root_kobj)
return -ENOMEM;
+ ret = sysfs_create_group(klp_root_kobj, &klp_sysfs_group);
+ if (ret) {
+ pr_err("cannot create livepatch attributes in sysfs\n");
+ kobject_put(klp_root_kobj);
+ return ret;
+ }
+
return 0;
}
--
2.12.2
next prev parent reply other threads:[~2017-05-18 12:01 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-18 12:00 [PATCH 0/3] livepatch: Introduce " Miroslav Benes
2017-05-18 12:00 ` Miroslav Benes [this message]
2017-05-18 13:05 ` [PATCH 1/3] livepatch: Add " Libor Pechacek
2017-05-18 13:20 ` Miroslav Benes
2017-05-18 12:00 ` [PATCH 2/3] livepatch: send a fake signal to all blocking tasks Miroslav Benes
2017-05-18 13:10 ` Libor Pechacek
2017-05-18 13:20 ` Miroslav Benes
2017-05-18 16:49 ` Oleg Nesterov
2017-05-18 18:14 ` Miroslav Benes
2017-05-18 19:52 ` Oleg Nesterov
2017-05-19 7:51 ` Miroslav Benes
2017-05-23 17:30 ` Josh Poimboeuf
2017-05-24 8:31 ` Miroslav Benes
2017-05-18 12:00 ` [PATCH 3/3] livepatch: force transition process to finish Miroslav Benes
2017-05-18 13:16 ` Libor Pechacek
2017-05-18 13:22 ` Miroslav Benes
2017-05-23 17:27 ` Josh Poimboeuf
2017-05-24 8:36 ` Miroslav Benes
2017-05-24 13:06 ` Petr Mladek
2017-05-24 14:15 ` Miroslav Benes
2017-05-24 15:09 ` Petr Mladek
2017-05-25 12:59 ` Miroslav Benes
2017-05-25 16:03 ` Petr Mladek
2017-05-26 17:37 ` Josh Poimboeuf
2017-05-29 12:28 ` Petr Mladek
2017-05-30 12:41 ` Josh Poimboeuf
2017-05-26 17:38 ` Josh Poimboeuf
2017-05-29 9:26 ` 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=20170518120043.7205-2-mbenes@suse.cz \
--to=mbenes@suse.cz \
--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=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®