Received: by 10.223.185.116 with SMTP id b49csp296932wrg; Fri, 2 Mar 2018 19:35:13 -0800 (PST) X-Google-Smtp-Source: AG47ELup84m+kAEgcgHVLpiVz9DNpcQjFMo3sYJW3YpYzyW9vz7VRGcW2AKd/66NAGoqQrQPOWkQ X-Received: by 2002:a17:902:8a8d:: with SMTP id p13-v6mr7308266plo.144.1520048113618; Fri, 02 Mar 2018 19:35:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520048113; cv=none; d=google.com; s=arc-20160816; b=Zqj/mPBoUNKPu3FJ+78hlc45KyHMqYQTmvzV+S5veEmo5kl/eU+aerFl5RJk3a/l3+ jJEIcMdsulL4uNacZbDvyVt0+/ZCzoLmHB/cTjpOArgKRnhq1znA1j6sNJ86btcZQoCp HZCnyiucCkf+kPsEK25DPZqd/d9SnJkiWNPxO8GB97fYGl3n0RUoV1TPLpmZ5hRTsyVY D/RzBdBTcu8js38Tu8jPGMjCY8HwAzWBrEPBNqUdS1aZjnaJF36mB1fatLWF69HNm1LH MPfZoF/dpArl+w34SoVla80KR2mDK1qv6WicRqtInVRqKE3ijF01+qYPKWF7gVbvogax owsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=HNJEHFES6o8Ovxf7/2ZgdAPfoF+ZNVhk662WkHiKmc8=; b=FgYrsPj4Hzd2TQVEw7Gou3fdikT5sQwra00D2ppQ/lmgUaoCHccIBAjqHjIoY7cRVJ t3eY5aUIwU5QJi4vBvjQREP8ZZbitSVZdxgsu28u3mp0l2UEwadodcMGXN/uTkwAFGoT U0MRLP1/Lk1bUK7sC7XLtBUNfbSm1cQYICMHEz+uf1of9RDnGVNYKD9KrgNmvEgkNz0T JmYPBcPpbgHTFHZCZDra3H/zea7jDcZ8cYl+JzgSKxFOo11uZJg/F1sDz0ME/fsocVw6 OWLB+hJo/QqFQetYDI6S6PT75nHoRCPm71Pu2epwmWI90lKaV6JS+AEg5Vbgcbzc0ZAJ Imjg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o20-v6si5818885pli.105.2018.03.02.19.34.59; Fri, 02 Mar 2018 19:35:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932764AbeCBWA4 (ORCPT + 99 others); Fri, 2 Mar 2018 17:00:56 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41760 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932681AbeCBWAl (ORCPT ); Fri, 2 Mar 2018 17:00:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5DDC7B4AD; Fri, 2 Mar 2018 22:00:40 +0000 (UTC) Received: from jlaw-desktop.bos.csb (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E99A2166BAE; Fri, 2 Mar 2018 22:00:40 +0000 (UTC) Subject: Re: [PATCH v8 7/8] livepatch: Correctly handle atomic replace for not yet loaded modules To: Petr Mladek , Miroslav Benes Cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180221132914.4809-1-pmladek@suse.com> <20180221132914.4809-8-pmladek@suse.com> <20180301102859.zwrt6w36ub474nb2@pathway.suse.cz> From: Joe Lawrence Organization: Red Hat Message-ID: <7f920ec3-dfe0-6a4d-dd25-5d5c4fa75714@redhat.com> Date: Fri, 2 Mar 2018 17:00:40 -0500 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: <20180301102859.zwrt6w36ub474nb2@pathway.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 22:00:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 22:00:40 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'joe.lawrence@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/01/2018 05:28 AM, Petr Mladek wrote: > On Thu 2018-02-22 22:00:28, Miroslav Benes wrote: >> On Wed, 21 Feb 2018, Petr Mladek wrote: >>> This patch allows the late initialization. >>> >>> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c >>> index ad508a86b2f9..da1438d47d83 100644 >>> --- a/kernel/livepatch/core.c >>> +++ b/kernel/livepatch/core.c >>> @@ -984,7 +988,12 @@ static void klp_free_patch(struct klp_patch *patch) >>> >>> static int klp_init_func(struct klp_object *obj, struct klp_func *func) >>> { >>> - if (!func->old_name || !func->new_func) >>> + if (!func->old_name) >>> + return -EINVAL; >>> + >>> + /* NOPs do not know the address until the patched module is loaded. */ >>> + if (!func->new_func && >>> + (!klp_is_func_type(func, KLP_FUNC_NOP) || klp_is_object_loaded(obj))) >>> return -EINVAL; >> >> If we changed the order of klp_init_func() and klp_init_object_loaded() >> calls in klp_init_object(), the hunk would not be needed. Is that correct? > > Not really. klp_init_object_loaded() would set func->new_func only > when the object was loaded. But we want to proceed here and create > the kobject for NOPs even when it was not loaded. > > >>> INIT_LIST_HEAD(&func->stack_node); >>> @@ -1039,6 +1048,9 @@ static int klp_init_object_loaded(struct klp_patch *patch, >>> return -ENOENT; >>> } >>> >>> + if (klp_is_func_type(func, KLP_FUNC_NOP)) >>> + func->new_func = (void *)func->old_addr; >> >> Is there a reason why you left the same assignment in >> klp_alloc_func_nop()? This one is enough, no? > > Good point! I am going to replace the obsolete assignment > with a comment in v8. Hi Petr, Miroslav, I don't think the assignment in klp_alloc_func_nop() was necessarily redundant. It was removed in v9 and that breaks my atomic replace sample module when I try to load it. (Perhaps the sample patch has issues, but here are my debug notes): To recap: patch 1 - modifies cmdline_proc_show() patch 2 - modifies only meminfo_proc_show() when I load patch 2 with .replace=1, klp_add_nops() is called and this adds a nop function to patch 2 so it reverts cmdline_proc_show(): klp_init_patch() if (patch->replace) klp_add_nops() list_for_each_entry(old_patch, &klp_patches, list) { klp_for_each_object(old_patch, old_obj) { klp_add_object_nops() klp_add_func_nop() klp_alloc_func_nop() the patch continues initialization and I hit the second -EINVAL condition on that nop function in klp_init_func(): klp_init_object klp_init_func (from added debug): [ 48.456980] livepatch: func->old_name=cmdline_proc_show [ 48.457620] livepatch: func->new_func= (null) [ 48.458042] livepatch: klp_is_func_type(func, KLP_FUNC_NOP)=1 [ 48.458573] livepatch: klp_is_object_loaded(obj)=1 If I restore the assignment of func->new_func to klp_alloc_func_nop() then the replacement patch properly loads. (Reordering the code may have similar effect?) I think this problem is contained to only replacement patches that need the nop-revert feature... if the replacement patch provides a new function definition, then it shouldn't be affected. Man, we need a regression test suite for all these cases :) -- Joe