From patchwork Wed Jan 25 23:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13116404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88D6FC54EED for ; Wed, 25 Jan 2023 23:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A9C36B007B; Wed, 25 Jan 2023 18:36:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 234556B007D; Wed, 25 Jan 2023 18:36:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC876B007E; Wed, 25 Jan 2023 18:36:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F15E46B007B for ; Wed, 25 Jan 2023 18:36:07 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9325440ADD for ; Wed, 25 Jan 2023 23:36:07 +0000 (UTC) X-FDA: 80394931974.30.E731E9B Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id BD041180012 for ; Wed, 25 Jan 2023 23:36:05 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qKTNUdAE; spf=pass (imf24.hostedemail.com: domain of 35LzRYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35LzRYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674689765; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OA1QItPelKW7nnImTBVBUTh9wI/to6l4+fxwxM8frdY=; b=bV5zF8Y8UrQ8iVIarJIGWgTCRO0iLrpR5C1oBE2XQU/8N9YmKl6juEYqjpC4bYleM2HXOz C4DbojKQ1XIafcRJd2NIQs03Xg+96Q/Hg3GeS9f5r94uUbi8JjIIq5HR2sv8CT5Y86OZdC LG+P8iEU+ajwAA50B4iIC9gEgvxZIdE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qKTNUdAE; spf=pass (imf24.hostedemail.com: domain of 35LzRYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35LzRYwYKCMk796t2qv33v0t.r310x29C-11zAprz.36v@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674689765; a=rsa-sha256; cv=none; b=0PAmYP6x7laRgBM1mmrf/ghVZVEJWiCnDZn/wrSnEH7suvR1DAIkoXHU4UdDAMsrYKhZ5F CNligMrJ8e0avOpIMjWgxdZSyWVHn/Z0DjW/l2nWVsSLaI4VOAqc3bDdUvb3epajMlDCqT Zj+v8P8cHmsd21+cYPhf/+EcqAWRh98= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-50660dd3263so1198017b3.19 for ; Wed, 25 Jan 2023 15:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OA1QItPelKW7nnImTBVBUTh9wI/to6l4+fxwxM8frdY=; b=qKTNUdAE5hQ5PW8YlcaPldCem1GoBjMxVuSpxQHrMcNXTaNxXEo9ic5ofsiINpZuP6 ScHyAOu97fOwye/7E0RytrIWyTmZtuYpGHexas2ZUlU78GVgNCJ5Ib52rIblrXezxJiw TcYv29usd8N/RWDMmKJi9sstdK9ZmfH6cJzonZBnFrolLr4Oc/OpQfbshtJe7FC750a+ 7l8uLIBYS3lt6k3WU5EvZGO7LsqtZmf2+KwUHbJbspvivzz3DpJFlYLtZA9KrX1vTT3B aFuBFc4GAVt3y4gqg31iYRfxy+FahLngHsaxL5dQYjjovRITn7XTVJi1/7iiLOG8GQEP u58w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OA1QItPelKW7nnImTBVBUTh9wI/to6l4+fxwxM8frdY=; b=NC3C+irC/n+jag8W9VRZhA+zY+K/U+ngBkPOzP22YR07RS9S/xcOjxzQu8K7cBbA9d H6TyBOaDfccwR/u3jthM2PWPApOG+u9uyhOKMOdwHub8ZEOU/4A9YF9dxDd5WpMFqon+ TjFoZOg3w/Hks0ZAvdKbs2C3KhXrA8+LDPo3QzfJDgIg2rztYAAXy76HlQcOGrNhl51O x4AbIiFUSCkmu/ExzeHWAVqCfIVJixIGpxK5i2+V2zx+eg8c7RcZXNC+nG6B6ewO6NYe iVJ6wUX58TsBFrr/VguIy2s6i/0t2jhgCauYUlHrvY0rWPqI4uClj3+h6Bq1YmKZobpL mVaw== X-Gm-Message-State: AO0yUKUXGJxtpRDlKco+ff/CHroQqku97lo3VwBZC/3731e/B5lGF0UN FUT4RWgG1vcqJ2lA1R9E8TKMhyq+BNo= X-Google-Smtp-Source: AK7set8NTS/dta8Ss2CDBh+UNbLavR6LoemLWoMd1vGrr7xSrGqUZ683FLbWYoBYEHndrOaWpiWo9YTijd4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f7b0:20e8:ce66:f98]) (user=surenb job=sendgmr) by 2002:a25:d1c7:0:b0:80b:6777:a2a0 with SMTP id i190-20020a25d1c7000000b0080b6777a2a0mr977883ybg.335.1674689764898; Wed, 25 Jan 2023 15:36:04 -0800 (PST) Date: Wed, 25 Jan 2023 15:35:50 -0800 In-Reply-To: <20230125233554.153109-1-surenb@google.com> Mime-Version: 1.0 References: <20230125233554.153109-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230125233554.153109-4-surenb@google.com> Subject: [PATCH v3 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BD041180012 X-Stat-Signature: jprow9nzeoj9xktnufy314ppxghj8xde X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b4Ni5b1AsSar2xB0UCQ25UjXBXNf1eju86YNGrYREOE+c5BvjkqMAwC5fM0kSQtZr07f5+RZ1YmJKBM/7jnp9pj0BcKCRcHgZEoLG6l+x3y3Wl94QaobSLdYPxqFic5Vp4OTnAbk2XEqVaJaEj+NjEy53yDulCyI9+Yx/9QQ+V7EYefIwaUQfe6XIqtPailTUcwltXyjsRDhNq8CnZU/VP1DuyEqSTbRw8cqbTKIvg3H67cgWZlr9EgN831/5FizCaZnRgH9gMOsmaw79dJ6N5O03suk43LPr0ylm3BmbkQxPR9oEPesy/fCJykHIHh54qSyg0SZiujCLAnaSmsl4NRAsfCuqmdDFZ1wLchIn8syb3hml/JB9q/oYM5R42s+8nyN0kJFB9il0OX5f2+k9pq2EPZffTIipvaqdfJ6zmkUTUDD5KhXjA6IK5ceNMChvZdnBzmen/2IlFTmPFOiDLgytqb+5ZcP4kvGC1LFc4lzoZaDIcDwACV3KMUNACulNKQZK4hOX1Y/tkmZiSj8PUYGZj9H3SFGqyB2lVjggklpibI0Ef0uCRRA8I5c+64kkWuZU0rrOp5O218oYwNbHuR3CFgiDINTBuQyWjejYycALJbYE5yFmx+3XKJwxPE52wjZ3WWqvgesgBDr75uTEH3lv7wtyZNUZgJEijs= 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: To simplify the usage of VM_LOCKED_CLEAR_MASK in clear_vm_flags(), replace it with VM_LOCKED_MASK bitmask and convert all users. Signed-off-by: Suren Baghdasaryan Acked-by: Michal Hocko Acked-by: Mel Gorman Acked-by: Mel Gorman --- include/linux/mm.h | 4 ++-- kernel/fork.c | 2 +- mm/hugetlb.c | 4 ++-- mm/mlock.c | 6 +++--- mm/mmap.c | 6 +++--- mm/mremap.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index bf16ddd544a5..cccbc2811827 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -421,8 +421,8 @@ extern unsigned int kobjsize(const void *objp); /* This mask defines which mm->def_flags a process can inherit its parent */ #define VM_INIT_DEF_MASK VM_NOHUGEPAGE -/* This mask is used to clear all the VMA flags used by mlock */ -#define VM_LOCKED_CLEAR_MASK (~(VM_LOCKED | VM_LOCKONFAULT)) +/* This mask represents all the VMA flag bits used by mlock */ +#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) /* Arch-specific flags to clear when updating VM flags on protection change */ #ifndef VM_ARCH_CLEAR diff --git a/kernel/fork.c b/kernel/fork.c index a531901859d9..4f097999a570 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -669,7 +669,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, tmp->anon_vma = NULL; } else if (anon_vma_fork(tmp, mpnt)) goto fail_nomem_anon_vma_fork; - tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT); + clear_vm_flags(tmp, VM_LOCKED_MASK); file = tmp->vm_file; if (file) { struct address_space *mapping = file->f_mapping; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d20c8b09890e..4ecdbad9a451 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6973,8 +6973,8 @@ static unsigned long page_table_shareable(struct vm_area_struct *svma, unsigned long s_end = sbase + PUD_SIZE; /* Allow segments to share if only one is marked locked */ - unsigned long vm_flags = vma->vm_flags & VM_LOCKED_CLEAR_MASK; - unsigned long svm_flags = svma->vm_flags & VM_LOCKED_CLEAR_MASK; + unsigned long vm_flags = vma->vm_flags & ~VM_LOCKED_MASK; + unsigned long svm_flags = svma->vm_flags & ~VM_LOCKED_MASK; /* * match the virtual addresses, permission and the alignment of the diff --git a/mm/mlock.c b/mm/mlock.c index 0336f52e03d7..5c4fff93cd6b 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -497,7 +497,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len, if (vma->vm_start != tmp) return -ENOMEM; - newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK; + newflags = vma->vm_flags & ~VM_LOCKED_MASK; newflags |= flags; /* Here we know that vma->vm_start <= nstart < vma->vm_end. */ tmp = vma->vm_end; @@ -661,7 +661,7 @@ static int apply_mlockall_flags(int flags) struct vm_area_struct *vma, *prev = NULL; vm_flags_t to_add = 0; - current->mm->def_flags &= VM_LOCKED_CLEAR_MASK; + current->mm->def_flags &= ~VM_LOCKED_MASK; if (flags & MCL_FUTURE) { current->mm->def_flags |= VM_LOCKED; @@ -681,7 +681,7 @@ static int apply_mlockall_flags(int flags) for_each_vma(vmi, vma) { vm_flags_t newflags; - newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK; + newflags = vma->vm_flags & ~VM_LOCKED_MASK; newflags |= to_add; /* Ignore errors */ diff --git a/mm/mmap.c b/mm/mmap.c index d4abc6feced1..323bd253b25a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2671,7 +2671,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm)) - vma->vm_flags &= VM_LOCKED_CLEAR_MASK; + clear_vm_flags(vma, VM_LOCKED_MASK); else mm->locked_vm += (len >> PAGE_SHIFT); } @@ -3340,8 +3340,8 @@ static struct vm_area_struct *__install_special_mapping( vma->vm_start = addr; vma->vm_end = addr + len; - vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY; - vma->vm_flags &= VM_LOCKED_CLEAR_MASK; + init_vm_flags(vma, (vm_flags | mm->def_flags | + VM_DONTEXPAND | VM_SOFTDIRTY) & ~VM_LOCKED_MASK); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_ops = ops; diff --git a/mm/mremap.c b/mm/mremap.c index 1b3ee02bead7..35db9752cb6a 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -687,7 +687,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (unlikely(!err && (flags & MREMAP_DONTUNMAP))) { /* We always clear VM_LOCKED[ONFAULT] on the old vma */ - vma->vm_flags &= VM_LOCKED_CLEAR_MASK; + clear_vm_flags(vma, VM_LOCKED_MASK); /* * anon_vma links of the old vma is no longer needed after its page