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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0E483C00A89 for ; Fri, 30 Oct 2020 17:02:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 510A3206D5 for ; Fri, 30 Oct 2020 17:02:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="Hq8HhJqM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 510A3206D5 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 C59006B0071; Fri, 30 Oct 2020 13:02:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2F236B0073; Fri, 30 Oct 2020 13:02:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1F796B007B; Fri, 30 Oct 2020 13:02:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 86A156B0071 for ; Fri, 30 Oct 2020 13:02:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0C5243633 for ; Fri, 30 Oct 2020 17:02:33 +0000 (UTC) X-FDA: 77429210586.17.river68_2801d7327297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id D52A0180D0181 for ; Fri, 30 Oct 2020 17:02:32 +0000 (UTC) X-HE-Tag: river68_2801d7327297 X-Filterd-Recvd-Size: 6271 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 17:02:31 +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, 30 Oct 2020 10:02:40 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 30 Oct 2020 17:02:29 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 30 Oct 2020 17:02:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hLqgOjzwNsAuQfCXt6+oP628Kc3mOuw6puhFf3lktwRs8BbEQfpdYmUR1axviOCpVqKzYTJHih01Jz6KAQxlsvPdf0rtrVgZ+zMKIA9ojvOdRpd7HgmfsWmr0Tr/hj2yBDIXxfbOA7IG3Ysl0X4znzEEwu68Ms0YExTHwtzINSyZBedMZd5EclAzvYrkKgi0mMOcKxvGuJSWlXprZnrlyuLY+WNC8pKASwIEzMYMxNjc3JesrjZsqatLtjKpI8gEKrZNpX5iApsW6PpAfjDRHxX008tNWh5grrK56skzwwdAz/2KsbeQ09j0IR/d1uA8L0HIf+gr+8zyHmgD/d35Sw== 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=xtrND6DfV8ifG4p2ENrkSSUEtdNTOFnxyD7hFi7bs90=; b=EhOg/IQRbKH6ofOfoQHyA2KMl5C/tKSEFXhNGVWux1+Vk0eU+sMub8B0aLiHO6B4HZvx9+cbI8TZ/nnBkxMpCxkIaiRkbMlKdqF5NTWgLrIwrQlcX/8zDqVH8wDXYGZRZVVCUoN7tE6Pv1o/H1zloetoZ3KzIBGF35IUWpQBJpCcdOVUW2ymOGo+hNGmbw0cwQGsd18iJQmgxJrqe8lmVbjT5NxoNgxGDtWKNvS90+TsL9xzJ87sHcLyOqVajUD4JOjkTuvQvo+KGS+p7NzSIX5sCHKSxjjSKjZqajbYxeSK905sD4Z4qoQ8wKk9tcNF3pEiNeuzR0BViUPKZMCfOA== 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 DM6PR12MB3018.namprd12.prod.outlook.com (2603:10b6:5:118::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.24; Fri, 30 Oct 2020 17:02:28 +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.3499.027; Fri, 30 Oct 2020 17:02:28 +0000 Date: Fri, 30 Oct 2020 14:02:26 -0300 From: Jason Gunthorpe To: Jan Kara CC: , Peter Xu , Linus Torvalds , Andrea Arcangeli , Andrew Morton , Aneesh Kumar K.V , Christoph Hellwig , Hugh Dickins , Jann Horn , John Hubbard , Kirill Shutemov , Kirill Tkhai , Leon Romanovsky , Linux-MM , Michal Hocko , Oleg Nesterov Subject: Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork Message-ID: <20201030170226.GF2620339@nvidia.com> References: <0-v2-dfe9ecdb6c74+2066-gup_fork_jgg@nvidia.com> <2-v2-dfe9ecdb6c74+2066-gup_fork_jgg@nvidia.com> <20201030165105.GH19757@quack2.suse.cz> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20201030165105.GH19757@quack2.suse.cz> X-ClientProxiedBy: MN2PR15CA0015.namprd15.prod.outlook.com (2603:10b6:208:1b4::28) 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 MN2PR15CA0015.namprd15.prod.outlook.com (2603:10b6:208:1b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Fri, 30 Oct 2020 17:02:28 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kYXnG-00DRVp-Tx; Fri, 30 Oct 2020 14:02:26 -0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1604077360; bh=xtrND6DfV8ifG4p2ENrkSSUEtdNTOFnxyD7hFi7bs90=; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Date: From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType; b=Hq8HhJqMVuqogtuPd7EN6HyQpds4zhaELvuxoqxdUbtS3lJmvc5/UyzaZIMtAw0m1 il0DhKV2MErN9yn5nItz+IMrXyjPoiMW2+Zer6hvPyp2qyVpO1wBUwKTEAUV7CM5t9 aKGVmDXwAGsTgOhSvTqHsydgdvzGoeqy7ntlrX8fXC9NOFV+FrmbNxTZ4KebSOqHJm ipzqF35/SbD2U3eJXE13KwIQMzvl0NkACerUkOBHSTNNj+V7Rp+jQjflREcf/4QTwE kOUJ2SYoHZfYBcf2FI1SVDZoItKOSy2ns1GgTkk4+Lq+WGQFqrZhOEXmTO6Bthpj2P J/Re7+lSdBcuA== 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 Fri, Oct 30, 2020 at 05:51:05PM +0100, Jan Kara wrote: > Looks good to me. Just one nit below. With that fixed feel free to add: > > Reviewed-by: Jan Kara Thanks! > > @@ -446,6 +447,12 @@ struct mm_struct { > > */ > > atomic_t has_pinned; > > > > + /** > > + * @write_protect_seq: Odd when any thread is write protecting > > + * pages in this mm, for instance during fork(). > > + */ > > + seqcount_t write_protect_seq; > > + > > So this comment isn't quite true. We can be writeprotecting pages due to > many other reasons and not touch write_protect_seq. E.g. for shared > mappings or due to explicit mprotect() calls. So the write_protect_seq > protection has to be about something more than pure write protection. One > requirement certainly is that the VMA has to be is_cow_mapping(). What > about mprotect(2) calls? I guess the application would have only itself to > blame so we don't care? Yes, that sounds right, How about /** * @write_protect_seq: Locked when any thread is write protecting * pages for COW in this mm, for instance during page table copying * for fork(). */ mprotect and shared mappings cause faults on write access not COW? Jason