Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/vmalloc: remove vwrite()

The last user (/dev/kmem) is gone. Let's drop it.

Link: https://lkml.kernel.org/r/20210324102351.6932-4-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: huang ying <huang.ying.caritas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Hildenbrand and committed by
Linus Torvalds
f7c8ce44 f2e762ba

+1 -126
-1
include/linux/vmalloc.h
··· 229 229 230 230 /* for /proc/kcore */ 231 231 extern long vread(char *buf, char *addr, unsigned long count); 232 - extern long vwrite(char *buf, char *addr, unsigned long count); 233 232 234 233 /* 235 234 * Internals. Dont't use..
-10
mm/nommu.c
··· 210 210 return count; 211 211 } 212 212 213 - long vwrite(char *buf, char *addr, unsigned long count) 214 - { 215 - /* Don't allow overflow */ 216 - if ((unsigned long) addr + count < count) 217 - count = -(unsigned long) addr; 218 - 219 - memcpy(addr, buf, count); 220 - return count; 221 - } 222 - 223 213 /* 224 214 * vmalloc - allocate virtually contiguous memory 225 215 *
+1 -115
mm/vmalloc.c
··· 3146 3146 * kmap() and get small overhead in this access function. 3147 3147 */ 3148 3148 if (p) { 3149 - /* 3150 - * we can expect USER0 is not used (see vread/vwrite's 3151 - * function description) 3152 - */ 3149 + /* We can expect USER0 is not used -- see vread() */ 3153 3150 void *map = kmap_atomic(p); 3154 3151 memcpy(buf, map + offset, length); 3155 3152 kunmap_atomic(map); 3156 3153 } else 3157 3154 memset(buf, 0, length); 3158 3155 3159 - addr += length; 3160 - buf += length; 3161 - copied += length; 3162 - count -= length; 3163 - } 3164 - return copied; 3165 - } 3166 - 3167 - static int aligned_vwrite(char *buf, char *addr, unsigned long count) 3168 - { 3169 - struct page *p; 3170 - int copied = 0; 3171 - 3172 - while (count) { 3173 - unsigned long offset, length; 3174 - 3175 - offset = offset_in_page(addr); 3176 - length = PAGE_SIZE - offset; 3177 - if (length > count) 3178 - length = count; 3179 - p = vmalloc_to_page(addr); 3180 - /* 3181 - * To do safe access to this _mapped_ area, we need 3182 - * lock. But adding lock here means that we need to add 3183 - * overhead of vmalloc()/vfree() calles for this _debug_ 3184 - * interface, rarely used. Instead of that, we'll use 3185 - * kmap() and get small overhead in this access function. 3186 - */ 3187 - if (p) { 3188 - /* 3189 - * we can expect USER0 is not used (see vread/vwrite's 3190 - * function description) 3191 - */ 3192 - void *map = kmap_atomic(p); 3193 - memcpy(map + offset, buf, length); 3194 - kunmap_atomic(map); 3195 - } 3196 3156 addr += length; 3197 3157 buf += length; 3198 3158 copied += length; ··· 3240 3280 if (buf != buf_start + buflen) 3241 3281 memset(buf, 0, buflen - (buf - buf_start)); 3242 3282 3243 - return buflen; 3244 - } 3245 - 3246 - /** 3247 - * vwrite() - write vmalloc area in a safe way. 3248 - * @buf: buffer for source data 3249 - * @addr: vm address. 3250 - * @count: number of bytes to be read. 3251 - * 3252 - * This function checks that addr is a valid vmalloc'ed area, and 3253 - * copy data from a buffer to the given addr. If specified range of 3254 - * [addr...addr+count) includes some valid address, data is copied from 3255 - * proper area of @buf. If there are memory holes, no copy to hole. 3256 - * IOREMAP area is treated as memory hole and no copy is done. 3257 - * 3258 - * If [addr...addr+count) doesn't includes any intersects with alive 3259 - * vm_struct area, returns 0. @buf should be kernel's buffer. 3260 - * 3261 - * Note: In usual ops, vwrite() is never necessary because the caller 3262 - * should know vmalloc() area is valid and can use memcpy(). 3263 - * This is for routines which have to access vmalloc area without 3264 - * any information, as /dev/kmem. 3265 - * 3266 - * Return: number of bytes for which addr and buf should be 3267 - * increased (same number as @count) or %0 if [addr...addr+count) 3268 - * doesn't include any intersection with valid vmalloc area 3269 - */ 3270 - long vwrite(char *buf, char *addr, unsigned long count) 3271 - { 3272 - struct vmap_area *va; 3273 - struct vm_struct *vm; 3274 - char *vaddr; 3275 - unsigned long n, buflen; 3276 - int copied = 0; 3277 - 3278 - /* Don't allow overflow */ 3279 - if ((unsigned long) addr + count < count) 3280 - count = -(unsigned long) addr; 3281 - buflen = count; 3282 - 3283 - spin_lock(&vmap_area_lock); 3284 - list_for_each_entry(va, &vmap_area_list, list) { 3285 - if (!count) 3286 - break; 3287 - 3288 - if (!va->vm) 3289 - continue; 3290 - 3291 - vm = va->vm; 3292 - vaddr = (char *) vm->addr; 3293 - if (addr >= vaddr + get_vm_area_size(vm)) 3294 - continue; 3295 - while (addr < vaddr) { 3296 - if (count == 0) 3297 - goto finished; 3298 - buf++; 3299 - addr++; 3300 - count--; 3301 - } 3302 - n = vaddr + get_vm_area_size(vm) - addr; 3303 - if (n > count) 3304 - n = count; 3305 - if (!(vm->flags & VM_IOREMAP)) { 3306 - aligned_vwrite(buf, addr, n); 3307 - copied++; 3308 - } 3309 - buf += n; 3310 - addr += n; 3311 - count -= n; 3312 - } 3313 - finished: 3314 - spin_unlock(&vmap_area_lock); 3315 - if (!copied) 3316 - return 0; 3317 3283 return buflen; 3318 3284 } 3319 3285