Received: by 10.223.176.5 with SMTP id f5csp1522016wra; Wed, 31 Jan 2018 07:39:46 -0800 (PST) X-Google-Smtp-Source: AH8x227xwLHXU5BJFOjn3Ly4Zv3hzlXo69iNyu5oUlOuNwFtVEyfY/c6RwEZQS+r3gtcXyPgvdkQ X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr13460645pls.32.1517413186230; Wed, 31 Jan 2018 07:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517413186; cv=none; d=google.com; s=arc-20160816; b=YW/2bhsHqkKy3R4Lbi5db6/mPQGCURBe34M9o8wCfz4kknaxGsdfG+hG0hAVjTTclD PeEAAV8FAKochJIuU3ypU7GToBEieJJpYBopPq7QxzBACPcc5Gf3PvkI4UNXAA2GlHRk SdMtGq3HaT3BpzYgITe8m93dcEJqGmooKCAU++H0HELNYR26OoCuRVYiujEKPOd9SlAq WozDeI1TO6TUpzwnIeYiEGsUQEEKFbnfMv5OmFWkGGNJ6RNE0zxgUN5rw1YMaF0RTTkb WSoO/vcPeAseNhMusThm8XXOiWo5M9hFRhPHkre3D+U4IchmDYBGUMbZRZ+RjZWb3/P5 1DhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=J/rNXMSLVcdEb/4BGurzpxudGnhzPCWD25F8MH8mxFo=; b=aUF3zkb6pHYgQ5MGZ01z8eeUV418vOG/ZzBULduaxWzt437jWJy+YqaQhdAmt3pC/c bNTAIp4LlI5eVBo8iNkzLBwXBjY+UvbO9kqqhM4nelLLcmH3t8r0IRZIW+1ae0/iYTLx 4Y3g7a8HP/o2pD4Cdv+K1nxbxwXHUMJ/zNMMLfdrJAuMx+zloiMrvd2mqzl7n6nBnFek 6osx+t+dJLAh/pr5VWLpCDObNmk2zRBuW1iMFm0091h1quoFJ1M+D+ais1jYylanAxSB dkWeeSatUP41InAa0Y73bMuOuRCY6T2BiPfqFoA0hZ5q561VFnJkUGAObCmAQEPDHQju dO4w== 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 88-v6si4734541pla.342.2018.01.31.07.39.31; Wed, 31 Jan 2018 07:39:46 -0800 (PST) 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 S932157AbeAaPjH (ORCPT + 99 others); Wed, 31 Jan 2018 10:39:07 -0500 Received: from mx2.suse.de ([195.135.220.15]:39416 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932090AbeAaPjG (ORCPT ); Wed, 31 Jan 2018 10:39:06 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 41A18AE12; Wed, 31 Jan 2018 15:39:05 +0000 (UTC) Date: Wed, 31 Jan 2018 16:39:04 +0100 (CET) From: Miroslav Benes To: Petr Mladek cc: jpoimboe@redhat.com, jikos@kernel.org, Jason Baron , jeyu@kernel.org, Evgenii Shatokhin , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: Re: PATCH v6 3/6] livepatch: Initial support for dynamic structures In-Reply-To: <20180125160203.28959-4-pmladek@suse.com> Message-ID: References: <20180125160203.28959-1-pmladek@suse.com> <20180125160203.28959-4-pmladek@suse.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 25 Jan 2018, Petr Mladek wrote: > From: Jason Baron > > We are going to add a feature called atomic replace. It will allow to > create a patch that would replace all already registered patches. > For this, we will need to dynamically create funcs' and objects' > for functions that are not longer patched. > > This patch adds basic framework to handle such dynamic structures. > > It adds enum klp_func_type that allows to distinguish the dynamically > allocated funcs' structures. Note that objects' structures do not have > a clear type. Namely the static objects' structures might list both static > and dynamic funcs' structures. > > The function type is then used to limit klp_free() functions. We will > want to free the dynamic structures separately when they are not > longer needed. At the same time, we also want to make our life easier, > and introduce _any_ type that will allow to process all existing > structures in one go. > > We need to be careful here. First, objects' structures must be freed > only when all listed funcs' structures are freed. Also we must avoid > double free. Both problems are solved by removing the freed structures > from the list. > > Also note that klp_free*() functions are called also in klp_init_patch() > error path when only some kobjects have been initialized. The other > dynamic structures must be freed immediately by calling the respective > klp_free_*_dynamic() functions. > > Finally, the dynamic objects' structures are generic. The respective > klp_allocate_object_dynamic() and klp_free_object_dynamic() can > be implemented here. On the other hand, klp_free_func_dynamic() > is empty. It must be updated when a particular dynamic > klp_func_type is introduced. > > Signed-off-by: Jason Baron > [pmladek@suse.com: Converted into a generic API] > Signed-off-by: Petr Mladek > Cc: Josh Poimboeuf > Cc: Jessica Yu > Cc: Jiri Kosina > Cc: Miroslav Benes > --- > include/linux/livepatch.h | 37 +++++++++++- > kernel/livepatch/core.c | 139 ++++++++++++++++++++++++++++++++++++++++------ > 2 files changed, 159 insertions(+), 17 deletions(-) > > diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h > index e5db2ba7e2a5..21cad200f949 100644 > --- a/include/linux/livepatch.h > +++ b/include/linux/livepatch.h > @@ -35,12 +35,22 @@ > #define KLP_UNPATCHED 0 > #define KLP_PATCHED 1 > > +/* > + * Function type is used to distinguish dynamically allocated structures > + * and limit some operations. > + */ > +enum klp_func_type { > + KLP_FUNC_ANY = -1, /* Substitute any type */ > + KLP_FUNC_ORIGINAL = 0, /* Original statically defined structure */ Wouldn't KLP_FUNC_STATIC be better? KLP_FUNC_ORIGINAL confused me couple of times. Miroslav