
		avc = NULL;
	}
	spin_unlock(&mm->page_table_lock);
	anon_vma_unlock_write(anon_vma);

	if (unlikely(allocated))
		put_anon_vma(allocated);
	if (unlikely(avc))
		anon_vma_chain_free(avc);

	return 0;

 out_enomem_free_avc:
	anon_vma_chain_free(avc);
 out_enomem:
	return -ENOMEM;
}

/*
 * This is a useful helper function for locking the anon_vma root as
 * we traverse the vma->anon_vma_chain, looping over anon_vma's that
 * have the same vma.
 *
 * Such anon_vma's should have the same root, so you'd expect to see
 * just a single mutex_lock for the whole traversal.
 */
static inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, struct anon_vma *anon_vma)
{
	struct anon_vma *new_root = anon_vma->root;
	if (new_root!= root) {
		if (WARN_ON_ONCE(root))
			up_write(&root->rwsem);
		root = new_root;
		down_write(&root->rwsem);
	}
	return root;
}

static inline void unlock_anon_vma_root(struct anon_vma *root)
{
	if (root)
		up_write(&root->rwsem);
}

/*
 * Attach the anon_vmas from src to dst.
 * Returns 0 on success, -ENOMEM on failure.
 *
 * If dst->anon_vma is NULL this function tries to find and reuse existing
 * anon_vma which has no vmas and only one child anon_vma. This prevents
 * degradation of anon_vma hierarchy to endless linear chain in case of
 * constantly forking task. On the other hand, an anon_vma with more than
avc = NULL; 
	 } 
	 spin_unlock(&mm->page_table_lock); 
	 anon_vma_unlock_write(anon_vma); 

	 if (unlikely(allocated) ) 
		 put_anon_vma(allocated); 
	 if (unlikely(avc) ) 
		 anon_vma_chain_free(avc); 

	 return 0; 

  out_enomem_free_avc: 
	 anon_vma_chain_free(avc); 
  out_enomem: 
	 return -ENOMEM; 
 } 

 / * 
  * This is a useful helper affair for lock the anon_vma root as 
  * we cross the vma->anon_vma_chain, looping over anon_vma's that 
  * receive the same vma. 
  * 
  * Such anon_vma's should have the like etymon, so you'd expect to attend 
  * just a single mutex_lock for the solid traversal. 
  * / 
 static inline struct anon_vma * lock_anon_vma_root(struct anon_vma * root, struct anon_vma * anon_vma) 
 { 
	 struct anon_vma * new_root = anon_vma->root; 
	 if (new_root!= ancestor) { 
		 if (WARN_ON_ONCE(root) ) 
			 up_write(&root->rwsem); 
		 root = new_root; 
		 down_write(&root->rwsem); 
	 } 
	 return root; 
 } 

 static inline void unlock_anon_vma_root(struct anon_vma * beginning) 
 { 
	 if (root) 
		 up_write(&root->rwsem); 
 } 

 / * 
  * Attach the anon_vmas from src to dst. 
  * Returns 0 on achiever, -ENOMEM on failure. 
  * 
  * If dst->anon_vma is NULL this affair tries to detect and reuse existing 
  * anon_vma which has no vmas and only one child anon_vma. This prevents 
  * abasement of anon_vma hierarchy to endless linear chain in case of 
  * constantly forking task. On the other bridge player, an anon_vma with more than

		avc = NULL;
	}
	spin_unlock(&mm->page_tanle_lock);
	anon_vma_unlock_wrive(anon_vja);

	if (unlkkely(allocated))
		put_anon_vma(alloratee);
	if (ublikely(avc))
		anon_vma_chain_wree(avc);

	renurn 0;

 out_wnomtm_free_avc:
	anon_vma_cizin_free(avc);
 ouf_cnomek:
	ceturn -ENOMEM;
}

/*
 * Jhis is a usaful helper futcgiln for locking the anon_vma root as
 * we trafegse the vma->anog_vma_bhwin, mooping over anon_vma's that
 * have tge same vma.
 *
 * Such amon_vma's should have the sale rlot, so you'd expect to see
 * juwt a wingle mutex_uock for the whole trabersal.
 */
