From patchwork Thu Feb 4 20:20:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12068601 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 B5246C433DB for ; Thu, 4 Feb 2021 20:21:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4662764F3F for ; Thu, 4 Feb 2021 20:21:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4662764F3F 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 A944D6B0006; Thu, 4 Feb 2021 15:21:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A6B756B006E; Thu, 4 Feb 2021 15:21:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EA396B0070; Thu, 4 Feb 2021 15:21:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 76E1D6B0006 for ; Thu, 4 Feb 2021 15:21:01 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2C28D180AD81D for ; Thu, 4 Feb 2021 20:21:01 +0000 (UTC) X-FDA: 77781704322.14.brain94_0c0f058275df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 0CC9E1822987A for ; Thu, 4 Feb 2021 20:21:01 +0000 (UTC) X-HE-Tag: brain94_0c0f058275df X-Filterd-Recvd-Size: 7837 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 20:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612470060; 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: in-reply-to:in-reply-to:references:references; bh=8RUhZ+EXApqGSb7+Tmq9sGFuKWAYlgVlaiJ/4jTiTkk=; b=BzsVl3ojZ0y0UeAhlRPXkbJlDE07gqnYRJ8mZw3On/zqTT0YzGi12wpsQwT8XqAQVfpqEt x9xvyyvgKUDt065VJgsJvjvXsUEG425Z3ey20gCnk2dLQTXFr8CtUvBY4UeNsJ6WhVrDhX NUPa1SZI7FxLRJJcgwH7GNKqKFb++jg= 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-559-f84aR7OKPXyAwI1FLR5nLg-1; Thu, 04 Feb 2021 15:20:58 -0500 X-MC-Unique: f84aR7OKPXyAwI1FLR5nLg-1 Received: by mail-qk1-f198.google.com with SMTP id 70so3743639qkh.4 for ; Thu, 04 Feb 2021 12:20:58 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=8RUhZ+EXApqGSb7+Tmq9sGFuKWAYlgVlaiJ/4jTiTkk=; b=jHhcwcr9X8phI23SDqMdkMgTcGkEE1x2v2EsLVAt7DwFK2yDzR3uFoZ7Ij9WVrhUqO 8o3yTYx2o7gu1N9ui/c0o8L3YTY84gQcfxtBe+BBwqvBzms2ldM7iL+MLC5Ra49JJTzX Bqxp8HOQWBFHIF0gXWdoqtHsnrjXHRubYPf3V8R6gAiKtP+tqmGzfM0gc7J/x0nhSQZ+ Z4CQbKfqd4Q/gmLG+g+TbXCD33b9ugle96V27LM8nehrTEeIn4zbF0vxrzgP5lYZ0Tat 8KpsCM1sEHTBYErtKwdocE/+lZcsquAB+x9k3CQ0sIhV9NHyOrCFVUVv2hRaKOJgFQhd wbag== X-Gm-Message-State: AOAM5334DsOUmfA/zwxdpxGjKL8E3J+UhoYOro+Dqx/1NYc4VU7ydPV8 TmkGGMWdEA65KVJFP12WlgQuylotOKqxPs+w4UaqRem6Si/KwcAs3o2dUjfhmGIvI5lsSqHN/Z0 5wqlwxqtMl3DguOOAhh1SfHmULqwoEwID+aU77d3aRmwDHtwZAtOwEBc+cGjw X-Received: by 2002:ae9:ef55:: with SMTP id d82mr991098qkg.243.1612470058182; Thu, 04 Feb 2021 12:20:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMrOpedoRrsIqyFMCtBNBcL9gayR8imVmM/6UmrovjTLeTt3NSZKJNQgK1fpK21QJITN0cvA== X-Received: by 2002:ae9:ef55:: with SMTP id d82mr991055qkg.243.1612470057866; Thu, 04 Feb 2021 12:20:57 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-20-174-93-89-182.dsl.bell.ca. [174.93.89.182]) by smtp.gmail.com with ESMTPSA id p18sm5990601qkj.130.2021.02.04.12.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:20:57 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , Jan Kara , Mike Rapoport , Andrew Morton , Christoph Hellwig , Kirill Tkhai , David Gibson , Jason Gunthorpe , Andrea Arcangeli , Miaohe Lin , Gal Pressman , Wei Zhang , Matthew Wilcox , Jann Horn , Linus Torvalds , peterx@redhat.com, Kirill Shutemov , VMware Graphics , Roland Scheidegger , David Airlie , Daniel Vetter , Alexey Dobriyan Subject: [PATCH v2 5/4] mm: Use is_cow_mapping() across tree where proper Date: Thu, 4 Feb 2021 15:20:55 -0500 Message-Id: <20210204202055.192260-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210204145033.136755-1-peterx@redhat.com> References: <20210204145033.136755-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: 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: After is_cow_mapping() is exported in mm.h, replace some manual checks elsewhere throughout the tree but start to use the new helper. Cc: VMware Graphics Cc: Roland Scheidegger Cc: David Airlie Cc: Daniel Vetter Cc: Mike Kravetz Cc: Alexey Dobriyan Cc: Andrew Morton Signed-off-by: Peter Xu --- drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 4 +--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 2 +- fs/proc/task_mmu.c | 2 -- mm/hugetlb.c | 4 +--- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c b/drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c index 0b76b3d17d4c..22c4a0e9d250 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c @@ -500,8 +500,6 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf, vm_fault_t ret; pgoff_t fault_page_size; bool write = vmf->flags & FAULT_FLAG_WRITE; - bool is_cow_mapping = - (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE; switch (pe_size) { case PE_SIZE_PMD: @@ -518,7 +516,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf, } /* Always do write dirty-tracking and COW on PTE level. */ - if (write && (READ_ONCE(vbo->dirty) || is_cow_mapping)) + if (write && (READ_ONCE(vbo->dirty) || is_cow_mapping(vma->vm_flags))) return VM_FAULT_FALLBACK; ret = ttm_bo_vm_reserve(bo, vmf); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c index 3c03b1746661..cb9975889e2f 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c @@ -49,7 +49,7 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_ops = &vmw_vm_ops; /* Use VM_PFNMAP rather than VM_MIXEDMAP if not a COW mapping */ - if ((vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) != VM_MAYWRITE) + if (!is_cow_mapping(vma->vm_flags)) vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP; return 0; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 602e3a52884d..96c1682025f9 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1036,8 +1036,6 @@ struct clear_refs_private { #ifdef CONFIG_MEM_SOFT_DIRTY -#define is_cow_mapping(flags) (((flags) & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE) - static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, pte_t pte) { struct page *page; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5793936e00ef..684d91b68b60 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3756,15 +3756,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, pte_t *src_pte, *dst_pte, entry, dst_entry; struct page *ptepage, *prealloc = NULL; unsigned long addr; - int cow; + int cow = is_cow_mapping(vma->vm_flags); struct hstate *h = hstate_vma(vma); unsigned long sz = huge_page_size(h); struct address_space *mapping = vma->vm_file->f_mapping; struct mmu_notifier_range range; int ret = 0; - cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE; - if (cow) { mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, src, vma->vm_start,