Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3457650pxk; Mon, 21 Sep 2020 14:21:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwfO3w2e/o2vfGdnlVRRnuyPP6gm0XHxrKCVTzsXRbMlHYAjp+//H6BkM8+id+S3heu1XH X-Received: by 2002:a17:906:2786:: with SMTP id j6mr1456740ejc.73.1600723315367; Mon, 21 Sep 2020 14:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600723315; cv=none; d=google.com; s=arc-20160816; b=fDQtr6Kmc9fOvbSWyNLu5DlZC3vx65QEf1Hflzam4en7udEXgvtNUwMIeGRhvDP+RK DJE9pFlXECzEy3960B6OVrLzOuEIrkbj0vFOlA2iTv3apCMxtFFD+EuqWBC9gYTKx1Jk GQSIaeIvlj9ioOXJsA/kCMrnV9ygeIaluDWnbYh+5zr2IVqYgMU44bS8kMA8lPJx5m4h 4dzFdcFfBQVXpdEoOLdUKy//zksHlg6VFm1vC7z5ypg/jvvtl9CHQFxh9SIqkRVFBLAk ckAXpv8/lw3Yk394R9/V1/noTxWBwPIxrk0fvpMXtJPZkoDFd+v/y2rCDuppoMXxMs44 av7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gWLsY05lICNle2YhUQzZEkQ3xwxCbs5IFMyW9iOIK7U=; b=yeMMrJTsasI7hKQpxGeugsjKOxw1ZcAxkvirC5EyPmdmuw6iuqFbJWJmF+xtBMqjwM FBN2/29Xb6OihpcQ0Bmd8a2qKU5GKjOIPAFat7OScpSQFNJ7QeQLes8o/9AFGn8cF/El bVo4e5YebX0JlAZ8TZZ/wX+vjoMf8fz8/ma9hqAmk+Ro69d1n8A8CwRu1y8wQx6H/NSy 90/PWSLKM1fHBnDDD1uS7hiqU2QoOLlORbUvvvDhaN3oO1+bbWMoHc8ezQOHQJoFqn9Z eaKVREBbbDKTUOV7tQPanQTQ1/4vAMZiT15yl+pF9Mpxpw2xa7ABVn97eT+f2sG+TkZX hG8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cWzSK4Z1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si9314597edx.162.2020.09.21.14.21.32; Mon, 21 Sep 2020 14:21:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cWzSK4Z1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727474AbgIUVRx (ORCPT + 99 others); Mon, 21 Sep 2020 17:17:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58623 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727317AbgIUVRx (ORCPT ); Mon, 21 Sep 2020 17:17:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600723071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gWLsY05lICNle2YhUQzZEkQ3xwxCbs5IFMyW9iOIK7U=; b=cWzSK4Z1svVr/53IHI3nWRmxT6clDMU99WnwIYnOwzTcy2jcIqselApw76TT06wDLrr+Hd 2J0LBXMeVzzm4JSs9kCQGRkIKL5SwBV0/yOXFnWTCr8DrVzmbhWRYsuN3CSJ3z9Ete1NOL 5jqWIRcxT8TLqUvW579kH9xAEgaBFp4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-DY73P4UeNTqMxbH9ByI0cg-1; Mon, 21 Sep 2020 17:17:49 -0400 X-MC-Unique: DY73P4UeNTqMxbH9ByI0cg-1 Received: by mail-qk1-f198.google.com with SMTP id h191so12056998qke.1 for ; Mon, 21 Sep 2020 14:17:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gWLsY05lICNle2YhUQzZEkQ3xwxCbs5IFMyW9iOIK7U=; b=slEwNOH2UNPWkWEsB3AZYcQ3+YNQnEtOmxcjXmeEo7uZxIxE4+GUdr3q5exdYmAIaH He1paAnIXCUVziYTOU3gP7iVfjRBfdAO6CIgElYPDQLi6iSmIa9Q0XTCXSij0nsM52VT OoWDdbWBKC48Tsk9VneDaCHuDaW4OStArlYqm6IbuJDvHhW5bvBRElL2Y4dCn1PHiX73 0xeGBlC3sLtK80gfjTjB2WgVTpR+gM3UkE6KYpsctNVyPikCu/fDdD4Gq6W2hHEMCtqm QP1ZUexSTufWkzuieGPFaowVRHg4okVtSvpi6/0/mP/UVzUfvE3KdQnEhy1ZpGtDxYtc rcMA== X-Gm-Message-State: AOAM533A3LqlrhUrnIRhRFLDIilqm9Enepyu2yCTOstjY0nuuq2dFEvj VMR4uhRM2D1dGfk4zYQu174ui22+VZmIkjd5tYVOIC+BP3XWa4vvHlXBMSQbaoHYqbWPivO5V65 HaDMiy+0LO9O1LytTX8YzHEgE X-Received: by 2002:a05:620a:4107:: with SMTP id j7mr1630456qko.469.1600723067848; Mon, 21 Sep 2020 14:17:47 -0700 (PDT) X-Received: by 2002:a05:620a:4107:: with SMTP id j7mr1630433qko.469.1600723067537; Mon, 21 Sep 2020 14:17:47 -0700 (PDT) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id h68sm10225108qkf.30.2020.09.21.14.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 14:17:46 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jason Gunthorpe , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Peter Xu , Christoph Hellwig , Andrea Arcangeli , John Hubbard , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: [PATCH 0/5] mm: Break COW for pinned pages during fork() Date: Mon, 21 Sep 2020 17:17:39 -0400 Message-Id: <20200921211744.24758-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Finally I start to post formal patches because it's growing. And also sinc= e=0D we've discussed quite some issues already, so I feel like it's clearer on w= hat=0D we need to do, and how.=0D =0D This series is majorly inspired by the previous discussion on the list [1],= =0D starting from the report from Jason on the rdma test failure. Linus propos= ed=0D the solution, which seems to be a very nice approach to avoid the breakage = of=0D userspace apps that didn't use MADV_DONTFORK properly before. More informa= tion=0D can be found in that thread too.=0D =0D I believe the initial plan was to consider merging something like this for= =0D rc7/rc8. However now I'm not sure due to the fact that the code change in= =0D copy_pte_range() is probably more than expected, so it can be with some ris= k.=0D I'll leave this question to the reviewers...=0D =0D I tested it myself with fork() after vfio pinning a bunch of device pages, = and=0D I verified that the new copy pte logic worked as expected at least in the m= ost=0D general path. However I didn't test thp case yet because afaict vfio does = not=0D support thp backed dma pages. Luckily, the pmd/pud thp patch is much more= =0D straightforward than the pte one, so hopefully it can be directly verified = by=0D some code review plus some more heavy-weight rdma tests.=0D =0D Patch 1: Introduce mm.has_pinned (as single patch as suggested by Jaso= n)=0D Patch 2-3: Some slight rework on copy_page_range() path as preparation=0D Patch 4: Early cow solution for pte copy for pinned pages=0D Patch 5: Same as above, but for thp (pmd/pud).=0D =0D Hugetlbfs fix is still missing, but as planned, that's not urgent so we can= =0D work upon. Comments greatly welcomed.=0D =0D Thanks.=0D =0D Peter Xu (5):=0D mm: Introduce mm_struct.has_pinned=0D mm/fork: Pass new vma pointer into copy_page_range()=0D mm: Rework return value for copy_one_pte()=0D mm: Do early cow for pinned pages during fork() for ptes=0D mm/thp: Split huge pmds/puds if they're pinned when fork()=0D =0D include/linux/mm.h | 2 +-=0D include/linux/mm_types.h | 10 ++=0D kernel/fork.c | 3 +-=0D mm/gup.c | 6 ++=0D mm/huge_memory.c | 26 +++++=0D mm/memory.c | 226 +++++++++++++++++++++++++++++++++++----=0D 6 files changed, 248 insertions(+), 25 deletions(-)=0D =0D -- =0D 2.26.2=0D =0D