Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp557433pxk; Wed, 2 Sep 2020 08:42:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1buWZ1YLGl4XcVJqiTWFQLDEvmok9VVvzWvCyytAivyYrpvnOIgOFgBpWK4c8UIZX9yWs X-Received: by 2002:aa7:dc18:: with SMTP id b24mr702289edu.224.1599061353008; Wed, 02 Sep 2020 08:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599061353; cv=none; d=google.com; s=arc-20160816; b=jF8sOK6c902gKNZXlGLgydRcpEEYnVx2KD53CjA9aASwJw2FE55Iscc0cAuwynfkNF anT/Sr5OrPQ90SxLvg4LVGjrDwoDtZ5KKKyFWI9zN2kYak55zUk1RgbDZc0bie6A5PGS PGEuJJRfDKKhVW4cawkWUKBM2moa81iG2Wy/mhrNFtpT+Dchnz+9BRb9sGLm12adB64E Ik1RXyK9YfVaxhGKPRRUQGWDNQzXyvgJoQdcMzUVpv8KjXQ/ZovzuGYSKKhOWtML9cBL 2tJP99bKOQJUPZL2NrhVDEtKv8fAk2A98cY5QYJHWQfGTmcm/NWPhgscI/IjvG9QlhKd 3n3w== 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; bh=H1l4rJBsdFbSRFOMkTC40pjKEkftdhhtzwmYQKKVvNo=; b=fd2evJMa3c2+wxvphsfZ2qM3CkbyowuDpzKuSdwJpeGL1IDTLOIA3K5gU2h83lzvhM CGv7gC8vfYwGKAVoPIbZr7RB/zveqH4vWzfv+pIIIn/oOEAMpMJQTxAYIfEAHt8nwcHk m4MBVzy8kHUNN0LzV+cQRv0h0YS9UCbWbIzM60KR73aikf6+tDjfFr6pU+ncZSd2ze0L vzpdP1uAFYNOOg6HEKc2xayXcDTTqsGnrfemo5NmCBOYbBeM+OTIOQg0uK8cnnwIczT/ uHIbx/C/LDeXOwHe2oYXVEzXNeWvwkBXu570Gdb8cJa2AfFrJVWXOBFRvbYPoWF/644V uP8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l30si2583369ede.434.2020.09.02.08.41.44; Wed, 02 Sep 2020 08:42:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728179AbgIBPk4 (ORCPT + 99 others); Wed, 2 Sep 2020 11:40:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:39248 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgIBNpf (ORCPT ); Wed, 2 Sep 2020 09:45:35 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9147AB60B; Wed, 2 Sep 2020 13:45:34 +0000 (UTC) Date: Wed, 2 Sep 2020 15:45:33 +0200 (CEST) From: Miroslav Benes To: Joe Lawrence cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, nstange@suse.de Subject: Re: [PATCH 1/2] docs/livepatch: Add new compiler considerations doc In-Reply-To: <20200721161407.26806-2-joe.lawrence@redhat.com> Message-ID: References: <20200721161407.26806-1-joe.lawrence@redhat.com> <20200721161407.26806-2-joe.lawrence@redhat.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 Hi, first, I'm sorry for the late reply. Thanks, Josh, for the reminder. CCing Nicolai. Nicolai, could you take a look at the proposed documentation too, please? You have more up-to-date experience. On Tue, 21 Jul 2020, Joe Lawrence wrote: > +Examples > +======== > + > +Interprocedural optimization (IPA) > +---------------------------------- > + > +Function inlining is probably the most common compiler optimization that > +affects livepatching. In a simple example, inlining transforms the original > +code:: > + > + foo() { ... [ foo implementation ] ... } > + > + bar() { ... foo() ... } > + > +to:: > + > + bar() { ... [ foo implementation ] ... } > + > +Inlining is comparable to macro expansion, however the compiler may inline > +cases which it determines worthwhile (while preserving original call/return > +semantics in others) or even partially inline pieces of functions (see cold > +functions in GCC function suffixes section below). > + > +To safely livepatch ``foo()`` from the previous example, all of its callers > +need to be taken into consideration. For those callers that the compiler had > +inlined ``foo()``, a livepatch should include a new version of the calling > +function such that it: > + > + 1. Calls a new, patched version of the inlined function, or > + 2. Provides an updated version of the caller that contains its own inlined > + and updated version of the inlined function I'm afraid the above could cause a confusion... "1. Calls a new, patched version of the inlined function, or". The function is not inlined in this case. Would it be more understandable to use function names? 1. Calls a new, patched version of function foo(), or 2. Provides an updated version of bar() that contains its own inlined and updated version of foo() (as seen in the example above). Not to say that it is again a call of the compiler to decide that, so one usually prepares an updated version of foo() and updated version of bar() calling to it. Updated foo() has to be there for non-inlined cases anyway. > + > +Other interesting IPA examples include: > + > +- *IPA-SRA*: removal of unused parameters, replace parameters passed by > + referenced by parameters passed by value. This optimization basically s/referenced/reference/ > + violates ABI. > + > + .. note:: > + GCC changes the name of function. See GCC function suffixes > + section below. > + > +- *IPA-CP*: find values passed to functions are constants and then optimizes > + accordingly Several clones of a function are possible if a set is limited. "...accordingly. Several..." [...] > + void cdev_put(struct cdev *p) > + { > + if (p) { > + struct module *owner = p->owner; > + kobject_put(&p->kobj); > + module_put(owner); > + } > + } git am complained here about whitespace damage. [...] > +kgraft-analysis-tool > +-------------------- > + > +With the -fdump-ipa-clones flag, GCC will dump IPA clones that were created > +by all inter-procedural optimizations in ``.000i.ipa-clones`` files. > + > +kgraft-analysis-tool pretty-prints those IPA cloning decisions. The full > +list of affected functions provides additional updates that the source-based > +livepatch author may need to consider. For example, for the function > +``scatterwalk_unmap()``: > + > +:: > + > + $ ./kgraft-ipa-analysis.py --symbol=scatterwalk_unmap aesni-intel_glue.i.000i.ipa-clones > + Function: scatterwalk_unmap/2930 (include/crypto/scatterwalk.h:81:60) > + isra: scatterwalk_unmap.isra.2/3142 (include/crypto/scatterwalk.h:81:60) > + inlining to: helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > + inlining to: helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > + inlining to: helper_rfc4106_encrypt/3006 (arch/x86/crypto/aesni-intel_glue.c:939:12) > + > + Affected functions: 3 > + scatterwalk_unmap.isra.2/3142 (include/crypto/scatterwalk.h:81:60) > + helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > + helper_rfc4106_encrypt/3006 (arch/x86/crypto/aesni-intel_glue.c:939:12) The example for the github is not up-to-date. The tool now expects file_list with *.ipa-clones files and the output is a bit different for the recent kernel. $ echo arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones | kgraft-ipa-analysis.py --symbol=scatterwalk_unmap /dev/stdin Parsing file (1/1): arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones Function: scatterwalk_unmap/3935 (./include/crypto/scatterwalk.h:59:20) [REMOVED] [object file: arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones] isra: scatterwalk_unmap.isra.8/4117 (./include/crypto/scatterwalk.h:59:20) [REMOVED] inlining to: gcmaes_crypt_by_sg/4019 (arch/x86/crypto/aesni-intel_glue.c:682:12) [REMOVED] [edges: 4] constprop: gcmaes_crypt_by_sg.constprop.13/4182 (arch/x86/crypto/aesni-intel_glue.c:682:12) Affected functions: 3 scatterwalk_unmap.isra.8/4117 (./include/crypto/scatterwalk.h:59:20) [REMOVED] gcmaes_crypt_by_sg/4019 (arch/x86/crypto/aesni-intel_glue.c:682:12) [REMOVED] gcmaes_crypt_by_sg.constprop.13/4182 (arch/x86/crypto/aesni-intel_glue.c:682:12) The rest looks great. Thanks a lot, Joe, for putting it together. Miroslav