From patchwork Wed Jan 25 23:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13116403 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 5B442C54E94 for ; Wed, 25 Jan 2023 23:36:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAA996B0078; Wed, 25 Jan 2023 18:36:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B35D46B007B; Wed, 25 Jan 2023 18:36:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 986C76B007D; Wed, 25 Jan 2023 18:36:05 -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 855556B0078 for ; Wed, 25 Jan 2023 18:36:05 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 619CCA0274 for ; Wed, 25 Jan 2023 23:36:05 +0000 (UTC) X-FDA: 80394931890.16.49A1518 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf12.hostedemail.com (Postfix) with ESMTP id 9F57F40005 for ; Wed, 25 Jan 2023 23:36:03 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qAP7Xe1j; spf=pass (imf12.hostedemail.com: domain of 34rzRYwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34rzRYwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@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=1674689763; 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=ijhDThbayE4MrjmcyJpQB4++KqDnXZSVkoWdTA6boxg=; b=xyt56GksuFdANJhT5KA4dJcZX32TgF2+Cuk3EyWffRVtQ0FeJPo5dNSPM9hMveX95Pqc4s j8MhwCJ8rtHGOvmSiuaCKzGsEfvs4L9tv1MKxnqTfDOwUfVNx8G9iiNPoFqUPUA26GZLbz bhcrXwEE9ukJTTFzpxdgJPWvdk1Cd54= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qAP7Xe1j; spf=pass (imf12.hostedemail.com: domain of 34rzRYwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34rzRYwYKCMc574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674689763; a=rsa-sha256; cv=none; b=DbDiVmyVqkv80UD+MSyKozDkw10heaoe5g91kq87E51WH91bP5Tvzb6j1X7NxHoOiHFu// 6aPegLfOgg71HuRQbOQGVwKEvwAsrL67XPJk59mfcly136n5WqmodGE22i57W4T6632aIs 4JPwIO9qRsCwd/fEUY5ZhTApu8VCtuw= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-506466c484fso1383187b3.13 for ; Wed, 25 Jan 2023 15:36:03 -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=ijhDThbayE4MrjmcyJpQB4++KqDnXZSVkoWdTA6boxg=; b=qAP7Xe1jWQ2v1pDyzimk/ucUXt6pJgnQPRMzULtUiXJ7miq94fdzWh3UQtS4ELXLXG xnRyMqJvJr9Qyw4fk8i3KNqyrHI6q9BE51NGUhcMbBkXiFN4EkWsXQg+sNncoZfFgpAd pmakogcOD7fawIoyB40GTMQKoodOtmE61jQOjn9IiPN2QveUdh02XHqNgo44qZ1Swkka UsHWmYnCHoE7T0et5kXrXIFTIL10ukIq3X3ayvz36CK5hAZd9JEO8xbOLC65b5H6U0Ms J3NS+Lumkoi4FpH2j3VjTovOoJdkWi+DW6xdc6JIqkzB0eqSo4KKNBbmC2JFmfQN4m9j cFgA== 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=ijhDThbayE4MrjmcyJpQB4++KqDnXZSVkoWdTA6boxg=; b=JfYCZR5E4BGJkwxFe4DPTuYYcXi/WOYNUlXfQaKo/4xJHSWK8l2vl8hJXGEHjUQ6sc 7TMrX6RsvkZ+1EJEP20od3U1pLs+Y/xa5z3+7Q0Y08IW0ltXlz5VeEcHiiLiRkswqgqf EayybjgniwXFqceW4qVqF2InOZrTzWmIjHd50EB0jofwcipa/IZkt0z53EEfHUARZeEK s0WL7s68k+f81C0i2AaJgkYwckXjp1ed0ah79pF0TIzr7naWnZ4GHLdj3MNI5AueSAxk ynu7qIjDeKp59gqcXCuFfQUR8nZAyZZy5e4dMewBf1Ko/2iyqNvdZVc3JAu88qEpr4+a Xqtw== X-Gm-Message-State: AFqh2kqETYt0OlYB9zanm1EO4R/lkbdpEM3TxVaan4MhKn9MaV6W7gT6 g4Se1iidblaZ33swraFX4BsL5tknQT8= X-Google-Smtp-Source: AMrXdXuKSNG6CNUWpJ2GxlW/S4CYhyc7M4Q5HmRRIO5iXM40geoKvk7b/ruVHPa4Ev+GXlDquQW3EuW1OFs= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f7b0:20e8:ce66:f98]) (user=surenb job=sendgmr) by 2002:a0d:ff42:0:b0:4e0:8133:2a5a with SMTP id p63-20020a0dff42000000b004e081332a5amr3780554ywf.187.1674689762692; Wed, 25 Jan 2023 15:36:02 -0800 (PST) Date: Wed, 25 Jan 2023 15:35:49 -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-3-surenb@google.com> Subject: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions 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: rspam03 X-Stat-Signature: k545ghna3ujzck1we55afdq56cqd4893 X-Rspamd-Queue-Id: 9F57F40005 X-HE-Tag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m5ra8aoh5nTn5ftCF6sbfvXgHkBYfeLbNGSgi7FM3b1BlupGwFQW6TInW9/tRBa3GcIrQlf71MGp5y0x4l/3JXzJwOi/a81L4bQJrldeTOV9UlVwCe12vBH6NK6vmzkdgC7h4+9Ur35DJKG5eo/UXJYURaYXtWWP3F12WKmN2G9K4yREnOm4MiE8Cs7q9vTfy5mDL8pM7Eie75i35d85IsxiBj1kSKdYKMD3Nua1eOPTgHWNNv00018U7nonTMx6HGwWUUXnEtjeg4/0y7VpU0XjgXxe0qW5zCXKimMXB5qvP0FBQm+XDbrhN1VezCdUYkQVthJUi2SDrTiLJLDXy4DPTSqdo5sbh1EyAvUfZqEueRO9MNnHyBb//wnhJ4NfDIwDEqvo1aanNH3eE3MZIV6cMv34yOz3I82SIHhHr/XNlk0RvTqV7MU5l4xR2lJ8qBKr/x+q5Y2V3UIeR7Iwo/APnydwiB4g1eigQJ1/l+ZE4KlQkZMEPZIIPaOlhNLF/fZ48CTZ0rUHZCBfrPGN/lMTZBxc899hTNWQ80stew+mSV9Z++LcotJQTmd5IbX1agN9fX+83IqH8WCWVZTaGHKEDrHkUkNhFYvCYGFeyrWdfTZ06ONbM= 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: vm_flags are among VMA attributes which affect decisions like VMA merging and splitting. Therefore all vm_flags modifications are performed after taking exclusive mmap_lock to prevent vm_flags updates racing with such operations. Introduce modifier functions for vm_flags to be used whenever flags are updated. This way we can better check and control correct locking behavior during these updates. Signed-off-by: Suren Baghdasaryan Acked-by: Michal Hocko Acked-by: Mel Gorman Reviewed-by: Davidlohr Bueso --- include/linux/mm.h | 37 +++++++++++++++++++++++++++++++++++++ include/linux/mm_types.h | 10 +++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index c2f62bdce134..bf16ddd544a5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -627,6 +627,43 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) INIT_LIST_HEAD(&vma->anon_vma_chain); } +/* Use when VMA is not part of the VMA tree and needs no locking */ +static inline void init_vm_flags(struct vm_area_struct *vma, + vm_flags_t flags) +{ + ACCESS_PRIVATE(vma, __vm_flags) = flags; +} + +/* Use when VMA is part of the VMA tree and modifications need coordination */ +static inline void reset_vm_flags(struct vm_area_struct *vma, + vm_flags_t flags) +{ + mmap_assert_write_locked(vma->vm_mm); + init_vm_flags(vma, flags); +} + +static inline void set_vm_flags(struct vm_area_struct *vma, + vm_flags_t flags) +{ + mmap_assert_write_locked(vma->vm_mm); + ACCESS_PRIVATE(vma, __vm_flags) |= flags; +} + +static inline void clear_vm_flags(struct vm_area_struct *vma, + vm_flags_t flags) +{ + mmap_assert_write_locked(vma->vm_mm); + ACCESS_PRIVATE(vma, __vm_flags) &= ~flags; +} + +static inline void mod_vm_flags(struct vm_area_struct *vma, + vm_flags_t set, vm_flags_t clear) +{ + mmap_assert_write_locked(vma->vm_mm); + ACCESS_PRIVATE(vma, __vm_flags) |= set; + ACCESS_PRIVATE(vma, __vm_flags) &= ~clear; +} + static inline void vma_set_anonymous(struct vm_area_struct *vma) { vma->vm_ops = NULL; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 2d6d790d9bed..bccbd5896850 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -491,7 +491,15 @@ struct vm_area_struct { * See vmf_insert_mixed_prot() for discussion. */ pgprot_t vm_page_prot; - unsigned long vm_flags; /* Flags, see mm.h. */ + + /* + * Flags, see mm.h. + * To modify use {init|reset|set|clear|mod}_vm_flags() functions. + */ + union { + const vm_flags_t vm_flags; + vm_flags_t __private __vm_flags; + }; /* * For areas with an address space and backing store,