Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933702AbdGSTB7 (ORCPT ); Wed, 19 Jul 2017 15:01:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:37296 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933688AbdGSTB6 (ORCPT ); Wed, 19 Jul 2017 15:01:58 -0400 Date: Wed, 19 Jul 2017 21:01:55 +0200 (CEST) From: Miroslav Benes To: Joe Lawrence cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Poimboeuf , Jessica Yu , Jiri Kosina , Petr Mladek Subject: Re: [PATCH v2 1/2] livepatch: introduce shadow variable API In-Reply-To: <20170718202107.3hsptpdspr26snxc@redhat.com> Message-ID: References: <1498664247-12296-1-git-send-email-joe.lawrence@redhat.com> <1498664247-12296-2-git-send-email-joe.lawrence@redhat.com> <20170718202107.3hsptpdspr26snxc@redhat.com> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2483 Lines: 55 > > > +/** > > > + * _klp_shadow_attach() - allocate and add a new shadow variable > > > + * @obj: pointer to original data > > > + * @num: numerical description of new data > > > + * @new_data: pointer to new data > > > + * @new_size: size of new data > > > + * @gfp_flags: GFP mask for allocation > > > + * @lock: take klp_shadow_lock during klp_shadow_hash operations > > > > I am not sure about lock argument. Do we need it? Common practice is to > > have function foo() which takes a lock, and function __foo() which does > > not. > > > > In klp_shadow_get_or_attach(), you use it as I'd expect. You take the > > spinlock, call this function and release the spinlock. Is it possible > > to do the same in klp_shadow_attach() and have __klp_shadow_attach() > > without lock argument? > > Yes, this would be possible, though it would restrict > klp_shadow_attach() from accepting gfp_flags that might allow for > sleeping. More on that below ... Ok, that is a good remark. The problem is that it applies to klp_shadow_get_or_attach() too. There you acquire a spin_lock and call _klp_shadow_attach() with gfp_flags, which are then used for kzalloc. I might misread the code. It is getting late here. > > > + * > > > + * Note: allocates @new_size space for shadow variable data and copies > > > + * @new_size bytes from @new_data into the shadow varaible's own @new_data > > > + * space. If @new_data is NULL, @new_size is still allocated, but no > > > + * copy is performed. > > > > I must say I'm not entirely happy with this. I don't know if this is what > > Petr had in mind (I'm sure he'll get to the patch set soon). Calling > > memcpy instead of a simple assignment in v1 seems worse. > > This change was a bit of a experiment on my part in reaction to > adding klp_shadow_get_or_attach(). > > I like the simplicity of v1's pointer assignment -- in fact, moving all > allocation responsiblity (klp_shadow meta-data and data[] area) out to > the caller is doable, though implementing klp_shadow_get_or_attach() and > and klp_shadow_detach_all() complicates matters, for example, adding an > alloc/release callback. I originally attempted this for v2, but turned > back when the API and implementation grew complicated. If the memcpy > and gfp_flag restrictions are too ugly, I can try revisting that > approach. Ideas welcome :) Well, I didn't like callbacks either :). And no, I do not have a better idea. I still need to think about it. Miroslav