Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp545069ybg; Wed, 23 Oct 2019 02:06:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9X9mLw6vtn31QEJa7OmqFlPlzQ6TLvbjf3P2H1VVzPV4WGzsCdi50WZvnoeoof16Dm/zY X-Received: by 2002:a17:906:e2d6:: with SMTP id gr22mr31079248ejb.160.1571821577751; Wed, 23 Oct 2019 02:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571821577; cv=none; d=google.com; s=arc-20160816; b=Z50ByY/CLXy5G6CDmIVCZpIVxdfDThypm75GIwB9be+mJrh1uRmfBF/VEgE1Br+8HN bdhL8UwdorX8zm8VGKblApBU0mCEFJIH56Ey+C++6OBCcxnumcIuFPFs9WuEQXxIxuMZ 5C47K8EyKlZtqaTbjc1B4P/h95O+VDSp+U3AZpb9U3kGiOhw/umIgg2NUR00AjxZ0lUe sEfMz5HdA1YaK5xbA4Wv+kIJ3XJ9GfEBzBX5TUohINQwGzqrRXp/Bjn/iXVFHeEe/GIZ DOB8WEtovVTg7dyyvDWZmsgNdiAyllgnXlMEkvk+lytWvahvH2BIwIsFMKYTnAO0AdAY i07g== 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=uabShSd2Ex1Y3bz1Okt0ldUJ2f8rXXgAAyK3DCN8N7o=; b=SnH0le4zdh9dfxWKVmbuqmeTIjjuTirkURENMKDL/Lrg3AnT46rYKAEUrL7cwsqtba LdQ2+RlPlsDML+KYrS+Kx9Wtgup9LC3IWmH+ELntN/ClrXfa9OKoYUiEqQZVC7+l020U jpJjM+Qd4dhH7Uj463XO76NjMiYj90r9Lfruv7rynjbr5UPPOH/jhMQpyIAcFv16ZgJ5 qXe3B3Sa2ymX7v1rKT4qzTyTJ+1EofJa/99lRBMRDL0oJNSgOi08JpHbs5y10NOAoADD PUz4amAXFVZc1StrjrDfvT+opHljtRH2qp9vuyF/T1lIxtu1db0RYmlB4dtPJR9vIl7W J5GQ== 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 ck24si12207068ejb.400.2019.10.23.02.05.53; Wed, 23 Oct 2019 02:06:17 -0700 (PDT) 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 S2390850AbfJWJEV (ORCPT + 99 others); Wed, 23 Oct 2019 05:04:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:52210 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390380AbfJWJEV (ORCPT ); Wed, 23 Oct 2019 05:04:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4FDFFB365; Wed, 23 Oct 2019 09:04:18 +0000 (UTC) Date: Wed, 23 Oct 2019 11:04:04 +0200 (CEST) From: Miroslav Benes To: Josh Poimboeuf cc: Jessica Yu , Peter Zijlstra , Steven Rostedt , Joe Lawrence , x86@kernel.org, linux-kernel@vger.kernel.org, mhiramat@kernel.org, bristot@redhat.com, jbaron@akamai.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, namit@vmware.com, hpa@zytor.com, luto@kernel.org, ard.biesheuvel@linaro.org, live-patching@vger.kernel.org, pmladek@suse.com Subject: Re: [PATCH v3 5/6] x86/ftrace: Use text_poke() In-Reply-To: <20191022143107.xkymboxgcgojc5b5@treble> Message-ID: References: <88bab814-ea24-ece9-2bc0-7a1e10a62f12@redhat.com> <20191015153120.GA21580@linux-8ccs> <7e9c7dd1-809e-f130-26a3-3d3328477437@redhat.com> <20191015182705.1aeec284@gandalf.local.home> <20191016074951.GM2328@hirez.programming.kicks-ass.net> <20191018130342.GA4625@linux-8ccs> <20191022143107.xkymboxgcgojc5b5@treble> 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 Tue, 22 Oct 2019, Josh Poimboeuf wrote: > On Tue, Oct 22, 2019 at 10:27:49AM +0200, Miroslav Benes wrote: > > > Does that sound like what you had in mind or am I totally off? > > > > Sort of. What I had in mind was that we could get rid of all special .klp > > ELF section if module loader guarantees that only sections for loaded > > modules are processed. Then .klp.rela.$objname is not needed and proper > > .rela.text.$objname (or whatever its text section is named) should be > > sufficient. The same for the rest (.klp.arch). > > If I understand correctly, using kvm as an example to-be-patched module, > we'd have: > > .text.kvm > .rela.text.kvm > .altinstructions.kvm > .rela.altinstructions.kvm > __jump_table.kvm > .rela__jump_table.kvm > > etc. i.e. any "special" sections would need to be renamed. > > Is that right? Yes. > But also I think *any* sections which need relocations would need to be > renamed, for example: > > .rodata.kvm > .rela.rodata.kvm > .orc_unwind_ip.kvm > .rela.orc_unwind_ip.kvm Correct. > It's an interesting idea. > > We'd have to be careful about ordering issues. For example, there are > module-specific jump labels stored in mod->jump_entries. Right now > that's just a pointer to the module's __jump_table section. With late > module patching, when kvm is loaded we'd have to insert the klp module's > __jump_table.kvm entries into kvm's mod->jump_entries list somehow. Yes. > Presumably we'd also have that issue for other sections. Handling that > _might_ be as simple as just hacking up find_module_sections() to > re-allocate sections and append "patched sections" to them. > > But then you still have to worry about when to apply the relocations. > If you apply them before patching the sections, then relative > relocations would have the wrong values. If you apply them after, then > you have to figure out where the appended relocations are. Ah, right. That is a valid remark. > And if we allow unpatching then we'd presumably have to be able to > remove entries from the module specific section lists. Correct. > So I get the feeling a lot of complexity would creep in. Even just > thinking about it requires more mental gymnastics than the > one-patch-per-module idea, so I view that as a bad sign. Yes, the devil is in the details. It would be better if the approach helped even someone/something else in the kernel. Without it, it is probably better to stick to Steven's proposal and handle the complexity elsewhere. Thanks Miroslav