Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6735579imu; Mon, 21 Jan 2019 14:52:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN5drmNeE+hLb8i5Z+w/nJqjGZCJYk2pkQ6X7QH+eAcdwSWGT2MxVSQXwnLwwu+Wehp/Y3PJ X-Received: by 2002:a17:902:6a8c:: with SMTP id n12mr32069133plk.85.1548111179644; Mon, 21 Jan 2019 14:52:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548111179; cv=none; d=google.com; s=arc-20160816; b=sJSBDyNY+v41O6rgKsM8Tc2OlHi92p6XRpqQoe4XAjF+1anoPoV/0Z6zz0oiUwwEXE j4Xs3DF7VfRYD4aZSaGpELgq8V9q/IkPqQKoOJtShQ9d+wgQNpzMefJlLZnGuBdpf8u4 b61q1GxRhfqwjKr0O2k6LreQpldUhb6wDL+mUQgHFujQ1V5qCBiUR+kfpaKCH2Ch3Wmg FuW2kFBWQfBsyUxqFIzkXue4XKP24Z6nlfz/Vlz8iYNvL5NEA1zYZdCiy+wFIBGWYmc0 4AkN6KrHJiIjWrMQdPmjV1Q7CY/79hg8KxylFIVciMBbW/Au7s1rrK9l/ZJYpY7vBort ZR4Q== 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=O0y4SM7nSkJX6v7ympNyuozUOYs6WIGzzNf4vR4H+eg=; b=dbjZNxJjBN50++mJuDSk7hFmMjELQpHkiA7pv/uRH5YCYtmlgnBeOiGgPTsbjjMW1N 3Nxj4XyVEV3F7zjfKWP+GZ4nzisSYM+Yxy/TcTXeiFNqC8h6+4qxdId31PEY5Qh86Fw0 SBHyELdes+xHHG9UG0iCWupnUY7ZdrE845NstUs6RdtOTdNYJ7dHiHddG75uTSmeET/n V6N3jb8+A3Mxs4JxP5KKxa9nUXIr6Bn1tCOtkwl8aAURM4Hj1Te9WnrSFlFJT+/YClCg 6PqaZEM/0BN7DpCxkYl8wHVU7GD/HavrwJAPvu+SsOPIWvjBVtUsCcpCktEM2ZgsQuFO r0sA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si14393827pla.436.2019.01.21.14.52.43; Mon, 21 Jan 2019 14:52:59 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727885AbfAUWuy (ORCPT + 99 others); Mon, 21 Jan 2019 17:50:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36248 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727153AbfAUWuy (ORCPT ); Mon, 21 Jan 2019 17:50:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 865CA19D383; Mon, 21 Jan 2019 22:50:53 +0000 (UTC) Received: from redhat.com (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 988CE614C4; Mon, 21 Jan 2019 22:50:52 +0000 (UTC) Date: Mon, 21 Jan 2019 17:50:50 -0500 From: Joe Lawrence To: Petr Mladek Cc: Jiri Kosina , Josh Poimboeuf , Miroslav Benes , Jason Baron , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] livepatch: Remove the redundant enabled flag in struct klp_patch Message-ID: <20190121225050.GD8766@redhat.com> References: <20190116161720.796-1-pmladek@suse.com> <20190116161720.796-5-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190116161720.796-5-pmladek@suse.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Jan 2019 22:50:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 05:17:20PM +0100, Petr Mladek wrote: > Livepatches can not longer get enabled and disabled repeatedly. nit: s/not longer/no longer/g > The list klp_patches contains only enabled patches and eventually > the patch in transition. As a result, the enabled flag in > struct klp_patch provides redundant information and can get > removed. > > The flag is replaced by helper function klp_patch_enabled(). > It simplifies the code. Also it helps to understand the semantic, > especially for the patch in transition. > > Alternative solution was to remove klp_target_state. But this > would be unfortunate. The three state variable helps to > catch bugs and regressions. Also it makes it easier to get > the state a lockless way in klp_update_patch_state(). smaller nit: s/get the state/get the state in/ > > Suggested-by: Josh Poimboeuf > Signed-off-by: Petr Mladek > --- > include/linux/livepatch.h | 2 -- > kernel/livepatch/core.c | 23 +++++++++++++++-------- > kernel/livepatch/transition.c | 7 +++---- > kernel/livepatch/transition.h | 1 + > 4 files changed, 19 insertions(+), 14 deletions(-) > > diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h > index 53551f470722..fa68192e6bb2 100644 > --- a/include/linux/livepatch.h > +++ b/include/linux/livepatch.h > @@ -155,7 +155,6 @@ struct klp_object { > * @kobj: kobject for sysfs resources > * @obj_list: dynamic list of the object entries > * @kobj_added: @kobj has been added and needs freeing > - * @enabled: the patch is enabled (but operation may be incomplete) > * @forced: was involved in a forced transition > * @free_work: patch cleanup from workqueue-context > * @finish: for waiting till it is safe to remove the patch module > @@ -171,7 +170,6 @@ struct klp_patch { > struct kobject kobj; > struct list_head obj_list; > bool kobj_added; > - bool enabled; > bool forced; > struct work_struct free_work; > struct completion finish; > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > index 684766d306ad..8e644837e668 100644 > --- a/kernel/livepatch/core.c > +++ b/kernel/livepatch/core.c > @@ -59,6 +59,17 @@ static bool klp_is_module(struct klp_object *obj) > return obj->name; > } > > +static bool klp_patch_enabled(struct klp_patch *patch) > +{ > + if (patch == klp_transition_patch) { > + WARN_ON_ONCE(klp_target_state == KLP_UNDEFINED); > + > + return klp_target_state == KLP_PATCHED; > + } > + > + return !list_empty(&patch->list); > +} > + > /* sets obj->mod if object is not vmlinux and module is found */ > static void klp_find_object_module(struct klp_object *obj) > { > @@ -335,7 +346,7 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, > > mutex_lock(&klp_mutex); > > - if (patch->enabled == enabled) { > + if (klp_patch_enabled(patch) == enabled) { > /* already in requested state */ > ret = -EINVAL; > goto out; > @@ -369,7 +380,7 @@ static ssize_t enabled_show(struct kobject *kobj, > struct klp_patch *patch; > > patch = container_of(kobj, struct klp_patch, kobj); > - return snprintf(buf, PAGE_SIZE-1, "%d\n", patch->enabled); > + return snprintf(buf, PAGE_SIZE-1, "%d\n", klp_patch_enabled(patch)); > } > > static ssize_t transition_show(struct kobject *kobj, > @@ -862,7 +873,6 @@ static int klp_init_patch_early(struct klp_patch *patch) > INIT_LIST_HEAD(&patch->list); > INIT_LIST_HEAD(&patch->obj_list); > patch->kobj_added = false; > - patch->enabled = false; > patch->forced = false; > INIT_WORK(&patch->free_work, klp_free_patch_work_fn); > init_completion(&patch->finish); > @@ -919,7 +929,7 @@ static int __klp_disable_patch(struct klp_patch *patch) > { > struct klp_object *obj; > > - if (WARN_ON(!patch->enabled)) > + if (WARN_ON(!klp_patch_enabled(patch))) > return -EINVAL; > > if (klp_transition_patch) > @@ -941,7 +951,6 @@ static int __klp_disable_patch(struct klp_patch *patch) > smp_wmb(); > > klp_start_transition(); > - patch->enabled = false; > klp_try_complete_transition(); > > return 0; > @@ -955,7 +964,7 @@ static int __klp_enable_patch(struct klp_patch *patch) > if (klp_transition_patch) > return -EBUSY; > > - if (WARN_ON(patch->enabled)) > + if (list_empty(&patch->list)) > return -EINVAL; > > if (!patch->kobj_added) > @@ -994,7 +1003,6 @@ static int __klp_enable_patch(struct klp_patch *patch) > } > > klp_start_transition(); > - patch->enabled = true; > klp_try_complete_transition(); > > return 0; > @@ -1093,7 +1101,6 @@ void klp_discard_replaced_patches(struct klp_patch *new_patch) > if (old_patch == new_patch) > return; > > - old_patch->enabled = false; > klp_unpatch_objects(old_patch); > klp_free_patch_start(old_patch); > schedule_work(&old_patch->free_work); > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > index a3a6f32c6fd0..a40b58660640 100644 > --- a/kernel/livepatch/transition.c > +++ b/kernel/livepatch/transition.c > @@ -31,7 +31,7 @@ > > struct klp_patch *klp_transition_patch; > > -static int klp_target_state = KLP_UNDEFINED; > +int klp_target_state = KLP_UNDEFINED; > > /* > * This work can be performed periodically to finish patching or unpatching any > @@ -354,6 +354,7 @@ static bool klp_try_switch_task(struct task_struct *task) > void klp_try_complete_transition(void) > { > unsigned int cpu; > + int target_state = klp_target_state; > struct task_struct *g, *task; > struct klp_patch *patch; > bool complete = true; > @@ -412,7 +413,7 @@ void klp_try_complete_transition(void) > * klp_complete_transition() but it is called also > * from klp_cancel_transition(). > */ > - if (!patch->enabled) { > + if (target_state == KLP_UNPATCHED) { > klp_free_patch_start(patch); > schedule_work(&patch->free_work); > } > @@ -545,8 +546,6 @@ void klp_reverse_transition(void) > klp_target_state == KLP_PATCHED ? "patching to unpatching" : > "unpatching to patching"); > > - klp_transition_patch->enabled = !klp_transition_patch->enabled; > - > klp_target_state = !klp_target_state; > > /* > diff --git a/kernel/livepatch/transition.h b/kernel/livepatch/transition.h > index f9d0bc016067..b9f3e96d8c13 100644 > --- a/kernel/livepatch/transition.h > +++ b/kernel/livepatch/transition.h > @@ -5,6 +5,7 @@ > #include > > extern struct klp_patch *klp_transition_patch; > +extern int klp_target_state; > > void klp_init_transition(struct klp_patch *patch, int state); > void klp_cancel_transition(void); > -- > 2.13.7 > With commit msg nits, Acked-by: Joe Lawrence -- Joe