From mboxrd@z Thu Jan 1 00:00:00 1970 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 D51CEC54EAA for ; Thu, 26 Jan 2023 19:42:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6740F6B0072; Thu, 26 Jan 2023 14:42:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64AB06B0073; Thu, 26 Jan 2023 14:42:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53A6E8E0001; Thu, 26 Jan 2023 14:42:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 44A2A6B0072 for ; Thu, 26 Jan 2023 14:42:33 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0FFAA120F05 for ; Thu, 26 Jan 2023 19:42:33 +0000 (UTC) X-FDA: 80397972186.22.0C8F7CD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 5F47A100015 for ; Thu, 26 Jan 2023 19:42:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UOR8SpJG; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674762151; 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=zE7LNwhWXZWas+LZ++xPOzlHliPmIbBXGVZ5uB2cL5E=; b=XpMFpQVwDTqVBQRwHNVJkEBOpEiKsvUMgTC3eTHqYCf87zd10mYXJ4b1CzPFFXyK0kOrv4 LFo5YjdssVtX67M59IGAAPNvQD9nzaarZmkewMNdRlSZ8oNoaDIZE4Yaz5dlIaTbI8B3Ig ehGPBUhuvGxmszjUNQiYn6HWxdCSbZ4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UOR8SpJG; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674762151; a=rsa-sha256; cv=none; b=g4NrN/a042jrTCosc+AhIOlkOTzuoAF91e3N+I/diPqhlyatWlYYi81K+cDrrTFqiPc2US /gp7Kya2Q0LQWZ+SC+HNF8bkRxWSXAzCRgQMf2DusFaBVjkxnj5Q/TuztIhMgt2uqc6IW/ KDvQcNlSWWKHlHCNlsxwHmSYKMJs6R8= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4FEA6618D3; Thu, 26 Jan 2023 19:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD75DC433EF; Thu, 26 Jan 2023 19:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674762149; bh=E0Awn8IrDI0cjsY1zBcnDnJ8/kHskzlyS2ZRlhbVGpM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UOR8SpJGBLgLCTbpFfWyABzoglOwWkVC4qJRpXwMyy8edq2U+IEetogeCxqMJORUL ITlr15BU3l4JyJpIzyGlxgIWpIxtCBzYYG/isBf5BBRviAFqo5RV2ZXv3hzbt8Jy8A fi8bCQ9hiE0NpulsRBz/XpA+dgRYmn+gvnB+zONjs+eJJs0AHxg6vEMaLbfkYU2ETm vbXycJ2kHYRY8NeQNaxsRJBqkCG0WGIdpk833PNIjQ/xBFcQ4NkNN0S3fRfUNO3HYg MIU2+pOOlnxz7zr9qwC1zq871fB0XOWKtA84xyaxjyohcEs5R3BSlVDTrd9nvE/dzb k33gM0+Rg4mMA== Date: Thu, 26 Jan 2023 21:42:05 +0200 From: Mike Rapoport To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, 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, 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 Subject: Re: [PATCH v4 2/7] mm: introduce vma->vm_flags wrapper functions Message-ID: References: <20230126193752.297968-1-surenb@google.com> <20230126193752.297968-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230126193752.297968-3-surenb@google.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5F47A100015 X-Stat-Signature: cibu1c3339wjxnen8nnu81en8eyw8m6i X-Rspam-User: X-HE-Tag: 1674762151-737253 X-HE-Meta: U2FsdGVkX19TKm9iL9Xv/JCqVaxzWtpaQd81o3SQC0bOQuAElzxxFL0sWOSmQixv/ZnKSoXGqH2XYQE6LzJ5lPlmIYnMkXXZ71mpF64iibqxaxjVs4U2rXw45Ynnu2aE48x8W4guZP7pIB4yp+S0wC29TiEnhzrrJDYyLQydSRtp66OayBACpiLBgrPWijdZFAbT238El1rN3+enZQxbXCqlGDl2BL12xGbDkCiSYu4ADxkcBOgI0eA7Ns0pPy4A0P+oknC1DJ/LdPXfVuMBT3E0pFQvOERDfl3aeMZGwOof81qIDjlSxnLug8TkjTzyjcqEXoIGYimMViMKlZpB8yJC1xlPKqFo18nfCFL9Xkp4RnxthGS/VUFO7we67zF+9fZs4AT31i40yrC9S93hsFMAp/3NaalktYKIUPMkoAoKLbiBiXye5HmEc6+OtuszEX7XQoBw5HkqhpnGuJY9OYjcN0nH5ad30lbuVDQTcDgtdUey6rOL+nQ8dl7rZuLhin73Yilli/fpQXYkO8etLsrzp6G8WHcxLR+nbPNmFwyEmxkJENnG3jV1DNx1z6Q/YCsK+l2dKqEizko9CpuxNJasanUbiFM9Mo5W8p5OYOUdKXPXZZgRBx7SzZLvbtPV8o8xeLZFRxbjWeQXiLykjMTsZvBglWSpdvYGS5IVl42heZPxFwO2pNmpJF7Q/eK6HZJvKV2XJJ5shzyfbSmDVtKkpl3wWz5+HwQQLamrGrnpQ8daC3kFfl1wOOQm53+vbeCCoeWiTqqcUyMrpC/KglvQx8ezS06lWfjKnqGl1W6qc1lw2biQhlSODfPoiKmrZ3yOud1UP0ZBmTMGWZtJIyROY8PcQPdtTbaPw5EbiULanyNGcZGy+7vnCTN11RuR/76GzSwei197n3ekovYnoNmn4wXletJZXhT/IouqGReulZCepNsh1STwA83GJoTnbuilv00SqOrHh2Q1NkR I/FdwuBE 1sOBux5lwelSlcVseRpL2B6G2FC8wL884+jBAr+HPN/VZpPWQbwwDB5+CRa3Adv0HVuSlwg1AmMKil5J8NUwDhVlnODSPFyzkSjLBJPLHIFCm8f8F/8YpOcjkobznJOQz91oRDe57XCTLVQ4Taz4UFIPxMGL6RHH4BrmUTZ6L0rhGX9VQxeCw2Hrzl3EM0ZyNJQ5KSWNMNJipHmXmJYSlSgOiZ0vaHgIoXwtyof5L0lXnIWwCfaueBirxTN86SXBXw4WGq1eYiLPLaaFoVBLiFgtgxxbVgtfsg0PlLqxnS8WmJn5aFwJvGwvXD5UAUxrWAVmOWr0VIo9uwIxk56m0uPUAS67pmHQbW5EymUb1+xT/LJyRBWKiwN5+k3HbFiF+mv5HRAIUYBsEVjUbkdPvSq1o5GiaawzYVqtLPGg9UK7ACTNoyWFGndtObVbdS5J0tQysqfwz0X79lmAIbBWDmgX7nIOu57qe6ieLf6BMOWDrZ1DG9lgofpaOmaD4EHRNuLNnH1gJGQD0HbebIKiEN9LUt83mv9tbGWRmQ58bMWA76Kg2htbAxwO+Wa75oLrhOthg3hg0oigYFSFKZsoLtcWymqI/5zISolkYt7Kja+7qxd8= 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: On Thu, Jan 26, 2023 at 11:37:47AM -0800, Suren Baghdasaryan wrote: > 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 > Reviewed-by: Davidlohr Bueso > Acked-by: Michal Hocko > Acked-by: Mel Gorman Acked-by: Mike Rapoport (IBM) > --- > include/linux/mm.h | 40 ++++++++++++++++++++++++++++++++++++++++ > include/linux/mm_types.h | 10 +++++++++- > 2 files changed, 49 insertions(+), 1 deletion(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 8d636e895ee9..abb31103d060 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -627,6 +627,46 @@ 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 vm_flags_init(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 vm_flags_reset(struct vm_area_struct *vma, > + vm_flags_t flags) > +{ > + mmap_assert_write_locked(vma->vm_mm); > + vm_flags_init(vma, flags); > +} > + > +static inline void vm_flags_set(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 vm_flags_clear(struct vm_area_struct *vma, > + vm_flags_t flags) > +{ > + mmap_assert_write_locked(vma->vm_mm); > + ACCESS_PRIVATE(vma, __vm_flags) &= ~flags; > +} > + > +/* > + * Use only when the order of set/clear operations is unimportant, otherwise > + * use vm_flags_{set|clear} explicitly. > + */ > +static inline void vm_flags_mod(struct vm_area_struct *vma, > + vm_flags_t set, vm_flags_t clear) > +{ > + mmap_assert_write_locked(vma->vm_mm); > + vm_flags_init(vma, (vma->vm_flags | set) & ~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..da983aedb741 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 vm_flags_{init|reset|set|clear|mod} functions. > + */ > + union { > + const vm_flags_t vm_flags; > + vm_flags_t __private __vm_flags; > + }; > > /* > * For areas with an address space and backing store, > -- > 2.39.1 > -- Sincerely yours, Mike.