12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806 |
- #ifndef _LINUX_MM_H
- #define _LINUX_MM_H
- #include <linux/errno.h>
- #include <linux/mmdebug.h>
- #include <linux/gfp.h>
- #include <linux/bug.h>
- #include <linux/list.h>
- #include <linux/mmzone.h>
- #include <linux/rbtree.h>
- #include <linux/atomic.h>
- #include <linux/debug_locks.h>
- #include <linux/mm_types.h>
- #include <linux/mmap_lock.h>
- #include <linux/range.h>
- #include <linux/pfn.h>
- #include <linux/percpu-refcount.h>
- #include <linux/bit_spinlock.h>
- #include <linux/shrinker.h>
- #include <linux/resource.h>
- #include <linux/page_ext.h>
- #include <linux/err.h>
- #include <linux/page-flags.h>
- #include <linux/page_ref.h>
- #include <linux/overflow.h>
- #include <linux/sizes.h>
- #include <linux/sched.h>
- #include <linux/pgtable.h>
- #include <linux/kasan.h>
- #include <linux/page_pinner.h>
- #include <linux/memremap.h>
- #include <linux/android_kabi.h>
- struct mempolicy;
- struct anon_vma;
- struct anon_vma_chain;
- struct user_struct;
- struct pt_regs;
- extern int sysctl_page_lock_unfairness;
- void init_mm_internals(void);
- #ifndef CONFIG_NUMA
- extern unsigned long max_mapnr;
- static inline void set_max_mapnr(unsigned long limit)
- {
- max_mapnr = limit;
- }
- #else
- static inline void set_max_mapnr(unsigned long limit) { }
- #endif
- extern atomic_long_t _totalram_pages;
- static inline unsigned long totalram_pages(void)
- {
- return (unsigned long)atomic_long_read(&_totalram_pages);
- }
- static inline void totalram_pages_inc(void)
- {
- atomic_long_inc(&_totalram_pages);
- }
- static inline void totalram_pages_dec(void)
- {
- atomic_long_dec(&_totalram_pages);
- }
- static inline void totalram_pages_add(long count)
- {
- atomic_long_add(count, &_totalram_pages);
- }
- extern void * high_memory;
- extern int page_cluster;
- #ifdef CONFIG_SYSCTL
- extern int sysctl_legacy_va_layout;
- #else
- #define sysctl_legacy_va_layout 0
- #endif
- #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
- extern const int mmap_rnd_bits_min;
- extern const int mmap_rnd_bits_max;
- extern int mmap_rnd_bits __read_mostly;
- #endif
- #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
- extern const int mmap_rnd_compat_bits_min;
- extern const int mmap_rnd_compat_bits_max;
- extern int mmap_rnd_compat_bits __read_mostly;
- #endif
- #include <asm/page.h>
- #include <asm/processor.h>
- #ifndef untagged_addr
- #define untagged_addr(addr) (addr)
- #endif
- #ifndef __pa_symbol
- #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
- #endif
- #ifndef page_to_virt
- #define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x)))
- #endif
- #ifndef lm_alias
- #define lm_alias(x) __va(__pa_symbol(x))
- #endif
- #ifndef mm_forbids_zeropage
- #define mm_forbids_zeropage(X) (0)
- #endif
- #if BITS_PER_LONG == 64
- #define mm_zero_struct_page(pp) __mm_zero_struct_page(pp)
- static inline void __mm_zero_struct_page(struct page *page)
- {
- unsigned long *_pp = (void *)page;
-
- BUILD_BUG_ON(sizeof(struct page) & 7);
- BUILD_BUG_ON(sizeof(struct page) < 56);
- BUILD_BUG_ON(sizeof(struct page) > 96);
- switch (sizeof(struct page)) {
- case 96:
- _pp[11] = 0;
- fallthrough;
- case 88:
- _pp[10] = 0;
- fallthrough;
- case 80:
- _pp[9] = 0;
- fallthrough;
- case 72:
- _pp[8] = 0;
- fallthrough;
- case 64:
- _pp[7] = 0;
- fallthrough;
- case 56:
- _pp[6] = 0;
- _pp[5] = 0;
- _pp[4] = 0;
- _pp[3] = 0;
- _pp[2] = 0;
- _pp[1] = 0;
- _pp[0] = 0;
- }
- }
- #else
- #define mm_zero_struct_page(pp) ((void)memset((pp), 0, sizeof(struct page)))
- #endif
- #define MAPCOUNT_ELF_CORE_MARGIN (5)
- #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
- extern int sysctl_max_map_count;
- extern unsigned long sysctl_user_reserve_kbytes;
- extern unsigned long sysctl_admin_reserve_kbytes;
- extern int sysctl_overcommit_memory;
- extern int sysctl_overcommit_ratio;
- extern unsigned long sysctl_overcommit_kbytes;
- int overcommit_ratio_handler(struct ctl_table *, int, void *, size_t *,
- loff_t *);
- int overcommit_kbytes_handler(struct ctl_table *, int, void *, size_t *,
- loff_t *);
- int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *,
- loff_t *);
- #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
- #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
- #define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio))
- #else
- #define nth_page(page,n) ((page) + (n))
- #define folio_page_idx(folio, p) ((p) - &(folio)->page)
- #endif
- #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
- #define PAGE_ALIGN_DOWN(addr) ALIGN_DOWN(addr, PAGE_SIZE)
- #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE)
- #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
- static inline struct folio *lru_to_folio(struct list_head *head)
- {
- return list_entry((head)->prev, struct folio, lru);
- }
- void setup_initial_init_mm(void *start_code, void *end_code,
- void *end_data, void *brk);
- struct vm_area_struct *vm_area_alloc(struct mm_struct *);
- struct vm_area_struct *vm_area_dup(struct vm_area_struct *);
- void vm_area_free(struct vm_area_struct *);
- void __vm_area_free(struct vm_area_struct *vma);
- #ifndef CONFIG_MMU
- extern struct rb_root nommu_region_tree;
- extern struct rw_semaphore nommu_region_sem;
- extern unsigned int kobjsize(const void *objp);
- #endif
- #define VM_NONE 0x00000000
- #define VM_READ 0x00000001
- #define VM_WRITE 0x00000002
- #define VM_EXEC 0x00000004
- #define VM_SHARED 0x00000008
- #define VM_MAYREAD 0x00000010
- #define VM_MAYWRITE 0x00000020
- #define VM_MAYEXEC 0x00000040
- #define VM_MAYSHARE 0x00000080
- #define VM_GROWSDOWN 0x00000100
- #define VM_UFFD_MISSING 0x00000200
- #define VM_PFNMAP 0x00000400
- #define VM_UFFD_WP 0x00001000
- #define VM_LOCKED 0x00002000
- #define VM_IO 0x00004000
-
- #define VM_SEQ_READ 0x00008000
- #define VM_RAND_READ 0x00010000
- #define VM_DONTCOPY 0x00020000
- #define VM_DONTEXPAND 0x00040000
- #define VM_LOCKONFAULT 0x00080000
- #define VM_ACCOUNT 0x00100000
- #define VM_NORESERVE 0x00200000
- #define VM_HUGETLB 0x00400000
- #define VM_SYNC 0x00800000
- #define VM_ARCH_1 0x01000000
- #define VM_WIPEONFORK 0x02000000
- #define VM_DONTDUMP 0x04000000
- #ifdef CONFIG_MEM_SOFT_DIRTY
- # define VM_SOFTDIRTY 0x08000000
- #else
- # define VM_SOFTDIRTY 0
- #endif
- #define VM_MIXEDMAP 0x10000000
- #define VM_HUGEPAGE 0x20000000
- #define VM_NOHUGEPAGE 0x40000000
- #define VM_MERGEABLE 0x80000000
- #ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
- #define VM_HIGH_ARCH_BIT_0 32
- #define VM_HIGH_ARCH_BIT_1 33
- #define VM_HIGH_ARCH_BIT_2 34
- #define VM_HIGH_ARCH_BIT_3 35
- #define VM_HIGH_ARCH_BIT_4 36
- #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
- #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
- #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
- #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
- #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
- #endif
- #ifdef CONFIG_ARCH_HAS_PKEYS
- # define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0
- # define VM_PKEY_BIT0 VM_HIGH_ARCH_0
- # define VM_PKEY_BIT1 VM_HIGH_ARCH_1
- # define VM_PKEY_BIT2 VM_HIGH_ARCH_2
- # define VM_PKEY_BIT3 VM_HIGH_ARCH_3
- #ifdef CONFIG_PPC
- # define VM_PKEY_BIT4 VM_HIGH_ARCH_4
- #else
- # define VM_PKEY_BIT4 0
- #endif
- #endif
- #if defined(CONFIG_X86)
- # define VM_PAT VM_ARCH_1
- #elif defined(CONFIG_PPC)
- # define VM_SAO VM_ARCH_1
- #elif defined(CONFIG_PARISC)
- # define VM_GROWSUP VM_ARCH_1
- #elif defined(CONFIG_IA64)
- # define VM_GROWSUP VM_ARCH_1
- #elif defined(CONFIG_SPARC64)
- # define VM_SPARC_ADI VM_ARCH_1
- # define VM_ARCH_CLEAR VM_SPARC_ADI
- #elif defined(CONFIG_ARM64)
- # define VM_ARM64_BTI VM_ARCH_1
- # define VM_ARCH_CLEAR VM_ARM64_BTI
- #elif !defined(CONFIG_MMU)
- # define VM_MAPPED_COPY VM_ARCH_1
- #endif
- #if defined(CONFIG_ARM64_MTE)
- # define VM_MTE VM_HIGH_ARCH_0
- # define VM_MTE_ALLOWED VM_HIGH_ARCH_1
- #else
- # define VM_MTE VM_NONE
- # define VM_MTE_ALLOWED VM_NONE
- #endif
- #ifndef VM_GROWSUP
- # define VM_GROWSUP VM_NONE
- #endif
- #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR
- # define VM_UFFD_MINOR_BIT 37
- # define VM_UFFD_MINOR BIT(VM_UFFD_MINOR_BIT)
- #else
- # define VM_UFFD_MINOR VM_NONE
- #endif
- #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ | VM_STACK_EARLY)
- #define TASK_EXEC ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0)
- #define VM_DATA_FLAGS_TSK_EXEC (VM_READ | VM_WRITE | TASK_EXEC | \
- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
- #define VM_DATA_FLAGS_NON_EXEC (VM_READ | VM_WRITE | VM_MAYREAD | \
- VM_MAYWRITE | VM_MAYEXEC)
- #define VM_DATA_FLAGS_EXEC (VM_READ | VM_WRITE | VM_EXEC | \
- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
- #ifndef VM_DATA_DEFAULT_FLAGS
- #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_EXEC
- #endif
- #ifndef VM_STACK_DEFAULT_FLAGS
- #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
- #endif
- #ifdef CONFIG_STACK_GROWSUP
- #define VM_STACK VM_GROWSUP
- #define VM_STACK_EARLY VM_GROWSDOWN
- #else
- #define VM_STACK VM_GROWSDOWN
- #define VM_STACK_EARLY 0
- #endif
- #define VM_STACK_FLAGS (VM_STACK | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
- #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC)
- #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
- #define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)
- #define VM_INIT_DEF_MASK VM_NOHUGEPAGE
- #define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT)
- #ifndef VM_ARCH_CLEAR
- # define VM_ARCH_CLEAR VM_NONE
- #endif
- #define VM_FLAGS_CLEAR (ARCH_VM_PKEY_FLAGS | VM_ARCH_CLEAR)
- #define FAULT_FLAG_DEFAULT (FAULT_FLAG_ALLOW_RETRY | \
- FAULT_FLAG_KILLABLE | \
- FAULT_FLAG_INTERRUPTIBLE)
- static inline bool fault_flag_allow_retry_first(enum fault_flag flags)
- {
- return (flags & FAULT_FLAG_ALLOW_RETRY) &&
- (!(flags & FAULT_FLAG_TRIED));
- }
- #define FAULT_FLAG_TRACE \
- { FAULT_FLAG_WRITE, "WRITE" }, \
- { FAULT_FLAG_MKWRITE, "MKWRITE" }, \
- { FAULT_FLAG_ALLOW_RETRY, "ALLOW_RETRY" }, \
- { FAULT_FLAG_RETRY_NOWAIT, "RETRY_NOWAIT" }, \
- { FAULT_FLAG_KILLABLE, "KILLABLE" }, \
- { FAULT_FLAG_TRIED, "TRIED" }, \
- { FAULT_FLAG_USER, "USER" }, \
- { FAULT_FLAG_REMOTE, "REMOTE" }, \
- { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" }, \
- { FAULT_FLAG_INTERRUPTIBLE, "INTERRUPTIBLE" }, \
- { FAULT_FLAG_VMA_LOCK, "VMA_LOCK" }
- struct vm_fault {
- const struct {
- struct vm_area_struct *vma;
- gfp_t gfp_mask;
- pgoff_t pgoff;
- unsigned long address;
- unsigned long real_address;
- };
- enum fault_flag flags;
- pmd_t *pmd;
- pud_t *pud;
- union {
- pte_t orig_pte;
- pmd_t orig_pmd;
- };
- struct page *cow_page;
- struct page *page;
-
- pte_t *pte;
- spinlock_t *ptl;
- pgtable_t prealloc_pte;
- };
- enum page_entry_size {
- PE_SIZE_PTE = 0,
- PE_SIZE_PMD,
- PE_SIZE_PUD,
- };
- struct vm_operations_struct {
- void (*open)(struct vm_area_struct * area);
-
- void (*close)(struct vm_area_struct * area);
-
- int (*may_split)(struct vm_area_struct *area, unsigned long addr);
- int (*mremap)(struct vm_area_struct *area);
-
- int (*mprotect)(struct vm_area_struct *vma, unsigned long start,
- unsigned long end, unsigned long newflags);
- vm_fault_t (*fault)(struct vm_fault *vmf);
- vm_fault_t (*huge_fault)(struct vm_fault *vmf,
- enum page_entry_size pe_size);
- vm_fault_t (*map_pages)(struct vm_fault *vmf,
- pgoff_t start_pgoff, pgoff_t end_pgoff);
- unsigned long (*pagesize)(struct vm_area_struct * area);
-
- vm_fault_t (*page_mkwrite)(struct vm_fault *vmf);
-
- vm_fault_t (*pfn_mkwrite)(struct vm_fault *vmf);
-
- int (*access)(struct vm_area_struct *vma, unsigned long addr,
- void *buf, int len, int write);
-
- const char *(*name)(struct vm_area_struct *vma);
- #ifdef CONFIG_NUMA
-
- int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
-
- struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
- unsigned long addr);
- #endif
-
- struct page *(*find_special_page)(struct vm_area_struct *vma,
- unsigned long addr);
- ANDROID_KABI_RESERVE(1);
- ANDROID_KABI_RESERVE(2);
- ANDROID_KABI_RESERVE(3);
- ANDROID_KABI_RESERVE(4);
- };
- #ifdef CONFIG_PER_VMA_LOCK
- static inline bool vma_start_read(struct vm_area_struct *vma)
- {
-
- if (READ_ONCE(vma->vm_lock_seq) == READ_ONCE(vma->vm_mm->mm_lock_seq))
- return false;
- if (unlikely(down_read_trylock(&vma->vm_lock->lock) == 0))
- return false;
-
- if (unlikely(vma->vm_lock_seq == smp_load_acquire(&vma->vm_mm->mm_lock_seq))) {
- up_read(&vma->vm_lock->lock);
- return false;
- }
- return true;
- }
- static inline void vma_end_read(struct vm_area_struct *vma)
- {
- rcu_read_lock();
- up_read(&vma->vm_lock->lock);
- rcu_read_unlock();
- }
- static bool __is_vma_write_locked(struct vm_area_struct *vma, int *mm_lock_seq)
- {
- mmap_assert_write_locked(vma->vm_mm);
-
- *mm_lock_seq = vma->vm_mm->mm_lock_seq;
- return (vma->vm_lock_seq == *mm_lock_seq);
- }
- static inline void vma_start_write(struct vm_area_struct *vma)
- {
- int mm_lock_seq;
- if (__is_vma_write_locked(vma, &mm_lock_seq))
- return;
- down_write(&vma->vm_lock->lock);
-
- WRITE_ONCE(vma->vm_lock_seq, mm_lock_seq);
- up_write(&vma->vm_lock->lock);
- }
- static inline bool vma_try_start_write(struct vm_area_struct *vma)
- {
- int mm_lock_seq;
- if (__is_vma_write_locked(vma, &mm_lock_seq))
- return true;
- if (!down_write_trylock(&vma->vm_lock->lock))
- return false;
- WRITE_ONCE(vma->vm_lock_seq, mm_lock_seq);
- up_write(&vma->vm_lock->lock);
- return true;
- }
- static inline void vma_assert_write_locked(struct vm_area_struct *vma)
- {
- int mm_lock_seq;
- VM_BUG_ON_VMA(!__is_vma_write_locked(vma, &mm_lock_seq), vma);
- }
- static inline void vma_assert_locked(struct vm_area_struct *vma)
- {
- if (!rwsem_is_locked(&vma->vm_lock->lock))
- vma_assert_write_locked(vma);
- }
- static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached)
- {
-
- if (detached)
- vma_assert_write_locked(vma);
- vma->detached = detached;
- }
- static inline void release_fault_lock(struct vm_fault *vmf)
- {
- if (vmf->flags & FAULT_FLAG_VMA_LOCK)
- vma_end_read(vmf->vma);
- else
- mmap_read_unlock(vmf->vma->vm_mm);
- }
- static inline void assert_fault_locked(struct vm_fault *vmf)
- {
- if (vmf->flags & FAULT_FLAG_VMA_LOCK)
- vma_assert_locked(vmf->vma);
- else
- mmap_assert_locked(vmf->vma->vm_mm);
- }
- struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
- unsigned long address);
- #else
- static inline void vma_init_lock(struct vm_area_struct *vma) {}
- static inline bool vma_start_read(struct vm_area_struct *vma)
- { return false; }
- static inline void vma_end_read(struct vm_area_struct *vma) {}
- static inline void vma_start_write(struct vm_area_struct *vma) {}
- static inline bool vma_try_start_write(struct vm_area_struct *vma)
- { return true; }
- static inline void vma_assert_write_locked(struct vm_area_struct *vma)
- { mmap_assert_write_locked(vma->vm_mm); }
- static inline void vma_mark_detached(struct vm_area_struct *vma,
- bool detached) {}
- static inline void release_fault_lock(struct vm_fault *vmf)
- {
- mmap_read_unlock(vmf->vma->vm_mm);
- }
- static inline void assert_fault_locked(struct vm_fault *vmf)
- {
- mmap_assert_locked(vmf->vma->vm_mm);
- }
- static inline struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
- unsigned long address)
- {
- return NULL;
- }
- #endif
- static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
- {
- static const struct vm_operations_struct dummy_vm_ops = {};
- memset(vma, 0, sizeof(*vma));
- vma->vm_mm = mm;
- vma->vm_ops = &dummy_vm_ops;
- INIT_LIST_HEAD(&vma->anon_vma_chain);
- vma_mark_detached(vma, false);
- }
- static inline void vm_flags_init(struct vm_area_struct *vma,
- vm_flags_t flags)
- {
- ACCESS_PRIVATE(vma, __vm_flags) = flags;
- }
- static inline void vm_flags_reset(struct vm_area_struct *vma,
- vm_flags_t flags)
- {
- vma_assert_write_locked(vma);
- vm_flags_init(vma, flags);
- }
- static inline void vm_flags_reset_once(struct vm_area_struct *vma,
- vm_flags_t flags)
- {
- vma_assert_write_locked(vma);
- WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags);
- }
- static inline void vm_flags_set(struct vm_area_struct *vma,
- vm_flags_t flags)
- {
- vma_start_write(vma);
- ACCESS_PRIVATE(vma, __vm_flags) |= flags;
- }
- static inline void vm_flags_clear(struct vm_area_struct *vma,
- vm_flags_t flags)
- {
- vma_start_write(vma);
- ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
- }
- static inline void __vm_flags_mod(struct vm_area_struct *vma,
- vm_flags_t set, vm_flags_t clear)
- {
- vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
- }
- static inline void vm_flags_mod(struct vm_area_struct *vma,
- vm_flags_t set, vm_flags_t clear)
- {
- vma_start_write(vma);
- __vm_flags_mod(vma, set, clear);
- }
- static inline void vma_set_anonymous(struct vm_area_struct *vma)
- {
- vma->vm_ops = NULL;
- }
- static inline bool vma_is_anonymous(struct vm_area_struct *vma)
- {
- return !vma->vm_ops;
- }
- static inline bool vma_is_temporary_stack(struct vm_area_struct *vma)
- {
- int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
- if (!maybe_stack)
- return false;
- if ((vma->vm_flags & VM_STACK_INCOMPLETE_SETUP) ==
- VM_STACK_INCOMPLETE_SETUP)
- return true;
- return false;
- }
- static inline bool vma_is_foreign(struct vm_area_struct *vma)
- {
- if (!current->mm)
- return true;
- if (current->mm != vma->vm_mm)
- return true;
- return false;
- }
- static inline bool vma_is_accessible(struct vm_area_struct *vma)
- {
- return vma->vm_flags & VM_ACCESS_FLAGS;
- }
- static inline
- struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
- {
- return mas_find(&vmi->mas, max);
- }
- static inline struct vm_area_struct *vma_next(struct vma_iterator *vmi)
- {
-
- return vma_find(vmi, ULONG_MAX);
- }
- static inline struct vm_area_struct *vma_prev(struct vma_iterator *vmi)
- {
- return mas_prev(&vmi->mas, 0);
- }
- static inline unsigned long vma_iter_addr(struct vma_iterator *vmi)
- {
- return vmi->mas.index;
- }
- #define for_each_vma(__vmi, __vma) \
- while (((__vma) = vma_next(&(__vmi))) != NULL)
- #define for_each_vma_range(__vmi, __vma, __end) \
- while (((__vma) = vma_find(&(__vmi), (__end) - 1)) != NULL)
- #ifdef CONFIG_SHMEM
- bool vma_is_shmem(struct vm_area_struct *vma);
- #else
- static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
- #endif
- int vma_is_stack_for_current(struct vm_area_struct *vma);
- #define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) }
- struct mmu_gather;
- struct inode;
- static inline unsigned int compound_order(struct page *page)
- {
- if (!PageHead(page))
- return 0;
- return page[1].compound_order;
- }
- static inline unsigned int folio_order(struct folio *folio)
- {
- if (!folio_test_large(folio))
- return 0;
- return folio->_folio_order;
- }
- #include <linux/huge_mm.h>
- static inline int put_page_testzero(struct page *page)
- {
- int ret;
- VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
- ret = page_ref_dec_and_test(page);
- page_pinner_put_page(page);
- return ret;
- }
- static inline int folio_put_testzero(struct folio *folio)
- {
- return put_page_testzero(&folio->page);
- }
- static inline bool get_page_unless_zero(struct page *page)
- {
- return page_ref_add_unless(page, 1, 0);
- }
- extern int page_is_ram(unsigned long pfn);
- enum {
- REGION_INTERSECTS,
- REGION_DISJOINT,
- REGION_MIXED,
- };
- int region_intersects(resource_size_t offset, size_t size, unsigned long flags,
- unsigned long desc);
- struct page *vmalloc_to_page(const void *addr);
- unsigned long vmalloc_to_pfn(const void *addr);
- #ifndef is_ioremap_addr
- #define is_ioremap_addr(x) is_vmalloc_addr(x)
- #endif
- #ifdef CONFIG_MMU
- extern bool is_vmalloc_addr(const void *x);
- extern int is_vmalloc_or_module_addr(const void *x);
- #else
- static inline bool is_vmalloc_addr(const void *x)
- {
- return false;
- }
- static inline int is_vmalloc_or_module_addr(const void *x)
- {
- return 0;
- }
- #endif
- static inline int folio_entire_mapcount(struct folio *folio)
- {
- VM_BUG_ON_FOLIO(!folio_test_large(folio), folio);
- return atomic_read(folio_mapcount_ptr(folio)) + 1;
- }
- static inline int compound_mapcount(struct page *page)
- {
- return folio_entire_mapcount(page_folio(page));
- }
- static inline void page_mapcount_reset(struct page *page)
- {
- atomic_set(&(page)->_mapcount, -1);
- }
- int __page_mapcount(struct page *page);
- static inline int page_mapcount(struct page *page)
- {
- if (unlikely(PageCompound(page)))
- return __page_mapcount(page);
- return atomic_read(&page->_mapcount) + 1;
- }
- int folio_mapcount(struct folio *folio);
- #ifdef CONFIG_TRANSPARENT_HUGEPAGE
- static inline int total_mapcount(struct page *page)
- {
- return folio_mapcount(page_folio(page));
- }
- #else
- static inline int total_mapcount(struct page *page)
- {
- return page_mapcount(page);
- }
- #endif
- static inline struct page *virt_to_head_page(const void *x)
- {
- struct page *page = virt_to_page(x);
- return compound_head(page);
- }
- static inline struct folio *virt_to_folio(const void *x)
- {
- struct page *page = virt_to_page(x);
- return page_folio(page);
- }
- void __folio_put(struct folio *folio);
- void put_pages_list(struct list_head *pages);
- void split_page(struct page *page, unsigned int order);
- void folio_copy(struct folio *dst, struct folio *src);
- unsigned long nr_free_buffer_pages(void);
- typedef void compound_page_dtor(struct page *);
- enum compound_dtor_id {
- NULL_COMPOUND_DTOR,
- COMPOUND_PAGE_DTOR,
- #ifdef CONFIG_HUGETLB_PAGE
- HUGETLB_PAGE_DTOR,
- #endif
- #ifdef CONFIG_TRANSPARENT_HUGEPAGE
- TRANSHUGE_PAGE_DTOR,
- #endif
- NR_COMPOUND_DTORS,
- };
- extern compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS];
- static inline void set_compound_page_dtor(struct page *page,
- enum compound_dtor_id compound_dtor)
- {
- VM_BUG_ON_PAGE(compound_dtor >= NR_COMPOUND_DTORS, page);
- page[1].compound_dtor = compound_dtor;
- }
- void destroy_large_folio(struct folio *folio);
- static inline int head_compound_pincount(struct page *head)
- {
- return atomic_read(compound_pincount_ptr(head));
- }
- static inline void set_compound_order(struct page *page, unsigned int order)
- {
- page[1].compound_order = order;
- #ifdef CONFIG_64BIT
- page[1].compound_nr = 1U << order;
- #endif
- }
- static inline unsigned long compound_nr(struct page *page)
- {
- if (!PageHead(page))
- return 1;
- #ifdef CONFIG_64BIT
- return page[1].compound_nr;
- #else
- return 1UL << compound_order(page);
- #endif
- }
- static inline unsigned long page_size(struct page *page)
- {
- return PAGE_SIZE << compound_order(page);
- }
- static inline unsigned int page_shift(struct page *page)
- {
- return PAGE_SHIFT + compound_order(page);
- }
- static inline unsigned int thp_order(struct page *page)
- {
- VM_BUG_ON_PGFLAGS(PageTail(page), page);
- return compound_order(page);
- }
- static inline int thp_nr_pages(struct page *page)
- {
- VM_BUG_ON_PGFLAGS(PageTail(page), page);
- return compound_nr(page);
- }
- static inline unsigned long thp_size(struct page *page)
- {
- return PAGE_SIZE << thp_order(page);
- }
- void free_compound_page(struct page *page);
- #ifdef CONFIG_MMU
- static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
- {
- if (likely(vma->vm_flags & VM_WRITE))
- pte = pte_mkwrite(pte);
- return pte;
- }
- vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page);
- void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr);
- vm_fault_t finish_fault(struct vm_fault *vmf);
- vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf);
- #endif
- #if defined(CONFIG_ZONE_DEVICE) && defined(CONFIG_FS_DAX)
- DECLARE_STATIC_KEY_FALSE(devmap_managed_key);
- bool __put_devmap_managed_page_refs(struct page *page, int refs);
- static inline bool put_devmap_managed_page_refs(struct page *page, int refs)
- {
- if (!static_branch_unlikely(&devmap_managed_key))
- return false;
- if (!is_zone_device_page(page))
- return false;
- return __put_devmap_managed_page_refs(page, refs);
- }
- #else
- static inline bool put_devmap_managed_page_refs(struct page *page, int refs)
- {
- return false;
- }
- #endif
- static inline bool put_devmap_managed_page(struct page *page)
- {
- return put_devmap_managed_page_refs(page, 1);
- }
- #define folio_ref_zero_or_close_to_overflow(folio) \
- ((unsigned int) folio_ref_count(folio) + 127u <= 127u)
- static inline void folio_get(struct folio *folio)
- {
- VM_BUG_ON_FOLIO(folio_ref_zero_or_close_to_overflow(folio), folio);
- folio_ref_inc(folio);
- }
- static inline void get_page(struct page *page)
- {
- folio_get(page_folio(page));
- }
- bool __must_check try_grab_page(struct page *page, unsigned int flags);
- static inline __must_check bool try_get_page(struct page *page)
- {
- page = compound_head(page);
- if (WARN_ON_ONCE(page_ref_count(page) <= 0))
- return false;
- page_ref_inc(page);
- return true;
- }
- static inline void folio_put(struct folio *folio)
- {
- if (folio_put_testzero(folio))
- __folio_put(folio);
- }
- static inline void folio_put_refs(struct folio *folio, int refs)
- {
- if (folio_ref_sub_and_test(folio, refs))
- __folio_put(folio);
- }
- void release_pages(struct page **pages, int nr);
- static inline void folios_put(struct folio **folios, unsigned int nr)
- {
- release_pages((struct page **)folios, nr);
- }
- static inline void put_page(struct page *page)
- {
- struct folio *folio = page_folio(page);
-
- if (put_devmap_managed_page(&folio->page))
- return;
- folio_put(folio);
- }
- #define GUP_PIN_COUNTING_BIAS (1U << 10)
- void unpin_user_page(struct page *page);
- void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages,
- bool make_dirty);
- void unpin_user_page_range_dirty_lock(struct page *page, unsigned long npages,
- bool make_dirty);
- void unpin_user_pages(struct page **pages, unsigned long npages);
- static inline bool is_cow_mapping(vm_flags_t flags)
- {
- return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
- }
- #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
- #define SECTION_IN_PAGE_FLAGS
- #endif
- static inline int page_zone_id(struct page *page)
- {
- return (page->flags >> ZONEID_PGSHIFT) & ZONEID_MASK;
- }
- #ifdef NODE_NOT_IN_PAGE_FLAGS
- extern int page_to_nid(const struct page *page);
- #else
- static inline int page_to_nid(const struct page *page)
- {
- struct page *p = (struct page *)page;
- return (PF_POISONED_CHECK(p)->flags >> NODES_PGSHIFT) & NODES_MASK;
- }
- #endif
- static inline int folio_nid(const struct folio *folio)
- {
- return page_to_nid(&folio->page);
- }
- #ifdef CONFIG_NUMA_BALANCING
- #define PAGE_ACCESS_TIME_MIN_BITS 12
- #if LAST_CPUPID_SHIFT < PAGE_ACCESS_TIME_MIN_BITS
- #define PAGE_ACCESS_TIME_BUCKETS \
- (PAGE_ACCESS_TIME_MIN_BITS - LAST_CPUPID_SHIFT)
- #else
- #define PAGE_ACCESS_TIME_BUCKETS 0
- #endif
- #define PAGE_ACCESS_TIME_MASK \
- (LAST_CPUPID_MASK << PAGE_ACCESS_TIME_BUCKETS)
- static inline int cpu_pid_to_cpupid(int cpu, int pid)
- {
- return ((cpu & LAST__CPU_MASK) << LAST__PID_SHIFT) | (pid & LAST__PID_MASK);
- }
- static inline int cpupid_to_pid(int cpupid)
- {
- return cpupid & LAST__PID_MASK;
- }
- static inline int cpupid_to_cpu(int cpupid)
- {
- return (cpupid >> LAST__PID_SHIFT) & LAST__CPU_MASK;
- }
- static inline int cpupid_to_nid(int cpupid)
- {
- return cpu_to_node(cpupid_to_cpu(cpupid));
- }
- static inline bool cpupid_pid_unset(int cpupid)
- {
- return cpupid_to_pid(cpupid) == (-1 & LAST__PID_MASK);
- }
- static inline bool cpupid_cpu_unset(int cpupid)
- {
- return cpupid_to_cpu(cpupid) == (-1 & LAST__CPU_MASK);
- }
- static inline bool __cpupid_match_pid(pid_t task_pid, int cpupid)
- {
- return (task_pid & LAST__PID_MASK) == cpupid_to_pid(cpupid);
- }
- #define cpupid_match_pid(task, cpupid) __cpupid_match_pid(task->pid, cpupid)
- #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
- static inline int page_cpupid_xchg_last(struct page *page, int cpupid)
- {
- return xchg(&page->_last_cpupid, cpupid & LAST_CPUPID_MASK);
- }
- static inline int page_cpupid_last(struct page *page)
- {
- return page->_last_cpupid;
- }
- static inline void page_cpupid_reset_last(struct page *page)
- {
- page->_last_cpupid = -1 & LAST_CPUPID_MASK;
- }
- #else
- static inline int page_cpupid_last(struct page *page)
- {
- return (page->flags >> LAST_CPUPID_PGSHIFT) & LAST_CPUPID_MASK;
- }
- extern int page_cpupid_xchg_last(struct page *page, int cpupid);
- static inline void page_cpupid_reset_last(struct page *page)
- {
- page->flags |= LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT;
- }
- #endif
- static inline int xchg_page_access_time(struct page *page, int time)
- {
- int last_time;
- last_time = page_cpupid_xchg_last(page, time >> PAGE_ACCESS_TIME_BUCKETS);
- return last_time << PAGE_ACCESS_TIME_BUCKETS;
- }
- #else
- static inline int page_cpupid_xchg_last(struct page *page, int cpupid)
- {
- return page_to_nid(page);
- }
- static inline int xchg_page_access_time(struct page *page, int time)
- {
- return 0;
- }
- static inline int page_cpupid_last(struct page *page)
- {
- return page_to_nid(page);
- }
- static inline int cpupid_to_nid(int cpupid)
- {
- return -1;
- }
- static inline int cpupid_to_pid(int cpupid)
- {
- return -1;
- }
- static inline int cpupid_to_cpu(int cpupid)
- {
- return -1;
- }
- static inline int cpu_pid_to_cpupid(int nid, int pid)
- {
- return -1;
- }
- static inline bool cpupid_pid_unset(int cpupid)
- {
- return true;
- }
- static inline void page_cpupid_reset_last(struct page *page)
- {
- }
- static inline bool cpupid_match_pid(struct task_struct *task, int cpupid)
- {
- return false;
- }
- #endif
- #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
- static inline u8 page_kasan_tag(const struct page *page)
- {
- u8 tag = 0xff;
- if (kasan_enabled()) {
- tag = (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK;
- tag ^= 0xff;
- }
- return tag;
- }
- static inline void page_kasan_tag_set(struct page *page, u8 tag)
- {
- unsigned long old_flags, flags;
- if (!kasan_enabled())
- return;
- tag ^= 0xff;
- old_flags = READ_ONCE(page->flags);
- do {
- flags = old_flags;
- flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT);
- flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT;
- } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags)));
- }
- static inline void page_kasan_tag_reset(struct page *page)
- {
- if (kasan_enabled())
- page_kasan_tag_set(page, 0xff);
- }
- #else
- static inline u8 page_kasan_tag(const struct page *page)
- {
- return 0xff;
- }
- static inline void page_kasan_tag_set(struct page *page, u8 tag) { }
- static inline void page_kasan_tag_reset(struct page *page) { }
- #endif
- static inline struct zone *page_zone(const struct page *page)
- {
- return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
- }
- static inline pg_data_t *page_pgdat(const struct page *page)
- {
- return NODE_DATA(page_to_nid(page));
- }
- static inline struct zone *folio_zone(const struct folio *folio)
- {
- return page_zone(&folio->page);
- }
- static inline pg_data_t *folio_pgdat(const struct folio *folio)
- {
- return page_pgdat(&folio->page);
- }
- #ifdef SECTION_IN_PAGE_FLAGS
- static inline void set_page_section(struct page *page, unsigned long section)
- {
- page->flags &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT);
- page->flags |= (section & SECTIONS_MASK) << SECTIONS_PGSHIFT;
- }
- static inline unsigned long page_to_section(const struct page *page)
- {
- return (page->flags >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
- }
- #endif
- static inline unsigned long folio_pfn(struct folio *folio)
- {
- return page_to_pfn(&folio->page);
- }
- static inline struct folio *pfn_folio(unsigned long pfn)
- {
- return page_folio(pfn_to_page(pfn));
- }
- static inline atomic_t *folio_pincount_ptr(struct folio *folio)
- {
- return &folio_page(folio, 1)->compound_pincount;
- }
- static inline bool folio_maybe_dma_pinned(struct folio *folio)
- {
- if (folio_test_large(folio))
- return atomic_read(folio_pincount_ptr(folio)) > 0;
-
- return ((unsigned int)folio_ref_count(folio)) >=
- GUP_PIN_COUNTING_BIAS;
- }
- static inline bool page_maybe_dma_pinned(struct page *page)
- {
- return folio_maybe_dma_pinned(page_folio(page));
- }
- static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
- struct page *page)
- {
- VM_BUG_ON(!(raw_read_seqcount(&vma->vm_mm->write_protect_seq) & 1));
- if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
- return false;
- return page_maybe_dma_pinned(page);
- }
- #ifdef CONFIG_MIGRATION
- static inline bool is_longterm_pinnable_page(struct page *page)
- {
- #ifdef CONFIG_CMA
- int mt = get_pageblock_migratetype(page);
- if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
- return false;
- #endif
-
- if (is_zero_pfn(page_to_pfn(page)))
- return true;
-
- if (is_device_coherent_page(page))
- return false;
-
- return !is_zone_movable_page(page);
- }
- #else
- static inline bool is_longterm_pinnable_page(struct page *page)
- {
- return true;
- }
- #endif
- static inline bool folio_is_longterm_pinnable(struct folio *folio)
- {
- return is_longterm_pinnable_page(&folio->page);
- }
- static inline void set_page_zone(struct page *page, enum zone_type zone)
- {
- page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT);
- page->flags |= (zone & ZONES_MASK) << ZONES_PGSHIFT;
- }
- static inline void set_page_node(struct page *page, unsigned long node)
- {
- page->flags &= ~(NODES_MASK << NODES_PGSHIFT);
- page->flags |= (node & NODES_MASK) << NODES_PGSHIFT;
- }
- static inline void set_page_links(struct page *page, enum zone_type zone,
- unsigned long node, unsigned long pfn)
- {
- set_page_zone(page, zone);
- set_page_node(page, node);
- #ifdef SECTION_IN_PAGE_FLAGS
- set_page_section(page, pfn_to_section_nr(pfn));
- #endif
- }
- static inline long folio_nr_pages(struct folio *folio)
- {
- if (!folio_test_large(folio))
- return 1;
- #ifdef CONFIG_64BIT
- return folio->_folio_nr_pages;
- #else
- return 1L << folio->_folio_order;
- #endif
- }
- static inline struct folio *folio_next(struct folio *folio)
- {
- return (struct folio *)folio_page(folio, folio_nr_pages(folio));
- }
- static inline unsigned int folio_shift(struct folio *folio)
- {
- return PAGE_SHIFT + folio_order(folio);
- }
- static inline size_t folio_size(struct folio *folio)
- {
- return PAGE_SIZE << folio_order(folio);
- }
- static inline int folio_estimated_sharers(struct folio *folio)
- {
- return page_mapcount(folio_page(folio, 0));
- }
- #ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE
- static inline int arch_make_page_accessible(struct page *page)
- {
- return 0;
- }
- #endif
- #ifndef HAVE_ARCH_MAKE_FOLIO_ACCESSIBLE
- static inline int arch_make_folio_accessible(struct folio *folio)
- {
- int ret;
- long i, nr = folio_nr_pages(folio);
- for (i = 0; i < nr; i++) {
- ret = arch_make_page_accessible(folio_page(folio, i));
- if (ret)
- break;
- }
- return ret;
- }
- #endif
- #include <linux/vmstat.h>
- static __always_inline void *lowmem_page_address(const struct page *page)
- {
- return page_to_virt(page);
- }
- #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
- #define HASHED_PAGE_VIRTUAL
- #endif
- #if defined(WANT_PAGE_VIRTUAL)
- static inline void *page_address(const struct page *page)
- {
- return page->virtual;
- }
- static inline void set_page_address(struct page *page, void *address)
- {
- page->virtual = address;
- }
- #define page_address_init() do { } while(0)
- #endif
- #if defined(HASHED_PAGE_VIRTUAL)
- void *page_address(const struct page *page);
- void set_page_address(struct page *page, void *virtual);
- void page_address_init(void);
- #endif
- #if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
- #define page_address(page) lowmem_page_address(page)
- #define set_page_address(page, address) do { } while(0)
- #define page_address_init() do { } while(0)
- #endif
- static inline void *folio_address(const struct folio *folio)
- {
- return page_address(&folio->page);
- }
- extern void *page_rmapping(struct page *page);
- extern pgoff_t __page_file_index(struct page *page);
- static inline pgoff_t page_index(struct page *page)
- {
- if (unlikely(PageSwapCache(page)))
- return __page_file_index(page);
- return page->index;
- }
- bool page_mapped(struct page *page);
- bool folio_mapped(struct folio *folio);
- static inline bool page_is_pfmemalloc(const struct page *page)
- {
-
- return (uintptr_t)page->lru.next & BIT(1);
- }
- static inline void set_page_pfmemalloc(struct page *page)
- {
- page->lru.next = (void *)BIT(1);
- }
- static inline void clear_page_pfmemalloc(struct page *page)
- {
- page->lru.next = NULL;
- }
- extern void pagefault_out_of_memory(void);
- #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
- #define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1))
- #define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1))
- #define SHOW_MEM_FILTER_NODES (0x0001u)
- extern void __show_free_areas(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);
- static void __maybe_unused show_free_areas(unsigned int flags, nodemask_t *nodemask)
- {
- __show_free_areas(flags, nodemask, MAX_NR_ZONES - 1);
- }
- struct zap_details {
- struct folio *single_folio;
- bool even_cows;
- zap_flags_t zap_flags;
- };
- #define ZAP_FLAG_DROP_MARKER ((__force zap_flags_t) BIT(0))
- #define ZAP_FLAG_UNMAP ((__force zap_flags_t) BIT(1))
- #ifdef CONFIG_MMU
- extern bool can_do_mlock(void);
- #else
- static inline bool can_do_mlock(void) { return false; }
- #endif
- extern int user_shm_lock(size_t, struct ucounts *);
- extern void user_shm_unlock(size_t, struct ucounts *);
- struct folio *vm_normal_folio(struct vm_area_struct *vma, unsigned long addr,
- pte_t pte);
- struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
- pte_t pte);
- struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
- pmd_t pmd);
- void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
- unsigned long size);
- void zap_page_range(struct vm_area_struct *vma, unsigned long address,
- unsigned long size);
- void zap_page_range_single(struct vm_area_struct *vma, unsigned long address,
- unsigned long size, struct zap_details *details);
- void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt,
- struct vm_area_struct *start_vma, unsigned long start,
- unsigned long end, unsigned long start_t,
- unsigned long end_t, bool mm_wr_locked);
- struct mmu_notifier_range;
- void free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
- unsigned long end, unsigned long floor, unsigned long ceiling);
- int
- copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma);
- int follow_pte(struct mm_struct *mm, unsigned long address,
- pte_t **ptepp, spinlock_t **ptlp);
- int follow_pfn(struct vm_area_struct *vma, unsigned long address,
- unsigned long *pfn);
- int follow_phys(struct vm_area_struct *vma, unsigned long address,
- unsigned int flags, unsigned long *prot, resource_size_t *phys);
- int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
- void *buf, int len, int write);
- extern void truncate_pagecache(struct inode *inode, loff_t new);
- extern void truncate_setsize(struct inode *inode, loff_t newsize);
- void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to);
- void truncate_pagecache_range(struct inode *inode, loff_t offset, loff_t end);
- int generic_error_remove_page(struct address_space *mapping, struct page *page);
- #ifdef CONFIG_MMU
- extern vm_fault_t handle_mm_fault(struct vm_area_struct *vma,
- unsigned long address, unsigned int flags,
- struct pt_regs *regs);
- extern int fixup_user_fault(struct mm_struct *mm,
- unsigned long address, unsigned int fault_flags,
- bool *unlocked);
- void unmap_mapping_pages(struct address_space *mapping,
- pgoff_t start, pgoff_t nr, bool even_cows);
- void unmap_mapping_range(struct address_space *mapping,
- loff_t const holebegin, loff_t const holelen, int even_cows);
- struct vm_area_struct *lock_mm_and_find_vma(struct mm_struct *mm,
- unsigned long address, struct pt_regs *regs);
- #else
- static inline vm_fault_t handle_mm_fault(struct vm_area_struct *vma,
- unsigned long address, unsigned int flags,
- struct pt_regs *regs)
- {
-
- BUG();
- return VM_FAULT_SIGBUS;
- }
- static inline int fixup_user_fault(struct mm_struct *mm, unsigned long address,
- unsigned int fault_flags, bool *unlocked)
- {
-
- BUG();
- return -EFAULT;
- }
- static inline void unmap_mapping_pages(struct address_space *mapping,
- pgoff_t start, pgoff_t nr, bool even_cows) { }
- static inline void unmap_mapping_range(struct address_space *mapping,
- loff_t const holebegin, loff_t const holelen, int even_cows) { }
- #endif
- static inline void unmap_shared_mapping_range(struct address_space *mapping,
- loff_t const holebegin, loff_t const holelen)
- {
- unmap_mapping_range(mapping, holebegin, holelen, 0);
- }
- extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
- void *buf, int len, unsigned int gup_flags);
- extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
- void *buf, int len, unsigned int gup_flags);
- extern int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
- void *buf, int len, unsigned int gup_flags);
- long get_user_pages_remote(struct mm_struct *mm,
- unsigned long start, unsigned long nr_pages,
- unsigned int gup_flags, struct page **pages,
- struct vm_area_struct **vmas, int *locked);
- long pin_user_pages_remote(struct mm_struct *mm,
- unsigned long start, unsigned long nr_pages,
- unsigned int gup_flags, struct page **pages,
- struct vm_area_struct **vmas, int *locked);
- long get_user_pages(unsigned long start, unsigned long nr_pages,
- unsigned int gup_flags, struct page **pages,
- struct vm_area_struct **vmas);
- long pin_user_pages(unsigned long start, unsigned long nr_pages,
- unsigned int gup_flags, struct page **pages,
- struct vm_area_struct **vmas);
- long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
- struct page **pages, unsigned int gup_flags);
- long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
- struct page **pages, unsigned int gup_flags);
- int get_user_pages_fast(unsigned long start, int nr_pages,
- unsigned int gup_flags, struct page **pages);
- int pin_user_pages_fast(unsigned long start, int nr_pages,
- unsigned int gup_flags, struct page **pages);
- int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc);
- int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc,
- struct task_struct *task, bool bypass_rlim);
- struct kvec;
- int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
- struct page **pages);
- struct page *get_dump_page(unsigned long addr);
- bool folio_mark_dirty(struct folio *folio);
- bool set_page_dirty(struct page *page);
- int set_page_dirty_lock(struct page *page);
- int get_cmdline(struct task_struct *task, char *buffer, int buflen);
- extern unsigned long move_page_tables(struct vm_area_struct *vma,
- unsigned long old_addr, struct vm_area_struct *new_vma,
- unsigned long new_addr, unsigned long len,
- bool need_rmap_locks);
- #define MM_CP_TRY_CHANGE_WRITABLE (1UL << 0)
- #define MM_CP_PROT_NUMA (1UL << 1)
- #define MM_CP_UFFD_WP (1UL << 2)
- #define MM_CP_UFFD_WP_RESOLVE (1UL << 3)
- #define MM_CP_UFFD_WP_ALL (MM_CP_UFFD_WP | \
- MM_CP_UFFD_WP_RESOLVE)
- extern unsigned long change_protection(struct mmu_gather *tlb,
- struct vm_area_struct *vma, unsigned long start,
- unsigned long end, pgprot_t newprot,
- unsigned long cp_flags);
- extern int mprotect_fixup(struct mmu_gather *tlb, struct vm_area_struct *vma,
- struct vm_area_struct **pprev, unsigned long start,
- unsigned long end, unsigned long newflags);
- int get_user_pages_fast_only(unsigned long start, int nr_pages,
- unsigned int gup_flags, struct page **pages);
- int pin_user_pages_fast_only(unsigned long start, int nr_pages,
- unsigned int gup_flags, struct page **pages);
- static inline bool get_user_page_fast_only(unsigned long addr,
- unsigned int gup_flags, struct page **pagep)
- {
- return get_user_pages_fast_only(addr, 1, gup_flags, pagep) == 1;
- }
- static inline unsigned long get_mm_counter(struct mm_struct *mm, int member)
- {
- long val = atomic_long_read(&mm->rss_stat.count[member]);
- #ifdef SPLIT_RSS_COUNTING
-
- if (val < 0)
- val = 0;
- #endif
- return (unsigned long)val;
- }
- void mm_trace_rss_stat(struct mm_struct *mm, int member, long count);
- static inline void add_mm_counter(struct mm_struct *mm, int member, long value)
- {
- long count = atomic_long_add_return(value, &mm->rss_stat.count[member]);
- mm_trace_rss_stat(mm, member, count);
- }
- static inline void inc_mm_counter(struct mm_struct *mm, int member)
- {
- long count = atomic_long_inc_return(&mm->rss_stat.count[member]);
- mm_trace_rss_stat(mm, member, count);
- }
- static inline void dec_mm_counter(struct mm_struct *mm, int member)
- {
- long count = atomic_long_dec_return(&mm->rss_stat.count[member]);
- mm_trace_rss_stat(mm, member, count);
- }
- static inline int mm_counter_file(struct page *page)
- {
- if (PageSwapBacked(page))
- return MM_SHMEMPAGES;
- return MM_FILEPAGES;
- }
- static inline int mm_counter(struct page *page)
- {
- if (PageAnon(page))
- return MM_ANONPAGES;
- return mm_counter_file(page);
- }
- static inline unsigned long get_mm_rss(struct mm_struct *mm)
- {
- return get_mm_counter(mm, MM_FILEPAGES) +
- get_mm_counter(mm, MM_ANONPAGES) +
- get_mm_counter(mm, MM_SHMEMPAGES);
- }
- static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
- {
- return max(mm->hiwater_rss, get_mm_rss(mm));
- }
- static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
- {
- return max(mm->hiwater_vm, mm->total_vm);
- }
- static inline void update_hiwater_rss(struct mm_struct *mm)
- {
- unsigned long _rss = get_mm_rss(mm);
- if ((mm)->hiwater_rss < _rss)
- (mm)->hiwater_rss = _rss;
- }
- static inline void update_hiwater_vm(struct mm_struct *mm)
- {
- if (mm->hiwater_vm < mm->total_vm)
- mm->hiwater_vm = mm->total_vm;
- }
- static inline void reset_mm_hiwater_rss(struct mm_struct *mm)
- {
- mm->hiwater_rss = get_mm_rss(mm);
- }
- static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
- struct mm_struct *mm)
- {
- unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
- if (*maxrss < hiwater_rss)
- *maxrss = hiwater_rss;
- }
- #if defined(SPLIT_RSS_COUNTING)
- void sync_mm_rss(struct mm_struct *mm);
- #else
- static inline void sync_mm_rss(struct mm_struct *mm)
- {
- }
- #endif
- #ifndef CONFIG_ARCH_HAS_PTE_SPECIAL
- static inline int pte_special(pte_t pte)
- {
- return 0;
- }
- static inline pte_t pte_mkspecial(pte_t pte)
- {
- return pte;
- }
- #endif
- #ifndef CONFIG_ARCH_HAS_PTE_DEVMAP
- static inline int pte_devmap(pte_t pte)
- {
- return 0;
- }
- #endif
- int vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot);
- extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
- spinlock_t **ptl);
- static inline pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr,
- spinlock_t **ptl)
- {
- pte_t *ptep;
- __cond_lock(*ptl, ptep = __get_locked_pte(mm, addr, ptl));
- return ptep;
- }
- #ifdef __PAGETABLE_P4D_FOLDED
- static inline int __p4d_alloc(struct mm_struct *mm, pgd_t *pgd,
- unsigned long address)
- {
- return 0;
- }
- #else
- int __p4d_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
- #endif
- #if defined(__PAGETABLE_PUD_FOLDED) || !defined(CONFIG_MMU)
- static inline int __pud_alloc(struct mm_struct *mm, p4d_t *p4d,
- unsigned long address)
- {
- return 0;
- }
- static inline void mm_inc_nr_puds(struct mm_struct *mm) {}
- static inline void mm_dec_nr_puds(struct mm_struct *mm) {}
- #else
- int __pud_alloc(struct mm_struct *mm, p4d_t *p4d, unsigned long address);
- static inline void mm_inc_nr_puds(struct mm_struct *mm)
- {
- if (mm_pud_folded(mm))
- return;
- atomic_long_add(PTRS_PER_PUD * sizeof(pud_t), &mm->pgtables_bytes);
- }
- static inline void mm_dec_nr_puds(struct mm_struct *mm)
- {
- if (mm_pud_folded(mm))
- return;
- atomic_long_sub(PTRS_PER_PUD * sizeof(pud_t), &mm->pgtables_bytes);
- }
- #endif
- #if defined(__PAGETABLE_PMD_FOLDED) || !defined(CONFIG_MMU)
- static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
- unsigned long address)
- {
- return 0;
- }
- static inline void mm_inc_nr_pmds(struct mm_struct *mm) {}
- static inline void mm_dec_nr_pmds(struct mm_struct *mm) {}
- #else
- int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
- static inline void mm_inc_nr_pmds(struct mm_struct *mm)
- {
- if (mm_pmd_folded(mm))
- return;
- atomic_long_add(PTRS_PER_PMD * sizeof(pmd_t), &mm->pgtables_bytes);
- }
- static inline void mm_dec_nr_pmds(struct mm_struct *mm)
- {
- if (mm_pmd_folded(mm))
- return;
- atomic_long_sub(PTRS_PER_PMD * sizeof(pmd_t), &mm->pgtables_bytes);
- }
- #endif
- #ifdef CONFIG_MMU
- static inline void mm_pgtables_bytes_init(struct mm_struct *mm)
- {
- atomic_long_set(&mm->pgtables_bytes, 0);
- }
- static inline unsigned long mm_pgtables_bytes(const struct mm_struct *mm)
- {
- return atomic_long_read(&mm->pgtables_bytes);
- }
- static inline void mm_inc_nr_ptes(struct mm_struct *mm)
- {
- atomic_long_add(PTRS_PER_PTE * sizeof(pte_t), &mm->pgtables_bytes);
- }
- static inline void mm_dec_nr_ptes(struct mm_struct *mm)
- {
- atomic_long_sub(PTRS_PER_PTE * sizeof(pte_t), &mm->pgtables_bytes);
- }
- #else
- static inline void mm_pgtables_bytes_init(struct mm_struct *mm) {}
- static inline unsigned long mm_pgtables_bytes(const struct mm_struct *mm)
- {
- return 0;
- }
- static inline void mm_inc_nr_ptes(struct mm_struct *mm) {}
- static inline void mm_dec_nr_ptes(struct mm_struct *mm) {}
- #endif
- int __pte_alloc(struct mm_struct *mm, pmd_t *pmd);
- int __pte_alloc_kernel(pmd_t *pmd);
- #if defined(CONFIG_MMU)
- static inline p4d_t *p4d_alloc(struct mm_struct *mm, pgd_t *pgd,
- unsigned long address)
- {
- return (unlikely(pgd_none(*pgd)) && __p4d_alloc(mm, pgd, address)) ?
- NULL : p4d_offset(pgd, address);
- }
- static inline pud_t *pud_alloc(struct mm_struct *mm, p4d_t *p4d,
- unsigned long address)
- {
- return (unlikely(p4d_none(*p4d)) && __pud_alloc(mm, p4d, address)) ?
- NULL : pud_offset(p4d, address);
- }
- static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
- {
- return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
- NULL: pmd_offset(pud, address);
- }
- #endif
- #if USE_SPLIT_PTE_PTLOCKS
- #if ALLOC_SPLIT_PTLOCKS
- void __init ptlock_cache_init(void);
- extern bool ptlock_alloc(struct page *page);
- extern void ptlock_free(struct page *page);
- static inline spinlock_t *ptlock_ptr(struct page *page)
- {
- return page->ptl;
- }
- #else
- static inline void ptlock_cache_init(void)
- {
- }
- static inline bool ptlock_alloc(struct page *page)
- {
- return true;
- }
- static inline void ptlock_free(struct page *page)
- {
- }
- static inline spinlock_t *ptlock_ptr(struct page *page)
- {
- return &page->ptl;
- }
- #endif
- static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
- {
- return ptlock_ptr(pmd_page(*pmd));
- }
- static inline bool ptlock_init(struct page *page)
- {
-
- VM_BUG_ON_PAGE(*(unsigned long *)&page->ptl, page);
- if (!ptlock_alloc(page))
- return false;
- spin_lock_init(ptlock_ptr(page));
- return true;
- }
- #else
- static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
- {
- return &mm->page_table_lock;
- }
- static inline void ptlock_cache_init(void) {}
- static inline bool ptlock_init(struct page *page) { return true; }
- static inline void ptlock_free(struct page *page) {}
- #endif
- static inline void pgtable_init(void)
- {
- ptlock_cache_init();
- pgtable_cache_init();
- }
- static inline bool pgtable_pte_page_ctor(struct page *page)
- {
- if (!ptlock_init(page))
- return false;
- __SetPageTable(page);
- inc_lruvec_page_state(page, NR_PAGETABLE);
- return true;
- }
- static inline void pgtable_pte_page_dtor(struct page *page)
- {
- ptlock_free(page);
- __ClearPageTable(page);
- dec_lruvec_page_state(page, NR_PAGETABLE);
- }
- #define pte_offset_map_lock(mm, pmd, address, ptlp) \
- ({ \
- spinlock_t *__ptl = pte_lockptr(mm, pmd); \
- pte_t *__pte = pte_offset_map(pmd, address); \
- *(ptlp) = __ptl; \
- spin_lock(__ptl); \
- __pte; \
- })
- #define pte_unmap_unlock(pte, ptl) do { \
- spin_unlock(ptl); \
- pte_unmap(pte); \
- } while (0)
- #define pte_alloc(mm, pmd) (unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, pmd))
- #define pte_alloc_map(mm, pmd, address) \
- (pte_alloc(mm, pmd) ? NULL : pte_offset_map(pmd, address))
- #define pte_alloc_map_lock(mm, pmd, address, ptlp) \
- (pte_alloc(mm, pmd) ? \
- NULL : pte_offset_map_lock(mm, pmd, address, ptlp))
- #define pte_alloc_kernel(pmd, address) \
- ((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel(pmd))? \
- NULL: pte_offset_kernel(pmd, address))
- #if USE_SPLIT_PMD_PTLOCKS
- static struct page *pmd_to_page(pmd_t *pmd)
- {
- unsigned long mask = ~(PTRS_PER_PMD * sizeof(pmd_t) - 1);
- return virt_to_page((void *)((unsigned long) pmd & mask));
- }
- static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
- {
- return ptlock_ptr(pmd_to_page(pmd));
- }
- static inline bool pmd_ptlock_init(struct page *page)
- {
- #ifdef CONFIG_TRANSPARENT_HUGEPAGE
- page->pmd_huge_pte = NULL;
- #endif
- return ptlock_init(page);
- }
- static inline void pmd_ptlock_free(struct page *page)
- {
- #ifdef CONFIG_TRANSPARENT_HUGEPAGE
- VM_BUG_ON_PAGE(page->pmd_huge_pte, page);
- #endif
- ptlock_free(page);
- }
- #define pmd_huge_pte(mm, pmd) (pmd_to_page(pmd)->pmd_huge_pte)
- #else
- static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
- {
- return &mm->page_table_lock;
- }
- static inline bool pmd_ptlock_init(struct page *page) { return true; }
- static inline void pmd_ptlock_free(struct page *page) {}
- #define pmd_huge_pte(mm, pmd) ((mm)->pmd_huge_pte)
- #endif
- static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd)
- {
- spinlock_t *ptl = pmd_lockptr(mm, pmd);
- spin_lock(ptl);
- return ptl;
- }
- static inline bool pgtable_pmd_page_ctor(struct page *page)
- {
- if (!pmd_ptlock_init(page))
- return false;
- __SetPageTable(page);
- inc_lruvec_page_state(page, NR_PAGETABLE);
- return true;
- }
- static inline void pgtable_pmd_page_dtor(struct page *page)
- {
- pmd_ptlock_free(page);
- __ClearPageTable(page);
- dec_lruvec_page_state(page, NR_PAGETABLE);
- }
- static inline spinlock_t *pud_lockptr(struct mm_struct *mm, pud_t *pud)
- {
- return &mm->page_table_lock;
- }
- static inline spinlock_t *pud_lock(struct mm_struct *mm, pud_t *pud)
- {
- spinlock_t *ptl = pud_lockptr(mm, pud);
- spin_lock(ptl);
- return ptl;
- }
- extern void __init pagecache_init(void);
- extern void free_initmem(void);
- extern unsigned long free_reserved_area(void *start, void *end,
- int poison, const char *s);
- extern void adjust_managed_page_count(struct page *page, long count);
- extern void mem_init_print_info(void);
- extern void reserve_bootmem_region(phys_addr_t start, phys_addr_t end);
- static inline void free_reserved_page(struct page *page)
- {
- ClearPageReserved(page);
- init_page_count(page);
- __free_page(page);
- adjust_managed_page_count(page, 1);
- }
- #define free_highmem_page(page) free_reserved_page(page)
- static inline void mark_page_reserved(struct page *page)
- {
- SetPageReserved(page);
- adjust_managed_page_count(page, -1);
- }
- static inline unsigned long free_initmem_default(int poison)
- {
- extern char __init_begin[], __init_end[];
- return free_reserved_area(&__init_begin, &__init_end,
- poison, "unused kernel image (initmem)");
- }
- static inline unsigned long get_num_physpages(void)
- {
- int nid;
- unsigned long phys_pages = 0;
- for_each_online_node(nid)
- phys_pages += node_present_pages(nid);
- return phys_pages;
- }
- void free_area_init(unsigned long *max_zone_pfn);
- unsigned long node_map_pfn_alignment(void);
- unsigned long __absent_pages_in_range(int nid, unsigned long start_pfn,
- unsigned long end_pfn);
- extern unsigned long absent_pages_in_range(unsigned long start_pfn,
- unsigned long end_pfn);
- extern void get_pfn_range_for_nid(unsigned int nid,
- unsigned long *start_pfn, unsigned long *end_pfn);
- #ifndef CONFIG_NUMA
- static inline int early_pfn_to_nid(unsigned long pfn)
- {
- return 0;
- }
- #else
- extern int __meminit early_pfn_to_nid(unsigned long pfn);
- #endif
- extern void set_dma_reserve(unsigned long new_dma_reserve);
- extern void memmap_init_range(unsigned long, int, unsigned long,
- unsigned long, unsigned long, enum meminit_context,
- struct vmem_altmap *, int migratetype);
- extern void setup_per_zone_wmarks(void);
- extern void calculate_min_free_kbytes(void);
- extern int __meminit init_per_zone_wmark_min(void);
- extern void mem_init(void);
- extern void __init mmap_init(void);
- extern void __show_mem(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);
- static inline void show_mem(unsigned int flags, nodemask_t *nodemask)
- {
- __show_mem(flags, nodemask, MAX_NR_ZONES - 1);
- }
- extern long si_mem_available(void);
- extern void si_meminfo(struct sysinfo * val);
- extern void si_meminfo_node(struct sysinfo *val, int nid);
- #ifdef __HAVE_ARCH_RESERVED_KERNEL_PAGES
- extern unsigned long arch_reserved_kernel_pages(void);
- #endif
- extern __printf(3, 4)
- void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...);
- extern void setup_per_cpu_pageset(void);
- extern int min_free_kbytes;
- extern int watermark_boost_factor;
- extern int watermark_scale_factor;
- extern bool arch_has_descending_max_zone_pfns(void);
- extern atomic_long_t mmap_pages_allocated;
- extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t);
- void vma_interval_tree_insert(struct vm_area_struct *node,
- struct rb_root_cached *root);
- void vma_interval_tree_insert_after(struct vm_area_struct *node,
- struct vm_area_struct *prev,
- struct rb_root_cached *root);
- void vma_interval_tree_remove(struct vm_area_struct *node,
- struct rb_root_cached *root);
- struct vm_area_struct *vma_interval_tree_iter_first(struct rb_root_cached *root,
- unsigned long start, unsigned long last);
- struct vm_area_struct *vma_interval_tree_iter_next(struct vm_area_struct *node,
- unsigned long start, unsigned long last);
- #define vma_interval_tree_foreach(vma, root, start, last) \
- for (vma = vma_interval_tree_iter_first(root, start, last); \
- vma; vma = vma_interval_tree_iter_next(vma, start, last))
- void anon_vma_interval_tree_insert(struct anon_vma_chain *node,
- struct rb_root_cached *root);
- void anon_vma_interval_tree_remove(struct anon_vma_chain *node,
- struct rb_root_cached *root);
- struct anon_vma_chain *
- anon_vma_interval_tree_iter_first(struct rb_root_cached *root,
- unsigned long start, unsigned long last);
- struct anon_vma_chain *anon_vma_interval_tree_iter_next(
- struct anon_vma_chain *node, unsigned long start, unsigned long last);
- #ifdef CONFIG_DEBUG_VM_RB
- void anon_vma_interval_tree_verify(struct anon_vma_chain *node);
- #endif
- #define anon_vma_interval_tree_foreach(avc, root, start, last) \
- for (avc = anon_vma_interval_tree_iter_first(root, start, last); \
- avc; avc = anon_vma_interval_tree_iter_next(avc, start, last))
- extern int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin);
- extern int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
- unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert,
- struct vm_area_struct *expand);
- static inline int vma_adjust(struct vm_area_struct *vma, unsigned long start,
- unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert)
- {
- return __vma_adjust(vma, start, end, pgoff, insert, NULL);
- }
- extern struct vm_area_struct *vma_merge(struct mm_struct *,
- struct vm_area_struct *prev, unsigned long addr, unsigned long end,
- unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,
- struct mempolicy *, struct vm_userfaultfd_ctx, struct anon_vma_name *);
- extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);
- extern int __split_vma(struct mm_struct *, struct vm_area_struct *,
- unsigned long addr, int new_below);
- extern int split_vma(struct mm_struct *, struct vm_area_struct *,
- unsigned long addr, int new_below);
- extern int insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
- extern void unlink_file_vma(struct vm_area_struct *);
- extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
- unsigned long addr, unsigned long len, pgoff_t pgoff,
- bool *need_rmap_locks);
- extern void exit_mmap(struct mm_struct *);
- void vma_mas_store(struct vm_area_struct *vma, struct ma_state *mas);
- void vma_mas_remove(struct vm_area_struct *vma, struct ma_state *mas);
- static inline int check_data_rlimit(unsigned long rlim,
- unsigned long new,
- unsigned long start,
- unsigned long end_data,
- unsigned long start_data)
- {
- if (rlim < RLIM_INFINITY) {
- if (((new - start) + (end_data - start_data)) > rlim)
- return -ENOSPC;
- }
- return 0;
- }
- extern int mm_take_all_locks(struct mm_struct *mm);
- extern void mm_drop_all_locks(struct mm_struct *mm);
- extern int set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
- extern int replace_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
- extern struct file *get_mm_exe_file(struct mm_struct *mm);
- extern struct file *get_task_exe_file(struct task_struct *task);
- extern bool may_expand_vm(struct mm_struct *, vm_flags_t, unsigned long npages);
- extern void vm_stat_account(struct mm_struct *, vm_flags_t, long npages);
- extern bool vma_is_special_mapping(const struct vm_area_struct *vma,
- const struct vm_special_mapping *sm);
- extern struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
- unsigned long addr, unsigned long len,
- unsigned long flags,
- const struct vm_special_mapping *spec);
- extern int install_special_mapping(struct mm_struct *mm,
- unsigned long addr, unsigned long len,
- unsigned long flags, struct page **pages);
- unsigned long randomize_stack_top(unsigned long stack_top);
- unsigned long randomize_page(unsigned long start, unsigned long range);
- extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
- extern unsigned long mmap_region(struct file *file, unsigned long addr,
- unsigned long len, vm_flags_t vm_flags, unsigned long pgoff,
- struct list_head *uf);
- extern unsigned long do_mmap(struct file *file, unsigned long addr,
- unsigned long len, unsigned long prot, unsigned long flags,
- unsigned long pgoff, unsigned long *populate, struct list_head *uf);
- extern int do_mas_munmap(struct ma_state *mas, struct mm_struct *mm,
- unsigned long start, size_t len, struct list_head *uf,
- bool downgrade);
- extern int do_munmap(struct mm_struct *, unsigned long, size_t,
- struct list_head *uf);
- extern int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int behavior);
- #ifdef CONFIG_MMU
- extern int __mm_populate(unsigned long addr, unsigned long len,
- int ignore_errors);
- static inline void mm_populate(unsigned long addr, unsigned long len)
- {
-
- (void) __mm_populate(addr, len, 1);
- }
- #else
- static inline void mm_populate(unsigned long addr, unsigned long len) {}
- #endif
- extern int __must_check vm_brk(unsigned long, unsigned long);
- extern int __must_check vm_brk_flags(unsigned long, unsigned long, unsigned long);
- extern int vm_munmap(unsigned long, size_t);
- extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
- unsigned long, unsigned long,
- unsigned long, unsigned long);
- struct vm_unmapped_area_info {
- #define VM_UNMAPPED_AREA_TOPDOWN 1
- unsigned long flags;
- unsigned long length;
- unsigned long low_limit;
- unsigned long high_limit;
- unsigned long align_mask;
- unsigned long align_offset;
- };
- extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info);
- extern void truncate_inode_pages(struct address_space *, loff_t);
- extern void truncate_inode_pages_range(struct address_space *,
- loff_t lstart, loff_t lend);
- extern void truncate_inode_pages_final(struct address_space *);
- extern vm_fault_t filemap_fault(struct vm_fault *vmf);
- extern vm_fault_t filemap_map_pages(struct vm_fault *vmf,
- pgoff_t start_pgoff, pgoff_t end_pgoff);
- extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf);
- extern unsigned long stack_guard_gap;
- int expand_stack_locked(struct vm_area_struct *vma, unsigned long address);
- struct vm_area_struct *expand_stack(struct mm_struct * mm, unsigned long addr);
- int expand_downwards(struct vm_area_struct *vma, unsigned long address);
- extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
- extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
- struct vm_area_struct **pprev);
- struct vm_area_struct *find_vma_intersection(struct mm_struct *mm,
- unsigned long start_addr, unsigned long end_addr);
- static inline
- struct vm_area_struct *vma_lookup(struct mm_struct *mm, unsigned long addr)
- {
- return mtree_load(&mm->mm_mt, addr);
- }
- static inline unsigned long vm_start_gap(struct vm_area_struct *vma)
- {
- unsigned long vm_start = vma->vm_start;
- if (vma->vm_flags & VM_GROWSDOWN) {
- vm_start -= stack_guard_gap;
- if (vm_start > vma->vm_start)
- vm_start = 0;
- }
- return vm_start;
- }
- static inline unsigned long vm_end_gap(struct vm_area_struct *vma)
- {
- unsigned long vm_end = vma->vm_end;
- if (vma->vm_flags & VM_GROWSUP) {
- vm_end += stack_guard_gap;
- if (vm_end < vma->vm_end)
- vm_end = -PAGE_SIZE;
- }
- return vm_end;
- }
- static inline unsigned long vma_pages(struct vm_area_struct *vma)
- {
- return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
- }
- static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
- unsigned long vm_start, unsigned long vm_end)
- {
- struct vm_area_struct *vma = vma_lookup(mm, vm_start);
- if (vma && (vma->vm_start != vm_start || vma->vm_end != vm_end))
- vma = NULL;
- return vma;
- }
- static inline bool range_in_vma(struct vm_area_struct *vma,
- unsigned long start, unsigned long end)
- {
- return (vma && vma->vm_start <= start && end <= vma->vm_end);
- }
- #ifdef CONFIG_MMU
- pgprot_t vm_get_page_prot(unsigned long vm_flags);
- void vma_set_page_prot(struct vm_area_struct *vma);
- #else
- static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
- {
- return __pgprot(0);
- }
- static inline void vma_set_page_prot(struct vm_area_struct *vma)
- {
- vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
- }
- #endif
- void vma_set_file(struct vm_area_struct *vma, struct file *file);
- #ifdef CONFIG_NUMA_BALANCING
- unsigned long change_prot_numa(struct vm_area_struct *vma,
- unsigned long start, unsigned long end);
- #endif
- struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
- struct vm_area_struct *find_extend_vma_locked(struct mm_struct *,
- unsigned long addr);
- int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
- unsigned long pfn, unsigned long size, pgprot_t);
- int remap_pfn_range_notrack(struct vm_area_struct *vma, unsigned long addr,
- unsigned long pfn, unsigned long size, pgprot_t prot);
- int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
- int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr,
- struct page **pages, unsigned long *num);
- int vm_map_pages(struct vm_area_struct *vma, struct page **pages,
- unsigned long num);
- int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages,
- unsigned long num);
- vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
- unsigned long pfn);
- vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
- unsigned long pfn, pgprot_t pgprot);
- vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
- pfn_t pfn);
- vm_fault_t vmf_insert_mixed_prot(struct vm_area_struct *vma, unsigned long addr,
- pfn_t pfn, pgprot_t pgprot);
- vm_fault_t vmf_insert_mixed_mkwrite(struct vm_area_struct *vma,
- unsigned long addr, pfn_t pfn);
- int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len);
- static inline vm_fault_t vmf_insert_page(struct vm_area_struct *vma,
- unsigned long addr, struct page *page)
- {
- int err = vm_insert_page(vma, addr, page);
- if (err == -ENOMEM)
- return VM_FAULT_OOM;
- if (err < 0 && err != -EBUSY)
- return VM_FAULT_SIGBUS;
- return VM_FAULT_NOPAGE;
- }
- #ifndef io_remap_pfn_range
- static inline int io_remap_pfn_range(struct vm_area_struct *vma,
- unsigned long addr, unsigned long pfn,
- unsigned long size, pgprot_t prot)
- {
- return remap_pfn_range(vma, addr, pfn, size, pgprot_decrypted(prot));
- }
- #endif
- static inline vm_fault_t vmf_error(int err)
- {
- if (err == -ENOMEM)
- return VM_FAULT_OOM;
- return VM_FAULT_SIGBUS;
- }
- struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
- unsigned int foll_flags);
- #define FOLL_WRITE 0x01
- #define FOLL_TOUCH 0x02
- #define FOLL_GET 0x04
- #define FOLL_DUMP 0x08
- #define FOLL_FORCE 0x10
- #define FOLL_NOWAIT 0x20
- #define FOLL_NOFAULT 0x80
- #define FOLL_HWPOISON 0x100
- #define FOLL_MIGRATION 0x400
- #define FOLL_TRIED 0x800
- #define FOLL_REMOTE 0x2000
- #define FOLL_ANON 0x8000
- #define FOLL_LONGTERM 0x10000
- #define FOLL_SPLIT_PMD 0x20000
- #define FOLL_PIN 0x40000
- #define FOLL_FAST_ONLY 0x80000
- static inline int vm_fault_to_errno(vm_fault_t vm_fault, int foll_flags)
- {
- if (vm_fault & VM_FAULT_OOM)
- return -ENOMEM;
- if (vm_fault & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE))
- return (foll_flags & FOLL_HWPOISON) ? -EHWPOISON : -EFAULT;
- if (vm_fault & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV))
- return -EFAULT;
- return 0;
- }
- static inline bool gup_must_unshare(unsigned int flags, struct page *page)
- {
-
- if ((flags & (FOLL_WRITE | FOLL_PIN)) != FOLL_PIN)
- return false;
-
- if (!PageAnon(page))
- return false;
-
- if (IS_ENABLED(CONFIG_HAVE_FAST_GUP))
- smp_rmb();
-
- if (unlikely(!PageHead(page) && PageHuge(page)))
- page = compound_head(page);
-
- return !PageAnonExclusive(page);
- }
- static inline bool gup_can_follow_protnone(unsigned int flags)
- {
-
- return flags & FOLL_FORCE;
- }
- typedef int (*pte_fn_t)(pte_t *pte, unsigned long addr, void *data);
- extern int apply_to_page_range(struct mm_struct *mm, unsigned long address,
- unsigned long size, pte_fn_t fn, void *data);
- extern int apply_to_existing_page_range(struct mm_struct *mm,
- unsigned long address, unsigned long size,
- pte_fn_t fn, void *data);
- extern void __init init_mem_debugging_and_hardening(void);
- #ifdef CONFIG_PAGE_POISONING
- extern void __kernel_poison_pages(struct page *page, int numpages);
- extern void __kernel_unpoison_pages(struct page *page, int numpages);
- extern bool _page_poisoning_enabled_early;
- DECLARE_STATIC_KEY_FALSE(_page_poisoning_enabled);
- static inline bool page_poisoning_enabled(void)
- {
- return _page_poisoning_enabled_early;
- }
- static inline bool page_poisoning_enabled_static(void)
- {
- return static_branch_unlikely(&_page_poisoning_enabled);
- }
- static inline void kernel_poison_pages(struct page *page, int numpages)
- {
- if (page_poisoning_enabled_static())
- __kernel_poison_pages(page, numpages);
- }
- static inline void kernel_unpoison_pages(struct page *page, int numpages)
- {
- if (page_poisoning_enabled_static())
- __kernel_unpoison_pages(page, numpages);
- }
- #else
- static inline bool page_poisoning_enabled(void) { return false; }
- static inline bool page_poisoning_enabled_static(void) { return false; }
- static inline void __kernel_poison_pages(struct page *page, int nunmpages) { }
- static inline void kernel_poison_pages(struct page *page, int numpages) { }
- static inline void kernel_unpoison_pages(struct page *page, int numpages) { }
- #endif
- DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_ALLOC_DEFAULT_ON, init_on_alloc);
- static inline bool want_init_on_alloc(gfp_t flags)
- {
- if (static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON,
- &init_on_alloc))
- return true;
- return flags & __GFP_ZERO;
- }
- DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_FREE_DEFAULT_ON, init_on_free);
- static inline bool want_init_on_free(void)
- {
- return static_branch_maybe(CONFIG_INIT_ON_FREE_DEFAULT_ON,
- &init_on_free);
- }
- extern bool _debug_pagealloc_enabled_early;
- DECLARE_STATIC_KEY_FALSE(_debug_pagealloc_enabled);
- static inline bool debug_pagealloc_enabled(void)
- {
- return IS_ENABLED(CONFIG_DEBUG_PAGEALLOC) &&
- _debug_pagealloc_enabled_early;
- }
- static inline bool debug_pagealloc_enabled_static(void)
- {
- if (!IS_ENABLED(CONFIG_DEBUG_PAGEALLOC))
- return false;
- return static_branch_unlikely(&_debug_pagealloc_enabled);
- }
- #ifdef CONFIG_DEBUG_PAGEALLOC
- extern void __kernel_map_pages(struct page *page, int numpages, int enable);
- static inline void debug_pagealloc_map_pages(struct page *page, int numpages)
- {
- if (debug_pagealloc_enabled_static())
- __kernel_map_pages(page, numpages, 1);
- }
- static inline void debug_pagealloc_unmap_pages(struct page *page, int numpages)
- {
- if (debug_pagealloc_enabled_static())
- __kernel_map_pages(page, numpages, 0);
- }
- #else
- static inline void debug_pagealloc_map_pages(struct page *page, int numpages) {}
- static inline void debug_pagealloc_unmap_pages(struct page *page, int numpages) {}
- #endif
- #ifdef __HAVE_ARCH_GATE_AREA
- extern struct vm_area_struct *get_gate_vma(struct mm_struct *mm);
- extern int in_gate_area_no_mm(unsigned long addr);
- extern int in_gate_area(struct mm_struct *mm, unsigned long addr);
- #else
- static inline struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
- {
- return NULL;
- }
- static inline int in_gate_area_no_mm(unsigned long addr) { return 0; }
- static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
- {
- return 0;
- }
- #endif
- extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
- #ifdef CONFIG_SYSCTL
- extern int sysctl_drop_caches;
- int drop_caches_sysctl_handler(struct ctl_table *, int, void *, size_t *,
- loff_t *);
- #endif
- void drop_slab(void);
- #ifndef CONFIG_MMU
- #define randomize_va_space 0
- #else
- extern int randomize_va_space;
- #endif
- const char * arch_vma_name(struct vm_area_struct *vma);
- #ifdef CONFIG_MMU
- void print_vma_addr(char *prefix, unsigned long rip);
- #else
- static inline void print_vma_addr(char *prefix, unsigned long rip)
- {
- }
- #endif
- void *sparse_buffer_alloc(unsigned long size);
- struct page * __populate_section_memmap(unsigned long pfn,
- unsigned long nr_pages, int nid, struct vmem_altmap *altmap,
- struct dev_pagemap *pgmap);
- pgd_t *vmemmap_pgd_populate(unsigned long addr, int node);
- p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node);
- pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node);
- pmd_t *vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node);
- pte_t *vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node,
- struct vmem_altmap *altmap, struct page *reuse);
- void *vmemmap_alloc_block(unsigned long size, int node);
- struct vmem_altmap;
- void *vmemmap_alloc_block_buf(unsigned long size, int node,
- struct vmem_altmap *altmap);
- void vmemmap_verify(pte_t *, int, unsigned long, unsigned long);
- int vmemmap_populate_basepages(unsigned long start, unsigned long end,
- int node, struct vmem_altmap *altmap);
- int vmemmap_populate(unsigned long start, unsigned long end, int node,
- struct vmem_altmap *altmap);
- void vmemmap_populate_print_last(void);
- #ifdef CONFIG_MEMORY_HOTPLUG
- void vmemmap_free(unsigned long start, unsigned long end,
- struct vmem_altmap *altmap);
- #endif
- void register_page_bootmem_memmap(unsigned long section_nr, struct page *map,
- unsigned long nr_pages);
- enum mf_flags {
- MF_COUNT_INCREASED = 1 << 0,
- MF_ACTION_REQUIRED = 1 << 1,
- MF_MUST_KILL = 1 << 2,
- MF_SOFT_OFFLINE = 1 << 3,
- MF_UNPOISON = 1 << 4,
- MF_SW_SIMULATED = 1 << 5,
- MF_NO_RETRY = 1 << 6,
- };
- int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index,
- unsigned long count, int mf_flags);
- extern int memory_failure(unsigned long pfn, int flags);
- extern void memory_failure_queue_kick(int cpu);
- extern int unpoison_memory(unsigned long pfn);
- extern int sysctl_memory_failure_early_kill;
- extern int sysctl_memory_failure_recovery;
- extern void shake_page(struct page *p);
- extern atomic_long_t num_poisoned_pages __read_mostly;
- extern int soft_offline_page(unsigned long pfn, int flags);
- #ifdef CONFIG_MEMORY_FAILURE
- extern void memory_failure_queue(unsigned long pfn, int flags);
- extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags);
- #else
- static inline void memory_failure_queue(unsigned long pfn, int flags)
- {
- }
- static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
- {
- return 0;
- }
- #endif
- #ifndef arch_memory_failure
- static inline int arch_memory_failure(unsigned long pfn, int flags)
- {
- return -ENXIO;
- }
- #endif
- #ifndef arch_is_platform_page
- static inline bool arch_is_platform_page(u64 paddr)
- {
- return false;
- }
- #endif
- enum mf_result {
- MF_IGNORED,
- MF_FAILED,
- MF_DELAYED,
- MF_RECOVERED,
- };
- enum mf_action_page_type {
- MF_MSG_KERNEL,
- MF_MSG_KERNEL_HIGH_ORDER,
- MF_MSG_SLAB,
- MF_MSG_DIFFERENT_COMPOUND,
- MF_MSG_HUGE,
- MF_MSG_FREE_HUGE,
- MF_MSG_UNMAP_FAILED,
- MF_MSG_DIRTY_SWAPCACHE,
- MF_MSG_CLEAN_SWAPCACHE,
- MF_MSG_DIRTY_MLOCKED_LRU,
- MF_MSG_CLEAN_MLOCKED_LRU,
- MF_MSG_DIRTY_UNEVICTABLE_LRU,
- MF_MSG_CLEAN_UNEVICTABLE_LRU,
- MF_MSG_DIRTY_LRU,
- MF_MSG_CLEAN_LRU,
- MF_MSG_TRUNCATED_LRU,
- MF_MSG_BUDDY,
- MF_MSG_DAX,
- MF_MSG_UNSPLIT_THP,
- MF_MSG_UNKNOWN,
- };
- #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
- extern void clear_huge_page(struct page *page,
- unsigned long addr_hint,
- unsigned int pages_per_huge_page);
- extern void copy_user_huge_page(struct page *dst, struct page *src,
- unsigned long addr_hint,
- struct vm_area_struct *vma,
- unsigned int pages_per_huge_page);
- extern long copy_huge_page_from_user(struct page *dst_page,
- const void __user *usr_src,
- unsigned int pages_per_huge_page,
- bool allow_pagefault);
- static inline bool vma_is_special_huge(const struct vm_area_struct *vma)
- {
- return vma_is_dax(vma) || (vma->vm_file &&
- (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)));
- }
- #endif
- #ifdef CONFIG_DEBUG_PAGEALLOC
- extern unsigned int _debug_guardpage_minorder;
- DECLARE_STATIC_KEY_FALSE(_debug_guardpage_enabled);
- static inline unsigned int debug_guardpage_minorder(void)
- {
- return _debug_guardpage_minorder;
- }
- static inline bool debug_guardpage_enabled(void)
- {
- return static_branch_unlikely(&_debug_guardpage_enabled);
- }
- static inline bool page_is_guard(struct page *page)
- {
- if (!debug_guardpage_enabled())
- return false;
- return PageGuard(page);
- }
- #else
- static inline unsigned int debug_guardpage_minorder(void) { return 0; }
- static inline bool debug_guardpage_enabled(void) { return false; }
- static inline bool page_is_guard(struct page *page) { return false; }
- #endif
- #if MAX_NUMNODES > 1
- void __init setup_nr_node_ids(void);
- #else
- static inline void setup_nr_node_ids(void) {}
- #endif
- struct seq_file;
- void seq_printf(struct seq_file *m, const char *f, ...);
- static inline void show_val_meminfo(struct seq_file *m,
- const char *str, long size)
- {
- char name[17];
- int len = strlen(str);
- if (len <= 15) {
- sprintf(name, "%s:", str);
- } else {
- strncpy(name, str, 15);
- name[15] = ':';
- name[16] = '\0';
- }
- seq_printf(m, "%-16s%8ld kB\n", name, size);
- }
- extern int memcmp_pages(struct page *page1, struct page *page2);
- static inline int pages_identical(struct page *page1, struct page *page2)
- {
- return !memcmp_pages(page1, page2);
- }
- #ifdef CONFIG_MAPPING_DIRTY_HELPERS
- unsigned long clean_record_shared_mapping_range(struct address_space *mapping,
- pgoff_t first_index, pgoff_t nr,
- pgoff_t bitmap_pgoff,
- unsigned long *bitmap,
- pgoff_t *start,
- pgoff_t *end);
- unsigned long wp_shared_mapping_range(struct address_space *mapping,
- pgoff_t first_index, pgoff_t nr);
- #endif
- extern int sysctl_nr_trim_pages;
- extern int reclaim_shmem_address_space(struct address_space *mapping);
- #ifdef CONFIG_PRINTK
- void mem_dump_obj(void *object);
- #else
- static inline void mem_dump_obj(void *object) {}
- #endif
- static inline int seal_check_future_write(int seals, struct vm_area_struct *vma)
- {
- if (seals & F_SEAL_FUTURE_WRITE) {
-
- if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE))
- return -EPERM;
-
- if (vma->vm_flags & VM_SHARED)
- vm_flags_clear(vma, VM_MAYWRITE);
- }
- return 0;
- }
- #ifdef CONFIG_ANON_VMA_NAME
- int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
- unsigned long len_in,
- struct anon_vma_name *anon_name);
- #else
- static inline int
- madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
- unsigned long len_in, struct anon_vma_name *anon_name) {
- return 0;
- }
- #endif
- #define GPU_PAGE_MAGIC (0x9A0E06B9A0E)
- #endif
|