Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
futexes: Remove rw parameter from get_futex_key()
Currently, futexes have two problem: A) The current futex code doesn't handle private file mappings properly. get_futex_key() uses PageAnon() to distinguish file and anon, which can cause the following bad scenario: 1) thread-A call futex(private-mapping, FUTEX_WAIT), it sleeps on file mapping object. 2) thread-B writes a variable and it makes it cow. 3) thread-B calls futex(private-mapping, FUTEX_WAKE), it wakes up blocked thread on the anonymous page. (but it's nothing) B) Current futex code doesn't handle zero page properly. Read mode get_user_pages() can return zero page, but current futex code doesn't handle it at all. Then, zero page makes infinite loop internally. The solution is to use write mode get_user_page() always for page lookup. It prevents the lookup of both file page of private mappings and zero page. Performance concerns: Probaly very little, because glibc always initialize variables for futex before to call futex(). It means glibc users never see the overhead of this patch. Compatibility concerns: This patch has few compatibility issues. After this patch, FUTEX_WAIT require writable access to futex variables (read-only mappings makes EFAULT). But practically it's not a problem, glibc always initalizes variables for futexes explicitly - nobody uses read-only mappings. Reported-by: Hugh Dickins <[email protected]> Signed-off-by: KOSAKI Motohiro <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Acked-by: Darren Hart <[email protected]> Cc: <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Ulrich Drepper <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
- Loading branch information