Skip to content

Commit ca6eb14

Browse files
xzpetertorvalds
authored andcommitted
mm: use is_cow_mapping() across tree where proper
After is_cow_mapping() is exported in mm.h, replace some manual checks elsewhere throughout the tree but start to use the new helper. Link: https://lkml.kernel.org/r/20210217233547.93892-5-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Jason Gunthorpe <jgg@ziepe.ca> Cc: VMware Graphics <linux-graphics-maintainer@vmware.com> Cc: Roland Scheidegger <sroland@vmware.com> Cc: David Airlie <airlied@linux.ie> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: David Gibson <david@gibson.dropbear.id.au> Cc: Gal Pressman <galpress@amazon.com> Cc: Jan Kara <jack@suse.cz> Cc: Jann Horn <jannh@google.com> Cc: Kirill Shutemov <kirill@shutemov.name> Cc: Kirill Tkhai <ktkhai@virtuozzo.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Wei Zhang <wzam@amazon.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 97a7e47 commit ca6eb14

File tree

4 files changed

+3
-9
lines changed

4 files changed

+3
-9
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,6 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
500500
vm_fault_t ret;
501501
pgoff_t fault_page_size;
502502
bool write = vmf->flags & FAULT_FLAG_WRITE;
503-
bool is_cow_mapping =
504-
(vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
505503

506504
switch (pe_size) {
507505
case PE_SIZE_PMD:
@@ -518,7 +516,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
518516
}
519517

520518
/* Always do write dirty-tracking and COW on PTE level. */
521-
if (write && (READ_ONCE(vbo->dirty) || is_cow_mapping))
519+
if (write && (READ_ONCE(vbo->dirty) || is_cow_mapping(vma->vm_flags)))
522520
return VM_FAULT_FALLBACK;
523521

524522
ret = ttm_bo_vm_reserve(bo, vmf);

drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
4949
vma->vm_ops = &vmw_vm_ops;
5050

5151
/* Use VM_PFNMAP rather than VM_MIXEDMAP if not a COW mapping */
52-
if ((vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) != VM_MAYWRITE)
52+
if (!is_cow_mapping(vma->vm_flags))
5353
vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
5454

5555
return 0;

fs/proc/task_mmu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,6 @@ struct clear_refs_private {
10361036

10371037
#ifdef CONFIG_MEM_SOFT_DIRTY
10381038

1039-
#define is_cow_mapping(flags) (((flags) & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE)
1040-
10411039
static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
10421040
{
10431041
struct page *page;

mm/hugetlb.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,15 +3734,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
37343734
pte_t *src_pte, *dst_pte, entry, dst_entry;
37353735
struct page *ptepage;
37363736
unsigned long addr;
3737-
int cow;
3737+
bool cow = is_cow_mapping(vma->vm_flags);
37383738
struct hstate *h = hstate_vma(vma);
37393739
unsigned long sz = huge_page_size(h);
37403740
struct address_space *mapping = vma->vm_file->f_mapping;
37413741
struct mmu_notifier_range range;
37423742
int ret = 0;
37433743

3744-
cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
3745-
37463744
if (cow) {
37473745
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, src,
37483746
vma->vm_start,

0 commit comments

Comments
 (0)