1
0

patch-realtime 818 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362
  1. diff -Nur linux-4.1.26.orig/arch/alpha/mm/fault.c linux-4.1.26/arch/alpha/mm/fault.c
  2. --- linux-4.1.26.orig/arch/alpha/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  3. +++ linux-4.1.26/arch/alpha/mm/fault.c 2016-06-19 15:30:54.915151887 +0200
  4. @@ -23,8 +23,7 @@
  5. #include <linux/smp.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/module.h>
  8. -
  9. -#include <asm/uaccess.h>
  10. +#include <linux/uaccess.h>
  11. extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
  12. @@ -107,7 +106,7 @@
  13. /* If we're in an interrupt context, or have no user context,
  14. we must not take the fault. */
  15. - if (!mm || in_atomic())
  16. + if (!mm || faulthandler_disabled())
  17. goto no_context;
  18. #ifdef CONFIG_ALPHA_LARGE_VMALLOC
  19. diff -Nur linux-4.1.26.orig/arch/arc/include/asm/futex.h linux-4.1.26/arch/arc/include/asm/futex.h
  20. --- linux-4.1.26.orig/arch/arc/include/asm/futex.h 2016-06-07 01:13:11.000000000 +0200
  21. +++ linux-4.1.26/arch/arc/include/asm/futex.h 2016-06-19 15:30:54.915151887 +0200
  22. @@ -53,7 +53,7 @@
  23. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
  24. return -EFAULT;
  25. - pagefault_disable(); /* implies preempt_disable() */
  26. + pagefault_disable();
  27. switch (op) {
  28. case FUTEX_OP_SET:
  29. @@ -75,7 +75,7 @@
  30. ret = -ENOSYS;
  31. }
  32. - pagefault_enable(); /* subsumes preempt_enable() */
  33. + pagefault_enable();
  34. if (!ret) {
  35. switch (cmp) {
  36. @@ -104,7 +104,7 @@
  37. return ret;
  38. }
  39. -/* Compare-xchg with preemption disabled.
  40. +/* Compare-xchg with pagefaults disabled.
  41. * Notes:
  42. * -Best-Effort: Exchg happens only if compare succeeds.
  43. * If compare fails, returns; leaving retry/looping to upper layers
  44. @@ -121,7 +121,7 @@
  45. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
  46. return -EFAULT;
  47. - pagefault_disable(); /* implies preempt_disable() */
  48. + pagefault_disable();
  49. /* TBD : can use llock/scond */
  50. __asm__ __volatile__(
  51. @@ -142,7 +142,7 @@
  52. : "r"(oldval), "r"(newval), "r"(uaddr), "ir"(-EFAULT)
  53. : "cc", "memory");
  54. - pagefault_enable(); /* subsumes preempt_enable() */
  55. + pagefault_enable();
  56. *uval = val;
  57. return val;
  58. diff -Nur linux-4.1.26.orig/arch/arc/mm/fault.c linux-4.1.26/arch/arc/mm/fault.c
  59. --- linux-4.1.26.orig/arch/arc/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  60. +++ linux-4.1.26/arch/arc/mm/fault.c 2016-06-19 15:30:54.915151887 +0200
  61. @@ -86,7 +86,7 @@
  62. * If we're in an interrupt or have no user
  63. * context, we must not take the fault..
  64. */
  65. - if (in_atomic() || !mm)
  66. + if (faulthandler_disabled() || !mm)
  67. goto no_context;
  68. if (user_mode(regs))
  69. diff -Nur linux-4.1.26.orig/arch/arm/include/asm/cmpxchg.h linux-4.1.26/arch/arm/include/asm/cmpxchg.h
  70. --- linux-4.1.26.orig/arch/arm/include/asm/cmpxchg.h 2016-06-07 01:13:11.000000000 +0200
  71. +++ linux-4.1.26/arch/arm/include/asm/cmpxchg.h 2016-06-19 15:30:54.919152041 +0200
  72. @@ -129,6 +129,8 @@
  73. #else /* min ARCH >= ARMv6 */
  74. +#define __HAVE_ARCH_CMPXCHG 1
  75. +
  76. extern void __bad_cmpxchg(volatile void *ptr, int size);
  77. /*
  78. diff -Nur linux-4.1.26.orig/arch/arm/include/asm/futex.h linux-4.1.26/arch/arm/include/asm/futex.h
  79. --- linux-4.1.26.orig/arch/arm/include/asm/futex.h 2016-06-07 01:13:11.000000000 +0200
  80. +++ linux-4.1.26/arch/arm/include/asm/futex.h 2016-06-19 15:30:54.919152041 +0200
  81. @@ -93,6 +93,7 @@
  82. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  83. return -EFAULT;
  84. + preempt_disable();
  85. __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
  86. "1: " TUSER(ldr) " %1, [%4]\n"
  87. " teq %1, %2\n"
  88. @@ -104,6 +105,8 @@
  89. : "cc", "memory");
  90. *uval = val;
  91. + preempt_enable();
  92. +
  93. return ret;
  94. }
  95. @@ -124,7 +127,10 @@
  96. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  97. return -EFAULT;
  98. - pagefault_disable(); /* implies preempt_disable() */
  99. +#ifndef CONFIG_SMP
  100. + preempt_disable();
  101. +#endif
  102. + pagefault_disable();
  103. switch (op) {
  104. case FUTEX_OP_SET:
  105. @@ -146,7 +152,10 @@
  106. ret = -ENOSYS;
  107. }
  108. - pagefault_enable(); /* subsumes preempt_enable() */
  109. + pagefault_enable();
  110. +#ifndef CONFIG_SMP
  111. + preempt_enable();
  112. +#endif
  113. if (!ret) {
  114. switch (cmp) {
  115. diff -Nur linux-4.1.26.orig/arch/arm/include/asm/switch_to.h linux-4.1.26/arch/arm/include/asm/switch_to.h
  116. --- linux-4.1.26.orig/arch/arm/include/asm/switch_to.h 2016-06-07 01:13:11.000000000 +0200
  117. +++ linux-4.1.26/arch/arm/include/asm/switch_to.h 2016-06-19 15:30:54.919152041 +0200
  118. @@ -3,6 +3,13 @@
  119. #include <linux/thread_info.h>
  120. +#if defined CONFIG_PREEMPT_RT_FULL && defined CONFIG_HIGHMEM
  121. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p);
  122. +#else
  123. +static inline void
  124. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  125. +#endif
  126. +
  127. /*
  128. * For v7 SMP cores running a preemptible kernel we may be pre-empted
  129. * during a TLB maintenance operation, so execute an inner-shareable dsb
  130. @@ -22,6 +29,7 @@
  131. #define switch_to(prev,next,last) \
  132. do { \
  133. + switch_kmaps(prev, next); \
  134. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  135. } while (0)
  136. diff -Nur linux-4.1.26.orig/arch/arm/include/asm/thread_info.h linux-4.1.26/arch/arm/include/asm/thread_info.h
  137. --- linux-4.1.26.orig/arch/arm/include/asm/thread_info.h 2016-06-07 01:13:11.000000000 +0200
  138. +++ linux-4.1.26/arch/arm/include/asm/thread_info.h 2016-06-19 15:30:54.919152041 +0200
  139. @@ -50,6 +50,7 @@
  140. struct thread_info {
  141. unsigned long flags; /* low level flags */
  142. int preempt_count; /* 0 => preemptable, <0 => bug */
  143. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  144. mm_segment_t addr_limit; /* address limit */
  145. struct task_struct *task; /* main task structure */
  146. __u32 cpu; /* cpu */
  147. @@ -147,6 +148,7 @@
  148. #define TIF_SIGPENDING 0
  149. #define TIF_NEED_RESCHED 1
  150. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  151. +#define TIF_NEED_RESCHED_LAZY 3
  152. #define TIF_UPROBE 7
  153. #define TIF_SYSCALL_TRACE 8
  154. #define TIF_SYSCALL_AUDIT 9
  155. @@ -160,6 +162,7 @@
  156. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  157. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  158. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  159. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  160. #define _TIF_UPROBE (1 << TIF_UPROBE)
  161. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  162. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  163. diff -Nur linux-4.1.26.orig/arch/arm/Kconfig linux-4.1.26/arch/arm/Kconfig
  164. --- linux-4.1.26.orig/arch/arm/Kconfig 2016-06-07 01:13:11.000000000 +0200
  165. +++ linux-4.1.26/arch/arm/Kconfig 2016-06-19 15:30:54.919152041 +0200
  166. @@ -31,7 +31,7 @@
  167. select HARDIRQS_SW_RESEND
  168. select HAVE_ARCH_AUDITSYSCALL if (AEABI && !OABI_COMPAT)
  169. select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
  170. - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
  171. + select HAVE_ARCH_JUMP_LABEL if (!XIP_KERNEL && !PREEMPT_RT_BASE)
  172. select HAVE_ARCH_KGDB
  173. select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
  174. select HAVE_ARCH_TRACEHOOK
  175. @@ -66,6 +66,7 @@
  176. select HAVE_PERF_EVENTS
  177. select HAVE_PERF_REGS
  178. select HAVE_PERF_USER_STACK_DUMP
  179. + select HAVE_PREEMPT_LAZY
  180. select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
  181. select HAVE_REGS_AND_STACK_ACCESS_API
  182. select HAVE_SYSCALL_TRACEPOINTS
  183. diff -Nur linux-4.1.26.orig/arch/arm/kernel/asm-offsets.c linux-4.1.26/arch/arm/kernel/asm-offsets.c
  184. --- linux-4.1.26.orig/arch/arm/kernel/asm-offsets.c 2016-06-07 01:13:11.000000000 +0200
  185. +++ linux-4.1.26/arch/arm/kernel/asm-offsets.c 2016-06-19 15:30:54.919152041 +0200
  186. @@ -65,6 +65,7 @@
  187. BLANK();
  188. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  189. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  190. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  191. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  192. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  193. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  194. diff -Nur linux-4.1.26.orig/arch/arm/kernel/entry-armv.S linux-4.1.26/arch/arm/kernel/entry-armv.S
  195. --- linux-4.1.26.orig/arch/arm/kernel/entry-armv.S 2016-06-07 01:13:11.000000000 +0200
  196. +++ linux-4.1.26/arch/arm/kernel/entry-armv.S 2016-06-19 15:30:54.919152041 +0200
  197. @@ -208,11 +208,18 @@
  198. #ifdef CONFIG_PREEMPT
  199. get_thread_info tsk
  200. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  201. - ldr r0, [tsk, #TI_FLAGS] @ get flags
  202. teq r8, #0 @ if preempt count != 0
  203. + bne 1f @ return from exeption
  204. + ldr r0, [tsk, #TI_FLAGS] @ get flags
  205. + tst r0, #_TIF_NEED_RESCHED @ if NEED_RESCHED is set
  206. + blne svc_preempt @ preempt!
  207. +
  208. + ldr r8, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  209. + teq r8, #0 @ if preempt lazy count != 0
  210. movne r0, #0 @ force flags to 0
  211. - tst r0, #_TIF_NEED_RESCHED
  212. + tst r0, #_TIF_NEED_RESCHED_LAZY
  213. blne svc_preempt
  214. +1:
  215. #endif
  216. svc_exit r5, irq = 1 @ return from exception
  217. @@ -227,6 +234,8 @@
  218. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  219. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  220. tst r0, #_TIF_NEED_RESCHED
  221. + bne 1b
  222. + tst r0, #_TIF_NEED_RESCHED_LAZY
  223. reteq r8 @ go again
  224. b 1b
  225. #endif
  226. diff -Nur linux-4.1.26.orig/arch/arm/kernel/process.c linux-4.1.26/arch/arm/kernel/process.c
  227. --- linux-4.1.26.orig/arch/arm/kernel/process.c 2016-06-07 01:13:11.000000000 +0200
  228. +++ linux-4.1.26/arch/arm/kernel/process.c 2016-06-19 15:30:54.919152041 +0200
  229. @@ -290,6 +290,30 @@
  230. }
  231. #ifdef CONFIG_MMU
  232. +/*
  233. + * CONFIG_SPLIT_PTLOCK_CPUS results in a page->ptl lock. If the lock is not
  234. + * initialized by pgtable_page_ctor() then a coredump of the vector page will
  235. + * fail.
  236. + */
  237. +static int __init vectors_user_mapping_init_page(void)
  238. +{
  239. + struct page *page;
  240. + unsigned long addr = 0xffff0000;
  241. + pgd_t *pgd;
  242. + pud_t *pud;
  243. + pmd_t *pmd;
  244. +
  245. + pgd = pgd_offset_k(addr);
  246. + pud = pud_offset(pgd, addr);
  247. + pmd = pmd_offset(pud, addr);
  248. + page = pmd_page(*(pmd));
  249. +
  250. + pgtable_page_ctor(page);
  251. +
  252. + return 0;
  253. +}
  254. +late_initcall(vectors_user_mapping_init_page);
  255. +
  256. #ifdef CONFIG_KUSER_HELPERS
  257. /*
  258. * The vectors page is always readable from user space for the
  259. diff -Nur linux-4.1.26.orig/arch/arm/kernel/signal.c linux-4.1.26/arch/arm/kernel/signal.c
  260. --- linux-4.1.26.orig/arch/arm/kernel/signal.c 2016-06-07 01:13:11.000000000 +0200
  261. +++ linux-4.1.26/arch/arm/kernel/signal.c 2016-06-19 15:30:54.919152041 +0200
  262. @@ -568,7 +568,8 @@
  263. do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  264. {
  265. do {
  266. - if (likely(thread_flags & _TIF_NEED_RESCHED)) {
  267. + if (likely(thread_flags & (_TIF_NEED_RESCHED |
  268. + _TIF_NEED_RESCHED_LAZY))) {
  269. schedule();
  270. } else {
  271. if (unlikely(!user_mode(regs)))
  272. diff -Nur linux-4.1.26.orig/arch/arm/kernel/smp.c linux-4.1.26/arch/arm/kernel/smp.c
  273. --- linux-4.1.26.orig/arch/arm/kernel/smp.c 2016-06-07 01:13:11.000000000 +0200
  274. +++ linux-4.1.26/arch/arm/kernel/smp.c 2016-06-19 15:30:54.919152041 +0200
  275. @@ -213,8 +213,6 @@
  276. flush_cache_louis();
  277. local_flush_tlb_all();
  278. - clear_tasks_mm_cpumask(cpu);
  279. -
  280. return 0;
  281. }
  282. @@ -230,6 +228,9 @@
  283. pr_err("CPU%u: cpu didn't die\n", cpu);
  284. return;
  285. }
  286. +
  287. + clear_tasks_mm_cpumask(cpu);
  288. +
  289. pr_notice("CPU%u: shutdown\n", cpu);
  290. /*
  291. diff -Nur linux-4.1.26.orig/arch/arm/kernel/unwind.c linux-4.1.26/arch/arm/kernel/unwind.c
  292. --- linux-4.1.26.orig/arch/arm/kernel/unwind.c 2016-06-07 01:13:11.000000000 +0200
  293. +++ linux-4.1.26/arch/arm/kernel/unwind.c 2016-06-19 15:30:54.919152041 +0200
  294. @@ -93,7 +93,7 @@
  295. static const struct unwind_idx *__origin_unwind_idx;
  296. extern const struct unwind_idx __stop_unwind_idx[];
  297. -static DEFINE_SPINLOCK(unwind_lock);
  298. +static DEFINE_RAW_SPINLOCK(unwind_lock);
  299. static LIST_HEAD(unwind_tables);
  300. /* Convert a prel31 symbol to an absolute address */
  301. @@ -201,7 +201,7 @@
  302. /* module unwind tables */
  303. struct unwind_table *table;
  304. - spin_lock_irqsave(&unwind_lock, flags);
  305. + raw_spin_lock_irqsave(&unwind_lock, flags);
  306. list_for_each_entry(table, &unwind_tables, list) {
  307. if (addr >= table->begin_addr &&
  308. addr < table->end_addr) {
  309. @@ -213,7 +213,7 @@
  310. break;
  311. }
  312. }
  313. - spin_unlock_irqrestore(&unwind_lock, flags);
  314. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  315. }
  316. pr_debug("%s: idx = %p\n", __func__, idx);
  317. @@ -529,9 +529,9 @@
  318. tab->begin_addr = text_addr;
  319. tab->end_addr = text_addr + text_size;
  320. - spin_lock_irqsave(&unwind_lock, flags);
  321. + raw_spin_lock_irqsave(&unwind_lock, flags);
  322. list_add_tail(&tab->list, &unwind_tables);
  323. - spin_unlock_irqrestore(&unwind_lock, flags);
  324. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  325. return tab;
  326. }
  327. @@ -543,9 +543,9 @@
  328. if (!tab)
  329. return;
  330. - spin_lock_irqsave(&unwind_lock, flags);
  331. + raw_spin_lock_irqsave(&unwind_lock, flags);
  332. list_del(&tab->list);
  333. - spin_unlock_irqrestore(&unwind_lock, flags);
  334. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  335. kfree(tab);
  336. }
  337. diff -Nur linux-4.1.26.orig/arch/arm/kvm/arm.c linux-4.1.26/arch/arm/kvm/arm.c
  338. --- linux-4.1.26.orig/arch/arm/kvm/arm.c 2016-06-07 01:13:11.000000000 +0200
  339. +++ linux-4.1.26/arch/arm/kvm/arm.c 2016-06-19 15:30:54.919152041 +0200
  340. @@ -474,9 +474,9 @@
  341. static void vcpu_pause(struct kvm_vcpu *vcpu)
  342. {
  343. - wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
  344. + struct swait_head *wq = kvm_arch_vcpu_wq(vcpu);
  345. - wait_event_interruptible(*wq, !vcpu->arch.pause);
  346. + swait_event_interruptible(*wq, !vcpu->arch.pause);
  347. }
  348. static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
  349. diff -Nur linux-4.1.26.orig/arch/arm/kvm/psci.c linux-4.1.26/arch/arm/kvm/psci.c
  350. --- linux-4.1.26.orig/arch/arm/kvm/psci.c 2016-06-07 01:13:11.000000000 +0200
  351. +++ linux-4.1.26/arch/arm/kvm/psci.c 2016-06-19 15:30:54.919152041 +0200
  352. @@ -68,7 +68,7 @@
  353. {
  354. struct kvm *kvm = source_vcpu->kvm;
  355. struct kvm_vcpu *vcpu = NULL;
  356. - wait_queue_head_t *wq;
  357. + struct swait_head *wq;
  358. unsigned long cpu_id;
  359. unsigned long context_id;
  360. phys_addr_t target_pc;
  361. @@ -117,7 +117,7 @@
  362. smp_mb(); /* Make sure the above is visible */
  363. wq = kvm_arch_vcpu_wq(vcpu);
  364. - wake_up_interruptible(wq);
  365. + swait_wake_interruptible(wq);
  366. return PSCI_RET_SUCCESS;
  367. }
  368. diff -Nur linux-4.1.26.orig/arch/arm/mach-exynos/platsmp.c linux-4.1.26/arch/arm/mach-exynos/platsmp.c
  369. --- linux-4.1.26.orig/arch/arm/mach-exynos/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  370. +++ linux-4.1.26/arch/arm/mach-exynos/platsmp.c 2016-06-19 15:30:54.919152041 +0200
  371. @@ -231,7 +231,7 @@
  372. return (void __iomem *)(S5P_VA_SCU);
  373. }
  374. -static DEFINE_SPINLOCK(boot_lock);
  375. +static DEFINE_RAW_SPINLOCK(boot_lock);
  376. static void exynos_secondary_init(unsigned int cpu)
  377. {
  378. @@ -244,8 +244,8 @@
  379. /*
  380. * Synchronise with the boot thread.
  381. */
  382. - spin_lock(&boot_lock);
  383. - spin_unlock(&boot_lock);
  384. + raw_spin_lock(&boot_lock);
  385. + raw_spin_unlock(&boot_lock);
  386. }
  387. static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
  388. @@ -259,7 +259,7 @@
  389. * Set synchronisation state between this boot processor
  390. * and the secondary one
  391. */
  392. - spin_lock(&boot_lock);
  393. + raw_spin_lock(&boot_lock);
  394. /*
  395. * The secondary processor is waiting to be released from
  396. @@ -286,7 +286,7 @@
  397. if (timeout == 0) {
  398. printk(KERN_ERR "cpu1 power enable failed");
  399. - spin_unlock(&boot_lock);
  400. + raw_spin_unlock(&boot_lock);
  401. return -ETIMEDOUT;
  402. }
  403. }
  404. @@ -342,7 +342,7 @@
  405. * calibrations, then wait for it to finish
  406. */
  407. fail:
  408. - spin_unlock(&boot_lock);
  409. + raw_spin_unlock(&boot_lock);
  410. return pen_release != -1 ? ret : 0;
  411. }
  412. diff -Nur linux-4.1.26.orig/arch/arm/mach-hisi/platmcpm.c linux-4.1.26/arch/arm/mach-hisi/platmcpm.c
  413. --- linux-4.1.26.orig/arch/arm/mach-hisi/platmcpm.c 2016-06-07 01:13:11.000000000 +0200
  414. +++ linux-4.1.26/arch/arm/mach-hisi/platmcpm.c 2016-06-19 15:30:54.923152195 +0200
  415. @@ -57,7 +57,7 @@
  416. static void __iomem *sysctrl, *fabric;
  417. static int hip04_cpu_table[HIP04_MAX_CLUSTERS][HIP04_MAX_CPUS_PER_CLUSTER];
  418. -static DEFINE_SPINLOCK(boot_lock);
  419. +static DEFINE_RAW_SPINLOCK(boot_lock);
  420. static u32 fabric_phys_addr;
  421. /*
  422. * [0]: bootwrapper physical address
  423. @@ -104,7 +104,7 @@
  424. if (cluster >= HIP04_MAX_CLUSTERS || cpu >= HIP04_MAX_CPUS_PER_CLUSTER)
  425. return -EINVAL;
  426. - spin_lock_irq(&boot_lock);
  427. + raw_spin_lock_irq(&boot_lock);
  428. if (hip04_cpu_table[cluster][cpu])
  429. goto out;
  430. @@ -133,7 +133,7 @@
  431. udelay(20);
  432. out:
  433. hip04_cpu_table[cluster][cpu]++;
  434. - spin_unlock_irq(&boot_lock);
  435. + raw_spin_unlock_irq(&boot_lock);
  436. return 0;
  437. }
  438. @@ -149,7 +149,7 @@
  439. __mcpm_cpu_going_down(cpu, cluster);
  440. - spin_lock(&boot_lock);
  441. + raw_spin_lock(&boot_lock);
  442. BUG_ON(__mcpm_cluster_state(cluster) != CLUSTER_UP);
  443. hip04_cpu_table[cluster][cpu]--;
  444. if (hip04_cpu_table[cluster][cpu] == 1) {
  445. @@ -162,7 +162,7 @@
  446. last_man = hip04_cluster_is_down(cluster);
  447. if (last_man && __mcpm_outbound_enter_critical(cpu, cluster)) {
  448. - spin_unlock(&boot_lock);
  449. + raw_spin_unlock(&boot_lock);
  450. /* Since it's Cortex A15, disable L2 prefetching. */
  451. asm volatile(
  452. "mcr p15, 1, %0, c15, c0, 3 \n\t"
  453. @@ -173,7 +173,7 @@
  454. hip04_set_snoop_filter(cluster, 0);
  455. __mcpm_outbound_leave_critical(cluster, CLUSTER_DOWN);
  456. } else {
  457. - spin_unlock(&boot_lock);
  458. + raw_spin_unlock(&boot_lock);
  459. v7_exit_coherency_flush(louis);
  460. }
  461. @@ -192,7 +192,7 @@
  462. cpu >= HIP04_MAX_CPUS_PER_CLUSTER);
  463. count = TIMEOUT_MSEC / POLL_MSEC;
  464. - spin_lock_irq(&boot_lock);
  465. + raw_spin_lock_irq(&boot_lock);
  466. for (tries = 0; tries < count; tries++) {
  467. if (hip04_cpu_table[cluster][cpu]) {
  468. ret = -EBUSY;
  469. @@ -202,10 +202,10 @@
  470. data = readl_relaxed(sysctrl + SC_CPU_RESET_STATUS(cluster));
  471. if (data & CORE_WFI_STATUS(cpu))
  472. break;
  473. - spin_unlock_irq(&boot_lock);
  474. + raw_spin_unlock_irq(&boot_lock);
  475. /* Wait for clean L2 when the whole cluster is down. */
  476. msleep(POLL_MSEC);
  477. - spin_lock_irq(&boot_lock);
  478. + raw_spin_lock_irq(&boot_lock);
  479. }
  480. if (tries >= count)
  481. goto err;
  482. @@ -220,10 +220,10 @@
  483. }
  484. if (tries >= count)
  485. goto err;
  486. - spin_unlock_irq(&boot_lock);
  487. + raw_spin_unlock_irq(&boot_lock);
  488. return 0;
  489. err:
  490. - spin_unlock_irq(&boot_lock);
  491. + raw_spin_unlock_irq(&boot_lock);
  492. return ret;
  493. }
  494. @@ -235,10 +235,10 @@
  495. cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  496. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  497. - spin_lock(&boot_lock);
  498. + raw_spin_lock(&boot_lock);
  499. if (!hip04_cpu_table[cluster][cpu])
  500. hip04_cpu_table[cluster][cpu] = 1;
  501. - spin_unlock(&boot_lock);
  502. + raw_spin_unlock(&boot_lock);
  503. }
  504. static void __naked hip04_mcpm_power_up_setup(unsigned int affinity_level)
  505. diff -Nur linux-4.1.26.orig/arch/arm/mach-omap2/gpio.c linux-4.1.26/arch/arm/mach-omap2/gpio.c
  506. --- linux-4.1.26.orig/arch/arm/mach-omap2/gpio.c 2016-06-07 01:13:11.000000000 +0200
  507. +++ linux-4.1.26/arch/arm/mach-omap2/gpio.c 2016-06-19 15:30:54.923152195 +0200
  508. @@ -130,7 +130,6 @@
  509. }
  510. pwrdm = omap_hwmod_get_pwrdm(oh);
  511. - pdata->loses_context = pwrdm_can_ever_lose_context(pwrdm);
  512. pdev = omap_device_build(name, id - 1, oh, pdata, sizeof(*pdata));
  513. kfree(pdata);
  514. diff -Nur linux-4.1.26.orig/arch/arm/mach-omap2/omap-smp.c linux-4.1.26/arch/arm/mach-omap2/omap-smp.c
  515. --- linux-4.1.26.orig/arch/arm/mach-omap2/omap-smp.c 2016-06-07 01:13:11.000000000 +0200
  516. +++ linux-4.1.26/arch/arm/mach-omap2/omap-smp.c 2016-06-19 15:30:54.923152195 +0200
  517. @@ -43,7 +43,7 @@
  518. /* SCU base address */
  519. static void __iomem *scu_base;
  520. -static DEFINE_SPINLOCK(boot_lock);
  521. +static DEFINE_RAW_SPINLOCK(boot_lock);
  522. void __iomem *omap4_get_scu_base(void)
  523. {
  524. @@ -74,8 +74,8 @@
  525. /*
  526. * Synchronise with the boot thread.
  527. */
  528. - spin_lock(&boot_lock);
  529. - spin_unlock(&boot_lock);
  530. + raw_spin_lock(&boot_lock);
  531. + raw_spin_unlock(&boot_lock);
  532. }
  533. static int omap4_boot_secondary(unsigned int cpu, struct task_struct *idle)
  534. @@ -89,7 +89,7 @@
  535. * Set synchronisation state between this boot processor
  536. * and the secondary one
  537. */
  538. - spin_lock(&boot_lock);
  539. + raw_spin_lock(&boot_lock);
  540. /*
  541. * Update the AuxCoreBoot0 with boot state for secondary core.
  542. @@ -166,7 +166,7 @@
  543. * Now the secondary core is starting up let it run its
  544. * calibrations, then wait for it to finish
  545. */
  546. - spin_unlock(&boot_lock);
  547. + raw_spin_unlock(&boot_lock);
  548. return 0;
  549. }
  550. diff -Nur linux-4.1.26.orig/arch/arm/mach-omap2/powerdomain.c linux-4.1.26/arch/arm/mach-omap2/powerdomain.c
  551. --- linux-4.1.26.orig/arch/arm/mach-omap2/powerdomain.c 2016-06-07 01:13:11.000000000 +0200
  552. +++ linux-4.1.26/arch/arm/mach-omap2/powerdomain.c 2016-06-19 15:30:54.923152195 +0200
  553. @@ -1166,43 +1166,3 @@
  554. return count;
  555. }
  556. -/**
  557. - * pwrdm_can_ever_lose_context - can this powerdomain ever lose context?
  558. - * @pwrdm: struct powerdomain *
  559. - *
  560. - * Given a struct powerdomain * @pwrdm, returns 1 if the powerdomain
  561. - * can lose either memory or logic context or if @pwrdm is invalid, or
  562. - * returns 0 otherwise. This function is not concerned with how the
  563. - * powerdomain registers are programmed (i.e., to go off or not); it's
  564. - * concerned with whether it's ever possible for this powerdomain to
  565. - * go off while some other part of the chip is active. This function
  566. - * assumes that every powerdomain can go to either ON or INACTIVE.
  567. - */
  568. -bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm)
  569. -{
  570. - int i;
  571. -
  572. - if (!pwrdm) {
  573. - pr_debug("powerdomain: %s: invalid powerdomain pointer\n",
  574. - __func__);
  575. - return 1;
  576. - }
  577. -
  578. - if (pwrdm->pwrsts & PWRSTS_OFF)
  579. - return 1;
  580. -
  581. - if (pwrdm->pwrsts & PWRSTS_RET) {
  582. - if (pwrdm->pwrsts_logic_ret & PWRSTS_OFF)
  583. - return 1;
  584. -
  585. - for (i = 0; i < pwrdm->banks; i++)
  586. - if (pwrdm->pwrsts_mem_ret[i] & PWRSTS_OFF)
  587. - return 1;
  588. - }
  589. -
  590. - for (i = 0; i < pwrdm->banks; i++)
  591. - if (pwrdm->pwrsts_mem_on[i] & PWRSTS_OFF)
  592. - return 1;
  593. -
  594. - return 0;
  595. -}
  596. diff -Nur linux-4.1.26.orig/arch/arm/mach-omap2/powerdomain.h linux-4.1.26/arch/arm/mach-omap2/powerdomain.h
  597. --- linux-4.1.26.orig/arch/arm/mach-omap2/powerdomain.h 2016-06-07 01:13:11.000000000 +0200
  598. +++ linux-4.1.26/arch/arm/mach-omap2/powerdomain.h 2016-06-19 15:30:54.923152195 +0200
  599. @@ -244,7 +244,6 @@
  600. int pwrdm_pre_transition(struct powerdomain *pwrdm);
  601. int pwrdm_post_transition(struct powerdomain *pwrdm);
  602. int pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
  603. -bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
  604. extern int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 state);
  605. diff -Nur linux-4.1.26.orig/arch/arm/mach-prima2/platsmp.c linux-4.1.26/arch/arm/mach-prima2/platsmp.c
  606. --- linux-4.1.26.orig/arch/arm/mach-prima2/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  607. +++ linux-4.1.26/arch/arm/mach-prima2/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  608. @@ -22,7 +22,7 @@
  609. static void __iomem *clk_base;
  610. -static DEFINE_SPINLOCK(boot_lock);
  611. +static DEFINE_RAW_SPINLOCK(boot_lock);
  612. static void sirfsoc_secondary_init(unsigned int cpu)
  613. {
  614. @@ -36,8 +36,8 @@
  615. /*
  616. * Synchronise with the boot thread.
  617. */
  618. - spin_lock(&boot_lock);
  619. - spin_unlock(&boot_lock);
  620. + raw_spin_lock(&boot_lock);
  621. + raw_spin_unlock(&boot_lock);
  622. }
  623. static const struct of_device_id clk_ids[] = {
  624. @@ -75,7 +75,7 @@
  625. /* make sure write buffer is drained */
  626. mb();
  627. - spin_lock(&boot_lock);
  628. + raw_spin_lock(&boot_lock);
  629. /*
  630. * The secondary processor is waiting to be released from
  631. @@ -107,7 +107,7 @@
  632. * now the secondary core is starting up let it run its
  633. * calibrations, then wait for it to finish
  634. */
  635. - spin_unlock(&boot_lock);
  636. + raw_spin_unlock(&boot_lock);
  637. return pen_release != -1 ? -ENOSYS : 0;
  638. }
  639. diff -Nur linux-4.1.26.orig/arch/arm/mach-qcom/platsmp.c linux-4.1.26/arch/arm/mach-qcom/platsmp.c
  640. --- linux-4.1.26.orig/arch/arm/mach-qcom/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  641. +++ linux-4.1.26/arch/arm/mach-qcom/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  642. @@ -46,7 +46,7 @@
  643. extern void secondary_startup_arm(void);
  644. -static DEFINE_SPINLOCK(boot_lock);
  645. +static DEFINE_RAW_SPINLOCK(boot_lock);
  646. #ifdef CONFIG_HOTPLUG_CPU
  647. static void __ref qcom_cpu_die(unsigned int cpu)
  648. @@ -60,8 +60,8 @@
  649. /*
  650. * Synchronise with the boot thread.
  651. */
  652. - spin_lock(&boot_lock);
  653. - spin_unlock(&boot_lock);
  654. + raw_spin_lock(&boot_lock);
  655. + raw_spin_unlock(&boot_lock);
  656. }
  657. static int scss_release_secondary(unsigned int cpu)
  658. @@ -284,7 +284,7 @@
  659. * set synchronisation state between this boot processor
  660. * and the secondary one
  661. */
  662. - spin_lock(&boot_lock);
  663. + raw_spin_lock(&boot_lock);
  664. /*
  665. * Send the secondary CPU a soft interrupt, thereby causing
  666. @@ -297,7 +297,7 @@
  667. * now the secondary core is starting up let it run its
  668. * calibrations, then wait for it to finish
  669. */
  670. - spin_unlock(&boot_lock);
  671. + raw_spin_unlock(&boot_lock);
  672. return ret;
  673. }
  674. diff -Nur linux-4.1.26.orig/arch/arm/mach-spear/platsmp.c linux-4.1.26/arch/arm/mach-spear/platsmp.c
  675. --- linux-4.1.26.orig/arch/arm/mach-spear/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  676. +++ linux-4.1.26/arch/arm/mach-spear/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  677. @@ -32,7 +32,7 @@
  678. sync_cache_w(&pen_release);
  679. }
  680. -static DEFINE_SPINLOCK(boot_lock);
  681. +static DEFINE_RAW_SPINLOCK(boot_lock);
  682. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  683. @@ -47,8 +47,8 @@
  684. /*
  685. * Synchronise with the boot thread.
  686. */
  687. - spin_lock(&boot_lock);
  688. - spin_unlock(&boot_lock);
  689. + raw_spin_lock(&boot_lock);
  690. + raw_spin_unlock(&boot_lock);
  691. }
  692. static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  693. @@ -59,7 +59,7 @@
  694. * set synchronisation state between this boot processor
  695. * and the secondary one
  696. */
  697. - spin_lock(&boot_lock);
  698. + raw_spin_lock(&boot_lock);
  699. /*
  700. * The secondary processor is waiting to be released from
  701. @@ -84,7 +84,7 @@
  702. * now the secondary core is starting up let it run its
  703. * calibrations, then wait for it to finish
  704. */
  705. - spin_unlock(&boot_lock);
  706. + raw_spin_unlock(&boot_lock);
  707. return pen_release != -1 ? -ENOSYS : 0;
  708. }
  709. diff -Nur linux-4.1.26.orig/arch/arm/mach-sti/platsmp.c linux-4.1.26/arch/arm/mach-sti/platsmp.c
  710. --- linux-4.1.26.orig/arch/arm/mach-sti/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  711. +++ linux-4.1.26/arch/arm/mach-sti/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  712. @@ -34,7 +34,7 @@
  713. sync_cache_w(&pen_release);
  714. }
  715. -static DEFINE_SPINLOCK(boot_lock);
  716. +static DEFINE_RAW_SPINLOCK(boot_lock);
  717. static void sti_secondary_init(unsigned int cpu)
  718. {
  719. @@ -49,8 +49,8 @@
  720. /*
  721. * Synchronise with the boot thread.
  722. */
  723. - spin_lock(&boot_lock);
  724. - spin_unlock(&boot_lock);
  725. + raw_spin_lock(&boot_lock);
  726. + raw_spin_unlock(&boot_lock);
  727. }
  728. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  729. @@ -61,7 +61,7 @@
  730. * set synchronisation state between this boot processor
  731. * and the secondary one
  732. */
  733. - spin_lock(&boot_lock);
  734. + raw_spin_lock(&boot_lock);
  735. /*
  736. * The secondary processor is waiting to be released from
  737. @@ -92,7 +92,7 @@
  738. * now the secondary core is starting up let it run its
  739. * calibrations, then wait for it to finish
  740. */
  741. - spin_unlock(&boot_lock);
  742. + raw_spin_unlock(&boot_lock);
  743. return pen_release != -1 ? -ENOSYS : 0;
  744. }
  745. diff -Nur linux-4.1.26.orig/arch/arm/mach-ux500/platsmp.c linux-4.1.26/arch/arm/mach-ux500/platsmp.c
  746. --- linux-4.1.26.orig/arch/arm/mach-ux500/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  747. +++ linux-4.1.26/arch/arm/mach-ux500/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  748. @@ -51,7 +51,7 @@
  749. return NULL;
  750. }
  751. -static DEFINE_SPINLOCK(boot_lock);
  752. +static DEFINE_RAW_SPINLOCK(boot_lock);
  753. static void ux500_secondary_init(unsigned int cpu)
  754. {
  755. @@ -64,8 +64,8 @@
  756. /*
  757. * Synchronise with the boot thread.
  758. */
  759. - spin_lock(&boot_lock);
  760. - spin_unlock(&boot_lock);
  761. + raw_spin_lock(&boot_lock);
  762. + raw_spin_unlock(&boot_lock);
  763. }
  764. static int ux500_boot_secondary(unsigned int cpu, struct task_struct *idle)
  765. @@ -76,7 +76,7 @@
  766. * set synchronisation state between this boot processor
  767. * and the secondary one
  768. */
  769. - spin_lock(&boot_lock);
  770. + raw_spin_lock(&boot_lock);
  771. /*
  772. * The secondary processor is waiting to be released from
  773. @@ -97,7 +97,7 @@
  774. * now the secondary core is starting up let it run its
  775. * calibrations, then wait for it to finish
  776. */
  777. - spin_unlock(&boot_lock);
  778. + raw_spin_unlock(&boot_lock);
  779. return pen_release != -1 ? -ENOSYS : 0;
  780. }
  781. diff -Nur linux-4.1.26.orig/arch/arm/mm/fault.c linux-4.1.26/arch/arm/mm/fault.c
  782. --- linux-4.1.26.orig/arch/arm/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  783. +++ linux-4.1.26/arch/arm/mm/fault.c 2016-06-19 15:30:54.923152195 +0200
  784. @@ -276,7 +276,7 @@
  785. * If we're in an interrupt or have no user
  786. * context, we must not take the fault..
  787. */
  788. - if (in_atomic() || !mm)
  789. + if (faulthandler_disabled() || !mm)
  790. goto no_context;
  791. if (user_mode(regs))
  792. @@ -430,6 +430,9 @@
  793. if (addr < TASK_SIZE)
  794. return do_page_fault(addr, fsr, regs);
  795. + if (interrupts_enabled(regs))
  796. + local_irq_enable();
  797. +
  798. if (user_mode(regs))
  799. goto bad_area;
  800. @@ -497,6 +500,9 @@
  801. static int
  802. do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  803. {
  804. + if (interrupts_enabled(regs))
  805. + local_irq_enable();
  806. +
  807. do_bad_area(addr, fsr, regs);
  808. return 0;
  809. }
  810. diff -Nur linux-4.1.26.orig/arch/arm/mm/highmem.c linux-4.1.26/arch/arm/mm/highmem.c
  811. --- linux-4.1.26.orig/arch/arm/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  812. +++ linux-4.1.26/arch/arm/mm/highmem.c 2016-06-19 15:30:54.923152195 +0200
  813. @@ -54,11 +54,13 @@
  814. void *kmap_atomic(struct page *page)
  815. {
  816. + pte_t pte = mk_pte(page, kmap_prot);
  817. unsigned int idx;
  818. unsigned long vaddr;
  819. void *kmap;
  820. int type;
  821. + preempt_disable_nort();
  822. pagefault_disable();
  823. if (!PageHighMem(page))
  824. return page_address(page);
  825. @@ -92,7 +94,10 @@
  826. * in place, so the contained TLB flush ensures the TLB is updated
  827. * with the new mapping.
  828. */
  829. - set_fixmap_pte(idx, mk_pte(page, kmap_prot));
  830. +#ifdef CONFIG_PREEMPT_RT_FULL
  831. + current->kmap_pte[type] = pte;
  832. +#endif
  833. + set_fixmap_pte(idx, pte);
  834. return (void *)vaddr;
  835. }
  836. @@ -109,27 +114,33 @@
  837. if (cache_is_vivt())
  838. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
  839. +#ifdef CONFIG_PREEMPT_RT_FULL
  840. + current->kmap_pte[type] = __pte(0);
  841. +#endif
  842. #ifdef CONFIG_DEBUG_HIGHMEM
  843. BUG_ON(vaddr != __fix_to_virt(idx));
  844. - set_fixmap_pte(idx, __pte(0));
  845. #else
  846. (void) idx; /* to kill a warning */
  847. #endif
  848. + set_fixmap_pte(idx, __pte(0));
  849. kmap_atomic_idx_pop();
  850. } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
  851. /* this address was obtained through kmap_high_get() */
  852. kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
  853. }
  854. pagefault_enable();
  855. + preempt_enable_nort();
  856. }
  857. EXPORT_SYMBOL(__kunmap_atomic);
  858. void *kmap_atomic_pfn(unsigned long pfn)
  859. {
  860. + pte_t pte = pfn_pte(pfn, kmap_prot);
  861. unsigned long vaddr;
  862. int idx, type;
  863. struct page *page = pfn_to_page(pfn);
  864. + preempt_disable_nort();
  865. pagefault_disable();
  866. if (!PageHighMem(page))
  867. return page_address(page);
  868. @@ -140,7 +151,10 @@
  869. #ifdef CONFIG_DEBUG_HIGHMEM
  870. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  871. #endif
  872. - set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
  873. +#ifdef CONFIG_PREEMPT_RT_FULL
  874. + current->kmap_pte[type] = pte;
  875. +#endif
  876. + set_fixmap_pte(idx, pte);
  877. return (void *)vaddr;
  878. }
  879. @@ -154,3 +168,28 @@
  880. return pte_page(get_fixmap_pte(vaddr));
  881. }
  882. +
  883. +#if defined CONFIG_PREEMPT_RT_FULL
  884. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  885. +{
  886. + int i;
  887. +
  888. + /*
  889. + * Clear @prev's kmap_atomic mappings
  890. + */
  891. + for (i = 0; i < prev_p->kmap_idx; i++) {
  892. + int idx = i + KM_TYPE_NR * smp_processor_id();
  893. +
  894. + set_fixmap_pte(idx, __pte(0));
  895. + }
  896. + /*
  897. + * Restore @next_p's kmap_atomic mappings
  898. + */
  899. + for (i = 0; i < next_p->kmap_idx; i++) {
  900. + int idx = i + KM_TYPE_NR * smp_processor_id();
  901. +
  902. + if (!pte_none(next_p->kmap_pte[i]))
  903. + set_fixmap_pte(idx, next_p->kmap_pte[i]);
  904. + }
  905. +}
  906. +#endif
  907. diff -Nur linux-4.1.26.orig/arch/arm/plat-versatile/platsmp.c linux-4.1.26/arch/arm/plat-versatile/platsmp.c
  908. --- linux-4.1.26.orig/arch/arm/plat-versatile/platsmp.c 2016-06-07 01:13:11.000000000 +0200
  909. +++ linux-4.1.26/arch/arm/plat-versatile/platsmp.c 2016-06-19 15:30:54.923152195 +0200
  910. @@ -30,7 +30,7 @@
  911. sync_cache_w(&pen_release);
  912. }
  913. -static DEFINE_SPINLOCK(boot_lock);
  914. +static DEFINE_RAW_SPINLOCK(boot_lock);
  915. void versatile_secondary_init(unsigned int cpu)
  916. {
  917. @@ -43,8 +43,8 @@
  918. /*
  919. * Synchronise with the boot thread.
  920. */
  921. - spin_lock(&boot_lock);
  922. - spin_unlock(&boot_lock);
  923. + raw_spin_lock(&boot_lock);
  924. + raw_spin_unlock(&boot_lock);
  925. }
  926. int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
  927. @@ -55,7 +55,7 @@
  928. * Set synchronisation state between this boot processor
  929. * and the secondary one
  930. */
  931. - spin_lock(&boot_lock);
  932. + raw_spin_lock(&boot_lock);
  933. /*
  934. * This is really belt and braces; we hold unintended secondary
  935. @@ -85,7 +85,7 @@
  936. * now the secondary core is starting up let it run its
  937. * calibrations, then wait for it to finish
  938. */
  939. - spin_unlock(&boot_lock);
  940. + raw_spin_unlock(&boot_lock);
  941. return pen_release != -1 ? -ENOSYS : 0;
  942. }
  943. diff -Nur linux-4.1.26.orig/arch/arm64/include/asm/futex.h linux-4.1.26/arch/arm64/include/asm/futex.h
  944. --- linux-4.1.26.orig/arch/arm64/include/asm/futex.h 2016-06-07 01:13:11.000000000 +0200
  945. +++ linux-4.1.26/arch/arm64/include/asm/futex.h 2016-06-19 15:30:54.923152195 +0200
  946. @@ -58,7 +58,7 @@
  947. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  948. return -EFAULT;
  949. - pagefault_disable(); /* implies preempt_disable() */
  950. + pagefault_disable();
  951. switch (op) {
  952. case FUTEX_OP_SET:
  953. @@ -85,7 +85,7 @@
  954. ret = -ENOSYS;
  955. }
  956. - pagefault_enable(); /* subsumes preempt_enable() */
  957. + pagefault_enable();
  958. if (!ret) {
  959. switch (cmp) {
  960. diff -Nur linux-4.1.26.orig/arch/arm64/include/asm/thread_info.h linux-4.1.26/arch/arm64/include/asm/thread_info.h
  961. --- linux-4.1.26.orig/arch/arm64/include/asm/thread_info.h 2016-06-07 01:13:11.000000000 +0200
  962. +++ linux-4.1.26/arch/arm64/include/asm/thread_info.h 2016-06-19 15:30:54.923152195 +0200
  963. @@ -47,6 +47,7 @@
  964. mm_segment_t addr_limit; /* address limit */
  965. struct task_struct *task; /* main task structure */
  966. int preempt_count; /* 0 => preemptable, <0 => bug */
  967. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  968. int cpu; /* cpu */
  969. };
  970. @@ -101,6 +102,7 @@
  971. #define TIF_NEED_RESCHED 1
  972. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  973. #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */
  974. +#define TIF_NEED_RESCHED_LAZY 4
  975. #define TIF_NOHZ 7
  976. #define TIF_SYSCALL_TRACE 8
  977. #define TIF_SYSCALL_AUDIT 9
  978. @@ -117,6 +119,7 @@
  979. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  980. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  981. #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE)
  982. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  983. #define _TIF_NOHZ (1 << TIF_NOHZ)
  984. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  985. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  986. diff -Nur linux-4.1.26.orig/arch/arm64/Kconfig linux-4.1.26/arch/arm64/Kconfig
  987. --- linux-4.1.26.orig/arch/arm64/Kconfig 2016-06-07 01:13:11.000000000 +0200
  988. +++ linux-4.1.26/arch/arm64/Kconfig 2016-06-19 15:30:54.923152195 +0200
  989. @@ -69,8 +69,10 @@
  990. select HAVE_PERF_REGS
  991. select HAVE_PERF_USER_STACK_DUMP
  992. select HAVE_RCU_TABLE_FREE
  993. + select HAVE_PREEMPT_LAZY
  994. select HAVE_SYSCALL_TRACEPOINTS
  995. select IRQ_DOMAIN
  996. + select IRQ_FORCED_THREADING
  997. select MODULES_USE_ELF_RELA
  998. select NO_BOOTMEM
  999. select OF
  1000. @@ -599,7 +601,7 @@
  1001. config XEN
  1002. bool "Xen guest support on ARM64"
  1003. - depends on ARM64 && OF
  1004. + depends on ARM64 && OF && !PREEMPT_RT_FULL
  1005. select SWIOTLB_XEN
  1006. help
  1007. Say Y if you want to run Linux in a Virtual Machine on Xen on ARM64.
  1008. diff -Nur linux-4.1.26.orig/arch/arm64/kernel/asm-offsets.c linux-4.1.26/arch/arm64/kernel/asm-offsets.c
  1009. --- linux-4.1.26.orig/arch/arm64/kernel/asm-offsets.c 2016-06-07 01:13:11.000000000 +0200
  1010. +++ linux-4.1.26/arch/arm64/kernel/asm-offsets.c 2016-06-19 15:30:54.923152195 +0200
  1011. @@ -35,6 +35,7 @@
  1012. BLANK();
  1013. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1014. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1015. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1016. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  1017. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1018. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1019. diff -Nur linux-4.1.26.orig/arch/arm64/kernel/entry.S linux-4.1.26/arch/arm64/kernel/entry.S
  1020. --- linux-4.1.26.orig/arch/arm64/kernel/entry.S 2016-06-07 01:13:11.000000000 +0200
  1021. +++ linux-4.1.26/arch/arm64/kernel/entry.S 2016-06-19 15:30:58.591293647 +0200
  1022. @@ -367,11 +367,16 @@
  1023. #ifdef CONFIG_PREEMPT
  1024. get_thread_info tsk
  1025. ldr w24, [tsk, #TI_PREEMPT] // get preempt count
  1026. - cbnz w24, 1f // preempt count != 0
  1027. + cbnz w24, 2f // preempt count != 0
  1028. ldr x0, [tsk, #TI_FLAGS] // get flags
  1029. - tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  1030. - bl el1_preempt
  1031. + tbnz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  1032. +
  1033. + ldr w24, [tsk, #TI_PREEMPT_LAZY] // get preempt lazy count
  1034. + cbnz w24, 2f // preempt lazy count != 0
  1035. + tbz x0, #TIF_NEED_RESCHED_LAZY, 2f // needs rescheduling?
  1036. 1:
  1037. + bl el1_preempt
  1038. +2:
  1039. #endif
  1040. #ifdef CONFIG_TRACE_IRQFLAGS
  1041. bl trace_hardirqs_on
  1042. @@ -385,6 +390,7 @@
  1043. 1: bl preempt_schedule_irq // irq en/disable is done inside
  1044. ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
  1045. tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
  1046. + tbnz x0, #TIF_NEED_RESCHED_LAZY, 1b // needs rescheduling?
  1047. ret x24
  1048. #endif
  1049. @@ -622,6 +628,7 @@
  1050. str x0, [sp, #S_X0] // returned x0
  1051. work_pending:
  1052. tbnz x1, #TIF_NEED_RESCHED, work_resched
  1053. + tbnz x1, #TIF_NEED_RESCHED_LAZY, work_resched
  1054. /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */
  1055. ldr x2, [sp, #S_PSTATE]
  1056. mov x0, sp // 'regs'
  1057. diff -Nur linux-4.1.26.orig/arch/arm64/kernel/insn.c linux-4.1.26/arch/arm64/kernel/insn.c
  1058. --- linux-4.1.26.orig/arch/arm64/kernel/insn.c 2016-06-07 01:13:11.000000000 +0200
  1059. +++ linux-4.1.26/arch/arm64/kernel/insn.c 2016-06-19 15:30:58.595293802 +0200
  1060. @@ -77,7 +77,7 @@
  1061. }
  1062. }
  1063. -static DEFINE_SPINLOCK(patch_lock);
  1064. +static DEFINE_RAW_SPINLOCK(patch_lock);
  1065. static void __kprobes *patch_map(void *addr, int fixmap)
  1066. {
  1067. @@ -124,13 +124,13 @@
  1068. unsigned long flags = 0;
  1069. int ret;
  1070. - spin_lock_irqsave(&patch_lock, flags);
  1071. + raw_spin_lock_irqsave(&patch_lock, flags);
  1072. waddr = patch_map(addr, FIX_TEXT_POKE0);
  1073. ret = probe_kernel_write(waddr, &insn, AARCH64_INSN_SIZE);
  1074. patch_unmap(FIX_TEXT_POKE0);
  1075. - spin_unlock_irqrestore(&patch_lock, flags);
  1076. + raw_spin_unlock_irqrestore(&patch_lock, flags);
  1077. return ret;
  1078. }
  1079. diff -Nur linux-4.1.26.orig/arch/arm64/kernel/perf_event.c linux-4.1.26/arch/arm64/kernel/perf_event.c
  1080. --- linux-4.1.26.orig/arch/arm64/kernel/perf_event.c 2016-06-07 01:13:11.000000000 +0200
  1081. +++ linux-4.1.26/arch/arm64/kernel/perf_event.c 2016-06-19 15:30:58.595293802 +0200
  1082. @@ -488,7 +488,7 @@
  1083. }
  1084. err = request_irq(irq, armpmu->handle_irq,
  1085. - IRQF_NOBALANCING,
  1086. + IRQF_NOBALANCING | IRQF_NO_THREAD,
  1087. "arm-pmu", armpmu);
  1088. if (err) {
  1089. pr_err("unable to request IRQ%d for ARM PMU counters\n",
  1090. diff -Nur linux-4.1.26.orig/arch/arm64/mm/fault.c linux-4.1.26/arch/arm64/mm/fault.c
  1091. --- linux-4.1.26.orig/arch/arm64/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1092. +++ linux-4.1.26/arch/arm64/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1093. @@ -211,7 +211,7 @@
  1094. * If we're in an interrupt or have no user context, we must not take
  1095. * the fault.
  1096. */
  1097. - if (in_atomic() || !mm)
  1098. + if (faulthandler_disabled() || !mm)
  1099. goto no_context;
  1100. if (user_mode(regs))
  1101. diff -Nur linux-4.1.26.orig/arch/avr32/include/asm/uaccess.h linux-4.1.26/arch/avr32/include/asm/uaccess.h
  1102. --- linux-4.1.26.orig/arch/avr32/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  1103. +++ linux-4.1.26/arch/avr32/include/asm/uaccess.h 2016-06-19 15:30:58.595293802 +0200
  1104. @@ -97,7 +97,8 @@
  1105. * @x: Value to copy to user space.
  1106. * @ptr: Destination address, in user space.
  1107. *
  1108. - * Context: User context only. This function may sleep.
  1109. + * Context: User context only. This function may sleep if pagefaults are
  1110. + * enabled.
  1111. *
  1112. * This macro copies a single simple value from kernel space to user
  1113. * space. It supports simple types like char and int, but not larger
  1114. @@ -116,7 +117,8 @@
  1115. * @x: Variable to store result.
  1116. * @ptr: Source address, in user space.
  1117. *
  1118. - * Context: User context only. This function may sleep.
  1119. + * Context: User context only. This function may sleep if pagefaults are
  1120. + * enabled.
  1121. *
  1122. * This macro copies a single simple variable from user space to kernel
  1123. * space. It supports simple types like char and int, but not larger
  1124. @@ -136,7 +138,8 @@
  1125. * @x: Value to copy to user space.
  1126. * @ptr: Destination address, in user space.
  1127. *
  1128. - * Context: User context only. This function may sleep.
  1129. + * Context: User context only. This function may sleep if pagefaults are
  1130. + * enabled.
  1131. *
  1132. * This macro copies a single simple value from kernel space to user
  1133. * space. It supports simple types like char and int, but not larger
  1134. @@ -158,7 +161,8 @@
  1135. * @x: Variable to store result.
  1136. * @ptr: Source address, in user space.
  1137. *
  1138. - * Context: User context only. This function may sleep.
  1139. + * Context: User context only. This function may sleep if pagefaults are
  1140. + * enabled.
  1141. *
  1142. * This macro copies a single simple variable from user space to kernel
  1143. * space. It supports simple types like char and int, but not larger
  1144. diff -Nur linux-4.1.26.orig/arch/avr32/mm/fault.c linux-4.1.26/arch/avr32/mm/fault.c
  1145. --- linux-4.1.26.orig/arch/avr32/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1146. +++ linux-4.1.26/arch/avr32/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1147. @@ -14,11 +14,11 @@
  1148. #include <linux/pagemap.h>
  1149. #include <linux/kdebug.h>
  1150. #include <linux/kprobes.h>
  1151. +#include <linux/uaccess.h>
  1152. #include <asm/mmu_context.h>
  1153. #include <asm/sysreg.h>
  1154. #include <asm/tlb.h>
  1155. -#include <asm/uaccess.h>
  1156. #ifdef CONFIG_KPROBES
  1157. static inline int notify_page_fault(struct pt_regs *regs, int trap)
  1158. @@ -81,7 +81,7 @@
  1159. * If we're in an interrupt or have no user context, we must
  1160. * not take the fault...
  1161. */
  1162. - if (in_atomic() || !mm || regs->sr & SYSREG_BIT(GM))
  1163. + if (faulthandler_disabled() || !mm || regs->sr & SYSREG_BIT(GM))
  1164. goto no_context;
  1165. local_irq_enable();
  1166. diff -Nur linux-4.1.26.orig/arch/cris/mm/fault.c linux-4.1.26/arch/cris/mm/fault.c
  1167. --- linux-4.1.26.orig/arch/cris/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1168. +++ linux-4.1.26/arch/cris/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1169. @@ -8,7 +8,7 @@
  1170. #include <linux/interrupt.h>
  1171. #include <linux/module.h>
  1172. #include <linux/wait.h>
  1173. -#include <asm/uaccess.h>
  1174. +#include <linux/uaccess.h>
  1175. #include <arch/system.h>
  1176. extern int find_fixup_code(struct pt_regs *);
  1177. @@ -109,11 +109,11 @@
  1178. info.si_code = SEGV_MAPERR;
  1179. /*
  1180. - * If we're in an interrupt or "atomic" operation or have no
  1181. + * If we're in an interrupt, have pagefaults disabled or have no
  1182. * user context, we must not take the fault.
  1183. */
  1184. - if (in_atomic() || !mm)
  1185. + if (faulthandler_disabled() || !mm)
  1186. goto no_context;
  1187. if (user_mode(regs))
  1188. diff -Nur linux-4.1.26.orig/arch/frv/mm/fault.c linux-4.1.26/arch/frv/mm/fault.c
  1189. --- linux-4.1.26.orig/arch/frv/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1190. +++ linux-4.1.26/arch/frv/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1191. @@ -19,9 +19,9 @@
  1192. #include <linux/kernel.h>
  1193. #include <linux/ptrace.h>
  1194. #include <linux/hardirq.h>
  1195. +#include <linux/uaccess.h>
  1196. #include <asm/pgtable.h>
  1197. -#include <asm/uaccess.h>
  1198. #include <asm/gdb-stub.h>
  1199. /*****************************************************************************/
  1200. @@ -78,7 +78,7 @@
  1201. * If we're in an interrupt or have no user
  1202. * context, we must not take the fault..
  1203. */
  1204. - if (in_atomic() || !mm)
  1205. + if (faulthandler_disabled() || !mm)
  1206. goto no_context;
  1207. if (user_mode(__frame))
  1208. diff -Nur linux-4.1.26.orig/arch/frv/mm/highmem.c linux-4.1.26/arch/frv/mm/highmem.c
  1209. --- linux-4.1.26.orig/arch/frv/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  1210. +++ linux-4.1.26/arch/frv/mm/highmem.c 2016-06-19 15:30:58.595293802 +0200
  1211. @@ -42,6 +42,7 @@
  1212. unsigned long paddr;
  1213. int type;
  1214. + preempt_disable();
  1215. pagefault_disable();
  1216. type = kmap_atomic_idx_push();
  1217. paddr = page_to_phys(page);
  1218. @@ -85,5 +86,6 @@
  1219. }
  1220. kmap_atomic_idx_pop();
  1221. pagefault_enable();
  1222. + preempt_enable();
  1223. }
  1224. EXPORT_SYMBOL(__kunmap_atomic);
  1225. diff -Nur linux-4.1.26.orig/arch/hexagon/include/asm/uaccess.h linux-4.1.26/arch/hexagon/include/asm/uaccess.h
  1226. --- linux-4.1.26.orig/arch/hexagon/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  1227. +++ linux-4.1.26/arch/hexagon/include/asm/uaccess.h 2016-06-19 15:30:58.595293802 +0200
  1228. @@ -36,7 +36,8 @@
  1229. * @addr: User space pointer to start of block to check
  1230. * @size: Size of block to check
  1231. *
  1232. - * Context: User context only. This function may sleep.
  1233. + * Context: User context only. This function may sleep if pagefaults are
  1234. + * enabled.
  1235. *
  1236. * Checks if a pointer to a block of memory in user space is valid.
  1237. *
  1238. diff -Nur linux-4.1.26.orig/arch/ia64/mm/fault.c linux-4.1.26/arch/ia64/mm/fault.c
  1239. --- linux-4.1.26.orig/arch/ia64/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1240. +++ linux-4.1.26/arch/ia64/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1241. @@ -11,10 +11,10 @@
  1242. #include <linux/kprobes.h>
  1243. #include <linux/kdebug.h>
  1244. #include <linux/prefetch.h>
  1245. +#include <linux/uaccess.h>
  1246. #include <asm/pgtable.h>
  1247. #include <asm/processor.h>
  1248. -#include <asm/uaccess.h>
  1249. extern int die(char *, struct pt_regs *, long);
  1250. @@ -96,7 +96,7 @@
  1251. /*
  1252. * If we're in an interrupt or have no user context, we must not take the fault..
  1253. */
  1254. - if (in_atomic() || !mm)
  1255. + if (faulthandler_disabled() || !mm)
  1256. goto no_context;
  1257. #ifdef CONFIG_VIRTUAL_MEM_MAP
  1258. diff -Nur linux-4.1.26.orig/arch/Kconfig linux-4.1.26/arch/Kconfig
  1259. --- linux-4.1.26.orig/arch/Kconfig 2016-06-07 01:13:11.000000000 +0200
  1260. +++ linux-4.1.26/arch/Kconfig 2016-06-19 15:30:54.915151887 +0200
  1261. @@ -6,6 +6,7 @@
  1262. tristate "OProfile system profiling"
  1263. depends on PROFILING
  1264. depends on HAVE_OPROFILE
  1265. + depends on !PREEMPT_RT_FULL
  1266. select RING_BUFFER
  1267. select RING_BUFFER_ALLOW_SWAP
  1268. help
  1269. @@ -49,6 +50,7 @@
  1270. config JUMP_LABEL
  1271. bool "Optimize very unlikely/likely branches"
  1272. depends on HAVE_ARCH_JUMP_LABEL
  1273. + depends on (!INTERRUPT_OFF_HIST && !PREEMPT_OFF_HIST && !WAKEUP_LATENCY_HIST && !MISSED_TIMER_OFFSETS_HIST)
  1274. help
  1275. This option enables a transparent branch optimization that
  1276. makes certain almost-always-true or almost-always-false branch
  1277. diff -Nur linux-4.1.26.orig/arch/m32r/include/asm/uaccess.h linux-4.1.26/arch/m32r/include/asm/uaccess.h
  1278. --- linux-4.1.26.orig/arch/m32r/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  1279. +++ linux-4.1.26/arch/m32r/include/asm/uaccess.h 2016-06-19 15:30:58.595293802 +0200
  1280. @@ -91,7 +91,8 @@
  1281. * @addr: User space pointer to start of block to check
  1282. * @size: Size of block to check
  1283. *
  1284. - * Context: User context only. This function may sleep.
  1285. + * Context: User context only. This function may sleep if pagefaults are
  1286. + * enabled.
  1287. *
  1288. * Checks if a pointer to a block of memory in user space is valid.
  1289. *
  1290. @@ -155,7 +156,8 @@
  1291. * @x: Variable to store result.
  1292. * @ptr: Source address, in user space.
  1293. *
  1294. - * Context: User context only. This function may sleep.
  1295. + * Context: User context only. This function may sleep if pagefaults are
  1296. + * enabled.
  1297. *
  1298. * This macro copies a single simple variable from user space to kernel
  1299. * space. It supports simple types like char and int, but not larger
  1300. @@ -175,7 +177,8 @@
  1301. * @x: Value to copy to user space.
  1302. * @ptr: Destination address, in user space.
  1303. *
  1304. - * Context: User context only. This function may sleep.
  1305. + * Context: User context only. This function may sleep if pagefaults are
  1306. + * enabled.
  1307. *
  1308. * This macro copies a single simple value from kernel space to user
  1309. * space. It supports simple types like char and int, but not larger
  1310. @@ -194,7 +197,8 @@
  1311. * @x: Variable to store result.
  1312. * @ptr: Source address, in user space.
  1313. *
  1314. - * Context: User context only. This function may sleep.
  1315. + * Context: User context only. This function may sleep if pagefaults are
  1316. + * enabled.
  1317. *
  1318. * This macro copies a single simple variable from user space to kernel
  1319. * space. It supports simple types like char and int, but not larger
  1320. @@ -274,7 +278,8 @@
  1321. * @x: Value to copy to user space.
  1322. * @ptr: Destination address, in user space.
  1323. *
  1324. - * Context: User context only. This function may sleep.
  1325. + * Context: User context only. This function may sleep if pagefaults are
  1326. + * enabled.
  1327. *
  1328. * This macro copies a single simple value from kernel space to user
  1329. * space. It supports simple types like char and int, but not larger
  1330. @@ -568,7 +573,8 @@
  1331. * @from: Source address, in kernel space.
  1332. * @n: Number of bytes to copy.
  1333. *
  1334. - * Context: User context only. This function may sleep.
  1335. + * Context: User context only. This function may sleep if pagefaults are
  1336. + * enabled.
  1337. *
  1338. * Copy data from kernel space to user space. Caller must check
  1339. * the specified block with access_ok() before calling this function.
  1340. @@ -588,7 +594,8 @@
  1341. * @from: Source address, in kernel space.
  1342. * @n: Number of bytes to copy.
  1343. *
  1344. - * Context: User context only. This function may sleep.
  1345. + * Context: User context only. This function may sleep if pagefaults are
  1346. + * enabled.
  1347. *
  1348. * Copy data from kernel space to user space.
  1349. *
  1350. @@ -606,7 +613,8 @@
  1351. * @from: Source address, in user space.
  1352. * @n: Number of bytes to copy.
  1353. *
  1354. - * Context: User context only. This function may sleep.
  1355. + * Context: User context only. This function may sleep if pagefaults are
  1356. + * enabled.
  1357. *
  1358. * Copy data from user space to kernel space. Caller must check
  1359. * the specified block with access_ok() before calling this function.
  1360. @@ -626,7 +634,8 @@
  1361. * @from: Source address, in user space.
  1362. * @n: Number of bytes to copy.
  1363. *
  1364. - * Context: User context only. This function may sleep.
  1365. + * Context: User context only. This function may sleep if pagefaults are
  1366. + * enabled.
  1367. *
  1368. * Copy data from user space to kernel space.
  1369. *
  1370. @@ -677,7 +686,8 @@
  1371. * strlen_user: - Get the size of a string in user space.
  1372. * @str: The string to measure.
  1373. *
  1374. - * Context: User context only. This function may sleep.
  1375. + * Context: User context only. This function may sleep if pagefaults are
  1376. + * enabled.
  1377. *
  1378. * Get the size of a NUL-terminated string in user space.
  1379. *
  1380. diff -Nur linux-4.1.26.orig/arch/m32r/mm/fault.c linux-4.1.26/arch/m32r/mm/fault.c
  1381. --- linux-4.1.26.orig/arch/m32r/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1382. +++ linux-4.1.26/arch/m32r/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1383. @@ -24,9 +24,9 @@
  1384. #include <linux/vt_kern.h> /* For unblank_screen() */
  1385. #include <linux/highmem.h>
  1386. #include <linux/module.h>
  1387. +#include <linux/uaccess.h>
  1388. #include <asm/m32r.h>
  1389. -#include <asm/uaccess.h>
  1390. #include <asm/hardirq.h>
  1391. #include <asm/mmu_context.h>
  1392. #include <asm/tlbflush.h>
  1393. @@ -111,10 +111,10 @@
  1394. mm = tsk->mm;
  1395. /*
  1396. - * If we're in an interrupt or have no user context or are running in an
  1397. - * atomic region then we must not take the fault..
  1398. + * If we're in an interrupt or have no user context or have pagefaults
  1399. + * disabled then we must not take the fault.
  1400. */
  1401. - if (in_atomic() || !mm)
  1402. + if (faulthandler_disabled() || !mm)
  1403. goto bad_area_nosemaphore;
  1404. if (error_code & ACE_USERMODE)
  1405. diff -Nur linux-4.1.26.orig/arch/m68k/mm/fault.c linux-4.1.26/arch/m68k/mm/fault.c
  1406. --- linux-4.1.26.orig/arch/m68k/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1407. +++ linux-4.1.26/arch/m68k/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1408. @@ -10,10 +10,10 @@
  1409. #include <linux/ptrace.h>
  1410. #include <linux/interrupt.h>
  1411. #include <linux/module.h>
  1412. +#include <linux/uaccess.h>
  1413. #include <asm/setup.h>
  1414. #include <asm/traps.h>
  1415. -#include <asm/uaccess.h>
  1416. #include <asm/pgalloc.h>
  1417. extern void die_if_kernel(char *, struct pt_regs *, long);
  1418. @@ -81,7 +81,7 @@
  1419. * If we're in an interrupt or have no user
  1420. * context, we must not take the fault..
  1421. */
  1422. - if (in_atomic() || !mm)
  1423. + if (faulthandler_disabled() || !mm)
  1424. goto no_context;
  1425. if (user_mode(regs))
  1426. diff -Nur linux-4.1.26.orig/arch/metag/mm/fault.c linux-4.1.26/arch/metag/mm/fault.c
  1427. --- linux-4.1.26.orig/arch/metag/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1428. +++ linux-4.1.26/arch/metag/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1429. @@ -105,7 +105,7 @@
  1430. mm = tsk->mm;
  1431. - if (in_atomic() || !mm)
  1432. + if (faulthandler_disabled() || !mm)
  1433. goto no_context;
  1434. if (user_mode(regs))
  1435. diff -Nur linux-4.1.26.orig/arch/metag/mm/highmem.c linux-4.1.26/arch/metag/mm/highmem.c
  1436. --- linux-4.1.26.orig/arch/metag/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  1437. +++ linux-4.1.26/arch/metag/mm/highmem.c 2016-06-19 15:30:58.595293802 +0200
  1438. @@ -43,7 +43,7 @@
  1439. unsigned long vaddr;
  1440. int type;
  1441. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1442. + preempt_disable();
  1443. pagefault_disable();
  1444. if (!PageHighMem(page))
  1445. return page_address(page);
  1446. @@ -82,6 +82,7 @@
  1447. }
  1448. pagefault_enable();
  1449. + preempt_enable();
  1450. }
  1451. EXPORT_SYMBOL(__kunmap_atomic);
  1452. @@ -95,6 +96,7 @@
  1453. unsigned long vaddr;
  1454. int type;
  1455. + preempt_disable();
  1456. pagefault_disable();
  1457. type = kmap_atomic_idx_push();
  1458. diff -Nur linux-4.1.26.orig/arch/microblaze/include/asm/uaccess.h linux-4.1.26/arch/microblaze/include/asm/uaccess.h
  1459. --- linux-4.1.26.orig/arch/microblaze/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  1460. +++ linux-4.1.26/arch/microblaze/include/asm/uaccess.h 2016-06-19 15:30:58.595293802 +0200
  1461. @@ -178,7 +178,8 @@
  1462. * @x: Variable to store result.
  1463. * @ptr: Source address, in user space.
  1464. *
  1465. - * Context: User context only. This function may sleep.
  1466. + * Context: User context only. This function may sleep if pagefaults are
  1467. + * enabled.
  1468. *
  1469. * This macro copies a single simple variable from user space to kernel
  1470. * space. It supports simple types like char and int, but not larger
  1471. @@ -290,7 +291,8 @@
  1472. * @x: Value to copy to user space.
  1473. * @ptr: Destination address, in user space.
  1474. *
  1475. - * Context: User context only. This function may sleep.
  1476. + * Context: User context only. This function may sleep if pagefaults are
  1477. + * enabled.
  1478. *
  1479. * This macro copies a single simple value from kernel space to user
  1480. * space. It supports simple types like char and int, but not larger
  1481. diff -Nur linux-4.1.26.orig/arch/microblaze/mm/fault.c linux-4.1.26/arch/microblaze/mm/fault.c
  1482. --- linux-4.1.26.orig/arch/microblaze/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1483. +++ linux-4.1.26/arch/microblaze/mm/fault.c 2016-06-19 15:30:58.595293802 +0200
  1484. @@ -107,14 +107,14 @@
  1485. if ((error_code & 0x13) == 0x13 || (error_code & 0x11) == 0x11)
  1486. is_write = 0;
  1487. - if (unlikely(in_atomic() || !mm)) {
  1488. + if (unlikely(faulthandler_disabled() || !mm)) {
  1489. if (kernel_mode(regs))
  1490. goto bad_area_nosemaphore;
  1491. - /* in_atomic() in user mode is really bad,
  1492. + /* faulthandler_disabled() in user mode is really bad,
  1493. as is current->mm == NULL. */
  1494. - pr_emerg("Page fault in user mode with in_atomic(), mm = %p\n",
  1495. - mm);
  1496. + pr_emerg("Page fault in user mode with faulthandler_disabled(), mm = %p\n",
  1497. + mm);
  1498. pr_emerg("r15 = %lx MSR = %lx\n",
  1499. regs->r15, regs->msr);
  1500. die("Weird page fault", regs, SIGSEGV);
  1501. diff -Nur linux-4.1.26.orig/arch/microblaze/mm/highmem.c linux-4.1.26/arch/microblaze/mm/highmem.c
  1502. --- linux-4.1.26.orig/arch/microblaze/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  1503. +++ linux-4.1.26/arch/microblaze/mm/highmem.c 2016-06-19 15:30:58.599293956 +0200
  1504. @@ -37,7 +37,7 @@
  1505. unsigned long vaddr;
  1506. int idx, type;
  1507. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1508. + preempt_disable();
  1509. pagefault_disable();
  1510. if (!PageHighMem(page))
  1511. return page_address(page);
  1512. @@ -63,6 +63,7 @@
  1513. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  1514. pagefault_enable();
  1515. + preempt_enable();
  1516. return;
  1517. }
  1518. @@ -84,5 +85,6 @@
  1519. #endif
  1520. kmap_atomic_idx_pop();
  1521. pagefault_enable();
  1522. + preempt_enable();
  1523. }
  1524. EXPORT_SYMBOL(__kunmap_atomic);
  1525. diff -Nur linux-4.1.26.orig/arch/mips/include/asm/uaccess.h linux-4.1.26/arch/mips/include/asm/uaccess.h
  1526. --- linux-4.1.26.orig/arch/mips/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  1527. +++ linux-4.1.26/arch/mips/include/asm/uaccess.h 2016-06-19 15:30:58.599293956 +0200
  1528. @@ -103,7 +103,8 @@
  1529. * @addr: User space pointer to start of block to check
  1530. * @size: Size of block to check
  1531. *
  1532. - * Context: User context only. This function may sleep.
  1533. + * Context: User context only. This function may sleep if pagefaults are
  1534. + * enabled.
  1535. *
  1536. * Checks if a pointer to a block of memory in user space is valid.
  1537. *
  1538. @@ -138,7 +139,8 @@
  1539. * @x: Value to copy to user space.
  1540. * @ptr: Destination address, in user space.
  1541. *
  1542. - * Context: User context only. This function may sleep.
  1543. + * Context: User context only. This function may sleep if pagefaults are
  1544. + * enabled.
  1545. *
  1546. * This macro copies a single simple value from kernel space to user
  1547. * space. It supports simple types like char and int, but not larger
  1548. @@ -157,7 +159,8 @@
  1549. * @x: Variable to store result.
  1550. * @ptr: Source address, in user space.
  1551. *
  1552. - * Context: User context only. This function may sleep.
  1553. + * Context: User context only. This function may sleep if pagefaults are
  1554. + * enabled.
  1555. *
  1556. * This macro copies a single simple variable from user space to kernel
  1557. * space. It supports simple types like char and int, but not larger
  1558. @@ -177,7 +180,8 @@
  1559. * @x: Value to copy to user space.
  1560. * @ptr: Destination address, in user space.
  1561. *
  1562. - * Context: User context only. This function may sleep.
  1563. + * Context: User context only. This function may sleep if pagefaults are
  1564. + * enabled.
  1565. *
  1566. * This macro copies a single simple value from kernel space to user
  1567. * space. It supports simple types like char and int, but not larger
  1568. @@ -199,7 +203,8 @@
  1569. * @x: Variable to store result.
  1570. * @ptr: Source address, in user space.
  1571. *
  1572. - * Context: User context only. This function may sleep.
  1573. + * Context: User context only. This function may sleep if pagefaults are
  1574. + * enabled.
  1575. *
  1576. * This macro copies a single simple variable from user space to kernel
  1577. * space. It supports simple types like char and int, but not larger
  1578. @@ -498,7 +503,8 @@
  1579. * @x: Value to copy to user space.
  1580. * @ptr: Destination address, in user space.
  1581. *
  1582. - * Context: User context only. This function may sleep.
  1583. + * Context: User context only. This function may sleep if pagefaults are
  1584. + * enabled.
  1585. *
  1586. * This macro copies a single simple value from kernel space to user
  1587. * space. It supports simple types like char and int, but not larger
  1588. @@ -517,7 +523,8 @@
  1589. * @x: Variable to store result.
  1590. * @ptr: Source address, in user space.
  1591. *
  1592. - * Context: User context only. This function may sleep.
  1593. + * Context: User context only. This function may sleep if pagefaults are
  1594. + * enabled.
  1595. *
  1596. * This macro copies a single simple variable from user space to kernel
  1597. * space. It supports simple types like char and int, but not larger
  1598. @@ -537,7 +544,8 @@
  1599. * @x: Value to copy to user space.
  1600. * @ptr: Destination address, in user space.
  1601. *
  1602. - * Context: User context only. This function may sleep.
  1603. + * Context: User context only. This function may sleep if pagefaults are
  1604. + * enabled.
  1605. *
  1606. * This macro copies a single simple value from kernel space to user
  1607. * space. It supports simple types like char and int, but not larger
  1608. @@ -559,7 +567,8 @@
  1609. * @x: Variable to store result.
  1610. * @ptr: Source address, in user space.
  1611. *
  1612. - * Context: User context only. This function may sleep.
  1613. + * Context: User context only. This function may sleep if pagefaults are
  1614. + * enabled.
  1615. *
  1616. * This macro copies a single simple variable from user space to kernel
  1617. * space. It supports simple types like char and int, but not larger
  1618. @@ -815,7 +824,8 @@
  1619. * @from: Source address, in kernel space.
  1620. * @n: Number of bytes to copy.
  1621. *
  1622. - * Context: User context only. This function may sleep.
  1623. + * Context: User context only. This function may sleep if pagefaults are
  1624. + * enabled.
  1625. *
  1626. * Copy data from kernel space to user space. Caller must check
  1627. * the specified block with access_ok() before calling this function.
  1628. @@ -888,7 +898,8 @@
  1629. * @from: Source address, in kernel space.
  1630. * @n: Number of bytes to copy.
  1631. *
  1632. - * Context: User context only. This function may sleep.
  1633. + * Context: User context only. This function may sleep if pagefaults are
  1634. + * enabled.
  1635. *
  1636. * Copy data from kernel space to user space.
  1637. *
  1638. @@ -1075,7 +1086,8 @@
  1639. * @from: Source address, in user space.
  1640. * @n: Number of bytes to copy.
  1641. *
  1642. - * Context: User context only. This function may sleep.
  1643. + * Context: User context only. This function may sleep if pagefaults are
  1644. + * enabled.
  1645. *
  1646. * Copy data from user space to kernel space. Caller must check
  1647. * the specified block with access_ok() before calling this function.
  1648. @@ -1107,7 +1119,8 @@
  1649. * @from: Source address, in user space.
  1650. * @n: Number of bytes to copy.
  1651. *
  1652. - * Context: User context only. This function may sleep.
  1653. + * Context: User context only. This function may sleep if pagefaults are
  1654. + * enabled.
  1655. *
  1656. * Copy data from user space to kernel space.
  1657. *
  1658. @@ -1329,7 +1342,8 @@
  1659. * strlen_user: - Get the size of a string in user space.
  1660. * @str: The string to measure.
  1661. *
  1662. - * Context: User context only. This function may sleep.
  1663. + * Context: User context only. This function may sleep if pagefaults are
  1664. + * enabled.
  1665. *
  1666. * Get the size of a NUL-terminated string in user space.
  1667. *
  1668. @@ -1398,7 +1412,8 @@
  1669. * strnlen_user: - Get the size of a string in user space.
  1670. * @str: The string to measure.
  1671. *
  1672. - * Context: User context only. This function may sleep.
  1673. + * Context: User context only. This function may sleep if pagefaults are
  1674. + * enabled.
  1675. *
  1676. * Get the size of a NUL-terminated string in user space.
  1677. *
  1678. diff -Nur linux-4.1.26.orig/arch/mips/Kconfig linux-4.1.26/arch/mips/Kconfig
  1679. --- linux-4.1.26.orig/arch/mips/Kconfig 2016-06-07 01:13:11.000000000 +0200
  1680. +++ linux-4.1.26/arch/mips/Kconfig 2016-06-19 15:30:58.599293956 +0200
  1681. @@ -2367,7 +2367,7 @@
  1682. #
  1683. config HIGHMEM
  1684. bool "High Memory Support"
  1685. - depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA
  1686. + depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA && !PREEMPT_RT_FULL
  1687. config CPU_SUPPORTS_HIGHMEM
  1688. bool
  1689. diff -Nur linux-4.1.26.orig/arch/mips/kernel/signal-common.h linux-4.1.26/arch/mips/kernel/signal-common.h
  1690. --- linux-4.1.26.orig/arch/mips/kernel/signal-common.h 2016-06-07 01:13:11.000000000 +0200
  1691. +++ linux-4.1.26/arch/mips/kernel/signal-common.h 2016-06-19 15:30:58.599293956 +0200
  1692. @@ -28,12 +28,7 @@
  1693. extern int fpcsr_pending(unsigned int __user *fpcsr);
  1694. /* Make sure we will not lose FPU ownership */
  1695. -#ifdef CONFIG_PREEMPT
  1696. -#define lock_fpu_owner() preempt_disable()
  1697. -#define unlock_fpu_owner() preempt_enable()
  1698. -#else
  1699. -#define lock_fpu_owner() pagefault_disable()
  1700. -#define unlock_fpu_owner() pagefault_enable()
  1701. -#endif
  1702. +#define lock_fpu_owner() ({ preempt_disable(); pagefault_disable(); })
  1703. +#define unlock_fpu_owner() ({ pagefault_enable(); preempt_enable(); })
  1704. #endif /* __SIGNAL_COMMON_H */
  1705. diff -Nur linux-4.1.26.orig/arch/mips/mm/fault.c linux-4.1.26/arch/mips/mm/fault.c
  1706. --- linux-4.1.26.orig/arch/mips/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1707. +++ linux-4.1.26/arch/mips/mm/fault.c 2016-06-19 15:30:58.599293956 +0200
  1708. @@ -21,10 +21,10 @@
  1709. #include <linux/module.h>
  1710. #include <linux/kprobes.h>
  1711. #include <linux/perf_event.h>
  1712. +#include <linux/uaccess.h>
  1713. #include <asm/branch.h>
  1714. #include <asm/mmu_context.h>
  1715. -#include <asm/uaccess.h>
  1716. #include <asm/ptrace.h>
  1717. #include <asm/highmem.h> /* For VMALLOC_END */
  1718. #include <linux/kdebug.h>
  1719. @@ -94,7 +94,7 @@
  1720. * If we're in an interrupt or have no user
  1721. * context, we must not take the fault..
  1722. */
  1723. - if (in_atomic() || !mm)
  1724. + if (faulthandler_disabled() || !mm)
  1725. goto bad_area_nosemaphore;
  1726. if (user_mode(regs))
  1727. diff -Nur linux-4.1.26.orig/arch/mips/mm/highmem.c linux-4.1.26/arch/mips/mm/highmem.c
  1728. --- linux-4.1.26.orig/arch/mips/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  1729. +++ linux-4.1.26/arch/mips/mm/highmem.c 2016-06-19 15:30:58.599293956 +0200
  1730. @@ -47,7 +47,7 @@
  1731. unsigned long vaddr;
  1732. int idx, type;
  1733. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1734. + preempt_disable();
  1735. pagefault_disable();
  1736. if (!PageHighMem(page))
  1737. return page_address(page);
  1738. @@ -72,6 +72,7 @@
  1739. if (vaddr < FIXADDR_START) { // FIXME
  1740. pagefault_enable();
  1741. + preempt_enable();
  1742. return;
  1743. }
  1744. @@ -92,6 +93,7 @@
  1745. #endif
  1746. kmap_atomic_idx_pop();
  1747. pagefault_enable();
  1748. + preempt_enable();
  1749. }
  1750. EXPORT_SYMBOL(__kunmap_atomic);
  1751. @@ -104,6 +106,7 @@
  1752. unsigned long vaddr;
  1753. int idx, type;
  1754. + preempt_disable();
  1755. pagefault_disable();
  1756. type = kmap_atomic_idx_push();
  1757. diff -Nur linux-4.1.26.orig/arch/mips/mm/init.c linux-4.1.26/arch/mips/mm/init.c
  1758. --- linux-4.1.26.orig/arch/mips/mm/init.c 2016-06-07 01:13:11.000000000 +0200
  1759. +++ linux-4.1.26/arch/mips/mm/init.c 2016-06-19 15:30:58.599293956 +0200
  1760. @@ -90,6 +90,7 @@
  1761. BUG_ON(Page_dcache_dirty(page));
  1762. + preempt_disable();
  1763. pagefault_disable();
  1764. idx = (addr >> PAGE_SHIFT) & (FIX_N_COLOURS - 1);
  1765. idx += in_interrupt() ? FIX_N_COLOURS : 0;
  1766. @@ -152,6 +153,7 @@
  1767. write_c0_entryhi(old_ctx);
  1768. local_irq_restore(flags);
  1769. pagefault_enable();
  1770. + preempt_enable();
  1771. }
  1772. void copy_user_highpage(struct page *to, struct page *from,
  1773. diff -Nur linux-4.1.26.orig/arch/mn10300/include/asm/highmem.h linux-4.1.26/arch/mn10300/include/asm/highmem.h
  1774. --- linux-4.1.26.orig/arch/mn10300/include/asm/highmem.h 2016-06-07 01:13:11.000000000 +0200
  1775. +++ linux-4.1.26/arch/mn10300/include/asm/highmem.h 2016-06-19 15:30:58.599293956 +0200
  1776. @@ -75,6 +75,7 @@
  1777. unsigned long vaddr;
  1778. int idx, type;
  1779. + preempt_disable();
  1780. pagefault_disable();
  1781. if (page < highmem_start_page)
  1782. return page_address(page);
  1783. @@ -98,6 +99,7 @@
  1784. if (vaddr < FIXADDR_START) { /* FIXME */
  1785. pagefault_enable();
  1786. + preempt_enable();
  1787. return;
  1788. }
  1789. @@ -122,6 +124,7 @@
  1790. kmap_atomic_idx_pop();
  1791. pagefault_enable();
  1792. + preempt_enable();
  1793. }
  1794. #endif /* __KERNEL__ */
  1795. diff -Nur linux-4.1.26.orig/arch/mn10300/mm/fault.c linux-4.1.26/arch/mn10300/mm/fault.c
  1796. --- linux-4.1.26.orig/arch/mn10300/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1797. +++ linux-4.1.26/arch/mn10300/mm/fault.c 2016-06-19 15:30:58.599293956 +0200
  1798. @@ -23,8 +23,8 @@
  1799. #include <linux/interrupt.h>
  1800. #include <linux/init.h>
  1801. #include <linux/vt_kern.h> /* For unblank_screen() */
  1802. +#include <linux/uaccess.h>
  1803. -#include <asm/uaccess.h>
  1804. #include <asm/pgalloc.h>
  1805. #include <asm/hardirq.h>
  1806. #include <asm/cpu-regs.h>
  1807. @@ -168,7 +168,7 @@
  1808. * If we're in an interrupt or have no user
  1809. * context, we must not take the fault..
  1810. */
  1811. - if (in_atomic() || !mm)
  1812. + if (faulthandler_disabled() || !mm)
  1813. goto no_context;
  1814. if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
  1815. diff -Nur linux-4.1.26.orig/arch/nios2/mm/fault.c linux-4.1.26/arch/nios2/mm/fault.c
  1816. --- linux-4.1.26.orig/arch/nios2/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1817. +++ linux-4.1.26/arch/nios2/mm/fault.c 2016-06-19 15:30:58.599293956 +0200
  1818. @@ -77,7 +77,7 @@
  1819. * If we're in an interrupt or have no user
  1820. * context, we must not take the fault..
  1821. */
  1822. - if (in_atomic() || !mm)
  1823. + if (faulthandler_disabled() || !mm)
  1824. goto bad_area_nosemaphore;
  1825. if (user_mode(regs))
  1826. diff -Nur linux-4.1.26.orig/arch/parisc/include/asm/cacheflush.h linux-4.1.26/arch/parisc/include/asm/cacheflush.h
  1827. --- linux-4.1.26.orig/arch/parisc/include/asm/cacheflush.h 2016-06-07 01:13:11.000000000 +0200
  1828. +++ linux-4.1.26/arch/parisc/include/asm/cacheflush.h 2016-06-19 15:30:58.599293956 +0200
  1829. @@ -142,6 +142,7 @@
  1830. static inline void *kmap_atomic(struct page *page)
  1831. {
  1832. + preempt_disable();
  1833. pagefault_disable();
  1834. return page_address(page);
  1835. }
  1836. @@ -150,6 +151,7 @@
  1837. {
  1838. flush_kernel_dcache_page_addr(addr);
  1839. pagefault_enable();
  1840. + preempt_enable();
  1841. }
  1842. #define kmap_atomic_prot(page, prot) kmap_atomic(page)
  1843. diff -Nur linux-4.1.26.orig/arch/parisc/kernel/traps.c linux-4.1.26/arch/parisc/kernel/traps.c
  1844. --- linux-4.1.26.orig/arch/parisc/kernel/traps.c 2016-06-07 01:13:11.000000000 +0200
  1845. +++ linux-4.1.26/arch/parisc/kernel/traps.c 2016-06-19 15:30:58.599293956 +0200
  1846. @@ -26,9 +26,9 @@
  1847. #include <linux/console.h>
  1848. #include <linux/bug.h>
  1849. #include <linux/ratelimit.h>
  1850. +#include <linux/uaccess.h>
  1851. #include <asm/assembly.h>
  1852. -#include <asm/uaccess.h>
  1853. #include <asm/io.h>
  1854. #include <asm/irq.h>
  1855. #include <asm/traps.h>
  1856. @@ -796,7 +796,7 @@
  1857. * unless pagefault_disable() was called before.
  1858. */
  1859. - if (fault_space == 0 && !in_atomic())
  1860. + if (fault_space == 0 && !faulthandler_disabled())
  1861. {
  1862. /* Clean up and return if in exception table. */
  1863. if (fixup_exception(regs))
  1864. diff -Nur linux-4.1.26.orig/arch/parisc/mm/fault.c linux-4.1.26/arch/parisc/mm/fault.c
  1865. --- linux-4.1.26.orig/arch/parisc/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  1866. +++ linux-4.1.26/arch/parisc/mm/fault.c 2016-06-19 15:30:58.599293956 +0200
  1867. @@ -15,8 +15,8 @@
  1868. #include <linux/sched.h>
  1869. #include <linux/interrupt.h>
  1870. #include <linux/module.h>
  1871. +#include <linux/uaccess.h>
  1872. -#include <asm/uaccess.h>
  1873. #include <asm/traps.h>
  1874. /* Various important other fields */
  1875. @@ -208,7 +208,7 @@
  1876. int fault;
  1877. unsigned int flags;
  1878. - if (in_atomic())
  1879. + if (pagefault_disabled())
  1880. goto no_context;
  1881. tsk = current;
  1882. diff -Nur linux-4.1.26.orig/arch/powerpc/include/asm/kvm_host.h linux-4.1.26/arch/powerpc/include/asm/kvm_host.h
  1883. --- linux-4.1.26.orig/arch/powerpc/include/asm/kvm_host.h 2016-06-07 01:13:11.000000000 +0200
  1884. +++ linux-4.1.26/arch/powerpc/include/asm/kvm_host.h 2016-06-19 15:30:58.599293956 +0200
  1885. @@ -280,7 +280,7 @@
  1886. u8 in_guest;
  1887. struct list_head runnable_threads;
  1888. spinlock_t lock;
  1889. - wait_queue_head_t wq;
  1890. + struct swait_head wq;
  1891. spinlock_t stoltb_lock; /* protects stolen_tb and preempt_tb */
  1892. u64 stolen_tb;
  1893. u64 preempt_tb;
  1894. @@ -613,7 +613,7 @@
  1895. u8 prodded;
  1896. u32 last_inst;
  1897. - wait_queue_head_t *wqp;
  1898. + struct swait_head *wqp;
  1899. struct kvmppc_vcore *vcore;
  1900. int ret;
  1901. int trap;
  1902. diff -Nur linux-4.1.26.orig/arch/powerpc/include/asm/thread_info.h linux-4.1.26/arch/powerpc/include/asm/thread_info.h
  1903. --- linux-4.1.26.orig/arch/powerpc/include/asm/thread_info.h 2016-06-07 01:13:11.000000000 +0200
  1904. +++ linux-4.1.26/arch/powerpc/include/asm/thread_info.h 2016-06-19 15:30:58.603294110 +0200
  1905. @@ -42,6 +42,8 @@
  1906. int cpu; /* cpu we're on */
  1907. int preempt_count; /* 0 => preemptable,
  1908. <0 => BUG */
  1909. + int preempt_lazy_count; /* 0 => preemptable,
  1910. + <0 => BUG */
  1911. unsigned long local_flags; /* private flags for thread */
  1912. /* low level flags - has atomic operations done on it */
  1913. @@ -82,8 +84,7 @@
  1914. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  1915. #define TIF_SIGPENDING 1 /* signal pending */
  1916. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  1917. -#define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  1918. - TIF_NEED_RESCHED */
  1919. +#define TIF_NEED_RESCHED_LAZY 3 /* lazy rescheduling necessary */
  1920. #define TIF_32BIT 4 /* 32 bit binary */
  1921. #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
  1922. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  1923. @@ -101,6 +102,8 @@
  1924. #if defined(CONFIG_PPC64)
  1925. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  1926. #endif
  1927. +#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling
  1928. + TIF_NEED_RESCHED */
  1929. /* as above, but as bit values */
  1930. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  1931. @@ -119,14 +122,16 @@
  1932. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  1933. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  1934. #define _TIF_NOHZ (1<<TIF_NOHZ)
  1935. +#define _TIF_NEED_RESCHED_LAZY (1<<TIF_NEED_RESCHED_LAZY)
  1936. #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  1937. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  1938. _TIF_NOHZ)
  1939. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  1940. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  1941. - _TIF_RESTORE_TM)
  1942. + _TIF_RESTORE_TM | _TIF_NEED_RESCHED_LAZY)
  1943. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  1944. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  1945. /* Bits in local_flags */
  1946. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  1947. diff -Nur linux-4.1.26.orig/arch/powerpc/Kconfig linux-4.1.26/arch/powerpc/Kconfig
  1948. --- linux-4.1.26.orig/arch/powerpc/Kconfig 2016-06-07 01:13:11.000000000 +0200
  1949. +++ linux-4.1.26/arch/powerpc/Kconfig 2016-06-19 15:30:58.599293956 +0200
  1950. @@ -60,10 +60,11 @@
  1951. config RWSEM_GENERIC_SPINLOCK
  1952. bool
  1953. + default y if PREEMPT_RT_FULL
  1954. config RWSEM_XCHGADD_ALGORITHM
  1955. bool
  1956. - default y
  1957. + default y if !PREEMPT_RT_FULL
  1958. config GENERIC_LOCKBREAK
  1959. bool
  1960. @@ -138,6 +139,7 @@
  1961. select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
  1962. select GENERIC_STRNCPY_FROM_USER
  1963. select GENERIC_STRNLEN_USER
  1964. + select HAVE_PREEMPT_LAZY
  1965. select HAVE_MOD_ARCH_SPECIFIC
  1966. select MODULES_USE_ELF_RELA
  1967. select CLONE_BACKWARDS
  1968. @@ -312,7 +314,7 @@
  1969. config HIGHMEM
  1970. bool "High memory support"
  1971. - depends on PPC32
  1972. + depends on PPC32 && !PREEMPT_RT_FULL
  1973. source kernel/Kconfig.hz
  1974. source kernel/Kconfig.preempt
  1975. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/asm-offsets.c linux-4.1.26/arch/powerpc/kernel/asm-offsets.c
  1976. --- linux-4.1.26.orig/arch/powerpc/kernel/asm-offsets.c 2016-06-07 01:13:11.000000000 +0200
  1977. +++ linux-4.1.26/arch/powerpc/kernel/asm-offsets.c 2016-06-19 15:30:58.603294110 +0200
  1978. @@ -160,6 +160,7 @@
  1979. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1980. DEFINE(TI_LOCAL_FLAGS, offsetof(struct thread_info, local_flags));
  1981. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1982. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1983. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1984. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1985. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/entry_32.S linux-4.1.26/arch/powerpc/kernel/entry_32.S
  1986. --- linux-4.1.26.orig/arch/powerpc/kernel/entry_32.S 2016-06-07 01:13:11.000000000 +0200
  1987. +++ linux-4.1.26/arch/powerpc/kernel/entry_32.S 2016-06-19 15:30:58.603294110 +0200
  1988. @@ -813,7 +813,14 @@
  1989. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1990. bne restore
  1991. andi. r8,r8,_TIF_NEED_RESCHED
  1992. + bne+ 1f
  1993. + lwz r0,TI_PREEMPT_LAZY(r9)
  1994. + cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1995. + bne restore
  1996. + lwz r0,TI_FLAGS(r9)
  1997. + andi. r0,r0,_TIF_NEED_RESCHED_LAZY
  1998. beq+ restore
  1999. +1:
  2000. lwz r3,_MSR(r1)
  2001. andi. r0,r3,MSR_EE /* interrupts off? */
  2002. beq restore /* don't schedule if so */
  2003. @@ -824,11 +831,11 @@
  2004. */
  2005. bl trace_hardirqs_off
  2006. #endif
  2007. -1: bl preempt_schedule_irq
  2008. +2: bl preempt_schedule_irq
  2009. CURRENT_THREAD_INFO(r9, r1)
  2010. lwz r3,TI_FLAGS(r9)
  2011. - andi. r0,r3,_TIF_NEED_RESCHED
  2012. - bne- 1b
  2013. + andi. r0,r3,_TIF_NEED_RESCHED_MASK
  2014. + bne- 2b
  2015. #ifdef CONFIG_TRACE_IRQFLAGS
  2016. /* And now, to properly rebalance the above, we tell lockdep they
  2017. * are being turned back on, which will happen when we return
  2018. @@ -1149,7 +1156,7 @@
  2019. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  2020. do_work: /* r10 contains MSR_KERNEL here */
  2021. - andi. r0,r9,_TIF_NEED_RESCHED
  2022. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  2023. beq do_user_signal
  2024. do_resched: /* r10 contains MSR_KERNEL here */
  2025. @@ -1170,7 +1177,7 @@
  2026. MTMSRD(r10) /* disable interrupts */
  2027. CURRENT_THREAD_INFO(r9, r1)
  2028. lwz r9,TI_FLAGS(r9)
  2029. - andi. r0,r9,_TIF_NEED_RESCHED
  2030. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  2031. bne- do_resched
  2032. andi. r0,r9,_TIF_USER_WORK_MASK
  2033. beq restore_user
  2034. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/entry_64.S linux-4.1.26/arch/powerpc/kernel/entry_64.S
  2035. --- linux-4.1.26.orig/arch/powerpc/kernel/entry_64.S 2016-06-07 01:13:11.000000000 +0200
  2036. +++ linux-4.1.26/arch/powerpc/kernel/entry_64.S 2016-06-19 15:30:58.603294110 +0200
  2037. @@ -636,7 +636,7 @@
  2038. #else
  2039. beq restore
  2040. #endif
  2041. -1: andi. r0,r4,_TIF_NEED_RESCHED
  2042. +1: andi. r0,r4,_TIF_NEED_RESCHED_MASK
  2043. beq 2f
  2044. bl restore_interrupts
  2045. SCHEDULE_USER
  2046. @@ -698,10 +698,18 @@
  2047. #ifdef CONFIG_PREEMPT
  2048. /* Check if we need to preempt */
  2049. + lwz r8,TI_PREEMPT(r9)
  2050. + cmpwi 0,r8,0 /* if non-zero, just restore regs and return */
  2051. + bne restore
  2052. andi. r0,r4,_TIF_NEED_RESCHED
  2053. + bne+ check_count
  2054. +
  2055. + andi. r0,r4,_TIF_NEED_RESCHED_LAZY
  2056. beq+ restore
  2057. + lwz r8,TI_PREEMPT_LAZY(r9)
  2058. +
  2059. /* Check that preempt_count() == 0 and interrupts are enabled */
  2060. - lwz r8,TI_PREEMPT(r9)
  2061. +check_count:
  2062. cmpwi cr1,r8,0
  2063. ld r0,SOFTE(r1)
  2064. cmpdi r0,0
  2065. @@ -718,7 +726,7 @@
  2066. /* Re-test flags and eventually loop */
  2067. CURRENT_THREAD_INFO(r9, r1)
  2068. ld r4,TI_FLAGS(r9)
  2069. - andi. r0,r4,_TIF_NEED_RESCHED
  2070. + andi. r0,r4,_TIF_NEED_RESCHED_MASK
  2071. bne 1b
  2072. /*
  2073. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/irq.c linux-4.1.26/arch/powerpc/kernel/irq.c
  2074. --- linux-4.1.26.orig/arch/powerpc/kernel/irq.c 2016-06-07 01:13:11.000000000 +0200
  2075. +++ linux-4.1.26/arch/powerpc/kernel/irq.c 2016-06-19 15:30:58.603294110 +0200
  2076. @@ -614,6 +614,7 @@
  2077. }
  2078. }
  2079. +#ifndef CONFIG_PREEMPT_RT_FULL
  2080. void do_softirq_own_stack(void)
  2081. {
  2082. struct thread_info *curtp, *irqtp;
  2083. @@ -631,6 +632,7 @@
  2084. if (irqtp->flags)
  2085. set_bits(irqtp->flags, &curtp->flags);
  2086. }
  2087. +#endif
  2088. irq_hw_number_t virq_to_hw(unsigned int virq)
  2089. {
  2090. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/misc_32.S linux-4.1.26/arch/powerpc/kernel/misc_32.S
  2091. --- linux-4.1.26.orig/arch/powerpc/kernel/misc_32.S 2016-06-07 01:13:11.000000000 +0200
  2092. +++ linux-4.1.26/arch/powerpc/kernel/misc_32.S 2016-06-19 15:30:58.603294110 +0200
  2093. @@ -40,6 +40,7 @@
  2094. * We store the saved ksp_limit in the unused part
  2095. * of the STACK_FRAME_OVERHEAD
  2096. */
  2097. +#ifndef CONFIG_PREEMPT_RT_FULL
  2098. _GLOBAL(call_do_softirq)
  2099. mflr r0
  2100. stw r0,4(r1)
  2101. @@ -56,6 +57,7 @@
  2102. stw r10,THREAD+KSP_LIMIT(r2)
  2103. mtlr r0
  2104. blr
  2105. +#endif
  2106. /*
  2107. * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
  2108. diff -Nur linux-4.1.26.orig/arch/powerpc/kernel/misc_64.S linux-4.1.26/arch/powerpc/kernel/misc_64.S
  2109. --- linux-4.1.26.orig/arch/powerpc/kernel/misc_64.S 2016-06-07 01:13:11.000000000 +0200
  2110. +++ linux-4.1.26/arch/powerpc/kernel/misc_64.S 2016-06-19 15:30:58.603294110 +0200
  2111. @@ -29,6 +29,7 @@
  2112. .text
  2113. +#ifndef CONFIG_PREEMPT_RT_FULL
  2114. _GLOBAL(call_do_softirq)
  2115. mflr r0
  2116. std r0,16(r1)
  2117. @@ -39,6 +40,7 @@
  2118. ld r0,16(r1)
  2119. mtlr r0
  2120. blr
  2121. +#endif
  2122. _GLOBAL(call_do_irq)
  2123. mflr r0
  2124. diff -Nur linux-4.1.26.orig/arch/powerpc/kvm/book3s_hv.c linux-4.1.26/arch/powerpc/kvm/book3s_hv.c
  2125. --- linux-4.1.26.orig/arch/powerpc/kvm/book3s_hv.c 2016-06-07 01:13:11.000000000 +0200
  2126. +++ linux-4.1.26/arch/powerpc/kvm/book3s_hv.c 2016-06-19 15:30:58.603294110 +0200
  2127. @@ -115,11 +115,11 @@
  2128. static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
  2129. {
  2130. int cpu = vcpu->cpu;
  2131. - wait_queue_head_t *wqp;
  2132. + struct swait_head *wqp;
  2133. wqp = kvm_arch_vcpu_wq(vcpu);
  2134. - if (waitqueue_active(wqp)) {
  2135. - wake_up_interruptible(wqp);
  2136. + if (swaitqueue_active(wqp)) {
  2137. + swait_wake_interruptible(wqp);
  2138. ++vcpu->stat.halt_wakeup;
  2139. }
  2140. @@ -692,8 +692,8 @@
  2141. tvcpu->arch.prodded = 1;
  2142. smp_mb();
  2143. if (vcpu->arch.ceded) {
  2144. - if (waitqueue_active(&vcpu->wq)) {
  2145. - wake_up_interruptible(&vcpu->wq);
  2146. + if (swaitqueue_active(&vcpu->wq)) {
  2147. + swait_wake_interruptible(&vcpu->wq);
  2148. vcpu->stat.halt_wakeup++;
  2149. }
  2150. }
  2151. @@ -1432,7 +1432,7 @@
  2152. INIT_LIST_HEAD(&vcore->runnable_threads);
  2153. spin_lock_init(&vcore->lock);
  2154. spin_lock_init(&vcore->stoltb_lock);
  2155. - init_waitqueue_head(&vcore->wq);
  2156. + init_swait_head(&vcore->wq);
  2157. vcore->preempt_tb = TB_NIL;
  2158. vcore->lpcr = kvm->arch.lpcr;
  2159. vcore->first_vcpuid = core * threads_per_subcore;
  2160. @@ -2079,10 +2079,9 @@
  2161. {
  2162. struct kvm_vcpu *vcpu;
  2163. int do_sleep = 1;
  2164. + DEFINE_SWAITER(wait);
  2165. - DEFINE_WAIT(wait);
  2166. -
  2167. - prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  2168. + swait_prepare(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  2169. /*
  2170. * Check one last time for pending exceptions and ceded state after
  2171. @@ -2096,7 +2095,7 @@
  2172. }
  2173. if (!do_sleep) {
  2174. - finish_wait(&vc->wq, &wait);
  2175. + swait_finish(&vc->wq, &wait);
  2176. return;
  2177. }
  2178. @@ -2104,7 +2103,7 @@
  2179. trace_kvmppc_vcore_blocked(vc, 0);
  2180. spin_unlock(&vc->lock);
  2181. schedule();
  2182. - finish_wait(&vc->wq, &wait);
  2183. + swait_finish(&vc->wq, &wait);
  2184. spin_lock(&vc->lock);
  2185. vc->vcore_state = VCORE_INACTIVE;
  2186. trace_kvmppc_vcore_blocked(vc, 1);
  2187. @@ -2148,7 +2147,7 @@
  2188. kvmppc_start_thread(vcpu);
  2189. trace_kvm_guest_enter(vcpu);
  2190. } else if (vc->vcore_state == VCORE_SLEEPING) {
  2191. - wake_up(&vc->wq);
  2192. + swait_wake(&vc->wq);
  2193. }
  2194. }
  2195. diff -Nur linux-4.1.26.orig/arch/powerpc/kvm/Kconfig linux-4.1.26/arch/powerpc/kvm/Kconfig
  2196. --- linux-4.1.26.orig/arch/powerpc/kvm/Kconfig 2016-06-07 01:13:11.000000000 +0200
  2197. +++ linux-4.1.26/arch/powerpc/kvm/Kconfig 2016-06-19 15:30:58.603294110 +0200
  2198. @@ -172,6 +172,7 @@
  2199. config KVM_MPIC
  2200. bool "KVM in-kernel MPIC emulation"
  2201. depends on KVM && E500
  2202. + depends on !PREEMPT_RT_FULL
  2203. select HAVE_KVM_IRQCHIP
  2204. select HAVE_KVM_IRQFD
  2205. select HAVE_KVM_IRQ_ROUTING
  2206. diff -Nur linux-4.1.26.orig/arch/powerpc/mm/fault.c linux-4.1.26/arch/powerpc/mm/fault.c
  2207. --- linux-4.1.26.orig/arch/powerpc/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2208. +++ linux-4.1.26/arch/powerpc/mm/fault.c 2016-06-19 15:30:58.603294110 +0200
  2209. @@ -33,13 +33,13 @@
  2210. #include <linux/ratelimit.h>
  2211. #include <linux/context_tracking.h>
  2212. #include <linux/hugetlb.h>
  2213. +#include <linux/uaccess.h>
  2214. #include <asm/firmware.h>
  2215. #include <asm/page.h>
  2216. #include <asm/pgtable.h>
  2217. #include <asm/mmu.h>
  2218. #include <asm/mmu_context.h>
  2219. -#include <asm/uaccess.h>
  2220. #include <asm/tlbflush.h>
  2221. #include <asm/siginfo.h>
  2222. #include <asm/debug.h>
  2223. @@ -272,15 +272,16 @@
  2224. if (!arch_irq_disabled_regs(regs))
  2225. local_irq_enable();
  2226. - if (in_atomic() || mm == NULL) {
  2227. + if (faulthandler_disabled() || mm == NULL) {
  2228. if (!user_mode(regs)) {
  2229. rc = SIGSEGV;
  2230. goto bail;
  2231. }
  2232. - /* in_atomic() in user mode is really bad,
  2233. + /* faulthandler_disabled() in user mode is really bad,
  2234. as is current->mm == NULL. */
  2235. printk(KERN_EMERG "Page fault in user mode with "
  2236. - "in_atomic() = %d mm = %p\n", in_atomic(), mm);
  2237. + "faulthandler_disabled() = %d mm = %p\n",
  2238. + faulthandler_disabled(), mm);
  2239. printk(KERN_EMERG "NIP = %lx MSR = %lx\n",
  2240. regs->nip, regs->msr);
  2241. die("Weird page fault", regs, SIGSEGV);
  2242. diff -Nur linux-4.1.26.orig/arch/powerpc/mm/highmem.c linux-4.1.26/arch/powerpc/mm/highmem.c
  2243. --- linux-4.1.26.orig/arch/powerpc/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  2244. +++ linux-4.1.26/arch/powerpc/mm/highmem.c 2016-06-19 15:30:58.603294110 +0200
  2245. @@ -34,7 +34,7 @@
  2246. unsigned long vaddr;
  2247. int idx, type;
  2248. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2249. + preempt_disable();
  2250. pagefault_disable();
  2251. if (!PageHighMem(page))
  2252. return page_address(page);
  2253. @@ -59,6 +59,7 @@
  2254. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  2255. pagefault_enable();
  2256. + preempt_enable();
  2257. return;
  2258. }
  2259. @@ -82,5 +83,6 @@
  2260. kmap_atomic_idx_pop();
  2261. pagefault_enable();
  2262. + preempt_enable();
  2263. }
  2264. EXPORT_SYMBOL(__kunmap_atomic);
  2265. diff -Nur linux-4.1.26.orig/arch/powerpc/platforms/ps3/device-init.c linux-4.1.26/arch/powerpc/platforms/ps3/device-init.c
  2266. --- linux-4.1.26.orig/arch/powerpc/platforms/ps3/device-init.c 2016-06-07 01:13:11.000000000 +0200
  2267. +++ linux-4.1.26/arch/powerpc/platforms/ps3/device-init.c 2016-06-19 15:30:58.603294110 +0200
  2268. @@ -752,7 +752,7 @@
  2269. }
  2270. pr_debug("%s:%u: notification %s issued\n", __func__, __LINE__, op);
  2271. - res = wait_event_interruptible(dev->done.wait,
  2272. + res = swait_event_interruptible(dev->done.wait,
  2273. dev->done.done || kthread_should_stop());
  2274. if (kthread_should_stop())
  2275. res = -EINTR;
  2276. diff -Nur linux-4.1.26.orig/arch/s390/include/asm/kvm_host.h linux-4.1.26/arch/s390/include/asm/kvm_host.h
  2277. --- linux-4.1.26.orig/arch/s390/include/asm/kvm_host.h 2016-06-07 01:13:11.000000000 +0200
  2278. +++ linux-4.1.26/arch/s390/include/asm/kvm_host.h 2016-06-19 15:30:58.603294110 +0200
  2279. @@ -419,7 +419,7 @@
  2280. struct kvm_s390_local_interrupt {
  2281. spinlock_t lock;
  2282. struct kvm_s390_float_interrupt *float_int;
  2283. - wait_queue_head_t *wq;
  2284. + struct swait_head *wq;
  2285. atomic_t *cpuflags;
  2286. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  2287. struct kvm_s390_irq_payload irq;
  2288. diff -Nur linux-4.1.26.orig/arch/s390/include/asm/uaccess.h linux-4.1.26/arch/s390/include/asm/uaccess.h
  2289. --- linux-4.1.26.orig/arch/s390/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  2290. +++ linux-4.1.26/arch/s390/include/asm/uaccess.h 2016-06-19 15:30:58.603294110 +0200
  2291. @@ -98,7 +98,8 @@
  2292. * @from: Source address, in user space.
  2293. * @n: Number of bytes to copy.
  2294. *
  2295. - * Context: User context only. This function may sleep.
  2296. + * Context: User context only. This function may sleep if pagefaults are
  2297. + * enabled.
  2298. *
  2299. * Copy data from user space to kernel space. Caller must check
  2300. * the specified block with access_ok() before calling this function.
  2301. @@ -118,7 +119,8 @@
  2302. * @from: Source address, in kernel space.
  2303. * @n: Number of bytes to copy.
  2304. *
  2305. - * Context: User context only. This function may sleep.
  2306. + * Context: User context only. This function may sleep if pagefaults are
  2307. + * enabled.
  2308. *
  2309. * Copy data from kernel space to user space. Caller must check
  2310. * the specified block with access_ok() before calling this function.
  2311. @@ -264,7 +266,8 @@
  2312. * @from: Source address, in kernel space.
  2313. * @n: Number of bytes to copy.
  2314. *
  2315. - * Context: User context only. This function may sleep.
  2316. + * Context: User context only. This function may sleep if pagefaults are
  2317. + * enabled.
  2318. *
  2319. * Copy data from kernel space to user space.
  2320. *
  2321. @@ -290,7 +293,8 @@
  2322. * @from: Source address, in user space.
  2323. * @n: Number of bytes to copy.
  2324. *
  2325. - * Context: User context only. This function may sleep.
  2326. + * Context: User context only. This function may sleep if pagefaults are
  2327. + * enabled.
  2328. *
  2329. * Copy data from user space to kernel space.
  2330. *
  2331. @@ -348,7 +352,8 @@
  2332. * strlen_user: - Get the size of a string in user space.
  2333. * @str: The string to measure.
  2334. *
  2335. - * Context: User context only. This function may sleep.
  2336. + * Context: User context only. This function may sleep if pagefaults are
  2337. + * enabled.
  2338. *
  2339. * Get the size of a NUL-terminated string in user space.
  2340. *
  2341. diff -Nur linux-4.1.26.orig/arch/s390/kvm/interrupt.c linux-4.1.26/arch/s390/kvm/interrupt.c
  2342. --- linux-4.1.26.orig/arch/s390/kvm/interrupt.c 2016-06-07 01:13:11.000000000 +0200
  2343. +++ linux-4.1.26/arch/s390/kvm/interrupt.c 2016-06-19 15:30:58.607294264 +0200
  2344. @@ -875,13 +875,13 @@
  2345. void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
  2346. {
  2347. - if (waitqueue_active(&vcpu->wq)) {
  2348. + if (swaitqueue_active(&vcpu->wq)) {
  2349. /*
  2350. * The vcpu gave up the cpu voluntarily, mark it as a good
  2351. * yield-candidate.
  2352. */
  2353. vcpu->preempted = true;
  2354. - wake_up_interruptible(&vcpu->wq);
  2355. + swait_wake_interruptible(&vcpu->wq);
  2356. vcpu->stat.halt_wakeup++;
  2357. }
  2358. }
  2359. @@ -987,7 +987,7 @@
  2360. spin_lock(&li->lock);
  2361. irq.u.pgm.code = code;
  2362. __inject_prog(vcpu, &irq);
  2363. - BUG_ON(waitqueue_active(li->wq));
  2364. + BUG_ON(swaitqueue_active(li->wq));
  2365. spin_unlock(&li->lock);
  2366. return 0;
  2367. }
  2368. @@ -1006,7 +1006,7 @@
  2369. spin_lock(&li->lock);
  2370. irq.u.pgm = *pgm_info;
  2371. rc = __inject_prog(vcpu, &irq);
  2372. - BUG_ON(waitqueue_active(li->wq));
  2373. + BUG_ON(swaitqueue_active(li->wq));
  2374. spin_unlock(&li->lock);
  2375. return rc;
  2376. }
  2377. diff -Nur linux-4.1.26.orig/arch/s390/mm/fault.c linux-4.1.26/arch/s390/mm/fault.c
  2378. --- linux-4.1.26.orig/arch/s390/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2379. +++ linux-4.1.26/arch/s390/mm/fault.c 2016-06-19 15:30:58.607294264 +0200
  2380. @@ -399,7 +399,7 @@
  2381. * user context.
  2382. */
  2383. fault = VM_FAULT_BADCONTEXT;
  2384. - if (unlikely(!user_space_fault(regs) || in_atomic() || !mm))
  2385. + if (unlikely(!user_space_fault(regs) || faulthandler_disabled() || !mm))
  2386. goto out;
  2387. address = trans_exc_code & __FAIL_ADDR_MASK;
  2388. diff -Nur linux-4.1.26.orig/arch/score/include/asm/uaccess.h linux-4.1.26/arch/score/include/asm/uaccess.h
  2389. --- linux-4.1.26.orig/arch/score/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  2390. +++ linux-4.1.26/arch/score/include/asm/uaccess.h 2016-06-19 15:30:58.607294264 +0200
  2391. @@ -36,7 +36,8 @@
  2392. * @addr: User space pointer to start of block to check
  2393. * @size: Size of block to check
  2394. *
  2395. - * Context: User context only. This function may sleep.
  2396. + * Context: User context only. This function may sleep if pagefaults are
  2397. + * enabled.
  2398. *
  2399. * Checks if a pointer to a block of memory in user space is valid.
  2400. *
  2401. @@ -61,7 +62,8 @@
  2402. * @x: Value to copy to user space.
  2403. * @ptr: Destination address, in user space.
  2404. *
  2405. - * Context: User context only. This function may sleep.
  2406. + * Context: User context only. This function may sleep if pagefaults are
  2407. + * enabled.
  2408. *
  2409. * This macro copies a single simple value from kernel space to user
  2410. * space. It supports simple types like char and int, but not larger
  2411. @@ -79,7 +81,8 @@
  2412. * @x: Variable to store result.
  2413. * @ptr: Source address, in user space.
  2414. *
  2415. - * Context: User context only. This function may sleep.
  2416. + * Context: User context only. This function may sleep if pagefaults are
  2417. + * enabled.
  2418. *
  2419. * This macro copies a single simple variable from user space to kernel
  2420. * space. It supports simple types like char and int, but not larger
  2421. @@ -98,7 +101,8 @@
  2422. * @x: Value to copy to user space.
  2423. * @ptr: Destination address, in user space.
  2424. *
  2425. - * Context: User context only. This function may sleep.
  2426. + * Context: User context only. This function may sleep if pagefaults are
  2427. + * enabled.
  2428. *
  2429. * This macro copies a single simple value from kernel space to user
  2430. * space. It supports simple types like char and int, but not larger
  2431. @@ -119,7 +123,8 @@
  2432. * @x: Variable to store result.
  2433. * @ptr: Source address, in user space.
  2434. *
  2435. - * Context: User context only. This function may sleep.
  2436. + * Context: User context only. This function may sleep if pagefaults are
  2437. + * enabled.
  2438. *
  2439. * This macro copies a single simple variable from user space to kernel
  2440. * space. It supports simple types like char and int, but not larger
  2441. diff -Nur linux-4.1.26.orig/arch/score/mm/fault.c linux-4.1.26/arch/score/mm/fault.c
  2442. --- linux-4.1.26.orig/arch/score/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2443. +++ linux-4.1.26/arch/score/mm/fault.c 2016-06-19 15:30:58.607294264 +0200
  2444. @@ -34,6 +34,7 @@
  2445. #include <linux/string.h>
  2446. #include <linux/types.h>
  2447. #include <linux/ptrace.h>
  2448. +#include <linux/uaccess.h>
  2449. /*
  2450. * This routine handles page faults. It determines the address,
  2451. @@ -73,7 +74,7 @@
  2452. * If we're in an interrupt or have no user
  2453. * context, we must not take the fault..
  2454. */
  2455. - if (in_atomic() || !mm)
  2456. + if (pagefault_disabled() || !mm)
  2457. goto bad_area_nosemaphore;
  2458. if (user_mode(regs))
  2459. diff -Nur linux-4.1.26.orig/arch/sh/kernel/irq.c linux-4.1.26/arch/sh/kernel/irq.c
  2460. --- linux-4.1.26.orig/arch/sh/kernel/irq.c 2016-06-07 01:13:11.000000000 +0200
  2461. +++ linux-4.1.26/arch/sh/kernel/irq.c 2016-06-19 15:30:58.607294264 +0200
  2462. @@ -147,6 +147,7 @@
  2463. hardirq_ctx[cpu] = NULL;
  2464. }
  2465. +#ifndef CONFIG_PREEMPT_RT_FULL
  2466. void do_softirq_own_stack(void)
  2467. {
  2468. struct thread_info *curctx;
  2469. @@ -174,6 +175,7 @@
  2470. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  2471. );
  2472. }
  2473. +#endif
  2474. #else
  2475. static inline void handle_one_irq(unsigned int irq)
  2476. {
  2477. diff -Nur linux-4.1.26.orig/arch/sh/mm/fault.c linux-4.1.26/arch/sh/mm/fault.c
  2478. --- linux-4.1.26.orig/arch/sh/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2479. +++ linux-4.1.26/arch/sh/mm/fault.c 2016-06-19 15:30:58.607294264 +0200
  2480. @@ -17,6 +17,7 @@
  2481. #include <linux/kprobes.h>
  2482. #include <linux/perf_event.h>
  2483. #include <linux/kdebug.h>
  2484. +#include <linux/uaccess.h>
  2485. #include <asm/io_trapped.h>
  2486. #include <asm/mmu_context.h>
  2487. #include <asm/tlbflush.h>
  2488. @@ -438,9 +439,9 @@
  2489. /*
  2490. * If we're in an interrupt, have no user context or are running
  2491. - * in an atomic region then we must not take the fault:
  2492. + * with pagefaults disabled then we must not take the fault:
  2493. */
  2494. - if (unlikely(in_atomic() || !mm)) {
  2495. + if (unlikely(faulthandler_disabled() || !mm)) {
  2496. bad_area_nosemaphore(regs, error_code, address);
  2497. return;
  2498. }
  2499. diff -Nur linux-4.1.26.orig/arch/sparc/Kconfig linux-4.1.26/arch/sparc/Kconfig
  2500. --- linux-4.1.26.orig/arch/sparc/Kconfig 2016-06-07 01:13:11.000000000 +0200
  2501. +++ linux-4.1.26/arch/sparc/Kconfig 2016-06-19 15:30:58.607294264 +0200
  2502. @@ -189,12 +189,10 @@
  2503. source kernel/Kconfig.hz
  2504. config RWSEM_GENERIC_SPINLOCK
  2505. - bool
  2506. - default y if SPARC32
  2507. + def_bool PREEMPT_RT_FULL
  2508. config RWSEM_XCHGADD_ALGORITHM
  2509. - bool
  2510. - default y if SPARC64
  2511. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  2512. config GENERIC_HWEIGHT
  2513. bool
  2514. diff -Nur linux-4.1.26.orig/arch/sparc/kernel/irq_64.c linux-4.1.26/arch/sparc/kernel/irq_64.c
  2515. --- linux-4.1.26.orig/arch/sparc/kernel/irq_64.c 2016-06-07 01:13:11.000000000 +0200
  2516. +++ linux-4.1.26/arch/sparc/kernel/irq_64.c 2016-06-19 15:30:58.607294264 +0200
  2517. @@ -849,6 +849,7 @@
  2518. set_irq_regs(old_regs);
  2519. }
  2520. +#ifndef CONFIG_PREEMPT_RT_FULL
  2521. void do_softirq_own_stack(void)
  2522. {
  2523. void *orig_sp, *sp = softirq_stack[smp_processor_id()];
  2524. @@ -863,6 +864,7 @@
  2525. __asm__ __volatile__("mov %0, %%sp"
  2526. : : "r" (orig_sp));
  2527. }
  2528. +#endif
  2529. #ifdef CONFIG_HOTPLUG_CPU
  2530. void fixup_irqs(void)
  2531. diff -Nur linux-4.1.26.orig/arch/sparc/mm/fault_32.c linux-4.1.26/arch/sparc/mm/fault_32.c
  2532. --- linux-4.1.26.orig/arch/sparc/mm/fault_32.c 2016-06-07 01:13:11.000000000 +0200
  2533. +++ linux-4.1.26/arch/sparc/mm/fault_32.c 2016-06-19 15:30:58.607294264 +0200
  2534. @@ -21,6 +21,7 @@
  2535. #include <linux/perf_event.h>
  2536. #include <linux/interrupt.h>
  2537. #include <linux/kdebug.h>
  2538. +#include <linux/uaccess.h>
  2539. #include <asm/page.h>
  2540. #include <asm/pgtable.h>
  2541. @@ -29,7 +30,6 @@
  2542. #include <asm/setup.h>
  2543. #include <asm/smp.h>
  2544. #include <asm/traps.h>
  2545. -#include <asm/uaccess.h>
  2546. #include "mm_32.h"
  2547. @@ -196,7 +196,7 @@
  2548. * If we're in an interrupt or have no user
  2549. * context, we must not take the fault..
  2550. */
  2551. - if (in_atomic() || !mm)
  2552. + if (pagefault_disabled() || !mm)
  2553. goto no_context;
  2554. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  2555. diff -Nur linux-4.1.26.orig/arch/sparc/mm/fault_64.c linux-4.1.26/arch/sparc/mm/fault_64.c
  2556. --- linux-4.1.26.orig/arch/sparc/mm/fault_64.c 2016-06-07 01:13:11.000000000 +0200
  2557. +++ linux-4.1.26/arch/sparc/mm/fault_64.c 2016-06-19 15:30:58.607294264 +0200
  2558. @@ -22,12 +22,12 @@
  2559. #include <linux/kdebug.h>
  2560. #include <linux/percpu.h>
  2561. #include <linux/context_tracking.h>
  2562. +#include <linux/uaccess.h>
  2563. #include <asm/page.h>
  2564. #include <asm/pgtable.h>
  2565. #include <asm/openprom.h>
  2566. #include <asm/oplib.h>
  2567. -#include <asm/uaccess.h>
  2568. #include <asm/asi.h>
  2569. #include <asm/lsu.h>
  2570. #include <asm/sections.h>
  2571. @@ -330,7 +330,7 @@
  2572. * If we're in an interrupt or have no user
  2573. * context, we must not take the fault..
  2574. */
  2575. - if (in_atomic() || !mm)
  2576. + if (faulthandler_disabled() || !mm)
  2577. goto intr_or_no_mm;
  2578. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  2579. diff -Nur linux-4.1.26.orig/arch/sparc/mm/highmem.c linux-4.1.26/arch/sparc/mm/highmem.c
  2580. --- linux-4.1.26.orig/arch/sparc/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  2581. +++ linux-4.1.26/arch/sparc/mm/highmem.c 2016-06-19 15:30:58.607294264 +0200
  2582. @@ -53,7 +53,7 @@
  2583. unsigned long vaddr;
  2584. long idx, type;
  2585. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2586. + preempt_disable();
  2587. pagefault_disable();
  2588. if (!PageHighMem(page))
  2589. return page_address(page);
  2590. @@ -91,6 +91,7 @@
  2591. if (vaddr < FIXADDR_START) { // FIXME
  2592. pagefault_enable();
  2593. + preempt_enable();
  2594. return;
  2595. }
  2596. @@ -126,5 +127,6 @@
  2597. kmap_atomic_idx_pop();
  2598. pagefault_enable();
  2599. + preempt_enable();
  2600. }
  2601. EXPORT_SYMBOL(__kunmap_atomic);
  2602. diff -Nur linux-4.1.26.orig/arch/sparc/mm/init_64.c linux-4.1.26/arch/sparc/mm/init_64.c
  2603. --- linux-4.1.26.orig/arch/sparc/mm/init_64.c 2016-06-07 01:13:11.000000000 +0200
  2604. +++ linux-4.1.26/arch/sparc/mm/init_64.c 2016-06-19 15:30:58.607294264 +0200
  2605. @@ -2738,7 +2738,7 @@
  2606. struct mm_struct *mm = current->mm;
  2607. struct tsb_config *tp;
  2608. - if (in_atomic() || !mm) {
  2609. + if (faulthandler_disabled() || !mm) {
  2610. const struct exception_table_entry *entry;
  2611. entry = search_exception_tables(regs->tpc);
  2612. diff -Nur linux-4.1.26.orig/arch/tile/include/asm/uaccess.h linux-4.1.26/arch/tile/include/asm/uaccess.h
  2613. --- linux-4.1.26.orig/arch/tile/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  2614. +++ linux-4.1.26/arch/tile/include/asm/uaccess.h 2016-06-19 15:30:58.611294419 +0200
  2615. @@ -78,7 +78,8 @@
  2616. * @addr: User space pointer to start of block to check
  2617. * @size: Size of block to check
  2618. *
  2619. - * Context: User context only. This function may sleep.
  2620. + * Context: User context only. This function may sleep if pagefaults are
  2621. + * enabled.
  2622. *
  2623. * Checks if a pointer to a block of memory in user space is valid.
  2624. *
  2625. @@ -192,7 +193,8 @@
  2626. * @x: Variable to store result.
  2627. * @ptr: Source address, in user space.
  2628. *
  2629. - * Context: User context only. This function may sleep.
  2630. + * Context: User context only. This function may sleep if pagefaults are
  2631. + * enabled.
  2632. *
  2633. * This macro copies a single simple variable from user space to kernel
  2634. * space. It supports simple types like char and int, but not larger
  2635. @@ -274,7 +276,8 @@
  2636. * @x: Value to copy to user space.
  2637. * @ptr: Destination address, in user space.
  2638. *
  2639. - * Context: User context only. This function may sleep.
  2640. + * Context: User context only. This function may sleep if pagefaults are
  2641. + * enabled.
  2642. *
  2643. * This macro copies a single simple value from kernel space to user
  2644. * space. It supports simple types like char and int, but not larger
  2645. @@ -330,7 +333,8 @@
  2646. * @from: Source address, in kernel space.
  2647. * @n: Number of bytes to copy.
  2648. *
  2649. - * Context: User context only. This function may sleep.
  2650. + * Context: User context only. This function may sleep if pagefaults are
  2651. + * enabled.
  2652. *
  2653. * Copy data from kernel space to user space. Caller must check
  2654. * the specified block with access_ok() before calling this function.
  2655. @@ -366,7 +370,8 @@
  2656. * @from: Source address, in user space.
  2657. * @n: Number of bytes to copy.
  2658. *
  2659. - * Context: User context only. This function may sleep.
  2660. + * Context: User context only. This function may sleep if pagefaults are
  2661. + * enabled.
  2662. *
  2663. * Copy data from user space to kernel space. Caller must check
  2664. * the specified block with access_ok() before calling this function.
  2665. @@ -437,7 +442,8 @@
  2666. * @from: Source address, in user space.
  2667. * @n: Number of bytes to copy.
  2668. *
  2669. - * Context: User context only. This function may sleep.
  2670. + * Context: User context only. This function may sleep if pagefaults are
  2671. + * enabled.
  2672. *
  2673. * Copy data from user space to user space. Caller must check
  2674. * the specified blocks with access_ok() before calling this function.
  2675. diff -Nur linux-4.1.26.orig/arch/tile/mm/fault.c linux-4.1.26/arch/tile/mm/fault.c
  2676. --- linux-4.1.26.orig/arch/tile/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2677. +++ linux-4.1.26/arch/tile/mm/fault.c 2016-06-19 15:30:58.611294419 +0200
  2678. @@ -354,9 +354,9 @@
  2679. /*
  2680. * If we're in an interrupt, have no user context or are running in an
  2681. - * atomic region then we must not take the fault.
  2682. + * region with pagefaults disabled then we must not take the fault.
  2683. */
  2684. - if (in_atomic() || !mm) {
  2685. + if (pagefault_disabled() || !mm) {
  2686. vma = NULL; /* happy compiler */
  2687. goto bad_area_nosemaphore;
  2688. }
  2689. diff -Nur linux-4.1.26.orig/arch/tile/mm/highmem.c linux-4.1.26/arch/tile/mm/highmem.c
  2690. --- linux-4.1.26.orig/arch/tile/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  2691. +++ linux-4.1.26/arch/tile/mm/highmem.c 2016-06-19 15:30:58.611294419 +0200
  2692. @@ -201,7 +201,7 @@
  2693. int idx, type;
  2694. pte_t *pte;
  2695. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2696. + preempt_disable();
  2697. pagefault_disable();
  2698. /* Avoid icache flushes by disallowing atomic executable mappings. */
  2699. @@ -259,6 +259,7 @@
  2700. }
  2701. pagefault_enable();
  2702. + preempt_enable();
  2703. }
  2704. EXPORT_SYMBOL(__kunmap_atomic);
  2705. diff -Nur linux-4.1.26.orig/arch/um/kernel/trap.c linux-4.1.26/arch/um/kernel/trap.c
  2706. --- linux-4.1.26.orig/arch/um/kernel/trap.c 2016-06-07 01:13:11.000000000 +0200
  2707. +++ linux-4.1.26/arch/um/kernel/trap.c 2016-06-19 15:30:58.611294419 +0200
  2708. @@ -35,10 +35,10 @@
  2709. *code_out = SEGV_MAPERR;
  2710. /*
  2711. - * If the fault was during atomic operation, don't take the fault, just
  2712. + * If the fault was with pagefaults disabled, don't take the fault, just
  2713. * fail.
  2714. */
  2715. - if (in_atomic())
  2716. + if (faulthandler_disabled())
  2717. goto out_nosemaphore;
  2718. if (is_user)
  2719. diff -Nur linux-4.1.26.orig/arch/unicore32/mm/fault.c linux-4.1.26/arch/unicore32/mm/fault.c
  2720. --- linux-4.1.26.orig/arch/unicore32/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  2721. +++ linux-4.1.26/arch/unicore32/mm/fault.c 2016-06-19 15:30:58.611294419 +0200
  2722. @@ -218,7 +218,7 @@
  2723. * If we're in an interrupt or have no user
  2724. * context, we must not take the fault..
  2725. */
  2726. - if (in_atomic() || !mm)
  2727. + if (faulthandler_disabled() || !mm)
  2728. goto no_context;
  2729. if (user_mode(regs))
  2730. diff -Nur linux-4.1.26.orig/arch/x86/crypto/aesni-intel_glue.c linux-4.1.26/arch/x86/crypto/aesni-intel_glue.c
  2731. --- linux-4.1.26.orig/arch/x86/crypto/aesni-intel_glue.c 2016-06-07 01:13:11.000000000 +0200
  2732. +++ linux-4.1.26/arch/x86/crypto/aesni-intel_glue.c 2016-06-19 15:30:58.611294419 +0200
  2733. @@ -382,14 +382,14 @@
  2734. err = blkcipher_walk_virt(desc, &walk);
  2735. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2736. - kernel_fpu_begin();
  2737. while ((nbytes = walk.nbytes)) {
  2738. + kernel_fpu_begin();
  2739. aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2740. - nbytes & AES_BLOCK_MASK);
  2741. + nbytes & AES_BLOCK_MASK);
  2742. + kernel_fpu_end();
  2743. nbytes &= AES_BLOCK_SIZE - 1;
  2744. err = blkcipher_walk_done(desc, &walk, nbytes);
  2745. }
  2746. - kernel_fpu_end();
  2747. return err;
  2748. }
  2749. @@ -406,14 +406,14 @@
  2750. err = blkcipher_walk_virt(desc, &walk);
  2751. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2752. - kernel_fpu_begin();
  2753. while ((nbytes = walk.nbytes)) {
  2754. + kernel_fpu_begin();
  2755. aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2756. nbytes & AES_BLOCK_MASK);
  2757. + kernel_fpu_end();
  2758. nbytes &= AES_BLOCK_SIZE - 1;
  2759. err = blkcipher_walk_done(desc, &walk, nbytes);
  2760. }
  2761. - kernel_fpu_end();
  2762. return err;
  2763. }
  2764. @@ -430,14 +430,14 @@
  2765. err = blkcipher_walk_virt(desc, &walk);
  2766. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2767. - kernel_fpu_begin();
  2768. while ((nbytes = walk.nbytes)) {
  2769. + kernel_fpu_begin();
  2770. aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2771. nbytes & AES_BLOCK_MASK, walk.iv);
  2772. + kernel_fpu_end();
  2773. nbytes &= AES_BLOCK_SIZE - 1;
  2774. err = blkcipher_walk_done(desc, &walk, nbytes);
  2775. }
  2776. - kernel_fpu_end();
  2777. return err;
  2778. }
  2779. @@ -454,14 +454,14 @@
  2780. err = blkcipher_walk_virt(desc, &walk);
  2781. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2782. - kernel_fpu_begin();
  2783. while ((nbytes = walk.nbytes)) {
  2784. + kernel_fpu_begin();
  2785. aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2786. nbytes & AES_BLOCK_MASK, walk.iv);
  2787. + kernel_fpu_end();
  2788. nbytes &= AES_BLOCK_SIZE - 1;
  2789. err = blkcipher_walk_done(desc, &walk, nbytes);
  2790. }
  2791. - kernel_fpu_end();
  2792. return err;
  2793. }
  2794. @@ -513,18 +513,20 @@
  2795. err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
  2796. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2797. - kernel_fpu_begin();
  2798. while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
  2799. + kernel_fpu_begin();
  2800. aesni_ctr_enc_tfm(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2801. nbytes & AES_BLOCK_MASK, walk.iv);
  2802. + kernel_fpu_end();
  2803. nbytes &= AES_BLOCK_SIZE - 1;
  2804. err = blkcipher_walk_done(desc, &walk, nbytes);
  2805. }
  2806. if (walk.nbytes) {
  2807. + kernel_fpu_begin();
  2808. ctr_crypt_final(ctx, &walk);
  2809. + kernel_fpu_end();
  2810. err = blkcipher_walk_done(desc, &walk, 0);
  2811. }
  2812. - kernel_fpu_end();
  2813. return err;
  2814. }
  2815. diff -Nur linux-4.1.26.orig/arch/x86/crypto/cast5_avx_glue.c linux-4.1.26/arch/x86/crypto/cast5_avx_glue.c
  2816. --- linux-4.1.26.orig/arch/x86/crypto/cast5_avx_glue.c 2016-06-07 01:13:11.000000000 +0200
  2817. +++ linux-4.1.26/arch/x86/crypto/cast5_avx_glue.c 2016-06-19 15:30:58.611294419 +0200
  2818. @@ -60,7 +60,7 @@
  2819. static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
  2820. bool enc)
  2821. {
  2822. - bool fpu_enabled = false;
  2823. + bool fpu_enabled;
  2824. struct cast5_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  2825. const unsigned int bsize = CAST5_BLOCK_SIZE;
  2826. unsigned int nbytes;
  2827. @@ -76,7 +76,7 @@
  2828. u8 *wsrc = walk->src.virt.addr;
  2829. u8 *wdst = walk->dst.virt.addr;
  2830. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2831. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2832. /* Process multi-block batch */
  2833. if (nbytes >= bsize * CAST5_PARALLEL_BLOCKS) {
  2834. @@ -104,10 +104,9 @@
  2835. } while (nbytes >= bsize);
  2836. done:
  2837. + cast5_fpu_end(fpu_enabled);
  2838. err = blkcipher_walk_done(desc, walk, nbytes);
  2839. }
  2840. -
  2841. - cast5_fpu_end(fpu_enabled);
  2842. return err;
  2843. }
  2844. @@ -228,7 +227,7 @@
  2845. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  2846. struct scatterlist *src, unsigned int nbytes)
  2847. {
  2848. - bool fpu_enabled = false;
  2849. + bool fpu_enabled;
  2850. struct blkcipher_walk walk;
  2851. int err;
  2852. @@ -237,12 +236,11 @@
  2853. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2854. while ((nbytes = walk.nbytes)) {
  2855. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2856. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2857. nbytes = __cbc_decrypt(desc, &walk);
  2858. + cast5_fpu_end(fpu_enabled);
  2859. err = blkcipher_walk_done(desc, &walk, nbytes);
  2860. }
  2861. -
  2862. - cast5_fpu_end(fpu_enabled);
  2863. return err;
  2864. }
  2865. @@ -312,7 +310,7 @@
  2866. static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  2867. struct scatterlist *src, unsigned int nbytes)
  2868. {
  2869. - bool fpu_enabled = false;
  2870. + bool fpu_enabled;
  2871. struct blkcipher_walk walk;
  2872. int err;
  2873. @@ -321,13 +319,12 @@
  2874. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2875. while ((nbytes = walk.nbytes) >= CAST5_BLOCK_SIZE) {
  2876. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2877. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2878. nbytes = __ctr_crypt(desc, &walk);
  2879. + cast5_fpu_end(fpu_enabled);
  2880. err = blkcipher_walk_done(desc, &walk, nbytes);
  2881. }
  2882. - cast5_fpu_end(fpu_enabled);
  2883. -
  2884. if (walk.nbytes) {
  2885. ctr_crypt_final(desc, &walk);
  2886. err = blkcipher_walk_done(desc, &walk, 0);
  2887. diff -Nur linux-4.1.26.orig/arch/x86/crypto/glue_helper.c linux-4.1.26/arch/x86/crypto/glue_helper.c
  2888. --- linux-4.1.26.orig/arch/x86/crypto/glue_helper.c 2016-06-07 01:13:11.000000000 +0200
  2889. +++ linux-4.1.26/arch/x86/crypto/glue_helper.c 2016-06-19 15:30:58.611294419 +0200
  2890. @@ -39,7 +39,7 @@
  2891. void *ctx = crypto_blkcipher_ctx(desc->tfm);
  2892. const unsigned int bsize = 128 / 8;
  2893. unsigned int nbytes, i, func_bytes;
  2894. - bool fpu_enabled = false;
  2895. + bool fpu_enabled;
  2896. int err;
  2897. err = blkcipher_walk_virt(desc, walk);
  2898. @@ -49,7 +49,7 @@
  2899. u8 *wdst = walk->dst.virt.addr;
  2900. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2901. - desc, fpu_enabled, nbytes);
  2902. + desc, false, nbytes);
  2903. for (i = 0; i < gctx->num_funcs; i++) {
  2904. func_bytes = bsize * gctx->funcs[i].num_blocks;
  2905. @@ -71,10 +71,10 @@
  2906. }
  2907. done:
  2908. + glue_fpu_end(fpu_enabled);
  2909. err = blkcipher_walk_done(desc, walk, nbytes);
  2910. }
  2911. - glue_fpu_end(fpu_enabled);
  2912. return err;
  2913. }
  2914. @@ -194,7 +194,7 @@
  2915. struct scatterlist *src, unsigned int nbytes)
  2916. {
  2917. const unsigned int bsize = 128 / 8;
  2918. - bool fpu_enabled = false;
  2919. + bool fpu_enabled;
  2920. struct blkcipher_walk walk;
  2921. int err;
  2922. @@ -203,12 +203,12 @@
  2923. while ((nbytes = walk.nbytes)) {
  2924. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2925. - desc, fpu_enabled, nbytes);
  2926. + desc, false, nbytes);
  2927. nbytes = __glue_cbc_decrypt_128bit(gctx, desc, &walk);
  2928. + glue_fpu_end(fpu_enabled);
  2929. err = blkcipher_walk_done(desc, &walk, nbytes);
  2930. }
  2931. - glue_fpu_end(fpu_enabled);
  2932. return err;
  2933. }
  2934. EXPORT_SYMBOL_GPL(glue_cbc_decrypt_128bit);
  2935. @@ -277,7 +277,7 @@
  2936. struct scatterlist *src, unsigned int nbytes)
  2937. {
  2938. const unsigned int bsize = 128 / 8;
  2939. - bool fpu_enabled = false;
  2940. + bool fpu_enabled;
  2941. struct blkcipher_walk walk;
  2942. int err;
  2943. @@ -286,13 +286,12 @@
  2944. while ((nbytes = walk.nbytes) >= bsize) {
  2945. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2946. - desc, fpu_enabled, nbytes);
  2947. + desc, false, nbytes);
  2948. nbytes = __glue_ctr_crypt_128bit(gctx, desc, &walk);
  2949. + glue_fpu_end(fpu_enabled);
  2950. err = blkcipher_walk_done(desc, &walk, nbytes);
  2951. }
  2952. - glue_fpu_end(fpu_enabled);
  2953. -
  2954. if (walk.nbytes) {
  2955. glue_ctr_crypt_final_128bit(
  2956. gctx->funcs[gctx->num_funcs - 1].fn_u.ctr, desc, &walk);
  2957. @@ -347,7 +346,7 @@
  2958. void *tweak_ctx, void *crypt_ctx)
  2959. {
  2960. const unsigned int bsize = 128 / 8;
  2961. - bool fpu_enabled = false;
  2962. + bool fpu_enabled;
  2963. struct blkcipher_walk walk;
  2964. int err;
  2965. @@ -360,21 +359,21 @@
  2966. /* set minimum length to bsize, for tweak_fn */
  2967. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2968. - desc, fpu_enabled,
  2969. + desc, false,
  2970. nbytes < bsize ? bsize : nbytes);
  2971. -
  2972. /* calculate first value of T */
  2973. tweak_fn(tweak_ctx, walk.iv, walk.iv);
  2974. + glue_fpu_end(fpu_enabled);
  2975. while (nbytes) {
  2976. + fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2977. + desc, false, nbytes);
  2978. nbytes = __glue_xts_crypt_128bit(gctx, crypt_ctx, desc, &walk);
  2979. + glue_fpu_end(fpu_enabled);
  2980. err = blkcipher_walk_done(desc, &walk, nbytes);
  2981. nbytes = walk.nbytes;
  2982. }
  2983. -
  2984. - glue_fpu_end(fpu_enabled);
  2985. -
  2986. return err;
  2987. }
  2988. EXPORT_SYMBOL_GPL(glue_xts_crypt_128bit);
  2989. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/preempt.h linux-4.1.26/arch/x86/include/asm/preempt.h
  2990. --- linux-4.1.26.orig/arch/x86/include/asm/preempt.h 2016-06-07 01:13:11.000000000 +0200
  2991. +++ linux-4.1.26/arch/x86/include/asm/preempt.h 2016-06-19 15:30:58.611294419 +0200
  2992. @@ -82,17 +82,33 @@
  2993. * a decrement which hits zero means we have no preempt_count and should
  2994. * reschedule.
  2995. */
  2996. -static __always_inline bool __preempt_count_dec_and_test(void)
  2997. +static __always_inline bool ____preempt_count_dec_and_test(void)
  2998. {
  2999. GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
  3000. }
  3001. +static __always_inline bool __preempt_count_dec_and_test(void)
  3002. +{
  3003. + if (____preempt_count_dec_and_test())
  3004. + return true;
  3005. +#ifdef CONFIG_PREEMPT_LAZY
  3006. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  3007. +#else
  3008. + return false;
  3009. +#endif
  3010. +}
  3011. +
  3012. /*
  3013. * Returns true when we need to resched and can (barring IRQ state).
  3014. */
  3015. static __always_inline bool should_resched(int preempt_offset)
  3016. {
  3017. +#ifdef CONFIG_PREEMPT_LAZY
  3018. + return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset ||
  3019. + test_thread_flag(TIF_NEED_RESCHED_LAZY));
  3020. +#else
  3021. return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
  3022. +#endif
  3023. }
  3024. #ifdef CONFIG_PREEMPT
  3025. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/signal.h linux-4.1.26/arch/x86/include/asm/signal.h
  3026. --- linux-4.1.26.orig/arch/x86/include/asm/signal.h 2016-06-07 01:13:11.000000000 +0200
  3027. +++ linux-4.1.26/arch/x86/include/asm/signal.h 2016-06-19 15:30:58.611294419 +0200
  3028. @@ -23,6 +23,19 @@
  3029. unsigned long sig[_NSIG_WORDS];
  3030. } sigset_t;
  3031. +/*
  3032. + * Because some traps use the IST stack, we must keep preemption
  3033. + * disabled while calling do_trap(), but do_trap() may call
  3034. + * force_sig_info() which will grab the signal spin_locks for the
  3035. + * task, which in PREEMPT_RT_FULL are mutexes. By defining
  3036. + * ARCH_RT_DELAYS_SIGNAL_SEND the force_sig_info() will set
  3037. + * TIF_NOTIFY_RESUME and set up the signal to be sent on exit of the
  3038. + * trap.
  3039. + */
  3040. +#if defined(CONFIG_PREEMPT_RT_FULL)
  3041. +#define ARCH_RT_DELAYS_SIGNAL_SEND
  3042. +#endif
  3043. +
  3044. #ifndef CONFIG_COMPAT
  3045. typedef sigset_t compat_sigset_t;
  3046. #endif
  3047. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/stackprotector.h linux-4.1.26/arch/x86/include/asm/stackprotector.h
  3048. --- linux-4.1.26.orig/arch/x86/include/asm/stackprotector.h 2016-06-07 01:13:11.000000000 +0200
  3049. +++ linux-4.1.26/arch/x86/include/asm/stackprotector.h 2016-06-19 15:30:58.611294419 +0200
  3050. @@ -57,7 +57,7 @@
  3051. */
  3052. static __always_inline void boot_init_stack_canary(void)
  3053. {
  3054. - u64 canary;
  3055. + u64 uninitialized_var(canary);
  3056. u64 tsc;
  3057. #ifdef CONFIG_X86_64
  3058. @@ -68,8 +68,16 @@
  3059. * of randomness. The TSC only matters for very early init,
  3060. * there it already has some randomness on most systems. Later
  3061. * on during the bootup the random pool has true entropy too.
  3062. + *
  3063. + * For preempt-rt we need to weaken the randomness a bit, as
  3064. + * we can't call into the random generator from atomic context
  3065. + * due to locking constraints. We just leave canary
  3066. + * uninitialized and use the TSC based randomness on top of
  3067. + * it.
  3068. */
  3069. +#ifndef CONFIG_PREEMPT_RT_FULL
  3070. get_random_bytes(&canary, sizeof(canary));
  3071. +#endif
  3072. tsc = __native_read_tsc();
  3073. canary += tsc + (tsc << 32UL);
  3074. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/thread_info.h linux-4.1.26/arch/x86/include/asm/thread_info.h
  3075. --- linux-4.1.26.orig/arch/x86/include/asm/thread_info.h 2016-06-07 01:13:11.000000000 +0200
  3076. +++ linux-4.1.26/arch/x86/include/asm/thread_info.h 2016-06-19 15:30:58.611294419 +0200
  3077. @@ -55,6 +55,8 @@
  3078. __u32 status; /* thread synchronous flags */
  3079. __u32 cpu; /* current CPU */
  3080. int saved_preempt_count;
  3081. + int preempt_lazy_count; /* 0 => lazy preemptable
  3082. + <0 => BUG */
  3083. mm_segment_t addr_limit;
  3084. void __user *sysenter_return;
  3085. unsigned int sig_on_uaccess_error:1;
  3086. @@ -95,6 +97,7 @@
  3087. #define TIF_SYSCALL_EMU 6 /* syscall emulation active */
  3088. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  3089. #define TIF_SECCOMP 8 /* secure computing */
  3090. +#define TIF_NEED_RESCHED_LAZY 9 /* lazy rescheduling necessary */
  3091. #define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */
  3092. #define TIF_UPROBE 12 /* breakpointed or singlestepping */
  3093. #define TIF_NOTSC 16 /* TSC is not accessible in userland */
  3094. @@ -119,6 +122,7 @@
  3095. #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
  3096. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  3097. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  3098. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  3099. #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY)
  3100. #define _TIF_UPROBE (1 << TIF_UPROBE)
  3101. #define _TIF_NOTSC (1 << TIF_NOTSC)
  3102. @@ -168,6 +172,8 @@
  3103. #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  3104. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  3105. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  3106. +
  3107. #define STACK_WARN (THREAD_SIZE/8)
  3108. /*
  3109. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/uaccess_32.h linux-4.1.26/arch/x86/include/asm/uaccess_32.h
  3110. --- linux-4.1.26.orig/arch/x86/include/asm/uaccess_32.h 2016-06-07 01:13:11.000000000 +0200
  3111. +++ linux-4.1.26/arch/x86/include/asm/uaccess_32.h 2016-06-19 15:30:58.615294573 +0200
  3112. @@ -70,7 +70,8 @@
  3113. * @from: Source address, in kernel space.
  3114. * @n: Number of bytes to copy.
  3115. *
  3116. - * Context: User context only. This function may sleep.
  3117. + * Context: User context only. This function may sleep if pagefaults are
  3118. + * enabled.
  3119. *
  3120. * Copy data from kernel space to user space. Caller must check
  3121. * the specified block with access_ok() before calling this function.
  3122. @@ -117,7 +118,8 @@
  3123. * @from: Source address, in user space.
  3124. * @n: Number of bytes to copy.
  3125. *
  3126. - * Context: User context only. This function may sleep.
  3127. + * Context: User context only. This function may sleep if pagefaults are
  3128. + * enabled.
  3129. *
  3130. * Copy data from user space to kernel space. Caller must check
  3131. * the specified block with access_ok() before calling this function.
  3132. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/uaccess.h linux-4.1.26/arch/x86/include/asm/uaccess.h
  3133. --- linux-4.1.26.orig/arch/x86/include/asm/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  3134. +++ linux-4.1.26/arch/x86/include/asm/uaccess.h 2016-06-19 15:30:58.611294419 +0200
  3135. @@ -74,7 +74,8 @@
  3136. * @addr: User space pointer to start of block to check
  3137. * @size: Size of block to check
  3138. *
  3139. - * Context: User context only. This function may sleep.
  3140. + * Context: User context only. This function may sleep if pagefaults are
  3141. + * enabled.
  3142. *
  3143. * Checks if a pointer to a block of memory in user space is valid.
  3144. *
  3145. @@ -145,7 +146,8 @@
  3146. * @x: Variable to store result.
  3147. * @ptr: Source address, in user space.
  3148. *
  3149. - * Context: User context only. This function may sleep.
  3150. + * Context: User context only. This function may sleep if pagefaults are
  3151. + * enabled.
  3152. *
  3153. * This macro copies a single simple variable from user space to kernel
  3154. * space. It supports simple types like char and int, but not larger
  3155. @@ -240,7 +242,8 @@
  3156. * @x: Value to copy to user space.
  3157. * @ptr: Destination address, in user space.
  3158. *
  3159. - * Context: User context only. This function may sleep.
  3160. + * Context: User context only. This function may sleep if pagefaults are
  3161. + * enabled.
  3162. *
  3163. * This macro copies a single simple value from kernel space to user
  3164. * space. It supports simple types like char and int, but not larger
  3165. @@ -455,7 +458,8 @@
  3166. * @x: Variable to store result.
  3167. * @ptr: Source address, in user space.
  3168. *
  3169. - * Context: User context only. This function may sleep.
  3170. + * Context: User context only. This function may sleep if pagefaults are
  3171. + * enabled.
  3172. *
  3173. * This macro copies a single simple variable from user space to kernel
  3174. * space. It supports simple types like char and int, but not larger
  3175. @@ -479,7 +483,8 @@
  3176. * @x: Value to copy to user space.
  3177. * @ptr: Destination address, in user space.
  3178. *
  3179. - * Context: User context only. This function may sleep.
  3180. + * Context: User context only. This function may sleep if pagefaults are
  3181. + * enabled.
  3182. *
  3183. * This macro copies a single simple value from kernel space to user
  3184. * space. It supports simple types like char and int, but not larger
  3185. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/uv/uv_bau.h linux-4.1.26/arch/x86/include/asm/uv/uv_bau.h
  3186. --- linux-4.1.26.orig/arch/x86/include/asm/uv/uv_bau.h 2016-06-07 01:13:11.000000000 +0200
  3187. +++ linux-4.1.26/arch/x86/include/asm/uv/uv_bau.h 2016-06-19 15:30:58.615294573 +0200
  3188. @@ -615,9 +615,9 @@
  3189. cycles_t send_message;
  3190. cycles_t period_end;
  3191. cycles_t period_time;
  3192. - spinlock_t uvhub_lock;
  3193. - spinlock_t queue_lock;
  3194. - spinlock_t disable_lock;
  3195. + raw_spinlock_t uvhub_lock;
  3196. + raw_spinlock_t queue_lock;
  3197. + raw_spinlock_t disable_lock;
  3198. /* tunables */
  3199. int max_concurr;
  3200. int max_concurr_const;
  3201. @@ -776,15 +776,15 @@
  3202. * to be lowered below the current 'v'. atomic_add_unless can only stop
  3203. * on equal.
  3204. */
  3205. -static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  3206. +static inline int atomic_inc_unless_ge(raw_spinlock_t *lock, atomic_t *v, int u)
  3207. {
  3208. - spin_lock(lock);
  3209. + raw_spin_lock(lock);
  3210. if (atomic_read(v) >= u) {
  3211. - spin_unlock(lock);
  3212. + raw_spin_unlock(lock);
  3213. return 0;
  3214. }
  3215. atomic_inc(v);
  3216. - spin_unlock(lock);
  3217. + raw_spin_unlock(lock);
  3218. return 1;
  3219. }
  3220. diff -Nur linux-4.1.26.orig/arch/x86/include/asm/uv/uv_hub.h linux-4.1.26/arch/x86/include/asm/uv/uv_hub.h
  3221. --- linux-4.1.26.orig/arch/x86/include/asm/uv/uv_hub.h 2016-06-07 01:13:11.000000000 +0200
  3222. +++ linux-4.1.26/arch/x86/include/asm/uv/uv_hub.h 2016-06-19 15:30:58.615294573 +0200
  3223. @@ -492,7 +492,7 @@
  3224. unsigned short nr_online_cpus;
  3225. unsigned short pnode;
  3226. short memory_nid;
  3227. - spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  3228. + raw_spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  3229. unsigned long nmi_count; /* obsolete, see uv_hub_nmi */
  3230. };
  3231. extern struct uv_blade_info *uv_blade_info;
  3232. diff -Nur linux-4.1.26.orig/arch/x86/Kconfig linux-4.1.26/arch/x86/Kconfig
  3233. --- linux-4.1.26.orig/arch/x86/Kconfig 2016-06-07 01:13:11.000000000 +0200
  3234. +++ linux-4.1.26/arch/x86/Kconfig 2016-06-19 15:30:58.611294419 +0200
  3235. @@ -22,6 +22,7 @@
  3236. ### Arch settings
  3237. config X86
  3238. def_bool y
  3239. + select HAVE_PREEMPT_LAZY
  3240. select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
  3241. select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
  3242. select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
  3243. @@ -203,8 +204,11 @@
  3244. def_bool y
  3245. depends on ISA_DMA_API
  3246. +config RWSEM_GENERIC_SPINLOCK
  3247. + def_bool PREEMPT_RT_FULL
  3248. +
  3249. config RWSEM_XCHGADD_ALGORITHM
  3250. - def_bool y
  3251. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  3252. config GENERIC_CALIBRATE_DELAY
  3253. def_bool y
  3254. @@ -838,7 +842,7 @@
  3255. config MAXSMP
  3256. bool "Enable Maximum number of SMP Processors and NUMA Nodes"
  3257. depends on X86_64 && SMP && DEBUG_KERNEL
  3258. - select CPUMASK_OFFSTACK
  3259. + select CPUMASK_OFFSTACK if !PREEMPT_RT_FULL
  3260. ---help---
  3261. Enable maximum number of CPUS and NUMA Nodes for this architecture.
  3262. If unsure, say N.
  3263. diff -Nur linux-4.1.26.orig/arch/x86/kernel/apic/io_apic.c linux-4.1.26/arch/x86/kernel/apic/io_apic.c
  3264. --- linux-4.1.26.orig/arch/x86/kernel/apic/io_apic.c 2016-06-07 01:13:11.000000000 +0200
  3265. +++ linux-4.1.26/arch/x86/kernel/apic/io_apic.c 2016-06-19 15:30:58.615294573 +0200
  3266. @@ -1891,7 +1891,8 @@
  3267. static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
  3268. {
  3269. /* If we are moving the irq we need to mask it */
  3270. - if (unlikely(irqd_is_setaffinity_pending(data))) {
  3271. + if (unlikely(irqd_is_setaffinity_pending(data) &&
  3272. + !irqd_irq_inprogress(data))) {
  3273. mask_ioapic(cfg);
  3274. return true;
  3275. }
  3276. diff -Nur linux-4.1.26.orig/arch/x86/kernel/apic/x2apic_uv_x.c linux-4.1.26/arch/x86/kernel/apic/x2apic_uv_x.c
  3277. --- linux-4.1.26.orig/arch/x86/kernel/apic/x2apic_uv_x.c 2016-06-07 01:13:11.000000000 +0200
  3278. +++ linux-4.1.26/arch/x86/kernel/apic/x2apic_uv_x.c 2016-06-19 15:30:58.615294573 +0200
  3279. @@ -949,7 +949,7 @@
  3280. uv_blade_info[blade].pnode = pnode;
  3281. uv_blade_info[blade].nr_possible_cpus = 0;
  3282. uv_blade_info[blade].nr_online_cpus = 0;
  3283. - spin_lock_init(&uv_blade_info[blade].nmi_lock);
  3284. + raw_spin_lock_init(&uv_blade_info[blade].nmi_lock);
  3285. min_pnode = min(pnode, min_pnode);
  3286. max_pnode = max(pnode, max_pnode);
  3287. blade++;
  3288. diff -Nur linux-4.1.26.orig/arch/x86/kernel/asm-offsets.c linux-4.1.26/arch/x86/kernel/asm-offsets.c
  3289. --- linux-4.1.26.orig/arch/x86/kernel/asm-offsets.c 2016-06-07 01:13:11.000000000 +0200
  3290. +++ linux-4.1.26/arch/x86/kernel/asm-offsets.c 2016-06-19 15:30:58.615294573 +0200
  3291. @@ -32,6 +32,7 @@
  3292. OFFSET(TI_flags, thread_info, flags);
  3293. OFFSET(TI_status, thread_info, status);
  3294. OFFSET(TI_addr_limit, thread_info, addr_limit);
  3295. + OFFSET(TI_preempt_lazy_count, thread_info, preempt_lazy_count);
  3296. BLANK();
  3297. OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
  3298. @@ -71,4 +72,5 @@
  3299. BLANK();
  3300. DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
  3301. + DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  3302. }
  3303. diff -Nur linux-4.1.26.orig/arch/x86/kernel/cpu/mcheck/mce.c linux-4.1.26/arch/x86/kernel/cpu/mcheck/mce.c
  3304. --- linux-4.1.26.orig/arch/x86/kernel/cpu/mcheck/mce.c 2016-06-07 01:13:11.000000000 +0200
  3305. +++ linux-4.1.26/arch/x86/kernel/cpu/mcheck/mce.c 2016-06-19 15:30:58.615294573 +0200
  3306. @@ -41,6 +41,8 @@
  3307. #include <linux/debugfs.h>
  3308. #include <linux/irq_work.h>
  3309. #include <linux/export.h>
  3310. +#include <linux/jiffies.h>
  3311. +#include <linux/work-simple.h>
  3312. #include <asm/processor.h>
  3313. #include <asm/traps.h>
  3314. @@ -1267,7 +1269,7 @@
  3315. static unsigned long check_interval = INITIAL_CHECK_INTERVAL;
  3316. static DEFINE_PER_CPU(unsigned long, mce_next_interval); /* in jiffies */
  3317. -static DEFINE_PER_CPU(struct timer_list, mce_timer);
  3318. +static DEFINE_PER_CPU(struct hrtimer, mce_timer);
  3319. static unsigned long mce_adjust_timer_default(unsigned long interval)
  3320. {
  3321. @@ -1276,32 +1278,18 @@
  3322. static unsigned long (*mce_adjust_timer)(unsigned long interval) = mce_adjust_timer_default;
  3323. -static void __restart_timer(struct timer_list *t, unsigned long interval)
  3324. +static enum hrtimer_restart __restart_timer(struct hrtimer *timer, unsigned long interval)
  3325. {
  3326. - unsigned long when = jiffies + interval;
  3327. - unsigned long flags;
  3328. -
  3329. - local_irq_save(flags);
  3330. -
  3331. - if (timer_pending(t)) {
  3332. - if (time_before(when, t->expires))
  3333. - mod_timer_pinned(t, when);
  3334. - } else {
  3335. - t->expires = round_jiffies(when);
  3336. - add_timer_on(t, smp_processor_id());
  3337. - }
  3338. -
  3339. - local_irq_restore(flags);
  3340. + if (!interval)
  3341. + return HRTIMER_NORESTART;
  3342. + hrtimer_forward_now(timer, ns_to_ktime(jiffies_to_nsecs(interval)));
  3343. + return HRTIMER_RESTART;
  3344. }
  3345. -static void mce_timer_fn(unsigned long data)
  3346. +static enum hrtimer_restart mce_timer_fn(struct hrtimer *timer)
  3347. {
  3348. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3349. - int cpu = smp_processor_id();
  3350. unsigned long iv;
  3351. - WARN_ON(cpu != data);
  3352. -
  3353. iv = __this_cpu_read(mce_next_interval);
  3354. if (mce_available(this_cpu_ptr(&cpu_info))) {
  3355. @@ -1324,7 +1312,7 @@
  3356. done:
  3357. __this_cpu_write(mce_next_interval, iv);
  3358. - __restart_timer(t, iv);
  3359. + return __restart_timer(timer, iv);
  3360. }
  3361. /*
  3362. @@ -1332,7 +1320,7 @@
  3363. */
  3364. void mce_timer_kick(unsigned long interval)
  3365. {
  3366. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3367. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  3368. unsigned long iv = __this_cpu_read(mce_next_interval);
  3369. __restart_timer(t, interval);
  3370. @@ -1347,7 +1335,7 @@
  3371. int cpu;
  3372. for_each_online_cpu(cpu)
  3373. - del_timer_sync(&per_cpu(mce_timer, cpu));
  3374. + hrtimer_cancel(&per_cpu(mce_timer, cpu));
  3375. }
  3376. static void mce_do_trigger(struct work_struct *work)
  3377. @@ -1357,6 +1345,56 @@
  3378. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  3379. +static void __mce_notify_work(struct swork_event *event)
  3380. +{
  3381. + /* Not more than two messages every minute */
  3382. + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  3383. +
  3384. + /* wake processes polling /dev/mcelog */
  3385. + wake_up_interruptible(&mce_chrdev_wait);
  3386. +
  3387. + /*
  3388. + * There is no risk of missing notifications because
  3389. + * work_pending is always cleared before the function is
  3390. + * executed.
  3391. + */
  3392. + if (mce_helper[0] && !work_pending(&mce_trigger_work))
  3393. + schedule_work(&mce_trigger_work);
  3394. +
  3395. + if (__ratelimit(&ratelimit))
  3396. + pr_info(HW_ERR "Machine check events logged\n");
  3397. +}
  3398. +
  3399. +#ifdef CONFIG_PREEMPT_RT_FULL
  3400. +static bool notify_work_ready __read_mostly;
  3401. +static struct swork_event notify_work;
  3402. +
  3403. +static int mce_notify_work_init(void)
  3404. +{
  3405. + int err;
  3406. +
  3407. + err = swork_get();
  3408. + if (err)
  3409. + return err;
  3410. +
  3411. + INIT_SWORK(&notify_work, __mce_notify_work);
  3412. + notify_work_ready = true;
  3413. + return 0;
  3414. +}
  3415. +
  3416. +static void mce_notify_work(void)
  3417. +{
  3418. + if (notify_work_ready)
  3419. + swork_queue(&notify_work);
  3420. +}
  3421. +#else
  3422. +static void mce_notify_work(void)
  3423. +{
  3424. + __mce_notify_work(NULL);
  3425. +}
  3426. +static inline int mce_notify_work_init(void) { return 0; }
  3427. +#endif
  3428. +
  3429. /*
  3430. * Notify the user(s) about new machine check events.
  3431. * Can be called from interrupt context, but not from machine check/NMI
  3432. @@ -1364,19 +1402,8 @@
  3433. */
  3434. int mce_notify_irq(void)
  3435. {
  3436. - /* Not more than two messages every minute */
  3437. - static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  3438. -
  3439. if (test_and_clear_bit(0, &mce_need_notify)) {
  3440. - /* wake processes polling /dev/mcelog */
  3441. - wake_up_interruptible(&mce_chrdev_wait);
  3442. -
  3443. - if (mce_helper[0])
  3444. - schedule_work(&mce_trigger_work);
  3445. -
  3446. - if (__ratelimit(&ratelimit))
  3447. - pr_info(HW_ERR "Machine check events logged\n");
  3448. -
  3449. + mce_notify_work();
  3450. return 1;
  3451. }
  3452. return 0;
  3453. @@ -1649,7 +1676,7 @@
  3454. }
  3455. }
  3456. -static void mce_start_timer(unsigned int cpu, struct timer_list *t)
  3457. +static void mce_start_timer(unsigned int cpu, struct hrtimer *t)
  3458. {
  3459. unsigned long iv = check_interval * HZ;
  3460. @@ -1658,16 +1685,17 @@
  3461. per_cpu(mce_next_interval, cpu) = iv;
  3462. - t->expires = round_jiffies(jiffies + iv);
  3463. - add_timer_on(t, cpu);
  3464. + hrtimer_start_range_ns(t, ns_to_ktime(jiffies_to_usecs(iv) * 1000ULL),
  3465. + 0, HRTIMER_MODE_REL_PINNED);
  3466. }
  3467. static void __mcheck_cpu_init_timer(void)
  3468. {
  3469. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3470. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  3471. unsigned int cpu = smp_processor_id();
  3472. - setup_timer(t, mce_timer_fn, cpu);
  3473. + hrtimer_init(t, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  3474. + t->function = mce_timer_fn;
  3475. mce_start_timer(cpu, t);
  3476. }
  3477. @@ -2345,6 +2373,8 @@
  3478. if (!mce_available(raw_cpu_ptr(&cpu_info)))
  3479. return;
  3480. + hrtimer_cancel(this_cpu_ptr(&mce_timer));
  3481. +
  3482. if (!(action & CPU_TASKS_FROZEN))
  3483. cmci_clear();
  3484. for (i = 0; i < mca_cfg.banks; i++) {
  3485. @@ -2371,6 +2401,7 @@
  3486. if (b->init)
  3487. wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
  3488. }
  3489. + __mcheck_cpu_init_timer();
  3490. }
  3491. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  3492. @@ -2378,7 +2409,6 @@
  3493. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  3494. {
  3495. unsigned int cpu = (unsigned long)hcpu;
  3496. - struct timer_list *t = &per_cpu(mce_timer, cpu);
  3497. switch (action & ~CPU_TASKS_FROZEN) {
  3498. case CPU_ONLINE:
  3499. @@ -2398,11 +2428,9 @@
  3500. break;
  3501. case CPU_DOWN_PREPARE:
  3502. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  3503. - del_timer_sync(t);
  3504. break;
  3505. case CPU_DOWN_FAILED:
  3506. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  3507. - mce_start_timer(cpu, t);
  3508. break;
  3509. }
  3510. @@ -2441,6 +2469,10 @@
  3511. goto err_out;
  3512. }
  3513. + err = mce_notify_work_init();
  3514. + if (err)
  3515. + goto err_out;
  3516. +
  3517. if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
  3518. err = -ENOMEM;
  3519. goto err_out;
  3520. diff -Nur linux-4.1.26.orig/arch/x86/kernel/dumpstack_32.c linux-4.1.26/arch/x86/kernel/dumpstack_32.c
  3521. --- linux-4.1.26.orig/arch/x86/kernel/dumpstack_32.c 2016-06-07 01:13:11.000000000 +0200
  3522. +++ linux-4.1.26/arch/x86/kernel/dumpstack_32.c 2016-06-19 15:30:58.615294573 +0200
  3523. @@ -42,7 +42,7 @@
  3524. unsigned long *stack, unsigned long bp,
  3525. const struct stacktrace_ops *ops, void *data)
  3526. {
  3527. - const unsigned cpu = get_cpu();
  3528. + const unsigned cpu = get_cpu_light();
  3529. int graph = 0;
  3530. u32 *prev_esp;
  3531. @@ -86,7 +86,7 @@
  3532. break;
  3533. touch_nmi_watchdog();
  3534. }
  3535. - put_cpu();
  3536. + put_cpu_light();
  3537. }
  3538. EXPORT_SYMBOL(dump_trace);
  3539. diff -Nur linux-4.1.26.orig/arch/x86/kernel/dumpstack_64.c linux-4.1.26/arch/x86/kernel/dumpstack_64.c
  3540. --- linux-4.1.26.orig/arch/x86/kernel/dumpstack_64.c 2016-06-07 01:13:11.000000000 +0200
  3541. +++ linux-4.1.26/arch/x86/kernel/dumpstack_64.c 2016-06-19 15:30:58.615294573 +0200
  3542. @@ -152,7 +152,7 @@
  3543. unsigned long *stack, unsigned long bp,
  3544. const struct stacktrace_ops *ops, void *data)
  3545. {
  3546. - const unsigned cpu = get_cpu();
  3547. + const unsigned cpu = get_cpu_light();
  3548. struct thread_info *tinfo;
  3549. unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
  3550. unsigned long dummy;
  3551. @@ -241,7 +241,7 @@
  3552. * This handles the process stack:
  3553. */
  3554. bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
  3555. - put_cpu();
  3556. + put_cpu_light();
  3557. }
  3558. EXPORT_SYMBOL(dump_trace);
  3559. @@ -255,7 +255,7 @@
  3560. int cpu;
  3561. int i;
  3562. - preempt_disable();
  3563. + migrate_disable();
  3564. cpu = smp_processor_id();
  3565. irq_stack_end = (unsigned long *)(per_cpu(irq_stack_ptr, cpu));
  3566. @@ -291,7 +291,7 @@
  3567. pr_cont(" %016lx", *stack++);
  3568. touch_nmi_watchdog();
  3569. }
  3570. - preempt_enable();
  3571. + migrate_enable();
  3572. pr_cont("\n");
  3573. show_trace_log_lvl(task, regs, sp, bp, log_lvl);
  3574. diff -Nur linux-4.1.26.orig/arch/x86/kernel/entry_32.S linux-4.1.26/arch/x86/kernel/entry_32.S
  3575. --- linux-4.1.26.orig/arch/x86/kernel/entry_32.S 2016-06-07 01:13:11.000000000 +0200
  3576. +++ linux-4.1.26/arch/x86/kernel/entry_32.S 2016-06-19 15:30:58.615294573 +0200
  3577. @@ -359,8 +359,24 @@
  3578. ENTRY(resume_kernel)
  3579. DISABLE_INTERRUPTS(CLBR_ANY)
  3580. need_resched:
  3581. + # preempt count == 0 + NEED_RS set?
  3582. cmpl $0,PER_CPU_VAR(__preempt_count)
  3583. +#ifndef CONFIG_PREEMPT_LAZY
  3584. jnz restore_all
  3585. +#else
  3586. + jz test_int_off
  3587. +
  3588. + # atleast preempt count == 0 ?
  3589. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  3590. + jne restore_all
  3591. +
  3592. + cmpl $0,TI_preempt_lazy_count(%ebp) # non-zero preempt_lazy_count ?
  3593. + jnz restore_all
  3594. +
  3595. + testl $_TIF_NEED_RESCHED_LAZY, TI_flags(%ebp)
  3596. + jz restore_all
  3597. +test_int_off:
  3598. +#endif
  3599. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  3600. jz restore_all
  3601. call preempt_schedule_irq
  3602. @@ -594,7 +610,7 @@
  3603. ALIGN
  3604. RING0_PTREGS_FRAME # can't unwind into user space anyway
  3605. work_pending:
  3606. - testb $_TIF_NEED_RESCHED, %cl
  3607. + testl $_TIF_NEED_RESCHED_MASK, %ecx
  3608. jz work_notifysig
  3609. work_resched:
  3610. call schedule
  3611. @@ -607,7 +623,7 @@
  3612. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  3613. # than syscall tracing?
  3614. jz restore_all
  3615. - testb $_TIF_NEED_RESCHED, %cl
  3616. + testl $_TIF_NEED_RESCHED_MASK, %ecx
  3617. jnz work_resched
  3618. work_notifysig: # deal with pending signals and
  3619. diff -Nur linux-4.1.26.orig/arch/x86/kernel/entry_64.S linux-4.1.26/arch/x86/kernel/entry_64.S
  3620. --- linux-4.1.26.orig/arch/x86/kernel/entry_64.S 2016-06-07 01:13:11.000000000 +0200
  3621. +++ linux-4.1.26/arch/x86/kernel/entry_64.S 2016-06-19 15:30:58.615294573 +0200
  3622. @@ -370,8 +370,8 @@
  3623. /* First do a reschedule test. */
  3624. /* edx: work, edi: workmask */
  3625. int_careful:
  3626. - bt $TIF_NEED_RESCHED,%edx
  3627. - jnc int_very_careful
  3628. + testl $_TIF_NEED_RESCHED_MASK,%edx
  3629. + jz int_very_careful
  3630. TRACE_IRQS_ON
  3631. ENABLE_INTERRUPTS(CLBR_NONE)
  3632. pushq_cfi %rdi
  3633. @@ -776,7 +776,23 @@
  3634. bt $9,EFLAGS(%rsp) /* interrupts were off? */
  3635. jnc 1f
  3636. 0: cmpl $0,PER_CPU_VAR(__preempt_count)
  3637. +#ifndef CONFIG_PREEMPT_LAZY
  3638. jnz 1f
  3639. +#else
  3640. + jz do_preempt_schedule_irq
  3641. +
  3642. + # atleast preempt count == 0 ?
  3643. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  3644. + jnz 1f
  3645. +
  3646. + GET_THREAD_INFO(%rcx)
  3647. + cmpl $0, TI_preempt_lazy_count(%rcx)
  3648. + jnz 1f
  3649. +
  3650. + bt $TIF_NEED_RESCHED_LAZY,TI_flags(%rcx)
  3651. + jnc 1f
  3652. +do_preempt_schedule_irq:
  3653. +#endif
  3654. call preempt_schedule_irq
  3655. jmp 0b
  3656. 1:
  3657. @@ -844,8 +860,8 @@
  3658. /* edi: workmask, edx: work */
  3659. retint_careful:
  3660. CFI_RESTORE_STATE
  3661. - bt $TIF_NEED_RESCHED,%edx
  3662. - jnc retint_signal
  3663. + testl $_TIF_NEED_RESCHED_MASK,%edx
  3664. + jz retint_signal
  3665. TRACE_IRQS_ON
  3666. ENABLE_INTERRUPTS(CLBR_NONE)
  3667. pushq_cfi %rdi
  3668. @@ -1118,6 +1134,7 @@
  3669. jmp 2b
  3670. .previous
  3671. +#ifndef CONFIG_PREEMPT_RT_FULL
  3672. /* Call softirq on interrupt stack. Interrupts are off. */
  3673. ENTRY(do_softirq_own_stack)
  3674. CFI_STARTPROC
  3675. @@ -1137,6 +1154,7 @@
  3676. ret
  3677. CFI_ENDPROC
  3678. END(do_softirq_own_stack)
  3679. +#endif
  3680. #ifdef CONFIG_XEN
  3681. idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  3682. diff -Nur linux-4.1.26.orig/arch/x86/kernel/irq_32.c linux-4.1.26/arch/x86/kernel/irq_32.c
  3683. --- linux-4.1.26.orig/arch/x86/kernel/irq_32.c 2016-06-07 01:13:11.000000000 +0200
  3684. +++ linux-4.1.26/arch/x86/kernel/irq_32.c 2016-06-19 15:30:58.619294727 +0200
  3685. @@ -135,6 +135,7 @@
  3686. cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
  3687. }
  3688. +#ifndef CONFIG_PREEMPT_RT_FULL
  3689. void do_softirq_own_stack(void)
  3690. {
  3691. struct thread_info *curstk;
  3692. @@ -153,6 +154,7 @@
  3693. call_on_stack(__do_softirq, isp);
  3694. }
  3695. +#endif
  3696. bool handle_irq(unsigned irq, struct pt_regs *regs)
  3697. {
  3698. diff -Nur linux-4.1.26.orig/arch/x86/kernel/process_32.c linux-4.1.26/arch/x86/kernel/process_32.c
  3699. --- linux-4.1.26.orig/arch/x86/kernel/process_32.c 2016-06-07 01:13:11.000000000 +0200
  3700. +++ linux-4.1.26/arch/x86/kernel/process_32.c 2016-06-19 15:30:58.619294727 +0200
  3701. @@ -35,6 +35,7 @@
  3702. #include <linux/uaccess.h>
  3703. #include <linux/io.h>
  3704. #include <linux/kdebug.h>
  3705. +#include <linux/highmem.h>
  3706. #include <asm/pgtable.h>
  3707. #include <asm/ldt.h>
  3708. @@ -210,6 +211,35 @@
  3709. }
  3710. EXPORT_SYMBOL_GPL(start_thread);
  3711. +#ifdef CONFIG_PREEMPT_RT_FULL
  3712. +static void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  3713. +{
  3714. + int i;
  3715. +
  3716. + /*
  3717. + * Clear @prev's kmap_atomic mappings
  3718. + */
  3719. + for (i = 0; i < prev_p->kmap_idx; i++) {
  3720. + int idx = i + KM_TYPE_NR * smp_processor_id();
  3721. + pte_t *ptep = kmap_pte - idx;
  3722. +
  3723. + kpte_clear_flush(ptep, __fix_to_virt(FIX_KMAP_BEGIN + idx));
  3724. + }
  3725. + /*
  3726. + * Restore @next_p's kmap_atomic mappings
  3727. + */
  3728. + for (i = 0; i < next_p->kmap_idx; i++) {
  3729. + int idx = i + KM_TYPE_NR * smp_processor_id();
  3730. +
  3731. + if (!pte_none(next_p->kmap_pte[i]))
  3732. + set_pte(kmap_pte - idx, next_p->kmap_pte[i]);
  3733. + }
  3734. +}
  3735. +#else
  3736. +static inline void
  3737. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  3738. +#endif
  3739. +
  3740. /*
  3741. * switch_to(x,y) should switch tasks from x to y.
  3742. @@ -292,6 +322,8 @@
  3743. task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
  3744. __switch_to_xtra(prev_p, next_p, tss);
  3745. + switch_kmaps(prev_p, next_p);
  3746. +
  3747. /*
  3748. * Leave lazy mode, flushing any hypercalls made here.
  3749. * This must be done before restoring TLS segments so
  3750. diff -Nur linux-4.1.26.orig/arch/x86/kernel/signal.c linux-4.1.26/arch/x86/kernel/signal.c
  3751. --- linux-4.1.26.orig/arch/x86/kernel/signal.c 2016-06-07 01:13:11.000000000 +0200
  3752. +++ linux-4.1.26/arch/x86/kernel/signal.c 2016-06-19 15:30:58.619294727 +0200
  3753. @@ -726,6 +726,14 @@
  3754. {
  3755. user_exit();
  3756. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  3757. + if (unlikely(current->forced_info.si_signo)) {
  3758. + struct task_struct *t = current;
  3759. + force_sig_info(t->forced_info.si_signo, &t->forced_info, t);
  3760. + t->forced_info.si_signo = 0;
  3761. + }
  3762. +#endif
  3763. +
  3764. if (thread_info_flags & _TIF_UPROBE)
  3765. uprobe_notify_resume(regs);
  3766. diff -Nur linux-4.1.26.orig/arch/x86/kvm/lapic.c linux-4.1.26/arch/x86/kvm/lapic.c
  3767. --- linux-4.1.26.orig/arch/x86/kvm/lapic.c 2016-06-07 01:13:11.000000000 +0200
  3768. +++ linux-4.1.26/arch/x86/kvm/lapic.c 2016-06-19 15:30:58.619294727 +0200
  3769. @@ -1106,7 +1106,7 @@
  3770. static void apic_timer_expired(struct kvm_lapic *apic)
  3771. {
  3772. struct kvm_vcpu *vcpu = apic->vcpu;
  3773. - wait_queue_head_t *q = &vcpu->wq;
  3774. + struct swait_head *q = &vcpu->wq;
  3775. struct kvm_timer *ktimer = &apic->lapic_timer;
  3776. if (atomic_read(&apic->lapic_timer.pending))
  3777. @@ -1115,8 +1115,8 @@
  3778. atomic_inc(&apic->lapic_timer.pending);
  3779. kvm_set_pending_timer(vcpu);
  3780. - if (waitqueue_active(q))
  3781. - wake_up_interruptible(q);
  3782. + if (swaitqueue_active(q))
  3783. + swait_wake_interruptible(q);
  3784. if (apic_lvtt_tscdeadline(apic))
  3785. ktimer->expired_tscdeadline = ktimer->tscdeadline;
  3786. @@ -1169,8 +1169,36 @@
  3787. __delay(tsc_deadline - guest_tsc);
  3788. }
  3789. +static enum hrtimer_restart apic_timer_fn(struct hrtimer *data);
  3790. +
  3791. +static void __apic_timer_expired(struct hrtimer *data)
  3792. +{
  3793. + int ret, i = 0;
  3794. + enum hrtimer_restart r;
  3795. + struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
  3796. +
  3797. + r = apic_timer_fn(data);
  3798. +
  3799. + if (r == HRTIMER_RESTART) {
  3800. + do {
  3801. + ret = hrtimer_start_expires(data, HRTIMER_MODE_ABS);
  3802. + if (ret == -ETIME)
  3803. + hrtimer_add_expires_ns(&ktimer->timer,
  3804. + ktimer->period);
  3805. + i++;
  3806. + } while (ret == -ETIME && i < 10);
  3807. +
  3808. + if (ret == -ETIME) {
  3809. + printk_once(KERN_ERR "%s: failed to reprogram timer\n",
  3810. + __func__);
  3811. + WARN_ON_ONCE(1);
  3812. + }
  3813. + }
  3814. +}
  3815. +
  3816. static void start_apic_timer(struct kvm_lapic *apic)
  3817. {
  3818. + int ret;
  3819. ktime_t now;
  3820. atomic_set(&apic->lapic_timer.pending, 0);
  3821. @@ -1201,9 +1229,11 @@
  3822. }
  3823. }
  3824. - hrtimer_start(&apic->lapic_timer.timer,
  3825. + ret = hrtimer_start(&apic->lapic_timer.timer,
  3826. ktime_add_ns(now, apic->lapic_timer.period),
  3827. HRTIMER_MODE_ABS);
  3828. + if (ret == -ETIME)
  3829. + __apic_timer_expired(&apic->lapic_timer.timer);
  3830. apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
  3831. PRIx64 ", "
  3832. @@ -1235,8 +1265,10 @@
  3833. do_div(ns, this_tsc_khz);
  3834. expire = ktime_add_ns(now, ns);
  3835. expire = ktime_sub_ns(expire, lapic_timer_advance_ns);
  3836. - hrtimer_start(&apic->lapic_timer.timer,
  3837. + ret = hrtimer_start(&apic->lapic_timer.timer,
  3838. expire, HRTIMER_MODE_ABS);
  3839. + if (ret == -ETIME)
  3840. + __apic_timer_expired(&apic->lapic_timer.timer);
  3841. } else
  3842. apic_timer_expired(apic);
  3843. @@ -1709,6 +1741,7 @@
  3844. hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
  3845. HRTIMER_MODE_ABS);
  3846. apic->lapic_timer.timer.function = apic_timer_fn;
  3847. + apic->lapic_timer.timer.irqsafe = 1;
  3848. /*
  3849. * APIC is created enabled. This will prevent kvm_lapic_set_base from
  3850. @@ -1836,7 +1869,8 @@
  3851. timer = &vcpu->arch.apic->lapic_timer.timer;
  3852. if (hrtimer_cancel(timer))
  3853. - hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  3854. + if (hrtimer_start_expires(timer, HRTIMER_MODE_ABS) == -ETIME)
  3855. + __apic_timer_expired(timer);
  3856. }
  3857. /*
  3858. diff -Nur linux-4.1.26.orig/arch/x86/kvm/x86.c linux-4.1.26/arch/x86/kvm/x86.c
  3859. --- linux-4.1.26.orig/arch/x86/kvm/x86.c 2016-06-07 01:13:11.000000000 +0200
  3860. +++ linux-4.1.26/arch/x86/kvm/x86.c 2016-06-19 15:30:58.619294727 +0200
  3861. @@ -5810,6 +5810,13 @@
  3862. goto out;
  3863. }
  3864. +#ifdef CONFIG_PREEMPT_RT_FULL
  3865. + if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
  3866. + printk(KERN_ERR "RT requires X86_FEATURE_CONSTANT_TSC\n");
  3867. + return -EOPNOTSUPP;
  3868. + }
  3869. +#endif
  3870. +
  3871. r = kvm_mmu_module_init();
  3872. if (r)
  3873. goto out_free_percpu;
  3874. diff -Nur linux-4.1.26.orig/arch/x86/lib/usercopy_32.c linux-4.1.26/arch/x86/lib/usercopy_32.c
  3875. --- linux-4.1.26.orig/arch/x86/lib/usercopy_32.c 2016-06-07 01:13:11.000000000 +0200
  3876. +++ linux-4.1.26/arch/x86/lib/usercopy_32.c 2016-06-19 15:30:58.619294727 +0200
  3877. @@ -647,7 +647,8 @@
  3878. * @from: Source address, in kernel space.
  3879. * @n: Number of bytes to copy.
  3880. *
  3881. - * Context: User context only. This function may sleep.
  3882. + * Context: User context only. This function may sleep if pagefaults are
  3883. + * enabled.
  3884. *
  3885. * Copy data from kernel space to user space.
  3886. *
  3887. @@ -668,7 +669,8 @@
  3888. * @from: Source address, in user space.
  3889. * @n: Number of bytes to copy.
  3890. *
  3891. - * Context: User context only. This function may sleep.
  3892. + * Context: User context only. This function may sleep if pagefaults are
  3893. + * enabled.
  3894. *
  3895. * Copy data from user space to kernel space.
  3896. *
  3897. diff -Nur linux-4.1.26.orig/arch/x86/mm/fault.c linux-4.1.26/arch/x86/mm/fault.c
  3898. --- linux-4.1.26.orig/arch/x86/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  3899. +++ linux-4.1.26/arch/x86/mm/fault.c 2016-06-19 15:30:58.619294727 +0200
  3900. @@ -13,6 +13,7 @@
  3901. #include <linux/hugetlb.h> /* hstate_index_to_shift */
  3902. #include <linux/prefetch.h> /* prefetchw */
  3903. #include <linux/context_tracking.h> /* exception_enter(), ... */
  3904. +#include <linux/uaccess.h> /* faulthandler_disabled() */
  3905. #include <asm/traps.h> /* dotraplinkage, ... */
  3906. #include <asm/pgalloc.h> /* pgd_*(), ... */
  3907. @@ -1133,9 +1134,9 @@
  3908. /*
  3909. * If we're in an interrupt, have no user context or are running
  3910. - * in an atomic region then we must not take the fault:
  3911. + * in a region with pagefaults disabled then we must not take the fault
  3912. */
  3913. - if (unlikely(in_atomic() || !mm)) {
  3914. + if (unlikely(faulthandler_disabled() || !mm)) {
  3915. bad_area_nosemaphore(regs, error_code, address);
  3916. return;
  3917. }
  3918. diff -Nur linux-4.1.26.orig/arch/x86/mm/highmem_32.c linux-4.1.26/arch/x86/mm/highmem_32.c
  3919. --- linux-4.1.26.orig/arch/x86/mm/highmem_32.c 2016-06-07 01:13:11.000000000 +0200
  3920. +++ linux-4.1.26/arch/x86/mm/highmem_32.c 2016-06-19 15:30:58.619294727 +0200
  3921. @@ -32,10 +32,11 @@
  3922. */
  3923. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  3924. {
  3925. + pte_t pte = mk_pte(page, prot);
  3926. unsigned long vaddr;
  3927. int idx, type;
  3928. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  3929. + preempt_disable_nort();
  3930. pagefault_disable();
  3931. if (!PageHighMem(page))
  3932. @@ -45,7 +46,10 @@
  3933. idx = type + KM_TYPE_NR*smp_processor_id();
  3934. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  3935. BUG_ON(!pte_none(*(kmap_pte-idx)));
  3936. - set_pte(kmap_pte-idx, mk_pte(page, prot));
  3937. +#ifdef CONFIG_PREEMPT_RT_FULL
  3938. + current->kmap_pte[type] = pte;
  3939. +#endif
  3940. + set_pte(kmap_pte-idx, pte);
  3941. arch_flush_lazy_mmu_mode();
  3942. return (void *)vaddr;
  3943. @@ -88,6 +92,9 @@
  3944. * is a bad idea also, in case the page changes cacheability
  3945. * attributes or becomes a protected page in a hypervisor.
  3946. */
  3947. +#ifdef CONFIG_PREEMPT_RT_FULL
  3948. + current->kmap_pte[type] = __pte(0);
  3949. +#endif
  3950. kpte_clear_flush(kmap_pte-idx, vaddr);
  3951. kmap_atomic_idx_pop();
  3952. arch_flush_lazy_mmu_mode();
  3953. @@ -100,6 +107,7 @@
  3954. #endif
  3955. pagefault_enable();
  3956. + preempt_enable_nort();
  3957. }
  3958. EXPORT_SYMBOL(__kunmap_atomic);
  3959. diff -Nur linux-4.1.26.orig/arch/x86/mm/iomap_32.c linux-4.1.26/arch/x86/mm/iomap_32.c
  3960. --- linux-4.1.26.orig/arch/x86/mm/iomap_32.c 2016-06-07 01:13:11.000000000 +0200
  3961. +++ linux-4.1.26/arch/x86/mm/iomap_32.c 2016-06-19 15:30:58.619294727 +0200
  3962. @@ -56,15 +56,22 @@
  3963. void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
  3964. {
  3965. + pte_t pte = pfn_pte(pfn, prot);
  3966. unsigned long vaddr;
  3967. int idx, type;
  3968. + preempt_disable();
  3969. pagefault_disable();
  3970. type = kmap_atomic_idx_push();
  3971. idx = type + KM_TYPE_NR * smp_processor_id();
  3972. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  3973. - set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
  3974. + WARN_ON(!pte_none(*(kmap_pte - idx)));
  3975. +
  3976. +#ifdef CONFIG_PREEMPT_RT_FULL
  3977. + current->kmap_pte[type] = pte;
  3978. +#endif
  3979. + set_pte(kmap_pte - idx, pte);
  3980. arch_flush_lazy_mmu_mode();
  3981. return (void *)vaddr;
  3982. @@ -112,10 +119,14 @@
  3983. * is a bad idea also, in case the page changes cacheability
  3984. * attributes or becomes a protected page in a hypervisor.
  3985. */
  3986. +#ifdef CONFIG_PREEMPT_RT_FULL
  3987. + current->kmap_pte[type] = __pte(0);
  3988. +#endif
  3989. kpte_clear_flush(kmap_pte-idx, vaddr);
  3990. kmap_atomic_idx_pop();
  3991. }
  3992. pagefault_enable();
  3993. + preempt_enable();
  3994. }
  3995. EXPORT_SYMBOL_GPL(iounmap_atomic);
  3996. diff -Nur linux-4.1.26.orig/arch/x86/platform/uv/tlb_uv.c linux-4.1.26/arch/x86/platform/uv/tlb_uv.c
  3997. --- linux-4.1.26.orig/arch/x86/platform/uv/tlb_uv.c 2016-06-07 01:13:11.000000000 +0200
  3998. +++ linux-4.1.26/arch/x86/platform/uv/tlb_uv.c 2016-06-19 15:30:58.619294727 +0200
  3999. @@ -714,9 +714,9 @@
  4000. quiesce_local_uvhub(hmaster);
  4001. - spin_lock(&hmaster->queue_lock);
  4002. + raw_spin_lock(&hmaster->queue_lock);
  4003. reset_with_ipi(&bau_desc->distribution, bcp);
  4004. - spin_unlock(&hmaster->queue_lock);
  4005. + raw_spin_unlock(&hmaster->queue_lock);
  4006. end_uvhub_quiesce(hmaster);
  4007. @@ -736,9 +736,9 @@
  4008. quiesce_local_uvhub(hmaster);
  4009. - spin_lock(&hmaster->queue_lock);
  4010. + raw_spin_lock(&hmaster->queue_lock);
  4011. reset_with_ipi(&bau_desc->distribution, bcp);
  4012. - spin_unlock(&hmaster->queue_lock);
  4013. + raw_spin_unlock(&hmaster->queue_lock);
  4014. end_uvhub_quiesce(hmaster);
  4015. @@ -759,7 +759,7 @@
  4016. cycles_t tm1;
  4017. hmaster = bcp->uvhub_master;
  4018. - spin_lock(&hmaster->disable_lock);
  4019. + raw_spin_lock(&hmaster->disable_lock);
  4020. if (!bcp->baudisabled) {
  4021. stat->s_bau_disabled++;
  4022. tm1 = get_cycles();
  4023. @@ -772,7 +772,7 @@
  4024. }
  4025. }
  4026. }
  4027. - spin_unlock(&hmaster->disable_lock);
  4028. + raw_spin_unlock(&hmaster->disable_lock);
  4029. }
  4030. static void count_max_concurr(int stat, struct bau_control *bcp,
  4031. @@ -835,7 +835,7 @@
  4032. */
  4033. static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  4034. {
  4035. - spinlock_t *lock = &hmaster->uvhub_lock;
  4036. + raw_spinlock_t *lock = &hmaster->uvhub_lock;
  4037. atomic_t *v;
  4038. v = &hmaster->active_descriptor_count;
  4039. @@ -968,7 +968,7 @@
  4040. struct bau_control *hmaster;
  4041. hmaster = bcp->uvhub_master;
  4042. - spin_lock(&hmaster->disable_lock);
  4043. + raw_spin_lock(&hmaster->disable_lock);
  4044. if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
  4045. stat->s_bau_reenabled++;
  4046. for_each_present_cpu(tcpu) {
  4047. @@ -980,10 +980,10 @@
  4048. tbcp->period_giveups = 0;
  4049. }
  4050. }
  4051. - spin_unlock(&hmaster->disable_lock);
  4052. + raw_spin_unlock(&hmaster->disable_lock);
  4053. return 0;
  4054. }
  4055. - spin_unlock(&hmaster->disable_lock);
  4056. + raw_spin_unlock(&hmaster->disable_lock);
  4057. return -1;
  4058. }
  4059. @@ -1901,9 +1901,9 @@
  4060. bcp->cong_reps = congested_reps;
  4061. bcp->disabled_period = sec_2_cycles(disabled_period);
  4062. bcp->giveup_limit = giveup_limit;
  4063. - spin_lock_init(&bcp->queue_lock);
  4064. - spin_lock_init(&bcp->uvhub_lock);
  4065. - spin_lock_init(&bcp->disable_lock);
  4066. + raw_spin_lock_init(&bcp->queue_lock);
  4067. + raw_spin_lock_init(&bcp->uvhub_lock);
  4068. + raw_spin_lock_init(&bcp->disable_lock);
  4069. }
  4070. }
  4071. diff -Nur linux-4.1.26.orig/arch/x86/platform/uv/uv_time.c linux-4.1.26/arch/x86/platform/uv/uv_time.c
  4072. --- linux-4.1.26.orig/arch/x86/platform/uv/uv_time.c 2016-06-07 01:13:11.000000000 +0200
  4073. +++ linux-4.1.26/arch/x86/platform/uv/uv_time.c 2016-06-19 15:30:58.623294881 +0200
  4074. @@ -58,7 +58,7 @@
  4075. /* There is one of these allocated per node */
  4076. struct uv_rtc_timer_head {
  4077. - spinlock_t lock;
  4078. + raw_spinlock_t lock;
  4079. /* next cpu waiting for timer, local node relative: */
  4080. int next_cpu;
  4081. /* number of cpus on this node: */
  4082. @@ -178,7 +178,7 @@
  4083. uv_rtc_deallocate_timers();
  4084. return -ENOMEM;
  4085. }
  4086. - spin_lock_init(&head->lock);
  4087. + raw_spin_lock_init(&head->lock);
  4088. head->ncpus = uv_blade_nr_possible_cpus(bid);
  4089. head->next_cpu = -1;
  4090. blade_info[bid] = head;
  4091. @@ -232,7 +232,7 @@
  4092. unsigned long flags;
  4093. int next_cpu;
  4094. - spin_lock_irqsave(&head->lock, flags);
  4095. + raw_spin_lock_irqsave(&head->lock, flags);
  4096. next_cpu = head->next_cpu;
  4097. *t = expires;
  4098. @@ -244,12 +244,12 @@
  4099. if (uv_setup_intr(cpu, expires)) {
  4100. *t = ULLONG_MAX;
  4101. uv_rtc_find_next_timer(head, pnode);
  4102. - spin_unlock_irqrestore(&head->lock, flags);
  4103. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4104. return -ETIME;
  4105. }
  4106. }
  4107. - spin_unlock_irqrestore(&head->lock, flags);
  4108. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4109. return 0;
  4110. }
  4111. @@ -268,7 +268,7 @@
  4112. unsigned long flags;
  4113. int rc = 0;
  4114. - spin_lock_irqsave(&head->lock, flags);
  4115. + raw_spin_lock_irqsave(&head->lock, flags);
  4116. if ((head->next_cpu == bcpu && uv_read_rtc(NULL) >= *t) || force)
  4117. rc = 1;
  4118. @@ -280,7 +280,7 @@
  4119. uv_rtc_find_next_timer(head, pnode);
  4120. }
  4121. - spin_unlock_irqrestore(&head->lock, flags);
  4122. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4123. return rc;
  4124. }
  4125. @@ -300,13 +300,18 @@
  4126. static cycle_t uv_read_rtc(struct clocksource *cs)
  4127. {
  4128. unsigned long offset;
  4129. + cycle_t cycles;
  4130. + preempt_disable();
  4131. if (uv_get_min_hub_revision_id() == 1)
  4132. offset = 0;
  4133. else
  4134. offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
  4135. - return (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  4136. + cycles = (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  4137. + preempt_enable();
  4138. +
  4139. + return cycles;
  4140. }
  4141. /*
  4142. diff -Nur linux-4.1.26.orig/arch/xtensa/mm/fault.c linux-4.1.26/arch/xtensa/mm/fault.c
  4143. --- linux-4.1.26.orig/arch/xtensa/mm/fault.c 2016-06-07 01:13:11.000000000 +0200
  4144. +++ linux-4.1.26/arch/xtensa/mm/fault.c 2016-06-19 15:30:58.623294881 +0200
  4145. @@ -15,10 +15,10 @@
  4146. #include <linux/mm.h>
  4147. #include <linux/module.h>
  4148. #include <linux/hardirq.h>
  4149. +#include <linux/uaccess.h>
  4150. #include <asm/mmu_context.h>
  4151. #include <asm/cacheflush.h>
  4152. #include <asm/hardirq.h>
  4153. -#include <asm/uaccess.h>
  4154. #include <asm/pgalloc.h>
  4155. DEFINE_PER_CPU(unsigned long, asid_cache) = ASID_USER_FIRST;
  4156. @@ -57,7 +57,7 @@
  4157. /* If we're in an interrupt or have no user
  4158. * context, we must not take the fault..
  4159. */
  4160. - if (in_atomic() || !mm) {
  4161. + if (faulthandler_disabled() || !mm) {
  4162. bad_page_fault(regs, address, SIGSEGV);
  4163. return;
  4164. }
  4165. diff -Nur linux-4.1.26.orig/arch/xtensa/mm/highmem.c linux-4.1.26/arch/xtensa/mm/highmem.c
  4166. --- linux-4.1.26.orig/arch/xtensa/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  4167. +++ linux-4.1.26/arch/xtensa/mm/highmem.c 2016-06-19 15:30:58.623294881 +0200
  4168. @@ -42,6 +42,7 @@
  4169. enum fixed_addresses idx;
  4170. unsigned long vaddr;
  4171. + preempt_disable();
  4172. pagefault_disable();
  4173. if (!PageHighMem(page))
  4174. return page_address(page);
  4175. @@ -79,6 +80,7 @@
  4176. }
  4177. pagefault_enable();
  4178. + preempt_enable();
  4179. }
  4180. EXPORT_SYMBOL(__kunmap_atomic);
  4181. diff -Nur linux-4.1.26.orig/block/blk-core.c linux-4.1.26/block/blk-core.c
  4182. --- linux-4.1.26.orig/block/blk-core.c 2016-06-07 01:13:11.000000000 +0200
  4183. +++ linux-4.1.26/block/blk-core.c 2016-06-19 15:30:58.623294881 +0200
  4184. @@ -100,6 +100,9 @@
  4185. INIT_LIST_HEAD(&rq->queuelist);
  4186. INIT_LIST_HEAD(&rq->timeout_list);
  4187. +#ifdef CONFIG_PREEMPT_RT_FULL
  4188. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  4189. +#endif
  4190. rq->cpu = -1;
  4191. rq->q = q;
  4192. rq->__sector = (sector_t) -1;
  4193. @@ -194,7 +197,7 @@
  4194. **/
  4195. void blk_start_queue(struct request_queue *q)
  4196. {
  4197. - WARN_ON(!irqs_disabled());
  4198. + WARN_ON_NONRT(!irqs_disabled());
  4199. queue_flag_clear(QUEUE_FLAG_STOPPED, q);
  4200. __blk_run_queue(q);
  4201. @@ -661,7 +664,7 @@
  4202. q->bypass_depth = 1;
  4203. __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  4204. - init_waitqueue_head(&q->mq_freeze_wq);
  4205. + init_swait_head(&q->mq_freeze_wq);
  4206. if (blkcg_init_queue(q))
  4207. goto fail_bdi;
  4208. @@ -3077,7 +3080,7 @@
  4209. blk_run_queue_async(q);
  4210. else
  4211. __blk_run_queue(q);
  4212. - spin_unlock(q->queue_lock);
  4213. + spin_unlock_irq(q->queue_lock);
  4214. }
  4215. static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
  4216. @@ -3125,7 +3128,6 @@
  4217. void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  4218. {
  4219. struct request_queue *q;
  4220. - unsigned long flags;
  4221. struct request *rq;
  4222. LIST_HEAD(list);
  4223. unsigned int depth;
  4224. @@ -3145,11 +3147,6 @@
  4225. q = NULL;
  4226. depth = 0;
  4227. - /*
  4228. - * Save and disable interrupts here, to avoid doing it for every
  4229. - * queue lock we have to take.
  4230. - */
  4231. - local_irq_save(flags);
  4232. while (!list_empty(&list)) {
  4233. rq = list_entry_rq(list.next);
  4234. list_del_init(&rq->queuelist);
  4235. @@ -3162,7 +3159,7 @@
  4236. queue_unplugged(q, depth, from_schedule);
  4237. q = rq->q;
  4238. depth = 0;
  4239. - spin_lock(q->queue_lock);
  4240. + spin_lock_irq(q->queue_lock);
  4241. }
  4242. /*
  4243. @@ -3189,8 +3186,6 @@
  4244. */
  4245. if (q)
  4246. queue_unplugged(q, depth, from_schedule);
  4247. -
  4248. - local_irq_restore(flags);
  4249. }
  4250. void blk_finish_plug(struct blk_plug *plug)
  4251. diff -Nur linux-4.1.26.orig/block/blk-ioc.c linux-4.1.26/block/blk-ioc.c
  4252. --- linux-4.1.26.orig/block/blk-ioc.c 2016-06-07 01:13:11.000000000 +0200
  4253. +++ linux-4.1.26/block/blk-ioc.c 2016-06-19 15:30:58.623294881 +0200
  4254. @@ -7,6 +7,7 @@
  4255. #include <linux/bio.h>
  4256. #include <linux/blkdev.h>
  4257. #include <linux/slab.h>
  4258. +#include <linux/delay.h>
  4259. #include "blk.h"
  4260. @@ -109,7 +110,7 @@
  4261. spin_unlock(q->queue_lock);
  4262. } else {
  4263. spin_unlock_irqrestore(&ioc->lock, flags);
  4264. - cpu_relax();
  4265. + cpu_chill();
  4266. spin_lock_irqsave_nested(&ioc->lock, flags, 1);
  4267. }
  4268. }
  4269. @@ -187,7 +188,7 @@
  4270. spin_unlock(icq->q->queue_lock);
  4271. } else {
  4272. spin_unlock_irqrestore(&ioc->lock, flags);
  4273. - cpu_relax();
  4274. + cpu_chill();
  4275. goto retry;
  4276. }
  4277. }
  4278. diff -Nur linux-4.1.26.orig/block/blk-iopoll.c linux-4.1.26/block/blk-iopoll.c
  4279. --- linux-4.1.26.orig/block/blk-iopoll.c 2016-06-07 01:13:11.000000000 +0200
  4280. +++ linux-4.1.26/block/blk-iopoll.c 2016-06-19 15:30:58.623294881 +0200
  4281. @@ -35,6 +35,7 @@
  4282. list_add_tail(&iop->list, this_cpu_ptr(&blk_cpu_iopoll));
  4283. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4284. local_irq_restore(flags);
  4285. + preempt_check_resched_rt();
  4286. }
  4287. EXPORT_SYMBOL(blk_iopoll_sched);
  4288. @@ -132,6 +133,7 @@
  4289. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4290. local_irq_enable();
  4291. + preempt_check_resched_rt();
  4292. }
  4293. /**
  4294. @@ -201,6 +203,7 @@
  4295. this_cpu_ptr(&blk_cpu_iopoll));
  4296. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4297. local_irq_enable();
  4298. + preempt_check_resched_rt();
  4299. }
  4300. return NOTIFY_OK;
  4301. diff -Nur linux-4.1.26.orig/block/blk-mq.c linux-4.1.26/block/blk-mq.c
  4302. --- linux-4.1.26.orig/block/blk-mq.c 2016-06-07 01:13:11.000000000 +0200
  4303. +++ linux-4.1.26/block/blk-mq.c 2016-06-19 15:30:58.623294881 +0200
  4304. @@ -88,7 +88,7 @@
  4305. if (!(gfp & __GFP_WAIT))
  4306. return -EBUSY;
  4307. - ret = wait_event_interruptible(q->mq_freeze_wq,
  4308. + ret = swait_event_interruptible(q->mq_freeze_wq,
  4309. !q->mq_freeze_depth || blk_queue_dying(q));
  4310. if (blk_queue_dying(q))
  4311. return -ENODEV;
  4312. @@ -107,7 +107,7 @@
  4313. struct request_queue *q =
  4314. container_of(ref, struct request_queue, mq_usage_counter);
  4315. - wake_up_all(&q->mq_freeze_wq);
  4316. + swait_wake_all(&q->mq_freeze_wq);
  4317. }
  4318. void blk_mq_freeze_queue_start(struct request_queue *q)
  4319. @@ -127,7 +127,7 @@
  4320. static void blk_mq_freeze_queue_wait(struct request_queue *q)
  4321. {
  4322. - wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
  4323. + swait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
  4324. }
  4325. /*
  4326. @@ -151,7 +151,7 @@
  4327. spin_unlock_irq(q->queue_lock);
  4328. if (wake) {
  4329. percpu_ref_reinit(&q->mq_usage_counter);
  4330. - wake_up_all(&q->mq_freeze_wq);
  4331. + swait_wake_all(&q->mq_freeze_wq);
  4332. }
  4333. }
  4334. EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
  4335. @@ -170,7 +170,7 @@
  4336. * dying, we need to ensure that processes currently waiting on
  4337. * the queue are notified as well.
  4338. */
  4339. - wake_up_all(&q->mq_freeze_wq);
  4340. + swait_wake_all(&q->mq_freeze_wq);
  4341. }
  4342. bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
  4343. @@ -217,6 +217,9 @@
  4344. rq->resid_len = 0;
  4345. rq->sense = NULL;
  4346. +#ifdef CONFIG_PREEMPT_RT_FULL
  4347. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  4348. +#endif
  4349. INIT_LIST_HEAD(&rq->timeout_list);
  4350. rq->timeout = 0;
  4351. @@ -346,6 +349,17 @@
  4352. }
  4353. EXPORT_SYMBOL(blk_mq_end_request);
  4354. +#ifdef CONFIG_PREEMPT_RT_FULL
  4355. +
  4356. +void __blk_mq_complete_request_remote_work(struct work_struct *work)
  4357. +{
  4358. + struct request *rq = container_of(work, struct request, work);
  4359. +
  4360. + rq->q->softirq_done_fn(rq);
  4361. +}
  4362. +
  4363. +#else
  4364. +
  4365. static void __blk_mq_complete_request_remote(void *data)
  4366. {
  4367. struct request *rq = data;
  4368. @@ -353,6 +367,8 @@
  4369. rq->q->softirq_done_fn(rq);
  4370. }
  4371. +#endif
  4372. +
  4373. static void blk_mq_ipi_complete_request(struct request *rq)
  4374. {
  4375. struct blk_mq_ctx *ctx = rq->mq_ctx;
  4376. @@ -364,19 +380,23 @@
  4377. return;
  4378. }
  4379. - cpu = get_cpu();
  4380. + cpu = get_cpu_light();
  4381. if (!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
  4382. shared = cpus_share_cache(cpu, ctx->cpu);
  4383. if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
  4384. +#ifdef CONFIG_PREEMPT_RT_FULL
  4385. + schedule_work_on(ctx->cpu, &rq->work);
  4386. +#else
  4387. rq->csd.func = __blk_mq_complete_request_remote;
  4388. rq->csd.info = rq;
  4389. rq->csd.flags = 0;
  4390. smp_call_function_single_async(ctx->cpu, &rq->csd);
  4391. +#endif
  4392. } else {
  4393. rq->q->softirq_done_fn(rq);
  4394. }
  4395. - put_cpu();
  4396. + put_cpu_light();
  4397. }
  4398. void __blk_mq_complete_request(struct request *rq)
  4399. @@ -905,14 +925,14 @@
  4400. return;
  4401. if (!async) {
  4402. - int cpu = get_cpu();
  4403. + int cpu = get_cpu_light();
  4404. if (cpumask_test_cpu(cpu, hctx->cpumask)) {
  4405. __blk_mq_run_hw_queue(hctx);
  4406. - put_cpu();
  4407. + put_cpu_light();
  4408. return;
  4409. }
  4410. - put_cpu();
  4411. + put_cpu_light();
  4412. }
  4413. kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
  4414. @@ -1589,7 +1609,7 @@
  4415. {
  4416. struct blk_mq_hw_ctx *hctx = data;
  4417. - if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
  4418. + if (action == CPU_POST_DEAD)
  4419. return blk_mq_hctx_cpu_offline(hctx, cpu);
  4420. /*
  4421. diff -Nur linux-4.1.26.orig/block/blk-mq-cpu.c linux-4.1.26/block/blk-mq-cpu.c
  4422. --- linux-4.1.26.orig/block/blk-mq-cpu.c 2016-06-07 01:13:11.000000000 +0200
  4423. +++ linux-4.1.26/block/blk-mq-cpu.c 2016-06-19 15:30:58.623294881 +0200
  4424. @@ -16,7 +16,7 @@
  4425. #include "blk-mq.h"
  4426. static LIST_HEAD(blk_mq_cpu_notify_list);
  4427. -static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
  4428. +static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
  4429. static int blk_mq_main_cpu_notify(struct notifier_block *self,
  4430. unsigned long action, void *hcpu)
  4431. @@ -25,7 +25,10 @@
  4432. struct blk_mq_cpu_notifier *notify;
  4433. int ret = NOTIFY_OK;
  4434. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4435. + if (action != CPU_POST_DEAD)
  4436. + return NOTIFY_OK;
  4437. +
  4438. + spin_lock(&blk_mq_cpu_notify_lock);
  4439. list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
  4440. ret = notify->notify(notify->data, action, cpu);
  4441. @@ -33,7 +36,7 @@
  4442. break;
  4443. }
  4444. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4445. + spin_unlock(&blk_mq_cpu_notify_lock);
  4446. return ret;
  4447. }
  4448. @@ -41,16 +44,16 @@
  4449. {
  4450. BUG_ON(!notifier->notify);
  4451. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4452. + spin_lock(&blk_mq_cpu_notify_lock);
  4453. list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
  4454. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4455. + spin_unlock(&blk_mq_cpu_notify_lock);
  4456. }
  4457. void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
  4458. {
  4459. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4460. + spin_lock(&blk_mq_cpu_notify_lock);
  4461. list_del(&notifier->list);
  4462. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4463. + spin_unlock(&blk_mq_cpu_notify_lock);
  4464. }
  4465. void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
  4466. diff -Nur linux-4.1.26.orig/block/blk-mq.h linux-4.1.26/block/blk-mq.h
  4467. --- linux-4.1.26.orig/block/blk-mq.h 2016-06-07 01:13:11.000000000 +0200
  4468. +++ linux-4.1.26/block/blk-mq.h 2016-06-19 15:30:58.623294881 +0200
  4469. @@ -76,7 +76,10 @@
  4470. static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
  4471. unsigned int cpu)
  4472. {
  4473. - return per_cpu_ptr(q->queue_ctx, cpu);
  4474. + struct blk_mq_ctx *ctx;
  4475. +
  4476. + ctx = per_cpu_ptr(q->queue_ctx, cpu);
  4477. + return ctx;
  4478. }
  4479. /*
  4480. @@ -87,12 +90,12 @@
  4481. */
  4482. static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
  4483. {
  4484. - return __blk_mq_get_ctx(q, get_cpu());
  4485. + return __blk_mq_get_ctx(q, get_cpu_light());
  4486. }
  4487. static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
  4488. {
  4489. - put_cpu();
  4490. + put_cpu_light();
  4491. }
  4492. struct blk_mq_alloc_data {
  4493. diff -Nur linux-4.1.26.orig/block/blk-softirq.c linux-4.1.26/block/blk-softirq.c
  4494. --- linux-4.1.26.orig/block/blk-softirq.c 2016-06-07 01:13:11.000000000 +0200
  4495. +++ linux-4.1.26/block/blk-softirq.c 2016-06-19 15:30:58.623294881 +0200
  4496. @@ -51,6 +51,7 @@
  4497. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  4498. local_irq_restore(flags);
  4499. + preempt_check_resched_rt();
  4500. }
  4501. /*
  4502. @@ -93,6 +94,7 @@
  4503. this_cpu_ptr(&blk_cpu_done));
  4504. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  4505. local_irq_enable();
  4506. + preempt_check_resched_rt();
  4507. }
  4508. return NOTIFY_OK;
  4509. @@ -150,6 +152,7 @@
  4510. goto do_local;
  4511. local_irq_restore(flags);
  4512. + preempt_check_resched_rt();
  4513. }
  4514. /**
  4515. diff -Nur linux-4.1.26.orig/block/bounce.c linux-4.1.26/block/bounce.c
  4516. --- linux-4.1.26.orig/block/bounce.c 2016-06-07 01:13:11.000000000 +0200
  4517. +++ linux-4.1.26/block/bounce.c 2016-06-19 15:30:58.623294881 +0200
  4518. @@ -54,11 +54,11 @@
  4519. unsigned long flags;
  4520. unsigned char *vto;
  4521. - local_irq_save(flags);
  4522. + local_irq_save_nort(flags);
  4523. vto = kmap_atomic(to->bv_page);
  4524. memcpy(vto + to->bv_offset, vfrom, to->bv_len);
  4525. kunmap_atomic(vto);
  4526. - local_irq_restore(flags);
  4527. + local_irq_restore_nort(flags);
  4528. }
  4529. #else /* CONFIG_HIGHMEM */
  4530. diff -Nur linux-4.1.26.orig/crypto/algapi.c linux-4.1.26/crypto/algapi.c
  4531. --- linux-4.1.26.orig/crypto/algapi.c 2016-06-07 01:13:11.000000000 +0200
  4532. +++ linux-4.1.26/crypto/algapi.c 2016-06-19 15:30:58.623294881 +0200
  4533. @@ -695,13 +695,13 @@
  4534. int crypto_register_notifier(struct notifier_block *nb)
  4535. {
  4536. - return blocking_notifier_chain_register(&crypto_chain, nb);
  4537. + return srcu_notifier_chain_register(&crypto_chain, nb);
  4538. }
  4539. EXPORT_SYMBOL_GPL(crypto_register_notifier);
  4540. int crypto_unregister_notifier(struct notifier_block *nb)
  4541. {
  4542. - return blocking_notifier_chain_unregister(&crypto_chain, nb);
  4543. + return srcu_notifier_chain_unregister(&crypto_chain, nb);
  4544. }
  4545. EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
  4546. diff -Nur linux-4.1.26.orig/crypto/api.c linux-4.1.26/crypto/api.c
  4547. --- linux-4.1.26.orig/crypto/api.c 2016-06-07 01:13:11.000000000 +0200
  4548. +++ linux-4.1.26/crypto/api.c 2016-06-19 15:30:58.623294881 +0200
  4549. @@ -31,7 +31,7 @@
  4550. DECLARE_RWSEM(crypto_alg_sem);
  4551. EXPORT_SYMBOL_GPL(crypto_alg_sem);
  4552. -BLOCKING_NOTIFIER_HEAD(crypto_chain);
  4553. +SRCU_NOTIFIER_HEAD(crypto_chain);
  4554. EXPORT_SYMBOL_GPL(crypto_chain);
  4555. static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
  4556. @@ -236,10 +236,10 @@
  4557. {
  4558. int ok;
  4559. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  4560. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  4561. if (ok == NOTIFY_DONE) {
  4562. request_module("cryptomgr");
  4563. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  4564. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  4565. }
  4566. return ok;
  4567. diff -Nur linux-4.1.26.orig/crypto/internal.h linux-4.1.26/crypto/internal.h
  4568. --- linux-4.1.26.orig/crypto/internal.h 2016-06-07 01:13:11.000000000 +0200
  4569. +++ linux-4.1.26/crypto/internal.h 2016-06-19 15:30:58.623294881 +0200
  4570. @@ -48,7 +48,7 @@
  4571. extern struct list_head crypto_alg_list;
  4572. extern struct rw_semaphore crypto_alg_sem;
  4573. -extern struct blocking_notifier_head crypto_chain;
  4574. +extern struct srcu_notifier_head crypto_chain;
  4575. #ifdef CONFIG_PROC_FS
  4576. void __init crypto_init_proc(void);
  4577. @@ -142,7 +142,7 @@
  4578. static inline void crypto_notify(unsigned long val, void *v)
  4579. {
  4580. - blocking_notifier_call_chain(&crypto_chain, val, v);
  4581. + srcu_notifier_call_chain(&crypto_chain, val, v);
  4582. }
  4583. #endif /* _CRYPTO_INTERNAL_H */
  4584. diff -Nur linux-4.1.26.orig/Documentation/hwlat_detector.txt linux-4.1.26/Documentation/hwlat_detector.txt
  4585. --- linux-4.1.26.orig/Documentation/hwlat_detector.txt 1970-01-01 01:00:00.000000000 +0100
  4586. +++ linux-4.1.26/Documentation/hwlat_detector.txt 2016-06-19 15:30:54.915151887 +0200
  4587. @@ -0,0 +1,64 @@
  4588. +Introduction:
  4589. +-------------
  4590. +
  4591. +The module hwlat_detector is a special purpose kernel module that is used to
  4592. +detect large system latencies induced by the behavior of certain underlying
  4593. +hardware or firmware, independent of Linux itself. The code was developed
  4594. +originally to detect SMIs (System Management Interrupts) on x86 systems,
  4595. +however there is nothing x86 specific about this patchset. It was
  4596. +originally written for use by the "RT" patch since the Real Time
  4597. +kernel is highly latency sensitive.
  4598. +
  4599. +SMIs are usually not serviced by the Linux kernel, which typically does not
  4600. +even know that they are occuring. SMIs are instead are set up by BIOS code
  4601. +and are serviced by BIOS code, usually for "critical" events such as
  4602. +management of thermal sensors and fans. Sometimes though, SMIs are used for
  4603. +other tasks and those tasks can spend an inordinate amount of time in the
  4604. +handler (sometimes measured in milliseconds). Obviously this is a problem if
  4605. +you are trying to keep event service latencies down in the microsecond range.
  4606. +
  4607. +The hardware latency detector works by hogging all of the cpus for configurable
  4608. +amounts of time (by calling stop_machine()), polling the CPU Time Stamp Counter
  4609. +for some period, then looking for gaps in the TSC data. Any gap indicates a
  4610. +time when the polling was interrupted and since the machine is stopped and
  4611. +interrupts turned off the only thing that could do that would be an SMI.
  4612. +
  4613. +Note that the SMI detector should *NEVER* be used in a production environment.
  4614. +It is intended to be run manually to determine if the hardware platform has a
  4615. +problem with long system firmware service routines.
  4616. +
  4617. +Usage:
  4618. +------
  4619. +
  4620. +Loading the module hwlat_detector passing the parameter "enabled=1" (or by
  4621. +setting the "enable" entry in "hwlat_detector" debugfs toggled on) is the only
  4622. +step required to start the hwlat_detector. It is possible to redefine the
  4623. +threshold in microseconds (us) above which latency spikes will be taken
  4624. +into account (parameter "threshold=").
  4625. +
  4626. +Example:
  4627. +
  4628. + # modprobe hwlat_detector enabled=1 threshold=100
  4629. +
  4630. +After the module is loaded, it creates a directory named "hwlat_detector" under
  4631. +the debugfs mountpoint, "/debug/hwlat_detector" for this text. It is necessary
  4632. +to have debugfs mounted, which might be on /sys/debug on your system.
  4633. +
  4634. +The /debug/hwlat_detector interface contains the following files:
  4635. +
  4636. +count - number of latency spikes observed since last reset
  4637. +enable - a global enable/disable toggle (0/1), resets count
  4638. +max - maximum hardware latency actually observed (usecs)
  4639. +sample - a pipe from which to read current raw sample data
  4640. + in the format <timestamp> <latency observed usecs>
  4641. + (can be opened O_NONBLOCK for a single sample)
  4642. +threshold - minimum latency value to be considered (usecs)
  4643. +width - time period to sample with CPUs held (usecs)
  4644. + must be less than the total window size (enforced)
  4645. +window - total period of sampling, width being inside (usecs)
  4646. +
  4647. +By default we will set width to 500,000 and window to 1,000,000, meaning that
  4648. +we will sample every 1,000,000 usecs (1s) for 500,000 usecs (0.5s). If we
  4649. +observe any latencies that exceed the threshold (initially 100 usecs),
  4650. +then we write to a global sample ring buffer of 8K samples, which is
  4651. +consumed by reading from the "sample" (pipe) debugfs file interface.
  4652. diff -Nur linux-4.1.26.orig/Documentation/sysrq.txt linux-4.1.26/Documentation/sysrq.txt
  4653. --- linux-4.1.26.orig/Documentation/sysrq.txt 2016-06-07 01:13:11.000000000 +0200
  4654. +++ linux-4.1.26/Documentation/sysrq.txt 2016-06-19 15:30:54.915151887 +0200
  4655. @@ -59,10 +59,17 @@
  4656. On other - If you know of the key combos for other architectures, please
  4657. let me know so I can add them to this section.
  4658. -On all - write a character to /proc/sysrq-trigger. e.g.:
  4659. -
  4660. +On all - write a character to /proc/sysrq-trigger, e.g.:
  4661. echo t > /proc/sysrq-trigger
  4662. +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
  4663. + echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
  4664. + Send an ICMP echo request with this pattern plus the particular
  4665. + SysRq command key. Example:
  4666. + # ping -c1 -s57 -p0102030468
  4667. + will trigger the SysRq-H (help) command.
  4668. +
  4669. +
  4670. * What are the 'command' keys?
  4671. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4672. 'b' - Will immediately reboot the system without syncing or unmounting
  4673. diff -Nur linux-4.1.26.orig/Documentation/trace/histograms.txt linux-4.1.26/Documentation/trace/histograms.txt
  4674. --- linux-4.1.26.orig/Documentation/trace/histograms.txt 1970-01-01 01:00:00.000000000 +0100
  4675. +++ linux-4.1.26/Documentation/trace/histograms.txt 2016-06-19 15:30:54.915151887 +0200
  4676. @@ -0,0 +1,186 @@
  4677. + Using the Linux Kernel Latency Histograms
  4678. +
  4679. +
  4680. +This document gives a short explanation how to enable, configure and use
  4681. +latency histograms. Latency histograms are primarily relevant in the
  4682. +context of real-time enabled kernels (CONFIG_PREEMPT/CONFIG_PREEMPT_RT)
  4683. +and are used in the quality management of the Linux real-time
  4684. +capabilities.
  4685. +
  4686. +
  4687. +* Purpose of latency histograms
  4688. +
  4689. +A latency histogram continuously accumulates the frequencies of latency
  4690. +data. There are two types of histograms
  4691. +- potential sources of latencies
  4692. +- effective latencies
  4693. +
  4694. +
  4695. +* Potential sources of latencies
  4696. +
  4697. +Potential sources of latencies are code segments where interrupts,
  4698. +preemption or both are disabled (aka critical sections). To create
  4699. +histograms of potential sources of latency, the kernel stores the time
  4700. +stamp at the start of a critical section, determines the time elapsed
  4701. +when the end of the section is reached, and increments the frequency
  4702. +counter of that latency value - irrespective of whether any concurrently
  4703. +running process is affected by latency or not.
  4704. +- Configuration items (in the Kernel hacking/Tracers submenu)
  4705. + CONFIG_INTERRUPT_OFF_LATENCY
  4706. + CONFIG_PREEMPT_OFF_LATENCY
  4707. +
  4708. +
  4709. +* Effective latencies
  4710. +
  4711. +Effective latencies are actually occuring during wakeup of a process. To
  4712. +determine effective latencies, the kernel stores the time stamp when a
  4713. +process is scheduled to be woken up, and determines the duration of the
  4714. +wakeup time shortly before control is passed over to this process. Note
  4715. +that the apparent latency in user space may be somewhat longer, since the
  4716. +process may be interrupted after control is passed over to it but before
  4717. +the execution in user space takes place. Simply measuring the interval
  4718. +between enqueuing and wakeup may also not appropriate in cases when a
  4719. +process is scheduled as a result of a timer expiration. The timer may have
  4720. +missed its deadline, e.g. due to disabled interrupts, but this latency
  4721. +would not be registered. Therefore, the offsets of missed timers are
  4722. +recorded in a separate histogram. If both wakeup latency and missed timer
  4723. +offsets are configured and enabled, a third histogram may be enabled that
  4724. +records the overall latency as a sum of the timer latency, if any, and the
  4725. +wakeup latency. This histogram is called "timerandwakeup".
  4726. +- Configuration items (in the Kernel hacking/Tracers submenu)
  4727. + CONFIG_WAKEUP_LATENCY
  4728. + CONFIG_MISSED_TIMER_OFSETS
  4729. +
  4730. +
  4731. +* Usage
  4732. +
  4733. +The interface to the administration of the latency histograms is located
  4734. +in the debugfs file system. To mount it, either enter
  4735. +
  4736. +mount -t sysfs nodev /sys
  4737. +mount -t debugfs nodev /sys/kernel/debug
  4738. +
  4739. +from shell command line level, or add
  4740. +
  4741. +nodev /sys sysfs defaults 0 0
  4742. +nodev /sys/kernel/debug debugfs defaults 0 0
  4743. +
  4744. +to the file /etc/fstab. All latency histogram related files are then
  4745. +available in the directory /sys/kernel/debug/tracing/latency_hist. A
  4746. +particular histogram type is enabled by writing non-zero to the related
  4747. +variable in the /sys/kernel/debug/tracing/latency_hist/enable directory.
  4748. +Select "preemptirqsoff" for the histograms of potential sources of
  4749. +latencies and "wakeup" for histograms of effective latencies etc. The
  4750. +histogram data - one per CPU - are available in the files
  4751. +
  4752. +/sys/kernel/debug/tracing/latency_hist/preemptoff/CPUx
  4753. +/sys/kernel/debug/tracing/latency_hist/irqsoff/CPUx
  4754. +/sys/kernel/debug/tracing/latency_hist/preemptirqsoff/CPUx
  4755. +/sys/kernel/debug/tracing/latency_hist/wakeup/CPUx
  4756. +/sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio/CPUx
  4757. +/sys/kernel/debug/tracing/latency_hist/missed_timer_offsets/CPUx
  4758. +/sys/kernel/debug/tracing/latency_hist/timerandwakeup/CPUx
  4759. +
  4760. +The histograms are reset by writing non-zero to the file "reset" in a
  4761. +particular latency directory. To reset all latency data, use
  4762. +
  4763. +#!/bin/sh
  4764. +
  4765. +TRACINGDIR=/sys/kernel/debug/tracing
  4766. +HISTDIR=$TRACINGDIR/latency_hist
  4767. +
  4768. +if test -d $HISTDIR
  4769. +then
  4770. + cd $HISTDIR
  4771. + for i in `find . | grep /reset$`
  4772. + do
  4773. + echo 1 >$i
  4774. + done
  4775. +fi
  4776. +
  4777. +
  4778. +* Data format
  4779. +
  4780. +Latency data are stored with a resolution of one microsecond. The
  4781. +maximum latency is 10,240 microseconds. The data are only valid, if the
  4782. +overflow register is empty. Every output line contains the latency in
  4783. +microseconds in the first row and the number of samples in the second
  4784. +row. To display only lines with a positive latency count, use, for
  4785. +example,
  4786. +
  4787. +grep -v " 0$" /sys/kernel/debug/tracing/latency_hist/preemptoff/CPU0
  4788. +
  4789. +#Minimum latency: 0 microseconds.
  4790. +#Average latency: 0 microseconds.
  4791. +#Maximum latency: 25 microseconds.
  4792. +#Total samples: 3104770694
  4793. +#There are 0 samples greater or equal than 10240 microseconds
  4794. +#usecs samples
  4795. + 0 2984486876
  4796. + 1 49843506
  4797. + 2 58219047
  4798. + 3 5348126
  4799. + 4 2187960
  4800. + 5 3388262
  4801. + 6 959289
  4802. + 7 208294
  4803. + 8 40420
  4804. + 9 4485
  4805. + 10 14918
  4806. + 11 18340
  4807. + 12 25052
  4808. + 13 19455
  4809. + 14 5602
  4810. + 15 969
  4811. + 16 47
  4812. + 17 18
  4813. + 18 14
  4814. + 19 1
  4815. + 20 3
  4816. + 21 2
  4817. + 22 5
  4818. + 23 2
  4819. + 25 1
  4820. +
  4821. +
  4822. +* Wakeup latency of a selected process
  4823. +
  4824. +To only collect wakeup latency data of a particular process, write the
  4825. +PID of the requested process to
  4826. +
  4827. +/sys/kernel/debug/tracing/latency_hist/wakeup/pid
  4828. +
  4829. +PIDs are not considered, if this variable is set to 0.
  4830. +
  4831. +
  4832. +* Details of the process with the highest wakeup latency so far
  4833. +
  4834. +Selected data of the process that suffered from the highest wakeup
  4835. +latency that occurred in a particular CPU are available in the file
  4836. +
  4837. +/sys/kernel/debug/tracing/latency_hist/wakeup/max_latency-CPUx.
  4838. +
  4839. +In addition, other relevant system data at the time when the
  4840. +latency occurred are given.
  4841. +
  4842. +The format of the data is (all in one line):
  4843. +<PID> <Priority> <Latency> (<Timeroffset>) <Command> \
  4844. +<- <PID> <Priority> <Command> <Timestamp>
  4845. +
  4846. +The value of <Timeroffset> is only relevant in the combined timer
  4847. +and wakeup latency recording. In the wakeup recording, it is
  4848. +always 0, in the missed_timer_offsets recording, it is the same
  4849. +as <Latency>.
  4850. +
  4851. +When retrospectively searching for the origin of a latency and
  4852. +tracing was not enabled, it may be helpful to know the name and
  4853. +some basic data of the task that (finally) was switching to the
  4854. +late real-tlme task. In addition to the victim's data, also the
  4855. +data of the possible culprit are therefore displayed after the
  4856. +"<-" symbol.
  4857. +
  4858. +Finally, the timestamp of the time when the latency occurred
  4859. +in <seconds>.<microseconds> after the most recent system boot
  4860. +is provided.
  4861. +
  4862. +These data are also reset when the wakeup histogram is reset.
  4863. diff -Nur linux-4.1.26.orig/drivers/acpi/acpica/acglobal.h linux-4.1.26/drivers/acpi/acpica/acglobal.h
  4864. --- linux-4.1.26.orig/drivers/acpi/acpica/acglobal.h 2016-06-07 01:13:11.000000000 +0200
  4865. +++ linux-4.1.26/drivers/acpi/acpica/acglobal.h 2016-06-19 15:30:58.627295036 +0200
  4866. @@ -112,7 +112,7 @@
  4867. * interrupt level
  4868. */
  4869. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */
  4870. -ACPI_GLOBAL(acpi_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  4871. +ACPI_GLOBAL(acpi_raw_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  4872. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock);
  4873. /* Mutex for _OSI support */
  4874. diff -Nur linux-4.1.26.orig/drivers/acpi/acpica/hwregs.c linux-4.1.26/drivers/acpi/acpica/hwregs.c
  4875. --- linux-4.1.26.orig/drivers/acpi/acpica/hwregs.c 2016-06-07 01:13:11.000000000 +0200
  4876. +++ linux-4.1.26/drivers/acpi/acpica/hwregs.c 2016-06-19 15:30:58.627295036 +0200
  4877. @@ -269,14 +269,14 @@
  4878. ACPI_BITMASK_ALL_FIXED_STATUS,
  4879. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  4880. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  4881. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  4882. /* Clear the fixed events in PM1 A/B */
  4883. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  4884. ACPI_BITMASK_ALL_FIXED_STATUS);
  4885. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  4886. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  4887. if (ACPI_FAILURE(status)) {
  4888. goto exit;
  4889. diff -Nur linux-4.1.26.orig/drivers/acpi/acpica/hwxface.c linux-4.1.26/drivers/acpi/acpica/hwxface.c
  4890. --- linux-4.1.26.orig/drivers/acpi/acpica/hwxface.c 2016-06-07 01:13:11.000000000 +0200
  4891. +++ linux-4.1.26/drivers/acpi/acpica/hwxface.c 2016-06-19 15:30:58.627295036 +0200
  4892. @@ -374,7 +374,7 @@
  4893. return_ACPI_STATUS(AE_BAD_PARAMETER);
  4894. }
  4895. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  4896. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  4897. /*
  4898. * At this point, we know that the parent register is one of the
  4899. @@ -435,7 +435,7 @@
  4900. unlock_and_exit:
  4901. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  4902. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  4903. return_ACPI_STATUS(status);
  4904. }
  4905. diff -Nur linux-4.1.26.orig/drivers/acpi/acpica/utmutex.c linux-4.1.26/drivers/acpi/acpica/utmutex.c
  4906. --- linux-4.1.26.orig/drivers/acpi/acpica/utmutex.c 2016-06-07 01:13:11.000000000 +0200
  4907. +++ linux-4.1.26/drivers/acpi/acpica/utmutex.c 2016-06-19 15:30:58.627295036 +0200
  4908. @@ -88,7 +88,7 @@
  4909. return_ACPI_STATUS (status);
  4910. }
  4911. - status = acpi_os_create_lock (&acpi_gbl_hardware_lock);
  4912. + status = acpi_os_create_raw_lock (&acpi_gbl_hardware_lock);
  4913. if (ACPI_FAILURE (status)) {
  4914. return_ACPI_STATUS (status);
  4915. }
  4916. @@ -141,7 +141,7 @@
  4917. /* Delete the spinlocks */
  4918. acpi_os_delete_lock(acpi_gbl_gpe_lock);
  4919. - acpi_os_delete_lock(acpi_gbl_hardware_lock);
  4920. + acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
  4921. acpi_os_delete_lock(acpi_gbl_reference_count_lock);
  4922. /* Delete the reader/writer lock */
  4923. diff -Nur linux-4.1.26.orig/drivers/ata/libata-sff.c linux-4.1.26/drivers/ata/libata-sff.c
  4924. --- linux-4.1.26.orig/drivers/ata/libata-sff.c 2016-06-07 01:13:11.000000000 +0200
  4925. +++ linux-4.1.26/drivers/ata/libata-sff.c 2016-06-19 15:30:58.627295036 +0200
  4926. @@ -678,9 +678,9 @@
  4927. unsigned long flags;
  4928. unsigned int consumed;
  4929. - local_irq_save(flags);
  4930. + local_irq_save_nort(flags);
  4931. consumed = ata_sff_data_xfer32(dev, buf, buflen, rw);
  4932. - local_irq_restore(flags);
  4933. + local_irq_restore_nort(flags);
  4934. return consumed;
  4935. }
  4936. @@ -719,7 +719,7 @@
  4937. unsigned long flags;
  4938. /* FIXME: use a bounce buffer */
  4939. - local_irq_save(flags);
  4940. + local_irq_save_nort(flags);
  4941. buf = kmap_atomic(page);
  4942. /* do the actual data transfer */
  4943. @@ -727,7 +727,7 @@
  4944. do_write);
  4945. kunmap_atomic(buf);
  4946. - local_irq_restore(flags);
  4947. + local_irq_restore_nort(flags);
  4948. } else {
  4949. buf = page_address(page);
  4950. ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size,
  4951. @@ -864,7 +864,7 @@
  4952. unsigned long flags;
  4953. /* FIXME: use bounce buffer */
  4954. - local_irq_save(flags);
  4955. + local_irq_save_nort(flags);
  4956. buf = kmap_atomic(page);
  4957. /* do the actual data transfer */
  4958. @@ -872,7 +872,7 @@
  4959. count, rw);
  4960. kunmap_atomic(buf);
  4961. - local_irq_restore(flags);
  4962. + local_irq_restore_nort(flags);
  4963. } else {
  4964. buf = page_address(page);
  4965. consumed = ap->ops->sff_data_xfer(dev, buf + offset,
  4966. diff -Nur linux-4.1.26.orig/drivers/char/random.c linux-4.1.26/drivers/char/random.c
  4967. --- linux-4.1.26.orig/drivers/char/random.c 2016-06-07 01:13:11.000000000 +0200
  4968. +++ linux-4.1.26/drivers/char/random.c 2016-06-19 15:30:58.627295036 +0200
  4969. @@ -776,8 +776,6 @@
  4970. } sample;
  4971. long delta, delta2, delta3;
  4972. - preempt_disable();
  4973. -
  4974. sample.jiffies = jiffies;
  4975. sample.cycles = random_get_entropy();
  4976. sample.num = num;
  4977. @@ -818,7 +816,6 @@
  4978. */
  4979. credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
  4980. }
  4981. - preempt_enable();
  4982. }
  4983. void add_input_randomness(unsigned int type, unsigned int code,
  4984. @@ -871,28 +868,27 @@
  4985. return *(ptr + f->reg_idx++);
  4986. }
  4987. -void add_interrupt_randomness(int irq, int irq_flags)
  4988. +void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
  4989. {
  4990. struct entropy_store *r;
  4991. struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
  4992. - struct pt_regs *regs = get_irq_regs();
  4993. unsigned long now = jiffies;
  4994. cycles_t cycles = random_get_entropy();
  4995. __u32 c_high, j_high;
  4996. - __u64 ip;
  4997. unsigned long seed;
  4998. int credit = 0;
  4999. if (cycles == 0)
  5000. - cycles = get_reg(fast_pool, regs);
  5001. + cycles = get_reg(fast_pool, NULL);
  5002. c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0;
  5003. j_high = (sizeof(now) > 4) ? now >> 32 : 0;
  5004. fast_pool->pool[0] ^= cycles ^ j_high ^ irq;
  5005. fast_pool->pool[1] ^= now ^ c_high;
  5006. - ip = regs ? instruction_pointer(regs) : _RET_IP_;
  5007. + if (!ip)
  5008. + ip = _RET_IP_;
  5009. fast_pool->pool[2] ^= ip;
  5010. fast_pool->pool[3] ^= (sizeof(ip) > 4) ? ip >> 32 :
  5011. - get_reg(fast_pool, regs);
  5012. + get_reg(fast_pool, NULL);
  5013. fast_mix(fast_pool);
  5014. add_interrupt_bench(cycles);
  5015. diff -Nur linux-4.1.26.orig/drivers/clocksource/tcb_clksrc.c linux-4.1.26/drivers/clocksource/tcb_clksrc.c
  5016. --- linux-4.1.26.orig/drivers/clocksource/tcb_clksrc.c 2016-06-07 01:13:11.000000000 +0200
  5017. +++ linux-4.1.26/drivers/clocksource/tcb_clksrc.c 2016-06-19 15:30:58.627295036 +0200
  5018. @@ -23,8 +23,7 @@
  5019. * this 32 bit free-running counter. the second channel is not used.
  5020. *
  5021. * - The third channel may be used to provide a 16-bit clockevent
  5022. - * source, used in either periodic or oneshot mode. This runs
  5023. - * at 32 KiHZ, and can handle delays of up to two seconds.
  5024. + * source, used in either periodic or oneshot mode.
  5025. *
  5026. * A boot clocksource and clockevent source are also currently needed,
  5027. * unless the relevant platforms (ARM/AT91, AVR32/AT32) are changed so
  5028. @@ -74,6 +73,7 @@
  5029. struct tc_clkevt_device {
  5030. struct clock_event_device clkevt;
  5031. struct clk *clk;
  5032. + u32 freq;
  5033. void __iomem *regs;
  5034. };
  5035. @@ -82,13 +82,6 @@
  5036. return container_of(clkevt, struct tc_clkevt_device, clkevt);
  5037. }
  5038. -/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
  5039. - * because using one of the divided clocks would usually mean the
  5040. - * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
  5041. - *
  5042. - * A divided clock could be good for high resolution timers, since
  5043. - * 30.5 usec resolution can seem "low".
  5044. - */
  5045. static u32 timer_clock;
  5046. static void tc_mode(enum clock_event_mode m, struct clock_event_device *d)
  5047. @@ -111,11 +104,12 @@
  5048. case CLOCK_EVT_MODE_PERIODIC:
  5049. clk_enable(tcd->clk);
  5050. - /* slow clock, count up to RC, then irq and restart */
  5051. + /* count up to RC, then irq and restart */
  5052. __raw_writel(timer_clock
  5053. | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  5054. regs + ATMEL_TC_REG(2, CMR));
  5055. - __raw_writel((32768 + HZ/2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  5056. + __raw_writel((tcd->freq + HZ / 2) / HZ,
  5057. + tcaddr + ATMEL_TC_REG(2, RC));
  5058. /* Enable clock and interrupts on RC compare */
  5059. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  5060. @@ -128,7 +122,7 @@
  5061. case CLOCK_EVT_MODE_ONESHOT:
  5062. clk_enable(tcd->clk);
  5063. - /* slow clock, count up to RC, then irq and stop */
  5064. + /* count up to RC, then irq and stop */
  5065. __raw_writel(timer_clock | ATMEL_TC_CPCSTOP
  5066. | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  5067. regs + ATMEL_TC_REG(2, CMR));
  5068. @@ -157,8 +151,12 @@
  5069. .name = "tc_clkevt",
  5070. .features = CLOCK_EVT_FEAT_PERIODIC
  5071. | CLOCK_EVT_FEAT_ONESHOT,
  5072. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  5073. /* Should be lower than at91rm9200's system timer */
  5074. .rating = 125,
  5075. +#else
  5076. + .rating = 200,
  5077. +#endif
  5078. .set_next_event = tc_next_event,
  5079. .set_mode = tc_mode,
  5080. },
  5081. @@ -178,8 +176,9 @@
  5082. return IRQ_NONE;
  5083. }
  5084. -static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
  5085. +static int __init setup_clkevents(struct atmel_tc *tc, int divisor_idx)
  5086. {
  5087. + unsigned divisor = atmel_tc_divisors[divisor_idx];
  5088. int ret;
  5089. struct clk *t2_clk = tc->clk[2];
  5090. int irq = tc->irq[2];
  5091. @@ -193,7 +192,11 @@
  5092. clkevt.regs = tc->regs;
  5093. clkevt.clk = t2_clk;
  5094. - timer_clock = clk32k_divisor_idx;
  5095. + timer_clock = divisor_idx;
  5096. + if (!divisor)
  5097. + clkevt.freq = 32768;
  5098. + else
  5099. + clkevt.freq = clk_get_rate(t2_clk) / divisor;
  5100. clkevt.clkevt.cpumask = cpumask_of(0);
  5101. @@ -203,7 +206,7 @@
  5102. return ret;
  5103. }
  5104. - clockevents_config_and_register(&clkevt.clkevt, 32768, 1, 0xffff);
  5105. + clockevents_config_and_register(&clkevt.clkevt, clkevt.freq, 1, 0xffff);
  5106. return ret;
  5107. }
  5108. @@ -340,7 +343,11 @@
  5109. goto err_disable_t1;
  5110. /* channel 2: periodic and oneshot timer support */
  5111. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  5112. ret = setup_clkevents(tc, clk32k_divisor_idx);
  5113. +#else
  5114. + ret = setup_clkevents(tc, best_divisor_idx);
  5115. +#endif
  5116. if (ret)
  5117. goto err_unregister_clksrc;
  5118. diff -Nur linux-4.1.26.orig/drivers/clocksource/timer-atmel-pit.c linux-4.1.26/drivers/clocksource/timer-atmel-pit.c
  5119. --- linux-4.1.26.orig/drivers/clocksource/timer-atmel-pit.c 2016-06-07 01:13:11.000000000 +0200
  5120. +++ linux-4.1.26/drivers/clocksource/timer-atmel-pit.c 2016-06-19 15:30:58.627295036 +0200
  5121. @@ -90,6 +90,7 @@
  5122. return elapsed;
  5123. }
  5124. +static struct irqaction at91sam926x_pit_irq;
  5125. /*
  5126. * Clockevent device: interrupts every 1/HZ (== pit_cycles * MCK/16)
  5127. */
  5128. @@ -100,6 +101,8 @@
  5129. switch (mode) {
  5130. case CLOCK_EVT_MODE_PERIODIC:
  5131. + /* Set up irq handler */
  5132. + setup_irq(at91sam926x_pit_irq.irq, &at91sam926x_pit_irq);
  5133. /* update clocksource counter */
  5134. data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
  5135. pit_write(data->base, AT91_PIT_MR,
  5136. @@ -113,6 +116,7 @@
  5137. /* disable irq, leaving the clocksource active */
  5138. pit_write(data->base, AT91_PIT_MR,
  5139. (data->cycle - 1) | AT91_PIT_PITEN);
  5140. + remove_irq(at91sam926x_pit_irq.irq, &at91sam926x_pit_irq);
  5141. break;
  5142. case CLOCK_EVT_MODE_RESUME:
  5143. break;
  5144. diff -Nur linux-4.1.26.orig/drivers/clocksource/timer-atmel-st.c linux-4.1.26/drivers/clocksource/timer-atmel-st.c
  5145. --- linux-4.1.26.orig/drivers/clocksource/timer-atmel-st.c 2016-06-07 01:13:11.000000000 +0200
  5146. +++ linux-4.1.26/drivers/clocksource/timer-atmel-st.c 2016-06-19 15:30:58.627295036 +0200
  5147. @@ -131,6 +131,7 @@
  5148. break;
  5149. case CLOCK_EVT_MODE_SHUTDOWN:
  5150. case CLOCK_EVT_MODE_UNUSED:
  5151. + remove_irq(NR_IRQS_LEGACY + AT91_ID_SYS, &at91rm9200_timer_irq);
  5152. case CLOCK_EVT_MODE_RESUME:
  5153. irqmask = 0;
  5154. break;
  5155. diff -Nur linux-4.1.26.orig/drivers/cpufreq/cpufreq.c linux-4.1.26/drivers/cpufreq/cpufreq.c
  5156. --- linux-4.1.26.orig/drivers/cpufreq/cpufreq.c 2016-06-07 01:13:11.000000000 +0200
  5157. +++ linux-4.1.26/drivers/cpufreq/cpufreq.c 2016-06-19 15:30:58.627295036 +0200
  5158. @@ -64,12 +64,6 @@
  5159. return cpufreq_driver->target_index || cpufreq_driver->target;
  5160. }
  5161. -/*
  5162. - * rwsem to guarantee that cpufreq driver module doesn't unload during critical
  5163. - * sections
  5164. - */
  5165. -static DECLARE_RWSEM(cpufreq_rwsem);
  5166. -
  5167. /* internal prototypes */
  5168. static int __cpufreq_governor(struct cpufreq_policy *policy,
  5169. unsigned int event);
  5170. @@ -215,9 +209,6 @@
  5171. if (cpu >= nr_cpu_ids)
  5172. return NULL;
  5173. - if (!down_read_trylock(&cpufreq_rwsem))
  5174. - return NULL;
  5175. -
  5176. /* get the cpufreq driver */
  5177. read_lock_irqsave(&cpufreq_driver_lock, flags);
  5178. @@ -230,9 +221,6 @@
  5179. read_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5180. - if (!policy)
  5181. - up_read(&cpufreq_rwsem);
  5182. -
  5183. return policy;
  5184. }
  5185. EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
  5186. @@ -240,7 +228,6 @@
  5187. void cpufreq_cpu_put(struct cpufreq_policy *policy)
  5188. {
  5189. kobject_put(&policy->kobj);
  5190. - up_read(&cpufreq_rwsem);
  5191. }
  5192. EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
  5193. @@ -765,9 +752,6 @@
  5194. struct freq_attr *fattr = to_attr(attr);
  5195. ssize_t ret;
  5196. - if (!down_read_trylock(&cpufreq_rwsem))
  5197. - return -EINVAL;
  5198. -
  5199. down_read(&policy->rwsem);
  5200. if (fattr->show)
  5201. @@ -776,7 +760,6 @@
  5202. ret = -EIO;
  5203. up_read(&policy->rwsem);
  5204. - up_read(&cpufreq_rwsem);
  5205. return ret;
  5206. }
  5207. @@ -793,9 +776,6 @@
  5208. if (!cpu_online(policy->cpu))
  5209. goto unlock;
  5210. - if (!down_read_trylock(&cpufreq_rwsem))
  5211. - goto unlock;
  5212. -
  5213. down_write(&policy->rwsem);
  5214. if (fattr->store)
  5215. @@ -804,8 +784,6 @@
  5216. ret = -EIO;
  5217. up_write(&policy->rwsem);
  5218. -
  5219. - up_read(&cpufreq_rwsem);
  5220. unlock:
  5221. put_online_cpus();
  5222. @@ -1117,16 +1095,12 @@
  5223. if (unlikely(policy))
  5224. return 0;
  5225. - if (!down_read_trylock(&cpufreq_rwsem))
  5226. - return 0;
  5227. -
  5228. /* Check if this cpu was hot-unplugged earlier and has siblings */
  5229. read_lock_irqsave(&cpufreq_driver_lock, flags);
  5230. for_each_policy(policy) {
  5231. if (cpumask_test_cpu(cpu, policy->related_cpus)) {
  5232. read_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5233. ret = cpufreq_add_policy_cpu(policy, cpu, dev);
  5234. - up_read(&cpufreq_rwsem);
  5235. return ret;
  5236. }
  5237. }
  5238. @@ -1269,8 +1243,6 @@
  5239. kobject_uevent(&policy->kobj, KOBJ_ADD);
  5240. - up_read(&cpufreq_rwsem);
  5241. -
  5242. /* Callback for handling stuff after policy is ready */
  5243. if (cpufreq_driver->ready)
  5244. cpufreq_driver->ready(policy);
  5245. @@ -1304,8 +1276,6 @@
  5246. cpufreq_policy_free(policy);
  5247. nomem_out:
  5248. - up_read(&cpufreq_rwsem);
  5249. -
  5250. return ret;
  5251. }
  5252. @@ -2499,19 +2469,20 @@
  5253. pr_debug("unregistering driver %s\n", driver->name);
  5254. + /* Protect against concurrent cpu hotplug */
  5255. + get_online_cpus();
  5256. subsys_interface_unregister(&cpufreq_interface);
  5257. if (cpufreq_boost_supported())
  5258. cpufreq_sysfs_remove_file(&boost.attr);
  5259. unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
  5260. - down_write(&cpufreq_rwsem);
  5261. write_lock_irqsave(&cpufreq_driver_lock, flags);
  5262. cpufreq_driver = NULL;
  5263. write_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5264. - up_write(&cpufreq_rwsem);
  5265. + put_online_cpus();
  5266. return 0;
  5267. }
  5268. diff -Nur linux-4.1.26.orig/drivers/cpufreq/Kconfig.x86 linux-4.1.26/drivers/cpufreq/Kconfig.x86
  5269. --- linux-4.1.26.orig/drivers/cpufreq/Kconfig.x86 2016-06-07 01:13:11.000000000 +0200
  5270. +++ linux-4.1.26/drivers/cpufreq/Kconfig.x86 2016-06-19 15:30:58.627295036 +0200
  5271. @@ -123,7 +123,7 @@
  5272. config X86_POWERNOW_K8
  5273. tristate "AMD Opteron/Athlon64 PowerNow!"
  5274. - depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ
  5275. + depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ && !PREEMPT_RT_BASE
  5276. help
  5277. This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors.
  5278. Support for K10 and newer processors is now in acpi-cpufreq.
  5279. diff -Nur linux-4.1.26.orig/drivers/gpio/gpio-omap.c linux-4.1.26/drivers/gpio/gpio-omap.c
  5280. --- linux-4.1.26.orig/drivers/gpio/gpio-omap.c 2016-06-07 01:13:11.000000000 +0200
  5281. +++ linux-4.1.26/drivers/gpio/gpio-omap.c 2016-06-19 15:30:58.631295190 +0200
  5282. @@ -29,6 +29,7 @@
  5283. #include <linux/platform_data/gpio-omap.h>
  5284. #define OFF_MODE 1
  5285. +#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF
  5286. static LIST_HEAD(omap_gpio_list);
  5287. @@ -50,14 +51,15 @@
  5288. struct gpio_bank {
  5289. struct list_head node;
  5290. void __iomem *base;
  5291. - u16 irq;
  5292. + int irq;
  5293. u32 non_wakeup_gpios;
  5294. u32 enabled_non_wakeup_gpios;
  5295. struct gpio_regs context;
  5296. u32 saved_datain;
  5297. u32 level_mask;
  5298. u32 toggle_mask;
  5299. - spinlock_t lock;
  5300. + raw_spinlock_t lock;
  5301. + raw_spinlock_t wa_lock;
  5302. struct gpio_chip chip;
  5303. struct clk *dbck;
  5304. u32 mod_usage;
  5305. @@ -67,7 +69,7 @@
  5306. struct device *dev;
  5307. bool is_mpuio;
  5308. bool dbck_flag;
  5309. - bool loses_context;
  5310. +
  5311. bool context_valid;
  5312. int stride;
  5313. u32 width;
  5314. @@ -175,7 +177,7 @@
  5315. static inline void omap_gpio_dbck_enable(struct gpio_bank *bank)
  5316. {
  5317. if (bank->dbck_enable_mask && !bank->dbck_enabled) {
  5318. - clk_prepare_enable(bank->dbck);
  5319. + clk_enable(bank->dbck);
  5320. bank->dbck_enabled = true;
  5321. writel_relaxed(bank->dbck_enable_mask,
  5322. @@ -193,7 +195,7 @@
  5323. */
  5324. writel_relaxed(0, bank->base + bank->regs->debounce_en);
  5325. - clk_disable_unprepare(bank->dbck);
  5326. + clk_disable(bank->dbck);
  5327. bank->dbck_enabled = false;
  5328. }
  5329. }
  5330. @@ -204,8 +206,9 @@
  5331. * @offset: the gpio number on this @bank
  5332. * @debounce: debounce time to use
  5333. *
  5334. - * OMAP's debounce time is in 31us steps so we need
  5335. - * to convert and round up to the closest unit.
  5336. + * OMAP's debounce time is in 31us steps
  5337. + * <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31
  5338. + * so we need to convert and round up to the closest unit.
  5339. */
  5340. static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
  5341. unsigned debounce)
  5342. @@ -213,34 +216,33 @@
  5343. void __iomem *reg;
  5344. u32 val;
  5345. u32 l;
  5346. + bool enable = !!debounce;
  5347. if (!bank->dbck_flag)
  5348. return;
  5349. - if (debounce < 32)
  5350. - debounce = 0x01;
  5351. - else if (debounce > 7936)
  5352. - debounce = 0xff;
  5353. - else
  5354. - debounce = (debounce / 0x1f) - 1;
  5355. + if (enable) {
  5356. + debounce = DIV_ROUND_UP(debounce, 31) - 1;
  5357. + debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK;
  5358. + }
  5359. l = BIT(offset);
  5360. - clk_prepare_enable(bank->dbck);
  5361. + clk_enable(bank->dbck);
  5362. reg = bank->base + bank->regs->debounce;
  5363. writel_relaxed(debounce, reg);
  5364. reg = bank->base + bank->regs->debounce_en;
  5365. val = readl_relaxed(reg);
  5366. - if (debounce)
  5367. + if (enable)
  5368. val |= l;
  5369. else
  5370. val &= ~l;
  5371. bank->dbck_enable_mask = val;
  5372. writel_relaxed(val, reg);
  5373. - clk_disable_unprepare(bank->dbck);
  5374. + clk_disable(bank->dbck);
  5375. /*
  5376. * Enable debounce clock per module.
  5377. * This call is mandatory because in omap_gpio_request() when
  5378. @@ -285,7 +287,7 @@
  5379. bank->context.debounce = 0;
  5380. writel_relaxed(bank->context.debounce, bank->base +
  5381. bank->regs->debounce);
  5382. - clk_disable_unprepare(bank->dbck);
  5383. + clk_disable(bank->dbck);
  5384. bank->dbck_enabled = false;
  5385. }
  5386. }
  5387. @@ -488,9 +490,6 @@
  5388. unsigned long flags;
  5389. unsigned offset = d->hwirq;
  5390. - if (!BANK_USED(bank))
  5391. - pm_runtime_get_sync(bank->dev);
  5392. -
  5393. if (type & ~IRQ_TYPE_SENSE_MASK)
  5394. return -EINVAL;
  5395. @@ -498,20 +497,28 @@
  5396. (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
  5397. return -EINVAL;
  5398. - spin_lock_irqsave(&bank->lock, flags);
  5399. + raw_spin_lock_irqsave(&bank->lock, flags);
  5400. retval = omap_set_gpio_triggering(bank, offset, type);
  5401. + if (retval) {
  5402. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5403. + goto error;
  5404. + }
  5405. omap_gpio_init_irq(bank, offset);
  5406. if (!omap_gpio_is_input(bank, offset)) {
  5407. - spin_unlock_irqrestore(&bank->lock, flags);
  5408. - return -EINVAL;
  5409. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5410. + retval = -EINVAL;
  5411. + goto error;
  5412. }
  5413. - spin_unlock_irqrestore(&bank->lock, flags);
  5414. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5415. if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  5416. __irq_set_handler_locked(d->irq, handle_level_irq);
  5417. else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
  5418. __irq_set_handler_locked(d->irq, handle_edge_irq);
  5419. + return 0;
  5420. +
  5421. +error:
  5422. return retval;
  5423. }
  5424. @@ -626,34 +633,30 @@
  5425. return -EINVAL;
  5426. }
  5427. - spin_lock_irqsave(&bank->lock, flags);
  5428. + raw_spin_lock_irqsave(&bank->lock, flags);
  5429. if (enable)
  5430. bank->context.wake_en |= gpio_bit;
  5431. else
  5432. bank->context.wake_en &= ~gpio_bit;
  5433. writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
  5434. - spin_unlock_irqrestore(&bank->lock, flags);
  5435. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5436. return 0;
  5437. }
  5438. -static void omap_reset_gpio(struct gpio_bank *bank, unsigned offset)
  5439. -{
  5440. - omap_set_gpio_direction(bank, offset, 1);
  5441. - omap_set_gpio_irqenable(bank, offset, 0);
  5442. - omap_clear_gpio_irqstatus(bank, offset);
  5443. - omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  5444. - omap_clear_gpio_debounce(bank, offset);
  5445. -}
  5446. -
  5447. /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
  5448. static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable)
  5449. {
  5450. struct gpio_bank *bank = omap_irq_data_get_bank(d);
  5451. unsigned offset = d->hwirq;
  5452. + int ret;
  5453. +
  5454. + ret = omap_set_gpio_wakeup(bank, offset, enable);
  5455. + if (!ret)
  5456. + ret = irq_set_irq_wake(bank->irq, enable);
  5457. - return omap_set_gpio_wakeup(bank, offset, enable);
  5458. + return ret;
  5459. }
  5460. static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
  5461. @@ -668,17 +671,10 @@
  5462. if (!BANK_USED(bank))
  5463. pm_runtime_get_sync(bank->dev);
  5464. - spin_lock_irqsave(&bank->lock, flags);
  5465. - /* Set trigger to none. You need to enable the desired trigger with
  5466. - * request_irq() or set_irq_type(). Only do this if the IRQ line has
  5467. - * not already been requested.
  5468. - */
  5469. - if (!LINE_USED(bank->irq_usage, offset)) {
  5470. - omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  5471. - omap_enable_gpio_module(bank, offset);
  5472. - }
  5473. + raw_spin_lock_irqsave(&bank->lock, flags);
  5474. + omap_enable_gpio_module(bank, offset);
  5475. bank->mod_usage |= BIT(offset);
  5476. - spin_unlock_irqrestore(&bank->lock, flags);
  5477. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5478. return 0;
  5479. }
  5480. @@ -688,11 +684,14 @@
  5481. struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
  5482. unsigned long flags;
  5483. - spin_lock_irqsave(&bank->lock, flags);
  5484. + raw_spin_lock_irqsave(&bank->lock, flags);
  5485. bank->mod_usage &= ~(BIT(offset));
  5486. + if (!LINE_USED(bank->irq_usage, offset)) {
  5487. + omap_set_gpio_direction(bank, offset, 1);
  5488. + omap_clear_gpio_debounce(bank, offset);
  5489. + }
  5490. omap_disable_gpio_module(bank, offset);
  5491. - omap_reset_gpio(bank, offset);
  5492. - spin_unlock_irqrestore(&bank->lock, flags);
  5493. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5494. /*
  5495. * If this is the last gpio to be freed in the bank,
  5496. @@ -711,29 +710,27 @@
  5497. * line's interrupt handler has been run, we may miss some nested
  5498. * interrupts.
  5499. */
  5500. -static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  5501. +static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank)
  5502. {
  5503. void __iomem *isr_reg = NULL;
  5504. u32 isr;
  5505. unsigned int bit;
  5506. - struct gpio_bank *bank;
  5507. - int unmasked = 0;
  5508. - struct irq_chip *irqchip = irq_desc_get_chip(desc);
  5509. - struct gpio_chip *chip = irq_get_handler_data(irq);
  5510. + struct gpio_bank *bank = gpiobank;
  5511. + unsigned long wa_lock_flags;
  5512. + unsigned long lock_flags;
  5513. - chained_irq_enter(irqchip, desc);
  5514. -
  5515. - bank = container_of(chip, struct gpio_bank, chip);
  5516. isr_reg = bank->base + bank->regs->irqstatus;
  5517. - pm_runtime_get_sync(bank->dev);
  5518. -
  5519. if (WARN_ON(!isr_reg))
  5520. goto exit;
  5521. + pm_runtime_get_sync(bank->dev);
  5522. +
  5523. while (1) {
  5524. u32 isr_saved, level_mask = 0;
  5525. u32 enabled;
  5526. + raw_spin_lock_irqsave(&bank->lock, lock_flags);
  5527. +
  5528. enabled = omap_get_gpio_irqbank_mask(bank);
  5529. isr_saved = isr = readl_relaxed(isr_reg) & enabled;
  5530. @@ -747,12 +744,7 @@
  5531. omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask);
  5532. omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask);
  5533. - /* if there is only edge sensitive GPIO pin interrupts
  5534. - configured, we could unmask GPIO bank interrupt immediately */
  5535. - if (!level_mask && !unmasked) {
  5536. - unmasked = 1;
  5537. - chained_irq_exit(irqchip, desc);
  5538. - }
  5539. + raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
  5540. if (!isr)
  5541. break;
  5542. @@ -761,6 +753,7 @@
  5543. bit = __ffs(isr);
  5544. isr &= ~(BIT(bit));
  5545. + raw_spin_lock_irqsave(&bank->lock, lock_flags);
  5546. /*
  5547. * Some chips can't respond to both rising and falling
  5548. * at the same time. If this irq was requested with
  5549. @@ -771,18 +764,20 @@
  5550. if (bank->toggle_mask & (BIT(bit)))
  5551. omap_toggle_gpio_edge_triggering(bank, bit);
  5552. + raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
  5553. +
  5554. + raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags);
  5555. +
  5556. generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
  5557. bit));
  5558. +
  5559. + raw_spin_unlock_irqrestore(&bank->wa_lock,
  5560. + wa_lock_flags);
  5561. }
  5562. }
  5563. - /* if bank has any level sensitive GPIO pin interrupt
  5564. - configured, we must unmask the bank interrupt only after
  5565. - handler(s) are executed in order to avoid spurious bank
  5566. - interrupt */
  5567. exit:
  5568. - if (!unmasked)
  5569. - chained_irq_exit(irqchip, desc);
  5570. pm_runtime_put(bank->dev);
  5571. + return IRQ_HANDLED;
  5572. }
  5573. static unsigned int omap_gpio_irq_startup(struct irq_data *d)
  5574. @@ -791,15 +786,22 @@
  5575. unsigned long flags;
  5576. unsigned offset = d->hwirq;
  5577. - if (!BANK_USED(bank))
  5578. - pm_runtime_get_sync(bank->dev);
  5579. + raw_spin_lock_irqsave(&bank->lock, flags);
  5580. - spin_lock_irqsave(&bank->lock, flags);
  5581. - omap_gpio_init_irq(bank, offset);
  5582. - spin_unlock_irqrestore(&bank->lock, flags);
  5583. + if (!LINE_USED(bank->mod_usage, offset))
  5584. + omap_set_gpio_direction(bank, offset, 1);
  5585. + else if (!omap_gpio_is_input(bank, offset))
  5586. + goto err;
  5587. + omap_enable_gpio_module(bank, offset);
  5588. + bank->irq_usage |= BIT(offset);
  5589. +
  5590. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5591. omap_gpio_unmask_irq(d);
  5592. return 0;
  5593. +err:
  5594. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5595. + return -EINVAL;
  5596. }
  5597. static void omap_gpio_irq_shutdown(struct irq_data *d)
  5598. @@ -808,11 +810,28 @@
  5599. unsigned long flags;
  5600. unsigned offset = d->hwirq;
  5601. - spin_lock_irqsave(&bank->lock, flags);
  5602. + raw_spin_lock_irqsave(&bank->lock, flags);
  5603. bank->irq_usage &= ~(BIT(offset));
  5604. + omap_set_gpio_irqenable(bank, offset, 0);
  5605. + omap_clear_gpio_irqstatus(bank, offset);
  5606. + omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  5607. + if (!LINE_USED(bank->mod_usage, offset))
  5608. + omap_clear_gpio_debounce(bank, offset);
  5609. omap_disable_gpio_module(bank, offset);
  5610. - omap_reset_gpio(bank, offset);
  5611. - spin_unlock_irqrestore(&bank->lock, flags);
  5612. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5613. +}
  5614. +
  5615. +static void omap_gpio_irq_bus_lock(struct irq_data *data)
  5616. +{
  5617. + struct gpio_bank *bank = omap_irq_data_get_bank(data);
  5618. +
  5619. + if (!BANK_USED(bank))
  5620. + pm_runtime_get_sync(bank->dev);
  5621. +}
  5622. +
  5623. +static void gpio_irq_bus_sync_unlock(struct irq_data *data)
  5624. +{
  5625. + struct gpio_bank *bank = omap_irq_data_get_bank(data);
  5626. /*
  5627. * If this is the last IRQ to be freed in the bank,
  5628. @@ -836,10 +855,10 @@
  5629. unsigned offset = d->hwirq;
  5630. unsigned long flags;
  5631. - spin_lock_irqsave(&bank->lock, flags);
  5632. + raw_spin_lock_irqsave(&bank->lock, flags);
  5633. omap_set_gpio_irqenable(bank, offset, 0);
  5634. omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  5635. - spin_unlock_irqrestore(&bank->lock, flags);
  5636. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5637. }
  5638. static void omap_gpio_unmask_irq(struct irq_data *d)
  5639. @@ -849,7 +868,7 @@
  5640. u32 trigger = irqd_get_trigger_type(d);
  5641. unsigned long flags;
  5642. - spin_lock_irqsave(&bank->lock, flags);
  5643. + raw_spin_lock_irqsave(&bank->lock, flags);
  5644. if (trigger)
  5645. omap_set_gpio_triggering(bank, offset, trigger);
  5646. @@ -861,7 +880,7 @@
  5647. }
  5648. omap_set_gpio_irqenable(bank, offset, 1);
  5649. - spin_unlock_irqrestore(&bank->lock, flags);
  5650. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5651. }
  5652. /*---------------------------------------------------------------------*/
  5653. @@ -874,9 +893,9 @@
  5654. OMAP_MPUIO_GPIO_MASKIT / bank->stride;
  5655. unsigned long flags;
  5656. - spin_lock_irqsave(&bank->lock, flags);
  5657. + raw_spin_lock_irqsave(&bank->lock, flags);
  5658. writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
  5659. - spin_unlock_irqrestore(&bank->lock, flags);
  5660. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5661. return 0;
  5662. }
  5663. @@ -889,9 +908,9 @@
  5664. OMAP_MPUIO_GPIO_MASKIT / bank->stride;
  5665. unsigned long flags;
  5666. - spin_lock_irqsave(&bank->lock, flags);
  5667. + raw_spin_lock_irqsave(&bank->lock, flags);
  5668. writel_relaxed(bank->context.wake_en, mask_reg);
  5669. - spin_unlock_irqrestore(&bank->lock, flags);
  5670. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5671. return 0;
  5672. }
  5673. @@ -937,9 +956,9 @@
  5674. bank = container_of(chip, struct gpio_bank, chip);
  5675. reg = bank->base + bank->regs->direction;
  5676. - spin_lock_irqsave(&bank->lock, flags);
  5677. + raw_spin_lock_irqsave(&bank->lock, flags);
  5678. dir = !!(readl_relaxed(reg) & BIT(offset));
  5679. - spin_unlock_irqrestore(&bank->lock, flags);
  5680. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5681. return dir;
  5682. }
  5683. @@ -949,9 +968,9 @@
  5684. unsigned long flags;
  5685. bank = container_of(chip, struct gpio_bank, chip);
  5686. - spin_lock_irqsave(&bank->lock, flags);
  5687. + raw_spin_lock_irqsave(&bank->lock, flags);
  5688. omap_set_gpio_direction(bank, offset, 1);
  5689. - spin_unlock_irqrestore(&bank->lock, flags);
  5690. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5691. return 0;
  5692. }
  5693. @@ -973,10 +992,10 @@
  5694. unsigned long flags;
  5695. bank = container_of(chip, struct gpio_bank, chip);
  5696. - spin_lock_irqsave(&bank->lock, flags);
  5697. + raw_spin_lock_irqsave(&bank->lock, flags);
  5698. bank->set_dataout(bank, offset, value);
  5699. omap_set_gpio_direction(bank, offset, 0);
  5700. - spin_unlock_irqrestore(&bank->lock, flags);
  5701. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5702. return 0;
  5703. }
  5704. @@ -988,9 +1007,9 @@
  5705. bank = container_of(chip, struct gpio_bank, chip);
  5706. - spin_lock_irqsave(&bank->lock, flags);
  5707. + raw_spin_lock_irqsave(&bank->lock, flags);
  5708. omap2_set_gpio_debounce(bank, offset, debounce);
  5709. - spin_unlock_irqrestore(&bank->lock, flags);
  5710. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5711. return 0;
  5712. }
  5713. @@ -1001,9 +1020,9 @@
  5714. unsigned long flags;
  5715. bank = container_of(chip, struct gpio_bank, chip);
  5716. - spin_lock_irqsave(&bank->lock, flags);
  5717. + raw_spin_lock_irqsave(&bank->lock, flags);
  5718. bank->set_dataout(bank, offset, value);
  5719. - spin_unlock_irqrestore(&bank->lock, flags);
  5720. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5721. }
  5722. /*---------------------------------------------------------------------*/
  5723. @@ -1048,10 +1067,6 @@
  5724. /* Initialize interface clk ungated, module enabled */
  5725. if (bank->regs->ctrl)
  5726. writel_relaxed(0, base + bank->regs->ctrl);
  5727. -
  5728. - bank->dbck = clk_get(bank->dev, "dbclk");
  5729. - if (IS_ERR(bank->dbck))
  5730. - dev_err(bank->dev, "Could not get gpio dbck\n");
  5731. }
  5732. static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
  5733. @@ -1080,7 +1095,6 @@
  5734. } else {
  5735. bank->chip.label = "gpio";
  5736. bank->chip.base = gpio;
  5737. - gpio += bank->width;
  5738. }
  5739. bank->chip.ngpio = bank->width;
  5740. @@ -1090,6 +1104,9 @@
  5741. return ret;
  5742. }
  5743. + if (!bank->is_mpuio)
  5744. + gpio += bank->width;
  5745. +
  5746. #ifdef CONFIG_ARCH_OMAP1
  5747. /*
  5748. * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
  5749. @@ -1112,7 +1129,7 @@
  5750. }
  5751. ret = gpiochip_irqchip_add(&bank->chip, irqc,
  5752. - irq_base, omap_gpio_irq_handler,
  5753. + irq_base, handle_bad_irq,
  5754. IRQ_TYPE_NONE);
  5755. if (ret) {
  5756. @@ -1121,10 +1138,14 @@
  5757. return -ENODEV;
  5758. }
  5759. - gpiochip_set_chained_irqchip(&bank->chip, irqc,
  5760. - bank->irq, omap_gpio_irq_handler);
  5761. + gpiochip_set_chained_irqchip(&bank->chip, irqc, bank->irq, NULL);
  5762. - return 0;
  5763. + ret = devm_request_irq(bank->dev, bank->irq, omap_gpio_irq_handler,
  5764. + 0, dev_name(bank->dev), bank);
  5765. + if (ret)
  5766. + gpiochip_remove(&bank->chip);
  5767. +
  5768. + return ret;
  5769. }
  5770. static const struct of_device_id omap_gpio_match[];
  5771. @@ -1163,17 +1184,23 @@
  5772. irqc->irq_unmask = omap_gpio_unmask_irq,
  5773. irqc->irq_set_type = omap_gpio_irq_type,
  5774. irqc->irq_set_wake = omap_gpio_wake_enable,
  5775. + irqc->irq_bus_lock = omap_gpio_irq_bus_lock,
  5776. + irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock,
  5777. irqc->name = dev_name(&pdev->dev);
  5778. - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  5779. - if (unlikely(!res)) {
  5780. - dev_err(dev, "Invalid IRQ resource\n");
  5781. - return -ENODEV;
  5782. + bank->irq = platform_get_irq(pdev, 0);
  5783. + if (bank->irq <= 0) {
  5784. + if (!bank->irq)
  5785. + bank->irq = -ENXIO;
  5786. + if (bank->irq != -EPROBE_DEFER)
  5787. + dev_err(dev,
  5788. + "can't get irq resource ret=%d\n", bank->irq);
  5789. + return bank->irq;
  5790. }
  5791. - bank->irq = res->start;
  5792. bank->dev = dev;
  5793. bank->chip.dev = dev;
  5794. + bank->chip.owner = THIS_MODULE;
  5795. bank->dbck_flag = pdata->dbck_flag;
  5796. bank->stride = pdata->bank_stride;
  5797. bank->width = pdata->bank_width;
  5798. @@ -1183,15 +1210,9 @@
  5799. #ifdef CONFIG_OF_GPIO
  5800. bank->chip.of_node = of_node_get(node);
  5801. #endif
  5802. - if (node) {
  5803. - if (!of_property_read_bool(node, "ti,gpio-always-on"))
  5804. - bank->loses_context = true;
  5805. - } else {
  5806. - bank->loses_context = pdata->loses_context;
  5807. -
  5808. - if (bank->loses_context)
  5809. - bank->get_context_loss_count =
  5810. - pdata->get_context_loss_count;
  5811. + if (!node) {
  5812. + bank->get_context_loss_count =
  5813. + pdata->get_context_loss_count;
  5814. }
  5815. if (bank->regs->set_dataout && bank->regs->clr_dataout)
  5816. @@ -1199,16 +1220,27 @@
  5817. else
  5818. bank->set_dataout = omap_set_gpio_dataout_mask;
  5819. - spin_lock_init(&bank->lock);
  5820. + raw_spin_lock_init(&bank->lock);
  5821. + raw_spin_lock_init(&bank->wa_lock);
  5822. /* Static mapping, never released */
  5823. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  5824. bank->base = devm_ioremap_resource(dev, res);
  5825. if (IS_ERR(bank->base)) {
  5826. - irq_domain_remove(bank->chip.irqdomain);
  5827. return PTR_ERR(bank->base);
  5828. }
  5829. + if (bank->dbck_flag) {
  5830. + bank->dbck = devm_clk_get(bank->dev, "dbclk");
  5831. + if (IS_ERR(bank->dbck)) {
  5832. + dev_err(bank->dev,
  5833. + "Could not get gpio dbck. Disable debounce\n");
  5834. + bank->dbck_flag = false;
  5835. + } else {
  5836. + clk_prepare(bank->dbck);
  5837. + }
  5838. + }
  5839. +
  5840. platform_set_drvdata(pdev, bank);
  5841. pm_runtime_enable(bank->dev);
  5842. @@ -1221,8 +1253,11 @@
  5843. omap_gpio_mod_init(bank);
  5844. ret = omap_gpio_chip_init(bank, irqc);
  5845. - if (ret)
  5846. + if (ret) {
  5847. + pm_runtime_put_sync(bank->dev);
  5848. + pm_runtime_disable(bank->dev);
  5849. return ret;
  5850. + }
  5851. omap_gpio_show_rev(bank);
  5852. @@ -1233,6 +1268,19 @@
  5853. return 0;
  5854. }
  5855. +static int omap_gpio_remove(struct platform_device *pdev)
  5856. +{
  5857. + struct gpio_bank *bank = platform_get_drvdata(pdev);
  5858. +
  5859. + list_del(&bank->node);
  5860. + gpiochip_remove(&bank->chip);
  5861. + pm_runtime_disable(bank->dev);
  5862. + if (bank->dbck_flag)
  5863. + clk_unprepare(bank->dbck);
  5864. +
  5865. + return 0;
  5866. +}
  5867. +
  5868. #ifdef CONFIG_ARCH_OMAP2PLUS
  5869. #if defined(CONFIG_PM)
  5870. @@ -1246,7 +1294,7 @@
  5871. unsigned long flags;
  5872. u32 wake_low, wake_hi;
  5873. - spin_lock_irqsave(&bank->lock, flags);
  5874. + raw_spin_lock_irqsave(&bank->lock, flags);
  5875. /*
  5876. * Only edges can generate a wakeup event to the PRCM.
  5877. @@ -1299,7 +1347,7 @@
  5878. bank->get_context_loss_count(bank->dev);
  5879. omap_gpio_dbck_disable(bank);
  5880. - spin_unlock_irqrestore(&bank->lock, flags);
  5881. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5882. return 0;
  5883. }
  5884. @@ -1314,14 +1362,14 @@
  5885. unsigned long flags;
  5886. int c;
  5887. - spin_lock_irqsave(&bank->lock, flags);
  5888. + raw_spin_lock_irqsave(&bank->lock, flags);
  5889. /*
  5890. * On the first resume during the probe, the context has not
  5891. * been initialised and so initialise it now. Also initialise
  5892. * the context loss count.
  5893. */
  5894. - if (bank->loses_context && !bank->context_valid) {
  5895. + if (!bank->context_valid) {
  5896. omap_gpio_init_context(bank);
  5897. if (bank->get_context_loss_count)
  5898. @@ -1342,22 +1390,20 @@
  5899. writel_relaxed(bank->context.risingdetect,
  5900. bank->base + bank->regs->risingdetect);
  5901. - if (bank->loses_context) {
  5902. - if (!bank->get_context_loss_count) {
  5903. + if (!bank->get_context_loss_count) {
  5904. + omap_gpio_restore_context(bank);
  5905. + } else {
  5906. + c = bank->get_context_loss_count(bank->dev);
  5907. + if (c != bank->context_loss_count) {
  5908. omap_gpio_restore_context(bank);
  5909. } else {
  5910. - c = bank->get_context_loss_count(bank->dev);
  5911. - if (c != bank->context_loss_count) {
  5912. - omap_gpio_restore_context(bank);
  5913. - } else {
  5914. - spin_unlock_irqrestore(&bank->lock, flags);
  5915. - return 0;
  5916. - }
  5917. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5918. + return 0;
  5919. }
  5920. }
  5921. if (!bank->workaround_enabled) {
  5922. - spin_unlock_irqrestore(&bank->lock, flags);
  5923. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5924. return 0;
  5925. }
  5926. @@ -1412,18 +1458,19 @@
  5927. }
  5928. bank->workaround_enabled = false;
  5929. - spin_unlock_irqrestore(&bank->lock, flags);
  5930. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5931. return 0;
  5932. }
  5933. #endif /* CONFIG_PM */
  5934. +#if IS_BUILTIN(CONFIG_GPIO_OMAP)
  5935. void omap2_gpio_prepare_for_idle(int pwr_mode)
  5936. {
  5937. struct gpio_bank *bank;
  5938. list_for_each_entry(bank, &omap_gpio_list, node) {
  5939. - if (!BANK_USED(bank) || !bank->loses_context)
  5940. + if (!BANK_USED(bank))
  5941. continue;
  5942. bank->power_mode = pwr_mode;
  5943. @@ -1437,12 +1484,13 @@
  5944. struct gpio_bank *bank;
  5945. list_for_each_entry(bank, &omap_gpio_list, node) {
  5946. - if (!BANK_USED(bank) || !bank->loses_context)
  5947. + if (!BANK_USED(bank))
  5948. continue;
  5949. pm_runtime_get_sync(bank->dev);
  5950. }
  5951. }
  5952. +#endif
  5953. #if defined(CONFIG_PM)
  5954. static void omap_gpio_init_context(struct gpio_bank *p)
  5955. @@ -1598,6 +1646,7 @@
  5956. static struct platform_driver omap_gpio_driver = {
  5957. .probe = omap_gpio_probe,
  5958. + .remove = omap_gpio_remove,
  5959. .driver = {
  5960. .name = "omap_gpio",
  5961. .pm = &gpio_pm_ops,
  5962. @@ -1615,3 +1664,13 @@
  5963. return platform_driver_register(&omap_gpio_driver);
  5964. }
  5965. postcore_initcall(omap_gpio_drv_reg);
  5966. +
  5967. +static void __exit omap_gpio_exit(void)
  5968. +{
  5969. + platform_driver_unregister(&omap_gpio_driver);
  5970. +}
  5971. +module_exit(omap_gpio_exit);
  5972. +
  5973. +MODULE_DESCRIPTION("omap gpio driver");
  5974. +MODULE_ALIAS("platform:gpio-omap");
  5975. +MODULE_LICENSE("GPL v2");
  5976. diff -Nur linux-4.1.26.orig/drivers/gpio/Kconfig linux-4.1.26/drivers/gpio/Kconfig
  5977. --- linux-4.1.26.orig/drivers/gpio/Kconfig 2016-06-07 01:13:11.000000000 +0200
  5978. +++ linux-4.1.26/drivers/gpio/Kconfig 2016-06-19 15:30:58.631295190 +0200
  5979. @@ -308,7 +308,7 @@
  5980. family of SOCs.
  5981. config GPIO_OMAP
  5982. - bool "TI OMAP GPIO support" if COMPILE_TEST && !ARCH_OMAP2PLUS
  5983. + tristate "TI OMAP GPIO support" if ARCH_OMAP2PLUS || COMPILE_TEST
  5984. default y if ARCH_OMAP
  5985. depends on ARM
  5986. select GENERIC_IRQ_CHIP
  5987. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-4.1.26/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  5988. --- linux-4.1.26.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2016-06-07 01:13:11.000000000 +0200
  5989. +++ linux-4.1.26/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2016-06-19 15:30:58.631295190 +0200
  5990. @@ -32,6 +32,7 @@
  5991. #include "i915_trace.h"
  5992. #include "intel_drv.h"
  5993. #include <linux/dma_remapping.h>
  5994. +#include <linux/uaccess.h>
  5995. #define __EXEC_OBJECT_HAS_PIN (1<<31)
  5996. #define __EXEC_OBJECT_HAS_FENCE (1<<30)
  5997. @@ -465,7 +466,7 @@
  5998. }
  5999. /* We can't wait for rendering with pagefaults disabled */
  6000. - if (obj->active && in_atomic())
  6001. + if (obj->active && pagefault_disabled())
  6002. return -EFAULT;
  6003. if (use_cpu_reloc(obj))
  6004. @@ -1338,7 +1339,9 @@
  6005. return ret;
  6006. }
  6007. +#ifndef CONFIG_PREEMPT_RT_BASE
  6008. trace_i915_gem_ring_dispatch(intel_ring_get_request(ring), dispatch_flags);
  6009. +#endif
  6010. i915_gem_execbuffer_move_to_active(vmas, ring);
  6011. i915_gem_execbuffer_retire_commands(dev, file, ring, batch_obj);
  6012. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c linux-4.1.26/drivers/gpu/drm/i915/i915_gem_shrinker.c
  6013. --- linux-4.1.26.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c 2016-06-07 01:13:11.000000000 +0200
  6014. +++ linux-4.1.26/drivers/gpu/drm/i915/i915_gem_shrinker.c 2016-06-19 15:30:58.631295190 +0200
  6015. @@ -39,7 +39,7 @@
  6016. if (!mutex_is_locked(mutex))
  6017. return false;
  6018. -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
  6019. +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)) && !defined(CONFIG_PREEMPT_RT_BASE)
  6020. return mutex->owner == task;
  6021. #else
  6022. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  6023. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/i915/i915_irq.c linux-4.1.26/drivers/gpu/drm/i915/i915_irq.c
  6024. --- linux-4.1.26.orig/drivers/gpu/drm/i915/i915_irq.c 2016-06-07 01:13:11.000000000 +0200
  6025. +++ linux-4.1.26/drivers/gpu/drm/i915/i915_irq.c 2016-06-19 15:30:58.631295190 +0200
  6026. @@ -676,6 +676,7 @@
  6027. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6028. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  6029. + preempt_disable_rt();
  6030. /* Get optional system timestamp before query. */
  6031. if (stime)
  6032. @@ -727,6 +728,7 @@
  6033. *etime = ktime_get();
  6034. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  6035. + preempt_enable_rt();
  6036. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6037. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/i915/intel_display.c linux-4.1.26/drivers/gpu/drm/i915/intel_display.c
  6038. --- linux-4.1.26.orig/drivers/gpu/drm/i915/intel_display.c 2016-06-07 01:13:11.000000000 +0200
  6039. +++ linux-4.1.26/drivers/gpu/drm/i915/intel_display.c 2016-06-19 15:30:58.635295344 +0200
  6040. @@ -10084,7 +10084,7 @@
  6041. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  6042. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6043. - WARN_ON(!in_interrupt());
  6044. + WARN_ON_NONRT(!in_interrupt());
  6045. if (crtc == NULL)
  6046. return;
  6047. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/i915/intel_sprite.c linux-4.1.26/drivers/gpu/drm/i915/intel_sprite.c
  6048. --- linux-4.1.26.orig/drivers/gpu/drm/i915/intel_sprite.c 2016-06-07 01:13:11.000000000 +0200
  6049. +++ linux-4.1.26/drivers/gpu/drm/i915/intel_sprite.c 2016-06-19 15:30:58.635295344 +0200
  6050. @@ -37,6 +37,7 @@
  6051. #include "intel_drv.h"
  6052. #include <drm/i915_drm.h>
  6053. #include "i915_drv.h"
  6054. +#include <linux/locallock.h>
  6055. static bool
  6056. format_is_yuv(uint32_t format)
  6057. @@ -61,6 +62,8 @@
  6058. return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
  6059. }
  6060. +static DEFINE_LOCAL_IRQ_LOCK(pipe_update_lock);
  6061. +
  6062. /**
  6063. * intel_pipe_update_start() - start update of a set of display registers
  6064. * @crtc: the crtc of which the registers are going to be updated
  6065. @@ -101,7 +104,7 @@
  6066. if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
  6067. return false;
  6068. - local_irq_disable();
  6069. + local_lock_irq(pipe_update_lock);
  6070. trace_i915_pipe_update_start(crtc, min, max);
  6071. @@ -123,11 +126,11 @@
  6072. break;
  6073. }
  6074. - local_irq_enable();
  6075. + local_unlock_irq(pipe_update_lock);
  6076. timeout = schedule_timeout(timeout);
  6077. - local_irq_disable();
  6078. + local_lock_irq(pipe_update_lock);
  6079. }
  6080. finish_wait(wq, &wait);
  6081. @@ -158,7 +161,7 @@
  6082. trace_i915_pipe_update_end(crtc, end_vbl_count);
  6083. - local_irq_enable();
  6084. + local_unlock_irq(pipe_update_lock);
  6085. if (start_vbl_count != end_vbl_count)
  6086. DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
  6087. diff -Nur linux-4.1.26.orig/drivers/gpu/drm/radeon/radeon_display.c linux-4.1.26/drivers/gpu/drm/radeon/radeon_display.c
  6088. --- linux-4.1.26.orig/drivers/gpu/drm/radeon/radeon_display.c 2016-06-07 01:13:11.000000000 +0200
  6089. +++ linux-4.1.26/drivers/gpu/drm/radeon/radeon_display.c 2016-06-19 15:30:58.635295344 +0200
  6090. @@ -1798,6 +1798,7 @@
  6091. struct radeon_device *rdev = dev->dev_private;
  6092. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  6093. + preempt_disable_rt();
  6094. /* Get optional system timestamp before query. */
  6095. if (stime)
  6096. @@ -1890,6 +1891,7 @@
  6097. *etime = ktime_get();
  6098. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  6099. + preempt_enable_rt();
  6100. /* Decode into vertical and horizontal scanout position. */
  6101. *vpos = position & 0x1fff;
  6102. diff -Nur linux-4.1.26.orig/drivers/i2c/busses/i2c-omap.c linux-4.1.26/drivers/i2c/busses/i2c-omap.c
  6103. --- linux-4.1.26.orig/drivers/i2c/busses/i2c-omap.c 2016-06-07 01:13:11.000000000 +0200
  6104. +++ linux-4.1.26/drivers/i2c/busses/i2c-omap.c 2016-06-19 15:30:58.635295344 +0200
  6105. @@ -996,15 +996,12 @@
  6106. u16 mask;
  6107. u16 stat;
  6108. - spin_lock(&dev->lock);
  6109. - mask = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
  6110. stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
  6111. + mask = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
  6112. if (stat & mask)
  6113. ret = IRQ_WAKE_THREAD;
  6114. - spin_unlock(&dev->lock);
  6115. -
  6116. return ret;
  6117. }
  6118. diff -Nur linux-4.1.26.orig/drivers/ide/alim15x3.c linux-4.1.26/drivers/ide/alim15x3.c
  6119. --- linux-4.1.26.orig/drivers/ide/alim15x3.c 2016-06-07 01:13:11.000000000 +0200
  6120. +++ linux-4.1.26/drivers/ide/alim15x3.c 2016-06-19 15:30:58.635295344 +0200
  6121. @@ -234,7 +234,7 @@
  6122. isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  6123. - local_irq_save(flags);
  6124. + local_irq_save_nort(flags);
  6125. if (m5229_revision < 0xC2) {
  6126. /*
  6127. @@ -325,7 +325,7 @@
  6128. }
  6129. pci_dev_put(north);
  6130. pci_dev_put(isa_dev);
  6131. - local_irq_restore(flags);
  6132. + local_irq_restore_nort(flags);
  6133. return 0;
  6134. }
  6135. diff -Nur linux-4.1.26.orig/drivers/ide/hpt366.c linux-4.1.26/drivers/ide/hpt366.c
  6136. --- linux-4.1.26.orig/drivers/ide/hpt366.c 2016-06-07 01:13:11.000000000 +0200
  6137. +++ linux-4.1.26/drivers/ide/hpt366.c 2016-06-19 15:30:58.635295344 +0200
  6138. @@ -1241,7 +1241,7 @@
  6139. dma_old = inb(base + 2);
  6140. - local_irq_save(flags);
  6141. + local_irq_save_nort(flags);
  6142. dma_new = dma_old;
  6143. pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
  6144. @@ -1252,7 +1252,7 @@
  6145. if (dma_new != dma_old)
  6146. outb(dma_new, base + 2);
  6147. - local_irq_restore(flags);
  6148. + local_irq_restore_nort(flags);
  6149. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  6150. hwif->name, base, base + 7);
  6151. diff -Nur linux-4.1.26.orig/drivers/ide/ide-io.c linux-4.1.26/drivers/ide/ide-io.c
  6152. --- linux-4.1.26.orig/drivers/ide/ide-io.c 2016-06-07 01:13:11.000000000 +0200
  6153. +++ linux-4.1.26/drivers/ide/ide-io.c 2016-06-19 15:30:58.635295344 +0200
  6154. @@ -659,7 +659,7 @@
  6155. /* disable_irq_nosync ?? */
  6156. disable_irq(hwif->irq);
  6157. /* local CPU only, as if we were handling an interrupt */
  6158. - local_irq_disable();
  6159. + local_irq_disable_nort();
  6160. if (hwif->polling) {
  6161. startstop = handler(drive);
  6162. } else if (drive_is_ready(drive)) {
  6163. diff -Nur linux-4.1.26.orig/drivers/ide/ide-iops.c linux-4.1.26/drivers/ide/ide-iops.c
  6164. --- linux-4.1.26.orig/drivers/ide/ide-iops.c 2016-06-07 01:13:11.000000000 +0200
  6165. +++ linux-4.1.26/drivers/ide/ide-iops.c 2016-06-19 15:30:58.635295344 +0200
  6166. @@ -129,12 +129,12 @@
  6167. if ((stat & ATA_BUSY) == 0)
  6168. break;
  6169. - local_irq_restore(flags);
  6170. + local_irq_restore_nort(flags);
  6171. *rstat = stat;
  6172. return -EBUSY;
  6173. }
  6174. }
  6175. - local_irq_restore(flags);
  6176. + local_irq_restore_nort(flags);
  6177. }
  6178. /*
  6179. * Allow status to settle, then read it again.
  6180. diff -Nur linux-4.1.26.orig/drivers/ide/ide-io-std.c linux-4.1.26/drivers/ide/ide-io-std.c
  6181. --- linux-4.1.26.orig/drivers/ide/ide-io-std.c 2016-06-07 01:13:11.000000000 +0200
  6182. +++ linux-4.1.26/drivers/ide/ide-io-std.c 2016-06-19 15:30:58.635295344 +0200
  6183. @@ -175,7 +175,7 @@
  6184. unsigned long uninitialized_var(flags);
  6185. if ((io_32bit & 2) && !mmio) {
  6186. - local_irq_save(flags);
  6187. + local_irq_save_nort(flags);
  6188. ata_vlb_sync(io_ports->nsect_addr);
  6189. }
  6190. @@ -186,7 +186,7 @@
  6191. insl(data_addr, buf, words);
  6192. if ((io_32bit & 2) && !mmio)
  6193. - local_irq_restore(flags);
  6194. + local_irq_restore_nort(flags);
  6195. if (((len + 1) & 3) < 2)
  6196. return;
  6197. @@ -219,7 +219,7 @@
  6198. unsigned long uninitialized_var(flags);
  6199. if ((io_32bit & 2) && !mmio) {
  6200. - local_irq_save(flags);
  6201. + local_irq_save_nort(flags);
  6202. ata_vlb_sync(io_ports->nsect_addr);
  6203. }
  6204. @@ -230,7 +230,7 @@
  6205. outsl(data_addr, buf, words);
  6206. if ((io_32bit & 2) && !mmio)
  6207. - local_irq_restore(flags);
  6208. + local_irq_restore_nort(flags);
  6209. if (((len + 1) & 3) < 2)
  6210. return;
  6211. diff -Nur linux-4.1.26.orig/drivers/ide/ide-probe.c linux-4.1.26/drivers/ide/ide-probe.c
  6212. --- linux-4.1.26.orig/drivers/ide/ide-probe.c 2016-06-07 01:13:11.000000000 +0200
  6213. +++ linux-4.1.26/drivers/ide/ide-probe.c 2016-06-19 15:30:58.635295344 +0200
  6214. @@ -196,10 +196,10 @@
  6215. int bswap = 1;
  6216. /* local CPU only; some systems need this */
  6217. - local_irq_save(flags);
  6218. + local_irq_save_nort(flags);
  6219. /* read 512 bytes of id info */
  6220. hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
  6221. - local_irq_restore(flags);
  6222. + local_irq_restore_nort(flags);
  6223. drive->dev_flags |= IDE_DFLAG_ID_READ;
  6224. #ifdef DEBUG
  6225. diff -Nur linux-4.1.26.orig/drivers/ide/ide-taskfile.c linux-4.1.26/drivers/ide/ide-taskfile.c
  6226. --- linux-4.1.26.orig/drivers/ide/ide-taskfile.c 2016-06-07 01:13:11.000000000 +0200
  6227. +++ linux-4.1.26/drivers/ide/ide-taskfile.c 2016-06-19 15:30:58.635295344 +0200
  6228. @@ -250,7 +250,7 @@
  6229. page_is_high = PageHighMem(page);
  6230. if (page_is_high)
  6231. - local_irq_save(flags);
  6232. + local_irq_save_nort(flags);
  6233. buf = kmap_atomic(page) + offset;
  6234. @@ -271,7 +271,7 @@
  6235. kunmap_atomic(buf);
  6236. if (page_is_high)
  6237. - local_irq_restore(flags);
  6238. + local_irq_restore_nort(flags);
  6239. len -= nr_bytes;
  6240. }
  6241. @@ -414,7 +414,7 @@
  6242. }
  6243. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  6244. - local_irq_disable();
  6245. + local_irq_disable_nort();
  6246. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  6247. diff -Nur linux-4.1.26.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c linux-4.1.26/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
  6248. --- linux-4.1.26.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2016-06-07 01:13:11.000000000 +0200
  6249. +++ linux-4.1.26/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2016-06-19 15:30:58.639295498 +0200
  6250. @@ -821,7 +821,7 @@
  6251. ipoib_dbg_mcast(priv, "restarting multicast task\n");
  6252. - local_irq_save(flags);
  6253. + local_irq_save_nort(flags);
  6254. netif_addr_lock(dev);
  6255. spin_lock(&priv->lock);
  6256. @@ -903,7 +903,7 @@
  6257. spin_unlock(&priv->lock);
  6258. netif_addr_unlock(dev);
  6259. - local_irq_restore(flags);
  6260. + local_irq_restore_nort(flags);
  6261. /*
  6262. * make sure the in-flight joins have finished before we attempt
  6263. diff -Nur linux-4.1.26.orig/drivers/input/gameport/gameport.c linux-4.1.26/drivers/input/gameport/gameport.c
  6264. --- linux-4.1.26.orig/drivers/input/gameport/gameport.c 2016-06-07 01:13:11.000000000 +0200
  6265. +++ linux-4.1.26/drivers/input/gameport/gameport.c 2016-06-19 15:30:58.639295498 +0200
  6266. @@ -124,12 +124,12 @@
  6267. tx = 1 << 30;
  6268. for(i = 0; i < 50; i++) {
  6269. - local_irq_save(flags);
  6270. + local_irq_save_nort(flags);
  6271. GET_TIME(t1);
  6272. for (t = 0; t < 50; t++) gameport_read(gameport);
  6273. GET_TIME(t2);
  6274. GET_TIME(t3);
  6275. - local_irq_restore(flags);
  6276. + local_irq_restore_nort(flags);
  6277. udelay(i * 10);
  6278. if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
  6279. }
  6280. @@ -148,11 +148,11 @@
  6281. tx = 1 << 30;
  6282. for(i = 0; i < 50; i++) {
  6283. - local_irq_save(flags);
  6284. + local_irq_save_nort(flags);
  6285. rdtscl(t1);
  6286. for (t = 0; t < 50; t++) gameport_read(gameport);
  6287. rdtscl(t2);
  6288. - local_irq_restore(flags);
  6289. + local_irq_restore_nort(flags);
  6290. udelay(i * 10);
  6291. if (t2 - t1 < tx) tx = t2 - t1;
  6292. }
  6293. diff -Nur linux-4.1.26.orig/drivers/leds/trigger/Kconfig linux-4.1.26/drivers/leds/trigger/Kconfig
  6294. --- linux-4.1.26.orig/drivers/leds/trigger/Kconfig 2016-06-07 01:13:11.000000000 +0200
  6295. +++ linux-4.1.26/drivers/leds/trigger/Kconfig 2016-06-19 15:30:58.639295498 +0200
  6296. @@ -61,7 +61,7 @@
  6297. config LEDS_TRIGGER_CPU
  6298. bool "LED CPU Trigger"
  6299. - depends on LEDS_TRIGGERS
  6300. + depends on LEDS_TRIGGERS && !PREEMPT_RT_BASE
  6301. help
  6302. This allows LEDs to be controlled by active CPUs. This shows
  6303. the active CPUs across an array of LEDs so you can see which
  6304. diff -Nur linux-4.1.26.orig/drivers/md/bcache/Kconfig linux-4.1.26/drivers/md/bcache/Kconfig
  6305. --- linux-4.1.26.orig/drivers/md/bcache/Kconfig 2016-06-07 01:13:11.000000000 +0200
  6306. +++ linux-4.1.26/drivers/md/bcache/Kconfig 2016-06-19 15:30:58.639295498 +0200
  6307. @@ -1,6 +1,7 @@
  6308. config BCACHE
  6309. tristate "Block device as cache"
  6310. + depends on !PREEMPT_RT_FULL
  6311. ---help---
  6312. Allows a block device to be used as cache for other devices; uses
  6313. a btree for indexing and the layout is optimized for SSDs.
  6314. diff -Nur linux-4.1.26.orig/drivers/md/dm.c linux-4.1.26/drivers/md/dm.c
  6315. --- linux-4.1.26.orig/drivers/md/dm.c 2016-06-07 01:13:11.000000000 +0200
  6316. +++ linux-4.1.26/drivers/md/dm.c 2016-06-19 15:30:58.639295498 +0200
  6317. @@ -2133,7 +2133,7 @@
  6318. /* Establish tio->ti before queuing work (map_tio_request) */
  6319. tio->ti = ti;
  6320. queue_kthread_work(&md->kworker, &tio->work);
  6321. - BUG_ON(!irqs_disabled());
  6322. + BUG_ON_NONRT(!irqs_disabled());
  6323. }
  6324. goto out;
  6325. diff -Nur linux-4.1.26.orig/drivers/md/raid5.c linux-4.1.26/drivers/md/raid5.c
  6326. --- linux-4.1.26.orig/drivers/md/raid5.c 2016-06-07 01:13:11.000000000 +0200
  6327. +++ linux-4.1.26/drivers/md/raid5.c 2016-06-19 15:30:58.639295498 +0200
  6328. @@ -1918,8 +1918,9 @@
  6329. struct raid5_percpu *percpu;
  6330. unsigned long cpu;
  6331. - cpu = get_cpu();
  6332. + cpu = get_cpu_light();
  6333. percpu = per_cpu_ptr(conf->percpu, cpu);
  6334. + spin_lock(&percpu->lock);
  6335. if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
  6336. ops_run_biofill(sh);
  6337. overlap_clear++;
  6338. @@ -1975,7 +1976,8 @@
  6339. if (test_and_clear_bit(R5_Overlap, &dev->flags))
  6340. wake_up(&sh->raid_conf->wait_for_overlap);
  6341. }
  6342. - put_cpu();
  6343. + spin_unlock(&percpu->lock);
  6344. + put_cpu_light();
  6345. }
  6346. static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp)
  6347. @@ -6375,6 +6377,7 @@
  6348. __func__, cpu);
  6349. break;
  6350. }
  6351. + spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
  6352. }
  6353. put_online_cpus();
  6354. diff -Nur linux-4.1.26.orig/drivers/md/raid5.h linux-4.1.26/drivers/md/raid5.h
  6355. --- linux-4.1.26.orig/drivers/md/raid5.h 2016-06-07 01:13:11.000000000 +0200
  6356. +++ linux-4.1.26/drivers/md/raid5.h 2016-06-19 15:30:58.639295498 +0200
  6357. @@ -495,6 +495,7 @@
  6358. int recovery_disabled;
  6359. /* per cpu variables */
  6360. struct raid5_percpu {
  6361. + spinlock_t lock; /* Protection for -RT */
  6362. struct page *spare_page; /* Used when checking P/Q in raid6 */
  6363. struct flex_array *scribble; /* space for constructing buffer
  6364. * lists and performing address
  6365. diff -Nur linux-4.1.26.orig/drivers/misc/hwlat_detector.c linux-4.1.26/drivers/misc/hwlat_detector.c
  6366. --- linux-4.1.26.orig/drivers/misc/hwlat_detector.c 1970-01-01 01:00:00.000000000 +0100
  6367. +++ linux-4.1.26/drivers/misc/hwlat_detector.c 2016-06-19 15:30:58.643295653 +0200
  6368. @@ -0,0 +1,1240 @@
  6369. +/*
  6370. + * hwlat_detector.c - A simple Hardware Latency detector.
  6371. + *
  6372. + * Use this module to detect large system latencies induced by the behavior of
  6373. + * certain underlying system hardware or firmware, independent of Linux itself.
  6374. + * The code was developed originally to detect the presence of SMIs on Intel
  6375. + * and AMD systems, although there is no dependency upon x86 herein.
  6376. + *
  6377. + * The classical example usage of this module is in detecting the presence of
  6378. + * SMIs or System Management Interrupts on Intel and AMD systems. An SMI is a
  6379. + * somewhat special form of hardware interrupt spawned from earlier CPU debug
  6380. + * modes in which the (BIOS/EFI/etc.) firmware arranges for the South Bridge
  6381. + * LPC (or other device) to generate a special interrupt under certain
  6382. + * circumstances, for example, upon expiration of a special SMI timer device,
  6383. + * due to certain external thermal readings, on certain I/O address accesses,
  6384. + * and other situations. An SMI hits a special CPU pin, triggers a special
  6385. + * SMI mode (complete with special memory map), and the OS is unaware.
  6386. + *
  6387. + * Although certain hardware-inducing latencies are necessary (for example,
  6388. + * a modern system often requires an SMI handler for correct thermal control
  6389. + * and remote management) they can wreak havoc upon any OS-level performance
  6390. + * guarantees toward low-latency, especially when the OS is not even made
  6391. + * aware of the presence of these interrupts. For this reason, we need a
  6392. + * somewhat brute force mechanism to detect these interrupts. In this case,
  6393. + * we do it by hogging all of the CPU(s) for configurable timer intervals,
  6394. + * sampling the built-in CPU timer, looking for discontiguous readings.
  6395. + *
  6396. + * WARNING: This implementation necessarily introduces latencies. Therefore,
  6397. + * you should NEVER use this module in a production environment
  6398. + * requiring any kind of low-latency performance guarantee(s).
  6399. + *
  6400. + * Copyright (C) 2008-2009 Jon Masters, Red Hat, Inc. <jcm@redhat.com>
  6401. + *
  6402. + * Includes useful feedback from Clark Williams <clark@redhat.com>
  6403. + *
  6404. + * This file is licensed under the terms of the GNU General Public
  6405. + * License version 2. This program is licensed "as is" without any
  6406. + * warranty of any kind, whether express or implied.
  6407. + */
  6408. +
  6409. +#include <linux/module.h>
  6410. +#include <linux/init.h>
  6411. +#include <linux/ring_buffer.h>
  6412. +#include <linux/time.h>
  6413. +#include <linux/hrtimer.h>
  6414. +#include <linux/kthread.h>
  6415. +#include <linux/debugfs.h>
  6416. +#include <linux/seq_file.h>
  6417. +#include <linux/uaccess.h>
  6418. +#include <linux/version.h>
  6419. +#include <linux/delay.h>
  6420. +#include <linux/slab.h>
  6421. +#include <linux/trace_clock.h>
  6422. +
  6423. +#define BUF_SIZE_DEFAULT 262144UL /* 8K*(sizeof(entry)) */
  6424. +#define BUF_FLAGS (RB_FL_OVERWRITE) /* no block on full */
  6425. +#define U64STR_SIZE 22 /* 20 digits max */
  6426. +
  6427. +#define VERSION "1.0.0"
  6428. +#define BANNER "hwlat_detector: "
  6429. +#define DRVNAME "hwlat_detector"
  6430. +#define DEFAULT_SAMPLE_WINDOW 1000000 /* 1s */
  6431. +#define DEFAULT_SAMPLE_WIDTH 500000 /* 0.5s */
  6432. +#define DEFAULT_LAT_THRESHOLD 10 /* 10us */
  6433. +
  6434. +/* Module metadata */
  6435. +
  6436. +MODULE_LICENSE("GPL");
  6437. +MODULE_AUTHOR("Jon Masters <jcm@redhat.com>");
  6438. +MODULE_DESCRIPTION("A simple hardware latency detector");
  6439. +MODULE_VERSION(VERSION);
  6440. +
  6441. +/* Module parameters */
  6442. +
  6443. +static int debug;
  6444. +static int enabled;
  6445. +static int threshold;
  6446. +
  6447. +module_param(debug, int, 0); /* enable debug */
  6448. +module_param(enabled, int, 0); /* enable detector */
  6449. +module_param(threshold, int, 0); /* latency threshold */
  6450. +
  6451. +/* Buffering and sampling */
  6452. +
  6453. +static struct ring_buffer *ring_buffer; /* sample buffer */
  6454. +static DEFINE_MUTEX(ring_buffer_mutex); /* lock changes */
  6455. +static unsigned long buf_size = BUF_SIZE_DEFAULT;
  6456. +static struct task_struct *kthread; /* sampling thread */
  6457. +
  6458. +/* DebugFS filesystem entries */
  6459. +
  6460. +static struct dentry *debug_dir; /* debugfs directory */
  6461. +static struct dentry *debug_max; /* maximum TSC delta */
  6462. +static struct dentry *debug_count; /* total detect count */
  6463. +static struct dentry *debug_sample_width; /* sample width us */
  6464. +static struct dentry *debug_sample_window; /* sample window us */
  6465. +static struct dentry *debug_sample; /* raw samples us */
  6466. +static struct dentry *debug_threshold; /* threshold us */
  6467. +static struct dentry *debug_enable; /* enable/disable */
  6468. +
  6469. +/* Individual samples and global state */
  6470. +
  6471. +struct sample; /* latency sample */
  6472. +struct data; /* Global state */
  6473. +
  6474. +/* Sampling functions */
  6475. +static int __buffer_add_sample(struct sample *sample);
  6476. +static struct sample *buffer_get_sample(struct sample *sample);
  6477. +
  6478. +/* Threading and state */
  6479. +static int kthread_fn(void *unused);
  6480. +static int start_kthread(void);
  6481. +static int stop_kthread(void);
  6482. +static void __reset_stats(void);
  6483. +static int init_stats(void);
  6484. +
  6485. +/* Debugfs interface */
  6486. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  6487. + size_t cnt, loff_t *ppos, const u64 *entry);
  6488. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  6489. + size_t cnt, loff_t *ppos, u64 *entry);
  6490. +static int debug_sample_fopen(struct inode *inode, struct file *filp);
  6491. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  6492. + size_t cnt, loff_t *ppos);
  6493. +static int debug_sample_release(struct inode *inode, struct file *filp);
  6494. +static int debug_enable_fopen(struct inode *inode, struct file *filp);
  6495. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  6496. + size_t cnt, loff_t *ppos);
  6497. +static ssize_t debug_enable_fwrite(struct file *file,
  6498. + const char __user *user_buffer,
  6499. + size_t user_size, loff_t *offset);
  6500. +
  6501. +/* Initialization functions */
  6502. +static int init_debugfs(void);
  6503. +static void free_debugfs(void);
  6504. +static int detector_init(void);
  6505. +static void detector_exit(void);
  6506. +
  6507. +/* Individual latency samples are stored here when detected and packed into
  6508. + * the ring_buffer circular buffer, where they are overwritten when
  6509. + * more than buf_size/sizeof(sample) samples are received. */
  6510. +struct sample {
  6511. + u64 seqnum; /* unique sequence */
  6512. + u64 duration; /* ktime delta */
  6513. + u64 outer_duration; /* ktime delta (outer loop) */
  6514. + struct timespec timestamp; /* wall time */
  6515. + unsigned long lost;
  6516. +};
  6517. +
  6518. +/* keep the global state somewhere. */
  6519. +static struct data {
  6520. +
  6521. + struct mutex lock; /* protect changes */
  6522. +
  6523. + u64 count; /* total since reset */
  6524. + u64 max_sample; /* max hardware latency */
  6525. + u64 threshold; /* sample threshold level */
  6526. +
  6527. + u64 sample_window; /* total sampling window (on+off) */
  6528. + u64 sample_width; /* active sampling portion of window */
  6529. +
  6530. + atomic_t sample_open; /* whether the sample file is open */
  6531. +
  6532. + wait_queue_head_t wq; /* waitqeue for new sample values */
  6533. +
  6534. +} data;
  6535. +
  6536. +/**
  6537. + * __buffer_add_sample - add a new latency sample recording to the ring buffer
  6538. + * @sample: The new latency sample value
  6539. + *
  6540. + * This receives a new latency sample and records it in a global ring buffer.
  6541. + * No additional locking is used in this case.
  6542. + */
  6543. +static int __buffer_add_sample(struct sample *sample)
  6544. +{
  6545. + return ring_buffer_write(ring_buffer,
  6546. + sizeof(struct sample), sample);
  6547. +}
  6548. +
  6549. +/**
  6550. + * buffer_get_sample - remove a hardware latency sample from the ring buffer
  6551. + * @sample: Pre-allocated storage for the sample
  6552. + *
  6553. + * This retrieves a hardware latency sample from the global circular buffer
  6554. + */
  6555. +static struct sample *buffer_get_sample(struct sample *sample)
  6556. +{
  6557. + struct ring_buffer_event *e = NULL;
  6558. + struct sample *s = NULL;
  6559. + unsigned int cpu = 0;
  6560. +
  6561. + if (!sample)
  6562. + return NULL;
  6563. +
  6564. + mutex_lock(&ring_buffer_mutex);
  6565. + for_each_online_cpu(cpu) {
  6566. + e = ring_buffer_consume(ring_buffer, cpu, NULL, &sample->lost);
  6567. + if (e)
  6568. + break;
  6569. + }
  6570. +
  6571. + if (e) {
  6572. + s = ring_buffer_event_data(e);
  6573. + memcpy(sample, s, sizeof(struct sample));
  6574. + } else
  6575. + sample = NULL;
  6576. + mutex_unlock(&ring_buffer_mutex);
  6577. +
  6578. + return sample;
  6579. +}
  6580. +
  6581. +#ifndef CONFIG_TRACING
  6582. +#define time_type ktime_t
  6583. +#define time_get() ktime_get()
  6584. +#define time_to_us(x) ktime_to_us(x)
  6585. +#define time_sub(a, b) ktime_sub(a, b)
  6586. +#define init_time(a, b) (a).tv64 = b
  6587. +#define time_u64(a) ((a).tv64)
  6588. +#else
  6589. +#define time_type u64
  6590. +#define time_get() trace_clock_local()
  6591. +#define time_to_us(x) div_u64(x, 1000)
  6592. +#define time_sub(a, b) ((a) - (b))
  6593. +#define init_time(a, b) (a = b)
  6594. +#define time_u64(a) a
  6595. +#endif
  6596. +/**
  6597. + * get_sample - sample the CPU TSC and look for likely hardware latencies
  6598. + *
  6599. + * Used to repeatedly capture the CPU TSC (or similar), looking for potential
  6600. + * hardware-induced latency. Called with interrupts disabled and with
  6601. + * data.lock held.
  6602. + */
  6603. +static int get_sample(void)
  6604. +{
  6605. + time_type start, t1, t2, last_t2;
  6606. + s64 diff, total = 0;
  6607. + u64 sample = 0;
  6608. + u64 outer_sample = 0;
  6609. + int ret = -1;
  6610. +
  6611. + init_time(last_t2, 0);
  6612. + start = time_get(); /* start timestamp */
  6613. +
  6614. + do {
  6615. +
  6616. + t1 = time_get(); /* we'll look for a discontinuity */
  6617. + t2 = time_get();
  6618. +
  6619. + if (time_u64(last_t2)) {
  6620. + /* Check the delta from outer loop (t2 to next t1) */
  6621. + diff = time_to_us(time_sub(t1, last_t2));
  6622. + /* This shouldn't happen */
  6623. + if (diff < 0) {
  6624. + pr_err(BANNER "time running backwards\n");
  6625. + goto out;
  6626. + }
  6627. + if (diff > outer_sample)
  6628. + outer_sample = diff;
  6629. + }
  6630. + last_t2 = t2;
  6631. +
  6632. + total = time_to_us(time_sub(t2, start)); /* sample width */
  6633. +
  6634. + /* This checks the inner loop (t1 to t2) */
  6635. + diff = time_to_us(time_sub(t2, t1)); /* current diff */
  6636. +
  6637. + /* This shouldn't happen */
  6638. + if (diff < 0) {
  6639. + pr_err(BANNER "time running backwards\n");
  6640. + goto out;
  6641. + }
  6642. +
  6643. + if (diff > sample)
  6644. + sample = diff; /* only want highest value */
  6645. +
  6646. + } while (total <= data.sample_width);
  6647. +
  6648. + ret = 0;
  6649. +
  6650. + /* If we exceed the threshold value, we have found a hardware latency */
  6651. + if (sample > data.threshold || outer_sample > data.threshold) {
  6652. + struct sample s;
  6653. +
  6654. + ret = 1;
  6655. +
  6656. + data.count++;
  6657. + s.seqnum = data.count;
  6658. + s.duration = sample;
  6659. + s.outer_duration = outer_sample;
  6660. + s.timestamp = CURRENT_TIME;
  6661. + __buffer_add_sample(&s);
  6662. +
  6663. + /* Keep a running maximum ever recorded hardware latency */
  6664. + if (sample > data.max_sample)
  6665. + data.max_sample = sample;
  6666. + }
  6667. +
  6668. +out:
  6669. + return ret;
  6670. +}
  6671. +
  6672. +/*
  6673. + * kthread_fn - The CPU time sampling/hardware latency detection kernel thread
  6674. + * @unused: A required part of the kthread API.
  6675. + *
  6676. + * Used to periodically sample the CPU TSC via a call to get_sample. We
  6677. + * disable interrupts, which does (intentionally) introduce latency since we
  6678. + * need to ensure nothing else might be running (and thus pre-empting).
  6679. + * Obviously this should never be used in production environments.
  6680. + *
  6681. + * Currently this runs on which ever CPU it was scheduled on, but most
  6682. + * real-worald hardware latency situations occur across several CPUs,
  6683. + * but we might later generalize this if we find there are any actualy
  6684. + * systems with alternate SMI delivery or other hardware latencies.
  6685. + */
  6686. +static int kthread_fn(void *unused)
  6687. +{
  6688. + int ret;
  6689. + u64 interval;
  6690. +
  6691. + while (!kthread_should_stop()) {
  6692. +
  6693. + mutex_lock(&data.lock);
  6694. +
  6695. + local_irq_disable();
  6696. + ret = get_sample();
  6697. + local_irq_enable();
  6698. +
  6699. + if (ret > 0)
  6700. + wake_up(&data.wq); /* wake up reader(s) */
  6701. +
  6702. + interval = data.sample_window - data.sample_width;
  6703. + do_div(interval, USEC_PER_MSEC); /* modifies interval value */
  6704. +
  6705. + mutex_unlock(&data.lock);
  6706. +
  6707. + if (msleep_interruptible(interval))
  6708. + break;
  6709. + }
  6710. +
  6711. + return 0;
  6712. +}
  6713. +
  6714. +/**
  6715. + * start_kthread - Kick off the hardware latency sampling/detector kthread
  6716. + *
  6717. + * This starts a kernel thread that will sit and sample the CPU timestamp
  6718. + * counter (TSC or similar) and look for potential hardware latencies.
  6719. + */
  6720. +static int start_kthread(void)
  6721. +{
  6722. + kthread = kthread_run(kthread_fn, NULL,
  6723. + DRVNAME);
  6724. + if (IS_ERR(kthread)) {
  6725. + pr_err(BANNER "could not start sampling thread\n");
  6726. + enabled = 0;
  6727. + return -ENOMEM;
  6728. + }
  6729. +
  6730. + return 0;
  6731. +}
  6732. +
  6733. +/**
  6734. + * stop_kthread - Inform the hardware latency samping/detector kthread to stop
  6735. + *
  6736. + * This kicks the running hardware latency sampling/detector kernel thread and
  6737. + * tells it to stop sampling now. Use this on unload and at system shutdown.
  6738. + */
  6739. +static int stop_kthread(void)
  6740. +{
  6741. + int ret;
  6742. +
  6743. + ret = kthread_stop(kthread);
  6744. +
  6745. + return ret;
  6746. +}
  6747. +
  6748. +/**
  6749. + * __reset_stats - Reset statistics for the hardware latency detector
  6750. + *
  6751. + * We use data to store various statistics and global state. We call this
  6752. + * function in order to reset those when "enable" is toggled on or off, and
  6753. + * also at initialization. Should be called with data.lock held.
  6754. + */
  6755. +static void __reset_stats(void)
  6756. +{
  6757. + data.count = 0;
  6758. + data.max_sample = 0;
  6759. + ring_buffer_reset(ring_buffer); /* flush out old sample entries */
  6760. +}
  6761. +
  6762. +/**
  6763. + * init_stats - Setup global state statistics for the hardware latency detector
  6764. + *
  6765. + * We use data to store various statistics and global state. We also use
  6766. + * a global ring buffer (ring_buffer) to keep raw samples of detected hardware
  6767. + * induced system latencies. This function initializes these structures and
  6768. + * allocates the global ring buffer also.
  6769. + */
  6770. +static int init_stats(void)
  6771. +{
  6772. + int ret = -ENOMEM;
  6773. +
  6774. + mutex_init(&data.lock);
  6775. + init_waitqueue_head(&data.wq);
  6776. + atomic_set(&data.sample_open, 0);
  6777. +
  6778. + ring_buffer = ring_buffer_alloc(buf_size, BUF_FLAGS);
  6779. +
  6780. + if (WARN(!ring_buffer, KERN_ERR BANNER
  6781. + "failed to allocate ring buffer!\n"))
  6782. + goto out;
  6783. +
  6784. + __reset_stats();
  6785. + data.threshold = threshold ?: DEFAULT_LAT_THRESHOLD; /* threshold us */
  6786. + data.sample_window = DEFAULT_SAMPLE_WINDOW; /* window us */
  6787. + data.sample_width = DEFAULT_SAMPLE_WIDTH; /* width us */
  6788. +
  6789. + ret = 0;
  6790. +
  6791. +out:
  6792. + return ret;
  6793. +
  6794. +}
  6795. +
  6796. +/*
  6797. + * simple_data_read - Wrapper read function for global state debugfs entries
  6798. + * @filp: The active open file structure for the debugfs "file"
  6799. + * @ubuf: The userspace provided buffer to read value into
  6800. + * @cnt: The maximum number of bytes to read
  6801. + * @ppos: The current "file" position
  6802. + * @entry: The entry to read from
  6803. + *
  6804. + * This function provides a generic read implementation for the global state
  6805. + * "data" structure debugfs filesystem entries. It would be nice to use
  6806. + * simple_attr_read directly, but we need to make sure that the data.lock
  6807. + * is held during the actual read.
  6808. + */
  6809. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  6810. + size_t cnt, loff_t *ppos, const u64 *entry)
  6811. +{
  6812. + char buf[U64STR_SIZE];
  6813. + u64 val = 0;
  6814. + int len = 0;
  6815. +
  6816. + memset(buf, 0, sizeof(buf));
  6817. +
  6818. + if (!entry)
  6819. + return -EFAULT;
  6820. +
  6821. + mutex_lock(&data.lock);
  6822. + val = *entry;
  6823. + mutex_unlock(&data.lock);
  6824. +
  6825. + len = snprintf(buf, sizeof(buf), "%llu\n", (unsigned long long)val);
  6826. +
  6827. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
  6828. +
  6829. +}
  6830. +
  6831. +/*
  6832. + * simple_data_write - Wrapper write function for global state debugfs entries
  6833. + * @filp: The active open file structure for the debugfs "file"
  6834. + * @ubuf: The userspace provided buffer to write value from
  6835. + * @cnt: The maximum number of bytes to write
  6836. + * @ppos: The current "file" position
  6837. + * @entry: The entry to write to
  6838. + *
  6839. + * This function provides a generic write implementation for the global state
  6840. + * "data" structure debugfs filesystem entries. It would be nice to use
  6841. + * simple_attr_write directly, but we need to make sure that the data.lock
  6842. + * is held during the actual write.
  6843. + */
  6844. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  6845. + size_t cnt, loff_t *ppos, u64 *entry)
  6846. +{
  6847. + char buf[U64STR_SIZE];
  6848. + int csize = min(cnt, sizeof(buf));
  6849. + u64 val = 0;
  6850. + int err = 0;
  6851. +
  6852. + memset(buf, '\0', sizeof(buf));
  6853. + if (copy_from_user(buf, ubuf, csize))
  6854. + return -EFAULT;
  6855. +
  6856. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  6857. + err = kstrtoull(buf, 10, &val);
  6858. + if (err)
  6859. + return -EINVAL;
  6860. +
  6861. + mutex_lock(&data.lock);
  6862. + *entry = val;
  6863. + mutex_unlock(&data.lock);
  6864. +
  6865. + return csize;
  6866. +}
  6867. +
  6868. +/**
  6869. + * debug_count_fopen - Open function for "count" debugfs entry
  6870. + * @inode: The in-kernel inode representation of the debugfs "file"
  6871. + * @filp: The active open file structure for the debugfs "file"
  6872. + *
  6873. + * This function provides an open implementation for the "count" debugfs
  6874. + * interface to the hardware latency detector.
  6875. + */
  6876. +static int debug_count_fopen(struct inode *inode, struct file *filp)
  6877. +{
  6878. + return 0;
  6879. +}
  6880. +
  6881. +/**
  6882. + * debug_count_fread - Read function for "count" debugfs entry
  6883. + * @filp: The active open file structure for the debugfs "file"
  6884. + * @ubuf: The userspace provided buffer to read value into
  6885. + * @cnt: The maximum number of bytes to read
  6886. + * @ppos: The current "file" position
  6887. + *
  6888. + * This function provides a read implementation for the "count" debugfs
  6889. + * interface to the hardware latency detector. Can be used to read the
  6890. + * number of latency readings exceeding the configured threshold since
  6891. + * the detector was last reset (e.g. by writing a zero into "count").
  6892. + */
  6893. +static ssize_t debug_count_fread(struct file *filp, char __user *ubuf,
  6894. + size_t cnt, loff_t *ppos)
  6895. +{
  6896. + return simple_data_read(filp, ubuf, cnt, ppos, &data.count);
  6897. +}
  6898. +
  6899. +/**
  6900. + * debug_count_fwrite - Write function for "count" debugfs entry
  6901. + * @filp: The active open file structure for the debugfs "file"
  6902. + * @ubuf: The user buffer that contains the value to write
  6903. + * @cnt: The maximum number of bytes to write to "file"
  6904. + * @ppos: The current position in the debugfs "file"
  6905. + *
  6906. + * This function provides a write implementation for the "count" debugfs
  6907. + * interface to the hardware latency detector. Can be used to write a
  6908. + * desired value, especially to zero the total count.
  6909. + */
  6910. +static ssize_t debug_count_fwrite(struct file *filp,
  6911. + const char __user *ubuf,
  6912. + size_t cnt,
  6913. + loff_t *ppos)
  6914. +{
  6915. + return simple_data_write(filp, ubuf, cnt, ppos, &data.count);
  6916. +}
  6917. +
  6918. +/**
  6919. + * debug_enable_fopen - Dummy open function for "enable" debugfs interface
  6920. + * @inode: The in-kernel inode representation of the debugfs "file"
  6921. + * @filp: The active open file structure for the debugfs "file"
  6922. + *
  6923. + * This function provides an open implementation for the "enable" debugfs
  6924. + * interface to the hardware latency detector.
  6925. + */
  6926. +static int debug_enable_fopen(struct inode *inode, struct file *filp)
  6927. +{
  6928. + return 0;
  6929. +}
  6930. +
  6931. +/**
  6932. + * debug_enable_fread - Read function for "enable" debugfs interface
  6933. + * @filp: The active open file structure for the debugfs "file"
  6934. + * @ubuf: The userspace provided buffer to read value into
  6935. + * @cnt: The maximum number of bytes to read
  6936. + * @ppos: The current "file" position
  6937. + *
  6938. + * This function provides a read implementation for the "enable" debugfs
  6939. + * interface to the hardware latency detector. Can be used to determine
  6940. + * whether the detector is currently enabled ("0\n" or "1\n" returned).
  6941. + */
  6942. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  6943. + size_t cnt, loff_t *ppos)
  6944. +{
  6945. + char buf[4];
  6946. +
  6947. + if ((cnt < sizeof(buf)) || (*ppos))
  6948. + return 0;
  6949. +
  6950. + buf[0] = enabled ? '1' : '0';
  6951. + buf[1] = '\n';
  6952. + buf[2] = '\0';
  6953. + if (copy_to_user(ubuf, buf, strlen(buf)))
  6954. + return -EFAULT;
  6955. + return *ppos = strlen(buf);
  6956. +}
  6957. +
  6958. +/**
  6959. + * debug_enable_fwrite - Write function for "enable" debugfs interface
  6960. + * @filp: The active open file structure for the debugfs "file"
  6961. + * @ubuf: The user buffer that contains the value to write
  6962. + * @cnt: The maximum number of bytes to write to "file"
  6963. + * @ppos: The current position in the debugfs "file"
  6964. + *
  6965. + * This function provides a write implementation for the "enable" debugfs
  6966. + * interface to the hardware latency detector. Can be used to enable or
  6967. + * disable the detector, which will have the side-effect of possibly
  6968. + * also resetting the global stats and kicking off the measuring
  6969. + * kthread (on an enable) or the converse (upon a disable).
  6970. + */
  6971. +static ssize_t debug_enable_fwrite(struct file *filp,
  6972. + const char __user *ubuf,
  6973. + size_t cnt,
  6974. + loff_t *ppos)
  6975. +{
  6976. + char buf[4];
  6977. + int csize = min(cnt, sizeof(buf));
  6978. + long val = 0;
  6979. + int err = 0;
  6980. +
  6981. + memset(buf, '\0', sizeof(buf));
  6982. + if (copy_from_user(buf, ubuf, csize))
  6983. + return -EFAULT;
  6984. +
  6985. + buf[sizeof(buf)-1] = '\0'; /* just in case */
  6986. + err = kstrtoul(buf, 10, &val);
  6987. + if (0 != err)
  6988. + return -EINVAL;
  6989. +
  6990. + if (val) {
  6991. + if (enabled)
  6992. + goto unlock;
  6993. + enabled = 1;
  6994. + __reset_stats();
  6995. + if (start_kthread())
  6996. + return -EFAULT;
  6997. + } else {
  6998. + if (!enabled)
  6999. + goto unlock;
  7000. + enabled = 0;
  7001. + err = stop_kthread();
  7002. + if (err) {
  7003. + pr_err(BANNER "cannot stop kthread\n");
  7004. + return -EFAULT;
  7005. + }
  7006. + wake_up(&data.wq); /* reader(s) should return */
  7007. + }
  7008. +unlock:
  7009. + return csize;
  7010. +}
  7011. +
  7012. +/**
  7013. + * debug_max_fopen - Open function for "max" debugfs entry
  7014. + * @inode: The in-kernel inode representation of the debugfs "file"
  7015. + * @filp: The active open file structure for the debugfs "file"
  7016. + *
  7017. + * This function provides an open implementation for the "max" debugfs
  7018. + * interface to the hardware latency detector.
  7019. + */
  7020. +static int debug_max_fopen(struct inode *inode, struct file *filp)
  7021. +{
  7022. + return 0;
  7023. +}
  7024. +
  7025. +/**
  7026. + * debug_max_fread - Read function for "max" debugfs entry
  7027. + * @filp: The active open file structure for the debugfs "file"
  7028. + * @ubuf: The userspace provided buffer to read value into
  7029. + * @cnt: The maximum number of bytes to read
  7030. + * @ppos: The current "file" position
  7031. + *
  7032. + * This function provides a read implementation for the "max" debugfs
  7033. + * interface to the hardware latency detector. Can be used to determine
  7034. + * the maximum latency value observed since it was last reset.
  7035. + */
  7036. +static ssize_t debug_max_fread(struct file *filp, char __user *ubuf,
  7037. + size_t cnt, loff_t *ppos)
  7038. +{
  7039. + return simple_data_read(filp, ubuf, cnt, ppos, &data.max_sample);
  7040. +}
  7041. +
  7042. +/**
  7043. + * debug_max_fwrite - Write function for "max" debugfs entry
  7044. + * @filp: The active open file structure for the debugfs "file"
  7045. + * @ubuf: The user buffer that contains the value to write
  7046. + * @cnt: The maximum number of bytes to write to "file"
  7047. + * @ppos: The current position in the debugfs "file"
  7048. + *
  7049. + * This function provides a write implementation for the "max" debugfs
  7050. + * interface to the hardware latency detector. Can be used to reset the
  7051. + * maximum or set it to some other desired value - if, then, subsequent
  7052. + * measurements exceed this value, the maximum will be updated.
  7053. + */
  7054. +static ssize_t debug_max_fwrite(struct file *filp,
  7055. + const char __user *ubuf,
  7056. + size_t cnt,
  7057. + loff_t *ppos)
  7058. +{
  7059. + return simple_data_write(filp, ubuf, cnt, ppos, &data.max_sample);
  7060. +}
  7061. +
  7062. +
  7063. +/**
  7064. + * debug_sample_fopen - An open function for "sample" debugfs interface
  7065. + * @inode: The in-kernel inode representation of this debugfs "file"
  7066. + * @filp: The active open file structure for the debugfs "file"
  7067. + *
  7068. + * This function handles opening the "sample" file within the hardware
  7069. + * latency detector debugfs directory interface. This file is used to read
  7070. + * raw samples from the global ring_buffer and allows the user to see a
  7071. + * running latency history. Can be opened blocking or non-blocking,
  7072. + * affecting whether it behaves as a buffer read pipe, or does not.
  7073. + * Implements simple locking to prevent multiple simultaneous use.
  7074. + */
  7075. +static int debug_sample_fopen(struct inode *inode, struct file *filp)
  7076. +{
  7077. + if (!atomic_add_unless(&data.sample_open, 1, 1))
  7078. + return -EBUSY;
  7079. + else
  7080. + return 0;
  7081. +}
  7082. +
  7083. +/**
  7084. + * debug_sample_fread - A read function for "sample" debugfs interface
  7085. + * @filp: The active open file structure for the debugfs "file"
  7086. + * @ubuf: The user buffer that will contain the samples read
  7087. + * @cnt: The maximum bytes to read from the debugfs "file"
  7088. + * @ppos: The current position in the debugfs "file"
  7089. + *
  7090. + * This function handles reading from the "sample" file within the hardware
  7091. + * latency detector debugfs directory interface. This file is used to read
  7092. + * raw samples from the global ring_buffer and allows the user to see a
  7093. + * running latency history. By default this will block pending a new
  7094. + * value written into the sample buffer, unless there are already a
  7095. + * number of value(s) waiting in the buffer, or the sample file was
  7096. + * previously opened in a non-blocking mode of operation.
  7097. + */
  7098. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  7099. + size_t cnt, loff_t *ppos)
  7100. +{
  7101. + int len = 0;
  7102. + char buf[64];
  7103. + struct sample *sample = NULL;
  7104. +
  7105. + if (!enabled)
  7106. + return 0;
  7107. +
  7108. + sample = kzalloc(sizeof(struct sample), GFP_KERNEL);
  7109. + if (!sample)
  7110. + return -ENOMEM;
  7111. +
  7112. + while (!buffer_get_sample(sample)) {
  7113. +
  7114. + DEFINE_WAIT(wait);
  7115. +
  7116. + if (filp->f_flags & O_NONBLOCK) {
  7117. + len = -EAGAIN;
  7118. + goto out;
  7119. + }
  7120. +
  7121. + prepare_to_wait(&data.wq, &wait, TASK_INTERRUPTIBLE);
  7122. + schedule();
  7123. + finish_wait(&data.wq, &wait);
  7124. +
  7125. + if (signal_pending(current)) {
  7126. + len = -EINTR;
  7127. + goto out;
  7128. + }
  7129. +
  7130. + if (!enabled) { /* enable was toggled */
  7131. + len = 0;
  7132. + goto out;
  7133. + }
  7134. + }
  7135. +
  7136. + len = snprintf(buf, sizeof(buf), "%010lu.%010lu\t%llu\t%llu\n",
  7137. + sample->timestamp.tv_sec,
  7138. + sample->timestamp.tv_nsec,
  7139. + sample->duration,
  7140. + sample->outer_duration);
  7141. +
  7142. +
  7143. + /* handling partial reads is more trouble than it's worth */
  7144. + if (len > cnt)
  7145. + goto out;
  7146. +
  7147. + if (copy_to_user(ubuf, buf, len))
  7148. + len = -EFAULT;
  7149. +
  7150. +out:
  7151. + kfree(sample);
  7152. + return len;
  7153. +}
  7154. +
  7155. +/**
  7156. + * debug_sample_release - Release function for "sample" debugfs interface
  7157. + * @inode: The in-kernel inode represenation of the debugfs "file"
  7158. + * @filp: The active open file structure for the debugfs "file"
  7159. + *
  7160. + * This function completes the close of the debugfs interface "sample" file.
  7161. + * Frees the sample_open "lock" so that other users may open the interface.
  7162. + */
  7163. +static int debug_sample_release(struct inode *inode, struct file *filp)
  7164. +{
  7165. + atomic_dec(&data.sample_open);
  7166. +
  7167. + return 0;
  7168. +}
  7169. +
  7170. +/**
  7171. + * debug_threshold_fopen - Open function for "threshold" debugfs entry
  7172. + * @inode: The in-kernel inode representation of the debugfs "file"
  7173. + * @filp: The active open file structure for the debugfs "file"
  7174. + *
  7175. + * This function provides an open implementation for the "threshold" debugfs
  7176. + * interface to the hardware latency detector.
  7177. + */
  7178. +static int debug_threshold_fopen(struct inode *inode, struct file *filp)
  7179. +{
  7180. + return 0;
  7181. +}
  7182. +
  7183. +/**
  7184. + * debug_threshold_fread - Read function for "threshold" debugfs entry
  7185. + * @filp: The active open file structure for the debugfs "file"
  7186. + * @ubuf: The userspace provided buffer to read value into
  7187. + * @cnt: The maximum number of bytes to read
  7188. + * @ppos: The current "file" position
  7189. + *
  7190. + * This function provides a read implementation for the "threshold" debugfs
  7191. + * interface to the hardware latency detector. It can be used to determine
  7192. + * the current threshold level at which a latency will be recorded in the
  7193. + * global ring buffer, typically on the order of 10us.
  7194. + */
  7195. +static ssize_t debug_threshold_fread(struct file *filp, char __user *ubuf,
  7196. + size_t cnt, loff_t *ppos)
  7197. +{
  7198. + return simple_data_read(filp, ubuf, cnt, ppos, &data.threshold);
  7199. +}
  7200. +
  7201. +/**
  7202. + * debug_threshold_fwrite - Write function for "threshold" debugfs entry
  7203. + * @filp: The active open file structure for the debugfs "file"
  7204. + * @ubuf: The user buffer that contains the value to write
  7205. + * @cnt: The maximum number of bytes to write to "file"
  7206. + * @ppos: The current position in the debugfs "file"
  7207. + *
  7208. + * This function provides a write implementation for the "threshold" debugfs
  7209. + * interface to the hardware latency detector. It can be used to configure
  7210. + * the threshold level at which any subsequently detected latencies will
  7211. + * be recorded into the global ring buffer.
  7212. + */
  7213. +static ssize_t debug_threshold_fwrite(struct file *filp,
  7214. + const char __user *ubuf,
  7215. + size_t cnt,
  7216. + loff_t *ppos)
  7217. +{
  7218. + int ret;
  7219. +
  7220. + ret = simple_data_write(filp, ubuf, cnt, ppos, &data.threshold);
  7221. +
  7222. + if (enabled)
  7223. + wake_up_process(kthread);
  7224. +
  7225. + return ret;
  7226. +}
  7227. +
  7228. +/**
  7229. + * debug_width_fopen - Open function for "width" debugfs entry
  7230. + * @inode: The in-kernel inode representation of the debugfs "file"
  7231. + * @filp: The active open file structure for the debugfs "file"
  7232. + *
  7233. + * This function provides an open implementation for the "width" debugfs
  7234. + * interface to the hardware latency detector.
  7235. + */
  7236. +static int debug_width_fopen(struct inode *inode, struct file *filp)
  7237. +{
  7238. + return 0;
  7239. +}
  7240. +
  7241. +/**
  7242. + * debug_width_fread - Read function for "width" debugfs entry
  7243. + * @filp: The active open file structure for the debugfs "file"
  7244. + * @ubuf: The userspace provided buffer to read value into
  7245. + * @cnt: The maximum number of bytes to read
  7246. + * @ppos: The current "file" position
  7247. + *
  7248. + * This function provides a read implementation for the "width" debugfs
  7249. + * interface to the hardware latency detector. It can be used to determine
  7250. + * for how many us of the total window us we will actively sample for any
  7251. + * hardware-induced latecy periods. Obviously, it is not possible to
  7252. + * sample constantly and have the system respond to a sample reader, or,
  7253. + * worse, without having the system appear to have gone out to lunch.
  7254. + */
  7255. +static ssize_t debug_width_fread(struct file *filp, char __user *ubuf,
  7256. + size_t cnt, loff_t *ppos)
  7257. +{
  7258. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_width);
  7259. +}
  7260. +
  7261. +/**
  7262. + * debug_width_fwrite - Write function for "width" debugfs entry
  7263. + * @filp: The active open file structure for the debugfs "file"
  7264. + * @ubuf: The user buffer that contains the value to write
  7265. + * @cnt: The maximum number of bytes to write to "file"
  7266. + * @ppos: The current position in the debugfs "file"
  7267. + *
  7268. + * This function provides a write implementation for the "width" debugfs
  7269. + * interface to the hardware latency detector. It can be used to configure
  7270. + * for how many us of the total window us we will actively sample for any
  7271. + * hardware-induced latency periods. Obviously, it is not possible to
  7272. + * sample constantly and have the system respond to a sample reader, or,
  7273. + * worse, without having the system appear to have gone out to lunch. It
  7274. + * is enforced that width is less that the total window size.
  7275. + */
  7276. +static ssize_t debug_width_fwrite(struct file *filp,
  7277. + const char __user *ubuf,
  7278. + size_t cnt,
  7279. + loff_t *ppos)
  7280. +{
  7281. + char buf[U64STR_SIZE];
  7282. + int csize = min(cnt, sizeof(buf));
  7283. + u64 val = 0;
  7284. + int err = 0;
  7285. +
  7286. + memset(buf, '\0', sizeof(buf));
  7287. + if (copy_from_user(buf, ubuf, csize))
  7288. + return -EFAULT;
  7289. +
  7290. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  7291. + err = kstrtoull(buf, 10, &val);
  7292. + if (0 != err)
  7293. + return -EINVAL;
  7294. +
  7295. + mutex_lock(&data.lock);
  7296. + if (val < data.sample_window)
  7297. + data.sample_width = val;
  7298. + else {
  7299. + mutex_unlock(&data.lock);
  7300. + return -EINVAL;
  7301. + }
  7302. + mutex_unlock(&data.lock);
  7303. +
  7304. + if (enabled)
  7305. + wake_up_process(kthread);
  7306. +
  7307. + return csize;
  7308. +}
  7309. +
  7310. +/**
  7311. + * debug_window_fopen - Open function for "window" debugfs entry
  7312. + * @inode: The in-kernel inode representation of the debugfs "file"
  7313. + * @filp: The active open file structure for the debugfs "file"
  7314. + *
  7315. + * This function provides an open implementation for the "window" debugfs
  7316. + * interface to the hardware latency detector. The window is the total time
  7317. + * in us that will be considered one sample period. Conceptually, windows
  7318. + * occur back-to-back and contain a sample width period during which
  7319. + * actual sampling occurs.
  7320. + */
  7321. +static int debug_window_fopen(struct inode *inode, struct file *filp)
  7322. +{
  7323. + return 0;
  7324. +}
  7325. +
  7326. +/**
  7327. + * debug_window_fread - Read function for "window" debugfs entry
  7328. + * @filp: The active open file structure for the debugfs "file"
  7329. + * @ubuf: The userspace provided buffer to read value into
  7330. + * @cnt: The maximum number of bytes to read
  7331. + * @ppos: The current "file" position
  7332. + *
  7333. + * This function provides a read implementation for the "window" debugfs
  7334. + * interface to the hardware latency detector. The window is the total time
  7335. + * in us that will be considered one sample period. Conceptually, windows
  7336. + * occur back-to-back and contain a sample width period during which
  7337. + * actual sampling occurs. Can be used to read the total window size.
  7338. + */
  7339. +static ssize_t debug_window_fread(struct file *filp, char __user *ubuf,
  7340. + size_t cnt, loff_t *ppos)
  7341. +{
  7342. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_window);
  7343. +}
  7344. +
  7345. +/**
  7346. + * debug_window_fwrite - Write function for "window" debugfs entry
  7347. + * @filp: The active open file structure for the debugfs "file"
  7348. + * @ubuf: The user buffer that contains the value to write
  7349. + * @cnt: The maximum number of bytes to write to "file"
  7350. + * @ppos: The current position in the debugfs "file"
  7351. + *
  7352. + * This function provides a write implementation for the "window" debufds
  7353. + * interface to the hardware latency detetector. The window is the total time
  7354. + * in us that will be considered one sample period. Conceptually, windows
  7355. + * occur back-to-back and contain a sample width period during which
  7356. + * actual sampling occurs. Can be used to write a new total window size. It
  7357. + * is enfoced that any value written must be greater than the sample width
  7358. + * size, or an error results.
  7359. + */
  7360. +static ssize_t debug_window_fwrite(struct file *filp,
  7361. + const char __user *ubuf,
  7362. + size_t cnt,
  7363. + loff_t *ppos)
  7364. +{
  7365. + char buf[U64STR_SIZE];
  7366. + int csize = min(cnt, sizeof(buf));
  7367. + u64 val = 0;
  7368. + int err = 0;
  7369. +
  7370. + memset(buf, '\0', sizeof(buf));
  7371. + if (copy_from_user(buf, ubuf, csize))
  7372. + return -EFAULT;
  7373. +
  7374. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  7375. + err = kstrtoull(buf, 10, &val);
  7376. + if (0 != err)
  7377. + return -EINVAL;
  7378. +
  7379. + mutex_lock(&data.lock);
  7380. + if (data.sample_width < val)
  7381. + data.sample_window = val;
  7382. + else {
  7383. + mutex_unlock(&data.lock);
  7384. + return -EINVAL;
  7385. + }
  7386. + mutex_unlock(&data.lock);
  7387. +
  7388. + return csize;
  7389. +}
  7390. +
  7391. +/*
  7392. + * Function pointers for the "count" debugfs file operations
  7393. + */
  7394. +static const struct file_operations count_fops = {
  7395. + .open = debug_count_fopen,
  7396. + .read = debug_count_fread,
  7397. + .write = debug_count_fwrite,
  7398. + .owner = THIS_MODULE,
  7399. +};
  7400. +
  7401. +/*
  7402. + * Function pointers for the "enable" debugfs file operations
  7403. + */
  7404. +static const struct file_operations enable_fops = {
  7405. + .open = debug_enable_fopen,
  7406. + .read = debug_enable_fread,
  7407. + .write = debug_enable_fwrite,
  7408. + .owner = THIS_MODULE,
  7409. +};
  7410. +
  7411. +/*
  7412. + * Function pointers for the "max" debugfs file operations
  7413. + */
  7414. +static const struct file_operations max_fops = {
  7415. + .open = debug_max_fopen,
  7416. + .read = debug_max_fread,
  7417. + .write = debug_max_fwrite,
  7418. + .owner = THIS_MODULE,
  7419. +};
  7420. +
  7421. +/*
  7422. + * Function pointers for the "sample" debugfs file operations
  7423. + */
  7424. +static const struct file_operations sample_fops = {
  7425. + .open = debug_sample_fopen,
  7426. + .read = debug_sample_fread,
  7427. + .release = debug_sample_release,
  7428. + .owner = THIS_MODULE,
  7429. +};
  7430. +
  7431. +/*
  7432. + * Function pointers for the "threshold" debugfs file operations
  7433. + */
  7434. +static const struct file_operations threshold_fops = {
  7435. + .open = debug_threshold_fopen,
  7436. + .read = debug_threshold_fread,
  7437. + .write = debug_threshold_fwrite,
  7438. + .owner = THIS_MODULE,
  7439. +};
  7440. +
  7441. +/*
  7442. + * Function pointers for the "width" debugfs file operations
  7443. + */
  7444. +static const struct file_operations width_fops = {
  7445. + .open = debug_width_fopen,
  7446. + .read = debug_width_fread,
  7447. + .write = debug_width_fwrite,
  7448. + .owner = THIS_MODULE,
  7449. +};
  7450. +
  7451. +/*
  7452. + * Function pointers for the "window" debugfs file operations
  7453. + */
  7454. +static const struct file_operations window_fops = {
  7455. + .open = debug_window_fopen,
  7456. + .read = debug_window_fread,
  7457. + .write = debug_window_fwrite,
  7458. + .owner = THIS_MODULE,
  7459. +};
  7460. +
  7461. +/**
  7462. + * init_debugfs - A function to initialize the debugfs interface files
  7463. + *
  7464. + * This function creates entries in debugfs for "hwlat_detector", including
  7465. + * files to read values from the detector, current samples, and the
  7466. + * maximum sample that has been captured since the hardware latency
  7467. + * dectector was started.
  7468. + */
  7469. +static int init_debugfs(void)
  7470. +{
  7471. + int ret = -ENOMEM;
  7472. +
  7473. + debug_dir = debugfs_create_dir(DRVNAME, NULL);
  7474. + if (!debug_dir)
  7475. + goto err_debug_dir;
  7476. +
  7477. + debug_sample = debugfs_create_file("sample", 0444,
  7478. + debug_dir, NULL,
  7479. + &sample_fops);
  7480. + if (!debug_sample)
  7481. + goto err_sample;
  7482. +
  7483. + debug_count = debugfs_create_file("count", 0444,
  7484. + debug_dir, NULL,
  7485. + &count_fops);
  7486. + if (!debug_count)
  7487. + goto err_count;
  7488. +
  7489. + debug_max = debugfs_create_file("max", 0444,
  7490. + debug_dir, NULL,
  7491. + &max_fops);
  7492. + if (!debug_max)
  7493. + goto err_max;
  7494. +
  7495. + debug_sample_window = debugfs_create_file("window", 0644,
  7496. + debug_dir, NULL,
  7497. + &window_fops);
  7498. + if (!debug_sample_window)
  7499. + goto err_window;
  7500. +
  7501. + debug_sample_width = debugfs_create_file("width", 0644,
  7502. + debug_dir, NULL,
  7503. + &width_fops);
  7504. + if (!debug_sample_width)
  7505. + goto err_width;
  7506. +
  7507. + debug_threshold = debugfs_create_file("threshold", 0644,
  7508. + debug_dir, NULL,
  7509. + &threshold_fops);
  7510. + if (!debug_threshold)
  7511. + goto err_threshold;
  7512. +
  7513. + debug_enable = debugfs_create_file("enable", 0644,
  7514. + debug_dir, &enabled,
  7515. + &enable_fops);
  7516. + if (!debug_enable)
  7517. + goto err_enable;
  7518. +
  7519. + else {
  7520. + ret = 0;
  7521. + goto out;
  7522. + }
  7523. +
  7524. +err_enable:
  7525. + debugfs_remove(debug_threshold);
  7526. +err_threshold:
  7527. + debugfs_remove(debug_sample_width);
  7528. +err_width:
  7529. + debugfs_remove(debug_sample_window);
  7530. +err_window:
  7531. + debugfs_remove(debug_max);
  7532. +err_max:
  7533. + debugfs_remove(debug_count);
  7534. +err_count:
  7535. + debugfs_remove(debug_sample);
  7536. +err_sample:
  7537. + debugfs_remove(debug_dir);
  7538. +err_debug_dir:
  7539. +out:
  7540. + return ret;
  7541. +}
  7542. +
  7543. +/**
  7544. + * free_debugfs - A function to cleanup the debugfs file interface
  7545. + */
  7546. +static void free_debugfs(void)
  7547. +{
  7548. + /* could also use a debugfs_remove_recursive */
  7549. + debugfs_remove(debug_enable);
  7550. + debugfs_remove(debug_threshold);
  7551. + debugfs_remove(debug_sample_width);
  7552. + debugfs_remove(debug_sample_window);
  7553. + debugfs_remove(debug_max);
  7554. + debugfs_remove(debug_count);
  7555. + debugfs_remove(debug_sample);
  7556. + debugfs_remove(debug_dir);
  7557. +}
  7558. +
  7559. +/**
  7560. + * detector_init - Standard module initialization code
  7561. + */
  7562. +static int detector_init(void)
  7563. +{
  7564. + int ret = -ENOMEM;
  7565. +
  7566. + pr_info(BANNER "version %s\n", VERSION);
  7567. +
  7568. + ret = init_stats();
  7569. + if (0 != ret)
  7570. + goto out;
  7571. +
  7572. + ret = init_debugfs();
  7573. + if (0 != ret)
  7574. + goto err_stats;
  7575. +
  7576. + if (enabled)
  7577. + ret = start_kthread();
  7578. +
  7579. + goto out;
  7580. +
  7581. +err_stats:
  7582. + ring_buffer_free(ring_buffer);
  7583. +out:
  7584. + return ret;
  7585. +
  7586. +}
  7587. +
  7588. +/**
  7589. + * detector_exit - Standard module cleanup code
  7590. + */
  7591. +static void detector_exit(void)
  7592. +{
  7593. + int err;
  7594. +
  7595. + if (enabled) {
  7596. + enabled = 0;
  7597. + err = stop_kthread();
  7598. + if (err)
  7599. + pr_err(BANNER "cannot stop kthread\n");
  7600. + }
  7601. +
  7602. + free_debugfs();
  7603. + ring_buffer_free(ring_buffer); /* free up the ring buffer */
  7604. +
  7605. +}
  7606. +
  7607. +module_init(detector_init);
  7608. +module_exit(detector_exit);
  7609. diff -Nur linux-4.1.26.orig/drivers/misc/Kconfig linux-4.1.26/drivers/misc/Kconfig
  7610. --- linux-4.1.26.orig/drivers/misc/Kconfig 2016-06-07 01:13:11.000000000 +0200
  7611. +++ linux-4.1.26/drivers/misc/Kconfig 2016-06-19 15:30:58.639295498 +0200
  7612. @@ -54,6 +54,7 @@
  7613. config ATMEL_TCLIB
  7614. bool "Atmel AT32/AT91 Timer/Counter Library"
  7615. depends on (AVR32 || ARCH_AT91)
  7616. + default y if PREEMPT_RT_FULL
  7617. help
  7618. Select this if you want a library to allocate the Timer/Counter
  7619. blocks found on many Atmel processors. This facilitates using
  7620. @@ -69,8 +70,7 @@
  7621. are combined to make a single 32-bit timer.
  7622. When GENERIC_CLOCKEVENTS is defined, the third timer channel
  7623. - may be used as a clock event device supporting oneshot mode
  7624. - (delays of up to two seconds) based on the 32 KiHz clock.
  7625. + may be used as a clock event device supporting oneshot mode.
  7626. config ATMEL_TCB_CLKSRC_BLOCK
  7627. int
  7628. @@ -84,6 +84,15 @@
  7629. TC can be used for other purposes, such as PWM generation and
  7630. interval timing.
  7631. +config ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  7632. + bool "TC Block use 32 KiHz clock"
  7633. + depends on ATMEL_TCB_CLKSRC
  7634. + default y if !PREEMPT_RT_FULL
  7635. + help
  7636. + Select this to use 32 KiHz base clock rate as TC block clock
  7637. + source for clock events.
  7638. +
  7639. +
  7640. config DUMMY_IRQ
  7641. tristate "Dummy IRQ handler"
  7642. default n
  7643. @@ -113,6 +122,35 @@
  7644. for information on the specific driver level and support statement
  7645. for your IBM server.
  7646. +config HWLAT_DETECTOR
  7647. + tristate "Testing module to detect hardware-induced latencies"
  7648. + depends on DEBUG_FS
  7649. + depends on RING_BUFFER
  7650. + default m
  7651. + ---help---
  7652. + A simple hardware latency detector. Use this module to detect
  7653. + large latencies introduced by the behavior of the underlying
  7654. + system firmware external to Linux. We do this using periodic
  7655. + use of stop_machine to grab all available CPUs and measure
  7656. + for unexplainable gaps in the CPU timestamp counter(s). By
  7657. + default, the module is not enabled until the "enable" file
  7658. + within the "hwlat_detector" debugfs directory is toggled.
  7659. +
  7660. + This module is often used to detect SMI (System Management
  7661. + Interrupts) on x86 systems, though is not x86 specific. To
  7662. + this end, we default to using a sample window of 1 second,
  7663. + during which we will sample for 0.5 seconds. If an SMI or
  7664. + similar event occurs during that time, it is recorded
  7665. + into an 8K samples global ring buffer until retreived.
  7666. +
  7667. + WARNING: This software should never be enabled (it can be built
  7668. + but should not be turned on after it is loaded) in a production
  7669. + environment where high latencies are a concern since the
  7670. + sampling mechanism actually introduces latencies for
  7671. + regular tasks while the CPU(s) are being held.
  7672. +
  7673. + If unsure, say N
  7674. +
  7675. config PHANTOM
  7676. tristate "Sensable PHANToM (PCI)"
  7677. depends on PCI
  7678. diff -Nur linux-4.1.26.orig/drivers/misc/Makefile linux-4.1.26/drivers/misc/Makefile
  7679. --- linux-4.1.26.orig/drivers/misc/Makefile 2016-06-07 01:13:11.000000000 +0200
  7680. +++ linux-4.1.26/drivers/misc/Makefile 2016-06-19 15:30:58.639295498 +0200
  7681. @@ -38,6 +38,7 @@
  7682. obj-$(CONFIG_HMC6352) += hmc6352.o
  7683. obj-y += eeprom/
  7684. obj-y += cb710/
  7685. +obj-$(CONFIG_HWLAT_DETECTOR) += hwlat_detector.o
  7686. obj-$(CONFIG_SPEAR13XX_PCIE_GADGET) += spear13xx_pcie_gadget.o
  7687. obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
  7688. obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
  7689. diff -Nur linux-4.1.26.orig/drivers/mmc/host/mmci.c linux-4.1.26/drivers/mmc/host/mmci.c
  7690. --- linux-4.1.26.orig/drivers/mmc/host/mmci.c 2016-06-07 01:13:11.000000000 +0200
  7691. +++ linux-4.1.26/drivers/mmc/host/mmci.c 2016-06-19 15:30:58.643295653 +0200
  7692. @@ -1155,15 +1155,12 @@
  7693. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  7694. struct variant_data *variant = host->variant;
  7695. void __iomem *base = host->base;
  7696. - unsigned long flags;
  7697. u32 status;
  7698. status = readl(base + MMCISTATUS);
  7699. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  7700. - local_irq_save(flags);
  7701. -
  7702. do {
  7703. unsigned int remain, len;
  7704. char *buffer;
  7705. @@ -1203,8 +1200,6 @@
  7706. sg_miter_stop(sg_miter);
  7707. - local_irq_restore(flags);
  7708. -
  7709. /*
  7710. * If we have less than the fifo 'half-full' threshold to transfer,
  7711. * trigger a PIO interrupt as soon as any data is available.
  7712. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/3com/3c59x.c linux-4.1.26/drivers/net/ethernet/3com/3c59x.c
  7713. --- linux-4.1.26.orig/drivers/net/ethernet/3com/3c59x.c 2016-06-07 01:13:11.000000000 +0200
  7714. +++ linux-4.1.26/drivers/net/ethernet/3com/3c59x.c 2016-06-19 15:30:58.643295653 +0200
  7715. @@ -842,9 +842,9 @@
  7716. {
  7717. struct vortex_private *vp = netdev_priv(dev);
  7718. unsigned long flags;
  7719. - local_irq_save(flags);
  7720. + local_irq_save_nort(flags);
  7721. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
  7722. - local_irq_restore(flags);
  7723. + local_irq_restore_nort(flags);
  7724. }
  7725. #endif
  7726. @@ -1916,12 +1916,12 @@
  7727. * Block interrupts because vortex_interrupt does a bare spin_lock()
  7728. */
  7729. unsigned long flags;
  7730. - local_irq_save(flags);
  7731. + local_irq_save_nort(flags);
  7732. if (vp->full_bus_master_tx)
  7733. boomerang_interrupt(dev->irq, dev);
  7734. else
  7735. vortex_interrupt(dev->irq, dev);
  7736. - local_irq_restore(flags);
  7737. + local_irq_restore_nort(flags);
  7738. }
  7739. }
  7740. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c linux-4.1.26/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
  7741. --- linux-4.1.26.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2016-06-07 01:13:11.000000000 +0200
  7742. +++ linux-4.1.26/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2016-06-19 15:30:58.643295653 +0200
  7743. @@ -2212,11 +2212,7 @@
  7744. }
  7745. tpd_req = atl1c_cal_tpd_req(skb);
  7746. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
  7747. - if (netif_msg_pktdata(adapter))
  7748. - dev_info(&adapter->pdev->dev, "tx locked\n");
  7749. - return NETDEV_TX_LOCKED;
  7750. - }
  7751. + spin_lock_irqsave(&adapter->tx_lock, flags);
  7752. if (atl1c_tpd_avail(adapter, type) < tpd_req) {
  7753. /* no enough descriptor, just stop queue */
  7754. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c linux-4.1.26/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
  7755. --- linux-4.1.26.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2016-06-07 01:13:11.000000000 +0200
  7756. +++ linux-4.1.26/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2016-06-19 15:30:58.643295653 +0200
  7757. @@ -1880,8 +1880,7 @@
  7758. return NETDEV_TX_OK;
  7759. }
  7760. tpd_req = atl1e_cal_tdp_req(skb);
  7761. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags))
  7762. - return NETDEV_TX_LOCKED;
  7763. + spin_lock_irqsave(&adapter->tx_lock, flags);
  7764. if (atl1e_tpd_avail(adapter) < tpd_req) {
  7765. /* no enough descriptor, just stop queue */
  7766. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/chelsio/cxgb/sge.c linux-4.1.26/drivers/net/ethernet/chelsio/cxgb/sge.c
  7767. --- linux-4.1.26.orig/drivers/net/ethernet/chelsio/cxgb/sge.c 2016-06-07 01:13:11.000000000 +0200
  7768. +++ linux-4.1.26/drivers/net/ethernet/chelsio/cxgb/sge.c 2016-06-19 15:30:58.643295653 +0200
  7769. @@ -1664,8 +1664,7 @@
  7770. struct cmdQ *q = &sge->cmdQ[qid];
  7771. unsigned int credits, pidx, genbit, count, use_sched_skb = 0;
  7772. - if (!spin_trylock(&q->lock))
  7773. - return NETDEV_TX_LOCKED;
  7774. + spin_lock(&q->lock);
  7775. reclaim_completed_tx(sge, q);
  7776. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/freescale/gianfar.c linux-4.1.26/drivers/net/ethernet/freescale/gianfar.c
  7777. --- linux-4.1.26.orig/drivers/net/ethernet/freescale/gianfar.c 2016-06-07 01:13:11.000000000 +0200
  7778. +++ linux-4.1.26/drivers/net/ethernet/freescale/gianfar.c 2016-06-19 15:30:58.643295653 +0200
  7779. @@ -1540,7 +1540,7 @@
  7780. if (netif_running(ndev)) {
  7781. - local_irq_save(flags);
  7782. + local_irq_save_nort(flags);
  7783. lock_tx_qs(priv);
  7784. gfar_halt_nodisable(priv);
  7785. @@ -1556,7 +1556,7 @@
  7786. gfar_write(&regs->maccfg1, tempval);
  7787. unlock_tx_qs(priv);
  7788. - local_irq_restore(flags);
  7789. + local_irq_restore_nort(flags);
  7790. disable_napi(priv);
  7791. @@ -1598,7 +1598,7 @@
  7792. /* Disable Magic Packet mode, in case something
  7793. * else woke us up.
  7794. */
  7795. - local_irq_save(flags);
  7796. + local_irq_save_nort(flags);
  7797. lock_tx_qs(priv);
  7798. tempval = gfar_read(&regs->maccfg2);
  7799. @@ -1608,7 +1608,7 @@
  7800. gfar_start(priv);
  7801. unlock_tx_qs(priv);
  7802. - local_irq_restore(flags);
  7803. + local_irq_restore_nort(flags);
  7804. netif_device_attach(ndev);
  7805. @@ -3418,14 +3418,14 @@
  7806. dev->stats.tx_dropped++;
  7807. atomic64_inc(&priv->extra_stats.tx_underrun);
  7808. - local_irq_save(flags);
  7809. + local_irq_save_nort(flags);
  7810. lock_tx_qs(priv);
  7811. /* Reactivate the Tx Queues */
  7812. gfar_write(&regs->tstat, gfargrp->tstat);
  7813. unlock_tx_qs(priv);
  7814. - local_irq_restore(flags);
  7815. + local_irq_restore_nort(flags);
  7816. }
  7817. netif_dbg(priv, tx_err, dev, "Transmit Error\n");
  7818. }
  7819. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/neterion/s2io.c linux-4.1.26/drivers/net/ethernet/neterion/s2io.c
  7820. --- linux-4.1.26.orig/drivers/net/ethernet/neterion/s2io.c 2016-06-07 01:13:11.000000000 +0200
  7821. +++ linux-4.1.26/drivers/net/ethernet/neterion/s2io.c 2016-06-19 15:30:58.647295807 +0200
  7822. @@ -4084,12 +4084,7 @@
  7823. [skb->priority & (MAX_TX_FIFOS - 1)];
  7824. fifo = &mac_control->fifos[queue];
  7825. - if (do_spin_lock)
  7826. - spin_lock_irqsave(&fifo->tx_lock, flags);
  7827. - else {
  7828. - if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  7829. - return NETDEV_TX_LOCKED;
  7830. - }
  7831. + spin_lock_irqsave(&fifo->tx_lock, flags);
  7832. if (sp->config.multiq) {
  7833. if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
  7834. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c linux-4.1.26/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
  7835. --- linux-4.1.26.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2016-06-07 01:13:11.000000000 +0200
  7836. +++ linux-4.1.26/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2016-06-19 15:30:58.647295807 +0200
  7837. @@ -2137,10 +2137,8 @@
  7838. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  7839. unsigned long flags;
  7840. - if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) {
  7841. - /* Collision - tell upper layer to requeue */
  7842. - return NETDEV_TX_LOCKED;
  7843. - }
  7844. + spin_lock_irqsave(&tx_ring->tx_lock, flags);
  7845. +
  7846. if (unlikely(!PCH_GBE_DESC_UNUSED(tx_ring))) {
  7847. netif_stop_queue(netdev);
  7848. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  7849. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/realtek/8139too.c linux-4.1.26/drivers/net/ethernet/realtek/8139too.c
  7850. --- linux-4.1.26.orig/drivers/net/ethernet/realtek/8139too.c 2016-06-07 01:13:11.000000000 +0200
  7851. +++ linux-4.1.26/drivers/net/ethernet/realtek/8139too.c 2016-06-19 15:30:58.647295807 +0200
  7852. @@ -2229,7 +2229,7 @@
  7853. struct rtl8139_private *tp = netdev_priv(dev);
  7854. const int irq = tp->pci_dev->irq;
  7855. - disable_irq(irq);
  7856. + disable_irq_nosync(irq);
  7857. rtl8139_interrupt(irq, dev);
  7858. enable_irq(irq);
  7859. }
  7860. diff -Nur linux-4.1.26.orig/drivers/net/ethernet/tehuti/tehuti.c linux-4.1.26/drivers/net/ethernet/tehuti/tehuti.c
  7861. --- linux-4.1.26.orig/drivers/net/ethernet/tehuti/tehuti.c 2016-06-07 01:13:11.000000000 +0200
  7862. +++ linux-4.1.26/drivers/net/ethernet/tehuti/tehuti.c 2016-06-19 15:30:58.647295807 +0200
  7863. @@ -1629,13 +1629,8 @@
  7864. unsigned long flags;
  7865. ENTER;
  7866. - local_irq_save(flags);
  7867. - if (!spin_trylock(&priv->tx_lock)) {
  7868. - local_irq_restore(flags);
  7869. - DBG("%s[%s]: TX locked, returning NETDEV_TX_LOCKED\n",
  7870. - BDX_DRV_NAME, ndev->name);
  7871. - return NETDEV_TX_LOCKED;
  7872. - }
  7873. +
  7874. + spin_lock_irqsave(&priv->tx_lock, flags);
  7875. /* build tx descriptor */
  7876. BDX_ASSERT(f->m.wptr >= f->m.memsz); /* started with valid wptr */
  7877. diff -Nur linux-4.1.26.orig/drivers/net/rionet.c linux-4.1.26/drivers/net/rionet.c
  7878. --- linux-4.1.26.orig/drivers/net/rionet.c 2016-06-07 01:13:11.000000000 +0200
  7879. +++ linux-4.1.26/drivers/net/rionet.c 2016-06-19 15:30:58.647295807 +0200
  7880. @@ -174,11 +174,7 @@
  7881. unsigned long flags;
  7882. int add_num = 1;
  7883. - local_irq_save(flags);
  7884. - if (!spin_trylock(&rnet->tx_lock)) {
  7885. - local_irq_restore(flags);
  7886. - return NETDEV_TX_LOCKED;
  7887. - }
  7888. + spin_lock_irqsave(&rnet->tx_lock, flags);
  7889. if (is_multicast_ether_addr(eth->h_dest))
  7890. add_num = nets[rnet->mport->id].nact;
  7891. diff -Nur linux-4.1.26.orig/drivers/net/wireless/orinoco/orinoco_usb.c linux-4.1.26/drivers/net/wireless/orinoco/orinoco_usb.c
  7892. --- linux-4.1.26.orig/drivers/net/wireless/orinoco/orinoco_usb.c 2016-06-07 01:13:11.000000000 +0200
  7893. +++ linux-4.1.26/drivers/net/wireless/orinoco/orinoco_usb.c 2016-06-19 15:30:58.647295807 +0200
  7894. @@ -697,7 +697,7 @@
  7895. while (!ctx->done.done && msecs--)
  7896. udelay(1000);
  7897. } else {
  7898. - wait_event_interruptible(ctx->done.wait,
  7899. + swait_event_interruptible(ctx->done.wait,
  7900. ctx->done.done);
  7901. }
  7902. break;
  7903. diff -Nur linux-4.1.26.orig/drivers/pci/access.c linux-4.1.26/drivers/pci/access.c
  7904. --- linux-4.1.26.orig/drivers/pci/access.c 2016-06-07 01:13:11.000000000 +0200
  7905. +++ linux-4.1.26/drivers/pci/access.c 2016-06-19 15:30:58.647295807 +0200
  7906. @@ -561,7 +561,7 @@
  7907. WARN_ON(!dev->block_cfg_access);
  7908. dev->block_cfg_access = 0;
  7909. - wake_up_all(&pci_cfg_wait);
  7910. + wake_up_all_locked(&pci_cfg_wait);
  7911. raw_spin_unlock_irqrestore(&pci_lock, flags);
  7912. }
  7913. EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
  7914. diff -Nur linux-4.1.26.orig/drivers/scsi/fcoe/fcoe.c linux-4.1.26/drivers/scsi/fcoe/fcoe.c
  7915. --- linux-4.1.26.orig/drivers/scsi/fcoe/fcoe.c 2016-06-07 01:13:11.000000000 +0200
  7916. +++ linux-4.1.26/drivers/scsi/fcoe/fcoe.c 2016-06-19 15:30:58.647295807 +0200
  7917. @@ -1287,7 +1287,7 @@
  7918. struct sk_buff *skb;
  7919. #ifdef CONFIG_SMP
  7920. struct fcoe_percpu_s *p0;
  7921. - unsigned targ_cpu = get_cpu();
  7922. + unsigned targ_cpu = get_cpu_light();
  7923. #endif /* CONFIG_SMP */
  7924. FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
  7925. @@ -1343,7 +1343,7 @@
  7926. kfree_skb(skb);
  7927. spin_unlock_bh(&p->fcoe_rx_list.lock);
  7928. }
  7929. - put_cpu();
  7930. + put_cpu_light();
  7931. #else
  7932. /*
  7933. * This a non-SMP scenario where the singular Rx thread is
  7934. @@ -1567,11 +1567,11 @@
  7935. static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
  7936. {
  7937. struct fcoe_percpu_s *fps;
  7938. - int rc;
  7939. + int rc, cpu = get_cpu_light();
  7940. - fps = &get_cpu_var(fcoe_percpu);
  7941. + fps = &per_cpu(fcoe_percpu, cpu);
  7942. rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
  7943. - put_cpu_var(fcoe_percpu);
  7944. + put_cpu_light();
  7945. return rc;
  7946. }
  7947. @@ -1767,11 +1767,11 @@
  7948. return 0;
  7949. }
  7950. - stats = per_cpu_ptr(lport->stats, get_cpu());
  7951. + stats = per_cpu_ptr(lport->stats, get_cpu_light());
  7952. stats->InvalidCRCCount++;
  7953. if (stats->InvalidCRCCount < 5)
  7954. printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
  7955. - put_cpu();
  7956. + put_cpu_light();
  7957. return -EINVAL;
  7958. }
  7959. @@ -1847,13 +1847,13 @@
  7960. goto drop;
  7961. if (!fcoe_filter_frames(lport, fp)) {
  7962. - put_cpu();
  7963. + put_cpu_light();
  7964. fc_exch_recv(lport, fp);
  7965. return;
  7966. }
  7967. drop:
  7968. stats->ErrorFrames++;
  7969. - put_cpu();
  7970. + put_cpu_light();
  7971. kfree_skb(skb);
  7972. }
  7973. diff -Nur linux-4.1.26.orig/drivers/scsi/fcoe/fcoe_ctlr.c linux-4.1.26/drivers/scsi/fcoe/fcoe_ctlr.c
  7974. --- linux-4.1.26.orig/drivers/scsi/fcoe/fcoe_ctlr.c 2016-06-07 01:13:11.000000000 +0200
  7975. +++ linux-4.1.26/drivers/scsi/fcoe/fcoe_ctlr.c 2016-06-19 15:30:58.651295961 +0200
  7976. @@ -831,7 +831,7 @@
  7977. INIT_LIST_HEAD(&del_list);
  7978. - stats = per_cpu_ptr(fip->lp->stats, get_cpu());
  7979. + stats = per_cpu_ptr(fip->lp->stats, get_cpu_light());
  7980. list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
  7981. deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2;
  7982. @@ -867,7 +867,7 @@
  7983. sel_time = fcf->time;
  7984. }
  7985. }
  7986. - put_cpu();
  7987. + put_cpu_light();
  7988. list_for_each_entry_safe(fcf, next, &del_list, list) {
  7989. /* Removes fcf from current list */
  7990. diff -Nur linux-4.1.26.orig/drivers/scsi/libfc/fc_exch.c linux-4.1.26/drivers/scsi/libfc/fc_exch.c
  7991. --- linux-4.1.26.orig/drivers/scsi/libfc/fc_exch.c 2016-06-07 01:13:11.000000000 +0200
  7992. +++ linux-4.1.26/drivers/scsi/libfc/fc_exch.c 2016-06-19 15:30:58.651295961 +0200
  7993. @@ -814,10 +814,10 @@
  7994. }
  7995. memset(ep, 0, sizeof(*ep));
  7996. - cpu = get_cpu();
  7997. + cpu = get_cpu_light();
  7998. pool = per_cpu_ptr(mp->pool, cpu);
  7999. spin_lock_bh(&pool->lock);
  8000. - put_cpu();
  8001. + put_cpu_light();
  8002. /* peek cache of free slot */
  8003. if (pool->left != FC_XID_UNKNOWN) {
  8004. diff -Nur linux-4.1.26.orig/drivers/scsi/libsas/sas_ata.c linux-4.1.26/drivers/scsi/libsas/sas_ata.c
  8005. --- linux-4.1.26.orig/drivers/scsi/libsas/sas_ata.c 2016-06-07 01:13:11.000000000 +0200
  8006. +++ linux-4.1.26/drivers/scsi/libsas/sas_ata.c 2016-06-19 15:30:58.651295961 +0200
  8007. @@ -190,7 +190,7 @@
  8008. /* TODO: audit callers to ensure they are ready for qc_issue to
  8009. * unconditionally re-enable interrupts
  8010. */
  8011. - local_irq_save(flags);
  8012. + local_irq_save_nort(flags);
  8013. spin_unlock(ap->lock);
  8014. /* If the device fell off, no sense in issuing commands */
  8015. @@ -255,7 +255,7 @@
  8016. out:
  8017. spin_lock(ap->lock);
  8018. - local_irq_restore(flags);
  8019. + local_irq_restore_nort(flags);
  8020. return ret;
  8021. }
  8022. diff -Nur linux-4.1.26.orig/drivers/scsi/qla2xxx/qla_inline.h linux-4.1.26/drivers/scsi/qla2xxx/qla_inline.h
  8023. --- linux-4.1.26.orig/drivers/scsi/qla2xxx/qla_inline.h 2016-06-07 01:13:11.000000000 +0200
  8024. +++ linux-4.1.26/drivers/scsi/qla2xxx/qla_inline.h 2016-06-19 15:30:58.651295961 +0200
  8025. @@ -59,12 +59,12 @@
  8026. {
  8027. unsigned long flags;
  8028. struct qla_hw_data *ha = rsp->hw;
  8029. - local_irq_save(flags);
  8030. + local_irq_save_nort(flags);
  8031. if (IS_P3P_TYPE(ha))
  8032. qla82xx_poll(0, rsp);
  8033. else
  8034. ha->isp_ops->intr_handler(0, rsp);
  8035. - local_irq_restore(flags);
  8036. + local_irq_restore_nort(flags);
  8037. }
  8038. static inline uint8_t *
  8039. diff -Nur linux-4.1.26.orig/drivers/thermal/x86_pkg_temp_thermal.c linux-4.1.26/drivers/thermal/x86_pkg_temp_thermal.c
  8040. --- linux-4.1.26.orig/drivers/thermal/x86_pkg_temp_thermal.c 2016-06-07 01:13:11.000000000 +0200
  8041. +++ linux-4.1.26/drivers/thermal/x86_pkg_temp_thermal.c 2016-06-19 15:30:58.651295961 +0200
  8042. @@ -29,6 +29,7 @@
  8043. #include <linux/pm.h>
  8044. #include <linux/thermal.h>
  8045. #include <linux/debugfs.h>
  8046. +#include <linux/work-simple.h>
  8047. #include <asm/cpu_device_id.h>
  8048. #include <asm/mce.h>
  8049. @@ -352,7 +353,7 @@
  8050. }
  8051. }
  8052. -static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  8053. +static void platform_thermal_notify_work(struct swork_event *event)
  8054. {
  8055. unsigned long flags;
  8056. int cpu = smp_processor_id();
  8057. @@ -369,7 +370,7 @@
  8058. pkg_work_scheduled[phy_id]) {
  8059. disable_pkg_thres_interrupt();
  8060. spin_unlock_irqrestore(&pkg_work_lock, flags);
  8061. - return -EINVAL;
  8062. + return;
  8063. }
  8064. pkg_work_scheduled[phy_id] = 1;
  8065. spin_unlock_irqrestore(&pkg_work_lock, flags);
  8066. @@ -378,9 +379,48 @@
  8067. schedule_delayed_work_on(cpu,
  8068. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  8069. msecs_to_jiffies(notify_delay_ms));
  8070. +}
  8071. +
  8072. +#ifdef CONFIG_PREEMPT_RT_FULL
  8073. +static struct swork_event notify_work;
  8074. +
  8075. +static int thermal_notify_work_init(void)
  8076. +{
  8077. + int err;
  8078. +
  8079. + err = swork_get();
  8080. + if (err)
  8081. + return err;
  8082. +
  8083. + INIT_SWORK(&notify_work, platform_thermal_notify_work);
  8084. return 0;
  8085. }
  8086. +static void thermal_notify_work_cleanup(void)
  8087. +{
  8088. + swork_put();
  8089. +}
  8090. +
  8091. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  8092. +{
  8093. + swork_queue(&notify_work);
  8094. + return 0;
  8095. +}
  8096. +
  8097. +#else /* !CONFIG_PREEMPT_RT_FULL */
  8098. +
  8099. +static int thermal_notify_work_init(void) { return 0; }
  8100. +
  8101. +static void thermal_notify_work_cleanup(void) { }
  8102. +
  8103. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  8104. +{
  8105. + platform_thermal_notify_work(NULL);
  8106. +
  8107. + return 0;
  8108. +}
  8109. +#endif /* CONFIG_PREEMPT_RT_FULL */
  8110. +
  8111. static int find_siblings_cpu(int cpu)
  8112. {
  8113. int i;
  8114. @@ -584,6 +624,9 @@
  8115. if (!x86_match_cpu(pkg_temp_thermal_ids))
  8116. return -ENODEV;
  8117. + if (!thermal_notify_work_init())
  8118. + return -ENODEV;
  8119. +
  8120. spin_lock_init(&pkg_work_lock);
  8121. platform_thermal_package_notify =
  8122. pkg_temp_thermal_platform_thermal_notify;
  8123. @@ -608,7 +651,7 @@
  8124. kfree(pkg_work_scheduled);
  8125. platform_thermal_package_notify = NULL;
  8126. platform_thermal_package_rate_control = NULL;
  8127. -
  8128. + thermal_notify_work_cleanup();
  8129. return -ENODEV;
  8130. }
  8131. @@ -633,6 +676,7 @@
  8132. mutex_unlock(&phy_dev_list_mutex);
  8133. platform_thermal_package_notify = NULL;
  8134. platform_thermal_package_rate_control = NULL;
  8135. + thermal_notify_work_cleanup();
  8136. for_each_online_cpu(i)
  8137. cancel_delayed_work_sync(
  8138. &per_cpu(pkg_temp_thermal_threshold_work, i));
  8139. diff -Nur linux-4.1.26.orig/drivers/tty/serial/8250/8250_core.c linux-4.1.26/drivers/tty/serial/8250/8250_core.c
  8140. --- linux-4.1.26.orig/drivers/tty/serial/8250/8250_core.c 2016-06-07 01:13:11.000000000 +0200
  8141. +++ linux-4.1.26/drivers/tty/serial/8250/8250_core.c 2016-06-19 15:30:58.651295961 +0200
  8142. @@ -36,6 +36,7 @@
  8143. #include <linux/nmi.h>
  8144. #include <linux/mutex.h>
  8145. #include <linux/slab.h>
  8146. +#include <linux/kdb.h>
  8147. #include <linux/uaccess.h>
  8148. #include <linux/pm_runtime.h>
  8149. #ifdef CONFIG_SPARC
  8150. @@ -80,7 +81,16 @@
  8151. #define DEBUG_INTR(fmt...) do { } while (0)
  8152. #endif
  8153. -#define PASS_LIMIT 512
  8154. +/*
  8155. + * On -rt we can have a more delays, and legitimately
  8156. + * so - so don't drop work spuriously and spam the
  8157. + * syslog:
  8158. + */
  8159. +#ifdef CONFIG_PREEMPT_RT_FULL
  8160. +# define PASS_LIMIT 1000000
  8161. +#else
  8162. +# define PASS_LIMIT 512
  8163. +#endif
  8164. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  8165. @@ -3372,7 +3382,7 @@
  8166. if (port->sysrq)
  8167. locked = 0;
  8168. - else if (oops_in_progress)
  8169. + else if (oops_in_progress || in_kdb_printk())
  8170. locked = spin_trylock_irqsave(&port->lock, flags);
  8171. else
  8172. spin_lock_irqsave(&port->lock, flags);
  8173. diff -Nur linux-4.1.26.orig/drivers/tty/serial/amba-pl011.c linux-4.1.26/drivers/tty/serial/amba-pl011.c
  8174. --- linux-4.1.26.orig/drivers/tty/serial/amba-pl011.c 2016-06-07 01:13:11.000000000 +0200
  8175. +++ linux-4.1.26/drivers/tty/serial/amba-pl011.c 2016-06-19 15:30:58.651295961 +0200
  8176. @@ -2000,13 +2000,19 @@
  8177. clk_enable(uap->clk);
  8178. - local_irq_save(flags);
  8179. + /*
  8180. + * local_irq_save(flags);
  8181. + *
  8182. + * This local_irq_save() is nonsense. If we come in via sysrq
  8183. + * handling then interrupts are already disabled. Aside of
  8184. + * that the port.sysrq check is racy on SMP regardless.
  8185. + */
  8186. if (uap->port.sysrq)
  8187. locked = 0;
  8188. else if (oops_in_progress)
  8189. - locked = spin_trylock(&uap->port.lock);
  8190. + locked = spin_trylock_irqsave(&uap->port.lock, flags);
  8191. else
  8192. - spin_lock(&uap->port.lock);
  8193. + spin_lock_irqsave(&uap->port.lock, flags);
  8194. /*
  8195. * First save the CR then disable the interrupts
  8196. @@ -2028,8 +2034,7 @@
  8197. writew(old_cr, uap->port.membase + UART011_CR);
  8198. if (locked)
  8199. - spin_unlock(&uap->port.lock);
  8200. - local_irq_restore(flags);
  8201. + spin_unlock_irqrestore(&uap->port.lock, flags);
  8202. clk_disable(uap->clk);
  8203. }
  8204. diff -Nur linux-4.1.26.orig/drivers/tty/serial/omap-serial.c linux-4.1.26/drivers/tty/serial/omap-serial.c
  8205. --- linux-4.1.26.orig/drivers/tty/serial/omap-serial.c 2016-06-07 01:13:11.000000000 +0200
  8206. +++ linux-4.1.26/drivers/tty/serial/omap-serial.c 2016-06-19 15:30:58.651295961 +0200
  8207. @@ -1282,13 +1282,10 @@
  8208. pm_runtime_get_sync(up->dev);
  8209. - local_irq_save(flags);
  8210. - if (up->port.sysrq)
  8211. - locked = 0;
  8212. - else if (oops_in_progress)
  8213. - locked = spin_trylock(&up->port.lock);
  8214. + if (up->port.sysrq || oops_in_progress)
  8215. + locked = spin_trylock_irqsave(&up->port.lock, flags);
  8216. else
  8217. - spin_lock(&up->port.lock);
  8218. + spin_lock_irqsave(&up->port.lock, flags);
  8219. /*
  8220. * First save the IER then disable the interrupts
  8221. @@ -1317,8 +1314,7 @@
  8222. pm_runtime_mark_last_busy(up->dev);
  8223. pm_runtime_put_autosuspend(up->dev);
  8224. if (locked)
  8225. - spin_unlock(&up->port.lock);
  8226. - local_irq_restore(flags);
  8227. + spin_unlock_irqrestore(&up->port.lock, flags);
  8228. }
  8229. static int __init
  8230. diff -Nur linux-4.1.26.orig/drivers/usb/core/hcd.c linux-4.1.26/drivers/usb/core/hcd.c
  8231. --- linux-4.1.26.orig/drivers/usb/core/hcd.c 2016-06-07 01:13:11.000000000 +0200
  8232. +++ linux-4.1.26/drivers/usb/core/hcd.c 2016-06-19 15:30:58.655296115 +0200
  8233. @@ -1684,9 +1684,9 @@
  8234. * and no one may trigger the above deadlock situation when
  8235. * running complete() in tasklet.
  8236. */
  8237. - local_irq_save(flags);
  8238. + local_irq_save_nort(flags);
  8239. urb->complete(urb);
  8240. - local_irq_restore(flags);
  8241. + local_irq_restore_nort(flags);
  8242. usb_anchor_resume_wakeups(anchor);
  8243. atomic_dec(&urb->use_count);
  8244. diff -Nur linux-4.1.26.orig/drivers/usb/gadget/function/f_fs.c linux-4.1.26/drivers/usb/gadget/function/f_fs.c
  8245. --- linux-4.1.26.orig/drivers/usb/gadget/function/f_fs.c 2016-06-07 01:13:11.000000000 +0200
  8246. +++ linux-4.1.26/drivers/usb/gadget/function/f_fs.c 2016-06-19 15:30:58.655296115 +0200
  8247. @@ -1404,7 +1404,7 @@
  8248. pr_info("%s(): freeing\n", __func__);
  8249. ffs_data_clear(ffs);
  8250. BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
  8251. - waitqueue_active(&ffs->ep0req_completion.wait));
  8252. + swaitqueue_active(&ffs->ep0req_completion.wait));
  8253. kfree(ffs->dev_name);
  8254. kfree(ffs);
  8255. }
  8256. diff -Nur linux-4.1.26.orig/drivers/usb/gadget/legacy/inode.c linux-4.1.26/drivers/usb/gadget/legacy/inode.c
  8257. --- linux-4.1.26.orig/drivers/usb/gadget/legacy/inode.c 2016-06-07 01:13:11.000000000 +0200
  8258. +++ linux-4.1.26/drivers/usb/gadget/legacy/inode.c 2016-06-19 15:30:58.655296115 +0200
  8259. @@ -345,7 +345,7 @@
  8260. spin_unlock_irq (&epdata->dev->lock);
  8261. if (likely (value == 0)) {
  8262. - value = wait_event_interruptible (done.wait, done.done);
  8263. + value = swait_event_interruptible (done.wait, done.done);
  8264. if (value != 0) {
  8265. spin_lock_irq (&epdata->dev->lock);
  8266. if (likely (epdata->ep != NULL)) {
  8267. @@ -354,7 +354,7 @@
  8268. usb_ep_dequeue (epdata->ep, epdata->req);
  8269. spin_unlock_irq (&epdata->dev->lock);
  8270. - wait_event (done.wait, done.done);
  8271. + swait_event (done.wait, done.done);
  8272. if (epdata->status == -ECONNRESET)
  8273. epdata->status = -EINTR;
  8274. } else {
  8275. diff -Nur linux-4.1.26.orig/fs/aio.c linux-4.1.26/fs/aio.c
  8276. --- linux-4.1.26.orig/fs/aio.c 2016-06-07 01:13:11.000000000 +0200
  8277. +++ linux-4.1.26/fs/aio.c 2016-06-19 15:30:58.655296115 +0200
  8278. @@ -40,6 +40,7 @@
  8279. #include <linux/ramfs.h>
  8280. #include <linux/percpu-refcount.h>
  8281. #include <linux/mount.h>
  8282. +#include <linux/work-simple.h>
  8283. #include <asm/kmap_types.h>
  8284. #include <asm/uaccess.h>
  8285. @@ -115,7 +116,7 @@
  8286. struct page **ring_pages;
  8287. long nr_pages;
  8288. - struct work_struct free_work;
  8289. + struct swork_event free_work;
  8290. /*
  8291. * signals when all in-flight requests are done
  8292. @@ -253,6 +254,7 @@
  8293. .mount = aio_mount,
  8294. .kill_sb = kill_anon_super,
  8295. };
  8296. + BUG_ON(swork_get());
  8297. aio_mnt = kern_mount(&aio_fs);
  8298. if (IS_ERR(aio_mnt))
  8299. panic("Failed to create aio fs mount.");
  8300. @@ -559,9 +561,9 @@
  8301. return cancel(&kiocb->common);
  8302. }
  8303. -static void free_ioctx(struct work_struct *work)
  8304. +static void free_ioctx(struct swork_event *sev)
  8305. {
  8306. - struct kioctx *ctx = container_of(work, struct kioctx, free_work);
  8307. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  8308. pr_debug("freeing %p\n", ctx);
  8309. @@ -580,8 +582,8 @@
  8310. if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
  8311. complete(&ctx->rq_wait->comp);
  8312. - INIT_WORK(&ctx->free_work, free_ioctx);
  8313. - schedule_work(&ctx->free_work);
  8314. + INIT_SWORK(&ctx->free_work, free_ioctx);
  8315. + swork_queue(&ctx->free_work);
  8316. }
  8317. /*
  8318. @@ -589,9 +591,9 @@
  8319. * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
  8320. * now it's safe to cancel any that need to be.
  8321. */
  8322. -static void free_ioctx_users(struct percpu_ref *ref)
  8323. +static void free_ioctx_users_work(struct swork_event *sev)
  8324. {
  8325. - struct kioctx *ctx = container_of(ref, struct kioctx, users);
  8326. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  8327. struct aio_kiocb *req;
  8328. spin_lock_irq(&ctx->ctx_lock);
  8329. @@ -610,6 +612,14 @@
  8330. percpu_ref_put(&ctx->reqs);
  8331. }
  8332. +static void free_ioctx_users(struct percpu_ref *ref)
  8333. +{
  8334. + struct kioctx *ctx = container_of(ref, struct kioctx, users);
  8335. +
  8336. + INIT_SWORK(&ctx->free_work, free_ioctx_users_work);
  8337. + swork_queue(&ctx->free_work);
  8338. +}
  8339. +
  8340. static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
  8341. {
  8342. unsigned i, new_nr;
  8343. diff -Nur linux-4.1.26.orig/fs/autofs4/autofs_i.h linux-4.1.26/fs/autofs4/autofs_i.h
  8344. --- linux-4.1.26.orig/fs/autofs4/autofs_i.h 2016-06-07 01:13:11.000000000 +0200
  8345. +++ linux-4.1.26/fs/autofs4/autofs_i.h 2016-06-19 15:30:58.655296115 +0200
  8346. @@ -34,6 +34,7 @@
  8347. #include <linux/sched.h>
  8348. #include <linux/mount.h>
  8349. #include <linux/namei.h>
  8350. +#include <linux/delay.h>
  8351. #include <asm/current.h>
  8352. #include <asm/uaccess.h>
  8353. diff -Nur linux-4.1.26.orig/fs/autofs4/expire.c linux-4.1.26/fs/autofs4/expire.c
  8354. --- linux-4.1.26.orig/fs/autofs4/expire.c 2016-06-07 01:13:11.000000000 +0200
  8355. +++ linux-4.1.26/fs/autofs4/expire.c 2016-06-19 15:30:58.655296115 +0200
  8356. @@ -150,7 +150,7 @@
  8357. parent = p->d_parent;
  8358. if (!spin_trylock(&parent->d_lock)) {
  8359. spin_unlock(&p->d_lock);
  8360. - cpu_relax();
  8361. + cpu_chill();
  8362. goto relock;
  8363. }
  8364. spin_unlock(&p->d_lock);
  8365. diff -Nur linux-4.1.26.orig/fs/buffer.c linux-4.1.26/fs/buffer.c
  8366. --- linux-4.1.26.orig/fs/buffer.c 2016-06-07 01:13:11.000000000 +0200
  8367. +++ linux-4.1.26/fs/buffer.c 2016-06-19 15:30:58.655296115 +0200
  8368. @@ -301,8 +301,7 @@
  8369. * decide that the page is now completely done.
  8370. */
  8371. first = page_buffers(page);
  8372. - local_irq_save(flags);
  8373. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  8374. + flags = bh_uptodate_lock_irqsave(first);
  8375. clear_buffer_async_read(bh);
  8376. unlock_buffer(bh);
  8377. tmp = bh;
  8378. @@ -315,8 +314,7 @@
  8379. }
  8380. tmp = tmp->b_this_page;
  8381. } while (tmp != bh);
  8382. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8383. - local_irq_restore(flags);
  8384. + bh_uptodate_unlock_irqrestore(first, flags);
  8385. /*
  8386. * If none of the buffers had errors and they are all
  8387. @@ -328,9 +326,7 @@
  8388. return;
  8389. still_busy:
  8390. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8391. - local_irq_restore(flags);
  8392. - return;
  8393. + bh_uptodate_unlock_irqrestore(first, flags);
  8394. }
  8395. /*
  8396. @@ -358,8 +354,7 @@
  8397. }
  8398. first = page_buffers(page);
  8399. - local_irq_save(flags);
  8400. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  8401. + flags = bh_uptodate_lock_irqsave(first);
  8402. clear_buffer_async_write(bh);
  8403. unlock_buffer(bh);
  8404. @@ -371,15 +366,12 @@
  8405. }
  8406. tmp = tmp->b_this_page;
  8407. }
  8408. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8409. - local_irq_restore(flags);
  8410. + bh_uptodate_unlock_irqrestore(first, flags);
  8411. end_page_writeback(page);
  8412. return;
  8413. still_busy:
  8414. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8415. - local_irq_restore(flags);
  8416. - return;
  8417. + bh_uptodate_unlock_irqrestore(first, flags);
  8418. }
  8419. EXPORT_SYMBOL(end_buffer_async_write);
  8420. @@ -3325,6 +3317,7 @@
  8421. struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
  8422. if (ret) {
  8423. INIT_LIST_HEAD(&ret->b_assoc_buffers);
  8424. + buffer_head_init_locks(ret);
  8425. preempt_disable();
  8426. __this_cpu_inc(bh_accounting.nr);
  8427. recalc_bh_state();
  8428. diff -Nur linux-4.1.26.orig/fs/dcache.c linux-4.1.26/fs/dcache.c
  8429. --- linux-4.1.26.orig/fs/dcache.c 2016-06-07 01:13:11.000000000 +0200
  8430. +++ linux-4.1.26/fs/dcache.c 2016-06-19 15:30:58.655296115 +0200
  8431. @@ -19,6 +19,7 @@
  8432. #include <linux/mm.h>
  8433. #include <linux/fs.h>
  8434. #include <linux/fsnotify.h>
  8435. +#include <linux/delay.h>
  8436. #include <linux/slab.h>
  8437. #include <linux/init.h>
  8438. #include <linux/hash.h>
  8439. @@ -578,7 +579,7 @@
  8440. failed:
  8441. spin_unlock(&dentry->d_lock);
  8442. - cpu_relax();
  8443. + cpu_chill();
  8444. return dentry; /* try again with same dentry */
  8445. }
  8446. @@ -2388,7 +2389,7 @@
  8447. if (dentry->d_lockref.count == 1) {
  8448. if (!spin_trylock(&inode->i_lock)) {
  8449. spin_unlock(&dentry->d_lock);
  8450. - cpu_relax();
  8451. + cpu_chill();
  8452. goto again;
  8453. }
  8454. dentry->d_flags &= ~DCACHE_CANT_MOUNT;
  8455. diff -Nur linux-4.1.26.orig/fs/eventpoll.c linux-4.1.26/fs/eventpoll.c
  8456. --- linux-4.1.26.orig/fs/eventpoll.c 2016-06-07 01:13:11.000000000 +0200
  8457. +++ linux-4.1.26/fs/eventpoll.c 2016-06-19 15:30:58.655296115 +0200
  8458. @@ -505,12 +505,12 @@
  8459. */
  8460. static void ep_poll_safewake(wait_queue_head_t *wq)
  8461. {
  8462. - int this_cpu = get_cpu();
  8463. + int this_cpu = get_cpu_light();
  8464. ep_call_nested(&poll_safewake_ncalls, EP_MAX_NESTS,
  8465. ep_poll_wakeup_proc, NULL, wq, (void *) (long) this_cpu);
  8466. - put_cpu();
  8467. + put_cpu_light();
  8468. }
  8469. static void ep_remove_wait_queue(struct eppoll_entry *pwq)
  8470. diff -Nur linux-4.1.26.orig/fs/exec.c linux-4.1.26/fs/exec.c
  8471. --- linux-4.1.26.orig/fs/exec.c 2016-06-07 01:13:11.000000000 +0200
  8472. +++ linux-4.1.26/fs/exec.c 2016-06-19 15:30:58.659296270 +0200
  8473. @@ -859,12 +859,14 @@
  8474. }
  8475. }
  8476. task_lock(tsk);
  8477. + preempt_disable_rt();
  8478. active_mm = tsk->active_mm;
  8479. tsk->mm = mm;
  8480. tsk->active_mm = mm;
  8481. activate_mm(active_mm, mm);
  8482. tsk->mm->vmacache_seqnum = 0;
  8483. vmacache_flush(tsk);
  8484. + preempt_enable_rt();
  8485. task_unlock(tsk);
  8486. if (old_mm) {
  8487. up_read(&old_mm->mmap_sem);
  8488. diff -Nur linux-4.1.26.orig/fs/f2fs/f2fs.h linux-4.1.26/fs/f2fs/f2fs.h
  8489. --- linux-4.1.26.orig/fs/f2fs/f2fs.h 2016-06-07 01:13:11.000000000 +0200
  8490. +++ linux-4.1.26/fs/f2fs/f2fs.h 2016-06-19 15:30:58.659296270 +0200
  8491. @@ -22,7 +22,6 @@
  8492. #ifdef CONFIG_F2FS_CHECK_FS
  8493. #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
  8494. -#define f2fs_down_write(x, y) down_write_nest_lock(x, y)
  8495. #else
  8496. #define f2fs_bug_on(sbi, condition) \
  8497. do { \
  8498. @@ -31,7 +30,6 @@
  8499. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  8500. } \
  8501. } while (0)
  8502. -#define f2fs_down_write(x, y) down_write(x)
  8503. #endif
  8504. /*
  8505. @@ -838,7 +836,7 @@
  8506. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  8507. {
  8508. - f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
  8509. + down_write(&sbi->cp_rwsem);
  8510. }
  8511. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  8512. diff -Nur linux-4.1.26.orig/fs/jbd/checkpoint.c linux-4.1.26/fs/jbd/checkpoint.c
  8513. --- linux-4.1.26.orig/fs/jbd/checkpoint.c 2016-06-07 01:13:11.000000000 +0200
  8514. +++ linux-4.1.26/fs/jbd/checkpoint.c 2016-06-19 15:30:58.659296270 +0200
  8515. @@ -129,6 +129,8 @@
  8516. if (journal->j_flags & JFS_ABORT)
  8517. return;
  8518. spin_unlock(&journal->j_state_lock);
  8519. + if (current->plug)
  8520. + io_schedule();
  8521. mutex_lock(&journal->j_checkpoint_mutex);
  8522. /*
  8523. diff -Nur linux-4.1.26.orig/fs/jbd2/checkpoint.c linux-4.1.26/fs/jbd2/checkpoint.c
  8524. --- linux-4.1.26.orig/fs/jbd2/checkpoint.c 2016-06-07 01:13:11.000000000 +0200
  8525. +++ linux-4.1.26/fs/jbd2/checkpoint.c 2016-06-19 15:30:58.659296270 +0200
  8526. @@ -116,6 +116,8 @@
  8527. nblocks = jbd2_space_needed(journal);
  8528. while (jbd2_log_space_left(journal) < nblocks) {
  8529. write_unlock(&journal->j_state_lock);
  8530. + if (current->plug)
  8531. + io_schedule();
  8532. mutex_lock(&journal->j_checkpoint_mutex);
  8533. /*
  8534. diff -Nur linux-4.1.26.orig/fs/namespace.c linux-4.1.26/fs/namespace.c
  8535. --- linux-4.1.26.orig/fs/namespace.c 2016-06-07 01:13:11.000000000 +0200
  8536. +++ linux-4.1.26/fs/namespace.c 2016-06-19 15:30:58.659296270 +0200
  8537. @@ -14,6 +14,7 @@
  8538. #include <linux/mnt_namespace.h>
  8539. #include <linux/user_namespace.h>
  8540. #include <linux/namei.h>
  8541. +#include <linux/delay.h>
  8542. #include <linux/security.h>
  8543. #include <linux/idr.h>
  8544. #include <linux/init.h> /* init_rootfs */
  8545. @@ -353,8 +354,11 @@
  8546. * incremented count after it has set MNT_WRITE_HOLD.
  8547. */
  8548. smp_mb();
  8549. - while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD)
  8550. - cpu_relax();
  8551. + while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) {
  8552. + preempt_enable();
  8553. + cpu_chill();
  8554. + preempt_disable();
  8555. + }
  8556. /*
  8557. * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will
  8558. * be set to match its requirements. So we must not load that until
  8559. diff -Nur linux-4.1.26.orig/fs/ntfs/aops.c linux-4.1.26/fs/ntfs/aops.c
  8560. --- linux-4.1.26.orig/fs/ntfs/aops.c 2016-06-07 01:13:11.000000000 +0200
  8561. +++ linux-4.1.26/fs/ntfs/aops.c 2016-06-19 15:30:58.659296270 +0200
  8562. @@ -107,8 +107,7 @@
  8563. "0x%llx.", (unsigned long long)bh->b_blocknr);
  8564. }
  8565. first = page_buffers(page);
  8566. - local_irq_save(flags);
  8567. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  8568. + flags = bh_uptodate_lock_irqsave(first);
  8569. clear_buffer_async_read(bh);
  8570. unlock_buffer(bh);
  8571. tmp = bh;
  8572. @@ -123,8 +122,7 @@
  8573. }
  8574. tmp = tmp->b_this_page;
  8575. } while (tmp != bh);
  8576. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8577. - local_irq_restore(flags);
  8578. + bh_uptodate_unlock_irqrestore(first, flags);
  8579. /*
  8580. * If none of the buffers had errors then we can set the page uptodate,
  8581. * but we first have to perform the post read mst fixups, if the
  8582. @@ -145,13 +143,13 @@
  8583. recs = PAGE_CACHE_SIZE / rec_size;
  8584. /* Should have been verified before we got here... */
  8585. BUG_ON(!recs);
  8586. - local_irq_save(flags);
  8587. + local_irq_save_nort(flags);
  8588. kaddr = kmap_atomic(page);
  8589. for (i = 0; i < recs; i++)
  8590. post_read_mst_fixup((NTFS_RECORD*)(kaddr +
  8591. i * rec_size), rec_size);
  8592. kunmap_atomic(kaddr);
  8593. - local_irq_restore(flags);
  8594. + local_irq_restore_nort(flags);
  8595. flush_dcache_page(page);
  8596. if (likely(page_uptodate && !PageError(page)))
  8597. SetPageUptodate(page);
  8598. @@ -159,9 +157,7 @@
  8599. unlock_page(page);
  8600. return;
  8601. still_busy:
  8602. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8603. - local_irq_restore(flags);
  8604. - return;
  8605. + bh_uptodate_unlock_irqrestore(first, flags);
  8606. }
  8607. /**
  8608. diff -Nur linux-4.1.26.orig/fs/timerfd.c linux-4.1.26/fs/timerfd.c
  8609. --- linux-4.1.26.orig/fs/timerfd.c 2016-06-07 01:13:11.000000000 +0200
  8610. +++ linux-4.1.26/fs/timerfd.c 2016-06-19 15:30:58.659296270 +0200
  8611. @@ -450,7 +450,10 @@
  8612. break;
  8613. }
  8614. spin_unlock_irq(&ctx->wqh.lock);
  8615. - cpu_relax();
  8616. + if (isalarm(ctx))
  8617. + hrtimer_wait_for_timer(&ctx->t.alarm.timer);
  8618. + else
  8619. + hrtimer_wait_for_timer(&ctx->t.tmr);
  8620. }
  8621. /*
  8622. diff -Nur linux-4.1.26.orig/fs/xfs/xfs_inode.c linux-4.1.26/fs/xfs/xfs_inode.c
  8623. --- linux-4.1.26.orig/fs/xfs/xfs_inode.c 2016-06-07 01:13:11.000000000 +0200
  8624. +++ linux-4.1.26/fs/xfs/xfs_inode.c 2016-06-19 15:30:58.659296270 +0200
  8625. @@ -164,7 +164,7 @@
  8626. (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
  8627. ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
  8628. (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
  8629. - ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
  8630. + ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
  8631. if (lock_flags & XFS_IOLOCK_EXCL)
  8632. mrupdate_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags));
  8633. @@ -212,7 +212,7 @@
  8634. (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
  8635. ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
  8636. (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
  8637. - ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
  8638. + ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
  8639. if (lock_flags & XFS_IOLOCK_EXCL) {
  8640. if (!mrtryupdate(&ip->i_iolock))
  8641. @@ -281,7 +281,7 @@
  8642. (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
  8643. ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
  8644. (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
  8645. - ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
  8646. + ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
  8647. ASSERT(lock_flags != 0);
  8648. if (lock_flags & XFS_IOLOCK_EXCL)
  8649. @@ -364,30 +364,38 @@
  8650. /*
  8651. * Bump the subclass so xfs_lock_inodes() acquires each lock with a different
  8652. - * value. This shouldn't be called for page fault locking, but we also need to
  8653. - * ensure we don't overrun the number of lockdep subclasses for the iolock or
  8654. - * mmaplock as that is limited to 12 by the mmap lock lockdep annotations.
  8655. + * value. This can be called for any type of inode lock combination, including
  8656. + * parent locking. Care must be taken to ensure we don't overrun the subclass
  8657. + * storage fields in the class mask we build.
  8658. */
  8659. static inline int
  8660. xfs_lock_inumorder(int lock_mode, int subclass)
  8661. {
  8662. + int class = 0;
  8663. +
  8664. + ASSERT(!(lock_mode & (XFS_ILOCK_PARENT | XFS_ILOCK_RTBITMAP |
  8665. + XFS_ILOCK_RTSUM)));
  8666. +
  8667. if (lock_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)) {
  8668. - ASSERT(subclass + XFS_LOCK_INUMORDER <
  8669. - (1 << (XFS_MMAPLOCK_SHIFT - XFS_IOLOCK_SHIFT)));
  8670. - lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_IOLOCK_SHIFT;
  8671. + ASSERT(subclass <= XFS_IOLOCK_MAX_SUBCLASS);
  8672. + ASSERT(subclass + XFS_IOLOCK_PARENT_VAL <
  8673. + MAX_LOCKDEP_SUBCLASSES);
  8674. + class += subclass << XFS_IOLOCK_SHIFT;
  8675. + if (lock_mode & XFS_IOLOCK_PARENT)
  8676. + class += XFS_IOLOCK_PARENT_VAL << XFS_IOLOCK_SHIFT;
  8677. }
  8678. if (lock_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) {
  8679. - ASSERT(subclass + XFS_LOCK_INUMORDER <
  8680. - (1 << (XFS_ILOCK_SHIFT - XFS_MMAPLOCK_SHIFT)));
  8681. - lock_mode |= (subclass + XFS_LOCK_INUMORDER) <<
  8682. - XFS_MMAPLOCK_SHIFT;
  8683. + ASSERT(subclass <= XFS_MMAPLOCK_MAX_SUBCLASS);
  8684. + class += subclass << XFS_MMAPLOCK_SHIFT;
  8685. }
  8686. - if (lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))
  8687. - lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_ILOCK_SHIFT;
  8688. + if (lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)) {
  8689. + ASSERT(subclass <= XFS_ILOCK_MAX_SUBCLASS);
  8690. + class += subclass << XFS_ILOCK_SHIFT;
  8691. + }
  8692. - return lock_mode;
  8693. + return (lock_mode & ~XFS_LOCK_SUBCLASS_MASK) | class;
  8694. }
  8695. /*
  8696. @@ -399,6 +407,11 @@
  8697. * transaction (such as truncate). This can result in deadlock since the long
  8698. * running trans might need to wait for the inode we just locked in order to
  8699. * push the tail and free space in the log.
  8700. + *
  8701. + * xfs_lock_inodes() can only be used to lock one type of lock at a time -
  8702. + * the iolock, the mmaplock or the ilock, but not more than one at a time. If we
  8703. + * lock more than one at a time, lockdep will report false positives saying we
  8704. + * have violated locking orders.
  8705. */
  8706. void
  8707. xfs_lock_inodes(
  8708. @@ -409,8 +422,29 @@
  8709. int attempts = 0, i, j, try_lock;
  8710. xfs_log_item_t *lp;
  8711. - /* currently supports between 2 and 5 inodes */
  8712. + /*
  8713. + * Currently supports between 2 and 5 inodes with exclusive locking. We
  8714. + * support an arbitrary depth of locking here, but absolute limits on
  8715. + * inodes depend on the the type of locking and the limits placed by
  8716. + * lockdep annotations in xfs_lock_inumorder. These are all checked by
  8717. + * the asserts.
  8718. + */
  8719. ASSERT(ips && inodes >= 2 && inodes <= 5);
  8720. + ASSERT(lock_mode & (XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL |
  8721. + XFS_ILOCK_EXCL));
  8722. + ASSERT(!(lock_mode & (XFS_IOLOCK_SHARED | XFS_MMAPLOCK_SHARED |
  8723. + XFS_ILOCK_SHARED)));
  8724. + ASSERT(!(lock_mode & XFS_IOLOCK_EXCL) ||
  8725. + inodes <= XFS_IOLOCK_MAX_SUBCLASS + 1);
  8726. + ASSERT(!(lock_mode & XFS_MMAPLOCK_EXCL) ||
  8727. + inodes <= XFS_MMAPLOCK_MAX_SUBCLASS + 1);
  8728. + ASSERT(!(lock_mode & XFS_ILOCK_EXCL) ||
  8729. + inodes <= XFS_ILOCK_MAX_SUBCLASS + 1);
  8730. +
  8731. + if (lock_mode & XFS_IOLOCK_EXCL) {
  8732. + ASSERT(!(lock_mode & (XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL)));
  8733. + } else if (lock_mode & XFS_MMAPLOCK_EXCL)
  8734. + ASSERT(!(lock_mode & XFS_ILOCK_EXCL));
  8735. try_lock = 0;
  8736. i = 0;
  8737. diff -Nur linux-4.1.26.orig/fs/xfs/xfs_inode.h linux-4.1.26/fs/xfs/xfs_inode.h
  8738. --- linux-4.1.26.orig/fs/xfs/xfs_inode.h 2016-06-07 01:13:11.000000000 +0200
  8739. +++ linux-4.1.26/fs/xfs/xfs_inode.h 2016-06-19 15:30:58.659296270 +0200
  8740. @@ -284,9 +284,9 @@
  8741. * Flags for lockdep annotations.
  8742. *
  8743. * XFS_LOCK_PARENT - for directory operations that require locking a
  8744. - * parent directory inode and a child entry inode. The parent gets locked
  8745. - * with this flag so it gets a lockdep subclass of 1 and the child entry
  8746. - * lock will have a lockdep subclass of 0.
  8747. + * parent directory inode and a child entry inode. IOLOCK requires nesting,
  8748. + * MMAPLOCK does not support this class, ILOCK requires a single subclass
  8749. + * to differentiate parent from child.
  8750. *
  8751. * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
  8752. * inodes do not participate in the normal lock order, and thus have their
  8753. @@ -295,30 +295,63 @@
  8754. * XFS_LOCK_INUMORDER - for locking several inodes at the some time
  8755. * with xfs_lock_inodes(). This flag is used as the starting subclass
  8756. * and each subsequent lock acquired will increment the subclass by one.
  8757. - * So the first lock acquired will have a lockdep subclass of 4, the
  8758. - * second lock will have a lockdep subclass of 5, and so on. It is
  8759. - * the responsibility of the class builder to shift this to the correct
  8760. - * portion of the lock_mode lockdep mask.
  8761. + * However, MAX_LOCKDEP_SUBCLASSES == 8, which means we are greatly
  8762. + * limited to the subclasses we can represent via nesting. We need at least
  8763. + * 5 inodes nest depth for the ILOCK through rename, and we also have to support
  8764. + * XFS_ILOCK_PARENT, which gives 6 subclasses. Then we have XFS_ILOCK_RTBITMAP
  8765. + * and XFS_ILOCK_RTSUM, which are another 2 unique subclasses, so that's all
  8766. + * 8 subclasses supported by lockdep.
  8767. + *
  8768. + * This also means we have to number the sub-classes in the lowest bits of
  8769. + * the mask we keep, and we have to ensure we never exceed 3 bits of lockdep
  8770. + * mask and we can't use bit-masking to build the subclasses. What a mess.
  8771. + *
  8772. + * Bit layout:
  8773. + *
  8774. + * Bit Lock Region
  8775. + * 16-19 XFS_IOLOCK_SHIFT dependencies
  8776. + * 20-23 XFS_MMAPLOCK_SHIFT dependencies
  8777. + * 24-31 XFS_ILOCK_SHIFT dependencies
  8778. + *
  8779. + * IOLOCK values
  8780. + *
  8781. + * 0-3 subclass value
  8782. + * 4-7 PARENT subclass values
  8783. + *
  8784. + * MMAPLOCK values
  8785. + *
  8786. + * 0-3 subclass value
  8787. + * 4-7 unused
  8788. + *
  8789. + * ILOCK values
  8790. + * 0-4 subclass values
  8791. + * 5 PARENT subclass (not nestable)
  8792. + * 6 RTBITMAP subclass (not nestable)
  8793. + * 7 RTSUM subclass (not nestable)
  8794. + *
  8795. */
  8796. -#define XFS_LOCK_PARENT 1
  8797. -#define XFS_LOCK_RTBITMAP 2
  8798. -#define XFS_LOCK_RTSUM 3
  8799. -#define XFS_LOCK_INUMORDER 4
  8800. -
  8801. -#define XFS_IOLOCK_SHIFT 16
  8802. -#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
  8803. +#define XFS_IOLOCK_SHIFT 16
  8804. +#define XFS_IOLOCK_PARENT_VAL 4
  8805. +#define XFS_IOLOCK_MAX_SUBCLASS (XFS_IOLOCK_PARENT_VAL - 1)
  8806. +#define XFS_IOLOCK_DEP_MASK 0x000f0000
  8807. +#define XFS_IOLOCK_PARENT (XFS_IOLOCK_PARENT_VAL << XFS_IOLOCK_SHIFT)
  8808. -#define XFS_MMAPLOCK_SHIFT 20
  8809. +#define XFS_MMAPLOCK_SHIFT 20
  8810. +#define XFS_MMAPLOCK_NUMORDER 0
  8811. +#define XFS_MMAPLOCK_MAX_SUBCLASS 3
  8812. +#define XFS_MMAPLOCK_DEP_MASK 0x00f00000
  8813. -#define XFS_ILOCK_SHIFT 24
  8814. -#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
  8815. -#define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
  8816. -#define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
  8817. +#define XFS_ILOCK_SHIFT 24
  8818. +#define XFS_ILOCK_PARENT_VAL 5
  8819. +#define XFS_ILOCK_MAX_SUBCLASS (XFS_ILOCK_PARENT_VAL - 1)
  8820. +#define XFS_ILOCK_RTBITMAP_VAL 6
  8821. +#define XFS_ILOCK_RTSUM_VAL 7
  8822. +#define XFS_ILOCK_DEP_MASK 0xff000000
  8823. +#define XFS_ILOCK_PARENT (XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT)
  8824. +#define XFS_ILOCK_RTBITMAP (XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT)
  8825. +#define XFS_ILOCK_RTSUM (XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)
  8826. -#define XFS_IOLOCK_DEP_MASK 0x000f0000
  8827. -#define XFS_MMAPLOCK_DEP_MASK 0x00f00000
  8828. -#define XFS_ILOCK_DEP_MASK 0xff000000
  8829. -#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | \
  8830. +#define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \
  8831. XFS_MMAPLOCK_DEP_MASK | \
  8832. XFS_ILOCK_DEP_MASK)
  8833. diff -Nur linux-4.1.26.orig/include/acpi/platform/aclinux.h linux-4.1.26/include/acpi/platform/aclinux.h
  8834. --- linux-4.1.26.orig/include/acpi/platform/aclinux.h 2016-06-07 01:13:11.000000000 +0200
  8835. +++ linux-4.1.26/include/acpi/platform/aclinux.h 2016-06-19 15:30:58.659296270 +0200
  8836. @@ -123,6 +123,7 @@
  8837. #define acpi_cache_t struct kmem_cache
  8838. #define acpi_spinlock spinlock_t *
  8839. +#define acpi_raw_spinlock raw_spinlock_t *
  8840. #define acpi_cpu_flags unsigned long
  8841. /* Use native linux version of acpi_os_allocate_zeroed */
  8842. @@ -141,6 +142,20 @@
  8843. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
  8844. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
  8845. +#define acpi_os_create_raw_lock(__handle) \
  8846. +({ \
  8847. + raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
  8848. + \
  8849. + if (lock) { \
  8850. + *(__handle) = lock; \
  8851. + raw_spin_lock_init(*(__handle)); \
  8852. + } \
  8853. + lock ? AE_OK : AE_NO_MEMORY; \
  8854. + })
  8855. +
  8856. +#define acpi_os_delete_raw_lock(__handle) kfree(__handle)
  8857. +
  8858. +
  8859. /*
  8860. * OSL interfaces used by debugger/disassembler
  8861. */
  8862. diff -Nur linux-4.1.26.orig/include/asm-generic/bug.h linux-4.1.26/include/asm-generic/bug.h
  8863. --- linux-4.1.26.orig/include/asm-generic/bug.h 2016-06-07 01:13:11.000000000 +0200
  8864. +++ linux-4.1.26/include/asm-generic/bug.h 2016-06-19 15:30:58.663296424 +0200
  8865. @@ -206,6 +206,20 @@
  8866. # define WARN_ON_SMP(x) ({0;})
  8867. #endif
  8868. +#ifdef CONFIG_PREEMPT_RT_BASE
  8869. +# define BUG_ON_RT(c) BUG_ON(c)
  8870. +# define BUG_ON_NONRT(c) do { } while (0)
  8871. +# define WARN_ON_RT(condition) WARN_ON(condition)
  8872. +# define WARN_ON_NONRT(condition) do { } while (0)
  8873. +# define WARN_ON_ONCE_NONRT(condition) do { } while (0)
  8874. +#else
  8875. +# define BUG_ON_RT(c) do { } while (0)
  8876. +# define BUG_ON_NONRT(c) BUG_ON(c)
  8877. +# define WARN_ON_RT(condition) do { } while (0)
  8878. +# define WARN_ON_NONRT(condition) WARN_ON(condition)
  8879. +# define WARN_ON_ONCE_NONRT(condition) WARN_ON_ONCE(condition)
  8880. +#endif
  8881. +
  8882. #endif /* __ASSEMBLY__ */
  8883. #endif
  8884. diff -Nur linux-4.1.26.orig/include/asm-generic/futex.h linux-4.1.26/include/asm-generic/futex.h
  8885. --- linux-4.1.26.orig/include/asm-generic/futex.h 2016-06-07 01:13:11.000000000 +0200
  8886. +++ linux-4.1.26/include/asm-generic/futex.h 2016-06-19 15:30:58.663296424 +0200
  8887. @@ -8,8 +8,7 @@
  8888. #ifndef CONFIG_SMP
  8889. /*
  8890. * The following implementation only for uniprocessor machines.
  8891. - * For UP, it's relies on the fact that pagefault_disable() also disables
  8892. - * preemption to ensure mutual exclusion.
  8893. + * It relies on preempt_disable() ensuring mutual exclusion.
  8894. *
  8895. */
  8896. @@ -38,6 +37,7 @@
  8897. if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
  8898. oparg = 1 << oparg;
  8899. + preempt_disable();
  8900. pagefault_disable();
  8901. ret = -EFAULT;
  8902. @@ -72,6 +72,7 @@
  8903. out_pagefault_enable:
  8904. pagefault_enable();
  8905. + preempt_enable();
  8906. if (ret == 0) {
  8907. switch (cmp) {
  8908. @@ -106,6 +107,7 @@
  8909. {
  8910. u32 val;
  8911. + preempt_disable();
  8912. if (unlikely(get_user(val, uaddr) != 0))
  8913. return -EFAULT;
  8914. @@ -113,6 +115,7 @@
  8915. return -EFAULT;
  8916. *uval = val;
  8917. + preempt_enable();
  8918. return 0;
  8919. }
  8920. diff -Nur linux-4.1.26.orig/include/linux/blkdev.h linux-4.1.26/include/linux/blkdev.h
  8921. --- linux-4.1.26.orig/include/linux/blkdev.h 2016-06-07 01:13:11.000000000 +0200
  8922. +++ linux-4.1.26/include/linux/blkdev.h 2016-06-19 15:30:58.663296424 +0200
  8923. @@ -101,6 +101,7 @@
  8924. struct list_head queuelist;
  8925. union {
  8926. struct call_single_data csd;
  8927. + struct work_struct work;
  8928. unsigned long fifo_time;
  8929. };
  8930. @@ -482,7 +483,7 @@
  8931. struct throtl_data *td;
  8932. #endif
  8933. struct rcu_head rcu_head;
  8934. - wait_queue_head_t mq_freeze_wq;
  8935. + struct swait_head mq_freeze_wq;
  8936. struct percpu_ref mq_usage_counter;
  8937. struct list_head all_q_node;
  8938. diff -Nur linux-4.1.26.orig/include/linux/blk-mq.h linux-4.1.26/include/linux/blk-mq.h
  8939. --- linux-4.1.26.orig/include/linux/blk-mq.h 2016-06-07 01:13:11.000000000 +0200
  8940. +++ linux-4.1.26/include/linux/blk-mq.h 2016-06-19 15:30:58.663296424 +0200
  8941. @@ -202,6 +202,7 @@
  8942. struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
  8943. struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
  8944. +void __blk_mq_complete_request_remote_work(struct work_struct *work);
  8945. int blk_mq_request_started(struct request *rq);
  8946. void blk_mq_start_request(struct request *rq);
  8947. diff -Nur linux-4.1.26.orig/include/linux/bottom_half.h linux-4.1.26/include/linux/bottom_half.h
  8948. --- linux-4.1.26.orig/include/linux/bottom_half.h 2016-06-07 01:13:11.000000000 +0200
  8949. +++ linux-4.1.26/include/linux/bottom_half.h 2016-06-19 15:30:58.663296424 +0200
  8950. @@ -4,6 +4,39 @@
  8951. #include <linux/preempt.h>
  8952. #include <linux/preempt_mask.h>
  8953. +#ifdef CONFIG_PREEMPT_RT_FULL
  8954. +
  8955. +extern void __local_bh_disable(void);
  8956. +extern void _local_bh_enable(void);
  8957. +extern void __local_bh_enable(void);
  8958. +
  8959. +static inline void local_bh_disable(void)
  8960. +{
  8961. + __local_bh_disable();
  8962. +}
  8963. +
  8964. +static inline void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
  8965. +{
  8966. + __local_bh_disable();
  8967. +}
  8968. +
  8969. +static inline void local_bh_enable(void)
  8970. +{
  8971. + __local_bh_enable();
  8972. +}
  8973. +
  8974. +static inline void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
  8975. +{
  8976. + __local_bh_enable();
  8977. +}
  8978. +
  8979. +static inline void local_bh_enable_ip(unsigned long ip)
  8980. +{
  8981. + __local_bh_enable();
  8982. +}
  8983. +
  8984. +#else
  8985. +
  8986. #ifdef CONFIG_TRACE_IRQFLAGS
  8987. extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
  8988. #else
  8989. @@ -31,5 +64,6 @@
  8990. {
  8991. __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
  8992. }
  8993. +#endif
  8994. #endif /* _LINUX_BH_H */
  8995. diff -Nur linux-4.1.26.orig/include/linux/buffer_head.h linux-4.1.26/include/linux/buffer_head.h
  8996. --- linux-4.1.26.orig/include/linux/buffer_head.h 2016-06-07 01:13:11.000000000 +0200
  8997. +++ linux-4.1.26/include/linux/buffer_head.h 2016-06-19 15:30:58.663296424 +0200
  8998. @@ -75,8 +75,52 @@
  8999. struct address_space *b_assoc_map; /* mapping this buffer is
  9000. associated with */
  9001. atomic_t b_count; /* users using this buffer_head */
  9002. +#ifdef CONFIG_PREEMPT_RT_BASE
  9003. + spinlock_t b_uptodate_lock;
  9004. +#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || \
  9005. + defined(CONFIG_JBD2) || defined(CONFIG_JBD2_MODULE)
  9006. + spinlock_t b_state_lock;
  9007. + spinlock_t b_journal_head_lock;
  9008. +#endif
  9009. +#endif
  9010. };
  9011. +static inline unsigned long bh_uptodate_lock_irqsave(struct buffer_head *bh)
  9012. +{
  9013. + unsigned long flags;
  9014. +
  9015. +#ifndef CONFIG_PREEMPT_RT_BASE
  9016. + local_irq_save(flags);
  9017. + bit_spin_lock(BH_Uptodate_Lock, &bh->b_state);
  9018. +#else
  9019. + spin_lock_irqsave(&bh->b_uptodate_lock, flags);
  9020. +#endif
  9021. + return flags;
  9022. +}
  9023. +
  9024. +static inline void
  9025. +bh_uptodate_unlock_irqrestore(struct buffer_head *bh, unsigned long flags)
  9026. +{
  9027. +#ifndef CONFIG_PREEMPT_RT_BASE
  9028. + bit_spin_unlock(BH_Uptodate_Lock, &bh->b_state);
  9029. + local_irq_restore(flags);
  9030. +#else
  9031. + spin_unlock_irqrestore(&bh->b_uptodate_lock, flags);
  9032. +#endif
  9033. +}
  9034. +
  9035. +static inline void buffer_head_init_locks(struct buffer_head *bh)
  9036. +{
  9037. +#ifdef CONFIG_PREEMPT_RT_BASE
  9038. + spin_lock_init(&bh->b_uptodate_lock);
  9039. +#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || \
  9040. + defined(CONFIG_JBD2) || defined(CONFIG_JBD2_MODULE)
  9041. + spin_lock_init(&bh->b_state_lock);
  9042. + spin_lock_init(&bh->b_journal_head_lock);
  9043. +#endif
  9044. +#endif
  9045. +}
  9046. +
  9047. /*
  9048. * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
  9049. * and buffer_foo() functions.
  9050. diff -Nur linux-4.1.26.orig/include/linux/cgroup-defs.h linux-4.1.26/include/linux/cgroup-defs.h
  9051. --- linux-4.1.26.orig/include/linux/cgroup-defs.h 2016-06-07 01:13:11.000000000 +0200
  9052. +++ linux-4.1.26/include/linux/cgroup-defs.h 2016-06-19 15:30:58.663296424 +0200
  9053. @@ -124,6 +124,7 @@
  9054. /* percpu_ref killing and RCU release */
  9055. struct rcu_head rcu_head;
  9056. struct work_struct destroy_work;
  9057. + struct swork_event destroy_swork;
  9058. };
  9059. /*
  9060. diff -Nur linux-4.1.26.orig/include/linux/cgroup.h linux-4.1.26/include/linux/cgroup.h
  9061. --- linux-4.1.26.orig/include/linux/cgroup.h 2016-06-07 01:13:11.000000000 +0200
  9062. +++ linux-4.1.26/include/linux/cgroup.h 2016-06-19 15:30:58.663296424 +0200
  9063. @@ -17,6 +17,8 @@
  9064. #include <linux/fs.h>
  9065. #include <linux/seq_file.h>
  9066. #include <linux/kernfs.h>
  9067. +#include <linux/wait.h>
  9068. +#include <linux/work-simple.h>
  9069. #include <linux/cgroup-defs.h>
  9070. diff -Nur linux-4.1.26.orig/include/linux/completion.h linux-4.1.26/include/linux/completion.h
  9071. --- linux-4.1.26.orig/include/linux/completion.h 2016-06-07 01:13:11.000000000 +0200
  9072. +++ linux-4.1.26/include/linux/completion.h 2016-06-19 15:30:58.663296424 +0200
  9073. @@ -7,8 +7,7 @@
  9074. * Atomic wait-for-completion handler data structures.
  9075. * See kernel/sched/completion.c for details.
  9076. */
  9077. -
  9078. -#include <linux/wait.h>
  9079. +#include <linux/wait-simple.h>
  9080. /*
  9081. * struct completion - structure used to maintain state for a "completion"
  9082. @@ -24,11 +23,11 @@
  9083. */
  9084. struct completion {
  9085. unsigned int done;
  9086. - wait_queue_head_t wait;
  9087. + struct swait_head wait;
  9088. };
  9089. #define COMPLETION_INITIALIZER(work) \
  9090. - { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  9091. + { 0, SWAIT_HEAD_INITIALIZER((work).wait) }
  9092. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  9093. ({ init_completion(&work); work; })
  9094. @@ -73,7 +72,7 @@
  9095. static inline void init_completion(struct completion *x)
  9096. {
  9097. x->done = 0;
  9098. - init_waitqueue_head(&x->wait);
  9099. + init_swait_head(&x->wait);
  9100. }
  9101. /**
  9102. diff -Nur linux-4.1.26.orig/include/linux/cpu.h linux-4.1.26/include/linux/cpu.h
  9103. --- linux-4.1.26.orig/include/linux/cpu.h 2016-06-07 01:13:11.000000000 +0200
  9104. +++ linux-4.1.26/include/linux/cpu.h 2016-06-19 15:30:58.663296424 +0200
  9105. @@ -231,6 +231,8 @@
  9106. extern void put_online_cpus(void);
  9107. extern void cpu_hotplug_disable(void);
  9108. extern void cpu_hotplug_enable(void);
  9109. +extern void pin_current_cpu(void);
  9110. +extern void unpin_current_cpu(void);
  9111. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  9112. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  9113. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  9114. @@ -249,6 +251,8 @@
  9115. #define put_online_cpus() do { } while (0)
  9116. #define cpu_hotplug_disable() do { } while (0)
  9117. #define cpu_hotplug_enable() do { } while (0)
  9118. +static inline void pin_current_cpu(void) { }
  9119. +static inline void unpin_current_cpu(void) { }
  9120. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  9121. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  9122. /* These aren't inline functions due to a GCC bug. */
  9123. diff -Nur linux-4.1.26.orig/include/linux/delay.h linux-4.1.26/include/linux/delay.h
  9124. --- linux-4.1.26.orig/include/linux/delay.h 2016-06-07 01:13:11.000000000 +0200
  9125. +++ linux-4.1.26/include/linux/delay.h 2016-06-19 15:30:58.663296424 +0200
  9126. @@ -52,4 +52,10 @@
  9127. msleep(seconds * 1000);
  9128. }
  9129. +#ifdef CONFIG_PREEMPT_RT_FULL
  9130. +extern void cpu_chill(void);
  9131. +#else
  9132. +# define cpu_chill() cpu_relax()
  9133. +#endif
  9134. +
  9135. #endif /* defined(_LINUX_DELAY_H) */
  9136. diff -Nur linux-4.1.26.orig/include/linux/ftrace_event.h linux-4.1.26/include/linux/ftrace_event.h
  9137. --- linux-4.1.26.orig/include/linux/ftrace_event.h 2016-06-07 01:13:11.000000000 +0200
  9138. +++ linux-4.1.26/include/linux/ftrace_event.h 2016-06-19 15:30:58.663296424 +0200
  9139. @@ -66,6 +66,9 @@
  9140. unsigned char flags;
  9141. unsigned char preempt_count;
  9142. int pid;
  9143. + unsigned short migrate_disable;
  9144. + unsigned short padding;
  9145. + unsigned char preempt_lazy_count;
  9146. };
  9147. #define FTRACE_MAX_EVENT \
  9148. diff -Nur linux-4.1.26.orig/include/linux/ftrace.h linux-4.1.26/include/linux/ftrace.h
  9149. --- linux-4.1.26.orig/include/linux/ftrace.h 2016-06-07 01:13:11.000000000 +0200
  9150. +++ linux-4.1.26/include/linux/ftrace.h 2016-06-19 15:30:58.663296424 +0200
  9151. @@ -682,6 +682,18 @@
  9152. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  9153. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  9154. +static inline unsigned long get_lock_parent_ip(void)
  9155. +{
  9156. + unsigned long addr = CALLER_ADDR0;
  9157. +
  9158. + if (!in_lock_functions(addr))
  9159. + return addr;
  9160. + addr = CALLER_ADDR1;
  9161. + if (!in_lock_functions(addr))
  9162. + return addr;
  9163. + return CALLER_ADDR2;
  9164. +}
  9165. +
  9166. #ifdef CONFIG_IRQSOFF_TRACER
  9167. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  9168. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  9169. diff -Nur linux-4.1.26.orig/include/linux/highmem.h linux-4.1.26/include/linux/highmem.h
  9170. --- linux-4.1.26.orig/include/linux/highmem.h 2016-06-07 01:13:11.000000000 +0200
  9171. +++ linux-4.1.26/include/linux/highmem.h 2016-06-19 15:30:58.663296424 +0200
  9172. @@ -7,6 +7,7 @@
  9173. #include <linux/mm.h>
  9174. #include <linux/uaccess.h>
  9175. #include <linux/hardirq.h>
  9176. +#include <linux/sched.h>
  9177. #include <asm/cacheflush.h>
  9178. @@ -65,6 +66,7 @@
  9179. static inline void *kmap_atomic(struct page *page)
  9180. {
  9181. + preempt_disable_nort();
  9182. pagefault_disable();
  9183. return page_address(page);
  9184. }
  9185. @@ -73,6 +75,7 @@
  9186. static inline void __kunmap_atomic(void *addr)
  9187. {
  9188. pagefault_enable();
  9189. + preempt_enable_nort();
  9190. }
  9191. #define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
  9192. @@ -85,32 +88,51 @@
  9193. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  9194. +#ifndef CONFIG_PREEMPT_RT_FULL
  9195. DECLARE_PER_CPU(int, __kmap_atomic_idx);
  9196. +#endif
  9197. static inline int kmap_atomic_idx_push(void)
  9198. {
  9199. +#ifndef CONFIG_PREEMPT_RT_FULL
  9200. int idx = __this_cpu_inc_return(__kmap_atomic_idx) - 1;
  9201. -#ifdef CONFIG_DEBUG_HIGHMEM
  9202. +# ifdef CONFIG_DEBUG_HIGHMEM
  9203. WARN_ON_ONCE(in_irq() && !irqs_disabled());
  9204. BUG_ON(idx >= KM_TYPE_NR);
  9205. -#endif
  9206. +# endif
  9207. return idx;
  9208. +#else
  9209. + current->kmap_idx++;
  9210. + BUG_ON(current->kmap_idx > KM_TYPE_NR);
  9211. + return current->kmap_idx - 1;
  9212. +#endif
  9213. }
  9214. static inline int kmap_atomic_idx(void)
  9215. {
  9216. +#ifndef CONFIG_PREEMPT_RT_FULL
  9217. return __this_cpu_read(__kmap_atomic_idx) - 1;
  9218. +#else
  9219. + return current->kmap_idx - 1;
  9220. +#endif
  9221. }
  9222. static inline void kmap_atomic_idx_pop(void)
  9223. {
  9224. -#ifdef CONFIG_DEBUG_HIGHMEM
  9225. +#ifndef CONFIG_PREEMPT_RT_FULL
  9226. +# ifdef CONFIG_DEBUG_HIGHMEM
  9227. int idx = __this_cpu_dec_return(__kmap_atomic_idx);
  9228. BUG_ON(idx < 0);
  9229. -#else
  9230. +# else
  9231. __this_cpu_dec(__kmap_atomic_idx);
  9232. +# endif
  9233. +#else
  9234. + current->kmap_idx--;
  9235. +# ifdef CONFIG_DEBUG_HIGHMEM
  9236. + BUG_ON(current->kmap_idx < 0);
  9237. +# endif
  9238. #endif
  9239. }
  9240. diff -Nur linux-4.1.26.orig/include/linux/hrtimer.h linux-4.1.26/include/linux/hrtimer.h
  9241. --- linux-4.1.26.orig/include/linux/hrtimer.h 2016-06-07 01:13:11.000000000 +0200
  9242. +++ linux-4.1.26/include/linux/hrtimer.h 2016-06-19 15:30:58.663296424 +0200
  9243. @@ -111,6 +111,11 @@
  9244. enum hrtimer_restart (*function)(struct hrtimer *);
  9245. struct hrtimer_clock_base *base;
  9246. unsigned long state;
  9247. + struct list_head cb_entry;
  9248. + int irqsafe;
  9249. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  9250. + ktime_t praecox;
  9251. +#endif
  9252. #ifdef CONFIG_TIMER_STATS
  9253. int start_pid;
  9254. void *start_site;
  9255. @@ -147,6 +152,7 @@
  9256. int index;
  9257. clockid_t clockid;
  9258. struct timerqueue_head active;
  9259. + struct list_head expired;
  9260. ktime_t resolution;
  9261. ktime_t (*get_time)(void);
  9262. ktime_t softirq_time;
  9263. @@ -194,6 +200,9 @@
  9264. unsigned long nr_hangs;
  9265. ktime_t max_hang_time;
  9266. #endif
  9267. +#ifdef CONFIG_PREEMPT_RT_BASE
  9268. + wait_queue_head_t wait;
  9269. +#endif
  9270. struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
  9271. };
  9272. @@ -381,6 +390,13 @@
  9273. return hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  9274. }
  9275. +/* Softirq preemption could deadlock timer removal */
  9276. +#ifdef CONFIG_PREEMPT_RT_BASE
  9277. + extern void hrtimer_wait_for_timer(const struct hrtimer *timer);
  9278. +#else
  9279. +# define hrtimer_wait_for_timer(timer) do { cpu_relax(); } while (0)
  9280. +#endif
  9281. +
  9282. /* Query timers: */
  9283. extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
  9284. extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
  9285. diff -Nur linux-4.1.26.orig/include/linux/idr.h linux-4.1.26/include/linux/idr.h
  9286. --- linux-4.1.26.orig/include/linux/idr.h 2016-06-07 01:13:11.000000000 +0200
  9287. +++ linux-4.1.26/include/linux/idr.h 2016-06-19 15:30:58.663296424 +0200
  9288. @@ -95,10 +95,14 @@
  9289. * Each idr_preload() should be matched with an invocation of this
  9290. * function. See idr_preload() for details.
  9291. */
  9292. +#ifdef CONFIG_PREEMPT_RT_FULL
  9293. +void idr_preload_end(void);
  9294. +#else
  9295. static inline void idr_preload_end(void)
  9296. {
  9297. preempt_enable();
  9298. }
  9299. +#endif
  9300. /**
  9301. * idr_find - return pointer for given id
  9302. diff -Nur linux-4.1.26.orig/include/linux/init_task.h linux-4.1.26/include/linux/init_task.h
  9303. --- linux-4.1.26.orig/include/linux/init_task.h 2016-06-07 01:13:11.000000000 +0200
  9304. +++ linux-4.1.26/include/linux/init_task.h 2016-06-19 15:30:58.667296578 +0200
  9305. @@ -147,9 +147,16 @@
  9306. # define INIT_PERF_EVENTS(tsk)
  9307. #endif
  9308. +#ifdef CONFIG_PREEMPT_RT_BASE
  9309. +# define INIT_TIMER_LIST .posix_timer_list = NULL,
  9310. +#else
  9311. +# define INIT_TIMER_LIST
  9312. +#endif
  9313. +
  9314. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  9315. # define INIT_VTIME(tsk) \
  9316. - .vtime_seqlock = __SEQLOCK_UNLOCKED(tsk.vtime_seqlock), \
  9317. + .vtime_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.vtime_lock), \
  9318. + .vtime_seq = SEQCNT_ZERO(tsk.vtime_seq), \
  9319. .vtime_snap = 0, \
  9320. .vtime_snap_whence = VTIME_SYS,
  9321. #else
  9322. @@ -238,6 +245,7 @@
  9323. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  9324. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  9325. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  9326. + INIT_TIMER_LIST \
  9327. .pids = { \
  9328. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  9329. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  9330. diff -Nur linux-4.1.26.orig/include/linux/interrupt.h linux-4.1.26/include/linux/interrupt.h
  9331. --- linux-4.1.26.orig/include/linux/interrupt.h 2016-06-07 01:13:11.000000000 +0200
  9332. +++ linux-4.1.26/include/linux/interrupt.h 2016-06-19 15:30:58.667296578 +0200
  9333. @@ -61,6 +61,7 @@
  9334. * interrupt handler after suspending interrupts. For system
  9335. * wakeup devices users need to implement wakeup detection in
  9336. * their interrupt handlers.
  9337. + * IRQF_NO_SOFTIRQ_CALL - Do not process softirqs in the irq thread context (RT)
  9338. */
  9339. #define IRQF_SHARED 0x00000080
  9340. #define IRQF_PROBE_SHARED 0x00000100
  9341. @@ -74,6 +75,7 @@
  9342. #define IRQF_NO_THREAD 0x00010000
  9343. #define IRQF_EARLY_RESUME 0x00020000
  9344. #define IRQF_COND_SUSPEND 0x00040000
  9345. +#define IRQF_NO_SOFTIRQ_CALL 0x00080000
  9346. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  9347. @@ -102,6 +104,7 @@
  9348. * @flags: flags (see IRQF_* above)
  9349. * @thread_fn: interrupt handler function for threaded interrupts
  9350. * @thread: thread pointer for threaded interrupts
  9351. + * @secondary: pointer to secondary irqaction (force threading)
  9352. * @thread_flags: flags related to @thread
  9353. * @thread_mask: bitmask for keeping track of @thread activity
  9354. * @dir: pointer to the proc/irq/NN/name entry
  9355. @@ -113,6 +116,7 @@
  9356. struct irqaction *next;
  9357. irq_handler_t thread_fn;
  9358. struct task_struct *thread;
  9359. + struct irqaction *secondary;
  9360. unsigned int irq;
  9361. unsigned int flags;
  9362. unsigned long thread_flags;
  9363. @@ -184,7 +188,7 @@
  9364. #ifdef CONFIG_LOCKDEP
  9365. # define local_irq_enable_in_hardirq() do { } while (0)
  9366. #else
  9367. -# define local_irq_enable_in_hardirq() local_irq_enable()
  9368. +# define local_irq_enable_in_hardirq() local_irq_enable_nort()
  9369. #endif
  9370. extern void disable_irq_nosync(unsigned int irq);
  9371. @@ -215,6 +219,7 @@
  9372. unsigned int irq;
  9373. struct kref kref;
  9374. struct work_struct work;
  9375. + struct list_head list;
  9376. void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  9377. void (*release)(struct kref *ref);
  9378. };
  9379. @@ -377,9 +382,13 @@
  9380. bool state);
  9381. #ifdef CONFIG_IRQ_FORCED_THREADING
  9382. +# ifndef CONFIG_PREEMPT_RT_BASE
  9383. extern bool force_irqthreads;
  9384. +# else
  9385. +# define force_irqthreads (true)
  9386. +# endif
  9387. #else
  9388. -#define force_irqthreads (0)
  9389. +#define force_irqthreads (false)
  9390. #endif
  9391. #ifndef __ARCH_SET_SOFTIRQ_PENDING
  9392. @@ -435,9 +444,10 @@
  9393. void (*action)(struct softirq_action *);
  9394. };
  9395. +#ifndef CONFIG_PREEMPT_RT_FULL
  9396. asmlinkage void do_softirq(void);
  9397. asmlinkage void __do_softirq(void);
  9398. -
  9399. +static inline void thread_do_softirq(void) { do_softirq(); }
  9400. #ifdef __ARCH_HAS_DO_SOFTIRQ
  9401. void do_softirq_own_stack(void);
  9402. #else
  9403. @@ -446,13 +456,25 @@
  9404. __do_softirq();
  9405. }
  9406. #endif
  9407. +#else
  9408. +extern void thread_do_softirq(void);
  9409. +#endif
  9410. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  9411. extern void softirq_init(void);
  9412. extern void __raise_softirq_irqoff(unsigned int nr);
  9413. +#ifdef CONFIG_PREEMPT_RT_FULL
  9414. +extern void __raise_softirq_irqoff_ksoft(unsigned int nr);
  9415. +#else
  9416. +static inline void __raise_softirq_irqoff_ksoft(unsigned int nr)
  9417. +{
  9418. + __raise_softirq_irqoff(nr);
  9419. +}
  9420. +#endif
  9421. extern void raise_softirq_irqoff(unsigned int nr);
  9422. extern void raise_softirq(unsigned int nr);
  9423. +extern void softirq_check_pending_idle(void);
  9424. DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  9425. @@ -474,8 +496,9 @@
  9426. to be executed on some cpu at least once after this.
  9427. * If the tasklet is already scheduled, but its execution is still not
  9428. started, it will be executed only once.
  9429. - * If this tasklet is already running on another CPU (or schedule is called
  9430. - from tasklet itself), it is rescheduled for later.
  9431. + * If this tasklet is already running on another CPU, it is rescheduled
  9432. + for later.
  9433. + * Schedule must not be called from the tasklet itself (a lockup occurs)
  9434. * Tasklet is strictly serialized wrt itself, but not
  9435. wrt another tasklets. If client needs some intertask synchronization,
  9436. he makes it with spinlocks.
  9437. @@ -500,27 +523,36 @@
  9438. enum
  9439. {
  9440. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  9441. - TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  9442. + TASKLET_STATE_RUN, /* Tasklet is running (SMP only) */
  9443. + TASKLET_STATE_PENDING /* Tasklet is pending */
  9444. };
  9445. -#ifdef CONFIG_SMP
  9446. +#define TASKLET_STATEF_SCHED (1 << TASKLET_STATE_SCHED)
  9447. +#define TASKLET_STATEF_RUN (1 << TASKLET_STATE_RUN)
  9448. +#define TASKLET_STATEF_PENDING (1 << TASKLET_STATE_PENDING)
  9449. +
  9450. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  9451. static inline int tasklet_trylock(struct tasklet_struct *t)
  9452. {
  9453. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  9454. }
  9455. +static inline int tasklet_tryunlock(struct tasklet_struct *t)
  9456. +{
  9457. + return cmpxchg(&t->state, TASKLET_STATEF_RUN, 0) == TASKLET_STATEF_RUN;
  9458. +}
  9459. +
  9460. static inline void tasklet_unlock(struct tasklet_struct *t)
  9461. {
  9462. smp_mb__before_atomic();
  9463. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  9464. }
  9465. -static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  9466. -{
  9467. - while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  9468. -}
  9469. +extern void tasklet_unlock_wait(struct tasklet_struct *t);
  9470. +
  9471. #else
  9472. #define tasklet_trylock(t) 1
  9473. +#define tasklet_tryunlock(t) 1
  9474. #define tasklet_unlock_wait(t) do { } while (0)
  9475. #define tasklet_unlock(t) do { } while (0)
  9476. #endif
  9477. @@ -569,12 +601,7 @@
  9478. smp_mb();
  9479. }
  9480. -static inline void tasklet_enable(struct tasklet_struct *t)
  9481. -{
  9482. - smp_mb__before_atomic();
  9483. - atomic_dec(&t->count);
  9484. -}
  9485. -
  9486. +extern void tasklet_enable(struct tasklet_struct *t);
  9487. extern void tasklet_kill(struct tasklet_struct *t);
  9488. extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  9489. extern void tasklet_init(struct tasklet_struct *t,
  9490. @@ -605,6 +632,12 @@
  9491. tasklet_kill(&ttimer->tasklet);
  9492. }
  9493. +#ifdef CONFIG_PREEMPT_RT_FULL
  9494. +extern void softirq_early_init(void);
  9495. +#else
  9496. +static inline void softirq_early_init(void) { }
  9497. +#endif
  9498. +
  9499. /*
  9500. * Autoprobing for irqs:
  9501. *
  9502. diff -Nur linux-4.1.26.orig/include/linux/io-mapping.h linux-4.1.26/include/linux/io-mapping.h
  9503. --- linux-4.1.26.orig/include/linux/io-mapping.h 2016-06-07 01:13:11.000000000 +0200
  9504. +++ linux-4.1.26/include/linux/io-mapping.h 2016-06-19 15:30:58.667296578 +0200
  9505. @@ -141,6 +141,7 @@
  9506. io_mapping_map_atomic_wc(struct io_mapping *mapping,
  9507. unsigned long offset)
  9508. {
  9509. + preempt_disable();
  9510. pagefault_disable();
  9511. return ((char __force __iomem *) mapping) + offset;
  9512. }
  9513. @@ -149,6 +150,7 @@
  9514. io_mapping_unmap_atomic(void __iomem *vaddr)
  9515. {
  9516. pagefault_enable();
  9517. + preempt_enable();
  9518. }
  9519. /* Non-atomic map/unmap */
  9520. diff -Nur linux-4.1.26.orig/include/linux/irqdesc.h linux-4.1.26/include/linux/irqdesc.h
  9521. --- linux-4.1.26.orig/include/linux/irqdesc.h 2016-06-07 01:13:11.000000000 +0200
  9522. +++ linux-4.1.26/include/linux/irqdesc.h 2016-06-19 15:30:58.667296578 +0200
  9523. @@ -63,6 +63,7 @@
  9524. unsigned int irqs_unhandled;
  9525. atomic_t threads_handled;
  9526. int threads_handled_last;
  9527. + u64 random_ip;
  9528. raw_spinlock_t lock;
  9529. struct cpumask *percpu_enabled;
  9530. #ifdef CONFIG_SMP
  9531. diff -Nur linux-4.1.26.orig/include/linux/irqflags.h linux-4.1.26/include/linux/irqflags.h
  9532. --- linux-4.1.26.orig/include/linux/irqflags.h 2016-06-07 01:13:11.000000000 +0200
  9533. +++ linux-4.1.26/include/linux/irqflags.h 2016-06-19 15:30:58.667296578 +0200
  9534. @@ -25,8 +25,6 @@
  9535. # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
  9536. # define trace_hardirq_enter() do { current->hardirq_context++; } while (0)
  9537. # define trace_hardirq_exit() do { current->hardirq_context--; } while (0)
  9538. -# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  9539. -# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  9540. # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
  9541. #else
  9542. # define trace_hardirqs_on() do { } while (0)
  9543. @@ -39,9 +37,15 @@
  9544. # define trace_softirqs_enabled(p) 0
  9545. # define trace_hardirq_enter() do { } while (0)
  9546. # define trace_hardirq_exit() do { } while (0)
  9547. +# define INIT_TRACE_IRQFLAGS
  9548. +#endif
  9549. +
  9550. +#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT_FULL)
  9551. +# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  9552. +# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  9553. +#else
  9554. # define lockdep_softirq_enter() do { } while (0)
  9555. # define lockdep_softirq_exit() do { } while (0)
  9556. -# define INIT_TRACE_IRQFLAGS
  9557. #endif
  9558. #if defined(CONFIG_IRQSOFF_TRACER) || \
  9559. @@ -148,4 +152,23 @@
  9560. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  9561. +/*
  9562. + * local_irq* variants depending on RT/!RT
  9563. + */
  9564. +#ifdef CONFIG_PREEMPT_RT_FULL
  9565. +# define local_irq_disable_nort() do { } while (0)
  9566. +# define local_irq_enable_nort() do { } while (0)
  9567. +# define local_irq_save_nort(flags) local_save_flags(flags)
  9568. +# define local_irq_restore_nort(flags) (void)(flags)
  9569. +# define local_irq_disable_rt() local_irq_disable()
  9570. +# define local_irq_enable_rt() local_irq_enable()
  9571. +#else
  9572. +# define local_irq_disable_nort() local_irq_disable()
  9573. +# define local_irq_enable_nort() local_irq_enable()
  9574. +# define local_irq_save_nort(flags) local_irq_save(flags)
  9575. +# define local_irq_restore_nort(flags) local_irq_restore(flags)
  9576. +# define local_irq_disable_rt() do { } while (0)
  9577. +# define local_irq_enable_rt() do { } while (0)
  9578. +#endif
  9579. +
  9580. #endif
  9581. diff -Nur linux-4.1.26.orig/include/linux/irq.h linux-4.1.26/include/linux/irq.h
  9582. --- linux-4.1.26.orig/include/linux/irq.h 2016-06-07 01:13:11.000000000 +0200
  9583. +++ linux-4.1.26/include/linux/irq.h 2016-06-19 15:30:58.667296578 +0200
  9584. @@ -72,6 +72,7 @@
  9585. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  9586. * it from the spurious interrupt detection
  9587. * mechanism and from core side polling.
  9588. + * IRQ_NO_SOFTIRQ_CALL - No softirq processing in the irq thread context (RT)
  9589. */
  9590. enum {
  9591. IRQ_TYPE_NONE = 0x00000000,
  9592. @@ -97,13 +98,14 @@
  9593. IRQ_NOTHREAD = (1 << 16),
  9594. IRQ_PER_CPU_DEVID = (1 << 17),
  9595. IRQ_IS_POLLED = (1 << 18),
  9596. + IRQ_NO_SOFTIRQ_CALL = (1 << 19),
  9597. };
  9598. #define IRQF_MODIFY_MASK \
  9599. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  9600. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  9601. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  9602. - IRQ_IS_POLLED)
  9603. + IRQ_IS_POLLED | IRQ_NO_SOFTIRQ_CALL)
  9604. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  9605. diff -Nur linux-4.1.26.orig/include/linux/irq_work.h linux-4.1.26/include/linux/irq_work.h
  9606. --- linux-4.1.26.orig/include/linux/irq_work.h 2016-06-07 01:13:11.000000000 +0200
  9607. +++ linux-4.1.26/include/linux/irq_work.h 2016-06-19 15:30:58.667296578 +0200
  9608. @@ -16,6 +16,7 @@
  9609. #define IRQ_WORK_BUSY 2UL
  9610. #define IRQ_WORK_FLAGS 3UL
  9611. #define IRQ_WORK_LAZY 4UL /* Doesn't want IPI, wait for tick */
  9612. +#define IRQ_WORK_HARD_IRQ 8UL /* Run hard IRQ context, even on RT */
  9613. struct irq_work {
  9614. unsigned long flags;
  9615. @@ -51,4 +52,10 @@
  9616. static inline void irq_work_run(void) { }
  9617. #endif
  9618. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  9619. +void irq_work_tick_soft(void);
  9620. +#else
  9621. +static inline void irq_work_tick_soft(void) { }
  9622. +#endif
  9623. +
  9624. #endif /* _LINUX_IRQ_WORK_H */
  9625. diff -Nur linux-4.1.26.orig/include/linux/jbd_common.h linux-4.1.26/include/linux/jbd_common.h
  9626. --- linux-4.1.26.orig/include/linux/jbd_common.h 2016-06-07 01:13:11.000000000 +0200
  9627. +++ linux-4.1.26/include/linux/jbd_common.h 2016-06-19 15:30:58.667296578 +0200
  9628. @@ -15,32 +15,56 @@
  9629. static inline void jbd_lock_bh_state(struct buffer_head *bh)
  9630. {
  9631. +#ifndef CONFIG_PREEMPT_RT_BASE
  9632. bit_spin_lock(BH_State, &bh->b_state);
  9633. +#else
  9634. + spin_lock(&bh->b_state_lock);
  9635. +#endif
  9636. }
  9637. static inline int jbd_trylock_bh_state(struct buffer_head *bh)
  9638. {
  9639. +#ifndef CONFIG_PREEMPT_RT_BASE
  9640. return bit_spin_trylock(BH_State, &bh->b_state);
  9641. +#else
  9642. + return spin_trylock(&bh->b_state_lock);
  9643. +#endif
  9644. }
  9645. static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
  9646. {
  9647. +#ifndef CONFIG_PREEMPT_RT_BASE
  9648. return bit_spin_is_locked(BH_State, &bh->b_state);
  9649. +#else
  9650. + return spin_is_locked(&bh->b_state_lock);
  9651. +#endif
  9652. }
  9653. static inline void jbd_unlock_bh_state(struct buffer_head *bh)
  9654. {
  9655. +#ifndef CONFIG_PREEMPT_RT_BASE
  9656. bit_spin_unlock(BH_State, &bh->b_state);
  9657. +#else
  9658. + spin_unlock(&bh->b_state_lock);
  9659. +#endif
  9660. }
  9661. static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
  9662. {
  9663. +#ifndef CONFIG_PREEMPT_RT_BASE
  9664. bit_spin_lock(BH_JournalHead, &bh->b_state);
  9665. +#else
  9666. + spin_lock(&bh->b_journal_head_lock);
  9667. +#endif
  9668. }
  9669. static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
  9670. {
  9671. +#ifndef CONFIG_PREEMPT_RT_BASE
  9672. bit_spin_unlock(BH_JournalHead, &bh->b_state);
  9673. +#else
  9674. + spin_unlock(&bh->b_journal_head_lock);
  9675. +#endif
  9676. }
  9677. #endif
  9678. diff -Nur linux-4.1.26.orig/include/linux/kdb.h linux-4.1.26/include/linux/kdb.h
  9679. --- linux-4.1.26.orig/include/linux/kdb.h 2016-06-07 01:13:11.000000000 +0200
  9680. +++ linux-4.1.26/include/linux/kdb.h 2016-06-19 15:30:58.667296578 +0200
  9681. @@ -167,6 +167,7 @@
  9682. extern __printf(1, 2) int kdb_printf(const char *, ...);
  9683. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  9684. +#define in_kdb_printk() (kdb_trap_printk)
  9685. extern void kdb_init(int level);
  9686. /* Access to kdb specific polling devices */
  9687. @@ -201,6 +202,7 @@
  9688. extern int kdb_unregister(char *);
  9689. #else /* ! CONFIG_KGDB_KDB */
  9690. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  9691. +#define in_kdb_printk() (0)
  9692. static inline void kdb_init(int level) {}
  9693. static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
  9694. char *help, short minlen) { return 0; }
  9695. diff -Nur linux-4.1.26.orig/include/linux/kernel.h linux-4.1.26/include/linux/kernel.h
  9696. --- linux-4.1.26.orig/include/linux/kernel.h 2016-06-07 01:13:11.000000000 +0200
  9697. +++ linux-4.1.26/include/linux/kernel.h 2016-06-19 15:30:58.667296578 +0200
  9698. @@ -188,6 +188,9 @@
  9699. */
  9700. # define might_sleep() \
  9701. do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  9702. +
  9703. +# define might_sleep_no_state_check() \
  9704. + do { ___might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  9705. # define sched_annotate_sleep() (current->task_state_change = 0)
  9706. #else
  9707. static inline void ___might_sleep(const char *file, int line,
  9708. @@ -195,6 +198,7 @@
  9709. static inline void __might_sleep(const char *file, int line,
  9710. int preempt_offset) { }
  9711. # define might_sleep() do { might_resched(); } while (0)
  9712. +# define might_sleep_no_state_check() do { might_resched(); } while (0)
  9713. # define sched_annotate_sleep() do { } while (0)
  9714. #endif
  9715. @@ -244,7 +248,8 @@
  9716. #if defined(CONFIG_MMU) && \
  9717. (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP))
  9718. -void might_fault(void);
  9719. +#define might_fault() __might_fault(__FILE__, __LINE__)
  9720. +void __might_fault(const char *file, int line);
  9721. #else
  9722. static inline void might_fault(void) { }
  9723. #endif
  9724. @@ -466,6 +471,7 @@
  9725. SYSTEM_HALT,
  9726. SYSTEM_POWER_OFF,
  9727. SYSTEM_RESTART,
  9728. + SYSTEM_SUSPEND,
  9729. } system_state;
  9730. #define TAINT_PROPRIETARY_MODULE 0
  9731. diff -Nur linux-4.1.26.orig/include/linux/kvm_host.h linux-4.1.26/include/linux/kvm_host.h
  9732. --- linux-4.1.26.orig/include/linux/kvm_host.h 2016-06-07 01:13:11.000000000 +0200
  9733. +++ linux-4.1.26/include/linux/kvm_host.h 2016-06-19 15:30:58.667296578 +0200
  9734. @@ -230,7 +230,7 @@
  9735. int fpu_active;
  9736. int guest_fpu_loaded, guest_xcr0_loaded;
  9737. - wait_queue_head_t wq;
  9738. + struct swait_head wq;
  9739. struct pid *pid;
  9740. int sigset_active;
  9741. sigset_t sigset;
  9742. @@ -701,7 +701,7 @@
  9743. }
  9744. #endif
  9745. -static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  9746. +static inline struct swait_head *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  9747. {
  9748. #ifdef __KVM_HAVE_ARCH_WQP
  9749. return vcpu->arch.wqp;
  9750. diff -Nur linux-4.1.26.orig/include/linux/lglock.h linux-4.1.26/include/linux/lglock.h
  9751. --- linux-4.1.26.orig/include/linux/lglock.h 2016-06-07 01:13:11.000000000 +0200
  9752. +++ linux-4.1.26/include/linux/lglock.h 2016-06-19 15:30:58.667296578 +0200
  9753. @@ -34,22 +34,39 @@
  9754. #endif
  9755. struct lglock {
  9756. +#ifndef CONFIG_PREEMPT_RT_FULL
  9757. arch_spinlock_t __percpu *lock;
  9758. +#else
  9759. + struct rt_mutex __percpu *lock;
  9760. +#endif
  9761. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  9762. struct lock_class_key lock_key;
  9763. struct lockdep_map lock_dep_map;
  9764. #endif
  9765. };
  9766. -#define DEFINE_LGLOCK(name) \
  9767. +#ifndef CONFIG_PREEMPT_RT_FULL
  9768. +# define DEFINE_LGLOCK(name) \
  9769. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  9770. = __ARCH_SPIN_LOCK_UNLOCKED; \
  9771. struct lglock name = { .lock = &name ## _lock }
  9772. -#define DEFINE_STATIC_LGLOCK(name) \
  9773. +# define DEFINE_STATIC_LGLOCK(name) \
  9774. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  9775. = __ARCH_SPIN_LOCK_UNLOCKED; \
  9776. static struct lglock name = { .lock = &name ## _lock }
  9777. +#else
  9778. +
  9779. +# define DEFINE_LGLOCK(name) \
  9780. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  9781. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  9782. + struct lglock name = { .lock = &name ## _lock }
  9783. +
  9784. +# define DEFINE_STATIC_LGLOCK(name) \
  9785. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  9786. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  9787. + static struct lglock name = { .lock = &name ## _lock }
  9788. +#endif
  9789. void lg_lock_init(struct lglock *lg, char *name);
  9790. void lg_local_lock(struct lglock *lg);
  9791. @@ -59,6 +76,12 @@
  9792. void lg_global_lock(struct lglock *lg);
  9793. void lg_global_unlock(struct lglock *lg);
  9794. +#ifndef CONFIG_PREEMPT_RT_FULL
  9795. +#define lg_global_trylock_relax(name) lg_global_lock(name)
  9796. +#else
  9797. +void lg_global_trylock_relax(struct lglock *lg);
  9798. +#endif
  9799. +
  9800. #else
  9801. /* When !CONFIG_SMP, map lglock to spinlock */
  9802. #define lglock spinlock
  9803. diff -Nur linux-4.1.26.orig/include/linux/list_bl.h linux-4.1.26/include/linux/list_bl.h
  9804. --- linux-4.1.26.orig/include/linux/list_bl.h 2016-06-07 01:13:11.000000000 +0200
  9805. +++ linux-4.1.26/include/linux/list_bl.h 2016-06-19 15:30:58.667296578 +0200
  9806. @@ -2,6 +2,7 @@
  9807. #define _LINUX_LIST_BL_H
  9808. #include <linux/list.h>
  9809. +#include <linux/spinlock.h>
  9810. #include <linux/bit_spinlock.h>
  9811. /*
  9812. @@ -32,13 +33,22 @@
  9813. struct hlist_bl_head {
  9814. struct hlist_bl_node *first;
  9815. +#ifdef CONFIG_PREEMPT_RT_BASE
  9816. + raw_spinlock_t lock;
  9817. +#endif
  9818. };
  9819. struct hlist_bl_node {
  9820. struct hlist_bl_node *next, **pprev;
  9821. };
  9822. -#define INIT_HLIST_BL_HEAD(ptr) \
  9823. - ((ptr)->first = NULL)
  9824. +
  9825. +static inline void INIT_HLIST_BL_HEAD(struct hlist_bl_head *h)
  9826. +{
  9827. + h->first = NULL;
  9828. +#ifdef CONFIG_PREEMPT_RT_BASE
  9829. + raw_spin_lock_init(&h->lock);
  9830. +#endif
  9831. +}
  9832. static inline void INIT_HLIST_BL_NODE(struct hlist_bl_node *h)
  9833. {
  9834. @@ -117,12 +127,26 @@
  9835. static inline void hlist_bl_lock(struct hlist_bl_head *b)
  9836. {
  9837. +#ifndef CONFIG_PREEMPT_RT_BASE
  9838. bit_spin_lock(0, (unsigned long *)b);
  9839. +#else
  9840. + raw_spin_lock(&b->lock);
  9841. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  9842. + __set_bit(0, (unsigned long *)b);
  9843. +#endif
  9844. +#endif
  9845. }
  9846. static inline void hlist_bl_unlock(struct hlist_bl_head *b)
  9847. {
  9848. +#ifndef CONFIG_PREEMPT_RT_BASE
  9849. __bit_spin_unlock(0, (unsigned long *)b);
  9850. +#else
  9851. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  9852. + __clear_bit(0, (unsigned long *)b);
  9853. +#endif
  9854. + raw_spin_unlock(&b->lock);
  9855. +#endif
  9856. }
  9857. static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
  9858. diff -Nur linux-4.1.26.orig/include/linux/locallock.h linux-4.1.26/include/linux/locallock.h
  9859. --- linux-4.1.26.orig/include/linux/locallock.h 1970-01-01 01:00:00.000000000 +0100
  9860. +++ linux-4.1.26/include/linux/locallock.h 2016-06-19 15:30:58.667296578 +0200
  9861. @@ -0,0 +1,270 @@
  9862. +#ifndef _LINUX_LOCALLOCK_H
  9863. +#define _LINUX_LOCALLOCK_H
  9864. +
  9865. +#include <linux/percpu.h>
  9866. +#include <linux/spinlock.h>
  9867. +
  9868. +#ifdef CONFIG_PREEMPT_RT_BASE
  9869. +
  9870. +#ifdef CONFIG_DEBUG_SPINLOCK
  9871. +# define LL_WARN(cond) WARN_ON(cond)
  9872. +#else
  9873. +# define LL_WARN(cond) do { } while (0)
  9874. +#endif
  9875. +
  9876. +/*
  9877. + * per cpu lock based substitute for local_irq_*()
  9878. + */
  9879. +struct local_irq_lock {
  9880. + spinlock_t lock;
  9881. + struct task_struct *owner;
  9882. + int nestcnt;
  9883. + unsigned long flags;
  9884. +};
  9885. +
  9886. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) \
  9887. + DEFINE_PER_CPU(struct local_irq_lock, lvar) = { \
  9888. + .lock = __SPIN_LOCK_UNLOCKED((lvar).lock) }
  9889. +
  9890. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) \
  9891. + DECLARE_PER_CPU(struct local_irq_lock, lvar)
  9892. +
  9893. +#define local_irq_lock_init(lvar) \
  9894. + do { \
  9895. + int __cpu; \
  9896. + for_each_possible_cpu(__cpu) \
  9897. + spin_lock_init(&per_cpu(lvar, __cpu).lock); \
  9898. + } while (0)
  9899. +
  9900. +/*
  9901. + * spin_lock|trylock|unlock_local flavour that does not migrate disable
  9902. + * used for __local_lock|trylock|unlock where get_local_var/put_local_var
  9903. + * already takes care of the migrate_disable/enable
  9904. + * for CONFIG_PREEMPT_BASE map to the normal spin_* calls.
  9905. + */
  9906. +#ifdef CONFIG_PREEMPT_RT_FULL
  9907. +# define spin_lock_local(lock) rt_spin_lock(lock)
  9908. +# define spin_trylock_local(lock) rt_spin_trylock(lock)
  9909. +# define spin_unlock_local(lock) rt_spin_unlock(lock)
  9910. +#else
  9911. +# define spin_lock_local(lock) spin_lock(lock)
  9912. +# define spin_trylock_local(lock) spin_trylock(lock)
  9913. +# define spin_unlock_local(lock) spin_unlock(lock)
  9914. +#endif
  9915. +
  9916. +static inline void __local_lock(struct local_irq_lock *lv)
  9917. +{
  9918. + if (lv->owner != current) {
  9919. + spin_lock_local(&lv->lock);
  9920. + LL_WARN(lv->owner);
  9921. + LL_WARN(lv->nestcnt);
  9922. + lv->owner = current;
  9923. + }
  9924. + lv->nestcnt++;
  9925. +}
  9926. +
  9927. +#define local_lock(lvar) \
  9928. + do { __local_lock(&get_local_var(lvar)); } while (0)
  9929. +
  9930. +static inline int __local_trylock(struct local_irq_lock *lv)
  9931. +{
  9932. + if (lv->owner != current && spin_trylock_local(&lv->lock)) {
  9933. + LL_WARN(lv->owner);
  9934. + LL_WARN(lv->nestcnt);
  9935. + lv->owner = current;
  9936. + lv->nestcnt = 1;
  9937. + return 1;
  9938. + }
  9939. + return 0;
  9940. +}
  9941. +
  9942. +#define local_trylock(lvar) \
  9943. + ({ \
  9944. + int __locked; \
  9945. + __locked = __local_trylock(&get_local_var(lvar)); \
  9946. + if (!__locked) \
  9947. + put_local_var(lvar); \
  9948. + __locked; \
  9949. + })
  9950. +
  9951. +static inline void __local_unlock(struct local_irq_lock *lv)
  9952. +{
  9953. + LL_WARN(lv->nestcnt == 0);
  9954. + LL_WARN(lv->owner != current);
  9955. + if (--lv->nestcnt)
  9956. + return;
  9957. +
  9958. + lv->owner = NULL;
  9959. + spin_unlock_local(&lv->lock);
  9960. +}
  9961. +
  9962. +#define local_unlock(lvar) \
  9963. + do { \
  9964. + __local_unlock(this_cpu_ptr(&lvar)); \
  9965. + put_local_var(lvar); \
  9966. + } while (0)
  9967. +
  9968. +static inline void __local_lock_irq(struct local_irq_lock *lv)
  9969. +{
  9970. + spin_lock_irqsave(&lv->lock, lv->flags);
  9971. + LL_WARN(lv->owner);
  9972. + LL_WARN(lv->nestcnt);
  9973. + lv->owner = current;
  9974. + lv->nestcnt = 1;
  9975. +}
  9976. +
  9977. +#define local_lock_irq(lvar) \
  9978. + do { __local_lock_irq(&get_local_var(lvar)); } while (0)
  9979. +
  9980. +#define local_lock_irq_on(lvar, cpu) \
  9981. + do { __local_lock_irq(&per_cpu(lvar, cpu)); } while (0)
  9982. +
  9983. +static inline void __local_unlock_irq(struct local_irq_lock *lv)
  9984. +{
  9985. + LL_WARN(!lv->nestcnt);
  9986. + LL_WARN(lv->owner != current);
  9987. + lv->owner = NULL;
  9988. + lv->nestcnt = 0;
  9989. + spin_unlock_irq(&lv->lock);
  9990. +}
  9991. +
  9992. +#define local_unlock_irq(lvar) \
  9993. + do { \
  9994. + __local_unlock_irq(this_cpu_ptr(&lvar)); \
  9995. + put_local_var(lvar); \
  9996. + } while (0)
  9997. +
  9998. +#define local_unlock_irq_on(lvar, cpu) \
  9999. + do { \
  10000. + __local_unlock_irq(&per_cpu(lvar, cpu)); \
  10001. + } while (0)
  10002. +
  10003. +static inline int __local_lock_irqsave(struct local_irq_lock *lv)
  10004. +{
  10005. + if (lv->owner != current) {
  10006. + __local_lock_irq(lv);
  10007. + return 0;
  10008. + } else {
  10009. + lv->nestcnt++;
  10010. + return 1;
  10011. + }
  10012. +}
  10013. +
  10014. +#define local_lock_irqsave(lvar, _flags) \
  10015. + do { \
  10016. + if (__local_lock_irqsave(&get_local_var(lvar))) \
  10017. + put_local_var(lvar); \
  10018. + _flags = __this_cpu_read(lvar.flags); \
  10019. + } while (0)
  10020. +
  10021. +#define local_lock_irqsave_on(lvar, _flags, cpu) \
  10022. + do { \
  10023. + __local_lock_irqsave(&per_cpu(lvar, cpu)); \
  10024. + _flags = per_cpu(lvar, cpu).flags; \
  10025. + } while (0)
  10026. +
  10027. +static inline int __local_unlock_irqrestore(struct local_irq_lock *lv,
  10028. + unsigned long flags)
  10029. +{
  10030. + LL_WARN(!lv->nestcnt);
  10031. + LL_WARN(lv->owner != current);
  10032. + if (--lv->nestcnt)
  10033. + return 0;
  10034. +
  10035. + lv->owner = NULL;
  10036. + spin_unlock_irqrestore(&lv->lock, lv->flags);
  10037. + return 1;
  10038. +}
  10039. +
  10040. +#define local_unlock_irqrestore(lvar, flags) \
  10041. + do { \
  10042. + if (__local_unlock_irqrestore(this_cpu_ptr(&lvar), flags)) \
  10043. + put_local_var(lvar); \
  10044. + } while (0)
  10045. +
  10046. +#define local_unlock_irqrestore_on(lvar, flags, cpu) \
  10047. + do { \
  10048. + __local_unlock_irqrestore(&per_cpu(lvar, cpu), flags); \
  10049. + } while (0)
  10050. +
  10051. +#define local_spin_trylock_irq(lvar, lock) \
  10052. + ({ \
  10053. + int __locked; \
  10054. + local_lock_irq(lvar); \
  10055. + __locked = spin_trylock(lock); \
  10056. + if (!__locked) \
  10057. + local_unlock_irq(lvar); \
  10058. + __locked; \
  10059. + })
  10060. +
  10061. +#define local_spin_lock_irq(lvar, lock) \
  10062. + do { \
  10063. + local_lock_irq(lvar); \
  10064. + spin_lock(lock); \
  10065. + } while (0)
  10066. +
  10067. +#define local_spin_unlock_irq(lvar, lock) \
  10068. + do { \
  10069. + spin_unlock(lock); \
  10070. + local_unlock_irq(lvar); \
  10071. + } while (0)
  10072. +
  10073. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  10074. + do { \
  10075. + local_lock_irqsave(lvar, flags); \
  10076. + spin_lock(lock); \
  10077. + } while (0)
  10078. +
  10079. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  10080. + do { \
  10081. + spin_unlock(lock); \
  10082. + local_unlock_irqrestore(lvar, flags); \
  10083. + } while (0)
  10084. +
  10085. +#define get_locked_var(lvar, var) \
  10086. + (*({ \
  10087. + local_lock(lvar); \
  10088. + this_cpu_ptr(&var); \
  10089. + }))
  10090. +
  10091. +#define put_locked_var(lvar, var) local_unlock(lvar);
  10092. +
  10093. +#define local_lock_cpu(lvar) \
  10094. + ({ \
  10095. + local_lock(lvar); \
  10096. + smp_processor_id(); \
  10097. + })
  10098. +
  10099. +#define local_unlock_cpu(lvar) local_unlock(lvar)
  10100. +
  10101. +#else /* PREEMPT_RT_BASE */
  10102. +
  10103. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) __typeof__(const int) lvar
  10104. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) extern __typeof__(const int) lvar
  10105. +
  10106. +static inline void local_irq_lock_init(int lvar) { }
  10107. +
  10108. +#define local_lock(lvar) preempt_disable()
  10109. +#define local_unlock(lvar) preempt_enable()
  10110. +#define local_lock_irq(lvar) local_irq_disable()
  10111. +#define local_unlock_irq(lvar) local_irq_enable()
  10112. +#define local_lock_irqsave(lvar, flags) local_irq_save(flags)
  10113. +#define local_unlock_irqrestore(lvar, flags) local_irq_restore(flags)
  10114. +
  10115. +#define local_spin_trylock_irq(lvar, lock) spin_trylock_irq(lock)
  10116. +#define local_spin_lock_irq(lvar, lock) spin_lock_irq(lock)
  10117. +#define local_spin_unlock_irq(lvar, lock) spin_unlock_irq(lock)
  10118. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  10119. + spin_lock_irqsave(lock, flags)
  10120. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  10121. + spin_unlock_irqrestore(lock, flags)
  10122. +
  10123. +#define get_locked_var(lvar, var) get_cpu_var(var)
  10124. +#define put_locked_var(lvar, var) put_cpu_var(var)
  10125. +
  10126. +#define local_lock_cpu(lvar) get_cpu()
  10127. +#define local_unlock_cpu(lvar) put_cpu()
  10128. +
  10129. +#endif
  10130. +
  10131. +#endif
  10132. diff -Nur linux-4.1.26.orig/include/linux/mm_types.h linux-4.1.26/include/linux/mm_types.h
  10133. --- linux-4.1.26.orig/include/linux/mm_types.h 2016-06-07 01:13:11.000000000 +0200
  10134. +++ linux-4.1.26/include/linux/mm_types.h 2016-06-19 15:30:58.667296578 +0200
  10135. @@ -11,6 +11,7 @@
  10136. #include <linux/completion.h>
  10137. #include <linux/cpumask.h>
  10138. #include <linux/uprobes.h>
  10139. +#include <linux/rcupdate.h>
  10140. #include <linux/page-flags-layout.h>
  10141. #include <asm/page.h>
  10142. #include <asm/mmu.h>
  10143. @@ -453,6 +454,9 @@
  10144. bool tlb_flush_pending;
  10145. #endif
  10146. struct uprobes_state uprobes_state;
  10147. +#ifdef CONFIG_PREEMPT_RT_BASE
  10148. + struct rcu_head delayed_drop;
  10149. +#endif
  10150. #ifdef CONFIG_X86_INTEL_MPX
  10151. /* address of the bounds directory */
  10152. void __user *bd_addr;
  10153. diff -Nur linux-4.1.26.orig/include/linux/mutex.h linux-4.1.26/include/linux/mutex.h
  10154. --- linux-4.1.26.orig/include/linux/mutex.h 2016-06-07 01:13:11.000000000 +0200
  10155. +++ linux-4.1.26/include/linux/mutex.h 2016-06-19 15:30:58.671296732 +0200
  10156. @@ -19,6 +19,17 @@
  10157. #include <asm/processor.h>
  10158. #include <linux/osq_lock.h>
  10159. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10160. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  10161. + , .dep_map = { .name = #lockname }
  10162. +#else
  10163. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  10164. +#endif
  10165. +
  10166. +#ifdef CONFIG_PREEMPT_RT_FULL
  10167. +# include <linux/mutex_rt.h>
  10168. +#else
  10169. +
  10170. /*
  10171. * Simple, straightforward mutexes with strict semantics:
  10172. *
  10173. @@ -99,13 +110,6 @@
  10174. static inline void mutex_destroy(struct mutex *lock) {}
  10175. #endif
  10176. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10177. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  10178. - , .dep_map = { .name = #lockname }
  10179. -#else
  10180. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  10181. -#endif
  10182. -
  10183. #define __MUTEX_INITIALIZER(lockname) \
  10184. { .count = ATOMIC_INIT(1) \
  10185. , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
  10186. @@ -173,6 +177,8 @@
  10187. extern int mutex_trylock(struct mutex *lock);
  10188. extern void mutex_unlock(struct mutex *lock);
  10189. +#endif /* !PREEMPT_RT_FULL */
  10190. +
  10191. extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
  10192. #endif /* __LINUX_MUTEX_H */
  10193. diff -Nur linux-4.1.26.orig/include/linux/mutex_rt.h linux-4.1.26/include/linux/mutex_rt.h
  10194. --- linux-4.1.26.orig/include/linux/mutex_rt.h 1970-01-01 01:00:00.000000000 +0100
  10195. +++ linux-4.1.26/include/linux/mutex_rt.h 2016-06-19 15:30:58.671296732 +0200
  10196. @@ -0,0 +1,84 @@
  10197. +#ifndef __LINUX_MUTEX_RT_H
  10198. +#define __LINUX_MUTEX_RT_H
  10199. +
  10200. +#ifndef __LINUX_MUTEX_H
  10201. +#error "Please include mutex.h"
  10202. +#endif
  10203. +
  10204. +#include <linux/rtmutex.h>
  10205. +
  10206. +/* FIXME: Just for __lockfunc */
  10207. +#include <linux/spinlock.h>
  10208. +
  10209. +struct mutex {
  10210. + struct rt_mutex lock;
  10211. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10212. + struct lockdep_map dep_map;
  10213. +#endif
  10214. +};
  10215. +
  10216. +#define __MUTEX_INITIALIZER(mutexname) \
  10217. + { \
  10218. + .lock = __RT_MUTEX_INITIALIZER(mutexname.lock) \
  10219. + __DEP_MAP_MUTEX_INITIALIZER(mutexname) \
  10220. + }
  10221. +
  10222. +#define DEFINE_MUTEX(mutexname) \
  10223. + struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
  10224. +
  10225. +extern void __mutex_do_init(struct mutex *lock, const char *name, struct lock_class_key *key);
  10226. +extern void __lockfunc _mutex_lock(struct mutex *lock);
  10227. +extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
  10228. +extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
  10229. +extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
  10230. +extern void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
  10231. +extern int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
  10232. +extern int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass);
  10233. +extern int __lockfunc _mutex_trylock(struct mutex *lock);
  10234. +extern void __lockfunc _mutex_unlock(struct mutex *lock);
  10235. +
  10236. +#define mutex_is_locked(l) rt_mutex_is_locked(&(l)->lock)
  10237. +#define mutex_lock(l) _mutex_lock(l)
  10238. +#define mutex_lock_interruptible(l) _mutex_lock_interruptible(l)
  10239. +#define mutex_lock_killable(l) _mutex_lock_killable(l)
  10240. +#define mutex_trylock(l) _mutex_trylock(l)
  10241. +#define mutex_unlock(l) _mutex_unlock(l)
  10242. +#define mutex_destroy(l) rt_mutex_destroy(&(l)->lock)
  10243. +
  10244. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10245. +# define mutex_lock_nested(l, s) _mutex_lock_nested(l, s)
  10246. +# define mutex_lock_interruptible_nested(l, s) \
  10247. + _mutex_lock_interruptible_nested(l, s)
  10248. +# define mutex_lock_killable_nested(l, s) \
  10249. + _mutex_lock_killable_nested(l, s)
  10250. +
  10251. +# define mutex_lock_nest_lock(lock, nest_lock) \
  10252. +do { \
  10253. + typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
  10254. + _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
  10255. +} while (0)
  10256. +
  10257. +#else
  10258. +# define mutex_lock_nested(l, s) _mutex_lock(l)
  10259. +# define mutex_lock_interruptible_nested(l, s) \
  10260. + _mutex_lock_interruptible(l)
  10261. +# define mutex_lock_killable_nested(l, s) \
  10262. + _mutex_lock_killable(l)
  10263. +# define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
  10264. +#endif
  10265. +
  10266. +# define mutex_init(mutex) \
  10267. +do { \
  10268. + static struct lock_class_key __key; \
  10269. + \
  10270. + rt_mutex_init(&(mutex)->lock); \
  10271. + __mutex_do_init((mutex), #mutex, &__key); \
  10272. +} while (0)
  10273. +
  10274. +# define __mutex_init(mutex, name, key) \
  10275. +do { \
  10276. + rt_mutex_init(&(mutex)->lock); \
  10277. + __mutex_do_init((mutex), name, key); \
  10278. +} while (0)
  10279. +
  10280. +#endif
  10281. diff -Nur linux-4.1.26.orig/include/linux/netdevice.h linux-4.1.26/include/linux/netdevice.h
  10282. --- linux-4.1.26.orig/include/linux/netdevice.h 2016-06-07 01:13:11.000000000 +0200
  10283. +++ linux-4.1.26/include/linux/netdevice.h 2016-06-19 15:30:58.671296732 +0200
  10284. @@ -2192,11 +2192,20 @@
  10285. void synchronize_net(void);
  10286. int init_dummy_netdev(struct net_device *dev);
  10287. +#ifdef CONFIG_PREEMPT_RT_FULL
  10288. +static inline int dev_recursion_level(void)
  10289. +{
  10290. + return current->xmit_recursion;
  10291. +}
  10292. +
  10293. +#else
  10294. +
  10295. DECLARE_PER_CPU(int, xmit_recursion);
  10296. static inline int dev_recursion_level(void)
  10297. {
  10298. return this_cpu_read(xmit_recursion);
  10299. }
  10300. +#endif
  10301. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  10302. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  10303. @@ -2469,6 +2478,7 @@
  10304. unsigned int dropped;
  10305. struct sk_buff_head input_pkt_queue;
  10306. struct napi_struct backlog;
  10307. + struct sk_buff_head tofree_queue;
  10308. };
  10309. diff -Nur linux-4.1.26.orig/include/linux/netfilter/x_tables.h linux-4.1.26/include/linux/netfilter/x_tables.h
  10310. --- linux-4.1.26.orig/include/linux/netfilter/x_tables.h 2016-06-07 01:13:11.000000000 +0200
  10311. +++ linux-4.1.26/include/linux/netfilter/x_tables.h 2016-06-19 15:30:58.671296732 +0200
  10312. @@ -3,6 +3,7 @@
  10313. #include <linux/netdevice.h>
  10314. +#include <linux/locallock.h>
  10315. #include <uapi/linux/netfilter/x_tables.h>
  10316. /**
  10317. @@ -282,6 +283,8 @@
  10318. */
  10319. DECLARE_PER_CPU(seqcount_t, xt_recseq);
  10320. +DECLARE_LOCAL_IRQ_LOCK(xt_write_lock);
  10321. +
  10322. /**
  10323. * xt_write_recseq_begin - start of a write section
  10324. *
  10325. @@ -296,6 +299,9 @@
  10326. {
  10327. unsigned int addend;
  10328. + /* RT protection */
  10329. + local_lock(xt_write_lock);
  10330. +
  10331. /*
  10332. * Low order bit of sequence is set if we already
  10333. * called xt_write_recseq_begin().
  10334. @@ -326,6 +332,7 @@
  10335. /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */
  10336. smp_wmb();
  10337. __this_cpu_add(xt_recseq.sequence, addend);
  10338. + local_unlock(xt_write_lock);
  10339. }
  10340. /*
  10341. diff -Nur linux-4.1.26.orig/include/linux/notifier.h linux-4.1.26/include/linux/notifier.h
  10342. --- linux-4.1.26.orig/include/linux/notifier.h 2016-06-07 01:13:11.000000000 +0200
  10343. +++ linux-4.1.26/include/linux/notifier.h 2016-06-19 15:30:58.671296732 +0200
  10344. @@ -6,7 +6,7 @@
  10345. *
  10346. * Alan Cox <Alan.Cox@linux.org>
  10347. */
  10348. -
  10349. +
  10350. #ifndef _LINUX_NOTIFIER_H
  10351. #define _LINUX_NOTIFIER_H
  10352. #include <linux/errno.h>
  10353. @@ -42,9 +42,7 @@
  10354. * in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
  10355. * As compensation, srcu_notifier_chain_unregister() is rather expensive.
  10356. * SRCU notifier chains should be used when the chain will be called very
  10357. - * often but notifier_blocks will seldom be removed. Also, SRCU notifier
  10358. - * chains are slightly more difficult to use because they require special
  10359. - * runtime initialization.
  10360. + * often but notifier_blocks will seldom be removed.
  10361. */
  10362. typedef int (*notifier_fn_t)(struct notifier_block *nb,
  10363. @@ -88,7 +86,7 @@
  10364. (name)->head = NULL; \
  10365. } while (0)
  10366. -/* srcu_notifier_heads must be initialized and cleaned up dynamically */
  10367. +/* srcu_notifier_heads must be cleaned up dynamically */
  10368. extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
  10369. #define srcu_cleanup_notifier_head(name) \
  10370. cleanup_srcu_struct(&(name)->srcu);
  10371. @@ -101,7 +99,13 @@
  10372. .head = NULL }
  10373. #define RAW_NOTIFIER_INIT(name) { \
  10374. .head = NULL }
  10375. -/* srcu_notifier_heads cannot be initialized statically */
  10376. +
  10377. +#define SRCU_NOTIFIER_INIT(name, pcpu) \
  10378. + { \
  10379. + .mutex = __MUTEX_INITIALIZER(name.mutex), \
  10380. + .head = NULL, \
  10381. + .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
  10382. + }
  10383. #define ATOMIC_NOTIFIER_HEAD(name) \
  10384. struct atomic_notifier_head name = \
  10385. @@ -113,6 +117,18 @@
  10386. struct raw_notifier_head name = \
  10387. RAW_NOTIFIER_INIT(name)
  10388. +#define _SRCU_NOTIFIER_HEAD(name, mod) \
  10389. + static DEFINE_PER_CPU(struct srcu_struct_array, \
  10390. + name##_head_srcu_array); \
  10391. + mod struct srcu_notifier_head name = \
  10392. + SRCU_NOTIFIER_INIT(name, name##_head_srcu_array)
  10393. +
  10394. +#define SRCU_NOTIFIER_HEAD(name) \
  10395. + _SRCU_NOTIFIER_HEAD(name, )
  10396. +
  10397. +#define SRCU_NOTIFIER_HEAD_STATIC(name) \
  10398. + _SRCU_NOTIFIER_HEAD(name, static)
  10399. +
  10400. #ifdef __KERNEL__
  10401. extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
  10402. @@ -182,12 +198,12 @@
  10403. /*
  10404. * Declared notifiers so far. I can imagine quite a few more chains
  10405. - * over time (eg laptop power reset chains, reboot chain (to clean
  10406. + * over time (eg laptop power reset chains, reboot chain (to clean
  10407. * device units up), device [un]mount chain, module load/unload chain,
  10408. - * low memory chain, screenblank chain (for plug in modular screenblankers)
  10409. + * low memory chain, screenblank chain (for plug in modular screenblankers)
  10410. * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
  10411. */
  10412. -
  10413. +
  10414. /* CPU notfiers are defined in include/linux/cpu.h. */
  10415. /* netdevice notifiers are defined in include/linux/netdevice.h */
  10416. diff -Nur linux-4.1.26.orig/include/linux/percpu.h linux-4.1.26/include/linux/percpu.h
  10417. --- linux-4.1.26.orig/include/linux/percpu.h 2016-06-07 01:13:11.000000000 +0200
  10418. +++ linux-4.1.26/include/linux/percpu.h 2016-06-19 15:30:58.671296732 +0200
  10419. @@ -24,6 +24,35 @@
  10420. PERCPU_MODULE_RESERVE)
  10421. #endif
  10422. +#ifdef CONFIG_PREEMPT_RT_FULL
  10423. +
  10424. +#define get_local_var(var) (*({ \
  10425. + migrate_disable(); \
  10426. + this_cpu_ptr(&var); }))
  10427. +
  10428. +#define put_local_var(var) do { \
  10429. + (void)&(var); \
  10430. + migrate_enable(); \
  10431. +} while (0)
  10432. +
  10433. +# define get_local_ptr(var) ({ \
  10434. + migrate_disable(); \
  10435. + this_cpu_ptr(var); })
  10436. +
  10437. +# define put_local_ptr(var) do { \
  10438. + (void)(var); \
  10439. + migrate_enable(); \
  10440. +} while (0)
  10441. +
  10442. +#else
  10443. +
  10444. +#define get_local_var(var) get_cpu_var(var)
  10445. +#define put_local_var(var) put_cpu_var(var)
  10446. +#define get_local_ptr(var) get_cpu_ptr(var)
  10447. +#define put_local_ptr(var) put_cpu_ptr(var)
  10448. +
  10449. +#endif
  10450. +
  10451. /* minimum unit size, also is the maximum supported allocation size */
  10452. #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
  10453. diff -Nur linux-4.1.26.orig/include/linux/pid.h linux-4.1.26/include/linux/pid.h
  10454. --- linux-4.1.26.orig/include/linux/pid.h 2016-06-07 01:13:11.000000000 +0200
  10455. +++ linux-4.1.26/include/linux/pid.h 2016-06-19 15:30:58.671296732 +0200
  10456. @@ -2,6 +2,7 @@
  10457. #define _LINUX_PID_H
  10458. #include <linux/rcupdate.h>
  10459. +#include <linux/atomic.h>
  10460. enum pid_type
  10461. {
  10462. diff -Nur linux-4.1.26.orig/include/linux/platform_data/gpio-omap.h linux-4.1.26/include/linux/platform_data/gpio-omap.h
  10463. --- linux-4.1.26.orig/include/linux/platform_data/gpio-omap.h 2016-06-07 01:13:11.000000000 +0200
  10464. +++ linux-4.1.26/include/linux/platform_data/gpio-omap.h 2016-06-19 15:30:58.671296732 +0200
  10465. @@ -198,7 +198,6 @@
  10466. int bank_width; /* GPIO bank width */
  10467. int bank_stride; /* Only needed for omap1 MPUIO */
  10468. bool dbck_flag; /* dbck required or not - True for OMAP3&4 */
  10469. - bool loses_context; /* whether the bank would ever lose context */
  10470. bool is_mpuio; /* whether the bank is of type MPUIO */
  10471. u32 non_wakeup_gpios;
  10472. @@ -208,9 +207,17 @@
  10473. int (*get_context_loss_count)(struct device *dev);
  10474. };
  10475. +#if IS_BUILTIN(CONFIG_GPIO_OMAP)
  10476. extern void omap2_gpio_prepare_for_idle(int off_mode);
  10477. extern void omap2_gpio_resume_after_idle(void);
  10478. -extern void omap_set_gpio_debounce(int gpio, int enable);
  10479. -extern void omap_set_gpio_debounce_time(int gpio, int enable);
  10480. +#else
  10481. +static inline void omap2_gpio_prepare_for_idle(int off_mode)
  10482. +{
  10483. +}
  10484. +
  10485. +static inline void omap2_gpio_resume_after_idle(void)
  10486. +{
  10487. +}
  10488. +#endif
  10489. #endif
  10490. diff -Nur linux-4.1.26.orig/include/linux/preempt.h linux-4.1.26/include/linux/preempt.h
  10491. --- linux-4.1.26.orig/include/linux/preempt.h 2016-06-07 01:13:11.000000000 +0200
  10492. +++ linux-4.1.26/include/linux/preempt.h 2016-06-19 15:30:58.671296732 +0200
  10493. @@ -34,6 +34,20 @@
  10494. #define preempt_count_inc() preempt_count_add(1)
  10495. #define preempt_count_dec() preempt_count_sub(1)
  10496. +#ifdef CONFIG_PREEMPT_LAZY
  10497. +#define add_preempt_lazy_count(val) do { preempt_lazy_count() += (val); } while (0)
  10498. +#define sub_preempt_lazy_count(val) do { preempt_lazy_count() -= (val); } while (0)
  10499. +#define inc_preempt_lazy_count() add_preempt_lazy_count(1)
  10500. +#define dec_preempt_lazy_count() sub_preempt_lazy_count(1)
  10501. +#define preempt_lazy_count() (current_thread_info()->preempt_lazy_count)
  10502. +#else
  10503. +#define add_preempt_lazy_count(val) do { } while (0)
  10504. +#define sub_preempt_lazy_count(val) do { } while (0)
  10505. +#define inc_preempt_lazy_count() do { } while (0)
  10506. +#define dec_preempt_lazy_count() do { } while (0)
  10507. +#define preempt_lazy_count() (0)
  10508. +#endif
  10509. +
  10510. #ifdef CONFIG_PREEMPT_COUNT
  10511. #define preempt_disable() \
  10512. @@ -42,13 +56,25 @@
  10513. barrier(); \
  10514. } while (0)
  10515. +#define preempt_lazy_disable() \
  10516. +do { \
  10517. + inc_preempt_lazy_count(); \
  10518. + barrier(); \
  10519. +} while (0)
  10520. +
  10521. #define sched_preempt_enable_no_resched() \
  10522. do { \
  10523. barrier(); \
  10524. preempt_count_dec(); \
  10525. } while (0)
  10526. -#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  10527. +#ifdef CONFIG_PREEMPT_RT_BASE
  10528. +# define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  10529. +# define preempt_check_resched_rt() preempt_check_resched()
  10530. +#else
  10531. +# define preempt_enable_no_resched() preempt_enable()
  10532. +# define preempt_check_resched_rt() barrier();
  10533. +#endif
  10534. #ifdef CONFIG_PREEMPT
  10535. #define preempt_enable() \
  10536. @@ -64,6 +90,13 @@
  10537. __preempt_schedule(); \
  10538. } while (0)
  10539. +#define preempt_lazy_enable() \
  10540. +do { \
  10541. + dec_preempt_lazy_count(); \
  10542. + barrier(); \
  10543. + preempt_check_resched(); \
  10544. +} while (0)
  10545. +
  10546. #else
  10547. #define preempt_enable() \
  10548. do { \
  10549. @@ -122,6 +155,7 @@
  10550. #define preempt_disable_notrace() barrier()
  10551. #define preempt_enable_no_resched_notrace() barrier()
  10552. #define preempt_enable_notrace() barrier()
  10553. +#define preempt_check_resched_rt() barrier()
  10554. #endif /* CONFIG_PREEMPT_COUNT */
  10555. @@ -141,10 +175,31 @@
  10556. } while (0)
  10557. #define preempt_fold_need_resched() \
  10558. do { \
  10559. - if (tif_need_resched()) \
  10560. + if (tif_need_resched_now()) \
  10561. set_preempt_need_resched(); \
  10562. } while (0)
  10563. +#ifdef CONFIG_PREEMPT_RT_FULL
  10564. +# define preempt_disable_rt() preempt_disable()
  10565. +# define preempt_enable_rt() preempt_enable()
  10566. +# define preempt_disable_nort() barrier()
  10567. +# define preempt_enable_nort() barrier()
  10568. +# ifdef CONFIG_SMP
  10569. + extern void migrate_disable(void);
  10570. + extern void migrate_enable(void);
  10571. +# else /* CONFIG_SMP */
  10572. +# define migrate_disable() barrier()
  10573. +# define migrate_enable() barrier()
  10574. +# endif /* CONFIG_SMP */
  10575. +#else
  10576. +# define preempt_disable_rt() barrier()
  10577. +# define preempt_enable_rt() barrier()
  10578. +# define preempt_disable_nort() preempt_disable()
  10579. +# define preempt_enable_nort() preempt_enable()
  10580. +# define migrate_disable() preempt_disable()
  10581. +# define migrate_enable() preempt_enable()
  10582. +#endif
  10583. +
  10584. #ifdef CONFIG_PREEMPT_NOTIFIERS
  10585. struct preempt_notifier;
  10586. diff -Nur linux-4.1.26.orig/include/linux/preempt_mask.h linux-4.1.26/include/linux/preempt_mask.h
  10587. --- linux-4.1.26.orig/include/linux/preempt_mask.h 2016-06-07 01:13:11.000000000 +0200
  10588. +++ linux-4.1.26/include/linux/preempt_mask.h 2016-06-19 15:30:58.671296732 +0200
  10589. @@ -44,16 +44,26 @@
  10590. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  10591. #define NMI_OFFSET (1UL << NMI_SHIFT)
  10592. -#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  10593. +#ifndef CONFIG_PREEMPT_RT_FULL
  10594. +# define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  10595. +#else
  10596. +# define SOFTIRQ_DISABLE_OFFSET (0)
  10597. +#endif
  10598. #define PREEMPT_ACTIVE_BITS 1
  10599. #define PREEMPT_ACTIVE_SHIFT (NMI_SHIFT + NMI_BITS)
  10600. #define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
  10601. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  10602. -#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  10603. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
  10604. | NMI_MASK))
  10605. +#ifndef CONFIG_PREEMPT_RT_FULL
  10606. +# define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  10607. +# define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  10608. +#else
  10609. +# define softirq_count() (0UL)
  10610. +extern int in_serving_softirq(void);
  10611. +#endif
  10612. /*
  10613. * Are we doing bottom half or hardware interrupt processing?
  10614. @@ -64,7 +74,6 @@
  10615. #define in_irq() (hardirq_count())
  10616. #define in_softirq() (softirq_count())
  10617. #define in_interrupt() (irq_count())
  10618. -#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  10619. /*
  10620. * Are we in NMI context?
  10621. @@ -83,7 +92,11 @@
  10622. /*
  10623. * The preempt_count offset after spin_lock()
  10624. */
  10625. +#if !defined(CONFIG_PREEMPT_RT_FULL)
  10626. #define PREEMPT_LOCK_OFFSET PREEMPT_DISABLE_OFFSET
  10627. +#else
  10628. +#define PREEMPT_LOCK_OFFSET 0
  10629. +#endif
  10630. /*
  10631. * The preempt_count offset needed for things like:
  10632. diff -Nur linux-4.1.26.orig/include/linux/printk.h linux-4.1.26/include/linux/printk.h
  10633. --- linux-4.1.26.orig/include/linux/printk.h 2016-06-07 01:13:11.000000000 +0200
  10634. +++ linux-4.1.26/include/linux/printk.h 2016-06-19 15:30:58.671296732 +0200
  10635. @@ -115,9 +115,11 @@
  10636. #ifdef CONFIG_EARLY_PRINTK
  10637. extern asmlinkage __printf(1, 2)
  10638. void early_printk(const char *fmt, ...);
  10639. +extern void printk_kill(void);
  10640. #else
  10641. static inline __printf(1, 2) __cold
  10642. void early_printk(const char *s, ...) { }
  10643. +static inline void printk_kill(void) { }
  10644. #endif
  10645. typedef int(*printk_func_t)(const char *fmt, va_list args);
  10646. diff -Nur linux-4.1.26.orig/include/linux/radix-tree.h linux-4.1.26/include/linux/radix-tree.h
  10647. --- linux-4.1.26.orig/include/linux/radix-tree.h 2016-06-07 01:13:11.000000000 +0200
  10648. +++ linux-4.1.26/include/linux/radix-tree.h 2016-06-19 15:30:58.671296732 +0200
  10649. @@ -277,8 +277,13 @@
  10650. unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  10651. void ***results, unsigned long *indices,
  10652. unsigned long first_index, unsigned int max_items);
  10653. +#ifndef CONFIG_PREEMPT_RT_FULL
  10654. int radix_tree_preload(gfp_t gfp_mask);
  10655. int radix_tree_maybe_preload(gfp_t gfp_mask);
  10656. +#else
  10657. +static inline int radix_tree_preload(gfp_t gm) { return 0; }
  10658. +static inline int radix_tree_maybe_preload(gfp_t gfp_mask) { return 0; }
  10659. +#endif
  10660. void radix_tree_init(void);
  10661. void *radix_tree_tag_set(struct radix_tree_root *root,
  10662. unsigned long index, unsigned int tag);
  10663. @@ -303,7 +308,7 @@
  10664. static inline void radix_tree_preload_end(void)
  10665. {
  10666. - preempt_enable();
  10667. + preempt_enable_nort();
  10668. }
  10669. /**
  10670. diff -Nur linux-4.1.26.orig/include/linux/random.h linux-4.1.26/include/linux/random.h
  10671. --- linux-4.1.26.orig/include/linux/random.h 2016-06-07 01:13:11.000000000 +0200
  10672. +++ linux-4.1.26/include/linux/random.h 2016-06-19 15:30:58.671296732 +0200
  10673. @@ -11,7 +11,7 @@
  10674. extern void add_device_randomness(const void *, unsigned int);
  10675. extern void add_input_randomness(unsigned int type, unsigned int code,
  10676. unsigned int value);
  10677. -extern void add_interrupt_randomness(int irq, int irq_flags);
  10678. +extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
  10679. extern void get_random_bytes(void *buf, int nbytes);
  10680. extern void get_random_bytes_arch(void *buf, int nbytes);
  10681. diff -Nur linux-4.1.26.orig/include/linux/rcupdate.h linux-4.1.26/include/linux/rcupdate.h
  10682. --- linux-4.1.26.orig/include/linux/rcupdate.h 2016-06-07 01:13:11.000000000 +0200
  10683. +++ linux-4.1.26/include/linux/rcupdate.h 2016-06-19 15:30:58.671296732 +0200
  10684. @@ -167,6 +167,9 @@
  10685. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  10686. +#ifdef CONFIG_PREEMPT_RT_FULL
  10687. +#define call_rcu_bh call_rcu
  10688. +#else
  10689. /**
  10690. * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
  10691. * @head: structure to be used for queueing the RCU updates.
  10692. @@ -190,6 +193,7 @@
  10693. */
  10694. void call_rcu_bh(struct rcu_head *head,
  10695. void (*func)(struct rcu_head *head));
  10696. +#endif
  10697. /**
  10698. * call_rcu_sched() - Queue an RCU for invocation after sched grace period.
  10699. @@ -260,6 +264,11 @@
  10700. * types of kernel builds, the rcu_read_lock() nesting depth is unknowable.
  10701. */
  10702. #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
  10703. +#ifndef CONFIG_PREEMPT_RT_FULL
  10704. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  10705. +#else
  10706. +static inline int sched_rcu_preempt_depth(void) { return 0; }
  10707. +#endif
  10708. #else /* #ifdef CONFIG_PREEMPT_RCU */
  10709. @@ -283,6 +292,8 @@
  10710. return 0;
  10711. }
  10712. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  10713. +
  10714. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  10715. /* Internal to kernel */
  10716. @@ -463,7 +474,14 @@
  10717. int debug_lockdep_rcu_enabled(void);
  10718. int rcu_read_lock_held(void);
  10719. +#ifdef CONFIG_PREEMPT_RT_FULL
  10720. +static inline int rcu_read_lock_bh_held(void)
  10721. +{
  10722. + return rcu_read_lock_held();
  10723. +}
  10724. +#else
  10725. int rcu_read_lock_bh_held(void);
  10726. +#endif
  10727. /**
  10728. * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
  10729. @@ -990,10 +1008,14 @@
  10730. static inline void rcu_read_lock_bh(void)
  10731. {
  10732. local_bh_disable();
  10733. +#ifdef CONFIG_PREEMPT_RT_FULL
  10734. + rcu_read_lock();
  10735. +#else
  10736. __acquire(RCU_BH);
  10737. rcu_lock_acquire(&rcu_bh_lock_map);
  10738. rcu_lockdep_assert(rcu_is_watching(),
  10739. "rcu_read_lock_bh() used illegally while idle");
  10740. +#endif
  10741. }
  10742. /*
  10743. @@ -1003,10 +1025,14 @@
  10744. */
  10745. static inline void rcu_read_unlock_bh(void)
  10746. {
  10747. +#ifdef CONFIG_PREEMPT_RT_FULL
  10748. + rcu_read_unlock();
  10749. +#else
  10750. rcu_lockdep_assert(rcu_is_watching(),
  10751. "rcu_read_unlock_bh() used illegally while idle");
  10752. rcu_lock_release(&rcu_bh_lock_map);
  10753. __release(RCU_BH);
  10754. +#endif
  10755. local_bh_enable();
  10756. }
  10757. diff -Nur linux-4.1.26.orig/include/linux/rcutree.h linux-4.1.26/include/linux/rcutree.h
  10758. --- linux-4.1.26.orig/include/linux/rcutree.h 2016-06-07 01:13:11.000000000 +0200
  10759. +++ linux-4.1.26/include/linux/rcutree.h 2016-06-19 15:30:58.671296732 +0200
  10760. @@ -46,7 +46,11 @@
  10761. rcu_note_context_switch();
  10762. }
  10763. +#ifdef CONFIG_PREEMPT_RT_FULL
  10764. +# define synchronize_rcu_bh synchronize_rcu
  10765. +#else
  10766. void synchronize_rcu_bh(void);
  10767. +#endif
  10768. void synchronize_sched_expedited(void);
  10769. void synchronize_rcu_expedited(void);
  10770. @@ -74,7 +78,11 @@
  10771. }
  10772. void rcu_barrier(void);
  10773. +#ifdef CONFIG_PREEMPT_RT_FULL
  10774. +# define rcu_barrier_bh rcu_barrier
  10775. +#else
  10776. void rcu_barrier_bh(void);
  10777. +#endif
  10778. void rcu_barrier_sched(void);
  10779. unsigned long get_state_synchronize_rcu(void);
  10780. void cond_synchronize_rcu(unsigned long oldstate);
  10781. @@ -85,12 +93,10 @@
  10782. unsigned long rcu_batches_started_bh(void);
  10783. unsigned long rcu_batches_started_sched(void);
  10784. unsigned long rcu_batches_completed(void);
  10785. -unsigned long rcu_batches_completed_bh(void);
  10786. unsigned long rcu_batches_completed_sched(void);
  10787. void show_rcu_gp_kthreads(void);
  10788. void rcu_force_quiescent_state(void);
  10789. -void rcu_bh_force_quiescent_state(void);
  10790. void rcu_sched_force_quiescent_state(void);
  10791. void exit_rcu(void);
  10792. @@ -100,6 +106,14 @@
  10793. bool rcu_is_watching(void);
  10794. +#ifndef CONFIG_PREEMPT_RT_FULL
  10795. +void rcu_bh_force_quiescent_state(void);
  10796. +unsigned long rcu_batches_completed_bh(void);
  10797. +#else
  10798. +# define rcu_bh_force_quiescent_state rcu_force_quiescent_state
  10799. +# define rcu_batches_completed_bh rcu_batches_completed
  10800. +#endif
  10801. +
  10802. void rcu_all_qs(void);
  10803. #endif /* __LINUX_RCUTREE_H */
  10804. diff -Nur linux-4.1.26.orig/include/linux/rtmutex.h linux-4.1.26/include/linux/rtmutex.h
  10805. --- linux-4.1.26.orig/include/linux/rtmutex.h 2016-06-07 01:13:11.000000000 +0200
  10806. +++ linux-4.1.26/include/linux/rtmutex.h 2016-06-19 15:30:58.675296887 +0200
  10807. @@ -14,10 +14,14 @@
  10808. #include <linux/linkage.h>
  10809. #include <linux/rbtree.h>
  10810. -#include <linux/spinlock_types.h>
  10811. +#include <linux/spinlock_types_raw.h>
  10812. extern int max_lock_depth; /* for sysctl */
  10813. +#ifdef CONFIG_DEBUG_MUTEXES
  10814. +#include <linux/debug_locks.h>
  10815. +#endif
  10816. +
  10817. /**
  10818. * The rt_mutex structure
  10819. *
  10820. @@ -31,8 +35,8 @@
  10821. struct rb_root waiters;
  10822. struct rb_node *waiters_leftmost;
  10823. struct task_struct *owner;
  10824. -#ifdef CONFIG_DEBUG_RT_MUTEXES
  10825. int save_state;
  10826. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  10827. const char *name, *file;
  10828. int line;
  10829. void *magic;
  10830. @@ -55,22 +59,33 @@
  10831. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  10832. #endif
  10833. +# define rt_mutex_init(mutex) \
  10834. + do { \
  10835. + raw_spin_lock_init(&(mutex)->wait_lock); \
  10836. + __rt_mutex_init(mutex, #mutex); \
  10837. + } while (0)
  10838. +
  10839. #ifdef CONFIG_DEBUG_RT_MUTEXES
  10840. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  10841. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  10842. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
  10843. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  10844. #else
  10845. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  10846. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  10847. # define rt_mutex_debug_task_free(t) do { } while (0)
  10848. #endif
  10849. -#define __RT_MUTEX_INITIALIZER(mutexname) \
  10850. - { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  10851. +#define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  10852. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  10853. , .waiters = RB_ROOT \
  10854. , .owner = NULL \
  10855. - __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  10856. + __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  10857. +
  10858. +#define __RT_MUTEX_INITIALIZER(mutexname) \
  10859. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
  10860. +
  10861. +#define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
  10862. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  10863. + , .save_state = 1 }
  10864. #define DEFINE_RT_MUTEX(mutexname) \
  10865. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  10866. @@ -91,6 +106,7 @@
  10867. extern void rt_mutex_lock(struct rt_mutex *lock);
  10868. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
  10869. +extern int rt_mutex_lock_killable(struct rt_mutex *lock);
  10870. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  10871. struct hrtimer_sleeper *timeout);
  10872. diff -Nur linux-4.1.26.orig/include/linux/rwlock_rt.h linux-4.1.26/include/linux/rwlock_rt.h
  10873. --- linux-4.1.26.orig/include/linux/rwlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  10874. +++ linux-4.1.26/include/linux/rwlock_rt.h 2016-06-19 15:30:58.675296887 +0200
  10875. @@ -0,0 +1,99 @@
  10876. +#ifndef __LINUX_RWLOCK_RT_H
  10877. +#define __LINUX_RWLOCK_RT_H
  10878. +
  10879. +#ifndef __LINUX_SPINLOCK_H
  10880. +#error Do not include directly. Use spinlock.h
  10881. +#endif
  10882. +
  10883. +#define rwlock_init(rwl) \
  10884. +do { \
  10885. + static struct lock_class_key __key; \
  10886. + \
  10887. + rt_mutex_init(&(rwl)->lock); \
  10888. + __rt_rwlock_init(rwl, #rwl, &__key); \
  10889. +} while (0)
  10890. +
  10891. +extern void __lockfunc rt_write_lock(rwlock_t *rwlock);
  10892. +extern void __lockfunc rt_read_lock(rwlock_t *rwlock);
  10893. +extern int __lockfunc rt_write_trylock(rwlock_t *rwlock);
  10894. +extern int __lockfunc rt_write_trylock_irqsave(rwlock_t *trylock, unsigned long *flags);
  10895. +extern int __lockfunc rt_read_trylock(rwlock_t *rwlock);
  10896. +extern void __lockfunc rt_write_unlock(rwlock_t *rwlock);
  10897. +extern void __lockfunc rt_read_unlock(rwlock_t *rwlock);
  10898. +extern unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock);
  10899. +extern unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock);
  10900. +extern void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key);
  10901. +
  10902. +#define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
  10903. +#define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
  10904. +
  10905. +#define write_trylock_irqsave(lock, flags) \
  10906. + __cond_lock(lock, rt_write_trylock_irqsave(lock, &flags))
  10907. +
  10908. +#define read_lock_irqsave(lock, flags) \
  10909. + do { \
  10910. + typecheck(unsigned long, flags); \
  10911. + flags = rt_read_lock_irqsave(lock); \
  10912. + } while (0)
  10913. +
  10914. +#define write_lock_irqsave(lock, flags) \
  10915. + do { \
  10916. + typecheck(unsigned long, flags); \
  10917. + flags = rt_write_lock_irqsave(lock); \
  10918. + } while (0)
  10919. +
  10920. +#define read_lock(lock) rt_read_lock(lock)
  10921. +
  10922. +#define read_lock_bh(lock) \
  10923. + do { \
  10924. + local_bh_disable(); \
  10925. + rt_read_lock(lock); \
  10926. + } while (0)
  10927. +
  10928. +#define read_lock_irq(lock) read_lock(lock)
  10929. +
  10930. +#define write_lock(lock) rt_write_lock(lock)
  10931. +
  10932. +#define write_lock_bh(lock) \
  10933. + do { \
  10934. + local_bh_disable(); \
  10935. + rt_write_lock(lock); \
  10936. + } while (0)
  10937. +
  10938. +#define write_lock_irq(lock) write_lock(lock)
  10939. +
  10940. +#define read_unlock(lock) rt_read_unlock(lock)
  10941. +
  10942. +#define read_unlock_bh(lock) \
  10943. + do { \
  10944. + rt_read_unlock(lock); \
  10945. + local_bh_enable(); \
  10946. + } while (0)
  10947. +
  10948. +#define read_unlock_irq(lock) read_unlock(lock)
  10949. +
  10950. +#define write_unlock(lock) rt_write_unlock(lock)
  10951. +
  10952. +#define write_unlock_bh(lock) \
  10953. + do { \
  10954. + rt_write_unlock(lock); \
  10955. + local_bh_enable(); \
  10956. + } while (0)
  10957. +
  10958. +#define write_unlock_irq(lock) write_unlock(lock)
  10959. +
  10960. +#define read_unlock_irqrestore(lock, flags) \
  10961. + do { \
  10962. + typecheck(unsigned long, flags); \
  10963. + (void) flags; \
  10964. + rt_read_unlock(lock); \
  10965. + } while (0)
  10966. +
  10967. +#define write_unlock_irqrestore(lock, flags) \
  10968. + do { \
  10969. + typecheck(unsigned long, flags); \
  10970. + (void) flags; \
  10971. + rt_write_unlock(lock); \
  10972. + } while (0)
  10973. +
  10974. +#endif
  10975. diff -Nur linux-4.1.26.orig/include/linux/rwlock_types.h linux-4.1.26/include/linux/rwlock_types.h
  10976. --- linux-4.1.26.orig/include/linux/rwlock_types.h 2016-06-07 01:13:11.000000000 +0200
  10977. +++ linux-4.1.26/include/linux/rwlock_types.h 2016-06-19 15:30:58.675296887 +0200
  10978. @@ -1,6 +1,10 @@
  10979. #ifndef __LINUX_RWLOCK_TYPES_H
  10980. #define __LINUX_RWLOCK_TYPES_H
  10981. +#if !defined(__LINUX_SPINLOCK_TYPES_H)
  10982. +# error "Do not include directly, include spinlock_types.h"
  10983. +#endif
  10984. +
  10985. /*
  10986. * include/linux/rwlock_types.h - generic rwlock type definitions
  10987. * and initializers
  10988. @@ -43,6 +47,7 @@
  10989. RW_DEP_MAP_INIT(lockname) }
  10990. #endif
  10991. -#define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x)
  10992. +#define DEFINE_RWLOCK(name) \
  10993. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  10994. #endif /* __LINUX_RWLOCK_TYPES_H */
  10995. diff -Nur linux-4.1.26.orig/include/linux/rwlock_types_rt.h linux-4.1.26/include/linux/rwlock_types_rt.h
  10996. --- linux-4.1.26.orig/include/linux/rwlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  10997. +++ linux-4.1.26/include/linux/rwlock_types_rt.h 2016-06-19 15:30:58.675296887 +0200
  10998. @@ -0,0 +1,33 @@
  10999. +#ifndef __LINUX_RWLOCK_TYPES_RT_H
  11000. +#define __LINUX_RWLOCK_TYPES_RT_H
  11001. +
  11002. +#ifndef __LINUX_SPINLOCK_TYPES_H
  11003. +#error "Do not include directly. Include spinlock_types.h instead"
  11004. +#endif
  11005. +
  11006. +/*
  11007. + * rwlocks - rtmutex which allows single reader recursion
  11008. + */
  11009. +typedef struct {
  11010. + struct rt_mutex lock;
  11011. + int read_depth;
  11012. + unsigned int break_lock;
  11013. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11014. + struct lockdep_map dep_map;
  11015. +#endif
  11016. +} rwlock_t;
  11017. +
  11018. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11019. +# define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  11020. +#else
  11021. +# define RW_DEP_MAP_INIT(lockname)
  11022. +#endif
  11023. +
  11024. +#define __RW_LOCK_UNLOCKED(name) \
  11025. + { .lock = __RT_MUTEX_INITIALIZER_SAVE_STATE(name.lock), \
  11026. + RW_DEP_MAP_INIT(name) }
  11027. +
  11028. +#define DEFINE_RWLOCK(name) \
  11029. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  11030. +
  11031. +#endif
  11032. diff -Nur linux-4.1.26.orig/include/linux/rwsem.h linux-4.1.26/include/linux/rwsem.h
  11033. --- linux-4.1.26.orig/include/linux/rwsem.h 2016-06-07 01:13:11.000000000 +0200
  11034. +++ linux-4.1.26/include/linux/rwsem.h 2016-06-19 15:30:58.675296887 +0200
  11035. @@ -18,6 +18,10 @@
  11036. #include <linux/osq_lock.h>
  11037. #endif
  11038. +#ifdef CONFIG_PREEMPT_RT_FULL
  11039. +#include <linux/rwsem_rt.h>
  11040. +#else /* PREEMPT_RT_FULL */
  11041. +
  11042. struct rw_semaphore;
  11043. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  11044. @@ -177,4 +181,6 @@
  11045. # define up_read_non_owner(sem) up_read(sem)
  11046. #endif
  11047. +#endif /* !PREEMPT_RT_FULL */
  11048. +
  11049. #endif /* _LINUX_RWSEM_H */
  11050. diff -Nur linux-4.1.26.orig/include/linux/rwsem_rt.h linux-4.1.26/include/linux/rwsem_rt.h
  11051. --- linux-4.1.26.orig/include/linux/rwsem_rt.h 1970-01-01 01:00:00.000000000 +0100
  11052. +++ linux-4.1.26/include/linux/rwsem_rt.h 2016-06-19 15:30:58.675296887 +0200
  11053. @@ -0,0 +1,140 @@
  11054. +#ifndef _LINUX_RWSEM_RT_H
  11055. +#define _LINUX_RWSEM_RT_H
  11056. +
  11057. +#ifndef _LINUX_RWSEM_H
  11058. +#error "Include rwsem.h"
  11059. +#endif
  11060. +
  11061. +/*
  11062. + * RW-semaphores are a spinlock plus a reader-depth count.
  11063. + *
  11064. + * Note that the semantics are different from the usual
  11065. + * Linux rw-sems, in PREEMPT_RT mode we do not allow
  11066. + * multiple readers to hold the lock at once, we only allow
  11067. + * a read-lock owner to read-lock recursively. This is
  11068. + * better for latency, makes the implementation inherently
  11069. + * fair and makes it simpler as well.
  11070. + */
  11071. +
  11072. +#include <linux/rtmutex.h>
  11073. +
  11074. +struct rw_semaphore {
  11075. + struct rt_mutex lock;
  11076. + int read_depth;
  11077. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11078. + struct lockdep_map dep_map;
  11079. +#endif
  11080. +};
  11081. +
  11082. +#define __RWSEM_INITIALIZER(name) \
  11083. + { .lock = __RT_MUTEX_INITIALIZER(name.lock), \
  11084. + RW_DEP_MAP_INIT(name) }
  11085. +
  11086. +#define DECLARE_RWSEM(lockname) \
  11087. + struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)
  11088. +
  11089. +extern void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  11090. + struct lock_class_key *key);
  11091. +
  11092. +#define __rt_init_rwsem(sem, name, key) \
  11093. + do { \
  11094. + rt_mutex_init(&(sem)->lock); \
  11095. + __rt_rwsem_init((sem), (name), (key));\
  11096. + } while (0)
  11097. +
  11098. +#define __init_rwsem(sem, name, key) __rt_init_rwsem(sem, name, key)
  11099. +
  11100. +# define rt_init_rwsem(sem) \
  11101. +do { \
  11102. + static struct lock_class_key __key; \
  11103. + \
  11104. + __rt_init_rwsem((sem), #sem, &__key); \
  11105. +} while (0)
  11106. +
  11107. +extern void rt_down_write(struct rw_semaphore *rwsem);
  11108. +extern void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass);
  11109. +extern void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass);
  11110. +extern void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  11111. + struct lockdep_map *nest);
  11112. +extern void rt_down_read(struct rw_semaphore *rwsem);
  11113. +extern int rt_down_write_trylock(struct rw_semaphore *rwsem);
  11114. +extern int rt_down_read_trylock(struct rw_semaphore *rwsem);
  11115. +extern void __rt_up_read(struct rw_semaphore *rwsem);
  11116. +extern void rt_up_read(struct rw_semaphore *rwsem);
  11117. +extern void rt_up_write(struct rw_semaphore *rwsem);
  11118. +extern void rt_downgrade_write(struct rw_semaphore *rwsem);
  11119. +
  11120. +#define init_rwsem(sem) rt_init_rwsem(sem)
  11121. +#define rwsem_is_locked(s) rt_mutex_is_locked(&(s)->lock)
  11122. +
  11123. +static inline int rwsem_is_contended(struct rw_semaphore *sem)
  11124. +{
  11125. + /* rt_mutex_has_waiters() */
  11126. + return !RB_EMPTY_ROOT(&sem->lock.waiters);
  11127. +}
  11128. +
  11129. +static inline void down_read(struct rw_semaphore *sem)
  11130. +{
  11131. + rt_down_read(sem);
  11132. +}
  11133. +
  11134. +static inline int down_read_trylock(struct rw_semaphore *sem)
  11135. +{
  11136. + return rt_down_read_trylock(sem);
  11137. +}
  11138. +
  11139. +static inline void down_write(struct rw_semaphore *sem)
  11140. +{
  11141. + rt_down_write(sem);
  11142. +}
  11143. +
  11144. +static inline int down_write_trylock(struct rw_semaphore *sem)
  11145. +{
  11146. + return rt_down_write_trylock(sem);
  11147. +}
  11148. +
  11149. +static inline void __up_read(struct rw_semaphore *sem)
  11150. +{
  11151. + __rt_up_read(sem);
  11152. +}
  11153. +
  11154. +static inline void up_read(struct rw_semaphore *sem)
  11155. +{
  11156. + rt_up_read(sem);
  11157. +}
  11158. +
  11159. +static inline void up_write(struct rw_semaphore *sem)
  11160. +{
  11161. + rt_up_write(sem);
  11162. +}
  11163. +
  11164. +static inline void downgrade_write(struct rw_semaphore *sem)
  11165. +{
  11166. + rt_downgrade_write(sem);
  11167. +}
  11168. +
  11169. +static inline void down_read_nested(struct rw_semaphore *sem, int subclass)
  11170. +{
  11171. + return rt_down_read_nested(sem, subclass);
  11172. +}
  11173. +
  11174. +static inline void down_write_nested(struct rw_semaphore *sem, int subclass)
  11175. +{
  11176. + rt_down_write_nested(sem, subclass);
  11177. +}
  11178. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11179. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  11180. + struct rw_semaphore *nest_lock)
  11181. +{
  11182. + rt_down_write_nested_lock(sem, &nest_lock->dep_map);
  11183. +}
  11184. +
  11185. +#else
  11186. +
  11187. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  11188. + struct rw_semaphore *nest_lock)
  11189. +{
  11190. + rt_down_write_nested_lock(sem, NULL);
  11191. +}
  11192. +#endif
  11193. +#endif
  11194. diff -Nur linux-4.1.26.orig/include/linux/sched.h linux-4.1.26/include/linux/sched.h
  11195. --- linux-4.1.26.orig/include/linux/sched.h 2016-06-07 01:13:11.000000000 +0200
  11196. +++ linux-4.1.26/include/linux/sched.h 2016-06-19 15:30:58.675296887 +0200
  11197. @@ -26,6 +26,7 @@
  11198. #include <linux/nodemask.h>
  11199. #include <linux/mm_types.h>
  11200. #include <linux/preempt_mask.h>
  11201. +#include <asm/kmap_types.h>
  11202. #include <asm/page.h>
  11203. #include <asm/ptrace.h>
  11204. @@ -175,8 +176,6 @@
  11205. extern void calc_global_load(unsigned long ticks);
  11206. extern void update_cpu_load_nohz(void);
  11207. -extern unsigned long get_parent_ip(unsigned long addr);
  11208. -
  11209. extern void dump_cpu_task(int cpu);
  11210. struct seq_file;
  11211. @@ -234,10 +233,7 @@
  11212. TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  11213. __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
  11214. -#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
  11215. #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
  11216. -#define task_is_stopped_or_traced(task) \
  11217. - ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
  11218. #define task_contributes_to_load(task) \
  11219. ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
  11220. (task->flags & PF_FROZEN) == 0)
  11221. @@ -302,6 +298,11 @@
  11222. #endif
  11223. +#define __set_current_state_no_track(state_value) \
  11224. + do { current->state = (state_value); } while (0)
  11225. +#define set_current_state_no_track(state_value) \
  11226. + set_mb(current->state, (state_value))
  11227. +
  11228. /* Task command name length */
  11229. #define TASK_COMM_LEN 16
  11230. @@ -901,6 +902,50 @@
  11231. #define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
  11232. /*
  11233. + * Wake-queues are lists of tasks with a pending wakeup, whose
  11234. + * callers have already marked the task as woken internally,
  11235. + * and can thus carry on. A common use case is being able to
  11236. + * do the wakeups once the corresponding user lock as been
  11237. + * released.
  11238. + *
  11239. + * We hold reference to each task in the list across the wakeup,
  11240. + * thus guaranteeing that the memory is still valid by the time
  11241. + * the actual wakeups are performed in wake_up_q().
  11242. + *
  11243. + * One per task suffices, because there's never a need for a task to be
  11244. + * in two wake queues simultaneously; it is forbidden to abandon a task
  11245. + * in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
  11246. + * already in a wake queue, the wakeup will happen soon and the second
  11247. + * waker can just skip it.
  11248. + *
  11249. + * The WAKE_Q macro declares and initializes the list head.
  11250. + * wake_up_q() does NOT reinitialize the list; it's expected to be
  11251. + * called near the end of a function, where the fact that the queue is
  11252. + * not used again will be easy to see by inspection.
  11253. + *
  11254. + * Note that this can cause spurious wakeups. schedule() callers
  11255. + * must ensure the call is done inside a loop, confirming that the
  11256. + * wakeup condition has in fact occurred.
  11257. + */
  11258. +struct wake_q_node {
  11259. + struct wake_q_node *next;
  11260. +};
  11261. +
  11262. +struct wake_q_head {
  11263. + struct wake_q_node *first;
  11264. + struct wake_q_node **lastp;
  11265. +};
  11266. +
  11267. +#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
  11268. +
  11269. +#define WAKE_Q(name) \
  11270. + struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  11271. +
  11272. +extern void wake_q_add(struct wake_q_head *head,
  11273. + struct task_struct *task);
  11274. +extern void wake_up_q(struct wake_q_head *head);
  11275. +
  11276. +/*
  11277. * sched-domains (multiprocessor balancing) declarations:
  11278. */
  11279. #ifdef CONFIG_SMP
  11280. @@ -1292,6 +1337,7 @@
  11281. struct task_struct {
  11282. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  11283. + volatile long saved_state; /* saved state for "spinlock sleepers" */
  11284. void *stack;
  11285. atomic_t usage;
  11286. unsigned int flags; /* per process flags, defined below */
  11287. @@ -1328,6 +1374,12 @@
  11288. #endif
  11289. unsigned int policy;
  11290. +#ifdef CONFIG_PREEMPT_RT_FULL
  11291. + int migrate_disable;
  11292. +# ifdef CONFIG_SCHED_DEBUG
  11293. + int migrate_disable_atomic;
  11294. +# endif
  11295. +#endif
  11296. int nr_cpus_allowed;
  11297. cpumask_t cpus_allowed;
  11298. @@ -1435,7 +1487,8 @@
  11299. struct cputime prev_cputime;
  11300. #endif
  11301. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  11302. - seqlock_t vtime_seqlock;
  11303. + raw_spinlock_t vtime_lock;
  11304. + seqcount_t vtime_seq;
  11305. unsigned long long vtime_snap;
  11306. enum {
  11307. VTIME_SLEEPING = 0,
  11308. @@ -1451,6 +1504,9 @@
  11309. struct task_cputime cputime_expires;
  11310. struct list_head cpu_timers[3];
  11311. +#ifdef CONFIG_PREEMPT_RT_BASE
  11312. + struct task_struct *posix_timer_list;
  11313. +#endif
  11314. /* process credentials */
  11315. const struct cred __rcu *real_cred; /* objective and real subjective task
  11316. @@ -1483,10 +1539,15 @@
  11317. /* signal handlers */
  11318. struct signal_struct *signal;
  11319. struct sighand_struct *sighand;
  11320. + struct sigqueue *sigqueue_cache;
  11321. sigset_t blocked, real_blocked;
  11322. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  11323. struct sigpending pending;
  11324. +#ifdef CONFIG_PREEMPT_RT_FULL
  11325. + /* TODO: move me into ->restart_block ? */
  11326. + struct siginfo forced_info;
  11327. +#endif
  11328. unsigned long sas_ss_sp;
  11329. size_t sas_ss_size;
  11330. @@ -1512,6 +1573,8 @@
  11331. /* Protection of the PI data structures: */
  11332. raw_spinlock_t pi_lock;
  11333. + struct wake_q_node wake_q;
  11334. +
  11335. #ifdef CONFIG_RT_MUTEXES
  11336. /* PI waiters blocked on a rt_mutex held by this task */
  11337. struct rb_root pi_waiters;
  11338. @@ -1706,6 +1769,12 @@
  11339. unsigned long trace;
  11340. /* bitmask and counter of trace recursion */
  11341. unsigned long trace_recursion;
  11342. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  11343. + u64 preempt_timestamp_hist;
  11344. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  11345. + long timer_offset;
  11346. +#endif
  11347. +#endif
  11348. #endif /* CONFIG_TRACING */
  11349. #ifdef CONFIG_MEMCG
  11350. struct memcg_oom_info {
  11351. @@ -1722,14 +1791,26 @@
  11352. unsigned int sequential_io;
  11353. unsigned int sequential_io_avg;
  11354. #endif
  11355. +#ifdef CONFIG_PREEMPT_RT_BASE
  11356. + struct rcu_head put_rcu;
  11357. + int softirq_nestcnt;
  11358. + unsigned int softirqs_raised;
  11359. +#endif
  11360. +#ifdef CONFIG_PREEMPT_RT_FULL
  11361. +# if defined CONFIG_HIGHMEM || defined CONFIG_X86_32
  11362. + int kmap_idx;
  11363. + pte_t kmap_pte[KM_TYPE_NR];
  11364. +# endif
  11365. +#endif
  11366. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  11367. unsigned long task_state_change;
  11368. #endif
  11369. +#ifdef CONFIG_PREEMPT_RT_FULL
  11370. + int xmit_recursion;
  11371. +#endif
  11372. + int pagefault_disabled;
  11373. };
  11374. -/* Future-safe accessor for struct task_struct's cpus_allowed. */
  11375. -#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
  11376. -
  11377. #define TNF_MIGRATED 0x01
  11378. #define TNF_NO_GROUP 0x02
  11379. #define TNF_SHARED 0x04
  11380. @@ -1918,6 +1999,15 @@
  11381. extern void free_task(struct task_struct *tsk);
  11382. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  11383. +#ifdef CONFIG_PREEMPT_RT_BASE
  11384. +extern void __put_task_struct_cb(struct rcu_head *rhp);
  11385. +
  11386. +static inline void put_task_struct(struct task_struct *t)
  11387. +{
  11388. + if (atomic_dec_and_test(&t->usage))
  11389. + call_rcu(&t->put_rcu, __put_task_struct_cb);
  11390. +}
  11391. +#else
  11392. extern void __put_task_struct(struct task_struct *t);
  11393. static inline void put_task_struct(struct task_struct *t)
  11394. @@ -1925,6 +2015,7 @@
  11395. if (atomic_dec_and_test(&t->usage))
  11396. __put_task_struct(t);
  11397. }
  11398. +#endif
  11399. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  11400. extern void task_cputime(struct task_struct *t,
  11401. @@ -1963,6 +2054,7 @@
  11402. /*
  11403. * Per process flags
  11404. */
  11405. +#define PF_IN_SOFTIRQ 0x00000001 /* Task is serving softirq */
  11406. #define PF_EXITING 0x00000004 /* getting shut down */
  11407. #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
  11408. #define PF_VCPU 0x00000010 /* I'm a virtual CPU */
  11409. @@ -2127,6 +2219,10 @@
  11410. extern int set_cpus_allowed_ptr(struct task_struct *p,
  11411. const struct cpumask *new_mask);
  11412. +int migrate_me(void);
  11413. +void tell_sched_cpu_down_begin(int cpu);
  11414. +void tell_sched_cpu_down_done(int cpu);
  11415. +
  11416. #else
  11417. static inline void do_set_cpus_allowed(struct task_struct *p,
  11418. const struct cpumask *new_mask)
  11419. @@ -2139,6 +2235,9 @@
  11420. return -EINVAL;
  11421. return 0;
  11422. }
  11423. +static inline int migrate_me(void) { return 0; }
  11424. +static inline void tell_sched_cpu_down_begin(int cpu) { }
  11425. +static inline void tell_sched_cpu_down_done(int cpu) { }
  11426. #endif
  11427. #ifdef CONFIG_NO_HZ_COMMON
  11428. @@ -2355,6 +2454,7 @@
  11429. extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  11430. extern int wake_up_process(struct task_struct *tsk);
  11431. +extern int wake_up_lock_sleeper(struct task_struct * tsk);
  11432. extern void wake_up_new_task(struct task_struct *tsk);
  11433. #ifdef CONFIG_SMP
  11434. extern void kick_process(struct task_struct *tsk);
  11435. @@ -2471,12 +2571,24 @@
  11436. /* mmdrop drops the mm and the page tables */
  11437. extern void __mmdrop(struct mm_struct *);
  11438. +
  11439. static inline void mmdrop(struct mm_struct * mm)
  11440. {
  11441. if (unlikely(atomic_dec_and_test(&mm->mm_count)))
  11442. __mmdrop(mm);
  11443. }
  11444. +#ifdef CONFIG_PREEMPT_RT_BASE
  11445. +extern void __mmdrop_delayed(struct rcu_head *rhp);
  11446. +static inline void mmdrop_delayed(struct mm_struct *mm)
  11447. +{
  11448. + if (atomic_dec_and_test(&mm->mm_count))
  11449. + call_rcu(&mm->delayed_drop, __mmdrop_delayed);
  11450. +}
  11451. +#else
  11452. +# define mmdrop_delayed(mm) mmdrop(mm)
  11453. +#endif
  11454. +
  11455. /* mmput gets rid of the mappings and all user-space */
  11456. extern void mmput(struct mm_struct *);
  11457. /* Grab a reference to a task's mm, if it is not already going away */
  11458. @@ -2788,6 +2900,43 @@
  11459. return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  11460. }
  11461. +#ifdef CONFIG_PREEMPT_LAZY
  11462. +static inline void set_tsk_need_resched_lazy(struct task_struct *tsk)
  11463. +{
  11464. + set_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  11465. +}
  11466. +
  11467. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk)
  11468. +{
  11469. + clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  11470. +}
  11471. +
  11472. +static inline int test_tsk_need_resched_lazy(struct task_struct *tsk)
  11473. +{
  11474. + return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY));
  11475. +}
  11476. +
  11477. +static inline int need_resched_lazy(void)
  11478. +{
  11479. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  11480. +}
  11481. +
  11482. +static inline int need_resched_now(void)
  11483. +{
  11484. + return test_thread_flag(TIF_NEED_RESCHED);
  11485. +}
  11486. +
  11487. +#else
  11488. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk) { }
  11489. +static inline int need_resched_lazy(void) { return 0; }
  11490. +
  11491. +static inline int need_resched_now(void)
  11492. +{
  11493. + return test_thread_flag(TIF_NEED_RESCHED);
  11494. +}
  11495. +
  11496. +#endif
  11497. +
  11498. static inline int restart_syscall(void)
  11499. {
  11500. set_tsk_thread_flag(current, TIF_SIGPENDING);
  11501. @@ -2819,6 +2968,51 @@
  11502. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  11503. }
  11504. +static inline bool __task_is_stopped_or_traced(struct task_struct *task)
  11505. +{
  11506. + if (task->state & (__TASK_STOPPED | __TASK_TRACED))
  11507. + return true;
  11508. +#ifdef CONFIG_PREEMPT_RT_FULL
  11509. + if (task->saved_state & (__TASK_STOPPED | __TASK_TRACED))
  11510. + return true;
  11511. +#endif
  11512. + return false;
  11513. +}
  11514. +
  11515. +static inline bool task_is_stopped_or_traced(struct task_struct *task)
  11516. +{
  11517. + bool traced_stopped;
  11518. +
  11519. +#ifdef CONFIG_PREEMPT_RT_FULL
  11520. + unsigned long flags;
  11521. +
  11522. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  11523. + traced_stopped = __task_is_stopped_or_traced(task);
  11524. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  11525. +#else
  11526. + traced_stopped = __task_is_stopped_or_traced(task);
  11527. +#endif
  11528. + return traced_stopped;
  11529. +}
  11530. +
  11531. +static inline bool task_is_traced(struct task_struct *task)
  11532. +{
  11533. + bool traced = false;
  11534. +
  11535. + if (task->state & __TASK_TRACED)
  11536. + return true;
  11537. +#ifdef CONFIG_PREEMPT_RT_FULL
  11538. + /* in case the task is sleeping on tasklist_lock */
  11539. + raw_spin_lock_irq(&task->pi_lock);
  11540. + if (task->state & __TASK_TRACED)
  11541. + traced = true;
  11542. + else if (task->saved_state & __TASK_TRACED)
  11543. + traced = true;
  11544. + raw_spin_unlock_irq(&task->pi_lock);
  11545. +#endif
  11546. + return traced;
  11547. +}
  11548. +
  11549. /*
  11550. * cond_resched() and cond_resched_lock(): latency reduction via
  11551. * explicit rescheduling in places that are safe. The return
  11552. @@ -2840,12 +3034,16 @@
  11553. __cond_resched_lock(lock); \
  11554. })
  11555. +#ifndef CONFIG_PREEMPT_RT_FULL
  11556. extern int __cond_resched_softirq(void);
  11557. #define cond_resched_softirq() ({ \
  11558. ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
  11559. __cond_resched_softirq(); \
  11560. })
  11561. +#else
  11562. +# define cond_resched_softirq() cond_resched()
  11563. +#endif
  11564. static inline void cond_resched_rcu(void)
  11565. {
  11566. @@ -3012,6 +3210,26 @@
  11567. #endif /* CONFIG_SMP */
  11568. +static inline int __migrate_disabled(struct task_struct *p)
  11569. +{
  11570. +#ifdef CONFIG_PREEMPT_RT_FULL
  11571. + return p->migrate_disable;
  11572. +#else
  11573. + return 0;
  11574. +#endif
  11575. +}
  11576. +
  11577. +/* Future-safe accessor for struct task_struct's cpus_allowed. */
  11578. +static inline const struct cpumask *tsk_cpus_allowed(struct task_struct *p)
  11579. +{
  11580. +#ifdef CONFIG_PREEMPT_RT_FULL
  11581. + if (p->migrate_disable)
  11582. + return cpumask_of(task_cpu(p));
  11583. +#endif
  11584. +
  11585. + return &p->cpus_allowed;
  11586. +}
  11587. +
  11588. extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  11589. extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  11590. diff -Nur linux-4.1.26.orig/include/linux/seqlock.h linux-4.1.26/include/linux/seqlock.h
  11591. --- linux-4.1.26.orig/include/linux/seqlock.h 2016-06-07 01:13:11.000000000 +0200
  11592. +++ linux-4.1.26/include/linux/seqlock.h 2016-06-19 15:30:58.675296887 +0200
  11593. @@ -219,20 +219,30 @@
  11594. return __read_seqcount_retry(s, start);
  11595. }
  11596. -
  11597. -
  11598. -static inline void raw_write_seqcount_begin(seqcount_t *s)
  11599. +static inline void __raw_write_seqcount_begin(seqcount_t *s)
  11600. {
  11601. s->sequence++;
  11602. smp_wmb();
  11603. }
  11604. -static inline void raw_write_seqcount_end(seqcount_t *s)
  11605. +static inline void raw_write_seqcount_begin(seqcount_t *s)
  11606. +{
  11607. + preempt_disable_rt();
  11608. + __raw_write_seqcount_begin(s);
  11609. +}
  11610. +
  11611. +static inline void __raw_write_seqcount_end(seqcount_t *s)
  11612. {
  11613. smp_wmb();
  11614. s->sequence++;
  11615. }
  11616. +static inline void raw_write_seqcount_end(seqcount_t *s)
  11617. +{
  11618. + __raw_write_seqcount_end(s);
  11619. + preempt_enable_rt();
  11620. +}
  11621. +
  11622. /*
  11623. * raw_write_seqcount_latch - redirect readers to even/odd copy
  11624. * @s: pointer to seqcount_t
  11625. @@ -305,10 +315,32 @@
  11626. /*
  11627. * Read side functions for starting and finalizing a read side section.
  11628. */
  11629. +#ifndef CONFIG_PREEMPT_RT_FULL
  11630. static inline unsigned read_seqbegin(const seqlock_t *sl)
  11631. {
  11632. return read_seqcount_begin(&sl->seqcount);
  11633. }
  11634. +#else
  11635. +/*
  11636. + * Starvation safe read side for RT
  11637. + */
  11638. +static inline unsigned read_seqbegin(seqlock_t *sl)
  11639. +{
  11640. + unsigned ret;
  11641. +
  11642. +repeat:
  11643. + ret = ACCESS_ONCE(sl->seqcount.sequence);
  11644. + if (unlikely(ret & 1)) {
  11645. + /*
  11646. + * Take the lock and let the writer proceed (i.e. evtl
  11647. + * boost it), otherwise we could loop here forever.
  11648. + */
  11649. + spin_unlock_wait(&sl->lock);
  11650. + goto repeat;
  11651. + }
  11652. + return ret;
  11653. +}
  11654. +#endif
  11655. static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
  11656. {
  11657. @@ -323,36 +355,36 @@
  11658. static inline void write_seqlock(seqlock_t *sl)
  11659. {
  11660. spin_lock(&sl->lock);
  11661. - write_seqcount_begin(&sl->seqcount);
  11662. + __raw_write_seqcount_begin(&sl->seqcount);
  11663. }
  11664. static inline void write_sequnlock(seqlock_t *sl)
  11665. {
  11666. - write_seqcount_end(&sl->seqcount);
  11667. + __raw_write_seqcount_end(&sl->seqcount);
  11668. spin_unlock(&sl->lock);
  11669. }
  11670. static inline void write_seqlock_bh(seqlock_t *sl)
  11671. {
  11672. spin_lock_bh(&sl->lock);
  11673. - write_seqcount_begin(&sl->seqcount);
  11674. + __raw_write_seqcount_begin(&sl->seqcount);
  11675. }
  11676. static inline void write_sequnlock_bh(seqlock_t *sl)
  11677. {
  11678. - write_seqcount_end(&sl->seqcount);
  11679. + __raw_write_seqcount_end(&sl->seqcount);
  11680. spin_unlock_bh(&sl->lock);
  11681. }
  11682. static inline void write_seqlock_irq(seqlock_t *sl)
  11683. {
  11684. spin_lock_irq(&sl->lock);
  11685. - write_seqcount_begin(&sl->seqcount);
  11686. + __raw_write_seqcount_begin(&sl->seqcount);
  11687. }
  11688. static inline void write_sequnlock_irq(seqlock_t *sl)
  11689. {
  11690. - write_seqcount_end(&sl->seqcount);
  11691. + __raw_write_seqcount_end(&sl->seqcount);
  11692. spin_unlock_irq(&sl->lock);
  11693. }
  11694. @@ -361,7 +393,7 @@
  11695. unsigned long flags;
  11696. spin_lock_irqsave(&sl->lock, flags);
  11697. - write_seqcount_begin(&sl->seqcount);
  11698. + __raw_write_seqcount_begin(&sl->seqcount);
  11699. return flags;
  11700. }
  11701. @@ -371,7 +403,7 @@
  11702. static inline void
  11703. write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags)
  11704. {
  11705. - write_seqcount_end(&sl->seqcount);
  11706. + __raw_write_seqcount_end(&sl->seqcount);
  11707. spin_unlock_irqrestore(&sl->lock, flags);
  11708. }
  11709. diff -Nur linux-4.1.26.orig/include/linux/signal.h linux-4.1.26/include/linux/signal.h
  11710. --- linux-4.1.26.orig/include/linux/signal.h 2016-06-07 01:13:11.000000000 +0200
  11711. +++ linux-4.1.26/include/linux/signal.h 2016-06-19 15:30:58.675296887 +0200
  11712. @@ -233,6 +233,7 @@
  11713. }
  11714. extern void flush_sigqueue(struct sigpending *queue);
  11715. +extern void flush_task_sigqueue(struct task_struct *tsk);
  11716. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  11717. static inline int valid_signal(unsigned long sig)
  11718. diff -Nur linux-4.1.26.orig/include/linux/skbuff.h linux-4.1.26/include/linux/skbuff.h
  11719. --- linux-4.1.26.orig/include/linux/skbuff.h 2016-06-07 01:13:11.000000000 +0200
  11720. +++ linux-4.1.26/include/linux/skbuff.h 2016-06-19 15:30:58.675296887 +0200
  11721. @@ -187,6 +187,7 @@
  11722. __u32 qlen;
  11723. spinlock_t lock;
  11724. + raw_spinlock_t raw_lock;
  11725. };
  11726. struct sk_buff;
  11727. @@ -1337,6 +1338,12 @@
  11728. __skb_queue_head_init(list);
  11729. }
  11730. +static inline void skb_queue_head_init_raw(struct sk_buff_head *list)
  11731. +{
  11732. + raw_spin_lock_init(&list->raw_lock);
  11733. + __skb_queue_head_init(list);
  11734. +}
  11735. +
  11736. static inline void skb_queue_head_init_class(struct sk_buff_head *list,
  11737. struct lock_class_key *class)
  11738. {
  11739. diff -Nur linux-4.1.26.orig/include/linux/smp.h linux-4.1.26/include/linux/smp.h
  11740. --- linux-4.1.26.orig/include/linux/smp.h 2016-06-07 01:13:11.000000000 +0200
  11741. +++ linux-4.1.26/include/linux/smp.h 2016-06-19 15:30:58.675296887 +0200
  11742. @@ -185,6 +185,9 @@
  11743. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  11744. #define put_cpu() preempt_enable()
  11745. +#define get_cpu_light() ({ migrate_disable(); smp_processor_id(); })
  11746. +#define put_cpu_light() migrate_enable()
  11747. +
  11748. /*
  11749. * Callback to arch code if there's nosmp or maxcpus=0 on the
  11750. * boot command line:
  11751. diff -Nur linux-4.1.26.orig/include/linux/spinlock_api_smp.h linux-4.1.26/include/linux/spinlock_api_smp.h
  11752. --- linux-4.1.26.orig/include/linux/spinlock_api_smp.h 2016-06-07 01:13:11.000000000 +0200
  11753. +++ linux-4.1.26/include/linux/spinlock_api_smp.h 2016-06-19 15:30:58.679297041 +0200
  11754. @@ -189,6 +189,8 @@
  11755. return 0;
  11756. }
  11757. -#include <linux/rwlock_api_smp.h>
  11758. +#ifndef CONFIG_PREEMPT_RT_FULL
  11759. +# include <linux/rwlock_api_smp.h>
  11760. +#endif
  11761. #endif /* __LINUX_SPINLOCK_API_SMP_H */
  11762. diff -Nur linux-4.1.26.orig/include/linux/spinlock.h linux-4.1.26/include/linux/spinlock.h
  11763. --- linux-4.1.26.orig/include/linux/spinlock.h 2016-06-07 01:13:11.000000000 +0200
  11764. +++ linux-4.1.26/include/linux/spinlock.h 2016-06-19 15:30:58.679297041 +0200
  11765. @@ -281,7 +281,11 @@
  11766. #define raw_spin_can_lock(lock) (!raw_spin_is_locked(lock))
  11767. /* Include rwlock functions */
  11768. -#include <linux/rwlock.h>
  11769. +#ifdef CONFIG_PREEMPT_RT_FULL
  11770. +# include <linux/rwlock_rt.h>
  11771. +#else
  11772. +# include <linux/rwlock.h>
  11773. +#endif
  11774. /*
  11775. * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
  11776. @@ -292,6 +296,10 @@
  11777. # include <linux/spinlock_api_up.h>
  11778. #endif
  11779. +#ifdef CONFIG_PREEMPT_RT_FULL
  11780. +# include <linux/spinlock_rt.h>
  11781. +#else /* PREEMPT_RT_FULL */
  11782. +
  11783. /*
  11784. * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  11785. */
  11786. @@ -426,4 +434,6 @@
  11787. #define atomic_dec_and_lock(atomic, lock) \
  11788. __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
  11789. +#endif /* !PREEMPT_RT_FULL */
  11790. +
  11791. #endif /* __LINUX_SPINLOCK_H */
  11792. diff -Nur linux-4.1.26.orig/include/linux/spinlock_rt.h linux-4.1.26/include/linux/spinlock_rt.h
  11793. --- linux-4.1.26.orig/include/linux/spinlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  11794. +++ linux-4.1.26/include/linux/spinlock_rt.h 2016-06-19 15:30:58.679297041 +0200
  11795. @@ -0,0 +1,174 @@
  11796. +#ifndef __LINUX_SPINLOCK_RT_H
  11797. +#define __LINUX_SPINLOCK_RT_H
  11798. +
  11799. +#ifndef __LINUX_SPINLOCK_H
  11800. +#error Do not include directly. Use spinlock.h
  11801. +#endif
  11802. +
  11803. +#include <linux/bug.h>
  11804. +
  11805. +extern void
  11806. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key);
  11807. +
  11808. +#define spin_lock_init(slock) \
  11809. +do { \
  11810. + static struct lock_class_key __key; \
  11811. + \
  11812. + rt_mutex_init(&(slock)->lock); \
  11813. + __rt_spin_lock_init(slock, #slock, &__key); \
  11814. +} while (0)
  11815. +
  11816. +extern void __lockfunc rt_spin_lock(spinlock_t *lock);
  11817. +extern unsigned long __lockfunc rt_spin_lock_trace_flags(spinlock_t *lock);
  11818. +extern void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass);
  11819. +extern void __lockfunc rt_spin_unlock(spinlock_t *lock);
  11820. +extern void __lockfunc rt_spin_unlock_wait(spinlock_t *lock);
  11821. +extern int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags);
  11822. +extern int __lockfunc rt_spin_trylock_bh(spinlock_t *lock);
  11823. +extern int __lockfunc rt_spin_trylock(spinlock_t *lock);
  11824. +extern int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock);
  11825. +
  11826. +/*
  11827. + * lockdep-less calls, for derived types like rwlock:
  11828. + * (for trylock they can use rt_mutex_trylock() directly.
  11829. + */
  11830. +extern void __lockfunc __rt_spin_lock(struct rt_mutex *lock);
  11831. +extern void __lockfunc __rt_spin_unlock(struct rt_mutex *lock);
  11832. +extern int __lockfunc __rt_spin_trylock(struct rt_mutex *lock);
  11833. +
  11834. +#define spin_lock(lock) \
  11835. + do { \
  11836. + migrate_disable(); \
  11837. + rt_spin_lock(lock); \
  11838. + } while (0)
  11839. +
  11840. +#define spin_lock_bh(lock) \
  11841. + do { \
  11842. + local_bh_disable(); \
  11843. + migrate_disable(); \
  11844. + rt_spin_lock(lock); \
  11845. + } while (0)
  11846. +
  11847. +#define spin_lock_irq(lock) spin_lock(lock)
  11848. +
  11849. +#define spin_do_trylock(lock) __cond_lock(lock, rt_spin_trylock(lock))
  11850. +
  11851. +#define spin_trylock(lock) \
  11852. +({ \
  11853. + int __locked; \
  11854. + migrate_disable(); \
  11855. + __locked = spin_do_trylock(lock); \
  11856. + if (!__locked) \
  11857. + migrate_enable(); \
  11858. + __locked; \
  11859. +})
  11860. +
  11861. +#ifdef CONFIG_LOCKDEP
  11862. +# define spin_lock_nested(lock, subclass) \
  11863. + do { \
  11864. + migrate_disable(); \
  11865. + rt_spin_lock_nested(lock, subclass); \
  11866. + } while (0)
  11867. +
  11868. +#define spin_lock_bh_nested(lock, subclass) \
  11869. + do { \
  11870. + local_bh_disable(); \
  11871. + migrate_disable(); \
  11872. + rt_spin_lock_nested(lock, subclass); \
  11873. + } while (0)
  11874. +
  11875. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  11876. + do { \
  11877. + typecheck(unsigned long, flags); \
  11878. + flags = 0; \
  11879. + migrate_disable(); \
  11880. + rt_spin_lock_nested(lock, subclass); \
  11881. + } while (0)
  11882. +#else
  11883. +# define spin_lock_nested(lock, subclass) spin_lock(lock)
  11884. +# define spin_lock_bh_nested(lock, subclass) spin_lock_bh(lock)
  11885. +
  11886. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  11887. + do { \
  11888. + typecheck(unsigned long, flags); \
  11889. + flags = 0; \
  11890. + spin_lock(lock); \
  11891. + } while (0)
  11892. +#endif
  11893. +
  11894. +#define spin_lock_irqsave(lock, flags) \
  11895. + do { \
  11896. + typecheck(unsigned long, flags); \
  11897. + flags = 0; \
  11898. + spin_lock(lock); \
  11899. + } while (0)
  11900. +
  11901. +static inline unsigned long spin_lock_trace_flags(spinlock_t *lock)
  11902. +{
  11903. + unsigned long flags = 0;
  11904. +#ifdef CONFIG_TRACE_IRQFLAGS
  11905. + flags = rt_spin_lock_trace_flags(lock);
  11906. +#else
  11907. + spin_lock(lock); /* lock_local */
  11908. +#endif
  11909. + return flags;
  11910. +}
  11911. +
  11912. +/* FIXME: we need rt_spin_lock_nest_lock */
  11913. +#define spin_lock_nest_lock(lock, nest_lock) spin_lock_nested(lock, 0)
  11914. +
  11915. +#define spin_unlock(lock) \
  11916. + do { \
  11917. + rt_spin_unlock(lock); \
  11918. + migrate_enable(); \
  11919. + } while (0)
  11920. +
  11921. +#define spin_unlock_bh(lock) \
  11922. + do { \
  11923. + rt_spin_unlock(lock); \
  11924. + migrate_enable(); \
  11925. + local_bh_enable(); \
  11926. + } while (0)
  11927. +
  11928. +#define spin_unlock_irq(lock) spin_unlock(lock)
  11929. +
  11930. +#define spin_unlock_irqrestore(lock, flags) \
  11931. + do { \
  11932. + typecheck(unsigned long, flags); \
  11933. + (void) flags; \
  11934. + spin_unlock(lock); \
  11935. + } while (0)
  11936. +
  11937. +#define spin_trylock_bh(lock) __cond_lock(lock, rt_spin_trylock_bh(lock))
  11938. +#define spin_trylock_irq(lock) spin_trylock(lock)
  11939. +
  11940. +#define spin_trylock_irqsave(lock, flags) \
  11941. + rt_spin_trylock_irqsave(lock, &(flags))
  11942. +
  11943. +#define spin_unlock_wait(lock) rt_spin_unlock_wait(lock)
  11944. +
  11945. +#ifdef CONFIG_GENERIC_LOCKBREAK
  11946. +# define spin_is_contended(lock) ((lock)->break_lock)
  11947. +#else
  11948. +# define spin_is_contended(lock) (((void)(lock), 0))
  11949. +#endif
  11950. +
  11951. +static inline int spin_can_lock(spinlock_t *lock)
  11952. +{
  11953. + return !rt_mutex_is_locked(&lock->lock);
  11954. +}
  11955. +
  11956. +static inline int spin_is_locked(spinlock_t *lock)
  11957. +{
  11958. + return rt_mutex_is_locked(&lock->lock);
  11959. +}
  11960. +
  11961. +static inline void assert_spin_locked(spinlock_t *lock)
  11962. +{
  11963. + BUG_ON(!spin_is_locked(lock));
  11964. +}
  11965. +
  11966. +#define atomic_dec_and_lock(atomic, lock) \
  11967. + atomic_dec_and_spin_lock(atomic, lock)
  11968. +
  11969. +#endif
  11970. diff -Nur linux-4.1.26.orig/include/linux/spinlock_types.h linux-4.1.26/include/linux/spinlock_types.h
  11971. --- linux-4.1.26.orig/include/linux/spinlock_types.h 2016-06-07 01:13:11.000000000 +0200
  11972. +++ linux-4.1.26/include/linux/spinlock_types.h 2016-06-19 15:30:58.679297041 +0200
  11973. @@ -9,80 +9,15 @@
  11974. * Released under the General Public License (GPL).
  11975. */
  11976. -#if defined(CONFIG_SMP)
  11977. -# include <asm/spinlock_types.h>
  11978. -#else
  11979. -# include <linux/spinlock_types_up.h>
  11980. -#endif
  11981. -
  11982. -#include <linux/lockdep.h>
  11983. -
  11984. -typedef struct raw_spinlock {
  11985. - arch_spinlock_t raw_lock;
  11986. -#ifdef CONFIG_GENERIC_LOCKBREAK
  11987. - unsigned int break_lock;
  11988. -#endif
  11989. -#ifdef CONFIG_DEBUG_SPINLOCK
  11990. - unsigned int magic, owner_cpu;
  11991. - void *owner;
  11992. -#endif
  11993. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11994. - struct lockdep_map dep_map;
  11995. -#endif
  11996. -} raw_spinlock_t;
  11997. -
  11998. -#define SPINLOCK_MAGIC 0xdead4ead
  11999. -
  12000. -#define SPINLOCK_OWNER_INIT ((void *)-1L)
  12001. -
  12002. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12003. -# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  12004. -#else
  12005. -# define SPIN_DEP_MAP_INIT(lockname)
  12006. -#endif
  12007. +#include <linux/spinlock_types_raw.h>
  12008. -#ifdef CONFIG_DEBUG_SPINLOCK
  12009. -# define SPIN_DEBUG_INIT(lockname) \
  12010. - .magic = SPINLOCK_MAGIC, \
  12011. - .owner_cpu = -1, \
  12012. - .owner = SPINLOCK_OWNER_INIT,
  12013. +#ifndef CONFIG_PREEMPT_RT_FULL
  12014. +# include <linux/spinlock_types_nort.h>
  12015. +# include <linux/rwlock_types.h>
  12016. #else
  12017. -# define SPIN_DEBUG_INIT(lockname)
  12018. +# include <linux/rtmutex.h>
  12019. +# include <linux/spinlock_types_rt.h>
  12020. +# include <linux/rwlock_types_rt.h>
  12021. #endif
  12022. -#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  12023. - { \
  12024. - .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  12025. - SPIN_DEBUG_INIT(lockname) \
  12026. - SPIN_DEP_MAP_INIT(lockname) }
  12027. -
  12028. -#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  12029. - (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  12030. -
  12031. -#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  12032. -
  12033. -typedef struct spinlock {
  12034. - union {
  12035. - struct raw_spinlock rlock;
  12036. -
  12037. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12038. -# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  12039. - struct {
  12040. - u8 __padding[LOCK_PADSIZE];
  12041. - struct lockdep_map dep_map;
  12042. - };
  12043. -#endif
  12044. - };
  12045. -} spinlock_t;
  12046. -
  12047. -#define __SPIN_LOCK_INITIALIZER(lockname) \
  12048. - { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  12049. -
  12050. -#define __SPIN_LOCK_UNLOCKED(lockname) \
  12051. - (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  12052. -
  12053. -#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  12054. -
  12055. -#include <linux/rwlock_types.h>
  12056. -
  12057. #endif /* __LINUX_SPINLOCK_TYPES_H */
  12058. diff -Nur linux-4.1.26.orig/include/linux/spinlock_types_nort.h linux-4.1.26/include/linux/spinlock_types_nort.h
  12059. --- linux-4.1.26.orig/include/linux/spinlock_types_nort.h 1970-01-01 01:00:00.000000000 +0100
  12060. +++ linux-4.1.26/include/linux/spinlock_types_nort.h 2016-06-19 15:30:58.679297041 +0200
  12061. @@ -0,0 +1,33 @@
  12062. +#ifndef __LINUX_SPINLOCK_TYPES_NORT_H
  12063. +#define __LINUX_SPINLOCK_TYPES_NORT_H
  12064. +
  12065. +#ifndef __LINUX_SPINLOCK_TYPES_H
  12066. +#error "Do not include directly. Include spinlock_types.h instead"
  12067. +#endif
  12068. +
  12069. +/*
  12070. + * The non RT version maps spinlocks to raw_spinlocks
  12071. + */
  12072. +typedef struct spinlock {
  12073. + union {
  12074. + struct raw_spinlock rlock;
  12075. +
  12076. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12077. +# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  12078. + struct {
  12079. + u8 __padding[LOCK_PADSIZE];
  12080. + struct lockdep_map dep_map;
  12081. + };
  12082. +#endif
  12083. + };
  12084. +} spinlock_t;
  12085. +
  12086. +#define __SPIN_LOCK_INITIALIZER(lockname) \
  12087. + { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  12088. +
  12089. +#define __SPIN_LOCK_UNLOCKED(lockname) \
  12090. + (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  12091. +
  12092. +#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  12093. +
  12094. +#endif
  12095. diff -Nur linux-4.1.26.orig/include/linux/spinlock_types_raw.h linux-4.1.26/include/linux/spinlock_types_raw.h
  12096. --- linux-4.1.26.orig/include/linux/spinlock_types_raw.h 1970-01-01 01:00:00.000000000 +0100
  12097. +++ linux-4.1.26/include/linux/spinlock_types_raw.h 2016-06-19 15:30:58.679297041 +0200
  12098. @@ -0,0 +1,56 @@
  12099. +#ifndef __LINUX_SPINLOCK_TYPES_RAW_H
  12100. +#define __LINUX_SPINLOCK_TYPES_RAW_H
  12101. +
  12102. +#if defined(CONFIG_SMP)
  12103. +# include <asm/spinlock_types.h>
  12104. +#else
  12105. +# include <linux/spinlock_types_up.h>
  12106. +#endif
  12107. +
  12108. +#include <linux/lockdep.h>
  12109. +
  12110. +typedef struct raw_spinlock {
  12111. + arch_spinlock_t raw_lock;
  12112. +#ifdef CONFIG_GENERIC_LOCKBREAK
  12113. + unsigned int break_lock;
  12114. +#endif
  12115. +#ifdef CONFIG_DEBUG_SPINLOCK
  12116. + unsigned int magic, owner_cpu;
  12117. + void *owner;
  12118. +#endif
  12119. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12120. + struct lockdep_map dep_map;
  12121. +#endif
  12122. +} raw_spinlock_t;
  12123. +
  12124. +#define SPINLOCK_MAGIC 0xdead4ead
  12125. +
  12126. +#define SPINLOCK_OWNER_INIT ((void *)-1L)
  12127. +
  12128. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12129. +# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  12130. +#else
  12131. +# define SPIN_DEP_MAP_INIT(lockname)
  12132. +#endif
  12133. +
  12134. +#ifdef CONFIG_DEBUG_SPINLOCK
  12135. +# define SPIN_DEBUG_INIT(lockname) \
  12136. + .magic = SPINLOCK_MAGIC, \
  12137. + .owner_cpu = -1, \
  12138. + .owner = SPINLOCK_OWNER_INIT,
  12139. +#else
  12140. +# define SPIN_DEBUG_INIT(lockname)
  12141. +#endif
  12142. +
  12143. +#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  12144. + { \
  12145. + .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  12146. + SPIN_DEBUG_INIT(lockname) \
  12147. + SPIN_DEP_MAP_INIT(lockname) }
  12148. +
  12149. +#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  12150. + (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  12151. +
  12152. +#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  12153. +
  12154. +#endif
  12155. diff -Nur linux-4.1.26.orig/include/linux/spinlock_types_rt.h linux-4.1.26/include/linux/spinlock_types_rt.h
  12156. --- linux-4.1.26.orig/include/linux/spinlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  12157. +++ linux-4.1.26/include/linux/spinlock_types_rt.h 2016-06-19 15:30:58.679297041 +0200
  12158. @@ -0,0 +1,51 @@
  12159. +#ifndef __LINUX_SPINLOCK_TYPES_RT_H
  12160. +#define __LINUX_SPINLOCK_TYPES_RT_H
  12161. +
  12162. +#ifndef __LINUX_SPINLOCK_TYPES_H
  12163. +#error "Do not include directly. Include spinlock_types.h instead"
  12164. +#endif
  12165. +
  12166. +#include <linux/cache.h>
  12167. +
  12168. +/*
  12169. + * PREEMPT_RT: spinlocks - an RT mutex plus lock-break field:
  12170. + */
  12171. +typedef struct spinlock {
  12172. + struct rt_mutex lock;
  12173. + unsigned int break_lock;
  12174. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12175. + struct lockdep_map dep_map;
  12176. +#endif
  12177. +} spinlock_t;
  12178. +
  12179. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  12180. +# define __RT_SPIN_INITIALIZER(name) \
  12181. + { \
  12182. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  12183. + .save_state = 1, \
  12184. + .file = __FILE__, \
  12185. + .line = __LINE__ , \
  12186. + }
  12187. +#else
  12188. +# define __RT_SPIN_INITIALIZER(name) \
  12189. + { \
  12190. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  12191. + .save_state = 1, \
  12192. + }
  12193. +#endif
  12194. +
  12195. +/*
  12196. +.wait_list = PLIST_HEAD_INIT_RAW((name).lock.wait_list, (name).lock.wait_lock)
  12197. +*/
  12198. +
  12199. +#define __SPIN_LOCK_UNLOCKED(name) \
  12200. + { .lock = __RT_SPIN_INITIALIZER(name.lock), \
  12201. + SPIN_DEP_MAP_INIT(name) }
  12202. +
  12203. +#define __DEFINE_SPINLOCK(name) \
  12204. + spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
  12205. +
  12206. +#define DEFINE_SPINLOCK(name) \
  12207. + spinlock_t name __cacheline_aligned_in_smp = __SPIN_LOCK_UNLOCKED(name)
  12208. +
  12209. +#endif
  12210. diff -Nur linux-4.1.26.orig/include/linux/srcu.h linux-4.1.26/include/linux/srcu.h
  12211. --- linux-4.1.26.orig/include/linux/srcu.h 2016-06-07 01:13:11.000000000 +0200
  12212. +++ linux-4.1.26/include/linux/srcu.h 2016-06-19 15:30:58.679297041 +0200
  12213. @@ -84,10 +84,10 @@
  12214. void process_srcu(struct work_struct *work);
  12215. -#define __SRCU_STRUCT_INIT(name) \
  12216. +#define __SRCU_STRUCT_INIT(name, pcpu_name) \
  12217. { \
  12218. .completed = -300, \
  12219. - .per_cpu_ref = &name##_srcu_array, \
  12220. + .per_cpu_ref = &pcpu_name, \
  12221. .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
  12222. .running = false, \
  12223. .batch_queue = RCU_BATCH_INIT(name.batch_queue), \
  12224. @@ -104,7 +104,7 @@
  12225. */
  12226. #define __DEFINE_SRCU(name, is_static) \
  12227. static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
  12228. - is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
  12229. + is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_array)
  12230. #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
  12231. #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
  12232. diff -Nur linux-4.1.26.orig/include/linux/swap.h linux-4.1.26/include/linux/swap.h
  12233. --- linux-4.1.26.orig/include/linux/swap.h 2016-06-07 01:13:11.000000000 +0200
  12234. +++ linux-4.1.26/include/linux/swap.h 2016-06-19 15:30:58.679297041 +0200
  12235. @@ -11,6 +11,7 @@
  12236. #include <linux/fs.h>
  12237. #include <linux/atomic.h>
  12238. #include <linux/page-flags.h>
  12239. +#include <linux/locallock.h>
  12240. #include <asm/page.h>
  12241. struct notifier_block;
  12242. @@ -252,7 +253,8 @@
  12243. void *workingset_eviction(struct address_space *mapping, struct page *page);
  12244. bool workingset_refault(void *shadow);
  12245. void workingset_activation(struct page *page);
  12246. -extern struct list_lru workingset_shadow_nodes;
  12247. +extern struct list_lru __workingset_shadow_nodes;
  12248. +DECLARE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  12249. static inline unsigned int workingset_node_pages(struct radix_tree_node *node)
  12250. {
  12251. @@ -296,6 +298,7 @@
  12252. /* linux/mm/swap.c */
  12253. +DECLARE_LOCAL_IRQ_LOCK(swapvec_lock);
  12254. extern void lru_cache_add(struct page *);
  12255. extern void lru_cache_add_anon(struct page *page);
  12256. extern void lru_cache_add_file(struct page *page);
  12257. diff -Nur linux-4.1.26.orig/include/linux/thread_info.h linux-4.1.26/include/linux/thread_info.h
  12258. --- linux-4.1.26.orig/include/linux/thread_info.h 2016-06-07 01:13:11.000000000 +0200
  12259. +++ linux-4.1.26/include/linux/thread_info.h 2016-06-19 15:30:58.679297041 +0200
  12260. @@ -102,7 +102,17 @@
  12261. #define test_thread_flag(flag) \
  12262. test_ti_thread_flag(current_thread_info(), flag)
  12263. -#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  12264. +#ifdef CONFIG_PREEMPT_LAZY
  12265. +#define tif_need_resched() (test_thread_flag(TIF_NEED_RESCHED) || \
  12266. + test_thread_flag(TIF_NEED_RESCHED_LAZY))
  12267. +#define tif_need_resched_now() (test_thread_flag(TIF_NEED_RESCHED))
  12268. +#define tif_need_resched_lazy() test_thread_flag(TIF_NEED_RESCHED_LAZY))
  12269. +
  12270. +#else
  12271. +#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  12272. +#define tif_need_resched_now() test_thread_flag(TIF_NEED_RESCHED)
  12273. +#define tif_need_resched_lazy() 0
  12274. +#endif
  12275. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  12276. /*
  12277. diff -Nur linux-4.1.26.orig/include/linux/timer.h linux-4.1.26/include/linux/timer.h
  12278. --- linux-4.1.26.orig/include/linux/timer.h 2016-06-07 01:13:11.000000000 +0200
  12279. +++ linux-4.1.26/include/linux/timer.h 2016-06-19 15:30:58.679297041 +0200
  12280. @@ -241,7 +241,7 @@
  12281. extern int try_to_del_timer_sync(struct timer_list *timer);
  12282. -#ifdef CONFIG_SMP
  12283. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  12284. extern int del_timer_sync(struct timer_list *timer);
  12285. #else
  12286. # define del_timer_sync(t) del_timer(t)
  12287. diff -Nur linux-4.1.26.orig/include/linux/uaccess.h linux-4.1.26/include/linux/uaccess.h
  12288. --- linux-4.1.26.orig/include/linux/uaccess.h 2016-06-07 01:13:11.000000000 +0200
  12289. +++ linux-4.1.26/include/linux/uaccess.h 2016-06-19 15:30:58.679297041 +0200
  12290. @@ -1,21 +1,31 @@
  12291. #ifndef __LINUX_UACCESS_H__
  12292. #define __LINUX_UACCESS_H__
  12293. -#include <linux/preempt.h>
  12294. +#include <linux/sched.h>
  12295. #include <asm/uaccess.h>
  12296. +static __always_inline void pagefault_disabled_inc(void)
  12297. +{
  12298. + current->pagefault_disabled++;
  12299. +}
  12300. +
  12301. +static __always_inline void pagefault_disabled_dec(void)
  12302. +{
  12303. + current->pagefault_disabled--;
  12304. + WARN_ON(current->pagefault_disabled < 0);
  12305. +}
  12306. +
  12307. /*
  12308. - * These routines enable/disable the pagefault handler in that
  12309. - * it will not take any locks and go straight to the fixup table.
  12310. + * These routines enable/disable the pagefault handler. If disabled, it will
  12311. + * not take any locks and go straight to the fixup table.
  12312. *
  12313. - * They have great resemblance to the preempt_disable/enable calls
  12314. - * and in fact they are identical; this is because currently there is
  12315. - * no other way to make the pagefault handlers do this. So we do
  12316. - * disable preemption but we don't necessarily care about that.
  12317. + * User access methods will not sleep when called from a pagefault_disabled()
  12318. + * environment.
  12319. */
  12320. static inline void pagefault_disable(void)
  12321. {
  12322. - preempt_count_inc();
  12323. + migrate_disable();
  12324. + pagefault_disabled_inc();
  12325. /*
  12326. * make sure to have issued the store before a pagefault
  12327. * can hit.
  12328. @@ -25,18 +35,32 @@
  12329. static inline void pagefault_enable(void)
  12330. {
  12331. -#ifndef CONFIG_PREEMPT
  12332. /*
  12333. * make sure to issue those last loads/stores before enabling
  12334. * the pagefault handler again.
  12335. */
  12336. barrier();
  12337. - preempt_count_dec();
  12338. -#else
  12339. - preempt_enable();
  12340. -#endif
  12341. + pagefault_disabled_dec();
  12342. + migrate_enable();
  12343. }
  12344. +/*
  12345. + * Is the pagefault handler disabled? If so, user access methods will not sleep.
  12346. + */
  12347. +#define pagefault_disabled() (current->pagefault_disabled != 0)
  12348. +
  12349. +/*
  12350. + * The pagefault handler is in general disabled by pagefault_disable() or
  12351. + * when in irq context (via in_atomic()).
  12352. + *
  12353. + * This function should only be used by the fault handlers. Other users should
  12354. + * stick to pagefault_disabled().
  12355. + * Please NEVER use preempt_disable() to disable the fault handler. With
  12356. + * !CONFIG_PREEMPT_COUNT, this is like a NOP. So the handler won't be disabled.
  12357. + * in_atomic() will report different values based on !CONFIG_PREEMPT_COUNT.
  12358. + */
  12359. +#define faulthandler_disabled() (pagefault_disabled() || in_atomic())
  12360. +
  12361. #ifndef ARCH_HAS_NOCACHE_UACCESS
  12362. static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
  12363. diff -Nur linux-4.1.26.orig/include/linux/uprobes.h linux-4.1.26/include/linux/uprobes.h
  12364. --- linux-4.1.26.orig/include/linux/uprobes.h 2016-06-07 01:13:11.000000000 +0200
  12365. +++ linux-4.1.26/include/linux/uprobes.h 2016-06-19 15:30:58.679297041 +0200
  12366. @@ -27,6 +27,7 @@
  12367. #include <linux/errno.h>
  12368. #include <linux/rbtree.h>
  12369. #include <linux/types.h>
  12370. +#include <linux/wait.h>
  12371. struct vm_area_struct;
  12372. struct mm_struct;
  12373. diff -Nur linux-4.1.26.orig/include/linux/vmstat.h linux-4.1.26/include/linux/vmstat.h
  12374. --- linux-4.1.26.orig/include/linux/vmstat.h 2016-06-07 01:13:11.000000000 +0200
  12375. +++ linux-4.1.26/include/linux/vmstat.h 2016-06-19 15:30:58.679297041 +0200
  12376. @@ -33,7 +33,9 @@
  12377. */
  12378. static inline void __count_vm_event(enum vm_event_item item)
  12379. {
  12380. + preempt_disable_rt();
  12381. raw_cpu_inc(vm_event_states.event[item]);
  12382. + preempt_enable_rt();
  12383. }
  12384. static inline void count_vm_event(enum vm_event_item item)
  12385. @@ -43,7 +45,9 @@
  12386. static inline void __count_vm_events(enum vm_event_item item, long delta)
  12387. {
  12388. + preempt_disable_rt();
  12389. raw_cpu_add(vm_event_states.event[item], delta);
  12390. + preempt_enable_rt();
  12391. }
  12392. static inline void count_vm_events(enum vm_event_item item, long delta)
  12393. diff -Nur linux-4.1.26.orig/include/linux/wait.h linux-4.1.26/include/linux/wait.h
  12394. --- linux-4.1.26.orig/include/linux/wait.h 2016-06-07 01:13:11.000000000 +0200
  12395. +++ linux-4.1.26/include/linux/wait.h 2016-06-19 15:30:58.679297041 +0200
  12396. @@ -8,6 +8,7 @@
  12397. #include <linux/spinlock.h>
  12398. #include <asm/current.h>
  12399. #include <uapi/linux/wait.h>
  12400. +#include <linux/atomic.h>
  12401. typedef struct __wait_queue wait_queue_t;
  12402. typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
  12403. diff -Nur linux-4.1.26.orig/include/linux/wait-simple.h linux-4.1.26/include/linux/wait-simple.h
  12404. --- linux-4.1.26.orig/include/linux/wait-simple.h 1970-01-01 01:00:00.000000000 +0100
  12405. +++ linux-4.1.26/include/linux/wait-simple.h 2016-06-19 15:30:58.679297041 +0200
  12406. @@ -0,0 +1,207 @@
  12407. +#ifndef _LINUX_WAIT_SIMPLE_H
  12408. +#define _LINUX_WAIT_SIMPLE_H
  12409. +
  12410. +#include <linux/spinlock.h>
  12411. +#include <linux/list.h>
  12412. +
  12413. +#include <asm/current.h>
  12414. +
  12415. +struct swaiter {
  12416. + struct task_struct *task;
  12417. + struct list_head node;
  12418. +};
  12419. +
  12420. +#define DEFINE_SWAITER(name) \
  12421. + struct swaiter name = { \
  12422. + .task = current, \
  12423. + .node = LIST_HEAD_INIT((name).node), \
  12424. + }
  12425. +
  12426. +struct swait_head {
  12427. + raw_spinlock_t lock;
  12428. + struct list_head list;
  12429. +};
  12430. +
  12431. +#define SWAIT_HEAD_INITIALIZER(name) { \
  12432. + .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
  12433. + .list = LIST_HEAD_INIT((name).list), \
  12434. + }
  12435. +
  12436. +#define DEFINE_SWAIT_HEAD(name) \
  12437. + struct swait_head name = SWAIT_HEAD_INITIALIZER(name)
  12438. +
  12439. +extern void __init_swait_head(struct swait_head *h, struct lock_class_key *key);
  12440. +
  12441. +#define init_swait_head(swh) \
  12442. + do { \
  12443. + static struct lock_class_key __key; \
  12444. + \
  12445. + __init_swait_head((swh), &__key); \
  12446. + } while (0)
  12447. +
  12448. +/*
  12449. + * Waiter functions
  12450. + */
  12451. +extern void swait_prepare_locked(struct swait_head *head, struct swaiter *w);
  12452. +extern void swait_prepare(struct swait_head *head, struct swaiter *w, int state);
  12453. +extern void swait_finish_locked(struct swait_head *head, struct swaiter *w);
  12454. +extern void swait_finish(struct swait_head *head, struct swaiter *w);
  12455. +
  12456. +/* Check whether a head has waiters enqueued */
  12457. +static inline bool swaitqueue_active(struct swait_head *h)
  12458. +{
  12459. + /* Make sure the condition is visible before checking list_empty() */
  12460. + smp_mb();
  12461. + return !list_empty(&h->list);
  12462. +}
  12463. +
  12464. +/*
  12465. + * Wakeup functions
  12466. + */
  12467. +extern unsigned int __swait_wake(struct swait_head *head, unsigned int state, unsigned int num);
  12468. +extern unsigned int __swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num);
  12469. +
  12470. +#define swait_wake(head) __swait_wake(head, TASK_NORMAL, 1)
  12471. +#define swait_wake_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 1)
  12472. +#define swait_wake_all(head) __swait_wake(head, TASK_NORMAL, 0)
  12473. +#define swait_wake_all_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 0)
  12474. +
  12475. +/*
  12476. + * Event API
  12477. + */
  12478. +#define __swait_event(wq, condition) \
  12479. +do { \
  12480. + DEFINE_SWAITER(__wait); \
  12481. + \
  12482. + for (;;) { \
  12483. + swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
  12484. + if (condition) \
  12485. + break; \
  12486. + schedule(); \
  12487. + } \
  12488. + swait_finish(&wq, &__wait); \
  12489. +} while (0)
  12490. +
  12491. +/**
  12492. + * swait_event - sleep until a condition gets true
  12493. + * @wq: the waitqueue to wait on
  12494. + * @condition: a C expression for the event to wait for
  12495. + *
  12496. + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  12497. + * @condition evaluates to true. The @condition is checked each time
  12498. + * the waitqueue @wq is woken up.
  12499. + *
  12500. + * wake_up() has to be called after changing any variable that could
  12501. + * change the result of the wait condition.
  12502. + */
  12503. +#define swait_event(wq, condition) \
  12504. +do { \
  12505. + if (condition) \
  12506. + break; \
  12507. + __swait_event(wq, condition); \
  12508. +} while (0)
  12509. +
  12510. +#define __swait_event_interruptible(wq, condition, ret) \
  12511. +do { \
  12512. + DEFINE_SWAITER(__wait); \
  12513. + \
  12514. + for (;;) { \
  12515. + swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
  12516. + if (condition) \
  12517. + break; \
  12518. + if (signal_pending(current)) { \
  12519. + ret = -ERESTARTSYS; \
  12520. + break; \
  12521. + } \
  12522. + schedule(); \
  12523. + } \
  12524. + swait_finish(&wq, &__wait); \
  12525. +} while (0)
  12526. +
  12527. +#define __swait_event_interruptible_timeout(wq, condition, ret) \
  12528. +do { \
  12529. + DEFINE_SWAITER(__wait); \
  12530. + \
  12531. + for (;;) { \
  12532. + swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
  12533. + if (condition) \
  12534. + break; \
  12535. + if (signal_pending(current)) { \
  12536. + ret = -ERESTARTSYS; \
  12537. + break; \
  12538. + } \
  12539. + ret = schedule_timeout(ret); \
  12540. + if (!ret) \
  12541. + break; \
  12542. + } \
  12543. + swait_finish(&wq, &__wait); \
  12544. +} while (0)
  12545. +
  12546. +/**
  12547. + * swait_event_interruptible - sleep until a condition gets true
  12548. + * @wq: the waitqueue to wait on
  12549. + * @condition: a C expression for the event to wait for
  12550. + *
  12551. + * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  12552. + * @condition evaluates to true. The @condition is checked each time
  12553. + * the waitqueue @wq is woken up.
  12554. + *
  12555. + * wake_up() has to be called after changing any variable that could
  12556. + * change the result of the wait condition.
  12557. + */
  12558. +#define swait_event_interruptible(wq, condition) \
  12559. +({ \
  12560. + int __ret = 0; \
  12561. + if (!(condition)) \
  12562. + __swait_event_interruptible(wq, condition, __ret); \
  12563. + __ret; \
  12564. +})
  12565. +
  12566. +#define swait_event_interruptible_timeout(wq, condition, timeout) \
  12567. +({ \
  12568. + int __ret = timeout; \
  12569. + if (!(condition)) \
  12570. + __swait_event_interruptible_timeout(wq, condition, __ret); \
  12571. + __ret; \
  12572. +})
  12573. +
  12574. +#define __swait_event_timeout(wq, condition, ret) \
  12575. +do { \
  12576. + DEFINE_SWAITER(__wait); \
  12577. + \
  12578. + for (;;) { \
  12579. + swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
  12580. + if (condition) \
  12581. + break; \
  12582. + ret = schedule_timeout(ret); \
  12583. + if (!ret) \
  12584. + break; \
  12585. + } \
  12586. + swait_finish(&wq, &__wait); \
  12587. +} while (0)
  12588. +
  12589. +/**
  12590. + * swait_event_timeout - sleep until a condition gets true or a timeout elapses
  12591. + * @wq: the waitqueue to wait on
  12592. + * @condition: a C expression for the event to wait for
  12593. + * @timeout: timeout, in jiffies
  12594. + *
  12595. + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  12596. + * @condition evaluates to true. The @condition is checked each time
  12597. + * the waitqueue @wq is woken up.
  12598. + *
  12599. + * wake_up() has to be called after changing any variable that could
  12600. + * change the result of the wait condition.
  12601. + *
  12602. + * The function returns 0 if the @timeout elapsed, and the remaining
  12603. + * jiffies if the condition evaluated to true before the timeout elapsed.
  12604. + */
  12605. +#define swait_event_timeout(wq, condition, timeout) \
  12606. +({ \
  12607. + long __ret = timeout; \
  12608. + if (!(condition)) \
  12609. + __swait_event_timeout(wq, condition, __ret); \
  12610. + __ret; \
  12611. +})
  12612. +
  12613. +#endif
  12614. diff -Nur linux-4.1.26.orig/include/linux/work-simple.h linux-4.1.26/include/linux/work-simple.h
  12615. --- linux-4.1.26.orig/include/linux/work-simple.h 1970-01-01 01:00:00.000000000 +0100
  12616. +++ linux-4.1.26/include/linux/work-simple.h 2016-06-19 15:30:58.679297041 +0200
  12617. @@ -0,0 +1,24 @@
  12618. +#ifndef _LINUX_SWORK_H
  12619. +#define _LINUX_SWORK_H
  12620. +
  12621. +#include <linux/list.h>
  12622. +
  12623. +struct swork_event {
  12624. + struct list_head item;
  12625. + unsigned long flags;
  12626. + void (*func)(struct swork_event *);
  12627. +};
  12628. +
  12629. +static inline void INIT_SWORK(struct swork_event *event,
  12630. + void (*func)(struct swork_event *))
  12631. +{
  12632. + event->flags = 0;
  12633. + event->func = func;
  12634. +}
  12635. +
  12636. +bool swork_queue(struct swork_event *sev);
  12637. +
  12638. +int swork_get(void);
  12639. +void swork_put(void);
  12640. +
  12641. +#endif /* _LINUX_SWORK_H */
  12642. diff -Nur linux-4.1.26.orig/include/net/dst.h linux-4.1.26/include/net/dst.h
  12643. --- linux-4.1.26.orig/include/net/dst.h 2016-06-07 01:13:11.000000000 +0200
  12644. +++ linux-4.1.26/include/net/dst.h 2016-06-19 15:30:58.679297041 +0200
  12645. @@ -436,7 +436,7 @@
  12646. static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
  12647. struct sk_buff *skb)
  12648. {
  12649. - const struct hh_cache *hh;
  12650. + struct hh_cache *hh;
  12651. if (dst->pending_confirm) {
  12652. unsigned long now = jiffies;
  12653. diff -Nur linux-4.1.26.orig/include/net/neighbour.h linux-4.1.26/include/net/neighbour.h
  12654. --- linux-4.1.26.orig/include/net/neighbour.h 2016-06-07 01:13:11.000000000 +0200
  12655. +++ linux-4.1.26/include/net/neighbour.h 2016-06-19 15:30:58.679297041 +0200
  12656. @@ -445,7 +445,7 @@
  12657. }
  12658. #endif
  12659. -static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  12660. +static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
  12661. {
  12662. unsigned int seq;
  12663. int hh_len;
  12664. @@ -500,7 +500,7 @@
  12665. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  12666. -static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  12667. +static inline void neigh_ha_snapshot(char *dst, struct neighbour *n,
  12668. const struct net_device *dev)
  12669. {
  12670. unsigned int seq;
  12671. diff -Nur linux-4.1.26.orig/include/net/netns/ipv4.h linux-4.1.26/include/net/netns/ipv4.h
  12672. --- linux-4.1.26.orig/include/net/netns/ipv4.h 2016-06-07 01:13:11.000000000 +0200
  12673. +++ linux-4.1.26/include/net/netns/ipv4.h 2016-06-19 15:30:58.683297195 +0200
  12674. @@ -69,6 +69,7 @@
  12675. int sysctl_icmp_echo_ignore_all;
  12676. int sysctl_icmp_echo_ignore_broadcasts;
  12677. + int sysctl_icmp_echo_sysrq;
  12678. int sysctl_icmp_ignore_bogus_error_responses;
  12679. int sysctl_icmp_ratelimit;
  12680. int sysctl_icmp_ratemask;
  12681. diff -Nur linux-4.1.26.orig/include/trace/events/hist.h linux-4.1.26/include/trace/events/hist.h
  12682. --- linux-4.1.26.orig/include/trace/events/hist.h 1970-01-01 01:00:00.000000000 +0100
  12683. +++ linux-4.1.26/include/trace/events/hist.h 2016-06-19 15:30:58.683297195 +0200
  12684. @@ -0,0 +1,74 @@
  12685. +#undef TRACE_SYSTEM
  12686. +#define TRACE_SYSTEM hist
  12687. +
  12688. +#if !defined(_TRACE_HIST_H) || defined(TRACE_HEADER_MULTI_READ)
  12689. +#define _TRACE_HIST_H
  12690. +
  12691. +#include "latency_hist.h"
  12692. +#include <linux/tracepoint.h>
  12693. +
  12694. +#if !defined(CONFIG_PREEMPT_OFF_HIST) && !defined(CONFIG_INTERRUPT_OFF_HIST)
  12695. +#define trace_preemptirqsoff_hist(a, b)
  12696. +#define trace_preemptirqsoff_hist_rcuidle(a, b)
  12697. +#else
  12698. +TRACE_EVENT(preemptirqsoff_hist,
  12699. +
  12700. + TP_PROTO(int reason, int starthist),
  12701. +
  12702. + TP_ARGS(reason, starthist),
  12703. +
  12704. + TP_STRUCT__entry(
  12705. + __field(int, reason)
  12706. + __field(int, starthist)
  12707. + ),
  12708. +
  12709. + TP_fast_assign(
  12710. + __entry->reason = reason;
  12711. + __entry->starthist = starthist;
  12712. + ),
  12713. +
  12714. + TP_printk("reason=%s starthist=%s", getaction(__entry->reason),
  12715. + __entry->starthist ? "start" : "stop")
  12716. +);
  12717. +#endif
  12718. +
  12719. +#ifndef CONFIG_MISSED_TIMER_OFFSETS_HIST
  12720. +#define trace_hrtimer_interrupt(a, b, c, d)
  12721. +#define trace_hrtimer_interrupt_rcuidle(a, b, c, d)
  12722. +#else
  12723. +TRACE_EVENT(hrtimer_interrupt,
  12724. +
  12725. + TP_PROTO(int cpu, long long offset, struct task_struct *curr,
  12726. + struct task_struct *task),
  12727. +
  12728. + TP_ARGS(cpu, offset, curr, task),
  12729. +
  12730. + TP_STRUCT__entry(
  12731. + __field(int, cpu)
  12732. + __field(long long, offset)
  12733. + __array(char, ccomm, TASK_COMM_LEN)
  12734. + __field(int, cprio)
  12735. + __array(char, tcomm, TASK_COMM_LEN)
  12736. + __field(int, tprio)
  12737. + ),
  12738. +
  12739. + TP_fast_assign(
  12740. + __entry->cpu = cpu;
  12741. + __entry->offset = offset;
  12742. + memcpy(__entry->ccomm, curr->comm, TASK_COMM_LEN);
  12743. + __entry->cprio = curr->prio;
  12744. + memcpy(__entry->tcomm, task != NULL ? task->comm : "<none>",
  12745. + task != NULL ? TASK_COMM_LEN : 7);
  12746. + __entry->tprio = task != NULL ? task->prio : -1;
  12747. + ),
  12748. +
  12749. + TP_printk("cpu=%d offset=%lld curr=%s[%d] thread=%s[%d]",
  12750. + __entry->cpu, __entry->offset, __entry->ccomm,
  12751. + __entry->cprio, __entry->tcomm, __entry->tprio)
  12752. +);
  12753. +#endif
  12754. +
  12755. +#endif /* _TRACE_HIST_H */
  12756. +
  12757. +/* This part must be outside protection */
  12758. +#include <trace/define_trace.h>
  12759. diff -Nur linux-4.1.26.orig/include/trace/events/latency_hist.h linux-4.1.26/include/trace/events/latency_hist.h
  12760. --- linux-4.1.26.orig/include/trace/events/latency_hist.h 1970-01-01 01:00:00.000000000 +0100
  12761. +++ linux-4.1.26/include/trace/events/latency_hist.h 2016-06-19 15:30:58.683297195 +0200
  12762. @@ -0,0 +1,29 @@
  12763. +#ifndef _LATENCY_HIST_H
  12764. +#define _LATENCY_HIST_H
  12765. +
  12766. +enum hist_action {
  12767. + IRQS_ON,
  12768. + PREEMPT_ON,
  12769. + TRACE_STOP,
  12770. + IRQS_OFF,
  12771. + PREEMPT_OFF,
  12772. + TRACE_START,
  12773. +};
  12774. +
  12775. +static char *actions[] = {
  12776. + "IRQS_ON",
  12777. + "PREEMPT_ON",
  12778. + "TRACE_STOP",
  12779. + "IRQS_OFF",
  12780. + "PREEMPT_OFF",
  12781. + "TRACE_START",
  12782. +};
  12783. +
  12784. +static inline char *getaction(int action)
  12785. +{
  12786. + if (action >= 0 && action <= sizeof(actions)/sizeof(actions[0]))
  12787. + return actions[action];
  12788. + return "unknown";
  12789. +}
  12790. +
  12791. +#endif /* _LATENCY_HIST_H */
  12792. diff -Nur linux-4.1.26.orig/include/trace/events/sched.h linux-4.1.26/include/trace/events/sched.h
  12793. --- linux-4.1.26.orig/include/trace/events/sched.h 2016-06-07 01:13:11.000000000 +0200
  12794. +++ linux-4.1.26/include/trace/events/sched.h 2016-06-19 15:30:58.683297195 +0200
  12795. @@ -55,9 +55,9 @@
  12796. */
  12797. DECLARE_EVENT_CLASS(sched_wakeup_template,
  12798. - TP_PROTO(struct task_struct *p, int success),
  12799. + TP_PROTO(struct task_struct *p),
  12800. - TP_ARGS(__perf_task(p), success),
  12801. + TP_ARGS(__perf_task(p)),
  12802. TP_STRUCT__entry(
  12803. __array( char, comm, TASK_COMM_LEN )
  12804. @@ -71,25 +71,37 @@
  12805. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  12806. __entry->pid = p->pid;
  12807. __entry->prio = p->prio;
  12808. - __entry->success = success;
  12809. + __entry->success = 1; /* rudiment, kill when possible */
  12810. __entry->target_cpu = task_cpu(p);
  12811. ),
  12812. - TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
  12813. + TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
  12814. __entry->comm, __entry->pid, __entry->prio,
  12815. - __entry->success, __entry->target_cpu)
  12816. + __entry->target_cpu)
  12817. );
  12818. +/*
  12819. + * Tracepoint called when waking a task; this tracepoint is guaranteed to be
  12820. + * called from the waking context.
  12821. + */
  12822. +DEFINE_EVENT(sched_wakeup_template, sched_waking,
  12823. + TP_PROTO(struct task_struct *p),
  12824. + TP_ARGS(p));
  12825. +
  12826. +/*
  12827. + * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
  12828. + * It it not always called from the waking context.
  12829. + */
  12830. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  12831. - TP_PROTO(struct task_struct *p, int success),
  12832. - TP_ARGS(p, success));
  12833. + TP_PROTO(struct task_struct *p),
  12834. + TP_ARGS(p));
  12835. /*
  12836. * Tracepoint for waking up a new task:
  12837. */
  12838. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  12839. - TP_PROTO(struct task_struct *p, int success),
  12840. - TP_ARGS(p, success));
  12841. + TP_PROTO(struct task_struct *p),
  12842. + TP_ARGS(p));
  12843. #ifdef CREATE_TRACE_POINTS
  12844. static inline long __trace_sched_switch_state(struct task_struct *p)
  12845. diff -Nur linux-4.1.26.orig/init/Kconfig linux-4.1.26/init/Kconfig
  12846. --- linux-4.1.26.orig/init/Kconfig 2016-06-07 01:13:11.000000000 +0200
  12847. +++ linux-4.1.26/init/Kconfig 2016-06-19 15:30:58.683297195 +0200
  12848. @@ -637,7 +637,7 @@
  12849. config RCU_FAST_NO_HZ
  12850. bool "Accelerate last non-dyntick-idle CPU's grace periods"
  12851. - depends on NO_HZ_COMMON && SMP
  12852. + depends on NO_HZ_COMMON && SMP && !PREEMPT_RT_FULL
  12853. default n
  12854. help
  12855. This option permits CPUs to enter dynticks-idle state even if
  12856. @@ -664,7 +664,7 @@
  12857. config RCU_BOOST
  12858. bool "Enable RCU priority boosting"
  12859. depends on RT_MUTEXES && PREEMPT_RCU
  12860. - default n
  12861. + default y if PREEMPT_RT_FULL
  12862. help
  12863. This option boosts the priority of preempted RCU readers that
  12864. block the current preemptible RCU grace period for too long.
  12865. @@ -1101,6 +1101,7 @@
  12866. config RT_GROUP_SCHED
  12867. bool "Group scheduling for SCHED_RR/FIFO"
  12868. depends on CGROUP_SCHED
  12869. + depends on !PREEMPT_RT_FULL
  12870. default n
  12871. help
  12872. This feature lets you explicitly allocate real CPU bandwidth
  12873. @@ -1688,6 +1689,7 @@
  12874. config SLAB
  12875. bool "SLAB"
  12876. + depends on !PREEMPT_RT_FULL
  12877. help
  12878. The regular slab allocator that is established and known to work
  12879. well in all environments. It organizes cache hot objects in
  12880. @@ -1706,6 +1708,7 @@
  12881. config SLOB
  12882. depends on EXPERT
  12883. bool "SLOB (Simple Allocator)"
  12884. + depends on !PREEMPT_RT_FULL
  12885. help
  12886. SLOB replaces the stock allocator with a drastically simpler
  12887. allocator. SLOB is generally more space efficient but
  12888. @@ -1715,7 +1718,7 @@
  12889. config SLUB_CPU_PARTIAL
  12890. default y
  12891. - depends on SLUB && SMP
  12892. + depends on SLUB && SMP && !PREEMPT_RT_FULL
  12893. bool "SLUB per cpu partial cache"
  12894. help
  12895. Per cpu partial caches accellerate objects allocation and freeing
  12896. diff -Nur linux-4.1.26.orig/init/main.c linux-4.1.26/init/main.c
  12897. --- linux-4.1.26.orig/init/main.c 2016-06-07 01:13:11.000000000 +0200
  12898. +++ linux-4.1.26/init/main.c 2016-06-19 15:30:58.683297195 +0200
  12899. @@ -525,6 +525,7 @@
  12900. setup_command_line(command_line);
  12901. setup_nr_cpu_ids();
  12902. setup_per_cpu_areas();
  12903. + softirq_early_init();
  12904. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  12905. build_all_zonelists(NULL, NULL);
  12906. diff -Nur linux-4.1.26.orig/init/Makefile linux-4.1.26/init/Makefile
  12907. --- linux-4.1.26.orig/init/Makefile 2016-06-07 01:13:11.000000000 +0200
  12908. +++ linux-4.1.26/init/Makefile 2016-06-19 15:30:58.683297195 +0200
  12909. @@ -33,4 +33,4 @@
  12910. include/generated/compile.h: FORCE
  12911. @$($(quiet)chk_compile.h)
  12912. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
  12913. - "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)"
  12914. + "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CONFIG_PREEMPT_RT_FULL)" "$(CC) $(KBUILD_CFLAGS)"
  12915. diff -Nur linux-4.1.26.orig/ipc/mqueue.c linux-4.1.26/ipc/mqueue.c
  12916. --- linux-4.1.26.orig/ipc/mqueue.c 2016-06-07 01:13:11.000000000 +0200
  12917. +++ linux-4.1.26/ipc/mqueue.c 2016-06-19 15:30:58.683297195 +0200
  12918. @@ -47,8 +47,7 @@
  12919. #define RECV 1
  12920. #define STATE_NONE 0
  12921. -#define STATE_PENDING 1
  12922. -#define STATE_READY 2
  12923. +#define STATE_READY 1
  12924. struct posix_msg_tree_node {
  12925. struct rb_node rb_node;
  12926. @@ -568,15 +567,12 @@
  12927. wq_add(info, sr, ewp);
  12928. for (;;) {
  12929. - set_current_state(TASK_INTERRUPTIBLE);
  12930. + __set_current_state(TASK_INTERRUPTIBLE);
  12931. spin_unlock(&info->lock);
  12932. time = schedule_hrtimeout_range_clock(timeout, 0,
  12933. HRTIMER_MODE_ABS, CLOCK_REALTIME);
  12934. - while (ewp->state == STATE_PENDING)
  12935. - cpu_relax();
  12936. -
  12937. if (ewp->state == STATE_READY) {
  12938. retval = 0;
  12939. goto out;
  12940. @@ -904,11 +900,15 @@
  12941. * list of waiting receivers. A sender checks that list before adding the new
  12942. * message into the message array. If there is a waiting receiver, then it
  12943. * bypasses the message array and directly hands the message over to the
  12944. - * receiver.
  12945. - * The receiver accepts the message and returns without grabbing the queue
  12946. - * spinlock. Therefore an intermediate STATE_PENDING state and memory barriers
  12947. - * are necessary. The same algorithm is used for sysv semaphores, see
  12948. - * ipc/sem.c for more details.
  12949. + * receiver. The receiver accepts the message and returns without grabbing the
  12950. + * queue spinlock:
  12951. + *
  12952. + * - Set pointer to message.
  12953. + * - Queue the receiver task for later wakeup (without the info->lock).
  12954. + * - Update its state to STATE_READY. Now the receiver can continue.
  12955. + * - Wake up the process after the lock is dropped. Should the process wake up
  12956. + * before this wakeup (due to a timeout or a signal) it will either see
  12957. + * STATE_READY and continue or acquire the lock to check the state again.
  12958. *
  12959. * The same algorithm is used for senders.
  12960. */
  12961. @@ -916,21 +916,29 @@
  12962. /* pipelined_send() - send a message directly to the task waiting in
  12963. * sys_mq_timedreceive() (without inserting message into a queue).
  12964. */
  12965. -static inline void pipelined_send(struct mqueue_inode_info *info,
  12966. +static inline void pipelined_send(struct wake_q_head *wake_q,
  12967. + struct mqueue_inode_info *info,
  12968. struct msg_msg *message,
  12969. struct ext_wait_queue *receiver)
  12970. {
  12971. receiver->msg = message;
  12972. list_del(&receiver->list);
  12973. - receiver->state = STATE_PENDING;
  12974. - wake_up_process(receiver->task);
  12975. - smp_wmb();
  12976. + wake_q_add(wake_q, receiver->task);
  12977. + /*
  12978. + * Rely on the implicit cmpxchg barrier from wake_q_add such
  12979. + * that we can ensure that updating receiver->state is the last
  12980. + * write operation: As once set, the receiver can continue,
  12981. + * and if we don't have the reference count from the wake_q,
  12982. + * yet, at that point we can later have a use-after-free
  12983. + * condition and bogus wakeup.
  12984. + */
  12985. receiver->state = STATE_READY;
  12986. }
  12987. /* pipelined_receive() - if there is task waiting in sys_mq_timedsend()
  12988. * gets its message and put to the queue (we have one free place for sure). */
  12989. -static inline void pipelined_receive(struct mqueue_inode_info *info)
  12990. +static inline void pipelined_receive(struct wake_q_head *wake_q,
  12991. + struct mqueue_inode_info *info)
  12992. {
  12993. struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
  12994. @@ -941,10 +949,9 @@
  12995. }
  12996. if (msg_insert(sender->msg, info))
  12997. return;
  12998. +
  12999. list_del(&sender->list);
  13000. - sender->state = STATE_PENDING;
  13001. - wake_up_process(sender->task);
  13002. - smp_wmb();
  13003. + wake_q_add(wake_q, sender->task);
  13004. sender->state = STATE_READY;
  13005. }
  13006. @@ -962,6 +969,7 @@
  13007. struct timespec ts;
  13008. struct posix_msg_tree_node *new_leaf = NULL;
  13009. int ret = 0;
  13010. + WAKE_Q(wake_q);
  13011. if (u_abs_timeout) {
  13012. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  13013. @@ -1045,7 +1053,7 @@
  13014. } else {
  13015. receiver = wq_get_first_waiter(info, RECV);
  13016. if (receiver) {
  13017. - pipelined_send(info, msg_ptr, receiver);
  13018. + pipelined_send(&wake_q, info, msg_ptr, receiver);
  13019. } else {
  13020. /* adds message to the queue */
  13021. ret = msg_insert(msg_ptr, info);
  13022. @@ -1058,6 +1066,7 @@
  13023. }
  13024. out_unlock:
  13025. spin_unlock(&info->lock);
  13026. + wake_up_q(&wake_q);
  13027. out_free:
  13028. if (ret)
  13029. free_msg(msg_ptr);
  13030. @@ -1144,14 +1153,17 @@
  13031. msg_ptr = wait.msg;
  13032. }
  13033. } else {
  13034. + WAKE_Q(wake_q);
  13035. +
  13036. msg_ptr = msg_get(info);
  13037. inode->i_atime = inode->i_mtime = inode->i_ctime =
  13038. CURRENT_TIME;
  13039. /* There is now free space in queue. */
  13040. - pipelined_receive(info);
  13041. + pipelined_receive(&wake_q, info);
  13042. spin_unlock(&info->lock);
  13043. + wake_up_q(&wake_q);
  13044. ret = 0;
  13045. }
  13046. if (ret == 0) {
  13047. diff -Nur linux-4.1.26.orig/ipc/msg.c linux-4.1.26/ipc/msg.c
  13048. --- linux-4.1.26.orig/ipc/msg.c 2016-06-07 01:13:11.000000000 +0200
  13049. +++ linux-4.1.26/ipc/msg.c 2016-06-19 15:30:58.683297195 +0200
  13050. @@ -188,6 +188,12 @@
  13051. struct msg_receiver *msr, *t;
  13052. list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
  13053. + /*
  13054. + * Make sure that the wakeup doesnt preempt
  13055. + * this CPU prematurely. (on PREEMPT_RT)
  13056. + */
  13057. + preempt_disable_rt();
  13058. +
  13059. msr->r_msg = NULL; /* initialize expunge ordering */
  13060. wake_up_process(msr->r_tsk);
  13061. /*
  13062. @@ -198,6 +204,8 @@
  13063. */
  13064. smp_mb();
  13065. msr->r_msg = ERR_PTR(res);
  13066. +
  13067. + preempt_enable_rt();
  13068. }
  13069. }
  13070. @@ -574,6 +582,11 @@
  13071. if (testmsg(msg, msr->r_msgtype, msr->r_mode) &&
  13072. !security_msg_queue_msgrcv(msq, msg, msr->r_tsk,
  13073. msr->r_msgtype, msr->r_mode)) {
  13074. + /*
  13075. + * Make sure that the wakeup doesnt preempt
  13076. + * this CPU prematurely. (on PREEMPT_RT)
  13077. + */
  13078. + preempt_disable_rt();
  13079. list_del(&msr->r_list);
  13080. if (msr->r_maxsize < msg->m_ts) {
  13081. @@ -595,12 +608,13 @@
  13082. */
  13083. smp_mb();
  13084. msr->r_msg = msg;
  13085. + preempt_enable_rt();
  13086. return 1;
  13087. }
  13088. + preempt_enable_rt();
  13089. }
  13090. }
  13091. -
  13092. return 0;
  13093. }
  13094. diff -Nur linux-4.1.26.orig/ipc/sem.c linux-4.1.26/ipc/sem.c
  13095. --- linux-4.1.26.orig/ipc/sem.c 2016-06-07 01:13:11.000000000 +0200
  13096. +++ linux-4.1.26/ipc/sem.c 2016-06-19 15:30:58.683297195 +0200
  13097. @@ -690,6 +690,13 @@
  13098. static void wake_up_sem_queue_prepare(struct list_head *pt,
  13099. struct sem_queue *q, int error)
  13100. {
  13101. +#ifdef CONFIG_PREEMPT_RT_BASE
  13102. + struct task_struct *p = q->sleeper;
  13103. + get_task_struct(p);
  13104. + q->status = error;
  13105. + wake_up_process(p);
  13106. + put_task_struct(p);
  13107. +#else
  13108. if (list_empty(pt)) {
  13109. /*
  13110. * Hold preempt off so that we don't get preempted and have the
  13111. @@ -701,6 +708,7 @@
  13112. q->pid = error;
  13113. list_add_tail(&q->list, pt);
  13114. +#endif
  13115. }
  13116. /**
  13117. @@ -714,6 +722,7 @@
  13118. */
  13119. static void wake_up_sem_queue_do(struct list_head *pt)
  13120. {
  13121. +#ifndef CONFIG_PREEMPT_RT_BASE
  13122. struct sem_queue *q, *t;
  13123. int did_something;
  13124. @@ -726,6 +735,7 @@
  13125. }
  13126. if (did_something)
  13127. preempt_enable();
  13128. +#endif
  13129. }
  13130. static void unlink_queue(struct sem_array *sma, struct sem_queue *q)
  13131. diff -Nur linux-4.1.26.orig/kernel/bpf/hashtab.c linux-4.1.26/kernel/bpf/hashtab.c
  13132. --- linux-4.1.26.orig/kernel/bpf/hashtab.c 2016-06-07 01:13:11.000000000 +0200
  13133. +++ linux-4.1.26/kernel/bpf/hashtab.c 2016-06-19 15:30:58.683297195 +0200
  13134. @@ -17,7 +17,7 @@
  13135. struct bpf_htab {
  13136. struct bpf_map map;
  13137. struct hlist_head *buckets;
  13138. - spinlock_t lock;
  13139. + raw_spinlock_t lock;
  13140. u32 count; /* number of elements in this hashtable */
  13141. u32 n_buckets; /* number of hash buckets */
  13142. u32 elem_size; /* size of each element in bytes */
  13143. @@ -82,7 +82,7 @@
  13144. for (i = 0; i < htab->n_buckets; i++)
  13145. INIT_HLIST_HEAD(&htab->buckets[i]);
  13146. - spin_lock_init(&htab->lock);
  13147. + raw_spin_lock_init(&htab->lock);
  13148. htab->count = 0;
  13149. htab->elem_size = sizeof(struct htab_elem) +
  13150. @@ -230,7 +230,7 @@
  13151. l_new->hash = htab_map_hash(l_new->key, key_size);
  13152. /* bpf_map_update_elem() can be called in_irq() */
  13153. - spin_lock_irqsave(&htab->lock, flags);
  13154. + raw_spin_lock_irqsave(&htab->lock, flags);
  13155. head = select_bucket(htab, l_new->hash);
  13156. @@ -266,11 +266,11 @@
  13157. } else {
  13158. htab->count++;
  13159. }
  13160. - spin_unlock_irqrestore(&htab->lock, flags);
  13161. + raw_spin_unlock_irqrestore(&htab->lock, flags);
  13162. return 0;
  13163. err:
  13164. - spin_unlock_irqrestore(&htab->lock, flags);
  13165. + raw_spin_unlock_irqrestore(&htab->lock, flags);
  13166. kfree(l_new);
  13167. return ret;
  13168. }
  13169. @@ -291,7 +291,7 @@
  13170. hash = htab_map_hash(key, key_size);
  13171. - spin_lock_irqsave(&htab->lock, flags);
  13172. + raw_spin_lock_irqsave(&htab->lock, flags);
  13173. head = select_bucket(htab, hash);
  13174. @@ -304,7 +304,7 @@
  13175. ret = 0;
  13176. }
  13177. - spin_unlock_irqrestore(&htab->lock, flags);
  13178. + raw_spin_unlock_irqrestore(&htab->lock, flags);
  13179. return ret;
  13180. }
  13181. diff -Nur linux-4.1.26.orig/kernel/cgroup.c linux-4.1.26/kernel/cgroup.c
  13182. --- linux-4.1.26.orig/kernel/cgroup.c 2016-06-07 01:13:11.000000000 +0200
  13183. +++ linux-4.1.26/kernel/cgroup.c 2016-06-19 15:30:58.687297349 +0200
  13184. @@ -4422,10 +4422,10 @@
  13185. queue_work(cgroup_destroy_wq, &css->destroy_work);
  13186. }
  13187. -static void css_release_work_fn(struct work_struct *work)
  13188. +static void css_release_work_fn(struct swork_event *sev)
  13189. {
  13190. struct cgroup_subsys_state *css =
  13191. - container_of(work, struct cgroup_subsys_state, destroy_work);
  13192. + container_of(sev, struct cgroup_subsys_state, destroy_swork);
  13193. struct cgroup_subsys *ss = css->ss;
  13194. struct cgroup *cgrp = css->cgroup;
  13195. @@ -4464,8 +4464,8 @@
  13196. struct cgroup_subsys_state *css =
  13197. container_of(ref, struct cgroup_subsys_state, refcnt);
  13198. - INIT_WORK(&css->destroy_work, css_release_work_fn);
  13199. - queue_work(cgroup_destroy_wq, &css->destroy_work);
  13200. + INIT_SWORK(&css->destroy_swork, css_release_work_fn);
  13201. + swork_queue(&css->destroy_swork);
  13202. }
  13203. static void init_and_link_css(struct cgroup_subsys_state *css,
  13204. @@ -5081,6 +5081,7 @@
  13205. */
  13206. cgroup_destroy_wq = alloc_workqueue("cgroup_destroy", 0, 1);
  13207. BUG_ON(!cgroup_destroy_wq);
  13208. + BUG_ON(swork_get());
  13209. /*
  13210. * Used to destroy pidlists and separate to serve as flush domain.
  13211. diff -Nur linux-4.1.26.orig/kernel/cpu.c linux-4.1.26/kernel/cpu.c
  13212. --- linux-4.1.26.orig/kernel/cpu.c 2016-06-07 01:13:11.000000000 +0200
  13213. +++ linux-4.1.26/kernel/cpu.c 2016-06-19 15:30:58.687297349 +0200
  13214. @@ -74,8 +74,8 @@
  13215. #endif
  13216. } cpu_hotplug = {
  13217. .active_writer = NULL,
  13218. - .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  13219. .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
  13220. + .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  13221. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  13222. .dep_map = {.name = "cpu_hotplug.lock" },
  13223. #endif
  13224. @@ -88,6 +88,289 @@
  13225. #define cpuhp_lock_acquire() lock_map_acquire(&cpu_hotplug.dep_map)
  13226. #define cpuhp_lock_release() lock_map_release(&cpu_hotplug.dep_map)
  13227. +/**
  13228. + * hotplug_pcp - per cpu hotplug descriptor
  13229. + * @unplug: set when pin_current_cpu() needs to sync tasks
  13230. + * @sync_tsk: the task that waits for tasks to finish pinned sections
  13231. + * @refcount: counter of tasks in pinned sections
  13232. + * @grab_lock: set when the tasks entering pinned sections should wait
  13233. + * @synced: notifier for @sync_tsk to tell cpu_down it's finished
  13234. + * @mutex: the mutex to make tasks wait (used when @grab_lock is true)
  13235. + * @mutex_init: zero if the mutex hasn't been initialized yet.
  13236. + *
  13237. + * Although @unplug and @sync_tsk may point to the same task, the @unplug
  13238. + * is used as a flag and still exists after @sync_tsk has exited and
  13239. + * @sync_tsk set to NULL.
  13240. + */
  13241. +struct hotplug_pcp {
  13242. + struct task_struct *unplug;
  13243. + struct task_struct *sync_tsk;
  13244. + int refcount;
  13245. + int grab_lock;
  13246. + struct completion synced;
  13247. + struct completion unplug_wait;
  13248. +#ifdef CONFIG_PREEMPT_RT_FULL
  13249. + /*
  13250. + * Note, on PREEMPT_RT, the hotplug lock must save the state of
  13251. + * the task, otherwise the mutex will cause the task to fail
  13252. + * to sleep when required. (Because it's called from migrate_disable())
  13253. + *
  13254. + * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
  13255. + * state.
  13256. + */
  13257. + spinlock_t lock;
  13258. +#else
  13259. + struct mutex mutex;
  13260. +#endif
  13261. + int mutex_init;
  13262. +};
  13263. +
  13264. +#ifdef CONFIG_PREEMPT_RT_FULL
  13265. +# define hotplug_lock(hp) rt_spin_lock(&(hp)->lock)
  13266. +# define hotplug_unlock(hp) rt_spin_unlock(&(hp)->lock)
  13267. +#else
  13268. +# define hotplug_lock(hp) mutex_lock(&(hp)->mutex)
  13269. +# define hotplug_unlock(hp) mutex_unlock(&(hp)->mutex)
  13270. +#endif
  13271. +
  13272. +static DEFINE_PER_CPU(struct hotplug_pcp, hotplug_pcp);
  13273. +
  13274. +/**
  13275. + * pin_current_cpu - Prevent the current cpu from being unplugged
  13276. + *
  13277. + * Lightweight version of get_online_cpus() to prevent cpu from being
  13278. + * unplugged when code runs in a migration disabled region.
  13279. + *
  13280. + * Must be called with preemption disabled (preempt_count = 1)!
  13281. + */
  13282. +void pin_current_cpu(void)
  13283. +{
  13284. + struct hotplug_pcp *hp;
  13285. + int force = 0;
  13286. +
  13287. +retry:
  13288. + hp = this_cpu_ptr(&hotplug_pcp);
  13289. +
  13290. + if (!hp->unplug || hp->refcount || force || preempt_count() > 1 ||
  13291. + hp->unplug == current) {
  13292. + hp->refcount++;
  13293. + return;
  13294. + }
  13295. + if (hp->grab_lock) {
  13296. + preempt_enable();
  13297. + hotplug_lock(hp);
  13298. + hotplug_unlock(hp);
  13299. + } else {
  13300. + preempt_enable();
  13301. + /*
  13302. + * Try to push this task off of this CPU.
  13303. + */
  13304. + if (!migrate_me()) {
  13305. + preempt_disable();
  13306. + hp = this_cpu_ptr(&hotplug_pcp);
  13307. + if (!hp->grab_lock) {
  13308. + /*
  13309. + * Just let it continue it's already pinned
  13310. + * or about to sleep.
  13311. + */
  13312. + force = 1;
  13313. + goto retry;
  13314. + }
  13315. + preempt_enable();
  13316. + }
  13317. + }
  13318. + preempt_disable();
  13319. + goto retry;
  13320. +}
  13321. +
  13322. +/**
  13323. + * unpin_current_cpu - Allow unplug of current cpu
  13324. + *
  13325. + * Must be called with preemption or interrupts disabled!
  13326. + */
  13327. +void unpin_current_cpu(void)
  13328. +{
  13329. + struct hotplug_pcp *hp = this_cpu_ptr(&hotplug_pcp);
  13330. +
  13331. + WARN_ON(hp->refcount <= 0);
  13332. +
  13333. + /* This is safe. sync_unplug_thread is pinned to this cpu */
  13334. + if (!--hp->refcount && hp->unplug && hp->unplug != current)
  13335. + wake_up_process(hp->unplug);
  13336. +}
  13337. +
  13338. +static void wait_for_pinned_cpus(struct hotplug_pcp *hp)
  13339. +{
  13340. + set_current_state(TASK_UNINTERRUPTIBLE);
  13341. + while (hp->refcount) {
  13342. + schedule_preempt_disabled();
  13343. + set_current_state(TASK_UNINTERRUPTIBLE);
  13344. + }
  13345. +}
  13346. +
  13347. +static int sync_unplug_thread(void *data)
  13348. +{
  13349. + struct hotplug_pcp *hp = data;
  13350. +
  13351. + wait_for_completion(&hp->unplug_wait);
  13352. + preempt_disable();
  13353. + hp->unplug = current;
  13354. + wait_for_pinned_cpus(hp);
  13355. +
  13356. + /*
  13357. + * This thread will synchronize the cpu_down() with threads
  13358. + * that have pinned the CPU. When the pinned CPU count reaches
  13359. + * zero, we inform the cpu_down code to continue to the next step.
  13360. + */
  13361. + set_current_state(TASK_UNINTERRUPTIBLE);
  13362. + preempt_enable();
  13363. + complete(&hp->synced);
  13364. +
  13365. + /*
  13366. + * If all succeeds, the next step will need tasks to wait till
  13367. + * the CPU is offline before continuing. To do this, the grab_lock
  13368. + * is set and tasks going into pin_current_cpu() will block on the
  13369. + * mutex. But we still need to wait for those that are already in
  13370. + * pinned CPU sections. If the cpu_down() failed, the kthread_should_stop()
  13371. + * will kick this thread out.
  13372. + */
  13373. + while (!hp->grab_lock && !kthread_should_stop()) {
  13374. + schedule();
  13375. + set_current_state(TASK_UNINTERRUPTIBLE);
  13376. + }
  13377. +
  13378. + /* Make sure grab_lock is seen before we see a stale completion */
  13379. + smp_mb();
  13380. +
  13381. + /*
  13382. + * Now just before cpu_down() enters stop machine, we need to make
  13383. + * sure all tasks that are in pinned CPU sections are out, and new
  13384. + * tasks will now grab the lock, keeping them from entering pinned
  13385. + * CPU sections.
  13386. + */
  13387. + if (!kthread_should_stop()) {
  13388. + preempt_disable();
  13389. + wait_for_pinned_cpus(hp);
  13390. + preempt_enable();
  13391. + complete(&hp->synced);
  13392. + }
  13393. +
  13394. + set_current_state(TASK_UNINTERRUPTIBLE);
  13395. + while (!kthread_should_stop()) {
  13396. + schedule();
  13397. + set_current_state(TASK_UNINTERRUPTIBLE);
  13398. + }
  13399. + set_current_state(TASK_RUNNING);
  13400. +
  13401. + /*
  13402. + * Force this thread off this CPU as it's going down and
  13403. + * we don't want any more work on this CPU.
  13404. + */
  13405. + current->flags &= ~PF_NO_SETAFFINITY;
  13406. + set_cpus_allowed_ptr(current, cpu_present_mask);
  13407. + migrate_me();
  13408. + return 0;
  13409. +}
  13410. +
  13411. +static void __cpu_unplug_sync(struct hotplug_pcp *hp)
  13412. +{
  13413. + wake_up_process(hp->sync_tsk);
  13414. + wait_for_completion(&hp->synced);
  13415. +}
  13416. +
  13417. +static void __cpu_unplug_wait(unsigned int cpu)
  13418. +{
  13419. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  13420. +
  13421. + complete(&hp->unplug_wait);
  13422. + wait_for_completion(&hp->synced);
  13423. +}
  13424. +
  13425. +/*
  13426. + * Start the sync_unplug_thread on the target cpu and wait for it to
  13427. + * complete.
  13428. + */
  13429. +static int cpu_unplug_begin(unsigned int cpu)
  13430. +{
  13431. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  13432. + int err;
  13433. +
  13434. + /* Protected by cpu_hotplug.lock */
  13435. + if (!hp->mutex_init) {
  13436. +#ifdef CONFIG_PREEMPT_RT_FULL
  13437. + spin_lock_init(&hp->lock);
  13438. +#else
  13439. + mutex_init(&hp->mutex);
  13440. +#endif
  13441. + hp->mutex_init = 1;
  13442. + }
  13443. +
  13444. + /* Inform the scheduler to migrate tasks off this CPU */
  13445. + tell_sched_cpu_down_begin(cpu);
  13446. +
  13447. + init_completion(&hp->synced);
  13448. + init_completion(&hp->unplug_wait);
  13449. +
  13450. + hp->sync_tsk = kthread_create(sync_unplug_thread, hp, "sync_unplug/%d", cpu);
  13451. + if (IS_ERR(hp->sync_tsk)) {
  13452. + err = PTR_ERR(hp->sync_tsk);
  13453. + hp->sync_tsk = NULL;
  13454. + return err;
  13455. + }
  13456. + kthread_bind(hp->sync_tsk, cpu);
  13457. +
  13458. + /*
  13459. + * Wait for tasks to get out of the pinned sections,
  13460. + * it's still OK if new tasks enter. Some CPU notifiers will
  13461. + * wait for tasks that are going to enter these sections and
  13462. + * we must not have them block.
  13463. + */
  13464. + wake_up_process(hp->sync_tsk);
  13465. + return 0;
  13466. +}
  13467. +
  13468. +static void cpu_unplug_sync(unsigned int cpu)
  13469. +{
  13470. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  13471. +
  13472. + init_completion(&hp->synced);
  13473. + /* The completion needs to be initialzied before setting grab_lock */
  13474. + smp_wmb();
  13475. +
  13476. + /* Grab the mutex before setting grab_lock */
  13477. + hotplug_lock(hp);
  13478. + hp->grab_lock = 1;
  13479. +
  13480. + /*
  13481. + * The CPU notifiers have been completed.
  13482. + * Wait for tasks to get out of pinned CPU sections and have new
  13483. + * tasks block until the CPU is completely down.
  13484. + */
  13485. + __cpu_unplug_sync(hp);
  13486. +
  13487. + /* All done with the sync thread */
  13488. + kthread_stop(hp->sync_tsk);
  13489. + hp->sync_tsk = NULL;
  13490. +}
  13491. +
  13492. +static void cpu_unplug_done(unsigned int cpu)
  13493. +{
  13494. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  13495. +
  13496. + hp->unplug = NULL;
  13497. + /* Let all tasks know cpu unplug is finished before cleaning up */
  13498. + smp_wmb();
  13499. +
  13500. + if (hp->sync_tsk)
  13501. + kthread_stop(hp->sync_tsk);
  13502. +
  13503. + if (hp->grab_lock) {
  13504. + hotplug_unlock(hp);
  13505. + /* protected by cpu_hotplug.lock */
  13506. + hp->grab_lock = 0;
  13507. + }
  13508. + tell_sched_cpu_down_done(cpu);
  13509. +}
  13510. void get_online_cpus(void)
  13511. {
  13512. @@ -349,13 +632,15 @@
  13513. /* Requires cpu_add_remove_lock to be held */
  13514. static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
  13515. {
  13516. - int err, nr_calls = 0;
  13517. + int mycpu, err, nr_calls = 0;
  13518. void *hcpu = (void *)(long)cpu;
  13519. unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
  13520. struct take_cpu_down_param tcd_param = {
  13521. .mod = mod,
  13522. .hcpu = hcpu,
  13523. };
  13524. + cpumask_var_t cpumask;
  13525. + cpumask_var_t cpumask_org;
  13526. if (num_online_cpus() == 1)
  13527. return -EBUSY;
  13528. @@ -363,7 +648,34 @@
  13529. if (!cpu_online(cpu))
  13530. return -EINVAL;
  13531. + /* Move the downtaker off the unplug cpu */
  13532. + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
  13533. + return -ENOMEM;
  13534. + if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL)) {
  13535. + free_cpumask_var(cpumask);
  13536. + return -ENOMEM;
  13537. + }
  13538. +
  13539. + cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
  13540. + cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
  13541. + set_cpus_allowed_ptr(current, cpumask);
  13542. + free_cpumask_var(cpumask);
  13543. + migrate_disable();
  13544. + mycpu = smp_processor_id();
  13545. + if (mycpu == cpu) {
  13546. + printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
  13547. + migrate_enable();
  13548. + err = -EBUSY;
  13549. + goto restore_cpus;
  13550. + }
  13551. + migrate_enable();
  13552. +
  13553. cpu_hotplug_begin();
  13554. + err = cpu_unplug_begin(cpu);
  13555. + if (err) {
  13556. + printk("cpu_unplug_begin(%d) failed\n", cpu);
  13557. + goto out_cancel;
  13558. + }
  13559. err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
  13560. if (err) {
  13561. @@ -389,8 +701,12 @@
  13562. #endif
  13563. synchronize_rcu();
  13564. + __cpu_unplug_wait(cpu);
  13565. smpboot_park_threads(cpu);
  13566. + /* Notifiers are done. Don't let any more tasks pin this CPU. */
  13567. + cpu_unplug_sync(cpu);
  13568. +
  13569. /*
  13570. * So now all preempt/rcu users must observe !cpu_active().
  13571. */
  13572. @@ -427,9 +743,14 @@
  13573. check_for_tasks(cpu);
  13574. out_release:
  13575. + cpu_unplug_done(cpu);
  13576. +out_cancel:
  13577. cpu_hotplug_done();
  13578. if (!err)
  13579. cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
  13580. +restore_cpus:
  13581. + set_cpus_allowed_ptr(current, cpumask_org);
  13582. + free_cpumask_var(cpumask_org);
  13583. return err;
  13584. }
  13585. diff -Nur linux-4.1.26.orig/kernel/debug/kdb/kdb_io.c linux-4.1.26/kernel/debug/kdb/kdb_io.c
  13586. --- linux-4.1.26.orig/kernel/debug/kdb/kdb_io.c 2016-06-07 01:13:11.000000000 +0200
  13587. +++ linux-4.1.26/kernel/debug/kdb/kdb_io.c 2016-06-19 15:30:58.687297349 +0200
  13588. @@ -554,7 +554,6 @@
  13589. int linecount;
  13590. int colcount;
  13591. int logging, saved_loglevel = 0;
  13592. - int saved_trap_printk;
  13593. int got_printf_lock = 0;
  13594. int retlen = 0;
  13595. int fnd, len;
  13596. @@ -565,8 +564,6 @@
  13597. unsigned long uninitialized_var(flags);
  13598. preempt_disable();
  13599. - saved_trap_printk = kdb_trap_printk;
  13600. - kdb_trap_printk = 0;
  13601. /* Serialize kdb_printf if multiple cpus try to write at once.
  13602. * But if any cpu goes recursive in kdb, just print the output,
  13603. @@ -855,7 +852,6 @@
  13604. } else {
  13605. __release(kdb_printf_lock);
  13606. }
  13607. - kdb_trap_printk = saved_trap_printk;
  13608. preempt_enable();
  13609. return retlen;
  13610. }
  13611. @@ -865,9 +861,11 @@
  13612. va_list ap;
  13613. int r;
  13614. + kdb_trap_printk++;
  13615. va_start(ap, fmt);
  13616. r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap);
  13617. va_end(ap);
  13618. + kdb_trap_printk--;
  13619. return r;
  13620. }
  13621. diff -Nur linux-4.1.26.orig/kernel/events/core.c linux-4.1.26/kernel/events/core.c
  13622. --- linux-4.1.26.orig/kernel/events/core.c 2016-06-07 01:13:11.000000000 +0200
  13623. +++ linux-4.1.26/kernel/events/core.c 2016-06-19 15:30:58.687297349 +0200
  13624. @@ -6925,6 +6925,7 @@
  13625. hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  13626. hwc->hrtimer.function = perf_swevent_hrtimer;
  13627. + hwc->hrtimer.irqsafe = 1;
  13628. /*
  13629. * Since hrtimers have a fixed rate, we can do a static freq->period
  13630. diff -Nur linux-4.1.26.orig/kernel/exit.c linux-4.1.26/kernel/exit.c
  13631. --- linux-4.1.26.orig/kernel/exit.c 2016-06-07 01:13:11.000000000 +0200
  13632. +++ linux-4.1.26/kernel/exit.c 2016-06-19 15:30:58.687297349 +0200
  13633. @@ -144,7 +144,7 @@
  13634. * Do this under ->siglock, we can race with another thread
  13635. * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
  13636. */
  13637. - flush_sigqueue(&tsk->pending);
  13638. + flush_task_sigqueue(tsk);
  13639. tsk->sighand = NULL;
  13640. spin_unlock(&sighand->siglock);
  13641. diff -Nur linux-4.1.26.orig/kernel/fork.c linux-4.1.26/kernel/fork.c
  13642. --- linux-4.1.26.orig/kernel/fork.c 2016-06-07 01:13:11.000000000 +0200
  13643. +++ linux-4.1.26/kernel/fork.c 2016-06-19 15:30:58.687297349 +0200
  13644. @@ -108,7 +108,7 @@
  13645. DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  13646. -__cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
  13647. +DEFINE_RWLOCK(tasklist_lock); /* outer */
  13648. #ifdef CONFIG_PROVE_RCU
  13649. int lockdep_tasklist_lock_is_held(void)
  13650. @@ -244,7 +244,9 @@
  13651. if (atomic_dec_and_test(&sig->sigcnt))
  13652. free_signal_struct(sig);
  13653. }
  13654. -
  13655. +#ifdef CONFIG_PREEMPT_RT_BASE
  13656. +static
  13657. +#endif
  13658. void __put_task_struct(struct task_struct *tsk)
  13659. {
  13660. WARN_ON(!tsk->exit_state);
  13661. @@ -260,7 +262,18 @@
  13662. if (!profile_handoff_task(tsk))
  13663. free_task(tsk);
  13664. }
  13665. +#ifndef CONFIG_PREEMPT_RT_BASE
  13666. EXPORT_SYMBOL_GPL(__put_task_struct);
  13667. +#else
  13668. +void __put_task_struct_cb(struct rcu_head *rhp)
  13669. +{
  13670. + struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
  13671. +
  13672. + __put_task_struct(tsk);
  13673. +
  13674. +}
  13675. +EXPORT_SYMBOL_GPL(__put_task_struct_cb);
  13676. +#endif
  13677. void __init __weak arch_task_cache_init(void) { }
  13678. @@ -374,6 +387,7 @@
  13679. #endif
  13680. tsk->splice_pipe = NULL;
  13681. tsk->task_frag.page = NULL;
  13682. + tsk->wake_q.next = NULL;
  13683. account_kernel_stack(ti, 1);
  13684. @@ -680,6 +694,19 @@
  13685. }
  13686. EXPORT_SYMBOL_GPL(__mmdrop);
  13687. +#ifdef CONFIG_PREEMPT_RT_BASE
  13688. +/*
  13689. + * RCU callback for delayed mm drop. Not strictly rcu, but we don't
  13690. + * want another facility to make this work.
  13691. + */
  13692. +void __mmdrop_delayed(struct rcu_head *rhp)
  13693. +{
  13694. + struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
  13695. +
  13696. + __mmdrop(mm);
  13697. +}
  13698. +#endif
  13699. +
  13700. /*
  13701. * Decrement the use count and release all resources for an mm.
  13702. */
  13703. @@ -1214,6 +1241,9 @@
  13704. */
  13705. static void posix_cpu_timers_init(struct task_struct *tsk)
  13706. {
  13707. +#ifdef CONFIG_PREEMPT_RT_BASE
  13708. + tsk->posix_timer_list = NULL;
  13709. +#endif
  13710. tsk->cputime_expires.prof_exp = 0;
  13711. tsk->cputime_expires.virt_exp = 0;
  13712. tsk->cputime_expires.sched_exp = 0;
  13713. @@ -1338,6 +1368,7 @@
  13714. spin_lock_init(&p->alloc_lock);
  13715. init_sigpending(&p->pending);
  13716. + p->sigqueue_cache = NULL;
  13717. p->utime = p->stime = p->gtime = 0;
  13718. p->utimescaled = p->stimescaled = 0;
  13719. @@ -1345,7 +1376,8 @@
  13720. p->prev_cputime.utime = p->prev_cputime.stime = 0;
  13721. #endif
  13722. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  13723. - seqlock_init(&p->vtime_seqlock);
  13724. + raw_spin_lock_init(&p->vtime_lock);
  13725. + seqcount_init(&p->vtime_seq);
  13726. p->vtime_snap = 0;
  13727. p->vtime_snap_whence = VTIME_SLEEPING;
  13728. #endif
  13729. @@ -1396,6 +1428,9 @@
  13730. p->hardirq_context = 0;
  13731. p->softirq_context = 0;
  13732. #endif
  13733. +
  13734. + p->pagefault_disabled = 0;
  13735. +
  13736. #ifdef CONFIG_LOCKDEP
  13737. p->lockdep_depth = 0; /* no locks held yet */
  13738. p->curr_chain_key = 0;
  13739. diff -Nur linux-4.1.26.orig/kernel/futex.c linux-4.1.26/kernel/futex.c
  13740. --- linux-4.1.26.orig/kernel/futex.c 2016-06-07 01:13:11.000000000 +0200
  13741. +++ linux-4.1.26/kernel/futex.c 2016-06-19 15:32:42.447298576 +0200
  13742. @@ -738,7 +738,9 @@
  13743. * task still owns the PI-state:
  13744. */
  13745. if (head->next != next) {
  13746. + raw_spin_unlock_irq(&curr->pi_lock);
  13747. spin_unlock(&hb->lock);
  13748. + raw_spin_lock_irq(&curr->pi_lock);
  13749. continue;
  13750. }
  13751. @@ -1090,9 +1092,11 @@
  13752. /*
  13753. * The hash bucket lock must be held when this is called.
  13754. - * Afterwards, the futex_q must not be accessed.
  13755. + * Afterwards, the futex_q must not be accessed. Callers
  13756. + * must ensure to later call wake_up_q() for the actual
  13757. + * wakeups to occur.
  13758. */
  13759. -static void wake_futex(struct futex_q *q)
  13760. +static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q)
  13761. {
  13762. struct task_struct *p = q->task;
  13763. @@ -1100,14 +1104,10 @@
  13764. return;
  13765. /*
  13766. - * We set q->lock_ptr = NULL _before_ we wake up the task. If
  13767. - * a non-futex wake up happens on another CPU then the task
  13768. - * might exit and p would dereference a non-existing task
  13769. - * struct. Prevent this by holding a reference on p across the
  13770. - * wake up.
  13771. + * Queue the task for later wakeup for after we've released
  13772. + * the hb->lock. wake_q_add() grabs reference to p.
  13773. */
  13774. - get_task_struct(p);
  13775. -
  13776. + wake_q_add(wake_q, p);
  13777. __unqueue_futex(q);
  13778. /*
  13779. * The waiting task can free the futex_q as soon as
  13780. @@ -1117,16 +1117,15 @@
  13781. */
  13782. smp_wmb();
  13783. q->lock_ptr = NULL;
  13784. -
  13785. - wake_up_state(p, TASK_NORMAL);
  13786. - put_task_struct(p);
  13787. }
  13788. -static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this)
  13789. +static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
  13790. + struct futex_hash_bucket *hb)
  13791. {
  13792. struct task_struct *new_owner;
  13793. struct futex_pi_state *pi_state = this->pi_state;
  13794. u32 uninitialized_var(curval), newval;
  13795. + bool deboost;
  13796. int ret = 0;
  13797. if (!pi_state)
  13798. @@ -1188,7 +1187,17 @@
  13799. raw_spin_unlock_irq(&new_owner->pi_lock);
  13800. raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
  13801. - rt_mutex_unlock(&pi_state->pi_mutex);
  13802. +
  13803. + deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex);
  13804. +
  13805. + /*
  13806. + * We deboost after dropping hb->lock. That prevents a double
  13807. + * wakeup on RT.
  13808. + */
  13809. + spin_unlock(&hb->lock);
  13810. +
  13811. + if (deboost)
  13812. + rt_mutex_adjust_prio(current);
  13813. return 0;
  13814. }
  13815. @@ -1227,6 +1236,7 @@
  13816. struct futex_q *this, *next;
  13817. union futex_key key = FUTEX_KEY_INIT;
  13818. int ret;
  13819. + WAKE_Q(wake_q);
  13820. if (!bitset)
  13821. return -EINVAL;
  13822. @@ -1254,13 +1264,14 @@
  13823. if (!(this->bitset & bitset))
  13824. continue;
  13825. - wake_futex(this);
  13826. + mark_wake_futex(&wake_q, this);
  13827. if (++ret >= nr_wake)
  13828. break;
  13829. }
  13830. }
  13831. spin_unlock(&hb->lock);
  13832. + wake_up_q(&wake_q);
  13833. out_put_key:
  13834. put_futex_key(&key);
  13835. out:
  13836. @@ -1279,6 +1290,7 @@
  13837. struct futex_hash_bucket *hb1, *hb2;
  13838. struct futex_q *this, *next;
  13839. int ret, op_ret;
  13840. + WAKE_Q(wake_q);
  13841. retry:
  13842. ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, VERIFY_READ);
  13843. @@ -1330,7 +1342,7 @@
  13844. ret = -EINVAL;
  13845. goto out_unlock;
  13846. }
  13847. - wake_futex(this);
  13848. + mark_wake_futex(&wake_q, this);
  13849. if (++ret >= nr_wake)
  13850. break;
  13851. }
  13852. @@ -1344,7 +1356,7 @@
  13853. ret = -EINVAL;
  13854. goto out_unlock;
  13855. }
  13856. - wake_futex(this);
  13857. + mark_wake_futex(&wake_q, this);
  13858. if (++op_ret >= nr_wake2)
  13859. break;
  13860. }
  13861. @@ -1354,6 +1366,7 @@
  13862. out_unlock:
  13863. double_unlock_hb(hb1, hb2);
  13864. + wake_up_q(&wake_q);
  13865. out_put_keys:
  13866. put_futex_key(&key2);
  13867. out_put_key1:
  13868. @@ -1513,6 +1526,7 @@
  13869. struct futex_pi_state *pi_state = NULL;
  13870. struct futex_hash_bucket *hb1, *hb2;
  13871. struct futex_q *this, *next;
  13872. + WAKE_Q(wake_q);
  13873. if (requeue_pi) {
  13874. /*
  13875. @@ -1689,7 +1703,7 @@
  13876. * woken by futex_unlock_pi().
  13877. */
  13878. if (++task_count <= nr_wake && !requeue_pi) {
  13879. - wake_futex(this);
  13880. + mark_wake_futex(&wake_q, this);
  13881. continue;
  13882. }
  13883. @@ -1715,6 +1729,16 @@
  13884. requeue_pi_wake_futex(this, &key2, hb2);
  13885. drop_count++;
  13886. continue;
  13887. + } else if (ret == -EAGAIN) {
  13888. + /*
  13889. + * Waiter was woken by timeout or
  13890. + * signal and has set pi_blocked_on to
  13891. + * PI_WAKEUP_INPROGRESS before we
  13892. + * tried to enqueue it on the rtmutex.
  13893. + */
  13894. + this->pi_state = NULL;
  13895. + free_pi_state(pi_state);
  13896. + continue;
  13897. } else if (ret) {
  13898. /* -EDEADLK */
  13899. this->pi_state = NULL;
  13900. @@ -1729,6 +1753,7 @@
  13901. out_unlock:
  13902. free_pi_state(pi_state);
  13903. double_unlock_hb(hb1, hb2);
  13904. + wake_up_q(&wake_q);
  13905. hb_waiters_dec(hb2);
  13906. /*
  13907. @@ -2422,7 +2447,15 @@
  13908. */
  13909. match = futex_top_waiter(hb, &key);
  13910. if (match) {
  13911. - ret = wake_futex_pi(uaddr, uval, match);
  13912. + ret = wake_futex_pi(uaddr, uval, match, hb);
  13913. +
  13914. + /*
  13915. + * In case of success wake_futex_pi dropped the hash
  13916. + * bucket lock.
  13917. + */
  13918. + if (!ret)
  13919. + goto out_putkey;
  13920. +
  13921. /*
  13922. * The atomic access to the futex value generated a
  13923. * pagefault, so retry the user-access and the wakeup:
  13924. @@ -2458,6 +2491,7 @@
  13925. out_unlock:
  13926. spin_unlock(&hb->lock);
  13927. +out_putkey:
  13928. put_futex_key(&key);
  13929. return ret;
  13930. @@ -2568,7 +2602,7 @@
  13931. struct hrtimer_sleeper timeout, *to = NULL;
  13932. struct rt_mutex_waiter rt_waiter;
  13933. struct rt_mutex *pi_mutex = NULL;
  13934. - struct futex_hash_bucket *hb;
  13935. + struct futex_hash_bucket *hb, *hb2;
  13936. union futex_key key2 = FUTEX_KEY_INIT;
  13937. struct futex_q q = futex_q_init;
  13938. int res, ret;
  13939. @@ -2593,10 +2627,7 @@
  13940. * The waiter is allocated on our stack, manipulated by the requeue
  13941. * code while we sleep on uaddr.
  13942. */
  13943. - debug_rt_mutex_init_waiter(&rt_waiter);
  13944. - RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
  13945. - RB_CLEAR_NODE(&rt_waiter.tree_entry);
  13946. - rt_waiter.task = NULL;
  13947. + rt_mutex_init_waiter(&rt_waiter, false);
  13948. ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
  13949. if (unlikely(ret != 0))
  13950. @@ -2627,20 +2658,55 @@
  13951. /* Queue the futex_q, drop the hb lock, wait for wakeup. */
  13952. futex_wait_queue_me(hb, &q, to);
  13953. - spin_lock(&hb->lock);
  13954. - ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  13955. - spin_unlock(&hb->lock);
  13956. - if (ret)
  13957. - goto out_put_keys;
  13958. + /*
  13959. + * On RT we must avoid races with requeue and trying to block
  13960. + * on two mutexes (hb->lock and uaddr2's rtmutex) by
  13961. + * serializing access to pi_blocked_on with pi_lock.
  13962. + */
  13963. + raw_spin_lock_irq(&current->pi_lock);
  13964. + if (current->pi_blocked_on) {
  13965. + /*
  13966. + * We have been requeued or are in the process of
  13967. + * being requeued.
  13968. + */
  13969. + raw_spin_unlock_irq(&current->pi_lock);
  13970. + } else {
  13971. + /*
  13972. + * Setting pi_blocked_on to PI_WAKEUP_INPROGRESS
  13973. + * prevents a concurrent requeue from moving us to the
  13974. + * uaddr2 rtmutex. After that we can safely acquire
  13975. + * (and possibly block on) hb->lock.
  13976. + */
  13977. + current->pi_blocked_on = PI_WAKEUP_INPROGRESS;
  13978. + raw_spin_unlock_irq(&current->pi_lock);
  13979. +
  13980. + spin_lock(&hb->lock);
  13981. +
  13982. + /*
  13983. + * Clean up pi_blocked_on. We might leak it otherwise
  13984. + * when we succeeded with the hb->lock in the fast
  13985. + * path.
  13986. + */
  13987. + raw_spin_lock_irq(&current->pi_lock);
  13988. + current->pi_blocked_on = NULL;
  13989. + raw_spin_unlock_irq(&current->pi_lock);
  13990. +
  13991. + ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  13992. + spin_unlock(&hb->lock);
  13993. + if (ret)
  13994. + goto out_put_keys;
  13995. + }
  13996. /*
  13997. - * In order for us to be here, we know our q.key == key2, and since
  13998. - * we took the hb->lock above, we also know that futex_requeue() has
  13999. - * completed and we no longer have to concern ourselves with a wakeup
  14000. - * race with the atomic proxy lock acquisition by the requeue code. The
  14001. - * futex_requeue dropped our key1 reference and incremented our key2
  14002. - * reference count.
  14003. + * In order to be here, we have either been requeued, are in
  14004. + * the process of being requeued, or requeue successfully
  14005. + * acquired uaddr2 on our behalf. If pi_blocked_on was
  14006. + * non-null above, we may be racing with a requeue. Do not
  14007. + * rely on q->lock_ptr to be hb2->lock until after blocking on
  14008. + * hb->lock or hb2->lock. The futex_requeue dropped our key1
  14009. + * reference and incremented our key2 reference count.
  14010. */
  14011. + hb2 = hash_futex(&key2);
  14012. /* Check if the requeue code acquired the second futex for us. */
  14013. if (!q.rt_waiter) {
  14014. @@ -2649,14 +2715,15 @@
  14015. * did a lock-steal - fix up the PI-state in that case.
  14016. */
  14017. if (q.pi_state && (q.pi_state->owner != current)) {
  14018. - spin_lock(q.lock_ptr);
  14019. + spin_lock(&hb2->lock);
  14020. + BUG_ON(&hb2->lock != q.lock_ptr);
  14021. ret = fixup_pi_state_owner(uaddr2, &q, current);
  14022. /*
  14023. * Drop the reference to the pi state which
  14024. * the requeue_pi() code acquired for us.
  14025. */
  14026. free_pi_state(q.pi_state);
  14027. - spin_unlock(q.lock_ptr);
  14028. + spin_unlock(&hb2->lock);
  14029. }
  14030. } else {
  14031. /*
  14032. @@ -2669,7 +2736,8 @@
  14033. ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
  14034. debug_rt_mutex_free_waiter(&rt_waiter);
  14035. - spin_lock(q.lock_ptr);
  14036. + spin_lock(&hb2->lock);
  14037. + BUG_ON(&hb2->lock != q.lock_ptr);
  14038. /*
  14039. * Fixup the pi_state owner and possibly acquire the lock if we
  14040. * haven't already.
  14041. diff -Nur linux-4.1.26.orig/kernel/irq/handle.c linux-4.1.26/kernel/irq/handle.c
  14042. --- linux-4.1.26.orig/kernel/irq/handle.c 2016-06-07 01:13:11.000000000 +0200
  14043. +++ linux-4.1.26/kernel/irq/handle.c 2016-06-19 15:30:58.691297504 +0200
  14044. @@ -133,6 +133,8 @@
  14045. irqreturn_t
  14046. handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
  14047. {
  14048. + struct pt_regs *regs = get_irq_regs();
  14049. + u64 ip = regs ? instruction_pointer(regs) : 0;
  14050. irqreturn_t retval = IRQ_NONE;
  14051. unsigned int flags = 0, irq = desc->irq_data.irq;
  14052. @@ -173,7 +175,11 @@
  14053. action = action->next;
  14054. } while (action);
  14055. - add_interrupt_randomness(irq, flags);
  14056. +#ifndef CONFIG_PREEMPT_RT_FULL
  14057. + add_interrupt_randomness(irq, flags, ip);
  14058. +#else
  14059. + desc->random_ip = ip;
  14060. +#endif
  14061. if (!noirqdebug)
  14062. note_interrupt(irq, desc, retval);
  14063. diff -Nur linux-4.1.26.orig/kernel/irq/manage.c linux-4.1.26/kernel/irq/manage.c
  14064. --- linux-4.1.26.orig/kernel/irq/manage.c 2016-06-07 01:13:11.000000000 +0200
  14065. +++ linux-4.1.26/kernel/irq/manage.c 2016-06-19 15:30:58.691297504 +0200
  14066. @@ -22,6 +22,7 @@
  14067. #include "internals.h"
  14068. #ifdef CONFIG_IRQ_FORCED_THREADING
  14069. +# ifndef CONFIG_PREEMPT_RT_BASE
  14070. __read_mostly bool force_irqthreads;
  14071. static int __init setup_forced_irqthreads(char *arg)
  14072. @@ -30,6 +31,7 @@
  14073. return 0;
  14074. }
  14075. early_param("threadirqs", setup_forced_irqthreads);
  14076. +# endif
  14077. #endif
  14078. static void __synchronize_hardirq(struct irq_desc *desc)
  14079. @@ -179,6 +181,62 @@
  14080. irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
  14081. #endif
  14082. +#ifdef CONFIG_PREEMPT_RT_FULL
  14083. +static void _irq_affinity_notify(struct irq_affinity_notify *notify);
  14084. +static struct task_struct *set_affinity_helper;
  14085. +static LIST_HEAD(affinity_list);
  14086. +static DEFINE_RAW_SPINLOCK(affinity_list_lock);
  14087. +
  14088. +static int set_affinity_thread(void *unused)
  14089. +{
  14090. + while (1) {
  14091. + struct irq_affinity_notify *notify;
  14092. + int empty;
  14093. +
  14094. + set_current_state(TASK_INTERRUPTIBLE);
  14095. +
  14096. + raw_spin_lock_irq(&affinity_list_lock);
  14097. + empty = list_empty(&affinity_list);
  14098. + raw_spin_unlock_irq(&affinity_list_lock);
  14099. +
  14100. + if (empty)
  14101. + schedule();
  14102. + if (kthread_should_stop())
  14103. + break;
  14104. + set_current_state(TASK_RUNNING);
  14105. +try_next:
  14106. + notify = NULL;
  14107. +
  14108. + raw_spin_lock_irq(&affinity_list_lock);
  14109. + if (!list_empty(&affinity_list)) {
  14110. + notify = list_first_entry(&affinity_list,
  14111. + struct irq_affinity_notify, list);
  14112. + list_del_init(&notify->list);
  14113. + }
  14114. + raw_spin_unlock_irq(&affinity_list_lock);
  14115. +
  14116. + if (!notify)
  14117. + continue;
  14118. + _irq_affinity_notify(notify);
  14119. + goto try_next;
  14120. + }
  14121. + return 0;
  14122. +}
  14123. +
  14124. +static void init_helper_thread(void)
  14125. +{
  14126. + if (set_affinity_helper)
  14127. + return;
  14128. + set_affinity_helper = kthread_run(set_affinity_thread, NULL,
  14129. + "affinity-cb");
  14130. + WARN_ON(IS_ERR(set_affinity_helper));
  14131. +}
  14132. +#else
  14133. +
  14134. +static inline void init_helper_thread(void) { }
  14135. +
  14136. +#endif
  14137. +
  14138. int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
  14139. bool force)
  14140. {
  14141. @@ -218,7 +276,17 @@
  14142. if (desc->affinity_notify) {
  14143. kref_get(&desc->affinity_notify->kref);
  14144. +
  14145. +#ifdef CONFIG_PREEMPT_RT_FULL
  14146. + raw_spin_lock(&affinity_list_lock);
  14147. + if (list_empty(&desc->affinity_notify->list))
  14148. + list_add_tail(&affinity_list,
  14149. + &desc->affinity_notify->list);
  14150. + raw_spin_unlock(&affinity_list_lock);
  14151. + wake_up_process(set_affinity_helper);
  14152. +#else
  14153. schedule_work(&desc->affinity_notify->work);
  14154. +#endif
  14155. }
  14156. irqd_set(data, IRQD_AFFINITY_SET);
  14157. @@ -256,10 +324,8 @@
  14158. }
  14159. EXPORT_SYMBOL_GPL(irq_set_affinity_hint);
  14160. -static void irq_affinity_notify(struct work_struct *work)
  14161. +static void _irq_affinity_notify(struct irq_affinity_notify *notify)
  14162. {
  14163. - struct irq_affinity_notify *notify =
  14164. - container_of(work, struct irq_affinity_notify, work);
  14165. struct irq_desc *desc = irq_to_desc(notify->irq);
  14166. cpumask_var_t cpumask;
  14167. unsigned long flags;
  14168. @@ -281,6 +347,13 @@
  14169. kref_put(&notify->kref, notify->release);
  14170. }
  14171. +static void irq_affinity_notify(struct work_struct *work)
  14172. +{
  14173. + struct irq_affinity_notify *notify =
  14174. + container_of(work, struct irq_affinity_notify, work);
  14175. + _irq_affinity_notify(notify);
  14176. +}
  14177. +
  14178. /**
  14179. * irq_set_affinity_notifier - control notification of IRQ affinity changes
  14180. * @irq: Interrupt for which to enable/disable notification
  14181. @@ -310,6 +383,8 @@
  14182. notify->irq = irq;
  14183. kref_init(&notify->kref);
  14184. INIT_WORK(&notify->work, irq_affinity_notify);
  14185. + INIT_LIST_HEAD(&notify->list);
  14186. + init_helper_thread();
  14187. }
  14188. raw_spin_lock_irqsave(&desc->lock, flags);
  14189. @@ -697,6 +772,12 @@
  14190. return IRQ_NONE;
  14191. }
  14192. +static irqreturn_t irq_forced_secondary_handler(int irq, void *dev_id)
  14193. +{
  14194. + WARN(1, "Secondary action handler called for irq %d\n", irq);
  14195. + return IRQ_NONE;
  14196. +}
  14197. +
  14198. static int irq_wait_for_interrupt(struct irqaction *action)
  14199. {
  14200. set_current_state(TASK_INTERRUPTIBLE);
  14201. @@ -723,7 +804,8 @@
  14202. static void irq_finalize_oneshot(struct irq_desc *desc,
  14203. struct irqaction *action)
  14204. {
  14205. - if (!(desc->istate & IRQS_ONESHOT))
  14206. + if (!(desc->istate & IRQS_ONESHOT) ||
  14207. + action->handler == irq_forced_secondary_handler)
  14208. return;
  14209. again:
  14210. chip_bus_lock(desc);
  14211. @@ -825,7 +907,15 @@
  14212. local_bh_disable();
  14213. ret = action->thread_fn(action->irq, action->dev_id);
  14214. irq_finalize_oneshot(desc, action);
  14215. - local_bh_enable();
  14216. + /*
  14217. + * Interrupts which have real time requirements can be set up
  14218. + * to avoid softirq processing in the thread handler. This is
  14219. + * safe as these interrupts do not raise soft interrupts.
  14220. + */
  14221. + if (irq_settings_no_softirq_call(desc))
  14222. + _local_bh_enable();
  14223. + else
  14224. + local_bh_enable();
  14225. return ret;
  14226. }
  14227. @@ -877,6 +967,18 @@
  14228. irq_finalize_oneshot(desc, action);
  14229. }
  14230. +static void irq_wake_secondary(struct irq_desc *desc, struct irqaction *action)
  14231. +{
  14232. + struct irqaction *secondary = action->secondary;
  14233. +
  14234. + if (WARN_ON_ONCE(!secondary))
  14235. + return;
  14236. +
  14237. + raw_spin_lock_irq(&desc->lock);
  14238. + __irq_wake_thread(desc, secondary);
  14239. + raw_spin_unlock_irq(&desc->lock);
  14240. +}
  14241. +
  14242. /*
  14243. * Interrupt handler thread
  14244. */
  14245. @@ -907,7 +1009,15 @@
  14246. action_ret = handler_fn(desc, action);
  14247. if (action_ret == IRQ_HANDLED)
  14248. atomic_inc(&desc->threads_handled);
  14249. + if (action_ret == IRQ_WAKE_THREAD)
  14250. + irq_wake_secondary(desc, action);
  14251. +#ifdef CONFIG_PREEMPT_RT_FULL
  14252. + migrate_disable();
  14253. + add_interrupt_randomness(action->irq, 0,
  14254. + desc->random_ip ^ (unsigned long) action);
  14255. + migrate_enable();
  14256. +#endif
  14257. wake_threads_waitq(desc);
  14258. }
  14259. @@ -951,20 +1061,36 @@
  14260. }
  14261. EXPORT_SYMBOL_GPL(irq_wake_thread);
  14262. -static void irq_setup_forced_threading(struct irqaction *new)
  14263. +static int irq_setup_forced_threading(struct irqaction *new)
  14264. {
  14265. if (!force_irqthreads)
  14266. - return;
  14267. + return 0;
  14268. if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT))
  14269. - return;
  14270. + return 0;
  14271. new->flags |= IRQF_ONESHOT;
  14272. - if (!new->thread_fn) {
  14273. - set_bit(IRQTF_FORCED_THREAD, &new->thread_flags);
  14274. - new->thread_fn = new->handler;
  14275. - new->handler = irq_default_primary_handler;
  14276. - }
  14277. + /*
  14278. + * Handle the case where we have a real primary handler and a
  14279. + * thread handler. We force thread them as well by creating a
  14280. + * secondary action.
  14281. + */
  14282. + if (new->handler != irq_default_primary_handler && new->thread_fn) {
  14283. + /* Allocate the secondary action */
  14284. + new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
  14285. + if (!new->secondary)
  14286. + return -ENOMEM;
  14287. + new->secondary->handler = irq_forced_secondary_handler;
  14288. + new->secondary->thread_fn = new->thread_fn;
  14289. + new->secondary->dev_id = new->dev_id;
  14290. + new->secondary->irq = new->irq;
  14291. + new->secondary->name = new->name;
  14292. + }
  14293. + /* Deal with the primary handler */
  14294. + set_bit(IRQTF_FORCED_THREAD, &new->thread_flags);
  14295. + new->thread_fn = new->handler;
  14296. + new->handler = irq_default_primary_handler;
  14297. + return 0;
  14298. }
  14299. static int irq_request_resources(struct irq_desc *desc)
  14300. @@ -984,6 +1110,48 @@
  14301. c->irq_release_resources(d);
  14302. }
  14303. +static int
  14304. +setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
  14305. +{
  14306. + struct task_struct *t;
  14307. + struct sched_param param = {
  14308. + .sched_priority = MAX_USER_RT_PRIO/2,
  14309. + };
  14310. +
  14311. + if (!secondary) {
  14312. + t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
  14313. + new->name);
  14314. + } else {
  14315. + t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq,
  14316. + new->name);
  14317. + param.sched_priority += 1;
  14318. + }
  14319. +
  14320. + if (IS_ERR(t))
  14321. + return PTR_ERR(t);
  14322. +
  14323. + sched_setscheduler_nocheck(t, SCHED_FIFO, &param);
  14324. +
  14325. + /*
  14326. + * We keep the reference to the task struct even if
  14327. + * the thread dies to avoid that the interrupt code
  14328. + * references an already freed task_struct.
  14329. + */
  14330. + get_task_struct(t);
  14331. + new->thread = t;
  14332. + /*
  14333. + * Tell the thread to set its affinity. This is
  14334. + * important for shared interrupt handlers as we do
  14335. + * not invoke setup_affinity() for the secondary
  14336. + * handlers as everything is already set up. Even for
  14337. + * interrupts marked with IRQF_NO_BALANCE this is
  14338. + * correct as we want the thread to move to the cpu(s)
  14339. + * on which the requesting code placed the interrupt.
  14340. + */
  14341. + set_bit(IRQTF_AFFINITY, &new->thread_flags);
  14342. + return 0;
  14343. +}
  14344. +
  14345. /*
  14346. * Internal function to register an irqaction - typically used to
  14347. * allocate special interrupts that are part of the architecture.
  14348. @@ -1004,6 +1172,8 @@
  14349. if (!try_module_get(desc->owner))
  14350. return -ENODEV;
  14351. + new->irq = irq;
  14352. +
  14353. /*
  14354. * Check whether the interrupt nests into another interrupt
  14355. * thread.
  14356. @@ -1021,8 +1191,11 @@
  14357. */
  14358. new->handler = irq_nested_primary_handler;
  14359. } else {
  14360. - if (irq_settings_can_thread(desc))
  14361. - irq_setup_forced_threading(new);
  14362. + if (irq_settings_can_thread(desc)) {
  14363. + ret = irq_setup_forced_threading(new);
  14364. + if (ret)
  14365. + goto out_mput;
  14366. + }
  14367. }
  14368. /*
  14369. @@ -1031,37 +1204,14 @@
  14370. * thread.
  14371. */
  14372. if (new->thread_fn && !nested) {
  14373. - struct task_struct *t;
  14374. - static const struct sched_param param = {
  14375. - .sched_priority = MAX_USER_RT_PRIO/2,
  14376. - };
  14377. -
  14378. - t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
  14379. - new->name);
  14380. - if (IS_ERR(t)) {
  14381. - ret = PTR_ERR(t);
  14382. + ret = setup_irq_thread(new, irq, false);
  14383. + if (ret)
  14384. goto out_mput;
  14385. + if (new->secondary) {
  14386. + ret = setup_irq_thread(new->secondary, irq, true);
  14387. + if (ret)
  14388. + goto out_thread;
  14389. }
  14390. -
  14391. - sched_setscheduler_nocheck(t, SCHED_FIFO, &param);
  14392. -
  14393. - /*
  14394. - * We keep the reference to the task struct even if
  14395. - * the thread dies to avoid that the interrupt code
  14396. - * references an already freed task_struct.
  14397. - */
  14398. - get_task_struct(t);
  14399. - new->thread = t;
  14400. - /*
  14401. - * Tell the thread to set its affinity. This is
  14402. - * important for shared interrupt handlers as we do
  14403. - * not invoke setup_affinity() for the secondary
  14404. - * handlers as everything is already set up. Even for
  14405. - * interrupts marked with IRQF_NO_BALANCE this is
  14406. - * correct as we want the thread to move to the cpu(s)
  14407. - * on which the requesting code placed the interrupt.
  14408. - */
  14409. - set_bit(IRQTF_AFFINITY, &new->thread_flags);
  14410. }
  14411. if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
  14412. @@ -1221,6 +1371,9 @@
  14413. irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
  14414. }
  14415. + if (new->flags & IRQF_NO_SOFTIRQ_CALL)
  14416. + irq_settings_set_no_softirq_call(desc);
  14417. +
  14418. /* Set default affinity mask once everything is setup */
  14419. setup_affinity(irq, desc, mask);
  14420. @@ -1234,7 +1387,6 @@
  14421. irq, nmsk, omsk);
  14422. }
  14423. - new->irq = irq;
  14424. *old_ptr = new;
  14425. irq_pm_install_action(desc, new);
  14426. @@ -1260,6 +1412,8 @@
  14427. */
  14428. if (new->thread)
  14429. wake_up_process(new->thread);
  14430. + if (new->secondary)
  14431. + wake_up_process(new->secondary->thread);
  14432. register_irq_proc(irq, desc);
  14433. new->dir = NULL;
  14434. @@ -1290,6 +1444,13 @@
  14435. kthread_stop(t);
  14436. put_task_struct(t);
  14437. }
  14438. + if (new->secondary && new->secondary->thread) {
  14439. + struct task_struct *t = new->secondary->thread;
  14440. +
  14441. + new->secondary->thread = NULL;
  14442. + kthread_stop(t);
  14443. + put_task_struct(t);
  14444. + }
  14445. out_mput:
  14446. module_put(desc->owner);
  14447. return ret;
  14448. @@ -1397,9 +1558,14 @@
  14449. if (action->thread) {
  14450. kthread_stop(action->thread);
  14451. put_task_struct(action->thread);
  14452. + if (action->secondary && action->secondary->thread) {
  14453. + kthread_stop(action->secondary->thread);
  14454. + put_task_struct(action->secondary->thread);
  14455. + }
  14456. }
  14457. module_put(desc->owner);
  14458. + kfree(action->secondary);
  14459. return action;
  14460. }
  14461. @@ -1543,8 +1709,10 @@
  14462. retval = __setup_irq(irq, desc, action);
  14463. chip_bus_sync_unlock(desc);
  14464. - if (retval)
  14465. + if (retval) {
  14466. + kfree(action->secondary);
  14467. kfree(action);
  14468. + }
  14469. #ifdef CONFIG_DEBUG_SHIRQ_FIXME
  14470. if (!retval && (irqflags & IRQF_SHARED)) {
  14471. diff -Nur linux-4.1.26.orig/kernel/irq/settings.h linux-4.1.26/kernel/irq/settings.h
  14472. --- linux-4.1.26.orig/kernel/irq/settings.h 2016-06-07 01:13:11.000000000 +0200
  14473. +++ linux-4.1.26/kernel/irq/settings.h 2016-06-19 15:30:58.691297504 +0200
  14474. @@ -15,6 +15,7 @@
  14475. _IRQ_NESTED_THREAD = IRQ_NESTED_THREAD,
  14476. _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID,
  14477. _IRQ_IS_POLLED = IRQ_IS_POLLED,
  14478. + _IRQ_NO_SOFTIRQ_CALL = IRQ_NO_SOFTIRQ_CALL,
  14479. _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
  14480. };
  14481. @@ -28,6 +29,7 @@
  14482. #define IRQ_NESTED_THREAD GOT_YOU_MORON
  14483. #define IRQ_PER_CPU_DEVID GOT_YOU_MORON
  14484. #define IRQ_IS_POLLED GOT_YOU_MORON
  14485. +#define IRQ_NO_SOFTIRQ_CALL GOT_YOU_MORON
  14486. #undef IRQF_MODIFY_MASK
  14487. #define IRQF_MODIFY_MASK GOT_YOU_MORON
  14488. @@ -38,6 +40,16 @@
  14489. desc->status_use_accessors |= (set & _IRQF_MODIFY_MASK);
  14490. }
  14491. +static inline bool irq_settings_no_softirq_call(struct irq_desc *desc)
  14492. +{
  14493. + return desc->status_use_accessors & _IRQ_NO_SOFTIRQ_CALL;
  14494. +}
  14495. +
  14496. +static inline void irq_settings_set_no_softirq_call(struct irq_desc *desc)
  14497. +{
  14498. + desc->status_use_accessors |= _IRQ_NO_SOFTIRQ_CALL;
  14499. +}
  14500. +
  14501. static inline bool irq_settings_is_per_cpu(struct irq_desc *desc)
  14502. {
  14503. return desc->status_use_accessors & _IRQ_PER_CPU;
  14504. diff -Nur linux-4.1.26.orig/kernel/irq/spurious.c linux-4.1.26/kernel/irq/spurious.c
  14505. --- linux-4.1.26.orig/kernel/irq/spurious.c 2016-06-07 01:13:11.000000000 +0200
  14506. +++ linux-4.1.26/kernel/irq/spurious.c 2016-06-19 15:30:58.691297504 +0200
  14507. @@ -444,6 +444,10 @@
  14508. static int __init irqfixup_setup(char *str)
  14509. {
  14510. +#ifdef CONFIG_PREEMPT_RT_BASE
  14511. + pr_warn("irqfixup boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  14512. + return 1;
  14513. +#endif
  14514. irqfixup = 1;
  14515. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  14516. printk(KERN_WARNING "This may impact system performance.\n");
  14517. @@ -456,6 +460,10 @@
  14518. static int __init irqpoll_setup(char *str)
  14519. {
  14520. +#ifdef CONFIG_PREEMPT_RT_BASE
  14521. + pr_warn("irqpoll boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  14522. + return 1;
  14523. +#endif
  14524. irqfixup = 2;
  14525. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  14526. "enabled\n");
  14527. diff -Nur linux-4.1.26.orig/kernel/irq_work.c linux-4.1.26/kernel/irq_work.c
  14528. --- linux-4.1.26.orig/kernel/irq_work.c 2016-06-07 01:13:11.000000000 +0200
  14529. +++ linux-4.1.26/kernel/irq_work.c 2016-06-19 15:30:58.691297504 +0200
  14530. @@ -17,6 +17,7 @@
  14531. #include <linux/cpu.h>
  14532. #include <linux/notifier.h>
  14533. #include <linux/smp.h>
  14534. +#include <linux/interrupt.h>
  14535. #include <asm/processor.h>
  14536. @@ -65,6 +66,8 @@
  14537. */
  14538. bool irq_work_queue_on(struct irq_work *work, int cpu)
  14539. {
  14540. + struct llist_head *list;
  14541. +
  14542. /* All work should have been flushed before going offline */
  14543. WARN_ON_ONCE(cpu_is_offline(cpu));
  14544. @@ -75,7 +78,12 @@
  14545. if (!irq_work_claim(work))
  14546. return false;
  14547. - if (llist_add(&work->llnode, &per_cpu(raised_list, cpu)))
  14548. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL) && !(work->flags & IRQ_WORK_HARD_IRQ))
  14549. + list = &per_cpu(lazy_list, cpu);
  14550. + else
  14551. + list = &per_cpu(raised_list, cpu);
  14552. +
  14553. + if (llist_add(&work->llnode, list))
  14554. arch_send_call_function_single_ipi(cpu);
  14555. return true;
  14556. @@ -86,6 +94,9 @@
  14557. /* Enqueue the irq work @work on the current CPU */
  14558. bool irq_work_queue(struct irq_work *work)
  14559. {
  14560. + struct llist_head *list;
  14561. + bool lazy_work, realtime = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
  14562. +
  14563. /* Only queue if not already pending */
  14564. if (!irq_work_claim(work))
  14565. return false;
  14566. @@ -93,13 +104,15 @@
  14567. /* Queue the entry and raise the IPI if needed. */
  14568. preempt_disable();
  14569. - /* If the work is "lazy", handle it from next tick if any */
  14570. - if (work->flags & IRQ_WORK_LAZY) {
  14571. - if (llist_add(&work->llnode, this_cpu_ptr(&lazy_list)) &&
  14572. - tick_nohz_tick_stopped())
  14573. - arch_irq_work_raise();
  14574. - } else {
  14575. - if (llist_add(&work->llnode, this_cpu_ptr(&raised_list)))
  14576. + lazy_work = work->flags & IRQ_WORK_LAZY;
  14577. +
  14578. + if (lazy_work || (realtime && !(work->flags & IRQ_WORK_HARD_IRQ)))
  14579. + list = this_cpu_ptr(&lazy_list);
  14580. + else
  14581. + list = this_cpu_ptr(&raised_list);
  14582. +
  14583. + if (llist_add(&work->llnode, list)) {
  14584. + if (!lazy_work || tick_nohz_tick_stopped())
  14585. arch_irq_work_raise();
  14586. }
  14587. @@ -116,9 +129,8 @@
  14588. raised = this_cpu_ptr(&raised_list);
  14589. lazy = this_cpu_ptr(&lazy_list);
  14590. - if (llist_empty(raised) || arch_irq_work_has_interrupt())
  14591. - if (llist_empty(lazy))
  14592. - return false;
  14593. + if (llist_empty(raised) && llist_empty(lazy))
  14594. + return false;
  14595. /* All work should have been flushed before going offline */
  14596. WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
  14597. @@ -132,7 +144,7 @@
  14598. struct irq_work *work;
  14599. struct llist_node *llnode;
  14600. - BUG_ON(!irqs_disabled());
  14601. + BUG_ON_NONRT(!irqs_disabled());
  14602. if (llist_empty(list))
  14603. return;
  14604. @@ -169,7 +181,16 @@
  14605. void irq_work_run(void)
  14606. {
  14607. irq_work_run_list(this_cpu_ptr(&raised_list));
  14608. - irq_work_run_list(this_cpu_ptr(&lazy_list));
  14609. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) {
  14610. + /*
  14611. + * NOTE: we raise softirq via IPI for safety,
  14612. + * and execute in irq_work_tick() to move the
  14613. + * overhead from hard to soft irq context.
  14614. + */
  14615. + if (!llist_empty(this_cpu_ptr(&lazy_list)))
  14616. + raise_softirq(TIMER_SOFTIRQ);
  14617. + } else
  14618. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  14619. }
  14620. EXPORT_SYMBOL_GPL(irq_work_run);
  14621. @@ -179,8 +200,17 @@
  14622. if (!llist_empty(raised) && !arch_irq_work_has_interrupt())
  14623. irq_work_run_list(raised);
  14624. +
  14625. + if (!IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
  14626. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  14627. +}
  14628. +
  14629. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  14630. +void irq_work_tick_soft(void)
  14631. +{
  14632. irq_work_run_list(this_cpu_ptr(&lazy_list));
  14633. }
  14634. +#endif
  14635. /*
  14636. * Synchronize against the irq_work @entry, ensures the entry is not
  14637. diff -Nur linux-4.1.26.orig/kernel/Kconfig.locks linux-4.1.26/kernel/Kconfig.locks
  14638. --- linux-4.1.26.orig/kernel/Kconfig.locks 2016-06-07 01:13:11.000000000 +0200
  14639. +++ linux-4.1.26/kernel/Kconfig.locks 2016-06-19 15:30:58.683297195 +0200
  14640. @@ -225,11 +225,11 @@
  14641. config MUTEX_SPIN_ON_OWNER
  14642. def_bool y
  14643. - depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW
  14644. + depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  14645. config RWSEM_SPIN_ON_OWNER
  14646. def_bool y
  14647. - depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW
  14648. + depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  14649. config LOCK_SPIN_ON_OWNER
  14650. def_bool y
  14651. diff -Nur linux-4.1.26.orig/kernel/Kconfig.preempt linux-4.1.26/kernel/Kconfig.preempt
  14652. --- linux-4.1.26.orig/kernel/Kconfig.preempt 2016-06-07 01:13:11.000000000 +0200
  14653. +++ linux-4.1.26/kernel/Kconfig.preempt 2016-06-19 15:30:58.683297195 +0200
  14654. @@ -1,3 +1,16 @@
  14655. +config PREEMPT
  14656. + bool
  14657. + select PREEMPT_COUNT
  14658. +
  14659. +config PREEMPT_RT_BASE
  14660. + bool
  14661. + select PREEMPT
  14662. +
  14663. +config HAVE_PREEMPT_LAZY
  14664. + bool
  14665. +
  14666. +config PREEMPT_LAZY
  14667. + def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT_FULL
  14668. choice
  14669. prompt "Preemption Model"
  14670. @@ -33,9 +46,9 @@
  14671. Select this if you are building a kernel for a desktop system.
  14672. -config PREEMPT
  14673. +config PREEMPT__LL
  14674. bool "Preemptible Kernel (Low-Latency Desktop)"
  14675. - select PREEMPT_COUNT
  14676. + select PREEMPT
  14677. select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
  14678. help
  14679. This option reduces the latency of the kernel by making
  14680. @@ -52,6 +65,22 @@
  14681. embedded system with latency requirements in the milliseconds
  14682. range.
  14683. +config PREEMPT_RTB
  14684. + bool "Preemptible Kernel (Basic RT)"
  14685. + select PREEMPT_RT_BASE
  14686. + help
  14687. + This option is basically the same as (Low-Latency Desktop) but
  14688. + enables changes which are preliminary for the full preemptible
  14689. + RT kernel.
  14690. +
  14691. +config PREEMPT_RT_FULL
  14692. + bool "Fully Preemptible Kernel (RT)"
  14693. + depends on IRQ_FORCED_THREADING
  14694. + select PREEMPT_RT_BASE
  14695. + select PREEMPT_RCU
  14696. + help
  14697. + All and everything
  14698. +
  14699. endchoice
  14700. config PREEMPT_COUNT
  14701. diff -Nur linux-4.1.26.orig/kernel/ksysfs.c linux-4.1.26/kernel/ksysfs.c
  14702. --- linux-4.1.26.orig/kernel/ksysfs.c 2016-06-07 01:13:11.000000000 +0200
  14703. +++ linux-4.1.26/kernel/ksysfs.c 2016-06-19 15:30:58.691297504 +0200
  14704. @@ -136,6 +136,15 @@
  14705. #endif /* CONFIG_KEXEC */
  14706. +#if defined(CONFIG_PREEMPT_RT_FULL)
  14707. +static ssize_t realtime_show(struct kobject *kobj,
  14708. + struct kobj_attribute *attr, char *buf)
  14709. +{
  14710. + return sprintf(buf, "%d\n", 1);
  14711. +}
  14712. +KERNEL_ATTR_RO(realtime);
  14713. +#endif
  14714. +
  14715. /* whether file capabilities are enabled */
  14716. static ssize_t fscaps_show(struct kobject *kobj,
  14717. struct kobj_attribute *attr, char *buf)
  14718. @@ -203,6 +212,9 @@
  14719. &vmcoreinfo_attr.attr,
  14720. #endif
  14721. &rcu_expedited_attr.attr,
  14722. +#ifdef CONFIG_PREEMPT_RT_FULL
  14723. + &realtime_attr.attr,
  14724. +#endif
  14725. NULL
  14726. };
  14727. diff -Nur linux-4.1.26.orig/kernel/locking/lglock.c linux-4.1.26/kernel/locking/lglock.c
  14728. --- linux-4.1.26.orig/kernel/locking/lglock.c 2016-06-07 01:13:11.000000000 +0200
  14729. +++ linux-4.1.26/kernel/locking/lglock.c 2016-06-19 15:30:58.691297504 +0200
  14730. @@ -4,6 +4,15 @@
  14731. #include <linux/cpu.h>
  14732. #include <linux/string.h>
  14733. +#ifndef CONFIG_PREEMPT_RT_FULL
  14734. +# define lg_lock_ptr arch_spinlock_t
  14735. +# define lg_do_lock(l) arch_spin_lock(l)
  14736. +# define lg_do_unlock(l) arch_spin_unlock(l)
  14737. +#else
  14738. +# define lg_lock_ptr struct rt_mutex
  14739. +# define lg_do_lock(l) __rt_spin_lock(l)
  14740. +# define lg_do_unlock(l) __rt_spin_unlock(l)
  14741. +#endif
  14742. /*
  14743. * Note there is no uninit, so lglocks cannot be defined in
  14744. * modules (but it's fine to use them from there)
  14745. @@ -12,51 +21,60 @@
  14746. void lg_lock_init(struct lglock *lg, char *name)
  14747. {
  14748. +#ifdef CONFIG_PREEMPT_RT_FULL
  14749. + int i;
  14750. +
  14751. + for_each_possible_cpu(i) {
  14752. + struct rt_mutex *lock = per_cpu_ptr(lg->lock, i);
  14753. +
  14754. + rt_mutex_init(lock);
  14755. + }
  14756. +#endif
  14757. LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
  14758. }
  14759. EXPORT_SYMBOL(lg_lock_init);
  14760. void lg_local_lock(struct lglock *lg)
  14761. {
  14762. - arch_spinlock_t *lock;
  14763. + lg_lock_ptr *lock;
  14764. - preempt_disable();
  14765. + migrate_disable();
  14766. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  14767. lock = this_cpu_ptr(lg->lock);
  14768. - arch_spin_lock(lock);
  14769. + lg_do_lock(lock);
  14770. }
  14771. EXPORT_SYMBOL(lg_local_lock);
  14772. void lg_local_unlock(struct lglock *lg)
  14773. {
  14774. - arch_spinlock_t *lock;
  14775. + lg_lock_ptr *lock;
  14776. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  14777. lock = this_cpu_ptr(lg->lock);
  14778. - arch_spin_unlock(lock);
  14779. - preempt_enable();
  14780. + lg_do_unlock(lock);
  14781. + migrate_enable();
  14782. }
  14783. EXPORT_SYMBOL(lg_local_unlock);
  14784. void lg_local_lock_cpu(struct lglock *lg, int cpu)
  14785. {
  14786. - arch_spinlock_t *lock;
  14787. + lg_lock_ptr *lock;
  14788. - preempt_disable();
  14789. + preempt_disable_nort();
  14790. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  14791. lock = per_cpu_ptr(lg->lock, cpu);
  14792. - arch_spin_lock(lock);
  14793. + lg_do_lock(lock);
  14794. }
  14795. EXPORT_SYMBOL(lg_local_lock_cpu);
  14796. void lg_local_unlock_cpu(struct lglock *lg, int cpu)
  14797. {
  14798. - arch_spinlock_t *lock;
  14799. + lg_lock_ptr *lock;
  14800. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  14801. lock = per_cpu_ptr(lg->lock, cpu);
  14802. - arch_spin_unlock(lock);
  14803. - preempt_enable();
  14804. + lg_do_unlock(lock);
  14805. + preempt_enable_nort();
  14806. }
  14807. EXPORT_SYMBOL(lg_local_unlock_cpu);
  14808. @@ -64,12 +82,12 @@
  14809. {
  14810. int i;
  14811. - preempt_disable();
  14812. + preempt_disable_nort();
  14813. lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  14814. for_each_possible_cpu(i) {
  14815. - arch_spinlock_t *lock;
  14816. + lg_lock_ptr *lock;
  14817. lock = per_cpu_ptr(lg->lock, i);
  14818. - arch_spin_lock(lock);
  14819. + lg_do_lock(lock);
  14820. }
  14821. }
  14822. EXPORT_SYMBOL(lg_global_lock);
  14823. @@ -80,10 +98,35 @@
  14824. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  14825. for_each_possible_cpu(i) {
  14826. - arch_spinlock_t *lock;
  14827. + lg_lock_ptr *lock;
  14828. lock = per_cpu_ptr(lg->lock, i);
  14829. - arch_spin_unlock(lock);
  14830. + lg_do_unlock(lock);
  14831. }
  14832. - preempt_enable();
  14833. + preempt_enable_nort();
  14834. }
  14835. EXPORT_SYMBOL(lg_global_unlock);
  14836. +
  14837. +#ifdef CONFIG_PREEMPT_RT_FULL
  14838. +/*
  14839. + * HACK: If you use this, you get to keep the pieces.
  14840. + * Used in queue_stop_cpus_work() when stop machinery
  14841. + * is called from inactive CPU, so we can't schedule.
  14842. + */
  14843. +# define lg_do_trylock_relax(l) \
  14844. + do { \
  14845. + while (!__rt_spin_trylock(l)) \
  14846. + cpu_relax(); \
  14847. + } while (0)
  14848. +
  14849. +void lg_global_trylock_relax(struct lglock *lg)
  14850. +{
  14851. + int i;
  14852. +
  14853. + lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  14854. + for_each_possible_cpu(i) {
  14855. + lg_lock_ptr *lock;
  14856. + lock = per_cpu_ptr(lg->lock, i);
  14857. + lg_do_trylock_relax(lock);
  14858. + }
  14859. +}
  14860. +#endif
  14861. diff -Nur linux-4.1.26.orig/kernel/locking/lockdep.c linux-4.1.26/kernel/locking/lockdep.c
  14862. --- linux-4.1.26.orig/kernel/locking/lockdep.c 2016-06-07 01:13:11.000000000 +0200
  14863. +++ linux-4.1.26/kernel/locking/lockdep.c 2016-06-19 15:30:58.691297504 +0200
  14864. @@ -3563,6 +3563,7 @@
  14865. }
  14866. }
  14867. +#ifndef CONFIG_PREEMPT_RT_FULL
  14868. /*
  14869. * We dont accurately track softirq state in e.g.
  14870. * hardirq contexts (such as on 4KSTACKS), so only
  14871. @@ -3577,6 +3578,7 @@
  14872. DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
  14873. }
  14874. }
  14875. +#endif
  14876. if (!debug_locks)
  14877. print_irqtrace_events(current);
  14878. diff -Nur linux-4.1.26.orig/kernel/locking/locktorture.c linux-4.1.26/kernel/locking/locktorture.c
  14879. --- linux-4.1.26.orig/kernel/locking/locktorture.c 2016-06-07 01:13:11.000000000 +0200
  14880. +++ linux-4.1.26/kernel/locking/locktorture.c 2016-06-19 15:30:58.695297658 +0200
  14881. @@ -24,7 +24,6 @@
  14882. #include <linux/module.h>
  14883. #include <linux/kthread.h>
  14884. #include <linux/spinlock.h>
  14885. -#include <linux/rwlock.h>
  14886. #include <linux/mutex.h>
  14887. #include <linux/rwsem.h>
  14888. #include <linux/smp.h>
  14889. diff -Nur linux-4.1.26.orig/kernel/locking/Makefile linux-4.1.26/kernel/locking/Makefile
  14890. --- linux-4.1.26.orig/kernel/locking/Makefile 2016-06-07 01:13:11.000000000 +0200
  14891. +++ linux-4.1.26/kernel/locking/Makefile 2016-06-19 15:30:58.691297504 +0200
  14892. @@ -1,5 +1,5 @@
  14893. -obj-y += mutex.o semaphore.o rwsem.o
  14894. +obj-y += semaphore.o
  14895. ifdef CONFIG_FUNCTION_TRACER
  14896. CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE)
  14897. @@ -8,7 +8,11 @@
  14898. CFLAGS_REMOVE_rtmutex-debug.o = $(CC_FLAGS_FTRACE)
  14899. endif
  14900. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  14901. +obj-y += mutex.o
  14902. obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
  14903. +obj-y += rwsem.o
  14904. +endif
  14905. obj-$(CONFIG_LOCKDEP) += lockdep.o
  14906. ifeq ($(CONFIG_PROC_FS),y)
  14907. obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
  14908. @@ -22,8 +26,11 @@
  14909. obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
  14910. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
  14911. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
  14912. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  14913. obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
  14914. obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
  14915. +endif
  14916. obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o
  14917. +obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o
  14918. obj-$(CONFIG_QUEUE_RWLOCK) += qrwlock.o
  14919. obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
  14920. diff -Nur linux-4.1.26.orig/kernel/locking/rt.c linux-4.1.26/kernel/locking/rt.c
  14921. --- linux-4.1.26.orig/kernel/locking/rt.c 1970-01-01 01:00:00.000000000 +0100
  14922. +++ linux-4.1.26/kernel/locking/rt.c 2016-06-19 15:30:58.695297658 +0200
  14923. @@ -0,0 +1,461 @@
  14924. +/*
  14925. + * kernel/rt.c
  14926. + *
  14927. + * Real-Time Preemption Support
  14928. + *
  14929. + * started by Ingo Molnar:
  14930. + *
  14931. + * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  14932. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  14933. + *
  14934. + * historic credit for proving that Linux spinlocks can be implemented via
  14935. + * RT-aware mutexes goes to many people: The Pmutex project (Dirk Grambow
  14936. + * and others) who prototyped it on 2.4 and did lots of comparative
  14937. + * research and analysis; TimeSys, for proving that you can implement a
  14938. + * fully preemptible kernel via the use of IRQ threading and mutexes;
  14939. + * Bill Huey for persuasively arguing on lkml that the mutex model is the
  14940. + * right one; and to MontaVista, who ported pmutexes to 2.6.
  14941. + *
  14942. + * This code is a from-scratch implementation and is not based on pmutexes,
  14943. + * but the idea of converting spinlocks to mutexes is used here too.
  14944. + *
  14945. + * lock debugging, locking tree, deadlock detection:
  14946. + *
  14947. + * Copyright (C) 2004, LynuxWorks, Inc., Igor Manyilov, Bill Huey
  14948. + * Released under the General Public License (GPL).
  14949. + *
  14950. + * Includes portions of the generic R/W semaphore implementation from:
  14951. + *
  14952. + * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  14953. + * - Derived partially from idea by Andrea Arcangeli <andrea@suse.de>
  14954. + * - Derived also from comments by Linus
  14955. + *
  14956. + * Pending ownership of locks and ownership stealing:
  14957. + *
  14958. + * Copyright (C) 2005, Kihon Technologies Inc., Steven Rostedt
  14959. + *
  14960. + * (also by Steven Rostedt)
  14961. + * - Converted single pi_lock to individual task locks.
  14962. + *
  14963. + * By Esben Nielsen:
  14964. + * Doing priority inheritance with help of the scheduler.
  14965. + *
  14966. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  14967. + * - major rework based on Esben Nielsens initial patch
  14968. + * - replaced thread_info references by task_struct refs
  14969. + * - removed task->pending_owner dependency
  14970. + * - BKL drop/reacquire for semaphore style locks to avoid deadlocks
  14971. + * in the scheduler return path as discussed with Steven Rostedt
  14972. + *
  14973. + * Copyright (C) 2006, Kihon Technologies Inc.
  14974. + * Steven Rostedt <rostedt@goodmis.org>
  14975. + * - debugged and patched Thomas Gleixner's rework.
  14976. + * - added back the cmpxchg to the rework.
  14977. + * - turned atomic require back on for SMP.
  14978. + */
  14979. +
  14980. +#include <linux/spinlock.h>
  14981. +#include <linux/rtmutex.h>
  14982. +#include <linux/sched.h>
  14983. +#include <linux/delay.h>
  14984. +#include <linux/module.h>
  14985. +#include <linux/kallsyms.h>
  14986. +#include <linux/syscalls.h>
  14987. +#include <linux/interrupt.h>
  14988. +#include <linux/plist.h>
  14989. +#include <linux/fs.h>
  14990. +#include <linux/futex.h>
  14991. +#include <linux/hrtimer.h>
  14992. +
  14993. +#include "rtmutex_common.h"
  14994. +
  14995. +/*
  14996. + * struct mutex functions
  14997. + */
  14998. +void __mutex_do_init(struct mutex *mutex, const char *name,
  14999. + struct lock_class_key *key)
  15000. +{
  15001. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15002. + /*
  15003. + * Make sure we are not reinitializing a held lock:
  15004. + */
  15005. + debug_check_no_locks_freed((void *)mutex, sizeof(*mutex));
  15006. + lockdep_init_map(&mutex->dep_map, name, key, 0);
  15007. +#endif
  15008. + mutex->lock.save_state = 0;
  15009. +}
  15010. +EXPORT_SYMBOL(__mutex_do_init);
  15011. +
  15012. +void __lockfunc _mutex_lock(struct mutex *lock)
  15013. +{
  15014. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  15015. + rt_mutex_lock(&lock->lock);
  15016. +}
  15017. +EXPORT_SYMBOL(_mutex_lock);
  15018. +
  15019. +int __lockfunc _mutex_lock_interruptible(struct mutex *lock)
  15020. +{
  15021. + int ret;
  15022. +
  15023. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  15024. + ret = rt_mutex_lock_interruptible(&lock->lock);
  15025. + if (ret)
  15026. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  15027. + return ret;
  15028. +}
  15029. +EXPORT_SYMBOL(_mutex_lock_interruptible);
  15030. +
  15031. +int __lockfunc _mutex_lock_killable(struct mutex *lock)
  15032. +{
  15033. + int ret;
  15034. +
  15035. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  15036. + ret = rt_mutex_lock_killable(&lock->lock);
  15037. + if (ret)
  15038. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  15039. + return ret;
  15040. +}
  15041. +EXPORT_SYMBOL(_mutex_lock_killable);
  15042. +
  15043. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15044. +void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass)
  15045. +{
  15046. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  15047. + rt_mutex_lock(&lock->lock);
  15048. +}
  15049. +EXPORT_SYMBOL(_mutex_lock_nested);
  15050. +
  15051. +void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
  15052. +{
  15053. + mutex_acquire_nest(&lock->dep_map, 0, 0, nest, _RET_IP_);
  15054. + rt_mutex_lock(&lock->lock);
  15055. +}
  15056. +EXPORT_SYMBOL(_mutex_lock_nest_lock);
  15057. +
  15058. +int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass)
  15059. +{
  15060. + int ret;
  15061. +
  15062. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  15063. + ret = rt_mutex_lock_interruptible(&lock->lock);
  15064. + if (ret)
  15065. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  15066. + return ret;
  15067. +}
  15068. +EXPORT_SYMBOL(_mutex_lock_interruptible_nested);
  15069. +
  15070. +int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass)
  15071. +{
  15072. + int ret;
  15073. +
  15074. + mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  15075. + ret = rt_mutex_lock_killable(&lock->lock);
  15076. + if (ret)
  15077. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  15078. + return ret;
  15079. +}
  15080. +EXPORT_SYMBOL(_mutex_lock_killable_nested);
  15081. +#endif
  15082. +
  15083. +int __lockfunc _mutex_trylock(struct mutex *lock)
  15084. +{
  15085. + int ret = rt_mutex_trylock(&lock->lock);
  15086. +
  15087. + if (ret)
  15088. + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  15089. +
  15090. + return ret;
  15091. +}
  15092. +EXPORT_SYMBOL(_mutex_trylock);
  15093. +
  15094. +void __lockfunc _mutex_unlock(struct mutex *lock)
  15095. +{
  15096. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  15097. + rt_mutex_unlock(&lock->lock);
  15098. +}
  15099. +EXPORT_SYMBOL(_mutex_unlock);
  15100. +
  15101. +/*
  15102. + * rwlock_t functions
  15103. + */
  15104. +int __lockfunc rt_write_trylock(rwlock_t *rwlock)
  15105. +{
  15106. + int ret;
  15107. +
  15108. + migrate_disable();
  15109. + ret = rt_mutex_trylock(&rwlock->lock);
  15110. + if (ret)
  15111. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  15112. + else
  15113. + migrate_enable();
  15114. +
  15115. + return ret;
  15116. +}
  15117. +EXPORT_SYMBOL(rt_write_trylock);
  15118. +
  15119. +int __lockfunc rt_write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags)
  15120. +{
  15121. + int ret;
  15122. +
  15123. + *flags = 0;
  15124. + ret = rt_write_trylock(rwlock);
  15125. + return ret;
  15126. +}
  15127. +EXPORT_SYMBOL(rt_write_trylock_irqsave);
  15128. +
  15129. +int __lockfunc rt_read_trylock(rwlock_t *rwlock)
  15130. +{
  15131. + struct rt_mutex *lock = &rwlock->lock;
  15132. + int ret = 1;
  15133. +
  15134. + /*
  15135. + * recursive read locks succeed when current owns the lock,
  15136. + * but not when read_depth == 0 which means that the lock is
  15137. + * write locked.
  15138. + */
  15139. + if (rt_mutex_owner(lock) != current) {
  15140. + migrate_disable();
  15141. + ret = rt_mutex_trylock(lock);
  15142. + if (ret)
  15143. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  15144. + else
  15145. + migrate_enable();
  15146. +
  15147. + } else if (!rwlock->read_depth) {
  15148. + ret = 0;
  15149. + }
  15150. +
  15151. + if (ret)
  15152. + rwlock->read_depth++;
  15153. +
  15154. + return ret;
  15155. +}
  15156. +EXPORT_SYMBOL(rt_read_trylock);
  15157. +
  15158. +void __lockfunc rt_write_lock(rwlock_t *rwlock)
  15159. +{
  15160. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  15161. + migrate_disable();
  15162. + __rt_spin_lock(&rwlock->lock);
  15163. +}
  15164. +EXPORT_SYMBOL(rt_write_lock);
  15165. +
  15166. +void __lockfunc rt_read_lock(rwlock_t *rwlock)
  15167. +{
  15168. + struct rt_mutex *lock = &rwlock->lock;
  15169. +
  15170. +
  15171. + /*
  15172. + * recursive read locks succeed when current owns the lock
  15173. + */
  15174. + if (rt_mutex_owner(lock) != current) {
  15175. + migrate_disable();
  15176. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  15177. + __rt_spin_lock(lock);
  15178. + }
  15179. + rwlock->read_depth++;
  15180. +}
  15181. +
  15182. +EXPORT_SYMBOL(rt_read_lock);
  15183. +
  15184. +void __lockfunc rt_write_unlock(rwlock_t *rwlock)
  15185. +{
  15186. + /* NOTE: we always pass in '1' for nested, for simplicity */
  15187. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  15188. + __rt_spin_unlock(&rwlock->lock);
  15189. + migrate_enable();
  15190. +}
  15191. +EXPORT_SYMBOL(rt_write_unlock);
  15192. +
  15193. +void __lockfunc rt_read_unlock(rwlock_t *rwlock)
  15194. +{
  15195. + /* Release the lock only when read_depth is down to 0 */
  15196. + if (--rwlock->read_depth == 0) {
  15197. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  15198. + __rt_spin_unlock(&rwlock->lock);
  15199. + migrate_enable();
  15200. + }
  15201. +}
  15202. +EXPORT_SYMBOL(rt_read_unlock);
  15203. +
  15204. +unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock)
  15205. +{
  15206. + rt_write_lock(rwlock);
  15207. +
  15208. + return 0;
  15209. +}
  15210. +EXPORT_SYMBOL(rt_write_lock_irqsave);
  15211. +
  15212. +unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock)
  15213. +{
  15214. + rt_read_lock(rwlock);
  15215. +
  15216. + return 0;
  15217. +}
  15218. +EXPORT_SYMBOL(rt_read_lock_irqsave);
  15219. +
  15220. +void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key)
  15221. +{
  15222. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15223. + /*
  15224. + * Make sure we are not reinitializing a held lock:
  15225. + */
  15226. + debug_check_no_locks_freed((void *)rwlock, sizeof(*rwlock));
  15227. + lockdep_init_map(&rwlock->dep_map, name, key, 0);
  15228. +#endif
  15229. + rwlock->lock.save_state = 1;
  15230. + rwlock->read_depth = 0;
  15231. +}
  15232. +EXPORT_SYMBOL(__rt_rwlock_init);
  15233. +
  15234. +/*
  15235. + * rw_semaphores
  15236. + */
  15237. +
  15238. +void rt_up_write(struct rw_semaphore *rwsem)
  15239. +{
  15240. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  15241. + rt_mutex_unlock(&rwsem->lock);
  15242. +}
  15243. +EXPORT_SYMBOL(rt_up_write);
  15244. +
  15245. +void __rt_up_read(struct rw_semaphore *rwsem)
  15246. +{
  15247. + if (--rwsem->read_depth == 0)
  15248. + rt_mutex_unlock(&rwsem->lock);
  15249. +}
  15250. +
  15251. +void rt_up_read(struct rw_semaphore *rwsem)
  15252. +{
  15253. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  15254. + __rt_up_read(rwsem);
  15255. +}
  15256. +EXPORT_SYMBOL(rt_up_read);
  15257. +
  15258. +/*
  15259. + * downgrade a write lock into a read lock
  15260. + * - just wake up any readers at the front of the queue
  15261. + */
  15262. +void rt_downgrade_write(struct rw_semaphore *rwsem)
  15263. +{
  15264. + BUG_ON(rt_mutex_owner(&rwsem->lock) != current);
  15265. + rwsem->read_depth = 1;
  15266. +}
  15267. +EXPORT_SYMBOL(rt_downgrade_write);
  15268. +
  15269. +int rt_down_write_trylock(struct rw_semaphore *rwsem)
  15270. +{
  15271. + int ret = rt_mutex_trylock(&rwsem->lock);
  15272. +
  15273. + if (ret)
  15274. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  15275. + return ret;
  15276. +}
  15277. +EXPORT_SYMBOL(rt_down_write_trylock);
  15278. +
  15279. +void rt_down_write(struct rw_semaphore *rwsem)
  15280. +{
  15281. + rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
  15282. + rt_mutex_lock(&rwsem->lock);
  15283. +}
  15284. +EXPORT_SYMBOL(rt_down_write);
  15285. +
  15286. +void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass)
  15287. +{
  15288. + rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
  15289. + rt_mutex_lock(&rwsem->lock);
  15290. +}
  15291. +EXPORT_SYMBOL(rt_down_write_nested);
  15292. +
  15293. +void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  15294. + struct lockdep_map *nest)
  15295. +{
  15296. + rwsem_acquire_nest(&rwsem->dep_map, 0, 0, nest, _RET_IP_);
  15297. + rt_mutex_lock(&rwsem->lock);
  15298. +}
  15299. +EXPORT_SYMBOL(rt_down_write_nested_lock);
  15300. +
  15301. +int rt_down_read_trylock(struct rw_semaphore *rwsem)
  15302. +{
  15303. + struct rt_mutex *lock = &rwsem->lock;
  15304. + int ret = 1;
  15305. +
  15306. + /*
  15307. + * recursive read locks succeed when current owns the rwsem,
  15308. + * but not when read_depth == 0 which means that the rwsem is
  15309. + * write locked.
  15310. + */
  15311. + if (rt_mutex_owner(lock) != current)
  15312. + ret = rt_mutex_trylock(&rwsem->lock);
  15313. + else if (!rwsem->read_depth)
  15314. + ret = 0;
  15315. +
  15316. + if (ret) {
  15317. + rwsem->read_depth++;
  15318. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  15319. + }
  15320. + return ret;
  15321. +}
  15322. +EXPORT_SYMBOL(rt_down_read_trylock);
  15323. +
  15324. +static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
  15325. +{
  15326. + struct rt_mutex *lock = &rwsem->lock;
  15327. +
  15328. + rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
  15329. +
  15330. + if (rt_mutex_owner(lock) != current)
  15331. + rt_mutex_lock(&rwsem->lock);
  15332. + rwsem->read_depth++;
  15333. +}
  15334. +
  15335. +void rt_down_read(struct rw_semaphore *rwsem)
  15336. +{
  15337. + __rt_down_read(rwsem, 0);
  15338. +}
  15339. +EXPORT_SYMBOL(rt_down_read);
  15340. +
  15341. +void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
  15342. +{
  15343. + __rt_down_read(rwsem, subclass);
  15344. +}
  15345. +EXPORT_SYMBOL(rt_down_read_nested);
  15346. +
  15347. +void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  15348. + struct lock_class_key *key)
  15349. +{
  15350. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15351. + /*
  15352. + * Make sure we are not reinitializing a held lock:
  15353. + */
  15354. + debug_check_no_locks_freed((void *)rwsem, sizeof(*rwsem));
  15355. + lockdep_init_map(&rwsem->dep_map, name, key, 0);
  15356. +#endif
  15357. + rwsem->read_depth = 0;
  15358. + rwsem->lock.save_state = 0;
  15359. +}
  15360. +EXPORT_SYMBOL(__rt_rwsem_init);
  15361. +
  15362. +/**
  15363. + * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
  15364. + * @cnt: the atomic which we are to dec
  15365. + * @lock: the mutex to return holding if we dec to 0
  15366. + *
  15367. + * return true and hold lock if we dec to 0, return false otherwise
  15368. + */
  15369. +int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
  15370. +{
  15371. + /* dec if we can't possibly hit 0 */
  15372. + if (atomic_add_unless(cnt, -1, 1))
  15373. + return 0;
  15374. + /* we might hit 0, so take the lock */
  15375. + mutex_lock(lock);
  15376. + if (!atomic_dec_and_test(cnt)) {
  15377. + /* when we actually did the dec, we didn't hit 0 */
  15378. + mutex_unlock(lock);
  15379. + return 0;
  15380. + }
  15381. + /* we hit 0, and we hold the lock */
  15382. + return 1;
  15383. +}
  15384. +EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
  15385. diff -Nur linux-4.1.26.orig/kernel/locking/rtmutex.c linux-4.1.26/kernel/locking/rtmutex.c
  15386. --- linux-4.1.26.orig/kernel/locking/rtmutex.c 2016-06-07 01:13:11.000000000 +0200
  15387. +++ linux-4.1.26/kernel/locking/rtmutex.c 2016-06-19 15:30:58.695297658 +0200
  15388. @@ -7,6 +7,11 @@
  15389. * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  15390. * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
  15391. * Copyright (C) 2006 Esben Nielsen
  15392. + * Adaptive Spinlocks:
  15393. + * Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
  15394. + * and Peter Morreale,
  15395. + * Adaptive Spinlocks simplification:
  15396. + * Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
  15397. *
  15398. * See Documentation/locking/rt-mutex-design.txt for details.
  15399. */
  15400. @@ -16,6 +21,7 @@
  15401. #include <linux/sched/rt.h>
  15402. #include <linux/sched/deadline.h>
  15403. #include <linux/timer.h>
  15404. +#include <linux/ww_mutex.h>
  15405. #include "rtmutex_common.h"
  15406. @@ -69,6 +75,12 @@
  15407. clear_rt_mutex_waiters(lock);
  15408. }
  15409. +static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
  15410. +{
  15411. + return waiter && waiter != PI_WAKEUP_INPROGRESS &&
  15412. + waiter != PI_REQUEUE_INPROGRESS;
  15413. +}
  15414. +
  15415. /*
  15416. * We can speed up the acquire/release, if the architecture
  15417. * supports cmpxchg and if there's no debugging state to be set up
  15418. @@ -300,7 +312,7 @@
  15419. * of task. We do not use the spin_xx_mutex() variants here as we are
  15420. * outside of the debug path.)
  15421. */
  15422. -static void rt_mutex_adjust_prio(struct task_struct *task)
  15423. +void rt_mutex_adjust_prio(struct task_struct *task)
  15424. {
  15425. unsigned long flags;
  15426. @@ -335,6 +347,14 @@
  15427. return debug_rt_mutex_detect_deadlock(waiter, chwalk);
  15428. }
  15429. +static void rt_mutex_wake_waiter(struct rt_mutex_waiter *waiter)
  15430. +{
  15431. + if (waiter->savestate)
  15432. + wake_up_lock_sleeper(waiter->task);
  15433. + else
  15434. + wake_up_process(waiter->task);
  15435. +}
  15436. +
  15437. /*
  15438. * Max number of times we'll walk the boosting chain:
  15439. */
  15440. @@ -342,7 +362,8 @@
  15441. static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
  15442. {
  15443. - return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
  15444. + return rt_mutex_real_waiter(p->pi_blocked_on) ?
  15445. + p->pi_blocked_on->lock : NULL;
  15446. }
  15447. /*
  15448. @@ -479,7 +500,7 @@
  15449. * reached or the state of the chain has changed while we
  15450. * dropped the locks.
  15451. */
  15452. - if (!waiter)
  15453. + if (!rt_mutex_real_waiter(waiter))
  15454. goto out_unlock_pi;
  15455. /*
  15456. @@ -641,13 +662,16 @@
  15457. * follow here. This is the end of the chain we are walking.
  15458. */
  15459. if (!rt_mutex_owner(lock)) {
  15460. + struct rt_mutex_waiter *lock_top_waiter;
  15461. +
  15462. /*
  15463. * If the requeue [7] above changed the top waiter,
  15464. * then we need to wake the new top waiter up to try
  15465. * to get the lock.
  15466. */
  15467. - if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
  15468. - wake_up_process(rt_mutex_top_waiter(lock)->task);
  15469. + lock_top_waiter = rt_mutex_top_waiter(lock);
  15470. + if (prerequeue_top_waiter != lock_top_waiter)
  15471. + rt_mutex_wake_waiter(lock_top_waiter);
  15472. raw_spin_unlock(&lock->wait_lock);
  15473. return 0;
  15474. }
  15475. @@ -740,6 +764,25 @@
  15476. return ret;
  15477. }
  15478. +
  15479. +#define STEAL_NORMAL 0
  15480. +#define STEAL_LATERAL 1
  15481. +
  15482. +/*
  15483. + * Note that RT tasks are excluded from lateral-steals to prevent the
  15484. + * introduction of an unbounded latency
  15485. + */
  15486. +static inline int lock_is_stealable(struct task_struct *task,
  15487. + struct task_struct *pendowner, int mode)
  15488. +{
  15489. + if (mode == STEAL_NORMAL || rt_task(task)) {
  15490. + if (task->prio >= pendowner->prio)
  15491. + return 0;
  15492. + } else if (task->prio > pendowner->prio)
  15493. + return 0;
  15494. + return 1;
  15495. +}
  15496. +
  15497. /*
  15498. * Try to take an rt-mutex
  15499. *
  15500. @@ -750,8 +793,9 @@
  15501. * @waiter: The waiter that is queued to the lock's wait list if the
  15502. * callsite called task_blocked_on_lock(), otherwise NULL
  15503. */
  15504. -static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  15505. - struct rt_mutex_waiter *waiter)
  15506. +static int __try_to_take_rt_mutex(struct rt_mutex *lock,
  15507. + struct task_struct *task,
  15508. + struct rt_mutex_waiter *waiter, int mode)
  15509. {
  15510. unsigned long flags;
  15511. @@ -790,8 +834,10 @@
  15512. * If waiter is not the highest priority waiter of
  15513. * @lock, give up.
  15514. */
  15515. - if (waiter != rt_mutex_top_waiter(lock))
  15516. + if (waiter != rt_mutex_top_waiter(lock)) {
  15517. + /* XXX lock_is_stealable() ? */
  15518. return 0;
  15519. + }
  15520. /*
  15521. * We can acquire the lock. Remove the waiter from the
  15522. @@ -809,14 +855,10 @@
  15523. * not need to be dequeued.
  15524. */
  15525. if (rt_mutex_has_waiters(lock)) {
  15526. - /*
  15527. - * If @task->prio is greater than or equal to
  15528. - * the top waiter priority (kernel view),
  15529. - * @task lost.
  15530. - */
  15531. - if (task->prio >= rt_mutex_top_waiter(lock)->prio)
  15532. - return 0;
  15533. + struct task_struct *pown = rt_mutex_top_waiter(lock)->task;
  15534. + if (task != pown && !lock_is_stealable(task, pown, mode))
  15535. + return 0;
  15536. /*
  15537. * The current top waiter stays enqueued. We
  15538. * don't have to change anything in the lock
  15539. @@ -865,6 +907,347 @@
  15540. return 1;
  15541. }
  15542. +#ifdef CONFIG_PREEMPT_RT_FULL
  15543. +/*
  15544. + * preemptible spin_lock functions:
  15545. + */
  15546. +static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
  15547. + void (*slowfn)(struct rt_mutex *lock))
  15548. +{
  15549. + might_sleep_no_state_check();
  15550. +
  15551. + if (likely(rt_mutex_cmpxchg(lock, NULL, current)))
  15552. + rt_mutex_deadlock_account_lock(lock, current);
  15553. + else
  15554. + slowfn(lock);
  15555. +}
  15556. +
  15557. +static inline void rt_spin_lock_fastunlock(struct rt_mutex *lock,
  15558. + void (*slowfn)(struct rt_mutex *lock))
  15559. +{
  15560. + if (likely(rt_mutex_cmpxchg(lock, current, NULL)))
  15561. + rt_mutex_deadlock_account_unlock(current);
  15562. + else
  15563. + slowfn(lock);
  15564. +}
  15565. +#ifdef CONFIG_SMP
  15566. +/*
  15567. + * Note that owner is a speculative pointer and dereferencing relies
  15568. + * on rcu_read_lock() and the check against the lock owner.
  15569. + */
  15570. +static int adaptive_wait(struct rt_mutex *lock,
  15571. + struct task_struct *owner)
  15572. +{
  15573. + int res = 0;
  15574. +
  15575. + rcu_read_lock();
  15576. + for (;;) {
  15577. + if (owner != rt_mutex_owner(lock))
  15578. + break;
  15579. + /*
  15580. + * Ensure that owner->on_cpu is dereferenced _after_
  15581. + * checking the above to be valid.
  15582. + */
  15583. + barrier();
  15584. + if (!owner->on_cpu) {
  15585. + res = 1;
  15586. + break;
  15587. + }
  15588. + cpu_relax();
  15589. + }
  15590. + rcu_read_unlock();
  15591. + return res;
  15592. +}
  15593. +#else
  15594. +static int adaptive_wait(struct rt_mutex *lock,
  15595. + struct task_struct *orig_owner)
  15596. +{
  15597. + return 1;
  15598. +}
  15599. +#endif
  15600. +
  15601. +# define pi_lock(lock) raw_spin_lock_irq(lock)
  15602. +# define pi_unlock(lock) raw_spin_unlock_irq(lock)
  15603. +
  15604. +static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
  15605. + struct rt_mutex_waiter *waiter,
  15606. + struct task_struct *task,
  15607. + enum rtmutex_chainwalk chwalk);
  15608. +/*
  15609. + * Slow path lock function spin_lock style: this variant is very
  15610. + * careful not to miss any non-lock wakeups.
  15611. + *
  15612. + * We store the current state under p->pi_lock in p->saved_state and
  15613. + * the try_to_wake_up() code handles this accordingly.
  15614. + */
  15615. +static void noinline __sched rt_spin_lock_slowlock(struct rt_mutex *lock)
  15616. +{
  15617. + struct task_struct *lock_owner, *self = current;
  15618. + struct rt_mutex_waiter waiter, *top_waiter;
  15619. + int ret;
  15620. +
  15621. + rt_mutex_init_waiter(&waiter, true);
  15622. +
  15623. + raw_spin_lock(&lock->wait_lock);
  15624. +
  15625. + if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL)) {
  15626. + raw_spin_unlock(&lock->wait_lock);
  15627. + return;
  15628. + }
  15629. +
  15630. + BUG_ON(rt_mutex_owner(lock) == self);
  15631. +
  15632. + /*
  15633. + * We save whatever state the task is in and we'll restore it
  15634. + * after acquiring the lock taking real wakeups into account
  15635. + * as well. We are serialized via pi_lock against wakeups. See
  15636. + * try_to_wake_up().
  15637. + */
  15638. + pi_lock(&self->pi_lock);
  15639. + self->saved_state = self->state;
  15640. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  15641. + pi_unlock(&self->pi_lock);
  15642. +
  15643. + ret = task_blocks_on_rt_mutex(lock, &waiter, self, RT_MUTEX_MIN_CHAINWALK);
  15644. + BUG_ON(ret);
  15645. +
  15646. + for (;;) {
  15647. + /* Try to acquire the lock again. */
  15648. + if (__try_to_take_rt_mutex(lock, self, &waiter, STEAL_LATERAL))
  15649. + break;
  15650. +
  15651. + top_waiter = rt_mutex_top_waiter(lock);
  15652. + lock_owner = rt_mutex_owner(lock);
  15653. +
  15654. + raw_spin_unlock(&lock->wait_lock);
  15655. +
  15656. + debug_rt_mutex_print_deadlock(&waiter);
  15657. +
  15658. + if (top_waiter != &waiter || adaptive_wait(lock, lock_owner))
  15659. + schedule_rt_mutex(lock);
  15660. +
  15661. + raw_spin_lock(&lock->wait_lock);
  15662. +
  15663. + pi_lock(&self->pi_lock);
  15664. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  15665. + pi_unlock(&self->pi_lock);
  15666. + }
  15667. +
  15668. + /*
  15669. + * Restore the task state to current->saved_state. We set it
  15670. + * to the original state above and the try_to_wake_up() code
  15671. + * has possibly updated it when a real (non-rtmutex) wakeup
  15672. + * happened while we were blocked. Clear saved_state so
  15673. + * try_to_wakeup() does not get confused.
  15674. + */
  15675. + pi_lock(&self->pi_lock);
  15676. + __set_current_state_no_track(self->saved_state);
  15677. + self->saved_state = TASK_RUNNING;
  15678. + pi_unlock(&self->pi_lock);
  15679. +
  15680. + /*
  15681. + * try_to_take_rt_mutex() sets the waiter bit
  15682. + * unconditionally. We might have to fix that up:
  15683. + */
  15684. + fixup_rt_mutex_waiters(lock);
  15685. +
  15686. + BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
  15687. + BUG_ON(!RB_EMPTY_NODE(&waiter.tree_entry));
  15688. +
  15689. + raw_spin_unlock(&lock->wait_lock);
  15690. +
  15691. + debug_rt_mutex_free_waiter(&waiter);
  15692. +}
  15693. +
  15694. +static void wakeup_next_waiter(struct rt_mutex *lock);
  15695. +/*
  15696. + * Slow path to release a rt_mutex spin_lock style
  15697. + */
  15698. +static void noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
  15699. +{
  15700. + raw_spin_lock(&lock->wait_lock);
  15701. +
  15702. + debug_rt_mutex_unlock(lock);
  15703. +
  15704. + rt_mutex_deadlock_account_unlock(current);
  15705. +
  15706. + if (!rt_mutex_has_waiters(lock)) {
  15707. + lock->owner = NULL;
  15708. + raw_spin_unlock(&lock->wait_lock);
  15709. + return;
  15710. + }
  15711. +
  15712. + wakeup_next_waiter(lock);
  15713. +
  15714. + raw_spin_unlock(&lock->wait_lock);
  15715. +
  15716. + /* Undo pi boosting.when necessary */
  15717. + rt_mutex_adjust_prio(current);
  15718. +}
  15719. +
  15720. +void __lockfunc rt_spin_lock(spinlock_t *lock)
  15721. +{
  15722. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
  15723. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  15724. +}
  15725. +EXPORT_SYMBOL(rt_spin_lock);
  15726. +
  15727. +void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
  15728. +{
  15729. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock);
  15730. +}
  15731. +EXPORT_SYMBOL(__rt_spin_lock);
  15732. +
  15733. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15734. +void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
  15735. +{
  15736. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
  15737. + spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  15738. +}
  15739. +EXPORT_SYMBOL(rt_spin_lock_nested);
  15740. +#endif
  15741. +
  15742. +void __lockfunc rt_spin_unlock(spinlock_t *lock)
  15743. +{
  15744. + /* NOTE: we always pass in '1' for nested, for simplicity */
  15745. + spin_release(&lock->dep_map, 1, _RET_IP_);
  15746. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  15747. +}
  15748. +EXPORT_SYMBOL(rt_spin_unlock);
  15749. +
  15750. +void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
  15751. +{
  15752. + rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
  15753. +}
  15754. +EXPORT_SYMBOL(__rt_spin_unlock);
  15755. +
  15756. +/*
  15757. + * Wait for the lock to get unlocked: instead of polling for an unlock
  15758. + * (like raw spinlocks do), we lock and unlock, to force the kernel to
  15759. + * schedule if there's contention:
  15760. + */
  15761. +void __lockfunc rt_spin_unlock_wait(spinlock_t *lock)
  15762. +{
  15763. + spin_lock(lock);
  15764. + spin_unlock(lock);
  15765. +}
  15766. +EXPORT_SYMBOL(rt_spin_unlock_wait);
  15767. +
  15768. +int __lockfunc __rt_spin_trylock(struct rt_mutex *lock)
  15769. +{
  15770. + return rt_mutex_trylock(lock);
  15771. +}
  15772. +
  15773. +int __lockfunc rt_spin_trylock(spinlock_t *lock)
  15774. +{
  15775. + int ret = rt_mutex_trylock(&lock->lock);
  15776. +
  15777. + if (ret)
  15778. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  15779. + return ret;
  15780. +}
  15781. +EXPORT_SYMBOL(rt_spin_trylock);
  15782. +
  15783. +int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
  15784. +{
  15785. + int ret;
  15786. +
  15787. + local_bh_disable();
  15788. + ret = rt_mutex_trylock(&lock->lock);
  15789. + if (ret) {
  15790. + migrate_disable();
  15791. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  15792. + } else
  15793. + local_bh_enable();
  15794. + return ret;
  15795. +}
  15796. +EXPORT_SYMBOL(rt_spin_trylock_bh);
  15797. +
  15798. +int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags)
  15799. +{
  15800. + int ret;
  15801. +
  15802. + *flags = 0;
  15803. + ret = rt_mutex_trylock(&lock->lock);
  15804. + if (ret) {
  15805. + migrate_disable();
  15806. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  15807. + }
  15808. + return ret;
  15809. +}
  15810. +EXPORT_SYMBOL(rt_spin_trylock_irqsave);
  15811. +
  15812. +int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock)
  15813. +{
  15814. + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
  15815. + if (atomic_add_unless(atomic, -1, 1))
  15816. + return 0;
  15817. + migrate_disable();
  15818. + rt_spin_lock(lock);
  15819. + if (atomic_dec_and_test(atomic))
  15820. + return 1;
  15821. + rt_spin_unlock(lock);
  15822. + migrate_enable();
  15823. + return 0;
  15824. +}
  15825. +EXPORT_SYMBOL(atomic_dec_and_spin_lock);
  15826. +
  15827. + void
  15828. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key)
  15829. +{
  15830. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  15831. + /*
  15832. + * Make sure we are not reinitializing a held lock:
  15833. + */
  15834. + debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  15835. + lockdep_init_map(&lock->dep_map, name, key, 0);
  15836. +#endif
  15837. +}
  15838. +EXPORT_SYMBOL(__rt_spin_lock_init);
  15839. +
  15840. +#endif /* PREEMPT_RT_FULL */
  15841. +
  15842. +#ifdef CONFIG_PREEMPT_RT_FULL
  15843. + static inline int __sched
  15844. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  15845. +{
  15846. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  15847. + struct ww_acquire_ctx *hold_ctx = ACCESS_ONCE(ww->ctx);
  15848. +
  15849. + if (!hold_ctx)
  15850. + return 0;
  15851. +
  15852. + if (unlikely(ctx == hold_ctx))
  15853. + return -EALREADY;
  15854. +
  15855. + if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
  15856. + (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
  15857. +#ifdef CONFIG_DEBUG_MUTEXES
  15858. + DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
  15859. + ctx->contending_lock = ww;
  15860. +#endif
  15861. + return -EDEADLK;
  15862. + }
  15863. +
  15864. + return 0;
  15865. +}
  15866. +#else
  15867. + static inline int __sched
  15868. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  15869. +{
  15870. + BUG();
  15871. + return 0;
  15872. +}
  15873. +
  15874. +#endif
  15875. +
  15876. +static inline int
  15877. +try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  15878. + struct rt_mutex_waiter *waiter)
  15879. +{
  15880. + return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
  15881. +}
  15882. +
  15883. /*
  15884. * Task blocks on lock.
  15885. *
  15886. @@ -896,6 +1279,23 @@
  15887. return -EDEADLK;
  15888. raw_spin_lock_irqsave(&task->pi_lock, flags);
  15889. +
  15890. + /*
  15891. + * In the case of futex requeue PI, this will be a proxy
  15892. + * lock. The task will wake unaware that it is enqueueed on
  15893. + * this lock. Avoid blocking on two locks and corrupting
  15894. + * pi_blocked_on via the PI_WAKEUP_INPROGRESS
  15895. + * flag. futex_wait_requeue_pi() sets this when it wakes up
  15896. + * before requeue (due to a signal or timeout). Do not enqueue
  15897. + * the task if PI_WAKEUP_INPROGRESS is set.
  15898. + */
  15899. + if (task != current && task->pi_blocked_on == PI_WAKEUP_INPROGRESS) {
  15900. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  15901. + return -EAGAIN;
  15902. + }
  15903. +
  15904. + BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
  15905. +
  15906. __rt_mutex_adjust_prio(task);
  15907. waiter->task = task;
  15908. waiter->lock = lock;
  15909. @@ -919,7 +1319,7 @@
  15910. rt_mutex_enqueue_pi(owner, waiter);
  15911. __rt_mutex_adjust_prio(owner);
  15912. - if (owner->pi_blocked_on)
  15913. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  15914. chain_walk = 1;
  15915. } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
  15916. chain_walk = 1;
  15917. @@ -957,8 +1357,9 @@
  15918. /*
  15919. * Wake up the next waiter on the lock.
  15920. *
  15921. - * Remove the top waiter from the current tasks pi waiter list and
  15922. - * wake it up.
  15923. + * Remove the top waiter from the current tasks pi waiter list,
  15924. + * wake it up and return whether the current task needs to undo
  15925. + * a potential priority boosting.
  15926. *
  15927. * Called with lock->wait_lock held.
  15928. */
  15929. @@ -996,7 +1397,7 @@
  15930. * long as we hold lock->wait_lock. The waiter task needs to
  15931. * acquire it in order to dequeue the waiter.
  15932. */
  15933. - wake_up_process(waiter->task);
  15934. + rt_mutex_wake_waiter(waiter);
  15935. }
  15936. /*
  15937. @@ -1010,7 +1411,7 @@
  15938. {
  15939. bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
  15940. struct task_struct *owner = rt_mutex_owner(lock);
  15941. - struct rt_mutex *next_lock;
  15942. + struct rt_mutex *next_lock = NULL;
  15943. unsigned long flags;
  15944. raw_spin_lock_irqsave(&current->pi_lock, flags);
  15945. @@ -1035,7 +1436,8 @@
  15946. __rt_mutex_adjust_prio(owner);
  15947. /* Store the lock on which owner is blocked or NULL */
  15948. - next_lock = task_blocked_on_lock(owner);
  15949. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  15950. + next_lock = task_blocked_on_lock(owner);
  15951. raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
  15952. @@ -1071,17 +1473,17 @@
  15953. raw_spin_lock_irqsave(&task->pi_lock, flags);
  15954. waiter = task->pi_blocked_on;
  15955. - if (!waiter || (waiter->prio == task->prio &&
  15956. + if (!rt_mutex_real_waiter(waiter) || (waiter->prio == task->prio &&
  15957. !dl_prio(task->prio))) {
  15958. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  15959. return;
  15960. }
  15961. next_lock = waiter->lock;
  15962. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  15963. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  15964. get_task_struct(task);
  15965. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  15966. rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
  15967. next_lock, NULL, task);
  15968. }
  15969. @@ -1099,7 +1501,8 @@
  15970. static int __sched
  15971. __rt_mutex_slowlock(struct rt_mutex *lock, int state,
  15972. struct hrtimer_sleeper *timeout,
  15973. - struct rt_mutex_waiter *waiter)
  15974. + struct rt_mutex_waiter *waiter,
  15975. + struct ww_acquire_ctx *ww_ctx)
  15976. {
  15977. int ret = 0;
  15978. @@ -1122,6 +1525,12 @@
  15979. break;
  15980. }
  15981. + if (ww_ctx && ww_ctx->acquired > 0) {
  15982. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  15983. + if (ret)
  15984. + break;
  15985. + }
  15986. +
  15987. raw_spin_unlock(&lock->wait_lock);
  15988. debug_rt_mutex_print_deadlock(waiter);
  15989. @@ -1156,25 +1565,102 @@
  15990. }
  15991. }
  15992. +static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
  15993. + struct ww_acquire_ctx *ww_ctx)
  15994. +{
  15995. +#ifdef CONFIG_DEBUG_MUTEXES
  15996. + /*
  15997. + * If this WARN_ON triggers, you used ww_mutex_lock to acquire,
  15998. + * but released with a normal mutex_unlock in this call.
  15999. + *
  16000. + * This should never happen, always use ww_mutex_unlock.
  16001. + */
  16002. + DEBUG_LOCKS_WARN_ON(ww->ctx);
  16003. +
  16004. + /*
  16005. + * Not quite done after calling ww_acquire_done() ?
  16006. + */
  16007. + DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire);
  16008. +
  16009. + if (ww_ctx->contending_lock) {
  16010. + /*
  16011. + * After -EDEADLK you tried to
  16012. + * acquire a different ww_mutex? Bad!
  16013. + */
  16014. + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww);
  16015. +
  16016. + /*
  16017. + * You called ww_mutex_lock after receiving -EDEADLK,
  16018. + * but 'forgot' to unlock everything else first?
  16019. + */
  16020. + DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0);
  16021. + ww_ctx->contending_lock = NULL;
  16022. + }
  16023. +
  16024. + /*
  16025. + * Naughty, using a different class will lead to undefined behavior!
  16026. + */
  16027. + DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class);
  16028. +#endif
  16029. + ww_ctx->acquired++;
  16030. +}
  16031. +
  16032. +#ifdef CONFIG_PREEMPT_RT_FULL
  16033. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  16034. + struct ww_acquire_ctx *ww_ctx)
  16035. +{
  16036. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  16037. + struct rt_mutex_waiter *waiter, *n;
  16038. +
  16039. + /*
  16040. + * This branch gets optimized out for the common case,
  16041. + * and is only important for ww_mutex_lock.
  16042. + */
  16043. + ww_mutex_lock_acquired(ww, ww_ctx);
  16044. + ww->ctx = ww_ctx;
  16045. +
  16046. + /*
  16047. + * Give any possible sleeping processes the chance to wake up,
  16048. + * so they can recheck if they have to back off.
  16049. + */
  16050. + rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters,
  16051. + tree_entry) {
  16052. + /* XXX debug rt mutex waiter wakeup */
  16053. +
  16054. + BUG_ON(waiter->lock != lock);
  16055. + rt_mutex_wake_waiter(waiter);
  16056. + }
  16057. +}
  16058. +
  16059. +#else
  16060. +
  16061. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  16062. + struct ww_acquire_ctx *ww_ctx)
  16063. +{
  16064. + BUG();
  16065. +}
  16066. +#endif
  16067. +
  16068. /*
  16069. * Slow path lock function:
  16070. */
  16071. static int __sched
  16072. rt_mutex_slowlock(struct rt_mutex *lock, int state,
  16073. struct hrtimer_sleeper *timeout,
  16074. - enum rtmutex_chainwalk chwalk)
  16075. + enum rtmutex_chainwalk chwalk,
  16076. + struct ww_acquire_ctx *ww_ctx)
  16077. {
  16078. struct rt_mutex_waiter waiter;
  16079. int ret = 0;
  16080. - debug_rt_mutex_init_waiter(&waiter);
  16081. - RB_CLEAR_NODE(&waiter.pi_tree_entry);
  16082. - RB_CLEAR_NODE(&waiter.tree_entry);
  16083. + rt_mutex_init_waiter(&waiter, false);
  16084. raw_spin_lock(&lock->wait_lock);
  16085. /* Try to acquire the lock again: */
  16086. if (try_to_take_rt_mutex(lock, current, NULL)) {
  16087. + if (ww_ctx)
  16088. + ww_mutex_account_lock(lock, ww_ctx);
  16089. raw_spin_unlock(&lock->wait_lock);
  16090. return 0;
  16091. }
  16092. @@ -1192,13 +1678,23 @@
  16093. if (likely(!ret))
  16094. /* sleep on the mutex */
  16095. - ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
  16096. + ret = __rt_mutex_slowlock(lock, state, timeout, &waiter,
  16097. + ww_ctx);
  16098. + else if (ww_ctx) {
  16099. + /* ww_mutex received EDEADLK, let it become EALREADY */
  16100. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  16101. + BUG_ON(!ret);
  16102. + }
  16103. if (unlikely(ret)) {
  16104. __set_current_state(TASK_RUNNING);
  16105. if (rt_mutex_has_waiters(lock))
  16106. remove_waiter(lock, &waiter);
  16107. - rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  16108. + /* ww_mutex want to report EDEADLK/EALREADY, let them */
  16109. + if (!ww_ctx)
  16110. + rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  16111. + } else if (ww_ctx) {
  16112. + ww_mutex_account_lock(lock, ww_ctx);
  16113. }
  16114. /*
  16115. @@ -1255,7 +1751,7 @@
  16116. /*
  16117. * Slow path to release a rt-mutex:
  16118. */
  16119. -static void __sched
  16120. +static bool __sched
  16121. rt_mutex_slowunlock(struct rt_mutex *lock)
  16122. {
  16123. raw_spin_lock(&lock->wait_lock);
  16124. @@ -1298,7 +1794,7 @@
  16125. while (!rt_mutex_has_waiters(lock)) {
  16126. /* Drops lock->wait_lock ! */
  16127. if (unlock_rt_mutex_safe(lock) == true)
  16128. - return;
  16129. + return false;
  16130. /* Relock the rtmutex and try again */
  16131. raw_spin_lock(&lock->wait_lock);
  16132. }
  16133. @@ -1311,8 +1807,7 @@
  16134. raw_spin_unlock(&lock->wait_lock);
  16135. - /* Undo pi boosting if necessary: */
  16136. - rt_mutex_adjust_prio(current);
  16137. + return true;
  16138. }
  16139. /*
  16140. @@ -1323,31 +1818,36 @@
  16141. */
  16142. static inline int
  16143. rt_mutex_fastlock(struct rt_mutex *lock, int state,
  16144. + struct ww_acquire_ctx *ww_ctx,
  16145. int (*slowfn)(struct rt_mutex *lock, int state,
  16146. struct hrtimer_sleeper *timeout,
  16147. - enum rtmutex_chainwalk chwalk))
  16148. + enum rtmutex_chainwalk chwalk,
  16149. + struct ww_acquire_ctx *ww_ctx))
  16150. {
  16151. if (likely(rt_mutex_cmpxchg(lock, NULL, current))) {
  16152. rt_mutex_deadlock_account_lock(lock, current);
  16153. return 0;
  16154. } else
  16155. - return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
  16156. + return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK,
  16157. + ww_ctx);
  16158. }
  16159. static inline int
  16160. rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
  16161. struct hrtimer_sleeper *timeout,
  16162. enum rtmutex_chainwalk chwalk,
  16163. + struct ww_acquire_ctx *ww_ctx,
  16164. int (*slowfn)(struct rt_mutex *lock, int state,
  16165. struct hrtimer_sleeper *timeout,
  16166. - enum rtmutex_chainwalk chwalk))
  16167. + enum rtmutex_chainwalk chwalk,
  16168. + struct ww_acquire_ctx *ww_ctx))
  16169. {
  16170. if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
  16171. likely(rt_mutex_cmpxchg(lock, NULL, current))) {
  16172. rt_mutex_deadlock_account_lock(lock, current);
  16173. return 0;
  16174. } else
  16175. - return slowfn(lock, state, timeout, chwalk);
  16176. + return slowfn(lock, state, timeout, chwalk, ww_ctx);
  16177. }
  16178. static inline int
  16179. @@ -1363,12 +1863,14 @@
  16180. static inline void
  16181. rt_mutex_fastunlock(struct rt_mutex *lock,
  16182. - void (*slowfn)(struct rt_mutex *lock))
  16183. + bool (*slowfn)(struct rt_mutex *lock))
  16184. {
  16185. - if (likely(rt_mutex_cmpxchg(lock, current, NULL)))
  16186. + if (likely(rt_mutex_cmpxchg(lock, current, NULL))) {
  16187. rt_mutex_deadlock_account_unlock(current);
  16188. - else
  16189. - slowfn(lock);
  16190. + } else if (slowfn(lock)) {
  16191. + /* Undo pi boosting if necessary: */
  16192. + rt_mutex_adjust_prio(current);
  16193. + }
  16194. }
  16195. /**
  16196. @@ -1380,7 +1882,7 @@
  16197. {
  16198. might_sleep();
  16199. - rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
  16200. + rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock);
  16201. }
  16202. EXPORT_SYMBOL_GPL(rt_mutex_lock);
  16203. @@ -1397,7 +1899,7 @@
  16204. {
  16205. might_sleep();
  16206. - return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
  16207. + return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock);
  16208. }
  16209. EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  16210. @@ -1410,11 +1912,30 @@
  16211. might_sleep();
  16212. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  16213. - RT_MUTEX_FULL_CHAINWALK,
  16214. + RT_MUTEX_FULL_CHAINWALK, NULL,
  16215. rt_mutex_slowlock);
  16216. }
  16217. /**
  16218. + * rt_mutex_lock_killable - lock a rt_mutex killable
  16219. + *
  16220. + * @lock: the rt_mutex to be locked
  16221. + * @detect_deadlock: deadlock detection on/off
  16222. + *
  16223. + * Returns:
  16224. + * 0 on success
  16225. + * -EINTR when interrupted by a signal
  16226. + * -EDEADLK when the lock would deadlock (when deadlock detection is on)
  16227. + */
  16228. +int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
  16229. +{
  16230. + might_sleep();
  16231. +
  16232. + return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock);
  16233. +}
  16234. +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
  16235. +
  16236. +/**
  16237. * rt_mutex_timed_lock - lock a rt_mutex interruptible
  16238. * the timeout structure is provided
  16239. * by the caller
  16240. @@ -1434,6 +1955,7 @@
  16241. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  16242. RT_MUTEX_MIN_CHAINWALK,
  16243. + NULL,
  16244. rt_mutex_slowlock);
  16245. }
  16246. EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
  16247. @@ -1463,6 +1985,22 @@
  16248. EXPORT_SYMBOL_GPL(rt_mutex_unlock);
  16249. /**
  16250. + * rt_mutex_futex_unlock - Futex variant of rt_mutex_unlock
  16251. + * @lock: the rt_mutex to be unlocked
  16252. + *
  16253. + * Returns: true/false indicating whether priority adjustment is
  16254. + * required or not.
  16255. + */
  16256. +bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock)
  16257. +{
  16258. + if (likely(rt_mutex_cmpxchg(lock, current, NULL))) {
  16259. + rt_mutex_deadlock_account_unlock(current);
  16260. + return false;
  16261. + }
  16262. + return rt_mutex_slowunlock(lock);
  16263. +}
  16264. +
  16265. +/**
  16266. * rt_mutex_destroy - mark a mutex unusable
  16267. * @lock: the mutex to be destroyed
  16268. *
  16269. @@ -1492,13 +2030,12 @@
  16270. void __rt_mutex_init(struct rt_mutex *lock, const char *name)
  16271. {
  16272. lock->owner = NULL;
  16273. - raw_spin_lock_init(&lock->wait_lock);
  16274. lock->waiters = RB_ROOT;
  16275. lock->waiters_leftmost = NULL;
  16276. debug_rt_mutex_init(lock, name);
  16277. }
  16278. -EXPORT_SYMBOL_GPL(__rt_mutex_init);
  16279. +EXPORT_SYMBOL(__rt_mutex_init);
  16280. /**
  16281. * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  16282. @@ -1513,7 +2050,7 @@
  16283. void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  16284. struct task_struct *proxy_owner)
  16285. {
  16286. - __rt_mutex_init(lock, NULL);
  16287. + rt_mutex_init(lock);
  16288. debug_rt_mutex_proxy_lock(lock, proxy_owner);
  16289. rt_mutex_set_owner(lock, proxy_owner);
  16290. rt_mutex_deadlock_account_lock(lock, proxy_owner);
  16291. @@ -1561,6 +2098,35 @@
  16292. return 1;
  16293. }
  16294. +#ifdef CONFIG_PREEMPT_RT_FULL
  16295. + /*
  16296. + * In PREEMPT_RT there's an added race.
  16297. + * If the task, that we are about to requeue, times out,
  16298. + * it can set the PI_WAKEUP_INPROGRESS. This tells the requeue
  16299. + * to skip this task. But right after the task sets
  16300. + * its pi_blocked_on to PI_WAKEUP_INPROGRESS it can then
  16301. + * block on the spin_lock(&hb->lock), which in RT is an rtmutex.
  16302. + * This will replace the PI_WAKEUP_INPROGRESS with the actual
  16303. + * lock that it blocks on. We *must not* place this task
  16304. + * on this proxy lock in that case.
  16305. + *
  16306. + * To prevent this race, we first take the task's pi_lock
  16307. + * and check if it has updated its pi_blocked_on. If it has,
  16308. + * we assume that it woke up and we return -EAGAIN.
  16309. + * Otherwise, we set the task's pi_blocked_on to
  16310. + * PI_REQUEUE_INPROGRESS, so that if the task is waking up
  16311. + * it will know that we are in the process of requeuing it.
  16312. + */
  16313. + raw_spin_lock_irq(&task->pi_lock);
  16314. + if (task->pi_blocked_on) {
  16315. + raw_spin_unlock_irq(&task->pi_lock);
  16316. + raw_spin_unlock(&lock->wait_lock);
  16317. + return -EAGAIN;
  16318. + }
  16319. + task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
  16320. + raw_spin_unlock_irq(&task->pi_lock);
  16321. +#endif
  16322. +
  16323. /* We enforce deadlock detection for futexes */
  16324. ret = task_blocks_on_rt_mutex(lock, waiter, task,
  16325. RT_MUTEX_FULL_CHAINWALK);
  16326. @@ -1575,7 +2141,7 @@
  16327. ret = 0;
  16328. }
  16329. - if (unlikely(ret))
  16330. + if (ret && rt_mutex_has_waiters(lock))
  16331. remove_waiter(lock, waiter);
  16332. raw_spin_unlock(&lock->wait_lock);
  16333. @@ -1631,7 +2197,7 @@
  16334. set_current_state(TASK_INTERRUPTIBLE);
  16335. /* sleep on the mutex */
  16336. - ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
  16337. + ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
  16338. if (unlikely(ret))
  16339. remove_waiter(lock, waiter);
  16340. @@ -1646,3 +2212,89 @@
  16341. return ret;
  16342. }
  16343. +
  16344. +static inline int
  16345. +ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
  16346. +{
  16347. +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  16348. + unsigned tmp;
  16349. +
  16350. + if (ctx->deadlock_inject_countdown-- == 0) {
  16351. + tmp = ctx->deadlock_inject_interval;
  16352. + if (tmp > UINT_MAX/4)
  16353. + tmp = UINT_MAX;
  16354. + else
  16355. + tmp = tmp*2 + tmp + tmp/2;
  16356. +
  16357. + ctx->deadlock_inject_interval = tmp;
  16358. + ctx->deadlock_inject_countdown = tmp;
  16359. + ctx->contending_lock = lock;
  16360. +
  16361. + ww_mutex_unlock(lock);
  16362. +
  16363. + return -EDEADLK;
  16364. + }
  16365. +#endif
  16366. +
  16367. + return 0;
  16368. +}
  16369. +
  16370. +#ifdef CONFIG_PREEMPT_RT_FULL
  16371. +int __sched
  16372. +__ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  16373. +{
  16374. + int ret;
  16375. +
  16376. + might_sleep();
  16377. +
  16378. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  16379. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
  16380. + if (ret)
  16381. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  16382. + else if (!ret && ww_ctx->acquired > 1)
  16383. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  16384. +
  16385. + return ret;
  16386. +}
  16387. +EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
  16388. +
  16389. +int __sched
  16390. +__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  16391. +{
  16392. + int ret;
  16393. +
  16394. + might_sleep();
  16395. +
  16396. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  16397. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
  16398. + if (ret)
  16399. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  16400. + else if (!ret && ww_ctx->acquired > 1)
  16401. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  16402. +
  16403. + return ret;
  16404. +}
  16405. +EXPORT_SYMBOL_GPL(__ww_mutex_lock);
  16406. +
  16407. +void __sched ww_mutex_unlock(struct ww_mutex *lock)
  16408. +{
  16409. + int nest = !!lock->ctx;
  16410. +
  16411. + /*
  16412. + * The unlocking fastpath is the 0->1 transition from 'locked'
  16413. + * into 'unlocked' state:
  16414. + */
  16415. + if (nest) {
  16416. +#ifdef CONFIG_DEBUG_MUTEXES
  16417. + DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
  16418. +#endif
  16419. + if (lock->ctx->acquired > 0)
  16420. + lock->ctx->acquired--;
  16421. + lock->ctx = NULL;
  16422. + }
  16423. +
  16424. + mutex_release(&lock->base.dep_map, nest, _RET_IP_);
  16425. + rt_mutex_unlock(&lock->base.lock);
  16426. +}
  16427. +EXPORT_SYMBOL(ww_mutex_unlock);
  16428. +#endif
  16429. diff -Nur linux-4.1.26.orig/kernel/locking/rtmutex_common.h linux-4.1.26/kernel/locking/rtmutex_common.h
  16430. --- linux-4.1.26.orig/kernel/locking/rtmutex_common.h 2016-06-07 01:13:11.000000000 +0200
  16431. +++ linux-4.1.26/kernel/locking/rtmutex_common.h 2016-06-19 15:30:58.695297658 +0200
  16432. @@ -49,6 +49,7 @@
  16433. struct rb_node pi_tree_entry;
  16434. struct task_struct *task;
  16435. struct rt_mutex *lock;
  16436. + bool savestate;
  16437. #ifdef CONFIG_DEBUG_RT_MUTEXES
  16438. unsigned long ip;
  16439. struct pid *deadlock_task_pid;
  16440. @@ -119,6 +120,9 @@
  16441. /*
  16442. * PI-futex support (proxy locking functions, etc.):
  16443. */
  16444. +#define PI_WAKEUP_INPROGRESS ((struct rt_mutex_waiter *) 1)
  16445. +#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
  16446. +
  16447. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  16448. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  16449. struct task_struct *proxy_owner);
  16450. @@ -132,10 +136,24 @@
  16451. struct rt_mutex_waiter *waiter);
  16452. extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
  16453. +extern bool rt_mutex_futex_unlock(struct rt_mutex *lock);
  16454. +
  16455. +extern void rt_mutex_adjust_prio(struct task_struct *task);
  16456. +
  16457. #ifdef CONFIG_DEBUG_RT_MUTEXES
  16458. # include "rtmutex-debug.h"
  16459. #else
  16460. # include "rtmutex.h"
  16461. #endif
  16462. +static inline void
  16463. +rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
  16464. +{
  16465. + debug_rt_mutex_init_waiter(waiter);
  16466. + waiter->task = NULL;
  16467. + waiter->savestate = savestate;
  16468. + RB_CLEAR_NODE(&waiter->pi_tree_entry);
  16469. + RB_CLEAR_NODE(&waiter->tree_entry);
  16470. +}
  16471. +
  16472. #endif
  16473. diff -Nur linux-4.1.26.orig/kernel/locking/spinlock.c linux-4.1.26/kernel/locking/spinlock.c
  16474. --- linux-4.1.26.orig/kernel/locking/spinlock.c 2016-06-07 01:13:11.000000000 +0200
  16475. +++ linux-4.1.26/kernel/locking/spinlock.c 2016-06-19 15:30:58.695297658 +0200
  16476. @@ -124,8 +124,11 @@
  16477. * __[spin|read|write]_lock_bh()
  16478. */
  16479. BUILD_LOCK_OPS(spin, raw_spinlock);
  16480. +
  16481. +#ifndef CONFIG_PREEMPT_RT_FULL
  16482. BUILD_LOCK_OPS(read, rwlock);
  16483. BUILD_LOCK_OPS(write, rwlock);
  16484. +#endif
  16485. #endif
  16486. @@ -209,6 +212,8 @@
  16487. EXPORT_SYMBOL(_raw_spin_unlock_bh);
  16488. #endif
  16489. +#ifndef CONFIG_PREEMPT_RT_FULL
  16490. +
  16491. #ifndef CONFIG_INLINE_READ_TRYLOCK
  16492. int __lockfunc _raw_read_trylock(rwlock_t *lock)
  16493. {
  16494. @@ -353,6 +358,8 @@
  16495. EXPORT_SYMBOL(_raw_write_unlock_bh);
  16496. #endif
  16497. +#endif /* !PREEMPT_RT_FULL */
  16498. +
  16499. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  16500. void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
  16501. diff -Nur linux-4.1.26.orig/kernel/locking/spinlock_debug.c linux-4.1.26/kernel/locking/spinlock_debug.c
  16502. --- linux-4.1.26.orig/kernel/locking/spinlock_debug.c 2016-06-07 01:13:11.000000000 +0200
  16503. +++ linux-4.1.26/kernel/locking/spinlock_debug.c 2016-06-19 15:30:58.695297658 +0200
  16504. @@ -31,6 +31,7 @@
  16505. EXPORT_SYMBOL(__raw_spin_lock_init);
  16506. +#ifndef CONFIG_PREEMPT_RT_FULL
  16507. void __rwlock_init(rwlock_t *lock, const char *name,
  16508. struct lock_class_key *key)
  16509. {
  16510. @@ -48,6 +49,7 @@
  16511. }
  16512. EXPORT_SYMBOL(__rwlock_init);
  16513. +#endif
  16514. static void spin_dump(raw_spinlock_t *lock, const char *msg)
  16515. {
  16516. @@ -159,6 +161,7 @@
  16517. arch_spin_unlock(&lock->raw_lock);
  16518. }
  16519. +#ifndef CONFIG_PREEMPT_RT_FULL
  16520. static void rwlock_bug(rwlock_t *lock, const char *msg)
  16521. {
  16522. if (!debug_locks_off())
  16523. @@ -300,3 +303,5 @@
  16524. debug_write_unlock(lock);
  16525. arch_write_unlock(&lock->raw_lock);
  16526. }
  16527. +
  16528. +#endif
  16529. diff -Nur linux-4.1.26.orig/kernel/panic.c linux-4.1.26/kernel/panic.c
  16530. --- linux-4.1.26.orig/kernel/panic.c 2016-06-07 01:13:11.000000000 +0200
  16531. +++ linux-4.1.26/kernel/panic.c 2016-06-19 15:30:58.695297658 +0200
  16532. @@ -399,9 +399,11 @@
  16533. static int init_oops_id(void)
  16534. {
  16535. +#ifndef CONFIG_PREEMPT_RT_FULL
  16536. if (!oops_id)
  16537. get_random_bytes(&oops_id, sizeof(oops_id));
  16538. else
  16539. +#endif
  16540. oops_id++;
  16541. return 0;
  16542. diff -Nur linux-4.1.26.orig/kernel/power/hibernate.c linux-4.1.26/kernel/power/hibernate.c
  16543. --- linux-4.1.26.orig/kernel/power/hibernate.c 2016-06-07 01:13:11.000000000 +0200
  16544. +++ linux-4.1.26/kernel/power/hibernate.c 2016-06-19 15:30:58.695297658 +0200
  16545. @@ -285,6 +285,8 @@
  16546. local_irq_disable();
  16547. + system_state = SYSTEM_SUSPEND;
  16548. +
  16549. error = syscore_suspend();
  16550. if (error) {
  16551. printk(KERN_ERR "PM: Some system devices failed to power down, "
  16552. @@ -314,6 +316,7 @@
  16553. syscore_resume();
  16554. Enable_irqs:
  16555. + system_state = SYSTEM_RUNNING;
  16556. local_irq_enable();
  16557. Enable_cpus:
  16558. @@ -437,6 +440,7 @@
  16559. goto Enable_cpus;
  16560. local_irq_disable();
  16561. + system_state = SYSTEM_SUSPEND;
  16562. error = syscore_suspend();
  16563. if (error)
  16564. @@ -470,6 +474,7 @@
  16565. syscore_resume();
  16566. Enable_irqs:
  16567. + system_state = SYSTEM_RUNNING;
  16568. local_irq_enable();
  16569. Enable_cpus:
  16570. @@ -555,6 +560,7 @@
  16571. goto Platform_finish;
  16572. local_irq_disable();
  16573. + system_state = SYSTEM_SUSPEND;
  16574. syscore_suspend();
  16575. if (pm_wakeup_pending()) {
  16576. error = -EAGAIN;
  16577. @@ -567,6 +573,7 @@
  16578. Power_up:
  16579. syscore_resume();
  16580. + system_state = SYSTEM_RUNNING;
  16581. local_irq_enable();
  16582. enable_nonboot_cpus();
  16583. diff -Nur linux-4.1.26.orig/kernel/power/suspend.c linux-4.1.26/kernel/power/suspend.c
  16584. --- linux-4.1.26.orig/kernel/power/suspend.c 2016-06-07 01:13:11.000000000 +0200
  16585. +++ linux-4.1.26/kernel/power/suspend.c 2016-06-19 15:30:58.695297658 +0200
  16586. @@ -356,6 +356,8 @@
  16587. arch_suspend_disable_irqs();
  16588. BUG_ON(!irqs_disabled());
  16589. + system_state = SYSTEM_SUSPEND;
  16590. +
  16591. error = syscore_suspend();
  16592. if (!error) {
  16593. *wakeup = pm_wakeup_pending();
  16594. @@ -370,6 +372,8 @@
  16595. syscore_resume();
  16596. }
  16597. + system_state = SYSTEM_RUNNING;
  16598. +
  16599. arch_suspend_enable_irqs();
  16600. BUG_ON(irqs_disabled());
  16601. diff -Nur linux-4.1.26.orig/kernel/printk/printk.c linux-4.1.26/kernel/printk/printk.c
  16602. --- linux-4.1.26.orig/kernel/printk/printk.c 2016-06-07 01:13:11.000000000 +0200
  16603. +++ linux-4.1.26/kernel/printk/printk.c 2016-06-19 15:30:58.695297658 +0200
  16604. @@ -1163,6 +1163,7 @@
  16605. {
  16606. char *text;
  16607. int len = 0;
  16608. + int attempts = 0;
  16609. text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
  16610. if (!text)
  16611. @@ -1174,7 +1175,14 @@
  16612. u64 seq;
  16613. u32 idx;
  16614. enum log_flags prev;
  16615. -
  16616. + int num_msg;
  16617. +try_again:
  16618. + attempts++;
  16619. + if (attempts > 10) {
  16620. + len = -EBUSY;
  16621. + goto out;
  16622. + }
  16623. + num_msg = 0;
  16624. if (clear_seq < log_first_seq) {
  16625. /* messages are gone, move to first available one */
  16626. clear_seq = log_first_seq;
  16627. @@ -1195,6 +1203,14 @@
  16628. prev = msg->flags;
  16629. idx = log_next(idx);
  16630. seq++;
  16631. + num_msg++;
  16632. + if (num_msg > 5) {
  16633. + num_msg = 0;
  16634. + raw_spin_unlock_irq(&logbuf_lock);
  16635. + raw_spin_lock_irq(&logbuf_lock);
  16636. + if (clear_seq < log_first_seq)
  16637. + goto try_again;
  16638. + }
  16639. }
  16640. /* move first record forward until length fits into the buffer */
  16641. @@ -1208,6 +1224,14 @@
  16642. prev = msg->flags;
  16643. idx = log_next(idx);
  16644. seq++;
  16645. + num_msg++;
  16646. + if (num_msg > 5) {
  16647. + num_msg = 0;
  16648. + raw_spin_unlock_irq(&logbuf_lock);
  16649. + raw_spin_lock_irq(&logbuf_lock);
  16650. + if (clear_seq < log_first_seq)
  16651. + goto try_again;
  16652. + }
  16653. }
  16654. /* last message fitting into this dump */
  16655. @@ -1248,6 +1272,7 @@
  16656. clear_seq = log_next_seq;
  16657. clear_idx = log_next_idx;
  16658. }
  16659. +out:
  16660. raw_spin_unlock_irq(&logbuf_lock);
  16661. kfree(text);
  16662. @@ -1401,6 +1426,7 @@
  16663. if (!console_drivers)
  16664. return;
  16665. + migrate_disable();
  16666. for_each_console(con) {
  16667. if (exclusive_console && con != exclusive_console)
  16668. continue;
  16669. @@ -1413,6 +1439,7 @@
  16670. continue;
  16671. con->write(con, text, len);
  16672. }
  16673. + migrate_enable();
  16674. }
  16675. /*
  16676. @@ -1473,6 +1500,15 @@
  16677. static int console_trylock_for_printk(void)
  16678. {
  16679. unsigned int cpu = smp_processor_id();
  16680. +#ifdef CONFIG_PREEMPT_RT_FULL
  16681. + int lock = !early_boot_irqs_disabled && (preempt_count() == 0) &&
  16682. + !irqs_disabled();
  16683. +#else
  16684. + int lock = 1;
  16685. +#endif
  16686. +
  16687. + if (!lock)
  16688. + return 0;
  16689. if (!console_trylock())
  16690. return 0;
  16691. @@ -1607,6 +1643,62 @@
  16692. return textlen;
  16693. }
  16694. +#ifdef CONFIG_EARLY_PRINTK
  16695. +struct console *early_console;
  16696. +
  16697. +static void early_vprintk(const char *fmt, va_list ap)
  16698. +{
  16699. + if (early_console) {
  16700. + char buf[512];
  16701. + int n = vscnprintf(buf, sizeof(buf), fmt, ap);
  16702. +
  16703. + early_console->write(early_console, buf, n);
  16704. + }
  16705. +}
  16706. +
  16707. +asmlinkage void early_printk(const char *fmt, ...)
  16708. +{
  16709. + va_list ap;
  16710. +
  16711. + va_start(ap, fmt);
  16712. + early_vprintk(fmt, ap);
  16713. + va_end(ap);
  16714. +}
  16715. +
  16716. +/*
  16717. + * This is independent of any log levels - a global
  16718. + * kill switch that turns off all of printk.
  16719. + *
  16720. + * Used by the NMI watchdog if early-printk is enabled.
  16721. + */
  16722. +static bool __read_mostly printk_killswitch;
  16723. +
  16724. +static int __init force_early_printk_setup(char *str)
  16725. +{
  16726. + printk_killswitch = true;
  16727. + return 0;
  16728. +}
  16729. +early_param("force_early_printk", force_early_printk_setup);
  16730. +
  16731. +void printk_kill(void)
  16732. +{
  16733. + printk_killswitch = true;
  16734. +}
  16735. +
  16736. +static int forced_early_printk(const char *fmt, va_list ap)
  16737. +{
  16738. + if (!printk_killswitch)
  16739. + return 0;
  16740. + early_vprintk(fmt, ap);
  16741. + return 1;
  16742. +}
  16743. +#else
  16744. +static inline int forced_early_printk(const char *fmt, va_list ap)
  16745. +{
  16746. + return 0;
  16747. +}
  16748. +#endif
  16749. +
  16750. asmlinkage int vprintk_emit(int facility, int level,
  16751. const char *dict, size_t dictlen,
  16752. const char *fmt, va_list args)
  16753. @@ -1623,6 +1715,13 @@
  16754. /* cpu currently holding logbuf_lock in this function */
  16755. static unsigned int logbuf_cpu = UINT_MAX;
  16756. + /*
  16757. + * Fall back to early_printk if a debugging subsystem has
  16758. + * killed printk output
  16759. + */
  16760. + if (unlikely(forced_early_printk(fmt, args)))
  16761. + return 1;
  16762. +
  16763. if (level == LOGLEVEL_SCHED) {
  16764. level = LOGLEVEL_DEFAULT;
  16765. in_sched = true;
  16766. @@ -1764,8 +1863,7 @@
  16767. * console_sem which would prevent anyone from printing to
  16768. * console
  16769. */
  16770. - preempt_disable();
  16771. -
  16772. + migrate_disable();
  16773. /*
  16774. * Try to acquire and then immediately release the console
  16775. * semaphore. The release will print out buffers and wake up
  16776. @@ -1773,7 +1871,7 @@
  16777. */
  16778. if (console_trylock_for_printk())
  16779. console_unlock();
  16780. - preempt_enable();
  16781. + migrate_enable();
  16782. lockdep_on();
  16783. }
  16784. @@ -1902,26 +2000,6 @@
  16785. #endif /* CONFIG_PRINTK */
  16786. -#ifdef CONFIG_EARLY_PRINTK
  16787. -struct console *early_console;
  16788. -
  16789. -asmlinkage __visible void early_printk(const char *fmt, ...)
  16790. -{
  16791. - va_list ap;
  16792. - char buf[512];
  16793. - int n;
  16794. -
  16795. - if (!early_console)
  16796. - return;
  16797. -
  16798. - va_start(ap, fmt);
  16799. - n = vscnprintf(buf, sizeof(buf), fmt, ap);
  16800. - va_end(ap);
  16801. -
  16802. - early_console->write(early_console, buf, n);
  16803. -}
  16804. -#endif
  16805. -
  16806. static int __add_preferred_console(char *name, int idx, char *options,
  16807. char *brl_options)
  16808. {
  16809. @@ -2143,11 +2221,16 @@
  16810. goto out;
  16811. len = cont_print_text(text, size);
  16812. +#ifndef CONFIG_PREEMPT_RT_FULL
  16813. raw_spin_unlock(&logbuf_lock);
  16814. stop_critical_timings();
  16815. call_console_drivers(cont.level, text, len);
  16816. start_critical_timings();
  16817. local_irq_restore(flags);
  16818. +#else
  16819. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  16820. + call_console_drivers(cont.level, text, len);
  16821. +#endif
  16822. return;
  16823. out:
  16824. raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  16825. @@ -2246,12 +2329,17 @@
  16826. console_idx = log_next(console_idx);
  16827. console_seq++;
  16828. console_prev = msg->flags;
  16829. +#ifdef CONFIG_PREEMPT_RT_FULL
  16830. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  16831. + call_console_drivers(level, text, len);
  16832. +#else
  16833. raw_spin_unlock(&logbuf_lock);
  16834. stop_critical_timings(); /* don't trace print latency */
  16835. call_console_drivers(level, text, len);
  16836. start_critical_timings();
  16837. local_irq_restore(flags);
  16838. +#endif
  16839. if (do_cond_resched)
  16840. cond_resched();
  16841. diff -Nur linux-4.1.26.orig/kernel/ptrace.c linux-4.1.26/kernel/ptrace.c
  16842. --- linux-4.1.26.orig/kernel/ptrace.c 2016-06-07 01:13:11.000000000 +0200
  16843. +++ linux-4.1.26/kernel/ptrace.c 2016-06-19 15:30:58.699297812 +0200
  16844. @@ -129,7 +129,14 @@
  16845. spin_lock_irq(&task->sighand->siglock);
  16846. if (task_is_traced(task) && !__fatal_signal_pending(task)) {
  16847. - task->state = __TASK_TRACED;
  16848. + unsigned long flags;
  16849. +
  16850. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  16851. + if (task->state & __TASK_TRACED)
  16852. + task->state = __TASK_TRACED;
  16853. + else
  16854. + task->saved_state = __TASK_TRACED;
  16855. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16856. ret = true;
  16857. }
  16858. spin_unlock_irq(&task->sighand->siglock);
  16859. diff -Nur linux-4.1.26.orig/kernel/rcu/rcutorture.c linux-4.1.26/kernel/rcu/rcutorture.c
  16860. --- linux-4.1.26.orig/kernel/rcu/rcutorture.c 2016-06-07 01:13:11.000000000 +0200
  16861. +++ linux-4.1.26/kernel/rcu/rcutorture.c 2016-06-19 15:30:58.699297812 +0200
  16862. @@ -389,6 +389,7 @@
  16863. .name = "rcu"
  16864. };
  16865. +#ifndef CONFIG_PREEMPT_RT_FULL
  16866. /*
  16867. * Definitions for rcu_bh torture testing.
  16868. */
  16869. @@ -428,6 +429,12 @@
  16870. .name = "rcu_bh"
  16871. };
  16872. +#else
  16873. +static struct rcu_torture_ops rcu_bh_ops = {
  16874. + .ttype = INVALID_RCU_FLAVOR,
  16875. +};
  16876. +#endif
  16877. +
  16878. /*
  16879. * Don't even think about trying any of these in real life!!!
  16880. * The names includes "busted", and they really means it!
  16881. diff -Nur linux-4.1.26.orig/kernel/rcu/tree.c linux-4.1.26/kernel/rcu/tree.c
  16882. --- linux-4.1.26.orig/kernel/rcu/tree.c 2016-06-07 01:13:11.000000000 +0200
  16883. +++ linux-4.1.26/kernel/rcu/tree.c 2016-06-19 15:30:58.699297812 +0200
  16884. @@ -56,6 +56,11 @@
  16885. #include <linux/random.h>
  16886. #include <linux/ftrace_event.h>
  16887. #include <linux/suspend.h>
  16888. +#include <linux/delay.h>
  16889. +#include <linux/gfp.h>
  16890. +#include <linux/oom.h>
  16891. +#include <linux/smpboot.h>
  16892. +#include "../time/tick-internal.h"
  16893. #include "tree.h"
  16894. #include "rcu.h"
  16895. @@ -220,6 +225,19 @@
  16896. }
  16897. }
  16898. +#ifdef CONFIG_PREEMPT_RT_FULL
  16899. +static void rcu_preempt_qs(void);
  16900. +
  16901. +void rcu_bh_qs(void)
  16902. +{
  16903. + unsigned long flags;
  16904. +
  16905. + /* Callers to this function, rcu_preempt_qs(), must disable irqs. */
  16906. + local_irq_save(flags);
  16907. + rcu_preempt_qs();
  16908. + local_irq_restore(flags);
  16909. +}
  16910. +#else
  16911. void rcu_bh_qs(void)
  16912. {
  16913. if (!__this_cpu_read(rcu_bh_data.passed_quiesce)) {
  16914. @@ -229,6 +247,7 @@
  16915. __this_cpu_write(rcu_bh_data.passed_quiesce, 1);
  16916. }
  16917. }
  16918. +#endif
  16919. static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
  16920. @@ -404,6 +423,7 @@
  16921. }
  16922. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  16923. +#ifndef CONFIG_PREEMPT_RT_FULL
  16924. /*
  16925. * Return the number of RCU BH batches completed thus far for debug & stats.
  16926. */
  16927. @@ -431,6 +451,13 @@
  16928. }
  16929. EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  16930. +#else
  16931. +void rcu_force_quiescent_state(void)
  16932. +{
  16933. +}
  16934. +EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  16935. +#endif
  16936. +
  16937. /*
  16938. * Force a quiescent state for RCU-sched.
  16939. */
  16940. @@ -1545,7 +1572,7 @@
  16941. !ACCESS_ONCE(rsp->gp_flags) ||
  16942. !rsp->gp_kthread)
  16943. return;
  16944. - wake_up(&rsp->gp_wq);
  16945. + swait_wake(&rsp->gp_wq);
  16946. }
  16947. /*
  16948. @@ -1986,7 +2013,7 @@
  16949. ACCESS_ONCE(rsp->gpnum),
  16950. TPS("reqwait"));
  16951. rsp->gp_state = RCU_GP_WAIT_GPS;
  16952. - wait_event_interruptible(rsp->gp_wq,
  16953. + swait_event_interruptible(rsp->gp_wq,
  16954. ACCESS_ONCE(rsp->gp_flags) &
  16955. RCU_GP_FLAG_INIT);
  16956. /* Locking provides needed memory barrier. */
  16957. @@ -2015,7 +2042,7 @@
  16958. ACCESS_ONCE(rsp->gpnum),
  16959. TPS("fqswait"));
  16960. rsp->gp_state = RCU_GP_WAIT_FQS;
  16961. - ret = wait_event_interruptible_timeout(rsp->gp_wq,
  16962. + ret = swait_event_interruptible_timeout(rsp->gp_wq,
  16963. ((gf = ACCESS_ONCE(rsp->gp_flags)) &
  16964. RCU_GP_FLAG_FQS) ||
  16965. (!ACCESS_ONCE(rnp->qsmask) &&
  16966. @@ -2860,18 +2887,17 @@
  16967. /*
  16968. * Do RCU core processing for the current CPU.
  16969. */
  16970. -static void rcu_process_callbacks(struct softirq_action *unused)
  16971. +static void rcu_process_callbacks(void)
  16972. {
  16973. struct rcu_state *rsp;
  16974. if (cpu_is_offline(smp_processor_id()))
  16975. return;
  16976. - trace_rcu_utilization(TPS("Start RCU core"));
  16977. for_each_rcu_flavor(rsp)
  16978. __rcu_process_callbacks(rsp);
  16979. - trace_rcu_utilization(TPS("End RCU core"));
  16980. }
  16981. +static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  16982. /*
  16983. * Schedule RCU callback invocation. If the specified type of RCU
  16984. * does not support RCU priority boosting, just do a direct call,
  16985. @@ -2883,18 +2909,105 @@
  16986. {
  16987. if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active)))
  16988. return;
  16989. - if (likely(!rsp->boost)) {
  16990. - rcu_do_batch(rsp, rdp);
  16991. + rcu_do_batch(rsp, rdp);
  16992. +}
  16993. +
  16994. +static void rcu_wake_cond(struct task_struct *t, int status)
  16995. +{
  16996. + /*
  16997. + * If the thread is yielding, only wake it when this
  16998. + * is invoked from idle
  16999. + */
  17000. + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
  17001. + wake_up_process(t);
  17002. +}
  17003. +
  17004. +/*
  17005. + * Wake up this CPU's rcuc kthread to do RCU core processing.
  17006. + */
  17007. +static void invoke_rcu_core(void)
  17008. +{
  17009. + unsigned long flags;
  17010. + struct task_struct *t;
  17011. +
  17012. + if (!cpu_online(smp_processor_id()))
  17013. return;
  17014. + local_irq_save(flags);
  17015. + __this_cpu_write(rcu_cpu_has_work, 1);
  17016. + t = __this_cpu_read(rcu_cpu_kthread_task);
  17017. + if (t != NULL && current != t)
  17018. + rcu_wake_cond(t, __this_cpu_read(rcu_cpu_kthread_status));
  17019. + local_irq_restore(flags);
  17020. +}
  17021. +
  17022. +static void rcu_cpu_kthread_park(unsigned int cpu)
  17023. +{
  17024. + per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  17025. +}
  17026. +
  17027. +static int rcu_cpu_kthread_should_run(unsigned int cpu)
  17028. +{
  17029. + return __this_cpu_read(rcu_cpu_has_work);
  17030. +}
  17031. +
  17032. +/*
  17033. + * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  17034. + * RCU softirq used in flavors and configurations of RCU that do not
  17035. + * support RCU priority boosting.
  17036. + */
  17037. +static void rcu_cpu_kthread(unsigned int cpu)
  17038. +{
  17039. + unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  17040. + char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  17041. + int spincnt;
  17042. +
  17043. + for (spincnt = 0; spincnt < 10; spincnt++) {
  17044. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  17045. + local_bh_disable();
  17046. + *statusp = RCU_KTHREAD_RUNNING;
  17047. + this_cpu_inc(rcu_cpu_kthread_loops);
  17048. + local_irq_disable();
  17049. + work = *workp;
  17050. + *workp = 0;
  17051. + local_irq_enable();
  17052. + if (work)
  17053. + rcu_process_callbacks();
  17054. + local_bh_enable();
  17055. + if (*workp == 0) {
  17056. + trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  17057. + *statusp = RCU_KTHREAD_WAITING;
  17058. + return;
  17059. + }
  17060. }
  17061. - invoke_rcu_callbacks_kthread();
  17062. + *statusp = RCU_KTHREAD_YIELDING;
  17063. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  17064. + schedule_timeout_interruptible(2);
  17065. + trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  17066. + *statusp = RCU_KTHREAD_WAITING;
  17067. }
  17068. -static void invoke_rcu_core(void)
  17069. +static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  17070. + .store = &rcu_cpu_kthread_task,
  17071. + .thread_should_run = rcu_cpu_kthread_should_run,
  17072. + .thread_fn = rcu_cpu_kthread,
  17073. + .thread_comm = "rcuc/%u",
  17074. + .setup = rcu_cpu_kthread_setup,
  17075. + .park = rcu_cpu_kthread_park,
  17076. +};
  17077. +
  17078. +/*
  17079. + * Spawn per-CPU RCU core processing kthreads.
  17080. + */
  17081. +static int __init rcu_spawn_core_kthreads(void)
  17082. {
  17083. - if (cpu_online(smp_processor_id()))
  17084. - raise_softirq(RCU_SOFTIRQ);
  17085. + int cpu;
  17086. +
  17087. + for_each_possible_cpu(cpu)
  17088. + per_cpu(rcu_cpu_has_work, cpu) = 0;
  17089. + BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  17090. + return 0;
  17091. }
  17092. +early_initcall(rcu_spawn_core_kthreads);
  17093. /*
  17094. * Handle any core-RCU processing required by a call_rcu() invocation.
  17095. @@ -3040,6 +3153,7 @@
  17096. }
  17097. EXPORT_SYMBOL_GPL(call_rcu_sched);
  17098. +#ifndef CONFIG_PREEMPT_RT_FULL
  17099. /*
  17100. * Queue an RCU callback for invocation after a quicker grace period.
  17101. */
  17102. @@ -3048,6 +3162,7 @@
  17103. __call_rcu(head, func, &rcu_bh_state, -1, 0);
  17104. }
  17105. EXPORT_SYMBOL_GPL(call_rcu_bh);
  17106. +#endif
  17107. /*
  17108. * Queue an RCU callback for lazy invocation after a grace period.
  17109. @@ -3139,6 +3254,7 @@
  17110. }
  17111. EXPORT_SYMBOL_GPL(synchronize_sched);
  17112. +#ifndef CONFIG_PREEMPT_RT_FULL
  17113. /**
  17114. * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
  17115. *
  17116. @@ -3165,6 +3281,7 @@
  17117. wait_rcu_gp(call_rcu_bh);
  17118. }
  17119. EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
  17120. +#endif
  17121. /**
  17122. * get_state_synchronize_rcu - Snapshot current RCU state
  17123. @@ -3677,6 +3794,7 @@
  17124. mutex_unlock(&rsp->barrier_mutex);
  17125. }
  17126. +#ifndef CONFIG_PREEMPT_RT_FULL
  17127. /**
  17128. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  17129. */
  17130. @@ -3685,6 +3803,7 @@
  17131. _rcu_barrier(&rcu_bh_state);
  17132. }
  17133. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  17134. +#endif
  17135. /**
  17136. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  17137. @@ -4021,7 +4140,7 @@
  17138. }
  17139. }
  17140. - init_waitqueue_head(&rsp->gp_wq);
  17141. + init_swait_head(&rsp->gp_wq);
  17142. rnp = rsp->level[rcu_num_lvls - 1];
  17143. for_each_possible_cpu(i) {
  17144. while (i > rnp->grphi)
  17145. @@ -4120,7 +4239,6 @@
  17146. rcu_init_one(&rcu_bh_state, &rcu_bh_data);
  17147. rcu_init_one(&rcu_sched_state, &rcu_sched_data);
  17148. __rcu_init_preempt();
  17149. - open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  17150. /*
  17151. * We don't need protection against CPU-hotplug here because
  17152. diff -Nur linux-4.1.26.orig/kernel/rcu/tree.h linux-4.1.26/kernel/rcu/tree.h
  17153. --- linux-4.1.26.orig/kernel/rcu/tree.h 2016-06-07 01:13:11.000000000 +0200
  17154. +++ linux-4.1.26/kernel/rcu/tree.h 2016-06-19 15:30:58.699297812 +0200
  17155. @@ -27,6 +27,7 @@
  17156. #include <linux/threads.h>
  17157. #include <linux/cpumask.h>
  17158. #include <linux/seqlock.h>
  17159. +#include <linux/wait-simple.h>
  17160. /*
  17161. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  17162. @@ -210,7 +211,7 @@
  17163. /* This can happen due to race conditions. */
  17164. #endif /* #ifdef CONFIG_RCU_BOOST */
  17165. #ifdef CONFIG_RCU_NOCB_CPU
  17166. - wait_queue_head_t nocb_gp_wq[2];
  17167. + struct swait_head nocb_gp_wq[2];
  17168. /* Place for rcu_nocb_kthread() to wait GP. */
  17169. #endif /* #ifdef CONFIG_RCU_NOCB_CPU */
  17170. int need_future_gp[2];
  17171. @@ -349,7 +350,7 @@
  17172. atomic_long_t nocb_q_count_lazy; /* invocation (all stages). */
  17173. struct rcu_head *nocb_follower_head; /* CBs ready to invoke. */
  17174. struct rcu_head **nocb_follower_tail;
  17175. - wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */
  17176. + struct swait_head nocb_wq; /* For nocb kthreads to sleep on. */
  17177. struct task_struct *nocb_kthread;
  17178. int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
  17179. @@ -438,7 +439,7 @@
  17180. unsigned long gpnum; /* Current gp number. */
  17181. unsigned long completed; /* # of last completed gp. */
  17182. struct task_struct *gp_kthread; /* Task for grace periods. */
  17183. - wait_queue_head_t gp_wq; /* Where GP task waits. */
  17184. + struct swait_head gp_wq; /* Where GP task waits. */
  17185. short gp_flags; /* Commands for GP task. */
  17186. short gp_state; /* GP kthread sleep state. */
  17187. @@ -529,12 +530,10 @@
  17188. DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data);
  17189. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  17190. -#ifdef CONFIG_RCU_BOOST
  17191. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  17192. DECLARE_PER_CPU(int, rcu_cpu_kthread_cpu);
  17193. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  17194. DECLARE_PER_CPU(char, rcu_cpu_has_work);
  17195. -#endif /* #ifdef CONFIG_RCU_BOOST */
  17196. #ifndef RCU_TREE_NONCORE
  17197. @@ -553,10 +552,9 @@
  17198. static void __init __rcu_init_preempt(void);
  17199. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  17200. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
  17201. -static void invoke_rcu_callbacks_kthread(void);
  17202. static bool rcu_is_callbacks_kthread(void);
  17203. +static void rcu_cpu_kthread_setup(unsigned int cpu);
  17204. #ifdef CONFIG_RCU_BOOST
  17205. -static void rcu_preempt_do_callbacks(void);
  17206. static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
  17207. struct rcu_node *rnp);
  17208. #endif /* #ifdef CONFIG_RCU_BOOST */
  17209. diff -Nur linux-4.1.26.orig/kernel/rcu/tree_plugin.h linux-4.1.26/kernel/rcu/tree_plugin.h
  17210. --- linux-4.1.26.orig/kernel/rcu/tree_plugin.h 2016-06-07 01:13:11.000000000 +0200
  17211. +++ linux-4.1.26/kernel/rcu/tree_plugin.h 2016-06-19 15:30:58.699297812 +0200
  17212. @@ -24,27 +24,20 @@
  17213. * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  17214. */
  17215. -#include <linux/delay.h>
  17216. -#include <linux/gfp.h>
  17217. -#include <linux/oom.h>
  17218. -#include <linux/smpboot.h>
  17219. -#include "../time/tick-internal.h"
  17220. -
  17221. #ifdef CONFIG_RCU_BOOST
  17222. #include "../locking/rtmutex_common.h"
  17223. +#endif /* #ifdef CONFIG_RCU_BOOST */
  17224. +
  17225. /*
  17226. * Control variables for per-CPU and per-rcu_node kthreads. These
  17227. * handle all flavors of RCU.
  17228. */
  17229. -static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  17230. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  17231. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  17232. DEFINE_PER_CPU(char, rcu_cpu_has_work);
  17233. -#endif /* #ifdef CONFIG_RCU_BOOST */
  17234. -
  17235. #ifdef CONFIG_RCU_NOCB_CPU
  17236. static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
  17237. static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */
  17238. @@ -291,7 +284,7 @@
  17239. }
  17240. /* Hardware IRQ handlers cannot block, complain if they get here. */
  17241. - if (in_irq() || in_serving_softirq()) {
  17242. + if (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_OFFSET)) {
  17243. lockdep_rcu_suspicious(__FILE__, __LINE__,
  17244. "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n");
  17245. pr_alert("->rcu_read_unlock_special: %#x (b: %d, nq: %d)\n",
  17246. @@ -496,15 +489,6 @@
  17247. t->rcu_read_unlock_special.b.need_qs = true;
  17248. }
  17249. -#ifdef CONFIG_RCU_BOOST
  17250. -
  17251. -static void rcu_preempt_do_callbacks(void)
  17252. -{
  17253. - rcu_do_batch(&rcu_preempt_state, this_cpu_ptr(&rcu_preempt_data));
  17254. -}
  17255. -
  17256. -#endif /* #ifdef CONFIG_RCU_BOOST */
  17257. -
  17258. /*
  17259. * Queue a preemptible-RCU callback for invocation after a grace period.
  17260. */
  17261. @@ -939,6 +923,19 @@
  17262. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  17263. +/*
  17264. + * If boosting, set rcuc kthreads to realtime priority.
  17265. + */
  17266. +static void rcu_cpu_kthread_setup(unsigned int cpu)
  17267. +{
  17268. +#ifdef CONFIG_RCU_BOOST
  17269. + struct sched_param sp;
  17270. +
  17271. + sp.sched_priority = kthread_prio;
  17272. + sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  17273. +#endif /* #ifdef CONFIG_RCU_BOOST */
  17274. +}
  17275. +
  17276. #ifdef CONFIG_RCU_BOOST
  17277. #include "../locking/rtmutex_common.h"
  17278. @@ -970,16 +967,6 @@
  17279. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  17280. -static void rcu_wake_cond(struct task_struct *t, int status)
  17281. -{
  17282. - /*
  17283. - * If the thread is yielding, only wake it when this
  17284. - * is invoked from idle
  17285. - */
  17286. - if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
  17287. - wake_up_process(t);
  17288. -}
  17289. -
  17290. /*
  17291. * Carry out RCU priority boosting on the task indicated by ->exp_tasks
  17292. * or ->boost_tasks, advancing the pointer to the next task in the
  17293. @@ -1125,23 +1112,6 @@
  17294. }
  17295. /*
  17296. - * Wake up the per-CPU kthread to invoke RCU callbacks.
  17297. - */
  17298. -static void invoke_rcu_callbacks_kthread(void)
  17299. -{
  17300. - unsigned long flags;
  17301. -
  17302. - local_irq_save(flags);
  17303. - __this_cpu_write(rcu_cpu_has_work, 1);
  17304. - if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
  17305. - current != __this_cpu_read(rcu_cpu_kthread_task)) {
  17306. - rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
  17307. - __this_cpu_read(rcu_cpu_kthread_status));
  17308. - }
  17309. - local_irq_restore(flags);
  17310. -}
  17311. -
  17312. -/*
  17313. * Is the current CPU running the RCU-callbacks kthread?
  17314. * Caller must have preemption disabled.
  17315. */
  17316. @@ -1196,67 +1166,6 @@
  17317. return 0;
  17318. }
  17319. -static void rcu_kthread_do_work(void)
  17320. -{
  17321. - rcu_do_batch(&rcu_sched_state, this_cpu_ptr(&rcu_sched_data));
  17322. - rcu_do_batch(&rcu_bh_state, this_cpu_ptr(&rcu_bh_data));
  17323. - rcu_preempt_do_callbacks();
  17324. -}
  17325. -
  17326. -static void rcu_cpu_kthread_setup(unsigned int cpu)
  17327. -{
  17328. - struct sched_param sp;
  17329. -
  17330. - sp.sched_priority = kthread_prio;
  17331. - sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  17332. -}
  17333. -
  17334. -static void rcu_cpu_kthread_park(unsigned int cpu)
  17335. -{
  17336. - per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  17337. -}
  17338. -
  17339. -static int rcu_cpu_kthread_should_run(unsigned int cpu)
  17340. -{
  17341. - return __this_cpu_read(rcu_cpu_has_work);
  17342. -}
  17343. -
  17344. -/*
  17345. - * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  17346. - * RCU softirq used in flavors and configurations of RCU that do not
  17347. - * support RCU priority boosting.
  17348. - */
  17349. -static void rcu_cpu_kthread(unsigned int cpu)
  17350. -{
  17351. - unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  17352. - char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  17353. - int spincnt;
  17354. -
  17355. - for (spincnt = 0; spincnt < 10; spincnt++) {
  17356. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  17357. - local_bh_disable();
  17358. - *statusp = RCU_KTHREAD_RUNNING;
  17359. - this_cpu_inc(rcu_cpu_kthread_loops);
  17360. - local_irq_disable();
  17361. - work = *workp;
  17362. - *workp = 0;
  17363. - local_irq_enable();
  17364. - if (work)
  17365. - rcu_kthread_do_work();
  17366. - local_bh_enable();
  17367. - if (*workp == 0) {
  17368. - trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  17369. - *statusp = RCU_KTHREAD_WAITING;
  17370. - return;
  17371. - }
  17372. - }
  17373. - *statusp = RCU_KTHREAD_YIELDING;
  17374. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  17375. - schedule_timeout_interruptible(2);
  17376. - trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  17377. - *statusp = RCU_KTHREAD_WAITING;
  17378. -}
  17379. -
  17380. /*
  17381. * Set the per-rcu_node kthread's affinity to cover all CPUs that are
  17382. * served by the rcu_node in question. The CPU hotplug lock is still
  17383. @@ -1286,26 +1195,12 @@
  17384. free_cpumask_var(cm);
  17385. }
  17386. -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  17387. - .store = &rcu_cpu_kthread_task,
  17388. - .thread_should_run = rcu_cpu_kthread_should_run,
  17389. - .thread_fn = rcu_cpu_kthread,
  17390. - .thread_comm = "rcuc/%u",
  17391. - .setup = rcu_cpu_kthread_setup,
  17392. - .park = rcu_cpu_kthread_park,
  17393. -};
  17394. -
  17395. /*
  17396. * Spawn boost kthreads -- called as soon as the scheduler is running.
  17397. */
  17398. static void __init rcu_spawn_boost_kthreads(void)
  17399. {
  17400. struct rcu_node *rnp;
  17401. - int cpu;
  17402. -
  17403. - for_each_possible_cpu(cpu)
  17404. - per_cpu(rcu_cpu_has_work, cpu) = 0;
  17405. - BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  17406. rcu_for_each_leaf_node(rcu_state_p, rnp)
  17407. (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
  17408. }
  17409. @@ -1328,11 +1223,6 @@
  17410. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  17411. }
  17412. -static void invoke_rcu_callbacks_kthread(void)
  17413. -{
  17414. - WARN_ON_ONCE(1);
  17415. -}
  17416. -
  17417. static bool rcu_is_callbacks_kthread(void)
  17418. {
  17419. return false;
  17420. @@ -1356,7 +1246,7 @@
  17421. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  17422. -#if !defined(CONFIG_RCU_FAST_NO_HZ)
  17423. +#if !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL)
  17424. /*
  17425. * Check to see if any future RCU-related work will need to be done
  17426. @@ -1374,7 +1264,9 @@
  17427. return rcu_cpu_has_callbacks(NULL);
  17428. }
  17429. #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
  17430. +#endif /* !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL) */
  17431. +#if !defined(CONFIG_RCU_FAST_NO_HZ)
  17432. /*
  17433. * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
  17434. * after it.
  17435. @@ -1472,6 +1364,8 @@
  17436. return cbs_ready;
  17437. }
  17438. +#ifndef CONFIG_PREEMPT_RT_FULL
  17439. +
  17440. /*
  17441. * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
  17442. * to invoke. If the CPU has callbacks, try to advance them. Tell the
  17443. @@ -1512,7 +1406,7 @@
  17444. return 0;
  17445. }
  17446. #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
  17447. -
  17448. +#endif /* #ifndef CONFIG_PREEMPT_RT_FULL */
  17449. /*
  17450. * Prepare a CPU for idle from an RCU perspective. The first major task
  17451. * is to sense whether nohz mode has been enabled or disabled via sysfs.
  17452. @@ -1859,7 +1753,7 @@
  17453. */
  17454. static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
  17455. {
  17456. - wake_up_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
  17457. + swait_wake_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
  17458. }
  17459. /*
  17460. @@ -1877,8 +1771,8 @@
  17461. static void rcu_init_one_nocb(struct rcu_node *rnp)
  17462. {
  17463. - init_waitqueue_head(&rnp->nocb_gp_wq[0]);
  17464. - init_waitqueue_head(&rnp->nocb_gp_wq[1]);
  17465. + init_swait_head(&rnp->nocb_gp_wq[0]);
  17466. + init_swait_head(&rnp->nocb_gp_wq[1]);
  17467. }
  17468. #ifndef CONFIG_RCU_NOCB_CPU_ALL
  17469. @@ -1903,7 +1797,7 @@
  17470. if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
  17471. /* Prior smp_mb__after_atomic() orders against prior enqueue. */
  17472. ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
  17473. - wake_up(&rdp_leader->nocb_wq);
  17474. + swait_wake(&rdp_leader->nocb_wq);
  17475. }
  17476. }
  17477. @@ -2116,7 +2010,7 @@
  17478. */
  17479. trace_rcu_future_gp(rnp, rdp, c, TPS("StartWait"));
  17480. for (;;) {
  17481. - wait_event_interruptible(
  17482. + swait_event_interruptible(
  17483. rnp->nocb_gp_wq[c & 0x1],
  17484. (d = ULONG_CMP_GE(ACCESS_ONCE(rnp->completed), c)));
  17485. if (likely(d))
  17486. @@ -2144,7 +2038,7 @@
  17487. /* Wait for callbacks to appear. */
  17488. if (!rcu_nocb_poll) {
  17489. trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep");
  17490. - wait_event_interruptible(my_rdp->nocb_wq,
  17491. + swait_event_interruptible(my_rdp->nocb_wq,
  17492. !ACCESS_ONCE(my_rdp->nocb_leader_sleep));
  17493. /* Memory barrier handled by smp_mb() calls below and repoll. */
  17494. } else if (firsttime) {
  17495. @@ -2219,7 +2113,7 @@
  17496. * List was empty, wake up the follower.
  17497. * Memory barriers supplied by atomic_long_add().
  17498. */
  17499. - wake_up(&rdp->nocb_wq);
  17500. + swait_wake(&rdp->nocb_wq);
  17501. }
  17502. }
  17503. @@ -2240,7 +2134,7 @@
  17504. if (!rcu_nocb_poll) {
  17505. trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
  17506. "FollowerSleep");
  17507. - wait_event_interruptible(rdp->nocb_wq,
  17508. + swait_event_interruptible(rdp->nocb_wq,
  17509. ACCESS_ONCE(rdp->nocb_follower_head));
  17510. } else if (firsttime) {
  17511. /* Don't drown trace log with "Poll"! */
  17512. @@ -2399,7 +2293,7 @@
  17513. static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
  17514. {
  17515. rdp->nocb_tail = &rdp->nocb_head;
  17516. - init_waitqueue_head(&rdp->nocb_wq);
  17517. + init_swait_head(&rdp->nocb_wq);
  17518. rdp->nocb_follower_tail = &rdp->nocb_follower_head;
  17519. }
  17520. diff -Nur linux-4.1.26.orig/kernel/rcu/update.c linux-4.1.26/kernel/rcu/update.c
  17521. --- linux-4.1.26.orig/kernel/rcu/update.c 2016-06-07 01:13:11.000000000 +0200
  17522. +++ linux-4.1.26/kernel/rcu/update.c 2016-06-19 15:30:58.699297812 +0200
  17523. @@ -227,6 +227,7 @@
  17524. }
  17525. EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  17526. +#ifndef CONFIG_PREEMPT_RT_FULL
  17527. /**
  17528. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  17529. *
  17530. @@ -253,6 +254,7 @@
  17531. return in_softirq() || irqs_disabled();
  17532. }
  17533. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  17534. +#endif
  17535. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  17536. diff -Nur linux-4.1.26.orig/kernel/relay.c linux-4.1.26/kernel/relay.c
  17537. --- linux-4.1.26.orig/kernel/relay.c 2016-06-07 01:13:11.000000000 +0200
  17538. +++ linux-4.1.26/kernel/relay.c 2016-06-19 15:30:58.699297812 +0200
  17539. @@ -339,6 +339,10 @@
  17540. {
  17541. struct rchan_buf *buf = (struct rchan_buf *)data;
  17542. wake_up_interruptible(&buf->read_wait);
  17543. + /*
  17544. + * Stupid polling for now:
  17545. + */
  17546. + mod_timer(&buf->timer, jiffies + 1);
  17547. }
  17548. /**
  17549. @@ -356,6 +360,7 @@
  17550. init_waitqueue_head(&buf->read_wait);
  17551. kref_init(&buf->kref);
  17552. setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
  17553. + mod_timer(&buf->timer, jiffies + 1);
  17554. } else
  17555. del_timer_sync(&buf->timer);
  17556. @@ -739,15 +744,6 @@
  17557. else
  17558. buf->early_bytes += buf->chan->subbuf_size -
  17559. buf->padding[old_subbuf];
  17560. - smp_mb();
  17561. - if (waitqueue_active(&buf->read_wait))
  17562. - /*
  17563. - * Calling wake_up_interruptible() from here
  17564. - * will deadlock if we happen to be logging
  17565. - * from the scheduler (trying to re-grab
  17566. - * rq->lock), so defer it.
  17567. - */
  17568. - mod_timer(&buf->timer, jiffies + 1);
  17569. }
  17570. old = buf->data;
  17571. diff -Nur linux-4.1.26.orig/kernel/sched/completion.c linux-4.1.26/kernel/sched/completion.c
  17572. --- linux-4.1.26.orig/kernel/sched/completion.c 2016-06-07 01:13:11.000000000 +0200
  17573. +++ linux-4.1.26/kernel/sched/completion.c 2016-06-19 15:30:58.699297812 +0200
  17574. @@ -30,10 +30,10 @@
  17575. {
  17576. unsigned long flags;
  17577. - spin_lock_irqsave(&x->wait.lock, flags);
  17578. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  17579. x->done++;
  17580. - __wake_up_locked(&x->wait, TASK_NORMAL, 1);
  17581. - spin_unlock_irqrestore(&x->wait.lock, flags);
  17582. + __swait_wake_locked(&x->wait, TASK_NORMAL, 1);
  17583. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  17584. }
  17585. EXPORT_SYMBOL(complete);
  17586. @@ -50,10 +50,10 @@
  17587. {
  17588. unsigned long flags;
  17589. - spin_lock_irqsave(&x->wait.lock, flags);
  17590. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  17591. x->done += UINT_MAX/2;
  17592. - __wake_up_locked(&x->wait, TASK_NORMAL, 0);
  17593. - spin_unlock_irqrestore(&x->wait.lock, flags);
  17594. + __swait_wake_locked(&x->wait, TASK_NORMAL, 0);
  17595. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  17596. }
  17597. EXPORT_SYMBOL(complete_all);
  17598. @@ -62,20 +62,20 @@
  17599. long (*action)(long), long timeout, int state)
  17600. {
  17601. if (!x->done) {
  17602. - DECLARE_WAITQUEUE(wait, current);
  17603. + DEFINE_SWAITER(wait);
  17604. - __add_wait_queue_tail_exclusive(&x->wait, &wait);
  17605. + swait_prepare_locked(&x->wait, &wait);
  17606. do {
  17607. if (signal_pending_state(state, current)) {
  17608. timeout = -ERESTARTSYS;
  17609. break;
  17610. }
  17611. __set_current_state(state);
  17612. - spin_unlock_irq(&x->wait.lock);
  17613. + raw_spin_unlock_irq(&x->wait.lock);
  17614. timeout = action(timeout);
  17615. - spin_lock_irq(&x->wait.lock);
  17616. + raw_spin_lock_irq(&x->wait.lock);
  17617. } while (!x->done && timeout);
  17618. - __remove_wait_queue(&x->wait, &wait);
  17619. + swait_finish_locked(&x->wait, &wait);
  17620. if (!x->done)
  17621. return timeout;
  17622. }
  17623. @@ -89,9 +89,9 @@
  17624. {
  17625. might_sleep();
  17626. - spin_lock_irq(&x->wait.lock);
  17627. + raw_spin_lock_irq(&x->wait.lock);
  17628. timeout = do_wait_for_common(x, action, timeout, state);
  17629. - spin_unlock_irq(&x->wait.lock);
  17630. + raw_spin_unlock_irq(&x->wait.lock);
  17631. return timeout;
  17632. }
  17633. @@ -277,12 +277,12 @@
  17634. if (!READ_ONCE(x->done))
  17635. return 0;
  17636. - spin_lock_irqsave(&x->wait.lock, flags);
  17637. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  17638. if (!x->done)
  17639. ret = 0;
  17640. else
  17641. x->done--;
  17642. - spin_unlock_irqrestore(&x->wait.lock, flags);
  17643. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  17644. return ret;
  17645. }
  17646. EXPORT_SYMBOL(try_wait_for_completion);
  17647. @@ -311,7 +311,7 @@
  17648. * after it's acquired the lock.
  17649. */
  17650. smp_rmb();
  17651. - spin_unlock_wait(&x->wait.lock);
  17652. + raw_spin_unlock_wait(&x->wait.lock);
  17653. return true;
  17654. }
  17655. EXPORT_SYMBOL(completion_done);
  17656. diff -Nur linux-4.1.26.orig/kernel/sched/core.c linux-4.1.26/kernel/sched/core.c
  17657. --- linux-4.1.26.orig/kernel/sched/core.c 2016-06-07 01:13:11.000000000 +0200
  17658. +++ linux-4.1.26/kernel/sched/core.c 2016-06-19 15:30:58.703297966 +0200
  17659. @@ -282,7 +282,11 @@
  17660. * Number of tasks to iterate in a single balance run.
  17661. * Limited because this is done with IRQs disabled.
  17662. */
  17663. +#ifndef CONFIG_PREEMPT_RT_FULL
  17664. const_debug unsigned int sysctl_sched_nr_migrate = 32;
  17665. +#else
  17666. +const_debug unsigned int sysctl_sched_nr_migrate = 8;
  17667. +#endif
  17668. /*
  17669. * period over which we average the RT time consumption, measured
  17670. @@ -461,6 +465,7 @@
  17671. hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  17672. rq->hrtick_timer.function = hrtick;
  17673. + rq->hrtick_timer.irqsafe = 1;
  17674. }
  17675. #else /* CONFIG_SCHED_HRTICK */
  17676. static inline void hrtick_clear(struct rq *rq)
  17677. @@ -541,6 +546,52 @@
  17678. #endif
  17679. #endif
  17680. +void wake_q_add(struct wake_q_head *head, struct task_struct *task)
  17681. +{
  17682. + struct wake_q_node *node = &task->wake_q;
  17683. +
  17684. + /*
  17685. + * Atomically grab the task, if ->wake_q is !nil already it means
  17686. + * its already queued (either by us or someone else) and will get the
  17687. + * wakeup due to that.
  17688. + *
  17689. + * This cmpxchg() implies a full barrier, which pairs with the write
  17690. + * barrier implied by the wakeup in wake_up_list().
  17691. + */
  17692. + if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL))
  17693. + return;
  17694. +
  17695. + get_task_struct(task);
  17696. +
  17697. + /*
  17698. + * The head is context local, there can be no concurrency.
  17699. + */
  17700. + *head->lastp = node;
  17701. + head->lastp = &node->next;
  17702. +}
  17703. +
  17704. +void wake_up_q(struct wake_q_head *head)
  17705. +{
  17706. + struct wake_q_node *node = head->first;
  17707. +
  17708. + while (node != WAKE_Q_TAIL) {
  17709. + struct task_struct *task;
  17710. +
  17711. + task = container_of(node, struct task_struct, wake_q);
  17712. + BUG_ON(!task);
  17713. + /* task can safely be re-inserted now */
  17714. + node = node->next;
  17715. + task->wake_q.next = NULL;
  17716. +
  17717. + /*
  17718. + * wake_up_process() implies a wmb() to pair with the queueing
  17719. + * in wake_q_add() so as not to miss wakeups.
  17720. + */
  17721. + wake_up_process(task);
  17722. + put_task_struct(task);
  17723. + }
  17724. +}
  17725. +
  17726. /*
  17727. * resched_curr - mark rq's current task 'to be rescheduled now'.
  17728. *
  17729. @@ -572,6 +623,38 @@
  17730. trace_sched_wake_idle_without_ipi(cpu);
  17731. }
  17732. +#ifdef CONFIG_PREEMPT_LAZY
  17733. +void resched_curr_lazy(struct rq *rq)
  17734. +{
  17735. + struct task_struct *curr = rq->curr;
  17736. + int cpu;
  17737. +
  17738. + if (!sched_feat(PREEMPT_LAZY)) {
  17739. + resched_curr(rq);
  17740. + return;
  17741. + }
  17742. +
  17743. + lockdep_assert_held(&rq->lock);
  17744. +
  17745. + if (test_tsk_need_resched(curr))
  17746. + return;
  17747. +
  17748. + if (test_tsk_need_resched_lazy(curr))
  17749. + return;
  17750. +
  17751. + set_tsk_need_resched_lazy(curr);
  17752. +
  17753. + cpu = cpu_of(rq);
  17754. + if (cpu == smp_processor_id())
  17755. + return;
  17756. +
  17757. + /* NEED_RESCHED_LAZY must be visible before we test polling */
  17758. + smp_mb();
  17759. + if (!tsk_is_polling(curr))
  17760. + smp_send_reschedule(cpu);
  17761. +}
  17762. +#endif
  17763. +
  17764. void resched_cpu(int cpu)
  17765. {
  17766. struct rq *rq = cpu_rq(cpu);
  17767. @@ -595,12 +678,14 @@
  17768. */
  17769. int get_nohz_timer_target(int pinned)
  17770. {
  17771. - int cpu = smp_processor_id();
  17772. + int cpu;
  17773. int i;
  17774. struct sched_domain *sd;
  17775. + preempt_disable_rt();
  17776. + cpu = smp_processor_id();
  17777. if (pinned || !get_sysctl_timer_migration() || !idle_cpu(cpu))
  17778. - return cpu;
  17779. + goto preempt_en_rt;
  17780. rcu_read_lock();
  17781. for_each_domain(cpu, sd) {
  17782. @@ -613,6 +698,8 @@
  17783. }
  17784. unlock:
  17785. rcu_read_unlock();
  17786. +preempt_en_rt:
  17787. + preempt_enable_rt();
  17788. return cpu;
  17789. }
  17790. /*
  17791. @@ -1164,6 +1251,18 @@
  17792. static int migration_cpu_stop(void *data);
  17793. +static bool check_task_state(struct task_struct *p, long match_state)
  17794. +{
  17795. + bool match = false;
  17796. +
  17797. + raw_spin_lock_irq(&p->pi_lock);
  17798. + if (p->state == match_state || p->saved_state == match_state)
  17799. + match = true;
  17800. + raw_spin_unlock_irq(&p->pi_lock);
  17801. +
  17802. + return match;
  17803. +}
  17804. +
  17805. /*
  17806. * wait_task_inactive - wait for a thread to unschedule.
  17807. *
  17808. @@ -1208,7 +1307,7 @@
  17809. * is actually now running somewhere else!
  17810. */
  17811. while (task_running(rq, p)) {
  17812. - if (match_state && unlikely(p->state != match_state))
  17813. + if (match_state && !check_task_state(p, match_state))
  17814. return 0;
  17815. cpu_relax();
  17816. }
  17817. @@ -1223,7 +1322,8 @@
  17818. running = task_running(rq, p);
  17819. queued = task_on_rq_queued(p);
  17820. ncsw = 0;
  17821. - if (!match_state || p->state == match_state)
  17822. + if (!match_state || p->state == match_state ||
  17823. + p->saved_state == match_state)
  17824. ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
  17825. task_rq_unlock(rq, p, &flags);
  17826. @@ -1449,10 +1549,6 @@
  17827. {
  17828. activate_task(rq, p, en_flags);
  17829. p->on_rq = TASK_ON_RQ_QUEUED;
  17830. -
  17831. - /* if a worker is waking up, notify workqueue */
  17832. - if (p->flags & PF_WQ_WORKER)
  17833. - wq_worker_waking_up(p, cpu_of(rq));
  17834. }
  17835. /*
  17836. @@ -1462,9 +1558,9 @@
  17837. ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
  17838. {
  17839. check_preempt_curr(rq, p, wake_flags);
  17840. - trace_sched_wakeup(p, true);
  17841. -
  17842. p->state = TASK_RUNNING;
  17843. + trace_sched_wakeup(p);
  17844. +
  17845. #ifdef CONFIG_SMP
  17846. if (p->sched_class->task_woken)
  17847. p->sched_class->task_woken(rq, p);
  17848. @@ -1666,8 +1762,29 @@
  17849. */
  17850. smp_mb__before_spinlock();
  17851. raw_spin_lock_irqsave(&p->pi_lock, flags);
  17852. - if (!(p->state & state))
  17853. + if (!(p->state & state)) {
  17854. + /*
  17855. + * The task might be running due to a spinlock sleeper
  17856. + * wakeup. Check the saved state and set it to running
  17857. + * if the wakeup condition is true.
  17858. + */
  17859. + if (!(wake_flags & WF_LOCK_SLEEPER)) {
  17860. + if (p->saved_state & state) {
  17861. + p->saved_state = TASK_RUNNING;
  17862. + success = 1;
  17863. + }
  17864. + }
  17865. goto out;
  17866. + }
  17867. +
  17868. + /*
  17869. + * If this is a regular wakeup, then we can unconditionally
  17870. + * clear the saved state of a "lock sleeper".
  17871. + */
  17872. + if (!(wake_flags & WF_LOCK_SLEEPER))
  17873. + p->saved_state = TASK_RUNNING;
  17874. +
  17875. + trace_sched_waking(p);
  17876. success = 1; /* we're going to change ->state */
  17877. cpu = task_cpu(p);
  17878. @@ -1710,42 +1827,6 @@
  17879. }
  17880. /**
  17881. - * try_to_wake_up_local - try to wake up a local task with rq lock held
  17882. - * @p: the thread to be awakened
  17883. - *
  17884. - * Put @p on the run-queue if it's not already there. The caller must
  17885. - * ensure that this_rq() is locked, @p is bound to this_rq() and not
  17886. - * the current task.
  17887. - */
  17888. -static void try_to_wake_up_local(struct task_struct *p)
  17889. -{
  17890. - struct rq *rq = task_rq(p);
  17891. -
  17892. - if (WARN_ON_ONCE(rq != this_rq()) ||
  17893. - WARN_ON_ONCE(p == current))
  17894. - return;
  17895. -
  17896. - lockdep_assert_held(&rq->lock);
  17897. -
  17898. - if (!raw_spin_trylock(&p->pi_lock)) {
  17899. - raw_spin_unlock(&rq->lock);
  17900. - raw_spin_lock(&p->pi_lock);
  17901. - raw_spin_lock(&rq->lock);
  17902. - }
  17903. -
  17904. - if (!(p->state & TASK_NORMAL))
  17905. - goto out;
  17906. -
  17907. - if (!task_on_rq_queued(p))
  17908. - ttwu_activate(rq, p, ENQUEUE_WAKEUP);
  17909. -
  17910. - ttwu_do_wakeup(rq, p, 0);
  17911. - ttwu_stat(p, smp_processor_id(), 0);
  17912. -out:
  17913. - raw_spin_unlock(&p->pi_lock);
  17914. -}
  17915. -
  17916. -/**
  17917. * wake_up_process - Wake up a specific process
  17918. * @p: The process to be woken up.
  17919. *
  17920. @@ -1759,11 +1840,23 @@
  17921. */
  17922. int wake_up_process(struct task_struct *p)
  17923. {
  17924. - WARN_ON(task_is_stopped_or_traced(p));
  17925. + WARN_ON(__task_is_stopped_or_traced(p));
  17926. return try_to_wake_up(p, TASK_NORMAL, 0);
  17927. }
  17928. EXPORT_SYMBOL(wake_up_process);
  17929. +/**
  17930. + * wake_up_lock_sleeper - Wake up a specific process blocked on a "sleeping lock"
  17931. + * @p: The process to be woken up.
  17932. + *
  17933. + * Same as wake_up_process() above, but wake_flags=WF_LOCK_SLEEPER to indicate
  17934. + * the nature of the wakeup.
  17935. + */
  17936. +int wake_up_lock_sleeper(struct task_struct *p)
  17937. +{
  17938. + return try_to_wake_up(p, TASK_ALL, WF_LOCK_SLEEPER);
  17939. +}
  17940. +
  17941. int wake_up_state(struct task_struct *p, unsigned int state)
  17942. {
  17943. return try_to_wake_up(p, state, 0);
  17944. @@ -1959,6 +2052,9 @@
  17945. p->on_cpu = 0;
  17946. #endif
  17947. init_task_preempt_count(p);
  17948. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  17949. + task_thread_info(p)->preempt_lazy_count = 0;
  17950. +#endif
  17951. #ifdef CONFIG_SMP
  17952. plist_node_init(&p->pushable_tasks, MAX_PRIO);
  17953. RB_CLEAR_NODE(&p->pushable_dl_tasks);
  17954. @@ -2094,7 +2190,7 @@
  17955. rq = __task_rq_lock(p);
  17956. activate_task(rq, p, 0);
  17957. p->on_rq = TASK_ON_RQ_QUEUED;
  17958. - trace_sched_wakeup_new(p, true);
  17959. + trace_sched_wakeup_new(p);
  17960. check_preempt_curr(rq, p, WF_FORK);
  17961. #ifdef CONFIG_SMP
  17962. if (p->sched_class->task_woken)
  17963. @@ -2231,8 +2327,12 @@
  17964. finish_arch_post_lock_switch();
  17965. fire_sched_in_preempt_notifiers(current);
  17966. + /*
  17967. + * We use mmdrop_delayed() here so we don't have to do the
  17968. + * full __mmdrop() when we are the last user.
  17969. + */
  17970. if (mm)
  17971. - mmdrop(mm);
  17972. + mmdrop_delayed(mm);
  17973. if (unlikely(prev_state == TASK_DEAD)) {
  17974. if (prev->sched_class->task_dead)
  17975. prev->sched_class->task_dead(prev);
  17976. @@ -2543,16 +2643,6 @@
  17977. }
  17978. #endif
  17979. -notrace unsigned long get_parent_ip(unsigned long addr)
  17980. -{
  17981. - if (in_lock_functions(addr)) {
  17982. - addr = CALLER_ADDR2;
  17983. - if (in_lock_functions(addr))
  17984. - addr = CALLER_ADDR3;
  17985. - }
  17986. - return addr;
  17987. -}
  17988. -
  17989. #if defined(CONFIG_PREEMPT) && (defined(CONFIG_DEBUG_PREEMPT) || \
  17990. defined(CONFIG_PREEMPT_TRACER))
  17991. @@ -2574,7 +2664,7 @@
  17992. PREEMPT_MASK - 10);
  17993. #endif
  17994. if (preempt_count() == val) {
  17995. - unsigned long ip = get_parent_ip(CALLER_ADDR1);
  17996. + unsigned long ip = get_lock_parent_ip();
  17997. #ifdef CONFIG_DEBUG_PREEMPT
  17998. current->preempt_disable_ip = ip;
  17999. #endif
  18000. @@ -2601,7 +2691,7 @@
  18001. #endif
  18002. if (preempt_count() == val)
  18003. - trace_preempt_on(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
  18004. + trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip());
  18005. __preempt_count_sub(val);
  18006. }
  18007. EXPORT_SYMBOL(preempt_count_sub);
  18008. @@ -2657,6 +2747,133 @@
  18009. schedstat_inc(this_rq(), sched_count);
  18010. }
  18011. +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
  18012. +#define MIGRATE_DISABLE_SET_AFFIN (1<<30) /* Can't make a negative */
  18013. +#define migrate_disabled_updated(p) ((p)->migrate_disable & MIGRATE_DISABLE_SET_AFFIN)
  18014. +#define migrate_disable_count(p) ((p)->migrate_disable & ~MIGRATE_DISABLE_SET_AFFIN)
  18015. +
  18016. +static inline void update_migrate_disable(struct task_struct *p)
  18017. +{
  18018. + const struct cpumask *mask;
  18019. +
  18020. + if (likely(!p->migrate_disable))
  18021. + return;
  18022. +
  18023. + /* Did we already update affinity? */
  18024. + if (unlikely(migrate_disabled_updated(p)))
  18025. + return;
  18026. +
  18027. + /*
  18028. + * Since this is always current we can get away with only locking
  18029. + * rq->lock, the ->cpus_allowed value can normally only be changed
  18030. + * while holding both p->pi_lock and rq->lock, but seeing that this
  18031. + * is current, we cannot actually be waking up, so all code that
  18032. + * relies on serialization against p->pi_lock is out of scope.
  18033. + *
  18034. + * Having rq->lock serializes us against things like
  18035. + * set_cpus_allowed_ptr() that can still happen concurrently.
  18036. + */
  18037. + mask = tsk_cpus_allowed(p);
  18038. +
  18039. + if (p->sched_class->set_cpus_allowed)
  18040. + p->sched_class->set_cpus_allowed(p, mask);
  18041. + /* mask==cpumask_of(task_cpu(p)) which has a cpumask_weight==1 */
  18042. + p->nr_cpus_allowed = 1;
  18043. +
  18044. + /* Let migrate_enable know to fix things back up */
  18045. + p->migrate_disable |= MIGRATE_DISABLE_SET_AFFIN;
  18046. +}
  18047. +
  18048. +void migrate_disable(void)
  18049. +{
  18050. + struct task_struct *p = current;
  18051. +
  18052. + if (in_atomic() || irqs_disabled()) {
  18053. +#ifdef CONFIG_SCHED_DEBUG
  18054. + p->migrate_disable_atomic++;
  18055. +#endif
  18056. + return;
  18057. + }
  18058. +
  18059. +#ifdef CONFIG_SCHED_DEBUG
  18060. + if (unlikely(p->migrate_disable_atomic)) {
  18061. + tracing_off();
  18062. + WARN_ON_ONCE(1);
  18063. + }
  18064. +#endif
  18065. +
  18066. + if (p->migrate_disable) {
  18067. + p->migrate_disable++;
  18068. + return;
  18069. + }
  18070. +
  18071. + preempt_disable();
  18072. + preempt_lazy_disable();
  18073. + pin_current_cpu();
  18074. + p->migrate_disable = 1;
  18075. + preempt_enable();
  18076. +}
  18077. +EXPORT_SYMBOL(migrate_disable);
  18078. +
  18079. +void migrate_enable(void)
  18080. +{
  18081. + struct task_struct *p = current;
  18082. + const struct cpumask *mask;
  18083. + unsigned long flags;
  18084. + struct rq *rq;
  18085. +
  18086. + if (in_atomic() || irqs_disabled()) {
  18087. +#ifdef CONFIG_SCHED_DEBUG
  18088. + p->migrate_disable_atomic--;
  18089. +#endif
  18090. + return;
  18091. + }
  18092. +
  18093. +#ifdef CONFIG_SCHED_DEBUG
  18094. + if (unlikely(p->migrate_disable_atomic)) {
  18095. + tracing_off();
  18096. + WARN_ON_ONCE(1);
  18097. + }
  18098. +#endif
  18099. + WARN_ON_ONCE(p->migrate_disable <= 0);
  18100. +
  18101. + if (migrate_disable_count(p) > 1) {
  18102. + p->migrate_disable--;
  18103. + return;
  18104. + }
  18105. +
  18106. + preempt_disable();
  18107. + if (unlikely(migrate_disabled_updated(p))) {
  18108. + /*
  18109. + * Undo whatever update_migrate_disable() did, also see there
  18110. + * about locking.
  18111. + */
  18112. + rq = this_rq();
  18113. + raw_spin_lock_irqsave(&rq->lock, flags);
  18114. +
  18115. + /*
  18116. + * Clearing migrate_disable causes tsk_cpus_allowed to
  18117. + * show the tasks original cpu affinity.
  18118. + */
  18119. + p->migrate_disable = 0;
  18120. + mask = tsk_cpus_allowed(p);
  18121. + if (p->sched_class->set_cpus_allowed)
  18122. + p->sched_class->set_cpus_allowed(p, mask);
  18123. + p->nr_cpus_allowed = cpumask_weight(mask);
  18124. + raw_spin_unlock_irqrestore(&rq->lock, flags);
  18125. + } else
  18126. + p->migrate_disable = 0;
  18127. +
  18128. + unpin_current_cpu();
  18129. + preempt_enable();
  18130. + preempt_lazy_enable();
  18131. +}
  18132. +EXPORT_SYMBOL(migrate_enable);
  18133. +#else
  18134. +static inline void update_migrate_disable(struct task_struct *p) { }
  18135. +#define migrate_disabled_updated(p) 0
  18136. +#endif
  18137. +
  18138. /*
  18139. * Pick up the highest-prio task:
  18140. */
  18141. @@ -2763,6 +2980,8 @@
  18142. smp_mb__before_spinlock();
  18143. raw_spin_lock_irq(&rq->lock);
  18144. + update_migrate_disable(prev);
  18145. +
  18146. rq->clock_skip_update <<= 1; /* promote REQ to ACT */
  18147. switch_count = &prev->nivcsw;
  18148. @@ -2772,19 +2991,6 @@
  18149. } else {
  18150. deactivate_task(rq, prev, DEQUEUE_SLEEP);
  18151. prev->on_rq = 0;
  18152. -
  18153. - /*
  18154. - * If a worker went to sleep, notify and ask workqueue
  18155. - * whether it wants to wake up a task to maintain
  18156. - * concurrency.
  18157. - */
  18158. - if (prev->flags & PF_WQ_WORKER) {
  18159. - struct task_struct *to_wakeup;
  18160. -
  18161. - to_wakeup = wq_worker_sleeping(prev, cpu);
  18162. - if (to_wakeup)
  18163. - try_to_wake_up_local(to_wakeup);
  18164. - }
  18165. }
  18166. switch_count = &prev->nvcsw;
  18167. }
  18168. @@ -2794,6 +3000,7 @@
  18169. next = pick_next_task(rq, prev);
  18170. clear_tsk_need_resched(prev);
  18171. + clear_tsk_need_resched_lazy(prev);
  18172. clear_preempt_need_resched();
  18173. rq->clock_skip_update = 0;
  18174. @@ -2814,8 +3021,19 @@
  18175. static inline void sched_submit_work(struct task_struct *tsk)
  18176. {
  18177. - if (!tsk->state || tsk_is_pi_blocked(tsk))
  18178. + if (!tsk->state)
  18179. + return;
  18180. + /*
  18181. + * If a worker went to sleep, notify and ask workqueue whether
  18182. + * it wants to wake up a task to maintain concurrency.
  18183. + */
  18184. + if (tsk->flags & PF_WQ_WORKER)
  18185. + wq_worker_sleeping(tsk);
  18186. +
  18187. +
  18188. + if (tsk_is_pi_blocked(tsk))
  18189. return;
  18190. +
  18191. /*
  18192. * If we are going to sleep and we have plugged IO queued,
  18193. * make sure to submit it to avoid deadlocks.
  18194. @@ -2824,6 +3042,12 @@
  18195. blk_schedule_flush_plug(tsk);
  18196. }
  18197. +static void sched_update_worker(struct task_struct *tsk)
  18198. +{
  18199. + if (tsk->flags & PF_WQ_WORKER)
  18200. + wq_worker_running(tsk);
  18201. +}
  18202. +
  18203. asmlinkage __visible void __sched schedule(void)
  18204. {
  18205. struct task_struct *tsk = current;
  18206. @@ -2832,6 +3056,7 @@
  18207. do {
  18208. __schedule();
  18209. } while (need_resched());
  18210. + sched_update_worker(tsk);
  18211. }
  18212. EXPORT_SYMBOL(schedule);
  18213. @@ -2881,6 +3106,30 @@
  18214. } while (need_resched());
  18215. }
  18216. +#ifdef CONFIG_PREEMPT_LAZY
  18217. +/*
  18218. + * If TIF_NEED_RESCHED is then we allow to be scheduled away since this is
  18219. + * set by a RT task. Oterwise we try to avoid beeing scheduled out as long as
  18220. + * preempt_lazy_count counter >0.
  18221. + */
  18222. +static __always_inline int preemptible_lazy(void)
  18223. +{
  18224. + if (test_thread_flag(TIF_NEED_RESCHED))
  18225. + return 1;
  18226. + if (current_thread_info()->preempt_lazy_count)
  18227. + return 0;
  18228. + return 1;
  18229. +}
  18230. +
  18231. +#else
  18232. +
  18233. +static int preemptible_lazy(void)
  18234. +{
  18235. + return 1;
  18236. +}
  18237. +
  18238. +#endif
  18239. +
  18240. #ifdef CONFIG_PREEMPT
  18241. /*
  18242. * this is the entry point to schedule() from in-kernel preemption
  18243. @@ -2895,6 +3144,8 @@
  18244. */
  18245. if (likely(!preemptible()))
  18246. return;
  18247. + if (!preemptible_lazy())
  18248. + return;
  18249. preempt_schedule_common();
  18250. }
  18251. @@ -2922,6 +3173,8 @@
  18252. if (likely(!preemptible()))
  18253. return;
  18254. + if (!preemptible_lazy())
  18255. + return;
  18256. do {
  18257. __preempt_count_add(PREEMPT_ACTIVE);
  18258. @@ -2931,7 +3184,16 @@
  18259. * an infinite recursion.
  18260. */
  18261. prev_ctx = exception_enter();
  18262. + /*
  18263. + * The add/subtract must not be traced by the function
  18264. + * tracer. But we still want to account for the
  18265. + * preempt off latency tracer. Since the _notrace versions
  18266. + * of add/subtract skip the accounting for latency tracer
  18267. + * we must force it manually.
  18268. + */
  18269. + start_critical_timings();
  18270. __schedule();
  18271. + stop_critical_timings();
  18272. exception_exit(prev_ctx);
  18273. __preempt_count_sub(PREEMPT_ACTIVE);
  18274. @@ -4268,6 +4530,7 @@
  18275. }
  18276. EXPORT_SYMBOL(__cond_resched_lock);
  18277. +#ifndef CONFIG_PREEMPT_RT_FULL
  18278. int __sched __cond_resched_softirq(void)
  18279. {
  18280. BUG_ON(!in_softirq());
  18281. @@ -4281,6 +4544,7 @@
  18282. return 0;
  18283. }
  18284. EXPORT_SYMBOL(__cond_resched_softirq);
  18285. +#endif
  18286. /**
  18287. * yield - yield the current processor to other threads.
  18288. @@ -4635,7 +4899,9 @@
  18289. /* Set the preempt count _outside_ the spinlocks! */
  18290. init_idle_preempt_count(idle, cpu);
  18291. -
  18292. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  18293. + task_thread_info(idle)->preempt_lazy_count = 0;
  18294. +#endif
  18295. /*
  18296. * The idle tasks have their own, simple scheduling class:
  18297. */
  18298. @@ -4755,11 +5021,91 @@
  18299. void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
  18300. {
  18301. - if (p->sched_class->set_cpus_allowed)
  18302. - p->sched_class->set_cpus_allowed(p, new_mask);
  18303. + if (!migrate_disabled_updated(p)) {
  18304. + if (p->sched_class->set_cpus_allowed)
  18305. + p->sched_class->set_cpus_allowed(p, new_mask);
  18306. + p->nr_cpus_allowed = cpumask_weight(new_mask);
  18307. + }
  18308. cpumask_copy(&p->cpus_allowed, new_mask);
  18309. - p->nr_cpus_allowed = cpumask_weight(new_mask);
  18310. +}
  18311. +
  18312. +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
  18313. +static DEFINE_MUTEX(sched_down_mutex);
  18314. +static cpumask_t sched_down_cpumask;
  18315. +
  18316. +void tell_sched_cpu_down_begin(int cpu)
  18317. +{
  18318. + mutex_lock(&sched_down_mutex);
  18319. + cpumask_set_cpu(cpu, &sched_down_cpumask);
  18320. + mutex_unlock(&sched_down_mutex);
  18321. +}
  18322. +
  18323. +void tell_sched_cpu_down_done(int cpu)
  18324. +{
  18325. + mutex_lock(&sched_down_mutex);
  18326. + cpumask_clear_cpu(cpu, &sched_down_cpumask);
  18327. + mutex_unlock(&sched_down_mutex);
  18328. +}
  18329. +
  18330. +/**
  18331. + * migrate_me - try to move the current task off this cpu
  18332. + *
  18333. + * Used by the pin_current_cpu() code to try to get tasks
  18334. + * to move off the current CPU as it is going down.
  18335. + * It will only move the task if the task isn't pinned to
  18336. + * the CPU (with migrate_disable, affinity or NO_SETAFFINITY)
  18337. + * and the task has to be in a RUNNING state. Otherwise the
  18338. + * movement of the task will wake it up (change its state
  18339. + * to running) when the task did not expect it.
  18340. + *
  18341. + * Returns 1 if it succeeded in moving the current task
  18342. + * 0 otherwise.
  18343. + */
  18344. +int migrate_me(void)
  18345. +{
  18346. + struct task_struct *p = current;
  18347. + struct migration_arg arg;
  18348. + struct cpumask *cpumask;
  18349. + struct cpumask *mask;
  18350. + unsigned long flags;
  18351. + unsigned int dest_cpu;
  18352. + struct rq *rq;
  18353. +
  18354. + /*
  18355. + * We can not migrate tasks bounded to a CPU or tasks not
  18356. + * running. The movement of the task will wake it up.
  18357. + */
  18358. + if (p->flags & PF_NO_SETAFFINITY || p->state)
  18359. + return 0;
  18360. +
  18361. + mutex_lock(&sched_down_mutex);
  18362. + rq = task_rq_lock(p, &flags);
  18363. +
  18364. + cpumask = this_cpu_ptr(&sched_cpumasks);
  18365. + mask = &p->cpus_allowed;
  18366. +
  18367. + cpumask_andnot(cpumask, mask, &sched_down_cpumask);
  18368. +
  18369. + if (!cpumask_weight(cpumask)) {
  18370. + /* It's only on this CPU? */
  18371. + task_rq_unlock(rq, p, &flags);
  18372. + mutex_unlock(&sched_down_mutex);
  18373. + return 0;
  18374. + }
  18375. +
  18376. + dest_cpu = cpumask_any_and(cpu_active_mask, cpumask);
  18377. +
  18378. + arg.task = p;
  18379. + arg.dest_cpu = dest_cpu;
  18380. +
  18381. + task_rq_unlock(rq, p, &flags);
  18382. +
  18383. + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
  18384. + tlb_migrate_finish(p->mm);
  18385. + mutex_unlock(&sched_down_mutex);
  18386. +
  18387. + return 1;
  18388. }
  18389. /*
  18390. @@ -4805,7 +5151,7 @@
  18391. do_set_cpus_allowed(p, new_mask);
  18392. /* Can the task run on the task's current CPU? If so, we're done */
  18393. - if (cpumask_test_cpu(task_cpu(p), new_mask))
  18394. + if (cpumask_test_cpu(task_cpu(p), new_mask) || __migrate_disabled(p))
  18395. goto out;
  18396. dest_cpu = cpumask_any_and(cpu_active_mask, new_mask);
  18397. @@ -4945,6 +5291,8 @@
  18398. #ifdef CONFIG_HOTPLUG_CPU
  18399. +static DEFINE_PER_CPU(struct mm_struct *, idle_last_mm);
  18400. +
  18401. /*
  18402. * Ensures that the idle task is using init_mm right before its cpu goes
  18403. * offline.
  18404. @@ -4959,7 +5307,11 @@
  18405. switch_mm(mm, &init_mm, current);
  18406. finish_arch_post_lock_switch();
  18407. }
  18408. - mmdrop(mm);
  18409. + /*
  18410. + * Defer the cleanup to an alive cpu. On RT we can neither
  18411. + * call mmdrop() nor mmdrop_delayed() from here.
  18412. + */
  18413. + per_cpu(idle_last_mm, smp_processor_id()) = mm;
  18414. }
  18415. /*
  18416. @@ -5302,6 +5654,10 @@
  18417. case CPU_DEAD:
  18418. calc_load_migrate(rq);
  18419. + if (per_cpu(idle_last_mm, cpu)) {
  18420. + mmdrop(per_cpu(idle_last_mm, cpu));
  18421. + per_cpu(idle_last_mm, cpu) = NULL;
  18422. + }
  18423. break;
  18424. #endif
  18425. }
  18426. @@ -7281,7 +7637,8 @@
  18427. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  18428. static inline int preempt_count_equals(int preempt_offset)
  18429. {
  18430. - int nested = (preempt_count() & ~PREEMPT_ACTIVE) + rcu_preempt_depth();
  18431. + int nested = (preempt_count() & ~PREEMPT_ACTIVE) +
  18432. + sched_rcu_preempt_depth();
  18433. return (nested == preempt_offset);
  18434. }
  18435. diff -Nur linux-4.1.26.orig/kernel/sched/cputime.c linux-4.1.26/kernel/sched/cputime.c
  18436. --- linux-4.1.26.orig/kernel/sched/cputime.c 2016-06-07 01:13:11.000000000 +0200
  18437. +++ linux-4.1.26/kernel/sched/cputime.c 2016-06-19 15:30:58.703297966 +0200
  18438. @@ -675,37 +675,45 @@
  18439. void vtime_account_system(struct task_struct *tsk)
  18440. {
  18441. - write_seqlock(&tsk->vtime_seqlock);
  18442. + raw_spin_lock(&tsk->vtime_lock);
  18443. + write_seqcount_begin(&tsk->vtime_seq);
  18444. __vtime_account_system(tsk);
  18445. - write_sequnlock(&tsk->vtime_seqlock);
  18446. + write_seqcount_end(&tsk->vtime_seq);
  18447. + raw_spin_unlock(&tsk->vtime_lock);
  18448. }
  18449. void vtime_gen_account_irq_exit(struct task_struct *tsk)
  18450. {
  18451. - write_seqlock(&tsk->vtime_seqlock);
  18452. + raw_spin_lock(&tsk->vtime_lock);
  18453. + write_seqcount_begin(&tsk->vtime_seq);
  18454. __vtime_account_system(tsk);
  18455. if (context_tracking_in_user())
  18456. tsk->vtime_snap_whence = VTIME_USER;
  18457. - write_sequnlock(&tsk->vtime_seqlock);
  18458. + write_seqcount_end(&tsk->vtime_seq);
  18459. + raw_spin_unlock(&tsk->vtime_lock);
  18460. }
  18461. void vtime_account_user(struct task_struct *tsk)
  18462. {
  18463. cputime_t delta_cpu;
  18464. - write_seqlock(&tsk->vtime_seqlock);
  18465. + raw_spin_lock(&tsk->vtime_lock);
  18466. + write_seqcount_begin(&tsk->vtime_seq);
  18467. delta_cpu = get_vtime_delta(tsk);
  18468. tsk->vtime_snap_whence = VTIME_SYS;
  18469. account_user_time(tsk, delta_cpu, cputime_to_scaled(delta_cpu));
  18470. - write_sequnlock(&tsk->vtime_seqlock);
  18471. + write_seqcount_end(&tsk->vtime_seq);
  18472. + raw_spin_unlock(&tsk->vtime_lock);
  18473. }
  18474. void vtime_user_enter(struct task_struct *tsk)
  18475. {
  18476. - write_seqlock(&tsk->vtime_seqlock);
  18477. + raw_spin_lock(&tsk->vtime_lock);
  18478. + write_seqcount_begin(&tsk->vtime_seq);
  18479. __vtime_account_system(tsk);
  18480. tsk->vtime_snap_whence = VTIME_USER;
  18481. - write_sequnlock(&tsk->vtime_seqlock);
  18482. + write_seqcount_end(&tsk->vtime_seq);
  18483. + raw_spin_unlock(&tsk->vtime_lock);
  18484. }
  18485. void vtime_guest_enter(struct task_struct *tsk)
  18486. @@ -717,19 +725,23 @@
  18487. * synchronization against the reader (task_gtime())
  18488. * that can thus safely catch up with a tickless delta.
  18489. */
  18490. - write_seqlock(&tsk->vtime_seqlock);
  18491. + raw_spin_lock(&tsk->vtime_lock);
  18492. + write_seqcount_begin(&tsk->vtime_seq);
  18493. __vtime_account_system(tsk);
  18494. current->flags |= PF_VCPU;
  18495. - write_sequnlock(&tsk->vtime_seqlock);
  18496. + write_seqcount_end(&tsk->vtime_seq);
  18497. + raw_spin_unlock(&tsk->vtime_lock);
  18498. }
  18499. EXPORT_SYMBOL_GPL(vtime_guest_enter);
  18500. void vtime_guest_exit(struct task_struct *tsk)
  18501. {
  18502. - write_seqlock(&tsk->vtime_seqlock);
  18503. + raw_spin_lock(&tsk->vtime_lock);
  18504. + write_seqcount_begin(&tsk->vtime_seq);
  18505. __vtime_account_system(tsk);
  18506. current->flags &= ~PF_VCPU;
  18507. - write_sequnlock(&tsk->vtime_seqlock);
  18508. + write_seqcount_end(&tsk->vtime_seq);
  18509. + raw_spin_unlock(&tsk->vtime_lock);
  18510. }
  18511. EXPORT_SYMBOL_GPL(vtime_guest_exit);
  18512. @@ -742,24 +754,30 @@
  18513. void arch_vtime_task_switch(struct task_struct *prev)
  18514. {
  18515. - write_seqlock(&prev->vtime_seqlock);
  18516. + raw_spin_lock(&prev->vtime_lock);
  18517. + write_seqcount_begin(&prev->vtime_seq);
  18518. prev->vtime_snap_whence = VTIME_SLEEPING;
  18519. - write_sequnlock(&prev->vtime_seqlock);
  18520. + write_seqcount_end(&prev->vtime_seq);
  18521. + raw_spin_unlock(&prev->vtime_lock);
  18522. - write_seqlock(&current->vtime_seqlock);
  18523. + raw_spin_lock(&current->vtime_lock);
  18524. + write_seqcount_begin(&current->vtime_seq);
  18525. current->vtime_snap_whence = VTIME_SYS;
  18526. current->vtime_snap = sched_clock_cpu(smp_processor_id());
  18527. - write_sequnlock(&current->vtime_seqlock);
  18528. + write_seqcount_end(&current->vtime_seq);
  18529. + raw_spin_unlock(&current->vtime_lock);
  18530. }
  18531. void vtime_init_idle(struct task_struct *t, int cpu)
  18532. {
  18533. unsigned long flags;
  18534. - write_seqlock_irqsave(&t->vtime_seqlock, flags);
  18535. + raw_spin_lock_irqsave(&t->vtime_lock, flags);
  18536. + write_seqcount_begin(&t->vtime_seq);
  18537. t->vtime_snap_whence = VTIME_SYS;
  18538. t->vtime_snap = sched_clock_cpu(cpu);
  18539. - write_sequnlock_irqrestore(&t->vtime_seqlock, flags);
  18540. + write_seqcount_end(&t->vtime_seq);
  18541. + raw_spin_unlock_irqrestore(&t->vtime_lock, flags);
  18542. }
  18543. cputime_t task_gtime(struct task_struct *t)
  18544. @@ -768,13 +786,13 @@
  18545. cputime_t gtime;
  18546. do {
  18547. - seq = read_seqbegin(&t->vtime_seqlock);
  18548. + seq = read_seqcount_begin(&t->vtime_seq);
  18549. gtime = t->gtime;
  18550. if (t->flags & PF_VCPU)
  18551. gtime += vtime_delta(t);
  18552. - } while (read_seqretry(&t->vtime_seqlock, seq));
  18553. + } while (read_seqcount_retry(&t->vtime_seq, seq));
  18554. return gtime;
  18555. }
  18556. @@ -797,7 +815,7 @@
  18557. *udelta = 0;
  18558. *sdelta = 0;
  18559. - seq = read_seqbegin(&t->vtime_seqlock);
  18560. + seq = read_seqcount_begin(&t->vtime_seq);
  18561. if (u_dst)
  18562. *u_dst = *u_src;
  18563. @@ -821,7 +839,7 @@
  18564. if (t->vtime_snap_whence == VTIME_SYS)
  18565. *sdelta = delta;
  18566. }
  18567. - } while (read_seqretry(&t->vtime_seqlock, seq));
  18568. + } while (read_seqcount_retry(&t->vtime_seq, seq));
  18569. }
  18570. diff -Nur linux-4.1.26.orig/kernel/sched/deadline.c linux-4.1.26/kernel/sched/deadline.c
  18571. --- linux-4.1.26.orig/kernel/sched/deadline.c 2016-06-07 01:13:11.000000000 +0200
  18572. +++ linux-4.1.26/kernel/sched/deadline.c 2016-06-19 15:30:58.703297966 +0200
  18573. @@ -637,6 +637,7 @@
  18574. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  18575. timer->function = dl_task_timer;
  18576. + timer->irqsafe = 1;
  18577. }
  18578. static
  18579. diff -Nur linux-4.1.26.orig/kernel/sched/debug.c linux-4.1.26/kernel/sched/debug.c
  18580. --- linux-4.1.26.orig/kernel/sched/debug.c 2016-06-07 01:13:11.000000000 +0200
  18581. +++ linux-4.1.26/kernel/sched/debug.c 2016-06-19 15:30:58.703297966 +0200
  18582. @@ -260,6 +260,9 @@
  18583. P(rt_throttled);
  18584. PN(rt_time);
  18585. PN(rt_runtime);
  18586. +#ifdef CONFIG_SMP
  18587. + P(rt_nr_migratory);
  18588. +#endif
  18589. #undef PN
  18590. #undef P
  18591. @@ -648,6 +651,10 @@
  18592. #endif
  18593. P(policy);
  18594. P(prio);
  18595. +#ifdef CONFIG_PREEMPT_RT_FULL
  18596. + P(migrate_disable);
  18597. +#endif
  18598. + P(nr_cpus_allowed);
  18599. #undef PN
  18600. #undef __PN
  18601. #undef P
  18602. diff -Nur linux-4.1.26.orig/kernel/sched/fair.c linux-4.1.26/kernel/sched/fair.c
  18603. --- linux-4.1.26.orig/kernel/sched/fair.c 2016-06-07 01:13:11.000000000 +0200
  18604. +++ linux-4.1.26/kernel/sched/fair.c 2016-06-19 15:30:58.703297966 +0200
  18605. @@ -3201,7 +3201,7 @@
  18606. ideal_runtime = sched_slice(cfs_rq, curr);
  18607. delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
  18608. if (delta_exec > ideal_runtime) {
  18609. - resched_curr(rq_of(cfs_rq));
  18610. + resched_curr_lazy(rq_of(cfs_rq));
  18611. /*
  18612. * The current task ran long enough, ensure it doesn't get
  18613. * re-elected due to buddy favours.
  18614. @@ -3225,7 +3225,7 @@
  18615. return;
  18616. if (delta > ideal_runtime)
  18617. - resched_curr(rq_of(cfs_rq));
  18618. + resched_curr_lazy(rq_of(cfs_rq));
  18619. }
  18620. static void
  18621. @@ -3366,7 +3366,7 @@
  18622. * validating it and just reschedule.
  18623. */
  18624. if (queued) {
  18625. - resched_curr(rq_of(cfs_rq));
  18626. + resched_curr_lazy(rq_of(cfs_rq));
  18627. return;
  18628. }
  18629. /*
  18630. @@ -3557,7 +3557,7 @@
  18631. * hierarchy can be throttled
  18632. */
  18633. if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr))
  18634. - resched_curr(rq_of(cfs_rq));
  18635. + resched_curr_lazy(rq_of(cfs_rq));
  18636. }
  18637. static __always_inline
  18638. @@ -4180,7 +4180,7 @@
  18639. if (delta < 0) {
  18640. if (rq->curr == p)
  18641. - resched_curr(rq);
  18642. + resched_curr_lazy(rq);
  18643. return;
  18644. }
  18645. hrtick_start(rq, delta);
  18646. @@ -5076,7 +5076,7 @@
  18647. return;
  18648. preempt:
  18649. - resched_curr(rq);
  18650. + resched_curr_lazy(rq);
  18651. /*
  18652. * Only set the backward buddy when the current task is still
  18653. * on the rq. This can happen when a wakeup gets interleaved
  18654. @@ -7869,7 +7869,7 @@
  18655. * 'current' within the tree based on its new key value.
  18656. */
  18657. swap(curr->vruntime, se->vruntime);
  18658. - resched_curr(rq);
  18659. + resched_curr_lazy(rq);
  18660. }
  18661. se->vruntime -= cfs_rq->min_vruntime;
  18662. @@ -7894,7 +7894,7 @@
  18663. */
  18664. if (rq->curr == p) {
  18665. if (p->prio > oldprio)
  18666. - resched_curr(rq);
  18667. + resched_curr_lazy(rq);
  18668. } else
  18669. check_preempt_curr(rq, p, 0);
  18670. }
  18671. diff -Nur linux-4.1.26.orig/kernel/sched/features.h linux-4.1.26/kernel/sched/features.h
  18672. --- linux-4.1.26.orig/kernel/sched/features.h 2016-06-07 01:13:11.000000000 +0200
  18673. +++ linux-4.1.26/kernel/sched/features.h 2016-06-19 15:30:58.707298121 +0200
  18674. @@ -50,11 +50,19 @@
  18675. */
  18676. SCHED_FEAT(NONTASK_CAPACITY, true)
  18677. +#ifdef CONFIG_PREEMPT_RT_FULL
  18678. +SCHED_FEAT(TTWU_QUEUE, false)
  18679. +# ifdef CONFIG_PREEMPT_LAZY
  18680. +SCHED_FEAT(PREEMPT_LAZY, true)
  18681. +# endif
  18682. +#else
  18683. +
  18684. /*
  18685. * Queue remote wakeups on the target CPU and process them
  18686. * using the scheduler IPI. Reduces rq->lock contention/bounces.
  18687. */
  18688. SCHED_FEAT(TTWU_QUEUE, true)
  18689. +#endif
  18690. #ifdef HAVE_RT_PUSH_IPI
  18691. /*
  18692. diff -Nur linux-4.1.26.orig/kernel/sched/Makefile linux-4.1.26/kernel/sched/Makefile
  18693. --- linux-4.1.26.orig/kernel/sched/Makefile 2016-06-07 01:13:11.000000000 +0200
  18694. +++ linux-4.1.26/kernel/sched/Makefile 2016-06-19 15:30:58.699297812 +0200
  18695. @@ -13,7 +13,7 @@
  18696. obj-y += core.o proc.o clock.o cputime.o
  18697. obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
  18698. -obj-y += wait.o completion.o idle.o
  18699. +obj-y += wait.o wait-simple.o work-simple.o completion.o idle.o
  18700. obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o
  18701. obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
  18702. obj-$(CONFIG_SCHEDSTATS) += stats.o
  18703. diff -Nur linux-4.1.26.orig/kernel/sched/rt.c linux-4.1.26/kernel/sched/rt.c
  18704. --- linux-4.1.26.orig/kernel/sched/rt.c 2016-06-07 01:13:11.000000000 +0200
  18705. +++ linux-4.1.26/kernel/sched/rt.c 2016-06-19 15:30:58.707298121 +0200
  18706. @@ -44,6 +44,7 @@
  18707. hrtimer_init(&rt_b->rt_period_timer,
  18708. CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  18709. + rt_b->rt_period_timer.irqsafe = 1;
  18710. rt_b->rt_period_timer.function = sched_rt_period_timer;
  18711. }
  18712. @@ -89,6 +90,7 @@
  18713. rt_rq->push_cpu = nr_cpu_ids;
  18714. raw_spin_lock_init(&rt_rq->push_lock);
  18715. init_irq_work(&rt_rq->push_work, push_irq_work_func);
  18716. + rt_rq->push_work.flags |= IRQ_WORK_HARD_IRQ;
  18717. #endif
  18718. #endif /* CONFIG_SMP */
  18719. /* We start is dequeued state, because no RT tasks are queued */
  18720. diff -Nur linux-4.1.26.orig/kernel/sched/sched.h linux-4.1.26/kernel/sched/sched.h
  18721. --- linux-4.1.26.orig/kernel/sched/sched.h 2016-06-07 01:13:11.000000000 +0200
  18722. +++ linux-4.1.26/kernel/sched/sched.h 2016-06-19 15:30:58.707298121 +0200
  18723. @@ -1093,6 +1093,7 @@
  18724. #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
  18725. #define WF_FORK 0x02 /* child wakeup after fork */
  18726. #define WF_MIGRATED 0x4 /* internal use, task got migrated */
  18727. +#define WF_LOCK_SLEEPER 0x08 /* wakeup spinlock "sleeper" */
  18728. /*
  18729. * To aid in avoiding the subversion of "niceness" due to uneven distribution
  18730. @@ -1290,6 +1291,15 @@
  18731. extern void resched_curr(struct rq *rq);
  18732. extern void resched_cpu(int cpu);
  18733. +#ifdef CONFIG_PREEMPT_LAZY
  18734. +extern void resched_curr_lazy(struct rq *rq);
  18735. +#else
  18736. +static inline void resched_curr_lazy(struct rq *rq)
  18737. +{
  18738. + resched_curr(rq);
  18739. +}
  18740. +#endif
  18741. +
  18742. extern struct rt_bandwidth def_rt_bandwidth;
  18743. extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
  18744. diff -Nur linux-4.1.26.orig/kernel/sched/wait-simple.c linux-4.1.26/kernel/sched/wait-simple.c
  18745. --- linux-4.1.26.orig/kernel/sched/wait-simple.c 1970-01-01 01:00:00.000000000 +0100
  18746. +++ linux-4.1.26/kernel/sched/wait-simple.c 2016-06-19 15:30:58.707298121 +0200
  18747. @@ -0,0 +1,115 @@
  18748. +/*
  18749. + * Simple waitqueues without fancy flags and callbacks
  18750. + *
  18751. + * (C) 2011 Thomas Gleixner <tglx@linutronix.de>
  18752. + *
  18753. + * Based on kernel/wait.c
  18754. + *
  18755. + * For licencing details see kernel-base/COPYING
  18756. + */
  18757. +#include <linux/init.h>
  18758. +#include <linux/export.h>
  18759. +#include <linux/sched.h>
  18760. +#include <linux/wait-simple.h>
  18761. +
  18762. +/* Adds w to head->list. Must be called with head->lock locked. */
  18763. +static inline void __swait_enqueue(struct swait_head *head, struct swaiter *w)
  18764. +{
  18765. + list_add(&w->node, &head->list);
  18766. + /* We can't let the condition leak before the setting of head */
  18767. + smp_mb();
  18768. +}
  18769. +
  18770. +/* Removes w from head->list. Must be called with head->lock locked. */
  18771. +static inline void __swait_dequeue(struct swaiter *w)
  18772. +{
  18773. + list_del_init(&w->node);
  18774. +}
  18775. +
  18776. +void __init_swait_head(struct swait_head *head, struct lock_class_key *key)
  18777. +{
  18778. + raw_spin_lock_init(&head->lock);
  18779. + lockdep_set_class(&head->lock, key);
  18780. + INIT_LIST_HEAD(&head->list);
  18781. +}
  18782. +EXPORT_SYMBOL(__init_swait_head);
  18783. +
  18784. +void swait_prepare_locked(struct swait_head *head, struct swaiter *w)
  18785. +{
  18786. + w->task = current;
  18787. + if (list_empty(&w->node))
  18788. + __swait_enqueue(head, w);
  18789. +}
  18790. +
  18791. +void swait_prepare(struct swait_head *head, struct swaiter *w, int state)
  18792. +{
  18793. + unsigned long flags;
  18794. +
  18795. + raw_spin_lock_irqsave(&head->lock, flags);
  18796. + swait_prepare_locked(head, w);
  18797. + __set_current_state(state);
  18798. + raw_spin_unlock_irqrestore(&head->lock, flags);
  18799. +}
  18800. +EXPORT_SYMBOL(swait_prepare);
  18801. +
  18802. +void swait_finish_locked(struct swait_head *head, struct swaiter *w)
  18803. +{
  18804. + __set_current_state(TASK_RUNNING);
  18805. + if (w->task)
  18806. + __swait_dequeue(w);
  18807. +}
  18808. +
  18809. +void swait_finish(struct swait_head *head, struct swaiter *w)
  18810. +{
  18811. + unsigned long flags;
  18812. +
  18813. + __set_current_state(TASK_RUNNING);
  18814. + if (w->task) {
  18815. + raw_spin_lock_irqsave(&head->lock, flags);
  18816. + __swait_dequeue(w);
  18817. + raw_spin_unlock_irqrestore(&head->lock, flags);
  18818. + }
  18819. +}
  18820. +EXPORT_SYMBOL(swait_finish);
  18821. +
  18822. +unsigned int
  18823. +__swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num)
  18824. +{
  18825. + struct swaiter *curr, *next;
  18826. + int woken = 0;
  18827. +
  18828. + list_for_each_entry_safe(curr, next, &head->list, node) {
  18829. + if (wake_up_state(curr->task, state)) {
  18830. + __swait_dequeue(curr);
  18831. + /*
  18832. + * The waiting task can free the waiter as
  18833. + * soon as curr->task = NULL is written,
  18834. + * without taking any locks. A memory barrier
  18835. + * is required here to prevent the following
  18836. + * store to curr->task from getting ahead of
  18837. + * the dequeue operation.
  18838. + */
  18839. + smp_wmb();
  18840. + curr->task = NULL;
  18841. + if (++woken == num)
  18842. + break;
  18843. + }
  18844. + }
  18845. + return woken;
  18846. +}
  18847. +
  18848. +unsigned int
  18849. +__swait_wake(struct swait_head *head, unsigned int state, unsigned int num)
  18850. +{
  18851. + unsigned long flags;
  18852. + int woken;
  18853. +
  18854. + if (!swaitqueue_active(head))
  18855. + return 0;
  18856. +
  18857. + raw_spin_lock_irqsave(&head->lock, flags);
  18858. + woken = __swait_wake_locked(head, state, num);
  18859. + raw_spin_unlock_irqrestore(&head->lock, flags);
  18860. + return woken;
  18861. +}
  18862. +EXPORT_SYMBOL(__swait_wake);
  18863. diff -Nur linux-4.1.26.orig/kernel/sched/work-simple.c linux-4.1.26/kernel/sched/work-simple.c
  18864. --- linux-4.1.26.orig/kernel/sched/work-simple.c 1970-01-01 01:00:00.000000000 +0100
  18865. +++ linux-4.1.26/kernel/sched/work-simple.c 2016-06-19 15:30:58.707298121 +0200
  18866. @@ -0,0 +1,173 @@
  18867. +/*
  18868. + * Copyright (C) 2014 BMW Car IT GmbH, Daniel Wagner daniel.wagner@bmw-carit.de
  18869. + *
  18870. + * Provides a framework for enqueuing callbacks from irq context
  18871. + * PREEMPT_RT_FULL safe. The callbacks are executed in kthread context.
  18872. + */
  18873. +
  18874. +#include <linux/wait-simple.h>
  18875. +#include <linux/work-simple.h>
  18876. +#include <linux/kthread.h>
  18877. +#include <linux/slab.h>
  18878. +#include <linux/spinlock.h>
  18879. +#include <linux/export.h>
  18880. +
  18881. +#define SWORK_EVENT_PENDING (1 << 0)
  18882. +
  18883. +static DEFINE_MUTEX(worker_mutex);
  18884. +static struct sworker *glob_worker;
  18885. +
  18886. +struct sworker {
  18887. + struct list_head events;
  18888. + struct swait_head wq;
  18889. +
  18890. + raw_spinlock_t lock;
  18891. +
  18892. + struct task_struct *task;
  18893. + int refs;
  18894. +};
  18895. +
  18896. +static bool swork_readable(struct sworker *worker)
  18897. +{
  18898. + bool r;
  18899. +
  18900. + if (kthread_should_stop())
  18901. + return true;
  18902. +
  18903. + raw_spin_lock_irq(&worker->lock);
  18904. + r = !list_empty(&worker->events);
  18905. + raw_spin_unlock_irq(&worker->lock);
  18906. +
  18907. + return r;
  18908. +}
  18909. +
  18910. +static int swork_kthread(void *arg)
  18911. +{
  18912. + struct sworker *worker = arg;
  18913. +
  18914. + for (;;) {
  18915. + swait_event_interruptible(worker->wq,
  18916. + swork_readable(worker));
  18917. + if (kthread_should_stop())
  18918. + break;
  18919. +
  18920. + raw_spin_lock_irq(&worker->lock);
  18921. + while (!list_empty(&worker->events)) {
  18922. + struct swork_event *sev;
  18923. +
  18924. + sev = list_first_entry(&worker->events,
  18925. + struct swork_event, item);
  18926. + list_del(&sev->item);
  18927. + raw_spin_unlock_irq(&worker->lock);
  18928. +
  18929. + WARN_ON_ONCE(!test_and_clear_bit(SWORK_EVENT_PENDING,
  18930. + &sev->flags));
  18931. + sev->func(sev);
  18932. + raw_spin_lock_irq(&worker->lock);
  18933. + }
  18934. + raw_spin_unlock_irq(&worker->lock);
  18935. + }
  18936. + return 0;
  18937. +}
  18938. +
  18939. +static struct sworker *swork_create(void)
  18940. +{
  18941. + struct sworker *worker;
  18942. +
  18943. + worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  18944. + if (!worker)
  18945. + return ERR_PTR(-ENOMEM);
  18946. +
  18947. + INIT_LIST_HEAD(&worker->events);
  18948. + raw_spin_lock_init(&worker->lock);
  18949. + init_swait_head(&worker->wq);
  18950. +
  18951. + worker->task = kthread_run(swork_kthread, worker, "kswork");
  18952. + if (IS_ERR(worker->task)) {
  18953. + kfree(worker);
  18954. + return ERR_PTR(-ENOMEM);
  18955. + }
  18956. +
  18957. + return worker;
  18958. +}
  18959. +
  18960. +static void swork_destroy(struct sworker *worker)
  18961. +{
  18962. + kthread_stop(worker->task);
  18963. +
  18964. + WARN_ON(!list_empty(&worker->events));
  18965. + kfree(worker);
  18966. +}
  18967. +
  18968. +/**
  18969. + * swork_queue - queue swork
  18970. + *
  18971. + * Returns %false if @work was already on a queue, %true otherwise.
  18972. + *
  18973. + * The work is queued and processed on a random CPU
  18974. + */
  18975. +bool swork_queue(struct swork_event *sev)
  18976. +{
  18977. + unsigned long flags;
  18978. +
  18979. + if (test_and_set_bit(SWORK_EVENT_PENDING, &sev->flags))
  18980. + return false;
  18981. +
  18982. + raw_spin_lock_irqsave(&glob_worker->lock, flags);
  18983. + list_add_tail(&sev->item, &glob_worker->events);
  18984. + raw_spin_unlock_irqrestore(&glob_worker->lock, flags);
  18985. +
  18986. + swait_wake(&glob_worker->wq);
  18987. + return true;
  18988. +}
  18989. +EXPORT_SYMBOL_GPL(swork_queue);
  18990. +
  18991. +/**
  18992. + * swork_get - get an instance of the sworker
  18993. + *
  18994. + * Returns an negative error code if the initialization if the worker did not
  18995. + * work, %0 otherwise.
  18996. + *
  18997. + */
  18998. +int swork_get(void)
  18999. +{
  19000. + struct sworker *worker;
  19001. +
  19002. + mutex_lock(&worker_mutex);
  19003. + if (!glob_worker) {
  19004. + worker = swork_create();
  19005. + if (IS_ERR(worker)) {
  19006. + mutex_unlock(&worker_mutex);
  19007. + return -ENOMEM;
  19008. + }
  19009. +
  19010. + glob_worker = worker;
  19011. + }
  19012. +
  19013. + glob_worker->refs++;
  19014. + mutex_unlock(&worker_mutex);
  19015. +
  19016. + return 0;
  19017. +}
  19018. +EXPORT_SYMBOL_GPL(swork_get);
  19019. +
  19020. +/**
  19021. + * swork_put - puts an instance of the sworker
  19022. + *
  19023. + * Will destroy the sworker thread. This function must not be called until all
  19024. + * queued events have been completed.
  19025. + */
  19026. +void swork_put(void)
  19027. +{
  19028. + mutex_lock(&worker_mutex);
  19029. +
  19030. + glob_worker->refs--;
  19031. + if (glob_worker->refs > 0)
  19032. + goto out;
  19033. +
  19034. + swork_destroy(glob_worker);
  19035. + glob_worker = NULL;
  19036. +out:
  19037. + mutex_unlock(&worker_mutex);
  19038. +}
  19039. +EXPORT_SYMBOL_GPL(swork_put);
  19040. diff -Nur linux-4.1.26.orig/kernel/signal.c linux-4.1.26/kernel/signal.c
  19041. --- linux-4.1.26.orig/kernel/signal.c 2016-06-07 01:13:11.000000000 +0200
  19042. +++ linux-4.1.26/kernel/signal.c 2016-06-19 15:30:58.707298121 +0200
  19043. @@ -14,6 +14,7 @@
  19044. #include <linux/export.h>
  19045. #include <linux/init.h>
  19046. #include <linux/sched.h>
  19047. +#include <linux/sched/rt.h>
  19048. #include <linux/fs.h>
  19049. #include <linux/tty.h>
  19050. #include <linux/binfmts.h>
  19051. @@ -352,13 +353,45 @@
  19052. return false;
  19053. }
  19054. +#ifdef __HAVE_ARCH_CMPXCHG
  19055. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  19056. +{
  19057. + struct sigqueue *q = t->sigqueue_cache;
  19058. +
  19059. + if (cmpxchg(&t->sigqueue_cache, q, NULL) != q)
  19060. + return NULL;
  19061. + return q;
  19062. +}
  19063. +
  19064. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  19065. +{
  19066. + if (cmpxchg(&t->sigqueue_cache, NULL, q) == NULL)
  19067. + return 0;
  19068. + return 1;
  19069. +}
  19070. +
  19071. +#else
  19072. +
  19073. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  19074. +{
  19075. + return NULL;
  19076. +}
  19077. +
  19078. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  19079. +{
  19080. + return 1;
  19081. +}
  19082. +
  19083. +#endif
  19084. +
  19085. /*
  19086. * allocate a new signal queue record
  19087. * - this may be called without locks if and only if t == current, otherwise an
  19088. * appropriate lock must be held to stop the target task from exiting
  19089. */
  19090. static struct sigqueue *
  19091. -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
  19092. +__sigqueue_do_alloc(int sig, struct task_struct *t, gfp_t flags,
  19093. + int override_rlimit, int fromslab)
  19094. {
  19095. struct sigqueue *q = NULL;
  19096. struct user_struct *user;
  19097. @@ -375,7 +408,10 @@
  19098. if (override_rlimit ||
  19099. atomic_read(&user->sigpending) <=
  19100. task_rlimit(t, RLIMIT_SIGPENDING)) {
  19101. - q = kmem_cache_alloc(sigqueue_cachep, flags);
  19102. + if (!fromslab)
  19103. + q = get_task_cache(t);
  19104. + if (!q)
  19105. + q = kmem_cache_alloc(sigqueue_cachep, flags);
  19106. } else {
  19107. print_dropped_signal(sig);
  19108. }
  19109. @@ -392,6 +428,13 @@
  19110. return q;
  19111. }
  19112. +static struct sigqueue *
  19113. +__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags,
  19114. + int override_rlimit)
  19115. +{
  19116. + return __sigqueue_do_alloc(sig, t, flags, override_rlimit, 0);
  19117. +}
  19118. +
  19119. static void __sigqueue_free(struct sigqueue *q)
  19120. {
  19121. if (q->flags & SIGQUEUE_PREALLOC)
  19122. @@ -401,6 +444,21 @@
  19123. kmem_cache_free(sigqueue_cachep, q);
  19124. }
  19125. +static void sigqueue_free_current(struct sigqueue *q)
  19126. +{
  19127. + struct user_struct *up;
  19128. +
  19129. + if (q->flags & SIGQUEUE_PREALLOC)
  19130. + return;
  19131. +
  19132. + up = q->user;
  19133. + if (rt_prio(current->normal_prio) && !put_task_cache(current, q)) {
  19134. + atomic_dec(&up->sigpending);
  19135. + free_uid(up);
  19136. + } else
  19137. + __sigqueue_free(q);
  19138. +}
  19139. +
  19140. void flush_sigqueue(struct sigpending *queue)
  19141. {
  19142. struct sigqueue *q;
  19143. @@ -414,6 +472,21 @@
  19144. }
  19145. /*
  19146. + * Called from __exit_signal. Flush tsk->pending and
  19147. + * tsk->sigqueue_cache
  19148. + */
  19149. +void flush_task_sigqueue(struct task_struct *tsk)
  19150. +{
  19151. + struct sigqueue *q;
  19152. +
  19153. + flush_sigqueue(&tsk->pending);
  19154. +
  19155. + q = get_task_cache(tsk);
  19156. + if (q)
  19157. + kmem_cache_free(sigqueue_cachep, q);
  19158. +}
  19159. +
  19160. +/*
  19161. * Flush all pending signals for a task.
  19162. */
  19163. void __flush_signals(struct task_struct *t)
  19164. @@ -565,7 +638,7 @@
  19165. still_pending:
  19166. list_del_init(&first->list);
  19167. copy_siginfo(info, &first->info);
  19168. - __sigqueue_free(first);
  19169. + sigqueue_free_current(first);
  19170. } else {
  19171. /*
  19172. * Ok, it wasn't in the queue. This must be
  19173. @@ -611,6 +684,8 @@
  19174. {
  19175. int signr;
  19176. + WARN_ON_ONCE(tsk != current);
  19177. +
  19178. /* We only dequeue private signals from ourselves, we don't let
  19179. * signalfd steal them
  19180. */
  19181. @@ -1207,8 +1282,8 @@
  19182. * We don't want to have recursive SIGSEGV's etc, for example,
  19183. * that is why we also clear SIGNAL_UNKILLABLE.
  19184. */
  19185. -int
  19186. -force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  19187. +static int
  19188. +do_force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  19189. {
  19190. unsigned long int flags;
  19191. int ret, blocked, ignored;
  19192. @@ -1233,6 +1308,39 @@
  19193. return ret;
  19194. }
  19195. +int force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  19196. +{
  19197. +/*
  19198. + * On some archs, PREEMPT_RT has to delay sending a signal from a trap
  19199. + * since it can not enable preemption, and the signal code's spin_locks
  19200. + * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will
  19201. + * send the signal on exit of the trap.
  19202. + */
  19203. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  19204. + if (in_atomic()) {
  19205. + if (WARN_ON_ONCE(t != current))
  19206. + return 0;
  19207. + if (WARN_ON_ONCE(t->forced_info.si_signo))
  19208. + return 0;
  19209. +
  19210. + if (is_si_special(info)) {
  19211. + WARN_ON_ONCE(info != SEND_SIG_PRIV);
  19212. + t->forced_info.si_signo = sig;
  19213. + t->forced_info.si_errno = 0;
  19214. + t->forced_info.si_code = SI_KERNEL;
  19215. + t->forced_info.si_pid = 0;
  19216. + t->forced_info.si_uid = 0;
  19217. + } else {
  19218. + t->forced_info = *info;
  19219. + }
  19220. +
  19221. + set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
  19222. + return 0;
  19223. + }
  19224. +#endif
  19225. + return do_force_sig_info(sig, info, t);
  19226. +}
  19227. +
  19228. /*
  19229. * Nuke all other threads in the group.
  19230. */
  19231. @@ -1267,12 +1375,12 @@
  19232. * Disable interrupts early to avoid deadlocks.
  19233. * See rcu_read_unlock() comment header for details.
  19234. */
  19235. - local_irq_save(*flags);
  19236. + local_irq_save_nort(*flags);
  19237. rcu_read_lock();
  19238. sighand = rcu_dereference(tsk->sighand);
  19239. if (unlikely(sighand == NULL)) {
  19240. rcu_read_unlock();
  19241. - local_irq_restore(*flags);
  19242. + local_irq_restore_nort(*flags);
  19243. break;
  19244. }
  19245. /*
  19246. @@ -1293,7 +1401,7 @@
  19247. }
  19248. spin_unlock(&sighand->siglock);
  19249. rcu_read_unlock();
  19250. - local_irq_restore(*flags);
  19251. + local_irq_restore_nort(*flags);
  19252. }
  19253. return sighand;
  19254. @@ -1536,7 +1644,8 @@
  19255. */
  19256. struct sigqueue *sigqueue_alloc(void)
  19257. {
  19258. - struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0);
  19259. + /* Preallocated sigqueue objects always from the slabcache ! */
  19260. + struct sigqueue *q = __sigqueue_do_alloc(-1, current, GFP_KERNEL, 0, 1);
  19261. if (q)
  19262. q->flags |= SIGQUEUE_PREALLOC;
  19263. @@ -1897,15 +2006,7 @@
  19264. if (gstop_done && ptrace_reparented(current))
  19265. do_notify_parent_cldstop(current, false, why);
  19266. - /*
  19267. - * Don't want to allow preemption here, because
  19268. - * sys_ptrace() needs this task to be inactive.
  19269. - *
  19270. - * XXX: implement read_unlock_no_resched().
  19271. - */
  19272. - preempt_disable();
  19273. read_unlock(&tasklist_lock);
  19274. - preempt_enable_no_resched();
  19275. freezable_schedule();
  19276. } else {
  19277. /*
  19278. diff -Nur linux-4.1.26.orig/kernel/softirq.c linux-4.1.26/kernel/softirq.c
  19279. --- linux-4.1.26.orig/kernel/softirq.c 2016-06-07 01:13:11.000000000 +0200
  19280. +++ linux-4.1.26/kernel/softirq.c 2016-06-19 15:30:58.707298121 +0200
  19281. @@ -21,10 +21,12 @@
  19282. #include <linux/freezer.h>
  19283. #include <linux/kthread.h>
  19284. #include <linux/rcupdate.h>
  19285. +#include <linux/delay.h>
  19286. #include <linux/ftrace.h>
  19287. #include <linux/smp.h>
  19288. #include <linux/smpboot.h>
  19289. #include <linux/tick.h>
  19290. +#include <linux/locallock.h>
  19291. #include <linux/irq.h>
  19292. #define CREATE_TRACE_POINTS
  19293. @@ -56,12 +58,108 @@
  19294. static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
  19295. DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
  19296. +#ifdef CONFIG_PREEMPT_RT_FULL
  19297. +#define TIMER_SOFTIRQS ((1 << TIMER_SOFTIRQ) | (1 << HRTIMER_SOFTIRQ))
  19298. +DEFINE_PER_CPU(struct task_struct *, ktimer_softirqd);
  19299. +#endif
  19300. const char * const softirq_to_name[NR_SOFTIRQS] = {
  19301. "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
  19302. "TASKLET", "SCHED", "HRTIMER", "RCU"
  19303. };
  19304. +#ifdef CONFIG_NO_HZ_COMMON
  19305. +# ifdef CONFIG_PREEMPT_RT_FULL
  19306. +
  19307. +struct softirq_runner {
  19308. + struct task_struct *runner[NR_SOFTIRQS];
  19309. +};
  19310. +
  19311. +static DEFINE_PER_CPU(struct softirq_runner, softirq_runners);
  19312. +
  19313. +static inline void softirq_set_runner(unsigned int sirq)
  19314. +{
  19315. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  19316. +
  19317. + sr->runner[sirq] = current;
  19318. +}
  19319. +
  19320. +static inline void softirq_clr_runner(unsigned int sirq)
  19321. +{
  19322. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  19323. +
  19324. + sr->runner[sirq] = NULL;
  19325. +}
  19326. +
  19327. +/*
  19328. + * On preempt-rt a softirq running context might be blocked on a
  19329. + * lock. There might be no other runnable task on this CPU because the
  19330. + * lock owner runs on some other CPU. So we have to go into idle with
  19331. + * the pending bit set. Therefor we need to check this otherwise we
  19332. + * warn about false positives which confuses users and defeats the
  19333. + * whole purpose of this test.
  19334. + *
  19335. + * This code is called with interrupts disabled.
  19336. + */
  19337. +void softirq_check_pending_idle(void)
  19338. +{
  19339. + static int rate_limit;
  19340. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  19341. + u32 warnpending;
  19342. + int i;
  19343. +
  19344. + if (rate_limit >= 10)
  19345. + return;
  19346. +
  19347. + warnpending = local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK;
  19348. + for (i = 0; i < NR_SOFTIRQS; i++) {
  19349. + struct task_struct *tsk = sr->runner[i];
  19350. +
  19351. + /*
  19352. + * The wakeup code in rtmutex.c wakes up the task
  19353. + * _before_ it sets pi_blocked_on to NULL under
  19354. + * tsk->pi_lock. So we need to check for both: state
  19355. + * and pi_blocked_on.
  19356. + */
  19357. + if (tsk) {
  19358. + raw_spin_lock(&tsk->pi_lock);
  19359. + if (tsk->pi_blocked_on || tsk->state == TASK_RUNNING) {
  19360. + /* Clear all bits pending in that task */
  19361. + warnpending &= ~(tsk->softirqs_raised);
  19362. + warnpending &= ~(1 << i);
  19363. + }
  19364. + raw_spin_unlock(&tsk->pi_lock);
  19365. + }
  19366. + }
  19367. +
  19368. + if (warnpending) {
  19369. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  19370. + warnpending);
  19371. + rate_limit++;
  19372. + }
  19373. +}
  19374. +# else
  19375. +/*
  19376. + * On !PREEMPT_RT we just printk rate limited:
  19377. + */
  19378. +void softirq_check_pending_idle(void)
  19379. +{
  19380. + static int rate_limit;
  19381. +
  19382. + if (rate_limit < 10 &&
  19383. + (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  19384. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  19385. + local_softirq_pending());
  19386. + rate_limit++;
  19387. + }
  19388. +}
  19389. +# endif
  19390. +
  19391. +#else /* !CONFIG_NO_HZ_COMMON */
  19392. +static inline void softirq_set_runner(unsigned int sirq) { }
  19393. +static inline void softirq_clr_runner(unsigned int sirq) { }
  19394. +#endif
  19395. +
  19396. /*
  19397. * we cannot loop indefinitely here to avoid userspace starvation,
  19398. * but we also don't want to introduce a worst case 1/HZ latency
  19399. @@ -77,6 +175,79 @@
  19400. wake_up_process(tsk);
  19401. }
  19402. +#ifdef CONFIG_PREEMPT_RT_FULL
  19403. +static void wakeup_timer_softirqd(void)
  19404. +{
  19405. + /* Interrupts are disabled: no need to stop preemption */
  19406. + struct task_struct *tsk = __this_cpu_read(ktimer_softirqd);
  19407. +
  19408. + if (tsk && tsk->state != TASK_RUNNING)
  19409. + wake_up_process(tsk);
  19410. +}
  19411. +#endif
  19412. +
  19413. +static void handle_softirq(unsigned int vec_nr)
  19414. +{
  19415. + struct softirq_action *h = softirq_vec + vec_nr;
  19416. + int prev_count;
  19417. +
  19418. + prev_count = preempt_count();
  19419. +
  19420. + kstat_incr_softirqs_this_cpu(vec_nr);
  19421. +
  19422. + trace_softirq_entry(vec_nr);
  19423. + h->action(h);
  19424. + trace_softirq_exit(vec_nr);
  19425. + if (unlikely(prev_count != preempt_count())) {
  19426. + pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  19427. + vec_nr, softirq_to_name[vec_nr], h->action,
  19428. + prev_count, preempt_count());
  19429. + preempt_count_set(prev_count);
  19430. + }
  19431. +}
  19432. +
  19433. +#ifndef CONFIG_PREEMPT_RT_FULL
  19434. +static inline int ksoftirqd_softirq_pending(void)
  19435. +{
  19436. + return local_softirq_pending();
  19437. +}
  19438. +
  19439. +static void handle_pending_softirqs(u32 pending)
  19440. +{
  19441. + struct softirq_action *h = softirq_vec;
  19442. + int softirq_bit;
  19443. +
  19444. + local_irq_enable();
  19445. +
  19446. + h = softirq_vec;
  19447. +
  19448. + while ((softirq_bit = ffs(pending))) {
  19449. + unsigned int vec_nr;
  19450. +
  19451. + h += softirq_bit - 1;
  19452. + vec_nr = h - softirq_vec;
  19453. + handle_softirq(vec_nr);
  19454. +
  19455. + h++;
  19456. + pending >>= softirq_bit;
  19457. + }
  19458. +
  19459. + rcu_bh_qs();
  19460. + local_irq_disable();
  19461. +}
  19462. +
  19463. +static void run_ksoftirqd(unsigned int cpu)
  19464. +{
  19465. + local_irq_disable();
  19466. + if (ksoftirqd_softirq_pending()) {
  19467. + __do_softirq();
  19468. + local_irq_enable();
  19469. + cond_resched_rcu_qs();
  19470. + return;
  19471. + }
  19472. + local_irq_enable();
  19473. +}
  19474. +
  19475. /*
  19476. * preempt_count and SOFTIRQ_OFFSET usage:
  19477. * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
  19478. @@ -116,9 +287,9 @@
  19479. if (preempt_count() == cnt) {
  19480. #ifdef CONFIG_DEBUG_PREEMPT
  19481. - current->preempt_disable_ip = get_parent_ip(CALLER_ADDR1);
  19482. + current->preempt_disable_ip = get_lock_parent_ip();
  19483. #endif
  19484. - trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
  19485. + trace_preempt_off(CALLER_ADDR0, get_lock_parent_ip());
  19486. }
  19487. }
  19488. EXPORT_SYMBOL(__local_bh_disable_ip);
  19489. @@ -232,10 +403,8 @@
  19490. unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
  19491. unsigned long old_flags = current->flags;
  19492. int max_restart = MAX_SOFTIRQ_RESTART;
  19493. - struct softirq_action *h;
  19494. bool in_hardirq;
  19495. __u32 pending;
  19496. - int softirq_bit;
  19497. /*
  19498. * Mask out PF_MEMALLOC s current task context is borrowed for the
  19499. @@ -254,36 +423,7 @@
  19500. /* Reset the pending bitmask before enabling irqs */
  19501. set_softirq_pending(0);
  19502. - local_irq_enable();
  19503. -
  19504. - h = softirq_vec;
  19505. -
  19506. - while ((softirq_bit = ffs(pending))) {
  19507. - unsigned int vec_nr;
  19508. - int prev_count;
  19509. -
  19510. - h += softirq_bit - 1;
  19511. -
  19512. - vec_nr = h - softirq_vec;
  19513. - prev_count = preempt_count();
  19514. -
  19515. - kstat_incr_softirqs_this_cpu(vec_nr);
  19516. -
  19517. - trace_softirq_entry(vec_nr);
  19518. - h->action(h);
  19519. - trace_softirq_exit(vec_nr);
  19520. - if (unlikely(prev_count != preempt_count())) {
  19521. - pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  19522. - vec_nr, softirq_to_name[vec_nr], h->action,
  19523. - prev_count, preempt_count());
  19524. - preempt_count_set(prev_count);
  19525. - }
  19526. - h++;
  19527. - pending >>= softirq_bit;
  19528. - }
  19529. -
  19530. - rcu_bh_qs();
  19531. - local_irq_disable();
  19532. + handle_pending_softirqs(pending);
  19533. pending = local_softirq_pending();
  19534. if (pending) {
  19535. @@ -320,6 +460,310 @@
  19536. }
  19537. /*
  19538. + * This function must run with irqs disabled!
  19539. + */
  19540. +void raise_softirq_irqoff(unsigned int nr)
  19541. +{
  19542. + __raise_softirq_irqoff(nr);
  19543. +
  19544. + /*
  19545. + * If we're in an interrupt or softirq, we're done
  19546. + * (this also catches softirq-disabled code). We will
  19547. + * actually run the softirq once we return from
  19548. + * the irq or softirq.
  19549. + *
  19550. + * Otherwise we wake up ksoftirqd to make sure we
  19551. + * schedule the softirq soon.
  19552. + */
  19553. + if (!in_interrupt())
  19554. + wakeup_softirqd();
  19555. +}
  19556. +
  19557. +void __raise_softirq_irqoff(unsigned int nr)
  19558. +{
  19559. + trace_softirq_raise(nr);
  19560. + or_softirq_pending(1UL << nr);
  19561. +}
  19562. +
  19563. +static inline void local_bh_disable_nort(void) { local_bh_disable(); }
  19564. +static inline void _local_bh_enable_nort(void) { _local_bh_enable(); }
  19565. +static void ksoftirqd_set_sched_params(unsigned int cpu) { }
  19566. +
  19567. +#else /* !PREEMPT_RT_FULL */
  19568. +
  19569. +/*
  19570. + * On RT we serialize softirq execution with a cpu local lock per softirq
  19571. + */
  19572. +static DEFINE_PER_CPU(struct local_irq_lock [NR_SOFTIRQS], local_softirq_locks);
  19573. +
  19574. +void __init softirq_early_init(void)
  19575. +{
  19576. + int i;
  19577. +
  19578. + for (i = 0; i < NR_SOFTIRQS; i++)
  19579. + local_irq_lock_init(local_softirq_locks[i]);
  19580. +}
  19581. +
  19582. +static void lock_softirq(int which)
  19583. +{
  19584. + local_lock(local_softirq_locks[which]);
  19585. +}
  19586. +
  19587. +static void unlock_softirq(int which)
  19588. +{
  19589. + local_unlock(local_softirq_locks[which]);
  19590. +}
  19591. +
  19592. +static void do_single_softirq(int which)
  19593. +{
  19594. + unsigned long old_flags = current->flags;
  19595. +
  19596. + current->flags &= ~PF_MEMALLOC;
  19597. + vtime_account_irq_enter(current);
  19598. + current->flags |= PF_IN_SOFTIRQ;
  19599. + lockdep_softirq_enter();
  19600. + local_irq_enable();
  19601. + handle_softirq(which);
  19602. + local_irq_disable();
  19603. + lockdep_softirq_exit();
  19604. + current->flags &= ~PF_IN_SOFTIRQ;
  19605. + vtime_account_irq_enter(current);
  19606. + tsk_restore_flags(current, old_flags, PF_MEMALLOC);
  19607. +}
  19608. +
  19609. +/*
  19610. + * Called with interrupts disabled. Process softirqs which were raised
  19611. + * in current context (or on behalf of ksoftirqd).
  19612. + */
  19613. +static void do_current_softirqs(void)
  19614. +{
  19615. + while (current->softirqs_raised) {
  19616. + int i = __ffs(current->softirqs_raised);
  19617. + unsigned int pending, mask = (1U << i);
  19618. +
  19619. + current->softirqs_raised &= ~mask;
  19620. + local_irq_enable();
  19621. +
  19622. + /*
  19623. + * If the lock is contended, we boost the owner to
  19624. + * process the softirq or leave the critical section
  19625. + * now.
  19626. + */
  19627. + lock_softirq(i);
  19628. + local_irq_disable();
  19629. + softirq_set_runner(i);
  19630. + /*
  19631. + * Check with the local_softirq_pending() bits,
  19632. + * whether we need to process this still or if someone
  19633. + * else took care of it.
  19634. + */
  19635. + pending = local_softirq_pending();
  19636. + if (pending & mask) {
  19637. + set_softirq_pending(pending & ~mask);
  19638. + do_single_softirq(i);
  19639. + }
  19640. + softirq_clr_runner(i);
  19641. + WARN_ON(current->softirq_nestcnt != 1);
  19642. + local_irq_enable();
  19643. + unlock_softirq(i);
  19644. + local_irq_disable();
  19645. + }
  19646. +}
  19647. +
  19648. +void __local_bh_disable(void)
  19649. +{
  19650. + if (++current->softirq_nestcnt == 1)
  19651. + migrate_disable();
  19652. +}
  19653. +EXPORT_SYMBOL(__local_bh_disable);
  19654. +
  19655. +void __local_bh_enable(void)
  19656. +{
  19657. + if (WARN_ON(current->softirq_nestcnt == 0))
  19658. + return;
  19659. +
  19660. + local_irq_disable();
  19661. + if (current->softirq_nestcnt == 1 && current->softirqs_raised)
  19662. + do_current_softirqs();
  19663. + local_irq_enable();
  19664. +
  19665. + if (--current->softirq_nestcnt == 0)
  19666. + migrate_enable();
  19667. +}
  19668. +EXPORT_SYMBOL(__local_bh_enable);
  19669. +
  19670. +void _local_bh_enable(void)
  19671. +{
  19672. + if (WARN_ON(current->softirq_nestcnt == 0))
  19673. + return;
  19674. + if (--current->softirq_nestcnt == 0)
  19675. + migrate_enable();
  19676. +}
  19677. +EXPORT_SYMBOL(_local_bh_enable);
  19678. +
  19679. +int in_serving_softirq(void)
  19680. +{
  19681. + return current->flags & PF_IN_SOFTIRQ;
  19682. +}
  19683. +EXPORT_SYMBOL(in_serving_softirq);
  19684. +
  19685. +/* Called with preemption disabled */
  19686. +static void run_ksoftirqd(unsigned int cpu)
  19687. +{
  19688. + local_irq_disable();
  19689. + current->softirq_nestcnt++;
  19690. +
  19691. + do_current_softirqs();
  19692. + current->softirq_nestcnt--;
  19693. + local_irq_enable();
  19694. + cond_resched_rcu_qs();
  19695. +}
  19696. +
  19697. +/*
  19698. + * Called from netif_rx_ni(). Preemption enabled, but migration
  19699. + * disabled. So the cpu can't go away under us.
  19700. + */
  19701. +void thread_do_softirq(void)
  19702. +{
  19703. + if (!in_serving_softirq() && current->softirqs_raised) {
  19704. + current->softirq_nestcnt++;
  19705. + do_current_softirqs();
  19706. + current->softirq_nestcnt--;
  19707. + }
  19708. +}
  19709. +
  19710. +static void do_raise_softirq_irqoff(unsigned int nr)
  19711. +{
  19712. + unsigned int mask;
  19713. +
  19714. + mask = 1UL << nr;
  19715. +
  19716. + trace_softirq_raise(nr);
  19717. + or_softirq_pending(mask);
  19718. +
  19719. + /*
  19720. + * If we are not in a hard interrupt and inside a bh disabled
  19721. + * region, we simply raise the flag on current. local_bh_enable()
  19722. + * will make sure that the softirq is executed. Otherwise we
  19723. + * delegate it to ksoftirqd.
  19724. + */
  19725. + if (!in_irq() && current->softirq_nestcnt)
  19726. + current->softirqs_raised |= mask;
  19727. + else if (!__this_cpu_read(ksoftirqd) || !__this_cpu_read(ktimer_softirqd))
  19728. + return;
  19729. +
  19730. + if (mask & TIMER_SOFTIRQS)
  19731. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  19732. + else
  19733. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  19734. +}
  19735. +
  19736. +static void wakeup_proper_softirq(unsigned int nr)
  19737. +{
  19738. + if ((1UL << nr) & TIMER_SOFTIRQS)
  19739. + wakeup_timer_softirqd();
  19740. + else
  19741. + wakeup_softirqd();
  19742. +}
  19743. +
  19744. +
  19745. +void __raise_softirq_irqoff(unsigned int nr)
  19746. +{
  19747. + do_raise_softirq_irqoff(nr);
  19748. + if (!in_irq() && !current->softirq_nestcnt)
  19749. + wakeup_proper_softirq(nr);
  19750. +}
  19751. +
  19752. +/*
  19753. + * Same as __raise_softirq_irqoff() but will process them in ksoftirqd
  19754. + */
  19755. +void __raise_softirq_irqoff_ksoft(unsigned int nr)
  19756. +{
  19757. + unsigned int mask;
  19758. +
  19759. + if (WARN_ON_ONCE(!__this_cpu_read(ksoftirqd) ||
  19760. + !__this_cpu_read(ktimer_softirqd)))
  19761. + return;
  19762. + mask = 1UL << nr;
  19763. +
  19764. + trace_softirq_raise(nr);
  19765. + or_softirq_pending(mask);
  19766. + if (mask & TIMER_SOFTIRQS)
  19767. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  19768. + else
  19769. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  19770. + wakeup_proper_softirq(nr);
  19771. +}
  19772. +
  19773. +/*
  19774. + * This function must run with irqs disabled!
  19775. + */
  19776. +void raise_softirq_irqoff(unsigned int nr)
  19777. +{
  19778. + do_raise_softirq_irqoff(nr);
  19779. +
  19780. + /*
  19781. + * If we're in an hard interrupt we let irq return code deal
  19782. + * with the wakeup of ksoftirqd.
  19783. + */
  19784. + if (in_irq())
  19785. + return;
  19786. + /*
  19787. + * If we are in thread context but outside of a bh disabled
  19788. + * region, we need to wake ksoftirqd as well.
  19789. + *
  19790. + * CHECKME: Some of the places which do that could be wrapped
  19791. + * into local_bh_disable/enable pairs. Though it's unclear
  19792. + * whether this is worth the effort. To find those places just
  19793. + * raise a WARN() if the condition is met.
  19794. + */
  19795. + if (!current->softirq_nestcnt)
  19796. + wakeup_proper_softirq(nr);
  19797. +}
  19798. +
  19799. +static inline int ksoftirqd_softirq_pending(void)
  19800. +{
  19801. + return current->softirqs_raised;
  19802. +}
  19803. +
  19804. +static inline void local_bh_disable_nort(void) { }
  19805. +static inline void _local_bh_enable_nort(void) { }
  19806. +
  19807. +static inline void ksoftirqd_set_sched_params(unsigned int cpu)
  19808. +{
  19809. + /* Take over all but timer pending softirqs when starting */
  19810. + local_irq_disable();
  19811. + current->softirqs_raised = local_softirq_pending() & ~TIMER_SOFTIRQS;
  19812. + local_irq_enable();
  19813. +}
  19814. +
  19815. +static inline void ktimer_softirqd_set_sched_params(unsigned int cpu)
  19816. +{
  19817. + struct sched_param param = { .sched_priority = 1 };
  19818. +
  19819. + sched_setscheduler(current, SCHED_FIFO, &param);
  19820. +
  19821. + /* Take over timer pending softirqs when starting */
  19822. + local_irq_disable();
  19823. + current->softirqs_raised = local_softirq_pending() & TIMER_SOFTIRQS;
  19824. + local_irq_enable();
  19825. +}
  19826. +
  19827. +static inline void ktimer_softirqd_clr_sched_params(unsigned int cpu,
  19828. + bool online)
  19829. +{
  19830. + struct sched_param param = { .sched_priority = 0 };
  19831. +
  19832. + sched_setscheduler(current, SCHED_NORMAL, &param);
  19833. +}
  19834. +
  19835. +static int ktimer_softirqd_should_run(unsigned int cpu)
  19836. +{
  19837. + return current->softirqs_raised;
  19838. +}
  19839. +
  19840. +#endif /* PREEMPT_RT_FULL */
  19841. +/*
  19842. * Enter an interrupt context.
  19843. */
  19844. void irq_enter(void)
  19845. @@ -330,9 +774,9 @@
  19846. * Prevent raise_softirq from needlessly waking up ksoftirqd
  19847. * here, as softirq will be serviced on return from interrupt.
  19848. */
  19849. - local_bh_disable();
  19850. + local_bh_disable_nort();
  19851. tick_irq_enter();
  19852. - _local_bh_enable();
  19853. + _local_bh_enable_nort();
  19854. }
  19855. __irq_enter();
  19856. @@ -340,6 +784,7 @@
  19857. static inline void invoke_softirq(void)
  19858. {
  19859. +#ifndef CONFIG_PREEMPT_RT_FULL
  19860. if (!force_irqthreads) {
  19861. #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
  19862. /*
  19863. @@ -359,6 +804,18 @@
  19864. } else {
  19865. wakeup_softirqd();
  19866. }
  19867. +#else /* PREEMPT_RT_FULL */
  19868. + unsigned long flags;
  19869. +
  19870. + local_irq_save(flags);
  19871. + if (__this_cpu_read(ksoftirqd) &&
  19872. + __this_cpu_read(ksoftirqd)->softirqs_raised)
  19873. + wakeup_softirqd();
  19874. + if (__this_cpu_read(ktimer_softirqd) &&
  19875. + __this_cpu_read(ktimer_softirqd)->softirqs_raised)
  19876. + wakeup_timer_softirqd();
  19877. + local_irq_restore(flags);
  19878. +#endif
  19879. }
  19880. static inline void tick_irq_exit(void)
  19881. @@ -395,26 +852,6 @@
  19882. trace_hardirq_exit(); /* must be last! */
  19883. }
  19884. -/*
  19885. - * This function must run with irqs disabled!
  19886. - */
  19887. -inline void raise_softirq_irqoff(unsigned int nr)
  19888. -{
  19889. - __raise_softirq_irqoff(nr);
  19890. -
  19891. - /*
  19892. - * If we're in an interrupt or softirq, we're done
  19893. - * (this also catches softirq-disabled code). We will
  19894. - * actually run the softirq once we return from
  19895. - * the irq or softirq.
  19896. - *
  19897. - * Otherwise we wake up ksoftirqd to make sure we
  19898. - * schedule the softirq soon.
  19899. - */
  19900. - if (!in_interrupt())
  19901. - wakeup_softirqd();
  19902. -}
  19903. -
  19904. void raise_softirq(unsigned int nr)
  19905. {
  19906. unsigned long flags;
  19907. @@ -424,12 +861,6 @@
  19908. local_irq_restore(flags);
  19909. }
  19910. -void __raise_softirq_irqoff(unsigned int nr)
  19911. -{
  19912. - trace_softirq_raise(nr);
  19913. - or_softirq_pending(1UL << nr);
  19914. -}
  19915. -
  19916. void open_softirq(int nr, void (*action)(struct softirq_action *))
  19917. {
  19918. softirq_vec[nr].action = action;
  19919. @@ -446,15 +877,45 @@
  19920. static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
  19921. static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
  19922. +static void inline
  19923. +__tasklet_common_schedule(struct tasklet_struct *t, struct tasklet_head *head, unsigned int nr)
  19924. +{
  19925. + if (tasklet_trylock(t)) {
  19926. +again:
  19927. + /* We may have been preempted before tasklet_trylock
  19928. + * and __tasklet_action may have already run.
  19929. + * So double check the sched bit while the takslet
  19930. + * is locked before adding it to the list.
  19931. + */
  19932. + if (test_bit(TASKLET_STATE_SCHED, &t->state)) {
  19933. + t->next = NULL;
  19934. + *head->tail = t;
  19935. + head->tail = &(t->next);
  19936. + raise_softirq_irqoff(nr);
  19937. + tasklet_unlock(t);
  19938. + } else {
  19939. + /* This is subtle. If we hit the corner case above
  19940. + * It is possible that we get preempted right here,
  19941. + * and another task has successfully called
  19942. + * tasklet_schedule(), then this function, and
  19943. + * failed on the trylock. Thus we must be sure
  19944. + * before releasing the tasklet lock, that the
  19945. + * SCHED_BIT is clear. Otherwise the tasklet
  19946. + * may get its SCHED_BIT set, but not added to the
  19947. + * list
  19948. + */
  19949. + if (!tasklet_tryunlock(t))
  19950. + goto again;
  19951. + }
  19952. + }
  19953. +}
  19954. +
  19955. void __tasklet_schedule(struct tasklet_struct *t)
  19956. {
  19957. unsigned long flags;
  19958. local_irq_save(flags);
  19959. - t->next = NULL;
  19960. - *__this_cpu_read(tasklet_vec.tail) = t;
  19961. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  19962. - raise_softirq_irqoff(TASKLET_SOFTIRQ);
  19963. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  19964. local_irq_restore(flags);
  19965. }
  19966. EXPORT_SYMBOL(__tasklet_schedule);
  19967. @@ -464,10 +925,7 @@
  19968. unsigned long flags;
  19969. local_irq_save(flags);
  19970. - t->next = NULL;
  19971. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  19972. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  19973. - raise_softirq_irqoff(HI_SOFTIRQ);
  19974. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  19975. local_irq_restore(flags);
  19976. }
  19977. EXPORT_SYMBOL(__tasklet_hi_schedule);
  19978. @@ -476,82 +934,122 @@
  19979. {
  19980. BUG_ON(!irqs_disabled());
  19981. - t->next = __this_cpu_read(tasklet_hi_vec.head);
  19982. - __this_cpu_write(tasklet_hi_vec.head, t);
  19983. - __raise_softirq_irqoff(HI_SOFTIRQ);
  19984. + __tasklet_hi_schedule(t);
  19985. }
  19986. EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  19987. -static void tasklet_action(struct softirq_action *a)
  19988. +void tasklet_enable(struct tasklet_struct *t)
  19989. {
  19990. - struct tasklet_struct *list;
  19991. + if (!atomic_dec_and_test(&t->count))
  19992. + return;
  19993. + if (test_and_clear_bit(TASKLET_STATE_PENDING, &t->state))
  19994. + tasklet_schedule(t);
  19995. +}
  19996. +EXPORT_SYMBOL(tasklet_enable);
  19997. - local_irq_disable();
  19998. - list = __this_cpu_read(tasklet_vec.head);
  19999. - __this_cpu_write(tasklet_vec.head, NULL);
  20000. - __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  20001. - local_irq_enable();
  20002. +static void __tasklet_action(struct softirq_action *a,
  20003. + struct tasklet_struct *list)
  20004. +{
  20005. + int loops = 1000000;
  20006. while (list) {
  20007. struct tasklet_struct *t = list;
  20008. list = list->next;
  20009. - if (tasklet_trylock(t)) {
  20010. - if (!atomic_read(&t->count)) {
  20011. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  20012. - &t->state))
  20013. - BUG();
  20014. - t->func(t->data);
  20015. - tasklet_unlock(t);
  20016. - continue;
  20017. - }
  20018. - tasklet_unlock(t);
  20019. + /*
  20020. + * Should always succeed - after a tasklist got on the
  20021. + * list (after getting the SCHED bit set from 0 to 1),
  20022. + * nothing but the tasklet softirq it got queued to can
  20023. + * lock it:
  20024. + */
  20025. + if (!tasklet_trylock(t)) {
  20026. + WARN_ON(1);
  20027. + continue;
  20028. }
  20029. - local_irq_disable();
  20030. t->next = NULL;
  20031. - *__this_cpu_read(tasklet_vec.tail) = t;
  20032. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  20033. - __raise_softirq_irqoff(TASKLET_SOFTIRQ);
  20034. - local_irq_enable();
  20035. +
  20036. + /*
  20037. + * If we cannot handle the tasklet because it's disabled,
  20038. + * mark it as pending. tasklet_enable() will later
  20039. + * re-schedule the tasklet.
  20040. + */
  20041. + if (unlikely(atomic_read(&t->count))) {
  20042. +out_disabled:
  20043. + /* implicit unlock: */
  20044. + wmb();
  20045. + t->state = TASKLET_STATEF_PENDING;
  20046. + continue;
  20047. + }
  20048. +
  20049. + /*
  20050. + * After this point on the tasklet might be rescheduled
  20051. + * on another CPU, but it can only be added to another
  20052. + * CPU's tasklet list if we unlock the tasklet (which we
  20053. + * dont do yet).
  20054. + */
  20055. + if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  20056. + WARN_ON(1);
  20057. +
  20058. +again:
  20059. + t->func(t->data);
  20060. +
  20061. + /*
  20062. + * Try to unlock the tasklet. We must use cmpxchg, because
  20063. + * another CPU might have scheduled or disabled the tasklet.
  20064. + * We only allow the STATE_RUN -> 0 transition here.
  20065. + */
  20066. + while (!tasklet_tryunlock(t)) {
  20067. + /*
  20068. + * If it got disabled meanwhile, bail out:
  20069. + */
  20070. + if (atomic_read(&t->count))
  20071. + goto out_disabled;
  20072. + /*
  20073. + * If it got scheduled meanwhile, re-execute
  20074. + * the tasklet function:
  20075. + */
  20076. + if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  20077. + goto again;
  20078. + if (!--loops) {
  20079. + printk("hm, tasklet state: %08lx\n", t->state);
  20080. + WARN_ON(1);
  20081. + tasklet_unlock(t);
  20082. + break;
  20083. + }
  20084. + }
  20085. }
  20086. }
  20087. +static void tasklet_action(struct softirq_action *a)
  20088. +{
  20089. + struct tasklet_struct *list;
  20090. +
  20091. + local_irq_disable();
  20092. +
  20093. + list = __this_cpu_read(tasklet_vec.head);
  20094. + __this_cpu_write(tasklet_vec.head, NULL);
  20095. + __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  20096. +
  20097. + local_irq_enable();
  20098. +
  20099. + __tasklet_action(a, list);
  20100. +}
  20101. +
  20102. static void tasklet_hi_action(struct softirq_action *a)
  20103. {
  20104. struct tasklet_struct *list;
  20105. local_irq_disable();
  20106. +
  20107. list = __this_cpu_read(tasklet_hi_vec.head);
  20108. __this_cpu_write(tasklet_hi_vec.head, NULL);
  20109. __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
  20110. - local_irq_enable();
  20111. - while (list) {
  20112. - struct tasklet_struct *t = list;
  20113. -
  20114. - list = list->next;
  20115. -
  20116. - if (tasklet_trylock(t)) {
  20117. - if (!atomic_read(&t->count)) {
  20118. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  20119. - &t->state))
  20120. - BUG();
  20121. - t->func(t->data);
  20122. - tasklet_unlock(t);
  20123. - continue;
  20124. - }
  20125. - tasklet_unlock(t);
  20126. - }
  20127. + local_irq_enable();
  20128. - local_irq_disable();
  20129. - t->next = NULL;
  20130. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  20131. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  20132. - __raise_softirq_irqoff(HI_SOFTIRQ);
  20133. - local_irq_enable();
  20134. - }
  20135. + __tasklet_action(a, list);
  20136. }
  20137. void tasklet_init(struct tasklet_struct *t,
  20138. @@ -572,7 +1070,7 @@
  20139. while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
  20140. do {
  20141. - yield();
  20142. + msleep(1);
  20143. } while (test_bit(TASKLET_STATE_SCHED, &t->state));
  20144. }
  20145. tasklet_unlock_wait(t);
  20146. @@ -646,25 +1144,26 @@
  20147. open_softirq(HI_SOFTIRQ, tasklet_hi_action);
  20148. }
  20149. -static int ksoftirqd_should_run(unsigned int cpu)
  20150. -{
  20151. - return local_softirq_pending();
  20152. -}
  20153. -
  20154. -static void run_ksoftirqd(unsigned int cpu)
  20155. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  20156. +void tasklet_unlock_wait(struct tasklet_struct *t)
  20157. {
  20158. - local_irq_disable();
  20159. - if (local_softirq_pending()) {
  20160. + while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
  20161. /*
  20162. - * We can safely run softirq on inline stack, as we are not deep
  20163. - * in the task stack here.
  20164. + * Hack for now to avoid this busy-loop:
  20165. */
  20166. - __do_softirq();
  20167. - local_irq_enable();
  20168. - cond_resched_rcu_qs();
  20169. - return;
  20170. +#ifdef CONFIG_PREEMPT_RT_FULL
  20171. + msleep(1);
  20172. +#else
  20173. + barrier();
  20174. +#endif
  20175. }
  20176. - local_irq_enable();
  20177. +}
  20178. +EXPORT_SYMBOL(tasklet_unlock_wait);
  20179. +#endif
  20180. +
  20181. +static int ksoftirqd_should_run(unsigned int cpu)
  20182. +{
  20183. + return ksoftirqd_softirq_pending();
  20184. }
  20185. #ifdef CONFIG_HOTPLUG_CPU
  20186. @@ -746,16 +1245,31 @@
  20187. static struct smp_hotplug_thread softirq_threads = {
  20188. .store = &ksoftirqd,
  20189. + .setup = ksoftirqd_set_sched_params,
  20190. .thread_should_run = ksoftirqd_should_run,
  20191. .thread_fn = run_ksoftirqd,
  20192. .thread_comm = "ksoftirqd/%u",
  20193. };
  20194. +#ifdef CONFIG_PREEMPT_RT_FULL
  20195. +static struct smp_hotplug_thread softirq_timer_threads = {
  20196. + .store = &ktimer_softirqd,
  20197. + .setup = ktimer_softirqd_set_sched_params,
  20198. + .cleanup = ktimer_softirqd_clr_sched_params,
  20199. + .thread_should_run = ktimer_softirqd_should_run,
  20200. + .thread_fn = run_ksoftirqd,
  20201. + .thread_comm = "ktimersoftd/%u",
  20202. +};
  20203. +#endif
  20204. +
  20205. static __init int spawn_ksoftirqd(void)
  20206. {
  20207. register_cpu_notifier(&cpu_nfb);
  20208. BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
  20209. +#ifdef CONFIG_PREEMPT_RT_FULL
  20210. + BUG_ON(smpboot_register_percpu_thread(&softirq_timer_threads));
  20211. +#endif
  20212. return 0;
  20213. }
  20214. diff -Nur linux-4.1.26.orig/kernel/stop_machine.c linux-4.1.26/kernel/stop_machine.c
  20215. --- linux-4.1.26.orig/kernel/stop_machine.c 2016-06-07 01:13:11.000000000 +0200
  20216. +++ linux-4.1.26/kernel/stop_machine.c 2016-06-19 15:30:58.707298121 +0200
  20217. @@ -35,7 +35,7 @@
  20218. /* the actual stopper, one per every possible cpu, enabled on online cpus */
  20219. struct cpu_stopper {
  20220. - spinlock_t lock;
  20221. + raw_spinlock_t lock;
  20222. bool enabled; /* is this stopper enabled? */
  20223. struct list_head works; /* list of pending works */
  20224. };
  20225. @@ -78,7 +78,7 @@
  20226. unsigned long flags;
  20227. - spin_lock_irqsave(&stopper->lock, flags);
  20228. + raw_spin_lock_irqsave(&stopper->lock, flags);
  20229. if (stopper->enabled) {
  20230. list_add_tail(&work->list, &stopper->works);
  20231. @@ -86,7 +86,7 @@
  20232. } else
  20233. cpu_stop_signal_done(work->done, false);
  20234. - spin_unlock_irqrestore(&stopper->lock, flags);
  20235. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  20236. }
  20237. /**
  20238. @@ -248,7 +248,7 @@
  20239. struct irq_cpu_stop_queue_work_info call_args;
  20240. struct multi_stop_data msdata;
  20241. - preempt_disable();
  20242. + preempt_disable_nort();
  20243. msdata = (struct multi_stop_data){
  20244. .fn = fn,
  20245. .data = arg,
  20246. @@ -281,7 +281,7 @@
  20247. * This relies on the stopper workqueues to be FIFO.
  20248. */
  20249. if (!cpu_active(cpu1) || !cpu_active(cpu2)) {
  20250. - preempt_enable();
  20251. + preempt_enable_nort();
  20252. return -ENOENT;
  20253. }
  20254. @@ -295,7 +295,7 @@
  20255. &irq_cpu_stop_queue_work,
  20256. &call_args, 1);
  20257. lg_local_unlock(&stop_cpus_lock);
  20258. - preempt_enable();
  20259. + preempt_enable_nort();
  20260. wait_for_completion(&done.completion);
  20261. @@ -329,7 +329,7 @@
  20262. static void queue_stop_cpus_work(const struct cpumask *cpumask,
  20263. cpu_stop_fn_t fn, void *arg,
  20264. - struct cpu_stop_done *done)
  20265. + struct cpu_stop_done *done, bool inactive)
  20266. {
  20267. struct cpu_stop_work *work;
  20268. unsigned int cpu;
  20269. @@ -343,11 +343,13 @@
  20270. }
  20271. /*
  20272. - * Disable preemption while queueing to avoid getting
  20273. - * preempted by a stopper which might wait for other stoppers
  20274. - * to enter @fn which can lead to deadlock.
  20275. + * Make sure that all work is queued on all cpus before
  20276. + * any of the cpus can execute it.
  20277. */
  20278. - lg_global_lock(&stop_cpus_lock);
  20279. + if (!inactive)
  20280. + lg_global_lock(&stop_cpus_lock);
  20281. + else
  20282. + lg_global_trylock_relax(&stop_cpus_lock);
  20283. for_each_cpu(cpu, cpumask)
  20284. cpu_stop_queue_work(cpu, &per_cpu(stop_cpus_work, cpu));
  20285. lg_global_unlock(&stop_cpus_lock);
  20286. @@ -359,7 +361,7 @@
  20287. struct cpu_stop_done done;
  20288. cpu_stop_init_done(&done, cpumask_weight(cpumask));
  20289. - queue_stop_cpus_work(cpumask, fn, arg, &done);
  20290. + queue_stop_cpus_work(cpumask, fn, arg, &done, false);
  20291. wait_for_completion(&done.completion);
  20292. return done.executed ? done.ret : -ENOENT;
  20293. }
  20294. @@ -439,9 +441,9 @@
  20295. unsigned long flags;
  20296. int run;
  20297. - spin_lock_irqsave(&stopper->lock, flags);
  20298. + raw_spin_lock_irqsave(&stopper->lock, flags);
  20299. run = !list_empty(&stopper->works);
  20300. - spin_unlock_irqrestore(&stopper->lock, flags);
  20301. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  20302. return run;
  20303. }
  20304. @@ -453,13 +455,13 @@
  20305. repeat:
  20306. work = NULL;
  20307. - spin_lock_irq(&stopper->lock);
  20308. + raw_spin_lock_irq(&stopper->lock);
  20309. if (!list_empty(&stopper->works)) {
  20310. work = list_first_entry(&stopper->works,
  20311. struct cpu_stop_work, list);
  20312. list_del_init(&work->list);
  20313. }
  20314. - spin_unlock_irq(&stopper->lock);
  20315. + raw_spin_unlock_irq(&stopper->lock);
  20316. if (work) {
  20317. cpu_stop_fn_t fn = work->fn;
  20318. @@ -467,6 +469,16 @@
  20319. struct cpu_stop_done *done = work->done;
  20320. char ksym_buf[KSYM_NAME_LEN] __maybe_unused;
  20321. + /*
  20322. + * Wait until the stopper finished scheduling on all
  20323. + * cpus
  20324. + */
  20325. + lg_global_lock(&stop_cpus_lock);
  20326. + /*
  20327. + * Let other cpu threads continue as well
  20328. + */
  20329. + lg_global_unlock(&stop_cpus_lock);
  20330. +
  20331. /* cpu stop callbacks are not allowed to sleep */
  20332. preempt_disable();
  20333. @@ -500,20 +512,20 @@
  20334. unsigned long flags;
  20335. /* drain remaining works */
  20336. - spin_lock_irqsave(&stopper->lock, flags);
  20337. + raw_spin_lock_irqsave(&stopper->lock, flags);
  20338. list_for_each_entry(work, &stopper->works, list)
  20339. cpu_stop_signal_done(work->done, false);
  20340. stopper->enabled = false;
  20341. - spin_unlock_irqrestore(&stopper->lock, flags);
  20342. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  20343. }
  20344. static void cpu_stop_unpark(unsigned int cpu)
  20345. {
  20346. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  20347. - spin_lock_irq(&stopper->lock);
  20348. + raw_spin_lock_irq(&stopper->lock);
  20349. stopper->enabled = true;
  20350. - spin_unlock_irq(&stopper->lock);
  20351. + raw_spin_unlock_irq(&stopper->lock);
  20352. }
  20353. static struct smp_hotplug_thread cpu_stop_threads = {
  20354. @@ -535,10 +547,12 @@
  20355. for_each_possible_cpu(cpu) {
  20356. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  20357. - spin_lock_init(&stopper->lock);
  20358. + raw_spin_lock_init(&stopper->lock);
  20359. INIT_LIST_HEAD(&stopper->works);
  20360. }
  20361. + lg_lock_init(&stop_cpus_lock, "stop_cpus_lock");
  20362. +
  20363. BUG_ON(smpboot_register_percpu_thread(&cpu_stop_threads));
  20364. stop_machine_initialized = true;
  20365. return 0;
  20366. @@ -634,7 +648,7 @@
  20367. set_state(&msdata, MULTI_STOP_PREPARE);
  20368. cpu_stop_init_done(&done, num_active_cpus());
  20369. queue_stop_cpus_work(cpu_active_mask, multi_cpu_stop, &msdata,
  20370. - &done);
  20371. + &done, true);
  20372. ret = multi_cpu_stop(&msdata);
  20373. /* Busy wait for completion. */
  20374. diff -Nur linux-4.1.26.orig/kernel/time/hrtimer.c linux-4.1.26/kernel/time/hrtimer.c
  20375. --- linux-4.1.26.orig/kernel/time/hrtimer.c 2016-06-07 01:13:11.000000000 +0200
  20376. +++ linux-4.1.26/kernel/time/hrtimer.c 2016-06-19 15:30:58.707298121 +0200
  20377. @@ -48,11 +48,13 @@
  20378. #include <linux/sched/rt.h>
  20379. #include <linux/sched/deadline.h>
  20380. #include <linux/timer.h>
  20381. +#include <linux/kthread.h>
  20382. #include <linux/freezer.h>
  20383. #include <asm/uaccess.h>
  20384. #include <trace/events/timer.h>
  20385. +#include <trace/events/hist.h>
  20386. #include "tick-internal.h"
  20387. @@ -576,8 +578,7 @@
  20388. * When the callback is running, we do not reprogram the clock event
  20389. * device. The timer callback is either running on a different CPU or
  20390. * the callback is executed in the hrtimer_interrupt context. The
  20391. - * reprogramming is handled either by the softirq, which called the
  20392. - * callback or at the end of the hrtimer_interrupt.
  20393. + * reprogramming is handled at the end of the hrtimer_interrupt.
  20394. */
  20395. if (hrtimer_callback_running(timer))
  20396. return 0;
  20397. @@ -621,6 +622,9 @@
  20398. return res;
  20399. }
  20400. +static void __run_hrtimer(struct hrtimer *timer, ktime_t *now);
  20401. +static int hrtimer_rt_defer(struct hrtimer *timer);
  20402. +
  20403. /*
  20404. * Initialize the high resolution related parts of cpu_base
  20405. */
  20406. @@ -630,6 +634,21 @@
  20407. base->hres_active = 0;
  20408. }
  20409. +static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  20410. + struct hrtimer_clock_base *base,
  20411. + int wakeup)
  20412. +{
  20413. + if (!hrtimer_reprogram(timer, base))
  20414. + return 0;
  20415. + if (!wakeup)
  20416. + return -ETIME;
  20417. +#ifdef CONFIG_PREEMPT_RT_BASE
  20418. + if (!hrtimer_rt_defer(timer))
  20419. + return -ETIME;
  20420. +#endif
  20421. + return 1;
  20422. +}
  20423. +
  20424. static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
  20425. {
  20426. ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
  20427. @@ -695,6 +714,44 @@
  20428. static DECLARE_WORK(hrtimer_work, clock_was_set_work);
  20429. +#ifdef CONFIG_PREEMPT_RT_FULL
  20430. +/*
  20431. + * RT can not call schedule_work from real interrupt context.
  20432. + * Need to make a thread to do the real work.
  20433. + */
  20434. +static struct task_struct *clock_set_delay_thread;
  20435. +static bool do_clock_set_delay;
  20436. +
  20437. +static int run_clock_set_delay(void *ignore)
  20438. +{
  20439. + while (!kthread_should_stop()) {
  20440. + set_current_state(TASK_INTERRUPTIBLE);
  20441. + if (do_clock_set_delay) {
  20442. + do_clock_set_delay = false;
  20443. + schedule_work(&hrtimer_work);
  20444. + }
  20445. + schedule();
  20446. + }
  20447. + __set_current_state(TASK_RUNNING);
  20448. + return 0;
  20449. +}
  20450. +
  20451. +void clock_was_set_delayed(void)
  20452. +{
  20453. + do_clock_set_delay = true;
  20454. + /* Make visible before waking up process */
  20455. + smp_wmb();
  20456. + wake_up_process(clock_set_delay_thread);
  20457. +}
  20458. +
  20459. +static __init int create_clock_set_delay_thread(void)
  20460. +{
  20461. + clock_set_delay_thread = kthread_run(run_clock_set_delay, NULL, "kclksetdelayd");
  20462. + BUG_ON(!clock_set_delay_thread);
  20463. + return 0;
  20464. +}
  20465. +early_initcall(create_clock_set_delay_thread);
  20466. +#else /* PREEMPT_RT_FULL */
  20467. /*
  20468. * Called from timekeeping and resume code to reprogramm the hrtimer
  20469. * interrupt device on all cpus.
  20470. @@ -703,6 +760,7 @@
  20471. {
  20472. schedule_work(&hrtimer_work);
  20473. }
  20474. +#endif
  20475. #else
  20476. @@ -711,6 +769,13 @@
  20477. static inline int hrtimer_switch_to_hres(void) { return 0; }
  20478. static inline void
  20479. hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
  20480. +static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  20481. + struct hrtimer_clock_base *base,
  20482. + int wakeup)
  20483. +{
  20484. + return 0;
  20485. +}
  20486. +
  20487. static inline int hrtimer_reprogram(struct hrtimer *timer,
  20488. struct hrtimer_clock_base *base)
  20489. {
  20490. @@ -718,7 +783,6 @@
  20491. }
  20492. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  20493. static inline void retrigger_next_event(void *arg) { }
  20494. -
  20495. #endif /* CONFIG_HIGH_RES_TIMERS */
  20496. /*
  20497. @@ -836,6 +900,32 @@
  20498. }
  20499. EXPORT_SYMBOL_GPL(hrtimer_forward);
  20500. +#ifdef CONFIG_PREEMPT_RT_BASE
  20501. +# define wake_up_timer_waiters(b) wake_up(&(b)->wait)
  20502. +
  20503. +/**
  20504. + * hrtimer_wait_for_timer - Wait for a running timer
  20505. + *
  20506. + * @timer: timer to wait for
  20507. + *
  20508. + * The function waits in case the timers callback function is
  20509. + * currently executed on the waitqueue of the timer base. The
  20510. + * waitqueue is woken up after the timer callback function has
  20511. + * finished execution.
  20512. + */
  20513. +void hrtimer_wait_for_timer(const struct hrtimer *timer)
  20514. +{
  20515. + struct hrtimer_clock_base *base = timer->base;
  20516. +
  20517. + if (base && base->cpu_base && !timer->irqsafe)
  20518. + wait_event(base->cpu_base->wait,
  20519. + !(timer->state & HRTIMER_STATE_CALLBACK));
  20520. +}
  20521. +
  20522. +#else
  20523. +# define wake_up_timer_waiters(b) do { } while (0)
  20524. +#endif
  20525. +
  20526. /*
  20527. * enqueue_hrtimer - internal function to (re)start a timer
  20528. *
  20529. @@ -879,6 +969,11 @@
  20530. if (!(timer->state & HRTIMER_STATE_ENQUEUED))
  20531. goto out;
  20532. + if (unlikely(!list_empty(&timer->cb_entry))) {
  20533. + list_del_init(&timer->cb_entry);
  20534. + goto out;
  20535. + }
  20536. +
  20537. next_timer = timerqueue_getnext(&base->active);
  20538. timerqueue_del(&base->active, &timer->node);
  20539. if (&timer->node == next_timer) {
  20540. @@ -966,7 +1061,16 @@
  20541. new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  20542. timer_stats_hrtimer_set_start_info(timer);
  20543. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  20544. + {
  20545. + ktime_t now = new_base->get_time();
  20546. + if (ktime_to_ns(tim) < ktime_to_ns(now))
  20547. + timer->praecox = now;
  20548. + else
  20549. + timer->praecox = ktime_set(0, 0);
  20550. + }
  20551. +#endif
  20552. leftmost = enqueue_hrtimer(timer, new_base);
  20553. if (!leftmost) {
  20554. @@ -980,15 +1084,26 @@
  20555. * on dynticks target.
  20556. */
  20557. wake_up_nohz_cpu(new_base->cpu_base->cpu);
  20558. - } else if (new_base->cpu_base == this_cpu_ptr(&hrtimer_bases) &&
  20559. - hrtimer_reprogram(timer, new_base)) {
  20560. + } else if (new_base->cpu_base == this_cpu_ptr(&hrtimer_bases)) {
  20561. +
  20562. + ret = hrtimer_enqueue_reprogram(timer, new_base, wakeup);
  20563. + if (ret < 0) {
  20564. + /*
  20565. + * In case we failed to reprogram the timer (mostly
  20566. + * because out current timer is already elapsed),
  20567. + * remove it again and report a failure. This avoids
  20568. + * stale base->first entries.
  20569. + */
  20570. + debug_deactivate(timer);
  20571. + __remove_hrtimer(timer, new_base,
  20572. + timer->state & HRTIMER_STATE_CALLBACK, 0);
  20573. + } else if (ret > 0) {
  20574. /*
  20575. * Only allow reprogramming if the new base is on this CPU.
  20576. * (it might still be on another CPU if the timer was pending)
  20577. *
  20578. * XXX send_remote_softirq() ?
  20579. */
  20580. - if (wakeup) {
  20581. /*
  20582. * We need to drop cpu_base->lock to avoid a
  20583. * lock ordering issue vs. rq->lock.
  20584. @@ -996,9 +1111,7 @@
  20585. raw_spin_unlock(&new_base->cpu_base->lock);
  20586. raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  20587. local_irq_restore(flags);
  20588. - return ret;
  20589. - } else {
  20590. - __raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  20591. + return 0;
  20592. }
  20593. }
  20594. @@ -1089,7 +1202,7 @@
  20595. if (ret >= 0)
  20596. return ret;
  20597. - cpu_relax();
  20598. + hrtimer_wait_for_timer(timer);
  20599. }
  20600. }
  20601. EXPORT_SYMBOL_GPL(hrtimer_cancel);
  20602. @@ -1153,6 +1266,7 @@
  20603. base = hrtimer_clockid_to_base(clock_id);
  20604. timer->base = &cpu_base->clock_base[base];
  20605. + INIT_LIST_HEAD(&timer->cb_entry);
  20606. timerqueue_init(&timer->node);
  20607. #ifdef CONFIG_TIMER_STATS
  20608. @@ -1236,6 +1350,126 @@
  20609. timer->state &= ~HRTIMER_STATE_CALLBACK;
  20610. }
  20611. +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
  20612. +
  20613. +#ifdef CONFIG_PREEMPT_RT_BASE
  20614. +static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
  20615. + struct hrtimer_clock_base *base)
  20616. +{
  20617. + /*
  20618. + * Note, we clear the callback flag before we requeue the
  20619. + * timer otherwise we trigger the callback_running() check
  20620. + * in hrtimer_reprogram().
  20621. + */
  20622. + timer->state &= ~HRTIMER_STATE_CALLBACK;
  20623. +
  20624. + if (restart != HRTIMER_NORESTART) {
  20625. + BUG_ON(hrtimer_active(timer));
  20626. + /*
  20627. + * Enqueue the timer, if it's the leftmost timer then
  20628. + * we need to reprogram it.
  20629. + */
  20630. + if (!enqueue_hrtimer(timer, base))
  20631. + return;
  20632. +
  20633. +#ifndef CONFIG_HIGH_RES_TIMERS
  20634. + }
  20635. +#else
  20636. + if (base->cpu_base->hres_active &&
  20637. + hrtimer_reprogram(timer, base))
  20638. + goto requeue;
  20639. +
  20640. + } else if (hrtimer_active(timer)) {
  20641. + /*
  20642. + * If the timer was rearmed on another CPU, reprogram
  20643. + * the event device.
  20644. + */
  20645. + if (&timer->node == base->active.next &&
  20646. + base->cpu_base->hres_active &&
  20647. + hrtimer_reprogram(timer, base))
  20648. + goto requeue;
  20649. + }
  20650. + return;
  20651. +
  20652. +requeue:
  20653. + /*
  20654. + * Timer is expired. Thus move it from tree to pending list
  20655. + * again.
  20656. + */
  20657. + __remove_hrtimer(timer, base, timer->state, 0);
  20658. + list_add_tail(&timer->cb_entry, &base->expired);
  20659. +#endif
  20660. +}
  20661. +
  20662. +/*
  20663. + * The changes in mainline which removed the callback modes from
  20664. + * hrtimer are not yet working with -rt. The non wakeup_process()
  20665. + * based callbacks which involve sleeping locks need to be treated
  20666. + * seperately.
  20667. + */
  20668. +static void hrtimer_rt_run_pending(void)
  20669. +{
  20670. + enum hrtimer_restart (*fn)(struct hrtimer *);
  20671. + struct hrtimer_cpu_base *cpu_base;
  20672. + struct hrtimer_clock_base *base;
  20673. + struct hrtimer *timer;
  20674. + int index, restart;
  20675. +
  20676. + local_irq_disable();
  20677. + cpu_base = &per_cpu(hrtimer_bases, smp_processor_id());
  20678. +
  20679. + raw_spin_lock(&cpu_base->lock);
  20680. +
  20681. + for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
  20682. + base = &cpu_base->clock_base[index];
  20683. +
  20684. + while (!list_empty(&base->expired)) {
  20685. + timer = list_first_entry(&base->expired,
  20686. + struct hrtimer, cb_entry);
  20687. +
  20688. + /*
  20689. + * Same as the above __run_hrtimer function
  20690. + * just we run with interrupts enabled.
  20691. + */
  20692. + debug_hrtimer_deactivate(timer);
  20693. + __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
  20694. + timer_stats_account_hrtimer(timer);
  20695. + fn = timer->function;
  20696. +
  20697. + raw_spin_unlock_irq(&cpu_base->lock);
  20698. + restart = fn(timer);
  20699. + raw_spin_lock_irq(&cpu_base->lock);
  20700. +
  20701. + hrtimer_rt_reprogram(restart, timer, base);
  20702. + }
  20703. + }
  20704. +
  20705. + raw_spin_unlock_irq(&cpu_base->lock);
  20706. +
  20707. + wake_up_timer_waiters(cpu_base);
  20708. +}
  20709. +
  20710. +static int hrtimer_rt_defer(struct hrtimer *timer)
  20711. +{
  20712. + if (timer->irqsafe)
  20713. + return 0;
  20714. +
  20715. + __remove_hrtimer(timer, timer->base, timer->state, 0);
  20716. + list_add_tail(&timer->cb_entry, &timer->base->expired);
  20717. + return 1;
  20718. +}
  20719. +
  20720. +#else
  20721. +
  20722. +static inline void hrtimer_rt_run_pending(void)
  20723. +{
  20724. + hrtimer_peek_ahead_timers();
  20725. +}
  20726. +
  20727. +static inline int hrtimer_rt_defer(struct hrtimer *timer) { return 0; }
  20728. +
  20729. +#endif
  20730. +
  20731. #ifdef CONFIG_HIGH_RES_TIMERS
  20732. /*
  20733. @@ -1246,7 +1480,7 @@
  20734. {
  20735. struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
  20736. ktime_t expires_next, now, entry_time, delta;
  20737. - int i, retries = 0;
  20738. + int i, retries = 0, raise = 0;
  20739. BUG_ON(!cpu_base->hres_active);
  20740. cpu_base->nr_events++;
  20741. @@ -1281,6 +1515,15 @@
  20742. timer = container_of(node, struct hrtimer, node);
  20743. + trace_hrtimer_interrupt(raw_smp_processor_id(),
  20744. + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ?
  20745. + timer->praecox : hrtimer_get_expires(timer),
  20746. + basenow)),
  20747. + current,
  20748. + timer->function == hrtimer_wakeup ?
  20749. + container_of(timer, struct hrtimer_sleeper,
  20750. + timer)->task : NULL);
  20751. +
  20752. /*
  20753. * The immediate goal for using the softexpires is
  20754. * minimizing wakeups, not running timers at the
  20755. @@ -1296,7 +1539,10 @@
  20756. if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer))
  20757. break;
  20758. - __run_hrtimer(timer, &basenow);
  20759. + if (!hrtimer_rt_defer(timer))
  20760. + __run_hrtimer(timer, &basenow);
  20761. + else
  20762. + raise = 1;
  20763. }
  20764. }
  20765. /* Reevaluate the clock bases for the next expiry */
  20766. @@ -1313,7 +1559,7 @@
  20767. if (expires_next.tv64 == KTIME_MAX ||
  20768. !tick_program_event(expires_next, 0)) {
  20769. cpu_base->hang_detected = 0;
  20770. - return;
  20771. + goto out;
  20772. }
  20773. /*
  20774. @@ -1357,6 +1603,9 @@
  20775. tick_program_event(expires_next, 1);
  20776. printk_once(KERN_WARNING "hrtimer: interrupt took %llu ns\n",
  20777. ktime_to_ns(delta));
  20778. +out:
  20779. + if (raise)
  20780. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  20781. }
  20782. /*
  20783. @@ -1392,18 +1641,18 @@
  20784. __hrtimer_peek_ahead_timers();
  20785. local_irq_restore(flags);
  20786. }
  20787. -
  20788. -static void run_hrtimer_softirq(struct softirq_action *h)
  20789. -{
  20790. - hrtimer_peek_ahead_timers();
  20791. -}
  20792. -
  20793. #else /* CONFIG_HIGH_RES_TIMERS */
  20794. static inline void __hrtimer_peek_ahead_timers(void) { }
  20795. #endif /* !CONFIG_HIGH_RES_TIMERS */
  20796. +
  20797. +static void run_hrtimer_softirq(struct softirq_action *h)
  20798. +{
  20799. + hrtimer_rt_run_pending();
  20800. +}
  20801. +
  20802. /*
  20803. * Called from timer softirq every jiffy, expire hrtimers:
  20804. *
  20805. @@ -1436,7 +1685,7 @@
  20806. struct timerqueue_node *node;
  20807. struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
  20808. struct hrtimer_clock_base *base;
  20809. - int index, gettime = 1;
  20810. + int index, gettime = 1, raise = 0;
  20811. if (hrtimer_hres_active())
  20812. return;
  20813. @@ -1461,10 +1710,16 @@
  20814. hrtimer_get_expires_tv64(timer))
  20815. break;
  20816. - __run_hrtimer(timer, &base->softirq_time);
  20817. + if (!hrtimer_rt_defer(timer))
  20818. + __run_hrtimer(timer, &base->softirq_time);
  20819. + else
  20820. + raise = 1;
  20821. }
  20822. raw_spin_unlock(&cpu_base->lock);
  20823. }
  20824. +
  20825. + if (raise)
  20826. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  20827. }
  20828. /*
  20829. @@ -1486,16 +1741,18 @@
  20830. void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  20831. {
  20832. sl->timer.function = hrtimer_wakeup;
  20833. + sl->timer.irqsafe = 1;
  20834. sl->task = task;
  20835. }
  20836. EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
  20837. -static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
  20838. +static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode,
  20839. + unsigned long state)
  20840. {
  20841. hrtimer_init_sleeper(t, current);
  20842. do {
  20843. - set_current_state(TASK_INTERRUPTIBLE);
  20844. + set_current_state(state);
  20845. hrtimer_start_expires(&t->timer, mode);
  20846. if (!hrtimer_active(&t->timer))
  20847. t->task = NULL;
  20848. @@ -1539,7 +1796,8 @@
  20849. HRTIMER_MODE_ABS);
  20850. hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  20851. - if (do_nanosleep(&t, HRTIMER_MODE_ABS))
  20852. + /* cpu_chill() does not care about restart state. */
  20853. + if (do_nanosleep(&t, HRTIMER_MODE_ABS, TASK_INTERRUPTIBLE))
  20854. goto out;
  20855. rmtp = restart->nanosleep.rmtp;
  20856. @@ -1556,8 +1814,10 @@
  20857. return ret;
  20858. }
  20859. -long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  20860. - const enum hrtimer_mode mode, const clockid_t clockid)
  20861. +static long
  20862. +__hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  20863. + const enum hrtimer_mode mode, const clockid_t clockid,
  20864. + unsigned long state)
  20865. {
  20866. struct restart_block *restart;
  20867. struct hrtimer_sleeper t;
  20868. @@ -1570,7 +1830,7 @@
  20869. hrtimer_init_on_stack(&t.timer, clockid, mode);
  20870. hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
  20871. - if (do_nanosleep(&t, mode))
  20872. + if (do_nanosleep(&t, mode, state))
  20873. goto out;
  20874. /* Absolute timers do not update the rmtp value and restart: */
  20875. @@ -1597,6 +1857,12 @@
  20876. return ret;
  20877. }
  20878. +long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  20879. + const enum hrtimer_mode mode, const clockid_t clockid)
  20880. +{
  20881. + return __hrtimer_nanosleep(rqtp, rmtp, mode, clockid, TASK_INTERRUPTIBLE);
  20882. +}
  20883. +
  20884. SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
  20885. struct timespec __user *, rmtp)
  20886. {
  20887. @@ -1611,6 +1877,26 @@
  20888. return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  20889. }
  20890. +#ifdef CONFIG_PREEMPT_RT_FULL
  20891. +/*
  20892. + * Sleep for 1 ms in hope whoever holds what we want will let it go.
  20893. + */
  20894. +void cpu_chill(void)
  20895. +{
  20896. + struct timespec tu = {
  20897. + .tv_nsec = NSEC_PER_MSEC,
  20898. + };
  20899. + unsigned int freeze_flag = current->flags & PF_NOFREEZE;
  20900. +
  20901. + current->flags |= PF_NOFREEZE;
  20902. + __hrtimer_nanosleep(&tu, NULL, HRTIMER_MODE_REL, CLOCK_MONOTONIC,
  20903. + TASK_UNINTERRUPTIBLE);
  20904. + if (!freeze_flag)
  20905. + current->flags &= ~PF_NOFREEZE;
  20906. +}
  20907. +EXPORT_SYMBOL(cpu_chill);
  20908. +#endif
  20909. +
  20910. /*
  20911. * Functions related to boot-time initialization:
  20912. */
  20913. @@ -1622,10 +1908,14 @@
  20914. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  20915. cpu_base->clock_base[i].cpu_base = cpu_base;
  20916. timerqueue_init_head(&cpu_base->clock_base[i].active);
  20917. + INIT_LIST_HEAD(&cpu_base->clock_base[i].expired);
  20918. }
  20919. cpu_base->cpu = cpu;
  20920. hrtimer_init_hres(cpu_base);
  20921. +#ifdef CONFIG_PREEMPT_RT_BASE
  20922. + init_waitqueue_head(&cpu_base->wait);
  20923. +#endif
  20924. }
  20925. #ifdef CONFIG_HOTPLUG_CPU
  20926. @@ -1731,9 +2021,7 @@
  20927. hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
  20928. (void *)(long)smp_processor_id());
  20929. register_cpu_notifier(&hrtimers_nb);
  20930. -#ifdef CONFIG_HIGH_RES_TIMERS
  20931. open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
  20932. -#endif
  20933. }
  20934. /**
  20935. diff -Nur linux-4.1.26.orig/kernel/time/itimer.c linux-4.1.26/kernel/time/itimer.c
  20936. --- linux-4.1.26.orig/kernel/time/itimer.c 2016-06-07 01:13:11.000000000 +0200
  20937. +++ linux-4.1.26/kernel/time/itimer.c 2016-06-19 15:30:58.711298275 +0200
  20938. @@ -213,6 +213,7 @@
  20939. /* We are sharing ->siglock with it_real_fn() */
  20940. if (hrtimer_try_to_cancel(timer) < 0) {
  20941. spin_unlock_irq(&tsk->sighand->siglock);
  20942. + hrtimer_wait_for_timer(&tsk->signal->real_timer);
  20943. goto again;
  20944. }
  20945. expires = timeval_to_ktime(value->it_value);
  20946. diff -Nur linux-4.1.26.orig/kernel/time/jiffies.c linux-4.1.26/kernel/time/jiffies.c
  20947. --- linux-4.1.26.orig/kernel/time/jiffies.c 2016-06-07 01:13:11.000000000 +0200
  20948. +++ linux-4.1.26/kernel/time/jiffies.c 2016-06-19 15:30:58.711298275 +0200
  20949. @@ -74,7 +74,8 @@
  20950. .max_cycles = 10,
  20951. };
  20952. -__cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock);
  20953. +__cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(jiffies_lock);
  20954. +__cacheline_aligned_in_smp seqcount_t jiffies_seq;
  20955. #if (BITS_PER_LONG < 64)
  20956. u64 get_jiffies_64(void)
  20957. @@ -83,9 +84,9 @@
  20958. u64 ret;
  20959. do {
  20960. - seq = read_seqbegin(&jiffies_lock);
  20961. + seq = read_seqcount_begin(&jiffies_seq);
  20962. ret = jiffies_64;
  20963. - } while (read_seqretry(&jiffies_lock, seq));
  20964. + } while (read_seqcount_retry(&jiffies_seq, seq));
  20965. return ret;
  20966. }
  20967. EXPORT_SYMBOL(get_jiffies_64);
  20968. diff -Nur linux-4.1.26.orig/kernel/time/ntp.c linux-4.1.26/kernel/time/ntp.c
  20969. --- linux-4.1.26.orig/kernel/time/ntp.c 2016-06-07 01:13:11.000000000 +0200
  20970. +++ linux-4.1.26/kernel/time/ntp.c 2016-06-19 15:30:58.711298275 +0200
  20971. @@ -10,6 +10,7 @@
  20972. #include <linux/workqueue.h>
  20973. #include <linux/hrtimer.h>
  20974. #include <linux/jiffies.h>
  20975. +#include <linux/kthread.h>
  20976. #include <linux/math64.h>
  20977. #include <linux/timex.h>
  20978. #include <linux/time.h>
  20979. @@ -529,10 +530,52 @@
  20980. &sync_cmos_work, timespec_to_jiffies(&next));
  20981. }
  20982. +#ifdef CONFIG_PREEMPT_RT_FULL
  20983. +/*
  20984. + * RT can not call schedule_delayed_work from real interrupt context.
  20985. + * Need to make a thread to do the real work.
  20986. + */
  20987. +static struct task_struct *cmos_delay_thread;
  20988. +static bool do_cmos_delay;
  20989. +
  20990. +static int run_cmos_delay(void *ignore)
  20991. +{
  20992. + while (!kthread_should_stop()) {
  20993. + set_current_state(TASK_INTERRUPTIBLE);
  20994. + if (do_cmos_delay) {
  20995. + do_cmos_delay = false;
  20996. + queue_delayed_work(system_power_efficient_wq,
  20997. + &sync_cmos_work, 0);
  20998. + }
  20999. + schedule();
  21000. + }
  21001. + __set_current_state(TASK_RUNNING);
  21002. + return 0;
  21003. +}
  21004. +
  21005. +void ntp_notify_cmos_timer(void)
  21006. +{
  21007. + do_cmos_delay = true;
  21008. + /* Make visible before waking up process */
  21009. + smp_wmb();
  21010. + wake_up_process(cmos_delay_thread);
  21011. +}
  21012. +
  21013. +static __init int create_cmos_delay_thread(void)
  21014. +{
  21015. + cmos_delay_thread = kthread_run(run_cmos_delay, NULL, "kcmosdelayd");
  21016. + BUG_ON(!cmos_delay_thread);
  21017. + return 0;
  21018. +}
  21019. +early_initcall(create_cmos_delay_thread);
  21020. +
  21021. +#else
  21022. +
  21023. void ntp_notify_cmos_timer(void)
  21024. {
  21025. queue_delayed_work(system_power_efficient_wq, &sync_cmos_work, 0);
  21026. }
  21027. +#endif /* CONFIG_PREEMPT_RT_FULL */
  21028. #else
  21029. void ntp_notify_cmos_timer(void) { }
  21030. diff -Nur linux-4.1.26.orig/kernel/time/posix-cpu-timers.c linux-4.1.26/kernel/time/posix-cpu-timers.c
  21031. --- linux-4.1.26.orig/kernel/time/posix-cpu-timers.c 2016-06-07 01:13:11.000000000 +0200
  21032. +++ linux-4.1.26/kernel/time/posix-cpu-timers.c 2016-06-19 15:30:58.711298275 +0200
  21033. @@ -3,6 +3,7 @@
  21034. */
  21035. #include <linux/sched.h>
  21036. +#include <linux/sched/rt.h>
  21037. #include <linux/posix-timers.h>
  21038. #include <linux/errno.h>
  21039. #include <linux/math64.h>
  21040. @@ -626,7 +627,7 @@
  21041. /*
  21042. * Disarm any old timer after extracting its expiry time.
  21043. */
  21044. - WARN_ON_ONCE(!irqs_disabled());
  21045. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  21046. ret = 0;
  21047. old_incr = timer->it.cpu.incr;
  21048. @@ -1047,7 +1048,7 @@
  21049. /*
  21050. * Now re-arm for the new expiry time.
  21051. */
  21052. - WARN_ON_ONCE(!irqs_disabled());
  21053. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  21054. arm_timer(timer);
  21055. unlock_task_sighand(p, &flags);
  21056. @@ -1113,10 +1114,11 @@
  21057. sig = tsk->signal;
  21058. if (sig->cputimer.running) {
  21059. struct task_cputime group_sample;
  21060. + unsigned long flags;
  21061. - raw_spin_lock(&sig->cputimer.lock);
  21062. + raw_spin_lock_irqsave(&sig->cputimer.lock, flags);
  21063. group_sample = sig->cputimer.cputime;
  21064. - raw_spin_unlock(&sig->cputimer.lock);
  21065. + raw_spin_unlock_irqrestore(&sig->cputimer.lock, flags);
  21066. if (task_cputime_expired(&group_sample, &sig->cputime_expires))
  21067. return 1;
  21068. @@ -1130,13 +1132,13 @@
  21069. * already updated our counts. We need to check if any timers fire now.
  21070. * Interrupts are disabled.
  21071. */
  21072. -void run_posix_cpu_timers(struct task_struct *tsk)
  21073. +static void __run_posix_cpu_timers(struct task_struct *tsk)
  21074. {
  21075. LIST_HEAD(firing);
  21076. struct k_itimer *timer, *next;
  21077. unsigned long flags;
  21078. - WARN_ON_ONCE(!irqs_disabled());
  21079. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  21080. /*
  21081. * The fast path checks that there are no expired thread or thread
  21082. @@ -1194,6 +1196,190 @@
  21083. }
  21084. }
  21085. +#ifdef CONFIG_PREEMPT_RT_BASE
  21086. +#include <linux/kthread.h>
  21087. +#include <linux/cpu.h>
  21088. +DEFINE_PER_CPU(struct task_struct *, posix_timer_task);
  21089. +DEFINE_PER_CPU(struct task_struct *, posix_timer_tasklist);
  21090. +
  21091. +static int posix_cpu_timers_thread(void *data)
  21092. +{
  21093. + int cpu = (long)data;
  21094. +
  21095. + BUG_ON(per_cpu(posix_timer_task,cpu) != current);
  21096. +
  21097. + while (!kthread_should_stop()) {
  21098. + struct task_struct *tsk = NULL;
  21099. + struct task_struct *next = NULL;
  21100. +
  21101. + if (cpu_is_offline(cpu))
  21102. + goto wait_to_die;
  21103. +
  21104. + /* grab task list */
  21105. + raw_local_irq_disable();
  21106. + tsk = per_cpu(posix_timer_tasklist, cpu);
  21107. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  21108. + raw_local_irq_enable();
  21109. +
  21110. + /* its possible the list is empty, just return */
  21111. + if (!tsk) {
  21112. + set_current_state(TASK_INTERRUPTIBLE);
  21113. + schedule();
  21114. + __set_current_state(TASK_RUNNING);
  21115. + continue;
  21116. + }
  21117. +
  21118. + /* Process task list */
  21119. + while (1) {
  21120. + /* save next */
  21121. + next = tsk->posix_timer_list;
  21122. +
  21123. + /* run the task timers, clear its ptr and
  21124. + * unreference it
  21125. + */
  21126. + __run_posix_cpu_timers(tsk);
  21127. + tsk->posix_timer_list = NULL;
  21128. + put_task_struct(tsk);
  21129. +
  21130. + /* check if this is the last on the list */
  21131. + if (next == tsk)
  21132. + break;
  21133. + tsk = next;
  21134. + }
  21135. + }
  21136. + return 0;
  21137. +
  21138. +wait_to_die:
  21139. + /* Wait for kthread_stop */
  21140. + set_current_state(TASK_INTERRUPTIBLE);
  21141. + while (!kthread_should_stop()) {
  21142. + schedule();
  21143. + set_current_state(TASK_INTERRUPTIBLE);
  21144. + }
  21145. + __set_current_state(TASK_RUNNING);
  21146. + return 0;
  21147. +}
  21148. +
  21149. +static inline int __fastpath_timer_check(struct task_struct *tsk)
  21150. +{
  21151. + /* tsk == current, ensure it is safe to use ->signal/sighand */
  21152. + if (unlikely(tsk->exit_state))
  21153. + return 0;
  21154. +
  21155. + if (!task_cputime_zero(&tsk->cputime_expires))
  21156. + return 1;
  21157. +
  21158. + if (!task_cputime_zero(&tsk->signal->cputime_expires))
  21159. + return 1;
  21160. +
  21161. + return 0;
  21162. +}
  21163. +
  21164. +void run_posix_cpu_timers(struct task_struct *tsk)
  21165. +{
  21166. + unsigned long cpu = smp_processor_id();
  21167. + struct task_struct *tasklist;
  21168. +
  21169. + BUG_ON(!irqs_disabled());
  21170. + if(!per_cpu(posix_timer_task, cpu))
  21171. + return;
  21172. + /* get per-cpu references */
  21173. + tasklist = per_cpu(posix_timer_tasklist, cpu);
  21174. +
  21175. + /* check to see if we're already queued */
  21176. + if (!tsk->posix_timer_list && __fastpath_timer_check(tsk)) {
  21177. + get_task_struct(tsk);
  21178. + if (tasklist) {
  21179. + tsk->posix_timer_list = tasklist;
  21180. + } else {
  21181. + /*
  21182. + * The list is terminated by a self-pointing
  21183. + * task_struct
  21184. + */
  21185. + tsk->posix_timer_list = tsk;
  21186. + }
  21187. + per_cpu(posix_timer_tasklist, cpu) = tsk;
  21188. +
  21189. + wake_up_process(per_cpu(posix_timer_task, cpu));
  21190. + }
  21191. +}
  21192. +
  21193. +/*
  21194. + * posix_cpu_thread_call - callback that gets triggered when a CPU is added.
  21195. + * Here we can start up the necessary migration thread for the new CPU.
  21196. + */
  21197. +static int posix_cpu_thread_call(struct notifier_block *nfb,
  21198. + unsigned long action, void *hcpu)
  21199. +{
  21200. + int cpu = (long)hcpu;
  21201. + struct task_struct *p;
  21202. + struct sched_param param;
  21203. +
  21204. + switch (action) {
  21205. + case CPU_UP_PREPARE:
  21206. + p = kthread_create(posix_cpu_timers_thread, hcpu,
  21207. + "posixcputmr/%d",cpu);
  21208. + if (IS_ERR(p))
  21209. + return NOTIFY_BAD;
  21210. + p->flags |= PF_NOFREEZE;
  21211. + kthread_bind(p, cpu);
  21212. + /* Must be high prio to avoid getting starved */
  21213. + param.sched_priority = MAX_RT_PRIO-1;
  21214. + sched_setscheduler(p, SCHED_FIFO, &param);
  21215. + per_cpu(posix_timer_task,cpu) = p;
  21216. + break;
  21217. + case CPU_ONLINE:
  21218. + /* Strictly unneccessary, as first user will wake it. */
  21219. + wake_up_process(per_cpu(posix_timer_task,cpu));
  21220. + break;
  21221. +#ifdef CONFIG_HOTPLUG_CPU
  21222. + case CPU_UP_CANCELED:
  21223. + /* Unbind it from offline cpu so it can run. Fall thru. */
  21224. + kthread_bind(per_cpu(posix_timer_task, cpu),
  21225. + cpumask_any(cpu_online_mask));
  21226. + kthread_stop(per_cpu(posix_timer_task,cpu));
  21227. + per_cpu(posix_timer_task,cpu) = NULL;
  21228. + break;
  21229. + case CPU_DEAD:
  21230. + kthread_stop(per_cpu(posix_timer_task,cpu));
  21231. + per_cpu(posix_timer_task,cpu) = NULL;
  21232. + break;
  21233. +#endif
  21234. + }
  21235. + return NOTIFY_OK;
  21236. +}
  21237. +
  21238. +/* Register at highest priority so that task migration (migrate_all_tasks)
  21239. + * happens before everything else.
  21240. + */
  21241. +static struct notifier_block posix_cpu_thread_notifier = {
  21242. + .notifier_call = posix_cpu_thread_call,
  21243. + .priority = 10
  21244. +};
  21245. +
  21246. +static int __init posix_cpu_thread_init(void)
  21247. +{
  21248. + void *hcpu = (void *)(long)smp_processor_id();
  21249. + /* Start one for boot CPU. */
  21250. + unsigned long cpu;
  21251. +
  21252. + /* init the per-cpu posix_timer_tasklets */
  21253. + for_each_possible_cpu(cpu)
  21254. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  21255. +
  21256. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_UP_PREPARE, hcpu);
  21257. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_ONLINE, hcpu);
  21258. + register_cpu_notifier(&posix_cpu_thread_notifier);
  21259. + return 0;
  21260. +}
  21261. +early_initcall(posix_cpu_thread_init);
  21262. +#else /* CONFIG_PREEMPT_RT_BASE */
  21263. +void run_posix_cpu_timers(struct task_struct *tsk)
  21264. +{
  21265. + __run_posix_cpu_timers(tsk);
  21266. +}
  21267. +#endif /* CONFIG_PREEMPT_RT_BASE */
  21268. +
  21269. /*
  21270. * Set one of the process-wide special case CPU timers or RLIMIT_CPU.
  21271. * The tsk->sighand->siglock must be held by the caller.
  21272. diff -Nur linux-4.1.26.orig/kernel/time/posix-timers.c linux-4.1.26/kernel/time/posix-timers.c
  21273. --- linux-4.1.26.orig/kernel/time/posix-timers.c 2016-06-07 01:13:11.000000000 +0200
  21274. +++ linux-4.1.26/kernel/time/posix-timers.c 2016-06-19 15:30:58.711298275 +0200
  21275. @@ -499,6 +499,7 @@
  21276. static struct pid *good_sigevent(sigevent_t * event)
  21277. {
  21278. struct task_struct *rtn = current->group_leader;
  21279. + int sig = event->sigev_signo;
  21280. if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
  21281. (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
  21282. @@ -507,7 +508,8 @@
  21283. return NULL;
  21284. if (((event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) &&
  21285. - ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
  21286. + (sig <= 0 || sig > SIGRTMAX || sig_kernel_only(sig) ||
  21287. + sig_kernel_coredump(sig)))
  21288. return NULL;
  21289. return task_pid(rtn);
  21290. @@ -819,6 +821,20 @@
  21291. return overrun;
  21292. }
  21293. +/*
  21294. + * Protected by RCU!
  21295. + */
  21296. +static void timer_wait_for_callback(struct k_clock *kc, struct k_itimer *timr)
  21297. +{
  21298. +#ifdef CONFIG_PREEMPT_RT_FULL
  21299. + if (kc->timer_set == common_timer_set)
  21300. + hrtimer_wait_for_timer(&timr->it.real.timer);
  21301. + else
  21302. + /* FIXME: Whacky hack for posix-cpu-timers */
  21303. + schedule_timeout(1);
  21304. +#endif
  21305. +}
  21306. +
  21307. /* Set a POSIX.1b interval timer. */
  21308. /* timr->it_lock is taken. */
  21309. static int
  21310. @@ -896,6 +912,7 @@
  21311. if (!timr)
  21312. return -EINVAL;
  21313. + rcu_read_lock();
  21314. kc = clockid_to_kclock(timr->it_clock);
  21315. if (WARN_ON_ONCE(!kc || !kc->timer_set))
  21316. error = -EINVAL;
  21317. @@ -904,9 +921,12 @@
  21318. unlock_timer(timr, flag);
  21319. if (error == TIMER_RETRY) {
  21320. + timer_wait_for_callback(kc, timr);
  21321. rtn = NULL; // We already got the old time...
  21322. + rcu_read_unlock();
  21323. goto retry;
  21324. }
  21325. + rcu_read_unlock();
  21326. if (old_setting && !error &&
  21327. copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
  21328. @@ -944,10 +964,15 @@
  21329. if (!timer)
  21330. return -EINVAL;
  21331. + rcu_read_lock();
  21332. if (timer_delete_hook(timer) == TIMER_RETRY) {
  21333. unlock_timer(timer, flags);
  21334. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  21335. + timer);
  21336. + rcu_read_unlock();
  21337. goto retry_delete;
  21338. }
  21339. + rcu_read_unlock();
  21340. spin_lock(&current->sighand->siglock);
  21341. list_del(&timer->list);
  21342. @@ -973,8 +998,18 @@
  21343. retry_delete:
  21344. spin_lock_irqsave(&timer->it_lock, flags);
  21345. + /* On RT we can race with a deletion */
  21346. + if (!timer->it_signal) {
  21347. + unlock_timer(timer, flags);
  21348. + return;
  21349. + }
  21350. +
  21351. if (timer_delete_hook(timer) == TIMER_RETRY) {
  21352. + rcu_read_lock();
  21353. unlock_timer(timer, flags);
  21354. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  21355. + timer);
  21356. + rcu_read_unlock();
  21357. goto retry_delete;
  21358. }
  21359. list_del(&timer->list);
  21360. diff -Nur linux-4.1.26.orig/kernel/time/tick-broadcast-hrtimer.c linux-4.1.26/kernel/time/tick-broadcast-hrtimer.c
  21361. --- linux-4.1.26.orig/kernel/time/tick-broadcast-hrtimer.c 2016-06-07 01:13:11.000000000 +0200
  21362. +++ linux-4.1.26/kernel/time/tick-broadcast-hrtimer.c 2016-06-19 15:30:58.711298275 +0200
  21363. @@ -109,5 +109,6 @@
  21364. {
  21365. hrtimer_init(&bctimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  21366. bctimer.function = bc_handler;
  21367. + bctimer.irqsafe = true;
  21368. clockevents_register_device(&ce_broadcast_hrtimer);
  21369. }
  21370. diff -Nur linux-4.1.26.orig/kernel/time/tick-common.c linux-4.1.26/kernel/time/tick-common.c
  21371. --- linux-4.1.26.orig/kernel/time/tick-common.c 2016-06-07 01:13:11.000000000 +0200
  21372. +++ linux-4.1.26/kernel/time/tick-common.c 2016-06-19 15:30:58.711298275 +0200
  21373. @@ -78,13 +78,15 @@
  21374. static void tick_periodic(int cpu)
  21375. {
  21376. if (tick_do_timer_cpu == cpu) {
  21377. - write_seqlock(&jiffies_lock);
  21378. + raw_spin_lock(&jiffies_lock);
  21379. + write_seqcount_begin(&jiffies_seq);
  21380. /* Keep track of the next tick event */
  21381. tick_next_period = ktime_add(tick_next_period, tick_period);
  21382. do_timer(1);
  21383. - write_sequnlock(&jiffies_lock);
  21384. + write_seqcount_end(&jiffies_seq);
  21385. + raw_spin_unlock(&jiffies_lock);
  21386. update_wall_time();
  21387. }
  21388. @@ -146,9 +148,9 @@
  21389. ktime_t next;
  21390. do {
  21391. - seq = read_seqbegin(&jiffies_lock);
  21392. + seq = read_seqcount_begin(&jiffies_seq);
  21393. next = tick_next_period;
  21394. - } while (read_seqretry(&jiffies_lock, seq));
  21395. + } while (read_seqcount_retry(&jiffies_seq, seq));
  21396. clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT);
  21397. diff -Nur linux-4.1.26.orig/kernel/time/tick-sched.c linux-4.1.26/kernel/time/tick-sched.c
  21398. --- linux-4.1.26.orig/kernel/time/tick-sched.c 2016-06-07 01:13:11.000000000 +0200
  21399. +++ linux-4.1.26/kernel/time/tick-sched.c 2016-06-19 15:30:58.711298275 +0200
  21400. @@ -62,7 +62,8 @@
  21401. return;
  21402. /* Reevalute with jiffies_lock held */
  21403. - write_seqlock(&jiffies_lock);
  21404. + raw_spin_lock(&jiffies_lock);
  21405. + write_seqcount_begin(&jiffies_seq);
  21406. delta = ktime_sub(now, last_jiffies_update);
  21407. if (delta.tv64 >= tick_period.tv64) {
  21408. @@ -85,10 +86,12 @@
  21409. /* Keep the tick_next_period variable up to date */
  21410. tick_next_period = ktime_add(last_jiffies_update, tick_period);
  21411. } else {
  21412. - write_sequnlock(&jiffies_lock);
  21413. + write_seqcount_end(&jiffies_seq);
  21414. + raw_spin_unlock(&jiffies_lock);
  21415. return;
  21416. }
  21417. - write_sequnlock(&jiffies_lock);
  21418. + write_seqcount_end(&jiffies_seq);
  21419. + raw_spin_unlock(&jiffies_lock);
  21420. update_wall_time();
  21421. }
  21422. @@ -99,12 +102,14 @@
  21423. {
  21424. ktime_t period;
  21425. - write_seqlock(&jiffies_lock);
  21426. + raw_spin_lock(&jiffies_lock);
  21427. + write_seqcount_begin(&jiffies_seq);
  21428. /* Did we start the jiffies update yet ? */
  21429. if (last_jiffies_update.tv64 == 0)
  21430. last_jiffies_update = tick_next_period;
  21431. period = last_jiffies_update;
  21432. - write_sequnlock(&jiffies_lock);
  21433. + write_seqcount_end(&jiffies_seq);
  21434. + raw_spin_unlock(&jiffies_lock);
  21435. return period;
  21436. }
  21437. @@ -176,6 +181,11 @@
  21438. return false;
  21439. }
  21440. + if (!arch_irq_work_has_interrupt()) {
  21441. + trace_tick_stop(0, "missing irq work interrupt\n");
  21442. + return false;
  21443. + }
  21444. +
  21445. /* sched_clock_tick() needs us? */
  21446. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  21447. /*
  21448. @@ -222,6 +232,7 @@
  21449. static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = {
  21450. .func = nohz_full_kick_work_func,
  21451. + .flags = IRQ_WORK_HARD_IRQ,
  21452. };
  21453. /*
  21454. @@ -578,10 +589,10 @@
  21455. /* Read jiffies and the time when jiffies were updated last */
  21456. do {
  21457. - seq = read_seqbegin(&jiffies_lock);
  21458. + seq = read_seqcount_begin(&jiffies_seq);
  21459. last_update = last_jiffies_update;
  21460. last_jiffies = jiffies;
  21461. - } while (read_seqretry(&jiffies_lock, seq));
  21462. + } while (read_seqcount_retry(&jiffies_seq, seq));
  21463. if (rcu_needs_cpu(&rcu_delta_jiffies) ||
  21464. arch_needs_cpu() || irq_work_needs_cpu()) {
  21465. @@ -759,14 +770,7 @@
  21466. return false;
  21467. if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
  21468. - static int ratelimit;
  21469. -
  21470. - if (ratelimit < 10 &&
  21471. - (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  21472. - pr_warn("NOHZ: local_softirq_pending %02x\n",
  21473. - (unsigned int) local_softirq_pending());
  21474. - ratelimit++;
  21475. - }
  21476. + softirq_check_pending_idle();
  21477. return false;
  21478. }
  21479. @@ -1154,6 +1158,7 @@
  21480. * Emulate tick processing via per-CPU hrtimers:
  21481. */
  21482. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  21483. + ts->sched_timer.irqsafe = 1;
  21484. ts->sched_timer.function = tick_sched_timer;
  21485. /* Get the next period (per cpu) */
  21486. diff -Nur linux-4.1.26.orig/kernel/time/timekeeping.c linux-4.1.26/kernel/time/timekeeping.c
  21487. --- linux-4.1.26.orig/kernel/time/timekeeping.c 2016-06-07 01:13:11.000000000 +0200
  21488. +++ linux-4.1.26/kernel/time/timekeeping.c 2016-06-19 15:30:58.711298275 +0200
  21489. @@ -2064,8 +2064,10 @@
  21490. */
  21491. void xtime_update(unsigned long ticks)
  21492. {
  21493. - write_seqlock(&jiffies_lock);
  21494. + raw_spin_lock(&jiffies_lock);
  21495. + write_seqcount_begin(&jiffies_seq);
  21496. do_timer(ticks);
  21497. - write_sequnlock(&jiffies_lock);
  21498. + write_seqcount_end(&jiffies_seq);
  21499. + raw_spin_unlock(&jiffies_lock);
  21500. update_wall_time();
  21501. }
  21502. diff -Nur linux-4.1.26.orig/kernel/time/timekeeping.h linux-4.1.26/kernel/time/timekeeping.h
  21503. --- linux-4.1.26.orig/kernel/time/timekeeping.h 2016-06-07 01:13:11.000000000 +0200
  21504. +++ linux-4.1.26/kernel/time/timekeeping.h 2016-06-19 15:30:58.711298275 +0200
  21505. @@ -22,7 +22,8 @@
  21506. extern void do_timer(unsigned long ticks);
  21507. extern void update_wall_time(void);
  21508. -extern seqlock_t jiffies_lock;
  21509. +extern raw_spinlock_t jiffies_lock;
  21510. +extern seqcount_t jiffies_seq;
  21511. #define CS_NAME_LEN 32
  21512. diff -Nur linux-4.1.26.orig/kernel/time/timer.c linux-4.1.26/kernel/time/timer.c
  21513. --- linux-4.1.26.orig/kernel/time/timer.c 2016-06-07 01:13:11.000000000 +0200
  21514. +++ linux-4.1.26/kernel/time/timer.c 2016-06-19 15:30:58.711298275 +0200
  21515. @@ -78,6 +78,9 @@
  21516. struct tvec_base {
  21517. spinlock_t lock;
  21518. struct timer_list *running_timer;
  21519. +#ifdef CONFIG_PREEMPT_RT_FULL
  21520. + wait_queue_head_t wait_for_running_timer;
  21521. +#endif
  21522. unsigned long timer_jiffies;
  21523. unsigned long next_timer;
  21524. unsigned long active_timers;
  21525. @@ -768,6 +771,36 @@
  21526. }
  21527. }
  21528. +#ifndef CONFIG_PREEMPT_RT_FULL
  21529. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  21530. + struct tvec_base *old,
  21531. + struct tvec_base *new)
  21532. +{
  21533. + /* See the comment in lock_timer_base() */
  21534. + timer_set_base(timer, NULL);
  21535. + spin_unlock(&old->lock);
  21536. + spin_lock(&new->lock);
  21537. + timer_set_base(timer, new);
  21538. + return new;
  21539. +}
  21540. +#else
  21541. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  21542. + struct tvec_base *old,
  21543. + struct tvec_base *new)
  21544. +{
  21545. + /*
  21546. + * We cannot do the above because we might be preempted and
  21547. + * then the preempter would see NULL and loop forever.
  21548. + */
  21549. + if (spin_trylock(&new->lock)) {
  21550. + timer_set_base(timer, new);
  21551. + spin_unlock(&old->lock);
  21552. + return new;
  21553. + }
  21554. + return old;
  21555. +}
  21556. +#endif
  21557. +
  21558. static inline int
  21559. __mod_timer(struct timer_list *timer, unsigned long expires,
  21560. bool pending_only, int pinned)
  21561. @@ -798,14 +831,8 @@
  21562. * handler yet has not finished. This also guarantees that
  21563. * the timer is serialized wrt itself.
  21564. */
  21565. - if (likely(base->running_timer != timer)) {
  21566. - /* See the comment in lock_timer_base() */
  21567. - timer_set_base(timer, NULL);
  21568. - spin_unlock(&base->lock);
  21569. - base = new_base;
  21570. - spin_lock(&base->lock);
  21571. - timer_set_base(timer, base);
  21572. - }
  21573. + if (likely(base->running_timer != timer))
  21574. + base = switch_timer_base(timer, base, new_base);
  21575. }
  21576. timer->expires = expires;
  21577. @@ -979,6 +1006,29 @@
  21578. }
  21579. EXPORT_SYMBOL_GPL(add_timer_on);
  21580. +#ifdef CONFIG_PREEMPT_RT_FULL
  21581. +/*
  21582. + * Wait for a running timer
  21583. + */
  21584. +static void wait_for_running_timer(struct timer_list *timer)
  21585. +{
  21586. + struct tvec_base *base = timer->base;
  21587. +
  21588. + if (base->running_timer == timer)
  21589. + wait_event(base->wait_for_running_timer,
  21590. + base->running_timer != timer);
  21591. +}
  21592. +
  21593. +# define wakeup_timer_waiters(b) wake_up(&(b)->wait_for_running_timer)
  21594. +#else
  21595. +static inline void wait_for_running_timer(struct timer_list *timer)
  21596. +{
  21597. + cpu_relax();
  21598. +}
  21599. +
  21600. +# define wakeup_timer_waiters(b) do { } while (0)
  21601. +#endif
  21602. +
  21603. /**
  21604. * del_timer - deactive a timer.
  21605. * @timer: the timer to be deactivated
  21606. @@ -1036,7 +1086,7 @@
  21607. }
  21608. EXPORT_SYMBOL(try_to_del_timer_sync);
  21609. -#ifdef CONFIG_SMP
  21610. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  21611. static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
  21612. /**
  21613. @@ -1098,7 +1148,7 @@
  21614. int ret = try_to_del_timer_sync(timer);
  21615. if (ret >= 0)
  21616. return ret;
  21617. - cpu_relax();
  21618. + wait_for_running_timer(timer);
  21619. }
  21620. }
  21621. EXPORT_SYMBOL(del_timer_sync);
  21622. @@ -1219,15 +1269,17 @@
  21623. if (irqsafe) {
  21624. spin_unlock(&base->lock);
  21625. call_timer_fn(timer, fn, data);
  21626. + base->running_timer = NULL;
  21627. spin_lock(&base->lock);
  21628. } else {
  21629. spin_unlock_irq(&base->lock);
  21630. call_timer_fn(timer, fn, data);
  21631. + base->running_timer = NULL;
  21632. spin_lock_irq(&base->lock);
  21633. }
  21634. }
  21635. }
  21636. - base->running_timer = NULL;
  21637. + wakeup_timer_waiters(base);
  21638. spin_unlock_irq(&base->lock);
  21639. }
  21640. @@ -1367,6 +1419,14 @@
  21641. if (cpu_is_offline(smp_processor_id()))
  21642. return expires;
  21643. +#ifdef CONFIG_PREEMPT_RT_FULL
  21644. + /*
  21645. + * On PREEMPT_RT we cannot sleep here. As a result we can't take
  21646. + * the base lock to check when the next timer is pending and so
  21647. + * we assume the next jiffy.
  21648. + */
  21649. + return now + 1;
  21650. +#endif
  21651. spin_lock(&base->lock);
  21652. if (base->active_timers) {
  21653. if (time_before_eq(base->next_timer, base->timer_jiffies))
  21654. @@ -1392,13 +1452,13 @@
  21655. /* Note: this timer irq context must be accounted for as well. */
  21656. account_process_tick(p, user_tick);
  21657. + scheduler_tick();
  21658. run_local_timers();
  21659. rcu_check_callbacks(user_tick);
  21660. -#ifdef CONFIG_IRQ_WORK
  21661. +#if defined(CONFIG_IRQ_WORK)
  21662. if (in_irq())
  21663. irq_work_tick();
  21664. #endif
  21665. - scheduler_tick();
  21666. run_posix_cpu_timers(p);
  21667. }
  21668. @@ -1411,6 +1471,8 @@
  21669. hrtimer_run_pending();
  21670. + irq_work_tick_soft();
  21671. +
  21672. if (time_after_eq(jiffies, base->timer_jiffies))
  21673. __run_timers(base);
  21674. }
  21675. @@ -1566,7 +1628,7 @@
  21676. BUG_ON(cpu_online(cpu));
  21677. old_base = per_cpu(tvec_bases, cpu);
  21678. - new_base = get_cpu_var(tvec_bases);
  21679. + new_base = get_local_var(tvec_bases);
  21680. /*
  21681. * The caller is globally serialized and nobody else
  21682. * takes two locks at once, deadlock is not possible.
  21683. @@ -1590,7 +1652,7 @@
  21684. spin_unlock(&old_base->lock);
  21685. spin_unlock_irq(&new_base->lock);
  21686. - put_cpu_var(tvec_bases);
  21687. + put_local_var(tvec_bases);
  21688. }
  21689. static int timer_cpu_notify(struct notifier_block *self,
  21690. @@ -1625,6 +1687,9 @@
  21691. base->cpu = cpu;
  21692. per_cpu(tvec_bases, cpu) = base;
  21693. spin_lock_init(&base->lock);
  21694. +#ifdef CONFIG_PREEMPT_RT_FULL
  21695. + init_waitqueue_head(&base->wait_for_running_timer);
  21696. +#endif
  21697. for (j = 0; j < TVN_SIZE; j++) {
  21698. INIT_LIST_HEAD(base->tv5.vec + j);
  21699. diff -Nur linux-4.1.26.orig/kernel/trace/Kconfig linux-4.1.26/kernel/trace/Kconfig
  21700. --- linux-4.1.26.orig/kernel/trace/Kconfig 2016-06-07 01:13:11.000000000 +0200
  21701. +++ linux-4.1.26/kernel/trace/Kconfig 2016-06-19 15:30:58.711298275 +0200
  21702. @@ -187,6 +187,24 @@
  21703. enabled. This option and the preempt-off timing option can be
  21704. used together or separately.)
  21705. +config INTERRUPT_OFF_HIST
  21706. + bool "Interrupts-off Latency Histogram"
  21707. + depends on IRQSOFF_TRACER
  21708. + help
  21709. + This option generates continuously updated histograms (one per cpu)
  21710. + of the duration of time periods with interrupts disabled. The
  21711. + histograms are disabled by default. To enable them, write a non-zero
  21712. + number to
  21713. +
  21714. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  21715. +
  21716. + If PREEMPT_OFF_HIST is also selected, additional histograms (one
  21717. + per cpu) are generated that accumulate the duration of time periods
  21718. + when both interrupts and preemption are disabled. The histogram data
  21719. + will be located in the debug file system at
  21720. +
  21721. + /sys/kernel/debug/tracing/latency_hist/irqsoff
  21722. +
  21723. config PREEMPT_TRACER
  21724. bool "Preemption-off Latency Tracer"
  21725. default n
  21726. @@ -211,6 +229,24 @@
  21727. enabled. This option and the irqs-off timing option can be
  21728. used together or separately.)
  21729. +config PREEMPT_OFF_HIST
  21730. + bool "Preemption-off Latency Histogram"
  21731. + depends on PREEMPT_TRACER
  21732. + help
  21733. + This option generates continuously updated histograms (one per cpu)
  21734. + of the duration of time periods with preemption disabled. The
  21735. + histograms are disabled by default. To enable them, write a non-zero
  21736. + number to
  21737. +
  21738. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  21739. +
  21740. + If INTERRUPT_OFF_HIST is also selected, additional histograms (one
  21741. + per cpu) are generated that accumulate the duration of time periods
  21742. + when both interrupts and preemption are disabled. The histogram data
  21743. + will be located in the debug file system at
  21744. +
  21745. + /sys/kernel/debug/tracing/latency_hist/preemptoff
  21746. +
  21747. config SCHED_TRACER
  21748. bool "Scheduling Latency Tracer"
  21749. select GENERIC_TRACER
  21750. @@ -221,6 +257,74 @@
  21751. This tracer tracks the latency of the highest priority task
  21752. to be scheduled in, starting from the point it has woken up.
  21753. +config WAKEUP_LATENCY_HIST
  21754. + bool "Scheduling Latency Histogram"
  21755. + depends on SCHED_TRACER
  21756. + help
  21757. + This option generates continuously updated histograms (one per cpu)
  21758. + of the scheduling latency of the highest priority task.
  21759. + The histograms are disabled by default. To enable them, write a
  21760. + non-zero number to
  21761. +
  21762. + /sys/kernel/debug/tracing/latency_hist/enable/wakeup
  21763. +
  21764. + Two different algorithms are used, one to determine the latency of
  21765. + processes that exclusively use the highest priority of the system and
  21766. + another one to determine the latency of processes that share the
  21767. + highest system priority with other processes. The former is used to
  21768. + improve hardware and system software, the latter to optimize the
  21769. + priority design of a given system. The histogram data will be
  21770. + located in the debug file system at
  21771. +
  21772. + /sys/kernel/debug/tracing/latency_hist/wakeup
  21773. +
  21774. + and
  21775. +
  21776. + /sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio
  21777. +
  21778. + If both Scheduling Latency Histogram and Missed Timer Offsets
  21779. + Histogram are selected, additional histogram data will be collected
  21780. + that contain, in addition to the wakeup latency, the timer latency, in
  21781. + case the wakeup was triggered by an expired timer. These histograms
  21782. + are available in the
  21783. +
  21784. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  21785. +
  21786. + directory. They reflect the apparent interrupt and scheduling latency
  21787. + and are best suitable to determine the worst-case latency of a given
  21788. + system. To enable these histograms, write a non-zero number to
  21789. +
  21790. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  21791. +
  21792. +config MISSED_TIMER_OFFSETS_HIST
  21793. + depends on HIGH_RES_TIMERS
  21794. + select GENERIC_TRACER
  21795. + bool "Missed Timer Offsets Histogram"
  21796. + help
  21797. + Generate a histogram of missed timer offsets in microseconds. The
  21798. + histograms are disabled by default. To enable them, write a non-zero
  21799. + number to
  21800. +
  21801. + /sys/kernel/debug/tracing/latency_hist/enable/missed_timer_offsets
  21802. +
  21803. + The histogram data will be located in the debug file system at
  21804. +
  21805. + /sys/kernel/debug/tracing/latency_hist/missed_timer_offsets
  21806. +
  21807. + If both Scheduling Latency Histogram and Missed Timer Offsets
  21808. + Histogram are selected, additional histogram data will be collected
  21809. + that contain, in addition to the wakeup latency, the timer latency, in
  21810. + case the wakeup was triggered by an expired timer. These histograms
  21811. + are available in the
  21812. +
  21813. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  21814. +
  21815. + directory. They reflect the apparent interrupt and scheduling latency
  21816. + and are best suitable to determine the worst-case latency of a given
  21817. + system. To enable these histograms, write a non-zero number to
  21818. +
  21819. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  21820. +
  21821. config ENABLE_DEFAULT_TRACERS
  21822. bool "Trace process context switches and events"
  21823. depends on !GENERIC_TRACER
  21824. diff -Nur linux-4.1.26.orig/kernel/trace/latency_hist.c linux-4.1.26/kernel/trace/latency_hist.c
  21825. --- linux-4.1.26.orig/kernel/trace/latency_hist.c 1970-01-01 01:00:00.000000000 +0100
  21826. +++ linux-4.1.26/kernel/trace/latency_hist.c 2016-06-19 15:30:58.715298429 +0200
  21827. @@ -0,0 +1,1178 @@
  21828. +/*
  21829. + * kernel/trace/latency_hist.c
  21830. + *
  21831. + * Add support for histograms of preemption-off latency and
  21832. + * interrupt-off latency and wakeup latency, it depends on
  21833. + * Real-Time Preemption Support.
  21834. + *
  21835. + * Copyright (C) 2005 MontaVista Software, Inc.
  21836. + * Yi Yang <yyang@ch.mvista.com>
  21837. + *
  21838. + * Converted to work with the new latency tracer.
  21839. + * Copyright (C) 2008 Red Hat, Inc.
  21840. + * Steven Rostedt <srostedt@redhat.com>
  21841. + *
  21842. + */
  21843. +#include <linux/module.h>
  21844. +#include <linux/debugfs.h>
  21845. +#include <linux/seq_file.h>
  21846. +#include <linux/percpu.h>
  21847. +#include <linux/kallsyms.h>
  21848. +#include <linux/uaccess.h>
  21849. +#include <linux/sched.h>
  21850. +#include <linux/sched/rt.h>
  21851. +#include <linux/slab.h>
  21852. +#include <linux/atomic.h>
  21853. +#include <asm/div64.h>
  21854. +
  21855. +#include "trace.h"
  21856. +#include <trace/events/sched.h>
  21857. +
  21858. +#define NSECS_PER_USECS 1000L
  21859. +
  21860. +#define CREATE_TRACE_POINTS
  21861. +#include <trace/events/hist.h>
  21862. +
  21863. +enum {
  21864. + IRQSOFF_LATENCY = 0,
  21865. + PREEMPTOFF_LATENCY,
  21866. + PREEMPTIRQSOFF_LATENCY,
  21867. + WAKEUP_LATENCY,
  21868. + WAKEUP_LATENCY_SHAREDPRIO,
  21869. + MISSED_TIMER_OFFSETS,
  21870. + TIMERANDWAKEUP_LATENCY,
  21871. + MAX_LATENCY_TYPE,
  21872. +};
  21873. +
  21874. +#define MAX_ENTRY_NUM 10240
  21875. +
  21876. +struct hist_data {
  21877. + atomic_t hist_mode; /* 0 log, 1 don't log */
  21878. + long offset; /* set it to MAX_ENTRY_NUM/2 for a bipolar scale */
  21879. + long min_lat;
  21880. + long max_lat;
  21881. + unsigned long long below_hist_bound_samples;
  21882. + unsigned long long above_hist_bound_samples;
  21883. + long long accumulate_lat;
  21884. + unsigned long long total_samples;
  21885. + unsigned long long hist_array[MAX_ENTRY_NUM];
  21886. +};
  21887. +
  21888. +struct enable_data {
  21889. + int latency_type;
  21890. + int enabled;
  21891. +};
  21892. +
  21893. +static char *latency_hist_dir_root = "latency_hist";
  21894. +
  21895. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  21896. +static DEFINE_PER_CPU(struct hist_data, irqsoff_hist);
  21897. +static char *irqsoff_hist_dir = "irqsoff";
  21898. +static DEFINE_PER_CPU(cycles_t, hist_irqsoff_start);
  21899. +static DEFINE_PER_CPU(int, hist_irqsoff_counting);
  21900. +#endif
  21901. +
  21902. +#ifdef CONFIG_PREEMPT_OFF_HIST
  21903. +static DEFINE_PER_CPU(struct hist_data, preemptoff_hist);
  21904. +static char *preemptoff_hist_dir = "preemptoff";
  21905. +static DEFINE_PER_CPU(cycles_t, hist_preemptoff_start);
  21906. +static DEFINE_PER_CPU(int, hist_preemptoff_counting);
  21907. +#endif
  21908. +
  21909. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  21910. +static DEFINE_PER_CPU(struct hist_data, preemptirqsoff_hist);
  21911. +static char *preemptirqsoff_hist_dir = "preemptirqsoff";
  21912. +static DEFINE_PER_CPU(cycles_t, hist_preemptirqsoff_start);
  21913. +static DEFINE_PER_CPU(int, hist_preemptirqsoff_counting);
  21914. +#endif
  21915. +
  21916. +#if defined(CONFIG_PREEMPT_OFF_HIST) || defined(CONFIG_INTERRUPT_OFF_HIST)
  21917. +static notrace void probe_preemptirqsoff_hist(void *v, int reason, int start);
  21918. +static struct enable_data preemptirqsoff_enabled_data = {
  21919. + .latency_type = PREEMPTIRQSOFF_LATENCY,
  21920. + .enabled = 0,
  21921. +};
  21922. +#endif
  21923. +
  21924. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  21925. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21926. +struct maxlatproc_data {
  21927. + char comm[FIELD_SIZEOF(struct task_struct, comm)];
  21928. + char current_comm[FIELD_SIZEOF(struct task_struct, comm)];
  21929. + int pid;
  21930. + int current_pid;
  21931. + int prio;
  21932. + int current_prio;
  21933. + long latency;
  21934. + long timeroffset;
  21935. + cycle_t timestamp;
  21936. +};
  21937. +#endif
  21938. +
  21939. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21940. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist);
  21941. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist_sharedprio);
  21942. +static char *wakeup_latency_hist_dir = "wakeup";
  21943. +static char *wakeup_latency_hist_dir_sharedprio = "sharedprio";
  21944. +static notrace void probe_wakeup_latency_hist_start(void *v,
  21945. + struct task_struct *p);
  21946. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  21947. + struct task_struct *prev, struct task_struct *next);
  21948. +static notrace void probe_sched_migrate_task(void *,
  21949. + struct task_struct *task, int cpu);
  21950. +static struct enable_data wakeup_latency_enabled_data = {
  21951. + .latency_type = WAKEUP_LATENCY,
  21952. + .enabled = 0,
  21953. +};
  21954. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc);
  21955. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc_sharedprio);
  21956. +static DEFINE_PER_CPU(struct task_struct *, wakeup_task);
  21957. +static DEFINE_PER_CPU(int, wakeup_sharedprio);
  21958. +static unsigned long wakeup_pid;
  21959. +#endif
  21960. +
  21961. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21962. +static DEFINE_PER_CPU(struct hist_data, missed_timer_offsets);
  21963. +static char *missed_timer_offsets_dir = "missed_timer_offsets";
  21964. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  21965. + long long offset, struct task_struct *curr, struct task_struct *task);
  21966. +static struct enable_data missed_timer_offsets_enabled_data = {
  21967. + .latency_type = MISSED_TIMER_OFFSETS,
  21968. + .enabled = 0,
  21969. +};
  21970. +static DEFINE_PER_CPU(struct maxlatproc_data, missed_timer_offsets_maxlatproc);
  21971. +static unsigned long missed_timer_offsets_pid;
  21972. +#endif
  21973. +
  21974. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  21975. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21976. +static DEFINE_PER_CPU(struct hist_data, timerandwakeup_latency_hist);
  21977. +static char *timerandwakeup_latency_hist_dir = "timerandwakeup";
  21978. +static struct enable_data timerandwakeup_enabled_data = {
  21979. + .latency_type = TIMERANDWAKEUP_LATENCY,
  21980. + .enabled = 0,
  21981. +};
  21982. +static DEFINE_PER_CPU(struct maxlatproc_data, timerandwakeup_maxlatproc);
  21983. +#endif
  21984. +
  21985. +void notrace latency_hist(int latency_type, int cpu, long latency,
  21986. + long timeroffset, cycle_t stop,
  21987. + struct task_struct *p)
  21988. +{
  21989. + struct hist_data *my_hist;
  21990. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  21991. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21992. + struct maxlatproc_data *mp = NULL;
  21993. +#endif
  21994. +
  21995. + if (!cpu_possible(cpu) || latency_type < 0 ||
  21996. + latency_type >= MAX_LATENCY_TYPE)
  21997. + return;
  21998. +
  21999. + switch (latency_type) {
  22000. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22001. + case IRQSOFF_LATENCY:
  22002. + my_hist = &per_cpu(irqsoff_hist, cpu);
  22003. + break;
  22004. +#endif
  22005. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22006. + case PREEMPTOFF_LATENCY:
  22007. + my_hist = &per_cpu(preemptoff_hist, cpu);
  22008. + break;
  22009. +#endif
  22010. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  22011. + case PREEMPTIRQSOFF_LATENCY:
  22012. + my_hist = &per_cpu(preemptirqsoff_hist, cpu);
  22013. + break;
  22014. +#endif
  22015. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22016. + case WAKEUP_LATENCY:
  22017. + my_hist = &per_cpu(wakeup_latency_hist, cpu);
  22018. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  22019. + break;
  22020. + case WAKEUP_LATENCY_SHAREDPRIO:
  22021. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  22022. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  22023. + break;
  22024. +#endif
  22025. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22026. + case MISSED_TIMER_OFFSETS:
  22027. + my_hist = &per_cpu(missed_timer_offsets, cpu);
  22028. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  22029. + break;
  22030. +#endif
  22031. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  22032. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22033. + case TIMERANDWAKEUP_LATENCY:
  22034. + my_hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  22035. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  22036. + break;
  22037. +#endif
  22038. +
  22039. + default:
  22040. + return;
  22041. + }
  22042. +
  22043. + latency += my_hist->offset;
  22044. +
  22045. + if (atomic_read(&my_hist->hist_mode) == 0)
  22046. + return;
  22047. +
  22048. + if (latency < 0 || latency >= MAX_ENTRY_NUM) {
  22049. + if (latency < 0)
  22050. + my_hist->below_hist_bound_samples++;
  22051. + else
  22052. + my_hist->above_hist_bound_samples++;
  22053. + } else
  22054. + my_hist->hist_array[latency]++;
  22055. +
  22056. + if (unlikely(latency > my_hist->max_lat ||
  22057. + my_hist->min_lat == LONG_MAX)) {
  22058. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22059. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22060. + if (latency_type == WAKEUP_LATENCY ||
  22061. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  22062. + latency_type == MISSED_TIMER_OFFSETS ||
  22063. + latency_type == TIMERANDWAKEUP_LATENCY) {
  22064. + strncpy(mp->comm, p->comm, sizeof(mp->comm));
  22065. + strncpy(mp->current_comm, current->comm,
  22066. + sizeof(mp->current_comm));
  22067. + mp->pid = task_pid_nr(p);
  22068. + mp->current_pid = task_pid_nr(current);
  22069. + mp->prio = p->prio;
  22070. + mp->current_prio = current->prio;
  22071. + mp->latency = latency;
  22072. + mp->timeroffset = timeroffset;
  22073. + mp->timestamp = stop;
  22074. + }
  22075. +#endif
  22076. + my_hist->max_lat = latency;
  22077. + }
  22078. + if (unlikely(latency < my_hist->min_lat))
  22079. + my_hist->min_lat = latency;
  22080. + my_hist->total_samples++;
  22081. + my_hist->accumulate_lat += latency;
  22082. +}
  22083. +
  22084. +static void *l_start(struct seq_file *m, loff_t *pos)
  22085. +{
  22086. + loff_t *index_ptr = NULL;
  22087. + loff_t index = *pos;
  22088. + struct hist_data *my_hist = m->private;
  22089. +
  22090. + if (index == 0) {
  22091. + char minstr[32], avgstr[32], maxstr[32];
  22092. +
  22093. + atomic_dec(&my_hist->hist_mode);
  22094. +
  22095. + if (likely(my_hist->total_samples)) {
  22096. + long avg = (long) div64_s64(my_hist->accumulate_lat,
  22097. + my_hist->total_samples);
  22098. + snprintf(minstr, sizeof(minstr), "%ld",
  22099. + my_hist->min_lat - my_hist->offset);
  22100. + snprintf(avgstr, sizeof(avgstr), "%ld",
  22101. + avg - my_hist->offset);
  22102. + snprintf(maxstr, sizeof(maxstr), "%ld",
  22103. + my_hist->max_lat - my_hist->offset);
  22104. + } else {
  22105. + strcpy(minstr, "<undef>");
  22106. + strcpy(avgstr, minstr);
  22107. + strcpy(maxstr, minstr);
  22108. + }
  22109. +
  22110. + seq_printf(m, "#Minimum latency: %s microseconds\n"
  22111. + "#Average latency: %s microseconds\n"
  22112. + "#Maximum latency: %s microseconds\n"
  22113. + "#Total samples: %llu\n"
  22114. + "#There are %llu samples lower than %ld"
  22115. + " microseconds.\n"
  22116. + "#There are %llu samples greater or equal"
  22117. + " than %ld microseconds.\n"
  22118. + "#usecs\t%16s\n",
  22119. + minstr, avgstr, maxstr,
  22120. + my_hist->total_samples,
  22121. + my_hist->below_hist_bound_samples,
  22122. + -my_hist->offset,
  22123. + my_hist->above_hist_bound_samples,
  22124. + MAX_ENTRY_NUM - my_hist->offset,
  22125. + "samples");
  22126. + }
  22127. + if (index < MAX_ENTRY_NUM) {
  22128. + index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL);
  22129. + if (index_ptr)
  22130. + *index_ptr = index;
  22131. + }
  22132. +
  22133. + return index_ptr;
  22134. +}
  22135. +
  22136. +static void *l_next(struct seq_file *m, void *p, loff_t *pos)
  22137. +{
  22138. + loff_t *index_ptr = p;
  22139. + struct hist_data *my_hist = m->private;
  22140. +
  22141. + if (++*pos >= MAX_ENTRY_NUM) {
  22142. + atomic_inc(&my_hist->hist_mode);
  22143. + return NULL;
  22144. + }
  22145. + *index_ptr = *pos;
  22146. + return index_ptr;
  22147. +}
  22148. +
  22149. +static void l_stop(struct seq_file *m, void *p)
  22150. +{
  22151. + kfree(p);
  22152. +}
  22153. +
  22154. +static int l_show(struct seq_file *m, void *p)
  22155. +{
  22156. + int index = *(loff_t *) p;
  22157. + struct hist_data *my_hist = m->private;
  22158. +
  22159. + seq_printf(m, "%6ld\t%16llu\n", index - my_hist->offset,
  22160. + my_hist->hist_array[index]);
  22161. + return 0;
  22162. +}
  22163. +
  22164. +static const struct seq_operations latency_hist_seq_op = {
  22165. + .start = l_start,
  22166. + .next = l_next,
  22167. + .stop = l_stop,
  22168. + .show = l_show
  22169. +};
  22170. +
  22171. +static int latency_hist_open(struct inode *inode, struct file *file)
  22172. +{
  22173. + int ret;
  22174. +
  22175. + ret = seq_open(file, &latency_hist_seq_op);
  22176. + if (!ret) {
  22177. + struct seq_file *seq = file->private_data;
  22178. + seq->private = inode->i_private;
  22179. + }
  22180. + return ret;
  22181. +}
  22182. +
  22183. +static const struct file_operations latency_hist_fops = {
  22184. + .open = latency_hist_open,
  22185. + .read = seq_read,
  22186. + .llseek = seq_lseek,
  22187. + .release = seq_release,
  22188. +};
  22189. +
  22190. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22191. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22192. +static void clear_maxlatprocdata(struct maxlatproc_data *mp)
  22193. +{
  22194. + mp->comm[0] = mp->current_comm[0] = '\0';
  22195. + mp->prio = mp->current_prio = mp->pid = mp->current_pid =
  22196. + mp->latency = mp->timeroffset = -1;
  22197. + mp->timestamp = 0;
  22198. +}
  22199. +#endif
  22200. +
  22201. +static void hist_reset(struct hist_data *hist)
  22202. +{
  22203. + atomic_dec(&hist->hist_mode);
  22204. +
  22205. + memset(hist->hist_array, 0, sizeof(hist->hist_array));
  22206. + hist->below_hist_bound_samples = 0ULL;
  22207. + hist->above_hist_bound_samples = 0ULL;
  22208. + hist->min_lat = LONG_MAX;
  22209. + hist->max_lat = LONG_MIN;
  22210. + hist->total_samples = 0ULL;
  22211. + hist->accumulate_lat = 0LL;
  22212. +
  22213. + atomic_inc(&hist->hist_mode);
  22214. +}
  22215. +
  22216. +static ssize_t
  22217. +latency_hist_reset(struct file *file, const char __user *a,
  22218. + size_t size, loff_t *off)
  22219. +{
  22220. + int cpu;
  22221. + struct hist_data *hist = NULL;
  22222. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22223. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22224. + struct maxlatproc_data *mp = NULL;
  22225. +#endif
  22226. + off_t latency_type = (off_t) file->private_data;
  22227. +
  22228. + for_each_online_cpu(cpu) {
  22229. +
  22230. + switch (latency_type) {
  22231. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22232. + case PREEMPTOFF_LATENCY:
  22233. + hist = &per_cpu(preemptoff_hist, cpu);
  22234. + break;
  22235. +#endif
  22236. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22237. + case IRQSOFF_LATENCY:
  22238. + hist = &per_cpu(irqsoff_hist, cpu);
  22239. + break;
  22240. +#endif
  22241. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  22242. + case PREEMPTIRQSOFF_LATENCY:
  22243. + hist = &per_cpu(preemptirqsoff_hist, cpu);
  22244. + break;
  22245. +#endif
  22246. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22247. + case WAKEUP_LATENCY:
  22248. + hist = &per_cpu(wakeup_latency_hist, cpu);
  22249. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  22250. + break;
  22251. + case WAKEUP_LATENCY_SHAREDPRIO:
  22252. + hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  22253. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  22254. + break;
  22255. +#endif
  22256. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22257. + case MISSED_TIMER_OFFSETS:
  22258. + hist = &per_cpu(missed_timer_offsets, cpu);
  22259. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  22260. + break;
  22261. +#endif
  22262. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  22263. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22264. + case TIMERANDWAKEUP_LATENCY:
  22265. + hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  22266. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  22267. + break;
  22268. +#endif
  22269. + }
  22270. +
  22271. + hist_reset(hist);
  22272. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22273. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22274. + if (latency_type == WAKEUP_LATENCY ||
  22275. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  22276. + latency_type == MISSED_TIMER_OFFSETS ||
  22277. + latency_type == TIMERANDWAKEUP_LATENCY)
  22278. + clear_maxlatprocdata(mp);
  22279. +#endif
  22280. + }
  22281. +
  22282. + return size;
  22283. +}
  22284. +
  22285. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22286. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22287. +static ssize_t
  22288. +show_pid(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  22289. +{
  22290. + char buf[64];
  22291. + int r;
  22292. + unsigned long *this_pid = file->private_data;
  22293. +
  22294. + r = snprintf(buf, sizeof(buf), "%lu\n", *this_pid);
  22295. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  22296. +}
  22297. +
  22298. +static ssize_t do_pid(struct file *file, const char __user *ubuf,
  22299. + size_t cnt, loff_t *ppos)
  22300. +{
  22301. + char buf[64];
  22302. + unsigned long pid;
  22303. + unsigned long *this_pid = file->private_data;
  22304. +
  22305. + if (cnt >= sizeof(buf))
  22306. + return -EINVAL;
  22307. +
  22308. + if (copy_from_user(&buf, ubuf, cnt))
  22309. + return -EFAULT;
  22310. +
  22311. + buf[cnt] = '\0';
  22312. +
  22313. + if (kstrtoul(buf, 10, &pid))
  22314. + return -EINVAL;
  22315. +
  22316. + *this_pid = pid;
  22317. +
  22318. + return cnt;
  22319. +}
  22320. +#endif
  22321. +
  22322. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22323. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22324. +static ssize_t
  22325. +show_maxlatproc(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  22326. +{
  22327. + int r;
  22328. + struct maxlatproc_data *mp = file->private_data;
  22329. + int strmaxlen = (TASK_COMM_LEN * 2) + (8 * 8);
  22330. + unsigned long long t;
  22331. + unsigned long usecs, secs;
  22332. + char *buf;
  22333. +
  22334. + if (mp->pid == -1 || mp->current_pid == -1) {
  22335. + buf = "(none)\n";
  22336. + return simple_read_from_buffer(ubuf, cnt, ppos, buf,
  22337. + strlen(buf));
  22338. + }
  22339. +
  22340. + buf = kmalloc(strmaxlen, GFP_KERNEL);
  22341. + if (buf == NULL)
  22342. + return -ENOMEM;
  22343. +
  22344. + t = ns2usecs(mp->timestamp);
  22345. + usecs = do_div(t, USEC_PER_SEC);
  22346. + secs = (unsigned long) t;
  22347. + r = snprintf(buf, strmaxlen,
  22348. + "%d %d %ld (%ld) %s <- %d %d %s %lu.%06lu\n", mp->pid,
  22349. + MAX_RT_PRIO-1 - mp->prio, mp->latency, mp->timeroffset, mp->comm,
  22350. + mp->current_pid, MAX_RT_PRIO-1 - mp->current_prio, mp->current_comm,
  22351. + secs, usecs);
  22352. + r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  22353. + kfree(buf);
  22354. + return r;
  22355. +}
  22356. +#endif
  22357. +
  22358. +static ssize_t
  22359. +show_enable(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  22360. +{
  22361. + char buf[64];
  22362. + struct enable_data *ed = file->private_data;
  22363. + int r;
  22364. +
  22365. + r = snprintf(buf, sizeof(buf), "%d\n", ed->enabled);
  22366. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  22367. +}
  22368. +
  22369. +static ssize_t
  22370. +do_enable(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos)
  22371. +{
  22372. + char buf[64];
  22373. + long enable;
  22374. + struct enable_data *ed = file->private_data;
  22375. +
  22376. + if (cnt >= sizeof(buf))
  22377. + return -EINVAL;
  22378. +
  22379. + if (copy_from_user(&buf, ubuf, cnt))
  22380. + return -EFAULT;
  22381. +
  22382. + buf[cnt] = 0;
  22383. +
  22384. + if (kstrtoul(buf, 10, &enable))
  22385. + return -EINVAL;
  22386. +
  22387. + if ((enable && ed->enabled) || (!enable && !ed->enabled))
  22388. + return cnt;
  22389. +
  22390. + if (enable) {
  22391. + int ret;
  22392. +
  22393. + switch (ed->latency_type) {
  22394. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  22395. + case PREEMPTIRQSOFF_LATENCY:
  22396. + ret = register_trace_preemptirqsoff_hist(
  22397. + probe_preemptirqsoff_hist, NULL);
  22398. + if (ret) {
  22399. + pr_info("wakeup trace: Couldn't assign "
  22400. + "probe_preemptirqsoff_hist "
  22401. + "to trace_preemptirqsoff_hist\n");
  22402. + return ret;
  22403. + }
  22404. + break;
  22405. +#endif
  22406. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22407. + case WAKEUP_LATENCY:
  22408. + ret = register_trace_sched_wakeup(
  22409. + probe_wakeup_latency_hist_start, NULL);
  22410. + if (ret) {
  22411. + pr_info("wakeup trace: Couldn't assign "
  22412. + "probe_wakeup_latency_hist_start "
  22413. + "to trace_sched_wakeup\n");
  22414. + return ret;
  22415. + }
  22416. + ret = register_trace_sched_wakeup_new(
  22417. + probe_wakeup_latency_hist_start, NULL);
  22418. + if (ret) {
  22419. + pr_info("wakeup trace: Couldn't assign "
  22420. + "probe_wakeup_latency_hist_start "
  22421. + "to trace_sched_wakeup_new\n");
  22422. + unregister_trace_sched_wakeup(
  22423. + probe_wakeup_latency_hist_start, NULL);
  22424. + return ret;
  22425. + }
  22426. + ret = register_trace_sched_switch(
  22427. + probe_wakeup_latency_hist_stop, NULL);
  22428. + if (ret) {
  22429. + pr_info("wakeup trace: Couldn't assign "
  22430. + "probe_wakeup_latency_hist_stop "
  22431. + "to trace_sched_switch\n");
  22432. + unregister_trace_sched_wakeup(
  22433. + probe_wakeup_latency_hist_start, NULL);
  22434. + unregister_trace_sched_wakeup_new(
  22435. + probe_wakeup_latency_hist_start, NULL);
  22436. + return ret;
  22437. + }
  22438. + ret = register_trace_sched_migrate_task(
  22439. + probe_sched_migrate_task, NULL);
  22440. + if (ret) {
  22441. + pr_info("wakeup trace: Couldn't assign "
  22442. + "probe_sched_migrate_task "
  22443. + "to trace_sched_migrate_task\n");
  22444. + unregister_trace_sched_wakeup(
  22445. + probe_wakeup_latency_hist_start, NULL);
  22446. + unregister_trace_sched_wakeup_new(
  22447. + probe_wakeup_latency_hist_start, NULL);
  22448. + unregister_trace_sched_switch(
  22449. + probe_wakeup_latency_hist_stop, NULL);
  22450. + return ret;
  22451. + }
  22452. + break;
  22453. +#endif
  22454. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22455. + case MISSED_TIMER_OFFSETS:
  22456. + ret = register_trace_hrtimer_interrupt(
  22457. + probe_hrtimer_interrupt, NULL);
  22458. + if (ret) {
  22459. + pr_info("wakeup trace: Couldn't assign "
  22460. + "probe_hrtimer_interrupt "
  22461. + "to trace_hrtimer_interrupt\n");
  22462. + return ret;
  22463. + }
  22464. + break;
  22465. +#endif
  22466. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  22467. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22468. + case TIMERANDWAKEUP_LATENCY:
  22469. + if (!wakeup_latency_enabled_data.enabled ||
  22470. + !missed_timer_offsets_enabled_data.enabled)
  22471. + return -EINVAL;
  22472. + break;
  22473. +#endif
  22474. + default:
  22475. + break;
  22476. + }
  22477. + } else {
  22478. + switch (ed->latency_type) {
  22479. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  22480. + case PREEMPTIRQSOFF_LATENCY:
  22481. + {
  22482. + int cpu;
  22483. +
  22484. + unregister_trace_preemptirqsoff_hist(
  22485. + probe_preemptirqsoff_hist, NULL);
  22486. + for_each_online_cpu(cpu) {
  22487. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22488. + per_cpu(hist_irqsoff_counting,
  22489. + cpu) = 0;
  22490. +#endif
  22491. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22492. + per_cpu(hist_preemptoff_counting,
  22493. + cpu) = 0;
  22494. +#endif
  22495. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  22496. + per_cpu(hist_preemptirqsoff_counting,
  22497. + cpu) = 0;
  22498. +#endif
  22499. + }
  22500. + }
  22501. + break;
  22502. +#endif
  22503. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22504. + case WAKEUP_LATENCY:
  22505. + {
  22506. + int cpu;
  22507. +
  22508. + unregister_trace_sched_wakeup(
  22509. + probe_wakeup_latency_hist_start, NULL);
  22510. + unregister_trace_sched_wakeup_new(
  22511. + probe_wakeup_latency_hist_start, NULL);
  22512. + unregister_trace_sched_switch(
  22513. + probe_wakeup_latency_hist_stop, NULL);
  22514. + unregister_trace_sched_migrate_task(
  22515. + probe_sched_migrate_task, NULL);
  22516. +
  22517. + for_each_online_cpu(cpu) {
  22518. + per_cpu(wakeup_task, cpu) = NULL;
  22519. + per_cpu(wakeup_sharedprio, cpu) = 0;
  22520. + }
  22521. + }
  22522. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22523. + timerandwakeup_enabled_data.enabled = 0;
  22524. +#endif
  22525. + break;
  22526. +#endif
  22527. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22528. + case MISSED_TIMER_OFFSETS:
  22529. + unregister_trace_hrtimer_interrupt(
  22530. + probe_hrtimer_interrupt, NULL);
  22531. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22532. + timerandwakeup_enabled_data.enabled = 0;
  22533. +#endif
  22534. + break;
  22535. +#endif
  22536. + default:
  22537. + break;
  22538. + }
  22539. + }
  22540. + ed->enabled = enable;
  22541. + return cnt;
  22542. +}
  22543. +
  22544. +static const struct file_operations latency_hist_reset_fops = {
  22545. + .open = tracing_open_generic,
  22546. + .write = latency_hist_reset,
  22547. +};
  22548. +
  22549. +static const struct file_operations enable_fops = {
  22550. + .open = tracing_open_generic,
  22551. + .read = show_enable,
  22552. + .write = do_enable,
  22553. +};
  22554. +
  22555. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22556. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22557. +static const struct file_operations pid_fops = {
  22558. + .open = tracing_open_generic,
  22559. + .read = show_pid,
  22560. + .write = do_pid,
  22561. +};
  22562. +
  22563. +static const struct file_operations maxlatproc_fops = {
  22564. + .open = tracing_open_generic,
  22565. + .read = show_maxlatproc,
  22566. +};
  22567. +#endif
  22568. +
  22569. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  22570. +static notrace void probe_preemptirqsoff_hist(void *v, int reason,
  22571. + int starthist)
  22572. +{
  22573. + int cpu = raw_smp_processor_id();
  22574. + int time_set = 0;
  22575. +
  22576. + if (starthist) {
  22577. + cycle_t uninitialized_var(start);
  22578. +
  22579. + if (!preempt_count() && !irqs_disabled())
  22580. + return;
  22581. +
  22582. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22583. + if ((reason == IRQS_OFF || reason == TRACE_START) &&
  22584. + !per_cpu(hist_irqsoff_counting, cpu)) {
  22585. + per_cpu(hist_irqsoff_counting, cpu) = 1;
  22586. + start = ftrace_now(cpu);
  22587. + time_set++;
  22588. + per_cpu(hist_irqsoff_start, cpu) = start;
  22589. + }
  22590. +#endif
  22591. +
  22592. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22593. + if ((reason == PREEMPT_OFF || reason == TRACE_START) &&
  22594. + !per_cpu(hist_preemptoff_counting, cpu)) {
  22595. + per_cpu(hist_preemptoff_counting, cpu) = 1;
  22596. + if (!(time_set++))
  22597. + start = ftrace_now(cpu);
  22598. + per_cpu(hist_preemptoff_start, cpu) = start;
  22599. + }
  22600. +#endif
  22601. +
  22602. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  22603. + if (per_cpu(hist_irqsoff_counting, cpu) &&
  22604. + per_cpu(hist_preemptoff_counting, cpu) &&
  22605. + !per_cpu(hist_preemptirqsoff_counting, cpu)) {
  22606. + per_cpu(hist_preemptirqsoff_counting, cpu) = 1;
  22607. + if (!time_set)
  22608. + start = ftrace_now(cpu);
  22609. + per_cpu(hist_preemptirqsoff_start, cpu) = start;
  22610. + }
  22611. +#endif
  22612. + } else {
  22613. + cycle_t uninitialized_var(stop);
  22614. +
  22615. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22616. + if ((reason == IRQS_ON || reason == TRACE_STOP) &&
  22617. + per_cpu(hist_irqsoff_counting, cpu)) {
  22618. + cycle_t start = per_cpu(hist_irqsoff_start, cpu);
  22619. +
  22620. + stop = ftrace_now(cpu);
  22621. + time_set++;
  22622. + if (start) {
  22623. + long latency = ((long) (stop - start)) /
  22624. + NSECS_PER_USECS;
  22625. +
  22626. + latency_hist(IRQSOFF_LATENCY, cpu, latency, 0,
  22627. + stop, NULL);
  22628. + }
  22629. + per_cpu(hist_irqsoff_counting, cpu) = 0;
  22630. + }
  22631. +#endif
  22632. +
  22633. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22634. + if ((reason == PREEMPT_ON || reason == TRACE_STOP) &&
  22635. + per_cpu(hist_preemptoff_counting, cpu)) {
  22636. + cycle_t start = per_cpu(hist_preemptoff_start, cpu);
  22637. +
  22638. + if (!(time_set++))
  22639. + stop = ftrace_now(cpu);
  22640. + if (start) {
  22641. + long latency = ((long) (stop - start)) /
  22642. + NSECS_PER_USECS;
  22643. +
  22644. + latency_hist(PREEMPTOFF_LATENCY, cpu, latency,
  22645. + 0, stop, NULL);
  22646. + }
  22647. + per_cpu(hist_preemptoff_counting, cpu) = 0;
  22648. + }
  22649. +#endif
  22650. +
  22651. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  22652. + if ((!per_cpu(hist_irqsoff_counting, cpu) ||
  22653. + !per_cpu(hist_preemptoff_counting, cpu)) &&
  22654. + per_cpu(hist_preemptirqsoff_counting, cpu)) {
  22655. + cycle_t start = per_cpu(hist_preemptirqsoff_start, cpu);
  22656. +
  22657. + if (!time_set)
  22658. + stop = ftrace_now(cpu);
  22659. + if (start) {
  22660. + long latency = ((long) (stop - start)) /
  22661. + NSECS_PER_USECS;
  22662. +
  22663. + latency_hist(PREEMPTIRQSOFF_LATENCY, cpu,
  22664. + latency, 0, stop, NULL);
  22665. + }
  22666. + per_cpu(hist_preemptirqsoff_counting, cpu) = 0;
  22667. + }
  22668. +#endif
  22669. + }
  22670. +}
  22671. +#endif
  22672. +
  22673. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22674. +static DEFINE_RAW_SPINLOCK(wakeup_lock);
  22675. +static notrace void probe_sched_migrate_task(void *v, struct task_struct *task,
  22676. + int cpu)
  22677. +{
  22678. + int old_cpu = task_cpu(task);
  22679. +
  22680. + if (cpu != old_cpu) {
  22681. + unsigned long flags;
  22682. + struct task_struct *cpu_wakeup_task;
  22683. +
  22684. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  22685. +
  22686. + cpu_wakeup_task = per_cpu(wakeup_task, old_cpu);
  22687. + if (task == cpu_wakeup_task) {
  22688. + put_task_struct(cpu_wakeup_task);
  22689. + per_cpu(wakeup_task, old_cpu) = NULL;
  22690. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = task;
  22691. + get_task_struct(cpu_wakeup_task);
  22692. + }
  22693. +
  22694. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  22695. + }
  22696. +}
  22697. +
  22698. +static notrace void probe_wakeup_latency_hist_start(void *v,
  22699. + struct task_struct *p)
  22700. +{
  22701. + unsigned long flags;
  22702. + struct task_struct *curr = current;
  22703. + int cpu = task_cpu(p);
  22704. + struct task_struct *cpu_wakeup_task;
  22705. +
  22706. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  22707. +
  22708. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  22709. +
  22710. + if (wakeup_pid) {
  22711. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  22712. + p->prio == curr->prio)
  22713. + per_cpu(wakeup_sharedprio, cpu) = 1;
  22714. + if (likely(wakeup_pid != task_pid_nr(p)))
  22715. + goto out;
  22716. + } else {
  22717. + if (likely(!rt_task(p)) ||
  22718. + (cpu_wakeup_task && p->prio > cpu_wakeup_task->prio) ||
  22719. + p->prio > curr->prio)
  22720. + goto out;
  22721. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  22722. + p->prio == curr->prio)
  22723. + per_cpu(wakeup_sharedprio, cpu) = 1;
  22724. + }
  22725. +
  22726. + if (cpu_wakeup_task)
  22727. + put_task_struct(cpu_wakeup_task);
  22728. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = p;
  22729. + get_task_struct(cpu_wakeup_task);
  22730. + cpu_wakeup_task->preempt_timestamp_hist =
  22731. + ftrace_now(raw_smp_processor_id());
  22732. +out:
  22733. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  22734. +}
  22735. +
  22736. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  22737. + struct task_struct *prev, struct task_struct *next)
  22738. +{
  22739. + unsigned long flags;
  22740. + int cpu = task_cpu(next);
  22741. + long latency;
  22742. + cycle_t stop;
  22743. + struct task_struct *cpu_wakeup_task;
  22744. +
  22745. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  22746. +
  22747. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  22748. +
  22749. + if (cpu_wakeup_task == NULL)
  22750. + goto out;
  22751. +
  22752. + /* Already running? */
  22753. + if (unlikely(current == cpu_wakeup_task))
  22754. + goto out_reset;
  22755. +
  22756. + if (next != cpu_wakeup_task) {
  22757. + if (next->prio < cpu_wakeup_task->prio)
  22758. + goto out_reset;
  22759. +
  22760. + if (next->prio == cpu_wakeup_task->prio)
  22761. + per_cpu(wakeup_sharedprio, cpu) = 1;
  22762. +
  22763. + goto out;
  22764. + }
  22765. +
  22766. + if (current->prio == cpu_wakeup_task->prio)
  22767. + per_cpu(wakeup_sharedprio, cpu) = 1;
  22768. +
  22769. + /*
  22770. + * The task we are waiting for is about to be switched to.
  22771. + * Calculate latency and store it in histogram.
  22772. + */
  22773. + stop = ftrace_now(raw_smp_processor_id());
  22774. +
  22775. + latency = ((long) (stop - next->preempt_timestamp_hist)) /
  22776. + NSECS_PER_USECS;
  22777. +
  22778. + if (per_cpu(wakeup_sharedprio, cpu)) {
  22779. + latency_hist(WAKEUP_LATENCY_SHAREDPRIO, cpu, latency, 0, stop,
  22780. + next);
  22781. + per_cpu(wakeup_sharedprio, cpu) = 0;
  22782. + } else {
  22783. + latency_hist(WAKEUP_LATENCY, cpu, latency, 0, stop, next);
  22784. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22785. + if (timerandwakeup_enabled_data.enabled) {
  22786. + latency_hist(TIMERANDWAKEUP_LATENCY, cpu,
  22787. + next->timer_offset + latency, next->timer_offset,
  22788. + stop, next);
  22789. + }
  22790. +#endif
  22791. + }
  22792. +
  22793. +out_reset:
  22794. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22795. + next->timer_offset = 0;
  22796. +#endif
  22797. + put_task_struct(cpu_wakeup_task);
  22798. + per_cpu(wakeup_task, cpu) = NULL;
  22799. +out:
  22800. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  22801. +}
  22802. +#endif
  22803. +
  22804. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22805. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  22806. + long long latency_ns, struct task_struct *curr,
  22807. + struct task_struct *task)
  22808. +{
  22809. + if (latency_ns <= 0 && task != NULL && rt_task(task) &&
  22810. + (task->prio < curr->prio ||
  22811. + (task->prio == curr->prio &&
  22812. + !cpumask_test_cpu(cpu, &task->cpus_allowed)))) {
  22813. + long latency;
  22814. + cycle_t now;
  22815. +
  22816. + if (missed_timer_offsets_pid) {
  22817. + if (likely(missed_timer_offsets_pid !=
  22818. + task_pid_nr(task)))
  22819. + return;
  22820. + }
  22821. +
  22822. + now = ftrace_now(cpu);
  22823. + latency = (long) div_s64(-latency_ns, NSECS_PER_USECS);
  22824. + latency_hist(MISSED_TIMER_OFFSETS, cpu, latency, latency, now,
  22825. + task);
  22826. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22827. + task->timer_offset = latency;
  22828. +#endif
  22829. + }
  22830. +}
  22831. +#endif
  22832. +
  22833. +static __init int latency_hist_init(void)
  22834. +{
  22835. + struct dentry *latency_hist_root = NULL;
  22836. + struct dentry *dentry;
  22837. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22838. + struct dentry *dentry_sharedprio;
  22839. +#endif
  22840. + struct dentry *entry;
  22841. + struct dentry *enable_root;
  22842. + int i = 0;
  22843. + struct hist_data *my_hist;
  22844. + char name[64];
  22845. + char *cpufmt = "CPU%d";
  22846. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  22847. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22848. + char *cpufmt_maxlatproc = "max_latency-CPU%d";
  22849. + struct maxlatproc_data *mp = NULL;
  22850. +#endif
  22851. +
  22852. + dentry = tracing_init_dentry();
  22853. + latency_hist_root = debugfs_create_dir(latency_hist_dir_root, dentry);
  22854. + enable_root = debugfs_create_dir("enable", latency_hist_root);
  22855. +
  22856. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  22857. + dentry = debugfs_create_dir(irqsoff_hist_dir, latency_hist_root);
  22858. + for_each_possible_cpu(i) {
  22859. + sprintf(name, cpufmt, i);
  22860. + entry = debugfs_create_file(name, 0444, dentry,
  22861. + &per_cpu(irqsoff_hist, i), &latency_hist_fops);
  22862. + my_hist = &per_cpu(irqsoff_hist, i);
  22863. + atomic_set(&my_hist->hist_mode, 1);
  22864. + my_hist->min_lat = LONG_MAX;
  22865. + }
  22866. + entry = debugfs_create_file("reset", 0644, dentry,
  22867. + (void *)IRQSOFF_LATENCY, &latency_hist_reset_fops);
  22868. +#endif
  22869. +
  22870. +#ifdef CONFIG_PREEMPT_OFF_HIST
  22871. + dentry = debugfs_create_dir(preemptoff_hist_dir,
  22872. + latency_hist_root);
  22873. + for_each_possible_cpu(i) {
  22874. + sprintf(name, cpufmt, i);
  22875. + entry = debugfs_create_file(name, 0444, dentry,
  22876. + &per_cpu(preemptoff_hist, i), &latency_hist_fops);
  22877. + my_hist = &per_cpu(preemptoff_hist, i);
  22878. + atomic_set(&my_hist->hist_mode, 1);
  22879. + my_hist->min_lat = LONG_MAX;
  22880. + }
  22881. + entry = debugfs_create_file("reset", 0644, dentry,
  22882. + (void *)PREEMPTOFF_LATENCY, &latency_hist_reset_fops);
  22883. +#endif
  22884. +
  22885. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  22886. + dentry = debugfs_create_dir(preemptirqsoff_hist_dir,
  22887. + latency_hist_root);
  22888. + for_each_possible_cpu(i) {
  22889. + sprintf(name, cpufmt, i);
  22890. + entry = debugfs_create_file(name, 0444, dentry,
  22891. + &per_cpu(preemptirqsoff_hist, i), &latency_hist_fops);
  22892. + my_hist = &per_cpu(preemptirqsoff_hist, i);
  22893. + atomic_set(&my_hist->hist_mode, 1);
  22894. + my_hist->min_lat = LONG_MAX;
  22895. + }
  22896. + entry = debugfs_create_file("reset", 0644, dentry,
  22897. + (void *)PREEMPTIRQSOFF_LATENCY, &latency_hist_reset_fops);
  22898. +#endif
  22899. +
  22900. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  22901. + entry = debugfs_create_file("preemptirqsoff", 0644,
  22902. + enable_root, (void *)&preemptirqsoff_enabled_data,
  22903. + &enable_fops);
  22904. +#endif
  22905. +
  22906. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  22907. + dentry = debugfs_create_dir(wakeup_latency_hist_dir,
  22908. + latency_hist_root);
  22909. + dentry_sharedprio = debugfs_create_dir(
  22910. + wakeup_latency_hist_dir_sharedprio, dentry);
  22911. + for_each_possible_cpu(i) {
  22912. + sprintf(name, cpufmt, i);
  22913. +
  22914. + entry = debugfs_create_file(name, 0444, dentry,
  22915. + &per_cpu(wakeup_latency_hist, i),
  22916. + &latency_hist_fops);
  22917. + my_hist = &per_cpu(wakeup_latency_hist, i);
  22918. + atomic_set(&my_hist->hist_mode, 1);
  22919. + my_hist->min_lat = LONG_MAX;
  22920. +
  22921. + entry = debugfs_create_file(name, 0444, dentry_sharedprio,
  22922. + &per_cpu(wakeup_latency_hist_sharedprio, i),
  22923. + &latency_hist_fops);
  22924. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, i);
  22925. + atomic_set(&my_hist->hist_mode, 1);
  22926. + my_hist->min_lat = LONG_MAX;
  22927. +
  22928. + sprintf(name, cpufmt_maxlatproc, i);
  22929. +
  22930. + mp = &per_cpu(wakeup_maxlatproc, i);
  22931. + entry = debugfs_create_file(name, 0444, dentry, mp,
  22932. + &maxlatproc_fops);
  22933. + clear_maxlatprocdata(mp);
  22934. +
  22935. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, i);
  22936. + entry = debugfs_create_file(name, 0444, dentry_sharedprio, mp,
  22937. + &maxlatproc_fops);
  22938. + clear_maxlatprocdata(mp);
  22939. + }
  22940. + entry = debugfs_create_file("pid", 0644, dentry,
  22941. + (void *)&wakeup_pid, &pid_fops);
  22942. + entry = debugfs_create_file("reset", 0644, dentry,
  22943. + (void *)WAKEUP_LATENCY, &latency_hist_reset_fops);
  22944. + entry = debugfs_create_file("reset", 0644, dentry_sharedprio,
  22945. + (void *)WAKEUP_LATENCY_SHAREDPRIO, &latency_hist_reset_fops);
  22946. + entry = debugfs_create_file("wakeup", 0644,
  22947. + enable_root, (void *)&wakeup_latency_enabled_data,
  22948. + &enable_fops);
  22949. +#endif
  22950. +
  22951. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22952. + dentry = debugfs_create_dir(missed_timer_offsets_dir,
  22953. + latency_hist_root);
  22954. + for_each_possible_cpu(i) {
  22955. + sprintf(name, cpufmt, i);
  22956. + entry = debugfs_create_file(name, 0444, dentry,
  22957. + &per_cpu(missed_timer_offsets, i), &latency_hist_fops);
  22958. + my_hist = &per_cpu(missed_timer_offsets, i);
  22959. + atomic_set(&my_hist->hist_mode, 1);
  22960. + my_hist->min_lat = LONG_MAX;
  22961. +
  22962. + sprintf(name, cpufmt_maxlatproc, i);
  22963. + mp = &per_cpu(missed_timer_offsets_maxlatproc, i);
  22964. + entry = debugfs_create_file(name, 0444, dentry, mp,
  22965. + &maxlatproc_fops);
  22966. + clear_maxlatprocdata(mp);
  22967. + }
  22968. + entry = debugfs_create_file("pid", 0644, dentry,
  22969. + (void *)&missed_timer_offsets_pid, &pid_fops);
  22970. + entry = debugfs_create_file("reset", 0644, dentry,
  22971. + (void *)MISSED_TIMER_OFFSETS, &latency_hist_reset_fops);
  22972. + entry = debugfs_create_file("missed_timer_offsets", 0644,
  22973. + enable_root, (void *)&missed_timer_offsets_enabled_data,
  22974. + &enable_fops);
  22975. +#endif
  22976. +
  22977. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  22978. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  22979. + dentry = debugfs_create_dir(timerandwakeup_latency_hist_dir,
  22980. + latency_hist_root);
  22981. + for_each_possible_cpu(i) {
  22982. + sprintf(name, cpufmt, i);
  22983. + entry = debugfs_create_file(name, 0444, dentry,
  22984. + &per_cpu(timerandwakeup_latency_hist, i),
  22985. + &latency_hist_fops);
  22986. + my_hist = &per_cpu(timerandwakeup_latency_hist, i);
  22987. + atomic_set(&my_hist->hist_mode, 1);
  22988. + my_hist->min_lat = LONG_MAX;
  22989. +
  22990. + sprintf(name, cpufmt_maxlatproc, i);
  22991. + mp = &per_cpu(timerandwakeup_maxlatproc, i);
  22992. + entry = debugfs_create_file(name, 0444, dentry, mp,
  22993. + &maxlatproc_fops);
  22994. + clear_maxlatprocdata(mp);
  22995. + }
  22996. + entry = debugfs_create_file("reset", 0644, dentry,
  22997. + (void *)TIMERANDWAKEUP_LATENCY, &latency_hist_reset_fops);
  22998. + entry = debugfs_create_file("timerandwakeup", 0644,
  22999. + enable_root, (void *)&timerandwakeup_enabled_data,
  23000. + &enable_fops);
  23001. +#endif
  23002. + return 0;
  23003. +}
  23004. +
  23005. +device_initcall(latency_hist_init);
  23006. diff -Nur linux-4.1.26.orig/kernel/trace/Makefile linux-4.1.26/kernel/trace/Makefile
  23007. --- linux-4.1.26.orig/kernel/trace/Makefile 2016-06-07 01:13:11.000000000 +0200
  23008. +++ linux-4.1.26/kernel/trace/Makefile 2016-06-19 15:30:58.715298429 +0200
  23009. @@ -36,6 +36,10 @@
  23010. obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
  23011. obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
  23012. obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
  23013. +obj-$(CONFIG_INTERRUPT_OFF_HIST) += latency_hist.o
  23014. +obj-$(CONFIG_PREEMPT_OFF_HIST) += latency_hist.o
  23015. +obj-$(CONFIG_WAKEUP_LATENCY_HIST) += latency_hist.o
  23016. +obj-$(CONFIG_MISSED_TIMER_OFFSETS_HIST) += latency_hist.o
  23017. obj-$(CONFIG_NOP_TRACER) += trace_nop.o
  23018. obj-$(CONFIG_STACK_TRACER) += trace_stack.o
  23019. obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
  23020. diff -Nur linux-4.1.26.orig/kernel/trace/trace.c linux-4.1.26/kernel/trace/trace.c
  23021. --- linux-4.1.26.orig/kernel/trace/trace.c 2016-06-07 01:13:11.000000000 +0200
  23022. +++ linux-4.1.26/kernel/trace/trace.c 2016-06-19 15:30:58.715298429 +0200
  23023. @@ -1630,6 +1630,7 @@
  23024. struct task_struct *tsk = current;
  23025. entry->preempt_count = pc & 0xff;
  23026. + entry->preempt_lazy_count = preempt_lazy_count();
  23027. entry->pid = (tsk) ? tsk->pid : 0;
  23028. entry->flags =
  23029. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  23030. @@ -1639,8 +1640,11 @@
  23031. #endif
  23032. ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
  23033. ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
  23034. - (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
  23035. + (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
  23036. + (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
  23037. (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
  23038. +
  23039. + entry->migrate_disable = (tsk) ? __migrate_disabled(tsk) & 0xFF : 0;
  23040. }
  23041. EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
  23042. @@ -2558,14 +2562,17 @@
  23043. static void print_lat_help_header(struct seq_file *m)
  23044. {
  23045. - seq_puts(m, "# _------=> CPU# \n"
  23046. - "# / _-----=> irqs-off \n"
  23047. - "# | / _----=> need-resched \n"
  23048. - "# || / _---=> hardirq/softirq \n"
  23049. - "# ||| / _--=> preempt-depth \n"
  23050. - "# |||| / delay \n"
  23051. - "# cmd pid ||||| time | caller \n"
  23052. - "# \\ / ||||| \\ | / \n");
  23053. + seq_puts(m, "# _--------=> CPU# \n"
  23054. + "# / _-------=> irqs-off \n"
  23055. + "# | / _------=> need-resched \n"
  23056. + "# || / _-----=> need-resched_lazy \n"
  23057. + "# ||| / _----=> hardirq/softirq \n"
  23058. + "# |||| / _---=> preempt-depth \n"
  23059. + "# ||||| / _--=> preempt-lazy-depth\n"
  23060. + "# |||||| / _-=> migrate-disable \n"
  23061. + "# ||||||| / delay \n"
  23062. + "# cmd pid |||||||| time | caller \n"
  23063. + "# \\ / |||||||| \\ | / \n");
  23064. }
  23065. static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
  23066. @@ -2591,11 +2598,14 @@
  23067. print_event_info(buf, m);
  23068. seq_puts(m, "# _-----=> irqs-off\n"
  23069. "# / _----=> need-resched\n"
  23070. - "# | / _---=> hardirq/softirq\n"
  23071. - "# || / _--=> preempt-depth\n"
  23072. - "# ||| / delay\n"
  23073. - "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
  23074. - "# | | | |||| | |\n");
  23075. + "# |/ _-----=> need-resched_lazy\n"
  23076. + "# || / _---=> hardirq/softirq\n"
  23077. + "# ||| / _--=> preempt-depth\n"
  23078. + "# |||| /_--=> preempt-lazy-depth\n"
  23079. + "# ||||| _-=> migrate-disable \n"
  23080. + "# ||||| / delay\n"
  23081. + "# TASK-PID CPU# |||||| TIMESTAMP FUNCTION\n"
  23082. + "# | | | |||||| | |\n");
  23083. }
  23084. void
  23085. diff -Nur linux-4.1.26.orig/kernel/trace/trace_events.c linux-4.1.26/kernel/trace/trace_events.c
  23086. --- linux-4.1.26.orig/kernel/trace/trace_events.c 2016-06-07 01:13:11.000000000 +0200
  23087. +++ linux-4.1.26/kernel/trace/trace_events.c 2016-06-19 15:30:58.715298429 +0200
  23088. @@ -162,6 +162,8 @@
  23089. __common_field(unsigned char, flags);
  23090. __common_field(unsigned char, preempt_count);
  23091. __common_field(int, pid);
  23092. + __common_field(unsigned short, migrate_disable);
  23093. + __common_field(unsigned short, padding);
  23094. return ret;
  23095. }
  23096. diff -Nur linux-4.1.26.orig/kernel/trace/trace.h linux-4.1.26/kernel/trace/trace.h
  23097. --- linux-4.1.26.orig/kernel/trace/trace.h 2016-06-07 01:13:11.000000000 +0200
  23098. +++ linux-4.1.26/kernel/trace/trace.h 2016-06-19 15:30:58.715298429 +0200
  23099. @@ -120,6 +120,7 @@
  23100. * NEED_RESCHED - reschedule is requested
  23101. * HARDIRQ - inside an interrupt handler
  23102. * SOFTIRQ - inside a softirq handler
  23103. + * NEED_RESCHED_LAZY - lazy reschedule is requested
  23104. */
  23105. enum trace_flag_type {
  23106. TRACE_FLAG_IRQS_OFF = 0x01,
  23107. @@ -128,6 +129,7 @@
  23108. TRACE_FLAG_HARDIRQ = 0x08,
  23109. TRACE_FLAG_SOFTIRQ = 0x10,
  23110. TRACE_FLAG_PREEMPT_RESCHED = 0x20,
  23111. + TRACE_FLAG_NEED_RESCHED_LAZY = 0x40,
  23112. };
  23113. #define TRACE_BUF_SIZE 1024
  23114. diff -Nur linux-4.1.26.orig/kernel/trace/trace_irqsoff.c linux-4.1.26/kernel/trace/trace_irqsoff.c
  23115. --- linux-4.1.26.orig/kernel/trace/trace_irqsoff.c 2016-06-07 01:13:11.000000000 +0200
  23116. +++ linux-4.1.26/kernel/trace/trace_irqsoff.c 2016-06-19 15:30:58.715298429 +0200
  23117. @@ -13,6 +13,7 @@
  23118. #include <linux/uaccess.h>
  23119. #include <linux/module.h>
  23120. #include <linux/ftrace.h>
  23121. +#include <trace/events/hist.h>
  23122. #include "trace.h"
  23123. @@ -433,11 +434,13 @@
  23124. {
  23125. if (preempt_trace() || irq_trace())
  23126. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  23127. + trace_preemptirqsoff_hist_rcuidle(TRACE_START, 1);
  23128. }
  23129. EXPORT_SYMBOL_GPL(start_critical_timings);
  23130. void stop_critical_timings(void)
  23131. {
  23132. + trace_preemptirqsoff_hist_rcuidle(TRACE_STOP, 0);
  23133. if (preempt_trace() || irq_trace())
  23134. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  23135. }
  23136. @@ -447,6 +450,7 @@
  23137. #ifdef CONFIG_PROVE_LOCKING
  23138. void time_hardirqs_on(unsigned long a0, unsigned long a1)
  23139. {
  23140. + trace_preemptirqsoff_hist_rcuidle(IRQS_ON, 0);
  23141. if (!preempt_trace() && irq_trace())
  23142. stop_critical_timing(a0, a1);
  23143. }
  23144. @@ -455,6 +459,7 @@
  23145. {
  23146. if (!preempt_trace() && irq_trace())
  23147. start_critical_timing(a0, a1);
  23148. + trace_preemptirqsoff_hist_rcuidle(IRQS_OFF, 1);
  23149. }
  23150. #else /* !CONFIG_PROVE_LOCKING */
  23151. @@ -480,6 +485,7 @@
  23152. */
  23153. void trace_hardirqs_on(void)
  23154. {
  23155. + trace_preemptirqsoff_hist_rcuidle(IRQS_ON, 0);
  23156. if (!preempt_trace() && irq_trace())
  23157. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  23158. }
  23159. @@ -489,11 +495,13 @@
  23160. {
  23161. if (!preempt_trace() && irq_trace())
  23162. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  23163. + trace_preemptirqsoff_hist_rcuidle(IRQS_OFF, 1);
  23164. }
  23165. EXPORT_SYMBOL(trace_hardirqs_off);
  23166. __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
  23167. {
  23168. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  23169. if (!preempt_trace() && irq_trace())
  23170. stop_critical_timing(CALLER_ADDR0, caller_addr);
  23171. }
  23172. @@ -503,6 +511,7 @@
  23173. {
  23174. if (!preempt_trace() && irq_trace())
  23175. start_critical_timing(CALLER_ADDR0, caller_addr);
  23176. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  23177. }
  23178. EXPORT_SYMBOL(trace_hardirqs_off_caller);
  23179. @@ -512,12 +521,14 @@
  23180. #ifdef CONFIG_PREEMPT_TRACER
  23181. void trace_preempt_on(unsigned long a0, unsigned long a1)
  23182. {
  23183. + trace_preemptirqsoff_hist(PREEMPT_ON, 0);
  23184. if (preempt_trace() && !irq_trace())
  23185. stop_critical_timing(a0, a1);
  23186. }
  23187. void trace_preempt_off(unsigned long a0, unsigned long a1)
  23188. {
  23189. + trace_preemptirqsoff_hist(PREEMPT_ON, 1);
  23190. if (preempt_trace() && !irq_trace())
  23191. start_critical_timing(a0, a1);
  23192. }
  23193. diff -Nur linux-4.1.26.orig/kernel/trace/trace_output.c linux-4.1.26/kernel/trace/trace_output.c
  23194. --- linux-4.1.26.orig/kernel/trace/trace_output.c 2016-06-07 01:13:11.000000000 +0200
  23195. +++ linux-4.1.26/kernel/trace/trace_output.c 2016-06-19 15:30:58.715298429 +0200
  23196. @@ -430,6 +430,7 @@
  23197. {
  23198. char hardsoft_irq;
  23199. char need_resched;
  23200. + char need_resched_lazy;
  23201. char irqs_off;
  23202. int hardirq;
  23203. int softirq;
  23204. @@ -457,6 +458,8 @@
  23205. need_resched = '.';
  23206. break;
  23207. }
  23208. + need_resched_lazy =
  23209. + (entry->flags & TRACE_FLAG_NEED_RESCHED_LAZY) ? 'L' : '.';
  23210. hardsoft_irq =
  23211. (hardirq && softirq) ? 'H' :
  23212. @@ -464,14 +467,25 @@
  23213. softirq ? 's' :
  23214. '.';
  23215. - trace_seq_printf(s, "%c%c%c",
  23216. - irqs_off, need_resched, hardsoft_irq);
  23217. + trace_seq_printf(s, "%c%c%c%c",
  23218. + irqs_off, need_resched, need_resched_lazy,
  23219. + hardsoft_irq);
  23220. if (entry->preempt_count)
  23221. trace_seq_printf(s, "%x", entry->preempt_count);
  23222. else
  23223. trace_seq_putc(s, '.');
  23224. + if (entry->preempt_lazy_count)
  23225. + trace_seq_printf(s, "%x", entry->preempt_lazy_count);
  23226. + else
  23227. + trace_seq_putc(s, '.');
  23228. +
  23229. + if (entry->migrate_disable)
  23230. + trace_seq_printf(s, "%x", entry->migrate_disable);
  23231. + else
  23232. + trace_seq_putc(s, '.');
  23233. +
  23234. return !trace_seq_has_overflowed(s);
  23235. }
  23236. diff -Nur linux-4.1.26.orig/kernel/trace/trace_sched_switch.c linux-4.1.26/kernel/trace/trace_sched_switch.c
  23237. --- linux-4.1.26.orig/kernel/trace/trace_sched_switch.c 2016-06-07 01:13:11.000000000 +0200
  23238. +++ linux-4.1.26/kernel/trace/trace_sched_switch.c 2016-06-19 15:30:58.715298429 +0200
  23239. @@ -26,7 +26,7 @@
  23240. }
  23241. static void
  23242. -probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success)
  23243. +probe_sched_wakeup(void *ignore, struct task_struct *wakee)
  23244. {
  23245. if (unlikely(!sched_ref))
  23246. return;
  23247. diff -Nur linux-4.1.26.orig/kernel/trace/trace_sched_wakeup.c linux-4.1.26/kernel/trace/trace_sched_wakeup.c
  23248. --- linux-4.1.26.orig/kernel/trace/trace_sched_wakeup.c 2016-06-07 01:13:11.000000000 +0200
  23249. +++ linux-4.1.26/kernel/trace/trace_sched_wakeup.c 2016-06-19 15:30:58.719298583 +0200
  23250. @@ -514,7 +514,7 @@
  23251. }
  23252. static void
  23253. -probe_wakeup(void *ignore, struct task_struct *p, int success)
  23254. +probe_wakeup(void *ignore, struct task_struct *p)
  23255. {
  23256. struct trace_array_cpu *data;
  23257. int cpu = smp_processor_id();
  23258. diff -Nur linux-4.1.26.orig/kernel/user.c linux-4.1.26/kernel/user.c
  23259. --- linux-4.1.26.orig/kernel/user.c 2016-06-07 01:13:11.000000000 +0200
  23260. +++ linux-4.1.26/kernel/user.c 2016-06-19 15:30:58.719298583 +0200
  23261. @@ -161,11 +161,11 @@
  23262. if (!up)
  23263. return;
  23264. - local_irq_save(flags);
  23265. + local_irq_save_nort(flags);
  23266. if (atomic_dec_and_lock(&up->__count, &uidhash_lock))
  23267. free_user(up, flags);
  23268. else
  23269. - local_irq_restore(flags);
  23270. + local_irq_restore_nort(flags);
  23271. }
  23272. struct user_struct *alloc_uid(kuid_t uid)
  23273. diff -Nur linux-4.1.26.orig/kernel/watchdog.c linux-4.1.26/kernel/watchdog.c
  23274. --- linux-4.1.26.orig/kernel/watchdog.c 2016-06-07 01:13:11.000000000 +0200
  23275. +++ linux-4.1.26/kernel/watchdog.c 2016-06-19 15:30:58.719298583 +0200
  23276. @@ -262,6 +262,8 @@
  23277. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  23278. +static DEFINE_RAW_SPINLOCK(watchdog_output_lock);
  23279. +
  23280. static struct perf_event_attr wd_hw_attr = {
  23281. .type = PERF_TYPE_HARDWARE,
  23282. .config = PERF_COUNT_HW_CPU_CYCLES,
  23283. @@ -295,13 +297,21 @@
  23284. /* only print hardlockups once */
  23285. if (__this_cpu_read(hard_watchdog_warn) == true)
  23286. return;
  23287. + /*
  23288. + * If early-printk is enabled then make sure we do not
  23289. + * lock up in printk() and kill console logging:
  23290. + */
  23291. + printk_kill();
  23292. - if (hardlockup_panic)
  23293. + if (hardlockup_panic) {
  23294. panic("Watchdog detected hard LOCKUP on cpu %d",
  23295. this_cpu);
  23296. - else
  23297. + } else {
  23298. + raw_spin_lock(&watchdog_output_lock);
  23299. WARN(1, "Watchdog detected hard LOCKUP on cpu %d",
  23300. this_cpu);
  23301. + raw_spin_unlock(&watchdog_output_lock);
  23302. + }
  23303. __this_cpu_write(hard_watchdog_warn, true);
  23304. return;
  23305. @@ -444,6 +454,7 @@
  23306. /* kick off the timer for the hardlockup detector */
  23307. hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  23308. hrtimer->function = watchdog_timer_fn;
  23309. + hrtimer->irqsafe = 1;
  23310. /* Enable the perf event */
  23311. watchdog_nmi_enable(cpu);
  23312. diff -Nur linux-4.1.26.orig/kernel/workqueue.c linux-4.1.26/kernel/workqueue.c
  23313. --- linux-4.1.26.orig/kernel/workqueue.c 2016-06-07 01:13:11.000000000 +0200
  23314. +++ linux-4.1.26/kernel/workqueue.c 2016-06-19 15:30:58.719298583 +0200
  23315. @@ -48,6 +48,8 @@
  23316. #include <linux/nodemask.h>
  23317. #include <linux/moduleparam.h>
  23318. #include <linux/uaccess.h>
  23319. +#include <linux/locallock.h>
  23320. +#include <linux/delay.h>
  23321. #include "workqueue_internal.h"
  23322. @@ -121,11 +123,16 @@
  23323. * cpu or grabbing pool->lock is enough for read access. If
  23324. * POOL_DISASSOCIATED is set, it's identical to L.
  23325. *
  23326. + * On RT we need the extra protection via rt_lock_idle_list() for
  23327. + * the list manipulations against read access from
  23328. + * wq_worker_sleeping(). All other places are nicely serialized via
  23329. + * pool->lock.
  23330. + *
  23331. * A: pool->attach_mutex protected.
  23332. *
  23333. * PL: wq_pool_mutex protected.
  23334. *
  23335. - * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
  23336. + * PR: wq_pool_mutex protected for writes. RCU protected for reads.
  23337. *
  23338. * PW: wq_pool_mutex and wq->mutex protected for writes. Either for reads.
  23339. *
  23340. @@ -134,7 +141,7 @@
  23341. *
  23342. * WQ: wq->mutex protected.
  23343. *
  23344. - * WR: wq->mutex protected for writes. Sched-RCU protected for reads.
  23345. + * WR: wq->mutex protected for writes. RCU protected for reads.
  23346. *
  23347. * MD: wq_mayday_lock protected.
  23348. */
  23349. @@ -183,7 +190,7 @@
  23350. atomic_t nr_running ____cacheline_aligned_in_smp;
  23351. /*
  23352. - * Destruction of pool is sched-RCU protected to allow dereferences
  23353. + * Destruction of pool is RCU protected to allow dereferences
  23354. * from get_work_pool().
  23355. */
  23356. struct rcu_head rcu;
  23357. @@ -212,7 +219,7 @@
  23358. /*
  23359. * Release of unbound pwq is punted to system_wq. See put_pwq()
  23360. * and pwq_unbound_release_workfn() for details. pool_workqueue
  23361. - * itself is also sched-RCU protected so that the first pwq can be
  23362. + * itself is also RCU protected so that the first pwq can be
  23363. * determined without grabbing wq->mutex.
  23364. */
  23365. struct work_struct unbound_release_work;
  23366. @@ -334,6 +341,8 @@
  23367. struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
  23368. EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
  23369. +static DEFINE_LOCAL_IRQ_LOCK(pendingb_lock);
  23370. +
  23371. static int worker_thread(void *__worker);
  23372. static void copy_workqueue_attrs(struct workqueue_attrs *to,
  23373. const struct workqueue_attrs *from);
  23374. @@ -343,14 +352,14 @@
  23375. #include <trace/events/workqueue.h>
  23376. #define assert_rcu_or_pool_mutex() \
  23377. - rcu_lockdep_assert(rcu_read_lock_sched_held() || \
  23378. + rcu_lockdep_assert(rcu_read_lock_held() || \
  23379. lockdep_is_held(&wq_pool_mutex), \
  23380. - "sched RCU or wq_pool_mutex should be held")
  23381. + "RCU or wq_pool_mutex should be held")
  23382. #define assert_rcu_or_wq_mutex(wq) \
  23383. - rcu_lockdep_assert(rcu_read_lock_sched_held() || \
  23384. + rcu_lockdep_assert(rcu_read_lock_held() || \
  23385. lockdep_is_held(&wq->mutex), \
  23386. - "sched RCU or wq->mutex should be held")
  23387. + "RCU or wq->mutex should be held")
  23388. #define assert_rcu_or_wq_mutex_or_pool_mutex(wq) \
  23389. rcu_lockdep_assert(rcu_read_lock_sched_held() || \
  23390. @@ -368,7 +377,7 @@
  23391. * @pool: iteration cursor
  23392. * @pi: integer used for iteration
  23393. *
  23394. - * This must be called either with wq_pool_mutex held or sched RCU read
  23395. + * This must be called either with wq_pool_mutex held or RCU read
  23396. * locked. If the pool needs to be used beyond the locking in effect, the
  23397. * caller is responsible for guaranteeing that the pool stays online.
  23398. *
  23399. @@ -400,7 +409,7 @@
  23400. * @pwq: iteration cursor
  23401. * @wq: the target workqueue
  23402. *
  23403. - * This must be called either with wq->mutex held or sched RCU read locked.
  23404. + * This must be called either with wq->mutex held or RCU read locked.
  23405. * If the pwq needs to be used beyond the locking in effect, the caller is
  23406. * responsible for guaranteeing that the pwq stays online.
  23407. *
  23408. @@ -412,6 +421,31 @@
  23409. if (({ assert_rcu_or_wq_mutex(wq); false; })) { } \
  23410. else
  23411. +#ifdef CONFIG_PREEMPT_RT_BASE
  23412. +static inline void rt_lock_idle_list(struct worker_pool *pool)
  23413. +{
  23414. + preempt_disable();
  23415. +}
  23416. +static inline void rt_unlock_idle_list(struct worker_pool *pool)
  23417. +{
  23418. + preempt_enable();
  23419. +}
  23420. +static inline void sched_lock_idle_list(struct worker_pool *pool) { }
  23421. +static inline void sched_unlock_idle_list(struct worker_pool *pool) { }
  23422. +#else
  23423. +static inline void rt_lock_idle_list(struct worker_pool *pool) { }
  23424. +static inline void rt_unlock_idle_list(struct worker_pool *pool) { }
  23425. +static inline void sched_lock_idle_list(struct worker_pool *pool)
  23426. +{
  23427. + spin_lock_irq(&pool->lock);
  23428. +}
  23429. +static inline void sched_unlock_idle_list(struct worker_pool *pool)
  23430. +{
  23431. + spin_unlock_irq(&pool->lock);
  23432. +}
  23433. +#endif
  23434. +
  23435. +
  23436. #ifdef CONFIG_DEBUG_OBJECTS_WORK
  23437. static struct debug_obj_descr work_debug_descr;
  23438. @@ -562,8 +596,7 @@
  23439. * @wq: the target workqueue
  23440. * @node: the node ID
  23441. *
  23442. - * This must be called with any of wq_pool_mutex, wq->mutex or sched RCU
  23443. - * read locked.
  23444. + * This must be called with any of wq_pool_mutex, wq->mutex or RCU read locked.
  23445. * If the pwq needs to be used beyond the locking in effect, the caller is
  23446. * responsible for guaranteeing that the pwq stays online.
  23447. *
  23448. @@ -706,8 +739,8 @@
  23449. * @work: the work item of interest
  23450. *
  23451. * Pools are created and destroyed under wq_pool_mutex, and allows read
  23452. - * access under sched-RCU read lock. As such, this function should be
  23453. - * called under wq_pool_mutex or with preemption disabled.
  23454. + * access under RCU read lock. As such, this function should be
  23455. + * called under wq_pool_mutex or inside of a rcu_read_lock() region.
  23456. *
  23457. * All fields of the returned pool are accessible as long as the above
  23458. * mentioned locking is in effect. If the returned pool needs to be used
  23459. @@ -844,51 +877,44 @@
  23460. */
  23461. static void wake_up_worker(struct worker_pool *pool)
  23462. {
  23463. - struct worker *worker = first_idle_worker(pool);
  23464. + struct worker *worker;
  23465. +
  23466. + rt_lock_idle_list(pool);
  23467. +
  23468. + worker = first_idle_worker(pool);
  23469. if (likely(worker))
  23470. wake_up_process(worker->task);
  23471. +
  23472. + rt_unlock_idle_list(pool);
  23473. }
  23474. /**
  23475. - * wq_worker_waking_up - a worker is waking up
  23476. - * @task: task waking up
  23477. - * @cpu: CPU @task is waking up to
  23478. - *
  23479. - * This function is called during try_to_wake_up() when a worker is
  23480. - * being awoken.
  23481. + * wq_worker_running - a worker is running again
  23482. + * @task: task returning from sleep
  23483. *
  23484. - * CONTEXT:
  23485. - * spin_lock_irq(rq->lock)
  23486. + * This function is called when a worker returns from schedule()
  23487. */
  23488. -void wq_worker_waking_up(struct task_struct *task, int cpu)
  23489. +void wq_worker_running(struct task_struct *task)
  23490. {
  23491. struct worker *worker = kthread_data(task);
  23492. - if (!(worker->flags & WORKER_NOT_RUNNING)) {
  23493. - WARN_ON_ONCE(worker->pool->cpu != cpu);
  23494. + if (!worker->sleeping)
  23495. + return;
  23496. + if (!(worker->flags & WORKER_NOT_RUNNING))
  23497. atomic_inc(&worker->pool->nr_running);
  23498. - }
  23499. + worker->sleeping = 0;
  23500. }
  23501. /**
  23502. * wq_worker_sleeping - a worker is going to sleep
  23503. * @task: task going to sleep
  23504. - * @cpu: CPU in question, must be the current CPU number
  23505. - *
  23506. - * This function is called during schedule() when a busy worker is
  23507. - * going to sleep. Worker on the same cpu can be woken up by
  23508. - * returning pointer to its task.
  23509. - *
  23510. - * CONTEXT:
  23511. - * spin_lock_irq(rq->lock)
  23512. - *
  23513. - * Return:
  23514. - * Worker task on @cpu to wake up, %NULL if none.
  23515. + * This function is called from schedule() when a busy worker is
  23516. + * going to sleep.
  23517. */
  23518. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
  23519. +void wq_worker_sleeping(struct task_struct *task)
  23520. {
  23521. - struct worker *worker = kthread_data(task), *to_wakeup = NULL;
  23522. + struct worker *worker = kthread_data(task);
  23523. struct worker_pool *pool;
  23524. /*
  23525. @@ -897,29 +923,26 @@
  23526. * checking NOT_RUNNING.
  23527. */
  23528. if (worker->flags & WORKER_NOT_RUNNING)
  23529. - return NULL;
  23530. + return;
  23531. pool = worker->pool;
  23532. - /* this can only happen on the local cpu */
  23533. - if (WARN_ON_ONCE(cpu != raw_smp_processor_id() || pool->cpu != cpu))
  23534. - return NULL;
  23535. + if (WARN_ON_ONCE(worker->sleeping))
  23536. + return;
  23537. +
  23538. + worker->sleeping = 1;
  23539. /*
  23540. * The counterpart of the following dec_and_test, implied mb,
  23541. * worklist not empty test sequence is in insert_work().
  23542. * Please read comment there.
  23543. - *
  23544. - * NOT_RUNNING is clear. This means that we're bound to and
  23545. - * running on the local cpu w/ rq lock held and preemption
  23546. - * disabled, which in turn means that none else could be
  23547. - * manipulating idle_list, so dereferencing idle_list without pool
  23548. - * lock is safe.
  23549. */
  23550. if (atomic_dec_and_test(&pool->nr_running) &&
  23551. - !list_empty(&pool->worklist))
  23552. - to_wakeup = first_idle_worker(pool);
  23553. - return to_wakeup ? to_wakeup->task : NULL;
  23554. + !list_empty(&pool->worklist)) {
  23555. + sched_lock_idle_list(pool);
  23556. + wake_up_worker(pool);
  23557. + sched_unlock_idle_list(pool);
  23558. + }
  23559. }
  23560. /**
  23561. @@ -1113,12 +1136,12 @@
  23562. {
  23563. if (pwq) {
  23564. /*
  23565. - * As both pwqs and pools are sched-RCU protected, the
  23566. + * As both pwqs and pools are RCU protected, the
  23567. * following lock operations are safe.
  23568. */
  23569. - spin_lock_irq(&pwq->pool->lock);
  23570. + local_spin_lock_irq(pendingb_lock, &pwq->pool->lock);
  23571. put_pwq(pwq);
  23572. - spin_unlock_irq(&pwq->pool->lock);
  23573. + local_spin_unlock_irq(pendingb_lock, &pwq->pool->lock);
  23574. }
  23575. }
  23576. @@ -1220,7 +1243,7 @@
  23577. struct worker_pool *pool;
  23578. struct pool_workqueue *pwq;
  23579. - local_irq_save(*flags);
  23580. + local_lock_irqsave(pendingb_lock, *flags);
  23581. /* try to steal the timer if it exists */
  23582. if (is_dwork) {
  23583. @@ -1239,6 +1262,7 @@
  23584. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
  23585. return 0;
  23586. + rcu_read_lock();
  23587. /*
  23588. * The queueing is in progress, or it is already queued. Try to
  23589. * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
  23590. @@ -1277,14 +1301,16 @@
  23591. set_work_pool_and_keep_pending(work, pool->id);
  23592. spin_unlock(&pool->lock);
  23593. + rcu_read_unlock();
  23594. return 1;
  23595. }
  23596. spin_unlock(&pool->lock);
  23597. fail:
  23598. - local_irq_restore(*flags);
  23599. + rcu_read_unlock();
  23600. + local_unlock_irqrestore(pendingb_lock, *flags);
  23601. if (work_is_canceling(work))
  23602. return -ENOENT;
  23603. - cpu_relax();
  23604. + cpu_chill();
  23605. return -EAGAIN;
  23606. }
  23607. @@ -1353,7 +1379,7 @@
  23608. * queued or lose PENDING. Grabbing PENDING and queueing should
  23609. * happen with IRQ disabled.
  23610. */
  23611. - WARN_ON_ONCE(!irqs_disabled());
  23612. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  23613. debug_work_activate(work);
  23614. @@ -1361,6 +1387,8 @@
  23615. if (unlikely(wq->flags & __WQ_DRAINING) &&
  23616. WARN_ON_ONCE(!is_chained_work(wq)))
  23617. return;
  23618. +
  23619. + rcu_read_lock();
  23620. retry:
  23621. if (req_cpu == WORK_CPU_UNBOUND)
  23622. cpu = raw_smp_processor_id();
  23623. @@ -1417,10 +1445,8 @@
  23624. /* pwq determined, queue */
  23625. trace_workqueue_queue_work(req_cpu, pwq, work);
  23626. - if (WARN_ON(!list_empty(&work->entry))) {
  23627. - spin_unlock(&pwq->pool->lock);
  23628. - return;
  23629. - }
  23630. + if (WARN_ON(!list_empty(&work->entry)))
  23631. + goto out;
  23632. pwq->nr_in_flight[pwq->work_color]++;
  23633. work_flags = work_color_to_flags(pwq->work_color);
  23634. @@ -1436,7 +1462,9 @@
  23635. insert_work(pwq, work, worklist, work_flags);
  23636. +out:
  23637. spin_unlock(&pwq->pool->lock);
  23638. + rcu_read_unlock();
  23639. }
  23640. /**
  23641. @@ -1456,14 +1484,14 @@
  23642. bool ret = false;
  23643. unsigned long flags;
  23644. - local_irq_save(flags);
  23645. + local_lock_irqsave(pendingb_lock,flags);
  23646. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  23647. __queue_work(cpu, wq, work);
  23648. ret = true;
  23649. }
  23650. - local_irq_restore(flags);
  23651. + local_unlock_irqrestore(pendingb_lock, flags);
  23652. return ret;
  23653. }
  23654. EXPORT_SYMBOL(queue_work_on);
  23655. @@ -1530,14 +1558,14 @@
  23656. unsigned long flags;
  23657. /* read the comment in __queue_work() */
  23658. - local_irq_save(flags);
  23659. + local_lock_irqsave(pendingb_lock, flags);
  23660. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  23661. __queue_delayed_work(cpu, wq, dwork, delay);
  23662. ret = true;
  23663. }
  23664. - local_irq_restore(flags);
  23665. + local_unlock_irqrestore(pendingb_lock, flags);
  23666. return ret;
  23667. }
  23668. EXPORT_SYMBOL(queue_delayed_work_on);
  23669. @@ -1572,7 +1600,7 @@
  23670. if (likely(ret >= 0)) {
  23671. __queue_delayed_work(cpu, wq, dwork, delay);
  23672. - local_irq_restore(flags);
  23673. + local_unlock_irqrestore(pendingb_lock, flags);
  23674. }
  23675. /* -ENOENT from try_to_grab_pending() becomes %true */
  23676. @@ -1605,7 +1633,9 @@
  23677. worker->last_active = jiffies;
  23678. /* idle_list is LIFO */
  23679. + rt_lock_idle_list(pool);
  23680. list_add(&worker->entry, &pool->idle_list);
  23681. + rt_unlock_idle_list(pool);
  23682. if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
  23683. mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
  23684. @@ -1638,7 +1668,9 @@
  23685. return;
  23686. worker_clr_flags(worker, WORKER_IDLE);
  23687. pool->nr_idle--;
  23688. + rt_lock_idle_list(pool);
  23689. list_del_init(&worker->entry);
  23690. + rt_unlock_idle_list(pool);
  23691. }
  23692. static struct worker *alloc_worker(int node)
  23693. @@ -1806,7 +1838,9 @@
  23694. pool->nr_workers--;
  23695. pool->nr_idle--;
  23696. + rt_lock_idle_list(pool);
  23697. list_del_init(&worker->entry);
  23698. + rt_unlock_idle_list(pool);
  23699. worker->flags |= WORKER_DIE;
  23700. wake_up_process(worker->task);
  23701. }
  23702. @@ -2723,14 +2757,14 @@
  23703. might_sleep();
  23704. - local_irq_disable();
  23705. + rcu_read_lock();
  23706. pool = get_work_pool(work);
  23707. if (!pool) {
  23708. - local_irq_enable();
  23709. + rcu_read_unlock();
  23710. return false;
  23711. }
  23712. - spin_lock(&pool->lock);
  23713. + spin_lock_irq(&pool->lock);
  23714. /* see the comment in try_to_grab_pending() with the same code */
  23715. pwq = get_work_pwq(work);
  23716. if (pwq) {
  23717. @@ -2757,10 +2791,11 @@
  23718. else
  23719. lock_map_acquire_read(&pwq->wq->lockdep_map);
  23720. lock_map_release(&pwq->wq->lockdep_map);
  23721. -
  23722. + rcu_read_unlock();
  23723. return true;
  23724. already_gone:
  23725. spin_unlock_irq(&pool->lock);
  23726. + rcu_read_unlock();
  23727. return false;
  23728. }
  23729. @@ -2847,7 +2882,7 @@
  23730. /* tell other tasks trying to grab @work to back off */
  23731. mark_work_canceling(work);
  23732. - local_irq_restore(flags);
  23733. + local_unlock_irqrestore(pendingb_lock, flags);
  23734. flush_work(work);
  23735. clear_work_data(work);
  23736. @@ -2902,10 +2937,10 @@
  23737. */
  23738. bool flush_delayed_work(struct delayed_work *dwork)
  23739. {
  23740. - local_irq_disable();
  23741. + local_lock_irq(pendingb_lock);
  23742. if (del_timer_sync(&dwork->timer))
  23743. __queue_work(dwork->cpu, dwork->wq, &dwork->work);
  23744. - local_irq_enable();
  23745. + local_unlock_irq(pendingb_lock);
  23746. return flush_work(&dwork->work);
  23747. }
  23748. EXPORT_SYMBOL(flush_delayed_work);
  23749. @@ -2940,7 +2975,7 @@
  23750. set_work_pool_and_clear_pending(&dwork->work,
  23751. get_work_pool_id(&dwork->work));
  23752. - local_irq_restore(flags);
  23753. + local_unlock_irqrestore(pendingb_lock, flags);
  23754. return ret;
  23755. }
  23756. EXPORT_SYMBOL(cancel_delayed_work);
  23757. @@ -3198,7 +3233,7 @@
  23758. * put_unbound_pool - put a worker_pool
  23759. * @pool: worker_pool to put
  23760. *
  23761. - * Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
  23762. + * Put @pool. If its refcnt reaches zero, it gets destroyed in RCU
  23763. * safe manner. get_unbound_pool() calls this function on its failure path
  23764. * and this function should be able to release pools which went through,
  23765. * successfully or not, init_worker_pool().
  23766. @@ -3252,8 +3287,8 @@
  23767. del_timer_sync(&pool->idle_timer);
  23768. del_timer_sync(&pool->mayday_timer);
  23769. - /* sched-RCU protected to allow dereferences from get_work_pool() */
  23770. - call_rcu_sched(&pool->rcu, rcu_free_pool);
  23771. + /* RCU protected to allow dereferences from get_work_pool() */
  23772. + call_rcu(&pool->rcu, rcu_free_pool);
  23773. }
  23774. /**
  23775. @@ -3358,14 +3393,14 @@
  23776. put_unbound_pool(pool);
  23777. mutex_unlock(&wq_pool_mutex);
  23778. - call_rcu_sched(&pwq->rcu, rcu_free_pwq);
  23779. + call_rcu(&pwq->rcu, rcu_free_pwq);
  23780. /*
  23781. * If we're the last pwq going away, @wq is already dead and no one
  23782. * is gonna access it anymore. Schedule RCU free.
  23783. */
  23784. if (is_last)
  23785. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  23786. + call_rcu(&wq->rcu, rcu_free_wq);
  23787. }
  23788. /**
  23789. @@ -4003,7 +4038,7 @@
  23790. * The base ref is never dropped on per-cpu pwqs. Directly
  23791. * schedule RCU free.
  23792. */
  23793. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  23794. + call_rcu(&wq->rcu, rcu_free_wq);
  23795. } else {
  23796. /*
  23797. * We're the sole accessor of @wq at this point. Directly
  23798. @@ -4096,7 +4131,8 @@
  23799. struct pool_workqueue *pwq;
  23800. bool ret;
  23801. - rcu_read_lock_sched();
  23802. + rcu_read_lock();
  23803. + preempt_disable();
  23804. if (cpu == WORK_CPU_UNBOUND)
  23805. cpu = smp_processor_id();
  23806. @@ -4107,7 +4143,8 @@
  23807. pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
  23808. ret = !list_empty(&pwq->delayed_works);
  23809. - rcu_read_unlock_sched();
  23810. + preempt_enable();
  23811. + rcu_read_unlock();
  23812. return ret;
  23813. }
  23814. @@ -4133,15 +4170,15 @@
  23815. if (work_pending(work))
  23816. ret |= WORK_BUSY_PENDING;
  23817. - local_irq_save(flags);
  23818. + rcu_read_lock();
  23819. pool = get_work_pool(work);
  23820. if (pool) {
  23821. - spin_lock(&pool->lock);
  23822. + spin_lock_irqsave(&pool->lock, flags);
  23823. if (find_worker_executing_work(pool, work))
  23824. ret |= WORK_BUSY_RUNNING;
  23825. - spin_unlock(&pool->lock);
  23826. + spin_unlock_irqrestore(&pool->lock, flags);
  23827. }
  23828. - local_irq_restore(flags);
  23829. + rcu_read_unlock();
  23830. return ret;
  23831. }
  23832. @@ -4330,7 +4367,7 @@
  23833. unsigned long flags;
  23834. int pi;
  23835. - rcu_read_lock_sched();
  23836. + rcu_read_lock();
  23837. pr_info("Showing busy workqueues and worker pools:\n");
  23838. @@ -4381,7 +4418,7 @@
  23839. spin_unlock_irqrestore(&pool->lock, flags);
  23840. }
  23841. - rcu_read_unlock_sched();
  23842. + rcu_read_unlock();
  23843. }
  23844. /*
  23845. @@ -4742,16 +4779,16 @@
  23846. * nr_active is monotonically decreasing. It's safe
  23847. * to peek without lock.
  23848. */
  23849. - rcu_read_lock_sched();
  23850. + rcu_read_lock();
  23851. for_each_pwq(pwq, wq) {
  23852. WARN_ON_ONCE(pwq->nr_active < 0);
  23853. if (pwq->nr_active) {
  23854. busy = true;
  23855. - rcu_read_unlock_sched();
  23856. + rcu_read_unlock();
  23857. goto out_unlock;
  23858. }
  23859. }
  23860. - rcu_read_unlock_sched();
  23861. + rcu_read_unlock();
  23862. }
  23863. out_unlock:
  23864. mutex_unlock(&wq_pool_mutex);
  23865. @@ -4865,7 +4902,8 @@
  23866. const char *delim = "";
  23867. int node, written = 0;
  23868. - rcu_read_lock_sched();
  23869. + get_online_cpus();
  23870. + rcu_read_lock();
  23871. for_each_node(node) {
  23872. written += scnprintf(buf + written, PAGE_SIZE - written,
  23873. "%s%d:%d", delim, node,
  23874. @@ -4873,7 +4911,8 @@
  23875. delim = " ";
  23876. }
  23877. written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
  23878. - rcu_read_unlock_sched();
  23879. + rcu_read_unlock();
  23880. + put_online_cpus();
  23881. return written;
  23882. }
  23883. diff -Nur linux-4.1.26.orig/kernel/workqueue_internal.h linux-4.1.26/kernel/workqueue_internal.h
  23884. --- linux-4.1.26.orig/kernel/workqueue_internal.h 2016-06-07 01:13:11.000000000 +0200
  23885. +++ linux-4.1.26/kernel/workqueue_internal.h 2016-06-19 15:30:58.719298583 +0200
  23886. @@ -43,6 +43,7 @@
  23887. unsigned long last_active; /* L: last active timestamp */
  23888. unsigned int flags; /* X: flags */
  23889. int id; /* I: worker id */
  23890. + int sleeping; /* None */
  23891. /*
  23892. * Opaque string set with work_set_desc(). Printed out with task
  23893. @@ -68,7 +69,7 @@
  23894. * Scheduler hooks for concurrency managed workqueue. Only to be used from
  23895. * sched/core.c and workqueue.c.
  23896. */
  23897. -void wq_worker_waking_up(struct task_struct *task, int cpu);
  23898. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu);
  23899. +void wq_worker_running(struct task_struct *task);
  23900. +void wq_worker_sleeping(struct task_struct *task);
  23901. #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */
  23902. diff -Nur linux-4.1.26.orig/lib/debugobjects.c linux-4.1.26/lib/debugobjects.c
  23903. --- linux-4.1.26.orig/lib/debugobjects.c 2016-06-07 01:13:11.000000000 +0200
  23904. +++ linux-4.1.26/lib/debugobjects.c 2016-06-19 15:30:58.719298583 +0200
  23905. @@ -309,7 +309,10 @@
  23906. struct debug_obj *obj;
  23907. unsigned long flags;
  23908. - fill_pool();
  23909. +#ifdef CONFIG_PREEMPT_RT_FULL
  23910. + if (preempt_count() == 0 && !irqs_disabled())
  23911. +#endif
  23912. + fill_pool();
  23913. db = get_bucket((unsigned long) addr);
  23914. diff -Nur linux-4.1.26.orig/lib/dump_stack.c linux-4.1.26/lib/dump_stack.c
  23915. --- linux-4.1.26.orig/lib/dump_stack.c 2016-06-07 01:13:11.000000000 +0200
  23916. +++ linux-4.1.26/lib/dump_stack.c 2016-06-19 15:30:58.719298583 +0200
  23917. @@ -8,6 +8,7 @@
  23918. #include <linux/sched.h>
  23919. #include <linux/smp.h>
  23920. #include <linux/atomic.h>
  23921. +#include <linux/locallock.h>
  23922. static void __dump_stack(void)
  23923. {
  23924. diff -Nur linux-4.1.26.orig/lib/idr.c linux-4.1.26/lib/idr.c
  23925. --- linux-4.1.26.orig/lib/idr.c 2016-06-07 01:13:11.000000000 +0200
  23926. +++ linux-4.1.26/lib/idr.c 2016-06-19 15:30:58.723298738 +0200
  23927. @@ -30,6 +30,7 @@
  23928. #include <linux/idr.h>
  23929. #include <linux/spinlock.h>
  23930. #include <linux/percpu.h>
  23931. +#include <linux/locallock.h>
  23932. #define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
  23933. #define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
  23934. @@ -366,6 +367,35 @@
  23935. idr_mark_full(pa, id);
  23936. }
  23937. +#ifdef CONFIG_PREEMPT_RT_FULL
  23938. +static DEFINE_LOCAL_IRQ_LOCK(idr_lock);
  23939. +
  23940. +static inline void idr_preload_lock(void)
  23941. +{
  23942. + local_lock(idr_lock);
  23943. +}
  23944. +
  23945. +static inline void idr_preload_unlock(void)
  23946. +{
  23947. + local_unlock(idr_lock);
  23948. +}
  23949. +
  23950. +void idr_preload_end(void)
  23951. +{
  23952. + idr_preload_unlock();
  23953. +}
  23954. +EXPORT_SYMBOL(idr_preload_end);
  23955. +#else
  23956. +static inline void idr_preload_lock(void)
  23957. +{
  23958. + preempt_disable();
  23959. +}
  23960. +
  23961. +static inline void idr_preload_unlock(void)
  23962. +{
  23963. + preempt_enable();
  23964. +}
  23965. +#endif
  23966. /**
  23967. * idr_preload - preload for idr_alloc()
  23968. @@ -401,7 +431,7 @@
  23969. WARN_ON_ONCE(in_interrupt());
  23970. might_sleep_if(gfp_mask & __GFP_WAIT);
  23971. - preempt_disable();
  23972. + idr_preload_lock();
  23973. /*
  23974. * idr_alloc() is likely to succeed w/o full idr_layer buffer and
  23975. @@ -413,9 +443,9 @@
  23976. while (__this_cpu_read(idr_preload_cnt) < MAX_IDR_FREE) {
  23977. struct idr_layer *new;
  23978. - preempt_enable();
  23979. + idr_preload_unlock();
  23980. new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
  23981. - preempt_disable();
  23982. + idr_preload_lock();
  23983. if (!new)
  23984. break;
  23985. diff -Nur linux-4.1.26.orig/lib/Kconfig linux-4.1.26/lib/Kconfig
  23986. --- linux-4.1.26.orig/lib/Kconfig 2016-06-07 01:13:11.000000000 +0200
  23987. +++ linux-4.1.26/lib/Kconfig 2016-06-19 15:30:58.719298583 +0200
  23988. @@ -391,6 +391,7 @@
  23989. config CPUMASK_OFFSTACK
  23990. bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS
  23991. + depends on !PREEMPT_RT_FULL
  23992. help
  23993. Use dynamic allocation for cpumask_var_t, instead of putting
  23994. them on the stack. This is a bit more expensive, but avoids
  23995. diff -Nur linux-4.1.26.orig/lib/locking-selftest.c linux-4.1.26/lib/locking-selftest.c
  23996. --- linux-4.1.26.orig/lib/locking-selftest.c 2016-06-07 01:13:11.000000000 +0200
  23997. +++ linux-4.1.26/lib/locking-selftest.c 2016-06-19 15:30:58.723298738 +0200
  23998. @@ -590,6 +590,8 @@
  23999. #include "locking-selftest-spin-hardirq.h"
  24000. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  24001. +#ifndef CONFIG_PREEMPT_RT_FULL
  24002. +
  24003. #include "locking-selftest-rlock-hardirq.h"
  24004. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  24005. @@ -605,9 +607,12 @@
  24006. #include "locking-selftest-wlock-softirq.h"
  24007. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  24008. +#endif
  24009. +
  24010. #undef E1
  24011. #undef E2
  24012. +#ifndef CONFIG_PREEMPT_RT_FULL
  24013. /*
  24014. * Enabling hardirqs with a softirq-safe lock held:
  24015. */
  24016. @@ -640,6 +645,8 @@
  24017. #undef E1
  24018. #undef E2
  24019. +#endif
  24020. +
  24021. /*
  24022. * Enabling irqs with an irq-safe lock held:
  24023. */
  24024. @@ -663,6 +670,8 @@
  24025. #include "locking-selftest-spin-hardirq.h"
  24026. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  24027. +#ifndef CONFIG_PREEMPT_RT_FULL
  24028. +
  24029. #include "locking-selftest-rlock-hardirq.h"
  24030. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  24031. @@ -678,6 +687,8 @@
  24032. #include "locking-selftest-wlock-softirq.h"
  24033. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  24034. +#endif
  24035. +
  24036. #undef E1
  24037. #undef E2
  24038. @@ -709,6 +720,8 @@
  24039. #include "locking-selftest-spin-hardirq.h"
  24040. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  24041. +#ifndef CONFIG_PREEMPT_RT_FULL
  24042. +
  24043. #include "locking-selftest-rlock-hardirq.h"
  24044. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  24045. @@ -724,6 +737,8 @@
  24046. #include "locking-selftest-wlock-softirq.h"
  24047. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  24048. +#endif
  24049. +
  24050. #undef E1
  24051. #undef E2
  24052. #undef E3
  24053. @@ -757,6 +772,8 @@
  24054. #include "locking-selftest-spin-hardirq.h"
  24055. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  24056. +#ifndef CONFIG_PREEMPT_RT_FULL
  24057. +
  24058. #include "locking-selftest-rlock-hardirq.h"
  24059. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  24060. @@ -772,10 +789,14 @@
  24061. #include "locking-selftest-wlock-softirq.h"
  24062. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  24063. +#endif
  24064. +
  24065. #undef E1
  24066. #undef E2
  24067. #undef E3
  24068. +#ifndef CONFIG_PREEMPT_RT_FULL
  24069. +
  24070. /*
  24071. * read-lock / write-lock irq inversion.
  24072. *
  24073. @@ -838,6 +859,10 @@
  24074. #undef E2
  24075. #undef E3
  24076. +#endif
  24077. +
  24078. +#ifndef CONFIG_PREEMPT_RT_FULL
  24079. +
  24080. /*
  24081. * read-lock / write-lock recursion that is actually safe.
  24082. */
  24083. @@ -876,6 +901,8 @@
  24084. #undef E2
  24085. #undef E3
  24086. +#endif
  24087. +
  24088. /*
  24089. * read-lock / write-lock recursion that is unsafe.
  24090. */
  24091. @@ -1858,6 +1885,7 @@
  24092. printk(" --------------------------------------------------------------------------\n");
  24093. +#ifndef CONFIG_PREEMPT_RT_FULL
  24094. /*
  24095. * irq-context testcases:
  24096. */
  24097. @@ -1870,6 +1898,28 @@
  24098. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  24099. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  24100. +#else
  24101. + /* On -rt, we only do hardirq context test for raw spinlock */
  24102. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 12);
  24103. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 21);
  24104. +
  24105. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 12);
  24106. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 21);
  24107. +
  24108. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 123);
  24109. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 132);
  24110. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 213);
  24111. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 231);
  24112. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 312);
  24113. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 321);
  24114. +
  24115. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 123);
  24116. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 132);
  24117. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 213);
  24118. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 231);
  24119. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 312);
  24120. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 321);
  24121. +#endif
  24122. ww_tests();
  24123. diff -Nur linux-4.1.26.orig/lib/percpu_ida.c linux-4.1.26/lib/percpu_ida.c
  24124. --- linux-4.1.26.orig/lib/percpu_ida.c 2016-06-07 01:13:11.000000000 +0200
  24125. +++ linux-4.1.26/lib/percpu_ida.c 2016-06-19 15:30:58.723298738 +0200
  24126. @@ -26,6 +26,9 @@
  24127. #include <linux/string.h>
  24128. #include <linux/spinlock.h>
  24129. #include <linux/percpu_ida.h>
  24130. +#include <linux/locallock.h>
  24131. +
  24132. +static DEFINE_LOCAL_IRQ_LOCK(irq_off_lock);
  24133. struct percpu_ida_cpu {
  24134. /*
  24135. @@ -148,13 +151,13 @@
  24136. unsigned long flags;
  24137. int tag;
  24138. - local_irq_save(flags);
  24139. + local_lock_irqsave(irq_off_lock, flags);
  24140. tags = this_cpu_ptr(pool->tag_cpu);
  24141. /* Fastpath */
  24142. tag = alloc_local_tag(tags);
  24143. if (likely(tag >= 0)) {
  24144. - local_irq_restore(flags);
  24145. + local_unlock_irqrestore(irq_off_lock, flags);
  24146. return tag;
  24147. }
  24148. @@ -173,6 +176,7 @@
  24149. if (!tags->nr_free)
  24150. alloc_global_tags(pool, tags);
  24151. +
  24152. if (!tags->nr_free)
  24153. steal_tags(pool, tags);
  24154. @@ -184,7 +188,7 @@
  24155. }
  24156. spin_unlock(&pool->lock);
  24157. - local_irq_restore(flags);
  24158. + local_unlock_irqrestore(irq_off_lock, flags);
  24159. if (tag >= 0 || state == TASK_RUNNING)
  24160. break;
  24161. @@ -196,7 +200,7 @@
  24162. schedule();
  24163. - local_irq_save(flags);
  24164. + local_lock_irqsave(irq_off_lock, flags);
  24165. tags = this_cpu_ptr(pool->tag_cpu);
  24166. }
  24167. if (state != TASK_RUNNING)
  24168. @@ -221,7 +225,7 @@
  24169. BUG_ON(tag >= pool->nr_tags);
  24170. - local_irq_save(flags);
  24171. + local_lock_irqsave(irq_off_lock, flags);
  24172. tags = this_cpu_ptr(pool->tag_cpu);
  24173. spin_lock(&tags->lock);
  24174. @@ -253,7 +257,7 @@
  24175. spin_unlock(&pool->lock);
  24176. }
  24177. - local_irq_restore(flags);
  24178. + local_unlock_irqrestore(irq_off_lock, flags);
  24179. }
  24180. EXPORT_SYMBOL_GPL(percpu_ida_free);
  24181. @@ -345,7 +349,7 @@
  24182. struct percpu_ida_cpu *remote;
  24183. unsigned cpu, i, err = 0;
  24184. - local_irq_save(flags);
  24185. + local_lock_irqsave(irq_off_lock, flags);
  24186. for_each_possible_cpu(cpu) {
  24187. remote = per_cpu_ptr(pool->tag_cpu, cpu);
  24188. spin_lock(&remote->lock);
  24189. @@ -367,7 +371,7 @@
  24190. }
  24191. spin_unlock(&pool->lock);
  24192. out:
  24193. - local_irq_restore(flags);
  24194. + local_unlock_irqrestore(irq_off_lock, flags);
  24195. return err;
  24196. }
  24197. EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
  24198. diff -Nur linux-4.1.26.orig/lib/radix-tree.c linux-4.1.26/lib/radix-tree.c
  24199. --- linux-4.1.26.orig/lib/radix-tree.c 2016-06-07 01:13:11.000000000 +0200
  24200. +++ linux-4.1.26/lib/radix-tree.c 2016-06-19 15:30:58.723298738 +0200
  24201. @@ -195,12 +195,13 @@
  24202. * succeed in getting a node here (and never reach
  24203. * kmem_cache_alloc)
  24204. */
  24205. - rtp = this_cpu_ptr(&radix_tree_preloads);
  24206. + rtp = &get_cpu_var(radix_tree_preloads);
  24207. if (rtp->nr) {
  24208. ret = rtp->nodes[rtp->nr - 1];
  24209. rtp->nodes[rtp->nr - 1] = NULL;
  24210. rtp->nr--;
  24211. }
  24212. + put_cpu_var(radix_tree_preloads);
  24213. /*
  24214. * Update the allocation stack trace as this is more useful
  24215. * for debugging.
  24216. @@ -240,6 +241,7 @@
  24217. call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
  24218. }
  24219. +#ifndef CONFIG_PREEMPT_RT_FULL
  24220. /*
  24221. * Load up this CPU's radix_tree_node buffer with sufficient objects to
  24222. * ensure that the addition of a single element in the tree cannot fail. On
  24223. @@ -305,6 +307,7 @@
  24224. return 0;
  24225. }
  24226. EXPORT_SYMBOL(radix_tree_maybe_preload);
  24227. +#endif
  24228. /*
  24229. * Return the maximum key which can be store into a
  24230. diff -Nur linux-4.1.26.orig/lib/scatterlist.c linux-4.1.26/lib/scatterlist.c
  24231. --- linux-4.1.26.orig/lib/scatterlist.c 2016-06-07 01:13:11.000000000 +0200
  24232. +++ linux-4.1.26/lib/scatterlist.c 2016-06-19 15:30:58.723298738 +0200
  24233. @@ -592,7 +592,7 @@
  24234. flush_kernel_dcache_page(miter->page);
  24235. if (miter->__flags & SG_MITER_ATOMIC) {
  24236. - WARN_ON_ONCE(preemptible());
  24237. + WARN_ON_ONCE(!pagefault_disabled());
  24238. kunmap_atomic(miter->addr);
  24239. } else
  24240. kunmap(miter->page);
  24241. @@ -637,7 +637,7 @@
  24242. if (!sg_miter_skip(&miter, skip))
  24243. return false;
  24244. - local_irq_save(flags);
  24245. + local_irq_save_nort(flags);
  24246. while (sg_miter_next(&miter) && offset < buflen) {
  24247. unsigned int len;
  24248. @@ -654,7 +654,7 @@
  24249. sg_miter_stop(&miter);
  24250. - local_irq_restore(flags);
  24251. + local_irq_restore_nort(flags);
  24252. return offset;
  24253. }
  24254. diff -Nur linux-4.1.26.orig/lib/smp_processor_id.c linux-4.1.26/lib/smp_processor_id.c
  24255. --- linux-4.1.26.orig/lib/smp_processor_id.c 2016-06-07 01:13:11.000000000 +0200
  24256. +++ linux-4.1.26/lib/smp_processor_id.c 2016-06-19 15:30:58.723298738 +0200
  24257. @@ -39,8 +39,9 @@
  24258. if (!printk_ratelimit())
  24259. goto out_enable;
  24260. - printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
  24261. - what1, what2, preempt_count() - 1, current->comm, current->pid);
  24262. + printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x %08x] code: %s/%d\n",
  24263. + what1, what2, preempt_count() - 1, __migrate_disabled(current),
  24264. + current->comm, current->pid);
  24265. print_symbol("caller is %s\n", (long)__builtin_return_address(0));
  24266. dump_stack();
  24267. diff -Nur linux-4.1.26.orig/lib/strnlen_user.c linux-4.1.26/lib/strnlen_user.c
  24268. --- linux-4.1.26.orig/lib/strnlen_user.c 2016-06-07 01:13:11.000000000 +0200
  24269. +++ linux-4.1.26/lib/strnlen_user.c 2016-06-19 15:30:58.723298738 +0200
  24270. @@ -85,7 +85,8 @@
  24271. * @str: The string to measure.
  24272. * @count: Maximum count (including NUL character)
  24273. *
  24274. - * Context: User context only. This function may sleep.
  24275. + * Context: User context only. This function may sleep if pagefaults are
  24276. + * enabled.
  24277. *
  24278. * Get the size of a NUL-terminated string in user space.
  24279. *
  24280. @@ -121,7 +122,8 @@
  24281. * strlen_user: - Get the size of a user string INCLUDING final NUL.
  24282. * @str: The string to measure.
  24283. *
  24284. - * Context: User context only. This function may sleep.
  24285. + * Context: User context only. This function may sleep if pagefaults are
  24286. + * enabled.
  24287. *
  24288. * Get the size of a NUL-terminated string in user space.
  24289. *
  24290. diff -Nur linux-4.1.26.orig/mm/compaction.c linux-4.1.26/mm/compaction.c
  24291. --- linux-4.1.26.orig/mm/compaction.c 2016-06-07 01:13:11.000000000 +0200
  24292. +++ linux-4.1.26/mm/compaction.c 2016-06-19 15:30:58.823302594 +0200
  24293. @@ -1398,10 +1398,12 @@
  24294. cc->migrate_pfn & ~((1UL << cc->order) - 1);
  24295. if (last_migrated_pfn < current_block_start) {
  24296. - cpu = get_cpu();
  24297. + cpu = get_cpu_light();
  24298. + local_lock_irq(swapvec_lock);
  24299. lru_add_drain_cpu(cpu);
  24300. + local_unlock_irq(swapvec_lock);
  24301. drain_local_pages(zone);
  24302. - put_cpu();
  24303. + put_cpu_light();
  24304. /* No more flushing until we migrate again */
  24305. last_migrated_pfn = 0;
  24306. }
  24307. diff -Nur linux-4.1.26.orig/mm/filemap.c linux-4.1.26/mm/filemap.c
  24308. --- linux-4.1.26.orig/mm/filemap.c 2016-06-07 01:13:11.000000000 +0200
  24309. +++ linux-4.1.26/mm/filemap.c 2016-06-19 15:30:58.823302594 +0200
  24310. @@ -167,7 +167,9 @@
  24311. if (!workingset_node_pages(node) &&
  24312. list_empty(&node->private_list)) {
  24313. node->private_data = mapping;
  24314. - list_lru_add(&workingset_shadow_nodes, &node->private_list);
  24315. + local_lock(workingset_shadow_lock);
  24316. + list_lru_add(&__workingset_shadow_nodes, &node->private_list);
  24317. + local_unlock(workingset_shadow_lock);
  24318. }
  24319. }
  24320. @@ -533,9 +535,12 @@
  24321. * node->private_list is protected by
  24322. * mapping->tree_lock.
  24323. */
  24324. - if (!list_empty(&node->private_list))
  24325. - list_lru_del(&workingset_shadow_nodes,
  24326. + if (!list_empty(&node->private_list)) {
  24327. + local_lock(workingset_shadow_lock);
  24328. + list_lru_del(&__workingset_shadow_nodes,
  24329. &node->private_list);
  24330. + local_unlock(workingset_shadow_lock);
  24331. + }
  24332. }
  24333. return 0;
  24334. }
  24335. diff -Nur linux-4.1.26.orig/mm/highmem.c linux-4.1.26/mm/highmem.c
  24336. --- linux-4.1.26.orig/mm/highmem.c 2016-06-07 01:13:11.000000000 +0200
  24337. +++ linux-4.1.26/mm/highmem.c 2016-06-19 15:30:58.823302594 +0200
  24338. @@ -29,10 +29,11 @@
  24339. #include <linux/kgdb.h>
  24340. #include <asm/tlbflush.h>
  24341. -
  24342. +#ifndef CONFIG_PREEMPT_RT_FULL
  24343. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  24344. DEFINE_PER_CPU(int, __kmap_atomic_idx);
  24345. #endif
  24346. +#endif
  24347. /*
  24348. * Virtual_count is not a pure "count".
  24349. @@ -107,8 +108,9 @@
  24350. unsigned long totalhigh_pages __read_mostly;
  24351. EXPORT_SYMBOL(totalhigh_pages);
  24352. -
  24353. +#ifndef CONFIG_PREEMPT_RT_FULL
  24354. EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
  24355. +#endif
  24356. unsigned int nr_free_highpages (void)
  24357. {
  24358. diff -Nur linux-4.1.26.orig/mm/Kconfig linux-4.1.26/mm/Kconfig
  24359. --- linux-4.1.26.orig/mm/Kconfig 2016-06-07 01:13:11.000000000 +0200
  24360. +++ linux-4.1.26/mm/Kconfig 2016-06-19 15:30:58.823302594 +0200
  24361. @@ -409,7 +409,7 @@
  24362. config TRANSPARENT_HUGEPAGE
  24363. bool "Transparent Hugepage Support"
  24364. - depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE
  24365. + depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE && !PREEMPT_RT_FULL
  24366. select COMPACTION
  24367. help
  24368. Transparent Hugepages allows the kernel to use huge pages and
  24369. diff -Nur linux-4.1.26.orig/mm/memcontrol.c linux-4.1.26/mm/memcontrol.c
  24370. --- linux-4.1.26.orig/mm/memcontrol.c 2016-06-07 01:13:11.000000000 +0200
  24371. +++ linux-4.1.26/mm/memcontrol.c 2016-06-19 15:30:58.827302748 +0200
  24372. @@ -66,6 +66,8 @@
  24373. #include <net/sock.h>
  24374. #include <net/ip.h>
  24375. #include <net/tcp_memcontrol.h>
  24376. +#include <linux/locallock.h>
  24377. +
  24378. #include "slab.h"
  24379. #include <asm/uaccess.h>
  24380. @@ -85,6 +87,7 @@
  24381. #define do_swap_account 0
  24382. #endif
  24383. +static DEFINE_LOCAL_IRQ_LOCK(event_lock);
  24384. static const char * const mem_cgroup_stat_names[] = {
  24385. "cache",
  24386. "rss",
  24387. @@ -2124,14 +2127,17 @@
  24388. */
  24389. static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
  24390. {
  24391. - struct memcg_stock_pcp *stock = &get_cpu_var(memcg_stock);
  24392. + struct memcg_stock_pcp *stock;
  24393. + int cpu = get_cpu_light();
  24394. +
  24395. + stock = &per_cpu(memcg_stock, cpu);
  24396. if (stock->cached != memcg) { /* reset if necessary */
  24397. drain_stock(stock);
  24398. stock->cached = memcg;
  24399. }
  24400. stock->nr_pages += nr_pages;
  24401. - put_cpu_var(memcg_stock);
  24402. + put_cpu_light();
  24403. }
  24404. /*
  24405. @@ -2147,7 +2153,7 @@
  24406. return;
  24407. /* Notify other cpus that system-wide "drain" is running */
  24408. get_online_cpus();
  24409. - curcpu = get_cpu();
  24410. + curcpu = get_cpu_light();
  24411. for_each_online_cpu(cpu) {
  24412. struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
  24413. struct mem_cgroup *memcg;
  24414. @@ -2164,7 +2170,7 @@
  24415. schedule_work_on(cpu, &stock->work);
  24416. }
  24417. }
  24418. - put_cpu();
  24419. + put_cpu_light();
  24420. put_online_cpus();
  24421. mutex_unlock(&percpu_charge_mutex);
  24422. }
  24423. @@ -4803,12 +4809,12 @@
  24424. ret = 0;
  24425. - local_irq_disable();
  24426. + local_lock_irq(event_lock);
  24427. mem_cgroup_charge_statistics(to, page, nr_pages);
  24428. memcg_check_events(to, page);
  24429. mem_cgroup_charge_statistics(from, page, -nr_pages);
  24430. memcg_check_events(from, page);
  24431. - local_irq_enable();
  24432. + local_unlock_irq(event_lock);
  24433. out_unlock:
  24434. unlock_page(page);
  24435. out:
  24436. @@ -5551,10 +5557,10 @@
  24437. VM_BUG_ON_PAGE(!PageTransHuge(page), page);
  24438. }
  24439. - local_irq_disable();
  24440. + local_lock_irq(event_lock);
  24441. mem_cgroup_charge_statistics(memcg, page, nr_pages);
  24442. memcg_check_events(memcg, page);
  24443. - local_irq_enable();
  24444. + local_unlock_irq(event_lock);
  24445. if (do_swap_account && PageSwapCache(page)) {
  24446. swp_entry_t entry = { .val = page_private(page) };
  24447. @@ -5610,14 +5616,14 @@
  24448. memcg_oom_recover(memcg);
  24449. }
  24450. - local_irq_save(flags);
  24451. + local_lock_irqsave(event_lock, flags);
  24452. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS], nr_anon);
  24453. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_CACHE], nr_file);
  24454. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS_HUGE], nr_huge);
  24455. __this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT], pgpgout);
  24456. __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
  24457. memcg_check_events(memcg, dummy_page);
  24458. - local_irq_restore(flags);
  24459. + local_unlock_irqrestore(event_lock, flags);
  24460. if (!mem_cgroup_is_root(memcg))
  24461. css_put_many(&memcg->css, nr_pages);
  24462. @@ -5821,6 +5827,7 @@
  24463. {
  24464. struct mem_cgroup *memcg;
  24465. unsigned short oldid;
  24466. + unsigned long flags;
  24467. VM_BUG_ON_PAGE(PageLRU(page), page);
  24468. VM_BUG_ON_PAGE(page_count(page), page);
  24469. @@ -5843,9 +5850,11 @@
  24470. if (!mem_cgroup_is_root(memcg))
  24471. page_counter_uncharge(&memcg->memory, 1);
  24472. + local_lock_irqsave(event_lock, flags);
  24473. /* Caller disabled preemption with mapping->tree_lock */
  24474. mem_cgroup_charge_statistics(memcg, page, -1);
  24475. memcg_check_events(memcg, page);
  24476. + local_unlock_irqrestore(event_lock, flags);
  24477. }
  24478. /**
  24479. diff -Nur linux-4.1.26.orig/mm/memory.c linux-4.1.26/mm/memory.c
  24480. --- linux-4.1.26.orig/mm/memory.c 2016-06-07 01:13:11.000000000 +0200
  24481. +++ linux-4.1.26/mm/memory.c 2016-06-19 15:30:58.827302748 +0200
  24482. @@ -3753,7 +3753,7 @@
  24483. }
  24484. #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)
  24485. -void might_fault(void)
  24486. +void __might_fault(const char *file, int line)
  24487. {
  24488. /*
  24489. * Some code (nfs/sunrpc) uses socket ops on kernel memory while
  24490. @@ -3763,21 +3763,15 @@
  24491. */
  24492. if (segment_eq(get_fs(), KERNEL_DS))
  24493. return;
  24494. -
  24495. - /*
  24496. - * it would be nicer only to annotate paths which are not under
  24497. - * pagefault_disable, however that requires a larger audit and
  24498. - * providing helpers like get_user_atomic.
  24499. - */
  24500. - if (in_atomic())
  24501. + if (pagefault_disabled())
  24502. return;
  24503. -
  24504. - __might_sleep(__FILE__, __LINE__, 0);
  24505. -
  24506. + __might_sleep(file, line, 0);
  24507. +#if defined(CONFIG_DEBUG_ATOMIC_SLEEP)
  24508. if (current->mm)
  24509. might_lock_read(&current->mm->mmap_sem);
  24510. +#endif
  24511. }
  24512. -EXPORT_SYMBOL(might_fault);
  24513. +EXPORT_SYMBOL(__might_fault);
  24514. #endif
  24515. #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
  24516. diff -Nur linux-4.1.26.orig/mm/mmu_context.c linux-4.1.26/mm/mmu_context.c
  24517. --- linux-4.1.26.orig/mm/mmu_context.c 2016-06-07 01:13:11.000000000 +0200
  24518. +++ linux-4.1.26/mm/mmu_context.c 2016-06-19 15:30:58.827302748 +0200
  24519. @@ -23,6 +23,7 @@
  24520. struct task_struct *tsk = current;
  24521. task_lock(tsk);
  24522. + preempt_disable_rt();
  24523. active_mm = tsk->active_mm;
  24524. if (active_mm != mm) {
  24525. atomic_inc(&mm->mm_count);
  24526. @@ -30,6 +31,7 @@
  24527. }
  24528. tsk->mm = mm;
  24529. switch_mm(active_mm, mm, tsk);
  24530. + preempt_enable_rt();
  24531. task_unlock(tsk);
  24532. #ifdef finish_arch_post_lock_switch
  24533. finish_arch_post_lock_switch();
  24534. diff -Nur linux-4.1.26.orig/mm/page_alloc.c linux-4.1.26/mm/page_alloc.c
  24535. --- linux-4.1.26.orig/mm/page_alloc.c 2016-06-07 01:13:11.000000000 +0200
  24536. +++ linux-4.1.26/mm/page_alloc.c 2016-06-19 15:30:58.827302748 +0200
  24537. @@ -60,6 +60,7 @@
  24538. #include <linux/page_ext.h>
  24539. #include <linux/hugetlb.h>
  24540. #include <linux/sched/rt.h>
  24541. +#include <linux/locallock.h>
  24542. #include <linux/page_owner.h>
  24543. #include <asm/sections.h>
  24544. @@ -233,6 +234,18 @@
  24545. EXPORT_SYMBOL(nr_online_nodes);
  24546. #endif
  24547. +static DEFINE_LOCAL_IRQ_LOCK(pa_lock);
  24548. +
  24549. +#ifdef CONFIG_PREEMPT_RT_BASE
  24550. +# define cpu_lock_irqsave(cpu, flags) \
  24551. + local_lock_irqsave_on(pa_lock, flags, cpu)
  24552. +# define cpu_unlock_irqrestore(cpu, flags) \
  24553. + local_unlock_irqrestore_on(pa_lock, flags, cpu)
  24554. +#else
  24555. +# define cpu_lock_irqsave(cpu, flags) local_irq_save(flags)
  24556. +# define cpu_unlock_irqrestore(cpu, flags) local_irq_restore(flags)
  24557. +#endif
  24558. +
  24559. int page_group_by_mobility_disabled __read_mostly;
  24560. void set_pageblock_migratetype(struct page *page, int migratetype)
  24561. @@ -701,7 +714,7 @@
  24562. }
  24563. /*
  24564. - * Frees a number of pages from the PCP lists
  24565. + * Frees a number of pages which have been collected from the pcp lists.
  24566. * Assumes all pages on list are in same zone, and of same order.
  24567. * count is the number of pages to free.
  24568. *
  24569. @@ -712,18 +725,51 @@
  24570. * pinned" detection logic.
  24571. */
  24572. static void free_pcppages_bulk(struct zone *zone, int count,
  24573. - struct per_cpu_pages *pcp)
  24574. + struct list_head *list)
  24575. {
  24576. - int migratetype = 0;
  24577. - int batch_free = 0;
  24578. int to_free = count;
  24579. unsigned long nr_scanned;
  24580. + unsigned long flags;
  24581. +
  24582. + spin_lock_irqsave(&zone->lock, flags);
  24583. - spin_lock(&zone->lock);
  24584. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  24585. if (nr_scanned)
  24586. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  24587. + while (!list_empty(list)) {
  24588. + struct page *page = list_first_entry(list, struct page, lru);
  24589. + int mt; /* migratetype of the to-be-freed page */
  24590. +
  24591. + /* must delete as __free_one_page list manipulates */
  24592. + list_del(&page->lru);
  24593. +
  24594. + mt = get_freepage_migratetype(page);
  24595. + if (unlikely(has_isolate_pageblock(zone)))
  24596. + mt = get_pageblock_migratetype(page);
  24597. +
  24598. + /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
  24599. + __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  24600. + trace_mm_page_pcpu_drain(page, 0, mt);
  24601. + to_free--;
  24602. + }
  24603. + WARN_ON(to_free != 0);
  24604. + spin_unlock_irqrestore(&zone->lock, flags);
  24605. +}
  24606. +
  24607. +/*
  24608. + * Moves a number of pages from the PCP lists to free list which
  24609. + * is freed outside of the locked region.
  24610. + *
  24611. + * Assumes all pages on list are in same zone, and of same order.
  24612. + * count is the number of pages to free.
  24613. + */
  24614. +static void isolate_pcp_pages(int to_free, struct per_cpu_pages *src,
  24615. + struct list_head *dst)
  24616. +{
  24617. + int migratetype = 0;
  24618. + int batch_free = 0;
  24619. +
  24620. while (to_free) {
  24621. struct page *page;
  24622. struct list_head *list;
  24623. @@ -739,7 +785,7 @@
  24624. batch_free++;
  24625. if (++migratetype == MIGRATE_PCPTYPES)
  24626. migratetype = 0;
  24627. - list = &pcp->lists[migratetype];
  24628. + list = &src->lists[migratetype];
  24629. } while (list_empty(list));
  24630. /* This is the only non-empty list. Free them all. */
  24631. @@ -747,21 +793,11 @@
  24632. batch_free = to_free;
  24633. do {
  24634. - int mt; /* migratetype of the to-be-freed page */
  24635. -
  24636. - page = list_entry(list->prev, struct page, lru);
  24637. - /* must delete as __free_one_page list manipulates */
  24638. + page = list_last_entry(list, struct page, lru);
  24639. list_del(&page->lru);
  24640. - mt = get_freepage_migratetype(page);
  24641. - if (unlikely(has_isolate_pageblock(zone)))
  24642. - mt = get_pageblock_migratetype(page);
  24643. -
  24644. - /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
  24645. - __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  24646. - trace_mm_page_pcpu_drain(page, 0, mt);
  24647. + list_add(&page->lru, dst);
  24648. } while (--to_free && --batch_free && !list_empty(list));
  24649. }
  24650. - spin_unlock(&zone->lock);
  24651. }
  24652. static void free_one_page(struct zone *zone,
  24653. @@ -770,7 +806,9 @@
  24654. int migratetype)
  24655. {
  24656. unsigned long nr_scanned;
  24657. - spin_lock(&zone->lock);
  24658. + unsigned long flags;
  24659. +
  24660. + spin_lock_irqsave(&zone->lock, flags);
  24661. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  24662. if (nr_scanned)
  24663. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  24664. @@ -780,7 +818,7 @@
  24665. migratetype = get_pfnblock_migratetype(page, pfn);
  24666. }
  24667. __free_one_page(page, pfn, zone, order, migratetype);
  24668. - spin_unlock(&zone->lock);
  24669. + spin_unlock_irqrestore(&zone->lock, flags);
  24670. }
  24671. static int free_tail_pages_check(struct page *head_page, struct page *page)
  24672. @@ -845,11 +883,11 @@
  24673. return;
  24674. migratetype = get_pfnblock_migratetype(page, pfn);
  24675. - local_irq_save(flags);
  24676. + local_lock_irqsave(pa_lock, flags);
  24677. __count_vm_events(PGFREE, 1 << order);
  24678. set_freepage_migratetype(page, migratetype);
  24679. free_one_page(page_zone(page), page, pfn, order, migratetype);
  24680. - local_irq_restore(flags);
  24681. + local_unlock_irqrestore(pa_lock, flags);
  24682. }
  24683. void __init __free_pages_bootmem(struct page *page, unsigned long pfn,
  24684. @@ -1396,16 +1434,18 @@
  24685. void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
  24686. {
  24687. unsigned long flags;
  24688. + LIST_HEAD(dst);
  24689. int to_drain, batch;
  24690. - local_irq_save(flags);
  24691. + local_lock_irqsave(pa_lock, flags);
  24692. batch = READ_ONCE(pcp->batch);
  24693. to_drain = min(pcp->count, batch);
  24694. if (to_drain > 0) {
  24695. - free_pcppages_bulk(zone, to_drain, pcp);
  24696. + isolate_pcp_pages(to_drain, pcp, &dst);
  24697. pcp->count -= to_drain;
  24698. }
  24699. - local_irq_restore(flags);
  24700. + local_unlock_irqrestore(pa_lock, flags);
  24701. + free_pcppages_bulk(zone, to_drain, &dst);
  24702. }
  24703. #endif
  24704. @@ -1421,16 +1461,21 @@
  24705. unsigned long flags;
  24706. struct per_cpu_pageset *pset;
  24707. struct per_cpu_pages *pcp;
  24708. + LIST_HEAD(dst);
  24709. + int count;
  24710. - local_irq_save(flags);
  24711. + cpu_lock_irqsave(cpu, flags);
  24712. pset = per_cpu_ptr(zone->pageset, cpu);
  24713. pcp = &pset->pcp;
  24714. - if (pcp->count) {
  24715. - free_pcppages_bulk(zone, pcp->count, pcp);
  24716. + count = pcp->count;
  24717. + if (count) {
  24718. + isolate_pcp_pages(count, pcp, &dst);
  24719. pcp->count = 0;
  24720. }
  24721. - local_irq_restore(flags);
  24722. + cpu_unlock_irqrestore(cpu, flags);
  24723. + if (count)
  24724. + free_pcppages_bulk(zone, count, &dst);
  24725. }
  24726. /*
  24727. @@ -1516,8 +1561,17 @@
  24728. else
  24729. cpumask_clear_cpu(cpu, &cpus_with_pcps);
  24730. }
  24731. +#ifndef CONFIG_PREEMPT_RT_BASE
  24732. on_each_cpu_mask(&cpus_with_pcps, (smp_call_func_t) drain_local_pages,
  24733. zone, 1);
  24734. +#else
  24735. + for_each_cpu(cpu, &cpus_with_pcps) {
  24736. + if (zone)
  24737. + drain_pages_zone(cpu, zone);
  24738. + else
  24739. + drain_pages(cpu);
  24740. + }
  24741. +#endif
  24742. }
  24743. #ifdef CONFIG_HIBERNATION
  24744. @@ -1573,7 +1627,7 @@
  24745. migratetype = get_pfnblock_migratetype(page, pfn);
  24746. set_freepage_migratetype(page, migratetype);
  24747. - local_irq_save(flags);
  24748. + local_lock_irqsave(pa_lock, flags);
  24749. __count_vm_event(PGFREE);
  24750. /*
  24751. @@ -1599,12 +1653,17 @@
  24752. pcp->count++;
  24753. if (pcp->count >= pcp->high) {
  24754. unsigned long batch = READ_ONCE(pcp->batch);
  24755. - free_pcppages_bulk(zone, batch, pcp);
  24756. + LIST_HEAD(dst);
  24757. +
  24758. + isolate_pcp_pages(batch, pcp, &dst);
  24759. pcp->count -= batch;
  24760. + local_unlock_irqrestore(pa_lock, flags);
  24761. + free_pcppages_bulk(zone, batch, &dst);
  24762. + return;
  24763. }
  24764. out:
  24765. - local_irq_restore(flags);
  24766. + local_unlock_irqrestore(pa_lock, flags);
  24767. }
  24768. /*
  24769. @@ -1735,7 +1794,7 @@
  24770. struct per_cpu_pages *pcp;
  24771. struct list_head *list;
  24772. - local_irq_save(flags);
  24773. + local_lock_irqsave(pa_lock, flags);
  24774. pcp = &this_cpu_ptr(zone->pageset)->pcp;
  24775. list = &pcp->lists[migratetype];
  24776. if (list_empty(list)) {
  24777. @@ -1767,13 +1826,15 @@
  24778. */
  24779. WARN_ON_ONCE(order > 1);
  24780. }
  24781. - spin_lock_irqsave(&zone->lock, flags);
  24782. + local_spin_lock_irqsave(pa_lock, &zone->lock, flags);
  24783. page = __rmqueue(zone, order, migratetype);
  24784. - spin_unlock(&zone->lock);
  24785. - if (!page)
  24786. + if (!page) {
  24787. + spin_unlock(&zone->lock);
  24788. goto failed;
  24789. + }
  24790. __mod_zone_freepage_state(zone, -(1 << order),
  24791. get_freepage_migratetype(page));
  24792. + spin_unlock(&zone->lock);
  24793. }
  24794. __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
  24795. @@ -1783,13 +1844,13 @@
  24796. __count_zone_vm_events(PGALLOC, zone, 1 << order);
  24797. zone_statistics(preferred_zone, zone, gfp_flags);
  24798. - local_irq_restore(flags);
  24799. + local_unlock_irqrestore(pa_lock, flags);
  24800. VM_BUG_ON_PAGE(bad_range(zone, page), page);
  24801. return page;
  24802. failed:
  24803. - local_irq_restore(flags);
  24804. + local_unlock_irqrestore(pa_lock, flags);
  24805. return NULL;
  24806. }
  24807. @@ -5680,6 +5741,7 @@
  24808. void __init page_alloc_init(void)
  24809. {
  24810. hotcpu_notifier(page_alloc_cpu_notify, 0);
  24811. + local_irq_lock_init(pa_lock);
  24812. }
  24813. /*
  24814. @@ -6575,7 +6637,7 @@
  24815. struct per_cpu_pageset *pset;
  24816. /* avoid races with drain_pages() */
  24817. - local_irq_save(flags);
  24818. + local_lock_irqsave(pa_lock, flags);
  24819. if (zone->pageset != &boot_pageset) {
  24820. for_each_online_cpu(cpu) {
  24821. pset = per_cpu_ptr(zone->pageset, cpu);
  24822. @@ -6584,7 +6646,7 @@
  24823. free_percpu(zone->pageset);
  24824. zone->pageset = &boot_pageset;
  24825. }
  24826. - local_irq_restore(flags);
  24827. + local_unlock_irqrestore(pa_lock, flags);
  24828. }
  24829. #ifdef CONFIG_MEMORY_HOTREMOVE
  24830. diff -Nur linux-4.1.26.orig/mm/slab.h linux-4.1.26/mm/slab.h
  24831. --- linux-4.1.26.orig/mm/slab.h 2016-06-07 01:13:11.000000000 +0200
  24832. +++ linux-4.1.26/mm/slab.h 2016-06-19 15:30:58.827302748 +0200
  24833. @@ -330,7 +330,11 @@
  24834. * The slab lists for all objects.
  24835. */
  24836. struct kmem_cache_node {
  24837. +#ifdef CONFIG_SLUB
  24838. + raw_spinlock_t list_lock;
  24839. +#else
  24840. spinlock_t list_lock;
  24841. +#endif
  24842. #ifdef CONFIG_SLAB
  24843. struct list_head slabs_partial; /* partial list first, better asm code */
  24844. diff -Nur linux-4.1.26.orig/mm/slub.c linux-4.1.26/mm/slub.c
  24845. --- linux-4.1.26.orig/mm/slub.c 2016-06-07 01:13:11.000000000 +0200
  24846. +++ linux-4.1.26/mm/slub.c 2016-06-19 15:30:58.827302748 +0200
  24847. @@ -1069,7 +1069,7 @@
  24848. {
  24849. struct kmem_cache_node *n = get_node(s, page_to_nid(page));
  24850. - spin_lock_irqsave(&n->list_lock, *flags);
  24851. + raw_spin_lock_irqsave(&n->list_lock, *flags);
  24852. slab_lock(page);
  24853. if (!check_slab(s, page))
  24854. @@ -1116,7 +1116,7 @@
  24855. fail:
  24856. slab_unlock(page);
  24857. - spin_unlock_irqrestore(&n->list_lock, *flags);
  24858. + raw_spin_unlock_irqrestore(&n->list_lock, *flags);
  24859. slab_fix(s, "Object at 0x%p not freed", object);
  24860. return NULL;
  24861. }
  24862. @@ -1242,6 +1242,12 @@
  24863. #endif /* CONFIG_SLUB_DEBUG */
  24864. +struct slub_free_list {
  24865. + raw_spinlock_t lock;
  24866. + struct list_head list;
  24867. +};
  24868. +static DEFINE_PER_CPU(struct slub_free_list, slub_free_list);
  24869. +
  24870. /*
  24871. * Hooks for other subsystems that check memory allocations. In a typical
  24872. * production configuration these hooks all should produce no code at all.
  24873. @@ -1306,6 +1312,17 @@
  24874. kasan_slab_free(s, x);
  24875. }
  24876. +static void setup_object(struct kmem_cache *s, struct page *page,
  24877. + void *object)
  24878. +{
  24879. + setup_object_debug(s, page, object);
  24880. + if (unlikely(s->ctor)) {
  24881. + kasan_unpoison_object_data(s, object);
  24882. + s->ctor(object);
  24883. + kasan_poison_object_data(s, object);
  24884. + }
  24885. +}
  24886. +
  24887. /*
  24888. * Slab allocation and freeing
  24889. */
  24890. @@ -1336,10 +1353,17 @@
  24891. struct page *page;
  24892. struct kmem_cache_order_objects oo = s->oo;
  24893. gfp_t alloc_gfp;
  24894. + void *start, *p;
  24895. + int idx, order;
  24896. + bool enableirqs;
  24897. flags &= gfp_allowed_mask;
  24898. - if (flags & __GFP_WAIT)
  24899. + enableirqs = (flags & __GFP_WAIT) != 0;
  24900. +#ifdef CONFIG_PREEMPT_RT_FULL
  24901. + enableirqs |= system_state == SYSTEM_RUNNING;
  24902. +#endif
  24903. + if (enableirqs)
  24904. local_irq_enable();
  24905. flags |= s->allocflags;
  24906. @@ -1359,13 +1383,13 @@
  24907. * Try a lower order alloc if possible
  24908. */
  24909. page = alloc_slab_page(s, alloc_gfp, node, oo);
  24910. -
  24911. - if (page)
  24912. - stat(s, ORDER_FALLBACK);
  24913. + if (unlikely(!page))
  24914. + goto out;
  24915. + stat(s, ORDER_FALLBACK);
  24916. }
  24917. - if (kmemcheck_enabled && page
  24918. - && !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
  24919. + if (kmemcheck_enabled &&
  24920. + !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
  24921. int pages = 1 << oo_order(oo);
  24922. kmemcheck_alloc_shadow(page, oo_order(oo), alloc_gfp, node);
  24923. @@ -1380,51 +1404,9 @@
  24924. kmemcheck_mark_unallocated_pages(page, pages);
  24925. }
  24926. - if (flags & __GFP_WAIT)
  24927. - local_irq_disable();
  24928. - if (!page)
  24929. - return NULL;
  24930. -
  24931. page->objects = oo_objects(oo);
  24932. - mod_zone_page_state(page_zone(page),
  24933. - (s->flags & SLAB_RECLAIM_ACCOUNT) ?
  24934. - NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
  24935. - 1 << oo_order(oo));
  24936. -
  24937. - return page;
  24938. -}
  24939. -
  24940. -static void setup_object(struct kmem_cache *s, struct page *page,
  24941. - void *object)
  24942. -{
  24943. - setup_object_debug(s, page, object);
  24944. - if (unlikely(s->ctor)) {
  24945. - kasan_unpoison_object_data(s, object);
  24946. - s->ctor(object);
  24947. - kasan_poison_object_data(s, object);
  24948. - }
  24949. -}
  24950. -
  24951. -static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
  24952. -{
  24953. - struct page *page;
  24954. - void *start;
  24955. - void *p;
  24956. - int order;
  24957. - int idx;
  24958. -
  24959. - if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
  24960. - pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
  24961. - BUG();
  24962. - }
  24963. -
  24964. - page = allocate_slab(s,
  24965. - flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
  24966. - if (!page)
  24967. - goto out;
  24968. order = compound_order(page);
  24969. - inc_slabs_node(s, page_to_nid(page), page->objects);
  24970. page->slab_cache = s;
  24971. __SetPageSlab(page);
  24972. if (page_is_pfmemalloc(page))
  24973. @@ -1448,10 +1430,34 @@
  24974. page->freelist = start;
  24975. page->inuse = page->objects;
  24976. page->frozen = 1;
  24977. +
  24978. out:
  24979. + if (enableirqs)
  24980. + local_irq_disable();
  24981. + if (!page)
  24982. + return NULL;
  24983. +
  24984. + mod_zone_page_state(page_zone(page),
  24985. + (s->flags & SLAB_RECLAIM_ACCOUNT) ?
  24986. + NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
  24987. + 1 << oo_order(oo));
  24988. +
  24989. + inc_slabs_node(s, page_to_nid(page), page->objects);
  24990. +
  24991. return page;
  24992. }
  24993. +static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
  24994. +{
  24995. + if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
  24996. + pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
  24997. + BUG();
  24998. + }
  24999. +
  25000. + return allocate_slab(s,
  25001. + flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
  25002. +}
  25003. +
  25004. static void __free_slab(struct kmem_cache *s, struct page *page)
  25005. {
  25006. int order = compound_order(page);
  25007. @@ -1483,6 +1489,16 @@
  25008. memcg_uncharge_slab(s, order);
  25009. }
  25010. +static void free_delayed(struct list_head *h)
  25011. +{
  25012. + while(!list_empty(h)) {
  25013. + struct page *page = list_first_entry(h, struct page, lru);
  25014. +
  25015. + list_del(&page->lru);
  25016. + __free_slab(page->slab_cache, page);
  25017. + }
  25018. +}
  25019. +
  25020. #define need_reserve_slab_rcu \
  25021. (sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
  25022. @@ -1517,6 +1533,12 @@
  25023. }
  25024. call_rcu(head, rcu_free_slab);
  25025. + } else if (irqs_disabled()) {
  25026. + struct slub_free_list *f = this_cpu_ptr(&slub_free_list);
  25027. +
  25028. + raw_spin_lock(&f->lock);
  25029. + list_add(&page->lru, &f->list);
  25030. + raw_spin_unlock(&f->lock);
  25031. } else
  25032. __free_slab(s, page);
  25033. }
  25034. @@ -1630,7 +1652,7 @@
  25035. if (!n || !n->nr_partial)
  25036. return NULL;
  25037. - spin_lock(&n->list_lock);
  25038. + raw_spin_lock(&n->list_lock);
  25039. list_for_each_entry_safe(page, page2, &n->partial, lru) {
  25040. void *t;
  25041. @@ -1655,7 +1677,7 @@
  25042. break;
  25043. }
  25044. - spin_unlock(&n->list_lock);
  25045. + raw_spin_unlock(&n->list_lock);
  25046. return object;
  25047. }
  25048. @@ -1901,7 +1923,7 @@
  25049. * that acquire_slab() will see a slab page that
  25050. * is frozen
  25051. */
  25052. - spin_lock(&n->list_lock);
  25053. + raw_spin_lock(&n->list_lock);
  25054. }
  25055. } else {
  25056. m = M_FULL;
  25057. @@ -1912,7 +1934,7 @@
  25058. * slabs from diagnostic functions will not see
  25059. * any frozen slabs.
  25060. */
  25061. - spin_lock(&n->list_lock);
  25062. + raw_spin_lock(&n->list_lock);
  25063. }
  25064. }
  25065. @@ -1947,7 +1969,7 @@
  25066. goto redo;
  25067. if (lock)
  25068. - spin_unlock(&n->list_lock);
  25069. + raw_spin_unlock(&n->list_lock);
  25070. if (m == M_FREE) {
  25071. stat(s, DEACTIVATE_EMPTY);
  25072. @@ -1979,10 +2001,10 @@
  25073. n2 = get_node(s, page_to_nid(page));
  25074. if (n != n2) {
  25075. if (n)
  25076. - spin_unlock(&n->list_lock);
  25077. + raw_spin_unlock(&n->list_lock);
  25078. n = n2;
  25079. - spin_lock(&n->list_lock);
  25080. + raw_spin_lock(&n->list_lock);
  25081. }
  25082. do {
  25083. @@ -2011,7 +2033,7 @@
  25084. }
  25085. if (n)
  25086. - spin_unlock(&n->list_lock);
  25087. + raw_spin_unlock(&n->list_lock);
  25088. while (discard_page) {
  25089. page = discard_page;
  25090. @@ -2050,14 +2072,21 @@
  25091. pobjects = oldpage->pobjects;
  25092. pages = oldpage->pages;
  25093. if (drain && pobjects > s->cpu_partial) {
  25094. + struct slub_free_list *f;
  25095. unsigned long flags;
  25096. + LIST_HEAD(tofree);
  25097. /*
  25098. * partial array is full. Move the existing
  25099. * set to the per node partial list.
  25100. */
  25101. local_irq_save(flags);
  25102. unfreeze_partials(s, this_cpu_ptr(s->cpu_slab));
  25103. + f = this_cpu_ptr(&slub_free_list);
  25104. + raw_spin_lock(&f->lock);
  25105. + list_splice_init(&f->list, &tofree);
  25106. + raw_spin_unlock(&f->lock);
  25107. local_irq_restore(flags);
  25108. + free_delayed(&tofree);
  25109. oldpage = NULL;
  25110. pobjects = 0;
  25111. pages = 0;
  25112. @@ -2129,7 +2158,22 @@
  25113. static void flush_all(struct kmem_cache *s)
  25114. {
  25115. + LIST_HEAD(tofree);
  25116. + int cpu;
  25117. +
  25118. on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1, GFP_ATOMIC);
  25119. + for_each_online_cpu(cpu) {
  25120. + struct slub_free_list *f;
  25121. +
  25122. + if (!has_cpu_slab(cpu, s))
  25123. + continue;
  25124. +
  25125. + f = &per_cpu(slub_free_list, cpu);
  25126. + raw_spin_lock_irq(&f->lock);
  25127. + list_splice_init(&f->list, &tofree);
  25128. + raw_spin_unlock_irq(&f->lock);
  25129. + free_delayed(&tofree);
  25130. + }
  25131. }
  25132. /*
  25133. @@ -2165,10 +2209,10 @@
  25134. unsigned long x = 0;
  25135. struct page *page;
  25136. - spin_lock_irqsave(&n->list_lock, flags);
  25137. + raw_spin_lock_irqsave(&n->list_lock, flags);
  25138. list_for_each_entry(page, &n->partial, lru)
  25139. x += get_count(page);
  25140. - spin_unlock_irqrestore(&n->list_lock, flags);
  25141. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25142. return x;
  25143. }
  25144. #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
  25145. @@ -2305,9 +2349,11 @@
  25146. static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
  25147. unsigned long addr, struct kmem_cache_cpu *c)
  25148. {
  25149. + struct slub_free_list *f;
  25150. void *freelist;
  25151. struct page *page;
  25152. unsigned long flags;
  25153. + LIST_HEAD(tofree);
  25154. local_irq_save(flags);
  25155. #ifdef CONFIG_PREEMPT
  25156. @@ -2375,7 +2421,13 @@
  25157. VM_BUG_ON(!c->page->frozen);
  25158. c->freelist = get_freepointer(s, freelist);
  25159. c->tid = next_tid(c->tid);
  25160. +out:
  25161. + f = this_cpu_ptr(&slub_free_list);
  25162. + raw_spin_lock(&f->lock);
  25163. + list_splice_init(&f->list, &tofree);
  25164. + raw_spin_unlock(&f->lock);
  25165. local_irq_restore(flags);
  25166. + free_delayed(&tofree);
  25167. return freelist;
  25168. new_slab:
  25169. @@ -2392,8 +2444,7 @@
  25170. if (unlikely(!freelist)) {
  25171. slab_out_of_memory(s, gfpflags, node);
  25172. - local_irq_restore(flags);
  25173. - return NULL;
  25174. + goto out;
  25175. }
  25176. page = c->page;
  25177. @@ -2408,8 +2459,7 @@
  25178. deactivate_slab(s, page, get_freepointer(s, freelist));
  25179. c->page = NULL;
  25180. c->freelist = NULL;
  25181. - local_irq_restore(flags);
  25182. - return freelist;
  25183. + goto out;
  25184. }
  25185. /*
  25186. @@ -2593,7 +2643,7 @@
  25187. do {
  25188. if (unlikely(n)) {
  25189. - spin_unlock_irqrestore(&n->list_lock, flags);
  25190. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25191. n = NULL;
  25192. }
  25193. prior = page->freelist;
  25194. @@ -2625,7 +2675,7 @@
  25195. * Otherwise the list_lock will synchronize with
  25196. * other processors updating the list of slabs.
  25197. */
  25198. - spin_lock_irqsave(&n->list_lock, flags);
  25199. + raw_spin_lock_irqsave(&n->list_lock, flags);
  25200. }
  25201. }
  25202. @@ -2667,7 +2717,7 @@
  25203. add_partial(n, page, DEACTIVATE_TO_TAIL);
  25204. stat(s, FREE_ADD_PARTIAL);
  25205. }
  25206. - spin_unlock_irqrestore(&n->list_lock, flags);
  25207. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25208. return;
  25209. slab_empty:
  25210. @@ -2682,7 +2732,7 @@
  25211. remove_full(s, n, page);
  25212. }
  25213. - spin_unlock_irqrestore(&n->list_lock, flags);
  25214. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25215. stat(s, FREE_SLAB);
  25216. discard_slab(s, page);
  25217. }
  25218. @@ -2881,7 +2931,7 @@
  25219. init_kmem_cache_node(struct kmem_cache_node *n)
  25220. {
  25221. n->nr_partial = 0;
  25222. - spin_lock_init(&n->list_lock);
  25223. + raw_spin_lock_init(&n->list_lock);
  25224. INIT_LIST_HEAD(&n->partial);
  25225. #ifdef CONFIG_SLUB_DEBUG
  25226. atomic_long_set(&n->nr_slabs, 0);
  25227. @@ -3463,7 +3513,7 @@
  25228. for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
  25229. INIT_LIST_HEAD(promote + i);
  25230. - spin_lock_irqsave(&n->list_lock, flags);
  25231. + raw_spin_lock_irqsave(&n->list_lock, flags);
  25232. /*
  25233. * Build lists of slabs to discard or promote.
  25234. @@ -3494,7 +3544,7 @@
  25235. for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
  25236. list_splice(promote + i, &n->partial);
  25237. - spin_unlock_irqrestore(&n->list_lock, flags);
  25238. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25239. /* Release empty slabs */
  25240. list_for_each_entry_safe(page, t, &discard, lru)
  25241. @@ -3670,6 +3720,12 @@
  25242. {
  25243. static __initdata struct kmem_cache boot_kmem_cache,
  25244. boot_kmem_cache_node;
  25245. + int cpu;
  25246. +
  25247. + for_each_possible_cpu(cpu) {
  25248. + raw_spin_lock_init(&per_cpu(slub_free_list, cpu).lock);
  25249. + INIT_LIST_HEAD(&per_cpu(slub_free_list, cpu).list);
  25250. + }
  25251. if (debug_guardpage_minorder())
  25252. slub_max_order = 0;
  25253. @@ -3912,7 +3968,7 @@
  25254. struct page *page;
  25255. unsigned long flags;
  25256. - spin_lock_irqsave(&n->list_lock, flags);
  25257. + raw_spin_lock_irqsave(&n->list_lock, flags);
  25258. list_for_each_entry(page, &n->partial, lru) {
  25259. validate_slab_slab(s, page, map);
  25260. @@ -3934,7 +3990,7 @@
  25261. s->name, count, atomic_long_read(&n->nr_slabs));
  25262. out:
  25263. - spin_unlock_irqrestore(&n->list_lock, flags);
  25264. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25265. return count;
  25266. }
  25267. @@ -4122,12 +4178,12 @@
  25268. if (!atomic_long_read(&n->nr_slabs))
  25269. continue;
  25270. - spin_lock_irqsave(&n->list_lock, flags);
  25271. + raw_spin_lock_irqsave(&n->list_lock, flags);
  25272. list_for_each_entry(page, &n->partial, lru)
  25273. process_slab(&t, s, page, alloc, map);
  25274. list_for_each_entry(page, &n->full, lru)
  25275. process_slab(&t, s, page, alloc, map);
  25276. - spin_unlock_irqrestore(&n->list_lock, flags);
  25277. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  25278. }
  25279. for (i = 0; i < t.count; i++) {
  25280. diff -Nur linux-4.1.26.orig/mm/swap.c linux-4.1.26/mm/swap.c
  25281. --- linux-4.1.26.orig/mm/swap.c 2016-06-07 01:13:11.000000000 +0200
  25282. +++ linux-4.1.26/mm/swap.c 2016-06-19 15:30:58.831302903 +0200
  25283. @@ -32,6 +32,7 @@
  25284. #include <linux/gfp.h>
  25285. #include <linux/uio.h>
  25286. #include <linux/hugetlb.h>
  25287. +#include <linux/locallock.h>
  25288. #include "internal.h"
  25289. @@ -45,6 +46,9 @@
  25290. static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
  25291. static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs);
  25292. +static DEFINE_LOCAL_IRQ_LOCK(rotate_lock);
  25293. +DEFINE_LOCAL_IRQ_LOCK(swapvec_lock);
  25294. +
  25295. /*
  25296. * This path almost never happens for VM activity - pages are normally
  25297. * freed via pagevecs. But it gets used by networking.
  25298. @@ -481,11 +485,11 @@
  25299. unsigned long flags;
  25300. page_cache_get(page);
  25301. - local_irq_save(flags);
  25302. + local_lock_irqsave(rotate_lock, flags);
  25303. pvec = this_cpu_ptr(&lru_rotate_pvecs);
  25304. if (!pagevec_add(pvec, page))
  25305. pagevec_move_tail(pvec);
  25306. - local_irq_restore(flags);
  25307. + local_unlock_irqrestore(rotate_lock, flags);
  25308. }
  25309. }
  25310. @@ -536,12 +540,13 @@
  25311. void activate_page(struct page *page)
  25312. {
  25313. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  25314. - struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
  25315. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  25316. + activate_page_pvecs);
  25317. page_cache_get(page);
  25318. if (!pagevec_add(pvec, page))
  25319. pagevec_lru_move_fn(pvec, __activate_page, NULL);
  25320. - put_cpu_var(activate_page_pvecs);
  25321. + put_locked_var(swapvec_lock, activate_page_pvecs);
  25322. }
  25323. }
  25324. @@ -567,7 +572,7 @@
  25325. static void __lru_cache_activate_page(struct page *page)
  25326. {
  25327. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  25328. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  25329. int i;
  25330. /*
  25331. @@ -589,7 +594,7 @@
  25332. }
  25333. }
  25334. - put_cpu_var(lru_add_pvec);
  25335. + put_locked_var(swapvec_lock, lru_add_pvec);
  25336. }
  25337. /*
  25338. @@ -628,13 +633,13 @@
  25339. static void __lru_cache_add(struct page *page)
  25340. {
  25341. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  25342. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  25343. page_cache_get(page);
  25344. if (!pagevec_space(pvec))
  25345. __pagevec_lru_add(pvec);
  25346. pagevec_add(pvec, page);
  25347. - put_cpu_var(lru_add_pvec);
  25348. + put_locked_var(swapvec_lock, lru_add_pvec);
  25349. }
  25350. /**
  25351. @@ -814,9 +819,9 @@
  25352. unsigned long flags;
  25353. /* No harm done if a racing interrupt already did this */
  25354. - local_irq_save(flags);
  25355. + local_lock_irqsave(rotate_lock, flags);
  25356. pagevec_move_tail(pvec);
  25357. - local_irq_restore(flags);
  25358. + local_unlock_irqrestore(rotate_lock, flags);
  25359. }
  25360. pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
  25361. @@ -844,18 +849,19 @@
  25362. return;
  25363. if (likely(get_page_unless_zero(page))) {
  25364. - struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
  25365. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  25366. + lru_deactivate_file_pvecs);
  25367. if (!pagevec_add(pvec, page))
  25368. pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
  25369. - put_cpu_var(lru_deactivate_file_pvecs);
  25370. + put_locked_var(swapvec_lock, lru_deactivate_file_pvecs);
  25371. }
  25372. }
  25373. void lru_add_drain(void)
  25374. {
  25375. - lru_add_drain_cpu(get_cpu());
  25376. - put_cpu();
  25377. + lru_add_drain_cpu(local_lock_cpu(swapvec_lock));
  25378. + local_unlock_cpu(swapvec_lock);
  25379. }
  25380. static void lru_add_drain_per_cpu(struct work_struct *dummy)
  25381. diff -Nur linux-4.1.26.orig/mm/truncate.c linux-4.1.26/mm/truncate.c
  25382. --- linux-4.1.26.orig/mm/truncate.c 2016-06-07 01:13:11.000000000 +0200
  25383. +++ linux-4.1.26/mm/truncate.c 2016-06-19 15:30:58.831302903 +0200
  25384. @@ -56,8 +56,11 @@
  25385. * protected by mapping->tree_lock.
  25386. */
  25387. if (!workingset_node_shadows(node) &&
  25388. - !list_empty(&node->private_list))
  25389. - list_lru_del(&workingset_shadow_nodes, &node->private_list);
  25390. + !list_empty(&node->private_list)) {
  25391. + local_lock(workingset_shadow_lock);
  25392. + list_lru_del(&__workingset_shadow_nodes, &node->private_list);
  25393. + local_unlock(workingset_shadow_lock);
  25394. + }
  25395. __radix_tree_delete_node(&mapping->page_tree, node);
  25396. unlock:
  25397. spin_unlock_irq(&mapping->tree_lock);
  25398. diff -Nur linux-4.1.26.orig/mm/vmalloc.c linux-4.1.26/mm/vmalloc.c
  25399. --- linux-4.1.26.orig/mm/vmalloc.c 2016-06-07 01:13:11.000000000 +0200
  25400. +++ linux-4.1.26/mm/vmalloc.c 2016-06-19 15:30:58.831302903 +0200
  25401. @@ -819,7 +819,7 @@
  25402. struct vmap_block *vb;
  25403. struct vmap_area *va;
  25404. unsigned long vb_idx;
  25405. - int node, err;
  25406. + int node, err, cpu;
  25407. void *vaddr;
  25408. node = numa_node_id();
  25409. @@ -862,11 +862,12 @@
  25410. BUG_ON(err);
  25411. radix_tree_preload_end();
  25412. - vbq = &get_cpu_var(vmap_block_queue);
  25413. + cpu = get_cpu_light();
  25414. + vbq = this_cpu_ptr(&vmap_block_queue);
  25415. spin_lock(&vbq->lock);
  25416. list_add_tail_rcu(&vb->free_list, &vbq->free);
  25417. spin_unlock(&vbq->lock);
  25418. - put_cpu_var(vmap_block_queue);
  25419. + put_cpu_light();
  25420. return vaddr;
  25421. }
  25422. @@ -935,6 +936,7 @@
  25423. struct vmap_block *vb;
  25424. void *vaddr = NULL;
  25425. unsigned int order;
  25426. + int cpu;
  25427. BUG_ON(size & ~PAGE_MASK);
  25428. BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
  25429. @@ -949,7 +951,8 @@
  25430. order = get_order(size);
  25431. rcu_read_lock();
  25432. - vbq = &get_cpu_var(vmap_block_queue);
  25433. + cpu = get_cpu_light();
  25434. + vbq = this_cpu_ptr(&vmap_block_queue);
  25435. list_for_each_entry_rcu(vb, &vbq->free, free_list) {
  25436. unsigned long pages_off;
  25437. @@ -972,7 +975,7 @@
  25438. break;
  25439. }
  25440. - put_cpu_var(vmap_block_queue);
  25441. + put_cpu_light();
  25442. rcu_read_unlock();
  25443. /* Allocate new block if nothing was found */
  25444. diff -Nur linux-4.1.26.orig/mm/vmstat.c linux-4.1.26/mm/vmstat.c
  25445. --- linux-4.1.26.orig/mm/vmstat.c 2016-06-07 01:13:11.000000000 +0200
  25446. +++ linux-4.1.26/mm/vmstat.c 2016-06-19 15:30:58.831302903 +0200
  25447. @@ -226,6 +226,7 @@
  25448. long x;
  25449. long t;
  25450. + preempt_disable_rt();
  25451. x = delta + __this_cpu_read(*p);
  25452. t = __this_cpu_read(pcp->stat_threshold);
  25453. @@ -235,6 +236,7 @@
  25454. x = 0;
  25455. }
  25456. __this_cpu_write(*p, x);
  25457. + preempt_enable_rt();
  25458. }
  25459. EXPORT_SYMBOL(__mod_zone_page_state);
  25460. @@ -267,6 +269,7 @@
  25461. s8 __percpu *p = pcp->vm_stat_diff + item;
  25462. s8 v, t;
  25463. + preempt_disable_rt();
  25464. v = __this_cpu_inc_return(*p);
  25465. t = __this_cpu_read(pcp->stat_threshold);
  25466. if (unlikely(v > t)) {
  25467. @@ -275,6 +278,7 @@
  25468. zone_page_state_add(v + overstep, zone, item);
  25469. __this_cpu_write(*p, -overstep);
  25470. }
  25471. + preempt_enable_rt();
  25472. }
  25473. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  25474. @@ -289,6 +293,7 @@
  25475. s8 __percpu *p = pcp->vm_stat_diff + item;
  25476. s8 v, t;
  25477. + preempt_disable_rt();
  25478. v = __this_cpu_dec_return(*p);
  25479. t = __this_cpu_read(pcp->stat_threshold);
  25480. if (unlikely(v < - t)) {
  25481. @@ -297,6 +302,7 @@
  25482. zone_page_state_add(v - overstep, zone, item);
  25483. __this_cpu_write(*p, overstep);
  25484. }
  25485. + preempt_enable_rt();
  25486. }
  25487. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  25488. diff -Nur linux-4.1.26.orig/mm/workingset.c linux-4.1.26/mm/workingset.c
  25489. --- linux-4.1.26.orig/mm/workingset.c 2016-06-07 01:13:11.000000000 +0200
  25490. +++ linux-4.1.26/mm/workingset.c 2016-06-19 15:30:58.835303057 +0200
  25491. @@ -264,7 +264,8 @@
  25492. * point where they would still be useful.
  25493. */
  25494. -struct list_lru workingset_shadow_nodes;
  25495. +struct list_lru __workingset_shadow_nodes;
  25496. +DEFINE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  25497. static unsigned long count_shadow_nodes(struct shrinker *shrinker,
  25498. struct shrink_control *sc)
  25499. @@ -274,9 +275,9 @@
  25500. unsigned long pages;
  25501. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  25502. - local_irq_disable();
  25503. - shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
  25504. - local_irq_enable();
  25505. + local_lock_irq(workingset_shadow_lock);
  25506. + shadow_nodes = list_lru_shrink_count(&__workingset_shadow_nodes, sc);
  25507. + local_unlock_irq(workingset_shadow_lock);
  25508. pages = node_present_pages(sc->nid);
  25509. /*
  25510. @@ -363,9 +364,9 @@
  25511. spin_unlock(&mapping->tree_lock);
  25512. ret = LRU_REMOVED_RETRY;
  25513. out:
  25514. - local_irq_enable();
  25515. + local_unlock_irq(workingset_shadow_lock);
  25516. cond_resched();
  25517. - local_irq_disable();
  25518. + local_lock_irq(workingset_shadow_lock);
  25519. spin_lock(lru_lock);
  25520. return ret;
  25521. }
  25522. @@ -376,10 +377,10 @@
  25523. unsigned long ret;
  25524. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  25525. - local_irq_disable();
  25526. - ret = list_lru_shrink_walk(&workingset_shadow_nodes, sc,
  25527. + local_lock_irq(workingset_shadow_lock);
  25528. + ret = list_lru_shrink_walk(&__workingset_shadow_nodes, sc,
  25529. shadow_lru_isolate, NULL);
  25530. - local_irq_enable();
  25531. + local_unlock_irq(workingset_shadow_lock);
  25532. return ret;
  25533. }
  25534. @@ -400,7 +401,7 @@
  25535. {
  25536. int ret;
  25537. - ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
  25538. + ret = list_lru_init_key(&__workingset_shadow_nodes, &shadow_nodes_key);
  25539. if (ret)
  25540. goto err;
  25541. ret = register_shrinker(&workingset_shadow_shrinker);
  25542. @@ -408,7 +409,7 @@
  25543. goto err_list_lru;
  25544. return 0;
  25545. err_list_lru:
  25546. - list_lru_destroy(&workingset_shadow_nodes);
  25547. + list_lru_destroy(&__workingset_shadow_nodes);
  25548. err:
  25549. return ret;
  25550. }
  25551. diff -Nur linux-4.1.26.orig/net/core/dev.c linux-4.1.26/net/core/dev.c
  25552. --- linux-4.1.26.orig/net/core/dev.c 2016-06-07 01:13:11.000000000 +0200
  25553. +++ linux-4.1.26/net/core/dev.c 2016-06-19 15:30:58.839303211 +0200
  25554. @@ -184,6 +184,7 @@
  25555. static DEFINE_HASHTABLE(napi_hash, 8);
  25556. static seqcount_t devnet_rename_seq;
  25557. +static DEFINE_MUTEX(devnet_rename_mutex);
  25558. static inline void dev_base_seq_inc(struct net *net)
  25559. {
  25560. @@ -205,14 +206,14 @@
  25561. static inline void rps_lock(struct softnet_data *sd)
  25562. {
  25563. #ifdef CONFIG_RPS
  25564. - spin_lock(&sd->input_pkt_queue.lock);
  25565. + raw_spin_lock(&sd->input_pkt_queue.raw_lock);
  25566. #endif
  25567. }
  25568. static inline void rps_unlock(struct softnet_data *sd)
  25569. {
  25570. #ifdef CONFIG_RPS
  25571. - spin_unlock(&sd->input_pkt_queue.lock);
  25572. + raw_spin_unlock(&sd->input_pkt_queue.raw_lock);
  25573. #endif
  25574. }
  25575. @@ -852,7 +853,8 @@
  25576. strcpy(name, dev->name);
  25577. rcu_read_unlock();
  25578. if (read_seqcount_retry(&devnet_rename_seq, seq)) {
  25579. - cond_resched();
  25580. + mutex_lock(&devnet_rename_mutex);
  25581. + mutex_unlock(&devnet_rename_mutex);
  25582. goto retry;
  25583. }
  25584. @@ -1121,20 +1123,17 @@
  25585. if (dev->flags & IFF_UP)
  25586. return -EBUSY;
  25587. - write_seqcount_begin(&devnet_rename_seq);
  25588. + mutex_lock(&devnet_rename_mutex);
  25589. + __raw_write_seqcount_begin(&devnet_rename_seq);
  25590. - if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
  25591. - write_seqcount_end(&devnet_rename_seq);
  25592. - return 0;
  25593. - }
  25594. + if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
  25595. + goto outunlock;
  25596. memcpy(oldname, dev->name, IFNAMSIZ);
  25597. err = dev_get_valid_name(net, dev, newname);
  25598. - if (err < 0) {
  25599. - write_seqcount_end(&devnet_rename_seq);
  25600. - return err;
  25601. - }
  25602. + if (err < 0)
  25603. + goto outunlock;
  25604. if (oldname[0] && !strchr(oldname, '%'))
  25605. netdev_info(dev, "renamed from %s\n", oldname);
  25606. @@ -1147,11 +1146,12 @@
  25607. if (ret) {
  25608. memcpy(dev->name, oldname, IFNAMSIZ);
  25609. dev->name_assign_type = old_assign_type;
  25610. - write_seqcount_end(&devnet_rename_seq);
  25611. - return ret;
  25612. + err = ret;
  25613. + goto outunlock;
  25614. }
  25615. - write_seqcount_end(&devnet_rename_seq);
  25616. + __raw_write_seqcount_end(&devnet_rename_seq);
  25617. + mutex_unlock(&devnet_rename_mutex);
  25618. netdev_adjacent_rename_links(dev, oldname);
  25619. @@ -1172,7 +1172,8 @@
  25620. /* err >= 0 after dev_alloc_name() or stores the first errno */
  25621. if (err >= 0) {
  25622. err = ret;
  25623. - write_seqcount_begin(&devnet_rename_seq);
  25624. + mutex_lock(&devnet_rename_mutex);
  25625. + __raw_write_seqcount_begin(&devnet_rename_seq);
  25626. memcpy(dev->name, oldname, IFNAMSIZ);
  25627. memcpy(oldname, newname, IFNAMSIZ);
  25628. dev->name_assign_type = old_assign_type;
  25629. @@ -1185,6 +1186,11 @@
  25630. }
  25631. return err;
  25632. +
  25633. +outunlock:
  25634. + __raw_write_seqcount_end(&devnet_rename_seq);
  25635. + mutex_unlock(&devnet_rename_mutex);
  25636. + return err;
  25637. }
  25638. /**
  25639. @@ -2214,6 +2220,7 @@
  25640. sd->output_queue_tailp = &q->next_sched;
  25641. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  25642. local_irq_restore(flags);
  25643. + preempt_check_resched_rt();
  25644. }
  25645. void __netif_schedule(struct Qdisc *q)
  25646. @@ -2295,6 +2302,7 @@
  25647. __this_cpu_write(softnet_data.completion_queue, skb);
  25648. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  25649. local_irq_restore(flags);
  25650. + preempt_check_resched_rt();
  25651. }
  25652. EXPORT_SYMBOL(__dev_kfree_skb_irq);
  25653. @@ -2880,9 +2888,44 @@
  25654. #define skb_update_prio(skb)
  25655. #endif
  25656. +#ifdef CONFIG_PREEMPT_RT_FULL
  25657. +
  25658. +static inline int xmit_rec_read(void)
  25659. +{
  25660. + return current->xmit_recursion;
  25661. +}
  25662. +
  25663. +static inline void xmit_rec_inc(void)
  25664. +{
  25665. + current->xmit_recursion++;
  25666. +}
  25667. +
  25668. +static inline void xmit_rec_dec(void)
  25669. +{
  25670. + current->xmit_recursion--;
  25671. +}
  25672. +
  25673. +#else
  25674. +
  25675. DEFINE_PER_CPU(int, xmit_recursion);
  25676. EXPORT_SYMBOL(xmit_recursion);
  25677. +static inline int xmit_rec_read(void)
  25678. +{
  25679. + return __this_cpu_read(xmit_recursion);
  25680. +}
  25681. +
  25682. +static inline void xmit_rec_inc(void)
  25683. +{
  25684. + __this_cpu_inc(xmit_recursion);
  25685. +}
  25686. +
  25687. +static inline int xmit_rec_dec(void)
  25688. +{
  25689. + __this_cpu_dec(xmit_recursion);
  25690. +}
  25691. +#endif
  25692. +
  25693. #define RECURSION_LIMIT 10
  25694. /**
  25695. @@ -2984,7 +3027,7 @@
  25696. if (txq->xmit_lock_owner != cpu) {
  25697. - if (__this_cpu_read(xmit_recursion) > RECURSION_LIMIT)
  25698. + if (xmit_rec_read() > RECURSION_LIMIT)
  25699. goto recursion_alert;
  25700. skb = validate_xmit_skb(skb, dev);
  25701. @@ -2994,9 +3037,9 @@
  25702. HARD_TX_LOCK(dev, txq, cpu);
  25703. if (!netif_xmit_stopped(txq)) {
  25704. - __this_cpu_inc(xmit_recursion);
  25705. + xmit_rec_inc();
  25706. skb = dev_hard_start_xmit(skb, dev, txq, &rc);
  25707. - __this_cpu_dec(xmit_recursion);
  25708. + xmit_rec_dec();
  25709. if (dev_xmit_complete(rc)) {
  25710. HARD_TX_UNLOCK(dev, txq);
  25711. goto out;
  25712. @@ -3370,6 +3413,7 @@
  25713. rps_unlock(sd);
  25714. local_irq_restore(flags);
  25715. + preempt_check_resched_rt();
  25716. atomic_long_inc(&skb->dev->rx_dropped);
  25717. kfree_skb(skb);
  25718. @@ -3388,7 +3432,7 @@
  25719. struct rps_dev_flow voidflow, *rflow = &voidflow;
  25720. int cpu;
  25721. - preempt_disable();
  25722. + migrate_disable();
  25723. rcu_read_lock();
  25724. cpu = get_rps_cpu(skb->dev, skb, &rflow);
  25725. @@ -3398,13 +3442,13 @@
  25726. ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);
  25727. rcu_read_unlock();
  25728. - preempt_enable();
  25729. + migrate_enable();
  25730. } else
  25731. #endif
  25732. {
  25733. unsigned int qtail;
  25734. - ret = enqueue_to_backlog(skb, get_cpu(), &qtail);
  25735. - put_cpu();
  25736. + ret = enqueue_to_backlog(skb, get_cpu_light(), &qtail);
  25737. + put_cpu_light();
  25738. }
  25739. return ret;
  25740. }
  25741. @@ -3438,16 +3482,44 @@
  25742. trace_netif_rx_ni_entry(skb);
  25743. - preempt_disable();
  25744. + local_bh_disable();
  25745. err = netif_rx_internal(skb);
  25746. - if (local_softirq_pending())
  25747. - do_softirq();
  25748. - preempt_enable();
  25749. + local_bh_enable();
  25750. return err;
  25751. }
  25752. EXPORT_SYMBOL(netif_rx_ni);
  25753. +#ifdef CONFIG_PREEMPT_RT_FULL
  25754. +/*
  25755. + * RT runs ksoftirqd as a real time thread and the root_lock is a
  25756. + * "sleeping spinlock". If the trylock fails then we can go into an
  25757. + * infinite loop when ksoftirqd preempted the task which actually
  25758. + * holds the lock, because we requeue q and raise NET_TX softirq
  25759. + * causing ksoftirqd to loop forever.
  25760. + *
  25761. + * It's safe to use spin_lock on RT here as softirqs run in thread
  25762. + * context and cannot deadlock against the thread which is holding
  25763. + * root_lock.
  25764. + *
  25765. + * On !RT the trylock might fail, but there we bail out from the
  25766. + * softirq loop after 10 attempts which we can't do on RT. And the
  25767. + * task holding root_lock cannot be preempted, so the only downside of
  25768. + * that trylock is that we need 10 loops to decide that we should have
  25769. + * given up in the first one :)
  25770. + */
  25771. +static inline int take_root_lock(spinlock_t *lock)
  25772. +{
  25773. + spin_lock(lock);
  25774. + return 1;
  25775. +}
  25776. +#else
  25777. +static inline int take_root_lock(spinlock_t *lock)
  25778. +{
  25779. + return spin_trylock(lock);
  25780. +}
  25781. +#endif
  25782. +
  25783. static void net_tx_action(struct softirq_action *h)
  25784. {
  25785. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  25786. @@ -3489,7 +3561,7 @@
  25787. head = head->next_sched;
  25788. root_lock = qdisc_lock(q);
  25789. - if (spin_trylock(root_lock)) {
  25790. + if (take_root_lock(root_lock)) {
  25791. smp_mb__before_atomic();
  25792. clear_bit(__QDISC_STATE_SCHED,
  25793. &q->state);
  25794. @@ -3886,7 +3958,7 @@
  25795. skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
  25796. if (skb->dev == dev) {
  25797. __skb_unlink(skb, &sd->input_pkt_queue);
  25798. - kfree_skb(skb);
  25799. + __skb_queue_tail(&sd->tofree_queue, skb);
  25800. input_queue_head_incr(sd);
  25801. }
  25802. }
  25803. @@ -3895,10 +3967,13 @@
  25804. skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
  25805. if (skb->dev == dev) {
  25806. __skb_unlink(skb, &sd->process_queue);
  25807. - kfree_skb(skb);
  25808. + __skb_queue_tail(&sd->tofree_queue, skb);
  25809. input_queue_head_incr(sd);
  25810. }
  25811. }
  25812. +
  25813. + if (!skb_queue_empty(&sd->tofree_queue))
  25814. + raise_softirq_irqoff(NET_RX_SOFTIRQ);
  25815. }
  25816. static int napi_gro_complete(struct sk_buff *skb)
  25817. @@ -4349,6 +4424,7 @@
  25818. sd->rps_ipi_list = NULL;
  25819. local_irq_enable();
  25820. + preempt_check_resched_rt();
  25821. /* Send pending IPI's to kick RPS processing on remote cpus. */
  25822. while (remsd) {
  25823. @@ -4362,6 +4438,7 @@
  25824. } else
  25825. #endif
  25826. local_irq_enable();
  25827. + preempt_check_resched_rt();
  25828. }
  25829. static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
  25830. @@ -4443,6 +4520,7 @@
  25831. local_irq_save(flags);
  25832. ____napi_schedule(this_cpu_ptr(&softnet_data), n);
  25833. local_irq_restore(flags);
  25834. + preempt_check_resched_rt();
  25835. }
  25836. EXPORT_SYMBOL(__napi_schedule);
  25837. @@ -4717,7 +4795,7 @@
  25838. list_splice_tail(&repoll, &list);
  25839. list_splice(&list, &sd->poll_list);
  25840. if (!list_empty(&sd->poll_list))
  25841. - __raise_softirq_irqoff(NET_RX_SOFTIRQ);
  25842. + __raise_softirq_irqoff_ksoft(NET_RX_SOFTIRQ);
  25843. net_rps_action_and_irq_enable(sd);
  25844. }
  25845. @@ -6931,7 +7009,7 @@
  25846. void synchronize_net(void)
  25847. {
  25848. might_sleep();
  25849. - if (rtnl_is_locked())
  25850. + if (rtnl_is_locked() && !IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
  25851. synchronize_rcu_expedited();
  25852. else
  25853. synchronize_rcu();
  25854. @@ -7172,16 +7250,20 @@
  25855. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  25856. local_irq_enable();
  25857. + preempt_check_resched_rt();
  25858. /* Process offline CPU's input_pkt_queue */
  25859. while ((skb = __skb_dequeue(&oldsd->process_queue))) {
  25860. netif_rx_ni(skb);
  25861. input_queue_head_incr(oldsd);
  25862. }
  25863. - while ((skb = skb_dequeue(&oldsd->input_pkt_queue))) {
  25864. + while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) {
  25865. netif_rx_ni(skb);
  25866. input_queue_head_incr(oldsd);
  25867. }
  25868. + while ((skb = __skb_dequeue(&oldsd->tofree_queue))) {
  25869. + kfree_skb(skb);
  25870. + }
  25871. return NOTIFY_OK;
  25872. }
  25873. @@ -7483,8 +7565,9 @@
  25874. for_each_possible_cpu(i) {
  25875. struct softnet_data *sd = &per_cpu(softnet_data, i);
  25876. - skb_queue_head_init(&sd->input_pkt_queue);
  25877. - skb_queue_head_init(&sd->process_queue);
  25878. + skb_queue_head_init_raw(&sd->input_pkt_queue);
  25879. + skb_queue_head_init_raw(&sd->process_queue);
  25880. + skb_queue_head_init_raw(&sd->tofree_queue);
  25881. INIT_LIST_HEAD(&sd->poll_list);
  25882. sd->output_queue_tailp = &sd->output_queue;
  25883. #ifdef CONFIG_RPS
  25884. diff -Nur linux-4.1.26.orig/net/core/skbuff.c linux-4.1.26/net/core/skbuff.c
  25885. --- linux-4.1.26.orig/net/core/skbuff.c 2016-06-07 01:13:11.000000000 +0200
  25886. +++ linux-4.1.26/net/core/skbuff.c 2016-06-19 15:30:58.839303211 +0200
  25887. @@ -63,6 +63,7 @@
  25888. #include <linux/errqueue.h>
  25889. #include <linux/prefetch.h>
  25890. #include <linux/if_vlan.h>
  25891. +#include <linux/locallock.h>
  25892. #include <net/protocol.h>
  25893. #include <net/dst.h>
  25894. @@ -358,6 +359,8 @@
  25895. };
  25896. static DEFINE_PER_CPU(struct netdev_alloc_cache, netdev_alloc_cache);
  25897. static DEFINE_PER_CPU(struct netdev_alloc_cache, napi_alloc_cache);
  25898. +static DEFINE_LOCAL_IRQ_LOCK(netdev_alloc_lock);
  25899. +static DEFINE_LOCAL_IRQ_LOCK(napi_alloc_cache_lock);
  25900. static struct page *__page_frag_refill(struct netdev_alloc_cache *nc,
  25901. gfp_t gfp_mask)
  25902. @@ -435,9 +438,9 @@
  25903. unsigned long flags;
  25904. void *data;
  25905. - local_irq_save(flags);
  25906. + local_lock_irqsave(netdev_alloc_lock, flags);
  25907. data = __alloc_page_frag(&netdev_alloc_cache, fragsz, gfp_mask);
  25908. - local_irq_restore(flags);
  25909. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  25910. return data;
  25911. }
  25912. @@ -456,7 +459,12 @@
  25913. static void *__napi_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
  25914. {
  25915. - return __alloc_page_frag(&napi_alloc_cache, fragsz, gfp_mask);
  25916. + void *data;
  25917. +
  25918. + local_lock(napi_alloc_cache_lock);
  25919. + data = __alloc_page_frag(&napi_alloc_cache, fragsz, gfp_mask);
  25920. + local_unlock(napi_alloc_cache_lock);
  25921. + return data;
  25922. }
  25923. void *napi_alloc_frag(unsigned int fragsz)
  25924. diff -Nur linux-4.1.26.orig/net/core/sock.c linux-4.1.26/net/core/sock.c
  25925. --- linux-4.1.26.orig/net/core/sock.c 2016-06-07 01:13:11.000000000 +0200
  25926. +++ linux-4.1.26/net/core/sock.c 2016-06-19 15:30:58.839303211 +0200
  25927. @@ -2369,12 +2369,11 @@
  25928. if (sk->sk_lock.owned)
  25929. __lock_sock(sk);
  25930. sk->sk_lock.owned = 1;
  25931. - spin_unlock(&sk->sk_lock.slock);
  25932. + spin_unlock_bh(&sk->sk_lock.slock);
  25933. /*
  25934. * The sk_lock has mutex_lock() semantics here:
  25935. */
  25936. mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
  25937. - local_bh_enable();
  25938. }
  25939. EXPORT_SYMBOL(lock_sock_nested);
  25940. diff -Nur linux-4.1.26.orig/net/ipv4/icmp.c linux-4.1.26/net/ipv4/icmp.c
  25941. --- linux-4.1.26.orig/net/ipv4/icmp.c 2016-06-07 01:13:11.000000000 +0200
  25942. +++ linux-4.1.26/net/ipv4/icmp.c 2016-06-19 15:30:58.839303211 +0200
  25943. @@ -69,6 +69,7 @@
  25944. #include <linux/jiffies.h>
  25945. #include <linux/kernel.h>
  25946. #include <linux/fcntl.h>
  25947. +#include <linux/sysrq.h>
  25948. #include <linux/socket.h>
  25949. #include <linux/in.h>
  25950. #include <linux/inet.h>
  25951. @@ -867,6 +868,30 @@
  25952. }
  25953. /*
  25954. + * 32bit and 64bit have different timestamp length, so we check for
  25955. + * the cookie at offset 20 and verify it is repeated at offset 50
  25956. + */
  25957. +#define CO_POS0 20
  25958. +#define CO_POS1 50
  25959. +#define CO_SIZE sizeof(int)
  25960. +#define ICMP_SYSRQ_SIZE 57
  25961. +
  25962. +/*
  25963. + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
  25964. + * pattern and if it matches send the next byte as a trigger to sysrq.
  25965. + */
  25966. +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
  25967. +{
  25968. + int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
  25969. + char *p = skb->data;
  25970. +
  25971. + if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
  25972. + !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
  25973. + p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
  25974. + handle_sysrq(p[CO_POS0 + CO_SIZE]);
  25975. +}
  25976. +
  25977. +/*
  25978. * Handle ICMP_ECHO ("ping") requests.
  25979. *
  25980. * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
  25981. @@ -893,6 +918,11 @@
  25982. icmp_param.data_len = skb->len;
  25983. icmp_param.head_len = sizeof(struct icmphdr);
  25984. icmp_reply(&icmp_param, skb);
  25985. +
  25986. + if (skb->len == ICMP_SYSRQ_SIZE &&
  25987. + net->ipv4.sysctl_icmp_echo_sysrq) {
  25988. + icmp_check_sysrq(net, skb);
  25989. + }
  25990. }
  25991. /* should there be an ICMP stat for ignored echos? */
  25992. return true;
  25993. diff -Nur linux-4.1.26.orig/net/ipv4/sysctl_net_ipv4.c linux-4.1.26/net/ipv4/sysctl_net_ipv4.c
  25994. --- linux-4.1.26.orig/net/ipv4/sysctl_net_ipv4.c 2016-06-07 01:13:11.000000000 +0200
  25995. +++ linux-4.1.26/net/ipv4/sysctl_net_ipv4.c 2016-06-19 15:30:58.839303211 +0200
  25996. @@ -779,6 +779,13 @@
  25997. .proc_handler = proc_dointvec
  25998. },
  25999. {
  26000. + .procname = "icmp_echo_sysrq",
  26001. + .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
  26002. + .maxlen = sizeof(int),
  26003. + .mode = 0644,
  26004. + .proc_handler = proc_dointvec
  26005. + },
  26006. + {
  26007. .procname = "icmp_ignore_bogus_error_responses",
  26008. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  26009. .maxlen = sizeof(int),
  26010. diff -Nur linux-4.1.26.orig/net/mac80211/rx.c linux-4.1.26/net/mac80211/rx.c
  26011. --- linux-4.1.26.orig/net/mac80211/rx.c 2016-06-07 01:13:11.000000000 +0200
  26012. +++ linux-4.1.26/net/mac80211/rx.c 2016-06-19 15:30:58.839303211 +0200
  26013. @@ -3573,7 +3573,7 @@
  26014. struct ieee80211_supported_band *sband;
  26015. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  26016. - WARN_ON_ONCE(softirq_count() == 0);
  26017. + WARN_ON_ONCE_NONRT(softirq_count() == 0);
  26018. if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
  26019. goto drop;
  26020. diff -Nur linux-4.1.26.orig/net/netfilter/core.c linux-4.1.26/net/netfilter/core.c
  26021. --- linux-4.1.26.orig/net/netfilter/core.c 2016-06-07 01:13:11.000000000 +0200
  26022. +++ linux-4.1.26/net/netfilter/core.c 2016-06-19 15:30:58.839303211 +0200
  26023. @@ -22,11 +22,17 @@
  26024. #include <linux/proc_fs.h>
  26025. #include <linux/mutex.h>
  26026. #include <linux/slab.h>
  26027. +#include <linux/locallock.h>
  26028. #include <net/net_namespace.h>
  26029. #include <net/sock.h>
  26030. #include "nf_internals.h"
  26031. +#ifdef CONFIG_PREEMPT_RT_BASE
  26032. +DEFINE_LOCAL_IRQ_LOCK(xt_write_lock);
  26033. +EXPORT_PER_CPU_SYMBOL(xt_write_lock);
  26034. +#endif
  26035. +
  26036. static DEFINE_MUTEX(afinfo_mutex);
  26037. const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly;
  26038. diff -Nur linux-4.1.26.orig/net/packet/af_packet.c linux-4.1.26/net/packet/af_packet.c
  26039. --- linux-4.1.26.orig/net/packet/af_packet.c 2016-06-07 01:13:11.000000000 +0200
  26040. +++ linux-4.1.26/net/packet/af_packet.c 2016-06-19 15:30:58.839303211 +0200
  26041. @@ -63,6 +63,7 @@
  26042. #include <linux/if_packet.h>
  26043. #include <linux/wireless.h>
  26044. #include <linux/kernel.h>
  26045. +#include <linux/delay.h>
  26046. #include <linux/kmod.h>
  26047. #include <linux/slab.h>
  26048. #include <linux/vmalloc.h>
  26049. @@ -698,7 +699,7 @@
  26050. if (BLOCK_NUM_PKTS(pbd)) {
  26051. while (atomic_read(&pkc->blk_fill_in_prog)) {
  26052. /* Waiting for skb_copy_bits to finish... */
  26053. - cpu_relax();
  26054. + cpu_chill();
  26055. }
  26056. }
  26057. @@ -960,7 +961,7 @@
  26058. if (!(status & TP_STATUS_BLK_TMO)) {
  26059. while (atomic_read(&pkc->blk_fill_in_prog)) {
  26060. /* Waiting for skb_copy_bits to finish... */
  26061. - cpu_relax();
  26062. + cpu_chill();
  26063. }
  26064. }
  26065. prb_close_block(pkc, pbd, po, status);
  26066. diff -Nur linux-4.1.26.orig/net/rds/ib_rdma.c linux-4.1.26/net/rds/ib_rdma.c
  26067. --- linux-4.1.26.orig/net/rds/ib_rdma.c 2016-06-07 01:13:11.000000000 +0200
  26068. +++ linux-4.1.26/net/rds/ib_rdma.c 2016-06-19 15:30:58.843303365 +0200
  26069. @@ -34,6 +34,7 @@
  26070. #include <linux/slab.h>
  26071. #include <linux/rculist.h>
  26072. #include <linux/llist.h>
  26073. +#include <linux/delay.h>
  26074. #include "rds.h"
  26075. #include "ib.h"
  26076. @@ -286,7 +287,7 @@
  26077. for_each_online_cpu(cpu) {
  26078. flag = &per_cpu(clean_list_grace, cpu);
  26079. while (test_bit(CLEAN_LIST_BUSY_BIT, flag))
  26080. - cpu_relax();
  26081. + cpu_chill();
  26082. }
  26083. }
  26084. diff -Nur linux-4.1.26.orig/net/sched/sch_generic.c linux-4.1.26/net/sched/sch_generic.c
  26085. --- linux-4.1.26.orig/net/sched/sch_generic.c 2016-06-07 01:13:11.000000000 +0200
  26086. +++ linux-4.1.26/net/sched/sch_generic.c 2016-06-19 15:30:58.843303365 +0200
  26087. @@ -896,7 +896,7 @@
  26088. /* Wait for outstanding qdisc_run calls. */
  26089. list_for_each_entry(dev, head, close_list)
  26090. while (some_qdisc_is_busy(dev))
  26091. - yield();
  26092. + msleep(1);
  26093. }
  26094. void dev_deactivate(struct net_device *dev)
  26095. diff -Nur linux-4.1.26.orig/net/sunrpc/svc_xprt.c linux-4.1.26/net/sunrpc/svc_xprt.c
  26096. --- linux-4.1.26.orig/net/sunrpc/svc_xprt.c 2016-06-07 01:13:11.000000000 +0200
  26097. +++ linux-4.1.26/net/sunrpc/svc_xprt.c 2016-06-19 15:30:58.843303365 +0200
  26098. @@ -341,7 +341,7 @@
  26099. goto out;
  26100. }
  26101. - cpu = get_cpu();
  26102. + cpu = get_cpu_light();
  26103. pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
  26104. atomic_long_inc(&pool->sp_stats.packets);
  26105. @@ -377,7 +377,7 @@
  26106. atomic_long_inc(&pool->sp_stats.threads_woken);
  26107. wake_up_process(rqstp->rq_task);
  26108. - put_cpu();
  26109. + put_cpu_light();
  26110. goto out;
  26111. }
  26112. rcu_read_unlock();
  26113. @@ -398,7 +398,7 @@
  26114. goto redo_search;
  26115. }
  26116. rqstp = NULL;
  26117. - put_cpu();
  26118. + put_cpu_light();
  26119. out:
  26120. trace_svc_xprt_do_enqueue(xprt, rqstp);
  26121. }
  26122. diff -Nur linux-4.1.26.orig/scripts/mkcompile_h linux-4.1.26/scripts/mkcompile_h
  26123. --- linux-4.1.26.orig/scripts/mkcompile_h 2016-06-07 01:13:11.000000000 +0200
  26124. +++ linux-4.1.26/scripts/mkcompile_h 2016-06-19 15:30:58.843303365 +0200
  26125. @@ -4,7 +4,8 @@
  26126. ARCH=$2
  26127. SMP=$3
  26128. PREEMPT=$4
  26129. -CC=$5
  26130. +RT=$5
  26131. +CC=$6
  26132. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  26133. @@ -57,6 +58,7 @@
  26134. CONFIG_FLAGS=""
  26135. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  26136. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  26137. +if [ -n "$RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS RT"; fi
  26138. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  26139. # Truncate to maximum length
  26140. diff -Nur linux-4.1.26.orig/sound/core/pcm_native.c linux-4.1.26/sound/core/pcm_native.c
  26141. --- linux-4.1.26.orig/sound/core/pcm_native.c 2016-06-07 01:13:11.000000000 +0200
  26142. +++ linux-4.1.26/sound/core/pcm_native.c 2016-06-19 15:30:58.843303365 +0200
  26143. @@ -135,7 +135,7 @@
  26144. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  26145. {
  26146. if (!substream->pcm->nonatomic)
  26147. - local_irq_disable();
  26148. + local_irq_disable_nort();
  26149. snd_pcm_stream_lock(substream);
  26150. }
  26151. EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
  26152. @@ -150,7 +150,7 @@
  26153. {
  26154. snd_pcm_stream_unlock(substream);
  26155. if (!substream->pcm->nonatomic)
  26156. - local_irq_enable();
  26157. + local_irq_enable_nort();
  26158. }
  26159. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq);
  26160. @@ -158,7 +158,7 @@
  26161. {
  26162. unsigned long flags = 0;
  26163. if (!substream->pcm->nonatomic)
  26164. - local_irq_save(flags);
  26165. + local_irq_save_nort(flags);
  26166. snd_pcm_stream_lock(substream);
  26167. return flags;
  26168. }
  26169. @@ -176,7 +176,7 @@
  26170. {
  26171. snd_pcm_stream_unlock(substream);
  26172. if (!substream->pcm->nonatomic)
  26173. - local_irq_restore(flags);
  26174. + local_irq_restore_nort(flags);
  26175. }
  26176. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore);
  26177. diff -Nur linux-4.1.26.orig/sound/soc/intel/atom/sst/sst.c linux-4.1.26/sound/soc/intel/atom/sst/sst.c
  26178. --- linux-4.1.26.orig/sound/soc/intel/atom/sst/sst.c 2016-06-07 01:13:11.000000000 +0200
  26179. +++ linux-4.1.26/sound/soc/intel/atom/sst/sst.c 2016-06-19 15:30:58.843303365 +0200
  26180. @@ -368,8 +368,8 @@
  26181. * initialize by FW or driver when firmware is loaded
  26182. */
  26183. spin_lock_irqsave(&ctx->ipc_spin_lock, irq_flags);
  26184. - sst_shim_write64(shim, SST_IMRX, shim_regs->imrx),
  26185. - sst_shim_write64(shim, SST_CSR, shim_regs->csr),
  26186. + sst_shim_write64(shim, SST_IMRX, shim_regs->imrx);
  26187. + sst_shim_write64(shim, SST_CSR, shim_regs->csr);
  26188. spin_unlock_irqrestore(&ctx->ipc_spin_lock, irq_flags);
  26189. }
  26190. diff -Nur linux-4.1.26.orig/virt/kvm/async_pf.c linux-4.1.26/virt/kvm/async_pf.c
  26191. --- linux-4.1.26.orig/virt/kvm/async_pf.c 2016-06-07 01:13:11.000000000 +0200
  26192. +++ linux-4.1.26/virt/kvm/async_pf.c 2016-06-19 15:30:58.843303365 +0200
  26193. @@ -94,8 +94,8 @@
  26194. trace_kvm_async_pf_completed(addr, gva);
  26195. - if (waitqueue_active(&vcpu->wq))
  26196. - wake_up_interruptible(&vcpu->wq);
  26197. + if (swaitqueue_active(&vcpu->wq))
  26198. + swait_wake_interruptible(&vcpu->wq);
  26199. mmput(mm);
  26200. kvm_put_kvm(vcpu->kvm);
  26201. diff -Nur linux-4.1.26.orig/virt/kvm/kvm_main.c linux-4.1.26/virt/kvm/kvm_main.c
  26202. --- linux-4.1.26.orig/virt/kvm/kvm_main.c 2016-06-07 01:13:11.000000000 +0200
  26203. +++ linux-4.1.26/virt/kvm/kvm_main.c 2016-06-19 15:30:58.843303365 +0200
  26204. @@ -218,7 +218,7 @@
  26205. vcpu->kvm = kvm;
  26206. vcpu->vcpu_id = id;
  26207. vcpu->pid = NULL;
  26208. - init_waitqueue_head(&vcpu->wq);
  26209. + init_swait_head(&vcpu->wq);
  26210. kvm_async_pf_vcpu_init(vcpu);
  26211. page = alloc_page(GFP_KERNEL | __GFP_ZERO);
  26212. @@ -1780,7 +1780,7 @@
  26213. void kvm_vcpu_block(struct kvm_vcpu *vcpu)
  26214. {
  26215. ktime_t start, cur;
  26216. - DEFINE_WAIT(wait);
  26217. + DEFINE_SWAITER(wait);
  26218. bool waited = false;
  26219. start = cur = ktime_get();
  26220. @@ -1801,7 +1801,7 @@
  26221. }
  26222. for (;;) {
  26223. - prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  26224. + swait_prepare(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  26225. if (kvm_vcpu_check_block(vcpu) < 0)
  26226. break;
  26227. @@ -1810,7 +1810,7 @@
  26228. schedule();
  26229. }
  26230. - finish_wait(&vcpu->wq, &wait);
  26231. + swait_finish(&vcpu->wq, &wait);
  26232. cur = ktime_get();
  26233. out:
  26234. @@ -1826,11 +1826,11 @@
  26235. {
  26236. int me;
  26237. int cpu = vcpu->cpu;
  26238. - wait_queue_head_t *wqp;
  26239. + struct swait_head *wqp;
  26240. wqp = kvm_arch_vcpu_wq(vcpu);
  26241. - if (waitqueue_active(wqp)) {
  26242. - wake_up_interruptible(wqp);
  26243. + if (swaitqueue_active(wqp)) {
  26244. + swait_wake_interruptible(wqp);
  26245. ++vcpu->stat.halt_wakeup;
  26246. }
  26247. @@ -1931,7 +1931,7 @@
  26248. continue;
  26249. if (vcpu == me)
  26250. continue;
  26251. - if (waitqueue_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  26252. + if (swaitqueue_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  26253. continue;
  26254. if (!kvm_vcpu_eligible_for_directed_yield(vcpu))
  26255. continue;