From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 14 13:56:13 2006 Return-Path: X-Original-To: hackers@freebsd.org 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 C86E116A479; Wed, 14 Jun 2006 13:56:13 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from fw.zoral.com.ua (ll-227.216.82.212.sovam.net.ua [212.82.216.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id BA13043D49; Wed, 14 Jun 2006 13:56:12 +0000 (GMT) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by fw.zoral.com.ua (8.13.4/8.13.4) with ESMTP id k5EDu1wZ041023 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jun 2006 16:56:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6) with ESMTP id k5EDu17s085389; Wed, 14 Jun 2006 16:56:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6/Submit) id k5EDu0Ne085388; Wed, 14 Jun 2006 16:56:00 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 14 Jun 2006 16:56:00 +0300 From: Konstantin Belousov To: Bruno Haible Message-ID: <20060614135600.GB86300@deviant.kiev.zoral.com.ua> References: <200606101822.46437.bruno@clisp.org> <20060614103420.GA86300@deviant.kiev.zoral.com.ua> <200606141404.08811.bruno@clisp.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="neYutvxvOLaeuPCA" Content-Disposition: inline In-Reply-To: <200606141404.08811.bruno@clisp.org> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: ClamAV version 0.88.2, clamav-milter version 0.88.2 on fw.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-0.1 required=5.0 tests=ALL_TRUSTED,SPF_NEUTRAL autolearn=failed version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on fw.zoral.com.ua Cc: Vasil Dimov , hackers@freebsd.org Subject: Re: valid VMA ranges and mincore() 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: Wed, 14 Jun 2006 13:56:14 -0000 --neYutvxvOLaeuPCA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 14, 2006 at 02:04:08PM +0200, Bruno Haible wrote: > Hello Konstantin, >=20 > Thanks for reacting on this issue. >=20 > > Please, evaluate the patch. If it does what you need >=20 > - It doesn't change the manual page mincore.2. Yes, it was intended. Exactly because I anticipated issues you described below. > - For unmapped areas, it appears to be filling in values of -1 into > the array. This is not what Linux, Solaris, NetBSD do: They return > -1 from the system call and set errno to ENOMEM. See > Linux: http://linux.about.com/library/cmd/blcmdl2_mincore.htm > Solaris: http://docs.sun.com/app/docs/doc/816-5167/6mbb2jaib?a=3Dview > NetBSD: http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/sys/mincore.= 2?rev=3D1.19&content-type=3Dtext/plain > - Filling in values of -1 into the array will confuse existing applicatio= ns, > because -1 is all bits set, i.e. the nonexistent pages will appear to > be in-core, modified, referenced. Ok. See below. I hope that I fixed my problems with comprehension. > - Filling in values of -1 into the array could be done more easily by > changing the statements in sys/vm/vm_mmap.c lines 861 and 902. I do not agree. It zeroes array not only for holes, but also for (some) skipped vm areas. For instance, it happens for freshly allocated anonymous memory that has not faulted any pages still. Index: vm_mmap.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/local/arch/ncvs/src/sys/vm/vm_mmap.c,v retrieving revision 1.205 diff -u -r1.205 vm_mmap.c --- vm_mmap.c 21 Apr 2006 07:17:25 -0000 1.205 +++ vm_mmap.c 14 Jun 2006 13:51:20 -0000 @@ -756,8 +756,10 @@ first_addr =3D addr =3D trunc_page((vm_offset_t) uap->addr); end =3D addr + (vm_size_t)round_page(uap->len); map =3D &td->td_proc->p_vmspace->vm_map; - if (end > vm_map_max(map) || end < addr) + if (end < addr) return (EINVAL); + if (end > vm_map_max(map)) + return (ENOMEM); =20 /* * Address of byte vector @@ -770,8 +772,18 @@ RestartScan: timestamp =3D map->timestamp; =20 - if (!vm_map_lookup_entry(map, addr, &entry)) - entry =3D entry->next; + if (!vm_map_lookup_entry(map, first_addr, &entry)) { + vm_map_unlock_read(map); + return (ENOMEM); + } + for (current =3D entry; + (current !=3D &map->header) && (current->end < end); + current =3D current->next) { + if (current->end !=3D current->next->start) { + vm_map_unlock_read(map); + return (ENOMEM); + } + } =20 /* * Do this on a map entry basis so that if the pages are not --neYutvxvOLaeuPCA Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (FreeBSD) iD8DBQFEkBVrC3+MBN1Mb4gRAmZFAJ9l+IK963pIg2T4UOH/5HDGt3rKfACg4EBB CEwdj3EuDfmaSv5cCMpH6GA= =bnEY -----END PGP SIGNATURE----- --neYutvxvOLaeuPCA--