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

mm/uaccess, mm/fault: Clarify that uaccess may only sleep if pagefaults are enabled

In general, non-atomic variants of user access functions must not sleep
if pagefaults are disabled.

Let's update all relevant comments in uaccess code. This also reflects
the might_sleep() checks in might_fault().

Reviewed-and-tested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: David.Laight@ACULAB.COM
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bigeasy@linutronix.de
Cc: borntraeger@de.ibm.com
Cc: daniel.vetter@intel.com
Cc: heiko.carstens@de.ibm.com
Cc: herbert@gondor.apana.org.au
Cc: hocko@suse.cz
Cc: hughd@google.com
Cc: mst@redhat.com
Cc: paulus@samba.org
Cc: ralf@linux-mips.org
Cc: schwidefsky@de.ibm.com
Cc: yang.shi@windriver.com
Link: http://lkml.kernel.org/r/1431359540-32227-4-git-send-email-dahi@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

David Hildenbrand and committed by
Ingo Molnar
b3c395ef 9ec23531

+118 -59
+8 -4
arch/avr32/include/asm/uaccess.h
··· 97 97 * @x: Value to copy to user space. 98 98 * @ptr: Destination address, in user space. 99 99 * 100 - * Context: User context only. This function may sleep. 100 + * Context: User context only. This function may sleep if pagefaults are 101 + * enabled. 101 102 * 102 103 * This macro copies a single simple value from kernel space to user 103 104 * space. It supports simple types like char and int, but not larger ··· 117 116 * @x: Variable to store result. 118 117 * @ptr: Source address, in user space. 119 118 * 120 - * Context: User context only. This function may sleep. 119 + * Context: User context only. This function may sleep if pagefaults are 120 + * enabled. 121 121 * 122 122 * This macro copies a single simple variable from user space to kernel 123 123 * space. It supports simple types like char and int, but not larger ··· 138 136 * @x: Value to copy to user space. 139 137 * @ptr: Destination address, in user space. 140 138 * 141 - * Context: User context only. This function may sleep. 139 + * Context: User context only. This function may sleep if pagefaults are 140 + * enabled. 142 141 * 143 142 * This macro copies a single simple value from kernel space to user 144 143 * space. It supports simple types like char and int, but not larger ··· 161 158 * @x: Variable to store result. 162 159 * @ptr: Source address, in user space. 163 160 * 164 - * Context: User context only. This function may sleep. 161 + * Context: User context only. This function may sleep if pagefaults are 162 + * enabled. 165 163 * 166 164 * This macro copies a single simple variable from user space to kernel 167 165 * space. It supports simple types like char and int, but not larger
+2 -1
arch/hexagon/include/asm/uaccess.h
··· 36 36 * @addr: User space pointer to start of block to check 37 37 * @size: Size of block to check 38 38 * 39 - * Context: User context only. This function may sleep. 39 + * Context: User context only. This function may sleep if pagefaults are 40 + * enabled. 40 41 * 41 42 * Checks if a pointer to a block of memory in user space is valid. 42 43 *
+20 -10
arch/m32r/include/asm/uaccess.h
··· 91 91 * @addr: User space pointer to start of block to check 92 92 * @size: Size of block to check 93 93 * 94 - * Context: User context only. This function may sleep. 94 + * Context: User context only. This function may sleep if pagefaults are 95 + * enabled. 95 96 * 96 97 * Checks if a pointer to a block of memory in user space is valid. 97 98 * ··· 156 155 * @x: Variable to store result. 157 156 * @ptr: Source address, in user space. 158 157 * 159 - * Context: User context only. This function may sleep. 158 + * Context: User context only. This function may sleep if pagefaults are 159 + * enabled. 160 160 * 161 161 * This macro copies a single simple variable from user space to kernel 162 162 * space. It supports simple types like char and int, but not larger ··· 177 175 * @x: Value to copy to user space. 178 176 * @ptr: Destination address, in user space. 179 177 * 180 - * Context: User context only. This function may sleep. 178 + * Context: User context only. This function may sleep if pagefaults are 179 + * enabled. 181 180 * 182 181 * This macro copies a single simple value from kernel space to user 183 182 * space. It supports simple types like char and int, but not larger ··· 197 194 * @x: Variable to store result. 198 195 * @ptr: Source address, in user space. 199 196 * 200 - * Context: User context only. This function may sleep. 197 + * Context: User context only. This function may sleep if pagefaults are 198 + * enabled. 201 199 * 202 200 * This macro copies a single simple variable from user space to kernel 203 201 * space. It supports simple types like char and int, but not larger ··· 278 274 * @x: Value to copy to user space. 279 275 * @ptr: Destination address, in user space. 280 276 * 281 - * Context: User context only. This function may sleep. 277 + * Context: User context only. This function may sleep if pagefaults are 278 + * enabled. 282 279 * 283 280 * This macro copies a single simple value from kernel space to user 284 281 * space. It supports simple types like char and int, but not larger ··· 573 568 * @from: Source address, in kernel space. 574 569 * @n: Number of bytes to copy. 575 570 * 576 - * Context: User context only. This function may sleep. 571 + * Context: User context only. This function may sleep if pagefaults are 572 + * enabled. 577 573 * 578 574 * Copy data from kernel space to user space. Caller must check 579 575 * the specified block with access_ok() before calling this function. ··· 594 588 * @from: Source address, in kernel space. 595 589 * @n: Number of bytes to copy. 596 590 * 597 - * Context: User context only. This function may sleep. 591 + * Context: User context only. This function may sleep if pagefaults are 592 + * enabled. 598 593 * 599 594 * Copy data from kernel space to user space. 600 595 * ··· 613 606 * @from: Source address, in user space. 614 607 * @n: Number of bytes to copy. 615 608 * 616 - * Context: User context only. This function may sleep. 609 + * Context: User context only. This function may sleep if pagefaults are 610 + * enabled. 617 611 * 618 612 * Copy data from user space to kernel space. Caller must check 619 613 * the specified block with access_ok() before calling this function. ··· 634 626 * @from: Source address, in user space. 635 627 * @n: Number of bytes to copy. 636 628 * 637 - * Context: User context only. This function may sleep. 629 + * Context: User context only. This function may sleep if pagefaults are 630 + * enabled. 638 631 * 639 632 * Copy data from user space to kernel space. 640 633 * ··· 686 677 * strlen_user: - Get the size of a string in user space. 687 678 * @str: The string to measure. 688 679 * 689 - * Context: User context only. This function may sleep. 680 + * Context: User context only. This function may sleep if pagefaults are 681 + * enabled. 690 682 * 691 683 * Get the size of a NUL-terminated string in user space. 692 684 *
+4 -2
arch/microblaze/include/asm/uaccess.h
··· 178 178 * @x: Variable to store result. 179 179 * @ptr: Source address, in user space. 180 180 * 181 - * Context: User context only. This function may sleep. 181 + * Context: User context only. This function may sleep if pagefaults are 182 + * enabled. 182 183 * 183 184 * This macro copies a single simple variable from user space to kernel 184 185 * space. It supports simple types like char and int, but not larger ··· 291 290 * @x: Value to copy to user space. 292 291 * @ptr: Destination address, in user space. 293 292 * 294 - * Context: User context only. This function may sleep. 293 + * Context: User context only. This function may sleep if pagefaults are 294 + * enabled. 295 295 * 296 296 * This macro copies a single simple value from kernel space to user 297 297 * space. It supports simple types like char and int, but not larger
+30 -15
arch/mips/include/asm/uaccess.h
··· 103 103 * @addr: User space pointer to start of block to check 104 104 * @size: Size of block to check 105 105 * 106 - * Context: User context only. This function may sleep. 106 + * Context: User context only. This function may sleep if pagefaults are 107 + * enabled. 107 108 * 108 109 * Checks if a pointer to a block of memory in user space is valid. 109 110 * ··· 139 138 * @x: Value to copy to user space. 140 139 * @ptr: Destination address, in user space. 141 140 * 142 - * Context: User context only. This function may sleep. 141 + * Context: User context only. This function may sleep if pagefaults are 142 + * enabled. 143 143 * 144 144 * This macro copies a single simple value from kernel space to user 145 145 * space. It supports simple types like char and int, but not larger ··· 159 157 * @x: Variable to store result. 160 158 * @ptr: Source address, in user space. 161 159 * 162 - * Context: User context only. This function may sleep. 160 + * Context: User context only. This function may sleep if pagefaults are 161 + * enabled. 163 162 * 164 163 * This macro copies a single simple variable from user space to kernel 165 164 * space. It supports simple types like char and int, but not larger ··· 180 177 * @x: Value to copy to user space. 181 178 * @ptr: Destination address, in user space. 182 179 * 183 - * Context: User context only. This function may sleep. 180 + * Context: User context only. This function may sleep if pagefaults are 181 + * enabled. 184 182 * 185 183 * This macro copies a single simple value from kernel space to user 186 184 * space. It supports simple types like char and int, but not larger ··· 203 199 * @x: Variable to store result. 204 200 * @ptr: Source address, in user space. 205 201 * 206 - * Context: User context only. This function may sleep. 202 + * Context: User context only. This function may sleep if pagefaults are 203 + * enabled. 207 204 * 208 205 * This macro copies a single simple variable from user space to kernel 209 206 * space. It supports simple types like char and int, but not larger ··· 503 498 * @x: Value to copy to user space. 504 499 * @ptr: Destination address, in user space. 505 500 * 506 - * Context: User context only. This function may sleep. 501 + * Context: User context only. This function may sleep if pagefaults are 502 + * enabled. 507 503 * 508 504 * This macro copies a single simple value from kernel space to user 509 505 * space. It supports simple types like char and int, but not larger ··· 523 517 * @x: Variable to store result. 524 518 * @ptr: Source address, in user space. 525 519 * 526 - * Context: User context only. This function may sleep. 520 + * Context: User context only. This function may sleep if pagefaults are 521 + * enabled. 527 522 * 528 523 * This macro copies a single simple variable from user space to kernel 529 524 * space. It supports simple types like char and int, but not larger ··· 544 537 * @x: Value to copy to user space. 545 538 * @ptr: Destination address, in user space. 546 539 * 547 - * Context: User context only. This function may sleep. 540 + * Context: User context only. This function may sleep if pagefaults are 541 + * enabled. 548 542 * 549 543 * This macro copies a single simple value from kernel space to user 550 544 * space. It supports simple types like char and int, but not larger ··· 567 559 * @x: Variable to store result. 568 560 * @ptr: Source address, in user space. 569 561 * 570 - * Context: User context only. This function may sleep. 562 + * Context: User context only. This function may sleep if pagefaults are 563 + * enabled. 571 564 * 572 565 * This macro copies a single simple variable from user space to kernel 573 566 * space. It supports simple types like char and int, but not larger ··· 824 815 * @from: Source address, in kernel space. 825 816 * @n: Number of bytes to copy. 826 817 * 827 - * Context: User context only. This function may sleep. 818 + * Context: User context only. This function may sleep if pagefaults are 819 + * enabled. 828 820 * 829 821 * Copy data from kernel space to user space. Caller must check 830 822 * the specified block with access_ok() before calling this function. ··· 898 888 * @from: Source address, in kernel space. 899 889 * @n: Number of bytes to copy. 900 890 * 901 - * Context: User context only. This function may sleep. 891 + * Context: User context only. This function may sleep if pagefaults are 892 + * enabled. 902 893 * 903 894 * Copy data from kernel space to user space. 904 895 * ··· 1086 1075 * @from: Source address, in user space. 1087 1076 * @n: Number of bytes to copy. 1088 1077 * 1089 - * Context: User context only. This function may sleep. 1078 + * Context: User context only. This function may sleep if pagefaults are 1079 + * enabled. 1090 1080 * 1091 1081 * Copy data from user space to kernel space. Caller must check 1092 1082 * the specified block with access_ok() before calling this function. ··· 1119 1107 * @from: Source address, in user space. 1120 1108 * @n: Number of bytes to copy. 1121 1109 * 1122 - * Context: User context only. This function may sleep. 1110 + * Context: User context only. This function may sleep if pagefaults are 1111 + * enabled. 1123 1112 * 1124 1113 * Copy data from user space to kernel space. 1125 1114 * ··· 1342 1329 * strlen_user: - Get the size of a string in user space. 1343 1330 * @str: The string to measure. 1344 1331 * 1345 - * Context: User context only. This function may sleep. 1332 + * Context: User context only. This function may sleep if pagefaults are 1333 + * enabled. 1346 1334 * 1347 1335 * Get the size of a NUL-terminated string in user space. 1348 1336 * ··· 1412 1398 * strnlen_user: - Get the size of a string in user space. 1413 1399 * @str: The string to measure. 1414 1400 * 1415 - * Context: User context only. This function may sleep. 1401 + * Context: User context only. This function may sleep if pagefaults are 1402 + * enabled. 1416 1403 * 1417 1404 * Get the size of a NUL-terminated string in user space. 1418 1405 *
+10 -5
arch/s390/include/asm/uaccess.h
··· 98 98 * @from: Source address, in user space. 99 99 * @n: Number of bytes to copy. 100 100 * 101 - * Context: User context only. This function may sleep. 101 + * Context: User context only. This function may sleep if pagefaults are 102 + * enabled. 102 103 * 103 104 * Copy data from user space to kernel space. Caller must check 104 105 * the specified block with access_ok() before calling this function. ··· 119 118 * @from: Source address, in kernel space. 120 119 * @n: Number of bytes to copy. 121 120 * 122 - * Context: User context only. This function may sleep. 121 + * Context: User context only. This function may sleep if pagefaults are 122 + * enabled. 123 123 * 124 124 * Copy data from kernel space to user space. Caller must check 125 125 * the specified block with access_ok() before calling this function. ··· 266 264 * @from: Source address, in kernel space. 267 265 * @n: Number of bytes to copy. 268 266 * 269 - * Context: User context only. This function may sleep. 267 + * Context: User context only. This function may sleep if pagefaults are 268 + * enabled. 270 269 * 271 270 * Copy data from kernel space to user space. 272 271 * ··· 293 290 * @from: Source address, in user space. 294 291 * @n: Number of bytes to copy. 295 292 * 296 - * Context: User context only. This function may sleep. 293 + * Context: User context only. This function may sleep if pagefaults are 294 + * enabled. 297 295 * 298 296 * Copy data from user space to kernel space. 299 297 * ··· 352 348 * strlen_user: - Get the size of a string in user space. 353 349 * @str: The string to measure. 354 350 * 355 - * Context: User context only. This function may sleep. 351 + * Context: User context only. This function may sleep if pagefaults are 352 + * enabled. 356 353 * 357 354 * Get the size of a NUL-terminated string in user space. 358 355 *
+10 -5
arch/score/include/asm/uaccess.h
··· 36 36 * @addr: User space pointer to start of block to check 37 37 * @size: Size of block to check 38 38 * 39 - * Context: User context only. This function may sleep. 39 + * Context: User context only. This function may sleep if pagefaults are 40 + * enabled. 40 41 * 41 42 * Checks if a pointer to a block of memory in user space is valid. 42 43 * ··· 62 61 * @x: Value to copy to user space. 63 62 * @ptr: Destination address, in user space. 64 63 * 65 - * Context: User context only. This function may sleep. 64 + * Context: User context only. This function may sleep if pagefaults are 65 + * enabled. 66 66 * 67 67 * This macro copies a single simple value from kernel space to user 68 68 * space. It supports simple types like char and int, but not larger ··· 81 79 * @x: Variable to store result. 82 80 * @ptr: Source address, in user space. 83 81 * 84 - * Context: User context only. This function may sleep. 82 + * Context: User context only. This function may sleep if pagefaults are 83 + * enabled. 85 84 * 86 85 * This macro copies a single simple variable from user space to kernel 87 86 * space. It supports simple types like char and int, but not larger ··· 101 98 * @x: Value to copy to user space. 102 99 * @ptr: Destination address, in user space. 103 100 * 104 - * Context: User context only. This function may sleep. 101 + * Context: User context only. This function may sleep if pagefaults are 102 + * enabled. 105 103 * 106 104 * This macro copies a single simple value from kernel space to user 107 105 * space. It supports simple types like char and int, but not larger ··· 123 119 * @x: Variable to store result. 124 120 * @ptr: Source address, in user space. 125 121 * 126 - * Context: User context only. This function may sleep. 122 + * Context: User context only. This function may sleep if pagefaults are 123 + * enabled. 127 124 * 128 125 * This macro copies a single simple variable from user space to kernel 129 126 * space. It supports simple types like char and int, but not larger
+12 -6
arch/tile/include/asm/uaccess.h
··· 78 78 * @addr: User space pointer to start of block to check 79 79 * @size: Size of block to check 80 80 * 81 - * Context: User context only. This function may sleep. 81 + * Context: User context only. This function may sleep if pagefaults are 82 + * enabled. 82 83 * 83 84 * Checks if a pointer to a block of memory in user space is valid. 84 85 * ··· 193 192 * @x: Variable to store result. 194 193 * @ptr: Source address, in user space. 195 194 * 196 - * Context: User context only. This function may sleep. 195 + * Context: User context only. This function may sleep if pagefaults are 196 + * enabled. 197 197 * 198 198 * This macro copies a single simple variable from user space to kernel 199 199 * space. It supports simple types like char and int, but not larger ··· 276 274 * @x: Value to copy to user space. 277 275 * @ptr: Destination address, in user space. 278 276 * 279 - * Context: User context only. This function may sleep. 277 + * Context: User context only. This function may sleep if pagefaults are 278 + * enabled. 280 279 * 281 280 * This macro copies a single simple value from kernel space to user 282 281 * space. It supports simple types like char and int, but not larger ··· 333 330 * @from: Source address, in kernel space. 334 331 * @n: Number of bytes to copy. 335 332 * 336 - * Context: User context only. This function may sleep. 333 + * Context: User context only. This function may sleep if pagefaults are 334 + * enabled. 337 335 * 338 336 * Copy data from kernel space to user space. Caller must check 339 337 * the specified block with access_ok() before calling this function. ··· 370 366 * @from: Source address, in user space. 371 367 * @n: Number of bytes to copy. 372 368 * 373 - * Context: User context only. This function may sleep. 369 + * Context: User context only. This function may sleep if pagefaults are 370 + * enabled. 374 371 * 375 372 * Copy data from user space to kernel space. Caller must check 376 373 * the specified block with access_ok() before calling this function. ··· 442 437 * @from: Source address, in user space. 443 438 * @n: Number of bytes to copy. 444 439 * 445 - * Context: User context only. This function may sleep. 440 + * Context: User context only. This function may sleep if pagefaults are 441 + * enabled. 446 442 * 447 443 * Copy data from user space to user space. Caller must check 448 444 * the specified blocks with access_ok() before calling this function.
+10 -5
arch/x86/include/asm/uaccess.h
··· 74 74 * @addr: User space pointer to start of block to check 75 75 * @size: Size of block to check 76 76 * 77 - * Context: User context only. This function may sleep. 77 + * Context: User context only. This function may sleep if pagefaults are 78 + * enabled. 78 79 * 79 80 * Checks if a pointer to a block of memory in user space is valid. 80 81 * ··· 146 145 * @x: Variable to store result. 147 146 * @ptr: Source address, in user space. 148 147 * 149 - * Context: User context only. This function may sleep. 148 + * Context: User context only. This function may sleep if pagefaults are 149 + * enabled. 150 150 * 151 151 * This macro copies a single simple variable from user space to kernel 152 152 * space. It supports simple types like char and int, but not larger ··· 242 240 * @x: Value to copy to user space. 243 241 * @ptr: Destination address, in user space. 244 242 * 245 - * Context: User context only. This function may sleep. 243 + * Context: User context only. This function may sleep if pagefaults are 244 + * enabled. 246 245 * 247 246 * This macro copies a single simple value from kernel space to user 248 247 * space. It supports simple types like char and int, but not larger ··· 458 455 * @x: Variable to store result. 459 456 * @ptr: Source address, in user space. 460 457 * 461 - * Context: User context only. This function may sleep. 458 + * Context: User context only. This function may sleep if pagefaults are 459 + * enabled. 462 460 * 463 461 * This macro copies a single simple variable from user space to kernel 464 462 * space. It supports simple types like char and int, but not larger ··· 483 479 * @x: Value to copy to user space. 484 480 * @ptr: Destination address, in user space. 485 481 * 486 - * Context: User context only. This function may sleep. 482 + * Context: User context only. This function may sleep if pagefaults are 483 + * enabled. 487 484 * 488 485 * This macro copies a single simple value from kernel space to user 489 486 * space. It supports simple types like char and int, but not larger
+4 -2
arch/x86/include/asm/uaccess_32.h
··· 70 70 * @from: Source address, in kernel space. 71 71 * @n: Number of bytes to copy. 72 72 * 73 - * Context: User context only. This function may sleep. 73 + * Context: User context only. This function may sleep if pagefaults are 74 + * enabled. 74 75 * 75 76 * Copy data from kernel space to user space. Caller must check 76 77 * the specified block with access_ok() before calling this function. ··· 118 117 * @from: Source address, in user space. 119 118 * @n: Number of bytes to copy. 120 119 * 121 - * Context: User context only. This function may sleep. 120 + * Context: User context only. This function may sleep if pagefaults are 121 + * enabled. 122 122 * 123 123 * Copy data from user space to kernel space. Caller must check 124 124 * the specified block with access_ok() before calling this function.
+4 -2
arch/x86/lib/usercopy_32.c
··· 647 647 * @from: Source address, in kernel space. 648 648 * @n: Number of bytes to copy. 649 649 * 650 - * Context: User context only. This function may sleep. 650 + * Context: User context only. This function may sleep if pagefaults are 651 + * enabled. 651 652 * 652 653 * Copy data from kernel space to user space. 653 654 * ··· 669 668 * @from: Source address, in user space. 670 669 * @n: Number of bytes to copy. 671 670 * 672 - * Context: User context only. This function may sleep. 671 + * Context: User context only. This function may sleep if pagefaults are 672 + * enabled. 673 673 * 674 674 * Copy data from user space to kernel space. 675 675 *
+4 -2
lib/strnlen_user.c
··· 84 84 * @str: The string to measure. 85 85 * @count: Maximum count (including NUL character) 86 86 * 87 - * Context: User context only. This function may sleep. 87 + * Context: User context only. This function may sleep if pagefaults are 88 + * enabled. 88 89 * 89 90 * Get the size of a NUL-terminated string in user space. 90 91 * ··· 114 113 * strlen_user: - Get the size of a user string INCLUDING final NUL. 115 114 * @str: The string to measure. 116 115 * 117 - * Context: User context only. This function may sleep. 116 + * Context: User context only. This function may sleep if pagefaults are 117 + * enabled. 118 118 * 119 119 * Get the size of a NUL-terminated string in user space. 120 120 *