Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965613AbdGTPso (ORCPT ); Thu, 20 Jul 2017 11:48:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57601 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965576AbdGTPsm (ORCPT ); Thu, 20 Jul 2017 11:48:42 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91A1E7570F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=joe.lawrence@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 91A1E7570F Subject: Re: [PATCH v2 1/2] livepatch: introduce shadow variable API To: Miroslav Benes Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Poimboeuf , Jessica Yu , Jiri Kosina , Petr Mladek 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> From: Joe Lawrence Organization: Red Hat Message-ID: <164836e1-2d33-ec32-46ac-d6360f671b17@redhat.com> Date: Thu, 20 Jul 2017 11:48:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 20 Jul 2017 15:48:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2630 Lines: 68 On 07/20/2017 10:45 AM, Miroslav Benes wrote: > >>>>> + * >>>>> + * 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. > > Done and I agree that memcpy approach is not so bad after all :). So I'm > fine with it. I looked at it again this morning and a "pass-your-own" allocation API always comes back to adding callbacks and other complications :( In the end, most callers will be shadowing pointers and not entire structures, so I think the copy isn't too bad. On a related note, if we keep the allocations and memcpy, how about I shift around the attach/get calls like so: __klp_shadow_attach set shadow variable member values memcpy add to hash klp_shadow_attach alloc new shadow var lock call __klp_shadow_attach with new alloc unlock klp_shadow_get_or_attach be optimistic, call klp_shadow_get (if found, return it) be pessimistic, alloc new shadow var lock call klp_shadow_get again if unlikely found kfree unneeded alloc else call __klp_shadow_attach with new alloc unlock return whichever shadow var we used This way both calls can accept gfp_flags that may sleep, with the only downside that klp_shadow_get_or_attach may allocate an unnecessary shadow variable in the unlikely case that it's found on the second klp_shadow_get attempt (under the lock). No more clunky "bool lock" flag either. :) -- Joe