From owner-freebsd-hackers Mon Jul 9 8:19:29 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from hawk.mail.pas.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by hub.freebsd.org (Postfix) with ESMTP id 84FFD37B405 for ; Mon, 9 Jul 2001 08:19:25 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from mindspring.com (dialup-209.244.104.114.Dial1.SanJose1.Level3.net [209.244.104.114]) by hawk.mail.pas.earthlink.net (EL-8_9_3_3/8.9.3) with ESMTP id IAA25104; Mon, 9 Jul 2001 08:19:13 -0700 (PDT) Message-ID: <3B49CB95.F1861408@mindspring.com> Date: Mon, 09 Jul 2001 08:19:49 -0700 From: Terry Lambert Reply-To: tlambert2@mindspring.com X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: "Eugene L. Vorokov" Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: kernel panic when trying to use init's address space References: <200107051251.f65CpMp03726@bugz.infotecs.ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG "Eugene L. Vorokov" wrote: > > Hello, > > Some time ago I was asking about I/O in kernel mode when I don't have > struct proc to use syscalls. Actually I just wanted my kld to read it's > config file on load. Terry told me it's tricky, and I was thinking > about possible workarounds. I decided to try the following: look for > some process, get it's struct proc, allocate memory in it's address > space using mmap() syscall and then use open() and read() syscalls, > passing that struct proc to them. I first decided to look for init > process for this, since it always exists. So it looked like that: Clever hack. > *buf = 0; > > However at this point kernel panics with page fault. I really don't > understand why could it be ... Mapping doesn't necessarily make your pages resident. If you touch a non-resident page, you will fault, and taking a fault in kernel mode will cause a panic. > Of course, I've found another workaround. I recalled that kldload > program is still active when my module loads, so I started looking > for it instead of init. It works just fine, I'm able to allocate > memory, use it and finally read my config file. But I'm curious, > why doesn't it work with init ? What's so special in init from this > point of view ? Because the process is running you, it's resident, and thus the mmap() is able to occur immediately, instead of waiting for the next time it runs. The init program is generally idle, when it's not respawning processes or reaping children, so it's going to be non-resident most of the time. Another way of dealing with this would be to create a kproc. Probably, you will still end up panic'ing in certain circumstances of heavy memory load, which would prevent the mmap() from getting the pages in core; as things stand now, you happen to be winning a race, but it is still a race. You should look at the quota code in FFS; it has to read and write quota structures in a file from the kernel. You could also look at the exec code, which reads the first part of a file from the kernel, in order to decide what to exec. If you go the quota route, be sure to use the generic VOP version of the functions, so you aren't tied too strongly to FFS. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message