@@ -140,50 +140,91 @@ static __always_inline void del_page_from_lru_list(struct page *page,
140140
141141#ifdef CONFIG_ANON_VMA_NAME
142142/*
143- * mmap_lock should be read-locked when calling vma_anon_name() and while using
144- * the returned pointer.
143+ * mmap_lock should be read-locked when calling anon_vma_name(). Caller should
144+ * either keep holding the lock while using the returned pointer or it should
145+ * raise anon_vma_name refcount before releasing the lock.
145146 */
146- extern const char * vma_anon_name (struct vm_area_struct * vma );
147+ extern struct anon_vma_name * anon_vma_name (struct vm_area_struct * vma );
148+ extern struct anon_vma_name * anon_vma_name_alloc (const char * name );
149+ extern void anon_vma_name_free (struct kref * kref );
147150
148- /*
149- * mmap_lock should be read-locked for orig_vma->vm_mm.
150- * mmap_lock should be write-locked for new_vma->vm_mm or new_vma should be
151- * isolated.
152- */
153- extern void dup_vma_anon_name (struct vm_area_struct * orig_vma ,
154- struct vm_area_struct * new_vma );
151+ /* mmap_lock should be read-locked */
152+ static inline void anon_vma_name_get (struct anon_vma_name * anon_name )
153+ {
154+ if (anon_name )
155+ kref_get (& anon_name -> kref );
156+ }
155157
156- /*
157- * mmap_lock should be write-locked or vma should have been isolated under
158- * write-locked mmap_lock protection.
159- */
160- extern void free_vma_anon_name ( struct vm_area_struct * vma );
158+ static inline void anon_vma_name_put ( struct anon_vma_name * anon_name )
159+ {
160+ if ( anon_name )
161+ kref_put ( & anon_name -> kref , anon_vma_name_free );
162+ }
161163
162- /* mmap_lock should be read-locked */
163- static inline bool is_same_vma_anon_name (struct vm_area_struct * vma ,
164- const char * name )
164+ static inline
165+ struct anon_vma_name * anon_vma_name_reuse (struct anon_vma_name * anon_name )
166+ {
167+ /* Prevent anon_name refcount saturation early on */
168+ if (kref_read (& anon_name -> kref ) < REFCOUNT_MAX ) {
169+ anon_vma_name_get (anon_name );
170+ return anon_name ;
171+
172+ }
173+ return anon_vma_name_alloc (anon_name -> name );
174+ }
175+
176+ static inline void dup_anon_vma_name (struct vm_area_struct * orig_vma ,
177+ struct vm_area_struct * new_vma )
178+ {
179+ struct anon_vma_name * anon_name = anon_vma_name (orig_vma );
180+
181+ if (anon_name )
182+ new_vma -> anon_name = anon_vma_name_reuse (anon_name );
183+ }
184+
185+ static inline void free_anon_vma_name (struct vm_area_struct * vma )
165186{
166- const char * vma_name = vma_anon_name (vma );
187+ /*
188+ * Not using anon_vma_name because it generates a warning if mmap_lock
189+ * is not held, which might be the case here.
190+ */
191+ if (!vma -> vm_file )
192+ anon_vma_name_put (vma -> anon_name );
193+ }
167194
168- /* either both NULL, or pointers to same string */
169- if (vma_name == name )
195+ static inline bool anon_vma_name_eq (struct anon_vma_name * anon_name1 ,
196+ struct anon_vma_name * anon_name2 )
197+ {
198+ if (anon_name1 == anon_name2 )
170199 return true;
171200
172- return name && vma_name && !strcmp (name , vma_name );
201+ return anon_name1 && anon_name2 &&
202+ !strcmp (anon_name1 -> name , anon_name2 -> name );
173203}
204+
174205#else /* CONFIG_ANON_VMA_NAME */
175- static inline const char * vma_anon_name (struct vm_area_struct * vma )
206+ static inline struct anon_vma_name * anon_vma_name (struct vm_area_struct * vma )
176207{
177208 return NULL ;
178209}
179- static inline void dup_vma_anon_name (struct vm_area_struct * orig_vma ,
180- struct vm_area_struct * new_vma ) {}
181- static inline void free_vma_anon_name (struct vm_area_struct * vma ) {}
182- static inline bool is_same_vma_anon_name (struct vm_area_struct * vma ,
183- const char * name )
210+
211+ static inline struct anon_vma_name * anon_vma_name_alloc (const char * name )
212+ {
213+ return NULL ;
214+ }
215+
216+ static inline void anon_vma_name_get (struct anon_vma_name * anon_name ) {}
217+ static inline void anon_vma_name_put (struct anon_vma_name * anon_name ) {}
218+ static inline void dup_anon_vma_name (struct vm_area_struct * orig_vma ,
219+ struct vm_area_struct * new_vma ) {}
220+ static inline void free_anon_vma_name (struct vm_area_struct * vma ) {}
221+
222+ static inline bool anon_vma_name_eq (struct anon_vma_name * anon_name1 ,
223+ struct anon_vma_name * anon_name2 )
184224{
185225 return true;
186226}
227+
187228#endif /* CONFIG_ANON_VMA_NAME */
188229
189230static inline void init_tlb_flush_pending (struct mm_struct * mm )
0 commit comments