From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 27 09:20:55 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5D33E106566B for ; Thu, 27 Oct 2011 09:20:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id CABA88FC1B for ; Thu, 27 Oct 2011 09:20:54 +0000 (UTC) Received: from alf.home (alf.kiev.zoral.com.ua [10.1.1.177]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p9R9KmoJ017723 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 27 Oct 2011 12:20:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from alf.home (kostik@localhost [127.0.0.1]) by alf.home (8.14.5/8.14.5) with ESMTP id p9R9KmUT001923; Thu, 27 Oct 2011 12:20:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by alf.home (8.14.5/8.14.5/Submit) id p9R9KmVM001922; Thu, 27 Oct 2011 12:20:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: alf.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 27 Oct 2011 12:20:48 +0300 From: Kostik Belousov To: Daniel Grech Message-ID: <20111027092048.GK50300@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="te1vED83xZIPpfwV" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org Subject: Re: Kernel Space Memory Allocation X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 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 Oct 2011 09:20:55 -0000 --te1vED83xZIPpfwV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 27, 2011 at 10:31:43AM +0200, Daniel Grech wrote: > Hi, >=20 > I am allocating memory from a device driver in the kernel and passing it = on > to another driver. In the other driver it is neccessary for me to determi= ne > whether the address passed is from user space or kernel space as this dri= ver > can also be called from user space. I am currently using the following ch= eck > to determine if the address is in kernel space or userspace : >=20 > if ( ( (char *) VM_MIN_KERNEL_ADDRESS <=3D address) && (address <=3D (ch= ar *) > VM_MAX_KERNEL_ADDRESS) ) > { > KERNEL SPACE > } > else > { > USER SPACE > } >=20 > However, this does not always work. Sometimes although I allocate memory = in > the kernel using the malloc macro, this returns an address which is not in > the above range. Is there any workaround for this problem? >=20 > Thanks in advance for your help. Generally, you cannot determine the ownership of the address by its value. There are architectures that use separate kernel/user address spaces, e.g. Even for i386, there were a patch that switched page tables on the kernel entry, allowing the kernel to use whole 4GB of the address space. The proper way to do what you want is to supply explicit indicator of the address space referenced by the address. Read uio(9), in particular, look at the uio_seg. --te1vED83xZIPpfwV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk6pInAACgkQC3+MBN1Mb4jVpACg0yW/xfdT/fqc4rIZ6ESf5W32 4jkAoKwHoqoJdUuAJdXJS0XXN/Uu+e+g =FcZZ -----END PGP SIGNATURE----- --te1vED83xZIPpfwV--