From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754078AbbKLJQR (ORCPT ); Thu, 12 Nov 2015 04:16:17 -0500 Received: from mx2.suse.de ([195.135.220.15]:40032 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753700AbbKLJQM (ORCPT ); Thu, 12 Nov 2015 04:16:12 -0500 Date: Thu, 12 Nov 2015 10:16:10 +0100 From: Petr Mladek To: Jessica Yu Cc: Rusty Russell , Josh Poimboeuf , Seth Jennings , Jiri Kosina , Vojtech Pavlik , Miroslav Benes , linux-api@vger.kernel.org, live-patching@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: livepatch: reuse module loader code to write relocations Message-ID: <20151112091610.GJ4431@pathway.suse.cz> References: <1447130755-17383-1-git-send-email-jeyu@redhat.com> <1447130755-17383-4-git-send-email-jeyu@redhat.com> <20151111152256.GP2599@pathway.suse.cz> <20151111182718.GA30025@packer-debian-8-amd64.digitalocean.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151111182718.GA30025@packer-debian-8-amd64.digitalocean.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2015-11-11 13:27:18, Jessica Yu wrote: > Basically, the patch module code is expected to build the reloc_secs > list for each object that is being patched. For example in kpatch, the > patch module generates this list in patch_init(). Like you guessed, it > does go through all the elf sections of the patch module to find the > reloc sections marked SHF_RELA_LIVEPATCH. We are able to access these > sections through module->info, which is set up for livepatch modules > before the module loader calls do_init_module() (and hence before > patch_init(), See patch 2/5). > See below for an example of how the reloc_secs list might be built: https://github.com/flaming-toast/kpatch/blob/no_dynrela_redux/kmod/patch/livepatch-patch-hook.c#L213 Thanks a lot for the link and explanation. I think that it would be nice to incorporate this into the patchset. I would put it into a separate function, e.g. klp_reloc_secs_init(). It can be called either from klp_register_patch() or from klp_init_patch(). > Once the patch module has built this list, it is good to go for use in > livepatch core. All livepatch has to do then is to iterate though the > list, resolve any outstanding symbols, and call apply_relocate_add(), > as shown in this patch. > > Miroslav mentioned in another email that we should start thinking > about including documentation about this, including the expected patch > module format. So perhaps v2 should include some documentation about > this whole process somewhere. That would be cool. Thank you, Petr From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Mladek Subject: Re: livepatch: reuse module loader code to write relocations Date: Thu, 12 Nov 2015 10:16:10 +0100 Message-ID: <20151112091610.GJ4431@pathway.suse.cz> References: <1447130755-17383-1-git-send-email-jeyu@redhat.com> <1447130755-17383-4-git-send-email-jeyu@redhat.com> <20151111152256.GP2599@pathway.suse.cz> <20151111182718.GA30025@packer-debian-8-amd64.digitalocean.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20151111182718.GA30025-N0bYjD2NfQ6k4hzjq3hgyGTy53QMssKEsp+A89P3RPuQWHG76I6BsA@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Jessica Yu Cc: Rusty Russell , Josh Poimboeuf , Seth Jennings , Jiri Kosina , Vojtech Pavlik , Miroslav Benes , linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, live-patching-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-api@vger.kernel.org On Wed 2015-11-11 13:27:18, Jessica Yu wrote: > Basically, the patch module code is expected to build the reloc_secs > list for each object that is being patched. For example in kpatch, the > patch module generates this list in patch_init(). Like you guessed, it > does go through all the elf sections of the patch module to find the > reloc sections marked SHF_RELA_LIVEPATCH. We are able to access these > sections through module->info, which is set up for livepatch modules > before the module loader calls do_init_module() (and hence before > patch_init(), See patch 2/5). > See below for an example of how the reloc_secs list might be built: https://github.com/flaming-toast/kpatch/blob/no_dynrela_redux/kmod/patch/livepatch-patch-hook.c#L213 Thanks a lot for the link and explanation. I think that it would be nice to incorporate this into the patchset. I would put it into a separate function, e.g. klp_reloc_secs_init(). It can be called either from klp_register_patch() or from klp_init_patch(). > Once the patch module has built this list, it is good to go for use in > livepatch core. All livepatch has to do then is to iterate though the > list, resolve any outstanding symbols, and call apply_relocate_add(), > as shown in this patch. > > Miroslav mentioned in another email that we should start thinking > about including documentation about this, including the expected patch > module format. So perhaps v2 should include some documentation about > this whole process somewhere. That would be cool. Thank you, Petr