Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9834252imu; Wed, 5 Dec 2018 11:03:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/XQKc9ayCNgS9oDLZYEUHF0a5d5P5Zs+T4BsaO/KoBa4LEkwEGgBriLAPbRSML0GUPopFCK X-Received: by 2002:a17:902:f01:: with SMTP id 1mr24542035ply.143.1544036605357; Wed, 05 Dec 2018 11:03:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544036605; cv=none; d=google.com; s=arc-20160816; b=HGMi1ilM1BCbH3fLG00JlP2Hq/YdZ+KiKxtA6i1JjJnqrxEKoAh+Ju5AmN69P9hS1o uY1sIJioYh410YUJz5ZcWVtweCmWnwcG+KYs7rqwm1FBjC7+Oj+RROMVvnplQTW/De1Z ddDGx8KGdt3wPzmlYC1QEWjaWjB2m/bSWM4mXTYzXth3wYsamnWYss2un81pJ5bMIdri qrjH+NYWnfspp880zRQgGnQdGlcpMfmSXtKYgBJaqI8Zjg0tSWEviZ/dqCrlm0lDhjj7 67pQ0u5q48STdeAhM0yrupivcYZemKWl60OgYTmhWho9KZV/u+XgQzQxI+Tis99m63MK X8lA== 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=mPBfu31SL7Q+lgdQYGi//YGicCkkDnMl56KJPo/9/tk=; b=fHg9Oz7KGnLrFyxwu6zUAY73YZ3WDpGb34BL4xIMaeibRb/umOFwVl7ON8nN5Tb0iX YVJswS1op4NaIiUG2UKG4Lp+IgLCnybOv3lfcCABhRa+YKmSMua/g8bP/Sue4Fw3u6gM syqYuqrKCHeZ6GPvKhuFJ6PG/++MN7TdP/6LzK/vY5sgK5VsN03hQTP0OvJL/mo6Pr8u XjGyEQbdzwM5CqjwU0zTJu7pA+Z4zVVIEEFPFnYuCFjD5bFWWM9+T+9/vZFhTDsD1nIk jFmKokWQrAXHtbKMKqEzDBnARaRQZ4YHvofzfu3TT+elW2iFmb4mDsIH1LZ7XQEFfAZE P+eQ== 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 x141si18355481pgx.266.2018.12.05.11.03.08; Wed, 05 Dec 2018 11:03:25 -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 S1728189AbeLETCX (ORCPT + 99 others); Wed, 5 Dec 2018 14:02:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36802 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727297AbeLETCX (ORCPT ); Wed, 5 Dec 2018 14:02:23 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FAE2811A9; Wed, 5 Dec 2018 19:02:22 +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 A6C1219C7B; Wed, 5 Dec 2018 19:02:21 +0000 (UTC) Date: Wed, 5 Dec 2018 14:02:20 -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, Jessica Yu Subject: Re: [PATCH v14 03/11] livepatch: Consolidate klp_free functions Message-ID: <20181205190220.vterzx33opvvijne@redhat.com> References: <20181129094431.7801-1-pmladek@suse.com> <20181129094431.7801-4-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181129094431.7801-4-pmladek@suse.com> User-Agent: Mutt/1.6.2-neo (2016-08-08) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 05 Dec 2018 19:02:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 29, 2018 at 10:44:23AM +0100, Petr Mladek wrote: > The code for freeing livepatch structures is a bit scattered and tricky: > > + direct calls to klp_free_*_limited() and kobject_put() are > used to release partially initialized objects > > + klp_free_patch() removes the patch from the public list > and releases all objects except for patch->kobj > > + object_put(&patch->kobj) and the related wait_for_completion() > are called directly outside klp_mutex; this code is duplicated; > > Now, we are going to remove the registration stage to simplify the API > and the code. This would require handling more situations in > klp_enable_patch() error paths. > > More importantly, we are going to add a feature called atomic replace. > It will need to dynamically create func and object structures. We will > want to reuse the existing init() and free() functions. This would > create even more error path scenarios. > > [*] We need our own flag. Note that kobject_put() cannot be called safely > when kobj.state_initialized is set. This flag is true when kobject_add() > part failed. And it is never cleared. > [*] We need our own flag. Note that kobject_put() cannot be called safely > when kobj.state_initialized is set. This flag is true when kobject_add() > part failed. And it is never cleared. > This patch implements a more clever free functions: ^^^^^^^^^^^^^ re-wording suggestions: "simpler", "clearer", "more straightforward" > > + checks kobj_alive flag instead of @limit[*] > > + initializes patch->list early so that the check for empty list > always works > > + The action(s) that has to be done outside klp_mutex are done > in separate klp_free_patch_finish() function. It waits only > when patch->kobj was really released via the _start() part. > > The patch does not change the existing behavior. > > [*] We need our own flag. Note that kobject_put() cannot be called safely > when kobj.state_initialized is set. This flag is true when kobject_add() > part failed. And it is never cleared. Isn't kobj.state_initialized also true in the ordinary kobject_put() case where kobject_add() succeeded? If so, this note could be modified slightly: (minimal change) [*] We need our own flag. Note that kobject_put() cannot be called safely just because kobj.state_initialized is set. This flag is even true when kobject_add() part failed. And it is never cleared. -- or -- (rewording) [*] We need our own flag to track that the kobject was successfully added to the hierarchy. Note that kobj.state_initialized only indicates that kobject has been initialized, not whether is has been added (and needs to be removed on cleanup). > > Signed-off-by: Petr Mladek > Cc: Josh Poimboeuf > Cc: Miroslav Benes > Cc: Jessica Yu > Cc: Jiri Kosina > Cc: Jason Baron > --- Acked-by: Joe Lawrence > > [ ... snip ... ] > > +static int klp_init_patch(struct klp_patch *patch) > +{ > + struct klp_object *obj; > + int ret; > + > + mutex_lock(&klp_mutex); > + > + ret = klp_init_patch_before_free(patch); > if (ret) { > mutex_unlock(&klp_mutex); > return ret; > } > I believe klp_init_patch_before_free() accumulates more responsibilities later in the patchset, but I'll ask here: does it really need the klp_mutex since it looks to be operating only on the klp_patch, its objects and functions? -- Joe