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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 8816DC433DB for ; Thu, 4 Feb 2021 23:20:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DAEA664FAD for ; Thu, 4 Feb 2021 23:20:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAEA664FAD 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 562C56B0006; Thu, 4 Feb 2021 18:20:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5142A6B006C; Thu, 4 Feb 2021 18:20:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 400956B006E; Thu, 4 Feb 2021 18:20:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 27B2C6B0006 for ; Thu, 4 Feb 2021 18:20:03 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E0792181AEF10 for ; Thu, 4 Feb 2021 23:20:02 +0000 (UTC) X-FDA: 77782155444.02.route62_540efd2275e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id BEB8C10097AA2 for ; Thu, 4 Feb 2021 23:20:02 +0000 (UTC) X-HE-Tag: route62_540efd2275e0 X-Filterd-Recvd-Size: 5010 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 23:20:02 +0000 (UTC) Received: by mail-qk1-f175.google.com with SMTP id r77so5143847qka.12 for ; Thu, 04 Feb 2021 15:20:02 -0800 (PST) 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=DJBAqOJIb2bK546eUomBLziWNsQdl9+DyYJ9LvCcAEY=; b=AdIuNlaAznLEic3h7nb6J5UFmUhLlTmFIx+P7W/VVAZIy6uKnlhP7k2mfFDbwo3Beo P3xT9UnKKOFe653iZY0vneLQtqYiAB4CoiDE8PGB9RoEiIcqgYA9Qn2FziXJRLPxM5G4 pZzyxg+xHsnPJRieFBz/YmgbZEE8D/oKFB1Wdx3gtN2K3tXD15xfbD9qYnmC02LnM8Rc QYFzYI1XtQnGCCMHoYouo0f+Ee3fSPX3CFOnFU51gUBz+cfeBx3NypC0lgXLF12jBqJe 4jXye5GtoDJHsiughq6M+xkqhyTJVygv+h50azgg43fTfOK93pvFktxCgYmT0btZe11T +65w== 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=DJBAqOJIb2bK546eUomBLziWNsQdl9+DyYJ9LvCcAEY=; b=nk1r1xDMr35kKNdQvISJrE4hhZYxNk4UOvvbZZr79kdwgDDstnDrlw+/CqYfgX5L9/ e39qztzlUy9OuzCn+leYF/SJ6dF3J/qFGvT4JmhAYlGqBC8k56BwS4nWlL6H8WjEHqEd MapIocmgLajOz+L2PK0rfrf8I96mTHwSEykPGcNoE2WQNkA/9Qn+CpCFK9E0LAqnMkzb FK5cvZIG+hKnRV07ZEL/iekF25V1nERTFeVGDpbN6wijrvNWXOcMB5xHAEztAkSzNNAv JKarXY7XwS/HrC9lo0FGFRbplcavnrCrd9NdpKzanThSZGA821mT4fHxq+6IObQo02IH 6t8g== X-Gm-Message-State: AOAM5338bwv0iXrJ5GB03VNzjUBw+ehX92IF2gnETcQzTJNB97l2Pn63 v50QtmDLMgrCgXCOpZ5PV+ZplQ== X-Google-Smtp-Source: ABdhPJxUA57wPycobe+FwcJXrI8gdQFRBo7XQFRm85rhupmZem2foImNoDNZ2Ljq7CooHWewWdzkFg== X-Received: by 2002:a05:620a:898:: with SMTP id b24mr1643689qka.269.1612480801680; Thu, 04 Feb 2021 15:20:01 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-115-133.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.115.133]) by smtp.gmail.com with ESMTPSA id z20sm6266353qki.93.2021.02.04.15.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 15:20:01 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1l7nuq-003e2a-NM; Thu, 04 Feb 2021 19:20:00 -0400 Date: Thu, 4 Feb 2021 19:20:00 -0400 From: Jason Gunthorpe To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kirill Shutemov , Wei Zhang , Mike Rapoport , Matthew Wilcox , Miaohe Lin , Andrea Arcangeli , Gal Pressman , Jan Kara , Jann Horn , Andrew Morton , Kirill Tkhai , Linus Torvalds , Mike Kravetz , David Gibson , Christoph Hellwig Subject: Re: [PATCH v2 3/4] mm: Introduce page_needs_cow_for_dma() for deciding whether cow Message-ID: <20210204232000.GG4718@ziepe.ca> References: <20210204145033.136755-1-peterx@redhat.com> <20210204145033.136755-4-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210204145033.136755-4-peterx@redhat.com> 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, Feb 04, 2021 at 09:50:32AM -0500, Peter Xu wrote: > We've got quite a few places (pte, pmd, pud) that explicitly checked against > whether we should break the cow right now during fork(). It's easier to > provide a helper, especially before we work the same thing on hugetlbfs. > > Since we'll reference is_cow_mapping() in mm.h, move it there too. Actually it > suites mm.h more since internal.h is mm/ only, but mm.h is exported to the > whole kernel. With that we should expect another patch to use is_cow_mapping() > whenever we can across the kernel since we do use it quite a lot but it's > always done with raw code against VM_* flags. > > Signed-off-by: Peter Xu > include/linux/mm.h | 21 +++++++++++++++++++++ > mm/huge_memory.c | 8 ++------ > mm/internal.h | 5 ----- > mm/memory.c | 7 +------ > 4 files changed, 24 insertions(+), 17 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index ecdf8a8cd6ae..6ea20721d349 100644 > +++ b/include/linux/mm.h > @@ -1291,6 +1291,27 @@ static inline bool page_maybe_dma_pinned(struct page *page) > GUP_PIN_COUNTING_BIAS; > } > > +static inline bool is_cow_mapping(vm_flags_t flags) > +{ It feels a bit more logical to pass in a struct vm_area_struct *' here? Jason