Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752856AbdHRNol convert rfc822-to-8bit (ORCPT ); Fri, 18 Aug 2017 09:44:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:34119 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752021AbdHRNog (ORCPT ); Fri, 18 Aug 2017 09:44:36 -0400 From: Nicolai Stange To: Joe Lawrence Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Poimboeuf , Jessica Yu , Jiri Kosina , Miroslav Benes , Petr Mladek Subject: Re: [PATCH v4] livepatch: introduce shadow variable API References: <1502740963-31310-1-git-send-email-joe.lawrence@redhat.com> <1502740963-31310-2-git-send-email-joe.lawrence@redhat.com> Date: Fri, 18 Aug 2017 15:44:29 +0200 In-Reply-To: <1502740963-31310-2-git-send-email-joe.lawrence@redhat.com> (Joe Lawrence's message of "Mon, 14 Aug 2017 16:02:43 -0400") Message-ID: <87pobtj8hu.fsf@suse.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1252 Lines: 51 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... Thanks, Nicolai > + } > + } > + > + rcu_read_unlock(); > + > + return NULL; > +} > +EXPORT_SYMBOL_GPL(klp_shadow_get); -- SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)