Re: Kill uvm_deallocate()

2019-11-02 Thread Mark Kettenis
> Date: Sat, 2 Nov 2019 10:55:30 +0100
> From: Martin Pieuchot 
> 
> This function is just a wrapper on top of uvm_unmap(), it has its own
> file and is called only 3 times in the kernel.  Getting rid of it makes
> the overall UVM simpler, ok?
> 
> Index: sys/conf/files
> ===
> RCS file: /cvs/src/sys/conf/files,v
> retrieving revision 1.675
> diff -u -p -r1.675 files
> --- sys/conf/files5 Oct 2019 05:33:14 -   1.675
> +++ sys/conf/files2 Nov 2019 09:40:31 -
> @@ -970,7 +970,6 @@ file uvm/uvm_stat.c
>  file uvm/uvm_swap.c
>  file uvm/uvm_swap_encrypt.c  uvm_swap_encrypt
>  file uvm/uvm_unix.c
> -file uvm/uvm_user.c
>  file uvm/uvm_vnode.c
>  
>  # IPv6
> Index: sys/kern/kern_exec.c
> ===
> RCS file: /cvs/src/sys/kern/kern_exec.c,v
> retrieving revision 1.208
> diff -u -p -r1.208 kern_exec.c
> --- sys/kern/kern_exec.c  2 Aug 2019 02:17:35 -   1.208
> +++ sys/kern/kern_exec.c  2 Nov 2019 09:40:31 -
> @@ -749,8 +749,7 @@ exec_abort:
>* get rid of the (new) address space we have created, if any, get rid
>* of our namei data and vnode, and exit noting failure
>*/
> - uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
> - VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
> + uvm_unmap(&vm->vm_map, VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS);
>   if (pack.ep_interp != NULL)
>   pool_put(&namei_pool, pack.ep_interp);
>   if (pack.ep_emul_arg != NULL)
> Index: sys/kern/sysv_shm.c
> ===
> RCS file: /cvs/src/sys/kern/sysv_shm.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 sysv_shm.c
> --- sys/kern/sysv_shm.c   28 Oct 2019 19:57:50 -  1.72
> +++ sys/kern/sysv_shm.c   2 Nov 2019 09:40:31 -
> @@ -160,14 +160,14 @@ shm_delete_mapping(struct vmspace *vm, s
>  {
>   struct shmid_ds *shmseg;
>   int segnum;
> - size_t size;
> + vaddr_t end;
>  
>   segnum = IPCID_TO_IX(shmmap_s->shmid);
>   if (segnum < 0 || segnum >= shminfo.shmmni ||
>   (shmseg = shmsegs[segnum]) == NULL)
>   return (EINVAL);
> - size = round_page(shmseg->shm_segsz);
> - uvm_deallocate(&vm->vm_map, shmmap_s->va, size);
> + end = round_page(shmmap_s->va+shmseg->shm_segsz);

Please add spaces around the '+'.  Otherwise ok kettenis@

> + uvm_unmap(&vm->vm_map, trunc_page(shmmap_s->va), end);
>   shmmap_s->shmid = -1;
>   shmseg->shm_dtime = time_second;
>   if ((--shmseg->shm_nattch <= 0) &&
> Index: sys/uvm/uvm_extern.h
> ===
> RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
> retrieving revision 1.148
> diff -u -p -r1.148 uvm_extern.h
> --- sys/uvm/uvm_extern.h  1 Jul 2019 21:13:03 -   1.148
> +++ sys/uvm/uvm_extern.h  2 Nov 2019 09:40:31 -
> @@ -455,7 +455,6 @@ int   uvm_coredump_walkmap(struct 
> proc *
>   uvm_coredump_setup_cb *_setup,
>   uvm_coredump_walk_cb *_walk, void *_cookie);
>  void uvm_grow(struct proc *, vaddr_t);
> -void uvm_deallocate(vm_map_t, vaddr_t, vsize_t);
>  struct uvm_object*uvn_attach(struct vnode *, vm_prot_t);
>  void uvm_pagezero_thread(void *);
>  void kmeminit_nkmempages(void);
> Index: sys/uvm/uvm_unix.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_unix.c,v
> retrieving revision 1.66
> diff -u -p -r1.66 uvm_unix.c
> --- sys/uvm/uvm_unix.c21 Jun 2019 09:39:49 -  1.66
> +++ sys/uvm/uvm_unix.c2 Nov 2019 09:40:31 -
> @@ -94,7 +94,7 @@ sys_obreak(struct proc *p, void *v, regi
>   }
>   vm->vm_dsize += atop(new - old);
>   } else {
> - uvm_deallocate(&vm->vm_map, new, old - new);
> + uvm_unmap(&vm->vm_map, new, old);
>   vm->vm_dsize -= atop(old - new);
>   }
>  
> Index: sys/uvm/uvm_user.c
> ===
> RCS file: sys/uvm/uvm_user.c
> diff -N sys/uvm/uvm_user.c
> --- sys/uvm/uvm_user.c14 Sep 2014 14:17:27 -  1.14
> +++ /dev/null 1 Jan 1970 00:00:00 -
> @@ -1,55 +0,0 @@
> -/*   $OpenBSD: uvm_user.c,v 1.14 2014/09/14 14:17:27 jsg Exp $   */
> -/*   $NetBSD: uvm_user.c,v 1.8 2000/06/27 17:29:37 mrg Exp $ */
> -
> -/*
> - * Copyright (c) 1997 Charles D. Cranor and Washington University.
> - * All rights reserved.
> - *
> - * Redistribution and use in source and binary forms, with or without
> - * modification, are permitted provided that the following conditions
> - * are met:
> - * 1. Redistributions of source code must retain the above copyright
> - *notice, this list of conditions and the following disclaimer.
> - * 2. 

Kill uvm_deallocate()

2019-11-02 Thread Martin Pieuchot
This function is just a wrapper on top of uvm_unmap(), it has its own
file and is called only 3 times in the kernel.  Getting rid of it makes
the overall UVM simpler, ok?

Index: sys/conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.675
diff -u -p -r1.675 files
--- sys/conf/files  5 Oct 2019 05:33:14 -   1.675
+++ sys/conf/files  2 Nov 2019 09:40:31 -
@@ -970,7 +970,6 @@ file uvm/uvm_stat.c
 file uvm/uvm_swap.c
 file uvm/uvm_swap_encrypt.cuvm_swap_encrypt
 file uvm/uvm_unix.c
-file uvm/uvm_user.c
 file uvm/uvm_vnode.c
 
 # IPv6
Index: sys/kern/kern_exec.c
===
RCS file: /cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.208
diff -u -p -r1.208 kern_exec.c
--- sys/kern/kern_exec.c2 Aug 2019 02:17:35 -   1.208
+++ sys/kern/kern_exec.c2 Nov 2019 09:40:31 -
@@ -749,8 +749,7 @@ exec_abort:
 * get rid of the (new) address space we have created, if any, get rid
 * of our namei data and vnode, and exit noting failure
 */
-   uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
-   VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
+   uvm_unmap(&vm->vm_map, VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS);
if (pack.ep_interp != NULL)
pool_put(&namei_pool, pack.ep_interp);
if (pack.ep_emul_arg != NULL)
Index: sys/kern/sysv_shm.c
===
RCS file: /cvs/src/sys/kern/sysv_shm.c,v
retrieving revision 1.72
diff -u -p -r1.72 sysv_shm.c
--- sys/kern/sysv_shm.c 28 Oct 2019 19:57:50 -  1.72
+++ sys/kern/sysv_shm.c 2 Nov 2019 09:40:31 -
@@ -160,14 +160,14 @@ shm_delete_mapping(struct vmspace *vm, s
 {
struct shmid_ds *shmseg;
int segnum;
-   size_t size;
+   vaddr_t end;
 
segnum = IPCID_TO_IX(shmmap_s->shmid);
if (segnum < 0 || segnum >= shminfo.shmmni ||
(shmseg = shmsegs[segnum]) == NULL)
return (EINVAL);
-   size = round_page(shmseg->shm_segsz);
-   uvm_deallocate(&vm->vm_map, shmmap_s->va, size);
+   end = round_page(shmmap_s->va+shmseg->shm_segsz);
+   uvm_unmap(&vm->vm_map, trunc_page(shmmap_s->va), end);
shmmap_s->shmid = -1;
shmseg->shm_dtime = time_second;
if ((--shmseg->shm_nattch <= 0) &&
Index: sys/uvm/uvm_extern.h
===
RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.148
diff -u -p -r1.148 uvm_extern.h
--- sys/uvm/uvm_extern.h1 Jul 2019 21:13:03 -   1.148
+++ sys/uvm/uvm_extern.h2 Nov 2019 09:40:31 -
@@ -455,7 +455,6 @@ int uvm_coredump_walkmap(struct proc *
uvm_coredump_setup_cb *_setup,
uvm_coredump_walk_cb *_walk, void *_cookie);
 void   uvm_grow(struct proc *, vaddr_t);
-void   uvm_deallocate(vm_map_t, vaddr_t, vsize_t);
 struct uvm_object  *uvn_attach(struct vnode *, vm_prot_t);
 void   uvm_pagezero_thread(void *);
 void   kmeminit_nkmempages(void);
Index: sys/uvm/uvm_unix.c
===
RCS file: /cvs/src/sys/uvm/uvm_unix.c,v
retrieving revision 1.66
diff -u -p -r1.66 uvm_unix.c
--- sys/uvm/uvm_unix.c  21 Jun 2019 09:39:49 -  1.66
+++ sys/uvm/uvm_unix.c  2 Nov 2019 09:40:31 -
@@ -94,7 +94,7 @@ sys_obreak(struct proc *p, void *v, regi
}
vm->vm_dsize += atop(new - old);
} else {
-   uvm_deallocate(&vm->vm_map, new, old - new);
+   uvm_unmap(&vm->vm_map, new, old);
vm->vm_dsize -= atop(old - new);
}
 
Index: sys/uvm/uvm_user.c
===
RCS file: sys/uvm/uvm_user.c
diff -N sys/uvm/uvm_user.c
--- sys/uvm/uvm_user.c  14 Sep 2014 14:17:27 -  1.14
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,55 +0,0 @@
-/* $OpenBSD: uvm_user.c,v 1.14 2014/09/14 14:17:27 jsg Exp $   */
-/* $NetBSD: uvm_user.c,v 1.8 2000/06/27 17:29:37 mrg Exp $ */
-
-/*
- * Copyright (c) 1997 Charles D. Cranor and Washington University.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR