Received: by 10.223.185.116 with SMTP id b49csp4777148wrg; Wed, 7 Mar 2018 00:22:45 -0800 (PST) X-Google-Smtp-Source: AG47ELuss7OrB7OaNjIud+FruD1y7NYN+l45pj5V7iGT/BAwlTg0L7OxeCp+7pu5npU3rjZpOAmy X-Received: by 2002:a17:902:47c2:: with SMTP id d2-v6mr19326193plh.253.1520410965115; Wed, 07 Mar 2018 00:22:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520410965; cv=none; d=google.com; s=arc-20160816; b=WoDWMvboLyV3BqX75SZB3ZvHESb89CW3TyPenE7/ky5WcVegJOwbkrQllFcwjWIJZA YsEkiPBSzrcmVwzkksxbUQ4+cUAbBQQuOp7hYhXMbaOKP2UsWfTBtYHSTF61sVqWqJ0A 89kTzdOAceqStm4XWMA+LKDCsz9saqJXZYbA6CmhQ/FsGa9RXfRCi1i9v29laKXQF55g vzUqa7ayWrAw0iKGUVM5w8ki0q4NVL6pVgswdIlEzq5Q7/NT2h2J3Cif3BUz5tD3YV34 GjSM2wBohxkpExMMEH8+QEnrDy85yze9LE0Iyxy9U2ur8NbO2tKsXG/+KPB5rf0gStvg 5MHw== 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=hiBZkoyYio3DhcNUkInr6nAK95MU+TpbJ9KfDB0Wyw0=; b=SMgcbAzzJI6/j+MmUfjNgg/RFfgrgOOEV2j/9bCKyjre9H0ey/JwZ+kWgxejUe2eKZ /oyVESfgKbkskRmx4SGh/0wUSSywsukDJn8ec84RAR75R1NKwYCp6uEo/QaC1+MgbU7C eo+B5+JZ4blha8qSUpW2osKw/nqz6YiDNTOQ9tikMzKK535aDOW+2/Rqsqp6b7bBvDjP sMxEQljW4sOhPiDPxcj1NkAOX5HzkJX7f4o3hHS8JetavvB+KGPXXTSqvUO3fgHrm/YI hNl6OTqbwD5+eq0Q4N9zvbdx2ODzCKmx7nDQlPbYIwZuIFlqYsAZU8SjPTmv9kp1Pr3O spIg== 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 j14si283107pfn.150.2018.03.07.00.22.30; Wed, 07 Mar 2018 00:22:45 -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 S933396AbeCGIVO (ORCPT + 99 others); Wed, 7 Mar 2018 03:21:14 -0500 Received: from mx2.suse.de ([195.135.220.15]:50185 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933324AbeCGIVI (ORCPT ); Wed, 7 Mar 2018 03:21:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 00289AF98; Wed, 7 Mar 2018 08:21:06 +0000 (UTC) From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Joe Lawrence , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v10 09/10] livepatch: Allow to replace even disabled patches Date: Wed, 7 Mar 2018 09:20:38 +0100 Message-Id: <20180307082039.10196-10-pmladek@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180307082039.10196-1-pmladek@suse.com> References: <20180307082039.10196-1-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Patches without the replace flag might depend on each other. It makes sense to enforce the order in which they are enabled and disabled. The situation is different when the patch replaces all existing ones. It should make the life easier for both: patch producers and users. Such a patch should be ready to replace basically any older patch. It should work well even in situations when the previous patches were not installed or when they were disabled from some reasons. The code is almost ready for this: + klp_add_nops() takes into account even disabled patches. In the worst case, we might enable some NOPs that are not really needed. + klp_throw_away_replaced_patches() removes all patches down the stack. We only need to make sure that the livepatch module is put only when it was gotten (enabled) before. Also we need to stop enforcing the stack order for the patches with the replace flag. Instead, we need to make sure that they are still usable (not replaced). Signed-off-by: Petr Mladek --- kernel/livepatch/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 73ce3f93e0bc..b098dc10d4d5 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -376,17 +376,19 @@ void klp_throw_away_replaced_patches(struct klp_patch *new_patch, if (old_patch == new_patch) return; - klp_unpatch_objects(old_patch, KLP_FUNC_ANY); - old_patch->enabled = false; + if (old_patch->enabled) { + klp_unpatch_objects(old_patch, KLP_FUNC_ANY); + old_patch->enabled = false; + + if (!keep_module) + module_put(old_patch->mod); + } /* * Replaced patches could not get re-enabled to keep * the code sane. */ list_move(&old_patch->list, &klp_replaced_patches); - - if (!keep_module) - module_put(old_patch->mod); } } @@ -470,8 +472,16 @@ static int __klp_enable_patch(struct klp_patch *patch) if (WARN_ON(patch->enabled)) return -EINVAL; - /* enforce stacking: only the first disabled patch can be enabled */ - if (patch->list.prev != &klp_patches && + if (!klp_is_patch_usable(patch)) + return -EINVAL; + + /* + * Enforce stacking: only the first disabled patch can be enabled. + * This is not required for patches with the replace flags. They + * override even disabled patches that were registered earlier. + */ + if (!patch->replace && + patch->list.prev != &klp_patches && !list_prev_entry(patch, list)->enabled) return -EBUSY; -- 2.13.6