From owner-freebsd-hackers@FreeBSD.ORG Thu Jan 27 16:09:04 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EA43816A4CE for ; Thu, 27 Jan 2005 16:09:04 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id 93B9143D2D for ; Thu, 27 Jan 2005 16:09:04 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.1/8.13.1) with ESMTP id j0RG9FUM072500; Thu, 27 Jan 2005 11:09:15 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.1/8.13.1/Submit) id j0RG9E4P072499; Thu, 27 Jan 2005 11:09:14 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Thu, 27 Jan 2005 11:09:14 -0500 From: David Schultz To: Jacques Fourie Message-ID: <20050127160914.GA72454@VARK.MIT.EDU> Mail-Followup-To: Jacques Fourie , freebsd-hackers@FreeBSD.ORG References: <41F90140.3020705@trispen.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41F90140.3020705@trispen.com> cc: freebsd-hackers@FreeBSD.ORG Subject: Re: kernel vm question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2005 16:09:05 -0000 On Thu, Jan 27, 2005, Jacques Fourie wrote: > Hi, > > I have a kernel module with the following entry point : > > static int test_modevent(module_t mod, int type, void *unused) > { > int s; > unsigned char *p = NULL; > unsigned char v = 0x55; > > switch (type) > { > case MOD_LOAD: > p = (unsigned char *)ip_output; > > s = splhigh(); > > v = p[0]; /* Page fault without this line */ > p[0] = v; [...] > If I remove the line "Page fault without this line" line, I get a page > fault when loading this module. This crash seems to be hardware as well > as version specific - I can not reproduce the crash on 4.8 but on one > particular piece of hardware it crashes consistently on 4.9 and 4.10. When the line is there, the compiler is probably smart enough to realize that 'x=y; y=x' is (usually) a no-op, so it optimizes away both statements. Otherwise, you get a page fault because you're trying to write to a non-writable page (namely, one in the kernel's code segment). If you're trying to do what I think you're trying to do, you need to poke around in the VM system and adjust the protection bits in the page you want to write to.