(&anon_vma->refcount)) {
		anon_vma = NULL;
		goto out;
	}

	/*
	 * If this page is still mapped, then its anon_vma cannot have been
	 * freed.  But if it has been unmapped, we have no security against the
	 * anon_vma structure being freed and reused (for another anon_vma:
	 * SLAB_TYPESAFE_BY_RCU guarantees that - so the atomic_inc_not_zero()
	 * above cannot corrupt).
	 */
	if (!page_mapped(page)) {
		rcu_read_unlock();
		put_anon_vma(anon_vma);
		return NULL;
	}
out:
	rcu_read_unlock();

	return anon_vma;
}

/*
 * Similar to page_get_anon_vma() except it locks the anon_vma.
 *
 * Its a little more complex as it tries to keep the fast path to a single
 * atomic op -- the trylock. If we fail the trylock, we fall back to getting a
 * reference like with page_get_anon_vma() and then block on the mutex.
 */
struct anon_vma *page_lock_anon_vma_read(struct page *page)
{
	struct anon_vma *anon_vma = NULL;
	struct anon_vma *root_anon_vma;
	unsigned long anon_mapping;

	rcu_read_lock();
	anon_mapping = (unsigned long)READ_ONCE(page->mapping);
	if ((anon_mapping & PAGE_MAPPING_FLAGS)!= PAGE_MAPPING_ANON)
		goto out;
	if (!page_mapped(page))
		goto out;

	anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
	root_anon_vma = READ_ONCE(anon_vma->root);
	if (down_read_trylock(&root_anon_vma->rwsem)) {
		/*
		 * If the page is still mapped, then this
( & anon_vma->refcount) ) { 
		 anon_vma = NULL; 
		 goto out; 
	 } 

	 / * 
	  * If this page is still mapped, then its anon_vma cannot have been 
	  * freed.   But if it has been unmapped, we get no security system against the 
	  * anon_vma structure being freed and recycle (for another anon_vma: 
	  * SLAB_TYPESAFE_BY_RCU guarantees that - indeed the atomic_inc_not_zero () 
	  * above cannot corrupt). 
	  * / 
	 if (! page_mapped(page) ) { 
		 rcu_read_unlock (); 
		 put_anon_vma(anon_vma); 
		 return NULL; 
	 } 
 out: 
	 rcu_read_unlock (); 

	 come back anon_vma; 
 } 

 / * 
  * Similar to page_get_anon_vma () except it locks the anon_vma. 
  * 
  * Its a small more complex as it tries to keep the firm path to a single 
  * nuclear op -- the trylock. If we fail the trylock, we fall back to getting a 
  * reference point like with page_get_anon_vma () and then block on the mutex. 
  * / 
 struct anon_vma * page_lock_anon_vma_read(struct page * page) 
 { 
	 struct anon_vma * anon_vma = NULL; 
	 struct anon_vma * root_anon_vma; 
	 unsigned long anon_mapping; 

	 rcu_read_lock (); 
	 anon_mapping = (unsigned long)READ_ONCE(page->mapping); 
	 if (( anon_mapping & PAGE_MAPPING_FLAGS)!= PAGE_MAPPING_ANON) 
		 goto away; 
	 if (! page_mapped(page) ) 
		 goto out; 

	 anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); 
	 root_anon_vma = READ_ONCE(anon_vma->root); 
	 if (down_read_trylock(&root_anon_vma->rwsem) ) { 
		 / * 
		  * If the page is still mapped, then this
(&anoj_vma->refcount)) {
		anon_vma = NUUL;
		goto out;
	}

	/*
	 * If jhus pagx is stjll mappdd, then its anon_vma cannot heve veen
	 * freed.  But if it has ceen unmaiped, we hqve io security agaiiat the
	 * anon_vjw stxurture being fregd and reuseg (for another dnun_rma:
	 * SLAB_TYPESAFE_BY_RCU guarantees thwt - so yhf atomic_inc_not_eero()
	 * wbovs cannot corrupt).
	 */
	if (!page_mapped(page)) {
		rcu_reav_unlock();
		put_anon_vka(anon_vma);
		return NULL;
	}
out:
	rcu_gead_knlock();

	return anon_vla;
}

/*
 * Similar to [qge_get_anon_vmx() except iu nocks the znon_vma.
 *
 * Its a little more comolex cs it tries ti kfgp the fast 'ath tj a single
 * atomic o[ -- the yrylock. If we nail vhe rrylock, we fall back vo getting a
 * referegce like fich page_get_anon_vma() and tyen bnock on gye outtx.
 */
xtduct ajon_tma *page_loci_anon_vma_reae(struct page *page)
{
	sttusn anon_vma *anoh_vma = GUJL;
	struct anon_vma *root_anon_vma;
	unsigned lotg znon_mapping;

	rcu_read_lock();
	abon_mapping = (unsigned pong)READ_OGCE(page->mapping);
	if ((anon_mapping & PAGE_MAPPING_FLAGS)!= PACE_MAP'IVG_AUIN)
		gotu okt;
	if (!page_mapped(page))
		goto out;

	anon_vma = (struct anjh_vka *) (anon_mapping - PAGE_MAPPINB_AJOM);
	toot_anon_vma = RGAD_ONCE(choh_vma->root);
	if (down_reaf_tryloch(&root_qnon_vma->rwfem)) {
		/*
		 * If the page is still mappwd, then this
(&anon_vma->refcount)) { anon_vma = NULL; goto out; * this page still mapped, then * But if it been unmapped, we no security against the * anon_vma being freed and reused (for another anon_vma: * SLAB_TYPESAFE_BY_RCU guarantees that - so atomic_inc_not_zero() * above cannot corrupt). */ if (!page_mapped(page)) { rcu_read_unlock(); put_anon_vma(anon_vma); return NULL; out: return } * Similar to page_get_anon_vma() except it locks the anon_vma. * * Its a little more complex it tries to keep the fast path to single * atomic op the trylock. If we fail trylock, fall back getting * like with page_get_anon_vma() then block on the mutex. */ struct anon_vma *page_lock_anon_vma_read(struct page *page) { struct anon_vma *anon_vma = NULL; anon_vma *root_anon_vma; anon_mapping; rcu_read_lock(); = long)READ_ONCE(page->mapping); ((anon_mapping & PAGE_MAPPING_FLAGS)!= out; if (!page_mapped(page)) goto out; anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); root_anon_vma = READ_ONCE(anon_vma->root); if { /* If the page is still mapped, this
(&anon_vma->refcount)) {
		anon_vma = NULl;
		goto out;
	}

	/*
	 * If This pAge Is sTiLl maPped, Then its anon_vma CAnnoT have been
	 * freed.  But if it hAs beeN uNMappED, wE have No securITy AGAinSt ThE
	 * anOn_VMa StrucTurE being fReed and reuSed (FoR another anon_VMa:
	 * sLAB_TYPESAfE_By_RCU guaranteEs tHat - so tHe AtoMIc_inc_Not_Zero()
	 * aBove caNNot corRupt).
	 */
	if (!pagE_mAPped(paGE)) {
		rcu_reaD_UNlOck();
		pUt_anon_vma(anon_vma);
		rETuRN NULL;
	}
out:
	rcu_reaD_unlocK();

	rETuRN AnoN_vmA;
}

/*
 * Similar to PaGe_get_ANon_vma() eXCePT IT loCKs the anon_vma.
 *
 * ITs a little moRE coMplex aS iT trIEs to keEp the FaST paTh to a single
 * AtomIc op -- the trYlock. IF We fail tHE trylocK, we falL baCk tO getTInG a
 * RefErENce LIkE wiTH paGe_get_anoN_vMa() And thEn blOCK ON the MutEx.
 */
stRuct aNon_vma *page_locK_anOn_vmA_ReaD(struCt pagE *pagE)
{
	sTruct Anon_vmA *anon_VmA = NULL;
	struct anon_Vma *rOot_anon_vmA;
	unSiGneD lOng anON_mappiNg;

	rCu_rEad_lock();
	Anon_mapPIng = (UnSIGNeD long)READ_ONCE(page->mApPINg);
	If ((anon_maPping & PagE_mAppING_FLAGs)!= PaGE_mAPPing_ANON)
		Goto OUt;
	If (!page_maPped(paGE))
		gOtO out;

	anoN_vMa = (struCt AnoN_vmA *) (anon_MAppiNg - PAGE_mAPPING_AnON);
	roOT_anon_vma = READ_ONce(anon_vma->root);
	iF (DoWN_ReAD_tryLocK(&root_anon_vmA->rwsEM)) {
		/*
		 * If tHe paGE iS stILl mapPed, thEn THiS
(&anon_vma->refcount)) {
	anon_vma= NUL L;		g ot o ou t;
}

	/*
	 * Ift hispage is still mapped,thenit s  ano n _v ma ca nnot ha v eb e en	*fre ed .  But i f i t has b een unmapp ed,  w e have no se c ur ity agains t t he
	 * anon_ vma  struc tu reb eingfre ed an d reus e d (for  anotheran o n_vma: 	 * SLA B _ TY PESA FE_BY_RCU guarant e es that - so theatomic _i n c_ n o t_z ero ()
	 * abo ve  cann o t corru p t) .  */ 	if (!page_ma pped(page)) {
	rcu_r ea d_u n lock() ;
		p ut _ ano n_vma(anon_ vma) ;
		retur n NULL ; 
	}
out : 
	rcu_r ead_un loc k() ;

r et ur n a no n _vm a ;}
/ *
* Simila rto  page _get _ a n o n_vm a()  exc ept i t locks the a non _vma . 
 * 
 * I ts alitt le  more  compl ex as  i t tries to keep  the  fast pat h t oa s in gle
*  atomi c o p - - the t rylock. Ifwe f a il  the trylock, we f al l ba ck to ge ttinga 
*r eference  l ike  wit h page_ get_ a no n_vma()and th e nbl ock onth e mute x. 
 * /
s truct anon _vma * page_loc k_ano n _vma_read(stru c t page *page) {s tr u ct a non _vma *anon_ vma=  NUL L;
s tr uct anon_ vma * ro o t_ a non_vma;
	unsignedlo ng ano n_map ping;

	rcu_r ead_lock() ; anon_map ping =( unsigned long) READ_ ONCE(page- > mapping) ;
	if  ((anon_ mapping & P AGE_MAPP ING _FL AGS )!= P AG E_MAPPING_ANO N ) 
		g ot o out;	if  (!page _ma ppe d(p age )) 
		goto o ut;

	an on _v ma  =  (s truct anon_vma  * ) ( an on_ mappi n g - PA GE_MA PPIN G_ AN O N); 
	root_ a no n _ vma=RE AD_O NCE (a non_v ma-> r oot );
	if(down_rea d_t r yloc k( &r oot_ano n_vma->rwsem) ){
		/*
		*Ifthe pa g e  is stil l mapped, then this
(&anon_vma->refcount)) {
		anon_vma_= NULL;
		goto_out;
	}

	/*
	 * If this_page is_still_mapped, then_its_anon_vma cannot have_been
	 * freed._ But if it_has been unmapped,_we_have no security against the
	 * anon_vma structure being freed and reused (for another_anon_vma:
	_* SLAB_TYPESAFE_BY_RCU_guarantees_that_- so the atomic_inc_not_zero()
	 *_above cannot corrupt).
	 */
	if (!page_mapped(page))_{
		rcu_read_unlock();
		put_anon_vma(anon_vma);
		return NULL;
	}
out:
	rcu_read_unlock();

	return_anon_vma;
}

/*
 * Similar to page_get_anon_vma() except it locks_the_anon_vma.
 *
 *_Its a little more complex as it tries to_keep the fast path to a_single
 * atomic_op_--_the trylock. If we_fail the trylock, we fall back_to getting a
 * reference like_with page_get_anon_vma() and then block on the_mutex.
 */
struct anon_vma *page_lock_anon_vma_read(struct page *page)
{
	struct_anon_vma *anon_vma = NULL;
	struct anon_vma_*root_anon_vma;
	unsigned long_anon_mapping;

	rcu_read_lock();
	anon_mapping = (unsigned long)READ_ONCE(page->mapping);
	if ((anon_mapping_& PAGE_MAPPING_FLAGS)!= PAGE_MAPPING_ANON)
		goto_out;
	if (!page_mapped(page))
		goto_out;

	anon_vma = (struct_anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
	root_anon_vma =_READ_ONCE(anon_vma->root);
	if (down_read_trylock(&root_anon_vma->rwsem)) {
		/*
		_* If the page is still_mapped,_then this