From patchwork Wed Feb 17 23:35:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12092603 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 761D6C433E0 for ; Wed, 17 Feb 2021 23:36:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D90E600EF for ; Wed, 17 Feb 2021 23:36:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D90E600EF 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 4EBEB6B0071; Wed, 17 Feb 2021 18:36:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DBDC8D0001; Wed, 17 Feb 2021 18:36:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DD1A6B0073; Wed, 17 Feb 2021 18:36:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id 03EA66B0071 for ; Wed, 17 Feb 2021 18:36:00 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C83718249980 for ; Wed, 17 Feb 2021 23:36:00 +0000 (UTC) X-FDA: 77829370080.12.504B752 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 43AF0407F8DB for ; Wed, 17 Feb 2021 23:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613604959; 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=bBTLGivaN2/sd96zZsp336IcNgBMJM5xgqwCgvKU+2Q=; b=c5Cr/i0hcbZIfRoEUgCVLusJ0dS6q1CIGoUo3kxcUuifPnwAsQD7Jf65w835/68kZ7YRlE kjTL+FaQbWTyopYWc9YhExEpuB5evQ143WVqVIRkeDKyx8XIoxTlGzHS7hqA41hE9hNFCA TLZwfL7qJD7dJ0S2FgoUGDmHalneLjY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-7oPZlBCsN_-4EjCuSgOWvg-1; Wed, 17 Feb 2021 18:35:58 -0500 X-MC-Unique: 7oPZlBCsN_-4EjCuSgOWvg-1 Received: by mail-qv1-f69.google.com with SMTP id j6so72232qvo.11 for ; Wed, 17 Feb 2021 15:35:57 -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=bBTLGivaN2/sd96zZsp336IcNgBMJM5xgqwCgvKU+2Q=; b=XY1LCcIQ7EQFTJkwwdX38MRJKcuAYeNtntPtzSXQthx+wAD7ev+MwDGX8gnfmREsA5 04NFT/onV+sz6ANmBjA4YMk/9IIFRJy8X5WE2sEihXwIYO7cM3VrmdVl6hwxqQXNyblK 86oizn/CFGM8/mD77uZX/6Ec+XGAG++rA/K25C0sxc6ZDc8Rxb6fwKf7t0oDvAtQmxhx oD99CyiqWLz+8MqsKswk6NpIRxK1ubb6zANpUz7gKWwIgrhHuIVtYt27Bl29lNTIJSr4 AjcigU2Z9nqehxL1cNACyYFeDlWCVT8OVgQ/svkN/FPdsaWZnW1brXQo75jP6oYmuccg YX1w== X-Gm-Message-State: AOAM530G9OxEkNTjd1iuB3nVyL8xFLq5KXhxlyAmOIeXg8YU95MuscMk aA7scgn5SeLYBLliVNvZ1Q+hkbGDNoq7H/1N77QY3QIX0d9cQkzKTcw83t16dPqARxQLpa8hfxD aE83yuqOY6Q7zcm+BkDmvBYpyJzfPyKpCAss9c8GOXQzSyymtIgHsl/hneOJE X-Received: by 2002:a05:622a:183:: with SMTP id s3mr1751836qtw.223.1613604956727; Wed, 17 Feb 2021 15:35:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCH2IIJVdVsOH2LNlUl1Ovh4tC3TAN8kSvtARyw6G8f10CuUr38qe/cCGqM2ng0NiVxAXCwQ== X-Received: by 2002:a05:622a:183:: with SMTP id s3mr1751793qtw.223.1613604956479; Wed, 17 Feb 2021 15:35:56 -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 o5sm2739622qkh.59.2021.02.17.15.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 15:35:56 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Gal Pressman , Matthew Wilcox , Wei Zhang , peterx@redhat.com, Mike Kravetz , Mike Rapoport , Christoph Hellwig , Andrew Morton , Linus Torvalds , David Gibson , Jason Gunthorpe , Jann Horn , Kirill Tkhai , Kirill Shutemov , Miaohe Lin , Andrea Arcangeli , Jan Kara , VMware Graphics , Roland Scheidegger , David Airlie , Daniel Vetter , Alexey Dobriyan Subject: [PATCH v5 4/5] mm: Use is_cow_mapping() across tree where proper Date: Wed, 17 Feb 2021 18:35:46 -0500 Message-Id: <20210217233547.93892-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217233547.93892-1-peterx@redhat.com> References: <20210217233547.93892-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-Stat-Signature: rmfosu8ooc4i7ezkixj5whj47cmoj4n4 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 43AF0407F8DB Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613604957-863849 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 Reviewed-by: Jason Gunthorpe 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 0a900afc66ff..45c9c6a7f1d6 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 3cec6fbef725..e862cab69583 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 2ba4ea4ab46e..8379224e1d43 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3731,15 +3731,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; unsigned long addr; - int cow; + bool 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,