Hugh Dickins fe19bd3dae mm, futex: fix shared futex pgoff on shmem huge page
If more than one futex is placed on a shmem huge page, it can happen
that waking the second wakes the first instead, and leaves the second
waiting: the key's shared.pgoff is wrong.

When 3.11 commit 13d60f4b6ab5 ("futex: Take hugepages into account when
generating futex_key"), the only shared huge pages came from hugetlbfs,
and the code added to deal with its exceptional page->index was put into
hugetlb source.  Then that was missed when 4.8 added shmem huge pages.

page_to_pgoff() is what others use for this nowadays: except that, as
currently written, it gives the right answer on hugetlbfs head, but
nonsense on hugetlbfs tails.  Fix that by calling hugetlbfs-specific
hugetlb_basepage_index() on PageHuge tails as well as on head.

Yes, it's unconventional to declare hugetlb_basepage_index() there in
pagemap.h, rather than in hugetlb.h; but I do not expect anything but
page_to_pgoff() ever to need it.

[akpm@linux-foundation.org: give hugetlb_basepage_index() prototype the correct scope]

Link: https://lkml.kernel.org/r/b17d946b-d09-326e-b42a-52884c36df32@google.com
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Reported-by: Neel Natu <neelnatu@google.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Zhang Yi <wetpzy@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-06-24 19:40:54 -07:00
..
2021-04-26 16:32:11 -07:00
2021-05-05 12:39:29 -07:00
2021-06-08 09:41:16 -07:00
2021-05-18 17:24:52 +01:00
2021-05-06 19:24:11 -07:00
2021-04-14 16:30:30 +03:00
2021-05-08 21:49:48 -06:00
2021-05-15 08:52:30 -07:00
2021-04-29 11:57:23 -07:00
2021-04-08 16:04:20 -07:00
2021-05-24 12:45:26 -04:00
2021-05-24 12:45:26 -04:00
2021-05-01 10:14:08 -07:00
2021-04-08 16:04:20 -07:00
2021-04-08 16:04:20 -07:00
2021-05-04 11:24:46 -07:00
2021-05-06 19:24:11 -07:00
2021-04-19 13:13:26 -04:00
2021-04-12 15:04:23 +02:00
2021-05-07 00:26:34 -07:00
2021-04-28 17:22:10 -07:00
2021-04-30 11:20:40 -07:00
2021-04-26 15:03:23 -07:00
2021-04-26 10:25:03 -07:00
2021-05-05 12:39:29 -07:00
2021-04-05 22:39:38 -04:00
2021-05-08 10:00:11 -07:00
2021-04-28 12:37:53 -07:00
2021-04-08 16:04:20 -07:00
2021-05-07 11:23:41 -07:00
2021-04-06 08:34:39 +02:00
2021-04-21 10:24:41 -05:00
2021-05-01 10:14:08 -07:00
2021-04-28 12:00:13 -07:00
2021-05-05 13:24:11 -07:00
2021-05-06 19:24:11 -07:00
2021-04-15 10:32:17 +02:00
2021-04-26 22:55:12 +01:00
2021-04-09 16:00:00 +02:00
\n
2021-04-29 11:06:13 -07:00
2021-06-24 19:40:53 -07:00
2021-04-16 15:31:02 -07:00