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.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 BC40EC4363D for ; Thu, 24 Sep 2020 18:15:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 284C622208 for ; Thu, 24 Sep 2020 18:15:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="f8n3Prqh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 284C622208 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 412EB6B005C; Thu, 24 Sep 2020 14:15:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C3A86B005D; Thu, 24 Sep 2020 14:15:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9A66B0062; Thu, 24 Sep 2020 14:15:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id 17E8A6B005C for ; Thu, 24 Sep 2020 14:15:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C5DC6180AD806 for ; Thu, 24 Sep 2020 18:15:04 +0000 (UTC) X-FDA: 77298756528.04.mist38_5f01c3527161 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id A3859800CE98 for ; Thu, 24 Sep 2020 18:15:04 +0000 (UTC) X-HE-Tag: mist38_5f01c3527161 X-Filterd-Recvd-Size: 5586 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 18:15:04 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id c2so349500qkf.10 for ; Thu, 24 Sep 2020 11:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9NJQT1B3t3dYmrEGe9dnjwFh4ipeAAV2W/ZTEBMDE8E=; b=f8n3PrqhsiKL7Dh0x9lJKBPskIhVVKnftymIA3j9bRtyUJn1yT9Ddh01jjE8qhv4w9 S7naQXy5ZGI9k/u1NLWLhQcdFok6O2JH8wlPD4DCP1/qMp5CN34bFZ0kNNsuknoZYh/7 vaV8JTK0BwZpPCbXjhyNnp+0PvEpl7afAQPik0fVQbGILY+XsXzCpNwBvmfdJgBdRknn eLttNv4CfF7eaV/qUEkrAIhcwWbS20AKpw6TYaMO9wt2i47/GoLeqRqjJQIVq1R1/wfQ iGJzoeZSNBYk0kMVub/FO4BpDBNArQ0zq4i092o1xV2XISv1vh+o0Wu50B1ZCoQDQDgX oylg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9NJQT1B3t3dYmrEGe9dnjwFh4ipeAAV2W/ZTEBMDE8E=; b=TEicl2ISXeYU4BbmNJKIs2zHIWIWmAnceDLgr3rMmXRtaAwimI29pR4Sx/MplRAaxw DEo8lWjxZ89549rQ7TitZ2BruyOkIF4S4Nx9KrmdEvnDNvfr7/V9ZsbJ/eXMyYVL2Ee8 N/ayTebfnvzmNXoMEqRFk9Sjrzck5YgHx4QJsRM5/yIoyH3EzSoAB7kFhibcDYLvdF+c b06DhgLjNANNdgokbxmdMB1lA8XVjndhp+5nD8ZOgKeNQ6ECrGrWzg2t5MYTZf8y91JW KLU0mSSlsP2gwEdUAHTaNYqzryxpaali0XfaC+L4kOraWIUoALuZ+lG0Ms7QEPa35ba6 WaWA== X-Gm-Message-State: AOAM530mAW1SlDUwYJKCzOFe+mp/yMMq9Oklz2xVchip9q5oWBdFRyGG Lr+G4nMMesmg0P9SY/AiXMgh2w== X-Google-Smtp-Source: ABdhPJxtioWuLnfbPVJThKB4P6JwxJpFNgCu3TtJPTEAMHuHXT4ys9heysqu1otOGnY9NOS0o5s9MA== X-Received: by 2002:a37:68c7:: with SMTP id d190mr335280qkc.127.1600971303370; Thu, 24 Sep 2020 11:15:03 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id c11sm165844qkb.58.2020.09.24.11.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 11:15:02 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kLVll-000Pxz-Nv; Thu, 24 Sep 2020 15:15:01 -0300 Date: Thu, 24 Sep 2020 15:15:01 -0300 From: Jason Gunthorpe To: Peter Xu Cc: John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200924181501.GF9916@ziepe.ca> References: <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> <20200922151736.GD19098@xz-x1> <20200922161046.GB731578@ziepe.ca> <20200922175415.GI19098@xz-x1> <20200922191116.GK8409@ziepe.ca> <20200923002735.GN19098@xz-x1> <20200923170759.GA9916@ziepe.ca> <20200924143517.GD79898@xz-x1> <20200924165152.GE9916@ziepe.ca> <20200924175531.GH79898@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924175531.GH79898@xz-x1> 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 Thu, Sep 24, 2020 at 01:55:31PM -0400, Peter Xu wrote: > On Thu, Sep 24, 2020 at 01:51:52PM -0300, Jason Gunthorpe wrote: > > > Regarding the solution here, I think we can also cover read-only fast-gup too > > > in the future - IIUC what we need to do is to make it pte_protnone() instead of > > > pte_wrprotect(), then in the fault handler we should identify this special > > > pte_protnone() against numa balancing (change_prot_numa()). I think it should > > > work fine too, iiuc, because I don't think we should migrate a page at all if > > > it's pinned for any reason... > > [1] > > > > > With your COW breaking patch the read only fast-gup should break the > > COW because of the write protect, just like for the write side. Not > > seeing why we need to do something more? > > Consider this sequence of a parent process managed to fork() a child: > > buf = malloc(); > // RDONLY gup > pin_user_pages(buf, !WRITE); > // pte of buf duplicated on both sides > fork(); > mprotect(buf, WRITE); > *buf = 1; > // buf page replaced as cow triggered > > Currently when fork() we'll happily share a pinned read-only page with the > child by copying the pte directly. Why? This series prevents that, the page will be maybe_dma_pinned, so fork() will copy it. > As a summary: imho the important thing is we should not allow any kind of > sharing of any dma page, even it's pinned for read. Any sharing that results in COW. MAP_SHARED is fine, for instance My feeling for READ when FOLL_PIN is used GUP_fast will go to the slow path any time it sees a read-only page. The slow path will determine if it is read-only because it could be COW'd or read-only for some other reason Jason