From patchwork Sat Oct 24 00:19:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11854657 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E8DE6A2 for ; Sat, 24 Oct 2020 00:19:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81423223EA for ; Sat, 24 Oct 2020 00:19:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="V0GFoo29" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81423223EA 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 79EF86B0062; Fri, 23 Oct 2020 20:19:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7591E6B006C; Fri, 23 Oct 2020 20:19:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63D136B0068; Fri, 23 Oct 2020 20:19:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 381B26B005C for ; Fri, 23 Oct 2020 20:19:26 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D0E31181AEF07 for ; Sat, 24 Oct 2020 00:19:25 +0000 (UTC) X-FDA: 77404909890.13.wool34_4604e6c2725d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id AD22F18140B67 for ; Sat, 24 Oct 2020 00:19:25 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jgg@nvidia.com,,RULES_HIT:30054:30064:30090:30091,0,RBL:216.228.121.65:@nvidia.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04yfmr9eqm16jiyunpj164tx756d3ychz8ktqkxa86ya69i8yqpjf6prskgickx.bsaezr3dzuiuoehfghnene57xu6f6kik6xowypt4c1gyrrthmf48cfogn81ka44.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: wool34_4604e6c2725d X-Filterd-Recvd-Size: 6186 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Sat, 24 Oct 2020 00:19:24 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 23 Oct 2020 17:19:02 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 24 Oct 2020 00:19:23 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.175) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 24 Oct 2020 00:19:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GAXcLskdVfHVgnK1k232Lr7bbRwqtu2toYX71hujVuJCV4xH3qwd3kxnkEqpiQXJgIjOxYjJz97a4wufUF9LFHv5y5ikYer2z+iPBa4Qh0jKS1TlYB0YiAzF4K7+2VRDp+Eg3R1ixuufNW4BwHFbWZkOgkjmx9QY30pwkLG2qJUpuY1gBd6cbIKcTixn0qR47Xpd8XISir9VHjJuy4roSmj405jLNdpp0qfJIHRD5tSi0qBexT81Ki9vVN2WPlIiSb7O/OBoVzFC8ytaCngiRWPVqh9FrQHULet0qTF6dcRjJFKouBPljCH2Ij4cf2fvRLr+0LZeh3pzbNrPPtOKLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8hc/8Q6QCvmUO88ri6lXmJCOxnqki9DVNSrSGpEaOOQ=; b=nOa6vD58qTnZsMdYHNPvVMQiMHxL+eejWHIAodhozyfZH9Ca28ngKNJgqYlx45b7k+nknQ1Am7AI3LZ/mCJC8ppCbnBVPZIHci9cg2VpoeysKy6nZGqb/fs47XrsIfbky+UkQK2z3hurpshLEaIJrczqnyF2GaMcGdF70dzAvT8gnESL7bXRVBCF/4vr26X6P0Hy+6iGjsCAAcWipJDsKT1/q0rEjbY5mto/8uiKkYOK6YEDgi94PS63nKGAH6YjNDkJlAnVikWUQ7lIhKKk0th7SLPhpX0tTUpLR93bnvxLlJmp6ODj5+6Fnbx3+1VE4NMSUKjwl3zU/TWkkeaeZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4299.namprd12.prod.outlook.com (2603:10b6:5:223::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Sat, 24 Oct 2020 00:19:22 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::cdbe:f274:ad65:9a78]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::cdbe:f274:ad65:9a78%7]) with mapi id 15.20.3477.028; Sat, 24 Oct 2020 00:19:21 +0000 From: Jason Gunthorpe To: , Peter Xu , Linus Torvalds CC: Andrea Arcangeli , Andrew Morton , Aneesh Kumar K.V , Christoph Hellwig , Hugh Dickins , Jan Kara , Jann Horn , John Hubbard , Kirill Shutemov , Kirill Tkhai , Leon Romanovsky , Linux-MM , Michal Hocko , Oleg Nesterov Subject: [PATCH 0/2] Add a 'seqcount' between gup_fast and copy_page_range Date: Fri, 23 Oct 2020 21:19:18 -0300 Message-ID: <0-v1-281e425c752f+2df-gup_fork_jgg@nvidia.com> X-ClientProxiedBy: MN2PR16CA0064.namprd16.prod.outlook.com (2603:10b6:208:234::33) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (156.34.48.30) by MN2PR16CA0064.namprd16.prod.outlook.com (2603:10b6:208:234::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Sat, 24 Oct 2020 00:19:21 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kW7HE-0076cr-9R; Fri, 23 Oct 2020 21:19:20 -0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1603498742; bh=fuS1tew5XDk0u8RbrHWll5frjd7462oWJeJ0mz8h5fU=; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To: CC:Subject:Date:Message-ID:Content-Transfer-Encoding:Content-Type: X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType; b=V0GFoo29qU5tjFZg1oBOVIHLfFRoAfs8eggmoZUtCEWP22UTDOhdYADW7g+DBdibr ivdsWkJ13njSTG4KuRgSea13m9Fd4cCEcRcG8rUVIC73Qy9elZr7gc84mJe0kdYru6 GxeQd707WTSz3BwcAKN3jRS2HH3vJq2XkOdZT4RrxcK3ofdPzywGonSlaGYNbLVdNL msXWnevSp7P0+bfnOR2KtprtkFZ5+Ik8c7qctBx6YgqI9GUX4jpnc2y8U8uBbygi7n IRigwMYf/UqfFToGNxX+YBnFcieCQb+HepvzFObEahJLaC5r4vlO0tIDkWFF4cWYMx V0kbkUKXJ8SEQ== 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: 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. 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(-)