Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1936859pxj; Sun, 13 Jun 2021 03:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjGLTIO7LpjVM9BTI6FfNEZqFTSU11Owi3dwnU79OT76AkTEFcZSKDMOMqvDbcTugjbii9 X-Received: by 2002:aa7:d388:: with SMTP id x8mr11906482edq.338.1623580191948; Sun, 13 Jun 2021 03:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623580191; cv=none; d=google.com; s=arc-20160816; b=UUJredjxNrusmW/F72rQzlg1Fa10sEcTPOIaTRW3kbdut5mpidu6cD+X7JiXBFuhHB FDMt9EvybroBgNRTY5gT+iHtP7XOkTm6f6xIGzE48T3t9ruuwX0ZGOu4/VZu3c3Wkk4C QYcSxdPtQJmdQMxJ010Atc62TaN6/CZDMu8dbcEyA94+MDwVAlDFTh8DZvRmNLXHsFBM f24faKjvgF41opMrzttsFVn7xi9olfre8Z55t2DWHG/eK0MjWc8w2sDFPKM7LRAw3FT5 xWWUWjCnBChcx6TbhOXn2Z/jm3qmZ64nnlua6rhbYjY2jvH/FQ+sWvQaSkAHDFOMPsmw 3A8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GI1B2TWOcVYfBM9mpBoycoXz69MytErLgsWQehgKcn8=; b=zazTLxLCJ3Mt2Ymg39L2nFqVgxuoC2ggiyHJzBQMPBTkdk0az6PDRlNyd2G5lMhNL5 azcHKuClafndL43Qq4xIegLBxMVmc4cn7tk5eFgvw7owPzO/JTRjyZM2lqJ65+CG9NWl d9dWaVUhz2wHZnhhfSlwXfHSKp0VTHZcR+FfOVJ9dz4dVjkdE0Htvgmo3lzENeIxIQta ds+I+iyLDW26VD2zfIDc1gXWxkiF417YUeK4/+fffeHlNLzVknxHs2T9EpO5+wa4qPRx 61Oik7OpXyDjP7VJW8OVmKqhXYPHSU5kDmrHaKPEPGfWMGlAgyS1us1KfuCjHY2KZAIQ iXIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pd2nYi5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si9312573ejo.589.2021.06.13.03.29.29; Sun, 13 Jun 2021 03:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pd2nYi5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231664AbhFMKaX (ORCPT + 99 others); Sun, 13 Jun 2021 06:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbhFMKaW (ORCPT ); Sun, 13 Jun 2021 06:30:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED6C2C061574 for ; Sun, 13 Jun 2021 03:28:19 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)