From patchwork Fri Feb 5 16:54:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12070465 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 106F3C433E0 for ; Fri, 5 Feb 2021 16:53:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7DAB264EE0 for ; Fri, 5 Feb 2021 16:53:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DAB264EE0 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 2B0DE6B0075; Fri, 5 Feb 2021 11:53:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C1766B007B; Fri, 5 Feb 2021 11:53:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 023D76B0075; Fri, 5 Feb 2021 11:53:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id DBCAC6B0075 for ; Fri, 5 Feb 2021 11:53:41 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 99DB83626 for ; Fri, 5 Feb 2021 16:53:41 +0000 (UTC) X-FDA: 77784810642.03.duck19_100624c275e6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 74C8728A4E9 for ; Fri, 5 Feb 2021 16:53:41 +0000 (UTC) X-HE-Tag: duck19_100624c275e6 X-Filterd-Recvd-Size: 7807 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 16:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612544020; 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=45ThGTqfFb6/yx2k3kPs+btJTG2mPFONj9RwvqJLKYY=; b=O4JFbhd6PRJ25jNdPFlITDabnD1o+fb6w0t/Bab1z6MM99BOUim8Crya7GUNJqGBG9N0a8 rtl2QLhpIZEuf4LSaovOs/3PL2fDFlz7KQ+vnSnVs8xCAbh33y3NqmMUN0a0rxSPgv9p/C x2Juk+jCeEFAykVEnnhfUyAVFoa7mFo= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-C5mE1GZ-OPK_ctvhgZMQTA-1; Fri, 05 Feb 2021 11:53:39 -0500 X-MC-Unique: C5mE1GZ-OPK_ctvhgZMQTA-1 Received: by mail-qt1-f199.google.com with SMTP id w3so5659165qti.17 for ; Fri, 05 Feb 2021 08:53:39 -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=45ThGTqfFb6/yx2k3kPs+btJTG2mPFONj9RwvqJLKYY=; b=E7P3r++BPOoNi51SNH6eKb3yxX3s7GFZR3/Gjys/l1vtgCQNSTA2Oj/dgpbSZnMcAi cHKwq8j1DMXdaBqjQA4fYFuLO02dK1RGiZVwl4HzMy1GfDVKlEupHD+EjO7IVnx9Ezfk awHFzVtPUC0R/Qc2OlDIysL0GvJNZ76NF1M2PjkeD6qtpMQL2Qt4Ya5e2muorjkR8Z/G +iFLXxuHLNMtpq0OoQpHxZEn3CPK/6nDBeOOYzzEEPMRjVKogoMTU3F/PM3PCjsS7hYJ y+N107bC+Jjv5oKQOsEluGQtF9QnMdUaEwGnu+f9ji4zKNF0liSUMwenYC+ec78O+Fob 5zmw== X-Gm-Message-State: AOAM531fyMBi4p0U+UXfLOf3fE/gTBj0lkz2nyJmXmk6hcTOqJEE/tdb qqugPdWA/MVHwCLO+VU5APyb9iNhydEsn1AuhB8VB6JEJr/QBHWJ+e2XqKNbmpwCAUaov18Y3Zj HQsPTNo7i9dTtOygULoSXVXwowZ8n4h5mOH1ubSjAKoMyUlVJDR7stjoaUVqs X-Received: by 2002:a37:d01:: with SMTP id 1mr5220152qkn.247.1612544018364; Fri, 05 Feb 2021 08:53:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxioHYSeFu7FIORv42JUdT5KiGh790cz4iF+AF9w2tOueheZlZAI5UINMF2g+tHX8/8AUMikA== X-Received: by 2002:a37:d01:: with SMTP id 1mr5220104qkn.247.1612544018061; Fri, 05 Feb 2021 08:53:38 -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 12sm9618893qkg.39.2021.02.05.08.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 08:53:37 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Gal Pressman , Andrea Arcangeli , Christoph Hellwig , Miaohe Lin , Kirill Shutemov , Jann Horn , Matthew Wilcox , Jan Kara , Jason Gunthorpe , Linus Torvalds , Mike Rapoport , David Gibson , Mike Kravetz , peterx@redhat.com, Kirill Tkhai , Wei Zhang , Andrew Morton , VMware Graphics , Roland Scheidegger , David Airlie , Daniel Vetter , Alexey Dobriyan Subject: [PATCH v3 4/5] mm: Use is_cow_mapping() across tree where proper Date: Fri, 5 Feb 2021 11:54:05 -0500 Message-Id: <20210205165406.4655-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210205165406.4655-1-peterx@redhat.com> References: <20210205165406.4655-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 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 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 71ccec5c3817..620700f05ff4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3733,15 +3733,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; + 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,