Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3658333imm; Mon, 4 Jun 2018 07:17:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLXP1Iu8/4/UKuaR0sqyIU3CKFIpFqkr6AS0stQyGL+nakZKW/pSHku0El2cOQ/Nu7m+dUx X-Received: by 2002:a63:2c94:: with SMTP id s142-v6mr5402183pgs.39.1528121876371; Mon, 04 Jun 2018 07:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528121876; cv=none; d=google.com; s=arc-20160816; b=JwnYkFcrk7Uevaw1o+vNw2RiqejjF4gV08ZftsKUaqxy8IX/Na3XhrPw+h2vqViAZf ziizVFw6iPiAMyWvRlH+xfQh0R3aMbtcYcBpgUFezOrrlYqlLSoUT5BPtksX6/m2BDsJ M0u12hX/2nU2w1ykV+6lKjno+N9GXfyjc8H++O+IeGKpvBmaykjv82jhzdTZxWppI9Jy EEsLwzh4q81fSaGRs+1mlv+BZdrQneX+NaEGTur6P9w8mZn2BSUISylysgFg4nDvgf0c Ocgpmfs6QHVDts9AJ+LXyl0Ajc10al8qhrt2PLWHOSqRLGDfE+0E29j+0rorAkQ1fOmT B00g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=liWj4VIrpWOAHjh+KPk/4hu0600rz4nYJ5h/x/kdwmU=; b=d6vk0BMKYuPdKYOnrjsiujQzEDdVINheh8VH3gKuJagmHO0yj6xPV5Nb2OwupZ4Fwy ssX05ye0VedllzK4I74hTCxQ1dZiVQiNUpMC8my+GgDhIVDtDEMyXIHwXqBkR0x/H4py jULeTcLhklQvM0Wt+aRHs42jIlb+LRRUQWpAwE9l0pCg7afP7dyCPQ6ghM0qNMkv4S+7 qH4fR4c5HNMf0W4cGZQFmeNuLM+c5wiR4AdU5SeCiGnDPISG9Ncb/8JwV8YBb3v6M/VA YSIs7BfaPEeRzPC5pmzA0Y+CxcVeMcSWP19WHT9GRPnsy+EpMGKAQW4JV0OSSCXRlKQb axYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4-v6si46702280plp.219.2018.06.04.07.17.41; Mon, 04 Jun 2018 07:17:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753710AbeFDOQ6 (ORCPT + 99 others); Mon, 4 Jun 2018 10:16:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:43746 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753654AbeFDOQm (ORCPT ); Mon, 4 Jun 2018 10:16:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0225BAECB; Mon, 4 Jun 2018 14:16:40 +0000 (UTC) From: Miroslav Benes To: jikos@kernel.org, jpoimboe@redhat.com, jeyu@kernel.org Cc: pmladek@suse.com, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH 2/2] livepatch: Remove signal sysfs attribute Date: Mon, 4 Jun 2018 16:16:36 +0200 Message-Id: <20180604141636.11523-3-mbenes@suse.cz> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180604141636.11523-1-mbenes@suse.cz> References: <20180604141636.11523-1-mbenes@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The fake signal is send automatically now. We can rely on it completely and remove the sysfs attribute. Signed-off-by: Miroslav Benes --- .../ABI/testing/sysfs-kernel-livepatch | 12 --- Documentation/livepatch/livepatch.txt | 16 ++-- kernel/livepatch/core.c | 32 -------- kernel/livepatch/transition.c | 80 +++++++++---------- kernel/livepatch/transition.h | 1 - 5 files changed, 47 insertions(+), 94 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch index dac7e1e62a8b..85db352f68f9 100644 --- a/Documentation/ABI/testing/sysfs-kernel-livepatch +++ b/Documentation/ABI/testing/sysfs-kernel-livepatch @@ -33,18 +33,6 @@ Contact: live-patching@vger.kernel.org An attribute which indicates whether the patch is currently in transition. -What: /sys/kernel/livepatch//signal -Date: Nov 2017 -KernelVersion: 4.15.0 -Contact: live-patching@vger.kernel.org -Description: - A writable attribute that allows administrator to affect the - course of an existing transition. Writing 1 sends a fake - signal to all remaining blocking tasks. The fake signal - means that no proper signal is delivered (there is no data in - signal pending structures). Tasks are interrupted or woken up, - and forced to change their patched state. - What: /sys/kernel/livepatch//force Date: Nov 2017 KernelVersion: 4.15.0 diff --git a/Documentation/livepatch/livepatch.txt b/Documentation/livepatch/livepatch.txt index 011897e2392f..b738d70ab002 100644 --- a/Documentation/livepatch/livepatch.txt +++ b/Documentation/livepatch/livepatch.txt @@ -158,13 +158,11 @@ If a patch is in transition, this file shows 0 to indicate the task is unpatched and 1 to indicate it's patched. Otherwise, if no patch is in transition, it shows -1. Any tasks which are blocking the transition can be signaled with SIGSTOP and SIGCONT to force them to change their -patched state. This may be harmful to the system though. -/sys/kernel/livepatch//signal attribute provides a better alternative. -Writing 1 to the attribute sends a fake signal to all remaining blocking -tasks. No proper signal is actually delivered (there is no data in signal -pending structures). Tasks are interrupted or woken up, and forced to change -their patched state. Despite the sysfs attribute the fake signal is also sent -every 10 seconds automatically. +patched state. This may be harmful to the system though. Sending a fake signal +to all remaining blocking tasks is a better alternative. No proper signal is +actually delivered (there is no data in signal pending structures). Tasks are +interrupted or woken up, and forced to change their patched state. The fake +signal is automatically sent every 10 seconds. Administrator can also affect a transition through /sys/kernel/livepatch//force attribute. Writing 1 there clears @@ -419,8 +417,8 @@ Information about the registered patches can be found under /sys/kernel/livepatch. The patches could be enabled and disabled by writing there. -/sys/kernel/livepatch//signal and /sys/kernel/livepatch//force -attributes allow administrator to affect a patching operation. +/sys/kernel/livepatch//force attributes allow administrator to affect a +patching operation. See Documentation/ABI/testing/sysfs-kernel-livepatch for more details. diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 3a4656fb7047..064dee4caf4f 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -449,7 +449,6 @@ EXPORT_SYMBOL_GPL(klp_enable_patch); * /sys/kernel/livepatch/ * /sys/kernel/livepatch//enabled * /sys/kernel/livepatch//transition - * /sys/kernel/livepatch//signal * /sys/kernel/livepatch//force * /sys/kernel/livepatch// * /sys/kernel/livepatch/// @@ -525,35 +524,6 @@ static ssize_t transition_show(struct kobject *kobj, patch == klp_transition_patch); } -static ssize_t signal_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count) -{ - struct klp_patch *patch; - int ret; - bool val; - - ret = kstrtobool(buf, &val); - if (ret) - return ret; - - if (!val) - return count; - - mutex_lock(&klp_mutex); - - patch = container_of(kobj, struct klp_patch, kobj); - if (patch != klp_transition_patch) { - mutex_unlock(&klp_mutex); - return -EINVAL; - } - - klp_send_signals(); - - mutex_unlock(&klp_mutex); - - return count; -} - static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { @@ -585,12 +555,10 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, static struct kobj_attribute enabled_kobj_attr = __ATTR_RW(enabled); static struct kobj_attribute transition_kobj_attr = __ATTR_RO(transition); -static struct kobj_attribute signal_kobj_attr = __ATTR_WO(signal); static struct kobj_attribute force_kobj_attr = __ATTR_WO(force); static struct attribute *klp_patch_attrs[] = { &enabled_kobj_attr.attr, &transition_kobj_attr.attr, - &signal_kobj_attr.attr, &force_kobj_attr.attr, NULL }; diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index c33d29c74ac6..988dbc270aea 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -356,6 +356,46 @@ static bool klp_try_switch_task(struct task_struct *task) } +/* + * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set. + * Kthreads with TIF_PATCH_PENDING set are woken up. + */ +static void klp_send_signals(void) +{ + struct task_struct *g, *task; + + pr_notice("signaling remaining tasks\n"); + + read_lock(&tasklist_lock); + for_each_process_thread(g, task) { + if (!klp_patch_pending(task)) + continue; + + /* + * There is a small race here. We could see TIF_PATCH_PENDING + * set and decide to wake up a kthread or send a fake signal. + * Meanwhile the task could migrate itself and the action + * would be meaningless. It is not serious though. + */ + if (task->flags & PF_KTHREAD) { + /* + * Wake up a kthread which sleeps interruptedly and + * still has not been migrated. + */ + wake_up_state(task, TASK_INTERRUPTIBLE); + } else { + /* + * Send fake signal to all non-kthread tasks which are + * still not migrated. + */ + spin_lock_irq(&task->sighand->siglock); + signal_wake_up(task, 0); + spin_unlock_irq(&task->sighand->siglock); + } + } + read_unlock(&tasklist_lock); +} + /* * Try to switch all remaining tasks to the target patch state by walking the * stacks of sleeping tasks and looking for any to-be-patched or @@ -583,46 +623,6 @@ void klp_copy_process(struct task_struct *child) /* TIF_PATCH_PENDING gets copied in setup_thread_stack() */ } -/* - * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set. - * Kthreads with TIF_PATCH_PENDING set are woken up. - */ -void klp_send_signals(void) -{ - struct task_struct *g, *task; - - pr_notice("signaling remaining tasks\n"); - - read_lock(&tasklist_lock); - for_each_process_thread(g, task) { - if (!klp_patch_pending(task)) - continue; - - /* - * There is a small race here. We could see TIF_PATCH_PENDING - * set and decide to wake up a kthread or send a fake signal. - * Meanwhile the task could migrate itself and the action - * would be meaningless. It is not serious though. - */ - if (task->flags & PF_KTHREAD) { - /* - * Wake up a kthread which sleeps interruptedly and - * still has not been migrated. - */ - wake_up_state(task, TASK_INTERRUPTIBLE); - } else { - /* - * Send fake signal to all non-kthread tasks which are - * still not migrated. - */ - spin_lock_irq(&task->sighand->siglock); - signal_wake_up(task, 0); - spin_unlock_irq(&task->sighand->siglock); - } - } - read_unlock(&tasklist_lock); -} - /* * Drop TIF_PATCH_PENDING of all tasks on admin's request. This forces an * existing transition to finish. diff --git a/kernel/livepatch/transition.h b/kernel/livepatch/transition.h index f9d0bc016067..322db16233de 100644 --- a/kernel/livepatch/transition.h +++ b/kernel/livepatch/transition.h @@ -11,7 +11,6 @@ void klp_cancel_transition(void); void klp_start_transition(void); void klp_try_complete_transition(void); void klp_reverse_transition(void); -void klp_send_signals(void); void klp_force_transition(void); #endif /* _LIVEPATCH_TRANSITION_H */ -- 2.17.0