Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 09 Jul 2001 08:19:49 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        "Eugene L. Vorokov" <vel@bugz.infotecs.ru>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: kernel panic when trying to use init's address space
Message-ID:  <3B49CB95.F1861408@mindspring.com>
References:  <200107051251.f65CpMp03726@bugz.infotecs.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
"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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B49CB95.F1861408>