Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5254530imu; Tue, 15 Jan 2019 14:10:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN7xOi8Y6jOw7wHLbVOg1f8ApQyYn0+QceAL4ot3Sv+um7vxzm7jkCxZQAty/O7dw+RSFPpW X-Received: by 2002:a63:61c1:: with SMTP id v184mr4999463pgb.54.1547590208007; Tue, 15 Jan 2019 14:10:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590207; cv=none; d=google.com; s=arc-20160816; b=UVX8UU65aW1gJ8fB7ma9FyQOhU3xvEVB9vFZXRdFqQGZPSA1s3ibbYEdeIsxAL013j USEnnBiniPHX+JNpQjHEh6Ui2ndGavadu6bsKQmDxVL+fOPL94/7g9DPIiCQNAOhITZ/ Sqi2Fn6uMZ1NNDNcory9V77LZEbcnzdAqVThgMRhi0yCL92aIVVBPBzEvboYu125dGUW +XbpJmyQFVIMi0RUtC+frowsL8ZQM3IqCOF9Fs2xvF1iCMZy6Cb6BKLi6DZgBpOB8F2T 6AeApmu6v4Fv40ek+ErltxbA/ffqkB3UwF+8OALc6/wsAEh2qHzFjg9fPyZe0hgDSSHt pLbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RvZS5Cq+l1cqMAwCIxyooJumZUpws5Cicvi4JC3i7H8=; b=w5P7b/Xl+gtk+YuJXZGjNe5+ypscYBf8s//KKE85B9+4aiNAQiF2u6TT4hhXLunkWT 8krmnwPZRAgskqQK0JonhBwLubnSrWBsLrW+m3GfwDLoz4FKzcJqFmF1FrUdkpVNMDIP c6xXp6yISWIHLGBo04koNFzMI3Il6rwPFTgPxcdl5Bu7M3owAA4VBfxDUbD5d+IvkrB5 AkpsQVei3IqTJc5SR5b7dK/bKr2g873oN5GCV/0vnS9sPxsm1pPnIQVAh1chTlquU3HG uh4ry+sIOei14s5abN3V5Rrsos5X1JMA5FA1HNRDM+mSwC2AGQZmUYqcLAbzhHA0SYzP urIw== 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 g18si4273347pgg.522.2019.01.15.14.09.48; Tue, 15 Jan 2019 14:10:07 -0800 (PST) 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 S2387991AbfAOQsG (ORCPT + 99 others); Tue, 15 Jan 2019 11:48:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:47472 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387721AbfAOQpM (ORCPT ); Tue, 15 Jan 2019 11:45:12 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C15E8ACD3; Tue, 15 Jan 2019 16:45:10 +0000 (UTC) From: Miroslav Benes To: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org, pmladek@suse.com Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH v2 1/2] livepatch: Send a fake signal periodically Date: Tue, 15 Jan 2019 17:45:06 +0100 Message-Id: <20190115164507.14676-2-mbenes@suse.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115164507.14676-1-mbenes@suse.cz> References: <20190115164507.14676-1-mbenes@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An administrator may send a fake signal to all remaining blocking tasks of a running transition by writing to /sys/kernel/livepatch//signal attribute. Let's do it automatically after 15 seconds. The timeout is chosen deliberately. It gives the tasks enough time to transition themselves. Theoretically, sending it once should be more than enough. However, every task must get outside of a patched function to be successfully transitioned. It could prove not to be simple and resending could be helpful in that case. A new workqueue job could be a cleaner solution to achieve it, but it could also introduce deadlocks and cause more headaches with synchronization and cancelling. Signed-off-by: Miroslav Benes --- Documentation/livepatch/livepatch.txt | 3 ++- kernel/livepatch/transition.c | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Documentation/livepatch/livepatch.txt b/Documentation/livepatch/livepatch.txt index 71d7f286ec4d..407e0f03dc99 100644 --- a/Documentation/livepatch/livepatch.txt +++ b/Documentation/livepatch/livepatch.txt @@ -163,7 +163,8 @@ patched state. This may be harmful to the system though. 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. +their patched state. Despite the sysfs attribute the fake signal is also sent +every 15 seconds automatically. Administrator can also affect a transition through /sys/kernel/livepatch//force attribute. Writing 1 there clears diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index 300273819674..12a1a65531a0 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -29,10 +29,14 @@ #define MAX_STACK_ENTRIES 100 #define STACK_ERR_BUF_SIZE 128 +#define SIGNALS_TIMEOUT 15 + struct klp_patch *klp_transition_patch; static int klp_target_state = KLP_UNDEFINED; +static unsigned int klp_signals_cnt; + /* * This work can be performed periodically to finish patching or unpatching any * "straggler" tasks which failed to transition in the first attempt. @@ -393,6 +397,10 @@ void klp_try_complete_transition(void) put_online_cpus(); if (!complete) { + if (klp_signals_cnt && !(klp_signals_cnt % SIGNALS_TIMEOUT)) + klp_send_signals(); + klp_signals_cnt++; + /* * Some tasks weren't able to be switched over. Try again * later and/or wait for other methods like kernel exit @@ -400,6 +408,7 @@ void klp_try_complete_transition(void) */ schedule_delayed_work(&klp_transition_work, round_jiffies_relative(HZ)); + return; } @@ -454,6 +463,8 @@ void klp_start_transition(void) if (task->patch_state != klp_target_state) set_tsk_thread_flag(task, TIF_PATCH_PENDING); } + + klp_signals_cnt = 0; } /* @@ -578,14 +589,14 @@ void klp_copy_process(struct task_struct *child) /* * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set. - * Kthreads with TIF_PATCH_PENDING set are woken up. Only admin can request this - * action currently. + * 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"); + if (klp_signals_cnt == SIGNALS_TIMEOUT) + pr_notice("signaling remaining tasks\n"); read_lock(&tasklist_lock); for_each_process_thread(g, task) { -- 2.20.1