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.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 8EEC2C43461 for ; Mon, 14 Sep 2020 17:59:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB7F220757 for ; Mon, 14 Sep 2020 17:59:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P6Vqdnh1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB7F220757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0D43F6B0083; Mon, 14 Sep 2020 13:59:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08489900009; Mon, 14 Sep 2020 13:59:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9EA56B0088; Mon, 14 Sep 2020 13:59:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id D2A826B0083 for ; Mon, 14 Sep 2020 13:59:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 87927181AC9CB for ; Mon, 14 Sep 2020 17:59:52 +0000 (UTC) X-FDA: 77262430224.02.vase07_560a6ff2710a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 44C5B10097AA8 for ; Mon, 14 Sep 2020 17:59:52 +0000 (UTC) X-HE-Tag: vase07_560a6ff2710a X-Filterd-Recvd-Size: 5873 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 17:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600106391; 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: in-reply-to:in-reply-to:references:references; bh=M4BeGj8qrSLHzBiuCyEaRzQwXGJLwNAdZKd1NIrOwTs=; b=P6Vqdnh13DBdfK4oYubSA9Kbc3n2YtacuYBYYuhVROR5KDWjzDNbc8LnVXQaIgsbW6jEMK TSdgphx1p5yw+UpPGPg4OdIWDbiTLZoP1WtJBwqZ2XEjkK6r9BkxBRfaas+jrk9hLLAvwP NjErqWNHL0XRsLa1ohj3kf4XL4YfSso= 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-154-Y9raTaMyMum9HROUmT9e7g-1; Mon, 14 Sep 2020 13:59:49 -0400 X-MC-Unique: Y9raTaMyMum9HROUmT9e7g-1 Received: by mail-qk1-f198.google.com with SMTP id c19so715776qkk.20 for ; Mon, 14 Sep 2020 10:59:49 -0700 (PDT) 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=M4BeGj8qrSLHzBiuCyEaRzQwXGJLwNAdZKd1NIrOwTs=; b=ktK2fZmVH0RmiOSdolUOZK+5hesvEPeEw08IKO5JXqOWg7mZmMJ7WmrcfTVR2ruKVE a41PWQDPl32NsV+YdNA9szkMoPFHhoe5tooQ1afWtQJ5JtI1XqFdzYy7xor+P6qEMz60 QoEvkhtZds1jp8udoeJlH9Xg8R3rqGTsLzTnxdbYeNtJqX/lxGJaEf2V3YoYsdBKqe75 4BFG6gGZXUExvgSpLNj9WYsQDIdu9jWUesJBSb9cf/xIczFpxn1RG3/e0OSJECBtjS9t 5WTx0KHG90q5U0PIY74d6loVf+t5eUclax83AmfkcpPl1mKy/1euOe5sO8coBfpNKpFi WwlA== X-Gm-Message-State: AOAM5307YLO7ea99H3+aikZmzHHcyTp31KGNwGeh7NOGFxqdKgnZ2x7e +JviSKkr1LepWHlMg6jICUps8y3eqc9S6Cejb96nwwoTW42XIM6S/RC6AAIh7Gz+GsYT+5YHB4E LWUOOUekA7lo= X-Received: by 2002:ac8:47d4:: with SMTP id d20mr14107062qtr.199.1600106389168; Mon, 14 Sep 2020 10:59:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv44TvLU6fjE8PK/EtRbu1JBfOwZD+ZBNpTMAPsDYtxBlCrRWrenoBvrYnwY0ldJnUxmmvFg== X-Received: by 2002:ac8:47d4:: with SMTP id d20mr14107035qtr.199.1600106388849; Mon, 14 Sep 2020 10:59:48 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id h65sm13867323qtd.58.2020.09.14.10.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 10:59:48 -0700 (PDT) Date: Mon, 14 Sep 2020 13:59:46 -0400 From: Peter Xu To: Oleg Nesterov Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Maya B . Gokhale" , Linus Torvalds , Yang Shi , Marty Mcfadden , Kirill Shutemov , Jann Horn , Jan Kara , Kirill Tkhai , Andrea Arcangeli , Christoph Hellwig , Andrew Morton Subject: Re: [PATCH 3/4] mm/gup: Remove enfornced COW mechanism Message-ID: <20200914175946.GC30881@xz-x1> References: <20200821234958.7896-1-peterx@redhat.com> <20200821234958.7896-4-peterx@redhat.com> <20200914142722.GA21906@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200914142722.GA21906@redhat.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 44C5B10097AA8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Mon, Sep 14, 2020 at 04:27:24PM +0200, Oleg Nesterov wrote: > On 08/21, Peter Xu wrote: > > > > --- a/mm/gup.c > > +++ b/mm/gup.c > > @@ -381,22 +381,13 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, > > } > > > > /* > > - * FOLL_FORCE or a forced COW break can write even to unwritable pte's, > > - * but only after we've gone through a COW cycle and they are dirty. > > + * FOLL_FORCE can write to even unwritable pte's, but only > > + * after we've gone through a COW cycle and they are dirty. > > */ > > static inline bool can_follow_write_pte(pte_t pte, unsigned int flags) > > { > > - return pte_write(pte) || ((flags & FOLL_COW) && pte_dirty(pte)); > > -} > > - > > -/* > > - * A (separate) COW fault might break the page the other way and > > - * get_user_pages() would return the page from what is now the wrong > > - * VM. So we need to force a COW break at GUP time even for reads. > > - */ > > -static inline bool should_force_cow_break(struct vm_area_struct *vma, unsigned int flags) > > -{ > > - return is_cow_mapping(vma->vm_flags) && (flags & (FOLL_GET | FOLL_PIN)); > > + return pte_write(pte) || > > + ((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte)); > > Do we really need to add the FOLL_FORCE check back? > > Afaics, FOLL_COW is only possible if FOLL_FORCE was set. When I proposed the patch I wanted to add back FOLL_FORCE because the previous removing of FOLL_FORCE should be related to the enforced COW mechanism where FOLL_COW can definitely happen without FOLL_FORCE. So when we want to revert the enforced COW we definitely need to recover this check too as it was. I didn't think deeper than that. However now I'm a bit confused on why FOLL_COW must be with FOLL_FORCE even without the enforced COW... Shouldn't FOLL_COW be able to happen even without FOLL_FORCE (as long as when a page is shared, and the gup is with WRITE permission)? Not sure what I've missed, though. -- Peter Xu