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 D46C4C54EED for ; Thu, 26 Jan 2023 08:33:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E36386B0071; Thu, 26 Jan 2023 03:33:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE5E26B0072; Thu, 26 Jan 2023 03:33:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD5986B0073; Thu, 26 Jan 2023 03:33:49 -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 BD7DB6B0071 for ; Thu, 26 Jan 2023 03:33:49 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8C7BF1A01DA for ; Thu, 26 Jan 2023 08:33:49 +0000 (UTC) X-FDA: 80396286978.23.EF7978A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf17.hostedemail.com (Postfix) with ESMTP id A960740008 for ; Thu, 26 Jan 2023 08:33:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ABHms4CN; spf=pass (imf17.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674722028; 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=GXjHHvrjlcVcmB5bHJQP/yQ5kg5FFZqE0yq1xQ++1Y0=; b=f3IhidLusifJtpK5FUDIifj6HjBZEEqImatmN5kLbDuaPKNA7rERTFPi9YhvUPIleIwQQ0 h02mBEA9CcsiJoY2w/SEDCAg9gWj+uKUkPtiL2BltNBzs6iBvIJ6JT0zLuN6F1sMoAtpkf xUa082m4BXW6JLUQujndyGVEO53sdEc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ABHms4CN; spf=pass (imf17.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674722028; a=rsa-sha256; cv=none; b=GIlYQ3D7/PwlBcs+VR7HFEMu7kNuq6Os20gxRIXn4rW2CwvZ1XvkjhR6ouHffCJq4Z8AFF 0q6JU1WJF1ZvON/Rl6+k7POCewZAvFvxB3EvK/OISuumgE60eDdVvkFy3J+lSjKMtJkvAA PnnlJQtqLdsMSSl3B1lyiocLPfIGvYw= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3790B2202A; Thu, 26 Jan 2023 08:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674722026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GXjHHvrjlcVcmB5bHJQP/yQ5kg5FFZqE0yq1xQ++1Y0=; b=ABHms4CN9xwdp1wySYh7Ha+4iKvgdgLyY817vvxympWKKpjd4FtbYJXz1UqMp61QoOakgF orpOb3DQ9IG8F1BgYLpol0LeI1Mx9g6yv0lDpERGyiEXoz8satqq0gDRT8yFoy4SspWG1T ymTUCHa4Wpt9gipgd/g/GKpYNaNwJDs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0FDA413A09; Thu, 26 Jan 2023 08:33:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SYJ1A+o60mPlOQAAMHmgww (envelope-from ); Thu, 26 Jan 2023 08:33:46 +0000 Date: Thu, 26 Jan 2023 09:33:45 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.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 Subject: Re: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions Message-ID: References: <20230125233554.153109-1-surenb@google.com> <20230125233554.153109-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230125233554.153109-3-surenb@google.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A960740008 X-Stat-Signature: h4mhh7qmo44ttsdrapwe1i6huaosrb7q X-Rspam-User: X-HE-Tag: 1674722027-354335 X-HE-Meta: U2FsdGVkX19MKDmGGbbrbvFEAhuNLtV36KlQbhWrIEjN9bdjColfxUqaurmpCp5YIIip70nYpeuc8JcOh29hN4M0rv5/NmceXulbohQRZR8Q2fBM6D8gHHWWhuGTaykv0GFRLAfy3oST22j1OaHJKvqJ2zzGoqNcxwQ1QVfQ8/pV5krAwZft4DhFtuhXz0TdPYpv7CroKbVh//7YpSyr4JXZ+GWCw7Ycy0rveI41OHxVxErMw1ufCnGCh5yze9tZxciwn2rxXKm7BRTUkJyaKUw8hLTB18j4pw/ZNQnMX5FC8sO4YMG5/qVTPmRaGOahrwFvmojXVo1NJXPNrg1pYhls4RVxdtCIY/hl/QmcERDvybeu5hsOd9vnJC2fp50D6twg/A7QWx4bnHBXGcNRGCZHy5HwFzco6lnyOsEViVTePkNdDQYLlVcZbb74FCb3KJ0nf5EZY14ue5x3o7PdRXN+4t2VZ10qdMU8Zqo3SWI2BL1v07tBJ5bWwHmh814pD+kTVbusz+SFLDAYJ3dy4zhp9fX8QwgInNH5ZxrITRMO7KmrMfKS2vJ1cENFODJsy1QD8kL8VZp+9hFw82EiVBseU40YNmfYWmezlkLD+tK8LXVb07uDBcJ8EQpeXv1gsglVN0a9YsGGPjTzOvt+JmD9XiRWmGtVu3qpXNrzkMJ3TIzZbWjAzWbNGxBKUgQoqyfITKBwra6c8DYgl92ZorIOGyjCeQUOCLVIdeYQ5qjkMuSnMBFxdfZ4bjbH9G2dG8mww4zoMUsST6kLoRVy/fBwhQIyybxpUGjGPrQbNTI+un3eEqUc9Ww9wiUhGRh3Vwq2MlAMCy2mcyw9XHNJYBIogZ1vzkdM8WEDMyWgFDHHSQyXwVbmSaF56SE+WmzWATuaJTK/qZ6wJL8tJQVeYvCBdUpTUJKdvfehgmtb+DJQRoAAjk1Zh2zszFtan+ZJz+h5F7NXRQO8JO0/Tbd gyY3bnQ1 1Rk/Zp5j2my/Wzz8oTVlBJaDLZ1ujdVlhGGFlvwYJBTzLx1Ndu01Ay0u/FSFz7BeHMRA50MapTKIPO5C6hSIxONDokagdu7DlSJV2IG+AVCpJEy9XOzAu+1xIMECQEllcWVzwRVd1b+gVRyhD6f0EiU/elwa8cWhoNDwaU0j/diZJwAy4feg7stBo83sGCbf0k99OLyHebOAhExWw5E9VkD18Z+H7jphi64Iqo6oQCECHfw/e7PURoowqZ6fBtuXJw9/ossYClijn98/b+we4j5wzyby4T4xMOX76eHf/p9sGqe0= 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 Wed 25-01-23 15:35:49, 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 with or without the proposed renaming (it seems we are not consistent on that much even in the core kernel - e.g. init_rwsem vs. mutex_init) Acked-by: Michal Hocko > --- > 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, > -- > 2.39.1 -- Michal Hocko SUSE Labs