Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7209557imu; Tue, 22 Jan 2019 02:09:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN75uCLVtrzDlR8u+8ghDsKHW9iqJmwxg/i79fbLlRppJYFpPC2HNhqEcriWlVgBsMVDZv8+ X-Received: by 2002:a65:6215:: with SMTP id d21mr251296pgv.289.1548151779092; Tue, 22 Jan 2019 02:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548151779; cv=none; d=google.com; s=arc-20160816; b=iDYTHlz7ynCuSh2CtLXFdKbAkICELjU9ExiGtvtbPr8sfnDiCopZH7bRwMNeze5AMe jS8xgZEzb3Tejk8rCYTj0vrOfQVvzA00j/99vZnABOTY5PlwKvEmgESzP+ysDic7eM+G c6hxociUutmCe4jB7TCfMoEVZeD4c9gXadP0WjFUzvREFkVne9h0tPJgQaIm/BjQg/X9 9ilnErbZ3qNLS1alS4Y4RxteXDQTOmIszgP9HjeLBaRIvriKD6E0SzzrAa3wnASsgEqU 24F0C4ryhIaOYmylXRl+mjfSMZgWM4N1rS3ytcbis+lGITbOmPmbZPQV8crIVeGnG0uv Z6mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=oMxYdQRBdxC83Dkpu5UvzTS1ch3MncA9xcNl5D+y3q0=; b=LuPxXGeZEbLCIk8Q3UXQ0BKog30Zq2ow4XZaIYaBczQZilmphfG+HcGcCyK/3JvTYY mHo2vyLJubgy44B63fHd+3NGxFxDt1c+Hs1ZfrxEObHOz4XCkf0hu4Yie4qH21bQDweC MhzOXZTExrjPnZ8yG32bXqSN47s9CxU1e+36ToV11p3m/QjiTrwyEgjZt8AtoXQaAQjx uJTYVSbt5EjeuJOp+J0KFcppt0vV7neIP7JQcI5qY9XQGeoGqIBI2aa2omKlJEBrrgO0 Nq0myVkfMwcfxybcbQorheQaYh/3a294HgjY7BNhHrwoThoZqDp80cSSoBejFiiMuOP1 mkBQ== 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 35si419394plf.177.2019.01.22.02.09.22; Tue, 22 Jan 2019 02:09:39 -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 S1727909AbfAVKHA (ORCPT + 99 others); Tue, 22 Jan 2019 05:07:00 -0500 Received: from mx2.suse.de ([195.135.220.15]:39064 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727417AbfAVKG7 (ORCPT ); Tue, 22 Jan 2019 05:06:59 -0500 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 7F008AD23; Tue, 22 Jan 2019 10:06:58 +0000 (UTC) Date: Tue, 22 Jan 2019 11:06:56 +0100 (CET) From: Miroslav Benes To: Petr Mladek cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Joe Lawrence , 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 In-Reply-To: <20190116161720.796-5-pmladek@suse.com> Message-ID: References: <20190116161720.796-1-pmladek@suse.com> <20190116161720.796-5-pmladek@suse.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jan 2019, Petr Mladek wrote: > 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); I think we'd have a race in the code then. enabled_show() does not take klp_mutex() when calling klp_patch_enabled(). A patch sysfs attributes are added quite early during its enablement. klp_init_transition() first sets klp_transition_patch, then klp_target_state. It means one can call enabled_show() with patch == klp_transition_patch and klp_target_state == KLP_UNDEFINED. No? The similar applies the disablement. klp_complete_transition() first clears klp_target_state (sets it to KLP_UNDEFINED), then it clears klp_transition_patch. We could add locking to enabled_show() or swap the assignments with some barriers on top. Or we could remove WARN_ON_ONCE() and live with false results in enabled_show(). It does not matter much, I think. All the other call sites of klp_patch_enabled() should be fine. > + return klp_target_state == KLP_PATCHED; > + } > + > + return !list_empty(&patch->list); > +} Shouldn't we also change list_del(&patch->list) in klp_free_patch_start() to list_del_init(&patch->list)? [...] > @@ -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; I wanted to ask why there is list_empty() and not klp_patch_enabled(), so just to be sure... the patch was added to klp_patches list, so patch->list is not empty (should not be). We could achieve the same by calling !klp_patch_enabled() given its implementation, but it would look counter-intuitive here. The rest looks fine. However, I am not sure if the outcome is better than what we have. Yes, patch->enabled is not technically necessary and we can live with that (as the patch proves). On the other hand, it gives the reader clear guidance about the patch's state. klp_patch_enabled() is not a complete replacement. We have to call list_empty() in __klp_enable_patch() or check the original klp_target_state in klp_try_complete_transition(). I am not against the change, I am glad to see it is achievable, but I am not sure if the code is better with it. Joe acked it. What do the others think? Thanks, Miroslav