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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 25CA0C2D0A3 for ; Sat, 24 Oct 2020 05:15:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 95E942226B for ; Sat, 24 Oct 2020 05:15:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="anNT05lG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95E942226B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 92D376B005C; Sat, 24 Oct 2020 01:14:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B5A96B0062; Sat, 24 Oct 2020 01:14:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77D5D6B0068; Sat, 24 Oct 2020 01:14:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 3F24C6B005C for ; Sat, 24 Oct 2020 01:14:59 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C07ED8249980 for ; Sat, 24 Oct 2020 05:14:58 +0000 (UTC) X-FDA: 77405654676.22.deer42_4212d442725f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4738518038E60 for ; Sat, 24 Oct 2020 05:14:57 +0000 (UTC) X-HE-Tag: deer42_4212d442725f X-Filterd-Recvd-Size: 4535 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Sat, 24 Oct 2020 05:14:56 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 23 Oct 2020 22:15:04 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 24 Oct 2020 05:14:55 +0000 Received: from [10.2.51.100] (10.124.1.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 24 Oct 2020 05:14:54 +0000 Subject: Re: [PATCH 0/2] Add a 'seqcount' between gup_fast and copy_page_range To: Jason Gunthorpe , , Peter Xu , Linus Torvalds CC: Andrea Arcangeli , Andrew Morton , Aneesh Kumar K.V , Christoph Hellwig , Hugh Dickins , Jan Kara , Jann Horn , Kirill Shutemov , Kirill Tkhai , Leon Romanovsky , Linux-MM , Michal Hocko , Oleg Nesterov References: <0-v1-281e425c752f+2df-gup_fork_jgg@nvidia.com> From: John Hubbard Message-ID: Date: Fri, 23 Oct 2020 22:14:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <0-v1-281e425c752f+2df-gup_fork_jgg@nvidia.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To DRHQMAIL107.nvidia.com (10.27.9.16) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1603516504; bh=d5ZZq2UxIXoOmTKdWleBV6mXqlwQorBKR+KXN/Jd49k=; h=Subject:To:CC:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; b=anNT05lGtoeSeHSBvIbVKupVWlMQ1s0QGzWB/ZzPCUQUif6tpc2h7lK8ETGe/4IyJ wrcJd+HRG2ltzAGkndLlvNdCjH0tbxDQQRt+ONdvCjsB83G6wTS1nB8Fte01JgzZa4 mB48SYAvj3JpVPgXHsotN0OMvbQyreMvqus+zIeitrO8NcH4JFTD+IydqVER+fzxyS rqGA8u6j5F7vezTprBQQpjh7UAhUTsgvOa0AB71DvLAoAi9ZNG3i6n1F/MxJwmSPxK ByPkzCABRwsVzj+U0j9UY5nS480VDG4gcImhKOhhRSjk3q30Cd5edoqpmHe42WKS4B mIFDD7dTTuy3Q== 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 10/23/20 5:19 PM, Jason Gunthorpe wrote: > As discussed and suggested by Linus use a seqcount like thing to close the > small race between gup_fast and copy_page_range. > > Unfortunately the good suggestion to just use write_seqcount_begin() blows > up lockdep immediately due to the (new?) requirement that the write side > of seqcount be in a preempt disabled region. For this application it does > not seem like a good idea, nor is it necessary as we don't spin on retry. > > So I open coded a similar construct. Don't like it, will redo this in some > other way if there is a better idea. Since seqcount seems to have this > property now, it also feels wrong to be the only place to use the raw_ > functions specifically to avoid the lockdep checks and other parts of > seqcount on the read side. I really think situations like this are exactly where the "raw" functions are appropriate. Using a locking API would be much better here, IMHO anyway, than having to work through the various rmb(), smb*(), and other barriers. > > This can go after the merge window. I was table to test it using two > threads, one forking and the other using ibv_reg_mr() to trigger GUP > fast. Modifying copy_page_range() to sleep made the window large enough to > reliably hit to test the logic. > > Jason Gunthorpe (2): > mm: reorganize internal_get_user_pages_fast() > mm: prevent gup_fast from racing with COW during fork > > include/linux/mm_types.h | 6 +++ > kernel/fork.c | 1 + > mm/gup.c | 107 ++++++++++++++++++++++++--------------- > mm/memory.c | 16 +++++- > 4 files changed, 87 insertions(+), 43 deletions(-) > thanks, -- John Hubbard NVIDIA