Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Dec 2008 15:01:44 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Cc:        rdivacky@freebsd.org
Subject:   Re: svn commit: r185765 - in head/sys: compat/linprocfs fs/procfs
Message-ID:  <20081208130144.GU2038@deviant.kiev.zoral.com.ua>
In-Reply-To: <200812081234.mB8CYqr0060148@svn.freebsd.org>
References:  <200812081234.mB8CYqr0060148@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--w5nY8nmEklXMR7Cj
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 08, 2008 at 12:34:52PM +0000, Konstantin Belousov wrote:
> Author: kib
> Date: Mon Dec  8 12:34:52 2008
> New Revision: 185765
> URL: http://svn.freebsd.org/changeset/base/185765
>=20
> Log:
>   Change the linprocfs <pid>/maps and procfs <pid>/map handlers to use
>   sbuf instead of doing uiomove. This allows for reads from non-zero
>   offsets to work.
>  =20
>   Patch is forward-ported des@' one, and was adopted to current code
>   by dchagin@ and me.
>  =20
>   Reviewed by:	des (linprocfs part)
>   PR:	kern/101453
>   MFC after:	1 week
>=20
> Modified:
>   head/sys/compat/linprocfs/linprocfs.c
>   head/sys/fs/procfs/procfs_map.c

Thanks for Roman Divacky for pointing this out, commit message is wrong.
I specified wrong log file to the svn ci -F switch.
The right commit message is below.

In procfs map handler, and in linprocfs maps handler, do not call
vn_fullpath() while having vm map locked. This is done in anticipation
of the vop_vptocnp commit, that would make vn_fullpath sometime
acquire vnode lock.

Also, in linprocfs, maps handler already acquires vnode lock.

No objections from:	des
MFC after:	2 week

