Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Mar 2018 13:19:27 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331842 - in stable/11/sys: kern sys vm
Message-ID:  <201803311319.w2VDJRGl067747@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Mar 31 13:19:27 2018
New Revision: 331842
URL: https://svnweb.freebsd.org/changeset/base/331842

Log:
  MFC r331490:
  Account the size of the vslock-ed memory by the thread.

Modified:
  stable/11/sys/kern/kern_fork.c
  stable/11/sys/kern/kern_kthread.c
  stable/11/sys/kern/kern_thr.c
  stable/11/sys/kern/subr_trap.c
  stable/11/sys/sys/proc.h
  stable/11/sys/vm/vm_glue.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/kern_fork.c
==============================================================================
--- stable/11/sys/kern/kern_fork.c	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/kern/kern_fork.c	Sat Mar 31 13:19:27 2018	(r331842)
@@ -483,6 +483,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct
 	bzero(&td2->td_startzero,
 	    __rangeof(struct thread, td_startzero, td_endzero));
 	td2->td_sleeptimo = 0;
+	td2->td_vslock_sz = 0;
 	bzero(&td2->td_si, sizeof(td2->td_si));
 
 	bcopy(&td->td_startcopy, &td2->td_startcopy,

Modified: stable/11/sys/kern/kern_kthread.c
==============================================================================
--- stable/11/sys/kern/kern_kthread.c	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/kern/kern_kthread.c	Sat Mar 31 13:19:27 2018	(r331842)
@@ -274,6 +274,7 @@ kthread_add(void (*func)(void *), void *arg, struct pr
 	bzero(&newtd->td_startzero,
 	    __rangeof(struct thread, td_startzero, td_endzero));
 	newtd->td_sleeptimo = 0;
+	newtd->td_vslock_sz = 0;
 	bzero(&newtd->td_si, sizeof(newtd->td_si));
 	bcopy(&oldtd->td_startcopy, &newtd->td_startcopy,
 	    __rangeof(struct thread, td_startcopy, td_endcopy));

Modified: stable/11/sys/kern/kern_thr.c
==============================================================================
--- stable/11/sys/kern/kern_thr.c	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/kern/kern_thr.c	Sat Mar 31 13:19:27 2018	(r331842)
@@ -233,6 +233,7 @@ thread_create(struct thread *td, struct rtprio *rtp,
 	bzero(&newtd->td_startzero,
 	    __rangeof(struct thread, td_startzero, td_endzero));
 	newtd->td_sleeptimo = 0;
+	newtd->td_vslock_sz = 0;
 	bzero(&newtd->td_si, sizeof(newtd->td_si));
 	bcopy(&td->td_startcopy, &newtd->td_startcopy,
 	    __rangeof(struct thread, td_startcopy, td_endcopy));

Modified: stable/11/sys/kern/subr_trap.c
==============================================================================
--- stable/11/sys/kern/subr_trap.c	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/kern/subr_trap.c	Sat Mar 31 13:19:27 2018	(r331842)
@@ -176,6 +176,8 @@ userret(struct thread *td, struct trapframe *frame)
 	    ("userret: Returning with stop signals deferred"));
 	KASSERT(td->td_su == NULL,
 	    ("userret: Returning with SU cleanup request not handled"));
+	KASSERT(td->td_vslock_sz == 0,
+	    ("userret: Returning with vslock-wired space"));
 #ifdef VIMAGE
 	/* Unfortunately td_vnet_lpush needs VNET_DEBUG. */
 	VNET_ASSERT(curvnet == NULL,

Modified: stable/11/sys/sys/proc.h
==============================================================================
--- stable/11/sys/sys/proc.h	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/sys/proc.h	Sat Mar 31 13:19:27 2018	(r331842)
@@ -350,6 +350,7 @@ struct thread {
 					   fork for child tracing. */
 	siginfo_t	td_si;		/* (c) For debugger or core file */
 	void		*td_lkpi_task;	/* LinuxKPI task struct pointer */
+	size_t		td_vslock_sz;	/* (k) amount of vslock-ed space */
 };
 
 struct thread0_storage {

Modified: stable/11/sys/vm/vm_glue.c
==============================================================================
--- stable/11/sys/vm/vm_glue.c	Sat Mar 31 12:45:39 2018	(r331841)
+++ stable/11/sys/vm/vm_glue.c	Sat Mar 31 13:19:27 2018	(r331842)
@@ -198,11 +198,16 @@ vslock(void *addr, size_t len)
 #endif
 	error = vm_map_wire(&curproc->p_vmspace->vm_map, start, end,
 	    VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
+	if (error == KERN_SUCCESS) {
+		curthread->td_vslock_sz += len;
+		return (0);
+	}
+
 	/*
 	 * Return EFAULT on error to match copy{in,out}() behaviour
 	 * rather than returning ENOMEM like mlock() would.
 	 */
-	return (error == KERN_SUCCESS ? 0 : EFAULT);
+	return (EFAULT);
 }
 
 void
@@ -210,6 +215,8 @@ vsunlock(void *addr, size_t len)
 {
 
 	/* Rely on the parameter sanity checks performed by vslock(). */
+	MPASS(curthread->td_vslock_sz >= len);
+	curthread->td_vslock_sz -= len;
 	(void)vm_map_unwire(&curproc->p_vmspace->vm_map,
 	    trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len),
 	    VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);



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