Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 May 2001 09:50:08 +0200
From:      Poul-Henning Kamp <phk@critter.freebsd.dk>
To:        Dima Dorfman <dima@unixfreak.org>
Cc:        Alfred Perlstein <alfred@FreeBSD.ORG>, current@FreeBSD.ORG
Subject:   Re: vm_pager_(de)allocate and vm_mtx 
Message-ID:  <97925.990863408@critter>
In-Reply-To: Your message of "Fri, 25 May 2001 22:51:11 PDT." <20010526055111.7B5803E28@bazooka.unixfreak.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20010526055111.7B5803E28@bazooka.unixfreak.org>, Dima Dorfman write
s:
>Alfred Perlstein <alfred@FreeBSD.ORG> writes:
>> * Dima Dorfman <dima@unixfreak.org> [010525 22:22] wrote:
>> > Is there a reason vm_pager_allocate acquires vm_mtx itself if
>> > necessary but vm_pager_deallocate does not?  At the moment, detaching
>> > an md(4) disk will panic the system with a failed mtx_assert in
>> > vm_pager_deallocate.  This can be fixed one of two ways:
>> > vm_pager_deallocate could be made to deal with vm_mtx itself like
>> > vm_pager_allocate does, or md(4) and any other drivers which call
>> > vm_pager_deallocate can be fixed to acquire vm_mtx.  So which will it
>> > be?  I'll supply patches for either case.
>> 
>> Usually fixing the caller is better as it will catch people that
>> expect vm state to remain unchanged across several calls.
>
>Patch to fix md(4) attached.  Look okay?

Looks fine, go ahead and commit.

Poul-Henning

>
>					Dima Dorfman
>					dima@unixfreak.org
>
>Index: md.c
>===================================================================
>RCS file: /stl/src/FreeBSD/src/sys/dev/md/md.c,v
>retrieving revision 1.33
>diff -u -r1.33 md.c
>--- md.c	2001/05/21 18:52:00	1.33
>+++ md.c	2001/05/26 05:48:57
>@@ -711,8 +711,11 @@
> 		(void)vn_close(sc->vnode, sc->flags & MD_READONLY ?  FREAD : (FREAD|FWRITE), sc->cred, p);
> 	if (sc->cred != NULL)
> 		crfree(sc->cred);
>-	if (sc->object != NULL)
>+	if (sc->object != NULL) {
>+		mtx_lock(&vm_mtx);
> 		vm_pager_deallocate(sc->object);
>+		mtx_unlock(&vm_mtx);
>+	}
> 	if (sc->secp != NULL) {
> 		for (u = 0; u < sc->nsect; u++) 
> 			if ((uintptr_t)sc->secp[u] > 255)
>@@ -763,17 +766,20 @@
> 	 * Note the truncation.
> 	 */
> 
>+	mtx_lock(&vm_mtx);
> 	sc->secsize = PAGE_SIZE;
> 	sc->nsect = mdio->md_size / (PAGE_SIZE / DEV_BSIZE);
> 	sc->object = vm_pager_allocate(OBJT_SWAP, NULL, sc->secsize * (vm_offset_t)sc->nsect, VM_PROT_DEFAULT, 0);
> 	if (mdio->md_options & MD_RESERVE) {
> 		if (swap_pager_reserve(sc->object, 0, sc->nsect) < 0) {
> 			vm_pager_deallocate(sc->object);
>+			mtx_unlock(&vm_mtx);
> 			sc->object = NULL;
> 			mddestroy(sc, mdio, p);
> 			return(EDOM);
> 		}
> 	}
>+	mtx_unlock(&vm_mtx);
> 	error = mdsetcred(sc, p->p_ucred);
> 	if (error)
> 		mddestroy(sc, mdio, p);
>
>To Unsubscribe: send mail to majordomo@FreeBSD.org
>with "unsubscribe freebsd-current" in the body of the message
>

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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