Subject: Re: CVS commit: src/sys/uvm
To: enami tsugutomo <enami@sm.sony.co.jp>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: source-changes
Date: 03/04/2003 17:51:24
--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Mar 04, 2003 at 04:43:37PM +0900, enami tsugutomo wrote:

 > I'm afraid null pointer is dereferenced when accessing something like
 > uobj->pgops->pgo_put (we test if pgo_put is null or not, but doesn't
 > test if pgops is null).

Ok, *this* is the patch I'll check in.  It adds a very minimal pager
for the uvm_loanzero_object.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=uvm-patch

Index: uvm_loan.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_loan.c,v
retrieving revision 1.40
diff -c -r1.40 uvm_loan.c
*** uvm_loan.c	2003/03/04 06:18:54	1.40
--- uvm_loan.c	2003/03/05 01:49:40
***************
*** 842,847 ****
--- 842,899 ----
  }
  
  /*
+  * Minimal pager for uvm_loanzero_object.  We need to provide a "put"
+  * method, because the page can end up on a paging queue, and the
+  * page daemon will want to call pgo_put when it encounters the page
+  * on the inactive list.
+  */
+ 
+ static int
+ ulz_put(struct uvm_object *uobj, voff_t start, voff_t stop, int flags)
+ {
+ 	struct vm_page *pg;
+ 
+ 	KDASSERT(uobj == &uvm_loanzero_object);
+ 
+ 	/*
+ 	 * Don't need to do any work here if we're not freeing pages.
+ 	 */
+ 
+ 	if ((flags & PGO_FREE) == 0) {
+ 		simple_unlock(&uobj->vmobjlock);
+ 		return 0;
+ 	}
+ 
+ 	/*
+ 	 * we don't actually want to ever free the uvm_loanzero_page, so
+ 	 * just reactivate or dequeue it.
+ 	 */
+ 
+ 	pg = TAILQ_FIRST(&uobj->memq);
+ 	KASSERT(pg != NULL);
+ 	KASSERT(TAILQ_NEXT(pg, listq) == NULL);
+ 
+ 	uvm_lock_pageq();
+ 	if (pg->uanon)
+ 		uvm_pageactivate(pg);
+ 	else
+ 		uvm_pagedequeue(pg);
+ 	uvm_unlock_pageq();
+ 
+ 	simple_unlock(&uobj->vmobjlock);
+ 	return 0;
+ }
+ 
+ static struct uvm_pagerops ulz_pager = {
+ 	NULL,		/* init */
+ 	NULL,		/* reference */
+ 	NULL,		/* detach */
+ 	NULL,		/* fault */
+ 	NULL,		/* get */
+ 	ulz_put,	/* put */
+ };
+ 
+ /*
   * uvm_loan_init(): initialize the uvm_loan() facility.
   */
  
***************
*** 851,854 ****
--- 903,907 ----
  
  	simple_lock_init(&uvm_loanzero_object.vmobjlock);
  	TAILQ_INIT(&uvm_loanzero_object.memq);
+ 	uvm_loanzero_object.pgops = &ulz_pager;
  }

--Q68bSM7Ycu6FN28Q--