From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031201AbbKDXM6 (ORCPT ); Wed, 4 Nov 2015 18:12:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47974 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030371AbbKDXMz (ORCPT ); Wed, 4 Nov 2015 18:12:55 -0500 Date: Wed, 4 Nov 2015 17:12:52 -0600 From: Josh Poimboeuf To: Jiri Kosina Cc: Miroslav Benes , Seth Jennings , Vojtech Pavlik , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, "Cyril B." Subject: Re: [PATCH] livepatch: Cleanup page permission changes Message-ID: <20151104231252.GA28254@treble.redhat.com> References: <132b018cfe2c6e4cef4d1b62ac3ed70333734111.1446494413.git.jpoimboe@redhat.com> <20151103174228.GN27488@treble.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2015 at 11:56:13PM +0100, Jiri Kosina wrote: > On Tue, 3 Nov 2015, Josh Poimboeuf wrote: > > > Subject: [PATCH] livepatch: Cleanup page permission changes > > > > Calling set_memory_rw() and set_memory_ro() for every iteration of the > > loop in klp_write_object_relocations() is messy and inefficient. Change > > all the RO pages to RW before the loop and convert them back to RO after > > the loop. > > Generally speaking, I like the patch and would like to have this in 4.4 > still (if worse becomes worst and we don't make it in time for merge > window, this still qualifies for -rc bugfix). > > > Suggested-by: Miroslav Benes > > Signed-off-by: Josh Poimboeuf > > --- > > arch/x86/kernel/livepatch.c | 25 ++----------------------- > > kernel/livepatch/core.c | 42 +++++++++++++++++++++++++++++++++++++----- > > 2 files changed, 39 insertions(+), 28 deletions(-) > > > > diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c > > index d1d35cc..1062eff 100644 > > --- a/arch/x86/kernel/livepatch.c > > +++ b/arch/x86/kernel/livepatch.c > > @@ -20,8 +20,6 @@ > > > > #include > > #include > > -#include > > -#include > > #include > > #include > > > > @@ -38,8 +36,7 @@ > > int klp_write_module_reloc(struct module *mod, unsigned long type, > > unsigned long loc, unsigned long value) > > { > > - int ret, numpages, size = 4; > > - bool readonly; > > + int size = 4; > > BTW I don't see a reason to have 'size' signed here. It was already signed to begin with, but I can change it to size_t. > [ ... snip ... [ > > --- a/kernel/livepatch/core.c > > +++ b/kernel/livepatch/core.c > > @@ -28,6 +28,7 @@ > > #include > > #include > > #include > > +#include > > > > /** > > * struct klp_ops - structure for tracking registered ftrace ops structs > > @@ -131,6 +132,33 @@ static bool klp_initialized(void) > > return !!klp_root_kobj; > > } > > > > +#ifdef CONFIG_DEBUG_SET_MODULE_RONX > > +static void set_page_attributes(void *start, void *end, > > + int (*set)(unsigned long start, int num_pages)) > > +{ > > + unsigned long begin_pfn = PFN_DOWN((unsigned long)start); > > + unsigned long end_pfn = PFN_DOWN((unsigned long)end); > > + > > + if (end_pfn > begin_pfn) > > + set(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn); > > +} > > +static void set_module_ro_rw(struct module *mod) > > +{ > > + set_page_attributes(mod->module_core, > > + mod->module_core + mod->core_ro_size, > > + set_memory_rw); > > +} > > +static void set_module_ro_ro(struct module *mod) > > Honestly, I find both the function names above horrible and not really > self-explanatory (especially the _ro_ro variant). At least comment, > explaining what they are actually doing, or picking up a better name, > would make the code much more self-explanatory in my eyes. Being the patch author, naturally the function names make sense to me. set_module_ro_ro() means "set the module's read-only area to have read-only permissions." Do you have any suggestions for a better name? -- Josh