Revert "Revert "mm/rmap: Fix anon_vma->degree ambiguity leading to double-reuse""

This reverts commit 4f35cec76058557d9eaec0d501d03c7657eb56b4 and does so
in an abi-safe way.

This is done by adding the new fields only to the end of the structure
and this structure is only passed around to other functions as a
pointer, the internal structure layout is only touched by the core
kernel, so adding it to the end is safe.

Update ABI using The Button:

Leaf changes summary: 1 artifact changed
Changed leaf types summary: 1 leaf type changed
Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 0 Added function
Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable

'struct anon_vma at rmap.h:33:1' changed:
  type size changed from 832 to 960 (in bits)
  2 data member insertions:
    'unsigned long int num_children', at offset 832 (in bits) at rmap.h:74:1
    'unsigned long int num_active_vmas', at offset 896 (in bits) at rmap.h:76:1
  5406 impacted interfaces

Bug: 260678056
Bug: 253167854
Change-Id: Ib1d45625cbc2e0b21330ca3dc2aa7aff34666d31
Signed-off-by: Lee Jones <joneslee@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Lee Jones
2023-04-18 10:35:38 +01:00
parent a42b1b6119
commit e36eef3783
3 changed files with 57 additions and 34 deletions

View File

@@ -14860,7 +14860,7 @@
<return type-id='48b5725f'/>
</function-type>
<pointer-type-def type-id='2b7b3388' size-in-bits='64' id='14f24806'/>
<class-decl name='anon_vma' size-in-bits='832' is-struct='yes' visibility='default' filepath='include/linux/rmap.h' line='33' column='1' id='14f332cc'>
<class-decl name='anon_vma' size-in-bits='960' is-struct='yes' visibility='default' filepath='include/linux/rmap.h' line='33' column='1' id='14f332cc'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='root' type-id='a8f86cda' visibility='default' filepath='include/linux/rmap.h' line='34' column='1'/>
</data-member>
@@ -14871,13 +14871,19 @@
<var-decl name='refcount' type-id='49178f86' visibility='default' filepath='include/linux/rmap.h' line='43' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='608'>
<var-decl name='degree' type-id='f0981eeb' visibility='default' filepath='include/linux/rmap.h' line='51' column='1'/>
<var-decl name='degree' type-id='f0981eeb' visibility='default' filepath='include/linux/rmap.h' line='45' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='640'>
<var-decl name='parent' type-id='a8f86cda' visibility='default' filepath='include/linux/rmap.h' line='53' column='1'/>
<var-decl name='parent' type-id='a8f86cda' visibility='default' filepath='include/linux/rmap.h' line='47' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='704'>
<var-decl name='rb_root' type-id='6fe1603d' visibility='default' filepath='include/linux/rmap.h' line='65' column='1'/>
<var-decl name='rb_root' type-id='6fe1603d' visibility='default' filepath='include/linux/rmap.h' line='59' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='832'>
<var-decl name='num_children' type-id='7359adad' visibility='default' filepath='include/linux/rmap.h' line='74' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='896'>
<var-decl name='num_active_vmas' type-id='7359adad' visibility='default' filepath='include/linux/rmap.h' line='76' column='1'/>
</data-member>
</class-decl>
<pointer-type-def type-id='031a4ff0' size-in-bits='64' id='1507ee2a'/>
@@ -99212,27 +99218,27 @@
<subrange length='38' type-id='7ff19f0f' id='aa4ccdac'/>
</array-type-def>
<pointer-type-def type-id='2a275b06' size-in-bits='64' id='dae07608'/>
<class-decl name='page_vma_mapped_walk' size-in-bits='448' is-struct='yes' visibility='default' filepath='include/linux/rmap.h' line='227' column='1' id='dae3142b'>
<class-decl name='page_vma_mapped_walk' size-in-bits='448' is-struct='yes' visibility='default' filepath='include/linux/rmap.h' line='240' column='1' id='dae3142b'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='page' type-id='02f11ed4' visibility='default' filepath='include/linux/rmap.h' line='228' column='1'/>
<var-decl name='page' type-id='02f11ed4' visibility='default' filepath='include/linux/rmap.h' line='241' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='64'>
<var-decl name='vma' type-id='2ae08426' visibility='default' filepath='include/linux/rmap.h' line='229' column='1'/>
<var-decl name='vma' type-id='2ae08426' visibility='default' filepath='include/linux/rmap.h' line='242' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='128'>
<var-decl name='address' type-id='7359adad' visibility='default' filepath='include/linux/rmap.h' line='230' column='1'/>
<var-decl name='address' type-id='7359adad' visibility='default' filepath='include/linux/rmap.h' line='243' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='192'>
<var-decl name='pmd' type-id='6d5994d5' visibility='default' filepath='include/linux/rmap.h' line='231' column='1'/>
<var-decl name='pmd' type-id='6d5994d5' visibility='default' filepath='include/linux/rmap.h' line='244' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='256'>
<var-decl name='pte' type-id='e8d572d7' visibility='default' filepath='include/linux/rmap.h' line='232' column='1'/>
<var-decl name='pte' type-id='e8d572d7' visibility='default' filepath='include/linux/rmap.h' line='245' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='320'>
<var-decl name='ptl' type-id='cff2d845' visibility='default' filepath='include/linux/rmap.h' line='233' column='1'/>
<var-decl name='ptl' type-id='cff2d845' visibility='default' filepath='include/linux/rmap.h' line='246' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='384'>
<var-decl name='flags' type-id='f0981eeb' visibility='default' filepath='include/linux/rmap.h' line='234' column='1'/>
<var-decl name='flags' type-id='f0981eeb' visibility='default' filepath='include/linux/rmap.h' line='247' column='1'/>
</data-member>
</class-decl>
<function-type size-in-bits='64' id='dae66efd'>
@@ -138389,8 +138395,8 @@
<parameter type-id='02f11ed4' name='page' filepath='mm/util.c' line='735' column='1'/>
<return type-id='f57039f0'/>
</function-decl>
<function-decl name='page_mkclean' mangled-name='page_mkclean' filepath='mm/rmap.c' line='997' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='page_mkclean'>
<parameter type-id='02f11ed4' name='page' filepath='mm/rmap.c' line='997' column='1'/>
<function-decl name='page_mkclean' mangled-name='page_mkclean' filepath='mm/rmap.c' line='1001' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='page_mkclean'>
<parameter type-id='02f11ed4' name='page' filepath='mm/rmap.c' line='1001' column='1'/>
<return type-id='95e97e5e'/>
</function-decl>
<var-decl name='page_pinner_inited' type-id='237c0d27' mangled-name='page_pinner_inited' visibility='default' filepath='mm/page_pinner.c' line='59' column='1' elf-symbol-id='page_pinner_inited'/>

