Received: by 10.213.65.68 with SMTP id h4csp298738imn; Fri, 23 Mar 2018 05:02:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELsJKZUvc3ctFwbYsZ1KVaeuEDSNXN45cO4wVmNtruz3tINVNe2fyJTZqx0ClJX6uIPuO84u X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr28513418pld.231.1521806572340; Fri, 23 Mar 2018 05:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521806572; cv=none; d=google.com; s=arc-20160816; b=oehgZo30hPyQEtc1LCiSb8hoxKdubkrxgN2BAXv9kBYD8cvibUpIZbWeggOuvfQCNS PuF7aJQOV6wjwD6LLe9P1f3EOR5mg6PKiBlHoesz+VLd9WVS9lgyy5xqgLDG5ImQ0BFZ O0hmB1Sd2SA7u+bIhGkXaWgtdJREdh3ibuBJ274WknLWlkl/kNMN6nOGdYGSlmflrfpL VujS1AKXQBCLJzuNod25EaTubrMrEx4XOwN7rwloZBIodd6xcPlCyP1Kt0/QL0FFlt4f GshQJfNdQiTZmQiy8fG+rofx6xtuLVO30CL3CgT5rg+GNPEtWFN0nDlo1ma7RsQDUh+E pwPA== 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=rnp2KwSbdkQfFbonGeMjlXL0l4aXFw1Ub9/xppmM0xs=; b=pRJPiLNnFltTT9+4aoRdSmB+Cc/32R3owNbujU+PChAdqZZCxC3/B5gT4triD3+R6h 9JkSiYx7fyAypJ+6JccS7MNh2BIZT57b0s7fpeXxXROWrRUanuSiWfWKLNxxXYjkodIn 6alX7A4C+u7bShxS3Xa1n3C/yBao2yb4U1dfcmOy9r0fbIKrzFoYUR0XVtpXdYXczgzV M5THWgHjnXyc0wlFLv7SGhVuUq7ESAKZ9gIESW6w/b6XxosxRF0OuuN/1rHIIkUWSNHr MzDT63OSHaBhck8bdWprkV4Z9JFMz3z08v8n/4DTjtFWPBVPNt5Wbt0ENp26JXSq/eLY FXQA== 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 l62si1560539pga.144.2018.03.23.05.02.37; Fri, 23 Mar 2018 05:02:52 -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 S1753703AbeCWMBa (ORCPT + 99 others); Fri, 23 Mar 2018 08:01:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:39649 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753565AbeCWMBD (ORCPT ); Fri, 23 Mar 2018 08:01:03 -0400 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 26872AEB6; Fri, 23 Mar 2018 12:01:02 +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 7/8] livepatch: Allow to replace even disabled patches Date: Fri, 23 Mar 2018 13:00:27 +0100 Message-Id: <20180323120028.31451-8-pmladek@suse.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180323120028.31451-1-pmladek@suse.com> References: <20180323120028.31451-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. These patches 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. There are needed two changes: + Disable only enabled patches in klp_discard_replaced_patches(). + 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). This check is already there. Signed-off-by: Petr Mladek --- kernel/livepatch/core.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 0b3be6e14b80..c64371ffc063 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -355,11 +355,13 @@ void klp_discard_replaced_patches(struct klp_patch *new_patch, bool keep_module) if (old_patch == new_patch) return; - klp_unpatch_objects(old_patch); - old_patch->enabled = false; + if (old_patch->enabled) { + klp_unpatch_objects(old_patch); + old_patch->enabled = false; - if (!keep_module) - module_put(old_patch->mod); + if (!keep_module) + module_put(old_patch->mod); + } /* * Replaced patches could not get re-enabled to keep @@ -453,8 +455,13 @@ static int __klp_enable_patch(struct klp_patch *patch) if (!klp_is_patch_on_stack(patch)) return -EINVAL; - /* Only the first disabled patch can be enabled. */ - if (patch->list.prev != &klp_patches && + /* + * 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