>=20
> Modified: head/sys/compat/linprocfs/linprocfs.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=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/sys/compat/linprocfs/linprocfs.c	Mon Dec  8 12:29:30 2008	(r1857=
64)
> +++ head/sys/compat/linprocfs/linprocfs.c	Mon Dec  8 12:34:52 2008	(r1857=
65)
> @@ -876,10 +876,12 @@ static int
>  linprocfs_doprocmaps(PFS_FILL_ARGS)
>  {
>  	vm_map_t map =3D &p->p_vmspace->vm_map;
> -	vm_map_entry_t entry;
> +	vm_map_entry_t entry, tmp_entry;
>  	vm_object_t obj, tobj, lobj;
> -	vm_offset_t saved_end;
> +	vm_offset_t e_start, e_end;
>  	vm_ooffset_t off =3D 0;
> +	vm_prot_t e_prot;
> +	unsigned int last_timestamp;
>  	char *name =3D "", *freename =3D NULL;
>  	ino_t ino;
>  	int ref_count, shadow_count, flags;
> @@ -905,7 +907,9 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
>  		freename =3D NULL;
>  		if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
>  			continue;
> -		saved_end =3D entry->end;
> +		e_prot =3D entry->protection;
> +		e_start =3D entry->start;
> +		e_end =3D entry->end;
>  		obj =3D entry->object.vm_object;
>  		for (lobj =3D tobj =3D obj; tobj; tobj =3D tobj->backing_object) {
>  			VM_OBJECT_LOCK(tobj);
> @@ -913,6 +917,8 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
>  				VM_OBJECT_UNLOCK(lobj);
>  			lobj =3D tobj;
>  		}
> +		last_timestamp =3D map->timestamp;
> +		vm_map_unlock_read(map);
>  		ino =3D 0;
>  		if (lobj) {
>  			off =3D IDX_TO_OFF(lobj->size);
> @@ -950,10 +956,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
>  		 */
>  		error =3D sbuf_printf(sb,
>  		    "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n",
> -		    (u_long)entry->start, (u_long)entry->end,
> -		    (entry->protection & VM_PROT_READ)?"r":"-",
> -		    (entry->protection & VM_PROT_WRITE)?"w":"-",
> -		    (entry->protection & VM_PROT_EXECUTE)?"x":"-",
> +		    (u_long)e_start, (u_long)e_end,
> +		    (e_prot & VM_PROT_READ)?"r":"-",
> +		    (e_prot & VM_PROT_WRITE)?"w":"-",
> +		    (e_prot & VM_PROT_EXECUTE)?"x":"-",
>  		    "p",
>  		    (u_long)off,
>  		    0,
> @@ -968,6 +974,16 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
>  			error =3D 0;
>  			break;
>  		}
> +		vm_map_lock_read(map);
> +		if (last_timestamp + 1 !=3D map->timestamp) {
> +			/*
> +			 * Look again for the entry because the map was
> +			 * modified while it was unlocked.  Specifically,
> +			 * the entry may have been clipped, merged, or deleted.
> +			 */
> +			vm_map_lookup_entry(map, e_end - 1, &tmp_entry);
> +			entry =3D tmp_entry;
> +		}
>  	}
>  	vm_map_unlock_read(map);
> =20
>=20
> Modified: head/sys/fs/procfs/procfs_map.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=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/sys/fs/procfs/procfs_map.c	Mon Dec  8 12:29:30 2008	(r185764)
> +++ head/sys/fs/procfs/procfs_map.c	Mon Dec  8 12:34:52 2008	(r185765)
> @@ -84,9 +84,10 @@ procfs_doprocmap(PFS_FILL_ARGS)
>  {
>  	int error, vfslocked;
>  	vm_map_t map =3D &p->p_vmspace->vm_map;
> -	vm_map_entry_t entry;
> +	vm_map_entry_t entry, tmp_entry;
>  	struct vnode *vp;
>  	char *fullpath, *freepath;
> +	unsigned int last_timestamp;
>  #ifdef COMPAT_IA32
>  	int wrap32 =3D 0;
>  #endif
> @@ -113,13 +114,19 @@ procfs_doprocmap(PFS_FILL_ARGS)
>  	     entry =3D entry->next) {
>  		vm_object_t obj, tobj, lobj;
>  		int ref_count, shadow_count, flags;
> -		vm_offset_t addr;
> +		vm_offset_t e_start, e_end, addr;
>  		int resident, privateresident;
>  		char *type;
> +		vm_eflags_t e_eflags;
> +		vm_prot_t e_prot;
> =20
>  		if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
>  			continue;
> =20
> +		e_eflags =3D entry->eflags;
> +		e_prot =3D entry->protection;
> +		e_start =3D entry->start;
> +		e_end =3D entry->end;
>  		privateresident =3D 0;
>  		obj =3D entry->object.vm_object;
>  		if (obj !=3D NULL) {
> @@ -143,11 +150,13 @@ procfs_doprocmap(PFS_FILL_ARGS)
>  				VM_OBJECT_UNLOCK(lobj);
>  			lobj =3D tobj;
>  		}
> +		last_timestamp =3D map->timestamp;
> +		vm_map_unlock_read(map);
> =20
>  		freepath =3D NULL;
>  		fullpath =3D "-";
>  		if (lobj) {
> -			switch(lobj->type) {
> +			switch (lobj->type) {
>  			default:
>  			case OBJT_DEFAULT:
>  				type =3D "default";
> @@ -193,19 +202,19 @@ procfs_doprocmap(PFS_FILL_ARGS)
>  		 */
>  		error =3D sbuf_printf(sb,
>  		    "0x%lx 0x%lx %d %d %p %s%s%s %d %d 0x%x %s %s %s %s\n",
> -			(u_long)entry->start, (u_long)entry->end,
> +			(u_long)e_start, (u_long)e_end,
>  			resident, privateresident,
>  #ifdef COMPAT_IA32
>  			wrap32 ? NULL : obj,	/* Hide 64 bit value */
>  #else
>  			obj,
>  #endif
> -			(entry->protection & VM_PROT_READ)?"r":"-",
> -			(entry->protection & VM_PROT_WRITE)?"w":"-",
> -			(entry->protection & VM_PROT_EXECUTE)?"x":"-",
> +			(e_prot & VM_PROT_READ)?"r":"-",
> +			(e_prot & VM_PROT_WRITE)?"w":"-",
> +			(e_prot & VM_PROT_EXECUTE)?"x":"-",
>  			ref_count, shadow_count, flags,
> -			(entry->eflags & MAP_ENTRY_COW)?"COW":"NCOW",
> -			(entry->eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC",
> +			(e_eflags & MAP_ENTRY_COW)?"COW":"NCOW",
> +			(e_eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC",
>  			type, fullpath);
> =20
>  		if (freepath !=3D NULL)
> @@ -215,6 +224,16 @@ procfs_doprocmap(PFS_FILL_ARGS)
>  			error =3D 0;
>  			break;
>  		}
> +		vm_map_lock_read(map);
> +		if (last_timestamp + 1 !=3D map->timestamp) {
> +			/*
> +			 * Look again for the entry because the map was
> +			 * modified while it was unlocked.  Specifically,
> +			 * the entry may have been clipped, merged, or deleted.
> +			 */
> +			vm_map_lookup_entry(map, e_end - 1, &tmp_entry);
> +			entry =3D tmp_entry;
> +		}
>  	}
>  	vm_map_unlock_read(map);
>  	return (error);

--w5nY8nmEklXMR7Cj
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iEYEARECAAYFAkk9GrcACgkQC3+MBN1Mb4h76gCg9MxYoQcoxC3fIXy1dNnhpm6n
HdAAn2o0XBcNhBDKk5KSjLsTdMMzEQis
=GYHS
-----END PGP SIGNATURE-----

--w5nY8nmEklXMR7Cj--



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