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=-5.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=no 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 80A79C48BE5 for ; Thu, 17 Jun 2021 01:43:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 195CF611BE for ; Thu, 17 Jun 2021 01:43:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 195CF611BE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 86E596B0070; Wed, 16 Jun 2021 21:43:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81E4A6B0071; Wed, 16 Jun 2021 21:43:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BF396B0072; Wed, 16 Jun 2021 21:43:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 37A6B6B0070 for ; Wed, 16 Jun 2021 21:43:21 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C759A180AD806 for ; Thu, 17 Jun 2021 01:43:20 +0000 (UTC) X-FDA: 78261518160.39.685F959 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf04.hostedemail.com (Postfix) with ESMTP id 9D0C137A for ; Thu, 17 Jun 2021 01:43:13 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B6266112D; Thu, 17 Jun 2021 01:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1623894197; bh=TfsTygI0gHSyYhqOTv8VBGgCJP8Jiua6aKYAwmvNJu4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=s6O005oO2/PzdpyTrKmakB40bKNOrYWA2pCHsqCb/lj8RcTdEk/QdqeLLUNgiDETI vjXn+LONvLpOv6Xo43pBx7iyGYdlHgCKNZJlFJBohiUnfOqBDpyH7mfVn9+hqqa5Tu EVuFxR9mIN1BSLO3el+UC5XzlUDqB/NVQFu73k6c= Date: Wed, 16 Jun 2021 18:43:16 -0700 From: Andrew Morton To: "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, kaleshsingh@google.com, npiggin@gmail.com, joel@joelfernandes.org, Christophe Leroy , Linus Torvalds , "Kirill A . Shutemov" , stable@vger.kernel.org, Hugh Dickins , "Kirill A . Shutemov" Subject: Re: [PATCH v2 6/6] mm/mremap: hold the rmap lock in write mode when moving page table entries. Message-Id: <20210616184316.17229c71508fbd536afa3662@linux-foundation.org> In-Reply-To: <20210616045239.370802-7-aneesh.kumar@linux.ibm.com> References: <20210616045239.370802-1-aneesh.kumar@linux.ibm.com> <20210616045239.370802-7-aneesh.kumar@linux.ibm.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=s6O005oO; dmarc=none; spf=pass (imf04.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: pyioytijk9f4ckxwci5aed99d5k96wjd X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9D0C137A X-HE-Tag: 1623894193-402381 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 Wed, 16 Jun 2021 10:22:39 +0530 "Aneesh Kumar K.V" wrote: > To avoid a race between rmap walk and mremap, mremap does take_rmap_locks(). > The lock was taken to ensure that rmap walk don't miss a page table entry due to > PTE moves via move_pagetables(). The kernel does further optimization of > this lock such that if we are going to find the newly added vma after the > old vma, the rmap lock is not taken. This is because rmap walk would find the > vmas in the same order and if we don't find the page table attached to > older vma we would find it with the new vma which we would iterate later. > > As explained in commit eb66ae030829 ("mremap: properly flush TLB before releasing the page") > mremap is special in that it doesn't take ownership of the page. The > optimized version for PUD/PMD aligned mremap also doesn't hold the ptl lock. > This can result in stale TLB entries as show below. > > ... > > Cc: stable@vger.kernel.org Sneaking a -stable patch into the middle of all of this was ... sneaky :( It doesn't actually apply to current mainline either. I think I'll pretend I didn't notice. Please sort this out with Greg when he reports this back to you.