Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2195266ybi; Thu, 18 Jul 2019 04:53:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJdrix/OA2fHsmk3k1AY3NLGelf9i822LlB3N+4SlvkhWLhUm2Ab8b5AdgqO7GZl2SKfpK X-Received: by 2002:a63:b555:: with SMTP id u21mr48097759pgo.222.1563450795624; Thu, 18 Jul 2019 04:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563450795; cv=none; d=google.com; s=arc-20160816; b=fzIrFs9egm8+X9Ue8vEyzTf3d9Bkgr7Y4PFu54mXfE4E6dNTfhB9xnescfURWvG1UC hy63zYrUoXOeoWDpkNzHgqmywT3ksdNpO5fHKPtmKx62NkP7VEyUgDDjlqcpk/LxG1tn fCr9tvdIybj1r+7aiZxociBQQkuk/B+6/p5KX6/raV7iY45GFlorcmXvaZdrS4zC8MCT li8wWswCXd2aulzRVrX3youQYDOWNflCgWPWSscB9qZsWEC3eCWN5mEv82XXyO2uSsSR pJ7jxSRVlQ+krU77VItzMIW4gVWt1kO9MnaLw57DbZ9Q63YXhz/SaqlvGe8VrTXQcvI6 UTPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fQZvapMySsB2Wpu1Jhx559EttXD5pSWbeQszmFPYTuk=; b=ruxrZVmmH9KoJfNbMOJuF4g2cshVGfOuySuhni+RD6TWC2xdufHCDQdfFu64F476eq MBc1rWUdJlxuGHsocBqYz+ZM7tbxwVIClGH9BLJEeE9xhCoT479t7zDLE5jgVOLHmd9k yNXzqy1KVZ04czHL9oGJ+jqpnfq2MZzZf5nRzROOZ5rcNKuOy2rW/pxxrGykJ9fA+tEc 3b+SfaVbuukuEYGNf0BqkhGybZkvZoMLtnH6mwZ7Jh+2sFGAorV4vMApF1VzZoOWrBPD UaYIBWeZN2bVsMzZdj0/lxMrSMZ4WIK54cb8iYxQ+qdEQTZTO7Z3xYeDHQvpDoLJn1jW 89Xg== 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 l6si2437846pjt.70.2019.07.18.04.52.58; Thu, 18 Jul 2019 04:53:15 -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 S2390130AbfGRLiD (ORCPT + 99 others); Thu, 18 Jul 2019 07:38:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:56014 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726495AbfGRLiD (ORCPT ); Thu, 18 Jul 2019 07:38:03 -0400 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 69640AC1C; Thu, 18 Jul 2019 11:38:01 +0000 (UTC) Date: Thu, 18 Jul 2019 13:38:01 +0200 From: Petr Mladek To: Nicolai Stange Cc: Jiri Kosina , Josh Poimboeuf , Miroslav Benes , Joe Lawrence , Kamalesh Babulal , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC 3/5] livepatch: Allow to distinguish different version of system state changes Message-ID: <20190718113801.bol75rgt26d72goy@pathway.suse.cz> References: <20190611135627.15556-1-pmladek@suse.com> <20190611135627.15556-4-pmladek@suse.com> <87o92n2sao.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o92n2sao.fsf@suse.de> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, first, I am sorry that I answer this non-trivial mail so late. I know that it might be hard to remember the context. On Mon 2019-06-24 12:26:07, Nicolai Stange wrote: > Petr Mladek writes: > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > > index 24c4a13bd26c..614642719825 100644 > > --- a/kernel/livepatch/core.c > > +++ b/kernel/livepatch/core.c > > @@ -1003,6 +1004,13 @@ int klp_enable_patch(struct klp_patch *patch) > > > > mutex_lock(&klp_mutex); > > > > + if(!klp_is_patch_compatible(patch)) { > > + pr_err("Livepatch patch (%s) is not compatible with the already installed livepatches.\n", > > + patch->mod->name); > > + mutex_unlock(&klp_mutex); > > + return -EINVAL; > > + } > > + > > ret = klp_init_patch_early(patch); > > if (ret) { > > mutex_unlock(&klp_mutex); > > > Just as a remark: klp_reverse_transition() could still transition back > to a !klp_is_patch_compatible() patch. I am slightly confused. The new livepatch is enabled only when the new states have the same or higher version. And only callbacks from the new livepatch are used, including post_unpatch() when the transition gets reverted. The "compatible" livepatch should be able to handle all situations: + Modify the system state when it was not modified before. + Take over the system state when it has already been modified by the previous livepatch. + Restore the previous state when the transition is reverted. > I don't think it's much of a problem, because for live patches > introducing completely new states to the system, it is reasonable > to assume that they'll start applying incompatible changes only from > their ->post_patch(), I guess. > > For state "upgrades" to higher versions, it's not so clear though and > some care will be needed. But I think these could still be handled > safely at the cost of some complexity in the new live patch's > ->post_patch(). Just to be sure. The post_unpatch() from the new livepatch will get called when the transitions is reverted. It should be able to revert any changes made by its own pre_patch(). You are right that it will need some care. Especially because the transition revert is not easy to test. I think that this is the main reason why Joe would like to introduce the sticky flag. It might be used to block the transition revert and livepatch disabling when it would be to complicated, error-prone, or even impossible. > Another detail is that ->post_unpatch() will be called for the new live > patch which has been unpatched due to transition reversal and one would > have to be careful not to free shared state from under the older, still > active live patch. How would ->post_unpatch() distinguish between > transition reversal and "normal" live patch disabling? By > klp_get_prev_state() != NULL? Exactly. klp_get_prev_state() != NULL can be used in the post_unpatch() to restore the original state when the transition gets reverted. See restore_console_loglevel() in lib/livepatch/test_klp_state2.c > Perhaps transition reversal should be mentioned in the documentation? Good point. I'll mention it in the documentation. Best Regards, Petr