Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3658153imm; Mon, 4 Jun 2018 07:17:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLI5vpM81DnfI0KxmXjTWkj65hpoC3WnmNc6zDuxKYLOtW+9mtu23lN0ac1TWAzomdXBB2G X-Received: by 2002:a62:18a:: with SMTP id 132-v6mr21523584pfb.62.1528121865171; Mon, 04 Jun 2018 07:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528121865; cv=none; d=google.com; s=arc-20160816; b=xvgwCs5psgcRUa6PpGxb+xK35+3eUYLP/kmPhxxFcDQpwzKJGbecsp8gmefaIGXb5n r0PDOsvDJXiEfliSHndEAlL87/ABsNTj+B4ZP5nYRTodw3dMQEPElUGXs3++NHhtDs4G xr0CelLu+SgkqB0Dh3pK5iQ0Li9eYtnCJeaOvL/OlioqM1nTSbGf8mP0OVqyEkArbqFU O144hykvRhVUFaivcxUaLz5opCp6vzsHKveCUAeaR+JmXrWON6z/Lsqy/fbfridKvnFD cyv/9VmjDlKHmahcigYHaUAp6n9adblNFTheLtkyEv5SK1Ey69/KHO5nMaiXgGTtI1g+ biKA== 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=L3TWlcVDwdLrQfRWNrSPfpKoKlfSzNXjLlC8Zb1G9Zk=; b=q5UY2mwwsnvM8PHD7/xGVXHx6+SexWkxUGRDxZN9/VpcDzz9cfz6r4Qtk8Sopz9RFP lTh7wbyUCpnYUG0jut9qTH1R7+jldyKnAk8LuOEH/glZV1qui/SyQmVO/wvYGUY/B7pi GTFB1yArPFGFS2ox76XFUgo2Df2jW8LgZruSiYaCnb7rRo0CBqvrNpvalDvEl7ioVA/W abA9JpE9D98bkJxUu4FU95vMtngOGXJurpWggIBdv+4RKsI0ZmCfT1u0ObjhbAXNuhSs ahXSuavs6akiEtwCdDPlzbYE+3P+Y/G/0G/L0PBjbLXyl5tTpapgCs/j0p0EesVX+Qhq y9Fg== 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 g10-v6si2328485pgr.72.2018.06.04.07.17.30; Mon, 04 Jun 2018 07:17:45 -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 S1753839AbeFDOQ7 (ORCPT + 99 others); Mon, 4 Jun 2018 10:16:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:43740 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753641AbeFDOQl (ORCPT ); Mon, 4 Jun 2018 10:16:41 -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 9E820AED5; Mon, 4 Jun 2018 14:16:39 +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 1/2] livepatch: Send a fake signal periodically Date: Mon, 4 Jun 2018 16:16:35 +0200 Message-Id: <20180604141636.11523-2-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 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 10 seconds. The timeout is chosen deliberately. It gives the tasks enough time to transition themselves. Theoretically, sending it once should be more than enough. Better be safe than sorry, so send it periodically. 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 | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/livepatch/livepatch.txt b/Documentation/livepatch/livepatch.txt index 1ae2de758c08..011897e2392f 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 10 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 7c6631e693bc..c33d29c74ac6 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -29,6 +29,8 @@ #define MAX_STACK_ENTRIES 100 #define STACK_ERR_BUF_SIZE 128 +#define SIGNALS_TIMEOUT 10 + struct klp_patch *klp_transition_patch; static int klp_target_state = KLP_UNDEFINED; @@ -367,6 +369,7 @@ void klp_try_complete_transition(void) unsigned int cpu; struct task_struct *g, *task; bool complete = true; + static unsigned int signals_cnt = 0; WARN_ON_ONCE(klp_target_state == KLP_UNDEFINED); @@ -403,6 +406,9 @@ void klp_try_complete_transition(void) put_online_cpus(); if (!complete) { + if (!(++signals_cnt % SIGNALS_TIMEOUT)) + klp_send_signals(); + /* * Some tasks weren't able to be switched over. Try again * later and/or wait for other methods like kernel exit @@ -410,10 +416,12 @@ void klp_try_complete_transition(void) */ schedule_delayed_work(&klp_transition_work, round_jiffies_relative(HZ)); + return; } /* we're done, now cleanup the data structures */ + signals_cnt = 0; klp_complete_transition(); } @@ -577,8 +585,7 @@ 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) { -- 2.17.0