From patchwork Thu Jan 26 19:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13117652 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 427FBC61DA3 for ; Thu, 26 Jan 2023 19:38:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2DC96B007B; Thu, 26 Jan 2023 14:38:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C90276B007D; Thu, 26 Jan 2023 14:38:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABB748E0001; Thu, 26 Jan 2023 14:38:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9A35F6B007B for ; Thu, 26 Jan 2023 14:38:06 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4E4A84013E for ; Thu, 26 Jan 2023 19:38:06 +0000 (UTC) X-FDA: 80397960972.09.1BE40F7 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf12.hostedemail.com (Postfix) with ESMTP id 7BD9240006 for ; Thu, 26 Jan 2023 19:38:04 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hZNOyExz; spf=pass (imf12.hostedemail.com: domain of 3m9bSYwYKCLgqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3m9bSYwYKCLgqspclZemmejc.amkjglsv-kkitYai.mpe@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=1674761884; 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=zlALSRCxyJ0x7DG1bpOTgFUYMDutHYK+9H12DiNU8rs=; b=TUi2HfZKQ9b59fZqkE7Pa8rofgiWpLUJ/W9v6KP7C5EmxGk1GuqVeLcv+I7P6QQmCl/k9A fQoGfHOLwWx4SpppPPUEn/rct9ah1FouAZ4Z2Mn6NKJJ+5EiuuzOBXqSbpqsYIveh1CErJ Jdj5zNLyF6KueduD+atmFHWo7/YuhXM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hZNOyExz; spf=pass (imf12.hostedemail.com: domain of 3m9bSYwYKCLgqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3m9bSYwYKCLgqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674761884; a=rsa-sha256; cv=none; b=UsmP2nBBElL1W5YfMIfr9MQzEPBc6D+srmPiHaE3uyuxRKg2A8vBYV1IYcicnv335AqIhu pkjspZ9sUjo7nEO7GixweR112e38iP/9JIca5BbeAiWJiTlMwRrVhVCzpQC6Dbn/ihiFWc 602LnDpIxdzXRFbEZnI9y+s5lA4zIRA= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-506368dc06dso30961777b3.9 for ; Thu, 26 Jan 2023 11:38:04 -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=zlALSRCxyJ0x7DG1bpOTgFUYMDutHYK+9H12DiNU8rs=; b=hZNOyExz2CHhT7Lv8/1Oy+IakRoysLUTyaLrhwc6OvOl1RbVfyxPx8HhLjEmNLtcA/ BY0BX8hVwmwqOoBOAUbSQfgCR7McBjwSKMlnib3/r+Av8uTAud1UBhrmVG6TzF1g76mR nuKWivb9Q4wk66ty4yI9N1cosIfPbmFsheg2/502610l56CKG4QzLSoUZoExOYXjJCTQ j2mkcTGMWryRdUGvLYawFTWuoFK7ET78LKvwGsKOravZ5CcFDpVAFxFbBhoiYUfS0ekE vHIKanEeNQgRE6ZGBJnrux4jsyMuoU7VO1dgH6FWHeLmXl9fOCxu7UFXShpt7uDJ75T0 D5rg== 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=zlALSRCxyJ0x7DG1bpOTgFUYMDutHYK+9H12DiNU8rs=; b=jLKH8mDbl38+koswUO1lybW540rpwBd5CtbMG/2aFbH8tLxSyKQmF0bZol3w2xN9fX miIoje3tzJSO4tXB7oezXfb5JeznijrSQH2ERyUrVivA3mvBSaeQxgvXWPwJcs+dCOJw kBecueI6vlLNqObGswwJKddTOUNCzf2wDjYxz5Lch/tuaKHMbSbRoTOdmVszfnps+xtW MkzebqP5QmSatKrxv6iL+n4IxqCXhvIJe/mNbdT0jv9YRr+sTC4hjrKpmsdSgZH1cKve Xz5OxVLFo+XsuABIQK566PrVoK+ub58dbAfmMZdQazxdqzUyYAsGKBEm7o9UdrUnycV7 tc5A== X-Gm-Message-State: AO0yUKWGDFEaOWO01oOa8MS9JdgVo0D2TDu2ZZlZ6ghXhNfWNcywqhla utP/eQEWUZaEkgFYKZvwIjUS9LDcjfI= X-Google-Smtp-Source: AK7set+wPgjPE4jCPi3P5+z8aENnhk2aKoIt+MqVYJV+W2PRabPfSrmAUbfkb2zGPKmrtE86F6tpsEUUWTA= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:d774:88af:bab3:648d]) (user=surenb job=sendgmr) by 2002:a81:52ce:0:b0:506:60ca:21c3 with SMTP id g197-20020a8152ce000000b0050660ca21c3mr1424396ywb.197.1674761883577; Thu, 26 Jan 2023 11:38:03 -0800 (PST) Date: Thu, 26 Jan 2023 11:37:48 -0800 In-Reply-To: <20230126193752.297968-1-surenb@google.com> Mime-Version: 1.0 References: <20230126193752.297968-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230126193752.297968-4-surenb@google.com> Subject: [PATCH v4 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, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@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: rspam03 X-Stat-Signature: ymrwcm5eiag7ufd19spucak67p9onxwp X-Rspamd-Queue-Id: 7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lTcp/HWwDmfov1Oj5z+VLy1LOxGIEKnry3eXffVs0/hgSqR7vty/ziHJLzJxC8dg5fd2tNZQyBsq6HpQc94F09mE8FK8A9gJlK7VYZ8uowdfuv5r80zDTE1Ttlr00bJWHSpliCpiq0lXA0KFTN70peUEeldPNj4V01hAWz5NcAj+oCxTbh79gRt5wussb+yWOYKmEKx7i2tUMQyfGIN1I2peH+gQIaethJi/K0MnTbHCkjax9PRKylfuyiRsieA+y5hACsNDKIWAja2e9cxKm7YpTwSHzYJNwhLmYeNsShEd/l87BmguN7kalGjd5BeZrxft82B3EtKqpSNS7VzZgn3CryAlr8WIaUBw/TCSD8JIhr+5HIVPv4LwCVoJEMkNqXQxIvGyTX53z2DPNENzH4KSeMjQpJ0pcMwgCtEWp8o5t0gnW7UW0x2WpxUq7dj1t2Yskvgy4P31lVWfgfTjUlc66eupRNKg56RbBFOrGwW8U09oozXUGuICl8aktp8TILKkB/B14tI5mV5xY+v/FKys1RY1CVEEB2tFip0F/unPO8Dw0dnbCvSkPQbICp9Q+aJLx3Ol1ALQT/l51JS6BIiaowCdDYInj8+BBDNMQtieywjqxGe5G+xeyF9a/ORSvj0Vk1smui4/504q0z67QGaO0Dp2XwAX6Jqs1CuRTjztmVlNTnC9Z9grgnRmDEpRZ4wxVmxaXZsT5iHP6BgFTJVooPYn5bMzj9HMT8y2r4pb3XP2NBjdFhHXegAPnLqxH2NsF2N8D0NlDoaSWLdh8lIs1JIKPrlg9M+VN64uxAS2dImKWE9YMoxdz 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 vm_flags_clear(), 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: Mike Rapoport (IBM) Reviewed-by: Davidlohr Bueso --- 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 abb31103d060..ad4fdb9405ba 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 9260f975b8f4..5e3029ea8e1e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -659,7 +659,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); + vm_flags_clear(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 b6cbba105ffc..3a01a9dbf445 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6970,8 +6970,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..fa3cbd625850 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; + vm_flags_clear(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; + vm_flags_init(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..55157b990091 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; + vm_flags_clear(vma, VM_LOCKED_MASK); /* * anon_vma links of the old vma is no longer needed after its page