View File

@@ -42,13 +42,7 @@ struct anon_vma {
*/
atomic_t refcount;
/*
* Count of child anon_vmas and VMAs which points to this anon_vma.
*
* This counter is used for making decision about reusing anon_vma
* instead of forking new one. See comments in function anon_vma_clone.
*/
unsigned degree;
unsigned degree; /* ANDROID: KABI preservation, DO NOT USE! */
struct anon_vma *parent; /* Parent of this anon_vma */
@@ -63,6 +57,25 @@ struct anon_vma {
/* Interval tree of private "related" vmas */
struct rb_root_cached rb_root;
/*
* ANDROID: KABI preservation, it's safe to put these at the end of this structure as it's
* only passed by a pointer everywhere, the size and internal structures are local to the
* core kernel.
*/
#ifndef __GENKSYMS__
/*
* Count of child anon_vmas. Equals to the count of all anon_vmas that
* have ->parent pointing to this one, including itself.
*
* This counter is used for making decision about reusing anon_vma
* instead of forking new one. See comments in function anon_vma_clone.
*/
unsigned long num_children;
/* Count of VMAs whose ->anon_vma pointer points to this object. */
unsigned long num_active_vmas;
#endif
};
/*

View File

@@ -91,7 +91,8 @@ static inline struct anon_vma *anon_vma_alloc(void)
anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
if (anon_vma) {
atomic_set(&anon_vma->refcount, 1);
anon_vma->degree = 1; /* Reference for first vma */
anon_vma->num_children = 0;
anon_vma->num_active_vmas = 0;
anon_vma->parent = anon_vma;
/*
* Initialise the anon_vma root to point to itself. If called
@@ -199,6 +200,7 @@ int __anon_vma_prepare(struct vm_area_struct *vma)
anon_vma = anon_vma_alloc();
if (unlikely(!anon_vma))
goto out_enomem_free_avc;
anon_vma->num_children++; /* self-parent link for new root */
allocated = anon_vma;
}
@@ -208,8 +210,7 @@ int __anon_vma_prepare(struct vm_area_struct *vma)
if (likely(!vma->anon_vma)) {
vma->anon_vma = anon_vma;
anon_vma_chain_link(vma, avc, anon_vma);
/* vma reference or self-parent link for new root */
anon_vma->degree++;
anon_vma->num_active_vmas++;
allocated = NULL;
avc = NULL;
}
@@ -294,19 +295,19 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
anon_vma_chain_link(dst, avc, anon_vma);
/*
* Reuse existing anon_vma if its degree lower than two,
* that means it has no vma and only one anon_vma child.
* Reuse existing anon_vma if it has no vma and only one
* anon_vma child.
*
* Do not chose parent anon_vma, otherwise first child
* will always reuse it. Root anon_vma is never reused:
* Root anon_vma is never reused:
* it has self-parent reference and at least one child.
*/
if (!dst->anon_vma && src->anon_vma &&
anon_vma != src->anon_vma && anon_vma->degree < 2)
anon_vma->num_children < 2 &&
anon_vma->num_active_vmas == 0)
dst->anon_vma = anon_vma;
}
if (dst->anon_vma)
dst->anon_vma->degree++;
dst->anon_vma->num_active_vmas++;
unlock_anon_vma_root(root);
return 0;
@@ -356,6 +357,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
anon_vma = anon_vma_alloc();
if (!anon_vma)
goto out_error;
anon_vma->num_active_vmas++;
avc = anon_vma_chain_alloc(GFP_KERNEL);
if (!avc)
goto out_error_free_anon_vma;
@@ -376,7 +378,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
vma->anon_vma = anon_vma;
anon_vma_lock_write(anon_vma);
anon_vma_chain_link(vma, avc, anon_vma);
anon_vma->parent->degree++;
anon_vma->parent->num_children++;
anon_vma_unlock_write(anon_vma);
return 0;
@@ -408,7 +410,7 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
* to free them outside the lock.
*/
if (RB_EMPTY_ROOT(&anon_vma->rb_root.rb_root)) {
anon_vma->parent->degree--;
anon_vma->parent->num_children--;
continue;
}
@@ -416,7 +418,8 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
anon_vma_chain_free(avc);
}
if (vma->anon_vma)
vma->anon_vma->degree--;
vma->anon_vma->num_active_vmas--;
unlock_anon_vma_root(root);
/*
@@ -427,7 +430,8 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) {
struct anon_vma *anon_vma = avc->anon_vma;
VM_WARN_ON(anon_vma->degree);
VM_WARN_ON(anon_vma->num_children);
VM_WARN_ON(anon_vma->num_active_vmas);
put_anon_vma(anon_vma);
list_del(&avc->same_vma);