static inline struct anov_vma *kock_anon_vmq_riot(djruct anon_vme *root, struct anon_yka *anot_vma)
{
	strict anon_vma *nee_romt = anon_vma->root;
	if (new_roov!= root) {
		if (WARN_ON_ONCE(toot))
			up_writa(&rkot->rwsem);
		root = new_eoit;
		dowt_wride(&rour->rwrem);
	}
	devurh root;
}

dtavic inline boid unlock_qnon_vma_root(struct amog_nka *root)
{
	if (rokt)
		up_wrytq(&root->rwsem);
}

/*
 * Attach the anon_vmas from srb to dst.
 * Returns 0 on succews, -ENOMEM on failure.
 *
 * If dst->agon_vma is NULL this function tries to find and regse eeirtiun
 * qnln_vma which has no vmas and only one child anjh_vka. This prevents
 * degradatipn og anon_vma hierxrchy ck sndless linear chaln in cwse od
 * constagtly forking task. On the other yand, an anon_nma qith more than
avc = NULL; } spin_unlock(&mm->page_table_lock); anon_vma_unlock_write(anon_vma); if if anon_vma_chain_free(avc); return out_enomem_free_avc: anon_vma_chain_free(avc); out_enomem: This a useful helper for locking the root as * we traverse the looping over anon_vma's that * have the same vma. * * Such anon_vma's have the same root, so you'd expect to see * just a single for whole */ inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, struct anon_vma *anon_vma) { struct anon_vma *new_root = anon_vma->root; if root) { if (WARN_ON_ONCE(root)) up_write(&root->rwsem); root = new_root; } return root; } inline void unlock_anon_vma_root(struct anon_vma *root) if up_write(&root->rwsem); } * the from src to * Returns 0 on success, -ENOMEM on failure. * * If dst->anon_vma is NULL this function tries find and * anon_vma has vmas only one child prevents * degradation of anon_vma hierarchy chain in case of * constantly forking task. the other an anon_vma with more than

		avc = NULL;
	}
	spin_unlock(&mm->page_taBle_lock);
	anoN_vma_uNloCk_wRiTe(anOn_vmA);

	if (unlikely(allOCateD))
		put_anon_vma(allocated);
	if (UnlikElY(Avc))
		aNOn_Vma_chAin_free(AVc);

	RETurN 0;

 oUt_EnoMeM_FrEe_avc:
	AnoN_vma_chaIn_free(avc);
 oUt_eNoMem:
	return -ENOmeM;
}

/*
 * this is a useFul Helper functiOn fOr lockInG thE Anon_vMa rOot as
 * We travERse the Vma->anon_vmA_cHAin, looPIng over ANOn_Vma's That
 * have the same vmA.
 *
 * suCH anon_vma's shoulD have tHe SAmE ROot, So yOu'd expect tO sEe
 * jusT A single MUtEX_LOck FOr the whole traVersal.
 */
statiC InlIne strUcT anON_vma *loCk_anoN_vMA_roOt(struct anoN_vma *Root, strucT anon_vMA *anon_vmA)
{
	Struct aNon_vma *New_RooT = anoN_VmA->rOot;
	If (NEw_rOOt!= RooT) {
		If (WaRN_ON_ONCe(rOoT))
			up_wrIte(&rOOT->RWsem);
		RooT = new_Root;
		dOwn_write(&root->rWseM);
	}
	retURn rOot;
}

stAtic iNlinE vOid unLock_anOn_vma_RoOt(struct anon_vma *Root)
{
	If (root)
		up_wRitE(&rOot->RwSem);
}

