Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbdHROT6 (ORCPT ); Fri, 18 Aug 2017 10:19:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58216 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750709AbdHROTz (ORCPT ); Fri, 18 Aug 2017 10:19:55 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B56D881DF3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=joe.lawrence@redhat.com Subject: Re: [PATCH v4] livepatch: introduce shadow variable API To: Petr Mladek , Nicolai Stange Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Poimboeuf , Jessica Yu , Jiri Kosina , Miroslav Benes References: <1502740963-31310-1-git-send-email-joe.lawrence@redhat.com> <1502740963-31310-2-git-send-email-joe.lawrence@redhat.com> <87pobtj8hu.fsf@suse.de> <20170818140445.GC25223@pathway.suse.cz> From: Joe Lawrence Organization: Red Hat Message-ID: <5f769d8c-f539-ebdc-359b-ef42dc7c019b@redhat.com> Date: Fri, 18 Aug 2017 10:19:54 -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: <20170818140445.GC25223@pathway.suse.cz> 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.25]); Fri, 18 Aug 2017 14:19:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1881 Lines: 53 On 08/18/2017 10:04 AM, Petr Mladek wrote: > On Fri 2017-08-18 15:44:29, Nicolai Stange wrote: >> Joe Lawrence writes: >> >> >>> + >>> +/** >>> + * klp_shadow_get() - retrieve a shadow variable data pointer >>> + * @obj: pointer to parent object >>> + * @id: data identifier >>> + * >>> + * Return: the shadow variable data element, NULL on failure. >>> + */ >>> +void *klp_shadow_get(void *obj, unsigned long id) >>> +{ >>> + struct klp_shadow *shadow; >>> + >>> + rcu_read_lock(); >>> + >>> + hash_for_each_possible_rcu(klp_shadow_hash, shadow, node, >>> + (unsigned long)obj) { >>> + >>> + if (klp_shadow_match(shadow, obj, id)) { >>> + rcu_read_unlock(); >>> + return shadow->data; >> >> I had to think a moment about what protects shadow from getting freed by >> a concurrent detach after that rcu_read_unlock(). Then I noticed that if >> obj and the livepatch are alive, then so is shadow, because there >> obviously hasn't been any reason to detach it. >> >> So maybe it would be nice to have an additional comment at >> klp_shadow_detach() that it's the API user's responsibility not to use a >> shadow instance after detaching it... Nicolai, I can add something like "This function releases the memory for this shadow variable instance, callers should stop referencing it accordingly." Similar text for klp_shadow_detach_all(). > Good point. In fact, it might make sense to rename the functions: > > attach -> create > detach -> destroy > > The name detach suggests that the variable is just not connected to > the parent object but that it is still accessible/usable. FWIW, kpatch calls them "kpatch_shadow_alloc" and "kpatch_shadow_free". Now that it's clear that we're not going separate shadow variable allocation from hash table insertion, going back to alloc/create and destroy/free is fine w/me. -- Joe