Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751731AbbKJB5w (ORCPT ); Mon, 9 Nov 2015 20:57:52 -0500 Received: from ozlabs.org ([103.22.144.67]:56090 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751476AbbKJB5v (ORCPT ); Mon, 9 Nov 2015 20:57:51 -0500 From: Rusty Russell To: Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Peter Zijlstra Subject: Re: [PATCH 4/4] module: clean up RO/NX handling. In-Reply-To: <20151109195153.GB3914@treble.redhat.com> References: <1447043037-10833-1-git-send-email-rusty@rustcorp.com.au> <1447043037-10833-5-git-send-email-rusty@rustcorp.com.au> <20151109195153.GB3914@treble.redhat.com> User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Tue, 10 Nov 2015 12:27:34 +1030 Message-ID: <87611ak44x.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1864 Lines: 46 Josh Poimboeuf writes: > On Mon, Nov 09, 2015 at 02:53:57PM +1030, Rusty Russell wrote: > >> @@ -1858,74 +1849,75 @@ static void mod_sysfs_teardown(struct module *mod) >> /* >> * LKM RO/NX protection: protect module's text/ro-data >> * from modification and any data from execution. >> + * >> + * General layout of module is: >> + * [text] [read-only-data] [writable data] >> + * text_size -----^ ^ ^ >> + * ro_size ------------------------| | >> + * size -------------------------------------------| >> + * >> + * These values are always page-aligned (as is base) >> */ >> -void set_page_attributes(void *start, void *end, int (*set)(unsigned long start, int num_pages)) >> +static void frob_text(const struct module_layout *layout, >> + int (*set_memory)(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); >> + BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1)); >> + BUG_ON((unsigned long)layout->text_size & (PAGE_SIZE-1)); >> + set_memory((unsigned long)layout->base, >> + layout->text_size >> PAGE_SHIFT); > > Should the set_memory() call be skipped if text_size is 0? Not AFAICT. And in practice: 1) Every module on my system has a .text section. 2) Every module has a rodata section (.modinfo) 3) Every module on my system has a .data section. So I think it would be a premature optimization. Thanks, Rusty. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/