Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jul 1997 19:57:42 -0700
From:      David Greenman <dg@root.com>
To:        Vinay Bannai <vinay@agni.nuko.com>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Location of copyin() and copyout().. 
Message-ID:  <199707300257.TAA12085@implode.root.com>
In-Reply-To: Your message of "Tue, 29 Jul 1997 19:27:30 PDT." <199707300227.TAA05696@agni.nuko.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
>So in a situation where I pin the user pages down (for DMA), it is okay to
>use copyin()/copyout().

   copyin/copyout can only be used at non-interrupt time while running in the
context of the process to which you're copying to/from. Otherwise, you have
to temporarily map the pages into the kernel address space, after which you
can access them directly (i.e. not use copyin/copyout). Does this make sense?
   The main purpose of copyin/copyout is to provide a machine-independant
mechanism for copying data through the kernel<->user protection domain. In
the case of the x86, it just happens that user process memory is accessible
to the kernel in the lower part of the address space, with one caveat: the
i386 processor doesn't honor kernel (CPL 0/supervisor) write protection on
pages and thus breaks COW when running in the kernel. So for the i386, copyout,
if necessary, simulates a write fault to the affected pages.
   A secondary purpose of copyin/copyout is to catch page protection
violations. There is a mechanism for catching a fatal page fault trap during
a copyin/copyout so that the kernel can recover from such an event gracefully
rather than crashing. When this happens, copyin/copyout return EFAULT to
the caller.

-DG

David Greenman
Core-team/Principal Architect, The FreeBSD Project



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