Received: by 10.223.176.5 with SMTP id f5csp2765767wra; Thu, 1 Feb 2018 05:50:23 -0800 (PST) X-Google-Smtp-Source: AH8x224kdH8EerVvZZclKqL8GfVaHzlLl8d1CdkyfxGtKdoyQaO6WIR2lLpTVKFK+BSx7l5tJXl7 X-Received: by 2002:a17:902:34a:: with SMTP id 68-v6mr32483422pld.276.1517493023696; Thu, 01 Feb 2018 05:50:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517493023; cv=none; d=google.com; s=arc-20160816; b=fAEoK0evYuEB3ns8gYyuzttKP+qUx/FMlRTtVZEfBGxfpFlzxXbIGI1y7MS4lYyAxa 6LehQ7zblsCOjNYxM8L2lXPQ05A3Y17vVRcSJUA7Zj4SbfMB/R6DxzH7Uf7pan9gIhlx uEMczYm+E1gAcI3eWb5qIN+9jmwV3rxrseFVDzJt0m824BQzFTwY7+r76OnWYm+tE7zn mqryi2P6MUCcmh/3PmNUjCSQ1nvkOGFg58YuutKhNV+zQ8byCqxpOZCIiJQkNQcd0pw0 dO8YL0NoH0N1aOHd7FP2psa2KzD40UsbLvxY7eau/B0ixdz/WOe3BRohhs6TiJGtBu2B 7MYA== 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=ooIiX52KdS6jHLRE8YtJVo77iigCKEqQ5AintCkm/7U=; b=EkoTIwiKLB8kwcrCnYcJKZgi6w70vrSVditvra0hHc/rxBIWCv+lp/uckZgklVLIvx kkm3GY3UXVZ9Xfatp5vWxiF1Pmd5HmaNTRAa8L8UIHLl00aqywTM9T7caC92sZQQQaLj UJO5rVXbooJk1z4+oGQNUfB3Uj8D5OsSxun/0ZX+44kQCcoIFXjnsnCUyYZ+k7VbO7+g 08WFjzZay/uMlhNZJ4ZsQt9RIuoaEg3e41sZ+cUyt49VmbTozN5zf73ahwXDdUAGH3D4 mJwxBCDbXN075mKYS8SFpGgZRcj/BULBqUWOFeEcEkngH9DrR8XEd0pK4PIrS4ARHfP+ /7qg== 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 g6-v6si1740463plm.373.2018.02.01.05.50.08; Thu, 01 Feb 2018 05:50:23 -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 S1752427AbeBANta (ORCPT + 99 others); Thu, 1 Feb 2018 08:49:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:43005 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752207AbeBANt0 (ORCPT ); Thu, 1 Feb 2018 08:49:26 -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 37019ABF3; Thu, 1 Feb 2018 13:49:25 +0000 (UTC) Date: Thu, 1 Feb 2018 14:49:24 +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 6/6] livepatch: Add atomic replace In-Reply-To: <20180125160203.28959-7-pmladek@suse.com> Message-ID: References: <20180125160203.28959-1-pmladek@suse.com> <20180125160203.28959-7-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 > -struct klp_object *klp_get_or_add_object(struct klp_patch *patch, > +static struct klp_object *klp_get_or_add_object(struct klp_patch *patch, > struct klp_object *old_obj) A nit, but this change belongs to 3/6, doesn't it? > { > struct klp_object *obj; > @@ -708,6 +764,102 @@ struct klp_object *klp_get_or_add_object(struct klp_patch *patch, > return obj; > } [...] > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > index 6917100fbe79..3f6cf5b9e048 100644 > --- a/kernel/livepatch/transition.c > +++ b/kernel/livepatch/transition.c > @@ -87,6 +87,33 @@ static void klp_complete_transition(void) > klp_transition_patch->mod->name, > klp_target_state == KLP_PATCHED ? "patching" : "unpatching"); > > + /* > + * For replace patches, we disable all previous patches, and replace > + * the dynamic no-op functions by removing the ftrace hook. > + */ > + if (klp_transition_patch->replace && klp_target_state == KLP_PATCHED) { > + /* > + * Make sure klp_ftrace_handler() can no longer see functions > + * from the replaced patches. Then all functions will be > + * redirected using klp_transition_patch. They will use > + * either a new code or they will stay in the original code > + * because of the nop funcs' structures. > + */ > + if (klp_forced) > + klp_synchronize_transition(); I'm not sure why this is here. klp_forced should not be so special that it would warrant a synchronization. However, I'm also not sure that it would be safe to remove it from the patch. Is this because "force" is the only one who can clear TIF_PATCH_PENDING of other tasks? So, there could be a task running in klp_ftrace_handler(), its TIF_PATCH_PENDING is cleared by force and we could have a problem because of that since we're throwing away replaced patches. Ok, that sounds viable. I'd welcome a comment on that in the code. Thanks, Miroslav > + > + klp_throw_away_replaced_patches(klp_transition_patch, > + klp_forced); > + > + /* > + * There is no need to synchronize the transition after removing > + * nops. They must be the last on the func_stack. Ftrace > + * gurantees that nobody will stay in the trampoline after > + * the ftrace handler is unregistered. > + */ > + klp_unpatch_objects(klp_transition_patch, KLP_FUNC_NOP); > + } > + > if (klp_target_state == KLP_UNPATCHED) { > /* > * All tasks have transitioned to KLP_UNPATCHED so we can now