From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFDE9C48BCF for ; Sun, 13 Jun 2021 10:28:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06D0961222 for ; Sun, 13 Jun 2021 10:28:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06D0961222 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 161426B006C; Sun, 13 Jun 2021 06:28:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1112E6B006E; Sun, 13 Jun 2021 06:28:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF4B36B0070; Sun, 13 Jun 2021 06:28:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id B99E06B006C for ; Sun, 13 Jun 2021 06:28:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 321BBDB3C for ; Sun, 13 Jun 2021 10:28:14 +0000 (UTC) X-FDA: 78248325708.07.98BE914 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 3F1C0C005A20 for ; Sun, 13 Jun 2021 10:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GI1B2TWOcVYfBM9mpBoycoXz69MytErLgsWQehgKcn8=; b=pd2nYi5uyQvVnMy+oYDubRyjt4 2t2NtygYzNzvYplPrjmJblv+Ykwp7dPQGc0CncRuC6WYasdtByDCy7K7SSpRZ34Jdyi7nWwnNXy+7 sWxN6rGBiTDrF6Xtvl0XNaTYK/I8Yaw1L6Z7SXcvBPHqDzNeBmSWxXkRn7EfwDiPrq5e/Agckb8Vq eYh4llxjzT1/GKPdUetp9yFH/mZyC1fIqEbty6Ngx9+w6/PQFjsBKobr0qX2YYe/iguMjUIlZnrW5 g0843wbMxEDJ1+Qz7NFUZY5KEx2QIv7Bo3thTFDOQXFMOXg+oTmbp5CBEeRiKRJFrOkXR2TwRZlWS uuUc0zeg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lsNKw-004SQS-T1; Sun, 13 Jun 2021 10:27:34 +0000 Date: Sun, 13 Jun 2021 11:27:26 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , "Kirill A. Shutemov" , Zhang Yi , Mel Gorman , Mike Kravetz , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Neel Natu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm, futex: Fix shared futex pgoff on shmem huge page Message-ID: References: <45e8fd67-51fd-7828-fe43-d261d6c33727@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3F1C0C005A20 X-Stat-Signature: smd3w7ugn59p8rjjjzoahzfwz7udiueo Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pd2nYi5u; dmarc=none; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1623580086-549869 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Jun 12, 2021 at 08:16:58PM -0700, Hugh Dickins wrote: > 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. > > Fixes: 800d8c63b2e9 ("shmem: add huge pages support") > Reported-by: Neel Natu > Signed-off-by: Hugh Dickins > Cc: Reviewed-by: Matthew Wilcox (Oracle)