Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6925366yba; Thu, 2 May 2019 00:31:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHlOEQ6QO90TxVZnFttcK4JAHtxRC9utyOfqDzifwfWqGbcEON3Dye5jH9zAZRLKotsm9v X-Received: by 2002:a63:7f0b:: with SMTP id a11mr2345951pgd.234.1556782315193; Thu, 02 May 2019 00:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556782315; cv=none; d=google.com; s=arc-20160816; b=oHrv5KbG9bv7SJPJr/n+0lWOYHwaXhz9w0u6YKuAF48B5gcoAJISc6blnFRa6mcoA7 znz/EJLYNzqMympzSM+WPqtvMUe+kwRgR46/yNrocRgGHKYGMaDsxReFthTtO3TKlkDF v9IBtUTdUyemBfNkGJA9IVDiY1ZVOvY8EGBml3get2wLcoGjZAYqidbZEaMMCGKu0cnH 8I91dpT50iJq2VSg6Lx5DAzwA8qWAWfCMRI2uQ8pv1klC89o97VAAe34PZ/3vsmhZidJ AmCQnGpxySCs5fT6fIqJ6hR/1Cbj4dwIMeA9IX8B9rLoOs5Ugy0P9oDjse+UZS/YVtSn 4q/w== 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=UTtt2sZmd8UHDot8GhNQjX+QpDvL15+cCkICVT9l460=; b=JrqNuUr8lOp5eXzXD/vdf/Pji7Wtnf1ONHCp/mtSAQsuvyuDA5j8VanVE00xlXF6/S kGxUjS5h8tjWxa3rWqxeeTZc4oc5qRA/1+a5GuyVwxuFUvwAmk9lRn5PNnfsjoIn5Ywd LaEL2zxwaXjdk6LLAtTYdRcpnCh24prUEV1QzkE++BNsOM6+xL6ZT5ZR+cF4JbFiCCC+ qgZ7pSfsQcE+I8DVysgcCT5XdRp5cLQ1udNgsc6wIA51o8HpsK+oeXhL/ey/x1WN1Jeg wI6UIs4kigCtuQTYR/qOFokxMZ1dnbjRa7xYmzpqFfMv5ONrTVc26ZZkVJ9MhwKjqQRl Sr/w== 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 o187si26899905pga.16.2019.05.02.00.31.39; Thu, 02 May 2019 00:31:55 -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 S1726264AbfEBHaq (ORCPT + 99 others); Thu, 2 May 2019 03:30:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:47774 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726186AbfEBHaq (ORCPT ); Thu, 2 May 2019 03:30:46 -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 36A83ADDA; Thu, 2 May 2019 07:30:45 +0000 (UTC) Date: Thu, 2 May 2019 09:30:44 +0200 From: Petr Mladek To: Greg Kroah-Hartman , "Tobin C. Harding" Cc: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , "Rafael J. Wysocki" , Joe Lawrence , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 5/5] livepatch: Do not manually track kobject initialization Message-ID: <20190502073044.bfzugymrncnaajxe@pathway.suse.cz> References: <20190502023142.20139-1-tobin@kernel.org> <20190502023142.20139-6-tobin@kernel.org> <20190502071232.GB16247@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190502071232.GB16247@kroah.com> 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 On Thu 2019-05-02 09:12:32, Greg Kroah-Hartman wrote: > On Thu, May 02, 2019 at 12:31:42PM +1000, Tobin C. Harding wrote: > > Currently we use custom logic to track kobject initialization. Recently > > a predicate function was added to the kobject API so we now no longer > > need to do this. > > > > Use kobject API to check for initialized state of kobjects instead of > > using custom logic to track state. > > > > Signed-off-by: Tobin C. Harding > > --- > > include/linux/livepatch.h | 6 ------ > > kernel/livepatch/core.c | 18 +++++------------- > > 2 files changed, 5 insertions(+), 19 deletions(-) > > > > @@ -626,7 +626,7 @@ static void __klp_free_objects(struct klp_patch *patch, bool nops_only) > > list_del(&obj->node); > > > > /* Might be called from klp_init_patch() error path. */ > > - if (obj->kobj_added) { > > + if (kobject_is_initialized(&obj->kobj)) { > > kobject_put(&obj->kobj); > > } else if (obj->dynamic) { > > klp_free_object_dynamic(obj); > > Same here, let's not be lazy. > > The code should "know" if the kobject has been initialized or not > because it is the entity that asked for it to be initialized. Don't add > extra logic to the kobject core (like the patch before this did) just > because this one subsystem wanted to only write 1 "cleanup" function. We use kobject for a mix of statically and dynamically defined structures[*]. And we misunderstood the behavior of kobject_init(). Anyway, the right solution is to call kobject_init() already in klp_init_patch_early() for the statically defined structures and in klp_alloc*() for the dynamically allocated ones. Then we could simply call kobject_put() every time. Tobin, this goes deeper into the livepatching code that you probably expected. Do you want to do the above suggested change or should I prepare the patch? Anyway, thanks for working on this. [*] Yes, we know that kobject was not designed for static structures. We even tried to use them but there was a lot of extra code with not a big benefit. Best Regards, Petr