From 910cc6927bf9a326cda4f0f3eeb37bde0c1ccbc4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 2 May 2004 07:57:45 +0000 Subject: [PATCH] We must pmap_qremove() pages that we previously pmap_qenter()'d before we can safely call kmem_free(). This corrects a serious corruption issue that occured when using PIPE algorithms other then the default. The default SFBUF algorithm was not effected by this bug. --- sys/kern/sys_pipe.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 0fe5aff6e5..f6eef6d4d1 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -17,7 +17,7 @@ * are met. * * $FreeBSD: src/sys/kern/sys_pipe.c,v 1.60.2.13 2002/08/05 15:05:15 des Exp $ - * $DragonFly: src/sys/kern/sys_pipe.c,v 1.18 2004/05/01 18:16:43 dillon Exp $ + * $DragonFly: src/sys/kern/sys_pipe.c,v 1.19 2004/05/02 07:57:45 dillon Exp $ */ /* @@ -697,10 +697,10 @@ pipe_clone_write_buffer(wpipe) xio_copy_xtok(&wpipe->pipe_map, wpipe->pipe_buffer.buffer, size); xio_release(&wpipe->pipe_map); if (wpipe->pipe_kva) { + pmap_qremove(wpipe->pipe_kva, XIO_INTERNAL_PAGES); kmem_free(kernel_map, wpipe->pipe_kva, XIO_INTERNAL_SIZE); wpipe->pipe_kva = NULL; } - } /* @@ -770,6 +770,7 @@ retry: pipelock(wpipe, 0); xio_release(&wpipe->pipe_map); if (wpipe->pipe_kva) { + pmap_qremove(wpipe->pipe_kva, XIO_INTERNAL_PAGES); kmem_free(kernel_map, wpipe->pipe_kva, XIO_INTERNAL_SIZE); wpipe->pipe_kva = NULL; } @@ -794,6 +795,17 @@ retry: pipe_clone_write_buffer(wpipe); KKASSERT((wpipe->pipe_state & PIPE_DIRECTIP) == 0); } else { + /* + * note: The pipe_kva mapping is not qremove'd here. For + * legacy PIPE_KMEM mode this constitutes an improvement + * over the original FreeBSD-4 algorithm. For PIPE_SFBUF2 + * mode the kva mapping must not be removed to get the + * caching benefit. + * + * For testing purposes we will give the original algorithm + * the benefit of the doubt 'what it could have been', and + * keep the optimization. + */ KKASSERT(wpipe->pipe_state & PIPE_DIRECTIP); xio_release(&wpipe->pipe_map); wpipe->pipe_state &= ~PIPE_DIRECTIP; @@ -1270,6 +1282,7 @@ pipeclose(struct pipe *cpipe) } if (cpipe->pipe_kva) { + pmap_qremove(cpipe->pipe_kva, XIO_INTERNAL_PAGES); kmem_free(kernel_map, cpipe->pipe_kva, XIO_INTERNAL_SIZE); cpipe->pipe_kva = NULL; } -- 2.41.0