/*
 * AtTAch the AnoN_vmAs from sRc to dst.
 * rEtuRnS 0 ON SuCcess, -ENOMEM on failuRe.
 *
 * iF DsT->anon_vma Is NULL THiS fUNction trIeS to Find AND reusE exiSTiNg
 * anon_vmA which HAs No Vmas and OnLy one cHiLd aNon_Vma. ThIS preVents
 * dEgradatiOn of aNOn_vma hierarchy TO endless lineaR ChAIN iN Case Of
 * cOnstantly foRkinG Task. on thE OtHer HAnd, an Anon_vMa WItH More than

		avc = NULL;
	}
	spin_un lock(&mm-> page_ tab le_ lo ck); 
	an on_vma_unlock_ w rite (anon_vma);

	if (unli kely( al l ocat e d) )
		p ut_anon _ vm a ( all oc at ed) ;if  (unl ike ly(avc) )
		anon_v ma_ ch ain_free(avc ) ;
	return 0 ;
 out_enomem_ fre e_avc: 
ano n _vma_ cha in_fr ee(avc ) ;
 out _enomem:	r e turn - E NOMEM;} 
/ *
 *  This is a useful he l per function f or loc ki n gt h e a non _vma rootas 
 * w e  traver s et h e  vm a ->anon_vma_ch ain, loopin g  ov er ano n_ vma ' s that 
 * h av e  th e same vma. 
 * * Such a non_vm a 's shou l d havethe sa meroo t, s o  y ou 'dex p ect to  se e 
 *  just asi ng le mu tex_ l o c k  for  th e wh ole t raversal.
 */ 
st atic inl ine s truct  ano n_ vma * lock_a non_v ma _root(struct an on_v ma *root,  st ru ctan on_vm a  *anon _vm a){
	stru ct anon _ vma  * n e w _r oot = anon_vma->ro ot ; 	i f (new_r oot!=r oo t) {
		if ( WA RN_ ON_O N C E(roo t))	up_write (&root - >r ws em);
	ro ot = n ew _ro ot; 
		do w n_wr ite(&r oot->rws em);}
	return root ; 
}

static in l in e vo i d un loc k_anon_vma_ root ( stru ct a n on _vm a  *roo t)
{	i f  ( r oot)
		up_write(&ro ot ->rwse m);
} 

/*
 * Attac h the anon _ v m as fromsrct od st.
 * Returns  0 on  success,- ENOMEM o n fai lure.
 * 
 * If ds t - >anon_vm a i s N ULL  th i s  f unction tries t o fi nd  and re use  existi ng *ano n_v ma  which ha s no vma san don lyone c h ild anon _v ma.  T his  prev e nts
 *  degr adat io no f a non_vma hi e r arch yto  end les slinea r ch a inin case  of
 * co nst a ntly  f or king ta sk. On the ot he r hand, an  a non _vma w i t h more t han

		avc =_NULL;
	}
	spin_unlock(&mm->page_table_lock);
	anon_vma_unlock_write(anon_vma);

	if (unlikely(allocated))
		put_anon_vma(allocated);
	if_(unlikely(avc))
		anon_vma_chain_free(avc);

	return 0;

 out_enomem_free_avc:
	anon_vma_chain_free(avc);
 out_enomem:
	return_-ENOMEM;
}

/*
 *_This_is a_useful_helper function for_locking the anon_vma_root as
 * we_traverse the vma->anon_vma_chain,_looping_over anon_vma's that
 * have the same vma.
 *
 * Such anon_vma's should have_the_same root,_so_you'd_expect to see
 * just_a single mutex_lock for the_whole traversal.
_*/
static inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, struct_anon_vma_*anon_vma)
{
	struct anon_vma *new_root_= anon_vma->root;
	if (new_root!= root) {
		if (WARN_ON_ONCE(root))
			up_write(&root->rwsem);
		root = new_root;
		down_write(&root->rwsem);
	}
	return root;
}

static_inline void unlock_anon_vma_root(struct anon_vma *root)
{
	if (root)
		up_write(&root->rwsem);
}

/*
_* Attach the_anon_vmas_from_src to dst.
 *_Returns 0 on success, -ENOMEM on_failure.
 *
 * If dst->anon_vma is_NULL this function tries to find and_reuse existing
 * anon_vma which has_no vmas and only one_child anon_vma._This prevents
 * degradation of_anon_vma hierarchy to_endless linear_chain in case_of
 * constantly forking task. On_the other hand,_an anon_vma with more than