patch-realtime 676 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868
  1. diff -Nur linux-4.9.6.orig/arch/arm/include/asm/irq.h linux-4.9.6/arch/arm/include/asm/irq.h
  2. --- linux-4.9.6.orig/arch/arm/include/asm/irq.h 2017-01-26 08:25:24.000000000 +0100
  3. +++ linux-4.9.6/arch/arm/include/asm/irq.h 2017-01-28 13:59:09.887654498 +0100
  4. @@ -22,6 +22,8 @@
  5. #endif
  6. #ifndef __ASSEMBLY__
  7. +#include <linux/cpumask.h>
  8. +
  9. struct irqaction;
  10. struct pt_regs;
  11. extern void migrate_irqs(void);
  12. diff -Nur linux-4.9.6.orig/arch/arm/include/asm/switch_to.h linux-4.9.6/arch/arm/include/asm/switch_to.h
  13. --- linux-4.9.6.orig/arch/arm/include/asm/switch_to.h 2017-01-26 08:25:24.000000000 +0100
  14. +++ linux-4.9.6/arch/arm/include/asm/switch_to.h 2017-01-28 13:59:09.887654498 +0100
  15. @@ -3,6 +3,13 @@
  16. #include <linux/thread_info.h>
  17. +#if defined CONFIG_PREEMPT_RT_FULL && defined CONFIG_HIGHMEM
  18. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p);
  19. +#else
  20. +static inline void
  21. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  22. +#endif
  23. +
  24. /*
  25. * For v7 SMP cores running a preemptible kernel we may be pre-empted
  26. * during a TLB maintenance operation, so execute an inner-shareable dsb
  27. @@ -25,6 +32,7 @@
  28. #define switch_to(prev,next,last) \
  29. do { \
  30. __complete_pending_tlbi(); \
  31. + switch_kmaps(prev, next); \
  32. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  33. } while (0)
  34. diff -Nur linux-4.9.6.orig/arch/arm/include/asm/thread_info.h linux-4.9.6/arch/arm/include/asm/thread_info.h
  35. --- linux-4.9.6.orig/arch/arm/include/asm/thread_info.h 2017-01-26 08:25:24.000000000 +0100
  36. +++ linux-4.9.6/arch/arm/include/asm/thread_info.h 2017-01-28 13:59:09.887654498 +0100
  37. @@ -49,6 +49,7 @@
  38. struct thread_info {
  39. unsigned long flags; /* low level flags */
  40. int preempt_count; /* 0 => preemptable, <0 => bug */
  41. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  42. mm_segment_t addr_limit; /* address limit */
  43. struct task_struct *task; /* main task structure */
  44. __u32 cpu; /* cpu */
  45. @@ -142,7 +143,8 @@
  46. #define TIF_SYSCALL_TRACE 4 /* syscall trace active */
  47. #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
  48. #define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
  49. -#define TIF_SECCOMP 7 /* seccomp syscall filtering active */
  50. +#define TIF_SECCOMP 8 /* seccomp syscall filtering active */
  51. +#define TIF_NEED_RESCHED_LAZY 7
  52. #define TIF_NOHZ 12 /* in adaptive nohz mode */
  53. #define TIF_USING_IWMMXT 17
  54. @@ -152,6 +154,7 @@
  55. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  56. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  57. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  58. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  59. #define _TIF_UPROBE (1 << TIF_UPROBE)
  60. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  61. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  62. @@ -167,7 +170,8 @@
  63. * Change these and you break ASM code in entry-common.S
  64. */
  65. #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
  66. - _TIF_NOTIFY_RESUME | _TIF_UPROBE)
  67. + _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  68. + _TIF_NEED_RESCHED_LAZY)
  69. #endif /* __KERNEL__ */
  70. #endif /* __ASM_ARM_THREAD_INFO_H */
  71. diff -Nur linux-4.9.6.orig/arch/arm/Kconfig linux-4.9.6/arch/arm/Kconfig
  72. --- linux-4.9.6.orig/arch/arm/Kconfig 2017-01-26 08:25:24.000000000 +0100
  73. +++ linux-4.9.6/arch/arm/Kconfig 2017-01-28 13:59:09.887654498 +0100
  74. @@ -36,7 +36,7 @@
  75. select HAVE_ARCH_AUDITSYSCALL if (AEABI && !OABI_COMPAT)
  76. select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
  77. select HAVE_ARCH_HARDENED_USERCOPY
  78. - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU
  79. + select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU && !PREEMPT_RT_BASE
  80. select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
  81. select HAVE_ARCH_MMAP_RND_BITS if MMU
  82. select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
  83. @@ -75,6 +75,7 @@
  84. select HAVE_PERF_EVENTS
  85. select HAVE_PERF_REGS
  86. select HAVE_PERF_USER_STACK_DUMP
  87. + select HAVE_PREEMPT_LAZY
  88. select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
  89. select HAVE_REGS_AND_STACK_ACCESS_API
  90. select HAVE_SYSCALL_TRACEPOINTS
  91. diff -Nur linux-4.9.6.orig/arch/arm/kernel/asm-offsets.c linux-4.9.6/arch/arm/kernel/asm-offsets.c
  92. --- linux-4.9.6.orig/arch/arm/kernel/asm-offsets.c 2017-01-26 08:25:24.000000000 +0100
  93. +++ linux-4.9.6/arch/arm/kernel/asm-offsets.c 2017-01-28 13:59:09.887654498 +0100
  94. @@ -65,6 +65,7 @@
  95. BLANK();
  96. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  97. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  98. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  99. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  100. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  101. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  102. diff -Nur linux-4.9.6.orig/arch/arm/kernel/entry-armv.S linux-4.9.6/arch/arm/kernel/entry-armv.S
  103. --- linux-4.9.6.orig/arch/arm/kernel/entry-armv.S 2017-01-26 08:25:24.000000000 +0100
  104. +++ linux-4.9.6/arch/arm/kernel/entry-armv.S 2017-01-28 13:59:09.887654498 +0100
  105. @@ -220,11 +220,18 @@
  106. #ifdef CONFIG_PREEMPT
  107. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  108. - ldr r0, [tsk, #TI_FLAGS] @ get flags
  109. teq r8, #0 @ if preempt count != 0
  110. + bne 1f @ return from exeption
  111. + ldr r0, [tsk, #TI_FLAGS] @ get flags
  112. + tst r0, #_TIF_NEED_RESCHED @ if NEED_RESCHED is set
  113. + blne svc_preempt @ preempt!
  114. +
  115. + ldr r8, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  116. + teq r8, #0 @ if preempt lazy count != 0
  117. movne r0, #0 @ force flags to 0
  118. - tst r0, #_TIF_NEED_RESCHED
  119. + tst r0, #_TIF_NEED_RESCHED_LAZY
  120. blne svc_preempt
  121. +1:
  122. #endif
  123. svc_exit r5, irq = 1 @ return from exception
  124. @@ -239,8 +246,14 @@
  125. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  126. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  127. tst r0, #_TIF_NEED_RESCHED
  128. + bne 1b
  129. + tst r0, #_TIF_NEED_RESCHED_LAZY
  130. reteq r8 @ go again
  131. - b 1b
  132. + ldr r0, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  133. + teq r0, #0 @ if preempt lazy count != 0
  134. + beq 1b
  135. + ret r8 @ go again
  136. +
  137. #endif
  138. __und_fault:
  139. diff -Nur linux-4.9.6.orig/arch/arm/kernel/entry-common.S linux-4.9.6/arch/arm/kernel/entry-common.S
  140. --- linux-4.9.6.orig/arch/arm/kernel/entry-common.S 2017-01-26 08:25:24.000000000 +0100
  141. +++ linux-4.9.6/arch/arm/kernel/entry-common.S 2017-01-28 13:59:09.887654498 +0100
  142. @@ -36,7 +36,9 @@
  143. UNWIND(.cantunwind )
  144. disable_irq_notrace @ disable interrupts
  145. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  146. - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  147. + tst r1, #((_TIF_SYSCALL_WORK | _TIF_WORK_MASK) & ~_TIF_SECCOMP)
  148. + bne fast_work_pending
  149. + tst r1, #_TIF_SECCOMP
  150. bne fast_work_pending
  151. /* perform architecture specific actions before user return */
  152. @@ -62,8 +64,11 @@
  153. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  154. disable_irq_notrace @ disable interrupts
  155. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  156. - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  157. + tst r1, #((_TIF_SYSCALL_WORK | _TIF_WORK_MASK) & ~_TIF_SECCOMP)
  158. + bne do_slower_path
  159. + tst r1, #_TIF_SECCOMP
  160. beq no_work_pending
  161. +do_slower_path:
  162. UNWIND(.fnend )
  163. ENDPROC(ret_fast_syscall)
  164. diff -Nur linux-4.9.6.orig/arch/arm/kernel/patch.c linux-4.9.6/arch/arm/kernel/patch.c
  165. --- linux-4.9.6.orig/arch/arm/kernel/patch.c 2017-01-26 08:25:24.000000000 +0100
  166. +++ linux-4.9.6/arch/arm/kernel/patch.c 2017-01-28 13:59:09.895654805 +0100
  167. @@ -15,7 +15,7 @@
  168. unsigned int insn;
  169. };
  170. -static DEFINE_SPINLOCK(patch_lock);
  171. +static DEFINE_RAW_SPINLOCK(patch_lock);
  172. static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
  173. __acquires(&patch_lock)
  174. @@ -32,7 +32,7 @@
  175. return addr;
  176. if (flags)
  177. - spin_lock_irqsave(&patch_lock, *flags);
  178. + raw_spin_lock_irqsave(&patch_lock, *flags);
  179. else
  180. __acquire(&patch_lock);
  181. @@ -47,7 +47,7 @@
  182. clear_fixmap(fixmap);
  183. if (flags)
  184. - spin_unlock_irqrestore(&patch_lock, *flags);
  185. + raw_spin_unlock_irqrestore(&patch_lock, *flags);
  186. else
  187. __release(&patch_lock);
  188. }
  189. diff -Nur linux-4.9.6.orig/arch/arm/kernel/process.c linux-4.9.6/arch/arm/kernel/process.c
  190. --- linux-4.9.6.orig/arch/arm/kernel/process.c 2017-01-26 08:25:24.000000000 +0100
  191. +++ linux-4.9.6/arch/arm/kernel/process.c 2017-01-28 13:59:09.895654805 +0100
  192. @@ -322,6 +322,30 @@
  193. }
  194. #ifdef CONFIG_MMU
  195. +/*
  196. + * CONFIG_SPLIT_PTLOCK_CPUS results in a page->ptl lock. If the lock is not
  197. + * initialized by pgtable_page_ctor() then a coredump of the vector page will
  198. + * fail.
  199. + */
  200. +static int __init vectors_user_mapping_init_page(void)
  201. +{
  202. + struct page *page;
  203. + unsigned long addr = 0xffff0000;
  204. + pgd_t *pgd;
  205. + pud_t *pud;
  206. + pmd_t *pmd;
  207. +
  208. + pgd = pgd_offset_k(addr);
  209. + pud = pud_offset(pgd, addr);
  210. + pmd = pmd_offset(pud, addr);
  211. + page = pmd_page(*(pmd));
  212. +
  213. + pgtable_page_ctor(page);
  214. +
  215. + return 0;
  216. +}
  217. +late_initcall(vectors_user_mapping_init_page);
  218. +
  219. #ifdef CONFIG_KUSER_HELPERS
  220. /*
  221. * The vectors page is always readable from user space for the
  222. diff -Nur linux-4.9.6.orig/arch/arm/kernel/signal.c linux-4.9.6/arch/arm/kernel/signal.c
  223. --- linux-4.9.6.orig/arch/arm/kernel/signal.c 2017-01-26 08:25:24.000000000 +0100
  224. +++ linux-4.9.6/arch/arm/kernel/signal.c 2017-01-28 13:59:09.895654805 +0100
  225. @@ -572,7 +572,8 @@
  226. */
  227. trace_hardirqs_off();
  228. do {
  229. - if (likely(thread_flags & _TIF_NEED_RESCHED)) {
  230. + if (likely(thread_flags & (_TIF_NEED_RESCHED |
  231. + _TIF_NEED_RESCHED_LAZY))) {
  232. schedule();
  233. } else {
  234. if (unlikely(!user_mode(regs)))
  235. diff -Nur linux-4.9.6.orig/arch/arm/kernel/smp.c linux-4.9.6/arch/arm/kernel/smp.c
  236. --- linux-4.9.6.orig/arch/arm/kernel/smp.c 2017-01-26 08:25:24.000000000 +0100
  237. +++ linux-4.9.6/arch/arm/kernel/smp.c 2017-01-28 13:59:09.895654805 +0100
  238. @@ -234,8 +234,6 @@
  239. flush_cache_louis();
  240. local_flush_tlb_all();
  241. - clear_tasks_mm_cpumask(cpu);
  242. -
  243. return 0;
  244. }
  245. @@ -251,6 +249,9 @@
  246. pr_err("CPU%u: cpu didn't die\n", cpu);
  247. return;
  248. }
  249. +
  250. + clear_tasks_mm_cpumask(cpu);
  251. +
  252. pr_notice("CPU%u: shutdown\n", cpu);
  253. /*
  254. diff -Nur linux-4.9.6.orig/arch/arm/kernel/unwind.c linux-4.9.6/arch/arm/kernel/unwind.c
  255. --- linux-4.9.6.orig/arch/arm/kernel/unwind.c 2017-01-26 08:25:24.000000000 +0100
  256. +++ linux-4.9.6/arch/arm/kernel/unwind.c 2017-01-28 13:59:09.895654805 +0100
  257. @@ -93,7 +93,7 @@
  258. static const struct unwind_idx *__origin_unwind_idx;
  259. extern const struct unwind_idx __stop_unwind_idx[];
  260. -static DEFINE_SPINLOCK(unwind_lock);
  261. +static DEFINE_RAW_SPINLOCK(unwind_lock);
  262. static LIST_HEAD(unwind_tables);
  263. /* Convert a prel31 symbol to an absolute address */
  264. @@ -201,7 +201,7 @@
  265. /* module unwind tables */
  266. struct unwind_table *table;
  267. - spin_lock_irqsave(&unwind_lock, flags);
  268. + raw_spin_lock_irqsave(&unwind_lock, flags);
  269. list_for_each_entry(table, &unwind_tables, list) {
  270. if (addr >= table->begin_addr &&
  271. addr < table->end_addr) {
  272. @@ -213,7 +213,7 @@
  273. break;
  274. }
  275. }
  276. - spin_unlock_irqrestore(&unwind_lock, flags);
  277. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  278. }
  279. pr_debug("%s: idx = %p\n", __func__, idx);
  280. @@ -529,9 +529,9 @@
  281. tab->begin_addr = text_addr;
  282. tab->end_addr = text_addr + text_size;
  283. - spin_lock_irqsave(&unwind_lock, flags);
  284. + raw_spin_lock_irqsave(&unwind_lock, flags);
  285. list_add_tail(&tab->list, &unwind_tables);
  286. - spin_unlock_irqrestore(&unwind_lock, flags);
  287. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  288. return tab;
  289. }
  290. @@ -543,9 +543,9 @@
  291. if (!tab)
  292. return;
  293. - spin_lock_irqsave(&unwind_lock, flags);
  294. + raw_spin_lock_irqsave(&unwind_lock, flags);
  295. list_del(&tab->list);
  296. - spin_unlock_irqrestore(&unwind_lock, flags);
  297. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  298. kfree(tab);
  299. }
  300. diff -Nur linux-4.9.6.orig/arch/arm/kvm/arm.c linux-4.9.6/arch/arm/kvm/arm.c
  301. --- linux-4.9.6.orig/arch/arm/kvm/arm.c 2017-01-26 08:25:24.000000000 +0100
  302. +++ linux-4.9.6/arch/arm/kvm/arm.c 2017-01-28 13:59:09.895654805 +0100
  303. @@ -619,7 +619,7 @@
  304. * involves poking the GIC, which must be done in a
  305. * non-preemptible context.
  306. */
  307. - preempt_disable();
  308. + migrate_disable();
  309. kvm_pmu_flush_hwstate(vcpu);
  310. kvm_timer_flush_hwstate(vcpu);
  311. kvm_vgic_flush_hwstate(vcpu);
  312. @@ -640,7 +640,7 @@
  313. kvm_pmu_sync_hwstate(vcpu);
  314. kvm_timer_sync_hwstate(vcpu);
  315. kvm_vgic_sync_hwstate(vcpu);
  316. - preempt_enable();
  317. + migrate_enable();
  318. continue;
  319. }
  320. @@ -696,7 +696,7 @@
  321. kvm_vgic_sync_hwstate(vcpu);
  322. - preempt_enable();
  323. + migrate_enable();
  324. ret = handle_exit(vcpu, run, ret);
  325. }
  326. diff -Nur linux-4.9.6.orig/arch/arm/mach-exynos/platsmp.c linux-4.9.6/arch/arm/mach-exynos/platsmp.c
  327. --- linux-4.9.6.orig/arch/arm/mach-exynos/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  328. +++ linux-4.9.6/arch/arm/mach-exynos/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  329. @@ -229,7 +229,7 @@
  330. return (void __iomem *)(S5P_VA_SCU);
  331. }
  332. -static DEFINE_SPINLOCK(boot_lock);
  333. +static DEFINE_RAW_SPINLOCK(boot_lock);
  334. static void exynos_secondary_init(unsigned int cpu)
  335. {
  336. @@ -242,8 +242,8 @@
  337. /*
  338. * Synchronise with the boot thread.
  339. */
  340. - spin_lock(&boot_lock);
  341. - spin_unlock(&boot_lock);
  342. + raw_spin_lock(&boot_lock);
  343. + raw_spin_unlock(&boot_lock);
  344. }
  345. int exynos_set_boot_addr(u32 core_id, unsigned long boot_addr)
  346. @@ -307,7 +307,7 @@
  347. * Set synchronisation state between this boot processor
  348. * and the secondary one
  349. */
  350. - spin_lock(&boot_lock);
  351. + raw_spin_lock(&boot_lock);
  352. /*
  353. * The secondary processor is waiting to be released from
  354. @@ -334,7 +334,7 @@
  355. if (timeout == 0) {
  356. printk(KERN_ERR "cpu1 power enable failed");
  357. - spin_unlock(&boot_lock);
  358. + raw_spin_unlock(&boot_lock);
  359. return -ETIMEDOUT;
  360. }
  361. }
  362. @@ -380,7 +380,7 @@
  363. * calibrations, then wait for it to finish
  364. */
  365. fail:
  366. - spin_unlock(&boot_lock);
  367. + raw_spin_unlock(&boot_lock);
  368. return pen_release != -1 ? ret : 0;
  369. }
  370. diff -Nur linux-4.9.6.orig/arch/arm/mach-hisi/platmcpm.c linux-4.9.6/arch/arm/mach-hisi/platmcpm.c
  371. --- linux-4.9.6.orig/arch/arm/mach-hisi/platmcpm.c 2017-01-26 08:25:24.000000000 +0100
  372. +++ linux-4.9.6/arch/arm/mach-hisi/platmcpm.c 2017-01-28 13:59:09.895654805 +0100
  373. @@ -61,7 +61,7 @@
  374. static void __iomem *sysctrl, *fabric;
  375. static int hip04_cpu_table[HIP04_MAX_CLUSTERS][HIP04_MAX_CPUS_PER_CLUSTER];
  376. -static DEFINE_SPINLOCK(boot_lock);
  377. +static DEFINE_RAW_SPINLOCK(boot_lock);
  378. static u32 fabric_phys_addr;
  379. /*
  380. * [0]: bootwrapper physical address
  381. @@ -113,7 +113,7 @@
  382. if (cluster >= HIP04_MAX_CLUSTERS || cpu >= HIP04_MAX_CPUS_PER_CLUSTER)
  383. return -EINVAL;
  384. - spin_lock_irq(&boot_lock);
  385. + raw_spin_lock_irq(&boot_lock);
  386. if (hip04_cpu_table[cluster][cpu])
  387. goto out;
  388. @@ -147,7 +147,7 @@
  389. out:
  390. hip04_cpu_table[cluster][cpu]++;
  391. - spin_unlock_irq(&boot_lock);
  392. + raw_spin_unlock_irq(&boot_lock);
  393. return 0;
  394. }
  395. @@ -162,11 +162,11 @@
  396. cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  397. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  398. - spin_lock(&boot_lock);
  399. + raw_spin_lock(&boot_lock);
  400. hip04_cpu_table[cluster][cpu]--;
  401. if (hip04_cpu_table[cluster][cpu] == 1) {
  402. /* A power_up request went ahead of us. */
  403. - spin_unlock(&boot_lock);
  404. + raw_spin_unlock(&boot_lock);
  405. return;
  406. } else if (hip04_cpu_table[cluster][cpu] > 1) {
  407. pr_err("Cluster %d CPU%d boots multiple times\n", cluster, cpu);
  408. @@ -174,7 +174,7 @@
  409. }
  410. last_man = hip04_cluster_is_down(cluster);
  411. - spin_unlock(&boot_lock);
  412. + raw_spin_unlock(&boot_lock);
  413. if (last_man) {
  414. /* Since it's Cortex A15, disable L2 prefetching. */
  415. asm volatile(
  416. @@ -203,7 +203,7 @@
  417. cpu >= HIP04_MAX_CPUS_PER_CLUSTER);
  418. count = TIMEOUT_MSEC / POLL_MSEC;
  419. - spin_lock_irq(&boot_lock);
  420. + raw_spin_lock_irq(&boot_lock);
  421. for (tries = 0; tries < count; tries++) {
  422. if (hip04_cpu_table[cluster][cpu])
  423. goto err;
  424. @@ -211,10 +211,10 @@
  425. data = readl_relaxed(sysctrl + SC_CPU_RESET_STATUS(cluster));
  426. if (data & CORE_WFI_STATUS(cpu))
  427. break;
  428. - spin_unlock_irq(&boot_lock);
  429. + raw_spin_unlock_irq(&boot_lock);
  430. /* Wait for clean L2 when the whole cluster is down. */
  431. msleep(POLL_MSEC);
  432. - spin_lock_irq(&boot_lock);
  433. + raw_spin_lock_irq(&boot_lock);
  434. }
  435. if (tries >= count)
  436. goto err;
  437. @@ -231,10 +231,10 @@
  438. goto err;
  439. if (hip04_cluster_is_down(cluster))
  440. hip04_set_snoop_filter(cluster, 0);
  441. - spin_unlock_irq(&boot_lock);
  442. + raw_spin_unlock_irq(&boot_lock);
  443. return 1;
  444. err:
  445. - spin_unlock_irq(&boot_lock);
  446. + raw_spin_unlock_irq(&boot_lock);
  447. return 0;
  448. }
  449. #endif
  450. diff -Nur linux-4.9.6.orig/arch/arm/mach-omap2/omap-smp.c linux-4.9.6/arch/arm/mach-omap2/omap-smp.c
  451. --- linux-4.9.6.orig/arch/arm/mach-omap2/omap-smp.c 2017-01-26 08:25:24.000000000 +0100
  452. +++ linux-4.9.6/arch/arm/mach-omap2/omap-smp.c 2017-01-28 13:59:09.895654805 +0100
  453. @@ -64,7 +64,7 @@
  454. .startup_addr = omap5_secondary_startup,
  455. };
  456. -static DEFINE_SPINLOCK(boot_lock);
  457. +static DEFINE_RAW_SPINLOCK(boot_lock);
  458. void __iomem *omap4_get_scu_base(void)
  459. {
  460. @@ -131,8 +131,8 @@
  461. /*
  462. * Synchronise with the boot thread.
  463. */
  464. - spin_lock(&boot_lock);
  465. - spin_unlock(&boot_lock);
  466. + raw_spin_lock(&boot_lock);
  467. + raw_spin_unlock(&boot_lock);
  468. }
  469. static int omap4_boot_secondary(unsigned int cpu, struct task_struct *idle)
  470. @@ -146,7 +146,7 @@
  471. * Set synchronisation state between this boot processor
  472. * and the secondary one
  473. */
  474. - spin_lock(&boot_lock);
  475. + raw_spin_lock(&boot_lock);
  476. /*
  477. * Update the AuxCoreBoot0 with boot state for secondary core.
  478. @@ -223,7 +223,7 @@
  479. * Now the secondary core is starting up let it run its
  480. * calibrations, then wait for it to finish
  481. */
  482. - spin_unlock(&boot_lock);
  483. + raw_spin_unlock(&boot_lock);
  484. return 0;
  485. }
  486. diff -Nur linux-4.9.6.orig/arch/arm/mach-prima2/platsmp.c linux-4.9.6/arch/arm/mach-prima2/platsmp.c
  487. --- linux-4.9.6.orig/arch/arm/mach-prima2/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  488. +++ linux-4.9.6/arch/arm/mach-prima2/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  489. @@ -22,7 +22,7 @@
  490. static void __iomem *clk_base;
  491. -static DEFINE_SPINLOCK(boot_lock);
  492. +static DEFINE_RAW_SPINLOCK(boot_lock);
  493. static void sirfsoc_secondary_init(unsigned int cpu)
  494. {
  495. @@ -36,8 +36,8 @@
  496. /*
  497. * Synchronise with the boot thread.
  498. */
  499. - spin_lock(&boot_lock);
  500. - spin_unlock(&boot_lock);
  501. + raw_spin_lock(&boot_lock);
  502. + raw_spin_unlock(&boot_lock);
  503. }
  504. static const struct of_device_id clk_ids[] = {
  505. @@ -75,7 +75,7 @@
  506. /* make sure write buffer is drained */
  507. mb();
  508. - spin_lock(&boot_lock);
  509. + raw_spin_lock(&boot_lock);
  510. /*
  511. * The secondary processor is waiting to be released from
  512. @@ -107,7 +107,7 @@
  513. * now the secondary core is starting up let it run its
  514. * calibrations, then wait for it to finish
  515. */
  516. - spin_unlock(&boot_lock);
  517. + raw_spin_unlock(&boot_lock);
  518. return pen_release != -1 ? -ENOSYS : 0;
  519. }
  520. diff -Nur linux-4.9.6.orig/arch/arm/mach-qcom/platsmp.c linux-4.9.6/arch/arm/mach-qcom/platsmp.c
  521. --- linux-4.9.6.orig/arch/arm/mach-qcom/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  522. +++ linux-4.9.6/arch/arm/mach-qcom/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  523. @@ -46,7 +46,7 @@
  524. extern void secondary_startup_arm(void);
  525. -static DEFINE_SPINLOCK(boot_lock);
  526. +static DEFINE_RAW_SPINLOCK(boot_lock);
  527. #ifdef CONFIG_HOTPLUG_CPU
  528. static void qcom_cpu_die(unsigned int cpu)
  529. @@ -60,8 +60,8 @@
  530. /*
  531. * Synchronise with the boot thread.
  532. */
  533. - spin_lock(&boot_lock);
  534. - spin_unlock(&boot_lock);
  535. + raw_spin_lock(&boot_lock);
  536. + raw_spin_unlock(&boot_lock);
  537. }
  538. static int scss_release_secondary(unsigned int cpu)
  539. @@ -284,7 +284,7 @@
  540. * set synchronisation state between this boot processor
  541. * and the secondary one
  542. */
  543. - spin_lock(&boot_lock);
  544. + raw_spin_lock(&boot_lock);
  545. /*
  546. * Send the secondary CPU a soft interrupt, thereby causing
  547. @@ -297,7 +297,7 @@
  548. * now the secondary core is starting up let it run its
  549. * calibrations, then wait for it to finish
  550. */
  551. - spin_unlock(&boot_lock);
  552. + raw_spin_unlock(&boot_lock);
  553. return ret;
  554. }
  555. diff -Nur linux-4.9.6.orig/arch/arm/mach-spear/platsmp.c linux-4.9.6/arch/arm/mach-spear/platsmp.c
  556. --- linux-4.9.6.orig/arch/arm/mach-spear/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  557. +++ linux-4.9.6/arch/arm/mach-spear/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  558. @@ -32,7 +32,7 @@
  559. sync_cache_w(&pen_release);
  560. }
  561. -static DEFINE_SPINLOCK(boot_lock);
  562. +static DEFINE_RAW_SPINLOCK(boot_lock);
  563. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  564. @@ -47,8 +47,8 @@
  565. /*
  566. * Synchronise with the boot thread.
  567. */
  568. - spin_lock(&boot_lock);
  569. - spin_unlock(&boot_lock);
  570. + raw_spin_lock(&boot_lock);
  571. + raw_spin_unlock(&boot_lock);
  572. }
  573. static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  574. @@ -59,7 +59,7 @@
  575. * set synchronisation state between this boot processor
  576. * and the secondary one
  577. */
  578. - spin_lock(&boot_lock);
  579. + raw_spin_lock(&boot_lock);
  580. /*
  581. * The secondary processor is waiting to be released from
  582. @@ -84,7 +84,7 @@
  583. * now the secondary core is starting up let it run its
  584. * calibrations, then wait for it to finish
  585. */
  586. - spin_unlock(&boot_lock);
  587. + raw_spin_unlock(&boot_lock);
  588. return pen_release != -1 ? -ENOSYS : 0;
  589. }
  590. diff -Nur linux-4.9.6.orig/arch/arm/mach-sti/platsmp.c linux-4.9.6/arch/arm/mach-sti/platsmp.c
  591. --- linux-4.9.6.orig/arch/arm/mach-sti/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  592. +++ linux-4.9.6/arch/arm/mach-sti/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  593. @@ -35,7 +35,7 @@
  594. sync_cache_w(&pen_release);
  595. }
  596. -static DEFINE_SPINLOCK(boot_lock);
  597. +static DEFINE_RAW_SPINLOCK(boot_lock);
  598. static void sti_secondary_init(unsigned int cpu)
  599. {
  600. @@ -48,8 +48,8 @@
  601. /*
  602. * Synchronise with the boot thread.
  603. */
  604. - spin_lock(&boot_lock);
  605. - spin_unlock(&boot_lock);
  606. + raw_spin_lock(&boot_lock);
  607. + raw_spin_unlock(&boot_lock);
  608. }
  609. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  610. @@ -60,7 +60,7 @@
  611. * set synchronisation state between this boot processor
  612. * and the secondary one
  613. */
  614. - spin_lock(&boot_lock);
  615. + raw_spin_lock(&boot_lock);
  616. /*
  617. * The secondary processor is waiting to be released from
  618. @@ -91,7 +91,7 @@
  619. * now the secondary core is starting up let it run its
  620. * calibrations, then wait for it to finish
  621. */
  622. - spin_unlock(&boot_lock);
  623. + raw_spin_unlock(&boot_lock);
  624. return pen_release != -1 ? -ENOSYS : 0;
  625. }
  626. diff -Nur linux-4.9.6.orig/arch/arm/mm/fault.c linux-4.9.6/arch/arm/mm/fault.c
  627. --- linux-4.9.6.orig/arch/arm/mm/fault.c 2017-01-26 08:25:24.000000000 +0100
  628. +++ linux-4.9.6/arch/arm/mm/fault.c 2017-01-28 13:59:09.895654805 +0100
  629. @@ -430,6 +430,9 @@
  630. if (addr < TASK_SIZE)
  631. return do_page_fault(addr, fsr, regs);
  632. + if (interrupts_enabled(regs))
  633. + local_irq_enable();
  634. +
  635. if (user_mode(regs))
  636. goto bad_area;
  637. @@ -497,6 +500,9 @@
  638. static int
  639. do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  640. {
  641. + if (interrupts_enabled(regs))
  642. + local_irq_enable();
  643. +
  644. do_bad_area(addr, fsr, regs);
  645. return 0;
  646. }
  647. diff -Nur linux-4.9.6.orig/arch/arm/mm/highmem.c linux-4.9.6/arch/arm/mm/highmem.c
  648. --- linux-4.9.6.orig/arch/arm/mm/highmem.c 2017-01-26 08:25:24.000000000 +0100
  649. +++ linux-4.9.6/arch/arm/mm/highmem.c 2017-01-28 13:59:09.895654805 +0100
  650. @@ -34,6 +34,11 @@
  651. return *ptep;
  652. }
  653. +static unsigned int fixmap_idx(int type)
  654. +{
  655. + return FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  656. +}
  657. +
  658. void *kmap(struct page *page)
  659. {
  660. might_sleep();
  661. @@ -54,12 +59,13 @@
  662. void *kmap_atomic(struct page *page)
  663. {
  664. + pte_t pte = mk_pte(page, kmap_prot);
  665. unsigned int idx;
  666. unsigned long vaddr;
  667. void *kmap;
  668. int type;
  669. - preempt_disable();
  670. + preempt_disable_nort();
  671. pagefault_disable();
  672. if (!PageHighMem(page))
  673. return page_address(page);
  674. @@ -79,7 +85,7 @@
  675. type = kmap_atomic_idx_push();
  676. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  677. + idx = fixmap_idx(type);
  678. vaddr = __fix_to_virt(idx);
  679. #ifdef CONFIG_DEBUG_HIGHMEM
  680. /*
  681. @@ -93,7 +99,10 @@
  682. * in place, so the contained TLB flush ensures the TLB is updated
  683. * with the new mapping.
  684. */
  685. - set_fixmap_pte(idx, mk_pte(page, kmap_prot));
  686. +#ifdef CONFIG_PREEMPT_RT_FULL
  687. + current->kmap_pte[type] = pte;
  688. +#endif
  689. + set_fixmap_pte(idx, pte);
  690. return (void *)vaddr;
  691. }
  692. @@ -106,44 +115,75 @@
  693. if (kvaddr >= (void *)FIXADDR_START) {
  694. type = kmap_atomic_idx();
  695. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  696. + idx = fixmap_idx(type);
  697. if (cache_is_vivt())
  698. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
  699. +#ifdef CONFIG_PREEMPT_RT_FULL
  700. + current->kmap_pte[type] = __pte(0);
  701. +#endif
  702. #ifdef CONFIG_DEBUG_HIGHMEM
  703. BUG_ON(vaddr != __fix_to_virt(idx));
  704. - set_fixmap_pte(idx, __pte(0));
  705. #else
  706. (void) idx; /* to kill a warning */
  707. #endif
  708. + set_fixmap_pte(idx, __pte(0));
  709. kmap_atomic_idx_pop();
  710. } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
  711. /* this address was obtained through kmap_high_get() */
  712. kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
  713. }
  714. pagefault_enable();
  715. - preempt_enable();
  716. + preempt_enable_nort();
  717. }
  718. EXPORT_SYMBOL(__kunmap_atomic);
  719. void *kmap_atomic_pfn(unsigned long pfn)
  720. {
  721. + pte_t pte = pfn_pte(pfn, kmap_prot);
  722. unsigned long vaddr;
  723. int idx, type;
  724. struct page *page = pfn_to_page(pfn);
  725. - preempt_disable();
  726. + preempt_disable_nort();
  727. pagefault_disable();
  728. if (!PageHighMem(page))
  729. return page_address(page);
  730. type = kmap_atomic_idx_push();
  731. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  732. + idx = fixmap_idx(type);
  733. vaddr = __fix_to_virt(idx);
  734. #ifdef CONFIG_DEBUG_HIGHMEM
  735. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  736. #endif
  737. - set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
  738. +#ifdef CONFIG_PREEMPT_RT_FULL
  739. + current->kmap_pte[type] = pte;
  740. +#endif
  741. + set_fixmap_pte(idx, pte);
  742. return (void *)vaddr;
  743. }
  744. +#if defined CONFIG_PREEMPT_RT_FULL
  745. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  746. +{
  747. + int i;
  748. +
  749. + /*
  750. + * Clear @prev's kmap_atomic mappings
  751. + */
  752. + for (i = 0; i < prev_p->kmap_idx; i++) {
  753. + int idx = fixmap_idx(i);
  754. +
  755. + set_fixmap_pte(idx, __pte(0));
  756. + }
  757. + /*
  758. + * Restore @next_p's kmap_atomic mappings
  759. + */
  760. + for (i = 0; i < next_p->kmap_idx; i++) {
  761. + int idx = fixmap_idx(i);
  762. +
  763. + if (!pte_none(next_p->kmap_pte[i]))
  764. + set_fixmap_pte(idx, next_p->kmap_pte[i]);
  765. + }
  766. +}
  767. +#endif
  768. diff -Nur linux-4.9.6.orig/arch/arm/plat-versatile/platsmp.c linux-4.9.6/arch/arm/plat-versatile/platsmp.c
  769. --- linux-4.9.6.orig/arch/arm/plat-versatile/platsmp.c 2017-01-26 08:25:24.000000000 +0100
  770. +++ linux-4.9.6/arch/arm/plat-versatile/platsmp.c 2017-01-28 13:59:09.895654805 +0100
  771. @@ -32,7 +32,7 @@
  772. sync_cache_w(&pen_release);
  773. }
  774. -static DEFINE_SPINLOCK(boot_lock);
  775. +static DEFINE_RAW_SPINLOCK(boot_lock);
  776. void versatile_secondary_init(unsigned int cpu)
  777. {
  778. @@ -45,8 +45,8 @@
  779. /*
  780. * Synchronise with the boot thread.
  781. */
  782. - spin_lock(&boot_lock);
  783. - spin_unlock(&boot_lock);
  784. + raw_spin_lock(&boot_lock);
  785. + raw_spin_unlock(&boot_lock);
  786. }
  787. int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
  788. @@ -57,7 +57,7 @@
  789. * Set synchronisation state between this boot processor
  790. * and the secondary one
  791. */
  792. - spin_lock(&boot_lock);
  793. + raw_spin_lock(&boot_lock);
  794. /*
  795. * This is really belt and braces; we hold unintended secondary
  796. @@ -87,7 +87,7 @@
  797. * now the secondary core is starting up let it run its
  798. * calibrations, then wait for it to finish
  799. */
  800. - spin_unlock(&boot_lock);
  801. + raw_spin_unlock(&boot_lock);
  802. return pen_release != -1 ? -ENOSYS : 0;
  803. }
  804. diff -Nur linux-4.9.6.orig/arch/arm64/include/asm/thread_info.h linux-4.9.6/arch/arm64/include/asm/thread_info.h
  805. --- linux-4.9.6.orig/arch/arm64/include/asm/thread_info.h 2017-01-26 08:25:24.000000000 +0100
  806. +++ linux-4.9.6/arch/arm64/include/asm/thread_info.h 2017-01-28 13:59:09.895654805 +0100
  807. @@ -49,6 +49,7 @@
  808. mm_segment_t addr_limit; /* address limit */
  809. struct task_struct *task; /* main task structure */
  810. int preempt_count; /* 0 => preemptable, <0 => bug */
  811. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  812. int cpu; /* cpu */
  813. };
  814. @@ -112,6 +113,7 @@
  815. #define TIF_NEED_RESCHED 1
  816. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  817. #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */
  818. +#define TIF_NEED_RESCHED_LAZY 4
  819. #define TIF_NOHZ 7
  820. #define TIF_SYSCALL_TRACE 8
  821. #define TIF_SYSCALL_AUDIT 9
  822. @@ -127,6 +129,7 @@
  823. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  824. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  825. #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE)
  826. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  827. #define _TIF_NOHZ (1 << TIF_NOHZ)
  828. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  829. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  830. @@ -135,7 +138,9 @@
  831. #define _TIF_32BIT (1 << TIF_32BIT)
  832. #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
  833. - _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
  834. + _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
  835. + _TIF_NEED_RESCHED_LAZY)
  836. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  837. #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  838. _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
  839. diff -Nur linux-4.9.6.orig/arch/arm64/Kconfig linux-4.9.6/arch/arm64/Kconfig
  840. --- linux-4.9.6.orig/arch/arm64/Kconfig 2017-01-26 08:25:24.000000000 +0100
  841. +++ linux-4.9.6/arch/arm64/Kconfig 2017-01-28 13:59:09.895654805 +0100
  842. @@ -91,6 +91,7 @@
  843. select HAVE_PERF_EVENTS
  844. select HAVE_PERF_REGS
  845. select HAVE_PERF_USER_STACK_DUMP
  846. + select HAVE_PREEMPT_LAZY
  847. select HAVE_REGS_AND_STACK_ACCESS_API
  848. select HAVE_RCU_TABLE_FREE
  849. select HAVE_SYSCALL_TRACEPOINTS
  850. @@ -694,7 +695,7 @@
  851. config XEN
  852. bool "Xen guest support on ARM64"
  853. - depends on ARM64 && OF
  854. + depends on ARM64 && OF && !PREEMPT_RT_FULL
  855. select SWIOTLB_XEN
  856. select PARAVIRT
  857. help
  858. diff -Nur linux-4.9.6.orig/arch/arm64/kernel/asm-offsets.c linux-4.9.6/arch/arm64/kernel/asm-offsets.c
  859. --- linux-4.9.6.orig/arch/arm64/kernel/asm-offsets.c 2017-01-26 08:25:24.000000000 +0100
  860. +++ linux-4.9.6/arch/arm64/kernel/asm-offsets.c 2017-01-28 13:59:09.895654805 +0100
  861. @@ -38,6 +38,7 @@
  862. BLANK();
  863. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  864. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  865. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  866. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  867. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  868. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  869. diff -Nur linux-4.9.6.orig/arch/arm64/kernel/entry.S linux-4.9.6/arch/arm64/kernel/entry.S
  870. --- linux-4.9.6.orig/arch/arm64/kernel/entry.S 2017-01-26 08:25:24.000000000 +0100
  871. +++ linux-4.9.6/arch/arm64/kernel/entry.S 2017-01-28 13:59:09.895654805 +0100
  872. @@ -428,11 +428,16 @@
  873. #ifdef CONFIG_PREEMPT
  874. ldr w24, [tsk, #TI_PREEMPT] // get preempt count
  875. - cbnz w24, 1f // preempt count != 0
  876. + cbnz w24, 2f // preempt count != 0
  877. ldr x0, [tsk, #TI_FLAGS] // get flags
  878. - tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  879. - bl el1_preempt
  880. + tbnz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  881. +
  882. + ldr w24, [tsk, #TI_PREEMPT_LAZY] // get preempt lazy count
  883. + cbnz w24, 2f // preempt lazy count != 0
  884. + tbz x0, #TIF_NEED_RESCHED_LAZY, 2f // needs rescheduling?
  885. 1:
  886. + bl el1_preempt
  887. +2:
  888. #endif
  889. #ifdef CONFIG_TRACE_IRQFLAGS
  890. bl trace_hardirqs_on
  891. @@ -446,6 +451,7 @@
  892. 1: bl preempt_schedule_irq // irq en/disable is done inside
  893. ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
  894. tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
  895. + tbnz x0, #TIF_NEED_RESCHED_LAZY, 1b // needs rescheduling?
  896. ret x24
  897. #endif
  898. diff -Nur linux-4.9.6.orig/arch/arm64/kernel/signal.c linux-4.9.6/arch/arm64/kernel/signal.c
  899. --- linux-4.9.6.orig/arch/arm64/kernel/signal.c 2017-01-26 08:25:24.000000000 +0100
  900. +++ linux-4.9.6/arch/arm64/kernel/signal.c 2017-01-28 13:59:09.895654805 +0100
  901. @@ -409,7 +409,7 @@
  902. */
  903. trace_hardirqs_off();
  904. do {
  905. - if (thread_flags & _TIF_NEED_RESCHED) {
  906. + if (thread_flags & _TIF_NEED_RESCHED_MASK) {
  907. schedule();
  908. } else {
  909. local_irq_enable();
  910. diff -Nur linux-4.9.6.orig/arch/Kconfig linux-4.9.6/arch/Kconfig
  911. --- linux-4.9.6.orig/arch/Kconfig 2017-01-26 08:25:24.000000000 +0100
  912. +++ linux-4.9.6/arch/Kconfig 2017-01-28 13:59:09.887654498 +0100
  913. @@ -9,6 +9,7 @@
  914. tristate "OProfile system profiling"
  915. depends on PROFILING
  916. depends on HAVE_OPROFILE
  917. + depends on !PREEMPT_RT_FULL
  918. select RING_BUFFER
  919. select RING_BUFFER_ALLOW_SWAP
  920. help
  921. @@ -52,6 +53,7 @@
  922. config JUMP_LABEL
  923. bool "Optimize very unlikely/likely branches"
  924. depends on HAVE_ARCH_JUMP_LABEL
  925. + depends on (!INTERRUPT_OFF_HIST && !PREEMPT_OFF_HIST && !WAKEUP_LATENCY_HIST && !MISSED_TIMER_OFFSETS_HIST)
  926. help
  927. This option enables a transparent branch optimization that
  928. makes certain almost-always-true or almost-always-false branch
  929. diff -Nur linux-4.9.6.orig/arch/mips/Kconfig linux-4.9.6/arch/mips/Kconfig
  930. --- linux-4.9.6.orig/arch/mips/Kconfig 2017-01-26 08:25:24.000000000 +0100
  931. +++ linux-4.9.6/arch/mips/Kconfig 2017-01-28 13:59:09.895654805 +0100
  932. @@ -2514,7 +2514,7 @@
  933. #
  934. config HIGHMEM
  935. bool "High Memory Support"
  936. - depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA
  937. + depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA && !PREEMPT_RT_FULL
  938. config CPU_SUPPORTS_HIGHMEM
  939. bool
  940. diff -Nur linux-4.9.6.orig/arch/powerpc/include/asm/thread_info.h linux-4.9.6/arch/powerpc/include/asm/thread_info.h
  941. --- linux-4.9.6.orig/arch/powerpc/include/asm/thread_info.h 2017-01-26 08:25:24.000000000 +0100
  942. +++ linux-4.9.6/arch/powerpc/include/asm/thread_info.h 2017-01-28 13:59:09.895654805 +0100
  943. @@ -43,6 +43,8 @@
  944. int cpu; /* cpu we're on */
  945. int preempt_count; /* 0 => preemptable,
  946. <0 => BUG */
  947. + int preempt_lazy_count; /* 0 => preemptable,
  948. + <0 => BUG */
  949. unsigned long local_flags; /* private flags for thread */
  950. #ifdef CONFIG_LIVEPATCH
  951. unsigned long *livepatch_sp;
  952. @@ -88,8 +90,7 @@
  953. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  954. #define TIF_SIGPENDING 1 /* signal pending */
  955. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  956. -#define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  957. - TIF_NEED_RESCHED */
  958. +#define TIF_NEED_RESCHED_LAZY 3 /* lazy rescheduling necessary */
  959. #define TIF_32BIT 4 /* 32 bit binary */
  960. #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
  961. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  962. @@ -107,6 +108,8 @@
  963. #if defined(CONFIG_PPC64)
  964. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  965. #endif
  966. +#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling
  967. + TIF_NEED_RESCHED */
  968. /* as above, but as bit values */
  969. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  970. @@ -125,14 +128,16 @@
  971. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  972. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  973. #define _TIF_NOHZ (1<<TIF_NOHZ)
  974. +#define _TIF_NEED_RESCHED_LAZY (1<<TIF_NEED_RESCHED_LAZY)
  975. #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  976. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  977. _TIF_NOHZ)
  978. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  979. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  980. - _TIF_RESTORE_TM)
  981. + _TIF_RESTORE_TM | _TIF_NEED_RESCHED_LAZY)
  982. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  983. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  984. /* Bits in local_flags */
  985. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  986. diff -Nur linux-4.9.6.orig/arch/powerpc/Kconfig linux-4.9.6/arch/powerpc/Kconfig
  987. --- linux-4.9.6.orig/arch/powerpc/Kconfig 2017-01-26 08:25:24.000000000 +0100
  988. +++ linux-4.9.6/arch/powerpc/Kconfig 2017-01-28 13:59:09.895654805 +0100
  989. @@ -52,10 +52,11 @@
  990. config RWSEM_GENERIC_SPINLOCK
  991. bool
  992. + default y if PREEMPT_RT_FULL
  993. config RWSEM_XCHGADD_ALGORITHM
  994. bool
  995. - default y
  996. + default y if !PREEMPT_RT_FULL
  997. config GENERIC_LOCKBREAK
  998. bool
  999. @@ -134,6 +135,7 @@
  1000. select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
  1001. select GENERIC_STRNCPY_FROM_USER
  1002. select GENERIC_STRNLEN_USER
  1003. + select HAVE_PREEMPT_LAZY
  1004. select HAVE_MOD_ARCH_SPECIFIC
  1005. select MODULES_USE_ELF_RELA
  1006. select CLONE_BACKWARDS
  1007. @@ -321,7 +323,7 @@
  1008. config HIGHMEM
  1009. bool "High memory support"
  1010. - depends on PPC32
  1011. + depends on PPC32 && !PREEMPT_RT_FULL
  1012. source kernel/Kconfig.hz
  1013. source kernel/Kconfig.preempt
  1014. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/asm-offsets.c linux-4.9.6/arch/powerpc/kernel/asm-offsets.c
  1015. --- linux-4.9.6.orig/arch/powerpc/kernel/asm-offsets.c 2017-01-26 08:25:24.000000000 +0100
  1016. +++ linux-4.9.6/arch/powerpc/kernel/asm-offsets.c 2017-01-28 13:59:09.895654805 +0100
  1017. @@ -156,6 +156,7 @@
  1018. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1019. DEFINE(TI_LOCAL_FLAGS, offsetof(struct thread_info, local_flags));
  1020. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1021. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1022. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1023. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1024. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/entry_32.S linux-4.9.6/arch/powerpc/kernel/entry_32.S
  1025. --- linux-4.9.6.orig/arch/powerpc/kernel/entry_32.S 2017-01-26 08:25:24.000000000 +0100
  1026. +++ linux-4.9.6/arch/powerpc/kernel/entry_32.S 2017-01-28 13:59:09.895654805 +0100
  1027. @@ -835,7 +835,14 @@
  1028. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1029. bne restore
  1030. andi. r8,r8,_TIF_NEED_RESCHED
  1031. + bne+ 1f
  1032. + lwz r0,TI_PREEMPT_LAZY(r9)
  1033. + cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1034. + bne restore
  1035. + lwz r0,TI_FLAGS(r9)
  1036. + andi. r0,r0,_TIF_NEED_RESCHED_LAZY
  1037. beq+ restore
  1038. +1:
  1039. lwz r3,_MSR(r1)
  1040. andi. r0,r3,MSR_EE /* interrupts off? */
  1041. beq restore /* don't schedule if so */
  1042. @@ -846,11 +853,11 @@
  1043. */
  1044. bl trace_hardirqs_off
  1045. #endif
  1046. -1: bl preempt_schedule_irq
  1047. +2: bl preempt_schedule_irq
  1048. CURRENT_THREAD_INFO(r9, r1)
  1049. lwz r3,TI_FLAGS(r9)
  1050. - andi. r0,r3,_TIF_NEED_RESCHED
  1051. - bne- 1b
  1052. + andi. r0,r3,_TIF_NEED_RESCHED_MASK
  1053. + bne- 2b
  1054. #ifdef CONFIG_TRACE_IRQFLAGS
  1055. /* And now, to properly rebalance the above, we tell lockdep they
  1056. * are being turned back on, which will happen when we return
  1057. @@ -1171,7 +1178,7 @@
  1058. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  1059. do_work: /* r10 contains MSR_KERNEL here */
  1060. - andi. r0,r9,_TIF_NEED_RESCHED
  1061. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1062. beq do_user_signal
  1063. do_resched: /* r10 contains MSR_KERNEL here */
  1064. @@ -1192,7 +1199,7 @@
  1065. MTMSRD(r10) /* disable interrupts */
  1066. CURRENT_THREAD_INFO(r9, r1)
  1067. lwz r9,TI_FLAGS(r9)
  1068. - andi. r0,r9,_TIF_NEED_RESCHED
  1069. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1070. bne- do_resched
  1071. andi. r0,r9,_TIF_USER_WORK_MASK
  1072. beq restore_user
  1073. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/entry_64.S linux-4.9.6/arch/powerpc/kernel/entry_64.S
  1074. --- linux-4.9.6.orig/arch/powerpc/kernel/entry_64.S 2017-01-26 08:25:24.000000000 +0100
  1075. +++ linux-4.9.6/arch/powerpc/kernel/entry_64.S 2017-01-28 13:59:09.895654805 +0100
  1076. @@ -656,7 +656,7 @@
  1077. bl restore_math
  1078. b restore
  1079. #endif
  1080. -1: andi. r0,r4,_TIF_NEED_RESCHED
  1081. +1: andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1082. beq 2f
  1083. bl restore_interrupts
  1084. SCHEDULE_USER
  1085. @@ -718,10 +718,18 @@
  1086. #ifdef CONFIG_PREEMPT
  1087. /* Check if we need to preempt */
  1088. + lwz r8,TI_PREEMPT(r9)
  1089. + cmpwi 0,r8,0 /* if non-zero, just restore regs and return */
  1090. + bne restore
  1091. andi. r0,r4,_TIF_NEED_RESCHED
  1092. + bne+ check_count
  1093. +
  1094. + andi. r0,r4,_TIF_NEED_RESCHED_LAZY
  1095. beq+ restore
  1096. + lwz r8,TI_PREEMPT_LAZY(r9)
  1097. +
  1098. /* Check that preempt_count() == 0 and interrupts are enabled */
  1099. - lwz r8,TI_PREEMPT(r9)
  1100. +check_count:
  1101. cmpwi cr1,r8,0
  1102. ld r0,SOFTE(r1)
  1103. cmpdi r0,0
  1104. @@ -738,7 +746,7 @@
  1105. /* Re-test flags and eventually loop */
  1106. CURRENT_THREAD_INFO(r9, r1)
  1107. ld r4,TI_FLAGS(r9)
  1108. - andi. r0,r4,_TIF_NEED_RESCHED
  1109. + andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1110. bne 1b
  1111. /*
  1112. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/irq.c linux-4.9.6/arch/powerpc/kernel/irq.c
  1113. --- linux-4.9.6.orig/arch/powerpc/kernel/irq.c 2017-01-26 08:25:24.000000000 +0100
  1114. +++ linux-4.9.6/arch/powerpc/kernel/irq.c 2017-01-28 13:59:09.895654805 +0100
  1115. @@ -638,6 +638,7 @@
  1116. }
  1117. }
  1118. +#ifndef CONFIG_PREEMPT_RT_FULL
  1119. void do_softirq_own_stack(void)
  1120. {
  1121. struct thread_info *curtp, *irqtp;
  1122. @@ -655,6 +656,7 @@
  1123. if (irqtp->flags)
  1124. set_bits(irqtp->flags, &curtp->flags);
  1125. }
  1126. +#endif
  1127. irq_hw_number_t virq_to_hw(unsigned int virq)
  1128. {
  1129. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/misc_32.S linux-4.9.6/arch/powerpc/kernel/misc_32.S
  1130. --- linux-4.9.6.orig/arch/powerpc/kernel/misc_32.S 2017-01-26 08:25:24.000000000 +0100
  1131. +++ linux-4.9.6/arch/powerpc/kernel/misc_32.S 2017-01-28 13:59:09.895654805 +0100
  1132. @@ -41,6 +41,7 @@
  1133. * We store the saved ksp_limit in the unused part
  1134. * of the STACK_FRAME_OVERHEAD
  1135. */
  1136. +#ifndef CONFIG_PREEMPT_RT_FULL
  1137. _GLOBAL(call_do_softirq)
  1138. mflr r0
  1139. stw r0,4(r1)
  1140. @@ -57,6 +58,7 @@
  1141. stw r10,THREAD+KSP_LIMIT(r2)
  1142. mtlr r0
  1143. blr
  1144. +#endif
  1145. /*
  1146. * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
  1147. diff -Nur linux-4.9.6.orig/arch/powerpc/kernel/misc_64.S linux-4.9.6/arch/powerpc/kernel/misc_64.S
  1148. --- linux-4.9.6.orig/arch/powerpc/kernel/misc_64.S 2017-01-26 08:25:24.000000000 +0100
  1149. +++ linux-4.9.6/arch/powerpc/kernel/misc_64.S 2017-01-28 13:59:09.895654805 +0100
  1150. @@ -31,6 +31,7 @@
  1151. .text
  1152. +#ifndef CONFIG_PREEMPT_RT_FULL
  1153. _GLOBAL(call_do_softirq)
  1154. mflr r0
  1155. std r0,16(r1)
  1156. @@ -41,6 +42,7 @@
  1157. ld r0,16(r1)
  1158. mtlr r0
  1159. blr
  1160. +#endif
  1161. _GLOBAL(call_do_irq)
  1162. mflr r0
  1163. diff -Nur linux-4.9.6.orig/arch/powerpc/kvm/Kconfig linux-4.9.6/arch/powerpc/kvm/Kconfig
  1164. --- linux-4.9.6.orig/arch/powerpc/kvm/Kconfig 2017-01-26 08:25:24.000000000 +0100
  1165. +++ linux-4.9.6/arch/powerpc/kvm/Kconfig 2017-01-28 13:59:09.895654805 +0100
  1166. @@ -175,6 +175,7 @@
  1167. config KVM_MPIC
  1168. bool "KVM in-kernel MPIC emulation"
  1169. depends on KVM && E500
  1170. + depends on !PREEMPT_RT_FULL
  1171. select HAVE_KVM_IRQCHIP
  1172. select HAVE_KVM_IRQFD
  1173. select HAVE_KVM_IRQ_ROUTING
  1174. diff -Nur linux-4.9.6.orig/arch/powerpc/platforms/ps3/device-init.c linux-4.9.6/arch/powerpc/platforms/ps3/device-init.c
  1175. --- linux-4.9.6.orig/arch/powerpc/platforms/ps3/device-init.c 2017-01-26 08:25:24.000000000 +0100
  1176. +++ linux-4.9.6/arch/powerpc/platforms/ps3/device-init.c 2017-01-28 13:59:09.895654805 +0100
  1177. @@ -752,7 +752,7 @@
  1178. }
  1179. pr_debug("%s:%u: notification %s issued\n", __func__, __LINE__, op);
  1180. - res = wait_event_interruptible(dev->done.wait,
  1181. + res = swait_event_interruptible(dev->done.wait,
  1182. dev->done.done || kthread_should_stop());
  1183. if (kthread_should_stop())
  1184. res = -EINTR;
  1185. diff -Nur linux-4.9.6.orig/arch/sh/kernel/irq.c linux-4.9.6/arch/sh/kernel/irq.c
  1186. --- linux-4.9.6.orig/arch/sh/kernel/irq.c 2017-01-26 08:25:24.000000000 +0100
  1187. +++ linux-4.9.6/arch/sh/kernel/irq.c 2017-01-28 13:59:09.895654805 +0100
  1188. @@ -147,6 +147,7 @@
  1189. hardirq_ctx[cpu] = NULL;
  1190. }
  1191. +#ifndef CONFIG_PREEMPT_RT_FULL
  1192. void do_softirq_own_stack(void)
  1193. {
  1194. struct thread_info *curctx;
  1195. @@ -174,6 +175,7 @@
  1196. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  1197. );
  1198. }
  1199. +#endif
  1200. #else
  1201. static inline void handle_one_irq(unsigned int irq)
  1202. {
  1203. diff -Nur linux-4.9.6.orig/arch/sparc/Kconfig linux-4.9.6/arch/sparc/Kconfig
  1204. --- linux-4.9.6.orig/arch/sparc/Kconfig 2017-01-26 08:25:24.000000000 +0100
  1205. +++ linux-4.9.6/arch/sparc/Kconfig 2017-01-28 13:59:09.895654805 +0100
  1206. @@ -194,12 +194,10 @@
  1207. source kernel/Kconfig.hz
  1208. config RWSEM_GENERIC_SPINLOCK
  1209. - bool
  1210. - default y if SPARC32
  1211. + def_bool PREEMPT_RT_FULL
  1212. config RWSEM_XCHGADD_ALGORITHM
  1213. - bool
  1214. - default y if SPARC64
  1215. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  1216. config GENERIC_HWEIGHT
  1217. bool
  1218. diff -Nur linux-4.9.6.orig/arch/sparc/kernel/irq_64.c linux-4.9.6/arch/sparc/kernel/irq_64.c
  1219. --- linux-4.9.6.orig/arch/sparc/kernel/irq_64.c 2017-01-26 08:25:24.000000000 +0100
  1220. +++ linux-4.9.6/arch/sparc/kernel/irq_64.c 2017-01-28 13:59:09.895654805 +0100
  1221. @@ -854,6 +854,7 @@
  1222. set_irq_regs(old_regs);
  1223. }
  1224. +#ifndef CONFIG_PREEMPT_RT_FULL
  1225. void do_softirq_own_stack(void)
  1226. {
  1227. void *orig_sp, *sp = softirq_stack[smp_processor_id()];
  1228. @@ -868,6 +869,7 @@
  1229. __asm__ __volatile__("mov %0, %%sp"
  1230. : : "r" (orig_sp));
  1231. }
  1232. +#endif
  1233. #ifdef CONFIG_HOTPLUG_CPU
  1234. void fixup_irqs(void)
  1235. diff -Nur linux-4.9.6.orig/arch/x86/crypto/aesni-intel_glue.c linux-4.9.6/arch/x86/crypto/aesni-intel_glue.c
  1236. --- linux-4.9.6.orig/arch/x86/crypto/aesni-intel_glue.c 2017-01-26 08:25:24.000000000 +0100
  1237. +++ linux-4.9.6/arch/x86/crypto/aesni-intel_glue.c 2017-01-28 13:59:09.895654805 +0100
  1238. @@ -372,14 +372,14 @@
  1239. err = blkcipher_walk_virt(desc, &walk);
  1240. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1241. - kernel_fpu_begin();
  1242. while ((nbytes = walk.nbytes)) {
  1243. + kernel_fpu_begin();
  1244. aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1245. - nbytes & AES_BLOCK_MASK);
  1246. + nbytes & AES_BLOCK_MASK);
  1247. + kernel_fpu_end();
  1248. nbytes &= AES_BLOCK_SIZE - 1;
  1249. err = blkcipher_walk_done(desc, &walk, nbytes);
  1250. }
  1251. - kernel_fpu_end();
  1252. return err;
  1253. }
  1254. @@ -396,14 +396,14 @@
  1255. err = blkcipher_walk_virt(desc, &walk);
  1256. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1257. - kernel_fpu_begin();
  1258. while ((nbytes = walk.nbytes)) {
  1259. + kernel_fpu_begin();
  1260. aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1261. nbytes & AES_BLOCK_MASK);
  1262. + kernel_fpu_end();
  1263. nbytes &= AES_BLOCK_SIZE - 1;
  1264. err = blkcipher_walk_done(desc, &walk, nbytes);
  1265. }
  1266. - kernel_fpu_end();
  1267. return err;
  1268. }
  1269. @@ -420,14 +420,14 @@
  1270. err = blkcipher_walk_virt(desc, &walk);
  1271. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1272. - kernel_fpu_begin();
  1273. while ((nbytes = walk.nbytes)) {
  1274. + kernel_fpu_begin();
  1275. aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1276. nbytes & AES_BLOCK_MASK, walk.iv);
  1277. + kernel_fpu_end();
  1278. nbytes &= AES_BLOCK_SIZE - 1;
  1279. err = blkcipher_walk_done(desc, &walk, nbytes);
  1280. }
  1281. - kernel_fpu_end();
  1282. return err;
  1283. }
  1284. @@ -444,14 +444,14 @@
  1285. err = blkcipher_walk_virt(desc, &walk);
  1286. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1287. - kernel_fpu_begin();
  1288. while ((nbytes = walk.nbytes)) {
  1289. + kernel_fpu_begin();
  1290. aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1291. nbytes & AES_BLOCK_MASK, walk.iv);
  1292. + kernel_fpu_end();
  1293. nbytes &= AES_BLOCK_SIZE - 1;
  1294. err = blkcipher_walk_done(desc, &walk, nbytes);
  1295. }
  1296. - kernel_fpu_end();
  1297. return err;
  1298. }
  1299. @@ -503,18 +503,20 @@
  1300. err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
  1301. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1302. - kernel_fpu_begin();
  1303. while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
  1304. + kernel_fpu_begin();
  1305. aesni_ctr_enc_tfm(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1306. nbytes & AES_BLOCK_MASK, walk.iv);
  1307. + kernel_fpu_end();
  1308. nbytes &= AES_BLOCK_SIZE - 1;
  1309. err = blkcipher_walk_done(desc, &walk, nbytes);
  1310. }
  1311. if (walk.nbytes) {
  1312. + kernel_fpu_begin();
  1313. ctr_crypt_final(ctx, &walk);
  1314. + kernel_fpu_end();
  1315. err = blkcipher_walk_done(desc, &walk, 0);
  1316. }
  1317. - kernel_fpu_end();
  1318. return err;
  1319. }
  1320. diff -Nur linux-4.9.6.orig/arch/x86/crypto/cast5_avx_glue.c linux-4.9.6/arch/x86/crypto/cast5_avx_glue.c
  1321. --- linux-4.9.6.orig/arch/x86/crypto/cast5_avx_glue.c 2017-01-26 08:25:24.000000000 +0100
  1322. +++ linux-4.9.6/arch/x86/crypto/cast5_avx_glue.c 2017-01-28 13:59:09.895654805 +0100
  1323. @@ -59,7 +59,7 @@
  1324. static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
  1325. bool enc)
  1326. {
  1327. - bool fpu_enabled = false;
  1328. + bool fpu_enabled;
  1329. struct cast5_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1330. const unsigned int bsize = CAST5_BLOCK_SIZE;
  1331. unsigned int nbytes;
  1332. @@ -75,7 +75,7 @@
  1333. u8 *wsrc = walk->src.virt.addr;
  1334. u8 *wdst = walk->dst.virt.addr;
  1335. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1336. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1337. /* Process multi-block batch */
  1338. if (nbytes >= bsize * CAST5_PARALLEL_BLOCKS) {
  1339. @@ -103,10 +103,9 @@
  1340. } while (nbytes >= bsize);
  1341. done:
  1342. + cast5_fpu_end(fpu_enabled);
  1343. err = blkcipher_walk_done(desc, walk, nbytes);
  1344. }
  1345. -
  1346. - cast5_fpu_end(fpu_enabled);
  1347. return err;
  1348. }
  1349. @@ -227,7 +226,7 @@
  1350. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1351. struct scatterlist *src, unsigned int nbytes)
  1352. {
  1353. - bool fpu_enabled = false;
  1354. + bool fpu_enabled;
  1355. struct blkcipher_walk walk;
  1356. int err;
  1357. @@ -236,12 +235,11 @@
  1358. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1359. while ((nbytes = walk.nbytes)) {
  1360. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1361. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1362. nbytes = __cbc_decrypt(desc, &walk);
  1363. + cast5_fpu_end(fpu_enabled);
  1364. err = blkcipher_walk_done(desc, &walk, nbytes);
  1365. }
  1366. -
  1367. - cast5_fpu_end(fpu_enabled);
  1368. return err;
  1369. }
  1370. @@ -311,7 +309,7 @@
  1371. static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1372. struct scatterlist *src, unsigned int nbytes)
  1373. {
  1374. - bool fpu_enabled = false;
  1375. + bool fpu_enabled;
  1376. struct blkcipher_walk walk;
  1377. int err;
  1378. @@ -320,13 +318,12 @@
  1379. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1380. while ((nbytes = walk.nbytes) >= CAST5_BLOCK_SIZE) {
  1381. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1382. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1383. nbytes = __ctr_crypt(desc, &walk);
  1384. + cast5_fpu_end(fpu_enabled);
  1385. err = blkcipher_walk_done(desc, &walk, nbytes);
  1386. }
  1387. - cast5_fpu_end(fpu_enabled);
  1388. -
  1389. if (walk.nbytes) {
  1390. ctr_crypt_final(desc, &walk);
  1391. err = blkcipher_walk_done(desc, &walk, 0);
  1392. diff -Nur linux-4.9.6.orig/arch/x86/crypto/glue_helper.c linux-4.9.6/arch/x86/crypto/glue_helper.c
  1393. --- linux-4.9.6.orig/arch/x86/crypto/glue_helper.c 2017-01-26 08:25:24.000000000 +0100
  1394. +++ linux-4.9.6/arch/x86/crypto/glue_helper.c 2017-01-28 13:59:09.895654805 +0100
  1395. @@ -39,7 +39,7 @@
  1396. void *ctx = crypto_blkcipher_ctx(desc->tfm);
  1397. const unsigned int bsize = 128 / 8;
  1398. unsigned int nbytes, i, func_bytes;
  1399. - bool fpu_enabled = false;
  1400. + bool fpu_enabled;
  1401. int err;
  1402. err = blkcipher_walk_virt(desc, walk);
  1403. @@ -49,7 +49,7 @@
  1404. u8 *wdst = walk->dst.virt.addr;
  1405. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1406. - desc, fpu_enabled, nbytes);
  1407. + desc, false, nbytes);
  1408. for (i = 0; i < gctx->num_funcs; i++) {
  1409. func_bytes = bsize * gctx->funcs[i].num_blocks;
  1410. @@ -71,10 +71,10 @@
  1411. }
  1412. done:
  1413. + glue_fpu_end(fpu_enabled);
  1414. err = blkcipher_walk_done(desc, walk, nbytes);
  1415. }
  1416. - glue_fpu_end(fpu_enabled);
  1417. return err;
  1418. }
  1419. @@ -194,7 +194,7 @@
  1420. struct scatterlist *src, unsigned int nbytes)
  1421. {
  1422. const unsigned int bsize = 128 / 8;
  1423. - bool fpu_enabled = false;
  1424. + bool fpu_enabled;
  1425. struct blkcipher_walk walk;
  1426. int err;
  1427. @@ -203,12 +203,12 @@
  1428. while ((nbytes = walk.nbytes)) {
  1429. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1430. - desc, fpu_enabled, nbytes);
  1431. + desc, false, nbytes);
  1432. nbytes = __glue_cbc_decrypt_128bit(gctx, desc, &walk);
  1433. + glue_fpu_end(fpu_enabled);
  1434. err = blkcipher_walk_done(desc, &walk, nbytes);
  1435. }
  1436. - glue_fpu_end(fpu_enabled);
  1437. return err;
  1438. }
  1439. EXPORT_SYMBOL_GPL(glue_cbc_decrypt_128bit);
  1440. @@ -277,7 +277,7 @@
  1441. struct scatterlist *src, unsigned int nbytes)
  1442. {
  1443. const unsigned int bsize = 128 / 8;
  1444. - bool fpu_enabled = false;
  1445. + bool fpu_enabled;
  1446. struct blkcipher_walk walk;
  1447. int err;
  1448. @@ -286,13 +286,12 @@
  1449. while ((nbytes = walk.nbytes) >= bsize) {
  1450. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1451. - desc, fpu_enabled, nbytes);
  1452. + desc, false, nbytes);
  1453. nbytes = __glue_ctr_crypt_128bit(gctx, desc, &walk);
  1454. + glue_fpu_end(fpu_enabled);
  1455. err = blkcipher_walk_done(desc, &walk, nbytes);
  1456. }
  1457. - glue_fpu_end(fpu_enabled);
  1458. -
  1459. if (walk.nbytes) {
  1460. glue_ctr_crypt_final_128bit(
  1461. gctx->funcs[gctx->num_funcs - 1].fn_u.ctr, desc, &walk);
  1462. @@ -347,7 +346,7 @@
  1463. void *tweak_ctx, void *crypt_ctx)
  1464. {
  1465. const unsigned int bsize = 128 / 8;
  1466. - bool fpu_enabled = false;
  1467. + bool fpu_enabled;
  1468. struct blkcipher_walk walk;
  1469. int err;
  1470. @@ -360,21 +359,21 @@
  1471. /* set minimum length to bsize, for tweak_fn */
  1472. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1473. - desc, fpu_enabled,
  1474. + desc, false,
  1475. nbytes < bsize ? bsize : nbytes);
  1476. -
  1477. /* calculate first value of T */
  1478. tweak_fn(tweak_ctx, walk.iv, walk.iv);
  1479. + glue_fpu_end(fpu_enabled);
  1480. while (nbytes) {
  1481. + fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1482. + desc, false, nbytes);
  1483. nbytes = __glue_xts_crypt_128bit(gctx, crypt_ctx, desc, &walk);
  1484. + glue_fpu_end(fpu_enabled);
  1485. err = blkcipher_walk_done(desc, &walk, nbytes);
  1486. nbytes = walk.nbytes;
  1487. }
  1488. -
  1489. - glue_fpu_end(fpu_enabled);
  1490. -
  1491. return err;
  1492. }
  1493. EXPORT_SYMBOL_GPL(glue_xts_crypt_128bit);
  1494. diff -Nur linux-4.9.6.orig/arch/x86/entry/common.c linux-4.9.6/arch/x86/entry/common.c
  1495. --- linux-4.9.6.orig/arch/x86/entry/common.c 2017-01-26 08:25:24.000000000 +0100
  1496. +++ linux-4.9.6/arch/x86/entry/common.c 2017-01-28 13:59:09.899654958 +0100
  1497. @@ -129,7 +129,7 @@
  1498. #define EXIT_TO_USERMODE_LOOP_FLAGS \
  1499. (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  1500. - _TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY)
  1501. + _TIF_NEED_RESCHED_MASK | _TIF_USER_RETURN_NOTIFY)
  1502. static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
  1503. {
  1504. @@ -145,9 +145,16 @@
  1505. /* We have work to do. */
  1506. local_irq_enable();
  1507. - if (cached_flags & _TIF_NEED_RESCHED)
  1508. + if (cached_flags & _TIF_NEED_RESCHED_MASK)
  1509. schedule();
  1510. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  1511. + if (unlikely(current->forced_info.si_signo)) {
  1512. + struct task_struct *t = current;
  1513. + force_sig_info(t->forced_info.si_signo, &t->forced_info, t);
  1514. + t->forced_info.si_signo = 0;
  1515. + }
  1516. +#endif
  1517. if (cached_flags & _TIF_UPROBE)
  1518. uprobe_notify_resume(regs);
  1519. diff -Nur linux-4.9.6.orig/arch/x86/entry/entry_32.S linux-4.9.6/arch/x86/entry/entry_32.S
  1520. --- linux-4.9.6.orig/arch/x86/entry/entry_32.S 2017-01-26 08:25:24.000000000 +0100
  1521. +++ linux-4.9.6/arch/x86/entry/entry_32.S 2017-01-28 13:59:09.899654958 +0100
  1522. @@ -308,8 +308,25 @@
  1523. ENTRY(resume_kernel)
  1524. DISABLE_INTERRUPTS(CLBR_ANY)
  1525. need_resched:
  1526. + # preempt count == 0 + NEED_RS set?
  1527. cmpl $0, PER_CPU_VAR(__preempt_count)
  1528. +#ifndef CONFIG_PREEMPT_LAZY
  1529. jnz restore_all
  1530. +#else
  1531. + jz test_int_off
  1532. +
  1533. + # atleast preempt count == 0 ?
  1534. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  1535. + jne restore_all
  1536. +
  1537. + movl PER_CPU_VAR(current_task), %ebp
  1538. + cmpl $0,TASK_TI_preempt_lazy_count(%ebp) # non-zero preempt_lazy_count ?
  1539. + jnz restore_all
  1540. +
  1541. + testl $_TIF_NEED_RESCHED_LAZY, TASK_TI_flags(%ebp)
  1542. + jz restore_all
  1543. +test_int_off:
  1544. +#endif
  1545. testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
  1546. jz restore_all
  1547. call preempt_schedule_irq
  1548. diff -Nur linux-4.9.6.orig/arch/x86/entry/entry_64.S linux-4.9.6/arch/x86/entry/entry_64.S
  1549. --- linux-4.9.6.orig/arch/x86/entry/entry_64.S 2017-01-26 08:25:24.000000000 +0100
  1550. +++ linux-4.9.6/arch/x86/entry/entry_64.S 2017-01-28 13:59:09.899654958 +0100
  1551. @@ -546,7 +546,23 @@
  1552. bt $9, EFLAGS(%rsp) /* were interrupts off? */
  1553. jnc 1f
  1554. 0: cmpl $0, PER_CPU_VAR(__preempt_count)
  1555. +#ifndef CONFIG_PREEMPT_LAZY
  1556. jnz 1f
  1557. +#else
  1558. + jz do_preempt_schedule_irq
  1559. +
  1560. + # atleast preempt count == 0 ?
  1561. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  1562. + jnz 1f
  1563. +
  1564. + movq PER_CPU_VAR(current_task), %rcx
  1565. + cmpl $0, TASK_TI_preempt_lazy_count(%rcx)
  1566. + jnz 1f
  1567. +
  1568. + bt $TIF_NEED_RESCHED_LAZY,TASK_TI_flags(%rcx)
  1569. + jnc 1f
  1570. +do_preempt_schedule_irq:
  1571. +#endif
  1572. call preempt_schedule_irq
  1573. jmp 0b
  1574. 1:
  1575. @@ -894,6 +910,7 @@
  1576. jmp 2b
  1577. .previous
  1578. +#ifndef CONFIG_PREEMPT_RT_FULL
  1579. /* Call softirq on interrupt stack. Interrupts are off. */
  1580. ENTRY(do_softirq_own_stack)
  1581. pushq %rbp
  1582. @@ -906,6 +923,7 @@
  1583. decl PER_CPU_VAR(irq_count)
  1584. ret
  1585. END(do_softirq_own_stack)
  1586. +#endif
  1587. #ifdef CONFIG_XEN
  1588. idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  1589. diff -Nur linux-4.9.6.orig/arch/x86/include/asm/preempt.h linux-4.9.6/arch/x86/include/asm/preempt.h
  1590. --- linux-4.9.6.orig/arch/x86/include/asm/preempt.h 2017-01-26 08:25:24.000000000 +0100
  1591. +++ linux-4.9.6/arch/x86/include/asm/preempt.h 2017-01-28 13:59:09.899654958 +0100
  1592. @@ -79,17 +79,46 @@
  1593. * a decrement which hits zero means we have no preempt_count and should
  1594. * reschedule.
  1595. */
  1596. -static __always_inline bool __preempt_count_dec_and_test(void)
  1597. +static __always_inline bool ____preempt_count_dec_and_test(void)
  1598. {
  1599. GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), e);
  1600. }
  1601. +static __always_inline bool __preempt_count_dec_and_test(void)
  1602. +{
  1603. + if (____preempt_count_dec_and_test())
  1604. + return true;
  1605. +#ifdef CONFIG_PREEMPT_LAZY
  1606. + if (current_thread_info()->preempt_lazy_count)
  1607. + return false;
  1608. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  1609. +#else
  1610. + return false;
  1611. +#endif
  1612. +}
  1613. +
  1614. /*
  1615. * Returns true when we need to resched and can (barring IRQ state).
  1616. */
  1617. static __always_inline bool should_resched(int preempt_offset)
  1618. {
  1619. +#ifdef CONFIG_PREEMPT_LAZY
  1620. + u32 tmp;
  1621. +
  1622. + tmp = raw_cpu_read_4(__preempt_count);
  1623. + if (tmp == preempt_offset)
  1624. + return true;
  1625. +
  1626. + /* preempt count == 0 ? */
  1627. + tmp &= ~PREEMPT_NEED_RESCHED;
  1628. + if (tmp)
  1629. + return false;
  1630. + if (current_thread_info()->preempt_lazy_count)
  1631. + return false;
  1632. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  1633. +#else
  1634. return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
  1635. +#endif
  1636. }
  1637. #ifdef CONFIG_PREEMPT
  1638. diff -Nur linux-4.9.6.orig/arch/x86/include/asm/signal.h linux-4.9.6/arch/x86/include/asm/signal.h
  1639. --- linux-4.9.6.orig/arch/x86/include/asm/signal.h 2017-01-26 08:25:24.000000000 +0100
  1640. +++ linux-4.9.6/arch/x86/include/asm/signal.h 2017-01-28 13:59:09.899654958 +0100
  1641. @@ -27,6 +27,19 @@
  1642. #define SA_IA32_ABI 0x02000000u
  1643. #define SA_X32_ABI 0x01000000u
  1644. +/*
  1645. + * Because some traps use the IST stack, we must keep preemption
  1646. + * disabled while calling do_trap(), but do_trap() may call
  1647. + * force_sig_info() which will grab the signal spin_locks for the
  1648. + * task, which in PREEMPT_RT_FULL are mutexes. By defining
  1649. + * ARCH_RT_DELAYS_SIGNAL_SEND the force_sig_info() will set
  1650. + * TIF_NOTIFY_RESUME and set up the signal to be sent on exit of the
  1651. + * trap.
  1652. + */
  1653. +#if defined(CONFIG_PREEMPT_RT_FULL)
  1654. +#define ARCH_RT_DELAYS_SIGNAL_SEND
  1655. +#endif
  1656. +
  1657. #ifndef CONFIG_COMPAT
  1658. typedef sigset_t compat_sigset_t;
  1659. #endif
  1660. diff -Nur linux-4.9.6.orig/arch/x86/include/asm/stackprotector.h linux-4.9.6/arch/x86/include/asm/stackprotector.h
  1661. --- linux-4.9.6.orig/arch/x86/include/asm/stackprotector.h 2017-01-26 08:25:24.000000000 +0100
  1662. +++ linux-4.9.6/arch/x86/include/asm/stackprotector.h 2017-01-28 13:59:09.899654958 +0100
  1663. @@ -59,7 +59,7 @@
  1664. */
  1665. static __always_inline void boot_init_stack_canary(void)
  1666. {
  1667. - u64 canary;
  1668. + u64 uninitialized_var(canary);
  1669. u64 tsc;
  1670. #ifdef CONFIG_X86_64
  1671. @@ -70,8 +70,15 @@
  1672. * of randomness. The TSC only matters for very early init,
  1673. * there it already has some randomness on most systems. Later
  1674. * on during the bootup the random pool has true entropy too.
  1675. + *
  1676. + * For preempt-rt we need to weaken the randomness a bit, as
  1677. + * we can't call into the random generator from atomic context
  1678. + * due to locking constraints. We just leave canary
  1679. + * uninitialized and use the TSC based randomness on top of it.
  1680. */
  1681. +#ifndef CONFIG_PREEMPT_RT_FULL
  1682. get_random_bytes(&canary, sizeof(canary));
  1683. +#endif
  1684. tsc = rdtsc();
  1685. canary += tsc + (tsc << 32UL);
  1686. diff -Nur linux-4.9.6.orig/arch/x86/include/asm/thread_info.h linux-4.9.6/arch/x86/include/asm/thread_info.h
  1687. --- linux-4.9.6.orig/arch/x86/include/asm/thread_info.h 2017-01-26 08:25:24.000000000 +0100
  1688. +++ linux-4.9.6/arch/x86/include/asm/thread_info.h 2017-01-28 13:59:09.899654958 +0100
  1689. @@ -54,11 +54,14 @@
  1690. struct thread_info {
  1691. unsigned long flags; /* low level flags */
  1692. + int preempt_lazy_count; /* 0 => lazy preemptable
  1693. + <0 => BUG */
  1694. };
  1695. #define INIT_THREAD_INFO(tsk) \
  1696. { \
  1697. .flags = 0, \
  1698. + .preempt_lazy_count = 0, \
  1699. }
  1700. #define init_stack (init_thread_union.stack)
  1701. @@ -67,6 +70,10 @@
  1702. #include <asm/asm-offsets.h>
  1703. +#define GET_THREAD_INFO(reg) \
  1704. + _ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
  1705. + _ASM_SUB $(THREAD_SIZE),reg ;
  1706. +
  1707. #endif
  1708. /*
  1709. @@ -85,6 +92,7 @@
  1710. #define TIF_SYSCALL_EMU 6 /* syscall emulation active */
  1711. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  1712. #define TIF_SECCOMP 8 /* secure computing */
  1713. +#define TIF_NEED_RESCHED_LAZY 9 /* lazy rescheduling necessary */
  1714. #define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */
  1715. #define TIF_UPROBE 12 /* breakpointed or singlestepping */
  1716. #define TIF_NOTSC 16 /* TSC is not accessible in userland */
  1717. @@ -108,6 +116,7 @@
  1718. #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
  1719. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  1720. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  1721. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  1722. #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY)
  1723. #define _TIF_UPROBE (1 << TIF_UPROBE)
  1724. #define _TIF_NOTSC (1 << TIF_NOTSC)
  1725. @@ -143,6 +152,8 @@
  1726. #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  1727. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  1728. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  1729. +
  1730. #define STACK_WARN (THREAD_SIZE/8)
  1731. /*
  1732. diff -Nur linux-4.9.6.orig/arch/x86/include/asm/uv/uv_bau.h linux-4.9.6/arch/x86/include/asm/uv/uv_bau.h
  1733. --- linux-4.9.6.orig/arch/x86/include/asm/uv/uv_bau.h 2017-01-26 08:25:24.000000000 +0100
  1734. +++ linux-4.9.6/arch/x86/include/asm/uv/uv_bau.h 2017-01-28 13:59:09.899654958 +0100
  1735. @@ -624,9 +624,9 @@
  1736. cycles_t send_message;
  1737. cycles_t period_end;
  1738. cycles_t period_time;
  1739. - spinlock_t uvhub_lock;
  1740. - spinlock_t queue_lock;
  1741. - spinlock_t disable_lock;
  1742. + raw_spinlock_t uvhub_lock;
  1743. + raw_spinlock_t queue_lock;
  1744. + raw_spinlock_t disable_lock;
  1745. /* tunables */
  1746. int max_concurr;
  1747. int max_concurr_const;
  1748. @@ -815,15 +815,15 @@
  1749. * to be lowered below the current 'v'. atomic_add_unless can only stop
  1750. * on equal.
  1751. */
  1752. -static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  1753. +static inline int atomic_inc_unless_ge(raw_spinlock_t *lock, atomic_t *v, int u)
  1754. {
  1755. - spin_lock(lock);
  1756. + raw_spin_lock(lock);
  1757. if (atomic_read(v) >= u) {
  1758. - spin_unlock(lock);
  1759. + raw_spin_unlock(lock);
  1760. return 0;
  1761. }
  1762. atomic_inc(v);
  1763. - spin_unlock(lock);
  1764. + raw_spin_unlock(lock);
  1765. return 1;
  1766. }
  1767. diff -Nur linux-4.9.6.orig/arch/x86/Kconfig linux-4.9.6/arch/x86/Kconfig
  1768. --- linux-4.9.6.orig/arch/x86/Kconfig 2017-01-26 08:25:24.000000000 +0100
  1769. +++ linux-4.9.6/arch/x86/Kconfig 2017-01-28 13:59:09.895654805 +0100
  1770. @@ -17,6 +17,7 @@
  1771. ### Arch settings
  1772. config X86
  1773. def_bool y
  1774. + select HAVE_PREEMPT_LAZY
  1775. select ACPI_LEGACY_TABLES_LOOKUP if ACPI
  1776. select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
  1777. select ANON_INODES
  1778. @@ -232,8 +233,11 @@
  1779. def_bool y
  1780. depends on ISA_DMA_API
  1781. +config RWSEM_GENERIC_SPINLOCK
  1782. + def_bool PREEMPT_RT_FULL
  1783. +
  1784. config RWSEM_XCHGADD_ALGORITHM
  1785. - def_bool y
  1786. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  1787. config GENERIC_CALIBRATE_DELAY
  1788. def_bool y
  1789. @@ -897,7 +901,7 @@
  1790. config MAXSMP
  1791. bool "Enable Maximum number of SMP Processors and NUMA Nodes"
  1792. depends on X86_64 && SMP && DEBUG_KERNEL
  1793. - select CPUMASK_OFFSTACK
  1794. + select CPUMASK_OFFSTACK if !PREEMPT_RT_FULL
  1795. ---help---
  1796. Enable maximum number of CPUS and NUMA Nodes for this architecture.
  1797. If unsure, say N.
  1798. diff -Nur linux-4.9.6.orig/arch/x86/kernel/acpi/boot.c linux-4.9.6/arch/x86/kernel/acpi/boot.c
  1799. --- linux-4.9.6.orig/arch/x86/kernel/acpi/boot.c 2017-01-26 08:25:24.000000000 +0100
  1800. +++ linux-4.9.6/arch/x86/kernel/acpi/boot.c 2017-01-28 13:59:09.899654958 +0100
  1801. @@ -87,7 +87,9 @@
  1802. * ->ioapic_mutex
  1803. * ->ioapic_lock
  1804. */
  1805. +#ifdef CONFIG_X86_IO_APIC
  1806. static DEFINE_MUTEX(acpi_ioapic_lock);
  1807. +#endif
  1808. /* --------------------------------------------------------------------------
  1809. Boot-time Configuration
  1810. diff -Nur linux-4.9.6.orig/arch/x86/kernel/apic/io_apic.c linux-4.9.6/arch/x86/kernel/apic/io_apic.c
  1811. --- linux-4.9.6.orig/arch/x86/kernel/apic/io_apic.c 2017-01-26 08:25:24.000000000 +0100
  1812. +++ linux-4.9.6/arch/x86/kernel/apic/io_apic.c 2017-01-28 13:59:09.899654958 +0100
  1813. @@ -1712,7 +1712,8 @@
  1814. static inline bool ioapic_irqd_mask(struct irq_data *data)
  1815. {
  1816. /* If we are moving the irq we need to mask it */
  1817. - if (unlikely(irqd_is_setaffinity_pending(data))) {
  1818. + if (unlikely(irqd_is_setaffinity_pending(data) &&
  1819. + !irqd_irq_inprogress(data))) {
  1820. mask_ioapic_irq(data);
  1821. return true;
  1822. }
  1823. diff -Nur linux-4.9.6.orig/arch/x86/kernel/asm-offsets.c linux-4.9.6/arch/x86/kernel/asm-offsets.c
  1824. --- linux-4.9.6.orig/arch/x86/kernel/asm-offsets.c 2017-01-26 08:25:24.000000000 +0100
  1825. +++ linux-4.9.6/arch/x86/kernel/asm-offsets.c 2017-01-28 13:59:09.899654958 +0100
  1826. @@ -36,6 +36,7 @@
  1827. BLANK();
  1828. OFFSET(TASK_TI_flags, task_struct, thread_info.flags);
  1829. + OFFSET(TASK_TI_preempt_lazy_count, task_struct, thread_info.preempt_lazy_count);
  1830. OFFSET(TASK_addr_limit, task_struct, thread.addr_limit);
  1831. BLANK();
  1832. @@ -91,4 +92,5 @@
  1833. BLANK();
  1834. DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
  1835. + DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  1836. }
  1837. diff -Nur linux-4.9.6.orig/arch/x86/kernel/cpu/mcheck/mce.c linux-4.9.6/arch/x86/kernel/cpu/mcheck/mce.c
  1838. --- linux-4.9.6.orig/arch/x86/kernel/cpu/mcheck/mce.c 2017-01-26 08:25:24.000000000 +0100
  1839. +++ linux-4.9.6/arch/x86/kernel/cpu/mcheck/mce.c 2017-01-28 13:59:09.899654958 +0100
  1840. @@ -41,6 +41,8 @@
  1841. #include <linux/debugfs.h>
  1842. #include <linux/irq_work.h>
  1843. #include <linux/export.h>
  1844. +#include <linux/jiffies.h>
  1845. +#include <linux/swork.h>
  1846. #include <linux/jump_label.h>
  1847. #include <asm/processor.h>
  1848. @@ -1317,7 +1319,7 @@
  1849. static unsigned long check_interval = INITIAL_CHECK_INTERVAL;
  1850. static DEFINE_PER_CPU(unsigned long, mce_next_interval); /* in jiffies */
  1851. -static DEFINE_PER_CPU(struct timer_list, mce_timer);
  1852. +static DEFINE_PER_CPU(struct hrtimer, mce_timer);
  1853. static unsigned long mce_adjust_timer_default(unsigned long interval)
  1854. {
  1855. @@ -1326,32 +1328,18 @@
  1856. static unsigned long (*mce_adjust_timer)(unsigned long interval) = mce_adjust_timer_default;
  1857. -static void __restart_timer(struct timer_list *t, unsigned long interval)
  1858. +static enum hrtimer_restart __restart_timer(struct hrtimer *timer, unsigned long interval)
  1859. {
  1860. - unsigned long when = jiffies + interval;
  1861. - unsigned long flags;
  1862. -
  1863. - local_irq_save(flags);
  1864. -
  1865. - if (timer_pending(t)) {
  1866. - if (time_before(when, t->expires))
  1867. - mod_timer(t, when);
  1868. - } else {
  1869. - t->expires = round_jiffies(when);
  1870. - add_timer_on(t, smp_processor_id());
  1871. - }
  1872. -
  1873. - local_irq_restore(flags);
  1874. + if (!interval)
  1875. + return HRTIMER_NORESTART;
  1876. + hrtimer_forward_now(timer, ns_to_ktime(jiffies_to_nsecs(interval)));
  1877. + return HRTIMER_RESTART;
  1878. }
  1879. -static void mce_timer_fn(unsigned long data)
  1880. +static enum hrtimer_restart mce_timer_fn(struct hrtimer *timer)
  1881. {
  1882. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  1883. - int cpu = smp_processor_id();
  1884. unsigned long iv;
  1885. - WARN_ON(cpu != data);
  1886. -
  1887. iv = __this_cpu_read(mce_next_interval);
  1888. if (mce_available(this_cpu_ptr(&cpu_info))) {
  1889. @@ -1374,7 +1362,7 @@
  1890. done:
  1891. __this_cpu_write(mce_next_interval, iv);
  1892. - __restart_timer(t, iv);
  1893. + return __restart_timer(timer, iv);
  1894. }
  1895. /*
  1896. @@ -1382,7 +1370,7 @@
  1897. */
  1898. void mce_timer_kick(unsigned long interval)
  1899. {
  1900. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  1901. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  1902. unsigned long iv = __this_cpu_read(mce_next_interval);
  1903. __restart_timer(t, interval);
  1904. @@ -1397,7 +1385,7 @@
  1905. int cpu;
  1906. for_each_online_cpu(cpu)
  1907. - del_timer_sync(&per_cpu(mce_timer, cpu));
  1908. + hrtimer_cancel(&per_cpu(mce_timer, cpu));
  1909. }
  1910. static void mce_do_trigger(struct work_struct *work)
  1911. @@ -1407,6 +1395,56 @@
  1912. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  1913. +static void __mce_notify_work(struct swork_event *event)
  1914. +{
  1915. + /* Not more than two messages every minute */
  1916. + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  1917. +
  1918. + /* wake processes polling /dev/mcelog */
  1919. + wake_up_interruptible(&mce_chrdev_wait);
  1920. +
  1921. + /*
  1922. + * There is no risk of missing notifications because
  1923. + * work_pending is always cleared before the function is
  1924. + * executed.
  1925. + */
  1926. + if (mce_helper[0] && !work_pending(&mce_trigger_work))
  1927. + schedule_work(&mce_trigger_work);
  1928. +
  1929. + if (__ratelimit(&ratelimit))
  1930. + pr_info(HW_ERR "Machine check events logged\n");
  1931. +}
  1932. +
  1933. +#ifdef CONFIG_PREEMPT_RT_FULL
  1934. +static bool notify_work_ready __read_mostly;
  1935. +static struct swork_event notify_work;
  1936. +
  1937. +static int mce_notify_work_init(void)
  1938. +{
  1939. + int err;
  1940. +
  1941. + err = swork_get();
  1942. + if (err)
  1943. + return err;
  1944. +
  1945. + INIT_SWORK(&notify_work, __mce_notify_work);
  1946. + notify_work_ready = true;
  1947. + return 0;
  1948. +}
  1949. +
  1950. +static void mce_notify_work(void)
  1951. +{
  1952. + if (notify_work_ready)
  1953. + swork_queue(&notify_work);
  1954. +}
  1955. +#else
  1956. +static void mce_notify_work(void)
  1957. +{
  1958. + __mce_notify_work(NULL);
  1959. +}
  1960. +static inline int mce_notify_work_init(void) { return 0; }
  1961. +#endif
  1962. +
  1963. /*
  1964. * Notify the user(s) about new machine check events.
  1965. * Can be called from interrupt context, but not from machine check/NMI
  1966. @@ -1414,19 +1452,8 @@
  1967. */
  1968. int mce_notify_irq(void)
  1969. {
  1970. - /* Not more than two messages every minute */
  1971. - static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  1972. -
  1973. if (test_and_clear_bit(0, &mce_need_notify)) {
  1974. - /* wake processes polling /dev/mcelog */
  1975. - wake_up_interruptible(&mce_chrdev_wait);
  1976. -
  1977. - if (mce_helper[0])
  1978. - schedule_work(&mce_trigger_work);
  1979. -
  1980. - if (__ratelimit(&ratelimit))
  1981. - pr_info(HW_ERR "Machine check events logged\n");
  1982. -
  1983. + mce_notify_work();
  1984. return 1;
  1985. }
  1986. return 0;
  1987. @@ -1732,7 +1759,7 @@
  1988. }
  1989. }
  1990. -static void mce_start_timer(unsigned int cpu, struct timer_list *t)
  1991. +static void mce_start_timer(unsigned int cpu, struct hrtimer *t)
  1992. {
  1993. unsigned long iv = check_interval * HZ;
  1994. @@ -1741,16 +1768,17 @@
  1995. per_cpu(mce_next_interval, cpu) = iv;
  1996. - t->expires = round_jiffies(jiffies + iv);
  1997. - add_timer_on(t, cpu);
  1998. + hrtimer_start_range_ns(t, ns_to_ktime(jiffies_to_usecs(iv) * 1000ULL),
  1999. + 0, HRTIMER_MODE_REL_PINNED);
  2000. }
  2001. static void __mcheck_cpu_init_timer(void)
  2002. {
  2003. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  2004. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  2005. unsigned int cpu = smp_processor_id();
  2006. - setup_pinned_timer(t, mce_timer_fn, cpu);
  2007. + hrtimer_init(t, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  2008. + t->function = mce_timer_fn;
  2009. mce_start_timer(cpu, t);
  2010. }
  2011. @@ -2475,6 +2503,8 @@
  2012. if (!mce_available(raw_cpu_ptr(&cpu_info)))
  2013. return;
  2014. + hrtimer_cancel(this_cpu_ptr(&mce_timer));
  2015. +
  2016. if (!(action & CPU_TASKS_FROZEN))
  2017. cmci_clear();
  2018. @@ -2497,6 +2527,7 @@
  2019. if (b->init)
  2020. wrmsrl(msr_ops.ctl(i), b->ctl);
  2021. }
  2022. + __mcheck_cpu_init_timer();
  2023. }
  2024. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  2025. @@ -2504,7 +2535,6 @@
  2026. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  2027. {
  2028. unsigned int cpu = (unsigned long)hcpu;
  2029. - struct timer_list *t = &per_cpu(mce_timer, cpu);
  2030. switch (action & ~CPU_TASKS_FROZEN) {
  2031. case CPU_ONLINE:
  2032. @@ -2524,11 +2554,9 @@
  2033. break;
  2034. case CPU_DOWN_PREPARE:
  2035. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  2036. - del_timer_sync(t);
  2037. break;
  2038. case CPU_DOWN_FAILED:
  2039. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  2040. - mce_start_timer(cpu, t);
  2041. break;
  2042. }
  2043. @@ -2567,6 +2595,10 @@
  2044. goto err_out;
  2045. }
  2046. + err = mce_notify_work_init();
  2047. + if (err)
  2048. + goto err_out;
  2049. +
  2050. if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
  2051. err = -ENOMEM;
  2052. goto err_out;
  2053. diff -Nur linux-4.9.6.orig/arch/x86/kernel/irq_32.c linux-4.9.6/arch/x86/kernel/irq_32.c
  2054. --- linux-4.9.6.orig/arch/x86/kernel/irq_32.c 2017-01-26 08:25:24.000000000 +0100
  2055. +++ linux-4.9.6/arch/x86/kernel/irq_32.c 2017-01-28 13:59:09.899654958 +0100
  2056. @@ -127,6 +127,7 @@
  2057. cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
  2058. }
  2059. +#ifndef CONFIG_PREEMPT_RT_FULL
  2060. void do_softirq_own_stack(void)
  2061. {
  2062. struct irq_stack *irqstk;
  2063. @@ -143,6 +144,7 @@
  2064. call_on_stack(__do_softirq, isp);
  2065. }
  2066. +#endif
  2067. bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
  2068. {
  2069. diff -Nur linux-4.9.6.orig/arch/x86/kernel/process_32.c linux-4.9.6/arch/x86/kernel/process_32.c
  2070. --- linux-4.9.6.orig/arch/x86/kernel/process_32.c 2017-01-26 08:25:24.000000000 +0100
  2071. +++ linux-4.9.6/arch/x86/kernel/process_32.c 2017-01-28 13:59:09.899654958 +0100
  2072. @@ -35,6 +35,7 @@
  2073. #include <linux/uaccess.h>
  2074. #include <linux/io.h>
  2075. #include <linux/kdebug.h>
  2076. +#include <linux/highmem.h>
  2077. #include <asm/pgtable.h>
  2078. #include <asm/ldt.h>
  2079. @@ -195,6 +196,35 @@
  2080. }
  2081. EXPORT_SYMBOL_GPL(start_thread);
  2082. +#ifdef CONFIG_PREEMPT_RT_FULL
  2083. +static void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  2084. +{
  2085. + int i;
  2086. +
  2087. + /*
  2088. + * Clear @prev's kmap_atomic mappings
  2089. + */
  2090. + for (i = 0; i < prev_p->kmap_idx; i++) {
  2091. + int idx = i + KM_TYPE_NR * smp_processor_id();
  2092. + pte_t *ptep = kmap_pte - idx;
  2093. +
  2094. + kpte_clear_flush(ptep, __fix_to_virt(FIX_KMAP_BEGIN + idx));
  2095. + }
  2096. + /*
  2097. + * Restore @next_p's kmap_atomic mappings
  2098. + */
  2099. + for (i = 0; i < next_p->kmap_idx; i++) {
  2100. + int idx = i + KM_TYPE_NR * smp_processor_id();
  2101. +
  2102. + if (!pte_none(next_p->kmap_pte[i]))
  2103. + set_pte(kmap_pte - idx, next_p->kmap_pte[i]);
  2104. + }
  2105. +}
  2106. +#else
  2107. +static inline void
  2108. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  2109. +#endif
  2110. +
  2111. /*
  2112. * switch_to(x,y) should switch tasks from x to y.
  2113. @@ -271,6 +301,8 @@
  2114. task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
  2115. __switch_to_xtra(prev_p, next_p, tss);
  2116. + switch_kmaps(prev_p, next_p);
  2117. +
  2118. /*
  2119. * Leave lazy mode, flushing any hypercalls made here.
  2120. * This must be done before restoring TLS segments so
  2121. diff -Nur linux-4.9.6.orig/arch/x86/kvm/lapic.c linux-4.9.6/arch/x86/kvm/lapic.c
  2122. --- linux-4.9.6.orig/arch/x86/kvm/lapic.c 2017-01-26 08:25:24.000000000 +0100
  2123. +++ linux-4.9.6/arch/x86/kvm/lapic.c 2017-01-28 13:59:09.899654958 +0100
  2124. @@ -1939,6 +1939,7 @@
  2125. hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
  2126. HRTIMER_MODE_ABS_PINNED);
  2127. apic->lapic_timer.timer.function = apic_timer_fn;
  2128. + apic->lapic_timer.timer.irqsafe = 1;
  2129. /*
  2130. * APIC is created enabled. This will prevent kvm_lapic_set_base from
  2131. diff -Nur linux-4.9.6.orig/arch/x86/kvm/x86.c linux-4.9.6/arch/x86/kvm/x86.c
  2132. --- linux-4.9.6.orig/arch/x86/kvm/x86.c 2017-01-26 08:25:24.000000000 +0100
  2133. +++ linux-4.9.6/arch/x86/kvm/x86.c 2017-01-28 13:59:09.903655111 +0100
  2134. @@ -5932,6 +5932,13 @@
  2135. goto out;
  2136. }
  2137. +#ifdef CONFIG_PREEMPT_RT_FULL
  2138. + if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
  2139. + printk(KERN_ERR "RT requires X86_FEATURE_CONSTANT_TSC\n");
  2140. + return -EOPNOTSUPP;
  2141. + }
  2142. +#endif
  2143. +
  2144. r = kvm_mmu_module_init();
  2145. if (r)
  2146. goto out_free_percpu;
  2147. diff -Nur linux-4.9.6.orig/arch/x86/mm/highmem_32.c linux-4.9.6/arch/x86/mm/highmem_32.c
  2148. --- linux-4.9.6.orig/arch/x86/mm/highmem_32.c 2017-01-26 08:25:24.000000000 +0100
  2149. +++ linux-4.9.6/arch/x86/mm/highmem_32.c 2017-01-28 13:59:09.903655111 +0100
  2150. @@ -32,10 +32,11 @@
  2151. */
  2152. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  2153. {
  2154. + pte_t pte = mk_pte(page, prot);
  2155. unsigned long vaddr;
  2156. int idx, type;
  2157. - preempt_disable();
  2158. + preempt_disable_nort();
  2159. pagefault_disable();
  2160. if (!PageHighMem(page))
  2161. @@ -45,7 +46,10 @@
  2162. idx = type + KM_TYPE_NR*smp_processor_id();
  2163. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  2164. BUG_ON(!pte_none(*(kmap_pte-idx)));
  2165. - set_pte(kmap_pte-idx, mk_pte(page, prot));
  2166. +#ifdef CONFIG_PREEMPT_RT_FULL
  2167. + current->kmap_pte[type] = pte;
  2168. +#endif
  2169. + set_pte(kmap_pte-idx, pte);
  2170. arch_flush_lazy_mmu_mode();
  2171. return (void *)vaddr;
  2172. @@ -88,6 +92,9 @@
  2173. * is a bad idea also, in case the page changes cacheability
  2174. * attributes or becomes a protected page in a hypervisor.
  2175. */
  2176. +#ifdef CONFIG_PREEMPT_RT_FULL
  2177. + current->kmap_pte[type] = __pte(0);
  2178. +#endif
  2179. kpte_clear_flush(kmap_pte-idx, vaddr);
  2180. kmap_atomic_idx_pop();
  2181. arch_flush_lazy_mmu_mode();
  2182. @@ -100,7 +107,7 @@
  2183. #endif
  2184. pagefault_enable();
  2185. - preempt_enable();
  2186. + preempt_enable_nort();
  2187. }
  2188. EXPORT_SYMBOL(__kunmap_atomic);
  2189. diff -Nur linux-4.9.6.orig/arch/x86/mm/iomap_32.c linux-4.9.6/arch/x86/mm/iomap_32.c
  2190. --- linux-4.9.6.orig/arch/x86/mm/iomap_32.c 2017-01-26 08:25:24.000000000 +0100
  2191. +++ linux-4.9.6/arch/x86/mm/iomap_32.c 2017-01-28 13:59:09.903655111 +0100
  2192. @@ -56,6 +56,7 @@
  2193. void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
  2194. {
  2195. + pte_t pte = pfn_pte(pfn, prot);
  2196. unsigned long vaddr;
  2197. int idx, type;
  2198. @@ -65,7 +66,12 @@
  2199. type = kmap_atomic_idx_push();
  2200. idx = type + KM_TYPE_NR * smp_processor_id();
  2201. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  2202. - set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
  2203. + WARN_ON(!pte_none(*(kmap_pte - idx)));
  2204. +
  2205. +#ifdef CONFIG_PREEMPT_RT_FULL
  2206. + current->kmap_pte[type] = pte;
  2207. +#endif
  2208. + set_pte(kmap_pte - idx, pte);
  2209. arch_flush_lazy_mmu_mode();
  2210. return (void *)vaddr;
  2211. @@ -113,6 +119,9 @@
  2212. * is a bad idea also, in case the page changes cacheability
  2213. * attributes or becomes a protected page in a hypervisor.
  2214. */
  2215. +#ifdef CONFIG_PREEMPT_RT_FULL
  2216. + current->kmap_pte[type] = __pte(0);
  2217. +#endif
  2218. kpte_clear_flush(kmap_pte-idx, vaddr);
  2219. kmap_atomic_idx_pop();
  2220. }
  2221. diff -Nur linux-4.9.6.orig/arch/x86/platform/uv/tlb_uv.c linux-4.9.6/arch/x86/platform/uv/tlb_uv.c
  2222. --- linux-4.9.6.orig/arch/x86/platform/uv/tlb_uv.c 2017-01-26 08:25:24.000000000 +0100
  2223. +++ linux-4.9.6/arch/x86/platform/uv/tlb_uv.c 2017-01-28 13:59:09.903655111 +0100
  2224. @@ -748,9 +748,9 @@
  2225. quiesce_local_uvhub(hmaster);
  2226. - spin_lock(&hmaster->queue_lock);
  2227. + raw_spin_lock(&hmaster->queue_lock);
  2228. reset_with_ipi(&bau_desc->distribution, bcp);
  2229. - spin_unlock(&hmaster->queue_lock);
  2230. + raw_spin_unlock(&hmaster->queue_lock);
  2231. end_uvhub_quiesce(hmaster);
  2232. @@ -770,9 +770,9 @@
  2233. quiesce_local_uvhub(hmaster);
  2234. - spin_lock(&hmaster->queue_lock);
  2235. + raw_spin_lock(&hmaster->queue_lock);
  2236. reset_with_ipi(&bau_desc->distribution, bcp);
  2237. - spin_unlock(&hmaster->queue_lock);
  2238. + raw_spin_unlock(&hmaster->queue_lock);
  2239. end_uvhub_quiesce(hmaster);
  2240. @@ -793,7 +793,7 @@
  2241. cycles_t tm1;
  2242. hmaster = bcp->uvhub_master;
  2243. - spin_lock(&hmaster->disable_lock);
  2244. + raw_spin_lock(&hmaster->disable_lock);
  2245. if (!bcp->baudisabled) {
  2246. stat->s_bau_disabled++;
  2247. tm1 = get_cycles();
  2248. @@ -806,7 +806,7 @@
  2249. }
  2250. }
  2251. }
  2252. - spin_unlock(&hmaster->disable_lock);
  2253. + raw_spin_unlock(&hmaster->disable_lock);
  2254. }
  2255. static void count_max_concurr(int stat, struct bau_control *bcp,
  2256. @@ -869,7 +869,7 @@
  2257. */
  2258. static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  2259. {
  2260. - spinlock_t *lock = &hmaster->uvhub_lock;
  2261. + raw_spinlock_t *lock = &hmaster->uvhub_lock;
  2262. atomic_t *v;
  2263. v = &hmaster->active_descriptor_count;
  2264. @@ -1002,7 +1002,7 @@
  2265. struct bau_control *hmaster;
  2266. hmaster = bcp->uvhub_master;
  2267. - spin_lock(&hmaster->disable_lock);
  2268. + raw_spin_lock(&hmaster->disable_lock);
  2269. if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
  2270. stat->s_bau_reenabled++;
  2271. for_each_present_cpu(tcpu) {
  2272. @@ -1014,10 +1014,10 @@
  2273. tbcp->period_giveups = 0;
  2274. }
  2275. }
  2276. - spin_unlock(&hmaster->disable_lock);
  2277. + raw_spin_unlock(&hmaster->disable_lock);
  2278. return 0;
  2279. }
  2280. - spin_unlock(&hmaster->disable_lock);
  2281. + raw_spin_unlock(&hmaster->disable_lock);
  2282. return -1;
  2283. }
  2284. @@ -1940,9 +1940,9 @@
  2285. bcp->cong_reps = congested_reps;
  2286. bcp->disabled_period = sec_2_cycles(disabled_period);
  2287. bcp->giveup_limit = giveup_limit;
  2288. - spin_lock_init(&bcp->queue_lock);
  2289. - spin_lock_init(&bcp->uvhub_lock);
  2290. - spin_lock_init(&bcp->disable_lock);
  2291. + raw_spin_lock_init(&bcp->queue_lock);
  2292. + raw_spin_lock_init(&bcp->uvhub_lock);
  2293. + raw_spin_lock_init(&bcp->disable_lock);
  2294. }
  2295. }
  2296. diff -Nur linux-4.9.6.orig/arch/x86/platform/uv/uv_time.c linux-4.9.6/arch/x86/platform/uv/uv_time.c
  2297. --- linux-4.9.6.orig/arch/x86/platform/uv/uv_time.c 2017-01-26 08:25:24.000000000 +0100
  2298. +++ linux-4.9.6/arch/x86/platform/uv/uv_time.c 2017-01-28 13:59:09.903655111 +0100
  2299. @@ -57,7 +57,7 @@
  2300. /* There is one of these allocated per node */
  2301. struct uv_rtc_timer_head {
  2302. - spinlock_t lock;
  2303. + raw_spinlock_t lock;
  2304. /* next cpu waiting for timer, local node relative: */
  2305. int next_cpu;
  2306. /* number of cpus on this node: */
  2307. @@ -177,7 +177,7 @@
  2308. uv_rtc_deallocate_timers();
  2309. return -ENOMEM;
  2310. }
  2311. - spin_lock_init(&head->lock);
  2312. + raw_spin_lock_init(&head->lock);
  2313. head->ncpus = uv_blade_nr_possible_cpus(bid);
  2314. head->next_cpu = -1;
  2315. blade_info[bid] = head;
  2316. @@ -231,7 +231,7 @@
  2317. unsigned long flags;
  2318. int next_cpu;
  2319. - spin_lock_irqsave(&head->lock, flags);
  2320. + raw_spin_lock_irqsave(&head->lock, flags);
  2321. next_cpu = head->next_cpu;
  2322. *t = expires;
  2323. @@ -243,12 +243,12 @@
  2324. if (uv_setup_intr(cpu, expires)) {
  2325. *t = ULLONG_MAX;
  2326. uv_rtc_find_next_timer(head, pnode);
  2327. - spin_unlock_irqrestore(&head->lock, flags);
  2328. + raw_spin_unlock_irqrestore(&head->lock, flags);
  2329. return -ETIME;
  2330. }
  2331. }
  2332. - spin_unlock_irqrestore(&head->lock, flags);
  2333. + raw_spin_unlock_irqrestore(&head->lock, flags);
  2334. return 0;
  2335. }
  2336. @@ -267,7 +267,7 @@
  2337. unsigned long flags;
  2338. int rc = 0;
  2339. - spin_lock_irqsave(&head->lock, flags);
  2340. + raw_spin_lock_irqsave(&head->lock, flags);
  2341. if ((head->next_cpu == bcpu && uv_read_rtc(NULL) >= *t) || force)
  2342. rc = 1;
  2343. @@ -279,7 +279,7 @@
  2344. uv_rtc_find_next_timer(head, pnode);
  2345. }
  2346. - spin_unlock_irqrestore(&head->lock, flags);
  2347. + raw_spin_unlock_irqrestore(&head->lock, flags);
  2348. return rc;
  2349. }
  2350. @@ -299,13 +299,18 @@
  2351. static cycle_t uv_read_rtc(struct clocksource *cs)
  2352. {
  2353. unsigned long offset;
  2354. + cycle_t cycles;
  2355. + preempt_disable();
  2356. if (uv_get_min_hub_revision_id() == 1)
  2357. offset = 0;
  2358. else
  2359. offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
  2360. - return (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  2361. + cycles = (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  2362. + preempt_enable();
  2363. +
  2364. + return cycles;
  2365. }
  2366. /*
  2367. diff -Nur linux-4.9.6.orig/block/blk-core.c linux-4.9.6/block/blk-core.c
  2368. --- linux-4.9.6.orig/block/blk-core.c 2017-01-26 08:25:24.000000000 +0100
  2369. +++ linux-4.9.6/block/blk-core.c 2017-01-28 13:59:09.903655111 +0100
  2370. @@ -125,6 +125,9 @@
  2371. INIT_LIST_HEAD(&rq->queuelist);
  2372. INIT_LIST_HEAD(&rq->timeout_list);
  2373. +#ifdef CONFIG_PREEMPT_RT_FULL
  2374. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  2375. +#endif
  2376. rq->cpu = -1;
  2377. rq->q = q;
  2378. rq->__sector = (sector_t) -1;
  2379. @@ -233,7 +236,7 @@
  2380. **/
  2381. void blk_start_queue(struct request_queue *q)
  2382. {
  2383. - WARN_ON(!irqs_disabled());
  2384. + WARN_ON_NONRT(!irqs_disabled());
  2385. queue_flag_clear(QUEUE_FLAG_STOPPED, q);
  2386. __blk_run_queue(q);
  2387. @@ -659,7 +662,7 @@
  2388. if (nowait)
  2389. return -EBUSY;
  2390. - ret = wait_event_interruptible(q->mq_freeze_wq,
  2391. + ret = swait_event_interruptible(q->mq_freeze_wq,
  2392. !atomic_read(&q->mq_freeze_depth) ||
  2393. blk_queue_dying(q));
  2394. if (blk_queue_dying(q))
  2395. @@ -679,7 +682,7 @@
  2396. struct request_queue *q =
  2397. container_of(ref, struct request_queue, q_usage_counter);
  2398. - wake_up_all(&q->mq_freeze_wq);
  2399. + swake_up_all(&q->mq_freeze_wq);
  2400. }
  2401. static void blk_rq_timed_out_timer(unsigned long data)
  2402. @@ -748,7 +751,7 @@
  2403. q->bypass_depth = 1;
  2404. __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  2405. - init_waitqueue_head(&q->mq_freeze_wq);
  2406. + init_swait_queue_head(&q->mq_freeze_wq);
  2407. /*
  2408. * Init percpu_ref in atomic mode so that it's faster to shutdown.
  2409. @@ -3177,7 +3180,7 @@
  2410. blk_run_queue_async(q);
  2411. else
  2412. __blk_run_queue(q);
  2413. - spin_unlock(q->queue_lock);
  2414. + spin_unlock_irq(q->queue_lock);
  2415. }
  2416. static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
  2417. @@ -3225,7 +3228,6 @@
  2418. void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  2419. {
  2420. struct request_queue *q;
  2421. - unsigned long flags;
  2422. struct request *rq;
  2423. LIST_HEAD(list);
  2424. unsigned int depth;
  2425. @@ -3245,11 +3247,6 @@
  2426. q = NULL;
  2427. depth = 0;
  2428. - /*
  2429. - * Save and disable interrupts here, to avoid doing it for every
  2430. - * queue lock we have to take.
  2431. - */
  2432. - local_irq_save(flags);
  2433. while (!list_empty(&list)) {
  2434. rq = list_entry_rq(list.next);
  2435. list_del_init(&rq->queuelist);
  2436. @@ -3262,7 +3259,7 @@
  2437. queue_unplugged(q, depth, from_schedule);
  2438. q = rq->q;
  2439. depth = 0;
  2440. - spin_lock(q->queue_lock);
  2441. + spin_lock_irq(q->queue_lock);
  2442. }
  2443. /*
  2444. @@ -3289,8 +3286,6 @@
  2445. */
  2446. if (q)
  2447. queue_unplugged(q, depth, from_schedule);
  2448. -
  2449. - local_irq_restore(flags);
  2450. }
  2451. void blk_finish_plug(struct blk_plug *plug)
  2452. diff -Nur linux-4.9.6.orig/block/blk-ioc.c linux-4.9.6/block/blk-ioc.c
  2453. --- linux-4.9.6.orig/block/blk-ioc.c 2017-01-26 08:25:24.000000000 +0100
  2454. +++ linux-4.9.6/block/blk-ioc.c 2017-01-28 13:59:09.903655111 +0100
  2455. @@ -7,6 +7,7 @@
  2456. #include <linux/bio.h>
  2457. #include <linux/blkdev.h>
  2458. #include <linux/slab.h>
  2459. +#include <linux/delay.h>
  2460. #include "blk.h"
  2461. @@ -109,7 +110,7 @@
  2462. spin_unlock(q->queue_lock);
  2463. } else {
  2464. spin_unlock_irqrestore(&ioc->lock, flags);
  2465. - cpu_relax();
  2466. + cpu_chill();
  2467. spin_lock_irqsave_nested(&ioc->lock, flags, 1);
  2468. }
  2469. }
  2470. @@ -187,7 +188,7 @@
  2471. spin_unlock(icq->q->queue_lock);
  2472. } else {
  2473. spin_unlock_irqrestore(&ioc->lock, flags);
  2474. - cpu_relax();
  2475. + cpu_chill();
  2476. goto retry;
  2477. }
  2478. }
  2479. diff -Nur linux-4.9.6.orig/block/blk-mq.c linux-4.9.6/block/blk-mq.c
  2480. --- linux-4.9.6.orig/block/blk-mq.c 2017-01-26 08:25:24.000000000 +0100
  2481. +++ linux-4.9.6/block/blk-mq.c 2017-01-28 13:59:09.903655111 +0100
  2482. @@ -72,7 +72,7 @@
  2483. static void blk_mq_freeze_queue_wait(struct request_queue *q)
  2484. {
  2485. - wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->q_usage_counter));
  2486. + swait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->q_usage_counter));
  2487. }
  2488. /*
  2489. @@ -110,7 +110,7 @@
  2490. WARN_ON_ONCE(freeze_depth < 0);
  2491. if (!freeze_depth) {
  2492. percpu_ref_reinit(&q->q_usage_counter);
  2493. - wake_up_all(&q->mq_freeze_wq);
  2494. + swake_up_all(&q->mq_freeze_wq);
  2495. }
  2496. }
  2497. EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
  2498. @@ -129,7 +129,7 @@
  2499. * dying, we need to ensure that processes currently waiting on
  2500. * the queue are notified as well.
  2501. */
  2502. - wake_up_all(&q->mq_freeze_wq);
  2503. + swake_up_all(&q->mq_freeze_wq);
  2504. }
  2505. bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
  2506. @@ -177,6 +177,9 @@
  2507. rq->resid_len = 0;
  2508. rq->sense = NULL;
  2509. +#ifdef CONFIG_PREEMPT_RT_FULL
  2510. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  2511. +#endif
  2512. INIT_LIST_HEAD(&rq->timeout_list);
  2513. rq->timeout = 0;
  2514. @@ -345,6 +348,17 @@
  2515. }
  2516. EXPORT_SYMBOL(blk_mq_end_request);
  2517. +#ifdef CONFIG_PREEMPT_RT_FULL
  2518. +
  2519. +void __blk_mq_complete_request_remote_work(struct work_struct *work)
  2520. +{
  2521. + struct request *rq = container_of(work, struct request, work);
  2522. +
  2523. + rq->q->softirq_done_fn(rq);
  2524. +}
  2525. +
  2526. +#else
  2527. +
  2528. static void __blk_mq_complete_request_remote(void *data)
  2529. {
  2530. struct request *rq = data;
  2531. @@ -352,6 +366,8 @@
  2532. rq->q->softirq_done_fn(rq);
  2533. }
  2534. +#endif
  2535. +
  2536. static void blk_mq_ipi_complete_request(struct request *rq)
  2537. {
  2538. struct blk_mq_ctx *ctx = rq->mq_ctx;
  2539. @@ -363,19 +379,23 @@
  2540. return;
  2541. }
  2542. - cpu = get_cpu();
  2543. + cpu = get_cpu_light();
  2544. if (!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
  2545. shared = cpus_share_cache(cpu, ctx->cpu);
  2546. if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
  2547. +#ifdef CONFIG_PREEMPT_RT_FULL
  2548. + schedule_work_on(ctx->cpu, &rq->work);
  2549. +#else
  2550. rq->csd.func = __blk_mq_complete_request_remote;
  2551. rq->csd.info = rq;
  2552. rq->csd.flags = 0;
  2553. smp_call_function_single_async(ctx->cpu, &rq->csd);
  2554. +#endif
  2555. } else {
  2556. rq->q->softirq_done_fn(rq);
  2557. }
  2558. - put_cpu();
  2559. + put_cpu_light();
  2560. }
  2561. static void __blk_mq_complete_request(struct request *rq)
  2562. @@ -915,14 +935,14 @@
  2563. return;
  2564. if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
  2565. - int cpu = get_cpu();
  2566. + int cpu = get_cpu_light();
  2567. if (cpumask_test_cpu(cpu, hctx->cpumask)) {
  2568. __blk_mq_run_hw_queue(hctx);
  2569. - put_cpu();
  2570. + put_cpu_light();
  2571. return;
  2572. }
  2573. - put_cpu();
  2574. + put_cpu_light();
  2575. }
  2576. kblockd_schedule_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work);
  2577. diff -Nur linux-4.9.6.orig/block/blk-mq.h linux-4.9.6/block/blk-mq.h
  2578. --- linux-4.9.6.orig/block/blk-mq.h 2017-01-26 08:25:24.000000000 +0100
  2579. +++ linux-4.9.6/block/blk-mq.h 2017-01-28 13:59:09.903655111 +0100
  2580. @@ -72,12 +72,12 @@
  2581. */
  2582. static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
  2583. {
  2584. - return __blk_mq_get_ctx(q, get_cpu());
  2585. + return __blk_mq_get_ctx(q, get_cpu_light());
  2586. }
  2587. static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
  2588. {
  2589. - put_cpu();
  2590. + put_cpu_light();
  2591. }
  2592. struct blk_mq_alloc_data {
  2593. diff -Nur linux-4.9.6.orig/block/blk-softirq.c linux-4.9.6/block/blk-softirq.c
  2594. --- linux-4.9.6.orig/block/blk-softirq.c 2017-01-26 08:25:24.000000000 +0100
  2595. +++ linux-4.9.6/block/blk-softirq.c 2017-01-28 13:59:09.903655111 +0100
  2596. @@ -51,6 +51,7 @@
  2597. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  2598. local_irq_restore(flags);
  2599. + preempt_check_resched_rt();
  2600. }
  2601. /*
  2602. @@ -89,6 +90,7 @@
  2603. this_cpu_ptr(&blk_cpu_done));
  2604. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  2605. local_irq_enable();
  2606. + preempt_check_resched_rt();
  2607. return 0;
  2608. }
  2609. @@ -141,6 +143,7 @@
  2610. goto do_local;
  2611. local_irq_restore(flags);
  2612. + preempt_check_resched_rt();
  2613. }
  2614. /**
  2615. diff -Nur linux-4.9.6.orig/block/bounce.c linux-4.9.6/block/bounce.c
  2616. --- linux-4.9.6.orig/block/bounce.c 2017-01-26 08:25:24.000000000 +0100
  2617. +++ linux-4.9.6/block/bounce.c 2017-01-28 13:59:09.903655111 +0100
  2618. @@ -55,11 +55,11 @@
  2619. unsigned long flags;
  2620. unsigned char *vto;
  2621. - local_irq_save(flags);
  2622. + local_irq_save_nort(flags);
  2623. vto = kmap_atomic(to->bv_page);
  2624. memcpy(vto + to->bv_offset, vfrom, to->bv_len);
  2625. kunmap_atomic(vto);
  2626. - local_irq_restore(flags);
  2627. + local_irq_restore_nort(flags);
  2628. }
  2629. #else /* CONFIG_HIGHMEM */
  2630. diff -Nur linux-4.9.6.orig/crypto/algapi.c linux-4.9.6/crypto/algapi.c
  2631. --- linux-4.9.6.orig/crypto/algapi.c 2017-01-26 08:25:24.000000000 +0100
  2632. +++ linux-4.9.6/crypto/algapi.c 2017-01-28 13:59:09.903655111 +0100
  2633. @@ -718,13 +718,13 @@
  2634. int crypto_register_notifier(struct notifier_block *nb)
  2635. {
  2636. - return blocking_notifier_chain_register(&crypto_chain, nb);
  2637. + return srcu_notifier_chain_register(&crypto_chain, nb);
  2638. }
  2639. EXPORT_SYMBOL_GPL(crypto_register_notifier);
  2640. int crypto_unregister_notifier(struct notifier_block *nb)
  2641. {
  2642. - return blocking_notifier_chain_unregister(&crypto_chain, nb);
  2643. + return srcu_notifier_chain_unregister(&crypto_chain, nb);
  2644. }
  2645. EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
  2646. diff -Nur linux-4.9.6.orig/crypto/api.c linux-4.9.6/crypto/api.c
  2647. --- linux-4.9.6.orig/crypto/api.c 2017-01-26 08:25:24.000000000 +0100
  2648. +++ linux-4.9.6/crypto/api.c 2017-01-28 13:59:09.903655111 +0100
  2649. @@ -31,7 +31,7 @@
  2650. DECLARE_RWSEM(crypto_alg_sem);
  2651. EXPORT_SYMBOL_GPL(crypto_alg_sem);
  2652. -BLOCKING_NOTIFIER_HEAD(crypto_chain);
  2653. +SRCU_NOTIFIER_HEAD(crypto_chain);
  2654. EXPORT_SYMBOL_GPL(crypto_chain);
  2655. static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
  2656. @@ -236,10 +236,10 @@
  2657. {
  2658. int ok;
  2659. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  2660. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  2661. if (ok == NOTIFY_DONE) {
  2662. request_module("cryptomgr");
  2663. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  2664. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  2665. }
  2666. return ok;
  2667. diff -Nur linux-4.9.6.orig/crypto/internal.h linux-4.9.6/crypto/internal.h
  2668. --- linux-4.9.6.orig/crypto/internal.h 2017-01-26 08:25:24.000000000 +0100
  2669. +++ linux-4.9.6/crypto/internal.h 2017-01-28 13:59:09.903655111 +0100
  2670. @@ -47,7 +47,7 @@
  2671. extern struct list_head crypto_alg_list;
  2672. extern struct rw_semaphore crypto_alg_sem;
  2673. -extern struct blocking_notifier_head crypto_chain;
  2674. +extern struct srcu_notifier_head crypto_chain;
  2675. #ifdef CONFIG_PROC_FS
  2676. void __init crypto_init_proc(void);
  2677. @@ -146,7 +146,7 @@
  2678. static inline void crypto_notify(unsigned long val, void *v)
  2679. {
  2680. - blocking_notifier_call_chain(&crypto_chain, val, v);
  2681. + srcu_notifier_call_chain(&crypto_chain, val, v);
  2682. }
  2683. #endif /* _CRYPTO_INTERNAL_H */
  2684. diff -Nur linux-4.9.6.orig/Documentation/sysrq.txt linux-4.9.6/Documentation/sysrq.txt
  2685. --- linux-4.9.6.orig/Documentation/sysrq.txt 2017-01-26 08:25:24.000000000 +0100
  2686. +++ linux-4.9.6/Documentation/sysrq.txt 2017-01-28 13:59:09.887654498 +0100
  2687. @@ -59,10 +59,17 @@
  2688. On other - If you know of the key combos for other architectures, please
  2689. let me know so I can add them to this section.
  2690. -On all - write a character to /proc/sysrq-trigger. e.g.:
  2691. -
  2692. +On all - write a character to /proc/sysrq-trigger, e.g.:
  2693. echo t > /proc/sysrq-trigger
  2694. +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
  2695. + echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
  2696. + Send an ICMP echo request with this pattern plus the particular
  2697. + SysRq command key. Example:
  2698. + # ping -c1 -s57 -p0102030468
  2699. + will trigger the SysRq-H (help) command.
  2700. +
  2701. +
  2702. * What are the 'command' keys?
  2703. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2704. 'b' - Will immediately reboot the system without syncing or unmounting
  2705. diff -Nur linux-4.9.6.orig/Documentation/trace/histograms.txt linux-4.9.6/Documentation/trace/histograms.txt
  2706. --- linux-4.9.6.orig/Documentation/trace/histograms.txt 1970-01-01 01:00:00.000000000 +0100
  2707. +++ linux-4.9.6/Documentation/trace/histograms.txt 2017-01-28 13:59:09.887654498 +0100
  2708. @@ -0,0 +1,186 @@
  2709. + Using the Linux Kernel Latency Histograms
  2710. +
  2711. +
  2712. +This document gives a short explanation how to enable, configure and use
  2713. +latency histograms. Latency histograms are primarily relevant in the
  2714. +context of real-time enabled kernels (CONFIG_PREEMPT/CONFIG_PREEMPT_RT)
  2715. +and are used in the quality management of the Linux real-time
  2716. +capabilities.
  2717. +
  2718. +
  2719. +* Purpose of latency histograms
  2720. +
  2721. +A latency histogram continuously accumulates the frequencies of latency
  2722. +data. There are two types of histograms
  2723. +- potential sources of latencies
  2724. +- effective latencies
  2725. +
  2726. +
  2727. +* Potential sources of latencies
  2728. +
  2729. +Potential sources of latencies are code segments where interrupts,
  2730. +preemption or both are disabled (aka critical sections). To create
  2731. +histograms of potential sources of latency, the kernel stores the time
  2732. +stamp at the start of a critical section, determines the time elapsed
  2733. +when the end of the section is reached, and increments the frequency
  2734. +counter of that latency value - irrespective of whether any concurrently
  2735. +running process is affected by latency or not.
  2736. +- Configuration items (in the Kernel hacking/Tracers submenu)
  2737. + CONFIG_INTERRUPT_OFF_LATENCY
  2738. + CONFIG_PREEMPT_OFF_LATENCY
  2739. +
  2740. +
  2741. +* Effective latencies
  2742. +
  2743. +Effective latencies are actually occuring during wakeup of a process. To
  2744. +determine effective latencies, the kernel stores the time stamp when a
  2745. +process is scheduled to be woken up, and determines the duration of the
  2746. +wakeup time shortly before control is passed over to this process. Note
  2747. +that the apparent latency in user space may be somewhat longer, since the
  2748. +process may be interrupted after control is passed over to it but before
  2749. +the execution in user space takes place. Simply measuring the interval
  2750. +between enqueuing and wakeup may also not appropriate in cases when a
  2751. +process is scheduled as a result of a timer expiration. The timer may have
  2752. +missed its deadline, e.g. due to disabled interrupts, but this latency
  2753. +would not be registered. Therefore, the offsets of missed timers are
  2754. +recorded in a separate histogram. If both wakeup latency and missed timer
  2755. +offsets are configured and enabled, a third histogram may be enabled that
  2756. +records the overall latency as a sum of the timer latency, if any, and the
  2757. +wakeup latency. This histogram is called "timerandwakeup".
  2758. +- Configuration items (in the Kernel hacking/Tracers submenu)
  2759. + CONFIG_WAKEUP_LATENCY
  2760. + CONFIG_MISSED_TIMER_OFSETS
  2761. +
  2762. +
  2763. +* Usage
  2764. +
  2765. +The interface to the administration of the latency histograms is located
  2766. +in the debugfs file system. To mount it, either enter
  2767. +
  2768. +mount -t sysfs nodev /sys
  2769. +mount -t debugfs nodev /sys/kernel/debug
  2770. +
  2771. +from shell command line level, or add
  2772. +
  2773. +nodev /sys sysfs defaults 0 0
  2774. +nodev /sys/kernel/debug debugfs defaults 0 0
  2775. +
  2776. +to the file /etc/fstab. All latency histogram related files are then
  2777. +available in the directory /sys/kernel/debug/tracing/latency_hist. A
  2778. +particular histogram type is enabled by writing non-zero to the related
  2779. +variable in the /sys/kernel/debug/tracing/latency_hist/enable directory.
  2780. +Select "preemptirqsoff" for the histograms of potential sources of
  2781. +latencies and "wakeup" for histograms of effective latencies etc. The
  2782. +histogram data - one per CPU - are available in the files
  2783. +
  2784. +/sys/kernel/debug/tracing/latency_hist/preemptoff/CPUx
  2785. +/sys/kernel/debug/tracing/latency_hist/irqsoff/CPUx
  2786. +/sys/kernel/debug/tracing/latency_hist/preemptirqsoff/CPUx
  2787. +/sys/kernel/debug/tracing/latency_hist/wakeup/CPUx
  2788. +/sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio/CPUx
  2789. +/sys/kernel/debug/tracing/latency_hist/missed_timer_offsets/CPUx
  2790. +/sys/kernel/debug/tracing/latency_hist/timerandwakeup/CPUx
  2791. +
  2792. +The histograms are reset by writing non-zero to the file "reset" in a
  2793. +particular latency directory. To reset all latency data, use
  2794. +
  2795. +#!/bin/sh
  2796. +
  2797. +TRACINGDIR=/sys/kernel/debug/tracing
  2798. +HISTDIR=$TRACINGDIR/latency_hist
  2799. +
  2800. +if test -d $HISTDIR
  2801. +then
  2802. + cd $HISTDIR
  2803. + for i in `find . | grep /reset$`
  2804. + do
  2805. + echo 1 >$i
  2806. + done
  2807. +fi
  2808. +
  2809. +
  2810. +* Data format
  2811. +
  2812. +Latency data are stored with a resolution of one microsecond. The
  2813. +maximum latency is 10,240 microseconds. The data are only valid, if the
  2814. +overflow register is empty. Every output line contains the latency in
  2815. +microseconds in the first row and the number of samples in the second
  2816. +row. To display only lines with a positive latency count, use, for
  2817. +example,
  2818. +
  2819. +grep -v " 0$" /sys/kernel/debug/tracing/latency_hist/preemptoff/CPU0
  2820. +
  2821. +#Minimum latency: 0 microseconds.
  2822. +#Average latency: 0 microseconds.
  2823. +#Maximum latency: 25 microseconds.
  2824. +#Total samples: 3104770694
  2825. +#There are 0 samples greater or equal than 10240 microseconds
  2826. +#usecs samples
  2827. + 0 2984486876
  2828. + 1 49843506
  2829. + 2 58219047
  2830. + 3 5348126
  2831. + 4 2187960
  2832. + 5 3388262
  2833. + 6 959289
  2834. + 7 208294
  2835. + 8 40420
  2836. + 9 4485
  2837. + 10 14918
  2838. + 11 18340
  2839. + 12 25052
  2840. + 13 19455
  2841. + 14 5602
  2842. + 15 969
  2843. + 16 47
  2844. + 17 18
  2845. + 18 14
  2846. + 19 1
  2847. + 20 3
  2848. + 21 2
  2849. + 22 5
  2850. + 23 2
  2851. + 25 1
  2852. +
  2853. +
  2854. +* Wakeup latency of a selected process
  2855. +
  2856. +To only collect wakeup latency data of a particular process, write the
  2857. +PID of the requested process to
  2858. +
  2859. +/sys/kernel/debug/tracing/latency_hist/wakeup/pid
  2860. +
  2861. +PIDs are not considered, if this variable is set to 0.
  2862. +
  2863. +
  2864. +* Details of the process with the highest wakeup latency so far
  2865. +
  2866. +Selected data of the process that suffered from the highest wakeup
  2867. +latency that occurred in a particular CPU are available in the file
  2868. +
  2869. +/sys/kernel/debug/tracing/latency_hist/wakeup/max_latency-CPUx.
  2870. +
  2871. +In addition, other relevant system data at the time when the
  2872. +latency occurred are given.
  2873. +
  2874. +The format of the data is (all in one line):
  2875. +<PID> <Priority> <Latency> (<Timeroffset>) <Command> \
  2876. +<- <PID> <Priority> <Command> <Timestamp>
  2877. +
  2878. +The value of <Timeroffset> is only relevant in the combined timer
  2879. +and wakeup latency recording. In the wakeup recording, it is
  2880. +always 0, in the missed_timer_offsets recording, it is the same
  2881. +as <Latency>.
  2882. +
  2883. +When retrospectively searching for the origin of a latency and
  2884. +tracing was not enabled, it may be helpful to know the name and
  2885. +some basic data of the task that (finally) was switching to the
  2886. +late real-tlme task. In addition to the victim's data, also the
  2887. +data of the possible culprit are therefore displayed after the
  2888. +"<-" symbol.
  2889. +
  2890. +Finally, the timestamp of the time when the latency occurred
  2891. +in <seconds>.<microseconds> after the most recent system boot
  2892. +is provided.
  2893. +
  2894. +These data are also reset when the wakeup histogram is reset.
  2895. diff -Nur linux-4.9.6.orig/drivers/acpi/acpica/acglobal.h linux-4.9.6/drivers/acpi/acpica/acglobal.h
  2896. --- linux-4.9.6.orig/drivers/acpi/acpica/acglobal.h 2017-01-26 08:25:24.000000000 +0100
  2897. +++ linux-4.9.6/drivers/acpi/acpica/acglobal.h 2017-01-28 13:59:09.903655111 +0100
  2898. @@ -116,7 +116,7 @@
  2899. * interrupt level
  2900. */
  2901. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */
  2902. -ACPI_GLOBAL(acpi_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  2903. +ACPI_GLOBAL(acpi_raw_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  2904. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock);
  2905. /* Mutex for _OSI support */
  2906. diff -Nur linux-4.9.6.orig/drivers/acpi/acpica/hwregs.c linux-4.9.6/drivers/acpi/acpica/hwregs.c
  2907. --- linux-4.9.6.orig/drivers/acpi/acpica/hwregs.c 2017-01-26 08:25:24.000000000 +0100
  2908. +++ linux-4.9.6/drivers/acpi/acpica/hwregs.c 2017-01-28 13:59:09.903655111 +0100
  2909. @@ -363,14 +363,14 @@
  2910. ACPI_BITMASK_ALL_FIXED_STATUS,
  2911. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  2912. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  2913. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  2914. /* Clear the fixed events in PM1 A/B */
  2915. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  2916. ACPI_BITMASK_ALL_FIXED_STATUS);
  2917. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  2918. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  2919. if (ACPI_FAILURE(status)) {
  2920. goto exit;
  2921. diff -Nur linux-4.9.6.orig/drivers/acpi/acpica/hwxface.c linux-4.9.6/drivers/acpi/acpica/hwxface.c
  2922. --- linux-4.9.6.orig/drivers/acpi/acpica/hwxface.c 2017-01-26 08:25:24.000000000 +0100
  2923. +++ linux-4.9.6/drivers/acpi/acpica/hwxface.c 2017-01-28 13:59:09.903655111 +0100
  2924. @@ -373,7 +373,7 @@
  2925. return_ACPI_STATUS(AE_BAD_PARAMETER);
  2926. }
  2927. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  2928. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  2929. /*
  2930. * At this point, we know that the parent register is one of the
  2931. @@ -434,7 +434,7 @@
  2932. unlock_and_exit:
  2933. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  2934. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  2935. return_ACPI_STATUS(status);
  2936. }
  2937. diff -Nur linux-4.9.6.orig/drivers/acpi/acpica/utmutex.c linux-4.9.6/drivers/acpi/acpica/utmutex.c
  2938. --- linux-4.9.6.orig/drivers/acpi/acpica/utmutex.c 2017-01-26 08:25:24.000000000 +0100
  2939. +++ linux-4.9.6/drivers/acpi/acpica/utmutex.c 2017-01-28 13:59:09.903655111 +0100
  2940. @@ -88,7 +88,7 @@
  2941. return_ACPI_STATUS (status);
  2942. }
  2943. - status = acpi_os_create_lock (&acpi_gbl_hardware_lock);
  2944. + status = acpi_os_create_raw_lock (&acpi_gbl_hardware_lock);
  2945. if (ACPI_FAILURE (status)) {
  2946. return_ACPI_STATUS (status);
  2947. }
  2948. @@ -145,7 +145,7 @@
  2949. /* Delete the spinlocks */
  2950. acpi_os_delete_lock(acpi_gbl_gpe_lock);
  2951. - acpi_os_delete_lock(acpi_gbl_hardware_lock);
  2952. + acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
  2953. acpi_os_delete_lock(acpi_gbl_reference_count_lock);
  2954. /* Delete the reader/writer lock */
  2955. diff -Nur linux-4.9.6.orig/drivers/ata/libata-sff.c linux-4.9.6/drivers/ata/libata-sff.c
  2956. --- linux-4.9.6.orig/drivers/ata/libata-sff.c 2017-01-26 08:25:24.000000000 +0100
  2957. +++ linux-4.9.6/drivers/ata/libata-sff.c 2017-01-28 13:59:09.907655265 +0100
  2958. @@ -678,9 +678,9 @@
  2959. unsigned long flags;
  2960. unsigned int consumed;
  2961. - local_irq_save(flags);
  2962. + local_irq_save_nort(flags);
  2963. consumed = ata_sff_data_xfer32(dev, buf, buflen, rw);
  2964. - local_irq_restore(flags);
  2965. + local_irq_restore_nort(flags);
  2966. return consumed;
  2967. }
  2968. @@ -719,7 +719,7 @@
  2969. unsigned long flags;
  2970. /* FIXME: use a bounce buffer */
  2971. - local_irq_save(flags);
  2972. + local_irq_save_nort(flags);
  2973. buf = kmap_atomic(page);
  2974. /* do the actual data transfer */
  2975. @@ -727,7 +727,7 @@
  2976. do_write);
  2977. kunmap_atomic(buf);
  2978. - local_irq_restore(flags);
  2979. + local_irq_restore_nort(flags);
  2980. } else {
  2981. buf = page_address(page);
  2982. ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size,
  2983. @@ -864,7 +864,7 @@
  2984. unsigned long flags;
  2985. /* FIXME: use bounce buffer */
  2986. - local_irq_save(flags);
  2987. + local_irq_save_nort(flags);
  2988. buf = kmap_atomic(page);
  2989. /* do the actual data transfer */
  2990. @@ -872,7 +872,7 @@
  2991. count, rw);
  2992. kunmap_atomic(buf);
  2993. - local_irq_restore(flags);
  2994. + local_irq_restore_nort(flags);
  2995. } else {
  2996. buf = page_address(page);
  2997. consumed = ap->ops->sff_data_xfer(dev, buf + offset,
  2998. diff -Nur linux-4.9.6.orig/drivers/block/zram/zcomp.c linux-4.9.6/drivers/block/zram/zcomp.c
  2999. --- linux-4.9.6.orig/drivers/block/zram/zcomp.c 2017-01-26 08:25:24.000000000 +0100
  3000. +++ linux-4.9.6/drivers/block/zram/zcomp.c 2017-01-28 13:59:09.907655265 +0100
  3001. @@ -118,12 +118,19 @@
  3002. struct zcomp_strm *zcomp_stream_get(struct zcomp *comp)
  3003. {
  3004. - return *get_cpu_ptr(comp->stream);
  3005. + struct zcomp_strm *zstrm;
  3006. +
  3007. + zstrm = *this_cpu_ptr(comp->stream);
  3008. + spin_lock(&zstrm->zcomp_lock);
  3009. + return zstrm;
  3010. }
  3011. void zcomp_stream_put(struct zcomp *comp)
  3012. {
  3013. - put_cpu_ptr(comp->stream);
  3014. + struct zcomp_strm *zstrm;
  3015. +
  3016. + zstrm = *this_cpu_ptr(comp->stream);
  3017. + spin_unlock(&zstrm->zcomp_lock);
  3018. }
  3019. int zcomp_compress(struct zcomp_strm *zstrm,
  3020. @@ -174,6 +181,7 @@
  3021. pr_err("Can't allocate a compression stream\n");
  3022. return NOTIFY_BAD;
  3023. }
  3024. + spin_lock_init(&zstrm->zcomp_lock);
  3025. *per_cpu_ptr(comp->stream, cpu) = zstrm;
  3026. break;
  3027. case CPU_DEAD:
  3028. diff -Nur linux-4.9.6.orig/drivers/block/zram/zcomp.h linux-4.9.6/drivers/block/zram/zcomp.h
  3029. --- linux-4.9.6.orig/drivers/block/zram/zcomp.h 2017-01-26 08:25:24.000000000 +0100
  3030. +++ linux-4.9.6/drivers/block/zram/zcomp.h 2017-01-28 13:59:09.907655265 +0100
  3031. @@ -14,6 +14,7 @@
  3032. /* compression/decompression buffer */
  3033. void *buffer;
  3034. struct crypto_comp *tfm;
  3035. + spinlock_t zcomp_lock;
  3036. };
  3037. /* dynamic per-device compression frontend */
  3038. diff -Nur linux-4.9.6.orig/drivers/block/zram/zram_drv.c linux-4.9.6/drivers/block/zram/zram_drv.c
  3039. --- linux-4.9.6.orig/drivers/block/zram/zram_drv.c 2017-01-26 08:25:24.000000000 +0100
  3040. +++ linux-4.9.6/drivers/block/zram/zram_drv.c 2017-01-28 13:59:09.907655265 +0100
  3041. @@ -528,6 +528,8 @@
  3042. goto out_error;
  3043. }
  3044. + zram_meta_init_table_locks(meta, disksize);
  3045. +
  3046. return meta;
  3047. out_error:
  3048. @@ -575,28 +577,28 @@
  3049. struct zram_meta *meta = zram->meta;
  3050. unsigned long handle;
  3051. unsigned int size;
  3052. + struct zcomp_strm *zstrm;
  3053. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3054. + zram_lock_table(&meta->table[index]);
  3055. handle = meta->table[index].handle;
  3056. size = zram_get_obj_size(meta, index);
  3057. if (!handle || zram_test_flag(meta, index, ZRAM_ZERO)) {
  3058. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3059. + zram_unlock_table(&meta->table[index]);
  3060. clear_page(mem);
  3061. return 0;
  3062. }
  3063. + zstrm = zcomp_stream_get(zram->comp);
  3064. cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_RO);
  3065. if (size == PAGE_SIZE) {
  3066. copy_page(mem, cmem);
  3067. } else {
  3068. - struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp);
  3069. -
  3070. ret = zcomp_decompress(zstrm, cmem, size, mem);
  3071. - zcomp_stream_put(zram->comp);
  3072. }
  3073. zs_unmap_object(meta->mem_pool, handle);
  3074. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3075. + zcomp_stream_put(zram->comp);
  3076. + zram_unlock_table(&meta->table[index]);
  3077. /* Should NEVER happen. Return bio error if it does. */
  3078. if (unlikely(ret)) {
  3079. @@ -616,14 +618,14 @@
  3080. struct zram_meta *meta = zram->meta;
  3081. page = bvec->bv_page;
  3082. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3083. + zram_lock_table(&meta->table[index]);
  3084. if (unlikely(!meta->table[index].handle) ||
  3085. zram_test_flag(meta, index, ZRAM_ZERO)) {
  3086. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3087. + zram_unlock_table(&meta->table[index]);
  3088. handle_zero_page(bvec);
  3089. return 0;
  3090. }
  3091. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3092. + zram_unlock_table(&meta->table[index]);
  3093. if (is_partial_io(bvec))
  3094. /* Use a temporary buffer to decompress the page */
  3095. @@ -700,10 +702,10 @@
  3096. if (user_mem)
  3097. kunmap_atomic(user_mem);
  3098. /* Free memory associated with this sector now. */
  3099. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3100. + zram_lock_table(&meta->table[index]);
  3101. zram_free_page(zram, index);
  3102. zram_set_flag(meta, index, ZRAM_ZERO);
  3103. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3104. + zram_unlock_table(&meta->table[index]);
  3105. atomic64_inc(&zram->stats.zero_pages);
  3106. ret = 0;
  3107. @@ -794,12 +796,12 @@
  3108. * Free memory associated with this sector
  3109. * before overwriting unused sectors.
  3110. */
  3111. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3112. + zram_lock_table(&meta->table[index]);
  3113. zram_free_page(zram, index);
  3114. meta->table[index].handle = handle;
  3115. zram_set_obj_size(meta, index, clen);
  3116. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3117. + zram_unlock_table(&meta->table[index]);
  3118. /* Update stats */
  3119. atomic64_add(clen, &zram->stats.compr_data_size);
  3120. @@ -842,9 +844,9 @@
  3121. }
  3122. while (n >= PAGE_SIZE) {
  3123. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3124. + zram_lock_table(&meta->table[index]);
  3125. zram_free_page(zram, index);
  3126. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3127. + zram_unlock_table(&meta->table[index]);
  3128. atomic64_inc(&zram->stats.notify_free);
  3129. index++;
  3130. n -= PAGE_SIZE;
  3131. @@ -973,9 +975,9 @@
  3132. zram = bdev->bd_disk->private_data;
  3133. meta = zram->meta;
  3134. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3135. + zram_lock_table(&meta->table[index]);
  3136. zram_free_page(zram, index);
  3137. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3138. + zram_unlock_table(&meta->table[index]);
  3139. atomic64_inc(&zram->stats.notify_free);
  3140. }
  3141. diff -Nur linux-4.9.6.orig/drivers/block/zram/zram_drv.h linux-4.9.6/drivers/block/zram/zram_drv.h
  3142. --- linux-4.9.6.orig/drivers/block/zram/zram_drv.h 2017-01-26 08:25:24.000000000 +0100
  3143. +++ linux-4.9.6/drivers/block/zram/zram_drv.h 2017-01-28 13:59:09.907655265 +0100
  3144. @@ -73,6 +73,9 @@
  3145. struct zram_table_entry {
  3146. unsigned long handle;
  3147. unsigned long value;
  3148. +#ifdef CONFIG_PREEMPT_RT_BASE
  3149. + spinlock_t lock;
  3150. +#endif
  3151. };
  3152. struct zram_stats {
  3153. @@ -120,4 +123,42 @@
  3154. */
  3155. bool claim; /* Protected by bdev->bd_mutex */
  3156. };
  3157. +
  3158. +#ifndef CONFIG_PREEMPT_RT_BASE
  3159. +static inline void zram_lock_table(struct zram_table_entry *table)
  3160. +{
  3161. + bit_spin_lock(ZRAM_ACCESS, &table->value);
  3162. +}
  3163. +
  3164. +static inline void zram_unlock_table(struct zram_table_entry *table)
  3165. +{
  3166. + bit_spin_unlock(ZRAM_ACCESS, &table->value);
  3167. +}
  3168. +
  3169. +static inline void zram_meta_init_table_locks(struct zram_meta *meta, u64 disksize) { }
  3170. +#else /* CONFIG_PREEMPT_RT_BASE */
  3171. +static inline void zram_lock_table(struct zram_table_entry *table)
  3172. +{
  3173. + spin_lock(&table->lock);
  3174. + __set_bit(ZRAM_ACCESS, &table->value);
  3175. +}
  3176. +
  3177. +static inline void zram_unlock_table(struct zram_table_entry *table)
  3178. +{
  3179. + __clear_bit(ZRAM_ACCESS, &table->value);
  3180. + spin_unlock(&table->lock);
  3181. +}
  3182. +
  3183. +static inline void zram_meta_init_table_locks(struct zram_meta *meta, u64 disksize)
  3184. +{
  3185. + size_t num_pages = disksize >> PAGE_SHIFT;
  3186. + size_t index;
  3187. +
  3188. + for (index = 0; index < num_pages; index++) {
  3189. + spinlock_t *lock = &meta->table[index].lock;
  3190. + spin_lock_init(lock);
  3191. + }
  3192. +}
  3193. +#endif /* CONFIG_PREEMPT_RT_BASE */
  3194. +
  3195. #endif
  3196. diff -Nur linux-4.9.6.orig/drivers/char/random.c linux-4.9.6/drivers/char/random.c
  3197. --- linux-4.9.6.orig/drivers/char/random.c 2017-01-26 08:25:24.000000000 +0100
  3198. +++ linux-4.9.6/drivers/char/random.c 2017-01-28 13:59:09.907655265 +0100
  3199. @@ -1028,8 +1028,6 @@
  3200. } sample;
  3201. long delta, delta2, delta3;
  3202. - preempt_disable();
  3203. -
  3204. sample.jiffies = jiffies;
  3205. sample.cycles = random_get_entropy();
  3206. sample.num = num;
  3207. @@ -1070,7 +1068,6 @@
  3208. */
  3209. credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
  3210. }
  3211. - preempt_enable();
  3212. }
  3213. void add_input_randomness(unsigned int type, unsigned int code,
  3214. @@ -1123,28 +1120,27 @@
  3215. return *(ptr + f->reg_idx++);
  3216. }
  3217. -void add_interrupt_randomness(int irq, int irq_flags)
  3218. +void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
  3219. {
  3220. struct entropy_store *r;
  3221. struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
  3222. - struct pt_regs *regs = get_irq_regs();
  3223. unsigned long now = jiffies;
  3224. cycles_t cycles = random_get_entropy();
  3225. __u32 c_high, j_high;
  3226. - __u64 ip;
  3227. unsigned long seed;
  3228. int credit = 0;
  3229. if (cycles == 0)
  3230. - cycles = get_reg(fast_pool, regs);
  3231. + cycles = get_reg(fast_pool, NULL);
  3232. c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0;
  3233. j_high = (sizeof(now) > 4) ? now >> 32 : 0;
  3234. fast_pool->pool[0] ^= cycles ^ j_high ^ irq;
  3235. fast_pool->pool[1] ^= now ^ c_high;
  3236. - ip = regs ? instruction_pointer(regs) : _RET_IP_;
  3237. + if (!ip)
  3238. + ip = _RET_IP_;
  3239. fast_pool->pool[2] ^= ip;
  3240. fast_pool->pool[3] ^= (sizeof(ip) > 4) ? ip >> 32 :
  3241. - get_reg(fast_pool, regs);
  3242. + get_reg(fast_pool, NULL);
  3243. fast_mix(fast_pool);
  3244. add_interrupt_bench(cycles);
  3245. diff -Nur linux-4.9.6.orig/drivers/clocksource/tcb_clksrc.c linux-4.9.6/drivers/clocksource/tcb_clksrc.c
  3246. --- linux-4.9.6.orig/drivers/clocksource/tcb_clksrc.c 2017-01-26 08:25:24.000000000 +0100
  3247. +++ linux-4.9.6/drivers/clocksource/tcb_clksrc.c 2017-01-28 13:59:09.907655265 +0100
  3248. @@ -23,8 +23,7 @@
  3249. * this 32 bit free-running counter. the second channel is not used.
  3250. *
  3251. * - The third channel may be used to provide a 16-bit clockevent
  3252. - * source, used in either periodic or oneshot mode. This runs
  3253. - * at 32 KiHZ, and can handle delays of up to two seconds.
  3254. + * source, used in either periodic or oneshot mode.
  3255. *
  3256. * A boot clocksource and clockevent source are also currently needed,
  3257. * unless the relevant platforms (ARM/AT91, AVR32/AT32) are changed so
  3258. @@ -74,6 +73,8 @@
  3259. struct tc_clkevt_device {
  3260. struct clock_event_device clkevt;
  3261. struct clk *clk;
  3262. + bool clk_enabled;
  3263. + u32 freq;
  3264. void __iomem *regs;
  3265. };
  3266. @@ -82,15 +83,26 @@
  3267. return container_of(clkevt, struct tc_clkevt_device, clkevt);
  3268. }
  3269. -/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
  3270. - * because using one of the divided clocks would usually mean the
  3271. - * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
  3272. - *
  3273. - * A divided clock could be good for high resolution timers, since
  3274. - * 30.5 usec resolution can seem "low".
  3275. - */
  3276. static u32 timer_clock;
  3277. +static void tc_clk_disable(struct clock_event_device *d)
  3278. +{
  3279. + struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  3280. +
  3281. + clk_disable(tcd->clk);
  3282. + tcd->clk_enabled = false;
  3283. +}
  3284. +
  3285. +static void tc_clk_enable(struct clock_event_device *d)
  3286. +{
  3287. + struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  3288. +
  3289. + if (tcd->clk_enabled)
  3290. + return;
  3291. + clk_enable(tcd->clk);
  3292. + tcd->clk_enabled = true;
  3293. +}
  3294. +
  3295. static int tc_shutdown(struct clock_event_device *d)
  3296. {
  3297. struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  3298. @@ -98,8 +110,14 @@
  3299. __raw_writel(0xff, regs + ATMEL_TC_REG(2, IDR));
  3300. __raw_writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
  3301. + return 0;
  3302. +}
  3303. +
  3304. +static int tc_shutdown_clk_off(struct clock_event_device *d)
  3305. +{
  3306. + tc_shutdown(d);
  3307. if (!clockevent_state_detached(d))
  3308. - clk_disable(tcd->clk);
  3309. + tc_clk_disable(d);
  3310. return 0;
  3311. }
  3312. @@ -112,9 +130,9 @@
  3313. if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
  3314. tc_shutdown(d);
  3315. - clk_enable(tcd->clk);
  3316. + tc_clk_enable(d);
  3317. - /* slow clock, count up to RC, then irq and stop */
  3318. + /* count up to RC, then irq and stop */
  3319. __raw_writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
  3320. ATMEL_TC_WAVESEL_UP_AUTO, regs + ATMEL_TC_REG(2, CMR));
  3321. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  3322. @@ -134,12 +152,12 @@
  3323. /* By not making the gentime core emulate periodic mode on top
  3324. * of oneshot, we get lower overhead and improved accuracy.
  3325. */
  3326. - clk_enable(tcd->clk);
  3327. + tc_clk_enable(d);
  3328. - /* slow clock, count up to RC, then irq and restart */
  3329. + /* count up to RC, then irq and restart */
  3330. __raw_writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  3331. regs + ATMEL_TC_REG(2, CMR));
  3332. - __raw_writel((32768 + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  3333. + __raw_writel((tcd->freq + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  3334. /* Enable clock and interrupts on RC compare */
  3335. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  3336. @@ -166,9 +184,13 @@
  3337. .features = CLOCK_EVT_FEAT_PERIODIC |
  3338. CLOCK_EVT_FEAT_ONESHOT,
  3339. /* Should be lower than at91rm9200's system timer */
  3340. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  3341. .rating = 125,
  3342. +#else
  3343. + .rating = 200,
  3344. +#endif
  3345. .set_next_event = tc_next_event,
  3346. - .set_state_shutdown = tc_shutdown,
  3347. + .set_state_shutdown = tc_shutdown_clk_off,
  3348. .set_state_periodic = tc_set_periodic,
  3349. .set_state_oneshot = tc_set_oneshot,
  3350. },
  3351. @@ -188,8 +210,9 @@
  3352. return IRQ_NONE;
  3353. }
  3354. -static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
  3355. +static int __init setup_clkevents(struct atmel_tc *tc, int divisor_idx)
  3356. {
  3357. + unsigned divisor = atmel_tc_divisors[divisor_idx];
  3358. int ret;
  3359. struct clk *t2_clk = tc->clk[2];
  3360. int irq = tc->irq[2];
  3361. @@ -210,7 +233,11 @@
  3362. clkevt.regs = tc->regs;
  3363. clkevt.clk = t2_clk;
  3364. - timer_clock = clk32k_divisor_idx;
  3365. + timer_clock = divisor_idx;
  3366. + if (!divisor)
  3367. + clkevt.freq = 32768;
  3368. + else
  3369. + clkevt.freq = clk_get_rate(t2_clk) / divisor;
  3370. clkevt.clkevt.cpumask = cpumask_of(0);
  3371. @@ -221,7 +248,7 @@
  3372. return ret;
  3373. }
  3374. - clockevents_config_and_register(&clkevt.clkevt, 32768, 1, 0xffff);
  3375. + clockevents_config_and_register(&clkevt.clkevt, clkevt.freq, 1, 0xffff);
  3376. return ret;
  3377. }
  3378. @@ -358,7 +385,11 @@
  3379. goto err_disable_t1;
  3380. /* channel 2: periodic and oneshot timer support */
  3381. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  3382. ret = setup_clkevents(tc, clk32k_divisor_idx);
  3383. +#else
  3384. + ret = setup_clkevents(tc, best_divisor_idx);
  3385. +#endif
  3386. if (ret)
  3387. goto err_unregister_clksrc;
  3388. diff -Nur linux-4.9.6.orig/drivers/clocksource/timer-atmel-pit.c linux-4.9.6/drivers/clocksource/timer-atmel-pit.c
  3389. --- linux-4.9.6.orig/drivers/clocksource/timer-atmel-pit.c 2017-01-26 08:25:24.000000000 +0100
  3390. +++ linux-4.9.6/drivers/clocksource/timer-atmel-pit.c 2017-01-28 13:59:09.907655265 +0100
  3391. @@ -46,6 +46,7 @@
  3392. u32 cycle;
  3393. u32 cnt;
  3394. unsigned int irq;
  3395. + bool irq_requested;
  3396. struct clk *mck;
  3397. };
  3398. @@ -96,15 +97,29 @@
  3399. /* disable irq, leaving the clocksource active */
  3400. pit_write(data->base, AT91_PIT_MR, (data->cycle - 1) | AT91_PIT_PITEN);
  3401. + if (data->irq_requested) {
  3402. + free_irq(data->irq, data);
  3403. + data->irq_requested = false;
  3404. + }
  3405. return 0;
  3406. }
  3407. +static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id);
  3408. /*
  3409. * Clockevent device: interrupts every 1/HZ (== pit_cycles * MCK/16)
  3410. */
  3411. static int pit_clkevt_set_periodic(struct clock_event_device *dev)
  3412. {
  3413. struct pit_data *data = clkevt_to_pit_data(dev);
  3414. + int ret;
  3415. +
  3416. + ret = request_irq(data->irq, at91sam926x_pit_interrupt,
  3417. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  3418. + "at91_tick", data);
  3419. + if (ret)
  3420. + panic(pr_fmt("Unable to setup IRQ\n"));
  3421. +
  3422. + data->irq_requested = true;
  3423. /* update clocksource counter */
  3424. data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
  3425. @@ -230,15 +245,6 @@
  3426. return ret;
  3427. }
  3428. - /* Set up irq handler */
  3429. - ret = request_irq(data->irq, at91sam926x_pit_interrupt,
  3430. - IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  3431. - "at91_tick", data);
  3432. - if (ret) {
  3433. - pr_err("Unable to setup IRQ\n");
  3434. - return ret;
  3435. - }
  3436. -
  3437. /* Set up and register clockevents */
  3438. data->clkevt.name = "pit";
  3439. data->clkevt.features = CLOCK_EVT_FEAT_PERIODIC;
  3440. diff -Nur linux-4.9.6.orig/drivers/clocksource/timer-atmel-st.c linux-4.9.6/drivers/clocksource/timer-atmel-st.c
  3441. --- linux-4.9.6.orig/drivers/clocksource/timer-atmel-st.c 2017-01-26 08:25:24.000000000 +0100
  3442. +++ linux-4.9.6/drivers/clocksource/timer-atmel-st.c 2017-01-28 13:59:09.907655265 +0100
  3443. @@ -115,18 +115,29 @@
  3444. last_crtr = read_CRTR();
  3445. }
  3446. +static int atmel_st_irq;
  3447. +
  3448. static int clkevt32k_shutdown(struct clock_event_device *evt)
  3449. {
  3450. clkdev32k_disable_and_flush_irq();
  3451. irqmask = 0;
  3452. regmap_write(regmap_st, AT91_ST_IER, irqmask);
  3453. + free_irq(atmel_st_irq, regmap_st);
  3454. return 0;
  3455. }
  3456. static int clkevt32k_set_oneshot(struct clock_event_device *dev)
  3457. {
  3458. + int ret;
  3459. +
  3460. clkdev32k_disable_and_flush_irq();
  3461. + ret = request_irq(atmel_st_irq, at91rm9200_timer_interrupt,
  3462. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  3463. + "at91_tick", regmap_st);
  3464. + if (ret)
  3465. + panic(pr_fmt("Unable to setup IRQ\n"));
  3466. +
  3467. /*
  3468. * ALM for oneshot irqs, set by next_event()
  3469. * before 32 seconds have passed.
  3470. @@ -139,8 +150,16 @@
  3471. static int clkevt32k_set_periodic(struct clock_event_device *dev)
  3472. {
  3473. + int ret;
  3474. +
  3475. clkdev32k_disable_and_flush_irq();
  3476. + ret = request_irq(atmel_st_irq, at91rm9200_timer_interrupt,
  3477. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  3478. + "at91_tick", regmap_st);
  3479. + if (ret)
  3480. + panic(pr_fmt("Unable to setup IRQ\n"));
  3481. +
  3482. /* PIT for periodic irqs; fixed rate of 1/HZ */
  3483. irqmask = AT91_ST_PITS;
  3484. regmap_write(regmap_st, AT91_ST_PIMR, timer_latch);
  3485. @@ -198,7 +217,7 @@
  3486. {
  3487. struct clk *sclk;
  3488. unsigned int sclk_rate, val;
  3489. - int irq, ret;
  3490. + int ret;
  3491. regmap_st = syscon_node_to_regmap(node);
  3492. if (IS_ERR(regmap_st)) {
  3493. @@ -212,21 +231,12 @@
  3494. regmap_read(regmap_st, AT91_ST_SR, &val);
  3495. /* Get the interrupts property */
  3496. - irq = irq_of_parse_and_map(node, 0);
  3497. - if (!irq) {
  3498. + atmel_st_irq = irq_of_parse_and_map(node, 0);
  3499. + if (!atmel_st_irq) {
  3500. pr_err("Unable to get IRQ from DT\n");
  3501. return -EINVAL;
  3502. }
  3503. - /* Make IRQs happen for the system timer */
  3504. - ret = request_irq(irq, at91rm9200_timer_interrupt,
  3505. - IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  3506. - "at91_tick", regmap_st);
  3507. - if (ret) {
  3508. - pr_err("Unable to setup IRQ\n");
  3509. - return ret;
  3510. - }
  3511. -
  3512. sclk = of_clk_get(node, 0);
  3513. if (IS_ERR(sclk)) {
  3514. pr_err("Unable to get slow clock\n");
  3515. diff -Nur linux-4.9.6.orig/drivers/connector/cn_proc.c linux-4.9.6/drivers/connector/cn_proc.c
  3516. --- linux-4.9.6.orig/drivers/connector/cn_proc.c 2017-01-26 08:25:24.000000000 +0100
  3517. +++ linux-4.9.6/drivers/connector/cn_proc.c 2017-01-28 13:59:09.907655265 +0100
  3518. @@ -32,6 +32,7 @@
  3519. #include <linux/pid_namespace.h>
  3520. #include <linux/cn_proc.h>
  3521. +#include <linux/locallock.h>
  3522. /*
  3523. * Size of a cn_msg followed by a proc_event structure. Since the
  3524. @@ -54,10 +55,11 @@
  3525. /* proc_event_counts is used as the sequence number of the netlink message */
  3526. static DEFINE_PER_CPU(__u32, proc_event_counts) = { 0 };
  3527. +static DEFINE_LOCAL_IRQ_LOCK(send_msg_lock);
  3528. static inline void send_msg(struct cn_msg *msg)
  3529. {
  3530. - preempt_disable();
  3531. + local_lock(send_msg_lock);
  3532. msg->seq = __this_cpu_inc_return(proc_event_counts) - 1;
  3533. ((struct proc_event *)msg->data)->cpu = smp_processor_id();
  3534. @@ -70,7 +72,7 @@
  3535. */
  3536. cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
  3537. - preempt_enable();
  3538. + local_unlock(send_msg_lock);
  3539. }
  3540. void proc_fork_connector(struct task_struct *task)
  3541. diff -Nur linux-4.9.6.orig/drivers/cpufreq/Kconfig.x86 linux-4.9.6/drivers/cpufreq/Kconfig.x86
  3542. --- linux-4.9.6.orig/drivers/cpufreq/Kconfig.x86 2017-01-26 08:25:24.000000000 +0100
  3543. +++ linux-4.9.6/drivers/cpufreq/Kconfig.x86 2017-01-28 13:59:09.907655265 +0100
  3544. @@ -124,7 +124,7 @@
  3545. config X86_POWERNOW_K8
  3546. tristate "AMD Opteron/Athlon64 PowerNow!"
  3547. - depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ
  3548. + depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ && !PREEMPT_RT_BASE
  3549. help
  3550. This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors.
  3551. Support for K10 and newer processors is now in acpi-cpufreq.
  3552. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-4.9.6/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  3553. --- linux-4.9.6.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2017-01-26 08:25:24.000000000 +0100
  3554. +++ linux-4.9.6/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2017-01-28 13:59:09.907655265 +0100
  3555. @@ -1537,7 +1537,9 @@
  3556. if (ret)
  3557. return ret;
  3558. +#ifndef CONFIG_PREEMPT_RT_BASE
  3559. trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags);
  3560. +#endif
  3561. i915_gem_execbuffer_move_to_active(vmas, params->request);
  3562. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c linux-4.9.6/drivers/gpu/drm/i915/i915_gem_shrinker.c
  3563. --- linux-4.9.6.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c 2017-01-26 08:25:24.000000000 +0100
  3564. +++ linux-4.9.6/drivers/gpu/drm/i915/i915_gem_shrinker.c 2017-01-28 13:59:09.907655265 +0100
  3565. @@ -40,7 +40,7 @@
  3566. if (!mutex_is_locked(mutex))
  3567. return false;
  3568. -#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_MUTEX_SPIN_ON_OWNER)
  3569. +#if (defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_MUTEX_SPIN_ON_OWNER)) && !defined(CONFIG_PREEMPT_RT_BASE)
  3570. return mutex->owner == task;
  3571. #else
  3572. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  3573. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/i915/i915_irq.c linux-4.9.6/drivers/gpu/drm/i915/i915_irq.c
  3574. --- linux-4.9.6.orig/drivers/gpu/drm/i915/i915_irq.c 2017-01-26 08:25:24.000000000 +0100
  3575. +++ linux-4.9.6/drivers/gpu/drm/i915/i915_irq.c 2017-01-28 13:59:09.907655265 +0100
  3576. @@ -812,6 +812,7 @@
  3577. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  3578. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  3579. + preempt_disable_rt();
  3580. /* Get optional system timestamp before query. */
  3581. if (stime)
  3582. @@ -863,6 +864,7 @@
  3583. *etime = ktime_get();
  3584. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  3585. + preempt_enable_rt();
  3586. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  3587. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/i915/intel_display.c linux-4.9.6/drivers/gpu/drm/i915/intel_display.c
  3588. --- linux-4.9.6.orig/drivers/gpu/drm/i915/intel_display.c 2017-01-26 08:25:24.000000000 +0100
  3589. +++ linux-4.9.6/drivers/gpu/drm/i915/intel_display.c 2017-01-28 13:59:09.911655420 +0100
  3590. @@ -12131,7 +12131,7 @@
  3591. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3592. struct intel_flip_work *work;
  3593. - WARN_ON(!in_interrupt());
  3594. + WARN_ON_NONRT(!in_interrupt());
  3595. if (crtc == NULL)
  3596. return;
  3597. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/i915/intel_sprite.c linux-4.9.6/drivers/gpu/drm/i915/intel_sprite.c
  3598. --- linux-4.9.6.orig/drivers/gpu/drm/i915/intel_sprite.c 2017-01-26 08:25:24.000000000 +0100
  3599. +++ linux-4.9.6/drivers/gpu/drm/i915/intel_sprite.c 2017-01-28 13:59:09.911655420 +0100
  3600. @@ -35,6 +35,7 @@
  3601. #include <drm/drm_rect.h>
  3602. #include <drm/drm_atomic.h>
  3603. #include <drm/drm_plane_helper.h>
  3604. +#include <linux/locallock.h>
  3605. #include "intel_drv.h"
  3606. #include "intel_frontbuffer.h"
  3607. #include <drm/i915_drm.h>
  3608. @@ -65,6 +66,8 @@
  3609. 1000 * adjusted_mode->crtc_htotal);
  3610. }
  3611. +static DEFINE_LOCAL_IRQ_LOCK(pipe_update_lock);
  3612. +
  3613. /**
  3614. * intel_pipe_update_start() - start update of a set of display registers
  3615. * @crtc: the crtc of which the registers are going to be updated
  3616. @@ -95,7 +98,7 @@
  3617. min = vblank_start - intel_usecs_to_scanlines(adjusted_mode, 100);
  3618. max = vblank_start - 1;
  3619. - local_irq_disable();
  3620. + local_lock_irq(pipe_update_lock);
  3621. if (min <= 0 || max <= 0)
  3622. return;
  3623. @@ -125,11 +128,11 @@
  3624. break;
  3625. }
  3626. - local_irq_enable();
  3627. + local_unlock_irq(pipe_update_lock);
  3628. timeout = schedule_timeout(timeout);
  3629. - local_irq_disable();
  3630. + local_lock_irq(pipe_update_lock);
  3631. }
  3632. finish_wait(wq, &wait);
  3633. @@ -181,7 +184,7 @@
  3634. crtc->base.state->event = NULL;
  3635. }
  3636. - local_irq_enable();
  3637. + local_unlock_irq(pipe_update_lock);
  3638. if (crtc->debug.start_vbl_count &&
  3639. crtc->debug.start_vbl_count != end_vbl_count) {
  3640. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/msm/msm_gem_shrinker.c linux-4.9.6/drivers/gpu/drm/msm/msm_gem_shrinker.c
  3641. --- linux-4.9.6.orig/drivers/gpu/drm/msm/msm_gem_shrinker.c 2017-01-26 08:25:24.000000000 +0100
  3642. +++ linux-4.9.6/drivers/gpu/drm/msm/msm_gem_shrinker.c 2017-01-28 13:59:09.911655420 +0100
  3643. @@ -23,7 +23,7 @@
  3644. if (!mutex_is_locked(mutex))
  3645. return false;
  3646. -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
  3647. +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)) && !defined(CONFIG_PREEMPT_RT_BASE)
  3648. return mutex->owner == task;
  3649. #else
  3650. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  3651. diff -Nur linux-4.9.6.orig/drivers/gpu/drm/radeon/radeon_display.c linux-4.9.6/drivers/gpu/drm/radeon/radeon_display.c
  3652. --- linux-4.9.6.orig/drivers/gpu/drm/radeon/radeon_display.c 2017-01-26 08:25:24.000000000 +0100
  3653. +++ linux-4.9.6/drivers/gpu/drm/radeon/radeon_display.c 2017-01-28 13:59:09.911655420 +0100
  3654. @@ -1845,6 +1845,7 @@
  3655. struct radeon_device *rdev = dev->dev_private;
  3656. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  3657. + preempt_disable_rt();
  3658. /* Get optional system timestamp before query. */
  3659. if (stime)
  3660. @@ -1937,6 +1938,7 @@
  3661. *etime = ktime_get();
  3662. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  3663. + preempt_enable_rt();
  3664. /* Decode into vertical and horizontal scanout position. */
  3665. *vpos = position & 0x1fff;
  3666. diff -Nur linux-4.9.6.orig/drivers/hv/vmbus_drv.c linux-4.9.6/drivers/hv/vmbus_drv.c
  3667. --- linux-4.9.6.orig/drivers/hv/vmbus_drv.c 2017-01-26 08:25:24.000000000 +0100
  3668. +++ linux-4.9.6/drivers/hv/vmbus_drv.c 2017-01-28 13:59:09.911655420 +0100
  3669. @@ -761,6 +761,8 @@
  3670. void *page_addr;
  3671. struct hv_message *msg;
  3672. union hv_synic_event_flags *event;
  3673. + struct pt_regs *regs = get_irq_regs();
  3674. + u64 ip = regs ? instruction_pointer(regs) : 0;
  3675. bool handled = false;
  3676. page_addr = hv_context.synic_event_page[cpu];
  3677. @@ -808,7 +810,7 @@
  3678. tasklet_schedule(hv_context.msg_dpc[cpu]);
  3679. }
  3680. - add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
  3681. + add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0, ip);
  3682. }
  3683. diff -Nur linux-4.9.6.orig/drivers/ide/alim15x3.c linux-4.9.6/drivers/ide/alim15x3.c
  3684. --- linux-4.9.6.orig/drivers/ide/alim15x3.c 2017-01-26 08:25:24.000000000 +0100
  3685. +++ linux-4.9.6/drivers/ide/alim15x3.c 2017-01-28 13:59:09.911655420 +0100
  3686. @@ -234,7 +234,7 @@
  3687. isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  3688. - local_irq_save(flags);
  3689. + local_irq_save_nort(flags);
  3690. if (m5229_revision < 0xC2) {
  3691. /*
  3692. @@ -325,7 +325,7 @@
  3693. }
  3694. pci_dev_put(north);
  3695. pci_dev_put(isa_dev);
  3696. - local_irq_restore(flags);
  3697. + local_irq_restore_nort(flags);
  3698. return 0;
  3699. }
  3700. diff -Nur linux-4.9.6.orig/drivers/ide/hpt366.c linux-4.9.6/drivers/ide/hpt366.c
  3701. --- linux-4.9.6.orig/drivers/ide/hpt366.c 2017-01-26 08:25:24.000000000 +0100
  3702. +++ linux-4.9.6/drivers/ide/hpt366.c 2017-01-28 13:59:09.911655420 +0100
  3703. @@ -1236,7 +1236,7 @@
  3704. dma_old = inb(base + 2);
  3705. - local_irq_save(flags);
  3706. + local_irq_save_nort(flags);
  3707. dma_new = dma_old;
  3708. pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
  3709. @@ -1247,7 +1247,7 @@
  3710. if (dma_new != dma_old)
  3711. outb(dma_new, base + 2);
  3712. - local_irq_restore(flags);
  3713. + local_irq_restore_nort(flags);
  3714. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  3715. hwif->name, base, base + 7);
  3716. diff -Nur linux-4.9.6.orig/drivers/ide/ide-io.c linux-4.9.6/drivers/ide/ide-io.c
  3717. --- linux-4.9.6.orig/drivers/ide/ide-io.c 2017-01-26 08:25:24.000000000 +0100
  3718. +++ linux-4.9.6/drivers/ide/ide-io.c 2017-01-28 13:59:09.911655420 +0100
  3719. @@ -659,7 +659,7 @@
  3720. /* disable_irq_nosync ?? */
  3721. disable_irq(hwif->irq);
  3722. /* local CPU only, as if we were handling an interrupt */
  3723. - local_irq_disable();
  3724. + local_irq_disable_nort();
  3725. if (hwif->polling) {
  3726. startstop = handler(drive);
  3727. } else if (drive_is_ready(drive)) {
  3728. diff -Nur linux-4.9.6.orig/drivers/ide/ide-iops.c linux-4.9.6/drivers/ide/ide-iops.c
  3729. --- linux-4.9.6.orig/drivers/ide/ide-iops.c 2017-01-26 08:25:24.000000000 +0100
  3730. +++ linux-4.9.6/drivers/ide/ide-iops.c 2017-01-28 13:59:09.911655420 +0100
  3731. @@ -129,12 +129,12 @@
  3732. if ((stat & ATA_BUSY) == 0)
  3733. break;
  3734. - local_irq_restore(flags);
  3735. + local_irq_restore_nort(flags);
  3736. *rstat = stat;
  3737. return -EBUSY;
  3738. }
  3739. }
  3740. - local_irq_restore(flags);
  3741. + local_irq_restore_nort(flags);
  3742. }
  3743. /*
  3744. * Allow status to settle, then read it again.
  3745. diff -Nur linux-4.9.6.orig/drivers/ide/ide-io-std.c linux-4.9.6/drivers/ide/ide-io-std.c
  3746. --- linux-4.9.6.orig/drivers/ide/ide-io-std.c 2017-01-26 08:25:24.000000000 +0100
  3747. +++ linux-4.9.6/drivers/ide/ide-io-std.c 2017-01-28 13:59:09.911655420 +0100
  3748. @@ -175,7 +175,7 @@
  3749. unsigned long uninitialized_var(flags);
  3750. if ((io_32bit & 2) && !mmio) {
  3751. - local_irq_save(flags);
  3752. + local_irq_save_nort(flags);
  3753. ata_vlb_sync(io_ports->nsect_addr);
  3754. }
  3755. @@ -186,7 +186,7 @@
  3756. insl(data_addr, buf, words);
  3757. if ((io_32bit & 2) && !mmio)
  3758. - local_irq_restore(flags);
  3759. + local_irq_restore_nort(flags);
  3760. if (((len + 1) & 3) < 2)
  3761. return;
  3762. @@ -219,7 +219,7 @@
  3763. unsigned long uninitialized_var(flags);
  3764. if ((io_32bit & 2) && !mmio) {
  3765. - local_irq_save(flags);
  3766. + local_irq_save_nort(flags);
  3767. ata_vlb_sync(io_ports->nsect_addr);
  3768. }
  3769. @@ -230,7 +230,7 @@
  3770. outsl(data_addr, buf, words);
  3771. if ((io_32bit & 2) && !mmio)
  3772. - local_irq_restore(flags);
  3773. + local_irq_restore_nort(flags);
  3774. if (((len + 1) & 3) < 2)
  3775. return;
  3776. diff -Nur linux-4.9.6.orig/drivers/ide/ide-probe.c linux-4.9.6/drivers/ide/ide-probe.c
  3777. --- linux-4.9.6.orig/drivers/ide/ide-probe.c 2017-01-26 08:25:24.000000000 +0100
  3778. +++ linux-4.9.6/drivers/ide/ide-probe.c 2017-01-28 13:59:09.911655420 +0100
  3779. @@ -196,10 +196,10 @@
  3780. int bswap = 1;
  3781. /* local CPU only; some systems need this */
  3782. - local_irq_save(flags);
  3783. + local_irq_save_nort(flags);
  3784. /* read 512 bytes of id info */
  3785. hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
  3786. - local_irq_restore(flags);
  3787. + local_irq_restore_nort(flags);
  3788. drive->dev_flags |= IDE_DFLAG_ID_READ;
  3789. #ifdef DEBUG
  3790. diff -Nur linux-4.9.6.orig/drivers/ide/ide-taskfile.c linux-4.9.6/drivers/ide/ide-taskfile.c
  3791. --- linux-4.9.6.orig/drivers/ide/ide-taskfile.c 2017-01-26 08:25:24.000000000 +0100
  3792. +++ linux-4.9.6/drivers/ide/ide-taskfile.c 2017-01-28 13:59:09.911655420 +0100
  3793. @@ -250,7 +250,7 @@
  3794. page_is_high = PageHighMem(page);
  3795. if (page_is_high)
  3796. - local_irq_save(flags);
  3797. + local_irq_save_nort(flags);
  3798. buf = kmap_atomic(page) + offset;
  3799. @@ -271,7 +271,7 @@
  3800. kunmap_atomic(buf);
  3801. if (page_is_high)
  3802. - local_irq_restore(flags);
  3803. + local_irq_restore_nort(flags);
  3804. len -= nr_bytes;
  3805. }
  3806. @@ -414,7 +414,7 @@
  3807. }
  3808. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  3809. - local_irq_disable();
  3810. + local_irq_disable_nort();
  3811. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  3812. diff -Nur linux-4.9.6.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c linux-4.9.6/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
  3813. --- linux-4.9.6.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2017-01-26 08:25:24.000000000 +0100
  3814. +++ linux-4.9.6/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2017-01-28 13:59:09.911655420 +0100
  3815. @@ -902,7 +902,7 @@
  3816. ipoib_dbg_mcast(priv, "restarting multicast task\n");
  3817. - local_irq_save(flags);
  3818. + local_irq_save_nort(flags);
  3819. netif_addr_lock(dev);
  3820. spin_lock(&priv->lock);
  3821. @@ -984,7 +984,7 @@
  3822. spin_unlock(&priv->lock);
  3823. netif_addr_unlock(dev);
  3824. - local_irq_restore(flags);
  3825. + local_irq_restore_nort(flags);
  3826. /*
  3827. * make sure the in-flight joins have finished before we attempt
  3828. diff -Nur linux-4.9.6.orig/drivers/input/gameport/gameport.c linux-4.9.6/drivers/input/gameport/gameport.c
  3829. --- linux-4.9.6.orig/drivers/input/gameport/gameport.c 2017-01-26 08:25:24.000000000 +0100
  3830. +++ linux-4.9.6/drivers/input/gameport/gameport.c 2017-01-28 13:59:09.915655573 +0100
  3831. @@ -91,13 +91,13 @@
  3832. tx = ~0;
  3833. for (i = 0; i < 50; i++) {
  3834. - local_irq_save(flags);
  3835. + local_irq_save_nort(flags);
  3836. t1 = ktime_get_ns();
  3837. for (t = 0; t < 50; t++)
  3838. gameport_read(gameport);
  3839. t2 = ktime_get_ns();
  3840. t3 = ktime_get_ns();
  3841. - local_irq_restore(flags);
  3842. + local_irq_restore_nort(flags);
  3843. udelay(i * 10);
  3844. t = (t2 - t1) - (t3 - t2);
  3845. if (t < tx)
  3846. @@ -124,12 +124,12 @@
  3847. tx = 1 << 30;
  3848. for(i = 0; i < 50; i++) {
  3849. - local_irq_save(flags);
  3850. + local_irq_save_nort(flags);
  3851. GET_TIME(t1);
  3852. for (t = 0; t < 50; t++) gameport_read(gameport);
  3853. GET_TIME(t2);
  3854. GET_TIME(t3);
  3855. - local_irq_restore(flags);
  3856. + local_irq_restore_nort(flags);
  3857. udelay(i * 10);
  3858. if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
  3859. }
  3860. @@ -148,11 +148,11 @@
  3861. tx = 1 << 30;
  3862. for(i = 0; i < 50; i++) {
  3863. - local_irq_save(flags);
  3864. + local_irq_save_nort(flags);
  3865. t1 = rdtsc();
  3866. for (t = 0; t < 50; t++) gameport_read(gameport);
  3867. t2 = rdtsc();
  3868. - local_irq_restore(flags);
  3869. + local_irq_restore_nort(flags);
  3870. udelay(i * 10);
  3871. if (t2 - t1 < tx) tx = t2 - t1;
  3872. }
  3873. diff -Nur linux-4.9.6.orig/drivers/iommu/amd_iommu.c linux-4.9.6/drivers/iommu/amd_iommu.c
  3874. --- linux-4.9.6.orig/drivers/iommu/amd_iommu.c 2017-01-26 08:25:24.000000000 +0100
  3875. +++ linux-4.9.6/drivers/iommu/amd_iommu.c 2017-01-28 13:59:09.915655573 +0100
  3876. @@ -1923,10 +1923,10 @@
  3877. int ret;
  3878. /*
  3879. - * Must be called with IRQs disabled. Warn here to detect early
  3880. - * when its not.
  3881. + * Must be called with IRQs disabled on a non RT kernel. Warn here to
  3882. + * detect early when its not.
  3883. */
  3884. - WARN_ON(!irqs_disabled());
  3885. + WARN_ON_NONRT(!irqs_disabled());
  3886. /* lock domain */
  3887. spin_lock(&domain->lock);
  3888. @@ -2094,10 +2094,10 @@
  3889. struct protection_domain *domain;
  3890. /*
  3891. - * Must be called with IRQs disabled. Warn here to detect early
  3892. - * when its not.
  3893. + * Must be called with IRQs disabled on a non RT kernel. Warn here to
  3894. + * detect early when its not.
  3895. */
  3896. - WARN_ON(!irqs_disabled());
  3897. + WARN_ON_NONRT(!irqs_disabled());
  3898. if (WARN_ON(!dev_data->domain))
  3899. return;
  3900. diff -Nur linux-4.9.6.orig/drivers/iommu/intel-iommu.c linux-4.9.6/drivers/iommu/intel-iommu.c
  3901. --- linux-4.9.6.orig/drivers/iommu/intel-iommu.c 2017-01-26 08:25:24.000000000 +0100
  3902. +++ linux-4.9.6/drivers/iommu/intel-iommu.c 2017-01-28 13:59:09.915655573 +0100
  3903. @@ -479,7 +479,7 @@
  3904. struct deferred_flush_table *tables;
  3905. };
  3906. -DEFINE_PER_CPU(struct deferred_flush_data, deferred_flush);
  3907. +static DEFINE_PER_CPU(struct deferred_flush_data, deferred_flush);
  3908. /* bitmap for indexing intel_iommus */
  3909. static int g_num_of_iommus;
  3910. @@ -3715,10 +3715,8 @@
  3911. struct intel_iommu *iommu;
  3912. struct deferred_flush_entry *entry;
  3913. struct deferred_flush_data *flush_data;
  3914. - unsigned int cpuid;
  3915. - cpuid = get_cpu();
  3916. - flush_data = per_cpu_ptr(&deferred_flush, cpuid);
  3917. + flush_data = raw_cpu_ptr(&deferred_flush);
  3918. /* Flush all CPUs' entries to avoid deferring too much. If
  3919. * this becomes a bottleneck, can just flush us, and rely on
  3920. @@ -3751,8 +3749,6 @@
  3921. }
  3922. flush_data->size++;
  3923. spin_unlock_irqrestore(&flush_data->lock, flags);
  3924. -
  3925. - put_cpu();
  3926. }
  3927. static void intel_unmap(struct device *dev, dma_addr_t dev_addr, size_t size)
  3928. diff -Nur linux-4.9.6.orig/drivers/iommu/iova.c linux-4.9.6/drivers/iommu/iova.c
  3929. --- linux-4.9.6.orig/drivers/iommu/iova.c 2017-01-26 08:25:24.000000000 +0100
  3930. +++ linux-4.9.6/drivers/iommu/iova.c 2017-01-28 13:59:09.915655573 +0100
  3931. @@ -22,6 +22,7 @@
  3932. #include <linux/slab.h>
  3933. #include <linux/smp.h>
  3934. #include <linux/bitops.h>
  3935. +#include <linux/cpu.h>
  3936. static bool iova_rcache_insert(struct iova_domain *iovad,
  3937. unsigned long pfn,
  3938. @@ -420,10 +421,8 @@
  3939. /* Try replenishing IOVAs by flushing rcache. */
  3940. flushed_rcache = true;
  3941. - preempt_disable();
  3942. for_each_online_cpu(cpu)
  3943. free_cpu_cached_iovas(cpu, iovad);
  3944. - preempt_enable();
  3945. goto retry;
  3946. }
  3947. @@ -751,7 +750,7 @@
  3948. bool can_insert = false;
  3949. unsigned long flags;
  3950. - cpu_rcache = get_cpu_ptr(rcache->cpu_rcaches);
  3951. + cpu_rcache = raw_cpu_ptr(rcache->cpu_rcaches);
  3952. spin_lock_irqsave(&cpu_rcache->lock, flags);
  3953. if (!iova_magazine_full(cpu_rcache->loaded)) {
  3954. @@ -781,7 +780,6 @@
  3955. iova_magazine_push(cpu_rcache->loaded, iova_pfn);
  3956. spin_unlock_irqrestore(&cpu_rcache->lock, flags);
  3957. - put_cpu_ptr(rcache->cpu_rcaches);
  3958. if (mag_to_free) {
  3959. iova_magazine_free_pfns(mag_to_free, iovad);
  3960. @@ -815,7 +813,7 @@
  3961. bool has_pfn = false;
  3962. unsigned long flags;
  3963. - cpu_rcache = get_cpu_ptr(rcache->cpu_rcaches);
  3964. + cpu_rcache = raw_cpu_ptr(rcache->cpu_rcaches);
  3965. spin_lock_irqsave(&cpu_rcache->lock, flags);
  3966. if (!iova_magazine_empty(cpu_rcache->loaded)) {
  3967. @@ -837,7 +835,6 @@
  3968. iova_pfn = iova_magazine_pop(cpu_rcache->loaded, limit_pfn);
  3969. spin_unlock_irqrestore(&cpu_rcache->lock, flags);
  3970. - put_cpu_ptr(rcache->cpu_rcaches);
  3971. return iova_pfn;
  3972. }
  3973. diff -Nur linux-4.9.6.orig/drivers/leds/trigger/Kconfig linux-4.9.6/drivers/leds/trigger/Kconfig
  3974. --- linux-4.9.6.orig/drivers/leds/trigger/Kconfig 2017-01-26 08:25:24.000000000 +0100
  3975. +++ linux-4.9.6/drivers/leds/trigger/Kconfig 2017-01-28 13:59:09.915655573 +0100
  3976. @@ -69,7 +69,7 @@
  3977. config LEDS_TRIGGER_CPU
  3978. bool "LED CPU Trigger"
  3979. - depends on LEDS_TRIGGERS
  3980. + depends on LEDS_TRIGGERS && !PREEMPT_RT_BASE
  3981. help
  3982. This allows LEDs to be controlled by active CPUs. This shows
  3983. the active CPUs across an array of LEDs so you can see which
  3984. diff -Nur linux-4.9.6.orig/drivers/md/bcache/Kconfig linux-4.9.6/drivers/md/bcache/Kconfig
  3985. --- linux-4.9.6.orig/drivers/md/bcache/Kconfig 2017-01-26 08:25:24.000000000 +0100
  3986. +++ linux-4.9.6/drivers/md/bcache/Kconfig 2017-01-28 13:59:09.915655573 +0100
  3987. @@ -1,6 +1,7 @@
  3988. config BCACHE
  3989. tristate "Block device as cache"
  3990. + depends on !PREEMPT_RT_FULL
  3991. ---help---
  3992. Allows a block device to be used as cache for other devices; uses
  3993. a btree for indexing and the layout is optimized for SSDs.
  3994. diff -Nur linux-4.9.6.orig/drivers/md/dm-rq.c linux-4.9.6/drivers/md/dm-rq.c
  3995. --- linux-4.9.6.orig/drivers/md/dm-rq.c 2017-01-26 08:25:24.000000000 +0100
  3996. +++ linux-4.9.6/drivers/md/dm-rq.c 2017-01-28 13:59:09.915655573 +0100
  3997. @@ -838,7 +838,7 @@
  3998. /* Establish tio->ti before queuing work (map_tio_request) */
  3999. tio->ti = ti;
  4000. kthread_queue_work(&md->kworker, &tio->work);
  4001. - BUG_ON(!irqs_disabled());
  4002. + BUG_ON_NONRT(!irqs_disabled());
  4003. }
  4004. }
  4005. diff -Nur linux-4.9.6.orig/drivers/md/raid5.c linux-4.9.6/drivers/md/raid5.c
  4006. --- linux-4.9.6.orig/drivers/md/raid5.c 2017-01-26 08:25:24.000000000 +0100
  4007. +++ linux-4.9.6/drivers/md/raid5.c 2017-01-28 13:59:09.915655573 +0100
  4008. @@ -1928,8 +1928,9 @@
  4009. struct raid5_percpu *percpu;
  4010. unsigned long cpu;
  4011. - cpu = get_cpu();
  4012. + cpu = get_cpu_light();
  4013. percpu = per_cpu_ptr(conf->percpu, cpu);
  4014. + spin_lock(&percpu->lock);
  4015. if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
  4016. ops_run_biofill(sh);
  4017. overlap_clear++;
  4018. @@ -1985,7 +1986,8 @@
  4019. if (test_and_clear_bit(R5_Overlap, &dev->flags))
  4020. wake_up(&sh->raid_conf->wait_for_overlap);
  4021. }
  4022. - put_cpu();
  4023. + spin_unlock(&percpu->lock);
  4024. + put_cpu_light();
  4025. }
  4026. static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
  4027. @@ -6391,6 +6393,7 @@
  4028. __func__, cpu);
  4029. return -ENOMEM;
  4030. }
  4031. + spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
  4032. return 0;
  4033. }
  4034. @@ -6401,7 +6404,6 @@
  4035. conf->percpu = alloc_percpu(struct raid5_percpu);
  4036. if (!conf->percpu)
  4037. return -ENOMEM;
  4038. -
  4039. err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node);
  4040. if (!err) {
  4041. conf->scribble_disks = max(conf->raid_disks,
  4042. diff -Nur linux-4.9.6.orig/drivers/md/raid5.h linux-4.9.6/drivers/md/raid5.h
  4043. --- linux-4.9.6.orig/drivers/md/raid5.h 2017-01-26 08:25:24.000000000 +0100
  4044. +++ linux-4.9.6/drivers/md/raid5.h 2017-01-28 13:59:09.915655573 +0100
  4045. @@ -504,6 +504,7 @@
  4046. int recovery_disabled;
  4047. /* per cpu variables */
  4048. struct raid5_percpu {
  4049. + spinlock_t lock; /* Protection for -RT */
  4050. struct page *spare_page; /* Used when checking P/Q in raid6 */
  4051. struct flex_array *scribble; /* space for constructing buffer
  4052. * lists and performing address
  4053. diff -Nur linux-4.9.6.orig/drivers/misc/Kconfig linux-4.9.6/drivers/misc/Kconfig
  4054. --- linux-4.9.6.orig/drivers/misc/Kconfig 2017-01-26 08:25:24.000000000 +0100
  4055. +++ linux-4.9.6/drivers/misc/Kconfig 2017-01-28 13:59:09.915655573 +0100
  4056. @@ -54,6 +54,7 @@
  4057. config ATMEL_TCLIB
  4058. bool "Atmel AT32/AT91 Timer/Counter Library"
  4059. depends on (AVR32 || ARCH_AT91)
  4060. + default y if PREEMPT_RT_FULL
  4061. help
  4062. Select this if you want a library to allocate the Timer/Counter
  4063. blocks found on many Atmel processors. This facilitates using
  4064. @@ -69,8 +70,7 @@
  4065. are combined to make a single 32-bit timer.
  4066. When GENERIC_CLOCKEVENTS is defined, the third timer channel
  4067. - may be used as a clock event device supporting oneshot mode
  4068. - (delays of up to two seconds) based on the 32 KiHz clock.
  4069. + may be used as a clock event device supporting oneshot mode.
  4070. config ATMEL_TCB_CLKSRC_BLOCK
  4071. int
  4072. @@ -84,6 +84,15 @@
  4073. TC can be used for other purposes, such as PWM generation and
  4074. interval timing.
  4075. +config ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  4076. + bool "TC Block use 32 KiHz clock"
  4077. + depends on ATMEL_TCB_CLKSRC
  4078. + default y if !PREEMPT_RT_FULL
  4079. + help
  4080. + Select this to use 32 KiHz base clock rate as TC block clock
  4081. + source for clock events.
  4082. +
  4083. +
  4084. config DUMMY_IRQ
  4085. tristate "Dummy IRQ handler"
  4086. default n
  4087. diff -Nur linux-4.9.6.orig/drivers/mmc/host/mmci.c linux-4.9.6/drivers/mmc/host/mmci.c
  4088. --- linux-4.9.6.orig/drivers/mmc/host/mmci.c 2017-01-26 08:25:24.000000000 +0100
  4089. +++ linux-4.9.6/drivers/mmc/host/mmci.c 2017-01-28 13:59:09.915655573 +0100
  4090. @@ -1147,15 +1147,12 @@
  4091. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  4092. struct variant_data *variant = host->variant;
  4093. void __iomem *base = host->base;
  4094. - unsigned long flags;
  4095. u32 status;
  4096. status = readl(base + MMCISTATUS);
  4097. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  4098. - local_irq_save(flags);
  4099. -
  4100. do {
  4101. unsigned int remain, len;
  4102. char *buffer;
  4103. @@ -1195,8 +1192,6 @@
  4104. sg_miter_stop(sg_miter);
  4105. - local_irq_restore(flags);
  4106. -
  4107. /*
  4108. * If we have less than the fifo 'half-full' threshold to transfer,
  4109. * trigger a PIO interrupt as soon as any data is available.
  4110. diff -Nur linux-4.9.6.orig/drivers/net/ethernet/3com/3c59x.c linux-4.9.6/drivers/net/ethernet/3com/3c59x.c
  4111. --- linux-4.9.6.orig/drivers/net/ethernet/3com/3c59x.c 2017-01-26 08:25:24.000000000 +0100
  4112. +++ linux-4.9.6/drivers/net/ethernet/3com/3c59x.c 2017-01-28 13:59:09.919655726 +0100
  4113. @@ -842,9 +842,9 @@
  4114. {
  4115. struct vortex_private *vp = netdev_priv(dev);
  4116. unsigned long flags;
  4117. - local_irq_save(flags);
  4118. + local_irq_save_nort(flags);
  4119. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
  4120. - local_irq_restore(flags);
  4121. + local_irq_restore_nort(flags);
  4122. }
  4123. #endif
  4124. @@ -1910,12 +1910,12 @@
  4125. * Block interrupts because vortex_interrupt does a bare spin_lock()
  4126. */
  4127. unsigned long flags;
  4128. - local_irq_save(flags);
  4129. + local_irq_save_nort(flags);
  4130. if (vp->full_bus_master_tx)
  4131. boomerang_interrupt(dev->irq, dev);
  4132. else
  4133. vortex_interrupt(dev->irq, dev);
  4134. - local_irq_restore(flags);
  4135. + local_irq_restore_nort(flags);
  4136. }
  4137. }
  4138. diff -Nur linux-4.9.6.orig/drivers/net/ethernet/realtek/8139too.c linux-4.9.6/drivers/net/ethernet/realtek/8139too.c
  4139. --- linux-4.9.6.orig/drivers/net/ethernet/realtek/8139too.c 2017-01-26 08:25:24.000000000 +0100
  4140. +++ linux-4.9.6/drivers/net/ethernet/realtek/8139too.c 2017-01-28 13:59:09.919655726 +0100
  4141. @@ -2233,7 +2233,7 @@
  4142. struct rtl8139_private *tp = netdev_priv(dev);
  4143. const int irq = tp->pci_dev->irq;
  4144. - disable_irq(irq);
  4145. + disable_irq_nosync(irq);
  4146. rtl8139_interrupt(irq, dev);
  4147. enable_irq(irq);
  4148. }
  4149. diff -Nur linux-4.9.6.orig/drivers/net/wireless/intersil/orinoco/orinoco_usb.c linux-4.9.6/drivers/net/wireless/intersil/orinoco/orinoco_usb.c
  4150. --- linux-4.9.6.orig/drivers/net/wireless/intersil/orinoco/orinoco_usb.c 2017-01-26 08:25:24.000000000 +0100
  4151. +++ linux-4.9.6/drivers/net/wireless/intersil/orinoco/orinoco_usb.c 2017-01-28 13:59:09.919655726 +0100
  4152. @@ -697,7 +697,7 @@
  4153. while (!ctx->done.done && msecs--)
  4154. udelay(1000);
  4155. } else {
  4156. - wait_event_interruptible(ctx->done.wait,
  4157. + swait_event_interruptible(ctx->done.wait,
  4158. ctx->done.done);
  4159. }
  4160. break;
  4161. diff -Nur linux-4.9.6.orig/drivers/pci/access.c linux-4.9.6/drivers/pci/access.c
  4162. --- linux-4.9.6.orig/drivers/pci/access.c 2017-01-26 08:25:24.000000000 +0100
  4163. +++ linux-4.9.6/drivers/pci/access.c 2017-01-28 13:59:09.919655726 +0100
  4164. @@ -672,7 +672,7 @@
  4165. WARN_ON(!dev->block_cfg_access);
  4166. dev->block_cfg_access = 0;
  4167. - wake_up_all(&pci_cfg_wait);
  4168. + wake_up_all_locked(&pci_cfg_wait);
  4169. raw_spin_unlock_irqrestore(&pci_lock, flags);
  4170. }
  4171. EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
  4172. diff -Nur linux-4.9.6.orig/drivers/scsi/fcoe/fcoe.c linux-4.9.6/drivers/scsi/fcoe/fcoe.c
  4173. --- linux-4.9.6.orig/drivers/scsi/fcoe/fcoe.c 2017-01-26 08:25:24.000000000 +0100
  4174. +++ linux-4.9.6/drivers/scsi/fcoe/fcoe.c 2017-01-28 13:59:09.919655726 +0100
  4175. @@ -1455,11 +1455,11 @@
  4176. static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
  4177. {
  4178. struct fcoe_percpu_s *fps;
  4179. - int rc;
  4180. + int rc, cpu = get_cpu_light();
  4181. - fps = &get_cpu_var(fcoe_percpu);
  4182. + fps = &per_cpu(fcoe_percpu, cpu);
  4183. rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
  4184. - put_cpu_var(fcoe_percpu);
  4185. + put_cpu_light();
  4186. return rc;
  4187. }
  4188. @@ -1646,11 +1646,11 @@
  4189. return 0;
  4190. }
  4191. - stats = per_cpu_ptr(lport->stats, get_cpu());
  4192. + stats = per_cpu_ptr(lport->stats, get_cpu_light());
  4193. stats->InvalidCRCCount++;
  4194. if (stats->InvalidCRCCount < 5)
  4195. printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
  4196. - put_cpu();
  4197. + put_cpu_light();
  4198. return -EINVAL;
  4199. }
  4200. @@ -1693,7 +1693,7 @@
  4201. */
  4202. hp = (struct fcoe_hdr *) skb_network_header(skb);
  4203. - stats = per_cpu_ptr(lport->stats, get_cpu());
  4204. + stats = per_cpu_ptr(lport->stats, get_cpu_light());
  4205. if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
  4206. if (stats->ErrorFrames < 5)
  4207. printk(KERN_WARNING "fcoe: FCoE version "
  4208. @@ -1725,13 +1725,13 @@
  4209. goto drop;
  4210. if (!fcoe_filter_frames(lport, fp)) {
  4211. - put_cpu();
  4212. + put_cpu_light();
  4213. fc_exch_recv(lport, fp);
  4214. return;
  4215. }
  4216. drop:
  4217. stats->ErrorFrames++;
  4218. - put_cpu();
  4219. + put_cpu_light();
  4220. kfree_skb(skb);
  4221. }
  4222. diff -Nur linux-4.9.6.orig/drivers/scsi/fcoe/fcoe_ctlr.c linux-4.9.6/drivers/scsi/fcoe/fcoe_ctlr.c
  4223. --- linux-4.9.6.orig/drivers/scsi/fcoe/fcoe_ctlr.c 2017-01-26 08:25:24.000000000 +0100
  4224. +++ linux-4.9.6/drivers/scsi/fcoe/fcoe_ctlr.c 2017-01-28 13:59:09.919655726 +0100
  4225. @@ -834,7 +834,7 @@
  4226. INIT_LIST_HEAD(&del_list);
  4227. - stats = per_cpu_ptr(fip->lp->stats, get_cpu());
  4228. + stats = per_cpu_ptr(fip->lp->stats, get_cpu_light());
  4229. list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
  4230. deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2;
  4231. @@ -870,7 +870,7 @@
  4232. sel_time = fcf->time;
  4233. }
  4234. }
  4235. - put_cpu();
  4236. + put_cpu_light();
  4237. list_for_each_entry_safe(fcf, next, &del_list, list) {
  4238. /* Removes fcf from current list */
  4239. diff -Nur linux-4.9.6.orig/drivers/scsi/libfc/fc_exch.c linux-4.9.6/drivers/scsi/libfc/fc_exch.c
  4240. --- linux-4.9.6.orig/drivers/scsi/libfc/fc_exch.c 2017-01-26 08:25:24.000000000 +0100
  4241. +++ linux-4.9.6/drivers/scsi/libfc/fc_exch.c 2017-01-28 13:59:09.919655726 +0100
  4242. @@ -814,10 +814,10 @@
  4243. }
  4244. memset(ep, 0, sizeof(*ep));
  4245. - cpu = get_cpu();
  4246. + cpu = get_cpu_light();
  4247. pool = per_cpu_ptr(mp->pool, cpu);
  4248. spin_lock_bh(&pool->lock);
  4249. - put_cpu();
  4250. + put_cpu_light();
  4251. /* peek cache of free slot */
  4252. if (pool->left != FC_XID_UNKNOWN) {
  4253. diff -Nur linux-4.9.6.orig/drivers/scsi/libsas/sas_ata.c linux-4.9.6/drivers/scsi/libsas/sas_ata.c
  4254. --- linux-4.9.6.orig/drivers/scsi/libsas/sas_ata.c 2017-01-26 08:25:24.000000000 +0100
  4255. +++ linux-4.9.6/drivers/scsi/libsas/sas_ata.c 2017-01-28 13:59:09.919655726 +0100
  4256. @@ -190,7 +190,7 @@
  4257. /* TODO: audit callers to ensure they are ready for qc_issue to
  4258. * unconditionally re-enable interrupts
  4259. */
  4260. - local_irq_save(flags);
  4261. + local_irq_save_nort(flags);
  4262. spin_unlock(ap->lock);
  4263. /* If the device fell off, no sense in issuing commands */
  4264. @@ -252,7 +252,7 @@
  4265. out:
  4266. spin_lock(ap->lock);
  4267. - local_irq_restore(flags);
  4268. + local_irq_restore_nort(flags);
  4269. return ret;
  4270. }
  4271. diff -Nur linux-4.9.6.orig/drivers/scsi/qla2xxx/qla_inline.h linux-4.9.6/drivers/scsi/qla2xxx/qla_inline.h
  4272. --- linux-4.9.6.orig/drivers/scsi/qla2xxx/qla_inline.h 2017-01-26 08:25:24.000000000 +0100
  4273. +++ linux-4.9.6/drivers/scsi/qla2xxx/qla_inline.h 2017-01-28 13:59:09.919655726 +0100
  4274. @@ -59,12 +59,12 @@
  4275. {
  4276. unsigned long flags;
  4277. struct qla_hw_data *ha = rsp->hw;
  4278. - local_irq_save(flags);
  4279. + local_irq_save_nort(flags);
  4280. if (IS_P3P_TYPE(ha))
  4281. qla82xx_poll(0, rsp);
  4282. else
  4283. ha->isp_ops->intr_handler(0, rsp);
  4284. - local_irq_restore(flags);
  4285. + local_irq_restore_nort(flags);
  4286. }
  4287. static inline uint8_t *
  4288. diff -Nur linux-4.9.6.orig/drivers/scsi/qla2xxx/qla_isr.c linux-4.9.6/drivers/scsi/qla2xxx/qla_isr.c
  4289. --- linux-4.9.6.orig/drivers/scsi/qla2xxx/qla_isr.c 2017-01-26 08:25:24.000000000 +0100
  4290. +++ linux-4.9.6/drivers/scsi/qla2xxx/qla_isr.c 2017-01-28 13:59:09.919655726 +0100
  4291. @@ -3125,7 +3125,11 @@
  4292. * kref_put().
  4293. */
  4294. kref_get(&qentry->irq_notify.kref);
  4295. +#ifdef CONFIG_PREEMPT_RT_BASE
  4296. + swork_queue(&qentry->irq_notify.swork);
  4297. +#else
  4298. schedule_work(&qentry->irq_notify.work);
  4299. +#endif
  4300. }
  4301. /*
  4302. diff -Nur linux-4.9.6.orig/drivers/thermal/x86_pkg_temp_thermal.c linux-4.9.6/drivers/thermal/x86_pkg_temp_thermal.c
  4303. --- linux-4.9.6.orig/drivers/thermal/x86_pkg_temp_thermal.c 2017-01-26 08:25:24.000000000 +0100
  4304. +++ linux-4.9.6/drivers/thermal/x86_pkg_temp_thermal.c 2017-01-28 13:59:09.923655879 +0100
  4305. @@ -29,6 +29,7 @@
  4306. #include <linux/pm.h>
  4307. #include <linux/thermal.h>
  4308. #include <linux/debugfs.h>
  4309. +#include <linux/swork.h>
  4310. #include <asm/cpu_device_id.h>
  4311. #include <asm/mce.h>
  4312. @@ -353,7 +354,7 @@
  4313. }
  4314. }
  4315. -static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  4316. +static void platform_thermal_notify_work(struct swork_event *event)
  4317. {
  4318. unsigned long flags;
  4319. int cpu = smp_processor_id();
  4320. @@ -370,7 +371,7 @@
  4321. pkg_work_scheduled[phy_id]) {
  4322. disable_pkg_thres_interrupt();
  4323. spin_unlock_irqrestore(&pkg_work_lock, flags);
  4324. - return -EINVAL;
  4325. + return;
  4326. }
  4327. pkg_work_scheduled[phy_id] = 1;
  4328. spin_unlock_irqrestore(&pkg_work_lock, flags);
  4329. @@ -379,9 +380,48 @@
  4330. schedule_delayed_work_on(cpu,
  4331. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  4332. msecs_to_jiffies(notify_delay_ms));
  4333. +}
  4334. +
  4335. +#ifdef CONFIG_PREEMPT_RT_FULL
  4336. +static struct swork_event notify_work;
  4337. +
  4338. +static int thermal_notify_work_init(void)
  4339. +{
  4340. + int err;
  4341. +
  4342. + err = swork_get();
  4343. + if (err)
  4344. + return err;
  4345. +
  4346. + INIT_SWORK(&notify_work, platform_thermal_notify_work);
  4347. return 0;
  4348. }
  4349. +static void thermal_notify_work_cleanup(void)
  4350. +{
  4351. + swork_put();
  4352. +}
  4353. +
  4354. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  4355. +{
  4356. + swork_queue(&notify_work);
  4357. + return 0;
  4358. +}
  4359. +
  4360. +#else /* !CONFIG_PREEMPT_RT_FULL */
  4361. +
  4362. +static int thermal_notify_work_init(void) { return 0; }
  4363. +
  4364. +static void thermal_notify_work_cleanup(void) { }
  4365. +
  4366. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  4367. +{
  4368. + platform_thermal_notify_work(NULL);
  4369. +
  4370. + return 0;
  4371. +}
  4372. +#endif /* CONFIG_PREEMPT_RT_FULL */
  4373. +
  4374. static int find_siblings_cpu(int cpu)
  4375. {
  4376. int i;
  4377. @@ -585,6 +625,9 @@
  4378. if (!x86_match_cpu(pkg_temp_thermal_ids))
  4379. return -ENODEV;
  4380. + if (!thermal_notify_work_init())
  4381. + return -ENODEV;
  4382. +
  4383. spin_lock_init(&pkg_work_lock);
  4384. platform_thermal_package_notify =
  4385. pkg_temp_thermal_platform_thermal_notify;
  4386. @@ -609,7 +652,7 @@
  4387. kfree(pkg_work_scheduled);
  4388. platform_thermal_package_notify = NULL;
  4389. platform_thermal_package_rate_control = NULL;
  4390. -
  4391. + thermal_notify_work_cleanup();
  4392. return -ENODEV;
  4393. }
  4394. @@ -634,6 +677,7 @@
  4395. mutex_unlock(&phy_dev_list_mutex);
  4396. platform_thermal_package_notify = NULL;
  4397. platform_thermal_package_rate_control = NULL;
  4398. + thermal_notify_work_cleanup();
  4399. for_each_online_cpu(i)
  4400. cancel_delayed_work_sync(
  4401. &per_cpu(pkg_temp_thermal_threshold_work, i));
  4402. diff -Nur linux-4.9.6.orig/drivers/tty/serial/8250/8250_core.c linux-4.9.6/drivers/tty/serial/8250/8250_core.c
  4403. --- linux-4.9.6.orig/drivers/tty/serial/8250/8250_core.c 2017-01-26 08:25:24.000000000 +0100
  4404. +++ linux-4.9.6/drivers/tty/serial/8250/8250_core.c 2017-01-28 13:59:09.923655879 +0100
  4405. @@ -58,7 +58,16 @@
  4406. static unsigned int skip_txen_test; /* force skip of txen test at init time */
  4407. -#define PASS_LIMIT 512
  4408. +/*
  4409. + * On -rt we can have a more delays, and legitimately
  4410. + * so - so don't drop work spuriously and spam the
  4411. + * syslog:
  4412. + */
  4413. +#ifdef CONFIG_PREEMPT_RT_FULL
  4414. +# define PASS_LIMIT 1000000
  4415. +#else
  4416. +# define PASS_LIMIT 512
  4417. +#endif
  4418. #include <asm/serial.h>
  4419. /*
  4420. diff -Nur linux-4.9.6.orig/drivers/tty/serial/8250/8250_port.c linux-4.9.6/drivers/tty/serial/8250/8250_port.c
  4421. --- linux-4.9.6.orig/drivers/tty/serial/8250/8250_port.c 2017-01-26 08:25:24.000000000 +0100
  4422. +++ linux-4.9.6/drivers/tty/serial/8250/8250_port.c 2017-01-28 13:59:09.923655879 +0100
  4423. @@ -35,6 +35,7 @@
  4424. #include <linux/nmi.h>
  4425. #include <linux/mutex.h>
  4426. #include <linux/slab.h>
  4427. +#include <linux/kdb.h>
  4428. #include <linux/uaccess.h>
  4429. #include <linux/pm_runtime.h>
  4430. #include <linux/timer.h>
  4431. @@ -3144,9 +3145,9 @@
  4432. serial8250_rpm_get(up);
  4433. - if (port->sysrq)
  4434. + if (port->sysrq || oops_in_progress)
  4435. locked = 0;
  4436. - else if (oops_in_progress)
  4437. + else if (in_kdb_printk())
  4438. locked = spin_trylock_irqsave(&port->lock, flags);
  4439. else
  4440. spin_lock_irqsave(&port->lock, flags);
  4441. diff -Nur linux-4.9.6.orig/drivers/tty/serial/amba-pl011.c linux-4.9.6/drivers/tty/serial/amba-pl011.c
  4442. --- linux-4.9.6.orig/drivers/tty/serial/amba-pl011.c 2017-01-26 08:25:24.000000000 +0100
  4443. +++ linux-4.9.6/drivers/tty/serial/amba-pl011.c 2017-01-28 13:59:09.923655879 +0100
  4444. @@ -2194,13 +2194,19 @@
  4445. clk_enable(uap->clk);
  4446. - local_irq_save(flags);
  4447. + /*
  4448. + * local_irq_save(flags);
  4449. + *
  4450. + * This local_irq_save() is nonsense. If we come in via sysrq
  4451. + * handling then interrupts are already disabled. Aside of
  4452. + * that the port.sysrq check is racy on SMP regardless.
  4453. + */
  4454. if (uap->port.sysrq)
  4455. locked = 0;
  4456. else if (oops_in_progress)
  4457. - locked = spin_trylock(&uap->port.lock);
  4458. + locked = spin_trylock_irqsave(&uap->port.lock, flags);
  4459. else
  4460. - spin_lock(&uap->port.lock);
  4461. + spin_lock_irqsave(&uap->port.lock, flags);
  4462. /*
  4463. * First save the CR then disable the interrupts
  4464. @@ -2224,8 +2230,7 @@
  4465. pl011_write(old_cr, uap, REG_CR);
  4466. if (locked)
  4467. - spin_unlock(&uap->port.lock);
  4468. - local_irq_restore(flags);
  4469. + spin_unlock_irqrestore(&uap->port.lock, flags);
  4470. clk_disable(uap->clk);
  4471. }
  4472. diff -Nur linux-4.9.6.orig/drivers/tty/serial/omap-serial.c linux-4.9.6/drivers/tty/serial/omap-serial.c
  4473. --- linux-4.9.6.orig/drivers/tty/serial/omap-serial.c 2017-01-26 08:25:24.000000000 +0100
  4474. +++ linux-4.9.6/drivers/tty/serial/omap-serial.c 2017-01-28 13:59:09.923655879 +0100
  4475. @@ -1257,13 +1257,10 @@
  4476. pm_runtime_get_sync(up->dev);
  4477. - local_irq_save(flags);
  4478. - if (up->port.sysrq)
  4479. - locked = 0;
  4480. - else if (oops_in_progress)
  4481. - locked = spin_trylock(&up->port.lock);
  4482. + if (up->port.sysrq || oops_in_progress)
  4483. + locked = spin_trylock_irqsave(&up->port.lock, flags);
  4484. else
  4485. - spin_lock(&up->port.lock);
  4486. + spin_lock_irqsave(&up->port.lock, flags);
  4487. /*
  4488. * First save the IER then disable the interrupts
  4489. @@ -1292,8 +1289,7 @@
  4490. pm_runtime_mark_last_busy(up->dev);
  4491. pm_runtime_put_autosuspend(up->dev);
  4492. if (locked)
  4493. - spin_unlock(&up->port.lock);
  4494. - local_irq_restore(flags);
  4495. + spin_unlock_irqrestore(&up->port.lock, flags);
  4496. }
  4497. static int __init
  4498. diff -Nur linux-4.9.6.orig/drivers/usb/core/hcd.c linux-4.9.6/drivers/usb/core/hcd.c
  4499. --- linux-4.9.6.orig/drivers/usb/core/hcd.c 2017-01-26 08:25:24.000000000 +0100
  4500. +++ linux-4.9.6/drivers/usb/core/hcd.c 2017-01-28 13:59:09.923655879 +0100
  4501. @@ -1761,9 +1761,9 @@
  4502. * and no one may trigger the above deadlock situation when
  4503. * running complete() in tasklet.
  4504. */
  4505. - local_irq_save(flags);
  4506. + local_irq_save_nort(flags);
  4507. urb->complete(urb);
  4508. - local_irq_restore(flags);
  4509. + local_irq_restore_nort(flags);
  4510. usb_anchor_resume_wakeups(anchor);
  4511. atomic_dec(&urb->use_count);
  4512. diff -Nur linux-4.9.6.orig/drivers/usb/gadget/function/f_fs.c linux-4.9.6/drivers/usb/gadget/function/f_fs.c
  4513. --- linux-4.9.6.orig/drivers/usb/gadget/function/f_fs.c 2017-01-26 08:25:24.000000000 +0100
  4514. +++ linux-4.9.6/drivers/usb/gadget/function/f_fs.c 2017-01-28 13:59:09.923655879 +0100
  4515. @@ -1593,7 +1593,7 @@
  4516. pr_info("%s(): freeing\n", __func__);
  4517. ffs_data_clear(ffs);
  4518. BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
  4519. - waitqueue_active(&ffs->ep0req_completion.wait));
  4520. + swait_active(&ffs->ep0req_completion.wait));
  4521. kfree(ffs->dev_name);
  4522. kfree(ffs);
  4523. }
  4524. diff -Nur linux-4.9.6.orig/drivers/usb/gadget/legacy/inode.c linux-4.9.6/drivers/usb/gadget/legacy/inode.c
  4525. --- linux-4.9.6.orig/drivers/usb/gadget/legacy/inode.c 2017-01-26 08:25:24.000000000 +0100
  4526. +++ linux-4.9.6/drivers/usb/gadget/legacy/inode.c 2017-01-28 13:59:09.923655879 +0100
  4527. @@ -346,7 +346,7 @@
  4528. spin_unlock_irq (&epdata->dev->lock);
  4529. if (likely (value == 0)) {
  4530. - value = wait_event_interruptible (done.wait, done.done);
  4531. + value = swait_event_interruptible (done.wait, done.done);
  4532. if (value != 0) {
  4533. spin_lock_irq (&epdata->dev->lock);
  4534. if (likely (epdata->ep != NULL)) {
  4535. @@ -355,7 +355,7 @@
  4536. usb_ep_dequeue (epdata->ep, epdata->req);
  4537. spin_unlock_irq (&epdata->dev->lock);
  4538. - wait_event (done.wait, done.done);
  4539. + swait_event (done.wait, done.done);
  4540. if (epdata->status == -ECONNRESET)
  4541. epdata->status = -EINTR;
  4542. } else {
  4543. diff -Nur linux-4.9.6.orig/fs/aio.c linux-4.9.6/fs/aio.c
  4544. --- linux-4.9.6.orig/fs/aio.c 2017-01-26 08:25:24.000000000 +0100
  4545. +++ linux-4.9.6/fs/aio.c 2017-01-28 13:59:09.923655879 +0100
  4546. @@ -40,6 +40,7 @@
  4547. #include <linux/ramfs.h>
  4548. #include <linux/percpu-refcount.h>
  4549. #include <linux/mount.h>
  4550. +#include <linux/swork.h>
  4551. #include <asm/kmap_types.h>
  4552. #include <asm/uaccess.h>
  4553. @@ -115,7 +116,7 @@
  4554. struct page **ring_pages;
  4555. long nr_pages;
  4556. - struct work_struct free_work;
  4557. + struct swork_event free_work;
  4558. /*
  4559. * signals when all in-flight requests are done
  4560. @@ -258,6 +259,7 @@
  4561. .mount = aio_mount,
  4562. .kill_sb = kill_anon_super,
  4563. };
  4564. + BUG_ON(swork_get());
  4565. aio_mnt = kern_mount(&aio_fs);
  4566. if (IS_ERR(aio_mnt))
  4567. panic("Failed to create aio fs mount.");
  4568. @@ -581,9 +583,9 @@
  4569. return cancel(&kiocb->common);
  4570. }
  4571. -static void free_ioctx(struct work_struct *work)
  4572. +static void free_ioctx(struct swork_event *sev)
  4573. {
  4574. - struct kioctx *ctx = container_of(work, struct kioctx, free_work);
  4575. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  4576. pr_debug("freeing %p\n", ctx);
  4577. @@ -602,8 +604,8 @@
  4578. if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
  4579. complete(&ctx->rq_wait->comp);
  4580. - INIT_WORK(&ctx->free_work, free_ioctx);
  4581. - schedule_work(&ctx->free_work);
  4582. + INIT_SWORK(&ctx->free_work, free_ioctx);
  4583. + swork_queue(&ctx->free_work);
  4584. }
  4585. /*
  4586. @@ -611,9 +613,9 @@
  4587. * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
  4588. * now it's safe to cancel any that need to be.
  4589. */
  4590. -static void free_ioctx_users(struct percpu_ref *ref)
  4591. +static void free_ioctx_users_work(struct swork_event *sev)
  4592. {
  4593. - struct kioctx *ctx = container_of(ref, struct kioctx, users);
  4594. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  4595. struct aio_kiocb *req;
  4596. spin_lock_irq(&ctx->ctx_lock);
  4597. @@ -632,6 +634,14 @@
  4598. percpu_ref_put(&ctx->reqs);
  4599. }
  4600. +static void free_ioctx_users(struct percpu_ref *ref)
  4601. +{
  4602. + struct kioctx *ctx = container_of(ref, struct kioctx, users);
  4603. +
  4604. + INIT_SWORK(&ctx->free_work, free_ioctx_users_work);
  4605. + swork_queue(&ctx->free_work);
  4606. +}
  4607. +
  4608. static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
  4609. {
  4610. unsigned i, new_nr;
  4611. diff -Nur linux-4.9.6.orig/fs/autofs4/autofs_i.h linux-4.9.6/fs/autofs4/autofs_i.h
  4612. --- linux-4.9.6.orig/fs/autofs4/autofs_i.h 2017-01-26 08:25:24.000000000 +0100
  4613. +++ linux-4.9.6/fs/autofs4/autofs_i.h 2017-01-28 13:59:09.923655879 +0100
  4614. @@ -31,6 +31,7 @@
  4615. #include <linux/sched.h>
  4616. #include <linux/mount.h>
  4617. #include <linux/namei.h>
  4618. +#include <linux/delay.h>
  4619. #include <asm/current.h>
  4620. #include <linux/uaccess.h>
  4621. diff -Nur linux-4.9.6.orig/fs/autofs4/expire.c linux-4.9.6/fs/autofs4/expire.c
  4622. --- linux-4.9.6.orig/fs/autofs4/expire.c 2017-01-26 08:25:24.000000000 +0100
  4623. +++ linux-4.9.6/fs/autofs4/expire.c 2017-01-28 13:59:09.923655879 +0100
  4624. @@ -148,7 +148,7 @@
  4625. parent = p->d_parent;
  4626. if (!spin_trylock(&parent->d_lock)) {
  4627. spin_unlock(&p->d_lock);
  4628. - cpu_relax();
  4629. + cpu_chill();
  4630. goto relock;
  4631. }
  4632. spin_unlock(&p->d_lock);
  4633. diff -Nur linux-4.9.6.orig/fs/buffer.c linux-4.9.6/fs/buffer.c
  4634. --- linux-4.9.6.orig/fs/buffer.c 2017-01-26 08:25:24.000000000 +0100
  4635. +++ linux-4.9.6/fs/buffer.c 2017-01-28 13:59:09.927656033 +0100
  4636. @@ -301,8 +301,7 @@
  4637. * decide that the page is now completely done.
  4638. */
  4639. first = page_buffers(page);
  4640. - local_irq_save(flags);
  4641. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  4642. + flags = bh_uptodate_lock_irqsave(first);
  4643. clear_buffer_async_read(bh);
  4644. unlock_buffer(bh);
  4645. tmp = bh;
  4646. @@ -315,8 +314,7 @@
  4647. }
  4648. tmp = tmp->b_this_page;
  4649. } while (tmp != bh);
  4650. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  4651. - local_irq_restore(flags);
  4652. + bh_uptodate_unlock_irqrestore(first, flags);
  4653. /*
  4654. * If none of the buffers had errors and they are all
  4655. @@ -328,9 +326,7 @@
  4656. return;
  4657. still_busy:
  4658. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  4659. - local_irq_restore(flags);
  4660. - return;
  4661. + bh_uptodate_unlock_irqrestore(first, flags);
  4662. }
  4663. /*
  4664. @@ -358,8 +354,7 @@
  4665. }
  4666. first = page_buffers(page);
  4667. - local_irq_save(flags);
  4668. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  4669. + flags = bh_uptodate_lock_irqsave(first);
  4670. clear_buffer_async_write(bh);
  4671. unlock_buffer(bh);
  4672. @@ -371,15 +366,12 @@
  4673. }
  4674. tmp = tmp->b_this_page;
  4675. }
  4676. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  4677. - local_irq_restore(flags);
  4678. + bh_uptodate_unlock_irqrestore(first, flags);
  4679. end_page_writeback(page);
  4680. return;
  4681. still_busy:
  4682. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  4683. - local_irq_restore(flags);
  4684. - return;
  4685. + bh_uptodate_unlock_irqrestore(first, flags);
  4686. }
  4687. EXPORT_SYMBOL(end_buffer_async_write);
  4688. @@ -3383,6 +3375,7 @@
  4689. struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
  4690. if (ret) {
  4691. INIT_LIST_HEAD(&ret->b_assoc_buffers);
  4692. + buffer_head_init_locks(ret);
  4693. preempt_disable();
  4694. __this_cpu_inc(bh_accounting.nr);
  4695. recalc_bh_state();
  4696. diff -Nur linux-4.9.6.orig/fs/cifs/readdir.c linux-4.9.6/fs/cifs/readdir.c
  4697. --- linux-4.9.6.orig/fs/cifs/readdir.c 2017-01-26 08:25:24.000000000 +0100
  4698. +++ linux-4.9.6/fs/cifs/readdir.c 2017-01-28 13:59:09.927656033 +0100
  4699. @@ -80,7 +80,7 @@
  4700. struct inode *inode;
  4701. struct super_block *sb = parent->d_sb;
  4702. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  4703. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  4704. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  4705. cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
  4706. diff -Nur linux-4.9.6.orig/fs/dcache.c linux-4.9.6/fs/dcache.c
  4707. --- linux-4.9.6.orig/fs/dcache.c 2017-01-26 08:25:24.000000000 +0100
  4708. +++ linux-4.9.6/fs/dcache.c 2017-01-28 13:59:09.927656033 +0100
  4709. @@ -19,6 +19,7 @@
  4710. #include <linux/mm.h>
  4711. #include <linux/fs.h>
  4712. #include <linux/fsnotify.h>
  4713. +#include <linux/delay.h>
  4714. #include <linux/slab.h>
  4715. #include <linux/init.h>
  4716. #include <linux/hash.h>
  4717. @@ -750,6 +751,8 @@
  4718. */
  4719. void dput(struct dentry *dentry)
  4720. {
  4721. + struct dentry *parent;
  4722. +
  4723. if (unlikely(!dentry))
  4724. return;
  4725. @@ -788,9 +791,18 @@
  4726. return;
  4727. kill_it:
  4728. - dentry = dentry_kill(dentry);
  4729. - if (dentry) {
  4730. - cond_resched();
  4731. + parent = dentry_kill(dentry);
  4732. + if (parent) {
  4733. + int r;
  4734. +
  4735. + if (parent == dentry) {
  4736. + /* the task with the highest priority won't schedule */
  4737. + r = cond_resched();
  4738. + if (!r)
  4739. + cpu_chill();
  4740. + } else {
  4741. + dentry = parent;
  4742. + }
  4743. goto repeat;
  4744. }
  4745. }
  4746. @@ -2324,7 +2336,7 @@
  4747. if (dentry->d_lockref.count == 1) {
  4748. if (!spin_trylock(&inode->i_lock)) {
  4749. spin_unlock(&dentry->d_lock);
  4750. - cpu_relax();
  4751. + cpu_chill();
  4752. goto again;
  4753. }
  4754. dentry->d_flags &= ~DCACHE_CANT_MOUNT;
  4755. @@ -2384,21 +2396,24 @@
  4756. static void d_wait_lookup(struct dentry *dentry)
  4757. {
  4758. - if (d_in_lookup(dentry)) {
  4759. - DECLARE_WAITQUEUE(wait, current);
  4760. - add_wait_queue(dentry->d_wait, &wait);
  4761. - do {
  4762. - set_current_state(TASK_UNINTERRUPTIBLE);
  4763. - spin_unlock(&dentry->d_lock);
  4764. - schedule();
  4765. - spin_lock(&dentry->d_lock);
  4766. - } while (d_in_lookup(dentry));
  4767. - }
  4768. + struct swait_queue __wait;
  4769. +
  4770. + if (!d_in_lookup(dentry))
  4771. + return;
  4772. +
  4773. + INIT_LIST_HEAD(&__wait.task_list);
  4774. + do {
  4775. + prepare_to_swait(dentry->d_wait, &__wait, TASK_UNINTERRUPTIBLE);
  4776. + spin_unlock(&dentry->d_lock);
  4777. + schedule();
  4778. + spin_lock(&dentry->d_lock);
  4779. + } while (d_in_lookup(dentry));
  4780. + finish_swait(dentry->d_wait, &__wait);
  4781. }
  4782. struct dentry *d_alloc_parallel(struct dentry *parent,
  4783. const struct qstr *name,
  4784. - wait_queue_head_t *wq)
  4785. + struct swait_queue_head *wq)
  4786. {
  4787. unsigned int hash = name->hash;
  4788. struct hlist_bl_head *b = in_lookup_hash(parent, hash);
  4789. @@ -2507,7 +2522,7 @@
  4790. hlist_bl_lock(b);
  4791. dentry->d_flags &= ~DCACHE_PAR_LOOKUP;
  4792. __hlist_bl_del(&dentry->d_u.d_in_lookup_hash);
  4793. - wake_up_all(dentry->d_wait);
  4794. + swake_up_all(dentry->d_wait);
  4795. dentry->d_wait = NULL;
  4796. hlist_bl_unlock(b);
  4797. INIT_HLIST_NODE(&dentry->d_u.d_alias);
  4798. @@ -3604,6 +3619,11 @@
  4799. void __init vfs_caches_init_early(void)
  4800. {
  4801. + int i;
  4802. +
  4803. + for (i = 0; i < ARRAY_SIZE(in_lookup_hashtable); i++)
  4804. + INIT_HLIST_BL_HEAD(&in_lookup_hashtable[i]);
  4805. +
  4806. dcache_init_early();
  4807. inode_init_early();
  4808. }
  4809. diff -Nur linux-4.9.6.orig/fs/eventpoll.c linux-4.9.6/fs/eventpoll.c
  4810. --- linux-4.9.6.orig/fs/eventpoll.c 2017-01-26 08:25:24.000000000 +0100
  4811. +++ linux-4.9.6/fs/eventpoll.c 2017-01-28 13:59:09.927656033 +0100
  4812. @@ -510,12 +510,12 @@
  4813. */
  4814. static void ep_poll_safewake(wait_queue_head_t *wq)
  4815. {
  4816. - int this_cpu = get_cpu();
  4817. + int this_cpu = get_cpu_light();
  4818. ep_call_nested(&poll_safewake_ncalls, EP_MAX_NESTS,
  4819. ep_poll_wakeup_proc, NULL, wq, (void *) (long) this_cpu);
  4820. - put_cpu();
  4821. + put_cpu_light();
  4822. }
  4823. static void ep_remove_wait_queue(struct eppoll_entry *pwq)
  4824. diff -Nur linux-4.9.6.orig/fs/exec.c linux-4.9.6/fs/exec.c
  4825. --- linux-4.9.6.orig/fs/exec.c 2017-01-26 08:25:24.000000000 +0100
  4826. +++ linux-4.9.6/fs/exec.c 2017-01-28 13:59:09.927656033 +0100
  4827. @@ -1017,12 +1017,14 @@
  4828. }
  4829. }
  4830. task_lock(tsk);
  4831. + preempt_disable_rt();
  4832. active_mm = tsk->active_mm;
  4833. tsk->mm = mm;
  4834. tsk->active_mm = mm;
  4835. activate_mm(active_mm, mm);
  4836. tsk->mm->vmacache_seqnum = 0;
  4837. vmacache_flush(tsk);
  4838. + preempt_enable_rt();
  4839. task_unlock(tsk);
  4840. if (old_mm) {
  4841. up_read(&old_mm->mmap_sem);
  4842. diff -Nur linux-4.9.6.orig/fs/fuse/dir.c linux-4.9.6/fs/fuse/dir.c
  4843. --- linux-4.9.6.orig/fs/fuse/dir.c 2017-01-26 08:25:24.000000000 +0100
  4844. +++ linux-4.9.6/fs/fuse/dir.c 2017-01-28 13:59:09.927656033 +0100
  4845. @@ -1191,7 +1191,7 @@
  4846. struct inode *dir = d_inode(parent);
  4847. struct fuse_conn *fc;
  4848. struct inode *inode;
  4849. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  4850. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  4851. if (!o->nodeid) {
  4852. /*
  4853. diff -Nur linux-4.9.6.orig/fs/jbd2/checkpoint.c linux-4.9.6/fs/jbd2/checkpoint.c
  4854. --- linux-4.9.6.orig/fs/jbd2/checkpoint.c 2017-01-26 08:25:24.000000000 +0100
  4855. +++ linux-4.9.6/fs/jbd2/checkpoint.c 2017-01-28 13:59:09.927656033 +0100
  4856. @@ -116,6 +116,8 @@
  4857. nblocks = jbd2_space_needed(journal);
  4858. while (jbd2_log_space_left(journal) < nblocks) {
  4859. write_unlock(&journal->j_state_lock);
  4860. + if (current->plug)
  4861. + io_schedule();
  4862. mutex_lock(&journal->j_checkpoint_mutex);
  4863. /*
  4864. diff -Nur linux-4.9.6.orig/fs/locks.c linux-4.9.6/fs/locks.c
  4865. --- linux-4.9.6.orig/fs/locks.c 2017-01-26 08:25:24.000000000 +0100
  4866. +++ linux-4.9.6/fs/locks.c 2017-01-28 13:59:09.927656033 +0100
  4867. @@ -935,7 +935,7 @@
  4868. return -ENOMEM;
  4869. }
  4870. - percpu_down_read_preempt_disable(&file_rwsem);
  4871. + percpu_down_read(&file_rwsem);
  4872. spin_lock(&ctx->flc_lock);
  4873. if (request->fl_flags & FL_ACCESS)
  4874. goto find_conflict;
  4875. @@ -976,7 +976,7 @@
  4876. out:
  4877. spin_unlock(&ctx->flc_lock);
  4878. - percpu_up_read_preempt_enable(&file_rwsem);
  4879. + percpu_up_read(&file_rwsem);
  4880. if (new_fl)
  4881. locks_free_lock(new_fl);
  4882. locks_dispose_list(&dispose);
  4883. @@ -1013,7 +1013,7 @@
  4884. new_fl2 = locks_alloc_lock();
  4885. }
  4886. - percpu_down_read_preempt_disable(&file_rwsem);
  4887. + percpu_down_read(&file_rwsem);
  4888. spin_lock(&ctx->flc_lock);
  4889. /*
  4890. * New lock request. Walk all POSIX locks and look for conflicts. If
  4891. @@ -1185,7 +1185,7 @@
  4892. }
  4893. out:
  4894. spin_unlock(&ctx->flc_lock);
  4895. - percpu_up_read_preempt_enable(&file_rwsem);
  4896. + percpu_up_read(&file_rwsem);
  4897. /*
  4898. * Free any unused locks.
  4899. */
  4900. @@ -1460,7 +1460,7 @@
  4901. return error;
  4902. }
  4903. - percpu_down_read_preempt_disable(&file_rwsem);
  4904. + percpu_down_read(&file_rwsem);
  4905. spin_lock(&ctx->flc_lock);
  4906. time_out_leases(inode, &dispose);
  4907. @@ -1512,13 +1512,13 @@
  4908. locks_insert_block(fl, new_fl);
  4909. trace_break_lease_block(inode, new_fl);
  4910. spin_unlock(&ctx->flc_lock);
  4911. - percpu_up_read_preempt_enable(&file_rwsem);
  4912. + percpu_up_read(&file_rwsem);
  4913. locks_dispose_list(&dispose);
  4914. error = wait_event_interruptible_timeout(new_fl->fl_wait,
  4915. !new_fl->fl_next, break_time);
  4916. - percpu_down_read_preempt_disable(&file_rwsem);
  4917. + percpu_down_read(&file_rwsem);
  4918. spin_lock(&ctx->flc_lock);
  4919. trace_break_lease_unblock(inode, new_fl);
  4920. locks_delete_block(new_fl);
  4921. @@ -1535,7 +1535,7 @@
  4922. }
  4923. out:
  4924. spin_unlock(&ctx->flc_lock);
  4925. - percpu_up_read_preempt_enable(&file_rwsem);
  4926. + percpu_up_read(&file_rwsem);
  4927. locks_dispose_list(&dispose);
  4928. locks_free_lock(new_fl);
  4929. return error;
  4930. @@ -1609,7 +1609,7 @@
  4931. ctx = smp_load_acquire(&inode->i_flctx);
  4932. if (ctx && !list_empty_careful(&ctx->flc_lease)) {
  4933. - percpu_down_read_preempt_disable(&file_rwsem);
  4934. + percpu_down_read(&file_rwsem);
  4935. spin_lock(&ctx->flc_lock);
  4936. time_out_leases(inode, &dispose);
  4937. list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
  4938. @@ -1619,7 +1619,7 @@
  4939. break;
  4940. }
  4941. spin_unlock(&ctx->flc_lock);
  4942. - percpu_up_read_preempt_enable(&file_rwsem);
  4943. + percpu_up_read(&file_rwsem);
  4944. locks_dispose_list(&dispose);
  4945. }
  4946. @@ -1694,7 +1694,7 @@
  4947. return -EINVAL;
  4948. }
  4949. - percpu_down_read_preempt_disable(&file_rwsem);
  4950. + percpu_down_read(&file_rwsem);
  4951. spin_lock(&ctx->flc_lock);
  4952. time_out_leases(inode, &dispose);
  4953. error = check_conflicting_open(dentry, arg, lease->fl_flags);
  4954. @@ -1765,7 +1765,7 @@
  4955. lease->fl_lmops->lm_setup(lease, priv);
  4956. out:
  4957. spin_unlock(&ctx->flc_lock);
  4958. - percpu_up_read_preempt_enable(&file_rwsem);
  4959. + percpu_up_read(&file_rwsem);
  4960. locks_dispose_list(&dispose);
  4961. if (is_deleg)
  4962. inode_unlock(inode);
  4963. @@ -1788,7 +1788,7 @@
  4964. return error;
  4965. }
  4966. - percpu_down_read_preempt_disable(&file_rwsem);
  4967. + percpu_down_read(&file_rwsem);
  4968. spin_lock(&ctx->flc_lock);
  4969. list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
  4970. if (fl->fl_file == filp &&
  4971. @@ -1801,7 +1801,7 @@
  4972. if (victim)
  4973. error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose);
  4974. spin_unlock(&ctx->flc_lock);
  4975. - percpu_up_read_preempt_enable(&file_rwsem);
  4976. + percpu_up_read(&file_rwsem);
  4977. locks_dispose_list(&dispose);
  4978. return error;
  4979. }
  4980. @@ -2532,13 +2532,13 @@
  4981. if (list_empty(&ctx->flc_lease))
  4982. return;
  4983. - percpu_down_read_preempt_disable(&file_rwsem);
  4984. + percpu_down_read(&file_rwsem);
  4985. spin_lock(&ctx->flc_lock);
  4986. list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list)
  4987. if (filp == fl->fl_file)
  4988. lease_modify(fl, F_UNLCK, &dispose);
  4989. spin_unlock(&ctx->flc_lock);
  4990. - percpu_up_read_preempt_enable(&file_rwsem);
  4991. + percpu_up_read(&file_rwsem);
  4992. locks_dispose_list(&dispose);
  4993. }
  4994. diff -Nur linux-4.9.6.orig/fs/namei.c linux-4.9.6/fs/namei.c
  4995. --- linux-4.9.6.orig/fs/namei.c 2017-01-26 08:25:24.000000000 +0100
  4996. +++ linux-4.9.6/fs/namei.c 2017-01-28 13:59:09.927656033 +0100
  4997. @@ -1629,7 +1629,7 @@
  4998. {
  4999. struct dentry *dentry = ERR_PTR(-ENOENT), *old;
  5000. struct inode *inode = dir->d_inode;
  5001. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5002. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5003. inode_lock_shared(inode);
  5004. /* Don't go there if it's already dead */
  5005. @@ -3086,7 +3086,7 @@
  5006. struct dentry *dentry;
  5007. int error, create_error = 0;
  5008. umode_t mode = op->mode;
  5009. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5010. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5011. if (unlikely(IS_DEADDIR(dir_inode)))
  5012. return -ENOENT;
  5013. diff -Nur linux-4.9.6.orig/fs/namespace.c linux-4.9.6/fs/namespace.c
  5014. --- linux-4.9.6.orig/fs/namespace.c 2017-01-26 08:25:24.000000000 +0100
  5015. +++ linux-4.9.6/fs/namespace.c 2017-01-28 13:59:09.931656187 +0100
  5016. @@ -14,6 +14,7 @@
  5017. #include <linux/mnt_namespace.h>
  5018. #include <linux/user_namespace.h>
  5019. #include <linux/namei.h>
  5020. +#include <linux/delay.h>
  5021. #include <linux/security.h>
  5022. #include <linux/idr.h>
  5023. #include <linux/init.h> /* init_rootfs */
  5024. @@ -356,8 +357,11 @@
  5025. * incremented count after it has set MNT_WRITE_HOLD.
  5026. */
  5027. smp_mb();
  5028. - while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD)
  5029. - cpu_relax();
  5030. + while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) {
  5031. + preempt_enable();
  5032. + cpu_chill();
  5033. + preempt_disable();
  5034. + }
  5035. /*
  5036. * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will
  5037. * be set to match its requirements. So we must not load that until
  5038. diff -Nur linux-4.9.6.orig/fs/nfs/delegation.c linux-4.9.6/fs/nfs/delegation.c
  5039. --- linux-4.9.6.orig/fs/nfs/delegation.c 2017-01-26 08:25:24.000000000 +0100
  5040. +++ linux-4.9.6/fs/nfs/delegation.c 2017-01-28 13:59:09.931656187 +0100
  5041. @@ -150,11 +150,11 @@
  5042. sp = state->owner;
  5043. /* Block nfs4_proc_unlck */
  5044. mutex_lock(&sp->so_delegreturn_mutex);
  5045. - seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
  5046. + seq = read_seqbegin(&sp->so_reclaim_seqlock);
  5047. err = nfs4_open_delegation_recall(ctx, state, stateid, type);
  5048. if (!err)
  5049. err = nfs_delegation_claim_locks(ctx, state, stateid);
  5050. - if (!err && read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
  5051. + if (!err && read_seqretry(&sp->so_reclaim_seqlock, seq))
  5052. err = -EAGAIN;
  5053. mutex_unlock(&sp->so_delegreturn_mutex);
  5054. put_nfs_open_context(ctx);
  5055. diff -Nur linux-4.9.6.orig/fs/nfs/dir.c linux-4.9.6/fs/nfs/dir.c
  5056. --- linux-4.9.6.orig/fs/nfs/dir.c 2017-01-26 08:25:24.000000000 +0100
  5057. +++ linux-4.9.6/fs/nfs/dir.c 2017-01-28 13:59:09.931656187 +0100
  5058. @@ -485,7 +485,7 @@
  5059. void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
  5060. {
  5061. struct qstr filename = QSTR_INIT(entry->name, entry->len);
  5062. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5063. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5064. struct dentry *dentry;
  5065. struct dentry *alias;
  5066. struct inode *dir = d_inode(parent);
  5067. @@ -1487,7 +1487,7 @@
  5068. struct file *file, unsigned open_flags,
  5069. umode_t mode, int *opened)
  5070. {
  5071. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5072. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5073. struct nfs_open_context *ctx;
  5074. struct dentry *res;
  5075. struct iattr attr = { .ia_valid = ATTR_OPEN };
  5076. @@ -1802,7 +1802,11 @@
  5077. trace_nfs_rmdir_enter(dir, dentry);
  5078. if (d_really_is_positive(dentry)) {
  5079. +#ifdef CONFIG_PREEMPT_RT_BASE
  5080. + down(&NFS_I(d_inode(dentry))->rmdir_sem);
  5081. +#else
  5082. down_write(&NFS_I(d_inode(dentry))->rmdir_sem);
  5083. +#endif
  5084. error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
  5085. /* Ensure the VFS deletes this inode */
  5086. switch (error) {
  5087. @@ -1812,7 +1816,11 @@
  5088. case -ENOENT:
  5089. nfs_dentry_handle_enoent(dentry);
  5090. }
  5091. +#ifdef CONFIG_PREEMPT_RT_BASE
  5092. + up(&NFS_I(d_inode(dentry))->rmdir_sem);
  5093. +#else
  5094. up_write(&NFS_I(d_inode(dentry))->rmdir_sem);
  5095. +#endif
  5096. } else
  5097. error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
  5098. trace_nfs_rmdir_exit(dir, dentry, error);
  5099. diff -Nur linux-4.9.6.orig/fs/nfs/inode.c linux-4.9.6/fs/nfs/inode.c
  5100. --- linux-4.9.6.orig/fs/nfs/inode.c 2017-01-26 08:25:24.000000000 +0100
  5101. +++ linux-4.9.6/fs/nfs/inode.c 2017-01-28 13:59:09.931656187 +0100
  5102. @@ -1957,7 +1957,11 @@
  5103. nfsi->nrequests = 0;
  5104. nfsi->commit_info.ncommit = 0;
  5105. atomic_set(&nfsi->commit_info.rpcs_out, 0);
  5106. +#ifdef CONFIG_PREEMPT_RT_BASE
  5107. + sema_init(&nfsi->rmdir_sem, 1);
  5108. +#else
  5109. init_rwsem(&nfsi->rmdir_sem);
  5110. +#endif
  5111. nfs4_init_once(nfsi);
  5112. }
  5113. diff -Nur linux-4.9.6.orig/fs/nfs/nfs4_fs.h linux-4.9.6/fs/nfs/nfs4_fs.h
  5114. --- linux-4.9.6.orig/fs/nfs/nfs4_fs.h 2017-01-26 08:25:24.000000000 +0100
  5115. +++ linux-4.9.6/fs/nfs/nfs4_fs.h 2017-01-28 13:59:09.931656187 +0100
  5116. @@ -111,7 +111,7 @@
  5117. unsigned long so_flags;
  5118. struct list_head so_states;
  5119. struct nfs_seqid_counter so_seqid;
  5120. - seqcount_t so_reclaim_seqcount;
  5121. + seqlock_t so_reclaim_seqlock;
  5122. struct mutex so_delegreturn_mutex;
  5123. };
  5124. diff -Nur linux-4.9.6.orig/fs/nfs/nfs4proc.c linux-4.9.6/fs/nfs/nfs4proc.c
  5125. --- linux-4.9.6.orig/fs/nfs/nfs4proc.c 2017-01-26 08:25:24.000000000 +0100
  5126. +++ linux-4.9.6/fs/nfs/nfs4proc.c 2017-01-28 13:59:09.931656187 +0100
  5127. @@ -2697,7 +2697,7 @@
  5128. unsigned int seq;
  5129. int ret;
  5130. - seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
  5131. + seq = raw_seqcount_begin(&sp->so_reclaim_seqlock.seqcount);
  5132. ret = _nfs4_proc_open(opendata);
  5133. if (ret != 0)
  5134. @@ -2735,7 +2735,7 @@
  5135. ctx->state = state;
  5136. if (d_inode(dentry) == state->inode) {
  5137. nfs_inode_attach_open_context(ctx);
  5138. - if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
  5139. + if (read_seqretry(&sp->so_reclaim_seqlock, seq))
  5140. nfs4_schedule_stateid_recovery(server, state);
  5141. }
  5142. out:
  5143. diff -Nur linux-4.9.6.orig/fs/nfs/nfs4state.c linux-4.9.6/fs/nfs/nfs4state.c
  5144. --- linux-4.9.6.orig/fs/nfs/nfs4state.c 2017-01-26 08:25:24.000000000 +0100
  5145. +++ linux-4.9.6/fs/nfs/nfs4state.c 2017-01-28 13:59:09.931656187 +0100
  5146. @@ -488,7 +488,7 @@
  5147. nfs4_init_seqid_counter(&sp->so_seqid);
  5148. atomic_set(&sp->so_count, 1);
  5149. INIT_LIST_HEAD(&sp->so_lru);
  5150. - seqcount_init(&sp->so_reclaim_seqcount);
  5151. + seqlock_init(&sp->so_reclaim_seqlock);
  5152. mutex_init(&sp->so_delegreturn_mutex);
  5153. return sp;
  5154. }
  5155. @@ -1497,8 +1497,12 @@
  5156. * recovering after a network partition or a reboot from a
  5157. * server that doesn't support a grace period.
  5158. */
  5159. +#ifdef CONFIG_PREEMPT_RT_FULL
  5160. + write_seqlock(&sp->so_reclaim_seqlock);
  5161. +#else
  5162. + write_seqcount_begin(&sp->so_reclaim_seqlock.seqcount);
  5163. +#endif
  5164. spin_lock(&sp->so_lock);
  5165. - raw_write_seqcount_begin(&sp->so_reclaim_seqcount);
  5166. restart:
  5167. list_for_each_entry(state, &sp->so_states, open_states) {
  5168. if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
  5169. @@ -1567,14 +1571,20 @@
  5170. spin_lock(&sp->so_lock);
  5171. goto restart;
  5172. }
  5173. - raw_write_seqcount_end(&sp->so_reclaim_seqcount);
  5174. spin_unlock(&sp->so_lock);
  5175. +#ifdef CONFIG_PREEMPT_RT_FULL
  5176. + write_sequnlock(&sp->so_reclaim_seqlock);
  5177. +#else
  5178. + write_seqcount_end(&sp->so_reclaim_seqlock.seqcount);
  5179. +#endif
  5180. return 0;
  5181. out_err:
  5182. nfs4_put_open_state(state);
  5183. - spin_lock(&sp->so_lock);
  5184. - raw_write_seqcount_end(&sp->so_reclaim_seqcount);
  5185. - spin_unlock(&sp->so_lock);
  5186. +#ifdef CONFIG_PREEMPT_RT_FULL
  5187. + write_sequnlock(&sp->so_reclaim_seqlock);
  5188. +#else
  5189. + write_seqcount_end(&sp->so_reclaim_seqlock.seqcount);
  5190. +#endif
  5191. return status;
  5192. }
  5193. diff -Nur linux-4.9.6.orig/fs/nfs/unlink.c linux-4.9.6/fs/nfs/unlink.c
  5194. --- linux-4.9.6.orig/fs/nfs/unlink.c 2017-01-26 08:25:24.000000000 +0100
  5195. +++ linux-4.9.6/fs/nfs/unlink.c 2017-01-28 13:59:09.931656187 +0100
  5196. @@ -12,7 +12,7 @@
  5197. #include <linux/sunrpc/clnt.h>
  5198. #include <linux/nfs_fs.h>
  5199. #include <linux/sched.h>
  5200. -#include <linux/wait.h>
  5201. +#include <linux/swait.h>
  5202. #include <linux/namei.h>
  5203. #include <linux/fsnotify.h>
  5204. @@ -51,6 +51,29 @@
  5205. rpc_restart_call_prepare(task);
  5206. }
  5207. +#ifdef CONFIG_PREEMPT_RT_BASE
  5208. +static void nfs_down_anon(struct semaphore *sema)
  5209. +{
  5210. + down(sema);
  5211. +}
  5212. +
  5213. +static void nfs_up_anon(struct semaphore *sema)
  5214. +{
  5215. + up(sema);
  5216. +}
  5217. +
  5218. +#else
  5219. +static void nfs_down_anon(struct rw_semaphore *rwsem)
  5220. +{
  5221. + down_read_non_owner(rwsem);
  5222. +}
  5223. +
  5224. +static void nfs_up_anon(struct rw_semaphore *rwsem)
  5225. +{
  5226. + up_read_non_owner(rwsem);
  5227. +}
  5228. +#endif
  5229. +
  5230. /**
  5231. * nfs_async_unlink_release - Release the sillydelete data.
  5232. * @task: rpc_task of the sillydelete
  5233. @@ -64,7 +87,7 @@
  5234. struct dentry *dentry = data->dentry;
  5235. struct super_block *sb = dentry->d_sb;
  5236. - up_read_non_owner(&NFS_I(d_inode(dentry->d_parent))->rmdir_sem);
  5237. + nfs_up_anon(&NFS_I(d_inode(dentry->d_parent))->rmdir_sem);
  5238. d_lookup_done(dentry);
  5239. nfs_free_unlinkdata(data);
  5240. dput(dentry);
  5241. @@ -117,10 +140,10 @@
  5242. struct inode *dir = d_inode(dentry->d_parent);
  5243. struct dentry *alias;
  5244. - down_read_non_owner(&NFS_I(dir)->rmdir_sem);
  5245. + nfs_down_anon(&NFS_I(dir)->rmdir_sem);
  5246. alias = d_alloc_parallel(dentry->d_parent, &data->args.name, &data->wq);
  5247. if (IS_ERR(alias)) {
  5248. - up_read_non_owner(&NFS_I(dir)->rmdir_sem);
  5249. + nfs_up_anon(&NFS_I(dir)->rmdir_sem);
  5250. return 0;
  5251. }
  5252. if (!d_in_lookup(alias)) {
  5253. @@ -142,7 +165,7 @@
  5254. ret = 0;
  5255. spin_unlock(&alias->d_lock);
  5256. dput(alias);
  5257. - up_read_non_owner(&NFS_I(dir)->rmdir_sem);
  5258. + nfs_up_anon(&NFS_I(dir)->rmdir_sem);
  5259. /*
  5260. * If we'd displaced old cached devname, free it. At that
  5261. * point dentry is definitely not a root, so we won't need
  5262. @@ -182,7 +205,7 @@
  5263. goto out_free_name;
  5264. }
  5265. data->res.dir_attr = &data->dir_attr;
  5266. - init_waitqueue_head(&data->wq);
  5267. + init_swait_queue_head(&data->wq);
  5268. status = -EBUSY;
  5269. spin_lock(&dentry->d_lock);
  5270. diff -Nur linux-4.9.6.orig/fs/ntfs/aops.c linux-4.9.6/fs/ntfs/aops.c
  5271. --- linux-4.9.6.orig/fs/ntfs/aops.c 2017-01-26 08:25:24.000000000 +0100
  5272. +++ linux-4.9.6/fs/ntfs/aops.c 2017-01-28 13:59:09.931656187 +0100
  5273. @@ -92,13 +92,13 @@
  5274. ofs = 0;
  5275. if (file_ofs < init_size)
  5276. ofs = init_size - file_ofs;
  5277. - local_irq_save(flags);
  5278. + local_irq_save_nort(flags);
  5279. kaddr = kmap_atomic(page);
  5280. memset(kaddr + bh_offset(bh) + ofs, 0,
  5281. bh->b_size - ofs);
  5282. flush_dcache_page(page);
  5283. kunmap_atomic(kaddr);
  5284. - local_irq_restore(flags);
  5285. + local_irq_restore_nort(flags);
  5286. }
  5287. } else {
  5288. clear_buffer_uptodate(bh);
  5289. @@ -107,8 +107,7 @@
  5290. "0x%llx.", (unsigned long long)bh->b_blocknr);
  5291. }
  5292. first = page_buffers(page);
  5293. - local_irq_save(flags);
  5294. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  5295. + flags = bh_uptodate_lock_irqsave(first);
  5296. clear_buffer_async_read(bh);
  5297. unlock_buffer(bh);
  5298. tmp = bh;
  5299. @@ -123,8 +122,7 @@
  5300. }
  5301. tmp = tmp->b_this_page;
  5302. } while (tmp != bh);
  5303. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  5304. - local_irq_restore(flags);
  5305. + bh_uptodate_unlock_irqrestore(first, flags);
  5306. /*
  5307. * If none of the buffers had errors then we can set the page uptodate,
  5308. * but we first have to perform the post read mst fixups, if the
  5309. @@ -145,13 +143,13 @@
  5310. recs = PAGE_SIZE / rec_size;
  5311. /* Should have been verified before we got here... */
  5312. BUG_ON(!recs);
  5313. - local_irq_save(flags);
  5314. + local_irq_save_nort(flags);
  5315. kaddr = kmap_atomic(page);
  5316. for (i = 0; i < recs; i++)
  5317. post_read_mst_fixup((NTFS_RECORD*)(kaddr +
  5318. i * rec_size), rec_size);
  5319. kunmap_atomic(kaddr);
  5320. - local_irq_restore(flags);
  5321. + local_irq_restore_nort(flags);
  5322. flush_dcache_page(page);
  5323. if (likely(page_uptodate && !PageError(page)))
  5324. SetPageUptodate(page);
  5325. @@ -159,9 +157,7 @@
  5326. unlock_page(page);
  5327. return;
  5328. still_busy:
  5329. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  5330. - local_irq_restore(flags);
  5331. - return;
  5332. + bh_uptodate_unlock_irqrestore(first, flags);
  5333. }
  5334. /**
  5335. diff -Nur linux-4.9.6.orig/fs/proc/base.c linux-4.9.6/fs/proc/base.c
  5336. --- linux-4.9.6.orig/fs/proc/base.c 2017-01-26 08:25:24.000000000 +0100
  5337. +++ linux-4.9.6/fs/proc/base.c 2017-01-28 13:59:09.931656187 +0100
  5338. @@ -1834,7 +1834,7 @@
  5339. child = d_hash_and_lookup(dir, &qname);
  5340. if (!child) {
  5341. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5342. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5343. child = d_alloc_parallel(dir, &qname, &wq);
  5344. if (IS_ERR(child))
  5345. goto end_instantiate;
  5346. diff -Nur linux-4.9.6.orig/fs/proc/proc_sysctl.c linux-4.9.6/fs/proc/proc_sysctl.c
  5347. --- linux-4.9.6.orig/fs/proc/proc_sysctl.c 2017-01-26 08:25:24.000000000 +0100
  5348. +++ linux-4.9.6/fs/proc/proc_sysctl.c 2017-01-28 13:59:09.935656342 +0100
  5349. @@ -632,7 +632,7 @@
  5350. child = d_lookup(dir, &qname);
  5351. if (!child) {
  5352. - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  5353. + DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
  5354. child = d_alloc_parallel(dir, &qname, &wq);
  5355. if (IS_ERR(child))
  5356. return false;
  5357. diff -Nur linux-4.9.6.orig/fs/timerfd.c linux-4.9.6/fs/timerfd.c
  5358. --- linux-4.9.6.orig/fs/timerfd.c 2017-01-26 08:25:24.000000000 +0100
  5359. +++ linux-4.9.6/fs/timerfd.c 2017-01-28 13:59:09.935656342 +0100
  5360. @@ -460,7 +460,10 @@
  5361. break;
  5362. }
  5363. spin_unlock_irq(&ctx->wqh.lock);
  5364. - cpu_relax();
  5365. + if (isalarm(ctx))
  5366. + hrtimer_wait_for_timer(&ctx->t.alarm.timer);
  5367. + else
  5368. + hrtimer_wait_for_timer(&ctx->t.tmr);
  5369. }
  5370. /*
  5371. diff -Nur linux-4.9.6.orig/include/acpi/platform/aclinux.h linux-4.9.6/include/acpi/platform/aclinux.h
  5372. --- linux-4.9.6.orig/include/acpi/platform/aclinux.h 2017-01-26 08:25:24.000000000 +0100
  5373. +++ linux-4.9.6/include/acpi/platform/aclinux.h 2017-01-28 13:59:09.935656342 +0100
  5374. @@ -133,6 +133,7 @@
  5375. #define acpi_cache_t struct kmem_cache
  5376. #define acpi_spinlock spinlock_t *
  5377. +#define acpi_raw_spinlock raw_spinlock_t *
  5378. #define acpi_cpu_flags unsigned long
  5379. /* Use native linux version of acpi_os_allocate_zeroed */
  5380. @@ -151,6 +152,20 @@
  5381. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
  5382. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
  5383. +#define acpi_os_create_raw_lock(__handle) \
  5384. +({ \
  5385. + raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
  5386. + \
  5387. + if (lock) { \
  5388. + *(__handle) = lock; \
  5389. + raw_spin_lock_init(*(__handle)); \
  5390. + } \
  5391. + lock ? AE_OK : AE_NO_MEMORY; \
  5392. + })
  5393. +
  5394. +#define acpi_os_delete_raw_lock(__handle) kfree(__handle)
  5395. +
  5396. +
  5397. /*
  5398. * OSL interfaces used by debugger/disassembler
  5399. */
  5400. diff -Nur linux-4.9.6.orig/include/asm-generic/bug.h linux-4.9.6/include/asm-generic/bug.h
  5401. --- linux-4.9.6.orig/include/asm-generic/bug.h 2017-01-26 08:25:24.000000000 +0100
  5402. +++ linux-4.9.6/include/asm-generic/bug.h 2017-01-28 13:59:09.935656342 +0100
  5403. @@ -215,6 +215,20 @@
  5404. # define WARN_ON_SMP(x) ({0;})
  5405. #endif
  5406. +#ifdef CONFIG_PREEMPT_RT_BASE
  5407. +# define BUG_ON_RT(c) BUG_ON(c)
  5408. +# define BUG_ON_NONRT(c) do { } while (0)
  5409. +# define WARN_ON_RT(condition) WARN_ON(condition)
  5410. +# define WARN_ON_NONRT(condition) do { } while (0)
  5411. +# define WARN_ON_ONCE_NONRT(condition) do { } while (0)
  5412. +#else
  5413. +# define BUG_ON_RT(c) do { } while (0)
  5414. +# define BUG_ON_NONRT(c) BUG_ON(c)
  5415. +# define WARN_ON_RT(condition) do { } while (0)
  5416. +# define WARN_ON_NONRT(condition) WARN_ON(condition)
  5417. +# define WARN_ON_ONCE_NONRT(condition) WARN_ON_ONCE(condition)
  5418. +#endif
  5419. +
  5420. #endif /* __ASSEMBLY__ */
  5421. #endif
  5422. diff -Nur linux-4.9.6.orig/include/linux/blkdev.h linux-4.9.6/include/linux/blkdev.h
  5423. --- linux-4.9.6.orig/include/linux/blkdev.h 2017-01-26 08:25:24.000000000 +0100
  5424. +++ linux-4.9.6/include/linux/blkdev.h 2017-01-28 13:59:09.935656342 +0100
  5425. @@ -89,6 +89,7 @@
  5426. struct list_head queuelist;
  5427. union {
  5428. struct call_single_data csd;
  5429. + struct work_struct work;
  5430. u64 fifo_time;
  5431. };
  5432. @@ -467,7 +468,7 @@
  5433. struct throtl_data *td;
  5434. #endif
  5435. struct rcu_head rcu_head;
  5436. - wait_queue_head_t mq_freeze_wq;
  5437. + struct swait_queue_head mq_freeze_wq;
  5438. struct percpu_ref q_usage_counter;
  5439. struct list_head all_q_node;
  5440. diff -Nur linux-4.9.6.orig/include/linux/blk-mq.h linux-4.9.6/include/linux/blk-mq.h
  5441. --- linux-4.9.6.orig/include/linux/blk-mq.h 2017-01-26 08:25:24.000000000 +0100
  5442. +++ linux-4.9.6/include/linux/blk-mq.h 2017-01-28 13:59:09.935656342 +0100
  5443. @@ -209,7 +209,7 @@
  5444. return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
  5445. }
  5446. -
  5447. +void __blk_mq_complete_request_remote_work(struct work_struct *work);
  5448. int blk_mq_request_started(struct request *rq);
  5449. void blk_mq_start_request(struct request *rq);
  5450. void blk_mq_end_request(struct request *rq, int error);
  5451. diff -Nur linux-4.9.6.orig/include/linux/bottom_half.h linux-4.9.6/include/linux/bottom_half.h
  5452. --- linux-4.9.6.orig/include/linux/bottom_half.h 2017-01-26 08:25:24.000000000 +0100
  5453. +++ linux-4.9.6/include/linux/bottom_half.h 2017-01-28 13:59:09.935656342 +0100
  5454. @@ -3,6 +3,39 @@
  5455. #include <linux/preempt.h>
  5456. +#ifdef CONFIG_PREEMPT_RT_FULL
  5457. +
  5458. +extern void __local_bh_disable(void);
  5459. +extern void _local_bh_enable(void);
  5460. +extern void __local_bh_enable(void);
  5461. +
  5462. +static inline void local_bh_disable(void)
  5463. +{
  5464. + __local_bh_disable();
  5465. +}
  5466. +
  5467. +static inline void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
  5468. +{
  5469. + __local_bh_disable();
  5470. +}
  5471. +
  5472. +static inline void local_bh_enable(void)
  5473. +{
  5474. + __local_bh_enable();
  5475. +}
  5476. +
  5477. +static inline void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
  5478. +{
  5479. + __local_bh_enable();
  5480. +}
  5481. +
  5482. +static inline void local_bh_enable_ip(unsigned long ip)
  5483. +{
  5484. + __local_bh_enable();
  5485. +}
  5486. +
  5487. +#else
  5488. +
  5489. #ifdef CONFIG_TRACE_IRQFLAGS
  5490. extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
  5491. #else
  5492. @@ -30,5 +63,6 @@
  5493. {
  5494. __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
  5495. }
  5496. +#endif
  5497. #endif /* _LINUX_BH_H */
  5498. diff -Nur linux-4.9.6.orig/include/linux/buffer_head.h linux-4.9.6/include/linux/buffer_head.h
  5499. --- linux-4.9.6.orig/include/linux/buffer_head.h 2017-01-26 08:25:24.000000000 +0100
  5500. +++ linux-4.9.6/include/linux/buffer_head.h 2017-01-28 13:59:09.935656342 +0100
  5501. @@ -75,8 +75,50 @@
  5502. struct address_space *b_assoc_map; /* mapping this buffer is
  5503. associated with */
  5504. atomic_t b_count; /* users using this buffer_head */
  5505. +#ifdef CONFIG_PREEMPT_RT_BASE
  5506. + spinlock_t b_uptodate_lock;
  5507. +#if IS_ENABLED(CONFIG_JBD2)
  5508. + spinlock_t b_state_lock;
  5509. + spinlock_t b_journal_head_lock;
  5510. +#endif
  5511. +#endif
  5512. };
  5513. +static inline unsigned long bh_uptodate_lock_irqsave(struct buffer_head *bh)
  5514. +{
  5515. + unsigned long flags;
  5516. +
  5517. +#ifndef CONFIG_PREEMPT_RT_BASE
  5518. + local_irq_save(flags);
  5519. + bit_spin_lock(BH_Uptodate_Lock, &bh->b_state);
  5520. +#else
  5521. + spin_lock_irqsave(&bh->b_uptodate_lock, flags);
  5522. +#endif
  5523. + return flags;
  5524. +}
  5525. +
  5526. +static inline void
  5527. +bh_uptodate_unlock_irqrestore(struct buffer_head *bh, unsigned long flags)
  5528. +{
  5529. +#ifndef CONFIG_PREEMPT_RT_BASE
  5530. + bit_spin_unlock(BH_Uptodate_Lock, &bh->b_state);
  5531. + local_irq_restore(flags);
  5532. +#else
  5533. + spin_unlock_irqrestore(&bh->b_uptodate_lock, flags);
  5534. +#endif
  5535. +}
  5536. +
  5537. +static inline void buffer_head_init_locks(struct buffer_head *bh)
  5538. +{
  5539. +#ifdef CONFIG_PREEMPT_RT_BASE
  5540. + spin_lock_init(&bh->b_uptodate_lock);
  5541. +#if IS_ENABLED(CONFIG_JBD2)
  5542. + spin_lock_init(&bh->b_state_lock);
  5543. + spin_lock_init(&bh->b_journal_head_lock);
  5544. +#endif
  5545. +#endif
  5546. +}
  5547. +
  5548. /*
  5549. * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
  5550. * and buffer_foo() functions.
  5551. diff -Nur linux-4.9.6.orig/include/linux/cgroup-defs.h linux-4.9.6/include/linux/cgroup-defs.h
  5552. --- linux-4.9.6.orig/include/linux/cgroup-defs.h 2017-01-26 08:25:24.000000000 +0100
  5553. +++ linux-4.9.6/include/linux/cgroup-defs.h 2017-01-28 13:59:09.935656342 +0100
  5554. @@ -16,6 +16,7 @@
  5555. #include <linux/percpu-refcount.h>
  5556. #include <linux/percpu-rwsem.h>
  5557. #include <linux/workqueue.h>
  5558. +#include <linux/swork.h>
  5559. #ifdef CONFIG_CGROUPS
  5560. @@ -137,6 +138,7 @@
  5561. /* percpu_ref killing and RCU release */
  5562. struct rcu_head rcu_head;
  5563. struct work_struct destroy_work;
  5564. + struct swork_event destroy_swork;
  5565. };
  5566. /*
  5567. diff -Nur linux-4.9.6.orig/include/linux/completion.h linux-4.9.6/include/linux/completion.h
  5568. --- linux-4.9.6.orig/include/linux/completion.h 2017-01-26 08:25:24.000000000 +0100
  5569. +++ linux-4.9.6/include/linux/completion.h 2017-01-28 13:59:09.935656342 +0100
  5570. @@ -7,8 +7,7 @@
  5571. * Atomic wait-for-completion handler data structures.
  5572. * See kernel/sched/completion.c for details.
  5573. */
  5574. -
  5575. -#include <linux/wait.h>
  5576. +#include <linux/swait.h>
  5577. /*
  5578. * struct completion - structure used to maintain state for a "completion"
  5579. @@ -24,11 +23,11 @@
  5580. */
  5581. struct completion {
  5582. unsigned int done;
  5583. - wait_queue_head_t wait;
  5584. + struct swait_queue_head wait;
  5585. };
  5586. #define COMPLETION_INITIALIZER(work) \
  5587. - { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  5588. + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  5589. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  5590. ({ init_completion(&work); work; })
  5591. @@ -73,7 +72,7 @@
  5592. static inline void init_completion(struct completion *x)
  5593. {
  5594. x->done = 0;
  5595. - init_waitqueue_head(&x->wait);
  5596. + init_swait_queue_head(&x->wait);
  5597. }
  5598. /**
  5599. diff -Nur linux-4.9.6.orig/include/linux/cpu.h linux-4.9.6/include/linux/cpu.h
  5600. --- linux-4.9.6.orig/include/linux/cpu.h 2017-01-26 08:25:24.000000000 +0100
  5601. +++ linux-4.9.6/include/linux/cpu.h 2017-01-28 13:59:09.935656342 +0100
  5602. @@ -182,6 +182,8 @@
  5603. extern void put_online_cpus(void);
  5604. extern void cpu_hotplug_disable(void);
  5605. extern void cpu_hotplug_enable(void);
  5606. +extern void pin_current_cpu(void);
  5607. +extern void unpin_current_cpu(void);
  5608. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  5609. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  5610. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  5611. @@ -199,6 +201,8 @@
  5612. #define put_online_cpus() do { } while (0)
  5613. #define cpu_hotplug_disable() do { } while (0)
  5614. #define cpu_hotplug_enable() do { } while (0)
  5615. +static inline void pin_current_cpu(void) { }
  5616. +static inline void unpin_current_cpu(void) { }
  5617. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  5618. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  5619. /* These aren't inline functions due to a GCC bug. */
  5620. diff -Nur linux-4.9.6.orig/include/linux/dcache.h linux-4.9.6/include/linux/dcache.h
  5621. --- linux-4.9.6.orig/include/linux/dcache.h 2017-01-26 08:25:24.000000000 +0100
  5622. +++ linux-4.9.6/include/linux/dcache.h 2017-01-28 13:59:09.935656342 +0100
  5623. @@ -11,6 +11,7 @@
  5624. #include <linux/rcupdate.h>
  5625. #include <linux/lockref.h>
  5626. #include <linux/stringhash.h>
  5627. +#include <linux/wait.h>
  5628. struct path;
  5629. struct vfsmount;
  5630. @@ -100,7 +101,7 @@
  5631. union {
  5632. struct list_head d_lru; /* LRU list */
  5633. - wait_queue_head_t *d_wait; /* in-lookup ones only */
  5634. + struct swait_queue_head *d_wait; /* in-lookup ones only */
  5635. };
  5636. struct list_head d_child; /* child of parent list */
  5637. struct list_head d_subdirs; /* our children */
  5638. @@ -230,7 +231,7 @@
  5639. extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
  5640. extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
  5641. extern struct dentry * d_alloc_parallel(struct dentry *, const struct qstr *,
  5642. - wait_queue_head_t *);
  5643. + struct swait_queue_head *);
  5644. extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
  5645. extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
  5646. extern struct dentry * d_exact_alias(struct dentry *, struct inode *);
  5647. diff -Nur linux-4.9.6.orig/include/linux/delay.h linux-4.9.6/include/linux/delay.h
  5648. --- linux-4.9.6.orig/include/linux/delay.h 2017-01-26 08:25:24.000000000 +0100
  5649. +++ linux-4.9.6/include/linux/delay.h 2017-01-28 13:59:09.935656342 +0100
  5650. @@ -52,4 +52,10 @@
  5651. msleep(seconds * 1000);
  5652. }
  5653. +#ifdef CONFIG_PREEMPT_RT_FULL
  5654. +extern void cpu_chill(void);
  5655. +#else
  5656. +# define cpu_chill() cpu_relax()
  5657. +#endif
  5658. +
  5659. #endif /* defined(_LINUX_DELAY_H) */
  5660. diff -Nur linux-4.9.6.orig/include/linux/highmem.h linux-4.9.6/include/linux/highmem.h
  5661. --- linux-4.9.6.orig/include/linux/highmem.h 2017-01-26 08:25:24.000000000 +0100
  5662. +++ linux-4.9.6/include/linux/highmem.h 2017-01-28 13:59:09.935656342 +0100
  5663. @@ -7,6 +7,7 @@
  5664. #include <linux/mm.h>
  5665. #include <linux/uaccess.h>
  5666. #include <linux/hardirq.h>
  5667. +#include <linux/sched.h>
  5668. #include <asm/cacheflush.h>
  5669. @@ -65,7 +66,7 @@
  5670. static inline void *kmap_atomic(struct page *page)
  5671. {
  5672. - preempt_disable();
  5673. + preempt_disable_nort();
  5674. pagefault_disable();
  5675. return page_address(page);
  5676. }
  5677. @@ -74,7 +75,7 @@
  5678. static inline void __kunmap_atomic(void *addr)
  5679. {
  5680. pagefault_enable();
  5681. - preempt_enable();
  5682. + preempt_enable_nort();
  5683. }
  5684. #define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
  5685. @@ -86,32 +87,51 @@
  5686. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  5687. +#ifndef CONFIG_PREEMPT_RT_FULL
  5688. DECLARE_PER_CPU(int, __kmap_atomic_idx);
  5689. +#endif
  5690. static inline int kmap_atomic_idx_push(void)
  5691. {
  5692. +#ifndef CONFIG_PREEMPT_RT_FULL
  5693. int idx = __this_cpu_inc_return(__kmap_atomic_idx) - 1;
  5694. -#ifdef CONFIG_DEBUG_HIGHMEM
  5695. +# ifdef CONFIG_DEBUG_HIGHMEM
  5696. WARN_ON_ONCE(in_irq() && !irqs_disabled());
  5697. BUG_ON(idx >= KM_TYPE_NR);
  5698. -#endif
  5699. +# endif
  5700. return idx;
  5701. +#else
  5702. + current->kmap_idx++;
  5703. + BUG_ON(current->kmap_idx > KM_TYPE_NR);
  5704. + return current->kmap_idx - 1;
  5705. +#endif
  5706. }
  5707. static inline int kmap_atomic_idx(void)
  5708. {
  5709. +#ifndef CONFIG_PREEMPT_RT_FULL
  5710. return __this_cpu_read(__kmap_atomic_idx) - 1;
  5711. +#else
  5712. + return current->kmap_idx - 1;
  5713. +#endif
  5714. }
  5715. static inline void kmap_atomic_idx_pop(void)
  5716. {
  5717. -#ifdef CONFIG_DEBUG_HIGHMEM
  5718. +#ifndef CONFIG_PREEMPT_RT_FULL
  5719. +# ifdef CONFIG_DEBUG_HIGHMEM
  5720. int idx = __this_cpu_dec_return(__kmap_atomic_idx);
  5721. BUG_ON(idx < 0);
  5722. -#else
  5723. +# else
  5724. __this_cpu_dec(__kmap_atomic_idx);
  5725. +# endif
  5726. +#else
  5727. + current->kmap_idx--;
  5728. +# ifdef CONFIG_DEBUG_HIGHMEM
  5729. + BUG_ON(current->kmap_idx < 0);
  5730. +# endif
  5731. #endif
  5732. }
  5733. diff -Nur linux-4.9.6.orig/include/linux/hrtimer.h linux-4.9.6/include/linux/hrtimer.h
  5734. --- linux-4.9.6.orig/include/linux/hrtimer.h 2017-01-26 08:25:24.000000000 +0100
  5735. +++ linux-4.9.6/include/linux/hrtimer.h 2017-01-28 13:59:09.935656342 +0100
  5736. @@ -87,6 +87,9 @@
  5737. * @function: timer expiry callback function
  5738. * @base: pointer to the timer base (per cpu and per clock)
  5739. * @state: state information (See bit values above)
  5740. + * @cb_entry: list entry to defer timers from hardirq context
  5741. + * @irqsafe: timer can run in hardirq context
  5742. + * @praecox: timer expiry time if expired at the time of programming
  5743. * @is_rel: Set if the timer was armed relative
  5744. * @start_pid: timer statistics field to store the pid of the task which
  5745. * started the timer
  5746. @@ -103,6 +106,11 @@
  5747. enum hrtimer_restart (*function)(struct hrtimer *);
  5748. struct hrtimer_clock_base *base;
  5749. u8 state;
  5750. + struct list_head cb_entry;
  5751. + int irqsafe;
  5752. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  5753. + ktime_t praecox;
  5754. +#endif
  5755. u8 is_rel;
  5756. #ifdef CONFIG_TIMER_STATS
  5757. int start_pid;
  5758. @@ -123,11 +131,7 @@
  5759. struct task_struct *task;
  5760. };
  5761. -#ifdef CONFIG_64BIT
  5762. # define HRTIMER_CLOCK_BASE_ALIGN 64
  5763. -#else
  5764. -# define HRTIMER_CLOCK_BASE_ALIGN 32
  5765. -#endif
  5766. /**
  5767. * struct hrtimer_clock_base - the timer base for a specific clock
  5768. @@ -136,6 +140,7 @@
  5769. * timer to a base on another cpu.
  5770. * @clockid: clock id for per_cpu support
  5771. * @active: red black tree root node for the active timers
  5772. + * @expired: list head for deferred timers.
  5773. * @get_time: function to retrieve the current time of the clock
  5774. * @offset: offset of this clock to the monotonic base
  5775. */
  5776. @@ -144,6 +149,7 @@
  5777. int index;
  5778. clockid_t clockid;
  5779. struct timerqueue_head active;
  5780. + struct list_head expired;
  5781. ktime_t (*get_time)(void);
  5782. ktime_t offset;
  5783. } __attribute__((__aligned__(HRTIMER_CLOCK_BASE_ALIGN)));
  5784. @@ -187,6 +193,7 @@
  5785. raw_spinlock_t lock;
  5786. seqcount_t seq;
  5787. struct hrtimer *running;
  5788. + struct hrtimer *running_soft;
  5789. unsigned int cpu;
  5790. unsigned int active_bases;
  5791. unsigned int clock_was_set_seq;
  5792. @@ -203,6 +210,9 @@
  5793. unsigned int nr_hangs;
  5794. unsigned int max_hang_time;
  5795. #endif
  5796. +#ifdef CONFIG_PREEMPT_RT_BASE
  5797. + wait_queue_head_t wait;
  5798. +#endif
  5799. struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
  5800. } ____cacheline_aligned;
  5801. @@ -412,6 +422,13 @@
  5802. hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  5803. }
  5804. +/* Softirq preemption could deadlock timer removal */
  5805. +#ifdef CONFIG_PREEMPT_RT_BASE
  5806. + extern void hrtimer_wait_for_timer(const struct hrtimer *timer);
  5807. +#else
  5808. +# define hrtimer_wait_for_timer(timer) do { cpu_relax(); } while (0)
  5809. +#endif
  5810. +
  5811. /* Query timers: */
  5812. extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
  5813. @@ -436,7 +453,7 @@
  5814. * Helper function to check, whether the timer is running the callback
  5815. * function
  5816. */
  5817. -static inline int hrtimer_callback_running(struct hrtimer *timer)
  5818. +static inline int hrtimer_callback_running(const struct hrtimer *timer)
  5819. {
  5820. return timer->base->cpu_base->running == timer;
  5821. }
  5822. diff -Nur linux-4.9.6.orig/include/linux/idr.h linux-4.9.6/include/linux/idr.h
  5823. --- linux-4.9.6.orig/include/linux/idr.h 2017-01-26 08:25:24.000000000 +0100
  5824. +++ linux-4.9.6/include/linux/idr.h 2017-01-28 13:59:09.935656342 +0100
  5825. @@ -95,10 +95,14 @@
  5826. * Each idr_preload() should be matched with an invocation of this
  5827. * function. See idr_preload() for details.
  5828. */
  5829. +#ifdef CONFIG_PREEMPT_RT_FULL
  5830. +void idr_preload_end(void);
  5831. +#else
  5832. static inline void idr_preload_end(void)
  5833. {
  5834. preempt_enable();
  5835. }
  5836. +#endif
  5837. /**
  5838. * idr_find - return pointer for given id
  5839. diff -Nur linux-4.9.6.orig/include/linux/init_task.h linux-4.9.6/include/linux/init_task.h
  5840. --- linux-4.9.6.orig/include/linux/init_task.h 2017-01-26 08:25:24.000000000 +0100
  5841. +++ linux-4.9.6/include/linux/init_task.h 2017-01-28 13:59:09.935656342 +0100
  5842. @@ -150,6 +150,12 @@
  5843. # define INIT_PERF_EVENTS(tsk)
  5844. #endif
  5845. +#ifdef CONFIG_PREEMPT_RT_BASE
  5846. +# define INIT_TIMER_LIST .posix_timer_list = NULL,
  5847. +#else
  5848. +# define INIT_TIMER_LIST
  5849. +#endif
  5850. +
  5851. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  5852. # define INIT_VTIME(tsk) \
  5853. .vtime_seqcount = SEQCNT_ZERO(tsk.vtime_seqcount), \
  5854. @@ -250,6 +256,7 @@
  5855. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  5856. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  5857. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  5858. + INIT_TIMER_LIST \
  5859. .pids = { \
  5860. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  5861. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  5862. diff -Nur linux-4.9.6.orig/include/linux/interrupt.h linux-4.9.6/include/linux/interrupt.h
  5863. --- linux-4.9.6.orig/include/linux/interrupt.h 2017-01-26 08:25:24.000000000 +0100
  5864. +++ linux-4.9.6/include/linux/interrupt.h 2017-01-28 13:59:09.935656342 +0100
  5865. @@ -14,6 +14,7 @@
  5866. #include <linux/hrtimer.h>
  5867. #include <linux/kref.h>
  5868. #include <linux/workqueue.h>
  5869. +#include <linux/swork.h>
  5870. #include <linux/atomic.h>
  5871. #include <asm/ptrace.h>
  5872. @@ -61,6 +62,7 @@
  5873. * interrupt handler after suspending interrupts. For system
  5874. * wakeup devices users need to implement wakeup detection in
  5875. * their interrupt handlers.
  5876. + * IRQF_NO_SOFTIRQ_CALL - Do not process softirqs in the irq thread context (RT)
  5877. */
  5878. #define IRQF_SHARED 0x00000080
  5879. #define IRQF_PROBE_SHARED 0x00000100
  5880. @@ -74,6 +76,7 @@
  5881. #define IRQF_NO_THREAD 0x00010000
  5882. #define IRQF_EARLY_RESUME 0x00020000
  5883. #define IRQF_COND_SUSPEND 0x00040000
  5884. +#define IRQF_NO_SOFTIRQ_CALL 0x00080000
  5885. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  5886. @@ -196,7 +199,7 @@
  5887. #ifdef CONFIG_LOCKDEP
  5888. # define local_irq_enable_in_hardirq() do { } while (0)
  5889. #else
  5890. -# define local_irq_enable_in_hardirq() local_irq_enable()
  5891. +# define local_irq_enable_in_hardirq() local_irq_enable_nort()
  5892. #endif
  5893. extern void disable_irq_nosync(unsigned int irq);
  5894. @@ -216,6 +219,7 @@
  5895. * struct irq_affinity_notify - context for notification of IRQ affinity changes
  5896. * @irq: Interrupt to which notification applies
  5897. * @kref: Reference count, for internal use
  5898. + * @swork: Swork item, for internal use
  5899. * @work: Work item, for internal use
  5900. * @notify: Function to be called on change. This will be
  5901. * called in process context.
  5902. @@ -227,7 +231,11 @@
  5903. struct irq_affinity_notify {
  5904. unsigned int irq;
  5905. struct kref kref;
  5906. +#ifdef CONFIG_PREEMPT_RT_BASE
  5907. + struct swork_event swork;
  5908. +#else
  5909. struct work_struct work;
  5910. +#endif
  5911. void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  5912. void (*release)(struct kref *ref);
  5913. };
  5914. @@ -406,9 +414,13 @@
  5915. bool state);
  5916. #ifdef CONFIG_IRQ_FORCED_THREADING
  5917. +# ifndef CONFIG_PREEMPT_RT_BASE
  5918. extern bool force_irqthreads;
  5919. +# else
  5920. +# define force_irqthreads (true)
  5921. +# endif
  5922. #else
  5923. -#define force_irqthreads (0)
  5924. +#define force_irqthreads (false)
  5925. #endif
  5926. #ifndef __ARCH_SET_SOFTIRQ_PENDING
  5927. @@ -465,9 +477,10 @@
  5928. void (*action)(struct softirq_action *);
  5929. };
  5930. +#ifndef CONFIG_PREEMPT_RT_FULL
  5931. asmlinkage void do_softirq(void);
  5932. asmlinkage void __do_softirq(void);
  5933. -
  5934. +static inline void thread_do_softirq(void) { do_softirq(); }
  5935. #ifdef __ARCH_HAS_DO_SOFTIRQ
  5936. void do_softirq_own_stack(void);
  5937. #else
  5938. @@ -476,13 +489,25 @@
  5939. __do_softirq();
  5940. }
  5941. #endif
  5942. +#else
  5943. +extern void thread_do_softirq(void);
  5944. +#endif
  5945. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  5946. extern void softirq_init(void);
  5947. extern void __raise_softirq_irqoff(unsigned int nr);
  5948. +#ifdef CONFIG_PREEMPT_RT_FULL
  5949. +extern void __raise_softirq_irqoff_ksoft(unsigned int nr);
  5950. +#else
  5951. +static inline void __raise_softirq_irqoff_ksoft(unsigned int nr)
  5952. +{
  5953. + __raise_softirq_irqoff(nr);
  5954. +}
  5955. +#endif
  5956. extern void raise_softirq_irqoff(unsigned int nr);
  5957. extern void raise_softirq(unsigned int nr);
  5958. +extern void softirq_check_pending_idle(void);
  5959. DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  5960. @@ -504,8 +529,9 @@
  5961. to be executed on some cpu at least once after this.
  5962. * If the tasklet is already scheduled, but its execution is still not
  5963. started, it will be executed only once.
  5964. - * If this tasklet is already running on another CPU (or schedule is called
  5965. - from tasklet itself), it is rescheduled for later.
  5966. + * If this tasklet is already running on another CPU, it is rescheduled
  5967. + for later.
  5968. + * Schedule must not be called from the tasklet itself (a lockup occurs)
  5969. * Tasklet is strictly serialized wrt itself, but not
  5970. wrt another tasklets. If client needs some intertask synchronization,
  5971. he makes it with spinlocks.
  5972. @@ -530,27 +556,36 @@
  5973. enum
  5974. {
  5975. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  5976. - TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  5977. + TASKLET_STATE_RUN, /* Tasklet is running (SMP only) */
  5978. + TASKLET_STATE_PENDING /* Tasklet is pending */
  5979. };
  5980. -#ifdef CONFIG_SMP
  5981. +#define TASKLET_STATEF_SCHED (1 << TASKLET_STATE_SCHED)
  5982. +#define TASKLET_STATEF_RUN (1 << TASKLET_STATE_RUN)
  5983. +#define TASKLET_STATEF_PENDING (1 << TASKLET_STATE_PENDING)
  5984. +
  5985. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  5986. static inline int tasklet_trylock(struct tasklet_struct *t)
  5987. {
  5988. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  5989. }
  5990. +static inline int tasklet_tryunlock(struct tasklet_struct *t)
  5991. +{
  5992. + return cmpxchg(&t->state, TASKLET_STATEF_RUN, 0) == TASKLET_STATEF_RUN;
  5993. +}
  5994. +
  5995. static inline void tasklet_unlock(struct tasklet_struct *t)
  5996. {
  5997. smp_mb__before_atomic();
  5998. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  5999. }
  6000. -static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  6001. -{
  6002. - while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  6003. -}
  6004. +extern void tasklet_unlock_wait(struct tasklet_struct *t);
  6005. +
  6006. #else
  6007. #define tasklet_trylock(t) 1
  6008. +#define tasklet_tryunlock(t) 1
  6009. #define tasklet_unlock_wait(t) do { } while (0)
  6010. #define tasklet_unlock(t) do { } while (0)
  6011. #endif
  6012. @@ -599,12 +634,7 @@
  6013. smp_mb();
  6014. }
  6015. -static inline void tasklet_enable(struct tasklet_struct *t)
  6016. -{
  6017. - smp_mb__before_atomic();
  6018. - atomic_dec(&t->count);
  6019. -}
  6020. -
  6021. +extern void tasklet_enable(struct tasklet_struct *t);
  6022. extern void tasklet_kill(struct tasklet_struct *t);
  6023. extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  6024. extern void tasklet_init(struct tasklet_struct *t,
  6025. @@ -635,6 +665,12 @@
  6026. tasklet_kill(&ttimer->tasklet);
  6027. }
  6028. +#ifdef CONFIG_PREEMPT_RT_FULL
  6029. +extern void softirq_early_init(void);
  6030. +#else
  6031. +static inline void softirq_early_init(void) { }
  6032. +#endif
  6033. +
  6034. /*
  6035. * Autoprobing for irqs:
  6036. *
  6037. diff -Nur linux-4.9.6.orig/include/linux/irqdesc.h linux-4.9.6/include/linux/irqdesc.h
  6038. --- linux-4.9.6.orig/include/linux/irqdesc.h 2017-01-26 08:25:24.000000000 +0100
  6039. +++ linux-4.9.6/include/linux/irqdesc.h 2017-01-28 13:59:09.935656342 +0100
  6040. @@ -66,6 +66,7 @@
  6041. unsigned int irqs_unhandled;
  6042. atomic_t threads_handled;
  6043. int threads_handled_last;
  6044. + u64 random_ip;
  6045. raw_spinlock_t lock;
  6046. struct cpumask *percpu_enabled;
  6047. const struct cpumask *percpu_affinity;
  6048. diff -Nur linux-4.9.6.orig/include/linux/irqflags.h linux-4.9.6/include/linux/irqflags.h
  6049. --- linux-4.9.6.orig/include/linux/irqflags.h 2017-01-26 08:25:24.000000000 +0100
  6050. +++ linux-4.9.6/include/linux/irqflags.h 2017-01-28 13:59:09.935656342 +0100
  6051. @@ -25,8 +25,6 @@
  6052. # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
  6053. # define trace_hardirq_enter() do { current->hardirq_context++; } while (0)
  6054. # define trace_hardirq_exit() do { current->hardirq_context--; } while (0)
  6055. -# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  6056. -# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  6057. # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
  6058. #else
  6059. # define trace_hardirqs_on() do { } while (0)
  6060. @@ -39,9 +37,15 @@
  6061. # define trace_softirqs_enabled(p) 0
  6062. # define trace_hardirq_enter() do { } while (0)
  6063. # define trace_hardirq_exit() do { } while (0)
  6064. +# define INIT_TRACE_IRQFLAGS
  6065. +#endif
  6066. +
  6067. +#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT_FULL)
  6068. +# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  6069. +# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  6070. +#else
  6071. # define lockdep_softirq_enter() do { } while (0)
  6072. # define lockdep_softirq_exit() do { } while (0)
  6073. -# define INIT_TRACE_IRQFLAGS
  6074. #endif
  6075. #if defined(CONFIG_IRQSOFF_TRACER) || \
  6076. @@ -148,4 +152,23 @@
  6077. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  6078. +/*
  6079. + * local_irq* variants depending on RT/!RT
  6080. + */
  6081. +#ifdef CONFIG_PREEMPT_RT_FULL
  6082. +# define local_irq_disable_nort() do { } while (0)
  6083. +# define local_irq_enable_nort() do { } while (0)
  6084. +# define local_irq_save_nort(flags) local_save_flags(flags)
  6085. +# define local_irq_restore_nort(flags) (void)(flags)
  6086. +# define local_irq_disable_rt() local_irq_disable()
  6087. +# define local_irq_enable_rt() local_irq_enable()
  6088. +#else
  6089. +# define local_irq_disable_nort() local_irq_disable()
  6090. +# define local_irq_enable_nort() local_irq_enable()
  6091. +# define local_irq_save_nort(flags) local_irq_save(flags)
  6092. +# define local_irq_restore_nort(flags) local_irq_restore(flags)
  6093. +# define local_irq_disable_rt() do { } while (0)
  6094. +# define local_irq_enable_rt() do { } while (0)
  6095. +#endif
  6096. +
  6097. #endif
  6098. diff -Nur linux-4.9.6.orig/include/linux/irq.h linux-4.9.6/include/linux/irq.h
  6099. --- linux-4.9.6.orig/include/linux/irq.h 2017-01-26 08:25:24.000000000 +0100
  6100. +++ linux-4.9.6/include/linux/irq.h 2017-01-28 13:59:09.935656342 +0100
  6101. @@ -72,6 +72,7 @@
  6102. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  6103. * it from the spurious interrupt detection
  6104. * mechanism and from core side polling.
  6105. + * IRQ_NO_SOFTIRQ_CALL - No softirq processing in the irq thread context (RT)
  6106. * IRQ_DISABLE_UNLAZY - Disable lazy irq disable
  6107. */
  6108. enum {
  6109. @@ -99,13 +100,14 @@
  6110. IRQ_PER_CPU_DEVID = (1 << 17),
  6111. IRQ_IS_POLLED = (1 << 18),
  6112. IRQ_DISABLE_UNLAZY = (1 << 19),
  6113. + IRQ_NO_SOFTIRQ_CALL = (1 << 20),
  6114. };
  6115. #define IRQF_MODIFY_MASK \
  6116. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  6117. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  6118. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  6119. - IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY)
  6120. + IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY | IRQ_NO_SOFTIRQ_CALL)
  6121. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  6122. diff -Nur linux-4.9.6.orig/include/linux/irq_work.h linux-4.9.6/include/linux/irq_work.h
  6123. --- linux-4.9.6.orig/include/linux/irq_work.h 2017-01-26 08:25:24.000000000 +0100
  6124. +++ linux-4.9.6/include/linux/irq_work.h 2017-01-28 13:59:09.935656342 +0100
  6125. @@ -16,6 +16,7 @@
  6126. #define IRQ_WORK_BUSY 2UL
  6127. #define IRQ_WORK_FLAGS 3UL
  6128. #define IRQ_WORK_LAZY 4UL /* Doesn't want IPI, wait for tick */
  6129. +#define IRQ_WORK_HARD_IRQ 8UL /* Run hard IRQ context, even on RT */
  6130. struct irq_work {
  6131. unsigned long flags;
  6132. @@ -51,4 +52,10 @@
  6133. static inline void irq_work_run(void) { }
  6134. #endif
  6135. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  6136. +void irq_work_tick_soft(void);
  6137. +#else
  6138. +static inline void irq_work_tick_soft(void) { }
  6139. +#endif
  6140. +
  6141. #endif /* _LINUX_IRQ_WORK_H */
  6142. diff -Nur linux-4.9.6.orig/include/linux/jbd2.h linux-4.9.6/include/linux/jbd2.h
  6143. --- linux-4.9.6.orig/include/linux/jbd2.h 2017-01-26 08:25:24.000000000 +0100
  6144. +++ linux-4.9.6/include/linux/jbd2.h 2017-01-28 13:59:09.939656496 +0100
  6145. @@ -347,32 +347,56 @@
  6146. static inline void jbd_lock_bh_state(struct buffer_head *bh)
  6147. {
  6148. +#ifndef CONFIG_PREEMPT_RT_BASE
  6149. bit_spin_lock(BH_State, &bh->b_state);
  6150. +#else
  6151. + spin_lock(&bh->b_state_lock);
  6152. +#endif
  6153. }
  6154. static inline int jbd_trylock_bh_state(struct buffer_head *bh)
  6155. {
  6156. +#ifndef CONFIG_PREEMPT_RT_BASE
  6157. return bit_spin_trylock(BH_State, &bh->b_state);
  6158. +#else
  6159. + return spin_trylock(&bh->b_state_lock);
  6160. +#endif
  6161. }
  6162. static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
  6163. {
  6164. +#ifndef CONFIG_PREEMPT_RT_BASE
  6165. return bit_spin_is_locked(BH_State, &bh->b_state);
  6166. +#else
  6167. + return spin_is_locked(&bh->b_state_lock);
  6168. +#endif
  6169. }
  6170. static inline void jbd_unlock_bh_state(struct buffer_head *bh)
  6171. {
  6172. +#ifndef CONFIG_PREEMPT_RT_BASE
  6173. bit_spin_unlock(BH_State, &bh->b_state);
  6174. +#else
  6175. + spin_unlock(&bh->b_state_lock);
  6176. +#endif
  6177. }
  6178. static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
  6179. {
  6180. +#ifndef CONFIG_PREEMPT_RT_BASE
  6181. bit_spin_lock(BH_JournalHead, &bh->b_state);
  6182. +#else
  6183. + spin_lock(&bh->b_journal_head_lock);
  6184. +#endif
  6185. }
  6186. static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
  6187. {
  6188. +#ifndef CONFIG_PREEMPT_RT_BASE
  6189. bit_spin_unlock(BH_JournalHead, &bh->b_state);
  6190. +#else
  6191. + spin_unlock(&bh->b_journal_head_lock);
  6192. +#endif
  6193. }
  6194. #define J_ASSERT(assert) BUG_ON(!(assert))
  6195. diff -Nur linux-4.9.6.orig/include/linux/kdb.h linux-4.9.6/include/linux/kdb.h
  6196. --- linux-4.9.6.orig/include/linux/kdb.h 2017-01-26 08:25:24.000000000 +0100
  6197. +++ linux-4.9.6/include/linux/kdb.h 2017-01-28 13:59:09.939656496 +0100
  6198. @@ -167,6 +167,7 @@
  6199. extern __printf(1, 2) int kdb_printf(const char *, ...);
  6200. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  6201. +#define in_kdb_printk() (kdb_trap_printk)
  6202. extern void kdb_init(int level);
  6203. /* Access to kdb specific polling devices */
  6204. @@ -201,6 +202,7 @@
  6205. extern int kdb_unregister(char *);
  6206. #else /* ! CONFIG_KGDB_KDB */
  6207. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  6208. +#define in_kdb_printk() (0)
  6209. static inline void kdb_init(int level) {}
  6210. static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
  6211. char *help, short minlen) { return 0; }
  6212. diff -Nur linux-4.9.6.orig/include/linux/kernel.h linux-4.9.6/include/linux/kernel.h
  6213. --- linux-4.9.6.orig/include/linux/kernel.h 2017-01-26 08:25:24.000000000 +0100
  6214. +++ linux-4.9.6/include/linux/kernel.h 2017-01-28 13:59:09.939656496 +0100
  6215. @@ -194,6 +194,9 @@
  6216. */
  6217. # define might_sleep() \
  6218. do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  6219. +
  6220. +# define might_sleep_no_state_check() \
  6221. + do { ___might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  6222. # define sched_annotate_sleep() (current->task_state_change = 0)
  6223. #else
  6224. static inline void ___might_sleep(const char *file, int line,
  6225. @@ -201,6 +204,7 @@
  6226. static inline void __might_sleep(const char *file, int line,
  6227. int preempt_offset) { }
  6228. # define might_sleep() do { might_resched(); } while (0)
  6229. +# define might_sleep_no_state_check() do { might_resched(); } while (0)
  6230. # define sched_annotate_sleep() do { } while (0)
  6231. #endif
  6232. @@ -488,6 +492,7 @@
  6233. SYSTEM_HALT,
  6234. SYSTEM_POWER_OFF,
  6235. SYSTEM_RESTART,
  6236. + SYSTEM_SUSPEND,
  6237. } system_state;
  6238. #define TAINT_PROPRIETARY_MODULE 0
  6239. diff -Nur linux-4.9.6.orig/include/linux/list_bl.h linux-4.9.6/include/linux/list_bl.h
  6240. --- linux-4.9.6.orig/include/linux/list_bl.h 2017-01-26 08:25:24.000000000 +0100
  6241. +++ linux-4.9.6/include/linux/list_bl.h 2017-01-28 13:59:09.939656496 +0100
  6242. @@ -2,6 +2,7 @@
  6243. #define _LINUX_LIST_BL_H
  6244. #include <linux/list.h>
  6245. +#include <linux/spinlock.h>
  6246. #include <linux/bit_spinlock.h>
  6247. /*
  6248. @@ -32,13 +33,24 @@
  6249. struct hlist_bl_head {
  6250. struct hlist_bl_node *first;
  6251. +#ifdef CONFIG_PREEMPT_RT_BASE
  6252. + raw_spinlock_t lock;
  6253. +#endif
  6254. };
  6255. struct hlist_bl_node {
  6256. struct hlist_bl_node *next, **pprev;
  6257. };
  6258. -#define INIT_HLIST_BL_HEAD(ptr) \
  6259. - ((ptr)->first = NULL)
  6260. +
  6261. +#ifdef CONFIG_PREEMPT_RT_BASE
  6262. +#define INIT_HLIST_BL_HEAD(h) \
  6263. +do { \
  6264. + (h)->first = NULL; \
  6265. + raw_spin_lock_init(&(h)->lock); \
  6266. +} while (0)
  6267. +#else
  6268. +#define INIT_HLIST_BL_HEAD(h) (h)->first = NULL
  6269. +#endif
  6270. static inline void INIT_HLIST_BL_NODE(struct hlist_bl_node *h)
  6271. {
  6272. @@ -118,12 +130,26 @@
  6273. static inline void hlist_bl_lock(struct hlist_bl_head *b)
  6274. {
  6275. +#ifndef CONFIG_PREEMPT_RT_BASE
  6276. bit_spin_lock(0, (unsigned long *)b);
  6277. +#else
  6278. + raw_spin_lock(&b->lock);
  6279. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  6280. + __set_bit(0, (unsigned long *)b);
  6281. +#endif
  6282. +#endif
  6283. }
  6284. static inline void hlist_bl_unlock(struct hlist_bl_head *b)
  6285. {
  6286. +#ifndef CONFIG_PREEMPT_RT_BASE
  6287. __bit_spin_unlock(0, (unsigned long *)b);
  6288. +#else
  6289. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  6290. + __clear_bit(0, (unsigned long *)b);
  6291. +#endif
  6292. + raw_spin_unlock(&b->lock);
  6293. +#endif
  6294. }
  6295. static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
  6296. diff -Nur linux-4.9.6.orig/include/linux/locallock.h linux-4.9.6/include/linux/locallock.h
  6297. --- linux-4.9.6.orig/include/linux/locallock.h 1970-01-01 01:00:00.000000000 +0100
  6298. +++ linux-4.9.6/include/linux/locallock.h 2017-01-28 13:59:09.939656496 +0100
  6299. @@ -0,0 +1,278 @@
  6300. +#ifndef _LINUX_LOCALLOCK_H
  6301. +#define _LINUX_LOCALLOCK_H
  6302. +
  6303. +#include <linux/percpu.h>
  6304. +#include <linux/spinlock.h>
  6305. +
  6306. +#ifdef CONFIG_PREEMPT_RT_BASE
  6307. +
  6308. +#ifdef CONFIG_DEBUG_SPINLOCK
  6309. +# define LL_WARN(cond) WARN_ON(cond)
  6310. +#else
  6311. +# define LL_WARN(cond) do { } while (0)
  6312. +#endif
  6313. +
  6314. +/*
  6315. + * per cpu lock based substitute for local_irq_*()
  6316. + */
  6317. +struct local_irq_lock {
  6318. + spinlock_t lock;
  6319. + struct task_struct *owner;
  6320. + int nestcnt;
  6321. + unsigned long flags;
  6322. +};
  6323. +
  6324. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) \
  6325. + DEFINE_PER_CPU(struct local_irq_lock, lvar) = { \
  6326. + .lock = __SPIN_LOCK_UNLOCKED((lvar).lock) }
  6327. +
  6328. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) \
  6329. + DECLARE_PER_CPU(struct local_irq_lock, lvar)
  6330. +
  6331. +#define local_irq_lock_init(lvar) \
  6332. + do { \
  6333. + int __cpu; \
  6334. + for_each_possible_cpu(__cpu) \
  6335. + spin_lock_init(&per_cpu(lvar, __cpu).lock); \
  6336. + } while (0)
  6337. +
  6338. +/*
  6339. + * spin_lock|trylock|unlock_local flavour that does not migrate disable
  6340. + * used for __local_lock|trylock|unlock where get_local_var/put_local_var
  6341. + * already takes care of the migrate_disable/enable
  6342. + * for CONFIG_PREEMPT_BASE map to the normal spin_* calls.
  6343. + */
  6344. +#ifdef CONFIG_PREEMPT_RT_FULL
  6345. +# define spin_lock_local(lock) rt_spin_lock__no_mg(lock)
  6346. +# define spin_trylock_local(lock) rt_spin_trylock__no_mg(lock)
  6347. +# define spin_unlock_local(lock) rt_spin_unlock__no_mg(lock)
  6348. +#else
  6349. +# define spin_lock_local(lock) spin_lock(lock)
  6350. +# define spin_trylock_local(lock) spin_trylock(lock)
  6351. +# define spin_unlock_local(lock) spin_unlock(lock)
  6352. +#endif
  6353. +
  6354. +static inline void __local_lock(struct local_irq_lock *lv)
  6355. +{
  6356. + if (lv->owner != current) {
  6357. + spin_lock_local(&lv->lock);
  6358. + LL_WARN(lv->owner);
  6359. + LL_WARN(lv->nestcnt);
  6360. + lv->owner = current;
  6361. + }
  6362. + lv->nestcnt++;
  6363. +}
  6364. +
  6365. +#define local_lock(lvar) \
  6366. + do { __local_lock(&get_local_var(lvar)); } while (0)
  6367. +
  6368. +#define local_lock_on(lvar, cpu) \
  6369. + do { __local_lock(&per_cpu(lvar, cpu)); } while (0)
  6370. +
  6371. +static inline int __local_trylock(struct local_irq_lock *lv)
  6372. +{
  6373. + if (lv->owner != current && spin_trylock_local(&lv->lock)) {
  6374. + LL_WARN(lv->owner);
  6375. + LL_WARN(lv->nestcnt);
  6376. + lv->owner = current;
  6377. + lv->nestcnt = 1;
  6378. + return 1;
  6379. + }
  6380. + return 0;
  6381. +}
  6382. +
  6383. +#define local_trylock(lvar) \
  6384. + ({ \
  6385. + int __locked; \
  6386. + __locked = __local_trylock(&get_local_var(lvar)); \
  6387. + if (!__locked) \
  6388. + put_local_var(lvar); \
  6389. + __locked; \
  6390. + })
  6391. +
  6392. +static inline void __local_unlock(struct local_irq_lock *lv)
  6393. +{
  6394. + LL_WARN(lv->nestcnt == 0);
  6395. + LL_WARN(lv->owner != current);
  6396. + if (--lv->nestcnt)
  6397. + return;
  6398. +
  6399. + lv->owner = NULL;
  6400. + spin_unlock_local(&lv->lock);
  6401. +}
  6402. +
  6403. +#define local_unlock(lvar) \
  6404. + do { \
  6405. + __local_unlock(this_cpu_ptr(&lvar)); \
  6406. + put_local_var(lvar); \
  6407. + } while (0)
  6408. +
  6409. +#define local_unlock_on(lvar, cpu) \
  6410. + do { __local_unlock(&per_cpu(lvar, cpu)); } while (0)
  6411. +
  6412. +static inline void __local_lock_irq(struct local_irq_lock *lv)
  6413. +{
  6414. + spin_lock_irqsave(&lv->lock, lv->flags);
  6415. + LL_WARN(lv->owner);
  6416. + LL_WARN(lv->nestcnt);
  6417. + lv->owner = current;
  6418. + lv->nestcnt = 1;
  6419. +}
  6420. +
  6421. +#define local_lock_irq(lvar) \
  6422. + do { __local_lock_irq(&get_local_var(lvar)); } while (0)
  6423. +
  6424. +#define local_lock_irq_on(lvar, cpu) \
  6425. + do { __local_lock_irq(&per_cpu(lvar, cpu)); } while (0)
  6426. +
  6427. +static inline void __local_unlock_irq(struct local_irq_lock *lv)
  6428. +{
  6429. + LL_WARN(!lv->nestcnt);
  6430. + LL_WARN(lv->owner != current);
  6431. + lv->owner = NULL;
  6432. + lv->nestcnt = 0;
  6433. + spin_unlock_irq(&lv->lock);
  6434. +}
  6435. +
  6436. +#define local_unlock_irq(lvar) \
  6437. + do { \
  6438. + __local_unlock_irq(this_cpu_ptr(&lvar)); \
  6439. + put_local_var(lvar); \
  6440. + } while (0)
  6441. +
  6442. +#define local_unlock_irq_on(lvar, cpu) \
  6443. + do { \
  6444. + __local_unlock_irq(&per_cpu(lvar, cpu)); \
  6445. + } while (0)
  6446. +
  6447. +static inline int __local_lock_irqsave(struct local_irq_lock *lv)
  6448. +{
  6449. + if (lv->owner != current) {
  6450. + __local_lock_irq(lv);
  6451. + return 0;
  6452. + } else {
  6453. + lv->nestcnt++;
  6454. + return 1;
  6455. + }
  6456. +}
  6457. +
  6458. +#define local_lock_irqsave(lvar, _flags) \
  6459. + do { \
  6460. + if (__local_lock_irqsave(&get_local_var(lvar))) \
  6461. + put_local_var(lvar); \
  6462. + _flags = __this_cpu_read(lvar.flags); \
  6463. + } while (0)
  6464. +
  6465. +#define local_lock_irqsave_on(lvar, _flags, cpu) \
  6466. + do { \
  6467. + __local_lock_irqsave(&per_cpu(lvar, cpu)); \
  6468. + _flags = per_cpu(lvar, cpu).flags; \
  6469. + } while (0)
  6470. +
  6471. +static inline int __local_unlock_irqrestore(struct local_irq_lock *lv,
  6472. + unsigned long flags)
  6473. +{
  6474. + LL_WARN(!lv->nestcnt);
  6475. + LL_WARN(lv->owner != current);
  6476. + if (--lv->nestcnt)
  6477. + return 0;
  6478. +
  6479. + lv->owner = NULL;
  6480. + spin_unlock_irqrestore(&lv->lock, lv->flags);
  6481. + return 1;
  6482. +}
  6483. +
  6484. +#define local_unlock_irqrestore(lvar, flags) \
  6485. + do { \
  6486. + if (__local_unlock_irqrestore(this_cpu_ptr(&lvar), flags)) \
  6487. + put_local_var(lvar); \
  6488. + } while (0)
  6489. +
  6490. +#define local_unlock_irqrestore_on(lvar, flags, cpu) \
  6491. + do { \
  6492. + __local_unlock_irqrestore(&per_cpu(lvar, cpu), flags); \
  6493. + } while (0)
  6494. +
  6495. +#define local_spin_trylock_irq(lvar, lock) \
  6496. + ({ \
  6497. + int __locked; \
  6498. + local_lock_irq(lvar); \
  6499. + __locked = spin_trylock(lock); \
  6500. + if (!__locked) \
  6501. + local_unlock_irq(lvar); \
  6502. + __locked; \
  6503. + })
  6504. +
  6505. +#define local_spin_lock_irq(lvar, lock) \
  6506. + do { \
  6507. + local_lock_irq(lvar); \
  6508. + spin_lock(lock); \
  6509. + } while (0)
  6510. +
  6511. +#define local_spin_unlock_irq(lvar, lock) \
  6512. + do { \
  6513. + spin_unlock(lock); \
  6514. + local_unlock_irq(lvar); \
  6515. + } while (0)
  6516. +
  6517. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  6518. + do { \
  6519. + local_lock_irqsave(lvar, flags); \
  6520. + spin_lock(lock); \
  6521. + } while (0)
  6522. +
  6523. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  6524. + do { \
  6525. + spin_unlock(lock); \
  6526. + local_unlock_irqrestore(lvar, flags); \
  6527. + } while (0)
  6528. +
  6529. +#define get_locked_var(lvar, var) \
  6530. + (*({ \
  6531. + local_lock(lvar); \
  6532. + this_cpu_ptr(&var); \
  6533. + }))
  6534. +
  6535. +#define put_locked_var(lvar, var) local_unlock(lvar);
  6536. +
  6537. +#define local_lock_cpu(lvar) \
  6538. + ({ \
  6539. + local_lock(lvar); \
  6540. + smp_processor_id(); \
  6541. + })
  6542. +
  6543. +#define local_unlock_cpu(lvar) local_unlock(lvar)
  6544. +
  6545. +#else /* PREEMPT_RT_BASE */
  6546. +
  6547. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) __typeof__(const int) lvar
  6548. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) extern __typeof__(const int) lvar
  6549. +
  6550. +static inline void local_irq_lock_init(int lvar) { }
  6551. +
  6552. +#define local_lock(lvar) preempt_disable()
  6553. +#define local_unlock(lvar) preempt_enable()
  6554. +#define local_lock_irq(lvar) local_irq_disable()
  6555. +#define local_lock_irq_on(lvar, cpu) local_irq_disable()
  6556. +#define local_unlock_irq(lvar) local_irq_enable()
  6557. +#define local_unlock_irq_on(lvar, cpu) local_irq_enable()
  6558. +#define local_lock_irqsave(lvar, flags) local_irq_save(flags)
  6559. +#define local_unlock_irqrestore(lvar, flags) local_irq_restore(flags)
  6560. +
  6561. +#define local_spin_trylock_irq(lvar, lock) spin_trylock_irq(lock)
  6562. +#define local_spin_lock_irq(lvar, lock) spin_lock_irq(lock)
  6563. +#define local_spin_unlock_irq(lvar, lock) spin_unlock_irq(lock)
  6564. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  6565. + spin_lock_irqsave(lock, flags)
  6566. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  6567. + spin_unlock_irqrestore(lock, flags)
  6568. +
  6569. +#define get_locked_var(lvar, var) get_cpu_var(var)
  6570. +#define put_locked_var(lvar, var) put_cpu_var(var)
  6571. +
  6572. +#define local_lock_cpu(lvar) get_cpu()
  6573. +#define local_unlock_cpu(lvar) put_cpu()
  6574. +
  6575. +#endif
  6576. +
  6577. +#endif
  6578. diff -Nur linux-4.9.6.orig/include/linux/mm_types.h linux-4.9.6/include/linux/mm_types.h
  6579. --- linux-4.9.6.orig/include/linux/mm_types.h 2017-01-26 08:25:24.000000000 +0100
  6580. +++ linux-4.9.6/include/linux/mm_types.h 2017-01-28 13:59:09.939656496 +0100
  6581. @@ -11,6 +11,7 @@
  6582. #include <linux/completion.h>
  6583. #include <linux/cpumask.h>
  6584. #include <linux/uprobes.h>
  6585. +#include <linux/rcupdate.h>
  6586. #include <linux/page-flags-layout.h>
  6587. #include <linux/workqueue.h>
  6588. #include <asm/page.h>
  6589. @@ -509,6 +510,9 @@
  6590. bool tlb_flush_pending;
  6591. #endif
  6592. struct uprobes_state uprobes_state;
  6593. +#ifdef CONFIG_PREEMPT_RT_BASE
  6594. + struct rcu_head delayed_drop;
  6595. +#endif
  6596. #ifdef CONFIG_X86_INTEL_MPX
  6597. /* address of the bounds directory */
  6598. void __user *bd_addr;
  6599. diff -Nur linux-4.9.6.orig/include/linux/mutex.h linux-4.9.6/include/linux/mutex.h
  6600. --- linux-4.9.6.orig/include/linux/mutex.h 2017-01-26 08:25:24.000000000 +0100
  6601. +++ linux-4.9.6/include/linux/mutex.h 2017-01-28 13:59:09.939656496 +0100
  6602. @@ -19,6 +19,17 @@
  6603. #include <asm/processor.h>
  6604. #include <linux/osq_lock.h>
  6605. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  6606. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  6607. + , .dep_map = { .name = #lockname }
  6608. +#else
  6609. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  6610. +#endif
  6611. +
  6612. +#ifdef CONFIG_PREEMPT_RT_FULL
  6613. +# include <linux/mutex_rt.h>
  6614. +#else
  6615. +
  6616. /*
  6617. * Simple, straightforward mutexes with strict semantics:
  6618. *
  6619. @@ -99,13 +110,6 @@
  6620. static inline void mutex_destroy(struct mutex *lock) {}
  6621. #endif
  6622. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  6623. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  6624. - , .dep_map = { .name = #lockname }
  6625. -#else
  6626. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  6627. -#endif
  6628. -
  6629. #define __MUTEX_INITIALIZER(lockname) \
  6630. { .count = ATOMIC_INIT(1) \
  6631. , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
  6632. @@ -173,6 +177,8 @@
  6633. extern int mutex_trylock(struct mutex *lock);
  6634. extern void mutex_unlock(struct mutex *lock);
  6635. +#endif /* !PREEMPT_RT_FULL */
  6636. +
  6637. extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
  6638. #endif /* __LINUX_MUTEX_H */
  6639. diff -Nur linux-4.9.6.orig/include/linux/mutex_rt.h linux-4.9.6/include/linux/mutex_rt.h
  6640. --- linux-4.9.6.orig/include/linux/mutex_rt.h 1970-01-01 01:00:00.000000000 +0100
  6641. +++ linux-4.9.6/include/linux/mutex_rt.h 2017-01-28 13:59:09.939656496 +0100
  6642. @@ -0,0 +1,84 @@
  6643. +#ifndef __LINUX_MUTEX_RT_H
  6644. +#define __LINUX_MUTEX_RT_H
  6645. +
  6646. +#ifndef __LINUX_MUTEX_H
  6647. +#error "Please include mutex.h"
  6648. +#endif
  6649. +
  6650. +#include <linux/rtmutex.h>
  6651. +
  6652. +/* FIXME: Just for __lockfunc */
  6653. +#include <linux/spinlock.h>
  6654. +
  6655. +struct mutex {
  6656. + struct rt_mutex lock;
  6657. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  6658. + struct lockdep_map dep_map;
  6659. +#endif
  6660. +};
  6661. +
  6662. +#define __MUTEX_INITIALIZER(mutexname) \
  6663. + { \
  6664. + .lock = __RT_MUTEX_INITIALIZER(mutexname.lock) \
  6665. + __DEP_MAP_MUTEX_INITIALIZER(mutexname) \
  6666. + }
  6667. +
  6668. +#define DEFINE_MUTEX(mutexname) \
  6669. + struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
  6670. +
  6671. +extern void __mutex_do_init(struct mutex *lock, const char *name, struct lock_class_key *key);
  6672. +extern void __lockfunc _mutex_lock(struct mutex *lock);
  6673. +extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
  6674. +extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
  6675. +extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
  6676. +extern void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
  6677. +extern int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
  6678. +extern int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass);
  6679. +extern int __lockfunc _mutex_trylock(struct mutex *lock);
  6680. +extern void __lockfunc _mutex_unlock(struct mutex *lock);
  6681. +
  6682. +#define mutex_is_locked(l) rt_mutex_is_locked(&(l)->lock)
  6683. +#define mutex_lock(l) _mutex_lock(l)
  6684. +#define mutex_lock_interruptible(l) _mutex_lock_interruptible(l)
  6685. +#define mutex_lock_killable(l) _mutex_lock_killable(l)
  6686. +#define mutex_trylock(l) _mutex_trylock(l)
  6687. +#define mutex_unlock(l) _mutex_unlock(l)
  6688. +#define mutex_destroy(l) rt_mutex_destroy(&(l)->lock)
  6689. +
  6690. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  6691. +# define mutex_lock_nested(l, s) _mutex_lock_nested(l, s)
  6692. +# define mutex_lock_interruptible_nested(l, s) \
  6693. + _mutex_lock_interruptible_nested(l, s)
  6694. +# define mutex_lock_killable_nested(l, s) \
  6695. + _mutex_lock_killable_nested(l, s)
  6696. +
  6697. +# define mutex_lock_nest_lock(lock, nest_lock) \
  6698. +do { \
  6699. + typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
  6700. + _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
  6701. +} while (0)
  6702. +
  6703. +#else
  6704. +# define mutex_lock_nested(l, s) _mutex_lock(l)
  6705. +# define mutex_lock_interruptible_nested(l, s) \
  6706. + _mutex_lock_interruptible(l)
  6707. +# define mutex_lock_killable_nested(l, s) \
  6708. + _mutex_lock_killable(l)
  6709. +# define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
  6710. +#endif
  6711. +
  6712. +# define mutex_init(mutex) \
  6713. +do { \
  6714. + static struct lock_class_key __key; \
  6715. + \
  6716. + rt_mutex_init(&(mutex)->lock); \
  6717. + __mutex_do_init((mutex), #mutex, &__key); \
  6718. +} while (0)
  6719. +
  6720. +# define __mutex_init(mutex, name, key) \
  6721. +do { \
  6722. + rt_mutex_init(&(mutex)->lock); \
  6723. + __mutex_do_init((mutex), name, key); \
  6724. +} while (0)
  6725. +
  6726. +#endif
  6727. diff -Nur linux-4.9.6.orig/include/linux/netdevice.h linux-4.9.6/include/linux/netdevice.h
  6728. --- linux-4.9.6.orig/include/linux/netdevice.h 2017-01-26 08:25:24.000000000 +0100
  6729. +++ linux-4.9.6/include/linux/netdevice.h 2017-01-28 13:59:09.939656496 +0100
  6730. @@ -396,7 +396,19 @@
  6731. typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
  6732. void __napi_schedule(struct napi_struct *n);
  6733. +
  6734. +/*
  6735. + * When PREEMPT_RT_FULL is defined, all device interrupt handlers
  6736. + * run as threads, and they can also be preempted (without PREEMPT_RT
  6737. + * interrupt threads can not be preempted). Which means that calling
  6738. + * __napi_schedule_irqoff() from an interrupt handler can be preempted
  6739. + * and can corrupt the napi->poll_list.
  6740. + */
  6741. +#ifdef CONFIG_PREEMPT_RT_FULL
  6742. +#define __napi_schedule_irqoff(n) __napi_schedule(n)
  6743. +#else
  6744. void __napi_schedule_irqoff(struct napi_struct *n);
  6745. +#endif
  6746. static inline bool napi_disable_pending(struct napi_struct *n)
  6747. {
  6748. @@ -2461,14 +2473,53 @@
  6749. void synchronize_net(void);
  6750. int init_dummy_netdev(struct net_device *dev);
  6751. -DECLARE_PER_CPU(int, xmit_recursion);
  6752. #define XMIT_RECURSION_LIMIT 10
  6753. +#ifdef CONFIG_PREEMPT_RT_FULL
  6754. +static inline int dev_recursion_level(void)
  6755. +{
  6756. + return current->xmit_recursion;
  6757. +}
  6758. +
  6759. +static inline int xmit_rec_read(void)
  6760. +{
  6761. + return current->xmit_recursion;
  6762. +}
  6763. +
  6764. +static inline void xmit_rec_inc(void)
  6765. +{
  6766. + current->xmit_recursion++;
  6767. +}
  6768. +
  6769. +static inline void xmit_rec_dec(void)
  6770. +{
  6771. + current->xmit_recursion--;
  6772. +}
  6773. +
  6774. +#else
  6775. +
  6776. +DECLARE_PER_CPU(int, xmit_recursion);
  6777. static inline int dev_recursion_level(void)
  6778. {
  6779. return this_cpu_read(xmit_recursion);
  6780. }
  6781. +static inline int xmit_rec_read(void)
  6782. +{
  6783. + return __this_cpu_read(xmit_recursion);
  6784. +}
  6785. +
  6786. +static inline void xmit_rec_inc(void)
  6787. +{
  6788. + __this_cpu_inc(xmit_recursion);
  6789. +}
  6790. +
  6791. +static inline void xmit_rec_dec(void)
  6792. +{
  6793. + __this_cpu_dec(xmit_recursion);
  6794. +}
  6795. +#endif
  6796. +
  6797. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  6798. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  6799. struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
  6800. @@ -2851,6 +2902,7 @@
  6801. unsigned int dropped;
  6802. struct sk_buff_head input_pkt_queue;
  6803. struct napi_struct backlog;
  6804. + struct sk_buff_head tofree_queue;
  6805. };
  6806. diff -Nur linux-4.9.6.orig/include/linux/netfilter/x_tables.h linux-4.9.6/include/linux/netfilter/x_tables.h
  6807. --- linux-4.9.6.orig/include/linux/netfilter/x_tables.h 2017-01-26 08:25:24.000000000 +0100
  6808. +++ linux-4.9.6/include/linux/netfilter/x_tables.h 2017-01-28 13:59:09.939656496 +0100
  6809. @@ -4,6 +4,7 @@
  6810. #include <linux/netdevice.h>
  6811. #include <linux/static_key.h>
  6812. +#include <linux/locallock.h>
  6813. #include <uapi/linux/netfilter/x_tables.h>
  6814. /* Test a struct->invflags and a boolean for inequality */
  6815. @@ -300,6 +301,8 @@
  6816. */
  6817. DECLARE_PER_CPU(seqcount_t, xt_recseq);
  6818. +DECLARE_LOCAL_IRQ_LOCK(xt_write_lock);
  6819. +
  6820. /* xt_tee_enabled - true if x_tables needs to handle reentrancy
  6821. *
  6822. * Enabled if current ip(6)tables ruleset has at least one -j TEE rule.
  6823. @@ -320,6 +323,9 @@
  6824. {
  6825. unsigned int addend;
  6826. + /* RT protection */
  6827. + local_lock(xt_write_lock);
  6828. +
  6829. /*
  6830. * Low order bit of sequence is set if we already
  6831. * called xt_write_recseq_begin().
  6832. @@ -350,6 +356,7 @@
  6833. /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */
  6834. smp_wmb();
  6835. __this_cpu_add(xt_recseq.sequence, addend);
  6836. + local_unlock(xt_write_lock);
  6837. }
  6838. /*
  6839. diff -Nur linux-4.9.6.orig/include/linux/nfs_fs.h linux-4.9.6/include/linux/nfs_fs.h
  6840. --- linux-4.9.6.orig/include/linux/nfs_fs.h 2017-01-26 08:25:24.000000000 +0100
  6841. +++ linux-4.9.6/include/linux/nfs_fs.h 2017-01-28 13:59:09.939656496 +0100
  6842. @@ -165,7 +165,11 @@
  6843. /* Readers: in-flight sillydelete RPC calls */
  6844. /* Writers: rmdir */
  6845. +#ifdef CONFIG_PREEMPT_RT_BASE
  6846. + struct semaphore rmdir_sem;
  6847. +#else
  6848. struct rw_semaphore rmdir_sem;
  6849. +#endif
  6850. #if IS_ENABLED(CONFIG_NFS_V4)
  6851. struct nfs4_cached_acl *nfs4_acl;
  6852. diff -Nur linux-4.9.6.orig/include/linux/nfs_xdr.h linux-4.9.6/include/linux/nfs_xdr.h
  6853. --- linux-4.9.6.orig/include/linux/nfs_xdr.h 2017-01-26 08:25:24.000000000 +0100
  6854. +++ linux-4.9.6/include/linux/nfs_xdr.h 2017-01-28 13:59:09.939656496 +0100
  6855. @@ -1490,7 +1490,7 @@
  6856. struct nfs_removeargs args;
  6857. struct nfs_removeres res;
  6858. struct dentry *dentry;
  6859. - wait_queue_head_t wq;
  6860. + struct swait_queue_head wq;
  6861. struct rpc_cred *cred;
  6862. struct nfs_fattr dir_attr;
  6863. long timeout;
  6864. diff -Nur linux-4.9.6.orig/include/linux/notifier.h linux-4.9.6/include/linux/notifier.h
  6865. --- linux-4.9.6.orig/include/linux/notifier.h 2017-01-26 08:25:24.000000000 +0100
  6866. +++ linux-4.9.6/include/linux/notifier.h 2017-01-28 13:59:09.939656496 +0100
  6867. @@ -6,7 +6,7 @@
  6868. *
  6869. * Alan Cox <Alan.Cox@linux.org>
  6870. */
  6871. -
  6872. +
  6873. #ifndef _LINUX_NOTIFIER_H
  6874. #define _LINUX_NOTIFIER_H
  6875. #include <linux/errno.h>
  6876. @@ -42,9 +42,7 @@
  6877. * in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
  6878. * As compensation, srcu_notifier_chain_unregister() is rather expensive.
  6879. * SRCU notifier chains should be used when the chain will be called very
  6880. - * often but notifier_blocks will seldom be removed. Also, SRCU notifier
  6881. - * chains are slightly more difficult to use because they require special
  6882. - * runtime initialization.
  6883. + * often but notifier_blocks will seldom be removed.
  6884. */
  6885. struct notifier_block;
  6886. @@ -90,7 +88,7 @@
  6887. (name)->head = NULL; \
  6888. } while (0)
  6889. -/* srcu_notifier_heads must be initialized and cleaned up dynamically */
  6890. +/* srcu_notifier_heads must be cleaned up dynamically */
  6891. extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
  6892. #define srcu_cleanup_notifier_head(name) \
  6893. cleanup_srcu_struct(&(name)->srcu);
  6894. @@ -103,7 +101,13 @@
  6895. .head = NULL }
  6896. #define RAW_NOTIFIER_INIT(name) { \
  6897. .head = NULL }
  6898. -/* srcu_notifier_heads cannot be initialized statically */
  6899. +
  6900. +#define SRCU_NOTIFIER_INIT(name, pcpu) \
  6901. + { \
  6902. + .mutex = __MUTEX_INITIALIZER(name.mutex), \
  6903. + .head = NULL, \
  6904. + .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
  6905. + }
  6906. #define ATOMIC_NOTIFIER_HEAD(name) \
  6907. struct atomic_notifier_head name = \
  6908. @@ -115,6 +119,18 @@
  6909. struct raw_notifier_head name = \
  6910. RAW_NOTIFIER_INIT(name)
  6911. +#define _SRCU_NOTIFIER_HEAD(name, mod) \
  6912. + static DEFINE_PER_CPU(struct srcu_struct_array, \
  6913. + name##_head_srcu_array); \
  6914. + mod struct srcu_notifier_head name = \
  6915. + SRCU_NOTIFIER_INIT(name, name##_head_srcu_array)
  6916. +
  6917. +#define SRCU_NOTIFIER_HEAD(name) \
  6918. + _SRCU_NOTIFIER_HEAD(name, )
  6919. +
  6920. +#define SRCU_NOTIFIER_HEAD_STATIC(name) \
  6921. + _SRCU_NOTIFIER_HEAD(name, static)
  6922. +
  6923. #ifdef __KERNEL__
  6924. extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
  6925. @@ -184,12 +200,12 @@
  6926. /*
  6927. * Declared notifiers so far. I can imagine quite a few more chains
  6928. - * over time (eg laptop power reset chains, reboot chain (to clean
  6929. + * over time (eg laptop power reset chains, reboot chain (to clean
  6930. * device units up), device [un]mount chain, module load/unload chain,
  6931. - * low memory chain, screenblank chain (for plug in modular screenblankers)
  6932. + * low memory chain, screenblank chain (for plug in modular screenblankers)
  6933. * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
  6934. */
  6935. -
  6936. +
  6937. /* CPU notfiers are defined in include/linux/cpu.h. */
  6938. /* netdevice notifiers are defined in include/linux/netdevice.h */
  6939. diff -Nur linux-4.9.6.orig/include/linux/percpu.h linux-4.9.6/include/linux/percpu.h
  6940. --- linux-4.9.6.orig/include/linux/percpu.h 2017-01-26 08:25:24.000000000 +0100
  6941. +++ linux-4.9.6/include/linux/percpu.h 2017-01-28 13:59:09.939656496 +0100
  6942. @@ -18,6 +18,35 @@
  6943. #define PERCPU_MODULE_RESERVE 0
  6944. #endif
  6945. +#ifdef CONFIG_PREEMPT_RT_FULL
  6946. +
  6947. +#define get_local_var(var) (*({ \
  6948. + migrate_disable(); \
  6949. + this_cpu_ptr(&var); }))
  6950. +
  6951. +#define put_local_var(var) do { \
  6952. + (void)&(var); \
  6953. + migrate_enable(); \
  6954. +} while (0)
  6955. +
  6956. +# define get_local_ptr(var) ({ \
  6957. + migrate_disable(); \
  6958. + this_cpu_ptr(var); })
  6959. +
  6960. +# define put_local_ptr(var) do { \
  6961. + (void)(var); \
  6962. + migrate_enable(); \
  6963. +} while (0)
  6964. +
  6965. +#else
  6966. +
  6967. +#define get_local_var(var) get_cpu_var(var)
  6968. +#define put_local_var(var) put_cpu_var(var)
  6969. +#define get_local_ptr(var) get_cpu_ptr(var)
  6970. +#define put_local_ptr(var) put_cpu_ptr(var)
  6971. +
  6972. +#endif
  6973. +
  6974. /* minimum unit size, also is the maximum supported allocation size */
  6975. #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
  6976. diff -Nur linux-4.9.6.orig/include/linux/percpu-rwsem.h linux-4.9.6/include/linux/percpu-rwsem.h
  6977. --- linux-4.9.6.orig/include/linux/percpu-rwsem.h 2017-01-26 08:25:24.000000000 +0100
  6978. +++ linux-4.9.6/include/linux/percpu-rwsem.h 2017-01-28 13:59:09.939656496 +0100
  6979. @@ -4,7 +4,7 @@
  6980. #include <linux/atomic.h>
  6981. #include <linux/rwsem.h>
  6982. #include <linux/percpu.h>
  6983. -#include <linux/wait.h>
  6984. +#include <linux/swait.h>
  6985. #include <linux/rcu_sync.h>
  6986. #include <linux/lockdep.h>
  6987. @@ -12,7 +12,7 @@
  6988. struct rcu_sync rss;
  6989. unsigned int __percpu *read_count;
  6990. struct rw_semaphore rw_sem;
  6991. - wait_queue_head_t writer;
  6992. + struct swait_queue_head writer;
  6993. int readers_block;
  6994. };
  6995. @@ -22,13 +22,13 @@
  6996. .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \
  6997. .read_count = &__percpu_rwsem_rc_##name, \
  6998. .rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \
  6999. - .writer = __WAIT_QUEUE_HEAD_INITIALIZER(name.writer), \
  7000. + .writer = __SWAIT_QUEUE_HEAD_INITIALIZER(name.writer), \
  7001. }
  7002. extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
  7003. extern void __percpu_up_read(struct percpu_rw_semaphore *);
  7004. -static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *sem)
  7005. +static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
  7006. {
  7007. might_sleep();
  7008. @@ -46,16 +46,10 @@
  7009. __this_cpu_inc(*sem->read_count);
  7010. if (unlikely(!rcu_sync_is_idle(&sem->rss)))
  7011. __percpu_down_read(sem, false); /* Unconditional memory barrier */
  7012. - barrier();
  7013. /*
  7014. - * The barrier() prevents the compiler from
  7015. + * The preempt_enable() prevents the compiler from
  7016. * bleeding the critical section out.
  7017. */
  7018. -}
  7019. -
  7020. -static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
  7021. -{
  7022. - percpu_down_read_preempt_disable(sem);
  7023. preempt_enable();
  7024. }
  7025. @@ -82,13 +76,9 @@
  7026. return ret;
  7027. }
  7028. -static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
  7029. +static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
  7030. {
  7031. - /*
  7032. - * The barrier() prevents the compiler from
  7033. - * bleeding the critical section out.
  7034. - */
  7035. - barrier();
  7036. + preempt_disable();
  7037. /*
  7038. * Same as in percpu_down_read().
  7039. */
  7040. @@ -101,12 +91,6 @@
  7041. rwsem_release(&sem->rw_sem.dep_map, 1, _RET_IP_);
  7042. }
  7043. -static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
  7044. -{
  7045. - preempt_disable();
  7046. - percpu_up_read_preempt_enable(sem);
  7047. -}
  7048. -
  7049. extern void percpu_down_write(struct percpu_rw_semaphore *);
  7050. extern void percpu_up_write(struct percpu_rw_semaphore *);
  7051. diff -Nur linux-4.9.6.orig/include/linux/pid.h linux-4.9.6/include/linux/pid.h
  7052. --- linux-4.9.6.orig/include/linux/pid.h 2017-01-26 08:25:24.000000000 +0100
  7053. +++ linux-4.9.6/include/linux/pid.h 2017-01-28 13:59:09.939656496 +0100
  7054. @@ -2,6 +2,7 @@
  7055. #define _LINUX_PID_H
  7056. #include <linux/rcupdate.h>
  7057. +#include <linux/atomic.h>
  7058. enum pid_type
  7059. {
  7060. diff -Nur linux-4.9.6.orig/include/linux/preempt.h linux-4.9.6/include/linux/preempt.h
  7061. --- linux-4.9.6.orig/include/linux/preempt.h 2017-01-26 08:25:24.000000000 +0100
  7062. +++ linux-4.9.6/include/linux/preempt.h 2017-01-28 13:59:09.939656496 +0100
  7063. @@ -50,7 +50,11 @@
  7064. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  7065. #define NMI_OFFSET (1UL << NMI_SHIFT)
  7066. -#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  7067. +#ifndef CONFIG_PREEMPT_RT_FULL
  7068. +# define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  7069. +#else
  7070. +# define SOFTIRQ_DISABLE_OFFSET (0)
  7071. +#endif
  7072. /* We use the MSB mostly because its available */
  7073. #define PREEMPT_NEED_RESCHED 0x80000000
  7074. @@ -59,9 +63,15 @@
  7075. #include <asm/preempt.h>
  7076. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  7077. -#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  7078. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
  7079. | NMI_MASK))
  7080. +#ifndef CONFIG_PREEMPT_RT_FULL
  7081. +# define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  7082. +# define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  7083. +#else
  7084. +# define softirq_count() (0UL)
  7085. +extern int in_serving_softirq(void);
  7086. +#endif
  7087. /*
  7088. * Are we doing bottom half or hardware interrupt processing?
  7089. @@ -72,7 +82,6 @@
  7090. #define in_irq() (hardirq_count())
  7091. #define in_softirq() (softirq_count())
  7092. #define in_interrupt() (irq_count())
  7093. -#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  7094. /*
  7095. * Are we in NMI context?
  7096. @@ -91,7 +100,11 @@
  7097. /*
  7098. * The preempt_count offset after spin_lock()
  7099. */
  7100. +#if !defined(CONFIG_PREEMPT_RT_FULL)
  7101. #define PREEMPT_LOCK_OFFSET PREEMPT_DISABLE_OFFSET
  7102. +#else
  7103. +#define PREEMPT_LOCK_OFFSET 0
  7104. +#endif
  7105. /*
  7106. * The preempt_count offset needed for things like:
  7107. @@ -140,6 +153,20 @@
  7108. #define preempt_count_inc() preempt_count_add(1)
  7109. #define preempt_count_dec() preempt_count_sub(1)
  7110. +#ifdef CONFIG_PREEMPT_LAZY
  7111. +#define add_preempt_lazy_count(val) do { preempt_lazy_count() += (val); } while (0)
  7112. +#define sub_preempt_lazy_count(val) do { preempt_lazy_count() -= (val); } while (0)
  7113. +#define inc_preempt_lazy_count() add_preempt_lazy_count(1)
  7114. +#define dec_preempt_lazy_count() sub_preempt_lazy_count(1)
  7115. +#define preempt_lazy_count() (current_thread_info()->preempt_lazy_count)
  7116. +#else
  7117. +#define add_preempt_lazy_count(val) do { } while (0)
  7118. +#define sub_preempt_lazy_count(val) do { } while (0)
  7119. +#define inc_preempt_lazy_count() do { } while (0)
  7120. +#define dec_preempt_lazy_count() do { } while (0)
  7121. +#define preempt_lazy_count() (0)
  7122. +#endif
  7123. +
  7124. #ifdef CONFIG_PREEMPT_COUNT
  7125. #define preempt_disable() \
  7126. @@ -148,13 +175,25 @@
  7127. barrier(); \
  7128. } while (0)
  7129. +#define preempt_lazy_disable() \
  7130. +do { \
  7131. + inc_preempt_lazy_count(); \
  7132. + barrier(); \
  7133. +} while (0)
  7134. +
  7135. #define sched_preempt_enable_no_resched() \
  7136. do { \
  7137. barrier(); \
  7138. preempt_count_dec(); \
  7139. } while (0)
  7140. -#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  7141. +#ifdef CONFIG_PREEMPT_RT_BASE
  7142. +# define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  7143. +# define preempt_check_resched_rt() preempt_check_resched()
  7144. +#else
  7145. +# define preempt_enable_no_resched() preempt_enable()
  7146. +# define preempt_check_resched_rt() barrier();
  7147. +#endif
  7148. #define preemptible() (preempt_count() == 0 && !irqs_disabled())
  7149. @@ -179,6 +218,13 @@
  7150. __preempt_schedule(); \
  7151. } while (0)
  7152. +#define preempt_lazy_enable() \
  7153. +do { \
  7154. + dec_preempt_lazy_count(); \
  7155. + barrier(); \
  7156. + preempt_check_resched(); \
  7157. +} while (0)
  7158. +
  7159. #else /* !CONFIG_PREEMPT */
  7160. #define preempt_enable() \
  7161. do { \
  7162. @@ -224,6 +270,7 @@
  7163. #define preempt_disable_notrace() barrier()
  7164. #define preempt_enable_no_resched_notrace() barrier()
  7165. #define preempt_enable_notrace() barrier()
  7166. +#define preempt_check_resched_rt() barrier()
  7167. #define preemptible() 0
  7168. #endif /* CONFIG_PREEMPT_COUNT */
  7169. @@ -244,10 +291,31 @@
  7170. } while (0)
  7171. #define preempt_fold_need_resched() \
  7172. do { \
  7173. - if (tif_need_resched()) \
  7174. + if (tif_need_resched_now()) \
  7175. set_preempt_need_resched(); \
  7176. } while (0)
  7177. +#ifdef CONFIG_PREEMPT_RT_FULL
  7178. +# define preempt_disable_rt() preempt_disable()
  7179. +# define preempt_enable_rt() preempt_enable()
  7180. +# define preempt_disable_nort() barrier()
  7181. +# define preempt_enable_nort() barrier()
  7182. +# ifdef CONFIG_SMP
  7183. + extern void migrate_disable(void);
  7184. + extern void migrate_enable(void);
  7185. +# else /* CONFIG_SMP */
  7186. +# define migrate_disable() barrier()
  7187. +# define migrate_enable() barrier()
  7188. +# endif /* CONFIG_SMP */
  7189. +#else
  7190. +# define preempt_disable_rt() barrier()
  7191. +# define preempt_enable_rt() barrier()
  7192. +# define preempt_disable_nort() preempt_disable()
  7193. +# define preempt_enable_nort() preempt_enable()
  7194. +# define migrate_disable() preempt_disable()
  7195. +# define migrate_enable() preempt_enable()
  7196. +#endif
  7197. +
  7198. #ifdef CONFIG_PREEMPT_NOTIFIERS
  7199. struct preempt_notifier;
  7200. diff -Nur linux-4.9.6.orig/include/linux/printk.h linux-4.9.6/include/linux/printk.h
  7201. --- linux-4.9.6.orig/include/linux/printk.h 2017-01-26 08:25:24.000000000 +0100
  7202. +++ linux-4.9.6/include/linux/printk.h 2017-01-28 13:59:09.939656496 +0100
  7203. @@ -126,9 +126,11 @@
  7204. #ifdef CONFIG_EARLY_PRINTK
  7205. extern asmlinkage __printf(1, 2)
  7206. void early_printk(const char *fmt, ...);
  7207. +extern void printk_kill(void);
  7208. #else
  7209. static inline __printf(1, 2) __cold
  7210. void early_printk(const char *s, ...) { }
  7211. +static inline void printk_kill(void) { }
  7212. #endif
  7213. #ifdef CONFIG_PRINTK_NMI
  7214. diff -Nur linux-4.9.6.orig/include/linux/radix-tree.h linux-4.9.6/include/linux/radix-tree.h
  7215. --- linux-4.9.6.orig/include/linux/radix-tree.h 2017-01-26 08:25:24.000000000 +0100
  7216. +++ linux-4.9.6/include/linux/radix-tree.h 2017-01-28 13:59:09.939656496 +0100
  7217. @@ -289,9 +289,19 @@
  7218. unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  7219. void ***results, unsigned long *indices,
  7220. unsigned long first_index, unsigned int max_items);
  7221. +#ifdef CONFIG_PREEMPT_RT_FULL
  7222. +static inline int radix_tree_preload(gfp_t gm) { return 0; }
  7223. +static inline int radix_tree_maybe_preload(gfp_t gfp_mask) { return 0; }
  7224. +static inline int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
  7225. +{
  7226. + return 0;
  7227. +};
  7228. +
  7229. +#else
  7230. int radix_tree_preload(gfp_t gfp_mask);
  7231. int radix_tree_maybe_preload(gfp_t gfp_mask);
  7232. int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order);
  7233. +#endif
  7234. void radix_tree_init(void);
  7235. void *radix_tree_tag_set(struct radix_tree_root *root,
  7236. unsigned long index, unsigned int tag);
  7237. @@ -316,7 +326,7 @@
  7238. static inline void radix_tree_preload_end(void)
  7239. {
  7240. - preempt_enable();
  7241. + preempt_enable_nort();
  7242. }
  7243. /**
  7244. diff -Nur linux-4.9.6.orig/include/linux/random.h linux-4.9.6/include/linux/random.h
  7245. --- linux-4.9.6.orig/include/linux/random.h 2017-01-26 08:25:24.000000000 +0100
  7246. +++ linux-4.9.6/include/linux/random.h 2017-01-28 13:59:09.943656649 +0100
  7247. @@ -31,7 +31,7 @@
  7248. extern void add_input_randomness(unsigned int type, unsigned int code,
  7249. unsigned int value) __latent_entropy;
  7250. -extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
  7251. +extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip) __latent_entropy;
  7252. extern void get_random_bytes(void *buf, int nbytes);
  7253. extern int add_random_ready_callback(struct random_ready_callback *rdy);
  7254. diff -Nur linux-4.9.6.orig/include/linux/rbtree_augmented.h linux-4.9.6/include/linux/rbtree_augmented.h
  7255. --- linux-4.9.6.orig/include/linux/rbtree_augmented.h 2017-01-26 08:25:24.000000000 +0100
  7256. +++ linux-4.9.6/include/linux/rbtree_augmented.h 2017-01-28 13:59:09.943656649 +0100
  7257. @@ -26,6 +26,7 @@
  7258. #include <linux/compiler.h>
  7259. #include <linux/rbtree.h>
  7260. +#include <linux/rcupdate.h>
  7261. /*
  7262. * Please note - only struct rb_augment_callbacks and the prototypes for
  7263. diff -Nur linux-4.9.6.orig/include/linux/rbtree.h linux-4.9.6/include/linux/rbtree.h
  7264. --- linux-4.9.6.orig/include/linux/rbtree.h 2017-01-26 08:25:24.000000000 +0100
  7265. +++ linux-4.9.6/include/linux/rbtree.h 2017-01-28 13:59:09.943656649 +0100
  7266. @@ -31,7 +31,7 @@
  7267. #include <linux/kernel.h>
  7268. #include <linux/stddef.h>
  7269. -#include <linux/rcupdate.h>
  7270. +#include <linux/rcu_assign_pointer.h>
  7271. struct rb_node {
  7272. unsigned long __rb_parent_color;
  7273. diff -Nur linux-4.9.6.orig/include/linux/rcu_assign_pointer.h linux-4.9.6/include/linux/rcu_assign_pointer.h
  7274. --- linux-4.9.6.orig/include/linux/rcu_assign_pointer.h 1970-01-01 01:00:00.000000000 +0100
  7275. +++ linux-4.9.6/include/linux/rcu_assign_pointer.h 2017-01-28 13:59:09.943656649 +0100
  7276. @@ -0,0 +1,54 @@
  7277. +#ifndef __LINUX_RCU_ASSIGN_POINTER_H__
  7278. +#define __LINUX_RCU_ASSIGN_POINTER_H__
  7279. +#include <linux/compiler.h>
  7280. +#include <asm/barrier.h>
  7281. +
  7282. +/**
  7283. + * RCU_INITIALIZER() - statically initialize an RCU-protected global variable
  7284. + * @v: The value to statically initialize with.
  7285. + */
  7286. +#define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)
  7287. +
  7288. +/**
  7289. + * rcu_assign_pointer() - assign to RCU-protected pointer
  7290. + * @p: pointer to assign to
  7291. + * @v: value to assign (publish)
  7292. + *
  7293. + * Assigns the specified value to the specified RCU-protected
  7294. + * pointer, ensuring that any concurrent RCU readers will see
  7295. + * any prior initialization.
  7296. + *
  7297. + * Inserts memory barriers on architectures that require them
  7298. + * (which is most of them), and also prevents the compiler from
  7299. + * reordering the code that initializes the structure after the pointer
  7300. + * assignment. More importantly, this call documents which pointers
  7301. + * will be dereferenced by RCU read-side code.
  7302. + *
  7303. + * In some special cases, you may use RCU_INIT_POINTER() instead
  7304. + * of rcu_assign_pointer(). RCU_INIT_POINTER() is a bit faster due
  7305. + * to the fact that it does not constrain either the CPU or the compiler.
  7306. + * That said, using RCU_INIT_POINTER() when you should have used
  7307. + * rcu_assign_pointer() is a very bad thing that results in
  7308. + * impossible-to-diagnose memory corruption. So please be careful.
  7309. + * See the RCU_INIT_POINTER() comment header for details.
  7310. + *
  7311. + * Note that rcu_assign_pointer() evaluates each of its arguments only
  7312. + * once, appearances notwithstanding. One of the "extra" evaluations
  7313. + * is in typeof() and the other visible only to sparse (__CHECKER__),
  7314. + * neither of which actually execute the argument. As with most cpp
  7315. + * macros, this execute-arguments-only-once property is important, so
  7316. + * please be careful when making changes to rcu_assign_pointer() and the
  7317. + * other macros that it invokes.
  7318. + */
  7319. +#define rcu_assign_pointer(p, v) \
  7320. +({ \
  7321. + uintptr_t _r_a_p__v = (uintptr_t)(v); \
  7322. + \
  7323. + if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \
  7324. + WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \
  7325. + else \
  7326. + smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
  7327. + _r_a_p__v; \
  7328. +})
  7329. +
  7330. +#endif
  7331. diff -Nur linux-4.9.6.orig/include/linux/rcupdate.h linux-4.9.6/include/linux/rcupdate.h
  7332. --- linux-4.9.6.orig/include/linux/rcupdate.h 2017-01-26 08:25:24.000000000 +0100
  7333. +++ linux-4.9.6/include/linux/rcupdate.h 2017-01-28 13:59:09.943656649 +0100
  7334. @@ -46,6 +46,7 @@
  7335. #include <linux/compiler.h>
  7336. #include <linux/ktime.h>
  7337. #include <linux/irqflags.h>
  7338. +#include <linux/rcu_assign_pointer.h>
  7339. #include <asm/barrier.h>
  7340. @@ -178,6 +179,9 @@
  7341. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  7342. +#ifdef CONFIG_PREEMPT_RT_FULL
  7343. +#define call_rcu_bh call_rcu
  7344. +#else
  7345. /**
  7346. * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
  7347. * @head: structure to be used for queueing the RCU updates.
  7348. @@ -201,6 +205,7 @@
  7349. */
  7350. void call_rcu_bh(struct rcu_head *head,
  7351. rcu_callback_t func);
  7352. +#endif
  7353. /**
  7354. * call_rcu_sched() - Queue an RCU for invocation after sched grace period.
  7355. @@ -301,6 +306,11 @@
  7356. * types of kernel builds, the rcu_read_lock() nesting depth is unknowable.
  7357. */
  7358. #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
  7359. +#ifndef CONFIG_PREEMPT_RT_FULL
  7360. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  7361. +#else
  7362. +static inline int sched_rcu_preempt_depth(void) { return 0; }
  7363. +#endif
  7364. #else /* #ifdef CONFIG_PREEMPT_RCU */
  7365. @@ -326,6 +336,8 @@
  7366. return 0;
  7367. }
  7368. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  7369. +
  7370. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  7371. /* Internal to kernel */
  7372. @@ -505,7 +517,14 @@
  7373. int debug_lockdep_rcu_enabled(void);
  7374. int rcu_read_lock_held(void);
  7375. +#ifdef CONFIG_PREEMPT_RT_FULL
  7376. +static inline int rcu_read_lock_bh_held(void)
  7377. +{
  7378. + return rcu_read_lock_held();
  7379. +}
  7380. +#else
  7381. int rcu_read_lock_bh_held(void);
  7382. +#endif
  7383. /**
  7384. * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
  7385. @@ -626,54 +645,6 @@
  7386. })
  7387. /**
  7388. - * RCU_INITIALIZER() - statically initialize an RCU-protected global variable
  7389. - * @v: The value to statically initialize with.
  7390. - */
  7391. -#define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)
  7392. -
  7393. -/**
  7394. - * rcu_assign_pointer() - assign to RCU-protected pointer
  7395. - * @p: pointer to assign to
  7396. - * @v: value to assign (publish)
  7397. - *
  7398. - * Assigns the specified value to the specified RCU-protected
  7399. - * pointer, ensuring that any concurrent RCU readers will see
  7400. - * any prior initialization.
  7401. - *
  7402. - * Inserts memory barriers on architectures that require them
  7403. - * (which is most of them), and also prevents the compiler from
  7404. - * reordering the code that initializes the structure after the pointer
  7405. - * assignment. More importantly, this call documents which pointers
  7406. - * will be dereferenced by RCU read-side code.
  7407. - *
  7408. - * In some special cases, you may use RCU_INIT_POINTER() instead
  7409. - * of rcu_assign_pointer(). RCU_INIT_POINTER() is a bit faster due
  7410. - * to the fact that it does not constrain either the CPU or the compiler.
  7411. - * That said, using RCU_INIT_POINTER() when you should have used
  7412. - * rcu_assign_pointer() is a very bad thing that results in
  7413. - * impossible-to-diagnose memory corruption. So please be careful.
  7414. - * See the RCU_INIT_POINTER() comment header for details.
  7415. - *
  7416. - * Note that rcu_assign_pointer() evaluates each of its arguments only
  7417. - * once, appearances notwithstanding. One of the "extra" evaluations
  7418. - * is in typeof() and the other visible only to sparse (__CHECKER__),
  7419. - * neither of which actually execute the argument. As with most cpp
  7420. - * macros, this execute-arguments-only-once property is important, so
  7421. - * please be careful when making changes to rcu_assign_pointer() and the
  7422. - * other macros that it invokes.
  7423. - */
  7424. -#define rcu_assign_pointer(p, v) \
  7425. -({ \
  7426. - uintptr_t _r_a_p__v = (uintptr_t)(v); \
  7427. - \
  7428. - if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \
  7429. - WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \
  7430. - else \
  7431. - smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
  7432. - _r_a_p__v; \
  7433. -})
  7434. -
  7435. -/**
  7436. * rcu_access_pointer() - fetch RCU pointer with no dereferencing
  7437. * @p: The pointer to read
  7438. *
  7439. @@ -951,10 +922,14 @@
  7440. static inline void rcu_read_lock_bh(void)
  7441. {
  7442. local_bh_disable();
  7443. +#ifdef CONFIG_PREEMPT_RT_FULL
  7444. + rcu_read_lock();
  7445. +#else
  7446. __acquire(RCU_BH);
  7447. rcu_lock_acquire(&rcu_bh_lock_map);
  7448. RCU_LOCKDEP_WARN(!rcu_is_watching(),
  7449. "rcu_read_lock_bh() used illegally while idle");
  7450. +#endif
  7451. }
  7452. /*
  7453. @@ -964,10 +939,14 @@
  7454. */
  7455. static inline void rcu_read_unlock_bh(void)
  7456. {
  7457. +#ifdef CONFIG_PREEMPT_RT_FULL
  7458. + rcu_read_unlock();
  7459. +#else
  7460. RCU_LOCKDEP_WARN(!rcu_is_watching(),
  7461. "rcu_read_unlock_bh() used illegally while idle");
  7462. rcu_lock_release(&rcu_bh_lock_map);
  7463. __release(RCU_BH);
  7464. +#endif
  7465. local_bh_enable();
  7466. }
  7467. diff -Nur linux-4.9.6.orig/include/linux/rcutree.h linux-4.9.6/include/linux/rcutree.h
  7468. --- linux-4.9.6.orig/include/linux/rcutree.h 2017-01-26 08:25:24.000000000 +0100
  7469. +++ linux-4.9.6/include/linux/rcutree.h 2017-01-28 13:59:09.943656649 +0100
  7470. @@ -44,7 +44,11 @@
  7471. rcu_note_context_switch();
  7472. }
  7473. +#ifdef CONFIG_PREEMPT_RT_FULL
  7474. +# define synchronize_rcu_bh synchronize_rcu
  7475. +#else
  7476. void synchronize_rcu_bh(void);
  7477. +#endif
  7478. void synchronize_sched_expedited(void);
  7479. void synchronize_rcu_expedited(void);
  7480. @@ -72,7 +76,11 @@
  7481. }
  7482. void rcu_barrier(void);
  7483. +#ifdef CONFIG_PREEMPT_RT_FULL
  7484. +# define rcu_barrier_bh rcu_barrier
  7485. +#else
  7486. void rcu_barrier_bh(void);
  7487. +#endif
  7488. void rcu_barrier_sched(void);
  7489. unsigned long get_state_synchronize_rcu(void);
  7490. void cond_synchronize_rcu(unsigned long oldstate);
  7491. @@ -82,17 +90,14 @@
  7492. extern unsigned long rcutorture_testseq;
  7493. extern unsigned long rcutorture_vernum;
  7494. unsigned long rcu_batches_started(void);
  7495. -unsigned long rcu_batches_started_bh(void);
  7496. unsigned long rcu_batches_started_sched(void);
  7497. unsigned long rcu_batches_completed(void);
  7498. -unsigned long rcu_batches_completed_bh(void);
  7499. unsigned long rcu_batches_completed_sched(void);
  7500. unsigned long rcu_exp_batches_completed(void);
  7501. unsigned long rcu_exp_batches_completed_sched(void);
  7502. void show_rcu_gp_kthreads(void);
  7503. void rcu_force_quiescent_state(void);
  7504. -void rcu_bh_force_quiescent_state(void);
  7505. void rcu_sched_force_quiescent_state(void);
  7506. void rcu_idle_enter(void);
  7507. @@ -109,6 +114,16 @@
  7508. bool rcu_is_watching(void);
  7509. +#ifndef CONFIG_PREEMPT_RT_FULL
  7510. +void rcu_bh_force_quiescent_state(void);
  7511. +unsigned long rcu_batches_started_bh(void);
  7512. +unsigned long rcu_batches_completed_bh(void);
  7513. +#else
  7514. +# define rcu_bh_force_quiescent_state rcu_force_quiescent_state
  7515. +# define rcu_batches_completed_bh rcu_batches_completed
  7516. +# define rcu_batches_started_bh rcu_batches_completed
  7517. +#endif
  7518. +
  7519. void rcu_all_qs(void);
  7520. /* RCUtree hotplug events */
  7521. diff -Nur linux-4.9.6.orig/include/linux/rtmutex.h linux-4.9.6/include/linux/rtmutex.h
  7522. --- linux-4.9.6.orig/include/linux/rtmutex.h 2017-01-26 08:25:24.000000000 +0100
  7523. +++ linux-4.9.6/include/linux/rtmutex.h 2017-01-28 13:59:09.943656649 +0100
  7524. @@ -13,11 +13,15 @@
  7525. #define __LINUX_RT_MUTEX_H
  7526. #include <linux/linkage.h>
  7527. +#include <linux/spinlock_types_raw.h>
  7528. #include <linux/rbtree.h>
  7529. -#include <linux/spinlock_types.h>
  7530. extern int max_lock_depth; /* for sysctl */
  7531. +#ifdef CONFIG_DEBUG_MUTEXES
  7532. +#include <linux/debug_locks.h>
  7533. +#endif
  7534. +
  7535. /**
  7536. * The rt_mutex structure
  7537. *
  7538. @@ -31,8 +35,8 @@
  7539. struct rb_root waiters;
  7540. struct rb_node *waiters_leftmost;
  7541. struct task_struct *owner;
  7542. -#ifdef CONFIG_DEBUG_RT_MUTEXES
  7543. int save_state;
  7544. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  7545. const char *name, *file;
  7546. int line;
  7547. void *magic;
  7548. @@ -55,22 +59,33 @@
  7549. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  7550. #endif
  7551. +# define rt_mutex_init(mutex) \
  7552. + do { \
  7553. + raw_spin_lock_init(&(mutex)->wait_lock); \
  7554. + __rt_mutex_init(mutex, #mutex); \
  7555. + } while (0)
  7556. +
  7557. #ifdef CONFIG_DEBUG_RT_MUTEXES
  7558. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  7559. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  7560. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
  7561. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  7562. #else
  7563. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  7564. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  7565. # define rt_mutex_debug_task_free(t) do { } while (0)
  7566. #endif
  7567. -#define __RT_MUTEX_INITIALIZER(mutexname) \
  7568. - { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  7569. +#define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  7570. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  7571. , .waiters = RB_ROOT \
  7572. , .owner = NULL \
  7573. - __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  7574. + __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  7575. +
  7576. +#define __RT_MUTEX_INITIALIZER(mutexname) \
  7577. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
  7578. +
  7579. +#define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
  7580. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  7581. + , .save_state = 1 }
  7582. #define DEFINE_RT_MUTEX(mutexname) \
  7583. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  7584. @@ -91,6 +106,7 @@
  7585. extern void rt_mutex_lock(struct rt_mutex *lock);
  7586. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
  7587. +extern int rt_mutex_lock_killable(struct rt_mutex *lock);
  7588. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  7589. struct hrtimer_sleeper *timeout);
  7590. diff -Nur linux-4.9.6.orig/include/linux/rwlock_rt.h linux-4.9.6/include/linux/rwlock_rt.h
  7591. --- linux-4.9.6.orig/include/linux/rwlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  7592. +++ linux-4.9.6/include/linux/rwlock_rt.h 2017-01-28 13:59:09.943656649 +0100
  7593. @@ -0,0 +1,99 @@
  7594. +#ifndef __LINUX_RWLOCK_RT_H
  7595. +#define __LINUX_RWLOCK_RT_H
  7596. +
  7597. +#ifndef __LINUX_SPINLOCK_H
  7598. +#error Do not include directly. Use spinlock.h
  7599. +#endif
  7600. +
  7601. +#define rwlock_init(rwl) \
  7602. +do { \
  7603. + static struct lock_class_key __key; \
  7604. + \
  7605. + rt_mutex_init(&(rwl)->lock); \
  7606. + __rt_rwlock_init(rwl, #rwl, &__key); \
  7607. +} while (0)
  7608. +
  7609. +extern void __lockfunc rt_write_lock(rwlock_t *rwlock);
  7610. +extern void __lockfunc rt_read_lock(rwlock_t *rwlock);
  7611. +extern int __lockfunc rt_write_trylock(rwlock_t *rwlock);
  7612. +extern int __lockfunc rt_write_trylock_irqsave(rwlock_t *trylock, unsigned long *flags);
  7613. +extern int __lockfunc rt_read_trylock(rwlock_t *rwlock);
  7614. +extern void __lockfunc rt_write_unlock(rwlock_t *rwlock);
  7615. +extern void __lockfunc rt_read_unlock(rwlock_t *rwlock);
  7616. +extern unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock);
  7617. +extern unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock);
  7618. +extern void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key);
  7619. +
  7620. +#define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
  7621. +#define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
  7622. +
  7623. +#define write_trylock_irqsave(lock, flags) \
  7624. + __cond_lock(lock, rt_write_trylock_irqsave(lock, &flags))
  7625. +
  7626. +#define read_lock_irqsave(lock, flags) \
  7627. + do { \
  7628. + typecheck(unsigned long, flags); \
  7629. + flags = rt_read_lock_irqsave(lock); \
  7630. + } while (0)
  7631. +
  7632. +#define write_lock_irqsave(lock, flags) \
  7633. + do { \
  7634. + typecheck(unsigned long, flags); \
  7635. + flags = rt_write_lock_irqsave(lock); \
  7636. + } while (0)
  7637. +
  7638. +#define read_lock(lock) rt_read_lock(lock)
  7639. +
  7640. +#define read_lock_bh(lock) \
  7641. + do { \
  7642. + local_bh_disable(); \
  7643. + rt_read_lock(lock); \
  7644. + } while (0)
  7645. +
  7646. +#define read_lock_irq(lock) read_lock(lock)
  7647. +
  7648. +#define write_lock(lock) rt_write_lock(lock)
  7649. +
  7650. +#define write_lock_bh(lock) \
  7651. + do { \
  7652. + local_bh_disable(); \
  7653. + rt_write_lock(lock); \
  7654. + } while (0)
  7655. +
  7656. +#define write_lock_irq(lock) write_lock(lock)
  7657. +
  7658. +#define read_unlock(lock) rt_read_unlock(lock)
  7659. +
  7660. +#define read_unlock_bh(lock) \
  7661. + do { \
  7662. + rt_read_unlock(lock); \
  7663. + local_bh_enable(); \
  7664. + } while (0)
  7665. +
  7666. +#define read_unlock_irq(lock) read_unlock(lock)
  7667. +
  7668. +#define write_unlock(lock) rt_write_unlock(lock)
  7669. +
  7670. +#define write_unlock_bh(lock) \
  7671. + do { \
  7672. + rt_write_unlock(lock); \
  7673. + local_bh_enable(); \
  7674. + } while (0)
  7675. +
  7676. +#define write_unlock_irq(lock) write_unlock(lock)
  7677. +
  7678. +#define read_unlock_irqrestore(lock, flags) \
  7679. + do { \
  7680. + typecheck(unsigned long, flags); \
  7681. + (void) flags; \
  7682. + rt_read_unlock(lock); \
  7683. + } while (0)
  7684. +
  7685. +#define write_unlock_irqrestore(lock, flags) \
  7686. + do { \
  7687. + typecheck(unsigned long, flags); \
  7688. + (void) flags; \
  7689. + rt_write_unlock(lock); \
  7690. + } while (0)
  7691. +
  7692. +#endif
  7693. diff -Nur linux-4.9.6.orig/include/linux/rwlock_types.h linux-4.9.6/include/linux/rwlock_types.h
  7694. --- linux-4.9.6.orig/include/linux/rwlock_types.h 2017-01-26 08:25:24.000000000 +0100
  7695. +++ linux-4.9.6/include/linux/rwlock_types.h 2017-01-28 13:59:09.943656649 +0100
  7696. @@ -1,6 +1,10 @@
  7697. #ifndef __LINUX_RWLOCK_TYPES_H
  7698. #define __LINUX_RWLOCK_TYPES_H
  7699. +#if !defined(__LINUX_SPINLOCK_TYPES_H)
  7700. +# error "Do not include directly, include spinlock_types.h"
  7701. +#endif
  7702. +
  7703. /*
  7704. * include/linux/rwlock_types.h - generic rwlock type definitions
  7705. * and initializers
  7706. diff -Nur linux-4.9.6.orig/include/linux/rwlock_types_rt.h linux-4.9.6/include/linux/rwlock_types_rt.h
  7707. --- linux-4.9.6.orig/include/linux/rwlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  7708. +++ linux-4.9.6/include/linux/rwlock_types_rt.h 2017-01-28 13:59:09.943656649 +0100
  7709. @@ -0,0 +1,33 @@
  7710. +#ifndef __LINUX_RWLOCK_TYPES_RT_H
  7711. +#define __LINUX_RWLOCK_TYPES_RT_H
  7712. +
  7713. +#ifndef __LINUX_SPINLOCK_TYPES_H
  7714. +#error "Do not include directly. Include spinlock_types.h instead"
  7715. +#endif
  7716. +
  7717. +/*
  7718. + * rwlocks - rtmutex which allows single reader recursion
  7719. + */
  7720. +typedef struct {
  7721. + struct rt_mutex lock;
  7722. + int read_depth;
  7723. + unsigned int break_lock;
  7724. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  7725. + struct lockdep_map dep_map;
  7726. +#endif
  7727. +} rwlock_t;
  7728. +
  7729. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  7730. +# define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  7731. +#else
  7732. +# define RW_DEP_MAP_INIT(lockname)
  7733. +#endif
  7734. +
  7735. +#define __RW_LOCK_UNLOCKED(name) \
  7736. + { .lock = __RT_MUTEX_INITIALIZER_SAVE_STATE(name.lock), \
  7737. + RW_DEP_MAP_INIT(name) }
  7738. +
  7739. +#define DEFINE_RWLOCK(name) \
  7740. + rwlock_t name = __RW_LOCK_UNLOCKED(name)
  7741. +
  7742. +#endif
  7743. diff -Nur linux-4.9.6.orig/include/linux/rwsem.h linux-4.9.6/include/linux/rwsem.h
  7744. --- linux-4.9.6.orig/include/linux/rwsem.h 2017-01-26 08:25:24.000000000 +0100
  7745. +++ linux-4.9.6/include/linux/rwsem.h 2017-01-28 13:59:09.943656649 +0100
  7746. @@ -19,6 +19,10 @@
  7747. #include <linux/osq_lock.h>
  7748. #endif
  7749. +#ifdef CONFIG_PREEMPT_RT_FULL
  7750. +#include <linux/rwsem_rt.h>
  7751. +#else /* PREEMPT_RT_FULL */
  7752. +
  7753. struct rw_semaphore;
  7754. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  7755. @@ -184,4 +188,6 @@
  7756. # define up_read_non_owner(sem) up_read(sem)
  7757. #endif
  7758. +#endif /* !PREEMPT_RT_FULL */
  7759. +
  7760. #endif /* _LINUX_RWSEM_H */
  7761. diff -Nur linux-4.9.6.orig/include/linux/rwsem_rt.h linux-4.9.6/include/linux/rwsem_rt.h
  7762. --- linux-4.9.6.orig/include/linux/rwsem_rt.h 1970-01-01 01:00:00.000000000 +0100
  7763. +++ linux-4.9.6/include/linux/rwsem_rt.h 2017-01-28 13:59:09.943656649 +0100
  7764. @@ -0,0 +1,167 @@
  7765. +#ifndef _LINUX_RWSEM_RT_H
  7766. +#define _LINUX_RWSEM_RT_H
  7767. +
  7768. +#ifndef _LINUX_RWSEM_H
  7769. +#error "Include rwsem.h"
  7770. +#endif
  7771. +
  7772. +/*
  7773. + * RW-semaphores are a spinlock plus a reader-depth count.
  7774. + *
  7775. + * Note that the semantics are different from the usual
  7776. + * Linux rw-sems, in PREEMPT_RT mode we do not allow
  7777. + * multiple readers to hold the lock at once, we only allow
  7778. + * a read-lock owner to read-lock recursively. This is
  7779. + * better for latency, makes the implementation inherently
  7780. + * fair and makes it simpler as well.
  7781. + */
  7782. +
  7783. +#include <linux/rtmutex.h>
  7784. +
  7785. +struct rw_semaphore {
  7786. + struct rt_mutex lock;
  7787. + int read_depth;
  7788. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  7789. + struct lockdep_map dep_map;
  7790. +#endif
  7791. +};
  7792. +
  7793. +#define __RWSEM_INITIALIZER(name) \
  7794. + { .lock = __RT_MUTEX_INITIALIZER(name.lock), \
  7795. + RW_DEP_MAP_INIT(name) }
  7796. +
  7797. +#define DECLARE_RWSEM(lockname) \
  7798. + struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)
  7799. +
  7800. +extern void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  7801. + struct lock_class_key *key);
  7802. +
  7803. +#define __rt_init_rwsem(sem, name, key) \
  7804. + do { \
  7805. + rt_mutex_init(&(sem)->lock); \
  7806. + __rt_rwsem_init((sem), (name), (key));\
  7807. + } while (0)
  7808. +
  7809. +#define __init_rwsem(sem, name, key) __rt_init_rwsem(sem, name, key)
  7810. +
  7811. +# define rt_init_rwsem(sem) \
  7812. +do { \
  7813. + static struct lock_class_key __key; \
  7814. + \
  7815. + __rt_init_rwsem((sem), #sem, &__key); \
  7816. +} while (0)
  7817. +
  7818. +extern void rt_down_write(struct rw_semaphore *rwsem);
  7819. +extern int rt_down_write_killable(struct rw_semaphore *rwsem);
  7820. +extern void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass);
  7821. +extern void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass);
  7822. +extern int rt_down_write_killable_nested(struct rw_semaphore *rwsem,
  7823. + int subclass);
  7824. +extern void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  7825. + struct lockdep_map *nest);
  7826. +extern void rt__down_read(struct rw_semaphore *rwsem);
  7827. +extern void rt_down_read(struct rw_semaphore *rwsem);
  7828. +extern int rt_down_write_trylock(struct rw_semaphore *rwsem);
  7829. +extern int rt__down_read_trylock(struct rw_semaphore *rwsem);
  7830. +extern int rt_down_read_trylock(struct rw_semaphore *rwsem);
  7831. +extern void __rt_up_read(struct rw_semaphore *rwsem);
  7832. +extern void rt_up_read(struct rw_semaphore *rwsem);
  7833. +extern void rt_up_write(struct rw_semaphore *rwsem);
  7834. +extern void rt_downgrade_write(struct rw_semaphore *rwsem);
  7835. +
  7836. +#define init_rwsem(sem) rt_init_rwsem(sem)
  7837. +#define rwsem_is_locked(s) rt_mutex_is_locked(&(s)->lock)
  7838. +
  7839. +static inline int rwsem_is_contended(struct rw_semaphore *sem)
  7840. +{
  7841. + /* rt_mutex_has_waiters() */
  7842. + return !RB_EMPTY_ROOT(&sem->lock.waiters);
  7843. +}
  7844. +
  7845. +static inline void __down_read(struct rw_semaphore *sem)
  7846. +{
  7847. + rt__down_read(sem);
  7848. +}
  7849. +
  7850. +static inline void down_read(struct rw_semaphore *sem)
  7851. +{
  7852. + rt_down_read(sem);
  7853. +}
  7854. +
  7855. +static inline int __down_read_trylock(struct rw_semaphore *sem)
  7856. +{
  7857. + return rt__down_read_trylock(sem);
  7858. +}
  7859. +
  7860. +static inline int down_read_trylock(struct rw_semaphore *sem)
  7861. +{
  7862. + return rt_down_read_trylock(sem);
  7863. +}
  7864. +
  7865. +static inline void down_write(struct rw_semaphore *sem)
  7866. +{
  7867. + rt_down_write(sem);
  7868. +}
  7869. +
  7870. +static inline int down_write_killable(struct rw_semaphore *sem)
  7871. +{
  7872. + return rt_down_write_killable(sem);
  7873. +}
  7874. +
  7875. +static inline int down_write_trylock(struct rw_semaphore *sem)
  7876. +{
  7877. + return rt_down_write_trylock(sem);
  7878. +}
  7879. +
  7880. +static inline void __up_read(struct rw_semaphore *sem)
  7881. +{
  7882. + __rt_up_read(sem);
  7883. +}
  7884. +
  7885. +static inline void up_read(struct rw_semaphore *sem)
  7886. +{
  7887. + rt_up_read(sem);
  7888. +}
  7889. +
  7890. +static inline void up_write(struct rw_semaphore *sem)
  7891. +{
  7892. + rt_up_write(sem);
  7893. +}
  7894. +
  7895. +static inline void downgrade_write(struct rw_semaphore *sem)
  7896. +{
  7897. + rt_downgrade_write(sem);
  7898. +}
  7899. +
  7900. +static inline void down_read_nested(struct rw_semaphore *sem, int subclass)
  7901. +{
  7902. + return rt_down_read_nested(sem, subclass);
  7903. +}
  7904. +
  7905. +static inline void down_write_nested(struct rw_semaphore *sem, int subclass)
  7906. +{
  7907. + rt_down_write_nested(sem, subclass);
  7908. +}
  7909. +
  7910. +static inline int down_write_killable_nested(struct rw_semaphore *sem,
  7911. + int subclass)
  7912. +{
  7913. + return rt_down_write_killable_nested(sem, subclass);
  7914. +}
  7915. +
  7916. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  7917. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  7918. + struct rw_semaphore *nest_lock)
  7919. +{
  7920. + rt_down_write_nested_lock(sem, &nest_lock->dep_map);
  7921. +}
  7922. +
  7923. +#else
  7924. +
  7925. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  7926. + struct rw_semaphore *nest_lock)
  7927. +{
  7928. + rt_down_write_nested_lock(sem, NULL);
  7929. +}
  7930. +#endif
  7931. +#endif
  7932. diff -Nur linux-4.9.6.orig/include/linux/sched.h linux-4.9.6/include/linux/sched.h
  7933. --- linux-4.9.6.orig/include/linux/sched.h 2017-01-26 08:25:24.000000000 +0100
  7934. +++ linux-4.9.6/include/linux/sched.h 2017-01-28 13:59:09.943656649 +0100
  7935. @@ -26,6 +26,7 @@
  7936. #include <linux/nodemask.h>
  7937. #include <linux/mm_types.h>
  7938. #include <linux/preempt.h>
  7939. +#include <asm/kmap_types.h>
  7940. #include <asm/page.h>
  7941. #include <asm/ptrace.h>
  7942. @@ -243,10 +244,7 @@
  7943. TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  7944. __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
  7945. -#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
  7946. #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
  7947. -#define task_is_stopped_or_traced(task) \
  7948. - ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
  7949. #define task_contributes_to_load(task) \
  7950. ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
  7951. (task->flags & PF_FROZEN) == 0 && \
  7952. @@ -312,6 +310,11 @@
  7953. #endif
  7954. +#define __set_current_state_no_track(state_value) \
  7955. + do { current->state = (state_value); } while (0)
  7956. +#define set_current_state_no_track(state_value) \
  7957. + set_mb(current->state, (state_value))
  7958. +
  7959. /* Task command name length */
  7960. #define TASK_COMM_LEN 16
  7961. @@ -1013,8 +1016,18 @@
  7962. struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  7963. extern void wake_q_add(struct wake_q_head *head,
  7964. - struct task_struct *task);
  7965. -extern void wake_up_q(struct wake_q_head *head);
  7966. + struct task_struct *task);
  7967. +extern void __wake_up_q(struct wake_q_head *head, bool sleeper);
  7968. +
  7969. +static inline void wake_up_q(struct wake_q_head *head)
  7970. +{
  7971. + __wake_up_q(head, false);
  7972. +}
  7973. +
  7974. +static inline void wake_up_q_sleeper(struct wake_q_head *head)
  7975. +{
  7976. + __wake_up_q(head, true);
  7977. +}
  7978. /*
  7979. * sched-domains (multiprocessor balancing) declarations:
  7980. @@ -1481,6 +1494,7 @@
  7981. struct thread_info thread_info;
  7982. #endif
  7983. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  7984. + volatile long saved_state; /* saved state for "spinlock sleepers" */
  7985. void *stack;
  7986. atomic_t usage;
  7987. unsigned int flags; /* per process flags, defined below */
  7988. @@ -1520,6 +1534,12 @@
  7989. #endif
  7990. unsigned int policy;
  7991. +#ifdef CONFIG_PREEMPT_RT_FULL
  7992. + int migrate_disable;
  7993. +# ifdef CONFIG_SCHED_DEBUG
  7994. + int migrate_disable_atomic;
  7995. +# endif
  7996. +#endif
  7997. int nr_cpus_allowed;
  7998. cpumask_t cpus_allowed;
  7999. @@ -1654,6 +1674,9 @@
  8000. struct task_cputime cputime_expires;
  8001. struct list_head cpu_timers[3];
  8002. +#ifdef CONFIG_PREEMPT_RT_BASE
  8003. + struct task_struct *posix_timer_list;
  8004. +#endif
  8005. /* process credentials */
  8006. const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */
  8007. @@ -1685,10 +1708,15 @@
  8008. /* signal handlers */
  8009. struct signal_struct *signal;
  8010. struct sighand_struct *sighand;
  8011. + struct sigqueue *sigqueue_cache;
  8012. sigset_t blocked, real_blocked;
  8013. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  8014. struct sigpending pending;
  8015. +#ifdef CONFIG_PREEMPT_RT_FULL
  8016. + /* TODO: move me into ->restart_block ? */
  8017. + struct siginfo forced_info;
  8018. +#endif
  8019. unsigned long sas_ss_sp;
  8020. size_t sas_ss_size;
  8021. @@ -1917,6 +1945,12 @@
  8022. /* bitmask and counter of trace recursion */
  8023. unsigned long trace_recursion;
  8024. #endif /* CONFIG_TRACING */
  8025. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  8026. + u64 preempt_timestamp_hist;
  8027. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  8028. + long timer_offset;
  8029. +#endif
  8030. +#endif
  8031. #ifdef CONFIG_KCOV
  8032. /* Coverage collection mode enabled for this task (0 if disabled). */
  8033. enum kcov_mode kcov_mode;
  8034. @@ -1942,9 +1976,23 @@
  8035. unsigned int sequential_io;
  8036. unsigned int sequential_io_avg;
  8037. #endif
  8038. +#ifdef CONFIG_PREEMPT_RT_BASE
  8039. + struct rcu_head put_rcu;
  8040. + int softirq_nestcnt;
  8041. + unsigned int softirqs_raised;
  8042. +#endif
  8043. +#ifdef CONFIG_PREEMPT_RT_FULL
  8044. +# if defined CONFIG_HIGHMEM || defined CONFIG_X86_32
  8045. + int kmap_idx;
  8046. + pte_t kmap_pte[KM_TYPE_NR];
  8047. +# endif
  8048. +#endif
  8049. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  8050. unsigned long task_state_change;
  8051. #endif
  8052. +#ifdef CONFIG_PREEMPT_RT_FULL
  8053. + int xmit_recursion;
  8054. +#endif
  8055. int pagefault_disabled;
  8056. #ifdef CONFIG_MMU
  8057. struct task_struct *oom_reaper_list;
  8058. @@ -1984,14 +2032,6 @@
  8059. }
  8060. #endif
  8061. -/* Future-safe accessor for struct task_struct's cpus_allowed. */
  8062. -#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
  8063. -
  8064. -static inline int tsk_nr_cpus_allowed(struct task_struct *p)
  8065. -{
  8066. - return p->nr_cpus_allowed;
  8067. -}
  8068. -
  8069. #define TNF_MIGRATED 0x01
  8070. #define TNF_NO_GROUP 0x02
  8071. #define TNF_SHARED 0x04
  8072. @@ -2207,6 +2247,15 @@
  8073. extern void free_task(struct task_struct *tsk);
  8074. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  8075. +#ifdef CONFIG_PREEMPT_RT_BASE
  8076. +extern void __put_task_struct_cb(struct rcu_head *rhp);
  8077. +
  8078. +static inline void put_task_struct(struct task_struct *t)
  8079. +{
  8080. + if (atomic_dec_and_test(&t->usage))
  8081. + call_rcu(&t->put_rcu, __put_task_struct_cb);
  8082. +}
  8083. +#else
  8084. extern void __put_task_struct(struct task_struct *t);
  8085. static inline void put_task_struct(struct task_struct *t)
  8086. @@ -2214,6 +2263,7 @@
  8087. if (atomic_dec_and_test(&t->usage))
  8088. __put_task_struct(t);
  8089. }
  8090. +#endif
  8091. struct task_struct *task_rcu_dereference(struct task_struct **ptask);
  8092. struct task_struct *try_get_task_struct(struct task_struct **ptask);
  8093. @@ -2255,6 +2305,7 @@
  8094. /*
  8095. * Per process flags
  8096. */
  8097. +#define PF_IN_SOFTIRQ 0x00000001 /* Task is serving softirq */
  8098. #define PF_EXITING 0x00000004 /* getting shut down */
  8099. #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
  8100. #define PF_VCPU 0x00000010 /* I'm a virtual CPU */
  8101. @@ -2423,6 +2474,10 @@
  8102. extern int set_cpus_allowed_ptr(struct task_struct *p,
  8103. const struct cpumask *new_mask);
  8104. +int migrate_me(void);
  8105. +void tell_sched_cpu_down_begin(int cpu);
  8106. +void tell_sched_cpu_down_done(int cpu);
  8107. +
  8108. #else
  8109. static inline void do_set_cpus_allowed(struct task_struct *p,
  8110. const struct cpumask *new_mask)
  8111. @@ -2435,6 +2490,9 @@
  8112. return -EINVAL;
  8113. return 0;
  8114. }
  8115. +static inline int migrate_me(void) { return 0; }
  8116. +static inline void tell_sched_cpu_down_begin(int cpu) { }
  8117. +static inline void tell_sched_cpu_down_done(int cpu) { }
  8118. #endif
  8119. #ifdef CONFIG_NO_HZ_COMMON
  8120. @@ -2673,6 +2731,7 @@
  8121. extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  8122. extern int wake_up_process(struct task_struct *tsk);
  8123. +extern int wake_up_lock_sleeper(struct task_struct * tsk);
  8124. extern void wake_up_new_task(struct task_struct *tsk);
  8125. #ifdef CONFIG_SMP
  8126. extern void kick_process(struct task_struct *tsk);
  8127. @@ -2881,6 +2940,17 @@
  8128. __mmdrop(mm);
  8129. }
  8130. +#ifdef CONFIG_PREEMPT_RT_BASE
  8131. +extern void __mmdrop_delayed(struct rcu_head *rhp);
  8132. +static inline void mmdrop_delayed(struct mm_struct *mm)
  8133. +{
  8134. + if (atomic_dec_and_test(&mm->mm_count))
  8135. + call_rcu(&mm->delayed_drop, __mmdrop_delayed);
  8136. +}
  8137. +#else
  8138. +# define mmdrop_delayed(mm) mmdrop(mm)
  8139. +#endif
  8140. +
  8141. static inline void mmdrop_async_fn(struct work_struct *work)
  8142. {
  8143. struct mm_struct *mm = container_of(work, struct mm_struct, async_put_work);
  8144. @@ -3273,6 +3343,43 @@
  8145. return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  8146. }
  8147. +#ifdef CONFIG_PREEMPT_LAZY
  8148. +static inline void set_tsk_need_resched_lazy(struct task_struct *tsk)
  8149. +{
  8150. + set_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  8151. +}
  8152. +
  8153. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk)
  8154. +{
  8155. + clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  8156. +}
  8157. +
  8158. +static inline int test_tsk_need_resched_lazy(struct task_struct *tsk)
  8159. +{
  8160. + return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY));
  8161. +}
  8162. +
  8163. +static inline int need_resched_lazy(void)
  8164. +{
  8165. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  8166. +}
  8167. +
  8168. +static inline int need_resched_now(void)
  8169. +{
  8170. + return test_thread_flag(TIF_NEED_RESCHED);
  8171. +}
  8172. +
  8173. +#else
  8174. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk) { }
  8175. +static inline int need_resched_lazy(void) { return 0; }
  8176. +
  8177. +static inline int need_resched_now(void)
  8178. +{
  8179. + return test_thread_flag(TIF_NEED_RESCHED);
  8180. +}
  8181. +
  8182. +#endif
  8183. +
  8184. static inline int restart_syscall(void)
  8185. {
  8186. set_tsk_thread_flag(current, TIF_SIGPENDING);
  8187. @@ -3304,6 +3411,51 @@
  8188. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  8189. }
  8190. +static inline bool __task_is_stopped_or_traced(struct task_struct *task)
  8191. +{
  8192. + if (task->state & (__TASK_STOPPED | __TASK_TRACED))
  8193. + return true;
  8194. +#ifdef CONFIG_PREEMPT_RT_FULL
  8195. + if (task->saved_state & (__TASK_STOPPED | __TASK_TRACED))
  8196. + return true;
  8197. +#endif
  8198. + return false;
  8199. +}
  8200. +
  8201. +static inline bool task_is_stopped_or_traced(struct task_struct *task)
  8202. +{
  8203. + bool traced_stopped;
  8204. +
  8205. +#ifdef CONFIG_PREEMPT_RT_FULL
  8206. + unsigned long flags;
  8207. +
  8208. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  8209. + traced_stopped = __task_is_stopped_or_traced(task);
  8210. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  8211. +#else
  8212. + traced_stopped = __task_is_stopped_or_traced(task);
  8213. +#endif
  8214. + return traced_stopped;
  8215. +}
  8216. +
  8217. +static inline bool task_is_traced(struct task_struct *task)
  8218. +{
  8219. + bool traced = false;
  8220. +
  8221. + if (task->state & __TASK_TRACED)
  8222. + return true;
  8223. +#ifdef CONFIG_PREEMPT_RT_FULL
  8224. + /* in case the task is sleeping on tasklist_lock */
  8225. + raw_spin_lock_irq(&task->pi_lock);
  8226. + if (task->state & __TASK_TRACED)
  8227. + traced = true;
  8228. + else if (task->saved_state & __TASK_TRACED)
  8229. + traced = true;
  8230. + raw_spin_unlock_irq(&task->pi_lock);
  8231. +#endif
  8232. + return traced;
  8233. +}
  8234. +
  8235. /*
  8236. * cond_resched() and cond_resched_lock(): latency reduction via
  8237. * explicit rescheduling in places that are safe. The return
  8238. @@ -3329,12 +3481,16 @@
  8239. __cond_resched_lock(lock); \
  8240. })
  8241. +#ifndef CONFIG_PREEMPT_RT_FULL
  8242. extern int __cond_resched_softirq(void);
  8243. #define cond_resched_softirq() ({ \
  8244. ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
  8245. __cond_resched_softirq(); \
  8246. })
  8247. +#else
  8248. +# define cond_resched_softirq() cond_resched()
  8249. +#endif
  8250. static inline void cond_resched_rcu(void)
  8251. {
  8252. @@ -3509,6 +3665,31 @@
  8253. #endif /* CONFIG_SMP */
  8254. +static inline int __migrate_disabled(struct task_struct *p)
  8255. +{
  8256. +#ifdef CONFIG_PREEMPT_RT_FULL
  8257. + return p->migrate_disable;
  8258. +#else
  8259. + return 0;
  8260. +#endif
  8261. +}
  8262. +
  8263. +/* Future-safe accessor for struct task_struct's cpus_allowed. */
  8264. +static inline const struct cpumask *tsk_cpus_allowed(struct task_struct *p)
  8265. +{
  8266. + if (__migrate_disabled(p))
  8267. + return cpumask_of(task_cpu(p));
  8268. +
  8269. + return &p->cpus_allowed;
  8270. +}
  8271. +
  8272. +static inline int tsk_nr_cpus_allowed(struct task_struct *p)
  8273. +{
  8274. + if (__migrate_disabled(p))
  8275. + return 1;
  8276. + return p->nr_cpus_allowed;
  8277. +}
  8278. +
  8279. extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  8280. extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  8281. diff -Nur linux-4.9.6.orig/include/linux/seqlock.h linux-4.9.6/include/linux/seqlock.h
  8282. --- linux-4.9.6.orig/include/linux/seqlock.h 2017-01-26 08:25:24.000000000 +0100
  8283. +++ linux-4.9.6/include/linux/seqlock.h 2017-01-28 13:59:09.943656649 +0100
  8284. @@ -220,20 +220,30 @@
  8285. return __read_seqcount_retry(s, start);
  8286. }
  8287. -
  8288. -
  8289. -static inline void raw_write_seqcount_begin(seqcount_t *s)
  8290. +static inline void __raw_write_seqcount_begin(seqcount_t *s)
  8291. {
  8292. s->sequence++;
  8293. smp_wmb();
  8294. }
  8295. -static inline void raw_write_seqcount_end(seqcount_t *s)
  8296. +static inline void raw_write_seqcount_begin(seqcount_t *s)
  8297. +{
  8298. + preempt_disable_rt();
  8299. + __raw_write_seqcount_begin(s);
  8300. +}
  8301. +
  8302. +static inline void __raw_write_seqcount_end(seqcount_t *s)
  8303. {
  8304. smp_wmb();
  8305. s->sequence++;
  8306. }
  8307. +static inline void raw_write_seqcount_end(seqcount_t *s)
  8308. +{
  8309. + __raw_write_seqcount_end(s);
  8310. + preempt_enable_rt();
  8311. +}
  8312. +
  8313. /**
  8314. * raw_write_seqcount_barrier - do a seq write barrier
  8315. * @s: pointer to seqcount_t
  8316. @@ -428,10 +438,32 @@
  8317. /*
  8318. * Read side functions for starting and finalizing a read side section.
  8319. */
  8320. +#ifndef CONFIG_PREEMPT_RT_FULL
  8321. static inline unsigned read_seqbegin(const seqlock_t *sl)
  8322. {
  8323. return read_seqcount_begin(&sl->seqcount);
  8324. }
  8325. +#else
  8326. +/*
  8327. + * Starvation safe read side for RT
  8328. + */
  8329. +static inline unsigned read_seqbegin(seqlock_t *sl)
  8330. +{
  8331. + unsigned ret;
  8332. +
  8333. +repeat:
  8334. + ret = ACCESS_ONCE(sl->seqcount.sequence);
  8335. + if (unlikely(ret & 1)) {
  8336. + /*
  8337. + * Take the lock and let the writer proceed (i.e. evtl
  8338. + * boost it), otherwise we could loop here forever.
  8339. + */
  8340. + spin_unlock_wait(&sl->lock);
  8341. + goto repeat;
  8342. + }
  8343. + return ret;
  8344. +}
  8345. +#endif
  8346. static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
  8347. {
  8348. @@ -446,36 +478,45 @@
  8349. static inline void write_seqlock(seqlock_t *sl)
  8350. {
  8351. spin_lock(&sl->lock);
  8352. - write_seqcount_begin(&sl->seqcount);
  8353. + __raw_write_seqcount_begin(&sl->seqcount);
  8354. +}
  8355. +
  8356. +static inline int try_write_seqlock(seqlock_t *sl)
  8357. +{
  8358. + if (spin_trylock(&sl->lock)) {
  8359. + __raw_write_seqcount_begin(&sl->seqcount);
  8360. + return 1;
  8361. + }
  8362. + return 0;
  8363. }
  8364. static inline void write_sequnlock(seqlock_t *sl)
  8365. {
  8366. - write_seqcount_end(&sl->seqcount);
  8367. + __raw_write_seqcount_end(&sl->seqcount);
  8368. spin_unlock(&sl->lock);
  8369. }
  8370. static inline void write_seqlock_bh(seqlock_t *sl)
  8371. {
  8372. spin_lock_bh(&sl->lock);
  8373. - write_seqcount_begin(&sl->seqcount);
  8374. + __raw_write_seqcount_begin(&sl->seqcount);
  8375. }
  8376. static inline void write_sequnlock_bh(seqlock_t *sl)
  8377. {
  8378. - write_seqcount_end(&sl->seqcount);
  8379. + __raw_write_seqcount_end(&sl->seqcount);
  8380. spin_unlock_bh(&sl->lock);
  8381. }
  8382. static inline void write_seqlock_irq(seqlock_t *sl)
  8383. {
  8384. spin_lock_irq(&sl->lock);
  8385. - write_seqcount_begin(&sl->seqcount);
  8386. + __raw_write_seqcount_begin(&sl->seqcount);
  8387. }
  8388. static inline void write_sequnlock_irq(seqlock_t *sl)
  8389. {
  8390. - write_seqcount_end(&sl->seqcount);
  8391. + __raw_write_seqcount_end(&sl->seqcount);
  8392. spin_unlock_irq(&sl->lock);
  8393. }
  8394. @@ -484,7 +525,7 @@
  8395. unsigned long flags;
  8396. spin_lock_irqsave(&sl->lock, flags);
  8397. - write_seqcount_begin(&sl->seqcount);
  8398. + __raw_write_seqcount_begin(&sl->seqcount);
  8399. return flags;
  8400. }
  8401. @@ -494,7 +535,7 @@
  8402. static inline void
  8403. write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags)
  8404. {
  8405. - write_seqcount_end(&sl->seqcount);
  8406. + __raw_write_seqcount_end(&sl->seqcount);
  8407. spin_unlock_irqrestore(&sl->lock, flags);
  8408. }
  8409. diff -Nur linux-4.9.6.orig/include/linux/signal.h linux-4.9.6/include/linux/signal.h
  8410. --- linux-4.9.6.orig/include/linux/signal.h 2017-01-26 08:25:24.000000000 +0100
  8411. +++ linux-4.9.6/include/linux/signal.h 2017-01-28 13:59:09.947656802 +0100
  8412. @@ -233,6 +233,7 @@
  8413. }
  8414. extern void flush_sigqueue(struct sigpending *queue);
  8415. +extern void flush_task_sigqueue(struct task_struct *tsk);
  8416. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  8417. static inline int valid_signal(unsigned long sig)
  8418. diff -Nur linux-4.9.6.orig/include/linux/skbuff.h linux-4.9.6/include/linux/skbuff.h
  8419. --- linux-4.9.6.orig/include/linux/skbuff.h 2017-01-26 08:25:24.000000000 +0100
  8420. +++ linux-4.9.6/include/linux/skbuff.h 2017-01-28 13:59:09.947656802 +0100
  8421. @@ -284,6 +284,7 @@
  8422. __u32 qlen;
  8423. spinlock_t lock;
  8424. + raw_spinlock_t raw_lock;
  8425. };
  8426. struct sk_buff;
  8427. @@ -1573,6 +1574,12 @@
  8428. __skb_queue_head_init(list);
  8429. }
  8430. +static inline void skb_queue_head_init_raw(struct sk_buff_head *list)
  8431. +{
  8432. + raw_spin_lock_init(&list->raw_lock);
  8433. + __skb_queue_head_init(list);
  8434. +}
  8435. +
  8436. static inline void skb_queue_head_init_class(struct sk_buff_head *list,
  8437. struct lock_class_key *class)
  8438. {
  8439. diff -Nur linux-4.9.6.orig/include/linux/smp.h linux-4.9.6/include/linux/smp.h
  8440. --- linux-4.9.6.orig/include/linux/smp.h 2017-01-26 08:25:24.000000000 +0100
  8441. +++ linux-4.9.6/include/linux/smp.h 2017-01-28 13:59:09.947656802 +0100
  8442. @@ -185,6 +185,9 @@
  8443. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  8444. #define put_cpu() preempt_enable()
  8445. +#define get_cpu_light() ({ migrate_disable(); smp_processor_id(); })
  8446. +#define put_cpu_light() migrate_enable()
  8447. +
  8448. /*
  8449. * Callback to arch code if there's nosmp or maxcpus=0 on the
  8450. * boot command line:
  8451. diff -Nur linux-4.9.6.orig/include/linux/spinlock_api_smp.h linux-4.9.6/include/linux/spinlock_api_smp.h
  8452. --- linux-4.9.6.orig/include/linux/spinlock_api_smp.h 2017-01-26 08:25:24.000000000 +0100
  8453. +++ linux-4.9.6/include/linux/spinlock_api_smp.h 2017-01-28 13:59:09.947656802 +0100
  8454. @@ -189,6 +189,8 @@
  8455. return 0;
  8456. }
  8457. -#include <linux/rwlock_api_smp.h>
  8458. +#ifndef CONFIG_PREEMPT_RT_FULL
  8459. +# include <linux/rwlock_api_smp.h>
  8460. +#endif
  8461. #endif /* __LINUX_SPINLOCK_API_SMP_H */
  8462. diff -Nur linux-4.9.6.orig/include/linux/spinlock.h linux-4.9.6/include/linux/spinlock.h
  8463. --- linux-4.9.6.orig/include/linux/spinlock.h 2017-01-26 08:25:24.000000000 +0100
  8464. +++ linux-4.9.6/include/linux/spinlock.h 2017-01-28 13:59:09.947656802 +0100
  8465. @@ -271,7 +271,11 @@
  8466. #define raw_spin_can_lock(lock) (!raw_spin_is_locked(lock))
  8467. /* Include rwlock functions */
  8468. -#include <linux/rwlock.h>
  8469. +#ifdef CONFIG_PREEMPT_RT_FULL
  8470. +# include <linux/rwlock_rt.h>
  8471. +#else
  8472. +# include <linux/rwlock.h>
  8473. +#endif
  8474. /*
  8475. * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
  8476. @@ -282,6 +286,10 @@
  8477. # include <linux/spinlock_api_up.h>
  8478. #endif
  8479. +#ifdef CONFIG_PREEMPT_RT_FULL
  8480. +# include <linux/spinlock_rt.h>
  8481. +#else /* PREEMPT_RT_FULL */
  8482. +
  8483. /*
  8484. * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  8485. */
  8486. @@ -347,6 +355,12 @@
  8487. raw_spin_unlock(&lock->rlock);
  8488. }
  8489. +static __always_inline int spin_unlock_no_deboost(spinlock_t *lock)
  8490. +{
  8491. + raw_spin_unlock(&lock->rlock);
  8492. + return 0;
  8493. +}
  8494. +
  8495. static __always_inline void spin_unlock_bh(spinlock_t *lock)
  8496. {
  8497. raw_spin_unlock_bh(&lock->rlock);
  8498. @@ -416,4 +430,6 @@
  8499. #define atomic_dec_and_lock(atomic, lock) \
  8500. __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
  8501. +#endif /* !PREEMPT_RT_FULL */
  8502. +
  8503. #endif /* __LINUX_SPINLOCK_H */
  8504. diff -Nur linux-4.9.6.orig/include/linux/spinlock_rt.h linux-4.9.6/include/linux/spinlock_rt.h
  8505. --- linux-4.9.6.orig/include/linux/spinlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  8506. +++ linux-4.9.6/include/linux/spinlock_rt.h 2017-01-28 13:59:09.947656802 +0100
  8507. @@ -0,0 +1,164 @@
  8508. +#ifndef __LINUX_SPINLOCK_RT_H
  8509. +#define __LINUX_SPINLOCK_RT_H
  8510. +
  8511. +#ifndef __LINUX_SPINLOCK_H
  8512. +#error Do not include directly. Use spinlock.h
  8513. +#endif
  8514. +
  8515. +#include <linux/bug.h>
  8516. +
  8517. +extern void
  8518. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key);
  8519. +
  8520. +#define spin_lock_init(slock) \
  8521. +do { \
  8522. + static struct lock_class_key __key; \
  8523. + \
  8524. + rt_mutex_init(&(slock)->lock); \
  8525. + __rt_spin_lock_init(slock, #slock, &__key); \
  8526. +} while (0)
  8527. +
  8528. +void __lockfunc rt_spin_lock__no_mg(spinlock_t *lock);
  8529. +void __lockfunc rt_spin_unlock__no_mg(spinlock_t *lock);
  8530. +int __lockfunc rt_spin_trylock__no_mg(spinlock_t *lock);
  8531. +
  8532. +extern void __lockfunc rt_spin_lock(spinlock_t *lock);
  8533. +extern unsigned long __lockfunc rt_spin_lock_trace_flags(spinlock_t *lock);
  8534. +extern void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass);
  8535. +extern void __lockfunc rt_spin_unlock(spinlock_t *lock);
  8536. +extern int __lockfunc rt_spin_unlock_no_deboost(spinlock_t *lock);
  8537. +extern void __lockfunc rt_spin_unlock_wait(spinlock_t *lock);
  8538. +extern int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags);
  8539. +extern int __lockfunc rt_spin_trylock_bh(spinlock_t *lock);
  8540. +extern int __lockfunc rt_spin_trylock(spinlock_t *lock);
  8541. +extern int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock);
  8542. +
  8543. +/*
  8544. + * lockdep-less calls, for derived types like rwlock:
  8545. + * (for trylock they can use rt_mutex_trylock() directly.
  8546. + */
  8547. +extern void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock);
  8548. +extern void __lockfunc __rt_spin_lock(struct rt_mutex *lock);
  8549. +extern void __lockfunc __rt_spin_unlock(struct rt_mutex *lock);
  8550. +
  8551. +#define spin_lock(lock) rt_spin_lock(lock)
  8552. +
  8553. +#define spin_lock_bh(lock) \
  8554. + do { \
  8555. + local_bh_disable(); \
  8556. + rt_spin_lock(lock); \
  8557. + } while (0)
  8558. +
  8559. +#define spin_lock_irq(lock) spin_lock(lock)
  8560. +
  8561. +#define spin_do_trylock(lock) __cond_lock(lock, rt_spin_trylock(lock))
  8562. +
  8563. +#define spin_trylock(lock) \
  8564. +({ \
  8565. + int __locked; \
  8566. + __locked = spin_do_trylock(lock); \
  8567. + __locked; \
  8568. +})
  8569. +
  8570. +#ifdef CONFIG_LOCKDEP
  8571. +# define spin_lock_nested(lock, subclass) \
  8572. + do { \
  8573. + rt_spin_lock_nested(lock, subclass); \
  8574. + } while (0)
  8575. +
  8576. +#define spin_lock_bh_nested(lock, subclass) \
  8577. + do { \
  8578. + local_bh_disable(); \
  8579. + rt_spin_lock_nested(lock, subclass); \
  8580. + } while (0)
  8581. +
  8582. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  8583. + do { \
  8584. + typecheck(unsigned long, flags); \
  8585. + flags = 0; \
  8586. + rt_spin_lock_nested(lock, subclass); \
  8587. + } while (0)
  8588. +#else
  8589. +# define spin_lock_nested(lock, subclass) spin_lock(lock)
  8590. +# define spin_lock_bh_nested(lock, subclass) spin_lock_bh(lock)
  8591. +
  8592. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  8593. + do { \
  8594. + typecheck(unsigned long, flags); \
  8595. + flags = 0; \
  8596. + spin_lock(lock); \
  8597. + } while (0)
  8598. +#endif
  8599. +
  8600. +#define spin_lock_irqsave(lock, flags) \
  8601. + do { \
  8602. + typecheck(unsigned long, flags); \
  8603. + flags = 0; \
  8604. + spin_lock(lock); \
  8605. + } while (0)
  8606. +
  8607. +static inline unsigned long spin_lock_trace_flags(spinlock_t *lock)
  8608. +{
  8609. + unsigned long flags = 0;
  8610. +#ifdef CONFIG_TRACE_IRQFLAGS
  8611. + flags = rt_spin_lock_trace_flags(lock);
  8612. +#else
  8613. + spin_lock(lock); /* lock_local */
  8614. +#endif
  8615. + return flags;
  8616. +}
  8617. +
  8618. +/* FIXME: we need rt_spin_lock_nest_lock */
  8619. +#define spin_lock_nest_lock(lock, nest_lock) spin_lock_nested(lock, 0)
  8620. +
  8621. +#define spin_unlock(lock) rt_spin_unlock(lock)
  8622. +#define spin_unlock_no_deboost(lock) rt_spin_unlock_no_deboost(lock)
  8623. +
  8624. +#define spin_unlock_bh(lock) \
  8625. + do { \
  8626. + rt_spin_unlock(lock); \
  8627. + local_bh_enable(); \
  8628. + } while (0)
  8629. +
  8630. +#define spin_unlock_irq(lock) spin_unlock(lock)
  8631. +
  8632. +#define spin_unlock_irqrestore(lock, flags) \
  8633. + do { \
  8634. + typecheck(unsigned long, flags); \
  8635. + (void) flags; \
  8636. + spin_unlock(lock); \
  8637. + } while (0)
  8638. +
  8639. +#define spin_trylock_bh(lock) __cond_lock(lock, rt_spin_trylock_bh(lock))
  8640. +#define spin_trylock_irq(lock) spin_trylock(lock)
  8641. +
  8642. +#define spin_trylock_irqsave(lock, flags) \
  8643. + rt_spin_trylock_irqsave(lock, &(flags))
  8644. +
  8645. +#define spin_unlock_wait(lock) rt_spin_unlock_wait(lock)
  8646. +
  8647. +#ifdef CONFIG_GENERIC_LOCKBREAK
  8648. +# define spin_is_contended(lock) ((lock)->break_lock)
  8649. +#else
  8650. +# define spin_is_contended(lock) (((void)(lock), 0))
  8651. +#endif
  8652. +
  8653. +static inline int spin_can_lock(spinlock_t *lock)
  8654. +{
  8655. + return !rt_mutex_is_locked(&lock->lock);
  8656. +}
  8657. +
  8658. +static inline int spin_is_locked(spinlock_t *lock)
  8659. +{
  8660. + return rt_mutex_is_locked(&lock->lock);
  8661. +}
  8662. +
  8663. +static inline void assert_spin_locked(spinlock_t *lock)
  8664. +{
  8665. + BUG_ON(!spin_is_locked(lock));
  8666. +}
  8667. +
  8668. +#define atomic_dec_and_lock(atomic, lock) \
  8669. + atomic_dec_and_spin_lock(atomic, lock)
  8670. +
  8671. +#endif
  8672. diff -Nur linux-4.9.6.orig/include/linux/spinlock_types.h linux-4.9.6/include/linux/spinlock_types.h
  8673. --- linux-4.9.6.orig/include/linux/spinlock_types.h 2017-01-26 08:25:24.000000000 +0100
  8674. +++ linux-4.9.6/include/linux/spinlock_types.h 2017-01-28 13:59:09.947656802 +0100
  8675. @@ -9,80 +9,15 @@
  8676. * Released under the General Public License (GPL).
  8677. */
  8678. -#if defined(CONFIG_SMP)
  8679. -# include <asm/spinlock_types.h>
  8680. -#else
  8681. -# include <linux/spinlock_types_up.h>
  8682. -#endif
  8683. -
  8684. -#include <linux/lockdep.h>
  8685. -
  8686. -typedef struct raw_spinlock {
  8687. - arch_spinlock_t raw_lock;
  8688. -#ifdef CONFIG_GENERIC_LOCKBREAK
  8689. - unsigned int break_lock;
  8690. -#endif
  8691. -#ifdef CONFIG_DEBUG_SPINLOCK
  8692. - unsigned int magic, owner_cpu;
  8693. - void *owner;
  8694. -#endif
  8695. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8696. - struct lockdep_map dep_map;
  8697. -#endif
  8698. -} raw_spinlock_t;
  8699. -
  8700. -#define SPINLOCK_MAGIC 0xdead4ead
  8701. -
  8702. -#define SPINLOCK_OWNER_INIT ((void *)-1L)
  8703. -
  8704. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8705. -# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  8706. -#else
  8707. -# define SPIN_DEP_MAP_INIT(lockname)
  8708. -#endif
  8709. +#include <linux/spinlock_types_raw.h>
  8710. -#ifdef CONFIG_DEBUG_SPINLOCK
  8711. -# define SPIN_DEBUG_INIT(lockname) \
  8712. - .magic = SPINLOCK_MAGIC, \
  8713. - .owner_cpu = -1, \
  8714. - .owner = SPINLOCK_OWNER_INIT,
  8715. +#ifndef CONFIG_PREEMPT_RT_FULL
  8716. +# include <linux/spinlock_types_nort.h>
  8717. +# include <linux/rwlock_types.h>
  8718. #else
  8719. -# define SPIN_DEBUG_INIT(lockname)
  8720. +# include <linux/rtmutex.h>
  8721. +# include <linux/spinlock_types_rt.h>
  8722. +# include <linux/rwlock_types_rt.h>
  8723. #endif
  8724. -#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  8725. - { \
  8726. - .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  8727. - SPIN_DEBUG_INIT(lockname) \
  8728. - SPIN_DEP_MAP_INIT(lockname) }
  8729. -
  8730. -#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  8731. - (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  8732. -
  8733. -#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  8734. -
  8735. -typedef struct spinlock {
  8736. - union {
  8737. - struct raw_spinlock rlock;
  8738. -
  8739. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8740. -# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  8741. - struct {
  8742. - u8 __padding[LOCK_PADSIZE];
  8743. - struct lockdep_map dep_map;
  8744. - };
  8745. -#endif
  8746. - };
  8747. -} spinlock_t;
  8748. -
  8749. -#define __SPIN_LOCK_INITIALIZER(lockname) \
  8750. - { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  8751. -
  8752. -#define __SPIN_LOCK_UNLOCKED(lockname) \
  8753. - (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  8754. -
  8755. -#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  8756. -
  8757. -#include <linux/rwlock_types.h>
  8758. -
  8759. #endif /* __LINUX_SPINLOCK_TYPES_H */
  8760. diff -Nur linux-4.9.6.orig/include/linux/spinlock_types_nort.h linux-4.9.6/include/linux/spinlock_types_nort.h
  8761. --- linux-4.9.6.orig/include/linux/spinlock_types_nort.h 1970-01-01 01:00:00.000000000 +0100
  8762. +++ linux-4.9.6/include/linux/spinlock_types_nort.h 2017-01-28 13:59:09.947656802 +0100
  8763. @@ -0,0 +1,33 @@
  8764. +#ifndef __LINUX_SPINLOCK_TYPES_NORT_H
  8765. +#define __LINUX_SPINLOCK_TYPES_NORT_H
  8766. +
  8767. +#ifndef __LINUX_SPINLOCK_TYPES_H
  8768. +#error "Do not include directly. Include spinlock_types.h instead"
  8769. +#endif
  8770. +
  8771. +/*
  8772. + * The non RT version maps spinlocks to raw_spinlocks
  8773. + */
  8774. +typedef struct spinlock {
  8775. + union {
  8776. + struct raw_spinlock rlock;
  8777. +
  8778. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8779. +# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  8780. + struct {
  8781. + u8 __padding[LOCK_PADSIZE];
  8782. + struct lockdep_map dep_map;
  8783. + };
  8784. +#endif
  8785. + };
  8786. +} spinlock_t;
  8787. +
  8788. +#define __SPIN_LOCK_INITIALIZER(lockname) \
  8789. + { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  8790. +
  8791. +#define __SPIN_LOCK_UNLOCKED(lockname) \
  8792. + (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  8793. +
  8794. +#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  8795. +
  8796. +#endif
  8797. diff -Nur linux-4.9.6.orig/include/linux/spinlock_types_raw.h linux-4.9.6/include/linux/spinlock_types_raw.h
  8798. --- linux-4.9.6.orig/include/linux/spinlock_types_raw.h 1970-01-01 01:00:00.000000000 +0100
  8799. +++ linux-4.9.6/include/linux/spinlock_types_raw.h 2017-01-28 13:59:09.947656802 +0100
  8800. @@ -0,0 +1,56 @@
  8801. +#ifndef __LINUX_SPINLOCK_TYPES_RAW_H
  8802. +#define __LINUX_SPINLOCK_TYPES_RAW_H
  8803. +
  8804. +#if defined(CONFIG_SMP)
  8805. +# include <asm/spinlock_types.h>
  8806. +#else
  8807. +# include <linux/spinlock_types_up.h>
  8808. +#endif
  8809. +
  8810. +#include <linux/lockdep.h>
  8811. +
  8812. +typedef struct raw_spinlock {
  8813. + arch_spinlock_t raw_lock;
  8814. +#ifdef CONFIG_GENERIC_LOCKBREAK
  8815. + unsigned int break_lock;
  8816. +#endif
  8817. +#ifdef CONFIG_DEBUG_SPINLOCK
  8818. + unsigned int magic, owner_cpu;
  8819. + void *owner;
  8820. +#endif
  8821. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8822. + struct lockdep_map dep_map;
  8823. +#endif
  8824. +} raw_spinlock_t;
  8825. +
  8826. +#define SPINLOCK_MAGIC 0xdead4ead
  8827. +
  8828. +#define SPINLOCK_OWNER_INIT ((void *)-1L)
  8829. +
  8830. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8831. +# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  8832. +#else
  8833. +# define SPIN_DEP_MAP_INIT(lockname)
  8834. +#endif
  8835. +
  8836. +#ifdef CONFIG_DEBUG_SPINLOCK
  8837. +# define SPIN_DEBUG_INIT(lockname) \
  8838. + .magic = SPINLOCK_MAGIC, \
  8839. + .owner_cpu = -1, \
  8840. + .owner = SPINLOCK_OWNER_INIT,
  8841. +#else
  8842. +# define SPIN_DEBUG_INIT(lockname)
  8843. +#endif
  8844. +
  8845. +#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  8846. + { \
  8847. + .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  8848. + SPIN_DEBUG_INIT(lockname) \
  8849. + SPIN_DEP_MAP_INIT(lockname) }
  8850. +
  8851. +#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  8852. + (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  8853. +
  8854. +#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  8855. +
  8856. +#endif
  8857. diff -Nur linux-4.9.6.orig/include/linux/spinlock_types_rt.h linux-4.9.6/include/linux/spinlock_types_rt.h
  8858. --- linux-4.9.6.orig/include/linux/spinlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  8859. +++ linux-4.9.6/include/linux/spinlock_types_rt.h 2017-01-28 13:59:09.947656802 +0100
  8860. @@ -0,0 +1,48 @@
  8861. +#ifndef __LINUX_SPINLOCK_TYPES_RT_H
  8862. +#define __LINUX_SPINLOCK_TYPES_RT_H
  8863. +
  8864. +#ifndef __LINUX_SPINLOCK_TYPES_H
  8865. +#error "Do not include directly. Include spinlock_types.h instead"
  8866. +#endif
  8867. +
  8868. +#include <linux/cache.h>
  8869. +
  8870. +/*
  8871. + * PREEMPT_RT: spinlocks - an RT mutex plus lock-break field:
  8872. + */
  8873. +typedef struct spinlock {
  8874. + struct rt_mutex lock;
  8875. + unsigned int break_lock;
  8876. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  8877. + struct lockdep_map dep_map;
  8878. +#endif
  8879. +} spinlock_t;
  8880. +
  8881. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  8882. +# define __RT_SPIN_INITIALIZER(name) \
  8883. + { \
  8884. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  8885. + .save_state = 1, \
  8886. + .file = __FILE__, \
  8887. + .line = __LINE__ , \
  8888. + }
  8889. +#else
  8890. +# define __RT_SPIN_INITIALIZER(name) \
  8891. + { \
  8892. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  8893. + .save_state = 1, \
  8894. + }
  8895. +#endif
  8896. +
  8897. +/*
  8898. +.wait_list = PLIST_HEAD_INIT_RAW((name).lock.wait_list, (name).lock.wait_lock)
  8899. +*/
  8900. +
  8901. +#define __SPIN_LOCK_UNLOCKED(name) \
  8902. + { .lock = __RT_SPIN_INITIALIZER(name.lock), \
  8903. + SPIN_DEP_MAP_INIT(name) }
  8904. +
  8905. +#define DEFINE_SPINLOCK(name) \
  8906. + spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
  8907. +
  8908. +#endif
  8909. diff -Nur linux-4.9.6.orig/include/linux/srcu.h linux-4.9.6/include/linux/srcu.h
  8910. --- linux-4.9.6.orig/include/linux/srcu.h 2017-01-26 08:25:24.000000000 +0100
  8911. +++ linux-4.9.6/include/linux/srcu.h 2017-01-28 13:59:09.947656802 +0100
  8912. @@ -84,10 +84,10 @@
  8913. void process_srcu(struct work_struct *work);
  8914. -#define __SRCU_STRUCT_INIT(name) \
  8915. +#define __SRCU_STRUCT_INIT(name, pcpu_name) \
  8916. { \
  8917. .completed = -300, \
  8918. - .per_cpu_ref = &name##_srcu_array, \
  8919. + .per_cpu_ref = &pcpu_name, \
  8920. .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
  8921. .running = false, \
  8922. .batch_queue = RCU_BATCH_INIT(name.batch_queue), \
  8923. @@ -119,7 +119,7 @@
  8924. */
  8925. #define __DEFINE_SRCU(name, is_static) \
  8926. static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
  8927. - is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
  8928. + is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_array)
  8929. #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
  8930. #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
  8931. diff -Nur linux-4.9.6.orig/include/linux/suspend.h linux-4.9.6/include/linux/suspend.h
  8932. --- linux-4.9.6.orig/include/linux/suspend.h 2017-01-26 08:25:24.000000000 +0100
  8933. +++ linux-4.9.6/include/linux/suspend.h 2017-01-28 13:59:09.947656802 +0100
  8934. @@ -193,6 +193,12 @@
  8935. void (*end)(void);
  8936. };
  8937. +#if defined(CONFIG_SUSPEND) || defined(CONFIG_HIBERNATION)
  8938. +extern bool pm_in_action;
  8939. +#else
  8940. +# define pm_in_action false
  8941. +#endif
  8942. +
  8943. #ifdef CONFIG_SUSPEND
  8944. /**
  8945. * suspend_set_ops - set platform dependent suspend operations
  8946. diff -Nur linux-4.9.6.orig/include/linux/swait.h linux-4.9.6/include/linux/swait.h
  8947. --- linux-4.9.6.orig/include/linux/swait.h 2017-01-26 08:25:24.000000000 +0100
  8948. +++ linux-4.9.6/include/linux/swait.h 2017-01-28 13:59:09.947656802 +0100
  8949. @@ -87,6 +87,7 @@
  8950. extern void swake_up(struct swait_queue_head *q);
  8951. extern void swake_up_all(struct swait_queue_head *q);
  8952. extern void swake_up_locked(struct swait_queue_head *q);
  8953. +extern void swake_up_all_locked(struct swait_queue_head *q);
  8954. extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
  8955. extern void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state);
  8956. diff -Nur linux-4.9.6.orig/include/linux/swap.h linux-4.9.6/include/linux/swap.h
  8957. --- linux-4.9.6.orig/include/linux/swap.h 2017-01-26 08:25:24.000000000 +0100
  8958. +++ linux-4.9.6/include/linux/swap.h 2017-01-28 13:59:09.947656802 +0100
  8959. @@ -11,6 +11,7 @@
  8960. #include <linux/fs.h>
  8961. #include <linux/atomic.h>
  8962. #include <linux/page-flags.h>
  8963. +#include <linux/locallock.h>
  8964. #include <asm/page.h>
  8965. struct notifier_block;
  8966. @@ -247,7 +248,8 @@
  8967. void *workingset_eviction(struct address_space *mapping, struct page *page);
  8968. bool workingset_refault(void *shadow);
  8969. void workingset_activation(struct page *page);
  8970. -extern struct list_lru workingset_shadow_nodes;
  8971. +extern struct list_lru __workingset_shadow_nodes;
  8972. +DECLARE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  8973. static inline unsigned int workingset_node_pages(struct radix_tree_node *node)
  8974. {
  8975. @@ -292,6 +294,7 @@
  8976. /* linux/mm/swap.c */
  8977. +DECLARE_LOCAL_IRQ_LOCK(swapvec_lock);
  8978. extern void lru_cache_add(struct page *);
  8979. extern void lru_cache_add_anon(struct page *page);
  8980. extern void lru_cache_add_file(struct page *page);
  8981. diff -Nur linux-4.9.6.orig/include/linux/swork.h linux-4.9.6/include/linux/swork.h
  8982. --- linux-4.9.6.orig/include/linux/swork.h 1970-01-01 01:00:00.000000000 +0100
  8983. +++ linux-4.9.6/include/linux/swork.h 2017-01-28 13:59:09.947656802 +0100
  8984. @@ -0,0 +1,24 @@
  8985. +#ifndef _LINUX_SWORK_H
  8986. +#define _LINUX_SWORK_H
  8987. +
  8988. +#include <linux/list.h>
  8989. +
  8990. +struct swork_event {
  8991. + struct list_head item;
  8992. + unsigned long flags;
  8993. + void (*func)(struct swork_event *);
  8994. +};
  8995. +
  8996. +static inline void INIT_SWORK(struct swork_event *event,
  8997. + void (*func)(struct swork_event *))
  8998. +{
  8999. + event->flags = 0;
  9000. + event->func = func;
  9001. +}
  9002. +
  9003. +bool swork_queue(struct swork_event *sev);
  9004. +
  9005. +int swork_get(void);
  9006. +void swork_put(void);
  9007. +
  9008. +#endif /* _LINUX_SWORK_H */
  9009. diff -Nur linux-4.9.6.orig/include/linux/thread_info.h linux-4.9.6/include/linux/thread_info.h
  9010. --- linux-4.9.6.orig/include/linux/thread_info.h 2017-01-26 08:25:24.000000000 +0100
  9011. +++ linux-4.9.6/include/linux/thread_info.h 2017-01-28 13:59:09.947656802 +0100
  9012. @@ -107,7 +107,17 @@
  9013. #define test_thread_flag(flag) \
  9014. test_ti_thread_flag(current_thread_info(), flag)
  9015. -#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  9016. +#ifdef CONFIG_PREEMPT_LAZY
  9017. +#define tif_need_resched() (test_thread_flag(TIF_NEED_RESCHED) || \
  9018. + test_thread_flag(TIF_NEED_RESCHED_LAZY))
  9019. +#define tif_need_resched_now() (test_thread_flag(TIF_NEED_RESCHED))
  9020. +#define tif_need_resched_lazy() test_thread_flag(TIF_NEED_RESCHED_LAZY))
  9021. +
  9022. +#else
  9023. +#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  9024. +#define tif_need_resched_now() test_thread_flag(TIF_NEED_RESCHED)
  9025. +#define tif_need_resched_lazy() 0
  9026. +#endif
  9027. #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
  9028. static inline int arch_within_stack_frames(const void * const stack,
  9029. diff -Nur linux-4.9.6.orig/include/linux/timer.h linux-4.9.6/include/linux/timer.h
  9030. --- linux-4.9.6.orig/include/linux/timer.h 2017-01-26 08:25:24.000000000 +0100
  9031. +++ linux-4.9.6/include/linux/timer.h 2017-01-28 13:59:09.947656802 +0100
  9032. @@ -241,7 +241,7 @@
  9033. extern int try_to_del_timer_sync(struct timer_list *timer);
  9034. -#ifdef CONFIG_SMP
  9035. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  9036. extern int del_timer_sync(struct timer_list *timer);
  9037. #else
  9038. # define del_timer_sync(t) del_timer(t)
  9039. diff -Nur linux-4.9.6.orig/include/linux/trace_events.h linux-4.9.6/include/linux/trace_events.h
  9040. --- linux-4.9.6.orig/include/linux/trace_events.h 2017-01-26 08:25:24.000000000 +0100
  9041. +++ linux-4.9.6/include/linux/trace_events.h 2017-01-28 13:59:09.947656802 +0100
  9042. @@ -56,6 +56,9 @@
  9043. unsigned char flags;
  9044. unsigned char preempt_count;
  9045. int pid;
  9046. + unsigned short migrate_disable;
  9047. + unsigned short padding;
  9048. + unsigned char preempt_lazy_count;
  9049. };
  9050. #define TRACE_EVENT_TYPE_MAX \
  9051. diff -Nur linux-4.9.6.orig/include/linux/uaccess.h linux-4.9.6/include/linux/uaccess.h
  9052. --- linux-4.9.6.orig/include/linux/uaccess.h 2017-01-26 08:25:24.000000000 +0100
  9053. +++ linux-4.9.6/include/linux/uaccess.h 2017-01-28 13:59:09.947656802 +0100
  9054. @@ -24,6 +24,7 @@
  9055. */
  9056. static inline void pagefault_disable(void)
  9057. {
  9058. + migrate_disable();
  9059. pagefault_disabled_inc();
  9060. /*
  9061. * make sure to have issued the store before a pagefault
  9062. @@ -40,6 +41,7 @@
  9063. */
  9064. barrier();
  9065. pagefault_disabled_dec();
  9066. + migrate_enable();
  9067. }
  9068. /*
  9069. diff -Nur linux-4.9.6.orig/include/linux/uprobes.h linux-4.9.6/include/linux/uprobes.h
  9070. --- linux-4.9.6.orig/include/linux/uprobes.h 2017-01-26 08:25:24.000000000 +0100
  9071. +++ linux-4.9.6/include/linux/uprobes.h 2017-01-28 13:59:09.947656802 +0100
  9072. @@ -27,6 +27,7 @@
  9073. #include <linux/errno.h>
  9074. #include <linux/rbtree.h>
  9075. #include <linux/types.h>
  9076. +#include <linux/wait.h>
  9077. struct vm_area_struct;
  9078. struct mm_struct;
  9079. diff -Nur linux-4.9.6.orig/include/linux/vmstat.h linux-4.9.6/include/linux/vmstat.h
  9080. --- linux-4.9.6.orig/include/linux/vmstat.h 2017-01-26 08:25:24.000000000 +0100
  9081. +++ linux-4.9.6/include/linux/vmstat.h 2017-01-28 13:59:09.947656802 +0100
  9082. @@ -33,7 +33,9 @@
  9083. */
  9084. static inline void __count_vm_event(enum vm_event_item item)
  9085. {
  9086. + preempt_disable_rt();
  9087. raw_cpu_inc(vm_event_states.event[item]);
  9088. + preempt_enable_rt();
  9089. }
  9090. static inline void count_vm_event(enum vm_event_item item)
  9091. @@ -43,7 +45,9 @@
  9092. static inline void __count_vm_events(enum vm_event_item item, long delta)
  9093. {
  9094. + preempt_disable_rt();
  9095. raw_cpu_add(vm_event_states.event[item], delta);
  9096. + preempt_enable_rt();
  9097. }
  9098. static inline void count_vm_events(enum vm_event_item item, long delta)
  9099. diff -Nur linux-4.9.6.orig/include/linux/wait.h linux-4.9.6/include/linux/wait.h
  9100. --- linux-4.9.6.orig/include/linux/wait.h 2017-01-26 08:25:24.000000000 +0100
  9101. +++ linux-4.9.6/include/linux/wait.h 2017-01-28 13:59:09.947656802 +0100
  9102. @@ -8,6 +8,7 @@
  9103. #include <linux/spinlock.h>
  9104. #include <asm/current.h>
  9105. #include <uapi/linux/wait.h>
  9106. +#include <linux/atomic.h>
  9107. typedef struct __wait_queue wait_queue_t;
  9108. typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
  9109. diff -Nur linux-4.9.6.orig/include/net/dst.h linux-4.9.6/include/net/dst.h
  9110. --- linux-4.9.6.orig/include/net/dst.h 2017-01-26 08:25:24.000000000 +0100
  9111. +++ linux-4.9.6/include/net/dst.h 2017-01-28 13:59:09.947656802 +0100
  9112. @@ -446,7 +446,7 @@
  9113. static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
  9114. struct sk_buff *skb)
  9115. {
  9116. - const struct hh_cache *hh;
  9117. + struct hh_cache *hh;
  9118. if (dst->pending_confirm) {
  9119. unsigned long now = jiffies;
  9120. diff -Nur linux-4.9.6.orig/include/net/gen_stats.h linux-4.9.6/include/net/gen_stats.h
  9121. --- linux-4.9.6.orig/include/net/gen_stats.h 2017-01-26 08:25:24.000000000 +0100
  9122. +++ linux-4.9.6/include/net/gen_stats.h 2017-01-28 13:59:09.947656802 +0100
  9123. @@ -5,6 +5,7 @@
  9124. #include <linux/socket.h>
  9125. #include <linux/rtnetlink.h>
  9126. #include <linux/pkt_sched.h>
  9127. +#include <net/net_seq_lock.h>
  9128. struct gnet_stats_basic_cpu {
  9129. struct gnet_stats_basic_packed bstats;
  9130. @@ -33,11 +34,11 @@
  9131. spinlock_t *lock, struct gnet_dump *d,
  9132. int padattr);
  9133. -int gnet_stats_copy_basic(const seqcount_t *running,
  9134. +int gnet_stats_copy_basic(net_seqlock_t *running,
  9135. struct gnet_dump *d,
  9136. struct gnet_stats_basic_cpu __percpu *cpu,
  9137. struct gnet_stats_basic_packed *b);
  9138. -void __gnet_stats_copy_basic(const seqcount_t *running,
  9139. +void __gnet_stats_copy_basic(net_seqlock_t *running,
  9140. struct gnet_stats_basic_packed *bstats,
  9141. struct gnet_stats_basic_cpu __percpu *cpu,
  9142. struct gnet_stats_basic_packed *b);
  9143. @@ -55,14 +56,14 @@
  9144. struct gnet_stats_basic_cpu __percpu *cpu_bstats,
  9145. struct gnet_stats_rate_est64 *rate_est,
  9146. spinlock_t *stats_lock,
  9147. - seqcount_t *running, struct nlattr *opt);
  9148. + net_seqlock_t *running, struct nlattr *opt);
  9149. void gen_kill_estimator(struct gnet_stats_basic_packed *bstats,
  9150. struct gnet_stats_rate_est64 *rate_est);
  9151. int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
  9152. struct gnet_stats_basic_cpu __percpu *cpu_bstats,
  9153. struct gnet_stats_rate_est64 *rate_est,
  9154. spinlock_t *stats_lock,
  9155. - seqcount_t *running, struct nlattr *opt);
  9156. + net_seqlock_t *running, struct nlattr *opt);
  9157. bool gen_estimator_active(const struct gnet_stats_basic_packed *bstats,
  9158. const struct gnet_stats_rate_est64 *rate_est);
  9159. #endif
  9160. diff -Nur linux-4.9.6.orig/include/net/neighbour.h linux-4.9.6/include/net/neighbour.h
  9161. --- linux-4.9.6.orig/include/net/neighbour.h 2017-01-26 08:25:24.000000000 +0100
  9162. +++ linux-4.9.6/include/net/neighbour.h 2017-01-28 13:59:09.947656802 +0100
  9163. @@ -446,7 +446,7 @@
  9164. }
  9165. #endif
  9166. -static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  9167. +static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
  9168. {
  9169. unsigned int seq;
  9170. int hh_len;
  9171. @@ -501,7 +501,7 @@
  9172. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  9173. -static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  9174. +static inline void neigh_ha_snapshot(char *dst, struct neighbour *n,
  9175. const struct net_device *dev)
  9176. {
  9177. unsigned int seq;
  9178. diff -Nur linux-4.9.6.orig/include/net/netns/ipv4.h linux-4.9.6/include/net/netns/ipv4.h
  9179. --- linux-4.9.6.orig/include/net/netns/ipv4.h 2017-01-26 08:25:24.000000000 +0100
  9180. +++ linux-4.9.6/include/net/netns/ipv4.h 2017-01-28 13:59:09.947656802 +0100
  9181. @@ -69,6 +69,7 @@
  9182. int sysctl_icmp_echo_ignore_all;
  9183. int sysctl_icmp_echo_ignore_broadcasts;
  9184. + int sysctl_icmp_echo_sysrq;
  9185. int sysctl_icmp_ignore_bogus_error_responses;
  9186. int sysctl_icmp_ratelimit;
  9187. int sysctl_icmp_ratemask;
  9188. diff -Nur linux-4.9.6.orig/include/net/net_seq_lock.h linux-4.9.6/include/net/net_seq_lock.h
  9189. --- linux-4.9.6.orig/include/net/net_seq_lock.h 1970-01-01 01:00:00.000000000 +0100
  9190. +++ linux-4.9.6/include/net/net_seq_lock.h 2017-01-28 13:59:09.947656802 +0100
  9191. @@ -0,0 +1,15 @@
  9192. +#ifndef __NET_NET_SEQ_LOCK_H__
  9193. +#define __NET_NET_SEQ_LOCK_H__
  9194. +
  9195. +#ifdef CONFIG_PREEMPT_RT_BASE
  9196. +# define net_seqlock_t seqlock_t
  9197. +# define net_seq_begin(__r) read_seqbegin(__r)
  9198. +# define net_seq_retry(__r, __s) read_seqretry(__r, __s)
  9199. +
  9200. +#else
  9201. +# define net_seqlock_t seqcount_t
  9202. +# define net_seq_begin(__r) read_seqcount_begin(__r)
  9203. +# define net_seq_retry(__r, __s) read_seqcount_retry(__r, __s)
  9204. +#endif
  9205. +
  9206. +#endif
  9207. diff -Nur linux-4.9.6.orig/include/net/sch_generic.h linux-4.9.6/include/net/sch_generic.h
  9208. --- linux-4.9.6.orig/include/net/sch_generic.h 2017-01-26 08:25:24.000000000 +0100
  9209. +++ linux-4.9.6/include/net/sch_generic.h 2017-01-28 13:59:09.951656955 +0100
  9210. @@ -10,6 +10,7 @@
  9211. #include <linux/dynamic_queue_limits.h>
  9212. #include <net/gen_stats.h>
  9213. #include <net/rtnetlink.h>
  9214. +#include <net/net_seq_lock.h>
  9215. struct Qdisc_ops;
  9216. struct qdisc_walker;
  9217. @@ -86,7 +87,7 @@
  9218. struct sk_buff *gso_skb ____cacheline_aligned_in_smp;
  9219. struct qdisc_skb_head q;
  9220. struct gnet_stats_basic_packed bstats;
  9221. - seqcount_t running;
  9222. + net_seqlock_t running;
  9223. struct gnet_stats_queue qstats;
  9224. unsigned long state;
  9225. struct Qdisc *next_sched;
  9226. @@ -98,13 +99,22 @@
  9227. spinlock_t busylock ____cacheline_aligned_in_smp;
  9228. };
  9229. -static inline bool qdisc_is_running(const struct Qdisc *qdisc)
  9230. +static inline bool qdisc_is_running(struct Qdisc *qdisc)
  9231. {
  9232. +#ifdef CONFIG_PREEMPT_RT_BASE
  9233. + return spin_is_locked(&qdisc->running.lock) ? true : false;
  9234. +#else
  9235. return (raw_read_seqcount(&qdisc->running) & 1) ? true : false;
  9236. +#endif
  9237. }
  9238. static inline bool qdisc_run_begin(struct Qdisc *qdisc)
  9239. {
  9240. +#ifdef CONFIG_PREEMPT_RT_BASE
  9241. + if (try_write_seqlock(&qdisc->running))
  9242. + return true;
  9243. + return false;
  9244. +#else
  9245. if (qdisc_is_running(qdisc))
  9246. return false;
  9247. /* Variant of write_seqcount_begin() telling lockdep a trylock
  9248. @@ -113,11 +123,16 @@
  9249. raw_write_seqcount_begin(&qdisc->running);
  9250. seqcount_acquire(&qdisc->running.dep_map, 0, 1, _RET_IP_);
  9251. return true;
  9252. +#endif
  9253. }
  9254. static inline void qdisc_run_end(struct Qdisc *qdisc)
  9255. {
  9256. +#ifdef CONFIG_PREEMPT_RT_BASE
  9257. + write_sequnlock(&qdisc->running);
  9258. +#else
  9259. write_seqcount_end(&qdisc->running);
  9260. +#endif
  9261. }
  9262. static inline bool qdisc_may_bulk(const struct Qdisc *qdisc)
  9263. @@ -308,7 +323,7 @@
  9264. return qdisc_lock(root);
  9265. }
  9266. -static inline seqcount_t *qdisc_root_sleeping_running(const struct Qdisc *qdisc)
  9267. +static inline net_seqlock_t *qdisc_root_sleeping_running(const struct Qdisc *qdisc)
  9268. {
  9269. struct Qdisc *root = qdisc_root_sleeping(qdisc);
  9270. diff -Nur linux-4.9.6.orig/include/trace/events/hist.h linux-4.9.6/include/trace/events/hist.h
  9271. --- linux-4.9.6.orig/include/trace/events/hist.h 1970-01-01 01:00:00.000000000 +0100
  9272. +++ linux-4.9.6/include/trace/events/hist.h 2017-01-28 13:59:09.951656955 +0100
  9273. @@ -0,0 +1,73 @@
  9274. +#undef TRACE_SYSTEM
  9275. +#define TRACE_SYSTEM hist
  9276. +
  9277. +#if !defined(_TRACE_HIST_H) || defined(TRACE_HEADER_MULTI_READ)
  9278. +#define _TRACE_HIST_H
  9279. +
  9280. +#include "latency_hist.h"
  9281. +#include <linux/tracepoint.h>
  9282. +
  9283. +#if !defined(CONFIG_PREEMPT_OFF_HIST) && !defined(CONFIG_INTERRUPT_OFF_HIST)
  9284. +#define trace_preemptirqsoff_hist(a, b)
  9285. +#define trace_preemptirqsoff_hist_rcuidle(a, b)
  9286. +#else
  9287. +TRACE_EVENT(preemptirqsoff_hist,
  9288. +
  9289. + TP_PROTO(int reason, int starthist),
  9290. +
  9291. + TP_ARGS(reason, starthist),
  9292. +
  9293. + TP_STRUCT__entry(
  9294. + __field(int, reason)
  9295. + __field(int, starthist)
  9296. + ),
  9297. +
  9298. + TP_fast_assign(
  9299. + __entry->reason = reason;
  9300. + __entry->starthist = starthist;
  9301. + ),
  9302. +
  9303. + TP_printk("reason=%s starthist=%s", getaction(__entry->reason),
  9304. + __entry->starthist ? "start" : "stop")
  9305. +);
  9306. +#endif
  9307. +
  9308. +#ifndef CONFIG_MISSED_TIMER_OFFSETS_HIST
  9309. +#define trace_hrtimer_interrupt(a, b, c, d)
  9310. +#else
  9311. +TRACE_EVENT(hrtimer_interrupt,
  9312. +
  9313. + TP_PROTO(int cpu, long long offset, struct task_struct *curr,
  9314. + struct task_struct *task),
  9315. +
  9316. + TP_ARGS(cpu, offset, curr, task),
  9317. +
  9318. + TP_STRUCT__entry(
  9319. + __field(int, cpu)
  9320. + __field(long long, offset)
  9321. + __array(char, ccomm, TASK_COMM_LEN)
  9322. + __field(int, cprio)
  9323. + __array(char, tcomm, TASK_COMM_LEN)
  9324. + __field(int, tprio)
  9325. + ),
  9326. +
  9327. + TP_fast_assign(
  9328. + __entry->cpu = cpu;
  9329. + __entry->offset = offset;
  9330. + memcpy(__entry->ccomm, curr->comm, TASK_COMM_LEN);
  9331. + __entry->cprio = curr->prio;
  9332. + memcpy(__entry->tcomm, task != NULL ? task->comm : "<none>",
  9333. + task != NULL ? TASK_COMM_LEN : 7);
  9334. + __entry->tprio = task != NULL ? task->prio : -1;
  9335. + ),
  9336. +
  9337. + TP_printk("cpu=%d offset=%lld curr=%s[%d] thread=%s[%d]",
  9338. + __entry->cpu, __entry->offset, __entry->ccomm,
  9339. + __entry->cprio, __entry->tcomm, __entry->tprio)
  9340. +);
  9341. +#endif
  9342. +
  9343. +#endif /* _TRACE_HIST_H */
  9344. +
  9345. +/* This part must be outside protection */
  9346. +#include <trace/define_trace.h>
  9347. diff -Nur linux-4.9.6.orig/include/trace/events/latency_hist.h linux-4.9.6/include/trace/events/latency_hist.h
  9348. --- linux-4.9.6.orig/include/trace/events/latency_hist.h 1970-01-01 01:00:00.000000000 +0100
  9349. +++ linux-4.9.6/include/trace/events/latency_hist.h 2017-01-28 13:59:09.951656955 +0100
  9350. @@ -0,0 +1,29 @@
  9351. +#ifndef _LATENCY_HIST_H
  9352. +#define _LATENCY_HIST_H
  9353. +
  9354. +enum hist_action {
  9355. + IRQS_ON,
  9356. + PREEMPT_ON,
  9357. + TRACE_STOP,
  9358. + IRQS_OFF,
  9359. + PREEMPT_OFF,
  9360. + TRACE_START,
  9361. +};
  9362. +
  9363. +static char *actions[] = {
  9364. + "IRQS_ON",
  9365. + "PREEMPT_ON",
  9366. + "TRACE_STOP",
  9367. + "IRQS_OFF",
  9368. + "PREEMPT_OFF",
  9369. + "TRACE_START",
  9370. +};
  9371. +
  9372. +static inline char *getaction(int action)
  9373. +{
  9374. + if (action >= 0 && action <= sizeof(actions)/sizeof(actions[0]))
  9375. + return actions[action];
  9376. + return "unknown";
  9377. +}
  9378. +
  9379. +#endif /* _LATENCY_HIST_H */
  9380. diff -Nur linux-4.9.6.orig/init/Kconfig linux-4.9.6/init/Kconfig
  9381. --- linux-4.9.6.orig/init/Kconfig 2017-01-26 08:25:24.000000000 +0100
  9382. +++ linux-4.9.6/init/Kconfig 2017-01-28 13:59:09.951656955 +0100
  9383. @@ -506,7 +506,7 @@
  9384. config RCU_EXPERT
  9385. bool "Make expert-level adjustments to RCU configuration"
  9386. - default n
  9387. + default y if PREEMPT_RT_FULL
  9388. help
  9389. This option needs to be enabled if you wish to make
  9390. expert-level adjustments to RCU configuration. By default,
  9391. @@ -623,7 +623,7 @@
  9392. config RCU_FAST_NO_HZ
  9393. bool "Accelerate last non-dyntick-idle CPU's grace periods"
  9394. - depends on NO_HZ_COMMON && SMP && RCU_EXPERT
  9395. + depends on NO_HZ_COMMON && SMP && RCU_EXPERT && !PREEMPT_RT_FULL
  9396. default n
  9397. help
  9398. This option permits CPUs to enter dynticks-idle state even if
  9399. @@ -650,7 +650,7 @@
  9400. config RCU_BOOST
  9401. bool "Enable RCU priority boosting"
  9402. depends on RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT
  9403. - default n
  9404. + default y if PREEMPT_RT_FULL
  9405. help
  9406. This option boosts the priority of preempted RCU readers that
  9407. block the current preemptible RCU grace period for too long.
  9408. @@ -781,19 +781,6 @@
  9409. endchoice
  9410. -config RCU_EXPEDITE_BOOT
  9411. - bool
  9412. - default n
  9413. - help
  9414. - This option enables expedited grace periods at boot time,
  9415. - as if rcu_expedite_gp() had been invoked early in boot.
  9416. - The corresponding rcu_unexpedite_gp() is invoked from
  9417. - rcu_end_inkernel_boot(), which is intended to be invoked
  9418. - at the end of the kernel-only boot sequence, just before
  9419. - init is exec'ed.
  9420. -
  9421. - Accept the default if unsure.
  9422. -
  9423. endmenu # "RCU Subsystem"
  9424. config BUILD_BIN2C
  9425. @@ -1064,6 +1051,7 @@
  9426. config RT_GROUP_SCHED
  9427. bool "Group scheduling for SCHED_RR/FIFO"
  9428. depends on CGROUP_SCHED
  9429. + depends on !PREEMPT_RT_FULL
  9430. default n
  9431. help
  9432. This feature lets you explicitly allocate real CPU bandwidth
  9433. @@ -1772,6 +1760,7 @@
  9434. config SLAB
  9435. bool "SLAB"
  9436. + depends on !PREEMPT_RT_FULL
  9437. select HAVE_HARDENED_USERCOPY_ALLOCATOR
  9438. help
  9439. The regular slab allocator that is established and known to work
  9440. @@ -1792,6 +1781,7 @@
  9441. config SLOB
  9442. depends on EXPERT
  9443. bool "SLOB (Simple Allocator)"
  9444. + depends on !PREEMPT_RT_FULL
  9445. help
  9446. SLOB replaces the stock allocator with a drastically simpler
  9447. allocator. SLOB is generally more space efficient but
  9448. @@ -1810,7 +1800,7 @@
  9449. config SLUB_CPU_PARTIAL
  9450. default y
  9451. - depends on SLUB && SMP
  9452. + depends on SLUB && SMP && !PREEMPT_RT_FULL
  9453. bool "SLUB per cpu partial cache"
  9454. help
  9455. Per cpu partial caches accellerate objects allocation and freeing
  9456. diff -Nur linux-4.9.6.orig/init/main.c linux-4.9.6/init/main.c
  9457. --- linux-4.9.6.orig/init/main.c 2017-01-26 08:25:24.000000000 +0100
  9458. +++ linux-4.9.6/init/main.c 2017-01-28 13:59:09.951656955 +0100
  9459. @@ -507,6 +507,7 @@
  9460. setup_command_line(command_line);
  9461. setup_nr_cpu_ids();
  9462. setup_per_cpu_areas();
  9463. + softirq_early_init();
  9464. boot_cpu_state_init();
  9465. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  9466. diff -Nur linux-4.9.6.orig/init/Makefile linux-4.9.6/init/Makefile
  9467. --- linux-4.9.6.orig/init/Makefile 2017-01-26 08:25:24.000000000 +0100
  9468. +++ linux-4.9.6/init/Makefile 2017-01-28 13:59:09.951656955 +0100
  9469. @@ -35,4 +35,4 @@
  9470. include/generated/compile.h: FORCE
  9471. @$($(quiet)chk_compile.h)
  9472. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
  9473. - "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)"
  9474. + "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CONFIG_PREEMPT_RT_FULL)" "$(CC) $(KBUILD_CFLAGS)"
  9475. diff -Nur linux-4.9.6.orig/ipc/sem.c linux-4.9.6/ipc/sem.c
  9476. --- linux-4.9.6.orig/ipc/sem.c 2017-01-26 08:25:24.000000000 +0100
  9477. +++ linux-4.9.6/ipc/sem.c 2017-01-28 13:59:09.951656955 +0100
  9478. @@ -712,6 +712,13 @@
  9479. static void wake_up_sem_queue_prepare(struct list_head *pt,
  9480. struct sem_queue *q, int error)
  9481. {
  9482. +#ifdef CONFIG_PREEMPT_RT_BASE
  9483. + struct task_struct *p = q->sleeper;
  9484. + get_task_struct(p);
  9485. + q->status = error;
  9486. + wake_up_process(p);
  9487. + put_task_struct(p);
  9488. +#else
  9489. if (list_empty(pt)) {
  9490. /*
  9491. * Hold preempt off so that we don't get preempted and have the
  9492. @@ -723,6 +730,7 @@
  9493. q->pid = error;
  9494. list_add_tail(&q->list, pt);
  9495. +#endif
  9496. }
  9497. /**
  9498. @@ -736,6 +744,7 @@
  9499. */
  9500. static void wake_up_sem_queue_do(struct list_head *pt)
  9501. {
  9502. +#ifndef CONFIG_PREEMPT_RT_BASE
  9503. struct sem_queue *q, *t;
  9504. int did_something;
  9505. @@ -748,6 +757,7 @@
  9506. }
  9507. if (did_something)
  9508. preempt_enable();
  9509. +#endif
  9510. }
  9511. static void unlink_queue(struct sem_array *sma, struct sem_queue *q)
  9512. diff -Nur linux-4.9.6.orig/kernel/cgroup.c linux-4.9.6/kernel/cgroup.c
  9513. --- linux-4.9.6.orig/kernel/cgroup.c 2017-01-26 08:25:24.000000000 +0100
  9514. +++ linux-4.9.6/kernel/cgroup.c 2017-01-28 13:59:09.951656955 +0100
  9515. @@ -5040,10 +5040,10 @@
  9516. queue_work(cgroup_destroy_wq, &css->destroy_work);
  9517. }
  9518. -static void css_release_work_fn(struct work_struct *work)
  9519. +static void css_release_work_fn(struct swork_event *sev)
  9520. {
  9521. struct cgroup_subsys_state *css =
  9522. - container_of(work, struct cgroup_subsys_state, destroy_work);
  9523. + container_of(sev, struct cgroup_subsys_state, destroy_swork);
  9524. struct cgroup_subsys *ss = css->ss;
  9525. struct cgroup *cgrp = css->cgroup;
  9526. @@ -5086,8 +5086,8 @@
  9527. struct cgroup_subsys_state *css =
  9528. container_of(ref, struct cgroup_subsys_state, refcnt);
  9529. - INIT_WORK(&css->destroy_work, css_release_work_fn);
  9530. - queue_work(cgroup_destroy_wq, &css->destroy_work);
  9531. + INIT_SWORK(&css->destroy_swork, css_release_work_fn);
  9532. + swork_queue(&css->destroy_swork);
  9533. }
  9534. static void init_and_link_css(struct cgroup_subsys_state *css,
  9535. @@ -5742,6 +5742,7 @@
  9536. */
  9537. cgroup_destroy_wq = alloc_workqueue("cgroup_destroy", 0, 1);
  9538. BUG_ON(!cgroup_destroy_wq);
  9539. + BUG_ON(swork_get());
  9540. /*
  9541. * Used to destroy pidlists and separate to serve as flush domain.
  9542. diff -Nur linux-4.9.6.orig/kernel/cpu.c linux-4.9.6/kernel/cpu.c
  9543. --- linux-4.9.6.orig/kernel/cpu.c 2017-01-26 08:25:24.000000000 +0100
  9544. +++ linux-4.9.6/kernel/cpu.c 2017-01-28 13:59:09.951656955 +0100
  9545. @@ -239,6 +239,289 @@
  9546. #define cpuhp_lock_acquire() lock_map_acquire(&cpu_hotplug.dep_map)
  9547. #define cpuhp_lock_release() lock_map_release(&cpu_hotplug.dep_map)
  9548. +/**
  9549. + * hotplug_pcp - per cpu hotplug descriptor
  9550. + * @unplug: set when pin_current_cpu() needs to sync tasks
  9551. + * @sync_tsk: the task that waits for tasks to finish pinned sections
  9552. + * @refcount: counter of tasks in pinned sections
  9553. + * @grab_lock: set when the tasks entering pinned sections should wait
  9554. + * @synced: notifier for @sync_tsk to tell cpu_down it's finished
  9555. + * @mutex: the mutex to make tasks wait (used when @grab_lock is true)
  9556. + * @mutex_init: zero if the mutex hasn't been initialized yet.
  9557. + *
  9558. + * Although @unplug and @sync_tsk may point to the same task, the @unplug
  9559. + * is used as a flag and still exists after @sync_tsk has exited and
  9560. + * @sync_tsk set to NULL.
  9561. + */
  9562. +struct hotplug_pcp {
  9563. + struct task_struct *unplug;
  9564. + struct task_struct *sync_tsk;
  9565. + int refcount;
  9566. + int grab_lock;
  9567. + struct completion synced;
  9568. + struct completion unplug_wait;
  9569. +#ifdef CONFIG_PREEMPT_RT_FULL
  9570. + /*
  9571. + * Note, on PREEMPT_RT, the hotplug lock must save the state of
  9572. + * the task, otherwise the mutex will cause the task to fail
  9573. + * to sleep when required. (Because it's called from migrate_disable())
  9574. + *
  9575. + * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
  9576. + * state.
  9577. + */
  9578. + spinlock_t lock;
  9579. +#else
  9580. + struct mutex mutex;
  9581. +#endif
  9582. + int mutex_init;
  9583. +};
  9584. +
  9585. +#ifdef CONFIG_PREEMPT_RT_FULL
  9586. +# define hotplug_lock(hp) rt_spin_lock__no_mg(&(hp)->lock)
  9587. +# define hotplug_unlock(hp) rt_spin_unlock__no_mg(&(hp)->lock)
  9588. +#else
  9589. +# define hotplug_lock(hp) mutex_lock(&(hp)->mutex)
  9590. +# define hotplug_unlock(hp) mutex_unlock(&(hp)->mutex)
  9591. +#endif
  9592. +
  9593. +static DEFINE_PER_CPU(struct hotplug_pcp, hotplug_pcp);
  9594. +
  9595. +/**
  9596. + * pin_current_cpu - Prevent the current cpu from being unplugged
  9597. + *
  9598. + * Lightweight version of get_online_cpus() to prevent cpu from being
  9599. + * unplugged when code runs in a migration disabled region.
  9600. + *
  9601. + * Must be called with preemption disabled (preempt_count = 1)!
  9602. + */
  9603. +void pin_current_cpu(void)
  9604. +{
  9605. + struct hotplug_pcp *hp;
  9606. + int force = 0;
  9607. +
  9608. +retry:
  9609. + hp = this_cpu_ptr(&hotplug_pcp);
  9610. +
  9611. + if (!hp->unplug || hp->refcount || force || preempt_count() > 1 ||
  9612. + hp->unplug == current) {
  9613. + hp->refcount++;
  9614. + return;
  9615. + }
  9616. + if (hp->grab_lock) {
  9617. + preempt_enable();
  9618. + hotplug_lock(hp);
  9619. + hotplug_unlock(hp);
  9620. + } else {
  9621. + preempt_enable();
  9622. + /*
  9623. + * Try to push this task off of this CPU.
  9624. + */
  9625. + if (!migrate_me()) {
  9626. + preempt_disable();
  9627. + hp = this_cpu_ptr(&hotplug_pcp);
  9628. + if (!hp->grab_lock) {
  9629. + /*
  9630. + * Just let it continue it's already pinned
  9631. + * or about to sleep.
  9632. + */
  9633. + force = 1;
  9634. + goto retry;
  9635. + }
  9636. + preempt_enable();
  9637. + }
  9638. + }
  9639. + preempt_disable();
  9640. + goto retry;
  9641. +}
  9642. +
  9643. +/**
  9644. + * unpin_current_cpu - Allow unplug of current cpu
  9645. + *
  9646. + * Must be called with preemption or interrupts disabled!
  9647. + */
  9648. +void unpin_current_cpu(void)
  9649. +{
  9650. + struct hotplug_pcp *hp = this_cpu_ptr(&hotplug_pcp);
  9651. +
  9652. + WARN_ON(hp->refcount <= 0);
  9653. +
  9654. + /* This is safe. sync_unplug_thread is pinned to this cpu */
  9655. + if (!--hp->refcount && hp->unplug && hp->unplug != current)
  9656. + wake_up_process(hp->unplug);
  9657. +}
  9658. +
  9659. +static void wait_for_pinned_cpus(struct hotplug_pcp *hp)
  9660. +{
  9661. + set_current_state(TASK_UNINTERRUPTIBLE);
  9662. + while (hp->refcount) {
  9663. + schedule_preempt_disabled();
  9664. + set_current_state(TASK_UNINTERRUPTIBLE);
  9665. + }
  9666. +}
  9667. +
  9668. +static int sync_unplug_thread(void *data)
  9669. +{
  9670. + struct hotplug_pcp *hp = data;
  9671. +
  9672. + wait_for_completion(&hp->unplug_wait);
  9673. + preempt_disable();
  9674. + hp->unplug = current;
  9675. + wait_for_pinned_cpus(hp);
  9676. +
  9677. + /*
  9678. + * This thread will synchronize the cpu_down() with threads
  9679. + * that have pinned the CPU. When the pinned CPU count reaches
  9680. + * zero, we inform the cpu_down code to continue to the next step.
  9681. + */
  9682. + set_current_state(TASK_UNINTERRUPTIBLE);
  9683. + preempt_enable();
  9684. + complete(&hp->synced);
  9685. +
  9686. + /*
  9687. + * If all succeeds, the next step will need tasks to wait till
  9688. + * the CPU is offline before continuing. To do this, the grab_lock
  9689. + * is set and tasks going into pin_current_cpu() will block on the
  9690. + * mutex. But we still need to wait for those that are already in
  9691. + * pinned CPU sections. If the cpu_down() failed, the kthread_should_stop()
  9692. + * will kick this thread out.
  9693. + */
  9694. + while (!hp->grab_lock && !kthread_should_stop()) {
  9695. + schedule();
  9696. + set_current_state(TASK_UNINTERRUPTIBLE);
  9697. + }
  9698. +
  9699. + /* Make sure grab_lock is seen before we see a stale completion */
  9700. + smp_mb();
  9701. +
  9702. + /*
  9703. + * Now just before cpu_down() enters stop machine, we need to make
  9704. + * sure all tasks that are in pinned CPU sections are out, and new
  9705. + * tasks will now grab the lock, keeping them from entering pinned
  9706. + * CPU sections.
  9707. + */
  9708. + if (!kthread_should_stop()) {
  9709. + preempt_disable();
  9710. + wait_for_pinned_cpus(hp);
  9711. + preempt_enable();
  9712. + complete(&hp->synced);
  9713. + }
  9714. +
  9715. + set_current_state(TASK_UNINTERRUPTIBLE);
  9716. + while (!kthread_should_stop()) {
  9717. + schedule();
  9718. + set_current_state(TASK_UNINTERRUPTIBLE);
  9719. + }
  9720. + set_current_state(TASK_RUNNING);
  9721. +
  9722. + /*
  9723. + * Force this thread off this CPU as it's going down and
  9724. + * we don't want any more work on this CPU.
  9725. + */
  9726. + current->flags &= ~PF_NO_SETAFFINITY;
  9727. + set_cpus_allowed_ptr(current, cpu_present_mask);
  9728. + migrate_me();
  9729. + return 0;
  9730. +}
  9731. +
  9732. +static void __cpu_unplug_sync(struct hotplug_pcp *hp)
  9733. +{
  9734. + wake_up_process(hp->sync_tsk);
  9735. + wait_for_completion(&hp->synced);
  9736. +}
  9737. +
  9738. +static void __cpu_unplug_wait(unsigned int cpu)
  9739. +{
  9740. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  9741. +
  9742. + complete(&hp->unplug_wait);
  9743. + wait_for_completion(&hp->synced);
  9744. +}
  9745. +
  9746. +/*
  9747. + * Start the sync_unplug_thread on the target cpu and wait for it to
  9748. + * complete.
  9749. + */
  9750. +static int cpu_unplug_begin(unsigned int cpu)
  9751. +{
  9752. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  9753. + int err;
  9754. +
  9755. + /* Protected by cpu_hotplug.lock */
  9756. + if (!hp->mutex_init) {
  9757. +#ifdef CONFIG_PREEMPT_RT_FULL
  9758. + spin_lock_init(&hp->lock);
  9759. +#else
  9760. + mutex_init(&hp->mutex);
  9761. +#endif
  9762. + hp->mutex_init = 1;
  9763. + }
  9764. +
  9765. + /* Inform the scheduler to migrate tasks off this CPU */
  9766. + tell_sched_cpu_down_begin(cpu);
  9767. +
  9768. + init_completion(&hp->synced);
  9769. + init_completion(&hp->unplug_wait);
  9770. +
  9771. + hp->sync_tsk = kthread_create(sync_unplug_thread, hp, "sync_unplug/%d", cpu);
  9772. + if (IS_ERR(hp->sync_tsk)) {
  9773. + err = PTR_ERR(hp->sync_tsk);
  9774. + hp->sync_tsk = NULL;
  9775. + return err;
  9776. + }
  9777. + kthread_bind(hp->sync_tsk, cpu);
  9778. +
  9779. + /*
  9780. + * Wait for tasks to get out of the pinned sections,
  9781. + * it's still OK if new tasks enter. Some CPU notifiers will
  9782. + * wait for tasks that are going to enter these sections and
  9783. + * we must not have them block.
  9784. + */
  9785. + wake_up_process(hp->sync_tsk);
  9786. + return 0;
  9787. +}
  9788. +
  9789. +static void cpu_unplug_sync(unsigned int cpu)
  9790. +{
  9791. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  9792. +
  9793. + init_completion(&hp->synced);
  9794. + /* The completion needs to be initialzied before setting grab_lock */
  9795. + smp_wmb();
  9796. +
  9797. + /* Grab the mutex before setting grab_lock */
  9798. + hotplug_lock(hp);
  9799. + hp->grab_lock = 1;
  9800. +
  9801. + /*
  9802. + * The CPU notifiers have been completed.
  9803. + * Wait for tasks to get out of pinned CPU sections and have new
  9804. + * tasks block until the CPU is completely down.
  9805. + */
  9806. + __cpu_unplug_sync(hp);
  9807. +
  9808. + /* All done with the sync thread */
  9809. + kthread_stop(hp->sync_tsk);
  9810. + hp->sync_tsk = NULL;
  9811. +}
  9812. +
  9813. +static void cpu_unplug_done(unsigned int cpu)
  9814. +{
  9815. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  9816. +
  9817. + hp->unplug = NULL;
  9818. + /* Let all tasks know cpu unplug is finished before cleaning up */
  9819. + smp_wmb();
  9820. +
  9821. + if (hp->sync_tsk)
  9822. + kthread_stop(hp->sync_tsk);
  9823. +
  9824. + if (hp->grab_lock) {
  9825. + hotplug_unlock(hp);
  9826. + /* protected by cpu_hotplug.lock */
  9827. + hp->grab_lock = 0;
  9828. + }
  9829. + tell_sched_cpu_down_done(cpu);
  9830. +}
  9831. void get_online_cpus(void)
  9832. {
  9833. @@ -789,10 +1072,14 @@
  9834. struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
  9835. int err;
  9836. + __cpu_unplug_wait(cpu);
  9837. /* Park the smpboot threads */
  9838. kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
  9839. smpboot_park_threads(cpu);
  9840. + /* Notifiers are done. Don't let any more tasks pin this CPU. */
  9841. + cpu_unplug_sync(cpu);
  9842. +
  9843. /*
  9844. * Prevent irq alloc/free while the dying cpu reorganizes the
  9845. * interrupt affinities.
  9846. @@ -877,6 +1164,9 @@
  9847. struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
  9848. int prev_state, ret = 0;
  9849. bool hasdied = false;
  9850. + int mycpu;
  9851. + cpumask_var_t cpumask;
  9852. + cpumask_var_t cpumask_org;
  9853. if (num_online_cpus() == 1)
  9854. return -EBUSY;
  9855. @@ -884,7 +1174,34 @@
  9856. if (!cpu_present(cpu))
  9857. return -EINVAL;
  9858. + /* Move the downtaker off the unplug cpu */
  9859. + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
  9860. + return -ENOMEM;
  9861. + if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL)) {
  9862. + free_cpumask_var(cpumask);
  9863. + return -ENOMEM;
  9864. + }
  9865. +
  9866. + cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
  9867. + cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
  9868. + set_cpus_allowed_ptr(current, cpumask);
  9869. + free_cpumask_var(cpumask);
  9870. + migrate_disable();
  9871. + mycpu = smp_processor_id();
  9872. + if (mycpu == cpu) {
  9873. + printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
  9874. + migrate_enable();
  9875. + ret = -EBUSY;
  9876. + goto restore_cpus;
  9877. + }
  9878. +
  9879. + migrate_enable();
  9880. cpu_hotplug_begin();
  9881. + ret = cpu_unplug_begin(cpu);
  9882. + if (ret) {
  9883. + printk("cpu_unplug_begin(%d) failed\n", cpu);
  9884. + goto out_cancel;
  9885. + }
  9886. cpuhp_tasks_frozen = tasks_frozen;
  9887. @@ -923,10 +1240,15 @@
  9888. hasdied = prev_state != st->state && st->state == CPUHP_OFFLINE;
  9889. out:
  9890. + cpu_unplug_done(cpu);
  9891. +out_cancel:
  9892. cpu_hotplug_done();
  9893. /* This post dead nonsense must die */
  9894. if (!ret && hasdied)
  9895. cpu_notify_nofail(CPU_POST_DEAD, cpu);
  9896. +restore_cpus:
  9897. + set_cpus_allowed_ptr(current, cpumask_org);
  9898. + free_cpumask_var(cpumask_org);
  9899. return ret;
  9900. }
  9901. diff -Nur linux-4.9.6.orig/kernel/debug/kdb/kdb_io.c linux-4.9.6/kernel/debug/kdb/kdb_io.c
  9902. --- linux-4.9.6.orig/kernel/debug/kdb/kdb_io.c 2017-01-26 08:25:24.000000000 +0100
  9903. +++ linux-4.9.6/kernel/debug/kdb/kdb_io.c 2017-01-28 13:59:09.951656955 +0100
  9904. @@ -554,7 +554,6 @@
  9905. int linecount;
  9906. int colcount;
  9907. int logging, saved_loglevel = 0;
  9908. - int saved_trap_printk;
  9909. int got_printf_lock = 0;
  9910. int retlen = 0;
  9911. int fnd, len;
  9912. @@ -565,8 +564,6 @@
  9913. unsigned long uninitialized_var(flags);
  9914. preempt_disable();
  9915. - saved_trap_printk = kdb_trap_printk;
  9916. - kdb_trap_printk = 0;
  9917. /* Serialize kdb_printf if multiple cpus try to write at once.
  9918. * But if any cpu goes recursive in kdb, just print the output,
  9919. @@ -855,7 +852,6 @@
  9920. } else {
  9921. __release(kdb_printf_lock);
  9922. }
  9923. - kdb_trap_printk = saved_trap_printk;
  9924. preempt_enable();
  9925. return retlen;
  9926. }
  9927. @@ -865,9 +861,11 @@
  9928. va_list ap;
  9929. int r;
  9930. + kdb_trap_printk++;
  9931. va_start(ap, fmt);
  9932. r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap);
  9933. va_end(ap);
  9934. + kdb_trap_printk--;
  9935. return r;
  9936. }
  9937. diff -Nur linux-4.9.6.orig/kernel/events/core.c linux-4.9.6/kernel/events/core.c
  9938. --- linux-4.9.6.orig/kernel/events/core.c 2017-01-26 08:25:24.000000000 +0100
  9939. +++ linux-4.9.6/kernel/events/core.c 2017-01-28 13:59:09.955657109 +0100
  9940. @@ -1050,6 +1050,7 @@
  9941. raw_spin_lock_init(&cpuctx->hrtimer_lock);
  9942. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
  9943. timer->function = perf_mux_hrtimer_handler;
  9944. + timer->irqsafe = 1;
  9945. }
  9946. static int perf_mux_hrtimer_restart(struct perf_cpu_context *cpuctx)
  9947. @@ -8335,6 +8336,7 @@
  9948. hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  9949. hwc->hrtimer.function = perf_swevent_hrtimer;
  9950. + hwc->hrtimer.irqsafe = 1;
  9951. /*
  9952. * Since hrtimers have a fixed rate, we can do a static freq->period
  9953. diff -Nur linux-4.9.6.orig/kernel/exit.c linux-4.9.6/kernel/exit.c
  9954. --- linux-4.9.6.orig/kernel/exit.c 2017-01-26 08:25:24.000000000 +0100
  9955. +++ linux-4.9.6/kernel/exit.c 2017-01-28 13:59:09.955657109 +0100
  9956. @@ -143,7 +143,7 @@
  9957. * Do this under ->siglock, we can race with another thread
  9958. * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
  9959. */
  9960. - flush_sigqueue(&tsk->pending);
  9961. + flush_task_sigqueue(tsk);
  9962. tsk->sighand = NULL;
  9963. spin_unlock(&sighand->siglock);
  9964. diff -Nur linux-4.9.6.orig/kernel/fork.c linux-4.9.6/kernel/fork.c
  9965. --- linux-4.9.6.orig/kernel/fork.c 2017-01-26 08:25:24.000000000 +0100
  9966. +++ linux-4.9.6/kernel/fork.c 2017-01-28 13:59:09.955657109 +0100
  9967. @@ -76,6 +76,7 @@
  9968. #include <linux/compiler.h>
  9969. #include <linux/sysctl.h>
  9970. #include <linux/kcov.h>
  9971. +#include <linux/kprobes.h>
  9972. #include <asm/pgtable.h>
  9973. #include <asm/pgalloc.h>
  9974. @@ -376,13 +377,24 @@
  9975. if (atomic_dec_and_test(&sig->sigcnt))
  9976. free_signal_struct(sig);
  9977. }
  9978. -
  9979. +#ifdef CONFIG_PREEMPT_RT_BASE
  9980. +static
  9981. +#endif
  9982. void __put_task_struct(struct task_struct *tsk)
  9983. {
  9984. WARN_ON(!tsk->exit_state);
  9985. WARN_ON(atomic_read(&tsk->usage));
  9986. WARN_ON(tsk == current);
  9987. + /*
  9988. + * Remove function-return probe instances associated with this
  9989. + * task and put them back on the free list.
  9990. + */
  9991. + kprobe_flush_task(tsk);
  9992. +
  9993. + /* Task is done with its stack. */
  9994. + put_task_stack(tsk);
  9995. +
  9996. cgroup_free(tsk);
  9997. task_numa_free(tsk);
  9998. security_task_free(tsk);
  9999. @@ -393,7 +405,18 @@
  10000. if (!profile_handoff_task(tsk))
  10001. free_task(tsk);
  10002. }
  10003. +#ifndef CONFIG_PREEMPT_RT_BASE
  10004. EXPORT_SYMBOL_GPL(__put_task_struct);
  10005. +#else
  10006. +void __put_task_struct_cb(struct rcu_head *rhp)
  10007. +{
  10008. + struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
  10009. +
  10010. + __put_task_struct(tsk);
  10011. +
  10012. +}
  10013. +EXPORT_SYMBOL_GPL(__put_task_struct_cb);
  10014. +#endif
  10015. void __init __weak arch_task_cache_init(void) { }
  10016. @@ -852,6 +875,19 @@
  10017. }
  10018. EXPORT_SYMBOL_GPL(__mmdrop);
  10019. +#ifdef CONFIG_PREEMPT_RT_BASE
  10020. +/*
  10021. + * RCU callback for delayed mm drop. Not strictly rcu, but we don't
  10022. + * want another facility to make this work.
  10023. + */
  10024. +void __mmdrop_delayed(struct rcu_head *rhp)
  10025. +{
  10026. + struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
  10027. +
  10028. + __mmdrop(mm);
  10029. +}
  10030. +#endif
  10031. +
  10032. static inline void __mmput(struct mm_struct *mm)
  10033. {
  10034. VM_BUG_ON(atomic_read(&mm->mm_users));
  10035. @@ -1426,6 +1462,9 @@
  10036. */
  10037. static void posix_cpu_timers_init(struct task_struct *tsk)
  10038. {
  10039. +#ifdef CONFIG_PREEMPT_RT_BASE
  10040. + tsk->posix_timer_list = NULL;
  10041. +#endif
  10042. tsk->cputime_expires.prof_exp = 0;
  10043. tsk->cputime_expires.virt_exp = 0;
  10044. tsk->cputime_expires.sched_exp = 0;
  10045. @@ -1552,6 +1591,7 @@
  10046. spin_lock_init(&p->alloc_lock);
  10047. init_sigpending(&p->pending);
  10048. + p->sigqueue_cache = NULL;
  10049. p->utime = p->stime = p->gtime = 0;
  10050. p->utimescaled = p->stimescaled = 0;
  10051. diff -Nur linux-4.9.6.orig/kernel/futex.c linux-4.9.6/kernel/futex.c
  10052. --- linux-4.9.6.orig/kernel/futex.c 2017-01-26 08:25:24.000000000 +0100
  10053. +++ linux-4.9.6/kernel/futex.c 2017-01-28 13:59:09.955657109 +0100
  10054. @@ -904,7 +904,9 @@
  10055. * task still owns the PI-state:
  10056. */
  10057. if (head->next != next) {
  10058. + raw_spin_unlock_irq(&curr->pi_lock);
  10059. spin_unlock(&hb->lock);
  10060. + raw_spin_lock_irq(&curr->pi_lock);
  10061. continue;
  10062. }
  10063. @@ -1299,6 +1301,7 @@
  10064. struct futex_pi_state *pi_state = this->pi_state;
  10065. u32 uninitialized_var(curval), newval;
  10066. WAKE_Q(wake_q);
  10067. + WAKE_Q(wake_sleeper_q);
  10068. bool deboost;
  10069. int ret = 0;
  10070. @@ -1365,7 +1368,8 @@
  10071. raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
  10072. - deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q);
  10073. + deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q,
  10074. + &wake_sleeper_q);
  10075. /*
  10076. * First unlock HB so the waiter does not spin on it once he got woken
  10077. @@ -1373,8 +1377,9 @@
  10078. * deboost first (and lose our higher priority), then the task might get
  10079. * scheduled away before the wake up can take place.
  10080. */
  10081. - spin_unlock(&hb->lock);
  10082. + deboost |= spin_unlock_no_deboost(&hb->lock);
  10083. wake_up_q(&wake_q);
  10084. + wake_up_q_sleeper(&wake_sleeper_q);
  10085. if (deboost)
  10086. rt_mutex_adjust_prio(current);
  10087. @@ -1924,6 +1929,16 @@
  10088. requeue_pi_wake_futex(this, &key2, hb2);
  10089. drop_count++;
  10090. continue;
  10091. + } else if (ret == -EAGAIN) {
  10092. + /*
  10093. + * Waiter was woken by timeout or
  10094. + * signal and has set pi_blocked_on to
  10095. + * PI_WAKEUP_INPROGRESS before we
  10096. + * tried to enqueue it on the rtmutex.
  10097. + */
  10098. + this->pi_state = NULL;
  10099. + put_pi_state(pi_state);
  10100. + continue;
  10101. } else if (ret) {
  10102. /*
  10103. * rt_mutex_start_proxy_lock() detected a
  10104. @@ -2814,7 +2829,7 @@
  10105. struct hrtimer_sleeper timeout, *to = NULL;
  10106. struct rt_mutex_waiter rt_waiter;
  10107. struct rt_mutex *pi_mutex = NULL;
  10108. - struct futex_hash_bucket *hb;
  10109. + struct futex_hash_bucket *hb, *hb2;
  10110. union futex_key key2 = FUTEX_KEY_INIT;
  10111. struct futex_q q = futex_q_init;
  10112. int res, ret;
  10113. @@ -2839,10 +2854,7 @@
  10114. * The waiter is allocated on our stack, manipulated by the requeue
  10115. * code while we sleep on uaddr.
  10116. */
  10117. - debug_rt_mutex_init_waiter(&rt_waiter);
  10118. - RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
  10119. - RB_CLEAR_NODE(&rt_waiter.tree_entry);
  10120. - rt_waiter.task = NULL;
  10121. + rt_mutex_init_waiter(&rt_waiter, false);
  10122. ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
  10123. if (unlikely(ret != 0))
  10124. @@ -2873,20 +2885,55 @@
  10125. /* Queue the futex_q, drop the hb lock, wait for wakeup. */
  10126. futex_wait_queue_me(hb, &q, to);
  10127. - spin_lock(&hb->lock);
  10128. - ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  10129. - spin_unlock(&hb->lock);
  10130. - if (ret)
  10131. - goto out_put_keys;
  10132. + /*
  10133. + * On RT we must avoid races with requeue and trying to block
  10134. + * on two mutexes (hb->lock and uaddr2's rtmutex) by
  10135. + * serializing access to pi_blocked_on with pi_lock.
  10136. + */
  10137. + raw_spin_lock_irq(&current->pi_lock);
  10138. + if (current->pi_blocked_on) {
  10139. + /*
  10140. + * We have been requeued or are in the process of
  10141. + * being requeued.
  10142. + */
  10143. + raw_spin_unlock_irq(&current->pi_lock);
  10144. + } else {
  10145. + /*
  10146. + * Setting pi_blocked_on to PI_WAKEUP_INPROGRESS
  10147. + * prevents a concurrent requeue from moving us to the
  10148. + * uaddr2 rtmutex. After that we can safely acquire
  10149. + * (and possibly block on) hb->lock.
  10150. + */
  10151. + current->pi_blocked_on = PI_WAKEUP_INPROGRESS;
  10152. + raw_spin_unlock_irq(&current->pi_lock);
  10153. +
  10154. + spin_lock(&hb->lock);
  10155. +
  10156. + /*
  10157. + * Clean up pi_blocked_on. We might leak it otherwise
  10158. + * when we succeeded with the hb->lock in the fast
  10159. + * path.
  10160. + */
  10161. + raw_spin_lock_irq(&current->pi_lock);
  10162. + current->pi_blocked_on = NULL;
  10163. + raw_spin_unlock_irq(&current->pi_lock);
  10164. +
  10165. + ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  10166. + spin_unlock(&hb->lock);
  10167. + if (ret)
  10168. + goto out_put_keys;
  10169. + }
  10170. /*
  10171. - * In order for us to be here, we know our q.key == key2, and since
  10172. - * we took the hb->lock above, we also know that futex_requeue() has
  10173. - * completed and we no longer have to concern ourselves with a wakeup
  10174. - * race with the atomic proxy lock acquisition by the requeue code. The
  10175. - * futex_requeue dropped our key1 reference and incremented our key2
  10176. - * reference count.
  10177. + * In order to be here, we have either been requeued, are in
  10178. + * the process of being requeued, or requeue successfully
  10179. + * acquired uaddr2 on our behalf. If pi_blocked_on was
  10180. + * non-null above, we may be racing with a requeue. Do not
  10181. + * rely on q->lock_ptr to be hb2->lock until after blocking on
  10182. + * hb->lock or hb2->lock. The futex_requeue dropped our key1
  10183. + * reference and incremented our key2 reference count.
  10184. */
  10185. + hb2 = hash_futex(&key2);
  10186. /* Check if the requeue code acquired the second futex for us. */
  10187. if (!q.rt_waiter) {
  10188. @@ -2895,14 +2942,15 @@
  10189. * did a lock-steal - fix up the PI-state in that case.
  10190. */
  10191. if (q.pi_state && (q.pi_state->owner != current)) {
  10192. - spin_lock(q.lock_ptr);
  10193. + spin_lock(&hb2->lock);
  10194. + BUG_ON(&hb2->lock != q.lock_ptr);
  10195. ret = fixup_pi_state_owner(uaddr2, &q, current);
  10196. /*
  10197. * Drop the reference to the pi state which
  10198. * the requeue_pi() code acquired for us.
  10199. */
  10200. put_pi_state(q.pi_state);
  10201. - spin_unlock(q.lock_ptr);
  10202. + spin_unlock(&hb2->lock);
  10203. }
  10204. } else {
  10205. /*
  10206. @@ -2915,7 +2963,8 @@
  10207. ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
  10208. debug_rt_mutex_free_waiter(&rt_waiter);
  10209. - spin_lock(q.lock_ptr);
  10210. + spin_lock(&hb2->lock);
  10211. + BUG_ON(&hb2->lock != q.lock_ptr);
  10212. /*
  10213. * Fixup the pi_state owner and possibly acquire the lock if we
  10214. * haven't already.
  10215. diff -Nur linux-4.9.6.orig/kernel/irq/handle.c linux-4.9.6/kernel/irq/handle.c
  10216. --- linux-4.9.6.orig/kernel/irq/handle.c 2017-01-26 08:25:24.000000000 +0100
  10217. +++ linux-4.9.6/kernel/irq/handle.c 2017-01-28 13:59:09.955657109 +0100
  10218. @@ -181,10 +181,16 @@
  10219. {
  10220. irqreturn_t retval;
  10221. unsigned int flags = 0;
  10222. + struct pt_regs *regs = get_irq_regs();
  10223. + u64 ip = regs ? instruction_pointer(regs) : 0;
  10224. retval = __handle_irq_event_percpu(desc, &flags);
  10225. - add_interrupt_randomness(desc->irq_data.irq, flags);
  10226. +#ifdef CONFIG_PREEMPT_RT_FULL
  10227. + desc->random_ip = ip;
  10228. +#else
  10229. + add_interrupt_randomness(desc->irq_data.irq, flags, ip);
  10230. +#endif
  10231. if (!noirqdebug)
  10232. note_interrupt(desc, retval);
  10233. diff -Nur linux-4.9.6.orig/kernel/irq/manage.c linux-4.9.6/kernel/irq/manage.c
  10234. --- linux-4.9.6.orig/kernel/irq/manage.c 2017-01-26 08:25:24.000000000 +0100
  10235. +++ linux-4.9.6/kernel/irq/manage.c 2017-01-28 13:59:09.955657109 +0100
  10236. @@ -22,6 +22,7 @@
  10237. #include "internals.h"
  10238. #ifdef CONFIG_IRQ_FORCED_THREADING
  10239. +# ifndef CONFIG_PREEMPT_RT_BASE
  10240. __read_mostly bool force_irqthreads;
  10241. static int __init setup_forced_irqthreads(char *arg)
  10242. @@ -30,6 +31,7 @@
  10243. return 0;
  10244. }
  10245. early_param("threadirqs", setup_forced_irqthreads);
  10246. +# endif
  10247. #endif
  10248. static void __synchronize_hardirq(struct irq_desc *desc)
  10249. @@ -233,7 +235,12 @@
  10250. if (desc->affinity_notify) {
  10251. kref_get(&desc->affinity_notify->kref);
  10252. +
  10253. +#ifdef CONFIG_PREEMPT_RT_BASE
  10254. + swork_queue(&desc->affinity_notify->swork);
  10255. +#else
  10256. schedule_work(&desc->affinity_notify->work);
  10257. +#endif
  10258. }
  10259. irqd_set(data, IRQD_AFFINITY_SET);
  10260. @@ -271,10 +278,8 @@
  10261. }
  10262. EXPORT_SYMBOL_GPL(irq_set_affinity_hint);
  10263. -static void irq_affinity_notify(struct work_struct *work)
  10264. +static void _irq_affinity_notify(struct irq_affinity_notify *notify)
  10265. {
  10266. - struct irq_affinity_notify *notify =
  10267. - container_of(work, struct irq_affinity_notify, work);
  10268. struct irq_desc *desc = irq_to_desc(notify->irq);
  10269. cpumask_var_t cpumask;
  10270. unsigned long flags;
  10271. @@ -296,6 +301,35 @@
  10272. kref_put(&notify->kref, notify->release);
  10273. }
  10274. +#ifdef CONFIG_PREEMPT_RT_BASE
  10275. +static void init_helper_thread(void)
  10276. +{
  10277. + static int init_sworker_once;
  10278. +
  10279. + if (init_sworker_once)
  10280. + return;
  10281. + if (WARN_ON(swork_get()))
  10282. + return;
  10283. + init_sworker_once = 1;
  10284. +}
  10285. +
  10286. +static void irq_affinity_notify(struct swork_event *swork)
  10287. +{
  10288. + struct irq_affinity_notify *notify =
  10289. + container_of(swork, struct irq_affinity_notify, swork);
  10290. + _irq_affinity_notify(notify);
  10291. +}
  10292. +
  10293. +#else
  10294. +
  10295. +static void irq_affinity_notify(struct work_struct *work)
  10296. +{
  10297. + struct irq_affinity_notify *notify =
  10298. + container_of(work, struct irq_affinity_notify, work);
  10299. + _irq_affinity_notify(notify);
  10300. +}
  10301. +#endif
  10302. +
  10303. /**
  10304. * irq_set_affinity_notifier - control notification of IRQ affinity changes
  10305. * @irq: Interrupt for which to enable/disable notification
  10306. @@ -324,7 +358,12 @@
  10307. if (notify) {
  10308. notify->irq = irq;
  10309. kref_init(&notify->kref);
  10310. +#ifdef CONFIG_PREEMPT_RT_BASE
  10311. + INIT_SWORK(&notify->swork, irq_affinity_notify);
  10312. + init_helper_thread();
  10313. +#else
  10314. INIT_WORK(&notify->work, irq_affinity_notify);
  10315. +#endif
  10316. }
  10317. raw_spin_lock_irqsave(&desc->lock, flags);
  10318. @@ -879,7 +918,15 @@
  10319. local_bh_disable();
  10320. ret = action->thread_fn(action->irq, action->dev_id);
  10321. irq_finalize_oneshot(desc, action);
  10322. - local_bh_enable();
  10323. + /*
  10324. + * Interrupts which have real time requirements can be set up
  10325. + * to avoid softirq processing in the thread handler. This is
  10326. + * safe as these interrupts do not raise soft interrupts.
  10327. + */
  10328. + if (irq_settings_no_softirq_call(desc))
  10329. + _local_bh_enable();
  10330. + else
  10331. + local_bh_enable();
  10332. return ret;
  10333. }
  10334. @@ -976,6 +1023,12 @@
  10335. if (action_ret == IRQ_WAKE_THREAD)
  10336. irq_wake_secondary(desc, action);
  10337. +#ifdef CONFIG_PREEMPT_RT_FULL
  10338. + migrate_disable();
  10339. + add_interrupt_randomness(action->irq, 0,
  10340. + desc->random_ip ^ (unsigned long) action);
  10341. + migrate_enable();
  10342. +#endif
  10343. wake_threads_waitq(desc);
  10344. }
  10345. @@ -1336,6 +1389,9 @@
  10346. irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
  10347. }
  10348. + if (new->flags & IRQF_NO_SOFTIRQ_CALL)
  10349. + irq_settings_set_no_softirq_call(desc);
  10350. +
  10351. /* Set default affinity mask once everything is setup */
  10352. setup_affinity(desc, mask);
  10353. @@ -2061,7 +2117,7 @@
  10354. * This call sets the internal irqchip state of an interrupt,
  10355. * depending on the value of @which.
  10356. *
  10357. - * This function should be called with preemption disabled if the
  10358. + * This function should be called with migration disabled if the
  10359. * interrupt controller has per-cpu registers.
  10360. */
  10361. int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  10362. diff -Nur linux-4.9.6.orig/kernel/irq/settings.h linux-4.9.6/kernel/irq/settings.h
  10363. --- linux-4.9.6.orig/kernel/irq/settings.h 2017-01-26 08:25:24.000000000 +0100
  10364. +++ linux-4.9.6/kernel/irq/settings.h 2017-01-28 13:59:09.955657109 +0100
  10365. @@ -16,6 +16,7 @@
  10366. _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID,
  10367. _IRQ_IS_POLLED = IRQ_IS_POLLED,
  10368. _IRQ_DISABLE_UNLAZY = IRQ_DISABLE_UNLAZY,
  10369. + _IRQ_NO_SOFTIRQ_CALL = IRQ_NO_SOFTIRQ_CALL,
  10370. _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
  10371. };
  10372. @@ -30,6 +31,7 @@
  10373. #define IRQ_PER_CPU_DEVID GOT_YOU_MORON
  10374. #define IRQ_IS_POLLED GOT_YOU_MORON
  10375. #define IRQ_DISABLE_UNLAZY GOT_YOU_MORON
  10376. +#define IRQ_NO_SOFTIRQ_CALL GOT_YOU_MORON
  10377. #undef IRQF_MODIFY_MASK
  10378. #define IRQF_MODIFY_MASK GOT_YOU_MORON
  10379. @@ -40,6 +42,16 @@
  10380. desc->status_use_accessors |= (set & _IRQF_MODIFY_MASK);
  10381. }
  10382. +static inline bool irq_settings_no_softirq_call(struct irq_desc *desc)
  10383. +{
  10384. + return desc->status_use_accessors & _IRQ_NO_SOFTIRQ_CALL;
  10385. +}
  10386. +
  10387. +static inline void irq_settings_set_no_softirq_call(struct irq_desc *desc)
  10388. +{
  10389. + desc->status_use_accessors |= _IRQ_NO_SOFTIRQ_CALL;
  10390. +}
  10391. +
  10392. static inline bool irq_settings_is_per_cpu(struct irq_desc *desc)
  10393. {
  10394. return desc->status_use_accessors & _IRQ_PER_CPU;
  10395. diff -Nur linux-4.9.6.orig/kernel/irq/spurious.c linux-4.9.6/kernel/irq/spurious.c
  10396. --- linux-4.9.6.orig/kernel/irq/spurious.c 2017-01-26 08:25:24.000000000 +0100
  10397. +++ linux-4.9.6/kernel/irq/spurious.c 2017-01-28 13:59:09.955657109 +0100
  10398. @@ -442,6 +442,10 @@
  10399. static int __init irqfixup_setup(char *str)
  10400. {
  10401. +#ifdef CONFIG_PREEMPT_RT_BASE
  10402. + pr_warn("irqfixup boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  10403. + return 1;
  10404. +#endif
  10405. irqfixup = 1;
  10406. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  10407. printk(KERN_WARNING "This may impact system performance.\n");
  10408. @@ -454,6 +458,10 @@
  10409. static int __init irqpoll_setup(char *str)
  10410. {
  10411. +#ifdef CONFIG_PREEMPT_RT_BASE
  10412. + pr_warn("irqpoll boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  10413. + return 1;
  10414. +#endif
  10415. irqfixup = 2;
  10416. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  10417. "enabled\n");
  10418. diff -Nur linux-4.9.6.orig/kernel/irq_work.c linux-4.9.6/kernel/irq_work.c
  10419. --- linux-4.9.6.orig/kernel/irq_work.c 2017-01-26 08:25:24.000000000 +0100
  10420. +++ linux-4.9.6/kernel/irq_work.c 2017-01-28 13:59:09.955657109 +0100
  10421. @@ -17,6 +17,7 @@
  10422. #include <linux/cpu.h>
  10423. #include <linux/notifier.h>
  10424. #include <linux/smp.h>
  10425. +#include <linux/interrupt.h>
  10426. #include <asm/processor.h>
  10427. @@ -65,6 +66,8 @@
  10428. */
  10429. bool irq_work_queue_on(struct irq_work *work, int cpu)
  10430. {
  10431. + struct llist_head *list;
  10432. +
  10433. /* All work should have been flushed before going offline */
  10434. WARN_ON_ONCE(cpu_is_offline(cpu));
  10435. @@ -75,7 +78,12 @@
  10436. if (!irq_work_claim(work))
  10437. return false;
  10438. - if (llist_add(&work->llnode, &per_cpu(raised_list, cpu)))
  10439. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL) && !(work->flags & IRQ_WORK_HARD_IRQ))
  10440. + list = &per_cpu(lazy_list, cpu);
  10441. + else
  10442. + list = &per_cpu(raised_list, cpu);
  10443. +
  10444. + if (llist_add(&work->llnode, list))
  10445. arch_send_call_function_single_ipi(cpu);
  10446. return true;
  10447. @@ -86,6 +94,9 @@
  10448. /* Enqueue the irq work @work on the current CPU */
  10449. bool irq_work_queue(struct irq_work *work)
  10450. {
  10451. + struct llist_head *list;
  10452. + bool lazy_work, realtime = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
  10453. +
  10454. /* Only queue if not already pending */
  10455. if (!irq_work_claim(work))
  10456. return false;
  10457. @@ -93,13 +104,15 @@
  10458. /* Queue the entry and raise the IPI if needed. */
  10459. preempt_disable();
  10460. - /* If the work is "lazy", handle it from next tick if any */
  10461. - if (work->flags & IRQ_WORK_LAZY) {
  10462. - if (llist_add(&work->llnode, this_cpu_ptr(&lazy_list)) &&
  10463. - tick_nohz_tick_stopped())
  10464. - arch_irq_work_raise();
  10465. - } else {
  10466. - if (llist_add(&work->llnode, this_cpu_ptr(&raised_list)))
  10467. + lazy_work = work->flags & IRQ_WORK_LAZY;
  10468. +
  10469. + if (lazy_work || (realtime && !(work->flags & IRQ_WORK_HARD_IRQ)))
  10470. + list = this_cpu_ptr(&lazy_list);
  10471. + else
  10472. + list = this_cpu_ptr(&raised_list);
  10473. +
  10474. + if (llist_add(&work->llnode, list)) {
  10475. + if (!lazy_work || tick_nohz_tick_stopped())
  10476. arch_irq_work_raise();
  10477. }
  10478. @@ -116,9 +129,8 @@
  10479. raised = this_cpu_ptr(&raised_list);
  10480. lazy = this_cpu_ptr(&lazy_list);
  10481. - if (llist_empty(raised) || arch_irq_work_has_interrupt())
  10482. - if (llist_empty(lazy))
  10483. - return false;
  10484. + if (llist_empty(raised) && llist_empty(lazy))
  10485. + return false;
  10486. /* All work should have been flushed before going offline */
  10487. WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
  10488. @@ -132,7 +144,7 @@
  10489. struct irq_work *work;
  10490. struct llist_node *llnode;
  10491. - BUG_ON(!irqs_disabled());
  10492. + BUG_ON_NONRT(!irqs_disabled());
  10493. if (llist_empty(list))
  10494. return;
  10495. @@ -169,7 +181,16 @@
  10496. void irq_work_run(void)
  10497. {
  10498. irq_work_run_list(this_cpu_ptr(&raised_list));
  10499. - irq_work_run_list(this_cpu_ptr(&lazy_list));
  10500. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) {
  10501. + /*
  10502. + * NOTE: we raise softirq via IPI for safety,
  10503. + * and execute in irq_work_tick() to move the
  10504. + * overhead from hard to soft irq context.
  10505. + */
  10506. + if (!llist_empty(this_cpu_ptr(&lazy_list)))
  10507. + raise_softirq(TIMER_SOFTIRQ);
  10508. + } else
  10509. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  10510. }
  10511. EXPORT_SYMBOL_GPL(irq_work_run);
  10512. @@ -179,8 +200,17 @@
  10513. if (!llist_empty(raised) && !arch_irq_work_has_interrupt())
  10514. irq_work_run_list(raised);
  10515. +
  10516. + if (!IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
  10517. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  10518. +}
  10519. +
  10520. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  10521. +void irq_work_tick_soft(void)
  10522. +{
  10523. irq_work_run_list(this_cpu_ptr(&lazy_list));
  10524. }
  10525. +#endif
  10526. /*
  10527. * Synchronize against the irq_work @entry, ensures the entry is not
  10528. diff -Nur linux-4.9.6.orig/kernel/Kconfig.locks linux-4.9.6/kernel/Kconfig.locks
  10529. --- linux-4.9.6.orig/kernel/Kconfig.locks 2017-01-26 08:25:24.000000000 +0100
  10530. +++ linux-4.9.6/kernel/Kconfig.locks 2017-01-28 13:59:09.951656955 +0100
  10531. @@ -225,11 +225,11 @@
  10532. config MUTEX_SPIN_ON_OWNER
  10533. def_bool y
  10534. - depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW
  10535. + depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  10536. config RWSEM_SPIN_ON_OWNER
  10537. def_bool y
  10538. - depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW
  10539. + depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  10540. config LOCK_SPIN_ON_OWNER
  10541. def_bool y
  10542. diff -Nur linux-4.9.6.orig/kernel/Kconfig.preempt linux-4.9.6/kernel/Kconfig.preempt
  10543. --- linux-4.9.6.orig/kernel/Kconfig.preempt 2017-01-26 08:25:24.000000000 +0100
  10544. +++ linux-4.9.6/kernel/Kconfig.preempt 2017-01-28 13:59:09.951656955 +0100
  10545. @@ -1,3 +1,16 @@
  10546. +config PREEMPT
  10547. + bool
  10548. + select PREEMPT_COUNT
  10549. +
  10550. +config PREEMPT_RT_BASE
  10551. + bool
  10552. + select PREEMPT
  10553. +
  10554. +config HAVE_PREEMPT_LAZY
  10555. + bool
  10556. +
  10557. +config PREEMPT_LAZY
  10558. + def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT_FULL
  10559. choice
  10560. prompt "Preemption Model"
  10561. @@ -33,9 +46,9 @@
  10562. Select this if you are building a kernel for a desktop system.
  10563. -config PREEMPT
  10564. +config PREEMPT__LL
  10565. bool "Preemptible Kernel (Low-Latency Desktop)"
  10566. - select PREEMPT_COUNT
  10567. + select PREEMPT
  10568. select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
  10569. help
  10570. This option reduces the latency of the kernel by making
  10571. @@ -52,6 +65,22 @@
  10572. embedded system with latency requirements in the milliseconds
  10573. range.
  10574. +config PREEMPT_RTB
  10575. + bool "Preemptible Kernel (Basic RT)"
  10576. + select PREEMPT_RT_BASE
  10577. + help
  10578. + This option is basically the same as (Low-Latency Desktop) but
  10579. + enables changes which are preliminary for the full preemptible
  10580. + RT kernel.
  10581. +
  10582. +config PREEMPT_RT_FULL
  10583. + bool "Fully Preemptible Kernel (RT)"
  10584. + depends on IRQ_FORCED_THREADING
  10585. + select PREEMPT_RT_BASE
  10586. + select PREEMPT_RCU
  10587. + help
  10588. + All and everything
  10589. +
  10590. endchoice
  10591. config PREEMPT_COUNT
  10592. diff -Nur linux-4.9.6.orig/kernel/ksysfs.c linux-4.9.6/kernel/ksysfs.c
  10593. --- linux-4.9.6.orig/kernel/ksysfs.c 2017-01-26 08:25:24.000000000 +0100
  10594. +++ linux-4.9.6/kernel/ksysfs.c 2017-01-28 13:59:09.955657109 +0100
  10595. @@ -136,6 +136,15 @@
  10596. #endif /* CONFIG_KEXEC_CORE */
  10597. +#if defined(CONFIG_PREEMPT_RT_FULL)
  10598. +static ssize_t realtime_show(struct kobject *kobj,
  10599. + struct kobj_attribute *attr, char *buf)
  10600. +{
  10601. + return sprintf(buf, "%d\n", 1);
  10602. +}
  10603. +KERNEL_ATTR_RO(realtime);
  10604. +#endif
  10605. +
  10606. /* whether file capabilities are enabled */
  10607. static ssize_t fscaps_show(struct kobject *kobj,
  10608. struct kobj_attribute *attr, char *buf)
  10609. @@ -225,6 +234,9 @@
  10610. &rcu_expedited_attr.attr,
  10611. &rcu_normal_attr.attr,
  10612. #endif
  10613. +#ifdef CONFIG_PREEMPT_RT_FULL
  10614. + &realtime_attr.attr,
  10615. +#endif
  10616. NULL
  10617. };
  10618. diff -Nur linux-4.9.6.orig/kernel/locking/lockdep.c linux-4.9.6/kernel/locking/lockdep.c
  10619. --- linux-4.9.6.orig/kernel/locking/lockdep.c 2017-01-26 08:25:24.000000000 +0100
  10620. +++ linux-4.9.6/kernel/locking/lockdep.c 2017-01-28 13:59:09.955657109 +0100
  10621. @@ -3689,6 +3689,7 @@
  10622. }
  10623. }
  10624. +#ifndef CONFIG_PREEMPT_RT_FULL
  10625. /*
  10626. * We dont accurately track softirq state in e.g.
  10627. * hardirq contexts (such as on 4KSTACKS), so only
  10628. @@ -3703,6 +3704,7 @@
  10629. DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
  10630. }
  10631. }
  10632. +#endif
  10633. if (!debug_locks)
  10634. print_irqtrace_events(current);
  10635. diff -Nur linux-4.9.6.orig/kernel/locking/locktorture.c linux-4.9.6/kernel/locking/locktorture.c
  10636. --- linux-4.9.6.orig/kernel/locking/locktorture.c 2017-01-26 08:25:24.000000000 +0100
  10637. +++ linux-4.9.6/kernel/locking/locktorture.c 2017-01-28 13:59:09.959657263 +0100
  10638. @@ -26,7 +26,6 @@
  10639. #include <linux/kthread.h>
  10640. #include <linux/sched/rt.h>
  10641. #include <linux/spinlock.h>
  10642. -#include <linux/rwlock.h>
  10643. #include <linux/mutex.h>
  10644. #include <linux/rwsem.h>
  10645. #include <linux/smp.h>
  10646. diff -Nur linux-4.9.6.orig/kernel/locking/Makefile linux-4.9.6/kernel/locking/Makefile
  10647. --- linux-4.9.6.orig/kernel/locking/Makefile 2017-01-26 08:25:24.000000000 +0100
  10648. +++ linux-4.9.6/kernel/locking/Makefile 2017-01-28 13:59:09.955657109 +0100
  10649. @@ -2,7 +2,7 @@
  10650. # and is generally not a function of system call inputs.
  10651. KCOV_INSTRUMENT := n
  10652. -obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o
  10653. +obj-y += semaphore.o percpu-rwsem.o
  10654. ifdef CONFIG_FUNCTION_TRACER
  10655. CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE)
  10656. @@ -11,7 +11,11 @@
  10657. CFLAGS_REMOVE_rtmutex-debug.o = $(CC_FLAGS_FTRACE)
  10658. endif
  10659. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  10660. +obj-y += mutex.o
  10661. obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
  10662. +obj-y += rwsem.o
  10663. +endif
  10664. obj-$(CONFIG_LOCKDEP) += lockdep.o
  10665. ifeq ($(CONFIG_PROC_FS),y)
  10666. obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
  10667. @@ -24,7 +28,10 @@
  10668. obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
  10669. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
  10670. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
  10671. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  10672. obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
  10673. obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
  10674. +endif
  10675. +obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o
  10676. obj-$(CONFIG_QUEUED_RWLOCKS) += qrwlock.o
  10677. obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
  10678. diff -Nur linux-4.9.6.orig/kernel/locking/percpu-rwsem.c linux-4.9.6/kernel/locking/percpu-rwsem.c
  10679. --- linux-4.9.6.orig/kernel/locking/percpu-rwsem.c 2017-01-26 08:25:24.000000000 +0100
  10680. +++ linux-4.9.6/kernel/locking/percpu-rwsem.c 2017-01-28 13:59:09.959657263 +0100
  10681. @@ -18,7 +18,7 @@
  10682. /* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */
  10683. rcu_sync_init(&sem->rss, RCU_SCHED_SYNC);
  10684. __init_rwsem(&sem->rw_sem, name, rwsem_key);
  10685. - init_waitqueue_head(&sem->writer);
  10686. + init_swait_queue_head(&sem->writer);
  10687. sem->readers_block = 0;
  10688. return 0;
  10689. }
  10690. @@ -103,7 +103,7 @@
  10691. __this_cpu_dec(*sem->read_count);
  10692. /* Prod writer to recheck readers_active */
  10693. - wake_up(&sem->writer);
  10694. + swake_up(&sem->writer);
  10695. }
  10696. EXPORT_SYMBOL_GPL(__percpu_up_read);
  10697. @@ -160,7 +160,7 @@
  10698. */
  10699. /* Wait for all now active readers to complete. */
  10700. - wait_event(sem->writer, readers_active_check(sem));
  10701. + swait_event(sem->writer, readers_active_check(sem));
  10702. }
  10703. EXPORT_SYMBOL_GPL(percpu_down_write);
  10704. diff -Nur linux-4.9.6.orig/kernel/locking/rt.c linux-4.9.6/kernel/locking/rt.c
  10705. --- linux-4.9.6.orig/kernel/locking/rt.c 1970-01-01 01:00:00.000000000 +0100
  10706. +++ linux-4.9.6/kernel/locking/rt.c 2017-01-28 13:59:10.035660185 +0100
  10707. @@ -0,0 +1,498 @@
  10708. +/*
  10709. + * kernel/rt.c
  10710. + *
  10711. + * Real-Time Preemption Support
  10712. + *
  10713. + * started by Ingo Molnar:
  10714. + *
  10715. + * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  10716. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  10717. + *
  10718. + * historic credit for proving that Linux spinlocks can be implemented via
  10719. + * RT-aware mutexes goes to many people: The Pmutex project (Dirk Grambow
  10720. + * and others) who prototyped it on 2.4 and did lots of comparative
  10721. + * research and analysis; TimeSys, for proving that you can implement a
  10722. + * fully preemptible kernel via the use of IRQ threading and mutexes;
  10723. + * Bill Huey for persuasively arguing on lkml that the mutex model is the
  10724. + * right one; and to MontaVista, who ported pmutexes to 2.6.
  10725. + *
  10726. + * This code is a from-scratch implementation and is not based on pmutexes,
  10727. + * but the idea of converting spinlocks to mutexes is used here too.
  10728. + *
  10729. + * lock debugging, locking tree, deadlock detection:
  10730. + *
  10731. + * Copyright (C) 2004, LynuxWorks, Inc., Igor Manyilov, Bill Huey
  10732. + * Released under the General Public License (GPL).
  10733. + *
  10734. + * Includes portions of the generic R/W semaphore implementation from:
  10735. + *
  10736. + * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  10737. + * - Derived partially from idea by Andrea Arcangeli <andrea@suse.de>
  10738. + * - Derived also from comments by Linus
  10739. + *
  10740. + * Pending ownership of locks and ownership stealing:
  10741. + *
  10742. + * Copyright (C) 2005, Kihon Technologies Inc., Steven Rostedt
  10743. + *
  10744. + * (also by Steven Rostedt)
  10745. + * - Converted single pi_lock to individual task locks.
  10746. + *
  10747. + * By Esben Nielsen:
  10748. + * Doing priority inheritance with help of the scheduler.
  10749. + *
  10750. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  10751. + * - major rework based on Esben Nielsens initial patch
  10752. + * - replaced thread_info references by task_struct refs
  10753. + * - removed task->pending_owner dependency
  10754. + * - BKL drop/reacquire for semaphore style locks to avoid deadlocks
  10755. + * in the scheduler return path as discussed with Steven Rostedt
  10756. + *
  10757. + * Copyright (C) 2006, Kihon Technologies Inc.
  10758. + * Steven Rostedt <rostedt@goodmis.org>
  10759. + * - debugged and patched Thomas Gleixner's rework.
  10760. + * - added back the cmpxchg to the rework.
  10761. + * - turned atomic require back on for SMP.
  10762. + */
  10763. +
  10764. +#include <linux/spinlock.h>
  10765. +#include <linux/rtmutex.h>
  10766. +#include <linux/sched.h>
  10767. +#include <linux/delay.h>
  10768. +#include <linux/module.h>
  10769. +#include <linux/kallsyms.h>
  10770. +#include <linux/syscalls.h>
  10771. +#include <linux/interrupt.h>
  10772. +#include <linux/plist.h>
  10773. +#include <linux/fs.h>
  10774. +#include <linux/futex.h>
  10775. +#include <linux/hrtimer.h>
  10776. +
  10777. +#include "rtmutex_common.h"
  10778. +
  10779. +/*
  10780. + * struct mutex functions
  10781. + */
  10782. +void __mutex_do_init(struct mutex *mutex, const char *name,
  10783. + struct lock_class_key *key)
  10784. +{
  10785. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10786. + /*
  10787. + * Make sure we are not reinitializing a held lock:
  10788. + */
  10789. + debug_check_no_locks_freed((void *)mutex, sizeof(*mutex));
  10790. + lockdep_init_map(&mutex->dep_map, name, key, 0);
  10791. +#endif
  10792. + mutex->lock.save_state = 0;
  10793. +}
  10794. +EXPORT_SYMBOL(__mutex_do_init);
  10795. +
  10796. +void __lockfunc _mutex_lock(struct mutex *lock)
  10797. +{
  10798. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  10799. + rt_mutex_lock(&lock->lock);
  10800. +}
  10801. +EXPORT_SYMBOL(_mutex_lock);
  10802. +
  10803. +int __lockfunc _mutex_lock_interruptible(struct mutex *lock)
  10804. +{
  10805. + int ret;
  10806. +
  10807. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  10808. + ret = rt_mutex_lock_interruptible(&lock->lock);
  10809. + if (ret)
  10810. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  10811. + return ret;
  10812. +}
  10813. +EXPORT_SYMBOL(_mutex_lock_interruptible);
  10814. +
  10815. +int __lockfunc _mutex_lock_killable(struct mutex *lock)
  10816. +{
  10817. + int ret;
  10818. +
  10819. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  10820. + ret = rt_mutex_lock_killable(&lock->lock);
  10821. + if (ret)
  10822. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  10823. + return ret;
  10824. +}
  10825. +EXPORT_SYMBOL(_mutex_lock_killable);
  10826. +
  10827. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10828. +void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass)
  10829. +{
  10830. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  10831. + rt_mutex_lock(&lock->lock);
  10832. +}
  10833. +EXPORT_SYMBOL(_mutex_lock_nested);
  10834. +
  10835. +void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
  10836. +{
  10837. + mutex_acquire_nest(&lock->dep_map, 0, 0, nest, _RET_IP_);
  10838. + rt_mutex_lock(&lock->lock);
  10839. +}
  10840. +EXPORT_SYMBOL(_mutex_lock_nest_lock);
  10841. +
  10842. +int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass)
  10843. +{
  10844. + int ret;
  10845. +
  10846. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  10847. + ret = rt_mutex_lock_interruptible(&lock->lock);
  10848. + if (ret)
  10849. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  10850. + return ret;
  10851. +}
  10852. +EXPORT_SYMBOL(_mutex_lock_interruptible_nested);
  10853. +
  10854. +int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass)
  10855. +{
  10856. + int ret;
  10857. +
  10858. + mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  10859. + ret = rt_mutex_lock_killable(&lock->lock);
  10860. + if (ret)
  10861. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  10862. + return ret;
  10863. +}
  10864. +EXPORT_SYMBOL(_mutex_lock_killable_nested);
  10865. +#endif
  10866. +
  10867. +int __lockfunc _mutex_trylock(struct mutex *lock)
  10868. +{
  10869. + int ret = rt_mutex_trylock(&lock->lock);
  10870. +
  10871. + if (ret)
  10872. + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  10873. +
  10874. + return ret;
  10875. +}
  10876. +EXPORT_SYMBOL(_mutex_trylock);
  10877. +
  10878. +void __lockfunc _mutex_unlock(struct mutex *lock)
  10879. +{
  10880. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  10881. + rt_mutex_unlock(&lock->lock);
  10882. +}
  10883. +EXPORT_SYMBOL(_mutex_unlock);
  10884. +
  10885. +/*
  10886. + * rwlock_t functions
  10887. + */
  10888. +int __lockfunc rt_write_trylock(rwlock_t *rwlock)
  10889. +{
  10890. + int ret;
  10891. +
  10892. + migrate_disable();
  10893. + ret = rt_mutex_trylock(&rwlock->lock);
  10894. + if (ret)
  10895. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  10896. + else
  10897. + migrate_enable();
  10898. +
  10899. + return ret;
  10900. +}
  10901. +EXPORT_SYMBOL(rt_write_trylock);
  10902. +
  10903. +int __lockfunc rt_write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags)
  10904. +{
  10905. + int ret;
  10906. +
  10907. + *flags = 0;
  10908. + ret = rt_write_trylock(rwlock);
  10909. + return ret;
  10910. +}
  10911. +EXPORT_SYMBOL(rt_write_trylock_irqsave);
  10912. +
  10913. +int __lockfunc rt_read_trylock(rwlock_t *rwlock)
  10914. +{
  10915. + struct rt_mutex *lock = &rwlock->lock;
  10916. + int ret = 1;
  10917. +
  10918. + /*
  10919. + * recursive read locks succeed when current owns the lock,
  10920. + * but not when read_depth == 0 which means that the lock is
  10921. + * write locked.
  10922. + */
  10923. + if (rt_mutex_owner(lock) != current) {
  10924. + migrate_disable();
  10925. + ret = rt_mutex_trylock(lock);
  10926. + if (ret)
  10927. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  10928. + else
  10929. + migrate_enable();
  10930. +
  10931. + } else if (!rwlock->read_depth) {
  10932. + ret = 0;
  10933. + }
  10934. +
  10935. + if (ret)
  10936. + rwlock->read_depth++;
  10937. +
  10938. + return ret;
  10939. +}
  10940. +EXPORT_SYMBOL(rt_read_trylock);
  10941. +
  10942. +void __lockfunc rt_write_lock(rwlock_t *rwlock)
  10943. +{
  10944. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  10945. + __rt_spin_lock(&rwlock->lock);
  10946. +}
  10947. +EXPORT_SYMBOL(rt_write_lock);
  10948. +
  10949. +void __lockfunc rt_read_lock(rwlock_t *rwlock)
  10950. +{
  10951. + struct rt_mutex *lock = &rwlock->lock;
  10952. +
  10953. +
  10954. + /*
  10955. + * recursive read locks succeed when current owns the lock
  10956. + */
  10957. + if (rt_mutex_owner(lock) != current) {
  10958. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  10959. + __rt_spin_lock(lock);
  10960. + }
  10961. + rwlock->read_depth++;
  10962. +}
  10963. +
  10964. +EXPORT_SYMBOL(rt_read_lock);
  10965. +
  10966. +void __lockfunc rt_write_unlock(rwlock_t *rwlock)
  10967. +{
  10968. + /* NOTE: we always pass in '1' for nested, for simplicity */
  10969. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  10970. + __rt_spin_unlock(&rwlock->lock);
  10971. + migrate_enable();
  10972. +}
  10973. +EXPORT_SYMBOL(rt_write_unlock);
  10974. +
  10975. +void __lockfunc rt_read_unlock(rwlock_t *rwlock)
  10976. +{
  10977. + /* Release the lock only when read_depth is down to 0 */
  10978. + if (--rwlock->read_depth == 0) {
  10979. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  10980. + __rt_spin_unlock(&rwlock->lock);
  10981. + migrate_enable();
  10982. + }
  10983. +}
  10984. +EXPORT_SYMBOL(rt_read_unlock);
  10985. +
  10986. +unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock)
  10987. +{
  10988. + rt_write_lock(rwlock);
  10989. +
  10990. + return 0;
  10991. +}
  10992. +EXPORT_SYMBOL(rt_write_lock_irqsave);
  10993. +
  10994. +unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock)
  10995. +{
  10996. + rt_read_lock(rwlock);
  10997. +
  10998. + return 0;
  10999. +}
  11000. +EXPORT_SYMBOL(rt_read_lock_irqsave);
  11001. +
  11002. +void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key)
  11003. +{
  11004. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11005. + /*
  11006. + * Make sure we are not reinitializing a held lock:
  11007. + */
  11008. + debug_check_no_locks_freed((void *)rwlock, sizeof(*rwlock));
  11009. + lockdep_init_map(&rwlock->dep_map, name, key, 0);
  11010. +#endif
  11011. + rwlock->lock.save_state = 1;
  11012. + rwlock->read_depth = 0;
  11013. +}
  11014. +EXPORT_SYMBOL(__rt_rwlock_init);
  11015. +
  11016. +/*
  11017. + * rw_semaphores
  11018. + */
  11019. +
  11020. +void rt_up_write(struct rw_semaphore *rwsem)
  11021. +{
  11022. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  11023. + rt_mutex_unlock(&rwsem->lock);
  11024. +}
  11025. +EXPORT_SYMBOL(rt_up_write);
  11026. +
  11027. +void __rt_up_read(struct rw_semaphore *rwsem)
  11028. +{
  11029. + if (--rwsem->read_depth == 0)
  11030. + rt_mutex_unlock(&rwsem->lock);
  11031. +}
  11032. +
  11033. +void rt_up_read(struct rw_semaphore *rwsem)
  11034. +{
  11035. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  11036. + __rt_up_read(rwsem);
  11037. +}
  11038. +EXPORT_SYMBOL(rt_up_read);
  11039. +
  11040. +/*
  11041. + * downgrade a write lock into a read lock
  11042. + * - just wake up any readers at the front of the queue
  11043. + */
  11044. +void rt_downgrade_write(struct rw_semaphore *rwsem)
  11045. +{
  11046. + BUG_ON(rt_mutex_owner(&rwsem->lock) != current);
  11047. + rwsem->read_depth = 1;
  11048. +}
  11049. +EXPORT_SYMBOL(rt_downgrade_write);
  11050. +
  11051. +int rt_down_write_trylock(struct rw_semaphore *rwsem)
  11052. +{
  11053. + int ret = rt_mutex_trylock(&rwsem->lock);
  11054. +
  11055. + if (ret)
  11056. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  11057. + return ret;
  11058. +}
  11059. +EXPORT_SYMBOL(rt_down_write_trylock);
  11060. +
  11061. +void rt_down_write(struct rw_semaphore *rwsem)
  11062. +{
  11063. + rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
  11064. + rt_mutex_lock(&rwsem->lock);
  11065. +}
  11066. +EXPORT_SYMBOL(rt_down_write);
  11067. +
  11068. +int rt_down_write_killable(struct rw_semaphore *rwsem)
  11069. +{
  11070. + int ret;
  11071. +
  11072. + rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
  11073. + ret = rt_mutex_lock_killable(&rwsem->lock);
  11074. + if (ret)
  11075. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  11076. + return ret;
  11077. +}
  11078. +EXPORT_SYMBOL(rt_down_write_killable);
  11079. +
  11080. +int rt_down_write_killable_nested(struct rw_semaphore *rwsem, int subclass)
  11081. +{
  11082. + int ret;
  11083. +
  11084. + rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
  11085. + ret = rt_mutex_lock_killable(&rwsem->lock);
  11086. + if (ret)
  11087. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  11088. + return ret;
  11089. +}
  11090. +EXPORT_SYMBOL(rt_down_write_killable_nested);
  11091. +
  11092. +void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass)
  11093. +{
  11094. + rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
  11095. + rt_mutex_lock(&rwsem->lock);
  11096. +}
  11097. +EXPORT_SYMBOL(rt_down_write_nested);
  11098. +
  11099. +void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  11100. + struct lockdep_map *nest)
  11101. +{
  11102. + rwsem_acquire_nest(&rwsem->dep_map, 0, 0, nest, _RET_IP_);
  11103. + rt_mutex_lock(&rwsem->lock);
  11104. +}
  11105. +EXPORT_SYMBOL(rt_down_write_nested_lock);
  11106. +
  11107. +int rt__down_read_trylock(struct rw_semaphore *rwsem)
  11108. +{
  11109. + struct rt_mutex *lock = &rwsem->lock;
  11110. + int ret = 1;
  11111. +
  11112. + /*
  11113. + * recursive read locks succeed when current owns the rwsem,
  11114. + * but not when read_depth == 0 which means that the rwsem is
  11115. + * write locked.
  11116. + */
  11117. + if (rt_mutex_owner(lock) != current)
  11118. + ret = rt_mutex_trylock(&rwsem->lock);
  11119. + else if (!rwsem->read_depth)
  11120. + ret = 0;
  11121. +
  11122. + if (ret)
  11123. + rwsem->read_depth++;
  11124. + return ret;
  11125. +
  11126. +}
  11127. +
  11128. +int rt_down_read_trylock(struct rw_semaphore *rwsem)
  11129. +{
  11130. + int ret;
  11131. +
  11132. + ret = rt__down_read_trylock(rwsem);
  11133. + if (ret)
  11134. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  11135. +
  11136. + return ret;
  11137. +}
  11138. +EXPORT_SYMBOL(rt_down_read_trylock);
  11139. +
  11140. +void rt__down_read(struct rw_semaphore *rwsem)
  11141. +{
  11142. + struct rt_mutex *lock = &rwsem->lock;
  11143. +
  11144. + if (rt_mutex_owner(lock) != current)
  11145. + rt_mutex_lock(&rwsem->lock);
  11146. + rwsem->read_depth++;
  11147. +}
  11148. +EXPORT_SYMBOL(rt__down_read);
  11149. +
  11150. +static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
  11151. +{
  11152. + rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
  11153. + rt__down_read(rwsem);
  11154. +}
  11155. +
  11156. +void rt_down_read(struct rw_semaphore *rwsem)
  11157. +{
  11158. + __rt_down_read(rwsem, 0);
  11159. +}
  11160. +EXPORT_SYMBOL(rt_down_read);
  11161. +
  11162. +void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
  11163. +{
  11164. + __rt_down_read(rwsem, subclass);
  11165. +}
  11166. +EXPORT_SYMBOL(rt_down_read_nested);
  11167. +
  11168. +void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  11169. + struct lock_class_key *key)
  11170. +{
  11171. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11172. + /*
  11173. + * Make sure we are not reinitializing a held lock:
  11174. + */
  11175. + debug_check_no_locks_freed((void *)rwsem, sizeof(*rwsem));
  11176. + lockdep_init_map(&rwsem->dep_map, name, key, 0);
  11177. +#endif
  11178. + rwsem->read_depth = 0;
  11179. + rwsem->lock.save_state = 0;
  11180. +}
  11181. +EXPORT_SYMBOL(__rt_rwsem_init);
  11182. +
  11183. +/**
  11184. + * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
  11185. + * @cnt: the atomic which we are to dec
  11186. + * @lock: the mutex to return holding if we dec to 0
  11187. + *
  11188. + * return true and hold lock if we dec to 0, return false otherwise
  11189. + */
  11190. +int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
  11191. +{
  11192. + /* dec if we can't possibly hit 0 */
  11193. + if (atomic_add_unless(cnt, -1, 1))
  11194. + return 0;
  11195. + /* we might hit 0, so take the lock */
  11196. + mutex_lock(lock);
  11197. + if (!atomic_dec_and_test(cnt)) {
  11198. + /* when we actually did the dec, we didn't hit 0 */
  11199. + mutex_unlock(lock);
  11200. + return 0;
  11201. + }
  11202. + /* we hit 0, and we hold the lock */
  11203. + return 1;
  11204. +}
  11205. +EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
  11206. diff -Nur linux-4.9.6.orig/kernel/locking/rtmutex.c linux-4.9.6/kernel/locking/rtmutex.c
  11207. --- linux-4.9.6.orig/kernel/locking/rtmutex.c 2017-01-26 08:25:24.000000000 +0100
  11208. +++ linux-4.9.6/kernel/locking/rtmutex.c 2017-01-28 13:59:10.035660185 +0100
  11209. @@ -7,6 +7,11 @@
  11210. * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  11211. * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
  11212. * Copyright (C) 2006 Esben Nielsen
  11213. + * Adaptive Spinlocks:
  11214. + * Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
  11215. + * and Peter Morreale,
  11216. + * Adaptive Spinlocks simplification:
  11217. + * Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
  11218. *
  11219. * See Documentation/locking/rt-mutex-design.txt for details.
  11220. */
  11221. @@ -16,6 +21,7 @@
  11222. #include <linux/sched/rt.h>
  11223. #include <linux/sched/deadline.h>
  11224. #include <linux/timer.h>
  11225. +#include <linux/ww_mutex.h>
  11226. #include "rtmutex_common.h"
  11227. @@ -133,6 +139,12 @@
  11228. WRITE_ONCE(*p, owner & ~RT_MUTEX_HAS_WAITERS);
  11229. }
  11230. +static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
  11231. +{
  11232. + return waiter && waiter != PI_WAKEUP_INPROGRESS &&
  11233. + waiter != PI_REQUEUE_INPROGRESS;
  11234. +}
  11235. +
  11236. /*
  11237. * We can speed up the acquire/release, if there's no debugging state to be
  11238. * set up.
  11239. @@ -414,6 +426,14 @@
  11240. return debug_rt_mutex_detect_deadlock(waiter, chwalk);
  11241. }
  11242. +static void rt_mutex_wake_waiter(struct rt_mutex_waiter *waiter)
  11243. +{
  11244. + if (waiter->savestate)
  11245. + wake_up_lock_sleeper(waiter->task);
  11246. + else
  11247. + wake_up_process(waiter->task);
  11248. +}
  11249. +
  11250. /*
  11251. * Max number of times we'll walk the boosting chain:
  11252. */
  11253. @@ -421,7 +441,8 @@
  11254. static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
  11255. {
  11256. - return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
  11257. + return rt_mutex_real_waiter(p->pi_blocked_on) ?
  11258. + p->pi_blocked_on->lock : NULL;
  11259. }
  11260. /*
  11261. @@ -557,7 +578,7 @@
  11262. * reached or the state of the chain has changed while we
  11263. * dropped the locks.
  11264. */
  11265. - if (!waiter)
  11266. + if (!rt_mutex_real_waiter(waiter))
  11267. goto out_unlock_pi;
  11268. /*
  11269. @@ -719,13 +740,16 @@
  11270. * follow here. This is the end of the chain we are walking.
  11271. */
  11272. if (!rt_mutex_owner(lock)) {
  11273. + struct rt_mutex_waiter *lock_top_waiter;
  11274. +
  11275. /*
  11276. * If the requeue [7] above changed the top waiter,
  11277. * then we need to wake the new top waiter up to try
  11278. * to get the lock.
  11279. */
  11280. - if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
  11281. - wake_up_process(rt_mutex_top_waiter(lock)->task);
  11282. + lock_top_waiter = rt_mutex_top_waiter(lock);
  11283. + if (prerequeue_top_waiter != lock_top_waiter)
  11284. + rt_mutex_wake_waiter(lock_top_waiter);
  11285. raw_spin_unlock_irq(&lock->wait_lock);
  11286. return 0;
  11287. }
  11288. @@ -818,6 +842,25 @@
  11289. return ret;
  11290. }
  11291. +
  11292. +#define STEAL_NORMAL 0
  11293. +#define STEAL_LATERAL 1
  11294. +
  11295. +/*
  11296. + * Note that RT tasks are excluded from lateral-steals to prevent the
  11297. + * introduction of an unbounded latency
  11298. + */
  11299. +static inline int lock_is_stealable(struct task_struct *task,
  11300. + struct task_struct *pendowner, int mode)
  11301. +{
  11302. + if (mode == STEAL_NORMAL || rt_task(task)) {
  11303. + if (task->prio >= pendowner->prio)
  11304. + return 0;
  11305. + } else if (task->prio > pendowner->prio)
  11306. + return 0;
  11307. + return 1;
  11308. +}
  11309. +
  11310. /*
  11311. * Try to take an rt-mutex
  11312. *
  11313. @@ -828,8 +871,9 @@
  11314. * @waiter: The waiter that is queued to the lock's wait tree if the
  11315. * callsite called task_blocked_on_lock(), otherwise NULL
  11316. */
  11317. -static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  11318. - struct rt_mutex_waiter *waiter)
  11319. +static int __try_to_take_rt_mutex(struct rt_mutex *lock,
  11320. + struct task_struct *task,
  11321. + struct rt_mutex_waiter *waiter, int mode)
  11322. {
  11323. /*
  11324. * Before testing whether we can acquire @lock, we set the
  11325. @@ -866,8 +910,10 @@
  11326. * If waiter is not the highest priority waiter of
  11327. * @lock, give up.
  11328. */
  11329. - if (waiter != rt_mutex_top_waiter(lock))
  11330. + if (waiter != rt_mutex_top_waiter(lock)) {
  11331. + /* XXX lock_is_stealable() ? */
  11332. return 0;
  11333. + }
  11334. /*
  11335. * We can acquire the lock. Remove the waiter from the
  11336. @@ -885,14 +931,10 @@
  11337. * not need to be dequeued.
  11338. */
  11339. if (rt_mutex_has_waiters(lock)) {
  11340. - /*
  11341. - * If @task->prio is greater than or equal to
  11342. - * the top waiter priority (kernel view),
  11343. - * @task lost.
  11344. - */
  11345. - if (task->prio >= rt_mutex_top_waiter(lock)->prio)
  11346. - return 0;
  11347. + struct task_struct *pown = rt_mutex_top_waiter(lock)->task;
  11348. + if (task != pown && !lock_is_stealable(task, pown, mode))
  11349. + return 0;
  11350. /*
  11351. * The current top waiter stays enqueued. We
  11352. * don't have to change anything in the lock
  11353. @@ -941,6 +983,433 @@
  11354. return 1;
  11355. }
  11356. +#ifdef CONFIG_PREEMPT_RT_FULL
  11357. +/*
  11358. + * preemptible spin_lock functions:
  11359. + */
  11360. +static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
  11361. + void (*slowfn)(struct rt_mutex *lock,
  11362. + bool mg_off),
  11363. + bool do_mig_dis)
  11364. +{
  11365. + might_sleep_no_state_check();
  11366. +
  11367. + if (do_mig_dis)
  11368. + migrate_disable();
  11369. +
  11370. + if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
  11371. + rt_mutex_deadlock_account_lock(lock, current);
  11372. + else
  11373. + slowfn(lock, do_mig_dis);
  11374. +}
  11375. +
  11376. +static inline int rt_spin_lock_fastunlock(struct rt_mutex *lock,
  11377. + int (*slowfn)(struct rt_mutex *lock))
  11378. +{
  11379. + if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
  11380. + rt_mutex_deadlock_account_unlock(current);
  11381. + return 0;
  11382. + }
  11383. + return slowfn(lock);
  11384. +}
  11385. +#ifdef CONFIG_SMP
  11386. +/*
  11387. + * Note that owner is a speculative pointer and dereferencing relies
  11388. + * on rcu_read_lock() and the check against the lock owner.
  11389. + */
  11390. +static int adaptive_wait(struct rt_mutex *lock,
  11391. + struct task_struct *owner)
  11392. +{
  11393. + int res = 0;
  11394. +
  11395. + rcu_read_lock();
  11396. + for (;;) {
  11397. + if (owner != rt_mutex_owner(lock))
  11398. + break;
  11399. + /*
  11400. + * Ensure that owner->on_cpu is dereferenced _after_
  11401. + * checking the above to be valid.
  11402. + */
  11403. + barrier();
  11404. + if (!owner->on_cpu) {
  11405. + res = 1;
  11406. + break;
  11407. + }
  11408. + cpu_relax();
  11409. + }
  11410. + rcu_read_unlock();
  11411. + return res;
  11412. +}
  11413. +#else
  11414. +static int adaptive_wait(struct rt_mutex *lock,
  11415. + struct task_struct *orig_owner)
  11416. +{
  11417. + return 1;
  11418. +}
  11419. +#endif
  11420. +
  11421. +static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
  11422. + struct rt_mutex_waiter *waiter,
  11423. + struct task_struct *task,
  11424. + enum rtmutex_chainwalk chwalk);
  11425. +/*
  11426. + * Slow path lock function spin_lock style: this variant is very
  11427. + * careful not to miss any non-lock wakeups.
  11428. + *
  11429. + * We store the current state under p->pi_lock in p->saved_state and
  11430. + * the try_to_wake_up() code handles this accordingly.
  11431. + */
  11432. +static void noinline __sched rt_spin_lock_slowlock(struct rt_mutex *lock,
  11433. + bool mg_off)
  11434. +{
  11435. + struct task_struct *lock_owner, *self = current;
  11436. + struct rt_mutex_waiter waiter, *top_waiter;
  11437. + unsigned long flags;
  11438. + int ret;
  11439. +
  11440. + rt_mutex_init_waiter(&waiter, true);
  11441. +
  11442. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  11443. +
  11444. + if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL)) {
  11445. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11446. + return;
  11447. + }
  11448. +
  11449. + BUG_ON(rt_mutex_owner(lock) == self);
  11450. +
  11451. + /*
  11452. + * We save whatever state the task is in and we'll restore it
  11453. + * after acquiring the lock taking real wakeups into account
  11454. + * as well. We are serialized via pi_lock against wakeups. See
  11455. + * try_to_wake_up().
  11456. + */
  11457. + raw_spin_lock(&self->pi_lock);
  11458. + self->saved_state = self->state;
  11459. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  11460. + raw_spin_unlock(&self->pi_lock);
  11461. +
  11462. + ret = task_blocks_on_rt_mutex(lock, &waiter, self, RT_MUTEX_MIN_CHAINWALK);
  11463. + BUG_ON(ret);
  11464. +
  11465. + for (;;) {
  11466. + /* Try to acquire the lock again. */
  11467. + if (__try_to_take_rt_mutex(lock, self, &waiter, STEAL_LATERAL))
  11468. + break;
  11469. +
  11470. + top_waiter = rt_mutex_top_waiter(lock);
  11471. + lock_owner = rt_mutex_owner(lock);
  11472. +
  11473. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11474. +
  11475. + debug_rt_mutex_print_deadlock(&waiter);
  11476. +
  11477. + if (top_waiter != &waiter || adaptive_wait(lock, lock_owner)) {
  11478. + if (mg_off)
  11479. + migrate_enable();
  11480. + schedule();
  11481. + if (mg_off)
  11482. + migrate_disable();
  11483. + }
  11484. +
  11485. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  11486. +
  11487. + raw_spin_lock(&self->pi_lock);
  11488. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  11489. + raw_spin_unlock(&self->pi_lock);
  11490. + }
  11491. +
  11492. + /*
  11493. + * Restore the task state to current->saved_state. We set it
  11494. + * to the original state above and the try_to_wake_up() code
  11495. + * has possibly updated it when a real (non-rtmutex) wakeup
  11496. + * happened while we were blocked. Clear saved_state so
  11497. + * try_to_wakeup() does not get confused.
  11498. + */
  11499. + raw_spin_lock(&self->pi_lock);
  11500. + __set_current_state_no_track(self->saved_state);
  11501. + self->saved_state = TASK_RUNNING;
  11502. + raw_spin_unlock(&self->pi_lock);
  11503. +
  11504. + /*
  11505. + * try_to_take_rt_mutex() sets the waiter bit
  11506. + * unconditionally. We might have to fix that up:
  11507. + */
  11508. + fixup_rt_mutex_waiters(lock);
  11509. +
  11510. + BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
  11511. + BUG_ON(!RB_EMPTY_NODE(&waiter.tree_entry));
  11512. +
  11513. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11514. +
  11515. + debug_rt_mutex_free_waiter(&waiter);
  11516. +}
  11517. +
  11518. +static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
  11519. + struct wake_q_head *wake_sleeper_q,
  11520. + struct rt_mutex *lock);
  11521. +/*
  11522. + * Slow path to release a rt_mutex spin_lock style
  11523. + */
  11524. +static int noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
  11525. +{
  11526. + unsigned long flags;
  11527. + WAKE_Q(wake_q);
  11528. + WAKE_Q(wake_sleeper_q);
  11529. +
  11530. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  11531. +
  11532. + debug_rt_mutex_unlock(lock);
  11533. +
  11534. + rt_mutex_deadlock_account_unlock(current);
  11535. +
  11536. + if (!rt_mutex_has_waiters(lock)) {
  11537. + lock->owner = NULL;
  11538. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11539. + return 0;
  11540. + }
  11541. +
  11542. + mark_wakeup_next_waiter(&wake_q, &wake_sleeper_q, lock);
  11543. +
  11544. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11545. + wake_up_q(&wake_q);
  11546. + wake_up_q_sleeper(&wake_sleeper_q);
  11547. +
  11548. + /* Undo pi boosting.when necessary */
  11549. + rt_mutex_adjust_prio(current);
  11550. + return 0;
  11551. +}
  11552. +
  11553. +static int noinline __sched rt_spin_lock_slowunlock_no_deboost(struct rt_mutex *lock)
  11554. +{
  11555. + unsigned long flags;
  11556. + WAKE_Q(wake_q);
  11557. + WAKE_Q(wake_sleeper_q);
  11558. +
  11559. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  11560. +
  11561. + debug_rt_mutex_unlock(lock);
  11562. +
  11563. + rt_mutex_deadlock_account_unlock(current);
  11564. +
  11565. + if (!rt_mutex_has_waiters(lock)) {
  11566. + lock->owner = NULL;
  11567. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11568. + return 0;
  11569. + }
  11570. +
  11571. + mark_wakeup_next_waiter(&wake_q, &wake_sleeper_q, lock);
  11572. +
  11573. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11574. + wake_up_q(&wake_q);
  11575. + wake_up_q_sleeper(&wake_sleeper_q);
  11576. + return 1;
  11577. +}
  11578. +
  11579. +void __lockfunc rt_spin_lock__no_mg(spinlock_t *lock)
  11580. +{
  11581. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, false);
  11582. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  11583. +}
  11584. +EXPORT_SYMBOL(rt_spin_lock__no_mg);
  11585. +
  11586. +void __lockfunc rt_spin_lock(spinlock_t *lock)
  11587. +{
  11588. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, true);
  11589. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  11590. +}
  11591. +EXPORT_SYMBOL(rt_spin_lock);
  11592. +
  11593. +void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
  11594. +{
  11595. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, true);
  11596. +}
  11597. +EXPORT_SYMBOL(__rt_spin_lock);
  11598. +
  11599. +void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock)
  11600. +{
  11601. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, false);
  11602. +}
  11603. +EXPORT_SYMBOL(__rt_spin_lock__no_mg);
  11604. +
  11605. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11606. +void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
  11607. +{
  11608. + spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  11609. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, true);
  11610. +}
  11611. +EXPORT_SYMBOL(rt_spin_lock_nested);
  11612. +#endif
  11613. +
  11614. +void __lockfunc rt_spin_unlock__no_mg(spinlock_t *lock)
  11615. +{
  11616. + /* NOTE: we always pass in '1' for nested, for simplicity */
  11617. + spin_release(&lock->dep_map, 1, _RET_IP_);
  11618. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  11619. +}
  11620. +EXPORT_SYMBOL(rt_spin_unlock__no_mg);
  11621. +
  11622. +void __lockfunc rt_spin_unlock(spinlock_t *lock)
  11623. +{
  11624. + /* NOTE: we always pass in '1' for nested, for simplicity */
  11625. + spin_release(&lock->dep_map, 1, _RET_IP_);
  11626. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  11627. + migrate_enable();
  11628. +}
  11629. +EXPORT_SYMBOL(rt_spin_unlock);
  11630. +
  11631. +int __lockfunc rt_spin_unlock_no_deboost(spinlock_t *lock)
  11632. +{
  11633. + int ret;
  11634. +
  11635. + /* NOTE: we always pass in '1' for nested, for simplicity */
  11636. + spin_release(&lock->dep_map, 1, _RET_IP_);
  11637. + ret = rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock_no_deboost);
  11638. + migrate_enable();
  11639. + return ret;
  11640. +}
  11641. +
  11642. +void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
  11643. +{
  11644. + rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
  11645. +}
  11646. +EXPORT_SYMBOL(__rt_spin_unlock);
  11647. +
  11648. +/*
  11649. + * Wait for the lock to get unlocked: instead of polling for an unlock
  11650. + * (like raw spinlocks do), we lock and unlock, to force the kernel to
  11651. + * schedule if there's contention:
  11652. + */
  11653. +void __lockfunc rt_spin_unlock_wait(spinlock_t *lock)
  11654. +{
  11655. + spin_lock(lock);
  11656. + spin_unlock(lock);
  11657. +}
  11658. +EXPORT_SYMBOL(rt_spin_unlock_wait);
  11659. +
  11660. +int __lockfunc rt_spin_trylock__no_mg(spinlock_t *lock)
  11661. +{
  11662. + int ret;
  11663. +
  11664. + ret = rt_mutex_trylock(&lock->lock);
  11665. + if (ret)
  11666. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  11667. + return ret;
  11668. +}
  11669. +EXPORT_SYMBOL(rt_spin_trylock__no_mg);
  11670. +
  11671. +int __lockfunc rt_spin_trylock(spinlock_t *lock)
  11672. +{
  11673. + int ret;
  11674. +
  11675. + migrate_disable();
  11676. + ret = rt_mutex_trylock(&lock->lock);
  11677. + if (ret)
  11678. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  11679. + else
  11680. + migrate_enable();
  11681. + return ret;
  11682. +}
  11683. +EXPORT_SYMBOL(rt_spin_trylock);
  11684. +
  11685. +int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
  11686. +{
  11687. + int ret;
  11688. +
  11689. + local_bh_disable();
  11690. + ret = rt_mutex_trylock(&lock->lock);
  11691. + if (ret) {
  11692. + migrate_disable();
  11693. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  11694. + } else
  11695. + local_bh_enable();
  11696. + return ret;
  11697. +}
  11698. +EXPORT_SYMBOL(rt_spin_trylock_bh);
  11699. +
  11700. +int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags)
  11701. +{
  11702. + int ret;
  11703. +
  11704. + *flags = 0;
  11705. + ret = rt_mutex_trylock(&lock->lock);
  11706. + if (ret) {
  11707. + migrate_disable();
  11708. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  11709. + }
  11710. + return ret;
  11711. +}
  11712. +EXPORT_SYMBOL(rt_spin_trylock_irqsave);
  11713. +
  11714. +int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock)
  11715. +{
  11716. + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
  11717. + if (atomic_add_unless(atomic, -1, 1))
  11718. + return 0;
  11719. + rt_spin_lock(lock);
  11720. + if (atomic_dec_and_test(atomic))
  11721. + return 1;
  11722. + rt_spin_unlock(lock);
  11723. + return 0;
  11724. +}
  11725. +EXPORT_SYMBOL(atomic_dec_and_spin_lock);
  11726. +
  11727. + void
  11728. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key)
  11729. +{
  11730. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11731. + /*
  11732. + * Make sure we are not reinitializing a held lock:
  11733. + */
  11734. + debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  11735. + lockdep_init_map(&lock->dep_map, name, key, 0);
  11736. +#endif
  11737. +}
  11738. +EXPORT_SYMBOL(__rt_spin_lock_init);
  11739. +
  11740. +#endif /* PREEMPT_RT_FULL */
  11741. +
  11742. +#ifdef CONFIG_PREEMPT_RT_FULL
  11743. + static inline int __sched
  11744. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  11745. +{
  11746. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  11747. + struct ww_acquire_ctx *hold_ctx = ACCESS_ONCE(ww->ctx);
  11748. +
  11749. + if (!hold_ctx)
  11750. + return 0;
  11751. +
  11752. + if (unlikely(ctx == hold_ctx))
  11753. + return -EALREADY;
  11754. +
  11755. + if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
  11756. + (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
  11757. +#ifdef CONFIG_DEBUG_MUTEXES
  11758. + DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
  11759. + ctx->contending_lock = ww;
  11760. +#endif
  11761. + return -EDEADLK;
  11762. + }
  11763. +
  11764. + return 0;
  11765. +}
  11766. +#else
  11767. + static inline int __sched
  11768. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  11769. +{
  11770. + BUG();
  11771. + return 0;
  11772. +}
  11773. +
  11774. +#endif
  11775. +
  11776. +static inline int
  11777. +try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  11778. + struct rt_mutex_waiter *waiter)
  11779. +{
  11780. + return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
  11781. +}
  11782. +
  11783. /*
  11784. * Task blocks on lock.
  11785. *
  11786. @@ -971,6 +1440,23 @@
  11787. return -EDEADLK;
  11788. raw_spin_lock(&task->pi_lock);
  11789. +
  11790. + /*
  11791. + * In the case of futex requeue PI, this will be a proxy
  11792. + * lock. The task will wake unaware that it is enqueueed on
  11793. + * this lock. Avoid blocking on two locks and corrupting
  11794. + * pi_blocked_on via the PI_WAKEUP_INPROGRESS
  11795. + * flag. futex_wait_requeue_pi() sets this when it wakes up
  11796. + * before requeue (due to a signal or timeout). Do not enqueue
  11797. + * the task if PI_WAKEUP_INPROGRESS is set.
  11798. + */
  11799. + if (task != current && task->pi_blocked_on == PI_WAKEUP_INPROGRESS) {
  11800. + raw_spin_unlock(&task->pi_lock);
  11801. + return -EAGAIN;
  11802. + }
  11803. +
  11804. + BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
  11805. +
  11806. __rt_mutex_adjust_prio(task);
  11807. waiter->task = task;
  11808. waiter->lock = lock;
  11809. @@ -994,7 +1480,7 @@
  11810. rt_mutex_enqueue_pi(owner, waiter);
  11811. __rt_mutex_adjust_prio(owner);
  11812. - if (owner->pi_blocked_on)
  11813. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  11814. chain_walk = 1;
  11815. } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
  11816. chain_walk = 1;
  11817. @@ -1036,6 +1522,7 @@
  11818. * Called with lock->wait_lock held and interrupts disabled.
  11819. */
  11820. static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
  11821. + struct wake_q_head *wake_sleeper_q,
  11822. struct rt_mutex *lock)
  11823. {
  11824. struct rt_mutex_waiter *waiter;
  11825. @@ -1064,7 +1551,10 @@
  11826. raw_spin_unlock(&current->pi_lock);
  11827. - wake_q_add(wake_q, waiter->task);
  11828. + if (waiter->savestate)
  11829. + wake_q_add(wake_sleeper_q, waiter->task);
  11830. + else
  11831. + wake_q_add(wake_q, waiter->task);
  11832. }
  11833. /*
  11834. @@ -1078,7 +1568,7 @@
  11835. {
  11836. bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
  11837. struct task_struct *owner = rt_mutex_owner(lock);
  11838. - struct rt_mutex *next_lock;
  11839. + struct rt_mutex *next_lock = NULL;
  11840. raw_spin_lock(&current->pi_lock);
  11841. rt_mutex_dequeue(lock, waiter);
  11842. @@ -1102,7 +1592,8 @@
  11843. __rt_mutex_adjust_prio(owner);
  11844. /* Store the lock on which owner is blocked or NULL */
  11845. - next_lock = task_blocked_on_lock(owner);
  11846. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  11847. + next_lock = task_blocked_on_lock(owner);
  11848. raw_spin_unlock(&owner->pi_lock);
  11849. @@ -1138,17 +1629,17 @@
  11850. raw_spin_lock_irqsave(&task->pi_lock, flags);
  11851. waiter = task->pi_blocked_on;
  11852. - if (!waiter || (waiter->prio == task->prio &&
  11853. + if (!rt_mutex_real_waiter(waiter) || (waiter->prio == task->prio &&
  11854. !dl_prio(task->prio))) {
  11855. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  11856. return;
  11857. }
  11858. next_lock = waiter->lock;
  11859. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  11860. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  11861. get_task_struct(task);
  11862. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  11863. rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
  11864. next_lock, NULL, task);
  11865. }
  11866. @@ -1166,7 +1657,8 @@
  11867. static int __sched
  11868. __rt_mutex_slowlock(struct rt_mutex *lock, int state,
  11869. struct hrtimer_sleeper *timeout,
  11870. - struct rt_mutex_waiter *waiter)
  11871. + struct rt_mutex_waiter *waiter,
  11872. + struct ww_acquire_ctx *ww_ctx)
  11873. {
  11874. int ret = 0;
  11875. @@ -1189,6 +1681,12 @@
  11876. break;
  11877. }
  11878. + if (ww_ctx && ww_ctx->acquired > 0) {
  11879. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  11880. + if (ret)
  11881. + break;
  11882. + }
  11883. +
  11884. raw_spin_unlock_irq(&lock->wait_lock);
  11885. debug_rt_mutex_print_deadlock(waiter);
  11886. @@ -1223,21 +1721,96 @@
  11887. }
  11888. }
  11889. +static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
  11890. + struct ww_acquire_ctx *ww_ctx)
  11891. +{
  11892. +#ifdef CONFIG_DEBUG_MUTEXES
  11893. + /*
  11894. + * If this WARN_ON triggers, you used ww_mutex_lock to acquire,
  11895. + * but released with a normal mutex_unlock in this call.
  11896. + *
  11897. + * This should never happen, always use ww_mutex_unlock.
  11898. + */
  11899. + DEBUG_LOCKS_WARN_ON(ww->ctx);
  11900. +
  11901. + /*
  11902. + * Not quite done after calling ww_acquire_done() ?
  11903. + */
  11904. + DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire);
  11905. +
  11906. + if (ww_ctx->contending_lock) {
  11907. + /*
  11908. + * After -EDEADLK you tried to
  11909. + * acquire a different ww_mutex? Bad!
  11910. + */
  11911. + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww);
  11912. +
  11913. + /*
  11914. + * You called ww_mutex_lock after receiving -EDEADLK,
  11915. + * but 'forgot' to unlock everything else first?
  11916. + */
  11917. + DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0);
  11918. + ww_ctx->contending_lock = NULL;
  11919. + }
  11920. +
  11921. + /*
  11922. + * Naughty, using a different class will lead to undefined behavior!
  11923. + */
  11924. + DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class);
  11925. +#endif
  11926. + ww_ctx->acquired++;
  11927. +}
  11928. +
  11929. +#ifdef CONFIG_PREEMPT_RT_FULL
  11930. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  11931. + struct ww_acquire_ctx *ww_ctx)
  11932. +{
  11933. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  11934. + struct rt_mutex_waiter *waiter, *n;
  11935. +
  11936. + /*
  11937. + * This branch gets optimized out for the common case,
  11938. + * and is only important for ww_mutex_lock.
  11939. + */
  11940. + ww_mutex_lock_acquired(ww, ww_ctx);
  11941. + ww->ctx = ww_ctx;
  11942. +
  11943. + /*
  11944. + * Give any possible sleeping processes the chance to wake up,
  11945. + * so they can recheck if they have to back off.
  11946. + */
  11947. + rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters,
  11948. + tree_entry) {
  11949. + /* XXX debug rt mutex waiter wakeup */
  11950. +
  11951. + BUG_ON(waiter->lock != lock);
  11952. + rt_mutex_wake_waiter(waiter);
  11953. + }
  11954. +}
  11955. +
  11956. +#else
  11957. +
  11958. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  11959. + struct ww_acquire_ctx *ww_ctx)
  11960. +{
  11961. + BUG();
  11962. +}
  11963. +#endif
  11964. +
  11965. /*
  11966. * Slow path lock function:
  11967. */
  11968. static int __sched
  11969. rt_mutex_slowlock(struct rt_mutex *lock, int state,
  11970. struct hrtimer_sleeper *timeout,
  11971. - enum rtmutex_chainwalk chwalk)
  11972. + enum rtmutex_chainwalk chwalk,
  11973. + struct ww_acquire_ctx *ww_ctx)
  11974. {
  11975. struct rt_mutex_waiter waiter;
  11976. unsigned long flags;
  11977. int ret = 0;
  11978. - debug_rt_mutex_init_waiter(&waiter);
  11979. - RB_CLEAR_NODE(&waiter.pi_tree_entry);
  11980. - RB_CLEAR_NODE(&waiter.tree_entry);
  11981. + rt_mutex_init_waiter(&waiter, false);
  11982. /*
  11983. * Technically we could use raw_spin_[un]lock_irq() here, but this can
  11984. @@ -1251,6 +1824,8 @@
  11985. /* Try to acquire the lock again: */
  11986. if (try_to_take_rt_mutex(lock, current, NULL)) {
  11987. + if (ww_ctx)
  11988. + ww_mutex_account_lock(lock, ww_ctx);
  11989. raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  11990. return 0;
  11991. }
  11992. @@ -1265,13 +1840,23 @@
  11993. if (likely(!ret))
  11994. /* sleep on the mutex */
  11995. - ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
  11996. + ret = __rt_mutex_slowlock(lock, state, timeout, &waiter,
  11997. + ww_ctx);
  11998. + else if (ww_ctx) {
  11999. + /* ww_mutex received EDEADLK, let it become EALREADY */
  12000. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  12001. + BUG_ON(!ret);
  12002. + }
  12003. if (unlikely(ret)) {
  12004. __set_current_state(TASK_RUNNING);
  12005. if (rt_mutex_has_waiters(lock))
  12006. remove_waiter(lock, &waiter);
  12007. - rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  12008. + /* ww_mutex want to report EDEADLK/EALREADY, let them */
  12009. + if (!ww_ctx)
  12010. + rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  12011. + } else if (ww_ctx) {
  12012. + ww_mutex_account_lock(lock, ww_ctx);
  12013. }
  12014. /*
  12015. @@ -1331,7 +1916,8 @@
  12016. * Return whether the current task needs to undo a potential priority boosting.
  12017. */
  12018. static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
  12019. - struct wake_q_head *wake_q)
  12020. + struct wake_q_head *wake_q,
  12021. + struct wake_q_head *wake_sleeper_q)
  12022. {
  12023. unsigned long flags;
  12024. @@ -1387,7 +1973,7 @@
  12025. *
  12026. * Queue the next waiter for wakeup once we release the wait_lock.
  12027. */
  12028. - mark_wakeup_next_waiter(wake_q, lock);
  12029. + mark_wakeup_next_waiter(wake_q, wake_sleeper_q, lock);
  12030. raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  12031. @@ -1403,31 +1989,36 @@
  12032. */
  12033. static inline int
  12034. rt_mutex_fastlock(struct rt_mutex *lock, int state,
  12035. + struct ww_acquire_ctx *ww_ctx,
  12036. int (*slowfn)(struct rt_mutex *lock, int state,
  12037. struct hrtimer_sleeper *timeout,
  12038. - enum rtmutex_chainwalk chwalk))
  12039. + enum rtmutex_chainwalk chwalk,
  12040. + struct ww_acquire_ctx *ww_ctx))
  12041. {
  12042. if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
  12043. rt_mutex_deadlock_account_lock(lock, current);
  12044. return 0;
  12045. } else
  12046. - return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
  12047. + return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK,
  12048. + ww_ctx);
  12049. }
  12050. static inline int
  12051. rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
  12052. struct hrtimer_sleeper *timeout,
  12053. enum rtmutex_chainwalk chwalk,
  12054. + struct ww_acquire_ctx *ww_ctx,
  12055. int (*slowfn)(struct rt_mutex *lock, int state,
  12056. struct hrtimer_sleeper *timeout,
  12057. - enum rtmutex_chainwalk chwalk))
  12058. + enum rtmutex_chainwalk chwalk,
  12059. + struct ww_acquire_ctx *ww_ctx))
  12060. {
  12061. if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
  12062. likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
  12063. rt_mutex_deadlock_account_lock(lock, current);
  12064. return 0;
  12065. } else
  12066. - return slowfn(lock, state, timeout, chwalk);
  12067. + return slowfn(lock, state, timeout, chwalk, ww_ctx);
  12068. }
  12069. static inline int
  12070. @@ -1444,17 +2035,20 @@
  12071. static inline void
  12072. rt_mutex_fastunlock(struct rt_mutex *lock,
  12073. bool (*slowfn)(struct rt_mutex *lock,
  12074. - struct wake_q_head *wqh))
  12075. + struct wake_q_head *wqh,
  12076. + struct wake_q_head *wq_sleeper))
  12077. {
  12078. WAKE_Q(wake_q);
  12079. + WAKE_Q(wake_sleeper_q);
  12080. if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
  12081. rt_mutex_deadlock_account_unlock(current);
  12082. } else {
  12083. - bool deboost = slowfn(lock, &wake_q);
  12084. + bool deboost = slowfn(lock, &wake_q, &wake_sleeper_q);
  12085. wake_up_q(&wake_q);
  12086. + wake_up_q_sleeper(&wake_sleeper_q);
  12087. /* Undo pi boosting if necessary: */
  12088. if (deboost)
  12089. @@ -1471,7 +2065,7 @@
  12090. {
  12091. might_sleep();
  12092. - rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
  12093. + rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock);
  12094. }
  12095. EXPORT_SYMBOL_GPL(rt_mutex_lock);
  12096. @@ -1488,7 +2082,7 @@
  12097. {
  12098. might_sleep();
  12099. - return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
  12100. + return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock);
  12101. }
  12102. EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  12103. @@ -1501,11 +2095,30 @@
  12104. might_sleep();
  12105. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  12106. - RT_MUTEX_FULL_CHAINWALK,
  12107. + RT_MUTEX_FULL_CHAINWALK, NULL,
  12108. rt_mutex_slowlock);
  12109. }
  12110. /**
  12111. + * rt_mutex_lock_killable - lock a rt_mutex killable
  12112. + *
  12113. + * @lock: the rt_mutex to be locked
  12114. + * @detect_deadlock: deadlock detection on/off
  12115. + *
  12116. + * Returns:
  12117. + * 0 on success
  12118. + * -EINTR when interrupted by a signal
  12119. + * -EDEADLK when the lock would deadlock (when deadlock detection is on)
  12120. + */
  12121. +int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
  12122. +{
  12123. + might_sleep();
  12124. +
  12125. + return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock);
  12126. +}
  12127. +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
  12128. +
  12129. +/**
  12130. * rt_mutex_timed_lock - lock a rt_mutex interruptible
  12131. * the timeout structure is provided
  12132. * by the caller
  12133. @@ -1525,6 +2138,7 @@
  12134. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  12135. RT_MUTEX_MIN_CHAINWALK,
  12136. + NULL,
  12137. rt_mutex_slowlock);
  12138. }
  12139. EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
  12140. @@ -1542,7 +2156,11 @@
  12141. */
  12142. int __sched rt_mutex_trylock(struct rt_mutex *lock)
  12143. {
  12144. +#ifdef CONFIG_PREEMPT_RT_FULL
  12145. + if (WARN_ON_ONCE(in_irq() || in_nmi()))
  12146. +#else
  12147. if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
  12148. +#endif
  12149. return 0;
  12150. return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
  12151. @@ -1568,13 +2186,14 @@
  12152. * required or not.
  12153. */
  12154. bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
  12155. - struct wake_q_head *wqh)
  12156. + struct wake_q_head *wqh,
  12157. + struct wake_q_head *wq_sleeper)
  12158. {
  12159. if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
  12160. rt_mutex_deadlock_account_unlock(current);
  12161. return false;
  12162. }
  12163. - return rt_mutex_slowunlock(lock, wqh);
  12164. + return rt_mutex_slowunlock(lock, wqh, wq_sleeper);
  12165. }
  12166. /**
  12167. @@ -1607,13 +2226,12 @@
  12168. void __rt_mutex_init(struct rt_mutex *lock, const char *name)
  12169. {
  12170. lock->owner = NULL;
  12171. - raw_spin_lock_init(&lock->wait_lock);
  12172. lock->waiters = RB_ROOT;
  12173. lock->waiters_leftmost = NULL;
  12174. debug_rt_mutex_init(lock, name);
  12175. }
  12176. -EXPORT_SYMBOL_GPL(__rt_mutex_init);
  12177. +EXPORT_SYMBOL(__rt_mutex_init);
  12178. /**
  12179. * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  12180. @@ -1628,7 +2246,7 @@
  12181. void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  12182. struct task_struct *proxy_owner)
  12183. {
  12184. - __rt_mutex_init(lock, NULL);
  12185. + rt_mutex_init(lock);
  12186. debug_rt_mutex_proxy_lock(lock, proxy_owner);
  12187. rt_mutex_set_owner(lock, proxy_owner);
  12188. rt_mutex_deadlock_account_lock(lock, proxy_owner);
  12189. @@ -1676,6 +2294,35 @@
  12190. return 1;
  12191. }
  12192. +#ifdef CONFIG_PREEMPT_RT_FULL
  12193. + /*
  12194. + * In PREEMPT_RT there's an added race.
  12195. + * If the task, that we are about to requeue, times out,
  12196. + * it can set the PI_WAKEUP_INPROGRESS. This tells the requeue
  12197. + * to skip this task. But right after the task sets
  12198. + * its pi_blocked_on to PI_WAKEUP_INPROGRESS it can then
  12199. + * block on the spin_lock(&hb->lock), which in RT is an rtmutex.
  12200. + * This will replace the PI_WAKEUP_INPROGRESS with the actual
  12201. + * lock that it blocks on. We *must not* place this task
  12202. + * on this proxy lock in that case.
  12203. + *
  12204. + * To prevent this race, we first take the task's pi_lock
  12205. + * and check if it has updated its pi_blocked_on. If it has,
  12206. + * we assume that it woke up and we return -EAGAIN.
  12207. + * Otherwise, we set the task's pi_blocked_on to
  12208. + * PI_REQUEUE_INPROGRESS, so that if the task is waking up
  12209. + * it will know that we are in the process of requeuing it.
  12210. + */
  12211. + raw_spin_lock(&task->pi_lock);
  12212. + if (task->pi_blocked_on) {
  12213. + raw_spin_unlock(&task->pi_lock);
  12214. + raw_spin_unlock_irq(&lock->wait_lock);
  12215. + return -EAGAIN;
  12216. + }
  12217. + task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
  12218. + raw_spin_unlock(&task->pi_lock);
  12219. +#endif
  12220. +
  12221. /* We enforce deadlock detection for futexes */
  12222. ret = task_blocks_on_rt_mutex(lock, waiter, task,
  12223. RT_MUTEX_FULL_CHAINWALK);
  12224. @@ -1690,7 +2337,7 @@
  12225. ret = 0;
  12226. }
  12227. - if (unlikely(ret))
  12228. + if (ret && rt_mutex_has_waiters(lock))
  12229. remove_waiter(lock, waiter);
  12230. raw_spin_unlock_irq(&lock->wait_lock);
  12231. @@ -1746,7 +2393,7 @@
  12232. set_current_state(TASK_INTERRUPTIBLE);
  12233. /* sleep on the mutex */
  12234. - ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
  12235. + ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
  12236. if (unlikely(ret))
  12237. remove_waiter(lock, waiter);
  12238. @@ -1761,3 +2408,89 @@
  12239. return ret;
  12240. }
  12241. +
  12242. +static inline int
  12243. +ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
  12244. +{
  12245. +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  12246. + unsigned tmp;
  12247. +
  12248. + if (ctx->deadlock_inject_countdown-- == 0) {
  12249. + tmp = ctx->deadlock_inject_interval;
  12250. + if (tmp > UINT_MAX/4)
  12251. + tmp = UINT_MAX;
  12252. + else
  12253. + tmp = tmp*2 + tmp + tmp/2;
  12254. +
  12255. + ctx->deadlock_inject_interval = tmp;
  12256. + ctx->deadlock_inject_countdown = tmp;
  12257. + ctx->contending_lock = lock;
  12258. +
  12259. + ww_mutex_unlock(lock);
  12260. +
  12261. + return -EDEADLK;
  12262. + }
  12263. +#endif
  12264. +
  12265. + return 0;
  12266. +}
  12267. +
  12268. +#ifdef CONFIG_PREEMPT_RT_FULL
  12269. +int __sched
  12270. +__ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  12271. +{
  12272. + int ret;
  12273. +
  12274. + might_sleep();
  12275. +
  12276. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  12277. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
  12278. + if (ret)
  12279. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  12280. + else if (!ret && ww_ctx->acquired > 1)
  12281. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  12282. +
  12283. + return ret;
  12284. +}
  12285. +EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
  12286. +
  12287. +int __sched
  12288. +__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  12289. +{
  12290. + int ret;
  12291. +
  12292. + might_sleep();
  12293. +
  12294. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  12295. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
  12296. + if (ret)
  12297. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  12298. + else if (!ret && ww_ctx->acquired > 1)
  12299. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  12300. +
  12301. + return ret;
  12302. +}
  12303. +EXPORT_SYMBOL_GPL(__ww_mutex_lock);
  12304. +
  12305. +void __sched ww_mutex_unlock(struct ww_mutex *lock)
  12306. +{
  12307. + int nest = !!lock->ctx;
  12308. +
  12309. + /*
  12310. + * The unlocking fastpath is the 0->1 transition from 'locked'
  12311. + * into 'unlocked' state:
  12312. + */
  12313. + if (nest) {
  12314. +#ifdef CONFIG_DEBUG_MUTEXES
  12315. + DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
  12316. +#endif
  12317. + if (lock->ctx->acquired > 0)
  12318. + lock->ctx->acquired--;
  12319. + lock->ctx = NULL;
  12320. + }
  12321. +
  12322. + mutex_release(&lock->base.dep_map, nest, _RET_IP_);
  12323. + rt_mutex_unlock(&lock->base.lock);
  12324. +}
  12325. +EXPORT_SYMBOL(ww_mutex_unlock);
  12326. +#endif
  12327. diff -Nur linux-4.9.6.orig/kernel/locking/rtmutex_common.h linux-4.9.6/kernel/locking/rtmutex_common.h
  12328. --- linux-4.9.6.orig/kernel/locking/rtmutex_common.h 2017-01-26 08:25:24.000000000 +0100
  12329. +++ linux-4.9.6/kernel/locking/rtmutex_common.h 2017-01-28 13:59:10.035660185 +0100
  12330. @@ -27,6 +27,7 @@
  12331. struct rb_node pi_tree_entry;
  12332. struct task_struct *task;
  12333. struct rt_mutex *lock;
  12334. + bool savestate;
  12335. #ifdef CONFIG_DEBUG_RT_MUTEXES
  12336. unsigned long ip;
  12337. struct pid *deadlock_task_pid;
  12338. @@ -98,6 +99,9 @@
  12339. /*
  12340. * PI-futex support (proxy locking functions, etc.):
  12341. */
  12342. +#define PI_WAKEUP_INPROGRESS ((struct rt_mutex_waiter *) 1)
  12343. +#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
  12344. +
  12345. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  12346. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  12347. struct task_struct *proxy_owner);
  12348. @@ -111,7 +115,8 @@
  12349. struct rt_mutex_waiter *waiter);
  12350. extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
  12351. extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
  12352. - struct wake_q_head *wqh);
  12353. + struct wake_q_head *wqh,
  12354. + struct wake_q_head *wq_sleeper);
  12355. extern void rt_mutex_adjust_prio(struct task_struct *task);
  12356. #ifdef CONFIG_DEBUG_RT_MUTEXES
  12357. @@ -120,4 +125,14 @@
  12358. # include "rtmutex.h"
  12359. #endif
  12360. +static inline void
  12361. +rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
  12362. +{
  12363. + debug_rt_mutex_init_waiter(waiter);
  12364. + waiter->task = NULL;
  12365. + waiter->savestate = savestate;
  12366. + RB_CLEAR_NODE(&waiter->pi_tree_entry);
  12367. + RB_CLEAR_NODE(&waiter->tree_entry);
  12368. +}
  12369. +
  12370. #endif
  12371. diff -Nur linux-4.9.6.orig/kernel/locking/spinlock.c linux-4.9.6/kernel/locking/spinlock.c
  12372. --- linux-4.9.6.orig/kernel/locking/spinlock.c 2017-01-26 08:25:24.000000000 +0100
  12373. +++ linux-4.9.6/kernel/locking/spinlock.c 2017-01-28 13:59:10.035660185 +0100
  12374. @@ -124,8 +124,11 @@
  12375. * __[spin|read|write]_lock_bh()
  12376. */
  12377. BUILD_LOCK_OPS(spin, raw_spinlock);
  12378. +
  12379. +#ifndef CONFIG_PREEMPT_RT_FULL
  12380. BUILD_LOCK_OPS(read, rwlock);
  12381. BUILD_LOCK_OPS(write, rwlock);
  12382. +#endif
  12383. #endif
  12384. @@ -209,6 +212,8 @@
  12385. EXPORT_SYMBOL(_raw_spin_unlock_bh);
  12386. #endif
  12387. +#ifndef CONFIG_PREEMPT_RT_FULL
  12388. +
  12389. #ifndef CONFIG_INLINE_READ_TRYLOCK
  12390. int __lockfunc _raw_read_trylock(rwlock_t *lock)
  12391. {
  12392. @@ -353,6 +358,8 @@
  12393. EXPORT_SYMBOL(_raw_write_unlock_bh);
  12394. #endif
  12395. +#endif /* !PREEMPT_RT_FULL */
  12396. +
  12397. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  12398. void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
  12399. diff -Nur linux-4.9.6.orig/kernel/locking/spinlock_debug.c linux-4.9.6/kernel/locking/spinlock_debug.c
  12400. --- linux-4.9.6.orig/kernel/locking/spinlock_debug.c 2017-01-26 08:25:24.000000000 +0100
  12401. +++ linux-4.9.6/kernel/locking/spinlock_debug.c 2017-01-28 13:59:10.035660185 +0100
  12402. @@ -31,6 +31,7 @@
  12403. EXPORT_SYMBOL(__raw_spin_lock_init);
  12404. +#ifndef CONFIG_PREEMPT_RT_FULL
  12405. void __rwlock_init(rwlock_t *lock, const char *name,
  12406. struct lock_class_key *key)
  12407. {
  12408. @@ -48,6 +49,7 @@
  12409. }
  12410. EXPORT_SYMBOL(__rwlock_init);
  12411. +#endif
  12412. static void spin_dump(raw_spinlock_t *lock, const char *msg)
  12413. {
  12414. @@ -159,6 +161,7 @@
  12415. arch_spin_unlock(&lock->raw_lock);
  12416. }
  12417. +#ifndef CONFIG_PREEMPT_RT_FULL
  12418. static void rwlock_bug(rwlock_t *lock, const char *msg)
  12419. {
  12420. if (!debug_locks_off())
  12421. @@ -300,3 +303,5 @@
  12422. debug_write_unlock(lock);
  12423. arch_write_unlock(&lock->raw_lock);
  12424. }
  12425. +
  12426. +#endif
  12427. diff -Nur linux-4.9.6.orig/kernel/panic.c linux-4.9.6/kernel/panic.c
  12428. --- linux-4.9.6.orig/kernel/panic.c 2017-01-26 08:25:24.000000000 +0100
  12429. +++ linux-4.9.6/kernel/panic.c 2017-01-28 13:59:10.035660185 +0100
  12430. @@ -482,9 +482,11 @@
  12431. static int init_oops_id(void)
  12432. {
  12433. +#ifndef CONFIG_PREEMPT_RT_FULL
  12434. if (!oops_id)
  12435. get_random_bytes(&oops_id, sizeof(oops_id));
  12436. else
  12437. +#endif
  12438. oops_id++;
  12439. return 0;
  12440. diff -Nur linux-4.9.6.orig/kernel/power/hibernate.c linux-4.9.6/kernel/power/hibernate.c
  12441. --- linux-4.9.6.orig/kernel/power/hibernate.c 2017-01-26 08:25:24.000000000 +0100
  12442. +++ linux-4.9.6/kernel/power/hibernate.c 2017-01-28 13:59:10.039660339 +0100
  12443. @@ -286,6 +286,8 @@
  12444. local_irq_disable();
  12445. + system_state = SYSTEM_SUSPEND;
  12446. +
  12447. error = syscore_suspend();
  12448. if (error) {
  12449. printk(KERN_ERR "PM: Some system devices failed to power down, "
  12450. @@ -317,6 +319,7 @@
  12451. syscore_resume();
  12452. Enable_irqs:
  12453. + system_state = SYSTEM_RUNNING;
  12454. local_irq_enable();
  12455. Enable_cpus:
  12456. @@ -446,6 +449,7 @@
  12457. goto Enable_cpus;
  12458. local_irq_disable();
  12459. + system_state = SYSTEM_SUSPEND;
  12460. error = syscore_suspend();
  12461. if (error)
  12462. @@ -479,6 +483,7 @@
  12463. syscore_resume();
  12464. Enable_irqs:
  12465. + system_state = SYSTEM_RUNNING;
  12466. local_irq_enable();
  12467. Enable_cpus:
  12468. @@ -564,6 +569,7 @@
  12469. goto Enable_cpus;
  12470. local_irq_disable();
  12471. + system_state = SYSTEM_SUSPEND;
  12472. syscore_suspend();
  12473. if (pm_wakeup_pending()) {
  12474. error = -EAGAIN;
  12475. @@ -576,6 +582,7 @@
  12476. Power_up:
  12477. syscore_resume();
  12478. + system_state = SYSTEM_RUNNING;
  12479. local_irq_enable();
  12480. Enable_cpus:
  12481. @@ -676,6 +683,10 @@
  12482. return error;
  12483. }
  12484. +#ifndef CONFIG_SUSPEND
  12485. +bool pm_in_action;
  12486. +#endif
  12487. +
  12488. /**
  12489. * hibernate - Carry out system hibernation, including saving the image.
  12490. */
  12491. @@ -689,6 +700,8 @@
  12492. return -EPERM;
  12493. }
  12494. + pm_in_action = true;
  12495. +
  12496. lock_system_sleep();
  12497. /* The snapshot device should not be opened while we're running */
  12498. if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
  12499. @@ -766,6 +779,7 @@
  12500. atomic_inc(&snapshot_device_available);
  12501. Unlock:
  12502. unlock_system_sleep();
  12503. + pm_in_action = false;
  12504. return error;
  12505. }
  12506. diff -Nur linux-4.9.6.orig/kernel/power/suspend.c linux-4.9.6/kernel/power/suspend.c
  12507. --- linux-4.9.6.orig/kernel/power/suspend.c 2017-01-26 08:25:24.000000000 +0100
  12508. +++ linux-4.9.6/kernel/power/suspend.c 2017-01-28 13:59:10.039660339 +0100
  12509. @@ -369,6 +369,8 @@
  12510. arch_suspend_disable_irqs();
  12511. BUG_ON(!irqs_disabled());
  12512. + system_state = SYSTEM_SUSPEND;
  12513. +
  12514. error = syscore_suspend();
  12515. if (!error) {
  12516. *wakeup = pm_wakeup_pending();
  12517. @@ -385,6 +387,8 @@
  12518. syscore_resume();
  12519. }
  12520. + system_state = SYSTEM_RUNNING;
  12521. +
  12522. arch_suspend_enable_irqs();
  12523. BUG_ON(irqs_disabled());
  12524. @@ -527,6 +531,8 @@
  12525. return error;
  12526. }
  12527. +bool pm_in_action;
  12528. +
  12529. /**
  12530. * pm_suspend - Externally visible function for suspending the system.
  12531. * @state: System sleep state to enter.
  12532. @@ -541,6 +547,8 @@
  12533. if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
  12534. return -EINVAL;
  12535. + pm_in_action = true;
  12536. +
  12537. error = enter_state(state);
  12538. if (error) {
  12539. suspend_stats.fail++;
  12540. @@ -548,6 +556,7 @@
  12541. } else {
  12542. suspend_stats.success++;
  12543. }
  12544. + pm_in_action = false;
  12545. return error;
  12546. }
  12547. EXPORT_SYMBOL(pm_suspend);
  12548. diff -Nur linux-4.9.6.orig/kernel/printk/printk.c linux-4.9.6/kernel/printk/printk.c
  12549. --- linux-4.9.6.orig/kernel/printk/printk.c 2017-01-26 08:25:24.000000000 +0100
  12550. +++ linux-4.9.6/kernel/printk/printk.c 2017-01-28 13:59:10.039660339 +0100
  12551. @@ -351,6 +351,65 @@
  12552. */
  12553. DEFINE_RAW_SPINLOCK(logbuf_lock);
  12554. +#ifdef CONFIG_EARLY_PRINTK
  12555. +struct console *early_console;
  12556. +
  12557. +static void early_vprintk(const char *fmt, va_list ap)
  12558. +{
  12559. + if (early_console) {
  12560. + char buf[512];
  12561. + int n = vscnprintf(buf, sizeof(buf), fmt, ap);
  12562. +
  12563. + early_console->write(early_console, buf, n);
  12564. + }
  12565. +}
  12566. +
  12567. +asmlinkage void early_printk(const char *fmt, ...)
  12568. +{
  12569. + va_list ap;
  12570. +
  12571. + va_start(ap, fmt);
  12572. + early_vprintk(fmt, ap);
  12573. + va_end(ap);
  12574. +}
  12575. +
  12576. +/*
  12577. + * This is independent of any log levels - a global
  12578. + * kill switch that turns off all of printk.
  12579. + *
  12580. + * Used by the NMI watchdog if early-printk is enabled.
  12581. + */
  12582. +static bool __read_mostly printk_killswitch;
  12583. +
  12584. +static int __init force_early_printk_setup(char *str)
  12585. +{
  12586. + printk_killswitch = true;
  12587. + return 0;
  12588. +}
  12589. +early_param("force_early_printk", force_early_printk_setup);
  12590. +
  12591. +void printk_kill(void)
  12592. +{
  12593. + printk_killswitch = true;
  12594. +}
  12595. +
  12596. +#ifdef CONFIG_PRINTK
  12597. +static int forced_early_printk(const char *fmt, va_list ap)
  12598. +{
  12599. + if (!printk_killswitch)
  12600. + return 0;
  12601. + early_vprintk(fmt, ap);
  12602. + return 1;
  12603. +}
  12604. +#endif
  12605. +
  12606. +#else
  12607. +static inline int forced_early_printk(const char *fmt, va_list ap)
  12608. +{
  12609. + return 0;
  12610. +}
  12611. +#endif
  12612. +
  12613. #ifdef CONFIG_PRINTK
  12614. DECLARE_WAIT_QUEUE_HEAD(log_wait);
  12615. /* the next printk record to read by syslog(READ) or /proc/kmsg */
  12616. @@ -1337,6 +1396,7 @@
  12617. {
  12618. char *text;
  12619. int len = 0;
  12620. + int attempts = 0;
  12621. text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
  12622. if (!text)
  12623. @@ -1348,6 +1408,14 @@
  12624. u64 seq;
  12625. u32 idx;
  12626. enum log_flags prev;
  12627. + int num_msg;
  12628. +try_again:
  12629. + attempts++;
  12630. + if (attempts > 10) {
  12631. + len = -EBUSY;
  12632. + goto out;
  12633. + }
  12634. + num_msg = 0;
  12635. /*
  12636. * Find first record that fits, including all following records,
  12637. @@ -1363,6 +1431,14 @@
  12638. prev = msg->flags;
  12639. idx = log_next(idx);
  12640. seq++;
  12641. + num_msg++;
  12642. + if (num_msg > 5) {
  12643. + num_msg = 0;
  12644. + raw_spin_unlock_irq(&logbuf_lock);
  12645. + raw_spin_lock_irq(&logbuf_lock);
  12646. + if (clear_seq < log_first_seq)
  12647. + goto try_again;
  12648. + }
  12649. }
  12650. /* move first record forward until length fits into the buffer */
  12651. @@ -1376,6 +1452,14 @@
  12652. prev = msg->flags;
  12653. idx = log_next(idx);
  12654. seq++;
  12655. + num_msg++;
  12656. + if (num_msg > 5) {
  12657. + num_msg = 0;
  12658. + raw_spin_unlock_irq(&logbuf_lock);
  12659. + raw_spin_lock_irq(&logbuf_lock);
  12660. + if (clear_seq < log_first_seq)
  12661. + goto try_again;
  12662. + }
  12663. }
  12664. /* last message fitting into this dump */
  12665. @@ -1416,6 +1500,7 @@
  12666. clear_seq = log_next_seq;
  12667. clear_idx = log_next_idx;
  12668. }
  12669. +out:
  12670. raw_spin_unlock_irq(&logbuf_lock);
  12671. kfree(text);
  12672. @@ -1569,6 +1654,12 @@
  12673. if (!console_drivers)
  12674. return;
  12675. + if (IS_ENABLED(CONFIG_PREEMPT_RT_BASE)) {
  12676. + if (in_irq() || in_nmi())
  12677. + return;
  12678. + }
  12679. +
  12680. + migrate_disable();
  12681. for_each_console(con) {
  12682. if (exclusive_console && con != exclusive_console)
  12683. continue;
  12684. @@ -1584,6 +1675,7 @@
  12685. else
  12686. con->write(con, text, len);
  12687. }
  12688. + migrate_enable();
  12689. }
  12690. /*
  12691. @@ -1781,6 +1873,13 @@
  12692. /* cpu currently holding logbuf_lock in this function */
  12693. static unsigned int logbuf_cpu = UINT_MAX;
  12694. + /*
  12695. + * Fall back to early_printk if a debugging subsystem has
  12696. + * killed printk output
  12697. + */
  12698. + if (unlikely(forced_early_printk(fmt, args)))
  12699. + return 1;
  12700. +
  12701. if (level == LOGLEVEL_SCHED) {
  12702. level = LOGLEVEL_DEFAULT;
  12703. in_sched = true;
  12704. @@ -1885,13 +1984,23 @@
  12705. /* If called from the scheduler, we can not call up(). */
  12706. if (!in_sched) {
  12707. + int may_trylock = 1;
  12708. +
  12709. lockdep_off();
  12710. +#ifdef CONFIG_PREEMPT_RT_FULL
  12711. + /*
  12712. + * we can't take a sleeping lock with IRQs or preeption disabled
  12713. + * so we can't print in these contexts
  12714. + */
  12715. + if (!(preempt_count() == 0 && !irqs_disabled()))
  12716. + may_trylock = 0;
  12717. +#endif
  12718. /*
  12719. * Try to acquire and then immediately release the console
  12720. * semaphore. The release will print out buffers and wake up
  12721. * /dev/kmsg and syslog() users.
  12722. */
  12723. - if (console_trylock())
  12724. + if (may_trylock && console_trylock())
  12725. console_unlock();
  12726. lockdep_on();
  12727. }
  12728. @@ -2014,26 +2123,6 @@
  12729. #endif /* CONFIG_PRINTK */
  12730. -#ifdef CONFIG_EARLY_PRINTK
  12731. -struct console *early_console;
  12732. -
  12733. -asmlinkage __visible void early_printk(const char *fmt, ...)
  12734. -{
  12735. - va_list ap;
  12736. - char buf[512];
  12737. - int n;
  12738. -
  12739. - if (!early_console)
  12740. - return;
  12741. -
  12742. - va_start(ap, fmt);
  12743. - n = vscnprintf(buf, sizeof(buf), fmt, ap);
  12744. - va_end(ap);
  12745. -
  12746. - early_console->write(early_console, buf, n);
  12747. -}
  12748. -#endif
  12749. -
  12750. static int __add_preferred_console(char *name, int idx, char *options,
  12751. char *brl_options)
  12752. {
  12753. @@ -2303,11 +2392,16 @@
  12754. goto out;
  12755. len = cont_print_text(text, size);
  12756. +#ifdef CONFIG_PREEMPT_RT_FULL
  12757. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  12758. + call_console_drivers(cont.level, NULL, 0, text, len);
  12759. +#else
  12760. raw_spin_unlock(&logbuf_lock);
  12761. stop_critical_timings();
  12762. call_console_drivers(cont.level, NULL, 0, text, len);
  12763. start_critical_timings();
  12764. local_irq_restore(flags);
  12765. +#endif
  12766. return;
  12767. out:
  12768. raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  12769. @@ -2431,13 +2525,17 @@
  12770. console_idx = log_next(console_idx);
  12771. console_seq++;
  12772. console_prev = msg->flags;
  12773. +#ifdef CONFIG_PREEMPT_RT_FULL
  12774. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  12775. + call_console_drivers(level, ext_text, ext_len, text, len);
  12776. +#else
  12777. raw_spin_unlock(&logbuf_lock);
  12778. stop_critical_timings(); /* don't trace print latency */
  12779. call_console_drivers(level, ext_text, ext_len, text, len);
  12780. start_critical_timings();
  12781. local_irq_restore(flags);
  12782. -
  12783. +#endif
  12784. if (do_cond_resched)
  12785. cond_resched();
  12786. }
  12787. @@ -2489,6 +2587,11 @@
  12788. {
  12789. struct console *c;
  12790. + if (IS_ENABLED(CONFIG_PREEMPT_RT_BASE)) {
  12791. + if (in_irq() || in_nmi())
  12792. + return;
  12793. + }
  12794. +
  12795. /*
  12796. * console_unblank can no longer be called in interrupt context unless
  12797. * oops_in_progress is set to 1..
  12798. diff -Nur linux-4.9.6.orig/kernel/ptrace.c linux-4.9.6/kernel/ptrace.c
  12799. --- linux-4.9.6.orig/kernel/ptrace.c 2017-01-26 08:25:24.000000000 +0100
  12800. +++ linux-4.9.6/kernel/ptrace.c 2017-01-28 13:59:10.039660339 +0100
  12801. @@ -166,7 +166,14 @@
  12802. spin_lock_irq(&task->sighand->siglock);
  12803. if (task_is_traced(task) && !__fatal_signal_pending(task)) {
  12804. - task->state = __TASK_TRACED;
  12805. + unsigned long flags;
  12806. +
  12807. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  12808. + if (task->state & __TASK_TRACED)
  12809. + task->state = __TASK_TRACED;
  12810. + else
  12811. + task->saved_state = __TASK_TRACED;
  12812. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  12813. ret = true;
  12814. }
  12815. spin_unlock_irq(&task->sighand->siglock);
  12816. diff -Nur linux-4.9.6.orig/kernel/rcu/rcutorture.c linux-4.9.6/kernel/rcu/rcutorture.c
  12817. --- linux-4.9.6.orig/kernel/rcu/rcutorture.c 2017-01-26 08:25:24.000000000 +0100
  12818. +++ linux-4.9.6/kernel/rcu/rcutorture.c 2017-01-28 13:59:10.039660339 +0100
  12819. @@ -404,6 +404,7 @@
  12820. .name = "rcu"
  12821. };
  12822. +#ifndef CONFIG_PREEMPT_RT_FULL
  12823. /*
  12824. * Definitions for rcu_bh torture testing.
  12825. */
  12826. @@ -443,6 +444,12 @@
  12827. .name = "rcu_bh"
  12828. };
  12829. +#else
  12830. +static struct rcu_torture_ops rcu_bh_ops = {
  12831. + .ttype = INVALID_RCU_FLAVOR,
  12832. +};
  12833. +#endif
  12834. +
  12835. /*
  12836. * Don't even think about trying any of these in real life!!!
  12837. * The names includes "busted", and they really means it!
  12838. diff -Nur linux-4.9.6.orig/kernel/rcu/tree.c linux-4.9.6/kernel/rcu/tree.c
  12839. --- linux-4.9.6.orig/kernel/rcu/tree.c 2017-01-26 08:25:24.000000000 +0100
  12840. +++ linux-4.9.6/kernel/rcu/tree.c 2017-01-28 13:59:10.039660339 +0100
  12841. @@ -55,6 +55,11 @@
  12842. #include <linux/random.h>
  12843. #include <linux/trace_events.h>
  12844. #include <linux/suspend.h>
  12845. +#include <linux/delay.h>
  12846. +#include <linux/gfp.h>
  12847. +#include <linux/oom.h>
  12848. +#include <linux/smpboot.h>
  12849. +#include "../time/tick-internal.h"
  12850. #include "tree.h"
  12851. #include "rcu.h"
  12852. @@ -260,6 +265,19 @@
  12853. this_cpu_ptr(&rcu_sched_data), true);
  12854. }
  12855. +#ifdef CONFIG_PREEMPT_RT_FULL
  12856. +static void rcu_preempt_qs(void);
  12857. +
  12858. +void rcu_bh_qs(void)
  12859. +{
  12860. + unsigned long flags;
  12861. +
  12862. + /* Callers to this function, rcu_preempt_qs(), must disable irqs. */
  12863. + local_irq_save(flags);
  12864. + rcu_preempt_qs();
  12865. + local_irq_restore(flags);
  12866. +}
  12867. +#else
  12868. void rcu_bh_qs(void)
  12869. {
  12870. if (__this_cpu_read(rcu_bh_data.cpu_no_qs.s)) {
  12871. @@ -269,6 +287,7 @@
  12872. __this_cpu_write(rcu_bh_data.cpu_no_qs.b.norm, false);
  12873. }
  12874. }
  12875. +#endif
  12876. static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
  12877. @@ -449,11 +468,13 @@
  12878. /*
  12879. * Return the number of RCU BH batches started thus far for debug & stats.
  12880. */
  12881. +#ifndef CONFIG_PREEMPT_RT_FULL
  12882. unsigned long rcu_batches_started_bh(void)
  12883. {
  12884. return rcu_bh_state.gpnum;
  12885. }
  12886. EXPORT_SYMBOL_GPL(rcu_batches_started_bh);
  12887. +#endif
  12888. /*
  12889. * Return the number of RCU batches completed thus far for debug & stats.
  12890. @@ -473,6 +494,7 @@
  12891. }
  12892. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  12893. +#ifndef CONFIG_PREEMPT_RT_FULL
  12894. /*
  12895. * Return the number of RCU BH batches completed thus far for debug & stats.
  12896. */
  12897. @@ -481,6 +503,7 @@
  12898. return rcu_bh_state.completed;
  12899. }
  12900. EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
  12901. +#endif
  12902. /*
  12903. * Return the number of RCU expedited batches completed thus far for
  12904. @@ -504,6 +527,7 @@
  12905. }
  12906. EXPORT_SYMBOL_GPL(rcu_exp_batches_completed_sched);
  12907. +#ifndef CONFIG_PREEMPT_RT_FULL
  12908. /*
  12909. * Force a quiescent state.
  12910. */
  12911. @@ -522,6 +546,13 @@
  12912. }
  12913. EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  12914. +#else
  12915. +void rcu_force_quiescent_state(void)
  12916. +{
  12917. +}
  12918. +EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  12919. +#endif
  12920. +
  12921. /*
  12922. * Force a quiescent state for RCU-sched.
  12923. */
  12924. @@ -572,9 +603,11 @@
  12925. case RCU_FLAVOR:
  12926. rsp = rcu_state_p;
  12927. break;
  12928. +#ifndef CONFIG_PREEMPT_RT_FULL
  12929. case RCU_BH_FLAVOR:
  12930. rsp = &rcu_bh_state;
  12931. break;
  12932. +#endif
  12933. case RCU_SCHED_FLAVOR:
  12934. rsp = &rcu_sched_state;
  12935. break;
  12936. @@ -3016,18 +3049,17 @@
  12937. /*
  12938. * Do RCU core processing for the current CPU.
  12939. */
  12940. -static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
  12941. +static __latent_entropy void rcu_process_callbacks(void)
  12942. {
  12943. struct rcu_state *rsp;
  12944. if (cpu_is_offline(smp_processor_id()))
  12945. return;
  12946. - trace_rcu_utilization(TPS("Start RCU core"));
  12947. for_each_rcu_flavor(rsp)
  12948. __rcu_process_callbacks(rsp);
  12949. - trace_rcu_utilization(TPS("End RCU core"));
  12950. }
  12951. +static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  12952. /*
  12953. * Schedule RCU callback invocation. If the specified type of RCU
  12954. * does not support RCU priority boosting, just do a direct call,
  12955. @@ -3039,18 +3071,105 @@
  12956. {
  12957. if (unlikely(!READ_ONCE(rcu_scheduler_fully_active)))
  12958. return;
  12959. - if (likely(!rsp->boost)) {
  12960. - rcu_do_batch(rsp, rdp);
  12961. + rcu_do_batch(rsp, rdp);
  12962. +}
  12963. +
  12964. +static void rcu_wake_cond(struct task_struct *t, int status)
  12965. +{
  12966. + /*
  12967. + * If the thread is yielding, only wake it when this
  12968. + * is invoked from idle
  12969. + */
  12970. + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
  12971. + wake_up_process(t);
  12972. +}
  12973. +
  12974. +/*
  12975. + * Wake up this CPU's rcuc kthread to do RCU core processing.
  12976. + */
  12977. +static void invoke_rcu_core(void)
  12978. +{
  12979. + unsigned long flags;
  12980. + struct task_struct *t;
  12981. +
  12982. + if (!cpu_online(smp_processor_id()))
  12983. return;
  12984. + local_irq_save(flags);
  12985. + __this_cpu_write(rcu_cpu_has_work, 1);
  12986. + t = __this_cpu_read(rcu_cpu_kthread_task);
  12987. + if (t != NULL && current != t)
  12988. + rcu_wake_cond(t, __this_cpu_read(rcu_cpu_kthread_status));
  12989. + local_irq_restore(flags);
  12990. +}
  12991. +
  12992. +static void rcu_cpu_kthread_park(unsigned int cpu)
  12993. +{
  12994. + per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  12995. +}
  12996. +
  12997. +static int rcu_cpu_kthread_should_run(unsigned int cpu)
  12998. +{
  12999. + return __this_cpu_read(rcu_cpu_has_work);
  13000. +}
  13001. +
  13002. +/*
  13003. + * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  13004. + * RCU softirq used in flavors and configurations of RCU that do not
  13005. + * support RCU priority boosting.
  13006. + */
  13007. +static void rcu_cpu_kthread(unsigned int cpu)
  13008. +{
  13009. + unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  13010. + char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  13011. + int spincnt;
  13012. +
  13013. + for (spincnt = 0; spincnt < 10; spincnt++) {
  13014. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  13015. + local_bh_disable();
  13016. + *statusp = RCU_KTHREAD_RUNNING;
  13017. + this_cpu_inc(rcu_cpu_kthread_loops);
  13018. + local_irq_disable();
  13019. + work = *workp;
  13020. + *workp = 0;
  13021. + local_irq_enable();
  13022. + if (work)
  13023. + rcu_process_callbacks();
  13024. + local_bh_enable();
  13025. + if (*workp == 0) {
  13026. + trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  13027. + *statusp = RCU_KTHREAD_WAITING;
  13028. + return;
  13029. + }
  13030. }
  13031. - invoke_rcu_callbacks_kthread();
  13032. + *statusp = RCU_KTHREAD_YIELDING;
  13033. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  13034. + schedule_timeout_interruptible(2);
  13035. + trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  13036. + *statusp = RCU_KTHREAD_WAITING;
  13037. }
  13038. -static void invoke_rcu_core(void)
  13039. +static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  13040. + .store = &rcu_cpu_kthread_task,
  13041. + .thread_should_run = rcu_cpu_kthread_should_run,
  13042. + .thread_fn = rcu_cpu_kthread,
  13043. + .thread_comm = "rcuc/%u",
  13044. + .setup = rcu_cpu_kthread_setup,
  13045. + .park = rcu_cpu_kthread_park,
  13046. +};
  13047. +
  13048. +/*
  13049. + * Spawn per-CPU RCU core processing kthreads.
  13050. + */
  13051. +static int __init rcu_spawn_core_kthreads(void)
  13052. {
  13053. - if (cpu_online(smp_processor_id()))
  13054. - raise_softirq(RCU_SOFTIRQ);
  13055. + int cpu;
  13056. +
  13057. + for_each_possible_cpu(cpu)
  13058. + per_cpu(rcu_cpu_has_work, cpu) = 0;
  13059. + BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  13060. + return 0;
  13061. }
  13062. +early_initcall(rcu_spawn_core_kthreads);
  13063. /*
  13064. * Handle any core-RCU processing required by a call_rcu() invocation.
  13065. @@ -3195,6 +3314,7 @@
  13066. }
  13067. EXPORT_SYMBOL_GPL(call_rcu_sched);
  13068. +#ifndef CONFIG_PREEMPT_RT_FULL
  13069. /*
  13070. * Queue an RCU callback for invocation after a quicker grace period.
  13071. */
  13072. @@ -3203,6 +3323,7 @@
  13073. __call_rcu(head, func, &rcu_bh_state, -1, 0);
  13074. }
  13075. EXPORT_SYMBOL_GPL(call_rcu_bh);
  13076. +#endif
  13077. /*
  13078. * Queue an RCU callback for lazy invocation after a grace period.
  13079. @@ -3294,6 +3415,7 @@
  13080. }
  13081. EXPORT_SYMBOL_GPL(synchronize_sched);
  13082. +#ifndef CONFIG_PREEMPT_RT_FULL
  13083. /**
  13084. * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
  13085. *
  13086. @@ -3320,6 +3442,7 @@
  13087. wait_rcu_gp(call_rcu_bh);
  13088. }
  13089. EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
  13090. +#endif
  13091. /**
  13092. * get_state_synchronize_rcu - Snapshot current RCU state
  13093. @@ -3698,6 +3821,7 @@
  13094. mutex_unlock(&rsp->barrier_mutex);
  13095. }
  13096. +#ifndef CONFIG_PREEMPT_RT_FULL
  13097. /**
  13098. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  13099. */
  13100. @@ -3706,6 +3830,7 @@
  13101. _rcu_barrier(&rcu_bh_state);
  13102. }
  13103. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  13104. +#endif
  13105. /**
  13106. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  13107. @@ -4227,12 +4352,13 @@
  13108. rcu_bootup_announce();
  13109. rcu_init_geometry();
  13110. +#ifndef CONFIG_PREEMPT_RT_FULL
  13111. rcu_init_one(&rcu_bh_state);
  13112. +#endif
  13113. rcu_init_one(&rcu_sched_state);
  13114. if (dump_tree)
  13115. rcu_dump_rcu_node_tree(&rcu_sched_state);
  13116. __rcu_init_preempt();
  13117. - open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  13118. /*
  13119. * We don't need protection against CPU-hotplug here because
  13120. diff -Nur linux-4.9.6.orig/kernel/rcu/tree.h linux-4.9.6/kernel/rcu/tree.h
  13121. --- linux-4.9.6.orig/kernel/rcu/tree.h 2017-01-26 08:25:24.000000000 +0100
  13122. +++ linux-4.9.6/kernel/rcu/tree.h 2017-01-28 13:59:10.043660493 +0100
  13123. @@ -588,18 +588,18 @@
  13124. */
  13125. extern struct rcu_state rcu_sched_state;
  13126. +#ifndef CONFIG_PREEMPT_RT_FULL
  13127. extern struct rcu_state rcu_bh_state;
  13128. +#endif
  13129. #ifdef CONFIG_PREEMPT_RCU
  13130. extern struct rcu_state rcu_preempt_state;
  13131. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  13132. -#ifdef CONFIG_RCU_BOOST
  13133. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  13134. DECLARE_PER_CPU(int, rcu_cpu_kthread_cpu);
  13135. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  13136. DECLARE_PER_CPU(char, rcu_cpu_has_work);
  13137. -#endif /* #ifdef CONFIG_RCU_BOOST */
  13138. #ifndef RCU_TREE_NONCORE
  13139. @@ -619,10 +619,9 @@
  13140. static void __init __rcu_init_preempt(void);
  13141. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  13142. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
  13143. -static void invoke_rcu_callbacks_kthread(void);
  13144. static bool rcu_is_callbacks_kthread(void);
  13145. +static void rcu_cpu_kthread_setup(unsigned int cpu);
  13146. #ifdef CONFIG_RCU_BOOST
  13147. -static void rcu_preempt_do_callbacks(void);
  13148. static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
  13149. struct rcu_node *rnp);
  13150. #endif /* #ifdef CONFIG_RCU_BOOST */
  13151. diff -Nur linux-4.9.6.orig/kernel/rcu/tree_plugin.h linux-4.9.6/kernel/rcu/tree_plugin.h
  13152. --- linux-4.9.6.orig/kernel/rcu/tree_plugin.h 2017-01-26 08:25:24.000000000 +0100
  13153. +++ linux-4.9.6/kernel/rcu/tree_plugin.h 2017-01-28 13:59:10.043660493 +0100
  13154. @@ -24,25 +24,10 @@
  13155. * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  13156. */
  13157. -#include <linux/delay.h>
  13158. -#include <linux/gfp.h>
  13159. -#include <linux/oom.h>
  13160. -#include <linux/smpboot.h>
  13161. -#include "../time/tick-internal.h"
  13162. -
  13163. #ifdef CONFIG_RCU_BOOST
  13164. #include "../locking/rtmutex_common.h"
  13165. -/*
  13166. - * Control variables for per-CPU and per-rcu_node kthreads. These
  13167. - * handle all flavors of RCU.
  13168. - */
  13169. -static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  13170. -DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  13171. -DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  13172. -DEFINE_PER_CPU(char, rcu_cpu_has_work);
  13173. -
  13174. #else /* #ifdef CONFIG_RCU_BOOST */
  13175. /*
  13176. @@ -55,6 +40,14 @@
  13177. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  13178. +/*
  13179. + * Control variables for per-CPU and per-rcu_node kthreads. These
  13180. + * handle all flavors of RCU.
  13181. + */
  13182. +DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  13183. +DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  13184. +DEFINE_PER_CPU(char, rcu_cpu_has_work);
  13185. +
  13186. #ifdef CONFIG_RCU_NOCB_CPU
  13187. static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
  13188. static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */
  13189. @@ -426,7 +419,7 @@
  13190. }
  13191. /* Hardware IRQ handlers cannot block, complain if they get here. */
  13192. - if (in_irq() || in_serving_softirq()) {
  13193. + if (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_OFFSET)) {
  13194. lockdep_rcu_suspicious(__FILE__, __LINE__,
  13195. "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n");
  13196. pr_alert("->rcu_read_unlock_special: %#x (b: %d, enq: %d nq: %d)\n",
  13197. @@ -632,15 +625,6 @@
  13198. t->rcu_read_unlock_special.b.need_qs = true;
  13199. }
  13200. -#ifdef CONFIG_RCU_BOOST
  13201. -
  13202. -static void rcu_preempt_do_callbacks(void)
  13203. -{
  13204. - rcu_do_batch(rcu_state_p, this_cpu_ptr(rcu_data_p));
  13205. -}
  13206. -
  13207. -#endif /* #ifdef CONFIG_RCU_BOOST */
  13208. -
  13209. /*
  13210. * Queue a preemptible-RCU callback for invocation after a grace period.
  13211. */
  13212. @@ -829,6 +813,19 @@
  13213. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  13214. +/*
  13215. + * If boosting, set rcuc kthreads to realtime priority.
  13216. + */
  13217. +static void rcu_cpu_kthread_setup(unsigned int cpu)
  13218. +{
  13219. +#ifdef CONFIG_RCU_BOOST
  13220. + struct sched_param sp;
  13221. +
  13222. + sp.sched_priority = kthread_prio;
  13223. + sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  13224. +#endif /* #ifdef CONFIG_RCU_BOOST */
  13225. +}
  13226. +
  13227. #ifdef CONFIG_RCU_BOOST
  13228. #include "../locking/rtmutex_common.h"
  13229. @@ -860,16 +857,6 @@
  13230. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  13231. -static void rcu_wake_cond(struct task_struct *t, int status)
  13232. -{
  13233. - /*
  13234. - * If the thread is yielding, only wake it when this
  13235. - * is invoked from idle
  13236. - */
  13237. - if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
  13238. - wake_up_process(t);
  13239. -}
  13240. -
  13241. /*
  13242. * Carry out RCU priority boosting on the task indicated by ->exp_tasks
  13243. * or ->boost_tasks, advancing the pointer to the next task in the
  13244. @@ -1013,23 +1000,6 @@
  13245. }
  13246. /*
  13247. - * Wake up the per-CPU kthread to invoke RCU callbacks.
  13248. - */
  13249. -static void invoke_rcu_callbacks_kthread(void)
  13250. -{
  13251. - unsigned long flags;
  13252. -
  13253. - local_irq_save(flags);
  13254. - __this_cpu_write(rcu_cpu_has_work, 1);
  13255. - if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
  13256. - current != __this_cpu_read(rcu_cpu_kthread_task)) {
  13257. - rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
  13258. - __this_cpu_read(rcu_cpu_kthread_status));
  13259. - }
  13260. - local_irq_restore(flags);
  13261. -}
  13262. -
  13263. -/*
  13264. * Is the current CPU running the RCU-callbacks kthread?
  13265. * Caller must have preemption disabled.
  13266. */
  13267. @@ -1083,67 +1053,6 @@
  13268. return 0;
  13269. }
  13270. -static void rcu_kthread_do_work(void)
  13271. -{
  13272. - rcu_do_batch(&rcu_sched_state, this_cpu_ptr(&rcu_sched_data));
  13273. - rcu_do_batch(&rcu_bh_state, this_cpu_ptr(&rcu_bh_data));
  13274. - rcu_preempt_do_callbacks();
  13275. -}
  13276. -
  13277. -static void rcu_cpu_kthread_setup(unsigned int cpu)
  13278. -{
  13279. - struct sched_param sp;
  13280. -
  13281. - sp.sched_priority = kthread_prio;
  13282. - sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  13283. -}
  13284. -
  13285. -static void rcu_cpu_kthread_park(unsigned int cpu)
  13286. -{
  13287. - per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  13288. -}
  13289. -
  13290. -static int rcu_cpu_kthread_should_run(unsigned int cpu)
  13291. -{
  13292. - return __this_cpu_read(rcu_cpu_has_work);
  13293. -}
  13294. -
  13295. -/*
  13296. - * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  13297. - * RCU softirq used in flavors and configurations of RCU that do not
  13298. - * support RCU priority boosting.
  13299. - */
  13300. -static void rcu_cpu_kthread(unsigned int cpu)
  13301. -{
  13302. - unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  13303. - char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  13304. - int spincnt;
  13305. -
  13306. - for (spincnt = 0; spincnt < 10; spincnt++) {
  13307. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  13308. - local_bh_disable();
  13309. - *statusp = RCU_KTHREAD_RUNNING;
  13310. - this_cpu_inc(rcu_cpu_kthread_loops);
  13311. - local_irq_disable();
  13312. - work = *workp;
  13313. - *workp = 0;
  13314. - local_irq_enable();
  13315. - if (work)
  13316. - rcu_kthread_do_work();
  13317. - local_bh_enable();
  13318. - if (*workp == 0) {
  13319. - trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  13320. - *statusp = RCU_KTHREAD_WAITING;
  13321. - return;
  13322. - }
  13323. - }
  13324. - *statusp = RCU_KTHREAD_YIELDING;
  13325. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  13326. - schedule_timeout_interruptible(2);
  13327. - trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  13328. - *statusp = RCU_KTHREAD_WAITING;
  13329. -}
  13330. -
  13331. /*
  13332. * Set the per-rcu_node kthread's affinity to cover all CPUs that are
  13333. * served by the rcu_node in question. The CPU hotplug lock is still
  13334. @@ -1174,26 +1083,12 @@
  13335. free_cpumask_var(cm);
  13336. }
  13337. -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  13338. - .store = &rcu_cpu_kthread_task,
  13339. - .thread_should_run = rcu_cpu_kthread_should_run,
  13340. - .thread_fn = rcu_cpu_kthread,
  13341. - .thread_comm = "rcuc/%u",
  13342. - .setup = rcu_cpu_kthread_setup,
  13343. - .park = rcu_cpu_kthread_park,
  13344. -};
  13345. -
  13346. /*
  13347. * Spawn boost kthreads -- called as soon as the scheduler is running.
  13348. */
  13349. static void __init rcu_spawn_boost_kthreads(void)
  13350. {
  13351. struct rcu_node *rnp;
  13352. - int cpu;
  13353. -
  13354. - for_each_possible_cpu(cpu)
  13355. - per_cpu(rcu_cpu_has_work, cpu) = 0;
  13356. - BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  13357. rcu_for_each_leaf_node(rcu_state_p, rnp)
  13358. (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
  13359. }
  13360. @@ -1216,11 +1111,6 @@
  13361. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  13362. }
  13363. -static void invoke_rcu_callbacks_kthread(void)
  13364. -{
  13365. - WARN_ON_ONCE(1);
  13366. -}
  13367. -
  13368. static bool rcu_is_callbacks_kthread(void)
  13369. {
  13370. return false;
  13371. @@ -1244,7 +1134,7 @@
  13372. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  13373. -#if !defined(CONFIG_RCU_FAST_NO_HZ)
  13374. +#if !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL)
  13375. /*
  13376. * Check to see if any future RCU-related work will need to be done
  13377. @@ -1261,7 +1151,9 @@
  13378. return IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)
  13379. ? 0 : rcu_cpu_has_callbacks(NULL);
  13380. }
  13381. +#endif /* !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL) */
  13382. +#if !defined(CONFIG_RCU_FAST_NO_HZ)
  13383. /*
  13384. * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
  13385. * after it.
  13386. @@ -1357,6 +1249,8 @@
  13387. return cbs_ready;
  13388. }
  13389. +#ifndef CONFIG_PREEMPT_RT_FULL
  13390. +
  13391. /*
  13392. * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
  13393. * to invoke. If the CPU has callbacks, try to advance them. Tell the
  13394. @@ -1402,6 +1296,7 @@
  13395. *nextevt = basemono + dj * TICK_NSEC;
  13396. return 0;
  13397. }
  13398. +#endif /* #ifndef CONFIG_PREEMPT_RT_FULL */
  13399. /*
  13400. * Prepare a CPU for idle from an RCU perspective. The first major task
  13401. diff -Nur linux-4.9.6.orig/kernel/rcu/update.c linux-4.9.6/kernel/rcu/update.c
  13402. --- linux-4.9.6.orig/kernel/rcu/update.c 2017-01-26 08:25:24.000000000 +0100
  13403. +++ linux-4.9.6/kernel/rcu/update.c 2017-01-28 13:59:10.043660493 +0100
  13404. @@ -62,7 +62,7 @@
  13405. #ifndef CONFIG_TINY_RCU
  13406. module_param(rcu_expedited, int, 0);
  13407. module_param(rcu_normal, int, 0);
  13408. -static int rcu_normal_after_boot;
  13409. +static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
  13410. module_param(rcu_normal_after_boot, int, 0);
  13411. #endif /* #ifndef CONFIG_TINY_RCU */
  13412. @@ -132,8 +132,7 @@
  13413. }
  13414. EXPORT_SYMBOL_GPL(rcu_gp_is_normal);
  13415. -static atomic_t rcu_expedited_nesting =
  13416. - ATOMIC_INIT(IS_ENABLED(CONFIG_RCU_EXPEDITE_BOOT) ? 1 : 0);
  13417. +static atomic_t rcu_expedited_nesting = ATOMIC_INIT(1);
  13418. /*
  13419. * Should normal grace-period primitives be expedited? Intended for
  13420. @@ -182,8 +181,7 @@
  13421. */
  13422. void rcu_end_inkernel_boot(void)
  13423. {
  13424. - if (IS_ENABLED(CONFIG_RCU_EXPEDITE_BOOT))
  13425. - rcu_unexpedite_gp();
  13426. + rcu_unexpedite_gp();
  13427. if (rcu_normal_after_boot)
  13428. WRITE_ONCE(rcu_normal, 1);
  13429. }
  13430. @@ -298,6 +296,7 @@
  13431. }
  13432. EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  13433. +#ifndef CONFIG_PREEMPT_RT_FULL
  13434. /**
  13435. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  13436. *
  13437. @@ -324,6 +323,7 @@
  13438. return in_softirq() || irqs_disabled();
  13439. }
  13440. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  13441. +#endif
  13442. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  13443. diff -Nur linux-4.9.6.orig/kernel/sched/completion.c linux-4.9.6/kernel/sched/completion.c
  13444. --- linux-4.9.6.orig/kernel/sched/completion.c 2017-01-26 08:25:24.000000000 +0100
  13445. +++ linux-4.9.6/kernel/sched/completion.c 2017-01-28 13:59:10.043660493 +0100
  13446. @@ -30,10 +30,10 @@
  13447. {
  13448. unsigned long flags;
  13449. - spin_lock_irqsave(&x->wait.lock, flags);
  13450. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  13451. x->done++;
  13452. - __wake_up_locked(&x->wait, TASK_NORMAL, 1);
  13453. - spin_unlock_irqrestore(&x->wait.lock, flags);
  13454. + swake_up_locked(&x->wait);
  13455. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  13456. }
  13457. EXPORT_SYMBOL(complete);
  13458. @@ -50,10 +50,10 @@
  13459. {
  13460. unsigned long flags;
  13461. - spin_lock_irqsave(&x->wait.lock, flags);
  13462. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  13463. x->done += UINT_MAX/2;
  13464. - __wake_up_locked(&x->wait, TASK_NORMAL, 0);
  13465. - spin_unlock_irqrestore(&x->wait.lock, flags);
  13466. + swake_up_all_locked(&x->wait);
  13467. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  13468. }
  13469. EXPORT_SYMBOL(complete_all);
  13470. @@ -62,20 +62,20 @@
  13471. long (*action)(long), long timeout, int state)
  13472. {
  13473. if (!x->done) {
  13474. - DECLARE_WAITQUEUE(wait, current);
  13475. + DECLARE_SWAITQUEUE(wait);
  13476. - __add_wait_queue_tail_exclusive(&x->wait, &wait);
  13477. + __prepare_to_swait(&x->wait, &wait);
  13478. do {
  13479. if (signal_pending_state(state, current)) {
  13480. timeout = -ERESTARTSYS;
  13481. break;
  13482. }
  13483. __set_current_state(state);
  13484. - spin_unlock_irq(&x->wait.lock);
  13485. + raw_spin_unlock_irq(&x->wait.lock);
  13486. timeout = action(timeout);
  13487. - spin_lock_irq(&x->wait.lock);
  13488. + raw_spin_lock_irq(&x->wait.lock);
  13489. } while (!x->done && timeout);
  13490. - __remove_wait_queue(&x->wait, &wait);
  13491. + __finish_swait(&x->wait, &wait);
  13492. if (!x->done)
  13493. return timeout;
  13494. }
  13495. @@ -89,9 +89,9 @@
  13496. {
  13497. might_sleep();
  13498. - spin_lock_irq(&x->wait.lock);
  13499. + raw_spin_lock_irq(&x->wait.lock);
  13500. timeout = do_wait_for_common(x, action, timeout, state);
  13501. - spin_unlock_irq(&x->wait.lock);
  13502. + raw_spin_unlock_irq(&x->wait.lock);
  13503. return timeout;
  13504. }
  13505. @@ -277,12 +277,12 @@
  13506. if (!READ_ONCE(x->done))
  13507. return 0;
  13508. - spin_lock_irqsave(&x->wait.lock, flags);
  13509. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  13510. if (!x->done)
  13511. ret = 0;
  13512. else
  13513. x->done--;
  13514. - spin_unlock_irqrestore(&x->wait.lock, flags);
  13515. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  13516. return ret;
  13517. }
  13518. EXPORT_SYMBOL(try_wait_for_completion);
  13519. @@ -311,7 +311,7 @@
  13520. * after it's acquired the lock.
  13521. */
  13522. smp_rmb();
  13523. - spin_unlock_wait(&x->wait.lock);
  13524. + raw_spin_unlock_wait(&x->wait.lock);
  13525. return true;
  13526. }
  13527. EXPORT_SYMBOL(completion_done);
  13528. diff -Nur linux-4.9.6.orig/kernel/sched/core.c linux-4.9.6/kernel/sched/core.c
  13529. --- linux-4.9.6.orig/kernel/sched/core.c 2017-01-26 08:25:24.000000000 +0100
  13530. +++ linux-4.9.6/kernel/sched/core.c 2017-01-28 13:59:10.043660493 +0100
  13531. @@ -129,7 +129,11 @@
  13532. * Number of tasks to iterate in a single balance run.
  13533. * Limited because this is done with IRQs disabled.
  13534. */
  13535. +#ifndef CONFIG_PREEMPT_RT_FULL
  13536. const_debug unsigned int sysctl_sched_nr_migrate = 32;
  13537. +#else
  13538. +const_debug unsigned int sysctl_sched_nr_migrate = 8;
  13539. +#endif
  13540. /*
  13541. * period over which we average the RT time consumption, measured
  13542. @@ -345,6 +349,7 @@
  13543. hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  13544. rq->hrtick_timer.function = hrtick;
  13545. + rq->hrtick_timer.irqsafe = 1;
  13546. }
  13547. #else /* CONFIG_SCHED_HRTICK */
  13548. static inline void hrtick_clear(struct rq *rq)
  13549. @@ -449,7 +454,7 @@
  13550. head->lastp = &node->next;
  13551. }
  13552. -void wake_up_q(struct wake_q_head *head)
  13553. +void __wake_up_q(struct wake_q_head *head, bool sleeper)
  13554. {
  13555. struct wake_q_node *node = head->first;
  13556. @@ -466,7 +471,10 @@
  13557. * wake_up_process() implies a wmb() to pair with the queueing
  13558. * in wake_q_add() so as not to miss wakeups.
  13559. */
  13560. - wake_up_process(task);
  13561. + if (sleeper)
  13562. + wake_up_lock_sleeper(task);
  13563. + else
  13564. + wake_up_process(task);
  13565. put_task_struct(task);
  13566. }
  13567. }
  13568. @@ -502,6 +510,38 @@
  13569. trace_sched_wake_idle_without_ipi(cpu);
  13570. }
  13571. +#ifdef CONFIG_PREEMPT_LAZY
  13572. +void resched_curr_lazy(struct rq *rq)
  13573. +{
  13574. + struct task_struct *curr = rq->curr;
  13575. + int cpu;
  13576. +
  13577. + if (!sched_feat(PREEMPT_LAZY)) {
  13578. + resched_curr(rq);
  13579. + return;
  13580. + }
  13581. +
  13582. + lockdep_assert_held(&rq->lock);
  13583. +
  13584. + if (test_tsk_need_resched(curr))
  13585. + return;
  13586. +
  13587. + if (test_tsk_need_resched_lazy(curr))
  13588. + return;
  13589. +
  13590. + set_tsk_need_resched_lazy(curr);
  13591. +
  13592. + cpu = cpu_of(rq);
  13593. + if (cpu == smp_processor_id())
  13594. + return;
  13595. +
  13596. + /* NEED_RESCHED_LAZY must be visible before we test polling */
  13597. + smp_mb();
  13598. + if (!tsk_is_polling(curr))
  13599. + smp_send_reschedule(cpu);
  13600. +}
  13601. +#endif
  13602. +
  13603. void resched_cpu(int cpu)
  13604. {
  13605. struct rq *rq = cpu_rq(cpu);
  13606. @@ -525,11 +565,14 @@
  13607. */
  13608. int get_nohz_timer_target(void)
  13609. {
  13610. - int i, cpu = smp_processor_id();
  13611. + int i, cpu;
  13612. struct sched_domain *sd;
  13613. + preempt_disable_rt();
  13614. + cpu = smp_processor_id();
  13615. +
  13616. if (!idle_cpu(cpu) && is_housekeeping_cpu(cpu))
  13617. - return cpu;
  13618. + goto preempt_en_rt;
  13619. rcu_read_lock();
  13620. for_each_domain(cpu, sd) {
  13621. @@ -548,6 +591,8 @@
  13622. cpu = housekeeping_any_cpu();
  13623. unlock:
  13624. rcu_read_unlock();
  13625. +preempt_en_rt:
  13626. + preempt_enable_rt();
  13627. return cpu;
  13628. }
  13629. /*
  13630. @@ -1100,6 +1145,11 @@
  13631. lockdep_assert_held(&p->pi_lock);
  13632. + if (__migrate_disabled(p)) {
  13633. + cpumask_copy(&p->cpus_allowed, new_mask);
  13634. + return;
  13635. + }
  13636. +
  13637. queued = task_on_rq_queued(p);
  13638. running = task_current(rq, p);
  13639. @@ -1122,6 +1172,84 @@
  13640. set_curr_task(rq, p);
  13641. }
  13642. +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
  13643. +static DEFINE_MUTEX(sched_down_mutex);
  13644. +static cpumask_t sched_down_cpumask;
  13645. +
  13646. +void tell_sched_cpu_down_begin(int cpu)
  13647. +{
  13648. + mutex_lock(&sched_down_mutex);
  13649. + cpumask_set_cpu(cpu, &sched_down_cpumask);
  13650. + mutex_unlock(&sched_down_mutex);
  13651. +}
  13652. +
  13653. +void tell_sched_cpu_down_done(int cpu)
  13654. +{
  13655. + mutex_lock(&sched_down_mutex);
  13656. + cpumask_clear_cpu(cpu, &sched_down_cpumask);
  13657. + mutex_unlock(&sched_down_mutex);
  13658. +}
  13659. +
  13660. +/**
  13661. + * migrate_me - try to move the current task off this cpu
  13662. + *
  13663. + * Used by the pin_current_cpu() code to try to get tasks
  13664. + * to move off the current CPU as it is going down.
  13665. + * It will only move the task if the task isn't pinned to
  13666. + * the CPU (with migrate_disable, affinity or NO_SETAFFINITY)
  13667. + * and the task has to be in a RUNNING state. Otherwise the
  13668. + * movement of the task will wake it up (change its state
  13669. + * to running) when the task did not expect it.
  13670. + *
  13671. + * Returns 1 if it succeeded in moving the current task
  13672. + * 0 otherwise.
  13673. + */
  13674. +int migrate_me(void)
  13675. +{
  13676. + struct task_struct *p = current;
  13677. + struct migration_arg arg;
  13678. + struct cpumask *cpumask;
  13679. + struct cpumask *mask;
  13680. + unsigned int dest_cpu;
  13681. + struct rq_flags rf;
  13682. + struct rq *rq;
  13683. +
  13684. + /*
  13685. + * We can not migrate tasks bounded to a CPU or tasks not
  13686. + * running. The movement of the task will wake it up.
  13687. + */
  13688. + if (p->flags & PF_NO_SETAFFINITY || p->state)
  13689. + return 0;
  13690. +
  13691. + mutex_lock(&sched_down_mutex);
  13692. + rq = task_rq_lock(p, &rf);
  13693. +
  13694. + cpumask = this_cpu_ptr(&sched_cpumasks);
  13695. + mask = &p->cpus_allowed;
  13696. +
  13697. + cpumask_andnot(cpumask, mask, &sched_down_cpumask);
  13698. +
  13699. + if (!cpumask_weight(cpumask)) {
  13700. + /* It's only on this CPU? */
  13701. + task_rq_unlock(rq, p, &rf);
  13702. + mutex_unlock(&sched_down_mutex);
  13703. + return 0;
  13704. + }
  13705. +
  13706. + dest_cpu = cpumask_any_and(cpu_active_mask, cpumask);
  13707. +
  13708. + arg.task = p;
  13709. + arg.dest_cpu = dest_cpu;
  13710. +
  13711. + task_rq_unlock(rq, p, &rf);
  13712. +
  13713. + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
  13714. + tlb_migrate_finish(p->mm);
  13715. + mutex_unlock(&sched_down_mutex);
  13716. +
  13717. + return 1;
  13718. +}
  13719. +
  13720. /*
  13721. * Change a given task's CPU affinity. Migrate the thread to a
  13722. * proper CPU and schedule it away if the CPU it's executing on
  13723. @@ -1179,7 +1307,7 @@
  13724. }
  13725. /* Can the task run on the task's current CPU? If so, we're done */
  13726. - if (cpumask_test_cpu(task_cpu(p), new_mask))
  13727. + if (cpumask_test_cpu(task_cpu(p), new_mask) || __migrate_disabled(p))
  13728. goto out;
  13729. dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
  13730. @@ -1366,6 +1494,18 @@
  13731. return ret;
  13732. }
  13733. +static bool check_task_state(struct task_struct *p, long match_state)
  13734. +{
  13735. + bool match = false;
  13736. +
  13737. + raw_spin_lock_irq(&p->pi_lock);
  13738. + if (p->state == match_state || p->saved_state == match_state)
  13739. + match = true;
  13740. + raw_spin_unlock_irq(&p->pi_lock);
  13741. +
  13742. + return match;
  13743. +}
  13744. +
  13745. /*
  13746. * wait_task_inactive - wait for a thread to unschedule.
  13747. *
  13748. @@ -1410,7 +1550,7 @@
  13749. * is actually now running somewhere else!
  13750. */
  13751. while (task_running(rq, p)) {
  13752. - if (match_state && unlikely(p->state != match_state))
  13753. + if (match_state && !check_task_state(p, match_state))
  13754. return 0;
  13755. cpu_relax();
  13756. }
  13757. @@ -1425,7 +1565,8 @@
  13758. running = task_running(rq, p);
  13759. queued = task_on_rq_queued(p);
  13760. ncsw = 0;
  13761. - if (!match_state || p->state == match_state)
  13762. + if (!match_state || p->state == match_state ||
  13763. + p->saved_state == match_state)
  13764. ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
  13765. task_rq_unlock(rq, p, &rf);
  13766. @@ -1680,10 +1821,6 @@
  13767. {
  13768. activate_task(rq, p, en_flags);
  13769. p->on_rq = TASK_ON_RQ_QUEUED;
  13770. -
  13771. - /* if a worker is waking up, notify workqueue */
  13772. - if (p->flags & PF_WQ_WORKER)
  13773. - wq_worker_waking_up(p, cpu_of(rq));
  13774. }
  13775. /*
  13776. @@ -2018,8 +2155,27 @@
  13777. */
  13778. smp_mb__before_spinlock();
  13779. raw_spin_lock_irqsave(&p->pi_lock, flags);
  13780. - if (!(p->state & state))
  13781. + if (!(p->state & state)) {
  13782. + /*
  13783. + * The task might be running due to a spinlock sleeper
  13784. + * wakeup. Check the saved state and set it to running
  13785. + * if the wakeup condition is true.
  13786. + */
  13787. + if (!(wake_flags & WF_LOCK_SLEEPER)) {
  13788. + if (p->saved_state & state) {
  13789. + p->saved_state = TASK_RUNNING;
  13790. + success = 1;
  13791. + }
  13792. + }
  13793. goto out;
  13794. + }
  13795. +
  13796. + /*
  13797. + * If this is a regular wakeup, then we can unconditionally
  13798. + * clear the saved state of a "lock sleeper".
  13799. + */
  13800. + if (!(wake_flags & WF_LOCK_SLEEPER))
  13801. + p->saved_state = TASK_RUNNING;
  13802. trace_sched_waking(p);
  13803. @@ -2102,53 +2258,6 @@
  13804. }
  13805. /**
  13806. - * try_to_wake_up_local - try to wake up a local task with rq lock held
  13807. - * @p: the thread to be awakened
  13808. - * @cookie: context's cookie for pinning
  13809. - *
  13810. - * Put @p on the run-queue if it's not already there. The caller must
  13811. - * ensure that this_rq() is locked, @p is bound to this_rq() and not
  13812. - * the current task.
  13813. - */
  13814. -static void try_to_wake_up_local(struct task_struct *p, struct pin_cookie cookie)
  13815. -{
  13816. - struct rq *rq = task_rq(p);
  13817. -
  13818. - if (WARN_ON_ONCE(rq != this_rq()) ||
  13819. - WARN_ON_ONCE(p == current))
  13820. - return;
  13821. -
  13822. - lockdep_assert_held(&rq->lock);
  13823. -
  13824. - if (!raw_spin_trylock(&p->pi_lock)) {
  13825. - /*
  13826. - * This is OK, because current is on_cpu, which avoids it being
  13827. - * picked for load-balance and preemption/IRQs are still
  13828. - * disabled avoiding further scheduler activity on it and we've
  13829. - * not yet picked a replacement task.
  13830. - */
  13831. - lockdep_unpin_lock(&rq->lock, cookie);
  13832. - raw_spin_unlock(&rq->lock);
  13833. - raw_spin_lock(&p->pi_lock);
  13834. - raw_spin_lock(&rq->lock);
  13835. - lockdep_repin_lock(&rq->lock, cookie);
  13836. - }
  13837. -
  13838. - if (!(p->state & TASK_NORMAL))
  13839. - goto out;
  13840. -
  13841. - trace_sched_waking(p);
  13842. -
  13843. - if (!task_on_rq_queued(p))
  13844. - ttwu_activate(rq, p, ENQUEUE_WAKEUP);
  13845. -
  13846. - ttwu_do_wakeup(rq, p, 0, cookie);
  13847. - ttwu_stat(p, smp_processor_id(), 0);
  13848. -out:
  13849. - raw_spin_unlock(&p->pi_lock);
  13850. -}
  13851. -
  13852. -/**
  13853. * wake_up_process - Wake up a specific process
  13854. * @p: The process to be woken up.
  13855. *
  13856. @@ -2166,6 +2275,18 @@
  13857. }
  13858. EXPORT_SYMBOL(wake_up_process);
  13859. +/**
  13860. + * wake_up_lock_sleeper - Wake up a specific process blocked on a "sleeping lock"
  13861. + * @p: The process to be woken up.
  13862. + *
  13863. + * Same as wake_up_process() above, but wake_flags=WF_LOCK_SLEEPER to indicate
  13864. + * the nature of the wakeup.
  13865. + */
  13866. +int wake_up_lock_sleeper(struct task_struct *p)
  13867. +{
  13868. + return try_to_wake_up(p, TASK_ALL, WF_LOCK_SLEEPER);
  13869. +}
  13870. +
  13871. int wake_up_state(struct task_struct *p, unsigned int state)
  13872. {
  13873. return try_to_wake_up(p, state, 0);
  13874. @@ -2442,6 +2563,9 @@
  13875. p->on_cpu = 0;
  13876. #endif
  13877. init_task_preempt_count(p);
  13878. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  13879. + task_thread_info(p)->preempt_lazy_count = 0;
  13880. +#endif
  13881. #ifdef CONFIG_SMP
  13882. plist_node_init(&p->pushable_tasks, MAX_PRIO);
  13883. RB_CLEAR_NODE(&p->pushable_dl_tasks);
  13884. @@ -2770,21 +2894,16 @@
  13885. finish_arch_post_lock_switch();
  13886. fire_sched_in_preempt_notifiers(current);
  13887. + /*
  13888. + * We use mmdrop_delayed() here so we don't have to do the
  13889. + * full __mmdrop() when we are the last user.
  13890. + */
  13891. if (mm)
  13892. - mmdrop(mm);
  13893. + mmdrop_delayed(mm);
  13894. if (unlikely(prev_state == TASK_DEAD)) {
  13895. if (prev->sched_class->task_dead)
  13896. prev->sched_class->task_dead(prev);
  13897. - /*
  13898. - * Remove function-return probe instances associated with this
  13899. - * task and put them back on the free list.
  13900. - */
  13901. - kprobe_flush_task(prev);
  13902. -
  13903. - /* Task is done with its stack. */
  13904. - put_task_stack(prev);
  13905. -
  13906. put_task_struct(prev);
  13907. }
  13908. @@ -3252,6 +3371,77 @@
  13909. schedstat_inc(this_rq()->sched_count);
  13910. }
  13911. +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
  13912. +
  13913. +void migrate_disable(void)
  13914. +{
  13915. + struct task_struct *p = current;
  13916. +
  13917. + if (in_atomic() || irqs_disabled()) {
  13918. +#ifdef CONFIG_SCHED_DEBUG
  13919. + p->migrate_disable_atomic++;
  13920. +#endif
  13921. + return;
  13922. + }
  13923. +
  13924. +#ifdef CONFIG_SCHED_DEBUG
  13925. + if (unlikely(p->migrate_disable_atomic)) {
  13926. + tracing_off();
  13927. + WARN_ON_ONCE(1);
  13928. + }
  13929. +#endif
  13930. +
  13931. + if (p->migrate_disable) {
  13932. + p->migrate_disable++;
  13933. + return;
  13934. + }
  13935. +
  13936. + preempt_disable();
  13937. + preempt_lazy_disable();
  13938. + pin_current_cpu();
  13939. + p->migrate_disable = 1;
  13940. + preempt_enable();
  13941. +}
  13942. +EXPORT_SYMBOL(migrate_disable);
  13943. +
  13944. +void migrate_enable(void)
  13945. +{
  13946. + struct task_struct *p = current;
  13947. +
  13948. + if (in_atomic() || irqs_disabled()) {
  13949. +#ifdef CONFIG_SCHED_DEBUG
  13950. + p->migrate_disable_atomic--;
  13951. +#endif
  13952. + return;
  13953. + }
  13954. +
  13955. +#ifdef CONFIG_SCHED_DEBUG
  13956. + if (unlikely(p->migrate_disable_atomic)) {
  13957. + tracing_off();
  13958. + WARN_ON_ONCE(1);
  13959. + }
  13960. +#endif
  13961. + WARN_ON_ONCE(p->migrate_disable <= 0);
  13962. +
  13963. + if (p->migrate_disable > 1) {
  13964. + p->migrate_disable--;
  13965. + return;
  13966. + }
  13967. +
  13968. + preempt_disable();
  13969. + /*
  13970. + * Clearing migrate_disable causes tsk_cpus_allowed to
  13971. + * show the tasks original cpu affinity.
  13972. + */
  13973. + p->migrate_disable = 0;
  13974. +
  13975. + unpin_current_cpu();
  13976. + preempt_enable();
  13977. + preempt_lazy_enable();
  13978. +}
  13979. +EXPORT_SYMBOL(migrate_enable);
  13980. +#endif
  13981. +
  13982. /*
  13983. * Pick up the highest-prio task:
  13984. */
  13985. @@ -3368,19 +3558,6 @@
  13986. } else {
  13987. deactivate_task(rq, prev, DEQUEUE_SLEEP);
  13988. prev->on_rq = 0;
  13989. -
  13990. - /*
  13991. - * If a worker went to sleep, notify and ask workqueue
  13992. - * whether it wants to wake up a task to maintain
  13993. - * concurrency.
  13994. - */
  13995. - if (prev->flags & PF_WQ_WORKER) {
  13996. - struct task_struct *to_wakeup;
  13997. -
  13998. - to_wakeup = wq_worker_sleeping(prev);
  13999. - if (to_wakeup)
  14000. - try_to_wake_up_local(to_wakeup, cookie);
  14001. - }
  14002. }
  14003. switch_count = &prev->nvcsw;
  14004. }
  14005. @@ -3390,6 +3567,7 @@
  14006. next = pick_next_task(rq, prev, cookie);
  14007. clear_tsk_need_resched(prev);
  14008. + clear_tsk_need_resched_lazy(prev);
  14009. clear_preempt_need_resched();
  14010. rq->clock_skip_update = 0;
  14011. @@ -3437,9 +3615,20 @@
  14012. static inline void sched_submit_work(struct task_struct *tsk)
  14013. {
  14014. - if (!tsk->state || tsk_is_pi_blocked(tsk))
  14015. + if (!tsk->state)
  14016. return;
  14017. /*
  14018. + * If a worker went to sleep, notify and ask workqueue whether
  14019. + * it wants to wake up a task to maintain concurrency.
  14020. + */
  14021. + if (tsk->flags & PF_WQ_WORKER)
  14022. + wq_worker_sleeping(tsk);
  14023. +
  14024. +
  14025. + if (tsk_is_pi_blocked(tsk))
  14026. + return;
  14027. +
  14028. + /*
  14029. * If we are going to sleep and we have plugged IO queued,
  14030. * make sure to submit it to avoid deadlocks.
  14031. */
  14032. @@ -3447,6 +3636,12 @@
  14033. blk_schedule_flush_plug(tsk);
  14034. }
  14035. +static void sched_update_worker(struct task_struct *tsk)
  14036. +{
  14037. + if (tsk->flags & PF_WQ_WORKER)
  14038. + wq_worker_running(tsk);
  14039. +}
  14040. +
  14041. asmlinkage __visible void __sched schedule(void)
  14042. {
  14043. struct task_struct *tsk = current;
  14044. @@ -3457,6 +3652,7 @@
  14045. __schedule(false);
  14046. sched_preempt_enable_no_resched();
  14047. } while (need_resched());
  14048. + sched_update_worker(tsk);
  14049. }
  14050. EXPORT_SYMBOL(schedule);
  14051. @@ -3520,6 +3716,30 @@
  14052. } while (need_resched());
  14053. }
  14054. +#ifdef CONFIG_PREEMPT_LAZY
  14055. +/*
  14056. + * If TIF_NEED_RESCHED is then we allow to be scheduled away since this is
  14057. + * set by a RT task. Oterwise we try to avoid beeing scheduled out as long as
  14058. + * preempt_lazy_count counter >0.
  14059. + */
  14060. +static __always_inline int preemptible_lazy(void)
  14061. +{
  14062. + if (test_thread_flag(TIF_NEED_RESCHED))
  14063. + return 1;
  14064. + if (current_thread_info()->preempt_lazy_count)
  14065. + return 0;
  14066. + return 1;
  14067. +}
  14068. +
  14069. +#else
  14070. +
  14071. +static inline int preemptible_lazy(void)
  14072. +{
  14073. + return 1;
  14074. +}
  14075. +
  14076. +#endif
  14077. +
  14078. #ifdef CONFIG_PREEMPT
  14079. /*
  14080. * this is the entry point to schedule() from in-kernel preemption
  14081. @@ -3534,7 +3754,8 @@
  14082. */
  14083. if (likely(!preemptible()))
  14084. return;
  14085. -
  14086. + if (!preemptible_lazy())
  14087. + return;
  14088. preempt_schedule_common();
  14089. }
  14090. NOKPROBE_SYMBOL(preempt_schedule);
  14091. @@ -3561,6 +3782,9 @@
  14092. if (likely(!preemptible()))
  14093. return;
  14094. + if (!preemptible_lazy())
  14095. + return;
  14096. +
  14097. do {
  14098. /*
  14099. * Because the function tracer can trace preempt_count_sub()
  14100. @@ -3583,7 +3807,16 @@
  14101. * an infinite recursion.
  14102. */
  14103. prev_ctx = exception_enter();
  14104. + /*
  14105. + * The add/subtract must not be traced by the function
  14106. + * tracer. But we still want to account for the
  14107. + * preempt off latency tracer. Since the _notrace versions
  14108. + * of add/subtract skip the accounting for latency tracer
  14109. + * we must force it manually.
  14110. + */
  14111. + start_critical_timings();
  14112. __schedule(true);
  14113. + stop_critical_timings();
  14114. exception_exit(prev_ctx);
  14115. preempt_latency_stop(1);
  14116. @@ -4939,6 +5172,7 @@
  14117. }
  14118. EXPORT_SYMBOL(__cond_resched_lock);
  14119. +#ifndef CONFIG_PREEMPT_RT_FULL
  14120. int __sched __cond_resched_softirq(void)
  14121. {
  14122. BUG_ON(!in_softirq());
  14123. @@ -4952,6 +5186,7 @@
  14124. return 0;
  14125. }
  14126. EXPORT_SYMBOL(__cond_resched_softirq);
  14127. +#endif
  14128. /**
  14129. * yield - yield the current processor to other threads.
  14130. @@ -5315,7 +5550,9 @@
  14131. /* Set the preempt count _outside_ the spinlocks! */
  14132. init_idle_preempt_count(idle, cpu);
  14133. -
  14134. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  14135. + task_thread_info(idle)->preempt_lazy_count = 0;
  14136. +#endif
  14137. /*
  14138. * The idle tasks have their own, simple scheduling class:
  14139. */
  14140. @@ -5458,6 +5695,8 @@
  14141. #endif /* CONFIG_NUMA_BALANCING */
  14142. #ifdef CONFIG_HOTPLUG_CPU
  14143. +static DEFINE_PER_CPU(struct mm_struct *, idle_last_mm);
  14144. +
  14145. /*
  14146. * Ensures that the idle task is using init_mm right before its cpu goes
  14147. * offline.
  14148. @@ -5472,7 +5711,12 @@
  14149. switch_mm_irqs_off(mm, &init_mm, current);
  14150. finish_arch_post_lock_switch();
  14151. }
  14152. - mmdrop(mm);
  14153. + /*
  14154. + * Defer the cleanup to an alive cpu. On RT we can neither
  14155. + * call mmdrop() nor mmdrop_delayed() from here.
  14156. + */
  14157. + per_cpu(idle_last_mm, smp_processor_id()) = mm;
  14158. +
  14159. }
  14160. /*
  14161. @@ -7418,6 +7662,10 @@
  14162. update_max_interval();
  14163. nohz_balance_exit_idle(cpu);
  14164. hrtick_clear(rq);
  14165. + if (per_cpu(idle_last_mm, cpu)) {
  14166. + mmdrop_delayed(per_cpu(idle_last_mm, cpu));
  14167. + per_cpu(idle_last_mm, cpu) = NULL;
  14168. + }
  14169. return 0;
  14170. }
  14171. #endif
  14172. @@ -7698,7 +7946,7 @@
  14173. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  14174. static inline int preempt_count_equals(int preempt_offset)
  14175. {
  14176. - int nested = preempt_count() + rcu_preempt_depth();
  14177. + int nested = preempt_count() + sched_rcu_preempt_depth();
  14178. return (nested == preempt_offset);
  14179. }
  14180. diff -Nur linux-4.9.6.orig/kernel/sched/deadline.c linux-4.9.6/kernel/sched/deadline.c
  14181. --- linux-4.9.6.orig/kernel/sched/deadline.c 2017-01-26 08:25:24.000000000 +0100
  14182. +++ linux-4.9.6/kernel/sched/deadline.c 2017-01-28 13:59:10.043660493 +0100
  14183. @@ -687,6 +687,7 @@
  14184. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  14185. timer->function = dl_task_timer;
  14186. + timer->irqsafe = 1;
  14187. }
  14188. static
  14189. diff -Nur linux-4.9.6.orig/kernel/sched/debug.c linux-4.9.6/kernel/sched/debug.c
  14190. --- linux-4.9.6.orig/kernel/sched/debug.c 2017-01-26 08:25:24.000000000 +0100
  14191. +++ linux-4.9.6/kernel/sched/debug.c 2017-01-28 13:59:10.043660493 +0100
  14192. @@ -558,6 +558,9 @@
  14193. P(rt_throttled);
  14194. PN(rt_time);
  14195. PN(rt_runtime);
  14196. +#ifdef CONFIG_SMP
  14197. + P(rt_nr_migratory);
  14198. +#endif
  14199. #undef PN
  14200. #undef P
  14201. @@ -953,6 +956,10 @@
  14202. #endif
  14203. P(policy);
  14204. P(prio);
  14205. +#ifdef CONFIG_PREEMPT_RT_FULL
  14206. + P(migrate_disable);
  14207. +#endif
  14208. + P(nr_cpus_allowed);
  14209. #undef PN_SCHEDSTAT
  14210. #undef PN
  14211. #undef __PN
  14212. diff -Nur linux-4.9.6.orig/kernel/sched/fair.c linux-4.9.6/kernel/sched/fair.c
  14213. --- linux-4.9.6.orig/kernel/sched/fair.c 2017-01-26 08:25:24.000000000 +0100
  14214. +++ linux-4.9.6/kernel/sched/fair.c 2017-01-28 13:59:10.047660646 +0100
  14215. @@ -3518,7 +3518,7 @@
  14216. ideal_runtime = sched_slice(cfs_rq, curr);
  14217. delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
  14218. if (delta_exec > ideal_runtime) {
  14219. - resched_curr(rq_of(cfs_rq));
  14220. + resched_curr_lazy(rq_of(cfs_rq));
  14221. /*
  14222. * The current task ran long enough, ensure it doesn't get
  14223. * re-elected due to buddy favours.
  14224. @@ -3542,7 +3542,7 @@
  14225. return;
  14226. if (delta > ideal_runtime)
  14227. - resched_curr(rq_of(cfs_rq));
  14228. + resched_curr_lazy(rq_of(cfs_rq));
  14229. }
  14230. static void
  14231. @@ -3684,7 +3684,7 @@
  14232. * validating it and just reschedule.
  14233. */
  14234. if (queued) {
  14235. - resched_curr(rq_of(cfs_rq));
  14236. + resched_curr_lazy(rq_of(cfs_rq));
  14237. return;
  14238. }
  14239. /*
  14240. @@ -3866,7 +3866,7 @@
  14241. * hierarchy can be throttled
  14242. */
  14243. if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr))
  14244. - resched_curr(rq_of(cfs_rq));
  14245. + resched_curr_lazy(rq_of(cfs_rq));
  14246. }
  14247. static __always_inline
  14248. @@ -4494,7 +4494,7 @@
  14249. if (delta < 0) {
  14250. if (rq->curr == p)
  14251. - resched_curr(rq);
  14252. + resched_curr_lazy(rq);
  14253. return;
  14254. }
  14255. hrtick_start(rq, delta);
  14256. @@ -5905,7 +5905,7 @@
  14257. return;
  14258. preempt:
  14259. - resched_curr(rq);
  14260. + resched_curr_lazy(rq);
  14261. /*
  14262. * Only set the backward buddy when the current task is still
  14263. * on the rq. This can happen when a wakeup gets interleaved
  14264. @@ -8631,7 +8631,7 @@
  14265. * 'current' within the tree based on its new key value.
  14266. */
  14267. swap(curr->vruntime, se->vruntime);
  14268. - resched_curr(rq);
  14269. + resched_curr_lazy(rq);
  14270. }
  14271. se->vruntime -= cfs_rq->min_vruntime;
  14272. @@ -8655,7 +8655,7 @@
  14273. */
  14274. if (rq->curr == p) {
  14275. if (p->prio > oldprio)
  14276. - resched_curr(rq);
  14277. + resched_curr_lazy(rq);
  14278. } else
  14279. check_preempt_curr(rq, p, 0);
  14280. }
  14281. diff -Nur linux-4.9.6.orig/kernel/sched/features.h linux-4.9.6/kernel/sched/features.h
  14282. --- linux-4.9.6.orig/kernel/sched/features.h 2017-01-26 08:25:24.000000000 +0100
  14283. +++ linux-4.9.6/kernel/sched/features.h 2017-01-28 13:59:10.047660646 +0100
  14284. @@ -45,11 +45,19 @@
  14285. */
  14286. SCHED_FEAT(NONTASK_CAPACITY, true)
  14287. +#ifdef CONFIG_PREEMPT_RT_FULL
  14288. +SCHED_FEAT(TTWU_QUEUE, false)
  14289. +# ifdef CONFIG_PREEMPT_LAZY
  14290. +SCHED_FEAT(PREEMPT_LAZY, true)
  14291. +# endif
  14292. +#else
  14293. +
  14294. /*
  14295. * Queue remote wakeups on the target CPU and process them
  14296. * using the scheduler IPI. Reduces rq->lock contention/bounces.
  14297. */
  14298. SCHED_FEAT(TTWU_QUEUE, true)
  14299. +#endif
  14300. #ifdef HAVE_RT_PUSH_IPI
  14301. /*
  14302. diff -Nur linux-4.9.6.orig/kernel/sched/Makefile linux-4.9.6/kernel/sched/Makefile
  14303. --- linux-4.9.6.orig/kernel/sched/Makefile 2017-01-26 08:25:24.000000000 +0100
  14304. +++ linux-4.9.6/kernel/sched/Makefile 2017-01-28 13:59:10.043660493 +0100
  14305. @@ -17,7 +17,7 @@
  14306. obj-y += core.o loadavg.o clock.o cputime.o
  14307. obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
  14308. -obj-y += wait.o swait.o completion.o idle.o
  14309. +obj-y += wait.o swait.o swork.o completion.o idle.o
  14310. obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o
  14311. obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
  14312. obj-$(CONFIG_SCHEDSTATS) += stats.o
  14313. diff -Nur linux-4.9.6.orig/kernel/sched/rt.c linux-4.9.6/kernel/sched/rt.c
  14314. --- linux-4.9.6.orig/kernel/sched/rt.c 2017-01-26 08:25:24.000000000 +0100
  14315. +++ linux-4.9.6/kernel/sched/rt.c 2017-01-28 13:59:10.047660646 +0100
  14316. @@ -47,6 +47,7 @@
  14317. hrtimer_init(&rt_b->rt_period_timer,
  14318. CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  14319. + rt_b->rt_period_timer.irqsafe = 1;
  14320. rt_b->rt_period_timer.function = sched_rt_period_timer;
  14321. }
  14322. @@ -101,6 +102,7 @@
  14323. rt_rq->push_cpu = nr_cpu_ids;
  14324. raw_spin_lock_init(&rt_rq->push_lock);
  14325. init_irq_work(&rt_rq->push_work, push_irq_work_func);
  14326. + rt_rq->push_work.flags |= IRQ_WORK_HARD_IRQ;
  14327. #endif
  14328. #endif /* CONFIG_SMP */
  14329. /* We start is dequeued state, because no RT tasks are queued */
  14330. diff -Nur linux-4.9.6.orig/kernel/sched/sched.h linux-4.9.6/kernel/sched/sched.h
  14331. --- linux-4.9.6.orig/kernel/sched/sched.h 2017-01-26 08:25:24.000000000 +0100
  14332. +++ linux-4.9.6/kernel/sched/sched.h 2017-01-28 13:59:10.047660646 +0100
  14333. @@ -1163,6 +1163,7 @@
  14334. #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
  14335. #define WF_FORK 0x02 /* child wakeup after fork */
  14336. #define WF_MIGRATED 0x4 /* internal use, task got migrated */
  14337. +#define WF_LOCK_SLEEPER 0x08 /* wakeup spinlock "sleeper" */
  14338. /*
  14339. * To aid in avoiding the subversion of "niceness" due to uneven distribution
  14340. @@ -1346,6 +1347,15 @@
  14341. extern void resched_curr(struct rq *rq);
  14342. extern void resched_cpu(int cpu);
  14343. +#ifdef CONFIG_PREEMPT_LAZY
  14344. +extern void resched_curr_lazy(struct rq *rq);
  14345. +#else
  14346. +static inline void resched_curr_lazy(struct rq *rq)
  14347. +{
  14348. + resched_curr(rq);
  14349. +}
  14350. +#endif
  14351. +
  14352. extern struct rt_bandwidth def_rt_bandwidth;
  14353. extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
  14354. diff -Nur linux-4.9.6.orig/kernel/sched/swait.c linux-4.9.6/kernel/sched/swait.c
  14355. --- linux-4.9.6.orig/kernel/sched/swait.c 2017-01-26 08:25:24.000000000 +0100
  14356. +++ linux-4.9.6/kernel/sched/swait.c 2017-01-28 13:59:10.047660646 +0100
  14357. @@ -1,5 +1,6 @@
  14358. #include <linux/sched.h>
  14359. #include <linux/swait.h>
  14360. +#include <linux/suspend.h>
  14361. void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
  14362. struct lock_class_key *key)
  14363. @@ -29,6 +30,25 @@
  14364. }
  14365. EXPORT_SYMBOL(swake_up_locked);
  14366. +void swake_up_all_locked(struct swait_queue_head *q)
  14367. +{
  14368. + struct swait_queue *curr;
  14369. + int wakes = 0;
  14370. +
  14371. + while (!list_empty(&q->task_list)) {
  14372. +
  14373. + curr = list_first_entry(&q->task_list, typeof(*curr),
  14374. + task_list);
  14375. + wake_up_process(curr->task);
  14376. + list_del_init(&curr->task_list);
  14377. + wakes++;
  14378. + }
  14379. + if (pm_in_action)
  14380. + return;
  14381. + WARN(wakes > 2, "complete_all() with %d waiters\n", wakes);
  14382. +}
  14383. +EXPORT_SYMBOL(swake_up_all_locked);
  14384. +
  14385. void swake_up(struct swait_queue_head *q)
  14386. {
  14387. unsigned long flags;
  14388. @@ -54,6 +74,7 @@
  14389. if (!swait_active(q))
  14390. return;
  14391. + WARN_ON(irqs_disabled());
  14392. raw_spin_lock_irq(&q->lock);
  14393. list_splice_init(&q->task_list, &tmp);
  14394. while (!list_empty(&tmp)) {
  14395. diff -Nur linux-4.9.6.orig/kernel/sched/swork.c linux-4.9.6/kernel/sched/swork.c
  14396. --- linux-4.9.6.orig/kernel/sched/swork.c 1970-01-01 01:00:00.000000000 +0100
  14397. +++ linux-4.9.6/kernel/sched/swork.c 2017-01-28 13:59:10.047660646 +0100
  14398. @@ -0,0 +1,173 @@
  14399. +/*
  14400. + * Copyright (C) 2014 BMW Car IT GmbH, Daniel Wagner daniel.wagner@bmw-carit.de
  14401. + *
  14402. + * Provides a framework for enqueuing callbacks from irq context
  14403. + * PREEMPT_RT_FULL safe. The callbacks are executed in kthread context.
  14404. + */
  14405. +
  14406. +#include <linux/swait.h>
  14407. +#include <linux/swork.h>
  14408. +#include <linux/kthread.h>
  14409. +#include <linux/slab.h>
  14410. +#include <linux/spinlock.h>
  14411. +#include <linux/export.h>
  14412. +
  14413. +#define SWORK_EVENT_PENDING (1 << 0)
  14414. +
  14415. +static DEFINE_MUTEX(worker_mutex);
  14416. +static struct sworker *glob_worker;
  14417. +
  14418. +struct sworker {
  14419. + struct list_head events;
  14420. + struct swait_queue_head wq;
  14421. +
  14422. + raw_spinlock_t lock;
  14423. +
  14424. + struct task_struct *task;
  14425. + int refs;
  14426. +};
  14427. +
  14428. +static bool swork_readable(struct sworker *worker)
  14429. +{
  14430. + bool r;
  14431. +
  14432. + if (kthread_should_stop())
  14433. + return true;
  14434. +
  14435. + raw_spin_lock_irq(&worker->lock);
  14436. + r = !list_empty(&worker->events);
  14437. + raw_spin_unlock_irq(&worker->lock);
  14438. +
  14439. + return r;
  14440. +}
  14441. +
  14442. +static int swork_kthread(void *arg)
  14443. +{
  14444. + struct sworker *worker = arg;
  14445. +
  14446. + for (;;) {
  14447. + swait_event_interruptible(worker->wq,
  14448. + swork_readable(worker));
  14449. + if (kthread_should_stop())
  14450. + break;
  14451. +
  14452. + raw_spin_lock_irq(&worker->lock);
  14453. + while (!list_empty(&worker->events)) {
  14454. + struct swork_event *sev;
  14455. +
  14456. + sev = list_first_entry(&worker->events,
  14457. + struct swork_event, item);
  14458. + list_del(&sev->item);
  14459. + raw_spin_unlock_irq(&worker->lock);
  14460. +
  14461. + WARN_ON_ONCE(!test_and_clear_bit(SWORK_EVENT_PENDING,
  14462. + &sev->flags));
  14463. + sev->func(sev);
  14464. + raw_spin_lock_irq(&worker->lock);
  14465. + }
  14466. + raw_spin_unlock_irq(&worker->lock);
  14467. + }
  14468. + return 0;
  14469. +}
  14470. +
  14471. +static struct sworker *swork_create(void)
  14472. +{
  14473. + struct sworker *worker;
  14474. +
  14475. + worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  14476. + if (!worker)
  14477. + return ERR_PTR(-ENOMEM);
  14478. +
  14479. + INIT_LIST_HEAD(&worker->events);
  14480. + raw_spin_lock_init(&worker->lock);
  14481. + init_swait_queue_head(&worker->wq);
  14482. +
  14483. + worker->task = kthread_run(swork_kthread, worker, "kswork");
  14484. + if (IS_ERR(worker->task)) {
  14485. + kfree(worker);
  14486. + return ERR_PTR(-ENOMEM);
  14487. + }
  14488. +
  14489. + return worker;
  14490. +}
  14491. +
  14492. +static void swork_destroy(struct sworker *worker)
  14493. +{
  14494. + kthread_stop(worker->task);
  14495. +
  14496. + WARN_ON(!list_empty(&worker->events));
  14497. + kfree(worker);
  14498. +}
  14499. +
  14500. +/**
  14501. + * swork_queue - queue swork
  14502. + *
  14503. + * Returns %false if @work was already on a queue, %true otherwise.
  14504. + *
  14505. + * The work is queued and processed on a random CPU
  14506. + */
  14507. +bool swork_queue(struct swork_event *sev)
  14508. +{
  14509. + unsigned long flags;
  14510. +
  14511. + if (test_and_set_bit(SWORK_EVENT_PENDING, &sev->flags))
  14512. + return false;
  14513. +
  14514. + raw_spin_lock_irqsave(&glob_worker->lock, flags);
  14515. + list_add_tail(&sev->item, &glob_worker->events);
  14516. + raw_spin_unlock_irqrestore(&glob_worker->lock, flags);
  14517. +
  14518. + swake_up(&glob_worker->wq);
  14519. + return true;
  14520. +}
  14521. +EXPORT_SYMBOL_GPL(swork_queue);
  14522. +
  14523. +/**
  14524. + * swork_get - get an instance of the sworker
  14525. + *
  14526. + * Returns an negative error code if the initialization if the worker did not
  14527. + * work, %0 otherwise.
  14528. + *
  14529. + */
  14530. +int swork_get(void)
  14531. +{
  14532. + struct sworker *worker;
  14533. +
  14534. + mutex_lock(&worker_mutex);
  14535. + if (!glob_worker) {
  14536. + worker = swork_create();
  14537. + if (IS_ERR(worker)) {
  14538. + mutex_unlock(&worker_mutex);
  14539. + return -ENOMEM;
  14540. + }
  14541. +
  14542. + glob_worker = worker;
  14543. + }
  14544. +
  14545. + glob_worker->refs++;
  14546. + mutex_unlock(&worker_mutex);
  14547. +
  14548. + return 0;
  14549. +}
  14550. +EXPORT_SYMBOL_GPL(swork_get);
  14551. +
  14552. +/**
  14553. + * swork_put - puts an instance of the sworker
  14554. + *
  14555. + * Will destroy the sworker thread. This function must not be called until all
  14556. + * queued events have been completed.
  14557. + */
  14558. +void swork_put(void)
  14559. +{
  14560. + mutex_lock(&worker_mutex);
  14561. +
  14562. + glob_worker->refs--;
  14563. + if (glob_worker->refs > 0)
  14564. + goto out;
  14565. +
  14566. + swork_destroy(glob_worker);
  14567. + glob_worker = NULL;
  14568. +out:
  14569. + mutex_unlock(&worker_mutex);
  14570. +}
  14571. +EXPORT_SYMBOL_GPL(swork_put);
  14572. diff -Nur linux-4.9.6.orig/kernel/signal.c linux-4.9.6/kernel/signal.c
  14573. --- linux-4.9.6.orig/kernel/signal.c 2017-01-26 08:25:24.000000000 +0100
  14574. +++ linux-4.9.6/kernel/signal.c 2017-01-28 13:59:10.047660646 +0100
  14575. @@ -14,6 +14,7 @@
  14576. #include <linux/export.h>
  14577. #include <linux/init.h>
  14578. #include <linux/sched.h>
  14579. +#include <linux/sched/rt.h>
  14580. #include <linux/fs.h>
  14581. #include <linux/tty.h>
  14582. #include <linux/binfmts.h>
  14583. @@ -352,13 +353,30 @@
  14584. return false;
  14585. }
  14586. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  14587. +{
  14588. + struct sigqueue *q = t->sigqueue_cache;
  14589. +
  14590. + if (cmpxchg(&t->sigqueue_cache, q, NULL) != q)
  14591. + return NULL;
  14592. + return q;
  14593. +}
  14594. +
  14595. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  14596. +{
  14597. + if (cmpxchg(&t->sigqueue_cache, NULL, q) == NULL)
  14598. + return 0;
  14599. + return 1;
  14600. +}
  14601. +
  14602. /*
  14603. * allocate a new signal queue record
  14604. * - this may be called without locks if and only if t == current, otherwise an
  14605. * appropriate lock must be held to stop the target task from exiting
  14606. */
  14607. static struct sigqueue *
  14608. -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
  14609. +__sigqueue_do_alloc(int sig, struct task_struct *t, gfp_t flags,
  14610. + int override_rlimit, int fromslab)
  14611. {
  14612. struct sigqueue *q = NULL;
  14613. struct user_struct *user;
  14614. @@ -375,7 +393,10 @@
  14615. if (override_rlimit ||
  14616. atomic_read(&user->sigpending) <=
  14617. task_rlimit(t, RLIMIT_SIGPENDING)) {
  14618. - q = kmem_cache_alloc(sigqueue_cachep, flags);
  14619. + if (!fromslab)
  14620. + q = get_task_cache(t);
  14621. + if (!q)
  14622. + q = kmem_cache_alloc(sigqueue_cachep, flags);
  14623. } else {
  14624. print_dropped_signal(sig);
  14625. }
  14626. @@ -392,6 +413,13 @@
  14627. return q;
  14628. }
  14629. +static struct sigqueue *
  14630. +__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags,
  14631. + int override_rlimit)
  14632. +{
  14633. + return __sigqueue_do_alloc(sig, t, flags, override_rlimit, 0);
  14634. +}
  14635. +
  14636. static void __sigqueue_free(struct sigqueue *q)
  14637. {
  14638. if (q->flags & SIGQUEUE_PREALLOC)
  14639. @@ -401,6 +429,21 @@
  14640. kmem_cache_free(sigqueue_cachep, q);
  14641. }
  14642. +static void sigqueue_free_current(struct sigqueue *q)
  14643. +{
  14644. + struct user_struct *up;
  14645. +
  14646. + if (q->flags & SIGQUEUE_PREALLOC)
  14647. + return;
  14648. +
  14649. + up = q->user;
  14650. + if (rt_prio(current->normal_prio) && !put_task_cache(current, q)) {
  14651. + atomic_dec(&up->sigpending);
  14652. + free_uid(up);
  14653. + } else
  14654. + __sigqueue_free(q);
  14655. +}
  14656. +
  14657. void flush_sigqueue(struct sigpending *queue)
  14658. {
  14659. struct sigqueue *q;
  14660. @@ -414,6 +457,21 @@
  14661. }
  14662. /*
  14663. + * Called from __exit_signal. Flush tsk->pending and
  14664. + * tsk->sigqueue_cache
  14665. + */
  14666. +void flush_task_sigqueue(struct task_struct *tsk)
  14667. +{
  14668. + struct sigqueue *q;
  14669. +
  14670. + flush_sigqueue(&tsk->pending);
  14671. +
  14672. + q = get_task_cache(tsk);
  14673. + if (q)
  14674. + kmem_cache_free(sigqueue_cachep, q);
  14675. +}
  14676. +
  14677. +/*
  14678. * Flush all pending signals for this kthread.
  14679. */
  14680. void flush_signals(struct task_struct *t)
  14681. @@ -525,7 +583,7 @@
  14682. still_pending:
  14683. list_del_init(&first->list);
  14684. copy_siginfo(info, &first->info);
  14685. - __sigqueue_free(first);
  14686. + sigqueue_free_current(first);
  14687. } else {
  14688. /*
  14689. * Ok, it wasn't in the queue. This must be
  14690. @@ -560,6 +618,8 @@
  14691. {
  14692. int signr;
  14693. + WARN_ON_ONCE(tsk != current);
  14694. +
  14695. /* We only dequeue private signals from ourselves, we don't let
  14696. * signalfd steal them
  14697. */
  14698. @@ -1156,8 +1216,8 @@
  14699. * We don't want to have recursive SIGSEGV's etc, for example,
  14700. * that is why we also clear SIGNAL_UNKILLABLE.
  14701. */
  14702. -int
  14703. -force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  14704. +static int
  14705. +do_force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  14706. {
  14707. unsigned long int flags;
  14708. int ret, blocked, ignored;
  14709. @@ -1182,6 +1242,39 @@
  14710. return ret;
  14711. }
  14712. +int force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  14713. +{
  14714. +/*
  14715. + * On some archs, PREEMPT_RT has to delay sending a signal from a trap
  14716. + * since it can not enable preemption, and the signal code's spin_locks
  14717. + * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will
  14718. + * send the signal on exit of the trap.
  14719. + */
  14720. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  14721. + if (in_atomic()) {
  14722. + if (WARN_ON_ONCE(t != current))
  14723. + return 0;
  14724. + if (WARN_ON_ONCE(t->forced_info.si_signo))
  14725. + return 0;
  14726. +
  14727. + if (is_si_special(info)) {
  14728. + WARN_ON_ONCE(info != SEND_SIG_PRIV);
  14729. + t->forced_info.si_signo = sig;
  14730. + t->forced_info.si_errno = 0;
  14731. + t->forced_info.si_code = SI_KERNEL;
  14732. + t->forced_info.si_pid = 0;
  14733. + t->forced_info.si_uid = 0;
  14734. + } else {
  14735. + t->forced_info = *info;
  14736. + }
  14737. +
  14738. + set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
  14739. + return 0;
  14740. + }
  14741. +#endif
  14742. + return do_force_sig_info(sig, info, t);
  14743. +}
  14744. +
  14745. /*
  14746. * Nuke all other threads in the group.
  14747. */
  14748. @@ -1216,12 +1309,12 @@
  14749. * Disable interrupts early to avoid deadlocks.
  14750. * See rcu_read_unlock() comment header for details.
  14751. */
  14752. - local_irq_save(*flags);
  14753. + local_irq_save_nort(*flags);
  14754. rcu_read_lock();
  14755. sighand = rcu_dereference(tsk->sighand);
  14756. if (unlikely(sighand == NULL)) {
  14757. rcu_read_unlock();
  14758. - local_irq_restore(*flags);
  14759. + local_irq_restore_nort(*flags);
  14760. break;
  14761. }
  14762. /*
  14763. @@ -1242,7 +1335,7 @@
  14764. }
  14765. spin_unlock(&sighand->siglock);
  14766. rcu_read_unlock();
  14767. - local_irq_restore(*flags);
  14768. + local_irq_restore_nort(*flags);
  14769. }
  14770. return sighand;
  14771. @@ -1485,7 +1578,8 @@
  14772. */
  14773. struct sigqueue *sigqueue_alloc(void)
  14774. {
  14775. - struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0);
  14776. + /* Preallocated sigqueue objects always from the slabcache ! */
  14777. + struct sigqueue *q = __sigqueue_do_alloc(-1, current, GFP_KERNEL, 0, 1);
  14778. if (q)
  14779. q->flags |= SIGQUEUE_PREALLOC;
  14780. @@ -1846,15 +1940,7 @@
  14781. if (gstop_done && ptrace_reparented(current))
  14782. do_notify_parent_cldstop(current, false, why);
  14783. - /*
  14784. - * Don't want to allow preemption here, because
  14785. - * sys_ptrace() needs this task to be inactive.
  14786. - *
  14787. - * XXX: implement read_unlock_no_resched().
  14788. - */
  14789. - preempt_disable();
  14790. read_unlock(&tasklist_lock);
  14791. - preempt_enable_no_resched();
  14792. freezable_schedule();
  14793. } else {
  14794. /*
  14795. diff -Nur linux-4.9.6.orig/kernel/softirq.c linux-4.9.6/kernel/softirq.c
  14796. --- linux-4.9.6.orig/kernel/softirq.c 2017-01-26 08:25:24.000000000 +0100
  14797. +++ linux-4.9.6/kernel/softirq.c 2017-01-28 13:59:10.083662028 +0100
  14798. @@ -21,10 +21,12 @@
  14799. #include <linux/freezer.h>
  14800. #include <linux/kthread.h>
  14801. #include <linux/rcupdate.h>
  14802. +#include <linux/delay.h>
  14803. #include <linux/ftrace.h>
  14804. #include <linux/smp.h>
  14805. #include <linux/smpboot.h>
  14806. #include <linux/tick.h>
  14807. +#include <linux/locallock.h>
  14808. #include <linux/irq.h>
  14809. #define CREATE_TRACE_POINTS
  14810. @@ -56,12 +58,108 @@
  14811. static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
  14812. DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
  14813. +#ifdef CONFIG_PREEMPT_RT_FULL
  14814. +#define TIMER_SOFTIRQS ((1 << TIMER_SOFTIRQ) | (1 << HRTIMER_SOFTIRQ))
  14815. +DEFINE_PER_CPU(struct task_struct *, ktimer_softirqd);
  14816. +#endif
  14817. const char * const softirq_to_name[NR_SOFTIRQS] = {
  14818. "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "IRQ_POLL",
  14819. "TASKLET", "SCHED", "HRTIMER", "RCU"
  14820. };
  14821. +#ifdef CONFIG_NO_HZ_COMMON
  14822. +# ifdef CONFIG_PREEMPT_RT_FULL
  14823. +
  14824. +struct softirq_runner {
  14825. + struct task_struct *runner[NR_SOFTIRQS];
  14826. +};
  14827. +
  14828. +static DEFINE_PER_CPU(struct softirq_runner, softirq_runners);
  14829. +
  14830. +static inline void softirq_set_runner(unsigned int sirq)
  14831. +{
  14832. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  14833. +
  14834. + sr->runner[sirq] = current;
  14835. +}
  14836. +
  14837. +static inline void softirq_clr_runner(unsigned int sirq)
  14838. +{
  14839. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  14840. +
  14841. + sr->runner[sirq] = NULL;
  14842. +}
  14843. +
  14844. +/*
  14845. + * On preempt-rt a softirq running context might be blocked on a
  14846. + * lock. There might be no other runnable task on this CPU because the
  14847. + * lock owner runs on some other CPU. So we have to go into idle with
  14848. + * the pending bit set. Therefor we need to check this otherwise we
  14849. + * warn about false positives which confuses users and defeats the
  14850. + * whole purpose of this test.
  14851. + *
  14852. + * This code is called with interrupts disabled.
  14853. + */
  14854. +void softirq_check_pending_idle(void)
  14855. +{
  14856. + static int rate_limit;
  14857. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  14858. + u32 warnpending;
  14859. + int i;
  14860. +
  14861. + if (rate_limit >= 10)
  14862. + return;
  14863. +
  14864. + warnpending = local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK;
  14865. + for (i = 0; i < NR_SOFTIRQS; i++) {
  14866. + struct task_struct *tsk = sr->runner[i];
  14867. +
  14868. + /*
  14869. + * The wakeup code in rtmutex.c wakes up the task
  14870. + * _before_ it sets pi_blocked_on to NULL under
  14871. + * tsk->pi_lock. So we need to check for both: state
  14872. + * and pi_blocked_on.
  14873. + */
  14874. + if (tsk) {
  14875. + raw_spin_lock(&tsk->pi_lock);
  14876. + if (tsk->pi_blocked_on || tsk->state == TASK_RUNNING) {
  14877. + /* Clear all bits pending in that task */
  14878. + warnpending &= ~(tsk->softirqs_raised);
  14879. + warnpending &= ~(1 << i);
  14880. + }
  14881. + raw_spin_unlock(&tsk->pi_lock);
  14882. + }
  14883. + }
  14884. +
  14885. + if (warnpending) {
  14886. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  14887. + warnpending);
  14888. + rate_limit++;
  14889. + }
  14890. +}
  14891. +# else
  14892. +/*
  14893. + * On !PREEMPT_RT we just printk rate limited:
  14894. + */
  14895. +void softirq_check_pending_idle(void)
  14896. +{
  14897. + static int rate_limit;
  14898. +
  14899. + if (rate_limit < 10 &&
  14900. + (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  14901. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  14902. + local_softirq_pending());
  14903. + rate_limit++;
  14904. + }
  14905. +}
  14906. +# endif
  14907. +
  14908. +#else /* !CONFIG_NO_HZ_COMMON */
  14909. +static inline void softirq_set_runner(unsigned int sirq) { }
  14910. +static inline void softirq_clr_runner(unsigned int sirq) { }
  14911. +#endif
  14912. +
  14913. /*
  14914. * we cannot loop indefinitely here to avoid userspace starvation,
  14915. * but we also don't want to introduce a worst case 1/HZ latency
  14916. @@ -77,6 +175,37 @@
  14917. wake_up_process(tsk);
  14918. }
  14919. +#ifdef CONFIG_PREEMPT_RT_FULL
  14920. +static void wakeup_timer_softirqd(void)
  14921. +{
  14922. + /* Interrupts are disabled: no need to stop preemption */
  14923. + struct task_struct *tsk = __this_cpu_read(ktimer_softirqd);
  14924. +
  14925. + if (tsk && tsk->state != TASK_RUNNING)
  14926. + wake_up_process(tsk);
  14927. +}
  14928. +#endif
  14929. +
  14930. +static void handle_softirq(unsigned int vec_nr)
  14931. +{
  14932. + struct softirq_action *h = softirq_vec + vec_nr;
  14933. + int prev_count;
  14934. +
  14935. + prev_count = preempt_count();
  14936. +
  14937. + kstat_incr_softirqs_this_cpu(vec_nr);
  14938. +
  14939. + trace_softirq_entry(vec_nr);
  14940. + h->action(h);
  14941. + trace_softirq_exit(vec_nr);
  14942. + if (unlikely(prev_count != preempt_count())) {
  14943. + pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  14944. + vec_nr, softirq_to_name[vec_nr], h->action,
  14945. + prev_count, preempt_count());
  14946. + preempt_count_set(prev_count);
  14947. + }
  14948. +}
  14949. +
  14950. /*
  14951. * If ksoftirqd is scheduled, we do not want to process pending softirqs
  14952. * right now. Let ksoftirqd handle this at its own rate, to get fairness.
  14953. @@ -88,6 +217,48 @@
  14954. return tsk && (tsk->state == TASK_RUNNING);
  14955. }
  14956. +#ifndef CONFIG_PREEMPT_RT_FULL
  14957. +static inline int ksoftirqd_softirq_pending(void)
  14958. +{
  14959. + return local_softirq_pending();
  14960. +}
  14961. +
  14962. +static void handle_pending_softirqs(u32 pending)
  14963. +{
  14964. + struct softirq_action *h = softirq_vec;
  14965. + int softirq_bit;
  14966. +
  14967. + local_irq_enable();
  14968. +
  14969. + h = softirq_vec;
  14970. +
  14971. + while ((softirq_bit = ffs(pending))) {
  14972. + unsigned int vec_nr;
  14973. +
  14974. + h += softirq_bit - 1;
  14975. + vec_nr = h - softirq_vec;
  14976. + handle_softirq(vec_nr);
  14977. +
  14978. + h++;
  14979. + pending >>= softirq_bit;
  14980. + }
  14981. +
  14982. + rcu_bh_qs();
  14983. + local_irq_disable();
  14984. +}
  14985. +
  14986. +static void run_ksoftirqd(unsigned int cpu)
  14987. +{
  14988. + local_irq_disable();
  14989. + if (ksoftirqd_softirq_pending()) {
  14990. + __do_softirq();
  14991. + local_irq_enable();
  14992. + cond_resched_rcu_qs();
  14993. + return;
  14994. + }
  14995. + local_irq_enable();
  14996. +}
  14997. +
  14998. /*
  14999. * preempt_count and SOFTIRQ_OFFSET usage:
  15000. * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
  15001. @@ -243,10 +414,8 @@
  15002. unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
  15003. unsigned long old_flags = current->flags;
  15004. int max_restart = MAX_SOFTIRQ_RESTART;
  15005. - struct softirq_action *h;
  15006. bool in_hardirq;
  15007. __u32 pending;
  15008. - int softirq_bit;
  15009. /*
  15010. * Mask out PF_MEMALLOC s current task context is borrowed for the
  15011. @@ -265,36 +434,7 @@
  15012. /* Reset the pending bitmask before enabling irqs */
  15013. set_softirq_pending(0);
  15014. - local_irq_enable();
  15015. -
  15016. - h = softirq_vec;
  15017. -
  15018. - while ((softirq_bit = ffs(pending))) {
  15019. - unsigned int vec_nr;
  15020. - int prev_count;
  15021. -
  15022. - h += softirq_bit - 1;
  15023. -
  15024. - vec_nr = h - softirq_vec;
  15025. - prev_count = preempt_count();
  15026. -
  15027. - kstat_incr_softirqs_this_cpu(vec_nr);
  15028. -
  15029. - trace_softirq_entry(vec_nr);
  15030. - h->action(h);
  15031. - trace_softirq_exit(vec_nr);
  15032. - if (unlikely(prev_count != preempt_count())) {
  15033. - pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  15034. - vec_nr, softirq_to_name[vec_nr], h->action,
  15035. - prev_count, preempt_count());
  15036. - preempt_count_set(prev_count);
  15037. - }
  15038. - h++;
  15039. - pending >>= softirq_bit;
  15040. - }
  15041. -
  15042. - rcu_bh_qs();
  15043. - local_irq_disable();
  15044. + handle_pending_softirqs(pending);
  15045. pending = local_softirq_pending();
  15046. if (pending) {
  15047. @@ -331,6 +471,309 @@
  15048. }
  15049. /*
  15050. + * This function must run with irqs disabled!
  15051. + */
  15052. +void raise_softirq_irqoff(unsigned int nr)
  15053. +{
  15054. + __raise_softirq_irqoff(nr);
  15055. +
  15056. + /*
  15057. + * If we're in an interrupt or softirq, we're done
  15058. + * (this also catches softirq-disabled code). We will
  15059. + * actually run the softirq once we return from
  15060. + * the irq or softirq.
  15061. + *
  15062. + * Otherwise we wake up ksoftirqd to make sure we
  15063. + * schedule the softirq soon.
  15064. + */
  15065. + if (!in_interrupt())
  15066. + wakeup_softirqd();
  15067. +}
  15068. +
  15069. +void __raise_softirq_irqoff(unsigned int nr)
  15070. +{
  15071. + trace_softirq_raise(nr);
  15072. + or_softirq_pending(1UL << nr);
  15073. +}
  15074. +
  15075. +static inline void local_bh_disable_nort(void) { local_bh_disable(); }
  15076. +static inline void _local_bh_enable_nort(void) { _local_bh_enable(); }
  15077. +static void ksoftirqd_set_sched_params(unsigned int cpu) { }
  15078. +
  15079. +#else /* !PREEMPT_RT_FULL */
  15080. +
  15081. +/*
  15082. + * On RT we serialize softirq execution with a cpu local lock per softirq
  15083. + */
  15084. +static DEFINE_PER_CPU(struct local_irq_lock [NR_SOFTIRQS], local_softirq_locks);
  15085. +
  15086. +void __init softirq_early_init(void)
  15087. +{
  15088. + int i;
  15089. +
  15090. + for (i = 0; i < NR_SOFTIRQS; i++)
  15091. + local_irq_lock_init(local_softirq_locks[i]);
  15092. +}
  15093. +
  15094. +static void lock_softirq(int which)
  15095. +{
  15096. + local_lock(local_softirq_locks[which]);
  15097. +}
  15098. +
  15099. +static void unlock_softirq(int which)
  15100. +{
  15101. + local_unlock(local_softirq_locks[which]);
  15102. +}
  15103. +
  15104. +static void do_single_softirq(int which)
  15105. +{
  15106. + unsigned long old_flags = current->flags;
  15107. +
  15108. + current->flags &= ~PF_MEMALLOC;
  15109. + vtime_account_irq_enter(current);
  15110. + current->flags |= PF_IN_SOFTIRQ;
  15111. + lockdep_softirq_enter();
  15112. + local_irq_enable();
  15113. + handle_softirq(which);
  15114. + local_irq_disable();
  15115. + lockdep_softirq_exit();
  15116. + current->flags &= ~PF_IN_SOFTIRQ;
  15117. + vtime_account_irq_enter(current);
  15118. + tsk_restore_flags(current, old_flags, PF_MEMALLOC);
  15119. +}
  15120. +
  15121. +/*
  15122. + * Called with interrupts disabled. Process softirqs which were raised
  15123. + * in current context (or on behalf of ksoftirqd).
  15124. + */
  15125. +static void do_current_softirqs(void)
  15126. +{
  15127. + while (current->softirqs_raised) {
  15128. + int i = __ffs(current->softirqs_raised);
  15129. + unsigned int pending, mask = (1U << i);
  15130. +
  15131. + current->softirqs_raised &= ~mask;
  15132. + local_irq_enable();
  15133. +
  15134. + /*
  15135. + * If the lock is contended, we boost the owner to
  15136. + * process the softirq or leave the critical section
  15137. + * now.
  15138. + */
  15139. + lock_softirq(i);
  15140. + local_irq_disable();
  15141. + softirq_set_runner(i);
  15142. + /*
  15143. + * Check with the local_softirq_pending() bits,
  15144. + * whether we need to process this still or if someone
  15145. + * else took care of it.
  15146. + */
  15147. + pending = local_softirq_pending();
  15148. + if (pending & mask) {
  15149. + set_softirq_pending(pending & ~mask);
  15150. + do_single_softirq(i);
  15151. + }
  15152. + softirq_clr_runner(i);
  15153. + WARN_ON(current->softirq_nestcnt != 1);
  15154. + local_irq_enable();
  15155. + unlock_softirq(i);
  15156. + local_irq_disable();
  15157. + }
  15158. +}
  15159. +
  15160. +void __local_bh_disable(void)
  15161. +{
  15162. + if (++current->softirq_nestcnt == 1)
  15163. + migrate_disable();
  15164. +}
  15165. +EXPORT_SYMBOL(__local_bh_disable);
  15166. +
  15167. +void __local_bh_enable(void)
  15168. +{
  15169. + if (WARN_ON(current->softirq_nestcnt == 0))
  15170. + return;
  15171. +
  15172. + local_irq_disable();
  15173. + if (current->softirq_nestcnt == 1 && current->softirqs_raised)
  15174. + do_current_softirqs();
  15175. + local_irq_enable();
  15176. +
  15177. + if (--current->softirq_nestcnt == 0)
  15178. + migrate_enable();
  15179. +}
  15180. +EXPORT_SYMBOL(__local_bh_enable);
  15181. +
  15182. +void _local_bh_enable(void)
  15183. +{
  15184. + if (WARN_ON(current->softirq_nestcnt == 0))
  15185. + return;
  15186. + if (--current->softirq_nestcnt == 0)
  15187. + migrate_enable();
  15188. +}
  15189. +EXPORT_SYMBOL(_local_bh_enable);
  15190. +
  15191. +int in_serving_softirq(void)
  15192. +{
  15193. + return current->flags & PF_IN_SOFTIRQ;
  15194. +}
  15195. +EXPORT_SYMBOL(in_serving_softirq);
  15196. +
  15197. +/* Called with preemption disabled */
  15198. +static void run_ksoftirqd(unsigned int cpu)
  15199. +{
  15200. + local_irq_disable();
  15201. + current->softirq_nestcnt++;
  15202. +
  15203. + do_current_softirqs();
  15204. + current->softirq_nestcnt--;
  15205. + local_irq_enable();
  15206. + cond_resched_rcu_qs();
  15207. +}
  15208. +
  15209. +/*
  15210. + * Called from netif_rx_ni(). Preemption enabled, but migration
  15211. + * disabled. So the cpu can't go away under us.
  15212. + */
  15213. +void thread_do_softirq(void)
  15214. +{
  15215. + if (!in_serving_softirq() && current->softirqs_raised) {
  15216. + current->softirq_nestcnt++;
  15217. + do_current_softirqs();
  15218. + current->softirq_nestcnt--;
  15219. + }
  15220. +}
  15221. +
  15222. +static void do_raise_softirq_irqoff(unsigned int nr)
  15223. +{
  15224. + unsigned int mask;
  15225. +
  15226. + mask = 1UL << nr;
  15227. +
  15228. + trace_softirq_raise(nr);
  15229. + or_softirq_pending(mask);
  15230. +
  15231. + /*
  15232. + * If we are not in a hard interrupt and inside a bh disabled
  15233. + * region, we simply raise the flag on current. local_bh_enable()
  15234. + * will make sure that the softirq is executed. Otherwise we
  15235. + * delegate it to ksoftirqd.
  15236. + */
  15237. + if (!in_irq() && current->softirq_nestcnt)
  15238. + current->softirqs_raised |= mask;
  15239. + else if (!__this_cpu_read(ksoftirqd) || !__this_cpu_read(ktimer_softirqd))
  15240. + return;
  15241. +
  15242. + if (mask & TIMER_SOFTIRQS)
  15243. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  15244. + else
  15245. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  15246. +}
  15247. +
  15248. +static void wakeup_proper_softirq(unsigned int nr)
  15249. +{
  15250. + if ((1UL << nr) & TIMER_SOFTIRQS)
  15251. + wakeup_timer_softirqd();
  15252. + else
  15253. + wakeup_softirqd();
  15254. +}
  15255. +
  15256. +void __raise_softirq_irqoff(unsigned int nr)
  15257. +{
  15258. + do_raise_softirq_irqoff(nr);
  15259. + if (!in_irq() && !current->softirq_nestcnt)
  15260. + wakeup_proper_softirq(nr);
  15261. +}
  15262. +
  15263. +/*
  15264. + * Same as __raise_softirq_irqoff() but will process them in ksoftirqd
  15265. + */
  15266. +void __raise_softirq_irqoff_ksoft(unsigned int nr)
  15267. +{
  15268. + unsigned int mask;
  15269. +
  15270. + if (WARN_ON_ONCE(!__this_cpu_read(ksoftirqd) ||
  15271. + !__this_cpu_read(ktimer_softirqd)))
  15272. + return;
  15273. + mask = 1UL << nr;
  15274. +
  15275. + trace_softirq_raise(nr);
  15276. + or_softirq_pending(mask);
  15277. + if (mask & TIMER_SOFTIRQS)
  15278. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  15279. + else
  15280. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  15281. + wakeup_proper_softirq(nr);
  15282. +}
  15283. +
  15284. +/*
  15285. + * This function must run with irqs disabled!
  15286. + */
  15287. +void raise_softirq_irqoff(unsigned int nr)
  15288. +{
  15289. + do_raise_softirq_irqoff(nr);
  15290. +
  15291. + /*
  15292. + * If we're in an hard interrupt we let irq return code deal
  15293. + * with the wakeup of ksoftirqd.
  15294. + */
  15295. + if (in_irq())
  15296. + return;
  15297. + /*
  15298. + * If we are in thread context but outside of a bh disabled
  15299. + * region, we need to wake ksoftirqd as well.
  15300. + *
  15301. + * CHECKME: Some of the places which do that could be wrapped
  15302. + * into local_bh_disable/enable pairs. Though it's unclear
  15303. + * whether this is worth the effort. To find those places just
  15304. + * raise a WARN() if the condition is met.
  15305. + */
  15306. + if (!current->softirq_nestcnt)
  15307. + wakeup_proper_softirq(nr);
  15308. +}
  15309. +
  15310. +static inline int ksoftirqd_softirq_pending(void)
  15311. +{
  15312. + return current->softirqs_raised;
  15313. +}
  15314. +
  15315. +static inline void local_bh_disable_nort(void) { }
  15316. +static inline void _local_bh_enable_nort(void) { }
  15317. +
  15318. +static inline void ksoftirqd_set_sched_params(unsigned int cpu)
  15319. +{
  15320. + /* Take over all but timer pending softirqs when starting */
  15321. + local_irq_disable();
  15322. + current->softirqs_raised = local_softirq_pending() & ~TIMER_SOFTIRQS;
  15323. + local_irq_enable();
  15324. +}
  15325. +
  15326. +static inline void ktimer_softirqd_set_sched_params(unsigned int cpu)
  15327. +{
  15328. + struct sched_param param = { .sched_priority = 1 };
  15329. +
  15330. + sched_setscheduler(current, SCHED_FIFO, &param);
  15331. +
  15332. + /* Take over timer pending softirqs when starting */
  15333. + local_irq_disable();
  15334. + current->softirqs_raised = local_softirq_pending() & TIMER_SOFTIRQS;
  15335. + local_irq_enable();
  15336. +}
  15337. +
  15338. +static inline void ktimer_softirqd_clr_sched_params(unsigned int cpu,
  15339. + bool online)
  15340. +{
  15341. + struct sched_param param = { .sched_priority = 0 };
  15342. +
  15343. + sched_setscheduler(current, SCHED_NORMAL, &param);
  15344. +}
  15345. +
  15346. +static int ktimer_softirqd_should_run(unsigned int cpu)
  15347. +{
  15348. + return current->softirqs_raised;
  15349. +}
  15350. +
  15351. +#endif /* PREEMPT_RT_FULL */
  15352. +/*
  15353. * Enter an interrupt context.
  15354. */
  15355. void irq_enter(void)
  15356. @@ -341,9 +784,9 @@
  15357. * Prevent raise_softirq from needlessly waking up ksoftirqd
  15358. * here, as softirq will be serviced on return from interrupt.
  15359. */
  15360. - local_bh_disable();
  15361. + local_bh_disable_nort();
  15362. tick_irq_enter();
  15363. - _local_bh_enable();
  15364. + _local_bh_enable_nort();
  15365. }
  15366. __irq_enter();
  15367. @@ -351,9 +794,13 @@
  15368. static inline void invoke_softirq(void)
  15369. {
  15370. +#ifdef CONFIG_PREEMPT_RT_FULL
  15371. + unsigned long flags;
  15372. +#endif
  15373. +
  15374. if (ksoftirqd_running())
  15375. return;
  15376. -
  15377. +#ifndef CONFIG_PREEMPT_RT_FULL
  15378. if (!force_irqthreads) {
  15379. #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
  15380. /*
  15381. @@ -373,6 +820,17 @@
  15382. } else {
  15383. wakeup_softirqd();
  15384. }
  15385. +#else /* PREEMPT_RT_FULL */
  15386. +
  15387. + local_irq_save(flags);
  15388. + if (__this_cpu_read(ksoftirqd) &&
  15389. + __this_cpu_read(ksoftirqd)->softirqs_raised)
  15390. + wakeup_softirqd();
  15391. + if (__this_cpu_read(ktimer_softirqd) &&
  15392. + __this_cpu_read(ktimer_softirqd)->softirqs_raised)
  15393. + wakeup_timer_softirqd();
  15394. + local_irq_restore(flags);
  15395. +#endif
  15396. }
  15397. static inline void tick_irq_exit(void)
  15398. @@ -409,26 +867,6 @@
  15399. trace_hardirq_exit(); /* must be last! */
  15400. }
  15401. -/*
  15402. - * This function must run with irqs disabled!
  15403. - */
  15404. -inline void raise_softirq_irqoff(unsigned int nr)
  15405. -{
  15406. - __raise_softirq_irqoff(nr);
  15407. -
  15408. - /*
  15409. - * If we're in an interrupt or softirq, we're done
  15410. - * (this also catches softirq-disabled code). We will
  15411. - * actually run the softirq once we return from
  15412. - * the irq or softirq.
  15413. - *
  15414. - * Otherwise we wake up ksoftirqd to make sure we
  15415. - * schedule the softirq soon.
  15416. - */
  15417. - if (!in_interrupt())
  15418. - wakeup_softirqd();
  15419. -}
  15420. -
  15421. void raise_softirq(unsigned int nr)
  15422. {
  15423. unsigned long flags;
  15424. @@ -438,12 +876,6 @@
  15425. local_irq_restore(flags);
  15426. }
  15427. -void __raise_softirq_irqoff(unsigned int nr)
  15428. -{
  15429. - trace_softirq_raise(nr);
  15430. - or_softirq_pending(1UL << nr);
  15431. -}
  15432. -
  15433. void open_softirq(int nr, void (*action)(struct softirq_action *))
  15434. {
  15435. softirq_vec[nr].action = action;
  15436. @@ -460,15 +892,45 @@
  15437. static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
  15438. static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
  15439. +static void inline
  15440. +__tasklet_common_schedule(struct tasklet_struct *t, struct tasklet_head *head, unsigned int nr)
  15441. +{
  15442. + if (tasklet_trylock(t)) {
  15443. +again:
  15444. + /* We may have been preempted before tasklet_trylock
  15445. + * and __tasklet_action may have already run.
  15446. + * So double check the sched bit while the takslet
  15447. + * is locked before adding it to the list.
  15448. + */
  15449. + if (test_bit(TASKLET_STATE_SCHED, &t->state)) {
  15450. + t->next = NULL;
  15451. + *head->tail = t;
  15452. + head->tail = &(t->next);
  15453. + raise_softirq_irqoff(nr);
  15454. + tasklet_unlock(t);
  15455. + } else {
  15456. + /* This is subtle. If we hit the corner case above
  15457. + * It is possible that we get preempted right here,
  15458. + * and another task has successfully called
  15459. + * tasklet_schedule(), then this function, and
  15460. + * failed on the trylock. Thus we must be sure
  15461. + * before releasing the tasklet lock, that the
  15462. + * SCHED_BIT is clear. Otherwise the tasklet
  15463. + * may get its SCHED_BIT set, but not added to the
  15464. + * list
  15465. + */
  15466. + if (!tasklet_tryunlock(t))
  15467. + goto again;
  15468. + }
  15469. + }
  15470. +}
  15471. +
  15472. void __tasklet_schedule(struct tasklet_struct *t)
  15473. {
  15474. unsigned long flags;
  15475. local_irq_save(flags);
  15476. - t->next = NULL;
  15477. - *__this_cpu_read(tasklet_vec.tail) = t;
  15478. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  15479. - raise_softirq_irqoff(TASKLET_SOFTIRQ);
  15480. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  15481. local_irq_restore(flags);
  15482. }
  15483. EXPORT_SYMBOL(__tasklet_schedule);
  15484. @@ -478,10 +940,7 @@
  15485. unsigned long flags;
  15486. local_irq_save(flags);
  15487. - t->next = NULL;
  15488. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  15489. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  15490. - raise_softirq_irqoff(HI_SOFTIRQ);
  15491. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  15492. local_irq_restore(flags);
  15493. }
  15494. EXPORT_SYMBOL(__tasklet_hi_schedule);
  15495. @@ -490,82 +949,122 @@
  15496. {
  15497. BUG_ON(!irqs_disabled());
  15498. - t->next = __this_cpu_read(tasklet_hi_vec.head);
  15499. - __this_cpu_write(tasklet_hi_vec.head, t);
  15500. - __raise_softirq_irqoff(HI_SOFTIRQ);
  15501. + __tasklet_hi_schedule(t);
  15502. }
  15503. EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  15504. -static __latent_entropy void tasklet_action(struct softirq_action *a)
  15505. +void tasklet_enable(struct tasklet_struct *t)
  15506. {
  15507. - struct tasklet_struct *list;
  15508. + if (!atomic_dec_and_test(&t->count))
  15509. + return;
  15510. + if (test_and_clear_bit(TASKLET_STATE_PENDING, &t->state))
  15511. + tasklet_schedule(t);
  15512. +}
  15513. +EXPORT_SYMBOL(tasklet_enable);
  15514. - local_irq_disable();
  15515. - list = __this_cpu_read(tasklet_vec.head);
  15516. - __this_cpu_write(tasklet_vec.head, NULL);
  15517. - __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  15518. - local_irq_enable();
  15519. +static void __tasklet_action(struct softirq_action *a,
  15520. + struct tasklet_struct *list)
  15521. +{
  15522. + int loops = 1000000;
  15523. while (list) {
  15524. struct tasklet_struct *t = list;
  15525. list = list->next;
  15526. - if (tasklet_trylock(t)) {
  15527. - if (!atomic_read(&t->count)) {
  15528. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  15529. - &t->state))
  15530. - BUG();
  15531. - t->func(t->data);
  15532. - tasklet_unlock(t);
  15533. - continue;
  15534. - }
  15535. - tasklet_unlock(t);
  15536. + /*
  15537. + * Should always succeed - after a tasklist got on the
  15538. + * list (after getting the SCHED bit set from 0 to 1),
  15539. + * nothing but the tasklet softirq it got queued to can
  15540. + * lock it:
  15541. + */
  15542. + if (!tasklet_trylock(t)) {
  15543. + WARN_ON(1);
  15544. + continue;
  15545. }
  15546. - local_irq_disable();
  15547. t->next = NULL;
  15548. - *__this_cpu_read(tasklet_vec.tail) = t;
  15549. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  15550. - __raise_softirq_irqoff(TASKLET_SOFTIRQ);
  15551. - local_irq_enable();
  15552. +
  15553. + /*
  15554. + * If we cannot handle the tasklet because it's disabled,
  15555. + * mark it as pending. tasklet_enable() will later
  15556. + * re-schedule the tasklet.
  15557. + */
  15558. + if (unlikely(atomic_read(&t->count))) {
  15559. +out_disabled:
  15560. + /* implicit unlock: */
  15561. + wmb();
  15562. + t->state = TASKLET_STATEF_PENDING;
  15563. + continue;
  15564. + }
  15565. +
  15566. + /*
  15567. + * After this point on the tasklet might be rescheduled
  15568. + * on another CPU, but it can only be added to another
  15569. + * CPU's tasklet list if we unlock the tasklet (which we
  15570. + * dont do yet).
  15571. + */
  15572. + if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  15573. + WARN_ON(1);
  15574. +
  15575. +again:
  15576. + t->func(t->data);
  15577. +
  15578. + /*
  15579. + * Try to unlock the tasklet. We must use cmpxchg, because
  15580. + * another CPU might have scheduled or disabled the tasklet.
  15581. + * We only allow the STATE_RUN -> 0 transition here.
  15582. + */
  15583. + while (!tasklet_tryunlock(t)) {
  15584. + /*
  15585. + * If it got disabled meanwhile, bail out:
  15586. + */
  15587. + if (atomic_read(&t->count))
  15588. + goto out_disabled;
  15589. + /*
  15590. + * If it got scheduled meanwhile, re-execute
  15591. + * the tasklet function:
  15592. + */
  15593. + if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  15594. + goto again;
  15595. + if (!--loops) {
  15596. + printk("hm, tasklet state: %08lx\n", t->state);
  15597. + WARN_ON(1);
  15598. + tasklet_unlock(t);
  15599. + break;
  15600. + }
  15601. + }
  15602. }
  15603. }
  15604. +static void tasklet_action(struct softirq_action *a)
  15605. +{
  15606. + struct tasklet_struct *list;
  15607. +
  15608. + local_irq_disable();
  15609. +
  15610. + list = __this_cpu_read(tasklet_vec.head);
  15611. + __this_cpu_write(tasklet_vec.head, NULL);
  15612. + __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  15613. +
  15614. + local_irq_enable();
  15615. +
  15616. + __tasklet_action(a, list);
  15617. +}
  15618. +
  15619. static __latent_entropy void tasklet_hi_action(struct softirq_action *a)
  15620. {
  15621. struct tasklet_struct *list;
  15622. local_irq_disable();
  15623. +
  15624. list = __this_cpu_read(tasklet_hi_vec.head);
  15625. __this_cpu_write(tasklet_hi_vec.head, NULL);
  15626. __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
  15627. - local_irq_enable();
  15628. - while (list) {
  15629. - struct tasklet_struct *t = list;
  15630. -
  15631. - list = list->next;
  15632. -
  15633. - if (tasklet_trylock(t)) {
  15634. - if (!atomic_read(&t->count)) {
  15635. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  15636. - &t->state))
  15637. - BUG();
  15638. - t->func(t->data);
  15639. - tasklet_unlock(t);
  15640. - continue;
  15641. - }
  15642. - tasklet_unlock(t);
  15643. - }
  15644. + local_irq_enable();
  15645. - local_irq_disable();
  15646. - t->next = NULL;
  15647. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  15648. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  15649. - __raise_softirq_irqoff(HI_SOFTIRQ);
  15650. - local_irq_enable();
  15651. - }
  15652. + __tasklet_action(a, list);
  15653. }
  15654. void tasklet_init(struct tasklet_struct *t,
  15655. @@ -586,7 +1085,7 @@
  15656. while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
  15657. do {
  15658. - yield();
  15659. + msleep(1);
  15660. } while (test_bit(TASKLET_STATE_SCHED, &t->state));
  15661. }
  15662. tasklet_unlock_wait(t);
  15663. @@ -660,25 +1159,26 @@
  15664. open_softirq(HI_SOFTIRQ, tasklet_hi_action);
  15665. }
  15666. -static int ksoftirqd_should_run(unsigned int cpu)
  15667. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  15668. +void tasklet_unlock_wait(struct tasklet_struct *t)
  15669. {
  15670. - return local_softirq_pending();
  15671. -}
  15672. -
  15673. -static void run_ksoftirqd(unsigned int cpu)
  15674. -{
  15675. - local_irq_disable();
  15676. - if (local_softirq_pending()) {
  15677. + while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
  15678. /*
  15679. - * We can safely run softirq on inline stack, as we are not deep
  15680. - * in the task stack here.
  15681. + * Hack for now to avoid this busy-loop:
  15682. */
  15683. - __do_softirq();
  15684. - local_irq_enable();
  15685. - cond_resched_rcu_qs();
  15686. - return;
  15687. +#ifdef CONFIG_PREEMPT_RT_FULL
  15688. + msleep(1);
  15689. +#else
  15690. + barrier();
  15691. +#endif
  15692. }
  15693. - local_irq_enable();
  15694. +}
  15695. +EXPORT_SYMBOL(tasklet_unlock_wait);
  15696. +#endif
  15697. +
  15698. +static int ksoftirqd_should_run(unsigned int cpu)
  15699. +{
  15700. + return ksoftirqd_softirq_pending();
  15701. }
  15702. #ifdef CONFIG_HOTPLUG_CPU
  15703. @@ -745,17 +1245,31 @@
  15704. static struct smp_hotplug_thread softirq_threads = {
  15705. .store = &ksoftirqd,
  15706. + .setup = ksoftirqd_set_sched_params,
  15707. .thread_should_run = ksoftirqd_should_run,
  15708. .thread_fn = run_ksoftirqd,
  15709. .thread_comm = "ksoftirqd/%u",
  15710. };
  15711. +#ifdef CONFIG_PREEMPT_RT_FULL
  15712. +static struct smp_hotplug_thread softirq_timer_threads = {
  15713. + .store = &ktimer_softirqd,
  15714. + .setup = ktimer_softirqd_set_sched_params,
  15715. + .cleanup = ktimer_softirqd_clr_sched_params,
  15716. + .thread_should_run = ktimer_softirqd_should_run,
  15717. + .thread_fn = run_ksoftirqd,
  15718. + .thread_comm = "ktimersoftd/%u",
  15719. +};
  15720. +#endif
  15721. +
  15722. static __init int spawn_ksoftirqd(void)
  15723. {
  15724. cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
  15725. takeover_tasklets);
  15726. BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
  15727. -
  15728. +#ifdef CONFIG_PREEMPT_RT_FULL
  15729. + BUG_ON(smpboot_register_percpu_thread(&softirq_timer_threads));
  15730. +#endif
  15731. return 0;
  15732. }
  15733. early_initcall(spawn_ksoftirqd);
  15734. diff -Nur linux-4.9.6.orig/kernel/stop_machine.c linux-4.9.6/kernel/stop_machine.c
  15735. --- linux-4.9.6.orig/kernel/stop_machine.c 2017-01-26 08:25:24.000000000 +0100
  15736. +++ linux-4.9.6/kernel/stop_machine.c 2017-01-28 13:59:10.087662182 +0100
  15737. @@ -36,7 +36,7 @@
  15738. struct cpu_stopper {
  15739. struct task_struct *thread;
  15740. - spinlock_t lock;
  15741. + raw_spinlock_t lock;
  15742. bool enabled; /* is this stopper enabled? */
  15743. struct list_head works; /* list of pending works */
  15744. @@ -78,14 +78,14 @@
  15745. unsigned long flags;
  15746. bool enabled;
  15747. - spin_lock_irqsave(&stopper->lock, flags);
  15748. + raw_spin_lock_irqsave(&stopper->lock, flags);
  15749. enabled = stopper->enabled;
  15750. if (enabled)
  15751. __cpu_stop_queue_work(stopper, work);
  15752. else if (work->done)
  15753. cpu_stop_signal_done(work->done);
  15754. - spin_unlock_irqrestore(&stopper->lock, flags);
  15755. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  15756. return enabled;
  15757. }
  15758. @@ -231,8 +231,8 @@
  15759. struct cpu_stopper *stopper2 = per_cpu_ptr(&cpu_stopper, cpu2);
  15760. int err;
  15761. retry:
  15762. - spin_lock_irq(&stopper1->lock);
  15763. - spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  15764. + raw_spin_lock_irq(&stopper1->lock);
  15765. + raw_spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  15766. err = -ENOENT;
  15767. if (!stopper1->enabled || !stopper2->enabled)
  15768. @@ -255,8 +255,8 @@
  15769. __cpu_stop_queue_work(stopper1, work1);
  15770. __cpu_stop_queue_work(stopper2, work2);
  15771. unlock:
  15772. - spin_unlock(&stopper2->lock);
  15773. - spin_unlock_irq(&stopper1->lock);
  15774. + raw_spin_unlock(&stopper2->lock);
  15775. + raw_spin_unlock_irq(&stopper1->lock);
  15776. if (unlikely(err == -EDEADLK)) {
  15777. while (stop_cpus_in_progress)
  15778. @@ -448,9 +448,9 @@
  15779. unsigned long flags;
  15780. int run;
  15781. - spin_lock_irqsave(&stopper->lock, flags);
  15782. + raw_spin_lock_irqsave(&stopper->lock, flags);
  15783. run = !list_empty(&stopper->works);
  15784. - spin_unlock_irqrestore(&stopper->lock, flags);
  15785. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  15786. return run;
  15787. }
  15788. @@ -461,13 +461,13 @@
  15789. repeat:
  15790. work = NULL;
  15791. - spin_lock_irq(&stopper->lock);
  15792. + raw_spin_lock_irq(&stopper->lock);
  15793. if (!list_empty(&stopper->works)) {
  15794. work = list_first_entry(&stopper->works,
  15795. struct cpu_stop_work, list);
  15796. list_del_init(&work->list);
  15797. }
  15798. - spin_unlock_irq(&stopper->lock);
  15799. + raw_spin_unlock_irq(&stopper->lock);
  15800. if (work) {
  15801. cpu_stop_fn_t fn = work->fn;
  15802. @@ -475,6 +475,8 @@
  15803. struct cpu_stop_done *done = work->done;
  15804. int ret;
  15805. + /* XXX */
  15806. +
  15807. /* cpu stop callbacks must not sleep, make in_atomic() == T */
  15808. preempt_count_inc();
  15809. ret = fn(arg);
  15810. @@ -541,7 +543,7 @@
  15811. for_each_possible_cpu(cpu) {
  15812. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  15813. - spin_lock_init(&stopper->lock);
  15814. + raw_spin_lock_init(&stopper->lock);
  15815. INIT_LIST_HEAD(&stopper->works);
  15816. }
  15817. diff -Nur linux-4.9.6.orig/kernel/time/hrtimer.c linux-4.9.6/kernel/time/hrtimer.c
  15818. --- linux-4.9.6.orig/kernel/time/hrtimer.c 2017-01-26 08:25:24.000000000 +0100
  15819. +++ linux-4.9.6/kernel/time/hrtimer.c 2017-01-28 13:59:10.087662182 +0100
  15820. @@ -53,6 +53,7 @@
  15821. #include <asm/uaccess.h>
  15822. #include <trace/events/timer.h>
  15823. +#include <trace/events/hist.h>
  15824. #include "tick-internal.h"
  15825. @@ -695,6 +696,29 @@
  15826. retrigger_next_event(NULL);
  15827. }
  15828. +#ifdef CONFIG_PREEMPT_RT_FULL
  15829. +
  15830. +static struct swork_event clock_set_delay_work;
  15831. +
  15832. +static void run_clock_set_delay(struct swork_event *event)
  15833. +{
  15834. + clock_was_set();
  15835. +}
  15836. +
  15837. +void clock_was_set_delayed(void)
  15838. +{
  15839. + swork_queue(&clock_set_delay_work);
  15840. +}
  15841. +
  15842. +static __init int create_clock_set_delay_thread(void)
  15843. +{
  15844. + WARN_ON(swork_get());
  15845. + INIT_SWORK(&clock_set_delay_work, run_clock_set_delay);
  15846. + return 0;
  15847. +}
  15848. +early_initcall(create_clock_set_delay_thread);
  15849. +#else /* PREEMPT_RT_FULL */
  15850. +
  15851. static void clock_was_set_work(struct work_struct *work)
  15852. {
  15853. clock_was_set();
  15854. @@ -710,6 +734,7 @@
  15855. {
  15856. schedule_work(&hrtimer_work);
  15857. }
  15858. +#endif
  15859. #else
  15860. @@ -719,11 +744,8 @@
  15861. static inline void hrtimer_switch_to_hres(void) { }
  15862. static inline void
  15863. hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
  15864. -static inline int hrtimer_reprogram(struct hrtimer *timer,
  15865. - struct hrtimer_clock_base *base)
  15866. -{
  15867. - return 0;
  15868. -}
  15869. +static inline void hrtimer_reprogram(struct hrtimer *timer,
  15870. + struct hrtimer_clock_base *base) { }
  15871. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  15872. static inline void retrigger_next_event(void *arg) { }
  15873. @@ -855,6 +877,32 @@
  15874. }
  15875. EXPORT_SYMBOL_GPL(hrtimer_forward);
  15876. +#ifdef CONFIG_PREEMPT_RT_BASE
  15877. +# define wake_up_timer_waiters(b) wake_up(&(b)->wait)
  15878. +
  15879. +/**
  15880. + * hrtimer_wait_for_timer - Wait for a running timer
  15881. + *
  15882. + * @timer: timer to wait for
  15883. + *
  15884. + * The function waits in case the timers callback function is
  15885. + * currently executed on the waitqueue of the timer base. The
  15886. + * waitqueue is woken up after the timer callback function has
  15887. + * finished execution.
  15888. + */
  15889. +void hrtimer_wait_for_timer(const struct hrtimer *timer)
  15890. +{
  15891. + struct hrtimer_clock_base *base = timer->base;
  15892. +
  15893. + if (base && base->cpu_base && !timer->irqsafe)
  15894. + wait_event(base->cpu_base->wait,
  15895. + !(hrtimer_callback_running(timer)));
  15896. +}
  15897. +
  15898. +#else
  15899. +# define wake_up_timer_waiters(b) do { } while (0)
  15900. +#endif
  15901. +
  15902. /*
  15903. * enqueue_hrtimer - internal function to (re)start a timer
  15904. *
  15905. @@ -896,6 +944,11 @@
  15906. if (!(state & HRTIMER_STATE_ENQUEUED))
  15907. return;
  15908. + if (unlikely(!list_empty(&timer->cb_entry))) {
  15909. + list_del_init(&timer->cb_entry);
  15910. + return;
  15911. + }
  15912. +
  15913. if (!timerqueue_del(&base->active, &timer->node))
  15914. cpu_base->active_bases &= ~(1 << base->index);
  15915. @@ -991,7 +1044,16 @@
  15916. new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  15917. timer_stats_hrtimer_set_start_info(timer);
  15918. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  15919. + {
  15920. + ktime_t now = new_base->get_time();
  15921. + if (ktime_to_ns(tim) < ktime_to_ns(now))
  15922. + timer->praecox = now;
  15923. + else
  15924. + timer->praecox = ktime_set(0, 0);
  15925. + }
  15926. +#endif
  15927. leftmost = enqueue_hrtimer(timer, new_base);
  15928. if (!leftmost)
  15929. goto unlock;
  15930. @@ -1063,7 +1125,7 @@
  15931. if (ret >= 0)
  15932. return ret;
  15933. - cpu_relax();
  15934. + hrtimer_wait_for_timer(timer);
  15935. }
  15936. }
  15937. EXPORT_SYMBOL_GPL(hrtimer_cancel);
  15938. @@ -1127,6 +1189,7 @@
  15939. base = hrtimer_clockid_to_base(clock_id);
  15940. timer->base = &cpu_base->clock_base[base];
  15941. + INIT_LIST_HEAD(&timer->cb_entry);
  15942. timerqueue_init(&timer->node);
  15943. #ifdef CONFIG_TIMER_STATS
  15944. @@ -1167,6 +1230,7 @@
  15945. seq = raw_read_seqcount_begin(&cpu_base->seq);
  15946. if (timer->state != HRTIMER_STATE_INACTIVE ||
  15947. + cpu_base->running_soft == timer ||
  15948. cpu_base->running == timer)
  15949. return true;
  15950. @@ -1265,10 +1329,112 @@
  15951. cpu_base->running = NULL;
  15952. }
  15953. +#ifdef CONFIG_PREEMPT_RT_BASE
  15954. +static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
  15955. + struct hrtimer_clock_base *base)
  15956. +{
  15957. + int leftmost;
  15958. +
  15959. + if (restart != HRTIMER_NORESTART &&
  15960. + !(timer->state & HRTIMER_STATE_ENQUEUED)) {
  15961. +
  15962. + leftmost = enqueue_hrtimer(timer, base);
  15963. + if (!leftmost)
  15964. + return;
  15965. +#ifdef CONFIG_HIGH_RES_TIMERS
  15966. + if (!hrtimer_is_hres_active(timer)) {
  15967. + /*
  15968. + * Kick to reschedule the next tick to handle the new timer
  15969. + * on dynticks target.
  15970. + */
  15971. + if (base->cpu_base->nohz_active)
  15972. + wake_up_nohz_cpu(base->cpu_base->cpu);
  15973. + } else {
  15974. +
  15975. + hrtimer_reprogram(timer, base);
  15976. + }
  15977. +#endif
  15978. + }
  15979. +}
  15980. +
  15981. +/*
  15982. + * The changes in mainline which removed the callback modes from
  15983. + * hrtimer are not yet working with -rt. The non wakeup_process()
  15984. + * based callbacks which involve sleeping locks need to be treated
  15985. + * seperately.
  15986. + */
  15987. +static void hrtimer_rt_run_pending(void)
  15988. +{
  15989. + enum hrtimer_restart (*fn)(struct hrtimer *);
  15990. + struct hrtimer_cpu_base *cpu_base;
  15991. + struct hrtimer_clock_base *base;
  15992. + struct hrtimer *timer;
  15993. + int index, restart;
  15994. +
  15995. + local_irq_disable();
  15996. + cpu_base = &per_cpu(hrtimer_bases, smp_processor_id());
  15997. +
  15998. + raw_spin_lock(&cpu_base->lock);
  15999. +
  16000. + for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
  16001. + base = &cpu_base->clock_base[index];
  16002. +
  16003. + while (!list_empty(&base->expired)) {
  16004. + timer = list_first_entry(&base->expired,
  16005. + struct hrtimer, cb_entry);
  16006. +
  16007. + /*
  16008. + * Same as the above __run_hrtimer function
  16009. + * just we run with interrupts enabled.
  16010. + */
  16011. + debug_deactivate(timer);
  16012. + cpu_base->running_soft = timer;
  16013. + raw_write_seqcount_barrier(&cpu_base->seq);
  16014. +
  16015. + __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 0);
  16016. + timer_stats_account_hrtimer(timer);
  16017. + fn = timer->function;
  16018. +
  16019. + raw_spin_unlock_irq(&cpu_base->lock);
  16020. + restart = fn(timer);
  16021. + raw_spin_lock_irq(&cpu_base->lock);
  16022. +
  16023. + hrtimer_rt_reprogram(restart, timer, base);
  16024. + raw_write_seqcount_barrier(&cpu_base->seq);
  16025. +
  16026. + WARN_ON_ONCE(cpu_base->running_soft != timer);
  16027. + cpu_base->running_soft = NULL;
  16028. + }
  16029. + }
  16030. +
  16031. + raw_spin_unlock_irq(&cpu_base->lock);
  16032. +
  16033. + wake_up_timer_waiters(cpu_base);
  16034. +}
  16035. +
  16036. +static int hrtimer_rt_defer(struct hrtimer *timer)
  16037. +{
  16038. + if (timer->irqsafe)
  16039. + return 0;
  16040. +
  16041. + __remove_hrtimer(timer, timer->base, timer->state, 0);
  16042. + list_add_tail(&timer->cb_entry, &timer->base->expired);
  16043. + return 1;
  16044. +}
  16045. +
  16046. +#else
  16047. +
  16048. +static inline int hrtimer_rt_defer(struct hrtimer *timer) { return 0; }
  16049. +
  16050. +#endif
  16051. +
  16052. +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
  16053. +
  16054. static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
  16055. {
  16056. struct hrtimer_clock_base *base = cpu_base->clock_base;
  16057. unsigned int active = cpu_base->active_bases;
  16058. + int raise = 0;
  16059. for (; active; base++, active >>= 1) {
  16060. struct timerqueue_node *node;
  16061. @@ -1284,6 +1450,15 @@
  16062. timer = container_of(node, struct hrtimer, node);
  16063. + trace_hrtimer_interrupt(raw_smp_processor_id(),
  16064. + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ?
  16065. + timer->praecox : hrtimer_get_expires(timer),
  16066. + basenow)),
  16067. + current,
  16068. + timer->function == hrtimer_wakeup ?
  16069. + container_of(timer, struct hrtimer_sleeper,
  16070. + timer)->task : NULL);
  16071. +
  16072. /*
  16073. * The immediate goal for using the softexpires is
  16074. * minimizing wakeups, not running timers at the
  16075. @@ -1299,9 +1474,14 @@
  16076. if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer))
  16077. break;
  16078. - __run_hrtimer(cpu_base, base, timer, &basenow);
  16079. + if (!hrtimer_rt_defer(timer))
  16080. + __run_hrtimer(cpu_base, base, timer, &basenow);
  16081. + else
  16082. + raise = 1;
  16083. }
  16084. }
  16085. + if (raise)
  16086. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  16087. }
  16088. #ifdef CONFIG_HIGH_RES_TIMERS
  16089. @@ -1464,16 +1644,18 @@
  16090. void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  16091. {
  16092. sl->timer.function = hrtimer_wakeup;
  16093. + sl->timer.irqsafe = 1;
  16094. sl->task = task;
  16095. }
  16096. EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
  16097. -static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
  16098. +static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode,
  16099. + unsigned long state)
  16100. {
  16101. hrtimer_init_sleeper(t, current);
  16102. do {
  16103. - set_current_state(TASK_INTERRUPTIBLE);
  16104. + set_current_state(state);
  16105. hrtimer_start_expires(&t->timer, mode);
  16106. if (likely(t->task))
  16107. @@ -1515,7 +1697,8 @@
  16108. HRTIMER_MODE_ABS);
  16109. hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  16110. - if (do_nanosleep(&t, HRTIMER_MODE_ABS))
  16111. + /* cpu_chill() does not care about restart state. */
  16112. + if (do_nanosleep(&t, HRTIMER_MODE_ABS, TASK_INTERRUPTIBLE))
  16113. goto out;
  16114. rmtp = restart->nanosleep.rmtp;
  16115. @@ -1532,8 +1715,10 @@
  16116. return ret;
  16117. }
  16118. -long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  16119. - const enum hrtimer_mode mode, const clockid_t clockid)
  16120. +static long
  16121. +__hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  16122. + const enum hrtimer_mode mode, const clockid_t clockid,
  16123. + unsigned long state)
  16124. {
  16125. struct restart_block *restart;
  16126. struct hrtimer_sleeper t;
  16127. @@ -1546,7 +1731,7 @@
  16128. hrtimer_init_on_stack(&t.timer, clockid, mode);
  16129. hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
  16130. - if (do_nanosleep(&t, mode))
  16131. + if (do_nanosleep(&t, mode, state))
  16132. goto out;
  16133. /* Absolute timers do not update the rmtp value and restart: */
  16134. @@ -1573,6 +1758,12 @@
  16135. return ret;
  16136. }
  16137. +long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  16138. + const enum hrtimer_mode mode, const clockid_t clockid)
  16139. +{
  16140. + return __hrtimer_nanosleep(rqtp, rmtp, mode, clockid, TASK_INTERRUPTIBLE);
  16141. +}
  16142. +
  16143. SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
  16144. struct timespec __user *, rmtp)
  16145. {
  16146. @@ -1587,6 +1778,26 @@
  16147. return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  16148. }
  16149. +#ifdef CONFIG_PREEMPT_RT_FULL
  16150. +/*
  16151. + * Sleep for 1 ms in hope whoever holds what we want will let it go.
  16152. + */
  16153. +void cpu_chill(void)
  16154. +{
  16155. + struct timespec tu = {
  16156. + .tv_nsec = NSEC_PER_MSEC,
  16157. + };
  16158. + unsigned int freeze_flag = current->flags & PF_NOFREEZE;
  16159. +
  16160. + current->flags |= PF_NOFREEZE;
  16161. + __hrtimer_nanosleep(&tu, NULL, HRTIMER_MODE_REL, CLOCK_MONOTONIC,
  16162. + TASK_UNINTERRUPTIBLE);
  16163. + if (!freeze_flag)
  16164. + current->flags &= ~PF_NOFREEZE;
  16165. +}
  16166. +EXPORT_SYMBOL(cpu_chill);
  16167. +#endif
  16168. +
  16169. /*
  16170. * Functions related to boot-time initialization:
  16171. */
  16172. @@ -1598,10 +1809,14 @@
  16173. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  16174. cpu_base->clock_base[i].cpu_base = cpu_base;
  16175. timerqueue_init_head(&cpu_base->clock_base[i].active);
  16176. + INIT_LIST_HEAD(&cpu_base->clock_base[i].expired);
  16177. }
  16178. cpu_base->cpu = cpu;
  16179. hrtimer_init_hres(cpu_base);
  16180. +#ifdef CONFIG_PREEMPT_RT_BASE
  16181. + init_waitqueue_head(&cpu_base->wait);
  16182. +#endif
  16183. return 0;
  16184. }
  16185. @@ -1671,9 +1886,26 @@
  16186. #endif /* CONFIG_HOTPLUG_CPU */
  16187. +#ifdef CONFIG_PREEMPT_RT_BASE
  16188. +
  16189. +static void run_hrtimer_softirq(struct softirq_action *h)
  16190. +{
  16191. + hrtimer_rt_run_pending();
  16192. +}
  16193. +
  16194. +static void hrtimers_open_softirq(void)
  16195. +{
  16196. + open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
  16197. +}
  16198. +
  16199. +#else
  16200. +static void hrtimers_open_softirq(void) { }
  16201. +#endif
  16202. +
  16203. void __init hrtimers_init(void)
  16204. {
  16205. hrtimers_prepare_cpu(smp_processor_id());
  16206. + hrtimers_open_softirq();
  16207. }
  16208. /**
  16209. diff -Nur linux-4.9.6.orig/kernel/time/itimer.c linux-4.9.6/kernel/time/itimer.c
  16210. --- linux-4.9.6.orig/kernel/time/itimer.c 2017-01-26 08:25:24.000000000 +0100
  16211. +++ linux-4.9.6/kernel/time/itimer.c 2017-01-28 13:59:10.087662182 +0100
  16212. @@ -213,6 +213,7 @@
  16213. /* We are sharing ->siglock with it_real_fn() */
  16214. if (hrtimer_try_to_cancel(timer) < 0) {
  16215. spin_unlock_irq(&tsk->sighand->siglock);
  16216. + hrtimer_wait_for_timer(&tsk->signal->real_timer);
  16217. goto again;
  16218. }
  16219. expires = timeval_to_ktime(value->it_value);
  16220. diff -Nur linux-4.9.6.orig/kernel/time/jiffies.c linux-4.9.6/kernel/time/jiffies.c
  16221. --- linux-4.9.6.orig/kernel/time/jiffies.c 2017-01-26 08:25:24.000000000 +0100
  16222. +++ linux-4.9.6/kernel/time/jiffies.c 2017-01-28 13:59:10.087662182 +0100
  16223. @@ -74,7 +74,8 @@
  16224. .max_cycles = 10,
  16225. };
  16226. -__cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock);
  16227. +__cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(jiffies_lock);
  16228. +__cacheline_aligned_in_smp seqcount_t jiffies_seq;
  16229. #if (BITS_PER_LONG < 64)
  16230. u64 get_jiffies_64(void)
  16231. @@ -83,9 +84,9 @@
  16232. u64 ret;
  16233. do {
  16234. - seq = read_seqbegin(&jiffies_lock);
  16235. + seq = read_seqcount_begin(&jiffies_seq);
  16236. ret = jiffies_64;
  16237. - } while (read_seqretry(&jiffies_lock, seq));
  16238. + } while (read_seqcount_retry(&jiffies_seq, seq));
  16239. return ret;
  16240. }
  16241. EXPORT_SYMBOL(get_jiffies_64);
  16242. diff -Nur linux-4.9.6.orig/kernel/time/ntp.c linux-4.9.6/kernel/time/ntp.c
  16243. --- linux-4.9.6.orig/kernel/time/ntp.c 2017-01-26 08:25:24.000000000 +0100
  16244. +++ linux-4.9.6/kernel/time/ntp.c 2017-01-28 13:59:10.087662182 +0100
  16245. @@ -17,6 +17,7 @@
  16246. #include <linux/module.h>
  16247. #include <linux/rtc.h>
  16248. #include <linux/math64.h>
  16249. +#include <linux/swork.h>
  16250. #include "ntp_internal.h"
  16251. #include "timekeeping_internal.h"
  16252. @@ -568,10 +569,35 @@
  16253. &sync_cmos_work, timespec64_to_jiffies(&next));
  16254. }
  16255. +#ifdef CONFIG_PREEMPT_RT_FULL
  16256. +
  16257. +static void run_clock_set_delay(struct swork_event *event)
  16258. +{
  16259. + queue_delayed_work(system_power_efficient_wq, &sync_cmos_work, 0);
  16260. +}
  16261. +
  16262. +static struct swork_event ntp_cmos_swork;
  16263. +
  16264. +void ntp_notify_cmos_timer(void)
  16265. +{
  16266. + swork_queue(&ntp_cmos_swork);
  16267. +}
  16268. +
  16269. +static __init int create_cmos_delay_thread(void)
  16270. +{
  16271. + WARN_ON(swork_get());
  16272. + INIT_SWORK(&ntp_cmos_swork, run_clock_set_delay);
  16273. + return 0;
  16274. +}
  16275. +early_initcall(create_cmos_delay_thread);
  16276. +
  16277. +#else
  16278. +
  16279. void ntp_notify_cmos_timer(void)
  16280. {
  16281. queue_delayed_work(system_power_efficient_wq, &sync_cmos_work, 0);
  16282. }
  16283. +#endif /* CONFIG_PREEMPT_RT_FULL */
  16284. #else
  16285. void ntp_notify_cmos_timer(void) { }
  16286. diff -Nur linux-4.9.6.orig/kernel/time/posix-cpu-timers.c linux-4.9.6/kernel/time/posix-cpu-timers.c
  16287. --- linux-4.9.6.orig/kernel/time/posix-cpu-timers.c 2017-01-26 08:25:24.000000000 +0100
  16288. +++ linux-4.9.6/kernel/time/posix-cpu-timers.c 2017-01-28 13:59:10.087662182 +0100
  16289. @@ -3,6 +3,7 @@
  16290. */
  16291. #include <linux/sched.h>
  16292. +#include <linux/sched/rt.h>
  16293. #include <linux/posix-timers.h>
  16294. #include <linux/errno.h>
  16295. #include <linux/math64.h>
  16296. @@ -620,7 +621,7 @@
  16297. /*
  16298. * Disarm any old timer after extracting its expiry time.
  16299. */
  16300. - WARN_ON_ONCE(!irqs_disabled());
  16301. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  16302. ret = 0;
  16303. old_incr = timer->it.cpu.incr;
  16304. @@ -1064,7 +1065,7 @@
  16305. /*
  16306. * Now re-arm for the new expiry time.
  16307. */
  16308. - WARN_ON_ONCE(!irqs_disabled());
  16309. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  16310. arm_timer(timer);
  16311. unlock_task_sighand(p, &flags);
  16312. @@ -1153,13 +1154,13 @@
  16313. * already updated our counts. We need to check if any timers fire now.
  16314. * Interrupts are disabled.
  16315. */
  16316. -void run_posix_cpu_timers(struct task_struct *tsk)
  16317. +static void __run_posix_cpu_timers(struct task_struct *tsk)
  16318. {
  16319. LIST_HEAD(firing);
  16320. struct k_itimer *timer, *next;
  16321. unsigned long flags;
  16322. - WARN_ON_ONCE(!irqs_disabled());
  16323. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  16324. /*
  16325. * The fast path checks that there are no expired thread or thread
  16326. @@ -1213,6 +1214,190 @@
  16327. }
  16328. }
  16329. +#ifdef CONFIG_PREEMPT_RT_BASE
  16330. +#include <linux/kthread.h>
  16331. +#include <linux/cpu.h>
  16332. +DEFINE_PER_CPU(struct task_struct *, posix_timer_task);
  16333. +DEFINE_PER_CPU(struct task_struct *, posix_timer_tasklist);
  16334. +
  16335. +static int posix_cpu_timers_thread(void *data)
  16336. +{
  16337. + int cpu = (long)data;
  16338. +
  16339. + BUG_ON(per_cpu(posix_timer_task,cpu) != current);
  16340. +
  16341. + while (!kthread_should_stop()) {
  16342. + struct task_struct *tsk = NULL;
  16343. + struct task_struct *next = NULL;
  16344. +
  16345. + if (cpu_is_offline(cpu))
  16346. + goto wait_to_die;
  16347. +
  16348. + /* grab task list */
  16349. + raw_local_irq_disable();
  16350. + tsk = per_cpu(posix_timer_tasklist, cpu);
  16351. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  16352. + raw_local_irq_enable();
  16353. +
  16354. + /* its possible the list is empty, just return */
  16355. + if (!tsk) {
  16356. + set_current_state(TASK_INTERRUPTIBLE);
  16357. + schedule();
  16358. + __set_current_state(TASK_RUNNING);
  16359. + continue;
  16360. + }
  16361. +
  16362. + /* Process task list */
  16363. + while (1) {
  16364. + /* save next */
  16365. + next = tsk->posix_timer_list;
  16366. +
  16367. + /* run the task timers, clear its ptr and
  16368. + * unreference it
  16369. + */
  16370. + __run_posix_cpu_timers(tsk);
  16371. + tsk->posix_timer_list = NULL;
  16372. + put_task_struct(tsk);
  16373. +
  16374. + /* check if this is the last on the list */
  16375. + if (next == tsk)
  16376. + break;
  16377. + tsk = next;
  16378. + }
  16379. + }
  16380. + return 0;
  16381. +
  16382. +wait_to_die:
  16383. + /* Wait for kthread_stop */
  16384. + set_current_state(TASK_INTERRUPTIBLE);
  16385. + while (!kthread_should_stop()) {
  16386. + schedule();
  16387. + set_current_state(TASK_INTERRUPTIBLE);
  16388. + }
  16389. + __set_current_state(TASK_RUNNING);
  16390. + return 0;
  16391. +}
  16392. +
  16393. +static inline int __fastpath_timer_check(struct task_struct *tsk)
  16394. +{
  16395. + /* tsk == current, ensure it is safe to use ->signal/sighand */
  16396. + if (unlikely(tsk->exit_state))
  16397. + return 0;
  16398. +
  16399. + if (!task_cputime_zero(&tsk->cputime_expires))
  16400. + return 1;
  16401. +
  16402. + if (!task_cputime_zero(&tsk->signal->cputime_expires))
  16403. + return 1;
  16404. +
  16405. + return 0;
  16406. +}
  16407. +
  16408. +void run_posix_cpu_timers(struct task_struct *tsk)
  16409. +{
  16410. + unsigned long cpu = smp_processor_id();
  16411. + struct task_struct *tasklist;
  16412. +
  16413. + BUG_ON(!irqs_disabled());
  16414. + if(!per_cpu(posix_timer_task, cpu))
  16415. + return;
  16416. + /* get per-cpu references */
  16417. + tasklist = per_cpu(posix_timer_tasklist, cpu);
  16418. +
  16419. + /* check to see if we're already queued */
  16420. + if (!tsk->posix_timer_list && __fastpath_timer_check(tsk)) {
  16421. + get_task_struct(tsk);
  16422. + if (tasklist) {
  16423. + tsk->posix_timer_list = tasklist;
  16424. + } else {
  16425. + /*
  16426. + * The list is terminated by a self-pointing
  16427. + * task_struct
  16428. + */
  16429. + tsk->posix_timer_list = tsk;
  16430. + }
  16431. + per_cpu(posix_timer_tasklist, cpu) = tsk;
  16432. +
  16433. + wake_up_process(per_cpu(posix_timer_task, cpu));
  16434. + }
  16435. +}
  16436. +
  16437. +/*
  16438. + * posix_cpu_thread_call - callback that gets triggered when a CPU is added.
  16439. + * Here we can start up the necessary migration thread for the new CPU.
  16440. + */
  16441. +static int posix_cpu_thread_call(struct notifier_block *nfb,
  16442. + unsigned long action, void *hcpu)
  16443. +{
  16444. + int cpu = (long)hcpu;
  16445. + struct task_struct *p;
  16446. + struct sched_param param;
  16447. +
  16448. + switch (action) {
  16449. + case CPU_UP_PREPARE:
  16450. + p = kthread_create(posix_cpu_timers_thread, hcpu,
  16451. + "posixcputmr/%d",cpu);
  16452. + if (IS_ERR(p))
  16453. + return NOTIFY_BAD;
  16454. + p->flags |= PF_NOFREEZE;
  16455. + kthread_bind(p, cpu);
  16456. + /* Must be high prio to avoid getting starved */
  16457. + param.sched_priority = MAX_RT_PRIO-1;
  16458. + sched_setscheduler(p, SCHED_FIFO, &param);
  16459. + per_cpu(posix_timer_task,cpu) = p;
  16460. + break;
  16461. + case CPU_ONLINE:
  16462. + /* Strictly unneccessary, as first user will wake it. */
  16463. + wake_up_process(per_cpu(posix_timer_task,cpu));
  16464. + break;
  16465. +#ifdef CONFIG_HOTPLUG_CPU
  16466. + case CPU_UP_CANCELED:
  16467. + /* Unbind it from offline cpu so it can run. Fall thru. */
  16468. + kthread_bind(per_cpu(posix_timer_task, cpu),
  16469. + cpumask_any(cpu_online_mask));
  16470. + kthread_stop(per_cpu(posix_timer_task,cpu));
  16471. + per_cpu(posix_timer_task,cpu) = NULL;
  16472. + break;
  16473. + case CPU_DEAD:
  16474. + kthread_stop(per_cpu(posix_timer_task,cpu));
  16475. + per_cpu(posix_timer_task,cpu) = NULL;
  16476. + break;
  16477. +#endif
  16478. + }
  16479. + return NOTIFY_OK;
  16480. +}
  16481. +
  16482. +/* Register at highest priority so that task migration (migrate_all_tasks)
  16483. + * happens before everything else.
  16484. + */
  16485. +static struct notifier_block posix_cpu_thread_notifier = {
  16486. + .notifier_call = posix_cpu_thread_call,
  16487. + .priority = 10
  16488. +};
  16489. +
  16490. +static int __init posix_cpu_thread_init(void)
  16491. +{
  16492. + void *hcpu = (void *)(long)smp_processor_id();
  16493. + /* Start one for boot CPU. */
  16494. + unsigned long cpu;
  16495. +
  16496. + /* init the per-cpu posix_timer_tasklets */
  16497. + for_each_possible_cpu(cpu)
  16498. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  16499. +
  16500. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_UP_PREPARE, hcpu);
  16501. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_ONLINE, hcpu);
  16502. + register_cpu_notifier(&posix_cpu_thread_notifier);
  16503. + return 0;
  16504. +}
  16505. +early_initcall(posix_cpu_thread_init);
  16506. +#else /* CONFIG_PREEMPT_RT_BASE */
  16507. +void run_posix_cpu_timers(struct task_struct *tsk)
  16508. +{
  16509. + __run_posix_cpu_timers(tsk);
  16510. +}
  16511. +#endif /* CONFIG_PREEMPT_RT_BASE */
  16512. +
  16513. /*
  16514. * Set one of the process-wide special case CPU timers or RLIMIT_CPU.
  16515. * The tsk->sighand->siglock must be held by the caller.
  16516. diff -Nur linux-4.9.6.orig/kernel/time/posix-timers.c linux-4.9.6/kernel/time/posix-timers.c
  16517. --- linux-4.9.6.orig/kernel/time/posix-timers.c 2017-01-26 08:25:24.000000000 +0100
  16518. +++ linux-4.9.6/kernel/time/posix-timers.c 2017-01-28 13:59:10.087662182 +0100
  16519. @@ -506,6 +506,7 @@
  16520. static struct pid *good_sigevent(sigevent_t * event)
  16521. {
  16522. struct task_struct *rtn = current->group_leader;
  16523. + int sig = event->sigev_signo;
  16524. if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
  16525. (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
  16526. @@ -514,7 +515,8 @@
  16527. return NULL;
  16528. if (((event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) &&
  16529. - ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
  16530. + (sig <= 0 || sig > SIGRTMAX || sig_kernel_only(sig) ||
  16531. + sig_kernel_coredump(sig)))
  16532. return NULL;
  16533. return task_pid(rtn);
  16534. @@ -826,6 +828,20 @@
  16535. return overrun;
  16536. }
  16537. +/*
  16538. + * Protected by RCU!
  16539. + */
  16540. +static void timer_wait_for_callback(struct k_clock *kc, struct k_itimer *timr)
  16541. +{
  16542. +#ifdef CONFIG_PREEMPT_RT_FULL
  16543. + if (kc->timer_set == common_timer_set)
  16544. + hrtimer_wait_for_timer(&timr->it.real.timer);
  16545. + else
  16546. + /* FIXME: Whacky hack for posix-cpu-timers */
  16547. + schedule_timeout(1);
  16548. +#endif
  16549. +}
  16550. +
  16551. /* Set a POSIX.1b interval timer. */
  16552. /* timr->it_lock is taken. */
  16553. static int
  16554. @@ -903,6 +919,7 @@
  16555. if (!timr)
  16556. return -EINVAL;
  16557. + rcu_read_lock();
  16558. kc = clockid_to_kclock(timr->it_clock);
  16559. if (WARN_ON_ONCE(!kc || !kc->timer_set))
  16560. error = -EINVAL;
  16561. @@ -911,9 +928,12 @@
  16562. unlock_timer(timr, flag);
  16563. if (error == TIMER_RETRY) {
  16564. + timer_wait_for_callback(kc, timr);
  16565. rtn = NULL; // We already got the old time...
  16566. + rcu_read_unlock();
  16567. goto retry;
  16568. }
  16569. + rcu_read_unlock();
  16570. if (old_setting && !error &&
  16571. copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
  16572. @@ -951,10 +971,15 @@
  16573. if (!timer)
  16574. return -EINVAL;
  16575. + rcu_read_lock();
  16576. if (timer_delete_hook(timer) == TIMER_RETRY) {
  16577. unlock_timer(timer, flags);
  16578. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  16579. + timer);
  16580. + rcu_read_unlock();
  16581. goto retry_delete;
  16582. }
  16583. + rcu_read_unlock();
  16584. spin_lock(&current->sighand->siglock);
  16585. list_del(&timer->list);
  16586. @@ -980,8 +1005,18 @@
  16587. retry_delete:
  16588. spin_lock_irqsave(&timer->it_lock, flags);
  16589. + /* On RT we can race with a deletion */
  16590. + if (!timer->it_signal) {
  16591. + unlock_timer(timer, flags);
  16592. + return;
  16593. + }
  16594. +
  16595. if (timer_delete_hook(timer) == TIMER_RETRY) {
  16596. + rcu_read_lock();
  16597. unlock_timer(timer, flags);
  16598. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  16599. + timer);
  16600. + rcu_read_unlock();
  16601. goto retry_delete;
  16602. }
  16603. list_del(&timer->list);
  16604. diff -Nur linux-4.9.6.orig/kernel/time/tick-broadcast-hrtimer.c linux-4.9.6/kernel/time/tick-broadcast-hrtimer.c
  16605. --- linux-4.9.6.orig/kernel/time/tick-broadcast-hrtimer.c 2017-01-26 08:25:24.000000000 +0100
  16606. +++ linux-4.9.6/kernel/time/tick-broadcast-hrtimer.c 2017-01-28 13:59:10.087662182 +0100
  16607. @@ -107,5 +107,6 @@
  16608. {
  16609. hrtimer_init(&bctimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  16610. bctimer.function = bc_handler;
  16611. + bctimer.irqsafe = true;
  16612. clockevents_register_device(&ce_broadcast_hrtimer);
  16613. }
  16614. diff -Nur linux-4.9.6.orig/kernel/time/tick-common.c linux-4.9.6/kernel/time/tick-common.c
  16615. --- linux-4.9.6.orig/kernel/time/tick-common.c 2017-01-26 08:25:24.000000000 +0100
  16616. +++ linux-4.9.6/kernel/time/tick-common.c 2017-01-28 13:59:10.087662182 +0100
  16617. @@ -79,13 +79,15 @@
  16618. static void tick_periodic(int cpu)
  16619. {
  16620. if (tick_do_timer_cpu == cpu) {
  16621. - write_seqlock(&jiffies_lock);
  16622. + raw_spin_lock(&jiffies_lock);
  16623. + write_seqcount_begin(&jiffies_seq);
  16624. /* Keep track of the next tick event */
  16625. tick_next_period = ktime_add(tick_next_period, tick_period);
  16626. do_timer(1);
  16627. - write_sequnlock(&jiffies_lock);
  16628. + write_seqcount_end(&jiffies_seq);
  16629. + raw_spin_unlock(&jiffies_lock);
  16630. update_wall_time();
  16631. }
  16632. @@ -157,9 +159,9 @@
  16633. ktime_t next;
  16634. do {
  16635. - seq = read_seqbegin(&jiffies_lock);
  16636. + seq = read_seqcount_begin(&jiffies_seq);
  16637. next = tick_next_period;
  16638. - } while (read_seqretry(&jiffies_lock, seq));
  16639. + } while (read_seqcount_retry(&jiffies_seq, seq));
  16640. clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
  16641. diff -Nur linux-4.9.6.orig/kernel/time/tick-sched.c linux-4.9.6/kernel/time/tick-sched.c
  16642. --- linux-4.9.6.orig/kernel/time/tick-sched.c 2017-01-26 08:25:24.000000000 +0100
  16643. +++ linux-4.9.6/kernel/time/tick-sched.c 2017-01-28 13:59:10.087662182 +0100
  16644. @@ -62,7 +62,8 @@
  16645. return;
  16646. /* Reevaluate with jiffies_lock held */
  16647. - write_seqlock(&jiffies_lock);
  16648. + raw_spin_lock(&jiffies_lock);
  16649. + write_seqcount_begin(&jiffies_seq);
  16650. delta = ktime_sub(now, last_jiffies_update);
  16651. if (delta.tv64 >= tick_period.tv64) {
  16652. @@ -85,10 +86,12 @@
  16653. /* Keep the tick_next_period variable up to date */
  16654. tick_next_period = ktime_add(last_jiffies_update, tick_period);
  16655. } else {
  16656. - write_sequnlock(&jiffies_lock);
  16657. + write_seqcount_end(&jiffies_seq);
  16658. + raw_spin_unlock(&jiffies_lock);
  16659. return;
  16660. }
  16661. - write_sequnlock(&jiffies_lock);
  16662. + write_seqcount_end(&jiffies_seq);
  16663. + raw_spin_unlock(&jiffies_lock);
  16664. update_wall_time();
  16665. }
  16666. @@ -99,12 +102,14 @@
  16667. {
  16668. ktime_t period;
  16669. - write_seqlock(&jiffies_lock);
  16670. + raw_spin_lock(&jiffies_lock);
  16671. + write_seqcount_begin(&jiffies_seq);
  16672. /* Did we start the jiffies update yet ? */
  16673. if (last_jiffies_update.tv64 == 0)
  16674. last_jiffies_update = tick_next_period;
  16675. period = last_jiffies_update;
  16676. - write_sequnlock(&jiffies_lock);
  16677. + write_seqcount_end(&jiffies_seq);
  16678. + raw_spin_unlock(&jiffies_lock);
  16679. return period;
  16680. }
  16681. @@ -215,6 +220,7 @@
  16682. static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = {
  16683. .func = nohz_full_kick_func,
  16684. + .flags = IRQ_WORK_HARD_IRQ,
  16685. };
  16686. /*
  16687. @@ -673,10 +679,10 @@
  16688. /* Read jiffies and the time when jiffies were updated last */
  16689. do {
  16690. - seq = read_seqbegin(&jiffies_lock);
  16691. + seq = read_seqcount_begin(&jiffies_seq);
  16692. basemono = last_jiffies_update.tv64;
  16693. basejiff = jiffies;
  16694. - } while (read_seqretry(&jiffies_lock, seq));
  16695. + } while (read_seqcount_retry(&jiffies_seq, seq));
  16696. ts->last_jiffies = basejiff;
  16697. if (rcu_needs_cpu(basemono, &next_rcu) ||
  16698. @@ -877,14 +883,7 @@
  16699. return false;
  16700. if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
  16701. - static int ratelimit;
  16702. -
  16703. - if (ratelimit < 10 &&
  16704. - (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  16705. - pr_warn("NOHZ: local_softirq_pending %02x\n",
  16706. - (unsigned int) local_softirq_pending());
  16707. - ratelimit++;
  16708. - }
  16709. + softirq_check_pending_idle();
  16710. return false;
  16711. }
  16712. @@ -1193,6 +1192,7 @@
  16713. * Emulate tick processing via per-CPU hrtimers:
  16714. */
  16715. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  16716. + ts->sched_timer.irqsafe = 1;
  16717. ts->sched_timer.function = tick_sched_timer;
  16718. /* Get the next period (per-CPU) */
  16719. diff -Nur linux-4.9.6.orig/kernel/time/timekeeping.c linux-4.9.6/kernel/time/timekeeping.c
  16720. --- linux-4.9.6.orig/kernel/time/timekeeping.c 2017-01-26 08:25:24.000000000 +0100
  16721. +++ linux-4.9.6/kernel/time/timekeeping.c 2017-01-28 13:59:10.087662182 +0100
  16722. @@ -2328,8 +2328,10 @@
  16723. */
  16724. void xtime_update(unsigned long ticks)
  16725. {
  16726. - write_seqlock(&jiffies_lock);
  16727. + raw_spin_lock(&jiffies_lock);
  16728. + write_seqcount_begin(&jiffies_seq);
  16729. do_timer(ticks);
  16730. - write_sequnlock(&jiffies_lock);
  16731. + write_seqcount_end(&jiffies_seq);
  16732. + raw_spin_unlock(&jiffies_lock);
  16733. update_wall_time();
  16734. }
  16735. diff -Nur linux-4.9.6.orig/kernel/time/timekeeping.h linux-4.9.6/kernel/time/timekeeping.h
  16736. --- linux-4.9.6.orig/kernel/time/timekeeping.h 2017-01-26 08:25:24.000000000 +0100
  16737. +++ linux-4.9.6/kernel/time/timekeeping.h 2017-01-28 13:59:10.087662182 +0100
  16738. @@ -19,7 +19,8 @@
  16739. extern void do_timer(unsigned long ticks);
  16740. extern void update_wall_time(void);
  16741. -extern seqlock_t jiffies_lock;
  16742. +extern raw_spinlock_t jiffies_lock;
  16743. +extern seqcount_t jiffies_seq;
  16744. #define CS_NAME_LEN 32
  16745. diff -Nur linux-4.9.6.orig/kernel/time/timer.c linux-4.9.6/kernel/time/timer.c
  16746. --- linux-4.9.6.orig/kernel/time/timer.c 2017-01-26 08:25:24.000000000 +0100
  16747. +++ linux-4.9.6/kernel/time/timer.c 2017-01-28 13:59:10.087662182 +0100
  16748. @@ -193,8 +193,11 @@
  16749. #endif
  16750. struct timer_base {
  16751. - spinlock_t lock;
  16752. + raw_spinlock_t lock;
  16753. struct timer_list *running_timer;
  16754. +#ifdef CONFIG_PREEMPT_RT_FULL
  16755. + struct swait_queue_head wait_for_running_timer;
  16756. +#endif
  16757. unsigned long clk;
  16758. unsigned long next_expiry;
  16759. unsigned int cpu;
  16760. @@ -948,10 +951,10 @@
  16761. if (!(tf & TIMER_MIGRATING)) {
  16762. base = get_timer_base(tf);
  16763. - spin_lock_irqsave(&base->lock, *flags);
  16764. + raw_spin_lock_irqsave(&base->lock, *flags);
  16765. if (timer->flags == tf)
  16766. return base;
  16767. - spin_unlock_irqrestore(&base->lock, *flags);
  16768. + raw_spin_unlock_irqrestore(&base->lock, *flags);
  16769. }
  16770. cpu_relax();
  16771. }
  16772. @@ -1023,9 +1026,9 @@
  16773. /* See the comment in lock_timer_base() */
  16774. timer->flags |= TIMER_MIGRATING;
  16775. - spin_unlock(&base->lock);
  16776. + raw_spin_unlock(&base->lock);
  16777. base = new_base;
  16778. - spin_lock(&base->lock);
  16779. + raw_spin_lock(&base->lock);
  16780. WRITE_ONCE(timer->flags,
  16781. (timer->flags & ~TIMER_BASEMASK) | base->cpu);
  16782. }
  16783. @@ -1050,7 +1053,7 @@
  16784. }
  16785. out_unlock:
  16786. - spin_unlock_irqrestore(&base->lock, flags);
  16787. + raw_spin_unlock_irqrestore(&base->lock, flags);
  16788. return ret;
  16789. }
  16790. @@ -1144,19 +1147,46 @@
  16791. if (base != new_base) {
  16792. timer->flags |= TIMER_MIGRATING;
  16793. - spin_unlock(&base->lock);
  16794. + raw_spin_unlock(&base->lock);
  16795. base = new_base;
  16796. - spin_lock(&base->lock);
  16797. + raw_spin_lock(&base->lock);
  16798. WRITE_ONCE(timer->flags,
  16799. (timer->flags & ~TIMER_BASEMASK) | cpu);
  16800. }
  16801. debug_activate(timer, timer->expires);
  16802. internal_add_timer(base, timer);
  16803. - spin_unlock_irqrestore(&base->lock, flags);
  16804. + raw_spin_unlock_irqrestore(&base->lock, flags);
  16805. }
  16806. EXPORT_SYMBOL_GPL(add_timer_on);
  16807. +#ifdef CONFIG_PREEMPT_RT_FULL
  16808. +/*
  16809. + * Wait for a running timer
  16810. + */
  16811. +static void wait_for_running_timer(struct timer_list *timer)
  16812. +{
  16813. + struct timer_base *base;
  16814. + u32 tf = timer->flags;
  16815. +
  16816. + if (tf & TIMER_MIGRATING)
  16817. + return;
  16818. +
  16819. + base = get_timer_base(tf);
  16820. + swait_event(base->wait_for_running_timer,
  16821. + base->running_timer != timer);
  16822. +}
  16823. +
  16824. +# define wakeup_timer_waiters(b) swake_up_all(&(b)->wait_for_running_timer)
  16825. +#else
  16826. +static inline void wait_for_running_timer(struct timer_list *timer)
  16827. +{
  16828. + cpu_relax();
  16829. +}
  16830. +
  16831. +# define wakeup_timer_waiters(b) do { } while (0)
  16832. +#endif
  16833. +
  16834. /**
  16835. * del_timer - deactive a timer.
  16836. * @timer: the timer to be deactivated
  16837. @@ -1180,7 +1210,7 @@
  16838. if (timer_pending(timer)) {
  16839. base = lock_timer_base(timer, &flags);
  16840. ret = detach_if_pending(timer, base, true);
  16841. - spin_unlock_irqrestore(&base->lock, flags);
  16842. + raw_spin_unlock_irqrestore(&base->lock, flags);
  16843. }
  16844. return ret;
  16845. @@ -1208,13 +1238,13 @@
  16846. timer_stats_timer_clear_start_info(timer);
  16847. ret = detach_if_pending(timer, base, true);
  16848. }
  16849. - spin_unlock_irqrestore(&base->lock, flags);
  16850. + raw_spin_unlock_irqrestore(&base->lock, flags);
  16851. return ret;
  16852. }
  16853. EXPORT_SYMBOL(try_to_del_timer_sync);
  16854. -#ifdef CONFIG_SMP
  16855. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  16856. /**
  16857. * del_timer_sync - deactivate a timer and wait for the handler to finish.
  16858. * @timer: the timer to be deactivated
  16859. @@ -1274,7 +1304,7 @@
  16860. int ret = try_to_del_timer_sync(timer);
  16861. if (ret >= 0)
  16862. return ret;
  16863. - cpu_relax();
  16864. + wait_for_running_timer(timer);
  16865. }
  16866. }
  16867. EXPORT_SYMBOL(del_timer_sync);
  16868. @@ -1339,14 +1369,17 @@
  16869. fn = timer->function;
  16870. data = timer->data;
  16871. - if (timer->flags & TIMER_IRQSAFE) {
  16872. - spin_unlock(&base->lock);
  16873. + if (!IS_ENABLED(CONFIG_PREEMPT_RT_FULL) &&
  16874. + timer->flags & TIMER_IRQSAFE) {
  16875. + raw_spin_unlock(&base->lock);
  16876. call_timer_fn(timer, fn, data);
  16877. - spin_lock(&base->lock);
  16878. + base->running_timer = NULL;
  16879. + raw_spin_lock(&base->lock);
  16880. } else {
  16881. - spin_unlock_irq(&base->lock);
  16882. + raw_spin_unlock_irq(&base->lock);
  16883. call_timer_fn(timer, fn, data);
  16884. - spin_lock_irq(&base->lock);
  16885. + base->running_timer = NULL;
  16886. + raw_spin_lock_irq(&base->lock);
  16887. }
  16888. }
  16889. }
  16890. @@ -1515,7 +1548,7 @@
  16891. if (cpu_is_offline(smp_processor_id()))
  16892. return expires;
  16893. - spin_lock(&base->lock);
  16894. + raw_spin_lock(&base->lock);
  16895. nextevt = __next_timer_interrupt(base);
  16896. is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
  16897. base->next_expiry = nextevt;
  16898. @@ -1543,7 +1576,7 @@
  16899. if ((expires - basem) > TICK_NSEC)
  16900. base->is_idle = true;
  16901. }
  16902. - spin_unlock(&base->lock);
  16903. + raw_spin_unlock(&base->lock);
  16904. return cmp_next_hrtimer_event(basem, expires);
  16905. }
  16906. @@ -1608,13 +1641,13 @@
  16907. /* Note: this timer irq context must be accounted for as well. */
  16908. account_process_tick(p, user_tick);
  16909. + scheduler_tick();
  16910. run_local_timers();
  16911. rcu_check_callbacks(user_tick);
  16912. -#ifdef CONFIG_IRQ_WORK
  16913. +#if defined(CONFIG_IRQ_WORK)
  16914. if (in_irq())
  16915. irq_work_tick();
  16916. #endif
  16917. - scheduler_tick();
  16918. run_posix_cpu_timers(p);
  16919. }
  16920. @@ -1630,7 +1663,7 @@
  16921. if (!time_after_eq(jiffies, base->clk))
  16922. return;
  16923. - spin_lock_irq(&base->lock);
  16924. + raw_spin_lock_irq(&base->lock);
  16925. while (time_after_eq(jiffies, base->clk)) {
  16926. @@ -1640,8 +1673,8 @@
  16927. while (levels--)
  16928. expire_timers(base, heads + levels);
  16929. }
  16930. - base->running_timer = NULL;
  16931. - spin_unlock_irq(&base->lock);
  16932. + raw_spin_unlock_irq(&base->lock);
  16933. + wakeup_timer_waiters(base);
  16934. }
  16935. /*
  16936. @@ -1651,6 +1684,8 @@
  16937. {
  16938. struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
  16939. + irq_work_tick_soft();
  16940. +
  16941. __run_timers(base);
  16942. if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && base->nohz_active)
  16943. __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
  16944. @@ -1836,16 +1871,16 @@
  16945. * The caller is globally serialized and nobody else
  16946. * takes two locks at once, deadlock is not possible.
  16947. */
  16948. - spin_lock_irq(&new_base->lock);
  16949. - spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
  16950. + raw_spin_lock_irq(&new_base->lock);
  16951. + raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
  16952. BUG_ON(old_base->running_timer);
  16953. for (i = 0; i < WHEEL_SIZE; i++)
  16954. migrate_timer_list(new_base, old_base->vectors + i);
  16955. - spin_unlock(&old_base->lock);
  16956. - spin_unlock_irq(&new_base->lock);
  16957. + raw_spin_unlock(&old_base->lock);
  16958. + raw_spin_unlock_irq(&new_base->lock);
  16959. put_cpu_ptr(&timer_bases);
  16960. }
  16961. return 0;
  16962. @@ -1861,8 +1896,11 @@
  16963. for (i = 0; i < NR_BASES; i++) {
  16964. base = per_cpu_ptr(&timer_bases[i], cpu);
  16965. base->cpu = cpu;
  16966. - spin_lock_init(&base->lock);
  16967. + raw_spin_lock_init(&base->lock);
  16968. base->clk = jiffies;
  16969. +#ifdef CONFIG_PREEMPT_RT_FULL
  16970. + init_swait_queue_head(&base->wait_for_running_timer);
  16971. +#endif
  16972. }
  16973. }
  16974. diff -Nur linux-4.9.6.orig/kernel/trace/Kconfig linux-4.9.6/kernel/trace/Kconfig
  16975. --- linux-4.9.6.orig/kernel/trace/Kconfig 2017-01-26 08:25:24.000000000 +0100
  16976. +++ linux-4.9.6/kernel/trace/Kconfig 2017-01-28 13:59:10.087662182 +0100
  16977. @@ -182,6 +182,24 @@
  16978. enabled. This option and the preempt-off timing option can be
  16979. used together or separately.)
  16980. +config INTERRUPT_OFF_HIST
  16981. + bool "Interrupts-off Latency Histogram"
  16982. + depends on IRQSOFF_TRACER
  16983. + help
  16984. + This option generates continuously updated histograms (one per cpu)
  16985. + of the duration of time periods with interrupts disabled. The
  16986. + histograms are disabled by default. To enable them, write a non-zero
  16987. + number to
  16988. +
  16989. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  16990. +
  16991. + If PREEMPT_OFF_HIST is also selected, additional histograms (one
  16992. + per cpu) are generated that accumulate the duration of time periods
  16993. + when both interrupts and preemption are disabled. The histogram data
  16994. + will be located in the debug file system at
  16995. +
  16996. + /sys/kernel/debug/tracing/latency_hist/irqsoff
  16997. +
  16998. config PREEMPT_TRACER
  16999. bool "Preemption-off Latency Tracer"
  17000. default n
  17001. @@ -206,6 +224,24 @@
  17002. enabled. This option and the irqs-off timing option can be
  17003. used together or separately.)
  17004. +config PREEMPT_OFF_HIST
  17005. + bool "Preemption-off Latency Histogram"
  17006. + depends on PREEMPT_TRACER
  17007. + help
  17008. + This option generates continuously updated histograms (one per cpu)
  17009. + of the duration of time periods with preemption disabled. The
  17010. + histograms are disabled by default. To enable them, write a non-zero
  17011. + number to
  17012. +
  17013. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  17014. +
  17015. + If INTERRUPT_OFF_HIST is also selected, additional histograms (one
  17016. + per cpu) are generated that accumulate the duration of time periods
  17017. + when both interrupts and preemption are disabled. The histogram data
  17018. + will be located in the debug file system at
  17019. +
  17020. + /sys/kernel/debug/tracing/latency_hist/preemptoff
  17021. +
  17022. config SCHED_TRACER
  17023. bool "Scheduling Latency Tracer"
  17024. select GENERIC_TRACER
  17025. @@ -251,6 +287,74 @@
  17026. file. Every time a latency is greater than tracing_thresh, it will
  17027. be recorded into the ring buffer.
  17028. +config WAKEUP_LATENCY_HIST
  17029. + bool "Scheduling Latency Histogram"
  17030. + depends on SCHED_TRACER
  17031. + help
  17032. + This option generates continuously updated histograms (one per cpu)
  17033. + of the scheduling latency of the highest priority task.
  17034. + The histograms are disabled by default. To enable them, write a
  17035. + non-zero number to
  17036. +
  17037. + /sys/kernel/debug/tracing/latency_hist/enable/wakeup
  17038. +
  17039. + Two different algorithms are used, one to determine the latency of
  17040. + processes that exclusively use the highest priority of the system and
  17041. + another one to determine the latency of processes that share the
  17042. + highest system priority with other processes. The former is used to
  17043. + improve hardware and system software, the latter to optimize the
  17044. + priority design of a given system. The histogram data will be
  17045. + located in the debug file system at
  17046. +
  17047. + /sys/kernel/debug/tracing/latency_hist/wakeup
  17048. +
  17049. + and
  17050. +
  17051. + /sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio
  17052. +
  17053. + If both Scheduling Latency Histogram and Missed Timer Offsets
  17054. + Histogram are selected, additional histogram data will be collected
  17055. + that contain, in addition to the wakeup latency, the timer latency, in
  17056. + case the wakeup was triggered by an expired timer. These histograms
  17057. + are available in the
  17058. +
  17059. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  17060. +
  17061. + directory. They reflect the apparent interrupt and scheduling latency
  17062. + and are best suitable to determine the worst-case latency of a given
  17063. + system. To enable these histograms, write a non-zero number to
  17064. +
  17065. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  17066. +
  17067. +config MISSED_TIMER_OFFSETS_HIST
  17068. + depends on HIGH_RES_TIMERS
  17069. + select GENERIC_TRACER
  17070. + bool "Missed Timer Offsets Histogram"
  17071. + help
  17072. + Generate a histogram of missed timer offsets in microseconds. The
  17073. + histograms are disabled by default. To enable them, write a non-zero
  17074. + number to
  17075. +
  17076. + /sys/kernel/debug/tracing/latency_hist/enable/missed_timer_offsets
  17077. +
  17078. + The histogram data will be located in the debug file system at
  17079. +
  17080. + /sys/kernel/debug/tracing/latency_hist/missed_timer_offsets
  17081. +
  17082. + If both Scheduling Latency Histogram and Missed Timer Offsets
  17083. + Histogram are selected, additional histogram data will be collected
  17084. + that contain, in addition to the wakeup latency, the timer latency, in
  17085. + case the wakeup was triggered by an expired timer. These histograms
  17086. + are available in the
  17087. +
  17088. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  17089. +
  17090. + directory. They reflect the apparent interrupt and scheduling latency
  17091. + and are best suitable to determine the worst-case latency of a given
  17092. + system. To enable these histograms, write a non-zero number to
  17093. +
  17094. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  17095. +
  17096. config ENABLE_DEFAULT_TRACERS
  17097. bool "Trace process context switches and events"
  17098. depends on !GENERIC_TRACER
  17099. diff -Nur linux-4.9.6.orig/kernel/trace/latency_hist.c linux-4.9.6/kernel/trace/latency_hist.c
  17100. --- linux-4.9.6.orig/kernel/trace/latency_hist.c 1970-01-01 01:00:00.000000000 +0100
  17101. +++ linux-4.9.6/kernel/trace/latency_hist.c 2017-01-28 13:59:10.091662336 +0100
  17102. @@ -0,0 +1,1178 @@
  17103. +/*
  17104. + * kernel/trace/latency_hist.c
  17105. + *
  17106. + * Add support for histograms of preemption-off latency and
  17107. + * interrupt-off latency and wakeup latency, it depends on
  17108. + * Real-Time Preemption Support.
  17109. + *
  17110. + * Copyright (C) 2005 MontaVista Software, Inc.
  17111. + * Yi Yang <yyang@ch.mvista.com>
  17112. + *
  17113. + * Converted to work with the new latency tracer.
  17114. + * Copyright (C) 2008 Red Hat, Inc.
  17115. + * Steven Rostedt <srostedt@redhat.com>
  17116. + *
  17117. + */
  17118. +#include <linux/module.h>
  17119. +#include <linux/debugfs.h>
  17120. +#include <linux/seq_file.h>
  17121. +#include <linux/percpu.h>
  17122. +#include <linux/kallsyms.h>
  17123. +#include <linux/uaccess.h>
  17124. +#include <linux/sched.h>
  17125. +#include <linux/sched/rt.h>
  17126. +#include <linux/slab.h>
  17127. +#include <linux/atomic.h>
  17128. +#include <asm/div64.h>
  17129. +
  17130. +#include "trace.h"
  17131. +#include <trace/events/sched.h>
  17132. +
  17133. +#define NSECS_PER_USECS 1000L
  17134. +
  17135. +#define CREATE_TRACE_POINTS
  17136. +#include <trace/events/hist.h>
  17137. +
  17138. +enum {
  17139. + IRQSOFF_LATENCY = 0,
  17140. + PREEMPTOFF_LATENCY,
  17141. + PREEMPTIRQSOFF_LATENCY,
  17142. + WAKEUP_LATENCY,
  17143. + WAKEUP_LATENCY_SHAREDPRIO,
  17144. + MISSED_TIMER_OFFSETS,
  17145. + TIMERANDWAKEUP_LATENCY,
  17146. + MAX_LATENCY_TYPE,
  17147. +};
  17148. +
  17149. +#define MAX_ENTRY_NUM 10240
  17150. +
  17151. +struct hist_data {
  17152. + atomic_t hist_mode; /* 0 log, 1 don't log */
  17153. + long offset; /* set it to MAX_ENTRY_NUM/2 for a bipolar scale */
  17154. + long min_lat;
  17155. + long max_lat;
  17156. + unsigned long long below_hist_bound_samples;
  17157. + unsigned long long above_hist_bound_samples;
  17158. + long long accumulate_lat;
  17159. + unsigned long long total_samples;
  17160. + unsigned long long hist_array[MAX_ENTRY_NUM];
  17161. +};
  17162. +
  17163. +struct enable_data {
  17164. + int latency_type;
  17165. + int enabled;
  17166. +};
  17167. +
  17168. +static char *latency_hist_dir_root = "latency_hist";
  17169. +
  17170. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17171. +static DEFINE_PER_CPU(struct hist_data, irqsoff_hist);
  17172. +static char *irqsoff_hist_dir = "irqsoff";
  17173. +static DEFINE_PER_CPU(cycles_t, hist_irqsoff_start);
  17174. +static DEFINE_PER_CPU(int, hist_irqsoff_counting);
  17175. +#endif
  17176. +
  17177. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17178. +static DEFINE_PER_CPU(struct hist_data, preemptoff_hist);
  17179. +static char *preemptoff_hist_dir = "preemptoff";
  17180. +static DEFINE_PER_CPU(cycles_t, hist_preemptoff_start);
  17181. +static DEFINE_PER_CPU(int, hist_preemptoff_counting);
  17182. +#endif
  17183. +
  17184. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  17185. +static DEFINE_PER_CPU(struct hist_data, preemptirqsoff_hist);
  17186. +static char *preemptirqsoff_hist_dir = "preemptirqsoff";
  17187. +static DEFINE_PER_CPU(cycles_t, hist_preemptirqsoff_start);
  17188. +static DEFINE_PER_CPU(int, hist_preemptirqsoff_counting);
  17189. +#endif
  17190. +
  17191. +#if defined(CONFIG_PREEMPT_OFF_HIST) || defined(CONFIG_INTERRUPT_OFF_HIST)
  17192. +static notrace void probe_preemptirqsoff_hist(void *v, int reason, int start);
  17193. +static struct enable_data preemptirqsoff_enabled_data = {
  17194. + .latency_type = PREEMPTIRQSOFF_LATENCY,
  17195. + .enabled = 0,
  17196. +};
  17197. +#endif
  17198. +
  17199. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17200. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17201. +struct maxlatproc_data {
  17202. + char comm[FIELD_SIZEOF(struct task_struct, comm)];
  17203. + char current_comm[FIELD_SIZEOF(struct task_struct, comm)];
  17204. + int pid;
  17205. + int current_pid;
  17206. + int prio;
  17207. + int current_prio;
  17208. + long latency;
  17209. + long timeroffset;
  17210. + cycle_t timestamp;
  17211. +};
  17212. +#endif
  17213. +
  17214. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17215. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist);
  17216. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist_sharedprio);
  17217. +static char *wakeup_latency_hist_dir = "wakeup";
  17218. +static char *wakeup_latency_hist_dir_sharedprio = "sharedprio";
  17219. +static notrace void probe_wakeup_latency_hist_start(void *v,
  17220. + struct task_struct *p);
  17221. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  17222. + bool preempt, struct task_struct *prev, struct task_struct *next);
  17223. +static notrace void probe_sched_migrate_task(void *,
  17224. + struct task_struct *task, int cpu);
  17225. +static struct enable_data wakeup_latency_enabled_data = {
  17226. + .latency_type = WAKEUP_LATENCY,
  17227. + .enabled = 0,
  17228. +};
  17229. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc);
  17230. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc_sharedprio);
  17231. +static DEFINE_PER_CPU(struct task_struct *, wakeup_task);
  17232. +static DEFINE_PER_CPU(int, wakeup_sharedprio);
  17233. +static unsigned long wakeup_pid;
  17234. +#endif
  17235. +
  17236. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17237. +static DEFINE_PER_CPU(struct hist_data, missed_timer_offsets);
  17238. +static char *missed_timer_offsets_dir = "missed_timer_offsets";
  17239. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  17240. + long long offset, struct task_struct *curr, struct task_struct *task);
  17241. +static struct enable_data missed_timer_offsets_enabled_data = {
  17242. + .latency_type = MISSED_TIMER_OFFSETS,
  17243. + .enabled = 0,
  17244. +};
  17245. +static DEFINE_PER_CPU(struct maxlatproc_data, missed_timer_offsets_maxlatproc);
  17246. +static unsigned long missed_timer_offsets_pid;
  17247. +#endif
  17248. +
  17249. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  17250. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17251. +static DEFINE_PER_CPU(struct hist_data, timerandwakeup_latency_hist);
  17252. +static char *timerandwakeup_latency_hist_dir = "timerandwakeup";
  17253. +static struct enable_data timerandwakeup_enabled_data = {
  17254. + .latency_type = TIMERANDWAKEUP_LATENCY,
  17255. + .enabled = 0,
  17256. +};
  17257. +static DEFINE_PER_CPU(struct maxlatproc_data, timerandwakeup_maxlatproc);
  17258. +#endif
  17259. +
  17260. +void notrace latency_hist(int latency_type, int cpu, long latency,
  17261. + long timeroffset, cycle_t stop,
  17262. + struct task_struct *p)
  17263. +{
  17264. + struct hist_data *my_hist;
  17265. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17266. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17267. + struct maxlatproc_data *mp = NULL;
  17268. +#endif
  17269. +
  17270. + if (!cpu_possible(cpu) || latency_type < 0 ||
  17271. + latency_type >= MAX_LATENCY_TYPE)
  17272. + return;
  17273. +
  17274. + switch (latency_type) {
  17275. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17276. + case IRQSOFF_LATENCY:
  17277. + my_hist = &per_cpu(irqsoff_hist, cpu);
  17278. + break;
  17279. +#endif
  17280. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17281. + case PREEMPTOFF_LATENCY:
  17282. + my_hist = &per_cpu(preemptoff_hist, cpu);
  17283. + break;
  17284. +#endif
  17285. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  17286. + case PREEMPTIRQSOFF_LATENCY:
  17287. + my_hist = &per_cpu(preemptirqsoff_hist, cpu);
  17288. + break;
  17289. +#endif
  17290. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17291. + case WAKEUP_LATENCY:
  17292. + my_hist = &per_cpu(wakeup_latency_hist, cpu);
  17293. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  17294. + break;
  17295. + case WAKEUP_LATENCY_SHAREDPRIO:
  17296. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  17297. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  17298. + break;
  17299. +#endif
  17300. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17301. + case MISSED_TIMER_OFFSETS:
  17302. + my_hist = &per_cpu(missed_timer_offsets, cpu);
  17303. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  17304. + break;
  17305. +#endif
  17306. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  17307. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17308. + case TIMERANDWAKEUP_LATENCY:
  17309. + my_hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  17310. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  17311. + break;
  17312. +#endif
  17313. +
  17314. + default:
  17315. + return;
  17316. + }
  17317. +
  17318. + latency += my_hist->offset;
  17319. +
  17320. + if (atomic_read(&my_hist->hist_mode) == 0)
  17321. + return;
  17322. +
  17323. + if (latency < 0 || latency >= MAX_ENTRY_NUM) {
  17324. + if (latency < 0)
  17325. + my_hist->below_hist_bound_samples++;
  17326. + else
  17327. + my_hist->above_hist_bound_samples++;
  17328. + } else
  17329. + my_hist->hist_array[latency]++;
  17330. +
  17331. + if (unlikely(latency > my_hist->max_lat ||
  17332. + my_hist->min_lat == LONG_MAX)) {
  17333. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17334. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17335. + if (latency_type == WAKEUP_LATENCY ||
  17336. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  17337. + latency_type == MISSED_TIMER_OFFSETS ||
  17338. + latency_type == TIMERANDWAKEUP_LATENCY) {
  17339. + strncpy(mp->comm, p->comm, sizeof(mp->comm));
  17340. + strncpy(mp->current_comm, current->comm,
  17341. + sizeof(mp->current_comm));
  17342. + mp->pid = task_pid_nr(p);
  17343. + mp->current_pid = task_pid_nr(current);
  17344. + mp->prio = p->prio;
  17345. + mp->current_prio = current->prio;
  17346. + mp->latency = latency;
  17347. + mp->timeroffset = timeroffset;
  17348. + mp->timestamp = stop;
  17349. + }
  17350. +#endif
  17351. + my_hist->max_lat = latency;
  17352. + }
  17353. + if (unlikely(latency < my_hist->min_lat))
  17354. + my_hist->min_lat = latency;
  17355. + my_hist->total_samples++;
  17356. + my_hist->accumulate_lat += latency;
  17357. +}
  17358. +
  17359. +static void *l_start(struct seq_file *m, loff_t *pos)
  17360. +{
  17361. + loff_t *index_ptr = NULL;
  17362. + loff_t index = *pos;
  17363. + struct hist_data *my_hist = m->private;
  17364. +
  17365. + if (index == 0) {
  17366. + char minstr[32], avgstr[32], maxstr[32];
  17367. +
  17368. + atomic_dec(&my_hist->hist_mode);
  17369. +
  17370. + if (likely(my_hist->total_samples)) {
  17371. + long avg = (long) div64_s64(my_hist->accumulate_lat,
  17372. + my_hist->total_samples);
  17373. + snprintf(minstr, sizeof(minstr), "%ld",
  17374. + my_hist->min_lat - my_hist->offset);
  17375. + snprintf(avgstr, sizeof(avgstr), "%ld",
  17376. + avg - my_hist->offset);
  17377. + snprintf(maxstr, sizeof(maxstr), "%ld",
  17378. + my_hist->max_lat - my_hist->offset);
  17379. + } else {
  17380. + strcpy(minstr, "<undef>");
  17381. + strcpy(avgstr, minstr);
  17382. + strcpy(maxstr, minstr);
  17383. + }
  17384. +
  17385. + seq_printf(m, "#Minimum latency: %s microseconds\n"
  17386. + "#Average latency: %s microseconds\n"
  17387. + "#Maximum latency: %s microseconds\n"
  17388. + "#Total samples: %llu\n"
  17389. + "#There are %llu samples lower than %ld"
  17390. + " microseconds.\n"
  17391. + "#There are %llu samples greater or equal"
  17392. + " than %ld microseconds.\n"
  17393. + "#usecs\t%16s\n",
  17394. + minstr, avgstr, maxstr,
  17395. + my_hist->total_samples,
  17396. + my_hist->below_hist_bound_samples,
  17397. + -my_hist->offset,
  17398. + my_hist->above_hist_bound_samples,
  17399. + MAX_ENTRY_NUM - my_hist->offset,
  17400. + "samples");
  17401. + }
  17402. + if (index < MAX_ENTRY_NUM) {
  17403. + index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL);
  17404. + if (index_ptr)
  17405. + *index_ptr = index;
  17406. + }
  17407. +
  17408. + return index_ptr;
  17409. +}
  17410. +
  17411. +static void *l_next(struct seq_file *m, void *p, loff_t *pos)
  17412. +{
  17413. + loff_t *index_ptr = p;
  17414. + struct hist_data *my_hist = m->private;
  17415. +
  17416. + if (++*pos >= MAX_ENTRY_NUM) {
  17417. + atomic_inc(&my_hist->hist_mode);
  17418. + return NULL;
  17419. + }
  17420. + *index_ptr = *pos;
  17421. + return index_ptr;
  17422. +}
  17423. +
  17424. +static void l_stop(struct seq_file *m, void *p)
  17425. +{
  17426. + kfree(p);
  17427. +}
  17428. +
  17429. +static int l_show(struct seq_file *m, void *p)
  17430. +{
  17431. + int index = *(loff_t *) p;
  17432. + struct hist_data *my_hist = m->private;
  17433. +
  17434. + seq_printf(m, "%6ld\t%16llu\n", index - my_hist->offset,
  17435. + my_hist->hist_array[index]);
  17436. + return 0;
  17437. +}
  17438. +
  17439. +static const struct seq_operations latency_hist_seq_op = {
  17440. + .start = l_start,
  17441. + .next = l_next,
  17442. + .stop = l_stop,
  17443. + .show = l_show
  17444. +};
  17445. +
  17446. +static int latency_hist_open(struct inode *inode, struct file *file)
  17447. +{
  17448. + int ret;
  17449. +
  17450. + ret = seq_open(file, &latency_hist_seq_op);
  17451. + if (!ret) {
  17452. + struct seq_file *seq = file->private_data;
  17453. + seq->private = inode->i_private;
  17454. + }
  17455. + return ret;
  17456. +}
  17457. +
  17458. +static const struct file_operations latency_hist_fops = {
  17459. + .open = latency_hist_open,
  17460. + .read = seq_read,
  17461. + .llseek = seq_lseek,
  17462. + .release = seq_release,
  17463. +};
  17464. +
  17465. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17466. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17467. +static void clear_maxlatprocdata(struct maxlatproc_data *mp)
  17468. +{
  17469. + mp->comm[0] = mp->current_comm[0] = '\0';
  17470. + mp->prio = mp->current_prio = mp->pid = mp->current_pid =
  17471. + mp->latency = mp->timeroffset = -1;
  17472. + mp->timestamp = 0;
  17473. +}
  17474. +#endif
  17475. +
  17476. +static void hist_reset(struct hist_data *hist)
  17477. +{
  17478. + atomic_dec(&hist->hist_mode);
  17479. +
  17480. + memset(hist->hist_array, 0, sizeof(hist->hist_array));
  17481. + hist->below_hist_bound_samples = 0ULL;
  17482. + hist->above_hist_bound_samples = 0ULL;
  17483. + hist->min_lat = LONG_MAX;
  17484. + hist->max_lat = LONG_MIN;
  17485. + hist->total_samples = 0ULL;
  17486. + hist->accumulate_lat = 0LL;
  17487. +
  17488. + atomic_inc(&hist->hist_mode);
  17489. +}
  17490. +
  17491. +static ssize_t
  17492. +latency_hist_reset(struct file *file, const char __user *a,
  17493. + size_t size, loff_t *off)
  17494. +{
  17495. + int cpu;
  17496. + struct hist_data *hist = NULL;
  17497. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17498. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17499. + struct maxlatproc_data *mp = NULL;
  17500. +#endif
  17501. + off_t latency_type = (off_t) file->private_data;
  17502. +
  17503. + for_each_online_cpu(cpu) {
  17504. +
  17505. + switch (latency_type) {
  17506. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17507. + case PREEMPTOFF_LATENCY:
  17508. + hist = &per_cpu(preemptoff_hist, cpu);
  17509. + break;
  17510. +#endif
  17511. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17512. + case IRQSOFF_LATENCY:
  17513. + hist = &per_cpu(irqsoff_hist, cpu);
  17514. + break;
  17515. +#endif
  17516. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  17517. + case PREEMPTIRQSOFF_LATENCY:
  17518. + hist = &per_cpu(preemptirqsoff_hist, cpu);
  17519. + break;
  17520. +#endif
  17521. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17522. + case WAKEUP_LATENCY:
  17523. + hist = &per_cpu(wakeup_latency_hist, cpu);
  17524. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  17525. + break;
  17526. + case WAKEUP_LATENCY_SHAREDPRIO:
  17527. + hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  17528. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  17529. + break;
  17530. +#endif
  17531. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17532. + case MISSED_TIMER_OFFSETS:
  17533. + hist = &per_cpu(missed_timer_offsets, cpu);
  17534. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  17535. + break;
  17536. +#endif
  17537. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  17538. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17539. + case TIMERANDWAKEUP_LATENCY:
  17540. + hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  17541. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  17542. + break;
  17543. +#endif
  17544. + }
  17545. +
  17546. + hist_reset(hist);
  17547. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17548. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17549. + if (latency_type == WAKEUP_LATENCY ||
  17550. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  17551. + latency_type == MISSED_TIMER_OFFSETS ||
  17552. + latency_type == TIMERANDWAKEUP_LATENCY)
  17553. + clear_maxlatprocdata(mp);
  17554. +#endif
  17555. + }
  17556. +
  17557. + return size;
  17558. +}
  17559. +
  17560. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17561. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17562. +static ssize_t
  17563. +show_pid(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  17564. +{
  17565. + char buf[64];
  17566. + int r;
  17567. + unsigned long *this_pid = file->private_data;
  17568. +
  17569. + r = snprintf(buf, sizeof(buf), "%lu\n", *this_pid);
  17570. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  17571. +}
  17572. +
  17573. +static ssize_t do_pid(struct file *file, const char __user *ubuf,
  17574. + size_t cnt, loff_t *ppos)
  17575. +{
  17576. + char buf[64];
  17577. + unsigned long pid;
  17578. + unsigned long *this_pid = file->private_data;
  17579. +
  17580. + if (cnt >= sizeof(buf))
  17581. + return -EINVAL;
  17582. +
  17583. + if (copy_from_user(&buf, ubuf, cnt))
  17584. + return -EFAULT;
  17585. +
  17586. + buf[cnt] = '\0';
  17587. +
  17588. + if (kstrtoul(buf, 10, &pid))
  17589. + return -EINVAL;
  17590. +
  17591. + *this_pid = pid;
  17592. +
  17593. + return cnt;
  17594. +}
  17595. +#endif
  17596. +
  17597. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17598. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17599. +static ssize_t
  17600. +show_maxlatproc(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  17601. +{
  17602. + int r;
  17603. + struct maxlatproc_data *mp = file->private_data;
  17604. + int strmaxlen = (TASK_COMM_LEN * 2) + (8 * 8);
  17605. + unsigned long long t;
  17606. + unsigned long usecs, secs;
  17607. + char *buf;
  17608. +
  17609. + if (mp->pid == -1 || mp->current_pid == -1) {
  17610. + buf = "(none)\n";
  17611. + return simple_read_from_buffer(ubuf, cnt, ppos, buf,
  17612. + strlen(buf));
  17613. + }
  17614. +
  17615. + buf = kmalloc(strmaxlen, GFP_KERNEL);
  17616. + if (buf == NULL)
  17617. + return -ENOMEM;
  17618. +
  17619. + t = ns2usecs(mp->timestamp);
  17620. + usecs = do_div(t, USEC_PER_SEC);
  17621. + secs = (unsigned long) t;
  17622. + r = snprintf(buf, strmaxlen,
  17623. + "%d %d %ld (%ld) %s <- %d %d %s %lu.%06lu\n", mp->pid,
  17624. + MAX_RT_PRIO-1 - mp->prio, mp->latency, mp->timeroffset, mp->comm,
  17625. + mp->current_pid, MAX_RT_PRIO-1 - mp->current_prio, mp->current_comm,
  17626. + secs, usecs);
  17627. + r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  17628. + kfree(buf);
  17629. + return r;
  17630. +}
  17631. +#endif
  17632. +
  17633. +static ssize_t
  17634. +show_enable(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  17635. +{
  17636. + char buf[64];
  17637. + struct enable_data *ed = file->private_data;
  17638. + int r;
  17639. +
  17640. + r = snprintf(buf, sizeof(buf), "%d\n", ed->enabled);
  17641. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  17642. +}
  17643. +
  17644. +static ssize_t
  17645. +do_enable(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos)
  17646. +{
  17647. + char buf[64];
  17648. + long enable;
  17649. + struct enable_data *ed = file->private_data;
  17650. +
  17651. + if (cnt >= sizeof(buf))
  17652. + return -EINVAL;
  17653. +
  17654. + if (copy_from_user(&buf, ubuf, cnt))
  17655. + return -EFAULT;
  17656. +
  17657. + buf[cnt] = 0;
  17658. +
  17659. + if (kstrtoul(buf, 10, &enable))
  17660. + return -EINVAL;
  17661. +
  17662. + if ((enable && ed->enabled) || (!enable && !ed->enabled))
  17663. + return cnt;
  17664. +
  17665. + if (enable) {
  17666. + int ret;
  17667. +
  17668. + switch (ed->latency_type) {
  17669. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  17670. + case PREEMPTIRQSOFF_LATENCY:
  17671. + ret = register_trace_preemptirqsoff_hist(
  17672. + probe_preemptirqsoff_hist, NULL);
  17673. + if (ret) {
  17674. + pr_info("wakeup trace: Couldn't assign "
  17675. + "probe_preemptirqsoff_hist "
  17676. + "to trace_preemptirqsoff_hist\n");
  17677. + return ret;
  17678. + }
  17679. + break;
  17680. +#endif
  17681. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17682. + case WAKEUP_LATENCY:
  17683. + ret = register_trace_sched_wakeup(
  17684. + probe_wakeup_latency_hist_start, NULL);
  17685. + if (ret) {
  17686. + pr_info("wakeup trace: Couldn't assign "
  17687. + "probe_wakeup_latency_hist_start "
  17688. + "to trace_sched_wakeup\n");
  17689. + return ret;
  17690. + }
  17691. + ret = register_trace_sched_wakeup_new(
  17692. + probe_wakeup_latency_hist_start, NULL);
  17693. + if (ret) {
  17694. + pr_info("wakeup trace: Couldn't assign "
  17695. + "probe_wakeup_latency_hist_start "
  17696. + "to trace_sched_wakeup_new\n");
  17697. + unregister_trace_sched_wakeup(
  17698. + probe_wakeup_latency_hist_start, NULL);
  17699. + return ret;
  17700. + }
  17701. + ret = register_trace_sched_switch(
  17702. + probe_wakeup_latency_hist_stop, NULL);
  17703. + if (ret) {
  17704. + pr_info("wakeup trace: Couldn't assign "
  17705. + "probe_wakeup_latency_hist_stop "
  17706. + "to trace_sched_switch\n");
  17707. + unregister_trace_sched_wakeup(
  17708. + probe_wakeup_latency_hist_start, NULL);
  17709. + unregister_trace_sched_wakeup_new(
  17710. + probe_wakeup_latency_hist_start, NULL);
  17711. + return ret;
  17712. + }
  17713. + ret = register_trace_sched_migrate_task(
  17714. + probe_sched_migrate_task, NULL);
  17715. + if (ret) {
  17716. + pr_info("wakeup trace: Couldn't assign "
  17717. + "probe_sched_migrate_task "
  17718. + "to trace_sched_migrate_task\n");
  17719. + unregister_trace_sched_wakeup(
  17720. + probe_wakeup_latency_hist_start, NULL);
  17721. + unregister_trace_sched_wakeup_new(
  17722. + probe_wakeup_latency_hist_start, NULL);
  17723. + unregister_trace_sched_switch(
  17724. + probe_wakeup_latency_hist_stop, NULL);
  17725. + return ret;
  17726. + }
  17727. + break;
  17728. +#endif
  17729. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17730. + case MISSED_TIMER_OFFSETS:
  17731. + ret = register_trace_hrtimer_interrupt(
  17732. + probe_hrtimer_interrupt, NULL);
  17733. + if (ret) {
  17734. + pr_info("wakeup trace: Couldn't assign "
  17735. + "probe_hrtimer_interrupt "
  17736. + "to trace_hrtimer_interrupt\n");
  17737. + return ret;
  17738. + }
  17739. + break;
  17740. +#endif
  17741. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  17742. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17743. + case TIMERANDWAKEUP_LATENCY:
  17744. + if (!wakeup_latency_enabled_data.enabled ||
  17745. + !missed_timer_offsets_enabled_data.enabled)
  17746. + return -EINVAL;
  17747. + break;
  17748. +#endif
  17749. + default:
  17750. + break;
  17751. + }
  17752. + } else {
  17753. + switch (ed->latency_type) {
  17754. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  17755. + case PREEMPTIRQSOFF_LATENCY:
  17756. + {
  17757. + int cpu;
  17758. +
  17759. + unregister_trace_preemptirqsoff_hist(
  17760. + probe_preemptirqsoff_hist, NULL);
  17761. + for_each_online_cpu(cpu) {
  17762. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17763. + per_cpu(hist_irqsoff_counting,
  17764. + cpu) = 0;
  17765. +#endif
  17766. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17767. + per_cpu(hist_preemptoff_counting,
  17768. + cpu) = 0;
  17769. +#endif
  17770. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  17771. + per_cpu(hist_preemptirqsoff_counting,
  17772. + cpu) = 0;
  17773. +#endif
  17774. + }
  17775. + }
  17776. + break;
  17777. +#endif
  17778. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17779. + case WAKEUP_LATENCY:
  17780. + {
  17781. + int cpu;
  17782. +
  17783. + unregister_trace_sched_wakeup(
  17784. + probe_wakeup_latency_hist_start, NULL);
  17785. + unregister_trace_sched_wakeup_new(
  17786. + probe_wakeup_latency_hist_start, NULL);
  17787. + unregister_trace_sched_switch(
  17788. + probe_wakeup_latency_hist_stop, NULL);
  17789. + unregister_trace_sched_migrate_task(
  17790. + probe_sched_migrate_task, NULL);
  17791. +
  17792. + for_each_online_cpu(cpu) {
  17793. + per_cpu(wakeup_task, cpu) = NULL;
  17794. + per_cpu(wakeup_sharedprio, cpu) = 0;
  17795. + }
  17796. + }
  17797. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17798. + timerandwakeup_enabled_data.enabled = 0;
  17799. +#endif
  17800. + break;
  17801. +#endif
  17802. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  17803. + case MISSED_TIMER_OFFSETS:
  17804. + unregister_trace_hrtimer_interrupt(
  17805. + probe_hrtimer_interrupt, NULL);
  17806. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17807. + timerandwakeup_enabled_data.enabled = 0;
  17808. +#endif
  17809. + break;
  17810. +#endif
  17811. + default:
  17812. + break;
  17813. + }
  17814. + }
  17815. + ed->enabled = enable;
  17816. + return cnt;
  17817. +}
  17818. +
  17819. +static const struct file_operations latency_hist_reset_fops = {
  17820. + .open = tracing_open_generic,
  17821. + .write = latency_hist_reset,
  17822. +};
  17823. +
  17824. +static const struct file_operations enable_fops = {
  17825. + .open = tracing_open_generic,
  17826. + .read = show_enable,
  17827. + .write = do_enable,
  17828. +};
  17829. +
  17830. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  17831. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  17832. +static const struct file_operations pid_fops = {
  17833. + .open = tracing_open_generic,
  17834. + .read = show_pid,
  17835. + .write = do_pid,
  17836. +};
  17837. +
  17838. +static const struct file_operations maxlatproc_fops = {
  17839. + .open = tracing_open_generic,
  17840. + .read = show_maxlatproc,
  17841. +};
  17842. +#endif
  17843. +
  17844. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  17845. +static notrace void probe_preemptirqsoff_hist(void *v, int reason,
  17846. + int starthist)
  17847. +{
  17848. + int cpu = raw_smp_processor_id();
  17849. + int time_set = 0;
  17850. +
  17851. + if (starthist) {
  17852. + cycle_t uninitialized_var(start);
  17853. +
  17854. + if (!preempt_count() && !irqs_disabled())
  17855. + return;
  17856. +
  17857. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17858. + if ((reason == IRQS_OFF || reason == TRACE_START) &&
  17859. + !per_cpu(hist_irqsoff_counting, cpu)) {
  17860. + per_cpu(hist_irqsoff_counting, cpu) = 1;
  17861. + start = ftrace_now(cpu);
  17862. + time_set++;
  17863. + per_cpu(hist_irqsoff_start, cpu) = start;
  17864. + }
  17865. +#endif
  17866. +
  17867. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17868. + if ((reason == PREEMPT_OFF || reason == TRACE_START) &&
  17869. + !per_cpu(hist_preemptoff_counting, cpu)) {
  17870. + per_cpu(hist_preemptoff_counting, cpu) = 1;
  17871. + if (!(time_set++))
  17872. + start = ftrace_now(cpu);
  17873. + per_cpu(hist_preemptoff_start, cpu) = start;
  17874. + }
  17875. +#endif
  17876. +
  17877. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  17878. + if (per_cpu(hist_irqsoff_counting, cpu) &&
  17879. + per_cpu(hist_preemptoff_counting, cpu) &&
  17880. + !per_cpu(hist_preemptirqsoff_counting, cpu)) {
  17881. + per_cpu(hist_preemptirqsoff_counting, cpu) = 1;
  17882. + if (!time_set)
  17883. + start = ftrace_now(cpu);
  17884. + per_cpu(hist_preemptirqsoff_start, cpu) = start;
  17885. + }
  17886. +#endif
  17887. + } else {
  17888. + cycle_t uninitialized_var(stop);
  17889. +
  17890. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  17891. + if ((reason == IRQS_ON || reason == TRACE_STOP) &&
  17892. + per_cpu(hist_irqsoff_counting, cpu)) {
  17893. + cycle_t start = per_cpu(hist_irqsoff_start, cpu);
  17894. +
  17895. + stop = ftrace_now(cpu);
  17896. + time_set++;
  17897. + if (start) {
  17898. + long latency = ((long) (stop - start)) /
  17899. + NSECS_PER_USECS;
  17900. +
  17901. + latency_hist(IRQSOFF_LATENCY, cpu, latency, 0,
  17902. + stop, NULL);
  17903. + }
  17904. + per_cpu(hist_irqsoff_counting, cpu) = 0;
  17905. + }
  17906. +#endif
  17907. +
  17908. +#ifdef CONFIG_PREEMPT_OFF_HIST
  17909. + if ((reason == PREEMPT_ON || reason == TRACE_STOP) &&
  17910. + per_cpu(hist_preemptoff_counting, cpu)) {
  17911. + cycle_t start = per_cpu(hist_preemptoff_start, cpu);
  17912. +
  17913. + if (!(time_set++))
  17914. + stop = ftrace_now(cpu);
  17915. + if (start) {
  17916. + long latency = ((long) (stop - start)) /
  17917. + NSECS_PER_USECS;
  17918. +
  17919. + latency_hist(PREEMPTOFF_LATENCY, cpu, latency,
  17920. + 0, stop, NULL);
  17921. + }
  17922. + per_cpu(hist_preemptoff_counting, cpu) = 0;
  17923. + }
  17924. +#endif
  17925. +
  17926. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  17927. + if ((!per_cpu(hist_irqsoff_counting, cpu) ||
  17928. + !per_cpu(hist_preemptoff_counting, cpu)) &&
  17929. + per_cpu(hist_preemptirqsoff_counting, cpu)) {
  17930. + cycle_t start = per_cpu(hist_preemptirqsoff_start, cpu);
  17931. +
  17932. + if (!time_set)
  17933. + stop = ftrace_now(cpu);
  17934. + if (start) {
  17935. + long latency = ((long) (stop - start)) /
  17936. + NSECS_PER_USECS;
  17937. +
  17938. + latency_hist(PREEMPTIRQSOFF_LATENCY, cpu,
  17939. + latency, 0, stop, NULL);
  17940. + }
  17941. + per_cpu(hist_preemptirqsoff_counting, cpu) = 0;
  17942. + }
  17943. +#endif
  17944. + }
  17945. +}
  17946. +#endif
  17947. +
  17948. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  17949. +static DEFINE_RAW_SPINLOCK(wakeup_lock);
  17950. +static notrace void probe_sched_migrate_task(void *v, struct task_struct *task,
  17951. + int cpu)
  17952. +{
  17953. + int old_cpu = task_cpu(task);
  17954. +
  17955. + if (cpu != old_cpu) {
  17956. + unsigned long flags;
  17957. + struct task_struct *cpu_wakeup_task;
  17958. +
  17959. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  17960. +
  17961. + cpu_wakeup_task = per_cpu(wakeup_task, old_cpu);
  17962. + if (task == cpu_wakeup_task) {
  17963. + put_task_struct(cpu_wakeup_task);
  17964. + per_cpu(wakeup_task, old_cpu) = NULL;
  17965. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = task;
  17966. + get_task_struct(cpu_wakeup_task);
  17967. + }
  17968. +
  17969. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  17970. + }
  17971. +}
  17972. +
  17973. +static notrace void probe_wakeup_latency_hist_start(void *v,
  17974. + struct task_struct *p)
  17975. +{
  17976. + unsigned long flags;
  17977. + struct task_struct *curr = current;
  17978. + int cpu = task_cpu(p);
  17979. + struct task_struct *cpu_wakeup_task;
  17980. +
  17981. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  17982. +
  17983. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  17984. +
  17985. + if (wakeup_pid) {
  17986. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  17987. + p->prio == curr->prio)
  17988. + per_cpu(wakeup_sharedprio, cpu) = 1;
  17989. + if (likely(wakeup_pid != task_pid_nr(p)))
  17990. + goto out;
  17991. + } else {
  17992. + if (likely(!rt_task(p)) ||
  17993. + (cpu_wakeup_task && p->prio > cpu_wakeup_task->prio) ||
  17994. + p->prio > curr->prio)
  17995. + goto out;
  17996. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  17997. + p->prio == curr->prio)
  17998. + per_cpu(wakeup_sharedprio, cpu) = 1;
  17999. + }
  18000. +
  18001. + if (cpu_wakeup_task)
  18002. + put_task_struct(cpu_wakeup_task);
  18003. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = p;
  18004. + get_task_struct(cpu_wakeup_task);
  18005. + cpu_wakeup_task->preempt_timestamp_hist =
  18006. + ftrace_now(raw_smp_processor_id());
  18007. +out:
  18008. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  18009. +}
  18010. +
  18011. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  18012. + bool preempt, struct task_struct *prev, struct task_struct *next)
  18013. +{
  18014. + unsigned long flags;
  18015. + int cpu = task_cpu(next);
  18016. + long latency;
  18017. + cycle_t stop;
  18018. + struct task_struct *cpu_wakeup_task;
  18019. +
  18020. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  18021. +
  18022. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  18023. +
  18024. + if (cpu_wakeup_task == NULL)
  18025. + goto out;
  18026. +
  18027. + /* Already running? */
  18028. + if (unlikely(current == cpu_wakeup_task))
  18029. + goto out_reset;
  18030. +
  18031. + if (next != cpu_wakeup_task) {
  18032. + if (next->prio < cpu_wakeup_task->prio)
  18033. + goto out_reset;
  18034. +
  18035. + if (next->prio == cpu_wakeup_task->prio)
  18036. + per_cpu(wakeup_sharedprio, cpu) = 1;
  18037. +
  18038. + goto out;
  18039. + }
  18040. +
  18041. + if (current->prio == cpu_wakeup_task->prio)
  18042. + per_cpu(wakeup_sharedprio, cpu) = 1;
  18043. +
  18044. + /*
  18045. + * The task we are waiting for is about to be switched to.
  18046. + * Calculate latency and store it in histogram.
  18047. + */
  18048. + stop = ftrace_now(raw_smp_processor_id());
  18049. +
  18050. + latency = ((long) (stop - next->preempt_timestamp_hist)) /
  18051. + NSECS_PER_USECS;
  18052. +
  18053. + if (per_cpu(wakeup_sharedprio, cpu)) {
  18054. + latency_hist(WAKEUP_LATENCY_SHAREDPRIO, cpu, latency, 0, stop,
  18055. + next);
  18056. + per_cpu(wakeup_sharedprio, cpu) = 0;
  18057. + } else {
  18058. + latency_hist(WAKEUP_LATENCY, cpu, latency, 0, stop, next);
  18059. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  18060. + if (timerandwakeup_enabled_data.enabled) {
  18061. + latency_hist(TIMERANDWAKEUP_LATENCY, cpu,
  18062. + next->timer_offset + latency, next->timer_offset,
  18063. + stop, next);
  18064. + }
  18065. +#endif
  18066. + }
  18067. +
  18068. +out_reset:
  18069. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  18070. + next->timer_offset = 0;
  18071. +#endif
  18072. + put_task_struct(cpu_wakeup_task);
  18073. + per_cpu(wakeup_task, cpu) = NULL;
  18074. +out:
  18075. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  18076. +}
  18077. +#endif
  18078. +
  18079. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  18080. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  18081. + long long latency_ns, struct task_struct *curr,
  18082. + struct task_struct *task)
  18083. +{
  18084. + if (latency_ns <= 0 && task != NULL && rt_task(task) &&
  18085. + (task->prio < curr->prio ||
  18086. + (task->prio == curr->prio &&
  18087. + !cpumask_test_cpu(cpu, &task->cpus_allowed)))) {
  18088. + long latency;
  18089. + cycle_t now;
  18090. +
  18091. + if (missed_timer_offsets_pid) {
  18092. + if (likely(missed_timer_offsets_pid !=
  18093. + task_pid_nr(task)))
  18094. + return;
  18095. + }
  18096. +
  18097. + now = ftrace_now(cpu);
  18098. + latency = (long) div_s64(-latency_ns, NSECS_PER_USECS);
  18099. + latency_hist(MISSED_TIMER_OFFSETS, cpu, latency, latency, now,
  18100. + task);
  18101. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  18102. + task->timer_offset = latency;
  18103. +#endif
  18104. + }
  18105. +}
  18106. +#endif
  18107. +
  18108. +static __init int latency_hist_init(void)
  18109. +{
  18110. + struct dentry *latency_hist_root = NULL;
  18111. + struct dentry *dentry;
  18112. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  18113. + struct dentry *dentry_sharedprio;
  18114. +#endif
  18115. + struct dentry *entry;
  18116. + struct dentry *enable_root;
  18117. + int i = 0;
  18118. + struct hist_data *my_hist;
  18119. + char name[64];
  18120. + char *cpufmt = "CPU%d";
  18121. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  18122. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  18123. + char *cpufmt_maxlatproc = "max_latency-CPU%d";
  18124. + struct maxlatproc_data *mp = NULL;
  18125. +#endif
  18126. +
  18127. + dentry = tracing_init_dentry();
  18128. + latency_hist_root = debugfs_create_dir(latency_hist_dir_root, dentry);
  18129. + enable_root = debugfs_create_dir("enable", latency_hist_root);
  18130. +
  18131. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  18132. + dentry = debugfs_create_dir(irqsoff_hist_dir, latency_hist_root);
  18133. + for_each_possible_cpu(i) {
  18134. + sprintf(name, cpufmt, i);
  18135. + entry = debugfs_create_file(name, 0444, dentry,
  18136. + &per_cpu(irqsoff_hist, i), &latency_hist_fops);
  18137. + my_hist = &per_cpu(irqsoff_hist, i);
  18138. + atomic_set(&my_hist->hist_mode, 1);
  18139. + my_hist->min_lat = LONG_MAX;
  18140. + }
  18141. + entry = debugfs_create_file("reset", 0644, dentry,
  18142. + (void *)IRQSOFF_LATENCY, &latency_hist_reset_fops);
  18143. +#endif
  18144. +
  18145. +#ifdef CONFIG_PREEMPT_OFF_HIST
  18146. + dentry = debugfs_create_dir(preemptoff_hist_dir,
  18147. + latency_hist_root);
  18148. + for_each_possible_cpu(i) {
  18149. + sprintf(name, cpufmt, i);
  18150. + entry = debugfs_create_file(name, 0444, dentry,
  18151. + &per_cpu(preemptoff_hist, i), &latency_hist_fops);
  18152. + my_hist = &per_cpu(preemptoff_hist, i);
  18153. + atomic_set(&my_hist->hist_mode, 1);
  18154. + my_hist->min_lat = LONG_MAX;
  18155. + }
  18156. + entry = debugfs_create_file("reset", 0644, dentry,
  18157. + (void *)PREEMPTOFF_LATENCY, &latency_hist_reset_fops);
  18158. +#endif
  18159. +
  18160. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  18161. + dentry = debugfs_create_dir(preemptirqsoff_hist_dir,
  18162. + latency_hist_root);
  18163. + for_each_possible_cpu(i) {
  18164. + sprintf(name, cpufmt, i);
  18165. + entry = debugfs_create_file(name, 0444, dentry,
  18166. + &per_cpu(preemptirqsoff_hist, i), &latency_hist_fops);
  18167. + my_hist = &per_cpu(preemptirqsoff_hist, i);
  18168. + atomic_set(&my_hist->hist_mode, 1);
  18169. + my_hist->min_lat = LONG_MAX;
  18170. + }
  18171. + entry = debugfs_create_file("reset", 0644, dentry,
  18172. + (void *)PREEMPTIRQSOFF_LATENCY, &latency_hist_reset_fops);
  18173. +#endif
  18174. +
  18175. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  18176. + entry = debugfs_create_file("preemptirqsoff", 0644,
  18177. + enable_root, (void *)&preemptirqsoff_enabled_data,
  18178. + &enable_fops);
  18179. +#endif
  18180. +
  18181. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  18182. + dentry = debugfs_create_dir(wakeup_latency_hist_dir,
  18183. + latency_hist_root);
  18184. + dentry_sharedprio = debugfs_create_dir(
  18185. + wakeup_latency_hist_dir_sharedprio, dentry);
  18186. + for_each_possible_cpu(i) {
  18187. + sprintf(name, cpufmt, i);
  18188. +
  18189. + entry = debugfs_create_file(name, 0444, dentry,
  18190. + &per_cpu(wakeup_latency_hist, i),
  18191. + &latency_hist_fops);
  18192. + my_hist = &per_cpu(wakeup_latency_hist, i);
  18193. + atomic_set(&my_hist->hist_mode, 1);
  18194. + my_hist->min_lat = LONG_MAX;
  18195. +
  18196. + entry = debugfs_create_file(name, 0444, dentry_sharedprio,
  18197. + &per_cpu(wakeup_latency_hist_sharedprio, i),
  18198. + &latency_hist_fops);
  18199. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, i);
  18200. + atomic_set(&my_hist->hist_mode, 1);
  18201. + my_hist->min_lat = LONG_MAX;
  18202. +
  18203. + sprintf(name, cpufmt_maxlatproc, i);
  18204. +
  18205. + mp = &per_cpu(wakeup_maxlatproc, i);
  18206. + entry = debugfs_create_file(name, 0444, dentry, mp,
  18207. + &maxlatproc_fops);
  18208. + clear_maxlatprocdata(mp);
  18209. +
  18210. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, i);
  18211. + entry = debugfs_create_file(name, 0444, dentry_sharedprio, mp,
  18212. + &maxlatproc_fops);
  18213. + clear_maxlatprocdata(mp);
  18214. + }
  18215. + entry = debugfs_create_file("pid", 0644, dentry,
  18216. + (void *)&wakeup_pid, &pid_fops);
  18217. + entry = debugfs_create_file("reset", 0644, dentry,
  18218. + (void *)WAKEUP_LATENCY, &latency_hist_reset_fops);
  18219. + entry = debugfs_create_file("reset", 0644, dentry_sharedprio,
  18220. + (void *)WAKEUP_LATENCY_SHAREDPRIO, &latency_hist_reset_fops);
  18221. + entry = debugfs_create_file("wakeup", 0644,
  18222. + enable_root, (void *)&wakeup_latency_enabled_data,
  18223. + &enable_fops);
  18224. +#endif
  18225. +
  18226. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  18227. + dentry = debugfs_create_dir(missed_timer_offsets_dir,
  18228. + latency_hist_root);
  18229. + for_each_possible_cpu(i) {
  18230. + sprintf(name, cpufmt, i);
  18231. + entry = debugfs_create_file(name, 0444, dentry,
  18232. + &per_cpu(missed_timer_offsets, i), &latency_hist_fops);
  18233. + my_hist = &per_cpu(missed_timer_offsets, i);
  18234. + atomic_set(&my_hist->hist_mode, 1);
  18235. + my_hist->min_lat = LONG_MAX;
  18236. +
  18237. + sprintf(name, cpufmt_maxlatproc, i);
  18238. + mp = &per_cpu(missed_timer_offsets_maxlatproc, i);
  18239. + entry = debugfs_create_file(name, 0444, dentry, mp,
  18240. + &maxlatproc_fops);
  18241. + clear_maxlatprocdata(mp);
  18242. + }
  18243. + entry = debugfs_create_file("pid", 0644, dentry,
  18244. + (void *)&missed_timer_offsets_pid, &pid_fops);
  18245. + entry = debugfs_create_file("reset", 0644, dentry,
  18246. + (void *)MISSED_TIMER_OFFSETS, &latency_hist_reset_fops);
  18247. + entry = debugfs_create_file("missed_timer_offsets", 0644,
  18248. + enable_root, (void *)&missed_timer_offsets_enabled_data,
  18249. + &enable_fops);
  18250. +#endif
  18251. +
  18252. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  18253. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  18254. + dentry = debugfs_create_dir(timerandwakeup_latency_hist_dir,
  18255. + latency_hist_root);
  18256. + for_each_possible_cpu(i) {
  18257. + sprintf(name, cpufmt, i);
  18258. + entry = debugfs_create_file(name, 0444, dentry,
  18259. + &per_cpu(timerandwakeup_latency_hist, i),
  18260. + &latency_hist_fops);
  18261. + my_hist = &per_cpu(timerandwakeup_latency_hist, i);
  18262. + atomic_set(&my_hist->hist_mode, 1);
  18263. + my_hist->min_lat = LONG_MAX;
  18264. +
  18265. + sprintf(name, cpufmt_maxlatproc, i);
  18266. + mp = &per_cpu(timerandwakeup_maxlatproc, i);
  18267. + entry = debugfs_create_file(name, 0444, dentry, mp,
  18268. + &maxlatproc_fops);
  18269. + clear_maxlatprocdata(mp);
  18270. + }
  18271. + entry = debugfs_create_file("reset", 0644, dentry,
  18272. + (void *)TIMERANDWAKEUP_LATENCY, &latency_hist_reset_fops);
  18273. + entry = debugfs_create_file("timerandwakeup", 0644,
  18274. + enable_root, (void *)&timerandwakeup_enabled_data,
  18275. + &enable_fops);
  18276. +#endif
  18277. + return 0;
  18278. +}
  18279. +
  18280. +device_initcall(latency_hist_init);
  18281. diff -Nur linux-4.9.6.orig/kernel/trace/Makefile linux-4.9.6/kernel/trace/Makefile
  18282. --- linux-4.9.6.orig/kernel/trace/Makefile 2017-01-26 08:25:24.000000000 +0100
  18283. +++ linux-4.9.6/kernel/trace/Makefile 2017-01-28 13:59:10.091662336 +0100
  18284. @@ -38,6 +38,10 @@
  18285. obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
  18286. obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
  18287. obj-$(CONFIG_HWLAT_TRACER) += trace_hwlat.o
  18288. +obj-$(CONFIG_INTERRUPT_OFF_HIST) += latency_hist.o
  18289. +obj-$(CONFIG_PREEMPT_OFF_HIST) += latency_hist.o
  18290. +obj-$(CONFIG_WAKEUP_LATENCY_HIST) += latency_hist.o
  18291. +obj-$(CONFIG_MISSED_TIMER_OFFSETS_HIST) += latency_hist.o
  18292. obj-$(CONFIG_NOP_TRACER) += trace_nop.o
  18293. obj-$(CONFIG_STACK_TRACER) += trace_stack.o
  18294. obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
  18295. diff -Nur linux-4.9.6.orig/kernel/trace/trace.c linux-4.9.6/kernel/trace/trace.c
  18296. --- linux-4.9.6.orig/kernel/trace/trace.c 2017-01-26 08:25:24.000000000 +0100
  18297. +++ linux-4.9.6/kernel/trace/trace.c 2017-01-28 13:59:10.091662336 +0100
  18298. @@ -1897,6 +1897,7 @@
  18299. struct task_struct *tsk = current;
  18300. entry->preempt_count = pc & 0xff;
  18301. + entry->preempt_lazy_count = preempt_lazy_count();
  18302. entry->pid = (tsk) ? tsk->pid : 0;
  18303. entry->flags =
  18304. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  18305. @@ -1907,8 +1908,11 @@
  18306. ((pc & NMI_MASK ) ? TRACE_FLAG_NMI : 0) |
  18307. ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
  18308. ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
  18309. - (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
  18310. + (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
  18311. + (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
  18312. (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
  18313. +
  18314. + entry->migrate_disable = (tsk) ? __migrate_disabled(tsk) & 0xFF : 0;
  18315. }
  18316. EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
  18317. @@ -2892,14 +2896,17 @@
  18318. static void print_lat_help_header(struct seq_file *m)
  18319. {
  18320. - seq_puts(m, "# _------=> CPU# \n"
  18321. - "# / _-----=> irqs-off \n"
  18322. - "# | / _----=> need-resched \n"
  18323. - "# || / _---=> hardirq/softirq \n"
  18324. - "# ||| / _--=> preempt-depth \n"
  18325. - "# |||| / delay \n"
  18326. - "# cmd pid ||||| time | caller \n"
  18327. - "# \\ / ||||| \\ | / \n");
  18328. + seq_puts(m, "# _--------=> CPU# \n"
  18329. + "# / _-------=> irqs-off \n"
  18330. + "# | / _------=> need-resched \n"
  18331. + "# || / _-----=> need-resched_lazy \n"
  18332. + "# ||| / _----=> hardirq/softirq \n"
  18333. + "# |||| / _---=> preempt-depth \n"
  18334. + "# ||||| / _--=> preempt-lazy-depth\n"
  18335. + "# |||||| / _-=> migrate-disable \n"
  18336. + "# ||||||| / delay \n"
  18337. + "# cmd pid |||||||| time | caller \n"
  18338. + "# \\ / |||||||| \\ | / \n");
  18339. }
  18340. static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
  18341. @@ -2925,11 +2932,14 @@
  18342. print_event_info(buf, m);
  18343. seq_puts(m, "# _-----=> irqs-off\n"
  18344. "# / _----=> need-resched\n"
  18345. - "# | / _---=> hardirq/softirq\n"
  18346. - "# || / _--=> preempt-depth\n"
  18347. - "# ||| / delay\n"
  18348. - "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
  18349. - "# | | | |||| | |\n");
  18350. + "# |/ _-----=> need-resched_lazy\n"
  18351. + "# || / _---=> hardirq/softirq\n"
  18352. + "# ||| / _--=> preempt-depth\n"
  18353. + "# |||| / _-=> preempt-lazy-depth\n"
  18354. + "# ||||| / _-=> migrate-disable \n"
  18355. + "# |||||| / delay\n"
  18356. + "# TASK-PID CPU# ||||||| TIMESTAMP FUNCTION\n"
  18357. + "# | | | ||||||| | |\n");
  18358. }
  18359. void
  18360. diff -Nur linux-4.9.6.orig/kernel/trace/trace_events.c linux-4.9.6/kernel/trace/trace_events.c
  18361. --- linux-4.9.6.orig/kernel/trace/trace_events.c 2017-01-26 08:25:24.000000000 +0100
  18362. +++ linux-4.9.6/kernel/trace/trace_events.c 2017-01-28 13:59:10.091662336 +0100
  18363. @@ -187,6 +187,8 @@
  18364. __common_field(unsigned char, flags);
  18365. __common_field(unsigned char, preempt_count);
  18366. __common_field(int, pid);
  18367. + __common_field(unsigned short, migrate_disable);
  18368. + __common_field(unsigned short, padding);
  18369. return ret;
  18370. }
  18371. diff -Nur linux-4.9.6.orig/kernel/trace/trace.h linux-4.9.6/kernel/trace/trace.h
  18372. --- linux-4.9.6.orig/kernel/trace/trace.h 2017-01-26 08:25:24.000000000 +0100
  18373. +++ linux-4.9.6/kernel/trace/trace.h 2017-01-28 13:59:10.091662336 +0100
  18374. @@ -124,6 +124,7 @@
  18375. * NEED_RESCHED - reschedule is requested
  18376. * HARDIRQ - inside an interrupt handler
  18377. * SOFTIRQ - inside a softirq handler
  18378. + * NEED_RESCHED_LAZY - lazy reschedule is requested
  18379. */
  18380. enum trace_flag_type {
  18381. TRACE_FLAG_IRQS_OFF = 0x01,
  18382. @@ -133,6 +134,7 @@
  18383. TRACE_FLAG_SOFTIRQ = 0x10,
  18384. TRACE_FLAG_PREEMPT_RESCHED = 0x20,
  18385. TRACE_FLAG_NMI = 0x40,
  18386. + TRACE_FLAG_NEED_RESCHED_LAZY = 0x80,
  18387. };
  18388. #define TRACE_BUF_SIZE 1024
  18389. diff -Nur linux-4.9.6.orig/kernel/trace/trace_irqsoff.c linux-4.9.6/kernel/trace/trace_irqsoff.c
  18390. --- linux-4.9.6.orig/kernel/trace/trace_irqsoff.c 2017-01-26 08:25:24.000000000 +0100
  18391. +++ linux-4.9.6/kernel/trace/trace_irqsoff.c 2017-01-28 13:59:10.091662336 +0100
  18392. @@ -13,6 +13,7 @@
  18393. #include <linux/uaccess.h>
  18394. #include <linux/module.h>
  18395. #include <linux/ftrace.h>
  18396. +#include <trace/events/hist.h>
  18397. #include "trace.h"
  18398. @@ -424,11 +425,13 @@
  18399. {
  18400. if (preempt_trace() || irq_trace())
  18401. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  18402. + trace_preemptirqsoff_hist_rcuidle(TRACE_START, 1);
  18403. }
  18404. EXPORT_SYMBOL_GPL(start_critical_timings);
  18405. void stop_critical_timings(void)
  18406. {
  18407. + trace_preemptirqsoff_hist_rcuidle(TRACE_STOP, 0);
  18408. if (preempt_trace() || irq_trace())
  18409. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  18410. }
  18411. @@ -438,6 +441,7 @@
  18412. #ifdef CONFIG_PROVE_LOCKING
  18413. void time_hardirqs_on(unsigned long a0, unsigned long a1)
  18414. {
  18415. + trace_preemptirqsoff_hist_rcuidle(IRQS_ON, 0);
  18416. if (!preempt_trace() && irq_trace())
  18417. stop_critical_timing(a0, a1);
  18418. }
  18419. @@ -446,6 +450,7 @@
  18420. {
  18421. if (!preempt_trace() && irq_trace())
  18422. start_critical_timing(a0, a1);
  18423. + trace_preemptirqsoff_hist_rcuidle(IRQS_OFF, 1);
  18424. }
  18425. #else /* !CONFIG_PROVE_LOCKING */
  18426. @@ -471,6 +476,7 @@
  18427. */
  18428. void trace_hardirqs_on(void)
  18429. {
  18430. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  18431. if (!preempt_trace() && irq_trace())
  18432. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  18433. }
  18434. @@ -480,11 +486,13 @@
  18435. {
  18436. if (!preempt_trace() && irq_trace())
  18437. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  18438. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  18439. }
  18440. EXPORT_SYMBOL(trace_hardirqs_off);
  18441. __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
  18442. {
  18443. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  18444. if (!preempt_trace() && irq_trace())
  18445. stop_critical_timing(CALLER_ADDR0, caller_addr);
  18446. }
  18447. @@ -494,6 +502,7 @@
  18448. {
  18449. if (!preempt_trace() && irq_trace())
  18450. start_critical_timing(CALLER_ADDR0, caller_addr);
  18451. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  18452. }
  18453. EXPORT_SYMBOL(trace_hardirqs_off_caller);
  18454. @@ -503,12 +512,14 @@
  18455. #ifdef CONFIG_PREEMPT_TRACER
  18456. void trace_preempt_on(unsigned long a0, unsigned long a1)
  18457. {
  18458. + trace_preemptirqsoff_hist(PREEMPT_ON, 0);
  18459. if (preempt_trace() && !irq_trace())
  18460. stop_critical_timing(a0, a1);
  18461. }
  18462. void trace_preempt_off(unsigned long a0, unsigned long a1)
  18463. {
  18464. + trace_preemptirqsoff_hist(PREEMPT_ON, 1);
  18465. if (preempt_trace() && !irq_trace())
  18466. start_critical_timing(a0, a1);
  18467. }
  18468. diff -Nur linux-4.9.6.orig/kernel/trace/trace_output.c linux-4.9.6/kernel/trace/trace_output.c
  18469. --- linux-4.9.6.orig/kernel/trace/trace_output.c 2017-01-26 08:25:24.000000000 +0100
  18470. +++ linux-4.9.6/kernel/trace/trace_output.c 2017-01-28 13:59:10.091662336 +0100
  18471. @@ -386,6 +386,7 @@
  18472. {
  18473. char hardsoft_irq;
  18474. char need_resched;
  18475. + char need_resched_lazy;
  18476. char irqs_off;
  18477. int hardirq;
  18478. int softirq;
  18479. @@ -416,6 +417,9 @@
  18480. break;
  18481. }
  18482. + need_resched_lazy =
  18483. + (entry->flags & TRACE_FLAG_NEED_RESCHED_LAZY) ? 'L' : '.';
  18484. +
  18485. hardsoft_irq =
  18486. (nmi && hardirq) ? 'Z' :
  18487. nmi ? 'z' :
  18488. @@ -424,14 +428,25 @@
  18489. softirq ? 's' :
  18490. '.' ;
  18491. - trace_seq_printf(s, "%c%c%c",
  18492. - irqs_off, need_resched, hardsoft_irq);
  18493. + trace_seq_printf(s, "%c%c%c%c",
  18494. + irqs_off, need_resched, need_resched_lazy,
  18495. + hardsoft_irq);
  18496. if (entry->preempt_count)
  18497. trace_seq_printf(s, "%x", entry->preempt_count);
  18498. else
  18499. trace_seq_putc(s, '.');
  18500. + if (entry->preempt_lazy_count)
  18501. + trace_seq_printf(s, "%x", entry->preempt_lazy_count);
  18502. + else
  18503. + trace_seq_putc(s, '.');
  18504. +
  18505. + if (entry->migrate_disable)
  18506. + trace_seq_printf(s, "%x", entry->migrate_disable);
  18507. + else
  18508. + trace_seq_putc(s, '.');
  18509. +
  18510. return !trace_seq_has_overflowed(s);
  18511. }
  18512. diff -Nur linux-4.9.6.orig/kernel/user.c linux-4.9.6/kernel/user.c
  18513. --- linux-4.9.6.orig/kernel/user.c 2017-01-26 08:25:24.000000000 +0100
  18514. +++ linux-4.9.6/kernel/user.c 2017-01-28 13:59:10.091662336 +0100
  18515. @@ -161,11 +161,11 @@
  18516. if (!up)
  18517. return;
  18518. - local_irq_save(flags);
  18519. + local_irq_save_nort(flags);
  18520. if (atomic_dec_and_lock(&up->__count, &uidhash_lock))
  18521. free_user(up, flags);
  18522. else
  18523. - local_irq_restore(flags);
  18524. + local_irq_restore_nort(flags);
  18525. }
  18526. struct user_struct *alloc_uid(kuid_t uid)
  18527. diff -Nur linux-4.9.6.orig/kernel/watchdog.c linux-4.9.6/kernel/watchdog.c
  18528. --- linux-4.9.6.orig/kernel/watchdog.c 2017-01-26 08:25:24.000000000 +0100
  18529. +++ linux-4.9.6/kernel/watchdog.c 2017-01-28 13:59:10.091662336 +0100
  18530. @@ -315,6 +315,8 @@
  18531. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  18532. +static DEFINE_RAW_SPINLOCK(watchdog_output_lock);
  18533. +
  18534. static struct perf_event_attr wd_hw_attr = {
  18535. .type = PERF_TYPE_HARDWARE,
  18536. .config = PERF_COUNT_HW_CPU_CYCLES,
  18537. @@ -348,6 +350,13 @@
  18538. /* only print hardlockups once */
  18539. if (__this_cpu_read(hard_watchdog_warn) == true)
  18540. return;
  18541. + /*
  18542. + * If early-printk is enabled then make sure we do not
  18543. + * lock up in printk() and kill console logging:
  18544. + */
  18545. + printk_kill();
  18546. +
  18547. + raw_spin_lock(&watchdog_output_lock);
  18548. pr_emerg("Watchdog detected hard LOCKUP on cpu %d", this_cpu);
  18549. print_modules();
  18550. @@ -365,6 +374,7 @@
  18551. !test_and_set_bit(0, &hardlockup_allcpu_dumped))
  18552. trigger_allbutself_cpu_backtrace();
  18553. + raw_spin_unlock(&watchdog_output_lock);
  18554. if (hardlockup_panic)
  18555. nmi_panic(regs, "Hard LOCKUP");
  18556. @@ -512,6 +522,7 @@
  18557. /* kick off the timer for the hardlockup detector */
  18558. hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  18559. hrtimer->function = watchdog_timer_fn;
  18560. + hrtimer->irqsafe = 1;
  18561. /* Enable the perf event */
  18562. watchdog_nmi_enable(cpu);
  18563. diff -Nur linux-4.9.6.orig/kernel/workqueue.c linux-4.9.6/kernel/workqueue.c
  18564. --- linux-4.9.6.orig/kernel/workqueue.c 2017-01-26 08:25:24.000000000 +0100
  18565. +++ linux-4.9.6/kernel/workqueue.c 2017-01-28 13:59:10.095662491 +0100
  18566. @@ -48,6 +48,8 @@
  18567. #include <linux/nodemask.h>
  18568. #include <linux/moduleparam.h>
  18569. #include <linux/uaccess.h>
  18570. +#include <linux/locallock.h>
  18571. +#include <linux/delay.h>
  18572. #include "workqueue_internal.h"
  18573. @@ -121,11 +123,16 @@
  18574. * cpu or grabbing pool->lock is enough for read access. If
  18575. * POOL_DISASSOCIATED is set, it's identical to L.
  18576. *
  18577. + * On RT we need the extra protection via rt_lock_idle_list() for
  18578. + * the list manipulations against read access from
  18579. + * wq_worker_sleeping(). All other places are nicely serialized via
  18580. + * pool->lock.
  18581. + *
  18582. * A: pool->attach_mutex protected.
  18583. *
  18584. * PL: wq_pool_mutex protected.
  18585. *
  18586. - * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
  18587. + * PR: wq_pool_mutex protected for writes. RCU protected for reads.
  18588. *
  18589. * PW: wq_pool_mutex and wq->mutex protected for writes. Either for reads.
  18590. *
  18591. @@ -134,7 +141,7 @@
  18592. *
  18593. * WQ: wq->mutex protected.
  18594. *
  18595. - * WR: wq->mutex protected for writes. Sched-RCU protected for reads.
  18596. + * WR: wq->mutex protected for writes. RCU protected for reads.
  18597. *
  18598. * MD: wq_mayday_lock protected.
  18599. */
  18600. @@ -185,7 +192,7 @@
  18601. atomic_t nr_running ____cacheline_aligned_in_smp;
  18602. /*
  18603. - * Destruction of pool is sched-RCU protected to allow dereferences
  18604. + * Destruction of pool is RCU protected to allow dereferences
  18605. * from get_work_pool().
  18606. */
  18607. struct rcu_head rcu;
  18608. @@ -214,7 +221,7 @@
  18609. /*
  18610. * Release of unbound pwq is punted to system_wq. See put_pwq()
  18611. * and pwq_unbound_release_workfn() for details. pool_workqueue
  18612. - * itself is also sched-RCU protected so that the first pwq can be
  18613. + * itself is also RCU protected so that the first pwq can be
  18614. * determined without grabbing wq->mutex.
  18615. */
  18616. struct work_struct unbound_release_work;
  18617. @@ -348,6 +355,8 @@
  18618. struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
  18619. EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
  18620. +static DEFINE_LOCAL_IRQ_LOCK(pendingb_lock);
  18621. +
  18622. static int worker_thread(void *__worker);
  18623. static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
  18624. @@ -355,20 +364,20 @@
  18625. #include <trace/events/workqueue.h>
  18626. #define assert_rcu_or_pool_mutex() \
  18627. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  18628. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  18629. !lockdep_is_held(&wq_pool_mutex), \
  18630. - "sched RCU or wq_pool_mutex should be held")
  18631. + "RCU or wq_pool_mutex should be held")
  18632. #define assert_rcu_or_wq_mutex(wq) \
  18633. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  18634. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  18635. !lockdep_is_held(&wq->mutex), \
  18636. - "sched RCU or wq->mutex should be held")
  18637. + "RCU or wq->mutex should be held")
  18638. #define assert_rcu_or_wq_mutex_or_pool_mutex(wq) \
  18639. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  18640. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  18641. !lockdep_is_held(&wq->mutex) && \
  18642. !lockdep_is_held(&wq_pool_mutex), \
  18643. - "sched RCU, wq->mutex or wq_pool_mutex should be held")
  18644. + "RCU, wq->mutex or wq_pool_mutex should be held")
  18645. #define for_each_cpu_worker_pool(pool, cpu) \
  18646. for ((pool) = &per_cpu(cpu_worker_pools, cpu)[0]; \
  18647. @@ -380,7 +389,7 @@
  18648. * @pool: iteration cursor
  18649. * @pi: integer used for iteration
  18650. *
  18651. - * This must be called either with wq_pool_mutex held or sched RCU read
  18652. + * This must be called either with wq_pool_mutex held or RCU read
  18653. * locked. If the pool needs to be used beyond the locking in effect, the
  18654. * caller is responsible for guaranteeing that the pool stays online.
  18655. *
  18656. @@ -412,7 +421,7 @@
  18657. * @pwq: iteration cursor
  18658. * @wq: the target workqueue
  18659. *
  18660. - * This must be called either with wq->mutex held or sched RCU read locked.
  18661. + * This must be called either with wq->mutex held or RCU read locked.
  18662. * If the pwq needs to be used beyond the locking in effect, the caller is
  18663. * responsible for guaranteeing that the pwq stays online.
  18664. *
  18665. @@ -424,6 +433,31 @@
  18666. if (({ assert_rcu_or_wq_mutex(wq); false; })) { } \
  18667. else
  18668. +#ifdef CONFIG_PREEMPT_RT_BASE
  18669. +static inline void rt_lock_idle_list(struct worker_pool *pool)
  18670. +{
  18671. + preempt_disable();
  18672. +}
  18673. +static inline void rt_unlock_idle_list(struct worker_pool *pool)
  18674. +{
  18675. + preempt_enable();
  18676. +}
  18677. +static inline void sched_lock_idle_list(struct worker_pool *pool) { }
  18678. +static inline void sched_unlock_idle_list(struct worker_pool *pool) { }
  18679. +#else
  18680. +static inline void rt_lock_idle_list(struct worker_pool *pool) { }
  18681. +static inline void rt_unlock_idle_list(struct worker_pool *pool) { }
  18682. +static inline void sched_lock_idle_list(struct worker_pool *pool)
  18683. +{
  18684. + spin_lock_irq(&pool->lock);
  18685. +}
  18686. +static inline void sched_unlock_idle_list(struct worker_pool *pool)
  18687. +{
  18688. + spin_unlock_irq(&pool->lock);
  18689. +}
  18690. +#endif
  18691. +
  18692. +
  18693. #ifdef CONFIG_DEBUG_OBJECTS_WORK
  18694. static struct debug_obj_descr work_debug_descr;
  18695. @@ -548,7 +582,7 @@
  18696. * @wq: the target workqueue
  18697. * @node: the node ID
  18698. *
  18699. - * This must be called with any of wq_pool_mutex, wq->mutex or sched RCU
  18700. + * This must be called with any of wq_pool_mutex, wq->mutex or RCU
  18701. * read locked.
  18702. * If the pwq needs to be used beyond the locking in effect, the caller is
  18703. * responsible for guaranteeing that the pwq stays online.
  18704. @@ -692,8 +726,8 @@
  18705. * @work: the work item of interest
  18706. *
  18707. * Pools are created and destroyed under wq_pool_mutex, and allows read
  18708. - * access under sched-RCU read lock. As such, this function should be
  18709. - * called under wq_pool_mutex or with preemption disabled.
  18710. + * access under RCU read lock. As such, this function should be
  18711. + * called under wq_pool_mutex or inside of a rcu_read_lock() region.
  18712. *
  18713. * All fields of the returned pool are accessible as long as the above
  18714. * mentioned locking is in effect. If the returned pool needs to be used
  18715. @@ -830,50 +864,45 @@
  18716. */
  18717. static void wake_up_worker(struct worker_pool *pool)
  18718. {
  18719. - struct worker *worker = first_idle_worker(pool);
  18720. + struct worker *worker;
  18721. +
  18722. + rt_lock_idle_list(pool);
  18723. +
  18724. + worker = first_idle_worker(pool);
  18725. if (likely(worker))
  18726. wake_up_process(worker->task);
  18727. +
  18728. + rt_unlock_idle_list(pool);
  18729. }
  18730. /**
  18731. - * wq_worker_waking_up - a worker is waking up
  18732. + * wq_worker_running - a worker is running again
  18733. * @task: task waking up
  18734. - * @cpu: CPU @task is waking up to
  18735. - *
  18736. - * This function is called during try_to_wake_up() when a worker is
  18737. - * being awoken.
  18738. *
  18739. - * CONTEXT:
  18740. - * spin_lock_irq(rq->lock)
  18741. + * This function is called when a worker returns from schedule()
  18742. */
  18743. -void wq_worker_waking_up(struct task_struct *task, int cpu)
  18744. +void wq_worker_running(struct task_struct *task)
  18745. {
  18746. struct worker *worker = kthread_data(task);
  18747. - if (!(worker->flags & WORKER_NOT_RUNNING)) {
  18748. - WARN_ON_ONCE(worker->pool->cpu != cpu);
  18749. + if (!worker->sleeping)
  18750. + return;
  18751. + if (!(worker->flags & WORKER_NOT_RUNNING))
  18752. atomic_inc(&worker->pool->nr_running);
  18753. - }
  18754. + worker->sleeping = 0;
  18755. }
  18756. /**
  18757. * wq_worker_sleeping - a worker is going to sleep
  18758. * @task: task going to sleep
  18759. *
  18760. - * This function is called during schedule() when a busy worker is
  18761. - * going to sleep. Worker on the same cpu can be woken up by
  18762. - * returning pointer to its task.
  18763. - *
  18764. - * CONTEXT:
  18765. - * spin_lock_irq(rq->lock)
  18766. - *
  18767. - * Return:
  18768. - * Worker task on @cpu to wake up, %NULL if none.
  18769. + * This function is called from schedule() when a busy worker is
  18770. + * going to sleep.
  18771. */
  18772. -struct task_struct *wq_worker_sleeping(struct task_struct *task)
  18773. +void wq_worker_sleeping(struct task_struct *task)
  18774. {
  18775. - struct worker *worker = kthread_data(task), *to_wakeup = NULL;
  18776. + struct worker *worker = kthread_data(task);
  18777. struct worker_pool *pool;
  18778. /*
  18779. @@ -882,29 +911,26 @@
  18780. * checking NOT_RUNNING.
  18781. */
  18782. if (worker->flags & WORKER_NOT_RUNNING)
  18783. - return NULL;
  18784. + return;
  18785. pool = worker->pool;
  18786. - /* this can only happen on the local cpu */
  18787. - if (WARN_ON_ONCE(pool->cpu != raw_smp_processor_id()))
  18788. - return NULL;
  18789. + if (WARN_ON_ONCE(worker->sleeping))
  18790. + return;
  18791. +
  18792. + worker->sleeping = 1;
  18793. /*
  18794. * The counterpart of the following dec_and_test, implied mb,
  18795. * worklist not empty test sequence is in insert_work().
  18796. * Please read comment there.
  18797. - *
  18798. - * NOT_RUNNING is clear. This means that we're bound to and
  18799. - * running on the local cpu w/ rq lock held and preemption
  18800. - * disabled, which in turn means that none else could be
  18801. - * manipulating idle_list, so dereferencing idle_list without pool
  18802. - * lock is safe.
  18803. */
  18804. if (atomic_dec_and_test(&pool->nr_running) &&
  18805. - !list_empty(&pool->worklist))
  18806. - to_wakeup = first_idle_worker(pool);
  18807. - return to_wakeup ? to_wakeup->task : NULL;
  18808. + !list_empty(&pool->worklist)) {
  18809. + sched_lock_idle_list(pool);
  18810. + wake_up_worker(pool);
  18811. + sched_unlock_idle_list(pool);
  18812. + }
  18813. }
  18814. /**
  18815. @@ -1098,12 +1124,14 @@
  18816. {
  18817. if (pwq) {
  18818. /*
  18819. - * As both pwqs and pools are sched-RCU protected, the
  18820. + * As both pwqs and pools are RCU protected, the
  18821. * following lock operations are safe.
  18822. */
  18823. - spin_lock_irq(&pwq->pool->lock);
  18824. + rcu_read_lock();
  18825. + local_spin_lock_irq(pendingb_lock, &pwq->pool->lock);
  18826. put_pwq(pwq);
  18827. - spin_unlock_irq(&pwq->pool->lock);
  18828. + local_spin_unlock_irq(pendingb_lock, &pwq->pool->lock);
  18829. + rcu_read_unlock();
  18830. }
  18831. }
  18832. @@ -1207,7 +1235,7 @@
  18833. struct worker_pool *pool;
  18834. struct pool_workqueue *pwq;
  18835. - local_irq_save(*flags);
  18836. + local_lock_irqsave(pendingb_lock, *flags);
  18837. /* try to steal the timer if it exists */
  18838. if (is_dwork) {
  18839. @@ -1226,6 +1254,7 @@
  18840. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
  18841. return 0;
  18842. + rcu_read_lock();
  18843. /*
  18844. * The queueing is in progress, or it is already queued. Try to
  18845. * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
  18846. @@ -1264,14 +1293,16 @@
  18847. set_work_pool_and_keep_pending(work, pool->id);
  18848. spin_unlock(&pool->lock);
  18849. + rcu_read_unlock();
  18850. return 1;
  18851. }
  18852. spin_unlock(&pool->lock);
  18853. fail:
  18854. - local_irq_restore(*flags);
  18855. + rcu_read_unlock();
  18856. + local_unlock_irqrestore(pendingb_lock, *flags);
  18857. if (work_is_canceling(work))
  18858. return -ENOENT;
  18859. - cpu_relax();
  18860. + cpu_chill();
  18861. return -EAGAIN;
  18862. }
  18863. @@ -1373,7 +1404,7 @@
  18864. * queued or lose PENDING. Grabbing PENDING and queueing should
  18865. * happen with IRQ disabled.
  18866. */
  18867. - WARN_ON_ONCE(!irqs_disabled());
  18868. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  18869. debug_work_activate(work);
  18870. @@ -1381,6 +1412,7 @@
  18871. if (unlikely(wq->flags & __WQ_DRAINING) &&
  18872. WARN_ON_ONCE(!is_chained_work(wq)))
  18873. return;
  18874. + rcu_read_lock();
  18875. retry:
  18876. if (req_cpu == WORK_CPU_UNBOUND)
  18877. cpu = wq_select_unbound_cpu(raw_smp_processor_id());
  18878. @@ -1437,10 +1469,8 @@
  18879. /* pwq determined, queue */
  18880. trace_workqueue_queue_work(req_cpu, pwq, work);
  18881. - if (WARN_ON(!list_empty(&work->entry))) {
  18882. - spin_unlock(&pwq->pool->lock);
  18883. - return;
  18884. - }
  18885. + if (WARN_ON(!list_empty(&work->entry)))
  18886. + goto out;
  18887. pwq->nr_in_flight[pwq->work_color]++;
  18888. work_flags = work_color_to_flags(pwq->work_color);
  18889. @@ -1458,7 +1488,9 @@
  18890. insert_work(pwq, work, worklist, work_flags);
  18891. +out:
  18892. spin_unlock(&pwq->pool->lock);
  18893. + rcu_read_unlock();
  18894. }
  18895. /**
  18896. @@ -1478,14 +1510,14 @@
  18897. bool ret = false;
  18898. unsigned long flags;
  18899. - local_irq_save(flags);
  18900. + local_lock_irqsave(pendingb_lock,flags);
  18901. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  18902. __queue_work(cpu, wq, work);
  18903. ret = true;
  18904. }
  18905. - local_irq_restore(flags);
  18906. + local_unlock_irqrestore(pendingb_lock, flags);
  18907. return ret;
  18908. }
  18909. EXPORT_SYMBOL(queue_work_on);
  18910. @@ -1552,14 +1584,14 @@
  18911. unsigned long flags;
  18912. /* read the comment in __queue_work() */
  18913. - local_irq_save(flags);
  18914. + local_lock_irqsave(pendingb_lock, flags);
  18915. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  18916. __queue_delayed_work(cpu, wq, dwork, delay);
  18917. ret = true;
  18918. }
  18919. - local_irq_restore(flags);
  18920. + local_unlock_irqrestore(pendingb_lock, flags);
  18921. return ret;
  18922. }
  18923. EXPORT_SYMBOL(queue_delayed_work_on);
  18924. @@ -1594,7 +1626,7 @@
  18925. if (likely(ret >= 0)) {
  18926. __queue_delayed_work(cpu, wq, dwork, delay);
  18927. - local_irq_restore(flags);
  18928. + local_unlock_irqrestore(pendingb_lock, flags);
  18929. }
  18930. /* -ENOENT from try_to_grab_pending() becomes %true */
  18931. @@ -1627,7 +1659,9 @@
  18932. worker->last_active = jiffies;
  18933. /* idle_list is LIFO */
  18934. + rt_lock_idle_list(pool);
  18935. list_add(&worker->entry, &pool->idle_list);
  18936. + rt_unlock_idle_list(pool);
  18937. if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
  18938. mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
  18939. @@ -1660,7 +1694,9 @@
  18940. return;
  18941. worker_clr_flags(worker, WORKER_IDLE);
  18942. pool->nr_idle--;
  18943. + rt_lock_idle_list(pool);
  18944. list_del_init(&worker->entry);
  18945. + rt_unlock_idle_list(pool);
  18946. }
  18947. static struct worker *alloc_worker(int node)
  18948. @@ -1826,7 +1862,9 @@
  18949. pool->nr_workers--;
  18950. pool->nr_idle--;
  18951. + rt_lock_idle_list(pool);
  18952. list_del_init(&worker->entry);
  18953. + rt_unlock_idle_list(pool);
  18954. worker->flags |= WORKER_DIE;
  18955. wake_up_process(worker->task);
  18956. }
  18957. @@ -2785,14 +2823,14 @@
  18958. might_sleep();
  18959. - local_irq_disable();
  18960. + rcu_read_lock();
  18961. pool = get_work_pool(work);
  18962. if (!pool) {
  18963. - local_irq_enable();
  18964. + rcu_read_unlock();
  18965. return false;
  18966. }
  18967. - spin_lock(&pool->lock);
  18968. + spin_lock_irq(&pool->lock);
  18969. /* see the comment in try_to_grab_pending() with the same code */
  18970. pwq = get_work_pwq(work);
  18971. if (pwq) {
  18972. @@ -2821,10 +2859,11 @@
  18973. else
  18974. lock_map_acquire_read(&pwq->wq->lockdep_map);
  18975. lock_map_release(&pwq->wq->lockdep_map);
  18976. -
  18977. + rcu_read_unlock();
  18978. return true;
  18979. already_gone:
  18980. spin_unlock_irq(&pool->lock);
  18981. + rcu_read_unlock();
  18982. return false;
  18983. }
  18984. @@ -2911,7 +2950,7 @@
  18985. /* tell other tasks trying to grab @work to back off */
  18986. mark_work_canceling(work);
  18987. - local_irq_restore(flags);
  18988. + local_unlock_irqrestore(pendingb_lock, flags);
  18989. flush_work(work);
  18990. clear_work_data(work);
  18991. @@ -2966,10 +3005,10 @@
  18992. */
  18993. bool flush_delayed_work(struct delayed_work *dwork)
  18994. {
  18995. - local_irq_disable();
  18996. + local_lock_irq(pendingb_lock);
  18997. if (del_timer_sync(&dwork->timer))
  18998. __queue_work(dwork->cpu, dwork->wq, &dwork->work);
  18999. - local_irq_enable();
  19000. + local_unlock_irq(pendingb_lock);
  19001. return flush_work(&dwork->work);
  19002. }
  19003. EXPORT_SYMBOL(flush_delayed_work);
  19004. @@ -2987,7 +3026,7 @@
  19005. return false;
  19006. set_work_pool_and_clear_pending(work, get_work_pool_id(work));
  19007. - local_irq_restore(flags);
  19008. + local_unlock_irqrestore(pendingb_lock, flags);
  19009. return ret;
  19010. }
  19011. @@ -3245,7 +3284,7 @@
  19012. * put_unbound_pool - put a worker_pool
  19013. * @pool: worker_pool to put
  19014. *
  19015. - * Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
  19016. + * Put @pool. If its refcnt reaches zero, it gets destroyed in RCU
  19017. * safe manner. get_unbound_pool() calls this function on its failure path
  19018. * and this function should be able to release pools which went through,
  19019. * successfully or not, init_worker_pool().
  19020. @@ -3299,8 +3338,8 @@
  19021. del_timer_sync(&pool->idle_timer);
  19022. del_timer_sync(&pool->mayday_timer);
  19023. - /* sched-RCU protected to allow dereferences from get_work_pool() */
  19024. - call_rcu_sched(&pool->rcu, rcu_free_pool);
  19025. + /* RCU protected to allow dereferences from get_work_pool() */
  19026. + call_rcu(&pool->rcu, rcu_free_pool);
  19027. }
  19028. /**
  19029. @@ -3407,14 +3446,14 @@
  19030. put_unbound_pool(pool);
  19031. mutex_unlock(&wq_pool_mutex);
  19032. - call_rcu_sched(&pwq->rcu, rcu_free_pwq);
  19033. + call_rcu(&pwq->rcu, rcu_free_pwq);
  19034. /*
  19035. * If we're the last pwq going away, @wq is already dead and no one
  19036. * is gonna access it anymore. Schedule RCU free.
  19037. */
  19038. if (is_last)
  19039. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  19040. + call_rcu(&wq->rcu, rcu_free_wq);
  19041. }
  19042. /**
  19043. @@ -4064,7 +4103,7 @@
  19044. * The base ref is never dropped on per-cpu pwqs. Directly
  19045. * schedule RCU free.
  19046. */
  19047. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  19048. + call_rcu(&wq->rcu, rcu_free_wq);
  19049. } else {
  19050. /*
  19051. * We're the sole accessor of @wq at this point. Directly
  19052. @@ -4157,7 +4196,8 @@
  19053. struct pool_workqueue *pwq;
  19054. bool ret;
  19055. - rcu_read_lock_sched();
  19056. + rcu_read_lock();
  19057. + preempt_disable();
  19058. if (cpu == WORK_CPU_UNBOUND)
  19059. cpu = smp_processor_id();
  19060. @@ -4168,7 +4208,8 @@
  19061. pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
  19062. ret = !list_empty(&pwq->delayed_works);
  19063. - rcu_read_unlock_sched();
  19064. + preempt_enable();
  19065. + rcu_read_unlock();
  19066. return ret;
  19067. }
  19068. @@ -4194,15 +4235,15 @@
  19069. if (work_pending(work))
  19070. ret |= WORK_BUSY_PENDING;
  19071. - local_irq_save(flags);
  19072. + rcu_read_lock();
  19073. pool = get_work_pool(work);
  19074. if (pool) {
  19075. - spin_lock(&pool->lock);
  19076. + spin_lock_irqsave(&pool->lock, flags);
  19077. if (find_worker_executing_work(pool, work))
  19078. ret |= WORK_BUSY_RUNNING;
  19079. - spin_unlock(&pool->lock);
  19080. + spin_unlock_irqrestore(&pool->lock, flags);
  19081. }
  19082. - local_irq_restore(flags);
  19083. + rcu_read_unlock();
  19084. return ret;
  19085. }
  19086. @@ -4391,7 +4432,7 @@
  19087. unsigned long flags;
  19088. int pi;
  19089. - rcu_read_lock_sched();
  19090. + rcu_read_lock();
  19091. pr_info("Showing busy workqueues and worker pools:\n");
  19092. @@ -4444,7 +4485,7 @@
  19093. spin_unlock_irqrestore(&pool->lock, flags);
  19094. }
  19095. - rcu_read_unlock_sched();
  19096. + rcu_read_unlock();
  19097. }
  19098. /*
  19099. @@ -4782,16 +4823,16 @@
  19100. * nr_active is monotonically decreasing. It's safe
  19101. * to peek without lock.
  19102. */
  19103. - rcu_read_lock_sched();
  19104. + rcu_read_lock();
  19105. for_each_pwq(pwq, wq) {
  19106. WARN_ON_ONCE(pwq->nr_active < 0);
  19107. if (pwq->nr_active) {
  19108. busy = true;
  19109. - rcu_read_unlock_sched();
  19110. + rcu_read_unlock();
  19111. goto out_unlock;
  19112. }
  19113. }
  19114. - rcu_read_unlock_sched();
  19115. + rcu_read_unlock();
  19116. }
  19117. out_unlock:
  19118. mutex_unlock(&wq_pool_mutex);
  19119. @@ -4981,7 +5022,8 @@
  19120. const char *delim = "";
  19121. int node, written = 0;
  19122. - rcu_read_lock_sched();
  19123. + get_online_cpus();
  19124. + rcu_read_lock();
  19125. for_each_node(node) {
  19126. written += scnprintf(buf + written, PAGE_SIZE - written,
  19127. "%s%d:%d", delim, node,
  19128. @@ -4989,7 +5031,8 @@
  19129. delim = " ";
  19130. }
  19131. written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
  19132. - rcu_read_unlock_sched();
  19133. + rcu_read_unlock();
  19134. + put_online_cpus();
  19135. return written;
  19136. }
  19137. diff -Nur linux-4.9.6.orig/kernel/workqueue_internal.h linux-4.9.6/kernel/workqueue_internal.h
  19138. --- linux-4.9.6.orig/kernel/workqueue_internal.h 2017-01-26 08:25:24.000000000 +0100
  19139. +++ linux-4.9.6/kernel/workqueue_internal.h 2017-01-28 13:59:10.095662491 +0100
  19140. @@ -43,6 +43,7 @@
  19141. unsigned long last_active; /* L: last active timestamp */
  19142. unsigned int flags; /* X: flags */
  19143. int id; /* I: worker id */
  19144. + int sleeping; /* None */
  19145. /*
  19146. * Opaque string set with work_set_desc(). Printed out with task
  19147. @@ -68,7 +69,7 @@
  19148. * Scheduler hooks for concurrency managed workqueue. Only to be used from
  19149. * sched/core.c and workqueue.c.
  19150. */
  19151. -void wq_worker_waking_up(struct task_struct *task, int cpu);
  19152. -struct task_struct *wq_worker_sleeping(struct task_struct *task);
  19153. +void wq_worker_running(struct task_struct *task);
  19154. +void wq_worker_sleeping(struct task_struct *task);
  19155. #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */
  19156. diff -Nur linux-4.9.6.orig/lib/debugobjects.c linux-4.9.6/lib/debugobjects.c
  19157. --- linux-4.9.6.orig/lib/debugobjects.c 2017-01-26 08:25:24.000000000 +0100
  19158. +++ linux-4.9.6/lib/debugobjects.c 2017-01-28 13:59:10.095662491 +0100
  19159. @@ -308,7 +308,10 @@
  19160. struct debug_obj *obj;
  19161. unsigned long flags;
  19162. - fill_pool();
  19163. +#ifdef CONFIG_PREEMPT_RT_FULL
  19164. + if (preempt_count() == 0 && !irqs_disabled())
  19165. +#endif
  19166. + fill_pool();
  19167. db = get_bucket((unsigned long) addr);
  19168. diff -Nur linux-4.9.6.orig/lib/idr.c linux-4.9.6/lib/idr.c
  19169. --- linux-4.9.6.orig/lib/idr.c 2017-01-26 08:25:24.000000000 +0100
  19170. +++ linux-4.9.6/lib/idr.c 2017-01-28 13:59:10.095662491 +0100
  19171. @@ -30,6 +30,7 @@
  19172. #include <linux/idr.h>
  19173. #include <linux/spinlock.h>
  19174. #include <linux/percpu.h>
  19175. +#include <linux/locallock.h>
  19176. #define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
  19177. #define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
  19178. @@ -45,6 +46,37 @@
  19179. static DEFINE_PER_CPU(int, idr_preload_cnt);
  19180. static DEFINE_SPINLOCK(simple_ida_lock);
  19181. +#ifdef CONFIG_PREEMPT_RT_FULL
  19182. +static DEFINE_LOCAL_IRQ_LOCK(idr_lock);
  19183. +
  19184. +static inline void idr_preload_lock(void)
  19185. +{
  19186. + local_lock(idr_lock);
  19187. +}
  19188. +
  19189. +static inline void idr_preload_unlock(void)
  19190. +{
  19191. + local_unlock(idr_lock);
  19192. +}
  19193. +
  19194. +void idr_preload_end(void)
  19195. +{
  19196. + idr_preload_unlock();
  19197. +}
  19198. +EXPORT_SYMBOL(idr_preload_end);
  19199. +#else
  19200. +static inline void idr_preload_lock(void)
  19201. +{
  19202. + preempt_disable();
  19203. +}
  19204. +
  19205. +static inline void idr_preload_unlock(void)
  19206. +{
  19207. + preempt_enable();
  19208. +}
  19209. +#endif
  19210. +
  19211. +
  19212. /* the maximum ID which can be allocated given idr->layers */
  19213. static int idr_max(int layers)
  19214. {
  19215. @@ -115,14 +147,14 @@
  19216. * context. See idr_preload() for details.
  19217. */
  19218. if (!in_interrupt()) {
  19219. - preempt_disable();
  19220. + idr_preload_lock();
  19221. new = __this_cpu_read(idr_preload_head);
  19222. if (new) {
  19223. __this_cpu_write(idr_preload_head, new->ary[0]);
  19224. __this_cpu_dec(idr_preload_cnt);
  19225. new->ary[0] = NULL;
  19226. }
  19227. - preempt_enable();
  19228. + idr_preload_unlock();
  19229. if (new)
  19230. return new;
  19231. }
  19232. @@ -366,7 +398,6 @@
  19233. idr_mark_full(pa, id);
  19234. }
  19235. -
  19236. /**
  19237. * idr_preload - preload for idr_alloc()
  19238. * @gfp_mask: allocation mask to use for preloading
  19239. @@ -401,7 +432,7 @@
  19240. WARN_ON_ONCE(in_interrupt());
  19241. might_sleep_if(gfpflags_allow_blocking(gfp_mask));
  19242. - preempt_disable();
  19243. + idr_preload_lock();
  19244. /*
  19245. * idr_alloc() is likely to succeed w/o full idr_layer buffer and
  19246. @@ -413,9 +444,9 @@
  19247. while (__this_cpu_read(idr_preload_cnt) < MAX_IDR_FREE) {
  19248. struct idr_layer *new;
  19249. - preempt_enable();
  19250. + idr_preload_unlock();
  19251. new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
  19252. - preempt_disable();
  19253. + idr_preload_lock();
  19254. if (!new)
  19255. break;
  19256. diff -Nur linux-4.9.6.orig/lib/irq_poll.c linux-4.9.6/lib/irq_poll.c
  19257. --- linux-4.9.6.orig/lib/irq_poll.c 2017-01-26 08:25:24.000000000 +0100
  19258. +++ linux-4.9.6/lib/irq_poll.c 2017-01-28 13:59:10.095662491 +0100
  19259. @@ -36,6 +36,7 @@
  19260. list_add_tail(&iop->list, this_cpu_ptr(&blk_cpu_iopoll));
  19261. __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
  19262. local_irq_restore(flags);
  19263. + preempt_check_resched_rt();
  19264. }
  19265. EXPORT_SYMBOL(irq_poll_sched);
  19266. @@ -71,6 +72,7 @@
  19267. local_irq_save(flags);
  19268. __irq_poll_complete(iop);
  19269. local_irq_restore(flags);
  19270. + preempt_check_resched_rt();
  19271. }
  19272. EXPORT_SYMBOL(irq_poll_complete);
  19273. @@ -95,6 +97,7 @@
  19274. }
  19275. local_irq_enable();
  19276. + preempt_check_resched_rt();
  19277. /* Even though interrupts have been re-enabled, this
  19278. * access is safe because interrupts can only add new
  19279. @@ -132,6 +135,7 @@
  19280. __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
  19281. local_irq_enable();
  19282. + preempt_check_resched_rt();
  19283. }
  19284. /**
  19285. @@ -195,6 +199,7 @@
  19286. this_cpu_ptr(&blk_cpu_iopoll));
  19287. __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
  19288. local_irq_enable();
  19289. + preempt_check_resched_rt();
  19290. return 0;
  19291. }
  19292. diff -Nur linux-4.9.6.orig/lib/Kconfig linux-4.9.6/lib/Kconfig
  19293. --- linux-4.9.6.orig/lib/Kconfig 2017-01-26 08:25:24.000000000 +0100
  19294. +++ linux-4.9.6/lib/Kconfig 2017-01-28 13:59:10.095662491 +0100
  19295. @@ -400,6 +400,7 @@
  19296. config CPUMASK_OFFSTACK
  19297. bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS
  19298. + depends on !PREEMPT_RT_FULL
  19299. help
  19300. Use dynamic allocation for cpumask_var_t, instead of putting
  19301. them on the stack. This is a bit more expensive, but avoids
  19302. diff -Nur linux-4.9.6.orig/lib/locking-selftest.c linux-4.9.6/lib/locking-selftest.c
  19303. --- linux-4.9.6.orig/lib/locking-selftest.c 2017-01-26 08:25:24.000000000 +0100
  19304. +++ linux-4.9.6/lib/locking-selftest.c 2017-01-28 13:59:10.095662491 +0100
  19305. @@ -590,6 +590,8 @@
  19306. #include "locking-selftest-spin-hardirq.h"
  19307. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  19308. +#ifndef CONFIG_PREEMPT_RT_FULL
  19309. +
  19310. #include "locking-selftest-rlock-hardirq.h"
  19311. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  19312. @@ -605,9 +607,12 @@
  19313. #include "locking-selftest-wlock-softirq.h"
  19314. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  19315. +#endif
  19316. +
  19317. #undef E1
  19318. #undef E2
  19319. +#ifndef CONFIG_PREEMPT_RT_FULL
  19320. /*
  19321. * Enabling hardirqs with a softirq-safe lock held:
  19322. */
  19323. @@ -640,6 +645,8 @@
  19324. #undef E1
  19325. #undef E2
  19326. +#endif
  19327. +
  19328. /*
  19329. * Enabling irqs with an irq-safe lock held:
  19330. */
  19331. @@ -663,6 +670,8 @@
  19332. #include "locking-selftest-spin-hardirq.h"
  19333. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  19334. +#ifndef CONFIG_PREEMPT_RT_FULL
  19335. +
  19336. #include "locking-selftest-rlock-hardirq.h"
  19337. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  19338. @@ -678,6 +687,8 @@
  19339. #include "locking-selftest-wlock-softirq.h"
  19340. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  19341. +#endif
  19342. +
  19343. #undef E1
  19344. #undef E2
  19345. @@ -709,6 +720,8 @@
  19346. #include "locking-selftest-spin-hardirq.h"
  19347. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  19348. +#ifndef CONFIG_PREEMPT_RT_FULL
  19349. +
  19350. #include "locking-selftest-rlock-hardirq.h"
  19351. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  19352. @@ -724,6 +737,8 @@
  19353. #include "locking-selftest-wlock-softirq.h"
  19354. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  19355. +#endif
  19356. +
  19357. #undef E1
  19358. #undef E2
  19359. #undef E3
  19360. @@ -757,6 +772,8 @@
  19361. #include "locking-selftest-spin-hardirq.h"
  19362. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  19363. +#ifndef CONFIG_PREEMPT_RT_FULL
  19364. +
  19365. #include "locking-selftest-rlock-hardirq.h"
  19366. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  19367. @@ -772,10 +789,14 @@
  19368. #include "locking-selftest-wlock-softirq.h"
  19369. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  19370. +#endif
  19371. +
  19372. #undef E1
  19373. #undef E2
  19374. #undef E3
  19375. +#ifndef CONFIG_PREEMPT_RT_FULL
  19376. +
  19377. /*
  19378. * read-lock / write-lock irq inversion.
  19379. *
  19380. @@ -838,6 +859,10 @@
  19381. #undef E2
  19382. #undef E3
  19383. +#endif
  19384. +
  19385. +#ifndef CONFIG_PREEMPT_RT_FULL
  19386. +
  19387. /*
  19388. * read-lock / write-lock recursion that is actually safe.
  19389. */
  19390. @@ -876,6 +901,8 @@
  19391. #undef E2
  19392. #undef E3
  19393. +#endif
  19394. +
  19395. /*
  19396. * read-lock / write-lock recursion that is unsafe.
  19397. */
  19398. @@ -1858,6 +1885,7 @@
  19399. printk(" --------------------------------------------------------------------------\n");
  19400. +#ifndef CONFIG_PREEMPT_RT_FULL
  19401. /*
  19402. * irq-context testcases:
  19403. */
  19404. @@ -1870,6 +1898,28 @@
  19405. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  19406. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  19407. +#else
  19408. + /* On -rt, we only do hardirq context test for raw spinlock */
  19409. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 12);
  19410. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 21);
  19411. +
  19412. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 12);
  19413. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 21);
  19414. +
  19415. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 123);
  19416. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 132);
  19417. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 213);
  19418. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 231);
  19419. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 312);
  19420. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 321);
  19421. +
  19422. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 123);
  19423. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 132);
  19424. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 213);
  19425. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 231);
  19426. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 312);
  19427. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 321);
  19428. +#endif
  19429. ww_tests();
  19430. diff -Nur linux-4.9.6.orig/lib/percpu_ida.c linux-4.9.6/lib/percpu_ida.c
  19431. --- linux-4.9.6.orig/lib/percpu_ida.c 2017-01-26 08:25:24.000000000 +0100
  19432. +++ linux-4.9.6/lib/percpu_ida.c 2017-01-28 13:59:10.095662491 +0100
  19433. @@ -26,6 +26,9 @@
  19434. #include <linux/string.h>
  19435. #include <linux/spinlock.h>
  19436. #include <linux/percpu_ida.h>
  19437. +#include <linux/locallock.h>
  19438. +
  19439. +static DEFINE_LOCAL_IRQ_LOCK(irq_off_lock);
  19440. struct percpu_ida_cpu {
  19441. /*
  19442. @@ -148,13 +151,13 @@
  19443. unsigned long flags;
  19444. int tag;
  19445. - local_irq_save(flags);
  19446. + local_lock_irqsave(irq_off_lock, flags);
  19447. tags = this_cpu_ptr(pool->tag_cpu);
  19448. /* Fastpath */
  19449. tag = alloc_local_tag(tags);
  19450. if (likely(tag >= 0)) {
  19451. - local_irq_restore(flags);
  19452. + local_unlock_irqrestore(irq_off_lock, flags);
  19453. return tag;
  19454. }
  19455. @@ -173,6 +176,7 @@
  19456. if (!tags->nr_free)
  19457. alloc_global_tags(pool, tags);
  19458. +
  19459. if (!tags->nr_free)
  19460. steal_tags(pool, tags);
  19461. @@ -184,7 +188,7 @@
  19462. }
  19463. spin_unlock(&pool->lock);
  19464. - local_irq_restore(flags);
  19465. + local_unlock_irqrestore(irq_off_lock, flags);
  19466. if (tag >= 0 || state == TASK_RUNNING)
  19467. break;
  19468. @@ -196,7 +200,7 @@
  19469. schedule();
  19470. - local_irq_save(flags);
  19471. + local_lock_irqsave(irq_off_lock, flags);
  19472. tags = this_cpu_ptr(pool->tag_cpu);
  19473. }
  19474. if (state != TASK_RUNNING)
  19475. @@ -221,7 +225,7 @@
  19476. BUG_ON(tag >= pool->nr_tags);
  19477. - local_irq_save(flags);
  19478. + local_lock_irqsave(irq_off_lock, flags);
  19479. tags = this_cpu_ptr(pool->tag_cpu);
  19480. spin_lock(&tags->lock);
  19481. @@ -253,7 +257,7 @@
  19482. spin_unlock(&pool->lock);
  19483. }
  19484. - local_irq_restore(flags);
  19485. + local_unlock_irqrestore(irq_off_lock, flags);
  19486. }
  19487. EXPORT_SYMBOL_GPL(percpu_ida_free);
  19488. @@ -345,7 +349,7 @@
  19489. struct percpu_ida_cpu *remote;
  19490. unsigned cpu, i, err = 0;
  19491. - local_irq_save(flags);
  19492. + local_lock_irqsave(irq_off_lock, flags);
  19493. for_each_possible_cpu(cpu) {
  19494. remote = per_cpu_ptr(pool->tag_cpu, cpu);
  19495. spin_lock(&remote->lock);
  19496. @@ -367,7 +371,7 @@
  19497. }
  19498. spin_unlock(&pool->lock);
  19499. out:
  19500. - local_irq_restore(flags);
  19501. + local_unlock_irqrestore(irq_off_lock, flags);
  19502. return err;
  19503. }
  19504. EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
  19505. diff -Nur linux-4.9.6.orig/lib/radix-tree.c linux-4.9.6/lib/radix-tree.c
  19506. --- linux-4.9.6.orig/lib/radix-tree.c 2017-01-26 08:25:24.000000000 +0100
  19507. +++ linux-4.9.6/lib/radix-tree.c 2017-01-28 13:59:10.095662491 +0100
  19508. @@ -290,13 +290,14 @@
  19509. * succeed in getting a node here (and never reach
  19510. * kmem_cache_alloc)
  19511. */
  19512. - rtp = this_cpu_ptr(&radix_tree_preloads);
  19513. + rtp = &get_cpu_var(radix_tree_preloads);
  19514. if (rtp->nr) {
  19515. ret = rtp->nodes;
  19516. rtp->nodes = ret->private_data;
  19517. ret->private_data = NULL;
  19518. rtp->nr--;
  19519. }
  19520. + put_cpu_var(radix_tree_preloads);
  19521. /*
  19522. * Update the allocation stack trace as this is more useful
  19523. * for debugging.
  19524. @@ -336,6 +337,7 @@
  19525. call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
  19526. }
  19527. +#ifndef CONFIG_PREEMPT_RT_FULL
  19528. /*
  19529. * Load up this CPU's radix_tree_node buffer with sufficient objects to
  19530. * ensure that the addition of a single element in the tree cannot fail. On
  19531. @@ -455,6 +457,7 @@
  19532. return __radix_tree_preload(gfp_mask, nr_nodes);
  19533. }
  19534. +#endif
  19535. /*
  19536. * The maximum index which can be stored in a radix tree
  19537. diff -Nur linux-4.9.6.orig/lib/scatterlist.c linux-4.9.6/lib/scatterlist.c
  19538. --- linux-4.9.6.orig/lib/scatterlist.c 2017-01-26 08:25:24.000000000 +0100
  19539. +++ linux-4.9.6/lib/scatterlist.c 2017-01-28 13:59:10.095662491 +0100
  19540. @@ -620,7 +620,7 @@
  19541. flush_kernel_dcache_page(miter->page);
  19542. if (miter->__flags & SG_MITER_ATOMIC) {
  19543. - WARN_ON_ONCE(preemptible());
  19544. + WARN_ON_ONCE(!pagefault_disabled());
  19545. kunmap_atomic(miter->addr);
  19546. } else
  19547. kunmap(miter->page);
  19548. @@ -664,7 +664,7 @@
  19549. if (!sg_miter_skip(&miter, skip))
  19550. return false;
  19551. - local_irq_save(flags);
  19552. + local_irq_save_nort(flags);
  19553. while (sg_miter_next(&miter) && offset < buflen) {
  19554. unsigned int len;
  19555. @@ -681,7 +681,7 @@
  19556. sg_miter_stop(&miter);
  19557. - local_irq_restore(flags);
  19558. + local_irq_restore_nort(flags);
  19559. return offset;
  19560. }
  19561. EXPORT_SYMBOL(sg_copy_buffer);
  19562. diff -Nur linux-4.9.6.orig/lib/smp_processor_id.c linux-4.9.6/lib/smp_processor_id.c
  19563. --- linux-4.9.6.orig/lib/smp_processor_id.c 2017-01-26 08:25:24.000000000 +0100
  19564. +++ linux-4.9.6/lib/smp_processor_id.c 2017-01-28 13:59:10.095662491 +0100
  19565. @@ -39,8 +39,9 @@
  19566. if (!printk_ratelimit())
  19567. goto out_enable;
  19568. - printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
  19569. - what1, what2, preempt_count() - 1, current->comm, current->pid);
  19570. + printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x %08x] code: %s/%d\n",
  19571. + what1, what2, preempt_count() - 1, __migrate_disabled(current),
  19572. + current->comm, current->pid);
  19573. print_symbol("caller is %s\n", (long)__builtin_return_address(0));
  19574. dump_stack();
  19575. diff -Nur linux-4.9.6.orig/mm/backing-dev.c linux-4.9.6/mm/backing-dev.c
  19576. --- linux-4.9.6.orig/mm/backing-dev.c 2017-01-26 08:25:24.000000000 +0100
  19577. +++ linux-4.9.6/mm/backing-dev.c 2017-01-28 13:59:10.095662491 +0100
  19578. @@ -457,9 +457,9 @@
  19579. {
  19580. unsigned long flags;
  19581. - local_irq_save(flags);
  19582. + local_irq_save_nort(flags);
  19583. if (!atomic_dec_and_lock(&congested->refcnt, &cgwb_lock)) {
  19584. - local_irq_restore(flags);
  19585. + local_irq_restore_nort(flags);
  19586. return;
  19587. }
  19588. diff -Nur linux-4.9.6.orig/mm/compaction.c linux-4.9.6/mm/compaction.c
  19589. --- linux-4.9.6.orig/mm/compaction.c 2017-01-26 08:25:24.000000000 +0100
  19590. +++ linux-4.9.6/mm/compaction.c 2017-01-28 13:59:10.095662491 +0100
  19591. @@ -1593,10 +1593,12 @@
  19592. block_start_pfn(cc->migrate_pfn, cc->order);
  19593. if (cc->last_migrated_pfn < current_block_start) {
  19594. - cpu = get_cpu();
  19595. + cpu = get_cpu_light();
  19596. + local_lock_irq(swapvec_lock);
  19597. lru_add_drain_cpu(cpu);
  19598. + local_unlock_irq(swapvec_lock);
  19599. drain_local_pages(zone);
  19600. - put_cpu();
  19601. + put_cpu_light();
  19602. /* No more flushing until we migrate again */
  19603. cc->last_migrated_pfn = 0;
  19604. }
  19605. diff -Nur linux-4.9.6.orig/mm/filemap.c linux-4.9.6/mm/filemap.c
  19606. --- linux-4.9.6.orig/mm/filemap.c 2017-01-26 08:25:24.000000000 +0100
  19607. +++ linux-4.9.6/mm/filemap.c 2017-01-28 13:59:10.099662644 +0100
  19608. @@ -159,9 +159,12 @@
  19609. * node->private_list is protected by
  19610. * mapping->tree_lock.
  19611. */
  19612. - if (!list_empty(&node->private_list))
  19613. - list_lru_del(&workingset_shadow_nodes,
  19614. + if (!list_empty(&node->private_list)) {
  19615. + local_lock(workingset_shadow_lock);
  19616. + list_lru_del(&__workingset_shadow_nodes,
  19617. &node->private_list);
  19618. + local_unlock(workingset_shadow_lock);
  19619. + }
  19620. }
  19621. return 0;
  19622. }
  19623. @@ -217,8 +220,10 @@
  19624. if (!dax_mapping(mapping) && !workingset_node_pages(node) &&
  19625. list_empty(&node->private_list)) {
  19626. node->private_data = mapping;
  19627. - list_lru_add(&workingset_shadow_nodes,
  19628. - &node->private_list);
  19629. + local_lock(workingset_shadow_lock);
  19630. + list_lru_add(&__workingset_shadow_nodes,
  19631. + &node->private_list);
  19632. + local_unlock(workingset_shadow_lock);
  19633. }
  19634. }
  19635. diff -Nur linux-4.9.6.orig/mm/highmem.c linux-4.9.6/mm/highmem.c
  19636. --- linux-4.9.6.orig/mm/highmem.c 2017-01-26 08:25:24.000000000 +0100
  19637. +++ linux-4.9.6/mm/highmem.c 2017-01-28 13:59:10.099662644 +0100
  19638. @@ -29,10 +29,11 @@
  19639. #include <linux/kgdb.h>
  19640. #include <asm/tlbflush.h>
  19641. -
  19642. +#ifndef CONFIG_PREEMPT_RT_FULL
  19643. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  19644. DEFINE_PER_CPU(int, __kmap_atomic_idx);
  19645. #endif
  19646. +#endif
  19647. /*
  19648. * Virtual_count is not a pure "count".
  19649. @@ -107,8 +108,9 @@
  19650. unsigned long totalhigh_pages __read_mostly;
  19651. EXPORT_SYMBOL(totalhigh_pages);
  19652. -
  19653. +#ifndef CONFIG_PREEMPT_RT_FULL
  19654. EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
  19655. +#endif
  19656. unsigned int nr_free_highpages (void)
  19657. {
  19658. diff -Nur linux-4.9.6.orig/mm/Kconfig linux-4.9.6/mm/Kconfig
  19659. --- linux-4.9.6.orig/mm/Kconfig 2017-01-26 08:25:24.000000000 +0100
  19660. +++ linux-4.9.6/mm/Kconfig 2017-01-28 13:59:10.095662491 +0100
  19661. @@ -410,7 +410,7 @@
  19662. config TRANSPARENT_HUGEPAGE
  19663. bool "Transparent Hugepage Support"
  19664. - depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE
  19665. + depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE && !PREEMPT_RT_FULL
  19666. select COMPACTION
  19667. select RADIX_TREE_MULTIORDER
  19668. help
  19669. diff -Nur linux-4.9.6.orig/mm/memcontrol.c linux-4.9.6/mm/memcontrol.c
  19670. --- linux-4.9.6.orig/mm/memcontrol.c 2017-01-26 08:25:24.000000000 +0100
  19671. +++ linux-4.9.6/mm/memcontrol.c 2017-01-28 13:59:10.099662644 +0100
  19672. @@ -67,6 +67,7 @@
  19673. #include <net/sock.h>
  19674. #include <net/ip.h>
  19675. #include "slab.h"
  19676. +#include <linux/locallock.h>
  19677. #include <asm/uaccess.h>
  19678. @@ -92,6 +93,8 @@
  19679. #define do_swap_account 0
  19680. #endif
  19681. +static DEFINE_LOCAL_IRQ_LOCK(event_lock);
  19682. +
  19683. /* Whether legacy memory+swap accounting is active */
  19684. static bool do_memsw_account(void)
  19685. {
  19686. @@ -1692,6 +1695,7 @@
  19687. #define FLUSHING_CACHED_CHARGE 0
  19688. };
  19689. static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock);
  19690. +static DEFINE_LOCAL_IRQ_LOCK(memcg_stock_ll);
  19691. static DEFINE_MUTEX(percpu_charge_mutex);
  19692. /**
  19693. @@ -1714,7 +1718,7 @@
  19694. if (nr_pages > CHARGE_BATCH)
  19695. return ret;
  19696. - local_irq_save(flags);
  19697. + local_lock_irqsave(memcg_stock_ll, flags);
  19698. stock = this_cpu_ptr(&memcg_stock);
  19699. if (memcg == stock->cached && stock->nr_pages >= nr_pages) {
  19700. @@ -1722,7 +1726,7 @@
  19701. ret = true;
  19702. }
  19703. - local_irq_restore(flags);
  19704. + local_unlock_irqrestore(memcg_stock_ll, flags);
  19705. return ret;
  19706. }
  19707. @@ -1749,13 +1753,13 @@
  19708. struct memcg_stock_pcp *stock;
  19709. unsigned long flags;
  19710. - local_irq_save(flags);
  19711. + local_lock_irqsave(memcg_stock_ll, flags);
  19712. stock = this_cpu_ptr(&memcg_stock);
  19713. drain_stock(stock);
  19714. clear_bit(FLUSHING_CACHED_CHARGE, &stock->flags);
  19715. - local_irq_restore(flags);
  19716. + local_unlock_irqrestore(memcg_stock_ll, flags);
  19717. }
  19718. /*
  19719. @@ -1767,7 +1771,7 @@
  19720. struct memcg_stock_pcp *stock;
  19721. unsigned long flags;
  19722. - local_irq_save(flags);
  19723. + local_lock_irqsave(memcg_stock_ll, flags);
  19724. stock = this_cpu_ptr(&memcg_stock);
  19725. if (stock->cached != memcg) { /* reset if necessary */
  19726. @@ -1776,7 +1780,7 @@
  19727. }
  19728. stock->nr_pages += nr_pages;
  19729. - local_irq_restore(flags);
  19730. + local_unlock_irqrestore(memcg_stock_ll, flags);
  19731. }
  19732. /*
  19733. @@ -1792,7 +1796,7 @@
  19734. return;
  19735. /* Notify other cpus that system-wide "drain" is running */
  19736. get_online_cpus();
  19737. - curcpu = get_cpu();
  19738. + curcpu = get_cpu_light();
  19739. for_each_online_cpu(cpu) {
  19740. struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
  19741. struct mem_cgroup *memcg;
  19742. @@ -1809,7 +1813,7 @@
  19743. schedule_work_on(cpu, &stock->work);
  19744. }
  19745. }
  19746. - put_cpu();
  19747. + put_cpu_light();
  19748. put_online_cpus();
  19749. mutex_unlock(&percpu_charge_mutex);
  19750. }
  19751. @@ -4548,12 +4552,12 @@
  19752. ret = 0;
  19753. - local_irq_disable();
  19754. + local_lock_irq(event_lock);
  19755. mem_cgroup_charge_statistics(to, page, compound, nr_pages);
  19756. memcg_check_events(to, page);
  19757. mem_cgroup_charge_statistics(from, page, compound, -nr_pages);
  19758. memcg_check_events(from, page);
  19759. - local_irq_enable();
  19760. + local_unlock_irq(event_lock);
  19761. out_unlock:
  19762. unlock_page(page);
  19763. out:
  19764. @@ -5428,10 +5432,10 @@
  19765. commit_charge(page, memcg, lrucare);
  19766. - local_irq_disable();
  19767. + local_lock_irq(event_lock);
  19768. mem_cgroup_charge_statistics(memcg, page, compound, nr_pages);
  19769. memcg_check_events(memcg, page);
  19770. - local_irq_enable();
  19771. + local_unlock_irq(event_lock);
  19772. if (do_memsw_account() && PageSwapCache(page)) {
  19773. swp_entry_t entry = { .val = page_private(page) };
  19774. @@ -5487,14 +5491,14 @@
  19775. memcg_oom_recover(memcg);
  19776. }
  19777. - local_irq_save(flags);
  19778. + local_lock_irqsave(event_lock, flags);
  19779. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS], nr_anon);
  19780. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_CACHE], nr_file);
  19781. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS_HUGE], nr_huge);
  19782. __this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT], pgpgout);
  19783. __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
  19784. memcg_check_events(memcg, dummy_page);
  19785. - local_irq_restore(flags);
  19786. + local_unlock_irqrestore(event_lock, flags);
  19787. if (!mem_cgroup_is_root(memcg))
  19788. css_put_many(&memcg->css, nr_pages);
  19789. @@ -5649,10 +5653,10 @@
  19790. commit_charge(newpage, memcg, false);
  19791. - local_irq_save(flags);
  19792. + local_lock_irqsave(event_lock, flags);
  19793. mem_cgroup_charge_statistics(memcg, newpage, compound, nr_pages);
  19794. memcg_check_events(memcg, newpage);
  19795. - local_irq_restore(flags);
  19796. + local_unlock_irqrestore(event_lock, flags);
  19797. }
  19798. DEFINE_STATIC_KEY_FALSE(memcg_sockets_enabled_key);
  19799. @@ -5832,6 +5836,7 @@
  19800. {
  19801. struct mem_cgroup *memcg, *swap_memcg;
  19802. unsigned short oldid;
  19803. + unsigned long flags;
  19804. VM_BUG_ON_PAGE(PageLRU(page), page);
  19805. VM_BUG_ON_PAGE(page_count(page), page);
  19806. @@ -5872,12 +5877,16 @@
  19807. * important here to have the interrupts disabled because it is the
  19808. * only synchronisation we have for udpating the per-CPU variables.
  19809. */
  19810. + local_lock_irqsave(event_lock, flags);
  19811. +#ifndef CONFIG_PREEMPT_RT_BASE
  19812. VM_BUG_ON(!irqs_disabled());
  19813. +#endif
  19814. mem_cgroup_charge_statistics(memcg, page, false, -1);
  19815. memcg_check_events(memcg, page);
  19816. if (!mem_cgroup_is_root(memcg))
  19817. css_put(&memcg->css);
  19818. + local_unlock_irqrestore(event_lock, flags);
  19819. }
  19820. /*
  19821. diff -Nur linux-4.9.6.orig/mm/mmu_context.c linux-4.9.6/mm/mmu_context.c
  19822. --- linux-4.9.6.orig/mm/mmu_context.c 2017-01-26 08:25:24.000000000 +0100
  19823. +++ linux-4.9.6/mm/mmu_context.c 2017-01-28 13:59:10.099662644 +0100
  19824. @@ -23,6 +23,7 @@
  19825. struct task_struct *tsk = current;
  19826. task_lock(tsk);
  19827. + preempt_disable_rt();
  19828. active_mm = tsk->active_mm;
  19829. if (active_mm != mm) {
  19830. atomic_inc(&mm->mm_count);
  19831. @@ -30,6 +31,7 @@
  19832. }
  19833. tsk->mm = mm;
  19834. switch_mm(active_mm, mm, tsk);
  19835. + preempt_enable_rt();
  19836. task_unlock(tsk);
  19837. #ifdef finish_arch_post_lock_switch
  19838. finish_arch_post_lock_switch();
  19839. diff -Nur linux-4.9.6.orig/mm/page_alloc.c linux-4.9.6/mm/page_alloc.c
  19840. --- linux-4.9.6.orig/mm/page_alloc.c 2017-01-26 08:25:24.000000000 +0100
  19841. +++ linux-4.9.6/mm/page_alloc.c 2017-01-28 13:59:10.099662644 +0100
  19842. @@ -61,6 +61,7 @@
  19843. #include <linux/page_ext.h>
  19844. #include <linux/hugetlb.h>
  19845. #include <linux/sched/rt.h>
  19846. +#include <linux/locallock.h>
  19847. #include <linux/page_owner.h>
  19848. #include <linux/kthread.h>
  19849. #include <linux/memcontrol.h>
  19850. @@ -281,6 +282,18 @@
  19851. EXPORT_SYMBOL(nr_online_nodes);
  19852. #endif
  19853. +static DEFINE_LOCAL_IRQ_LOCK(pa_lock);
  19854. +
  19855. +#ifdef CONFIG_PREEMPT_RT_BASE
  19856. +# define cpu_lock_irqsave(cpu, flags) \
  19857. + local_lock_irqsave_on(pa_lock, flags, cpu)
  19858. +# define cpu_unlock_irqrestore(cpu, flags) \
  19859. + local_unlock_irqrestore_on(pa_lock, flags, cpu)
  19860. +#else
  19861. +# define cpu_lock_irqsave(cpu, flags) local_irq_save(flags)
  19862. +# define cpu_unlock_irqrestore(cpu, flags) local_irq_restore(flags)
  19863. +#endif
  19864. +
  19865. int page_group_by_mobility_disabled __read_mostly;
  19866. #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
  19867. @@ -1072,7 +1085,7 @@
  19868. #endif /* CONFIG_DEBUG_VM */
  19869. /*
  19870. - * Frees a number of pages from the PCP lists
  19871. + * Frees a number of pages which have been collected from the pcp lists.
  19872. * Assumes all pages on list are in same zone, and of same order.
  19873. * count is the number of pages to free.
  19874. *
  19875. @@ -1083,19 +1096,58 @@
  19876. * pinned" detection logic.
  19877. */
  19878. static void free_pcppages_bulk(struct zone *zone, int count,
  19879. - struct per_cpu_pages *pcp)
  19880. + struct list_head *list)
  19881. {
  19882. - int migratetype = 0;
  19883. - int batch_free = 0;
  19884. unsigned long nr_scanned;
  19885. bool isolated_pageblocks;
  19886. + unsigned long flags;
  19887. +
  19888. + spin_lock_irqsave(&zone->lock, flags);
  19889. - spin_lock(&zone->lock);
  19890. isolated_pageblocks = has_isolate_pageblock(zone);
  19891. nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
  19892. if (nr_scanned)
  19893. __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, -nr_scanned);
  19894. + while (!list_empty(list)) {
  19895. + struct page *page;
  19896. + int mt; /* migratetype of the to-be-freed page */
  19897. +
  19898. + page = list_first_entry(list, struct page, lru);
  19899. + /* must delete as __free_one_page list manipulates */
  19900. + list_del(&page->lru);
  19901. +
  19902. + mt = get_pcppage_migratetype(page);
  19903. + /* MIGRATE_ISOLATE page should not go to pcplists */
  19904. + VM_BUG_ON_PAGE(is_migrate_isolate(mt), page);
  19905. + /* Pageblock could have been isolated meanwhile */
  19906. + if (unlikely(isolated_pageblocks))
  19907. + mt = get_pageblock_migratetype(page);
  19908. +
  19909. + if (bulkfree_pcp_prepare(page))
  19910. + continue;
  19911. +
  19912. + __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  19913. + trace_mm_page_pcpu_drain(page, 0, mt);
  19914. + count--;
  19915. + }
  19916. + WARN_ON(count != 0);
  19917. + spin_unlock_irqrestore(&zone->lock, flags);
  19918. +}
  19919. +
  19920. +/*
  19921. + * Moves a number of pages from the PCP lists to free list which
  19922. + * is freed outside of the locked region.
  19923. + *
  19924. + * Assumes all pages on list are in same zone, and of same order.
  19925. + * count is the number of pages to free.
  19926. + */
  19927. +static void isolate_pcp_pages(int count, struct per_cpu_pages *src,
  19928. + struct list_head *dst)
  19929. +{
  19930. + int migratetype = 0;
  19931. + int batch_free = 0;
  19932. +
  19933. while (count) {
  19934. struct page *page;
  19935. struct list_head *list;
  19936. @@ -1111,7 +1163,7 @@
  19937. batch_free++;
  19938. if (++migratetype == MIGRATE_PCPTYPES)
  19939. migratetype = 0;
  19940. - list = &pcp->lists[migratetype];
  19941. + list = &src->lists[migratetype];
  19942. } while (list_empty(list));
  19943. /* This is the only non-empty list. Free them all. */
  19944. @@ -1119,27 +1171,12 @@
  19945. batch_free = count;
  19946. do {
  19947. - int mt; /* migratetype of the to-be-freed page */
  19948. -
  19949. page = list_last_entry(list, struct page, lru);
  19950. - /* must delete as __free_one_page list manipulates */
  19951. list_del(&page->lru);
  19952. - mt = get_pcppage_migratetype(page);
  19953. - /* MIGRATE_ISOLATE page should not go to pcplists */
  19954. - VM_BUG_ON_PAGE(is_migrate_isolate(mt), page);
  19955. - /* Pageblock could have been isolated meanwhile */
  19956. - if (unlikely(isolated_pageblocks))
  19957. - mt = get_pageblock_migratetype(page);
  19958. -
  19959. - if (bulkfree_pcp_prepare(page))
  19960. - continue;
  19961. -
  19962. - __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  19963. - trace_mm_page_pcpu_drain(page, 0, mt);
  19964. + list_add(&page->lru, dst);
  19965. } while (--count && --batch_free && !list_empty(list));
  19966. }
  19967. - spin_unlock(&zone->lock);
  19968. }
  19969. static void free_one_page(struct zone *zone,
  19970. @@ -1148,7 +1185,9 @@
  19971. int migratetype)
  19972. {
  19973. unsigned long nr_scanned;
  19974. - spin_lock(&zone->lock);
  19975. + unsigned long flags;
  19976. +
  19977. + spin_lock_irqsave(&zone->lock, flags);
  19978. nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
  19979. if (nr_scanned)
  19980. __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, -nr_scanned);
  19981. @@ -1158,7 +1197,7 @@
  19982. migratetype = get_pfnblock_migratetype(page, pfn);
  19983. }
  19984. __free_one_page(page, pfn, zone, order, migratetype);
  19985. - spin_unlock(&zone->lock);
  19986. + spin_unlock_irqrestore(&zone->lock, flags);
  19987. }
  19988. static void __meminit __init_single_page(struct page *page, unsigned long pfn,
  19989. @@ -1244,10 +1283,10 @@
  19990. return;
  19991. migratetype = get_pfnblock_migratetype(page, pfn);
  19992. - local_irq_save(flags);
  19993. + local_lock_irqsave(pa_lock, flags);
  19994. __count_vm_events(PGFREE, 1 << order);
  19995. free_one_page(page_zone(page), page, pfn, order, migratetype);
  19996. - local_irq_restore(flags);
  19997. + local_unlock_irqrestore(pa_lock, flags);
  19998. }
  19999. static void __init __free_pages_boot_core(struct page *page, unsigned int order)
  20000. @@ -2246,16 +2285,18 @@
  20001. void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
  20002. {
  20003. unsigned long flags;
  20004. + LIST_HEAD(dst);
  20005. int to_drain, batch;
  20006. - local_irq_save(flags);
  20007. + local_lock_irqsave(pa_lock, flags);
  20008. batch = READ_ONCE(pcp->batch);
  20009. to_drain = min(pcp->count, batch);
  20010. if (to_drain > 0) {
  20011. - free_pcppages_bulk(zone, to_drain, pcp);
  20012. + isolate_pcp_pages(to_drain, pcp, &dst);
  20013. pcp->count -= to_drain;
  20014. }
  20015. - local_irq_restore(flags);
  20016. + local_unlock_irqrestore(pa_lock, flags);
  20017. + free_pcppages_bulk(zone, to_drain, &dst);
  20018. }
  20019. #endif
  20020. @@ -2271,16 +2312,21 @@
  20021. unsigned long flags;
  20022. struct per_cpu_pageset *pset;
  20023. struct per_cpu_pages *pcp;
  20024. + LIST_HEAD(dst);
  20025. + int count;
  20026. - local_irq_save(flags);
  20027. + cpu_lock_irqsave(cpu, flags);
  20028. pset = per_cpu_ptr(zone->pageset, cpu);
  20029. pcp = &pset->pcp;
  20030. - if (pcp->count) {
  20031. - free_pcppages_bulk(zone, pcp->count, pcp);
  20032. + count = pcp->count;
  20033. + if (count) {
  20034. + isolate_pcp_pages(count, pcp, &dst);
  20035. pcp->count = 0;
  20036. }
  20037. - local_irq_restore(flags);
  20038. + cpu_unlock_irqrestore(cpu, flags);
  20039. + if (count)
  20040. + free_pcppages_bulk(zone, count, &dst);
  20041. }
  20042. /*
  20043. @@ -2366,8 +2412,17 @@
  20044. else
  20045. cpumask_clear_cpu(cpu, &cpus_with_pcps);
  20046. }
  20047. +#ifndef CONFIG_PREEMPT_RT_BASE
  20048. on_each_cpu_mask(&cpus_with_pcps, (smp_call_func_t) drain_local_pages,
  20049. zone, 1);
  20050. +#else
  20051. + for_each_cpu(cpu, &cpus_with_pcps) {
  20052. + if (zone)
  20053. + drain_pages_zone(cpu, zone);
  20054. + else
  20055. + drain_pages(cpu);
  20056. + }
  20057. +#endif
  20058. }
  20059. #ifdef CONFIG_HIBERNATION
  20060. @@ -2427,7 +2482,7 @@
  20061. migratetype = get_pfnblock_migratetype(page, pfn);
  20062. set_pcppage_migratetype(page, migratetype);
  20063. - local_irq_save(flags);
  20064. + local_lock_irqsave(pa_lock, flags);
  20065. __count_vm_event(PGFREE);
  20066. /*
  20067. @@ -2453,12 +2508,17 @@
  20068. pcp->count++;
  20069. if (pcp->count >= pcp->high) {
  20070. unsigned long batch = READ_ONCE(pcp->batch);
  20071. - free_pcppages_bulk(zone, batch, pcp);
  20072. + LIST_HEAD(dst);
  20073. +
  20074. + isolate_pcp_pages(batch, pcp, &dst);
  20075. pcp->count -= batch;
  20076. + local_unlock_irqrestore(pa_lock, flags);
  20077. + free_pcppages_bulk(zone, batch, &dst);
  20078. + return;
  20079. }
  20080. out:
  20081. - local_irq_restore(flags);
  20082. + local_unlock_irqrestore(pa_lock, flags);
  20083. }
  20084. /*
  20085. @@ -2600,7 +2660,7 @@
  20086. struct per_cpu_pages *pcp;
  20087. struct list_head *list;
  20088. - local_irq_save(flags);
  20089. + local_lock_irqsave(pa_lock, flags);
  20090. do {
  20091. pcp = &this_cpu_ptr(zone->pageset)->pcp;
  20092. list = &pcp->lists[migratetype];
  20093. @@ -2627,7 +2687,7 @@
  20094. * allocate greater than order-1 page units with __GFP_NOFAIL.
  20095. */
  20096. WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1));
  20097. - spin_lock_irqsave(&zone->lock, flags);
  20098. + local_spin_lock_irqsave(pa_lock, &zone->lock, flags);
  20099. do {
  20100. page = NULL;
  20101. @@ -2639,22 +2699,24 @@
  20102. if (!page)
  20103. page = __rmqueue(zone, order, migratetype);
  20104. } while (page && check_new_pages(page, order));
  20105. - spin_unlock(&zone->lock);
  20106. - if (!page)
  20107. + if (!page) {
  20108. + spin_unlock(&zone->lock);
  20109. goto failed;
  20110. + }
  20111. __mod_zone_freepage_state(zone, -(1 << order),
  20112. get_pcppage_migratetype(page));
  20113. + spin_unlock(&zone->lock);
  20114. }
  20115. __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order);
  20116. zone_statistics(preferred_zone, zone, gfp_flags);
  20117. - local_irq_restore(flags);
  20118. + local_unlock_irqrestore(pa_lock, flags);
  20119. VM_BUG_ON_PAGE(bad_range(zone, page), page);
  20120. return page;
  20121. failed:
  20122. - local_irq_restore(flags);
  20123. + local_unlock_irqrestore(pa_lock, flags);
  20124. return NULL;
  20125. }
  20126. @@ -6505,7 +6567,9 @@
  20127. int cpu = (unsigned long)hcpu;
  20128. if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
  20129. + local_lock_irq_on(swapvec_lock, cpu);
  20130. lru_add_drain_cpu(cpu);
  20131. + local_unlock_irq_on(swapvec_lock, cpu);
  20132. drain_pages(cpu);
  20133. /*
  20134. @@ -6531,6 +6595,7 @@
  20135. void __init page_alloc_init(void)
  20136. {
  20137. hotcpu_notifier(page_alloc_cpu_notify, 0);
  20138. + local_irq_lock_init(pa_lock);
  20139. }
  20140. /*
  20141. @@ -7359,7 +7424,7 @@
  20142. struct per_cpu_pageset *pset;
  20143. /* avoid races with drain_pages() */
  20144. - local_irq_save(flags);
  20145. + local_lock_irqsave(pa_lock, flags);
  20146. if (zone->pageset != &boot_pageset) {
  20147. for_each_online_cpu(cpu) {
  20148. pset = per_cpu_ptr(zone->pageset, cpu);
  20149. @@ -7368,7 +7433,7 @@
  20150. free_percpu(zone->pageset);
  20151. zone->pageset = &boot_pageset;
  20152. }
  20153. - local_irq_restore(flags);
  20154. + local_unlock_irqrestore(pa_lock, flags);
  20155. }
  20156. #ifdef CONFIG_MEMORY_HOTREMOVE
  20157. diff -Nur linux-4.9.6.orig/mm/slab.h linux-4.9.6/mm/slab.h
  20158. --- linux-4.9.6.orig/mm/slab.h 2017-01-26 08:25:24.000000000 +0100
  20159. +++ linux-4.9.6/mm/slab.h 2017-01-28 13:59:10.099662644 +0100
  20160. @@ -426,7 +426,11 @@
  20161. * The slab lists for all objects.
  20162. */
  20163. struct kmem_cache_node {
  20164. +#ifdef CONFIG_SLUB
  20165. + raw_spinlock_t list_lock;
  20166. +#else
  20167. spinlock_t list_lock;
  20168. +#endif
  20169. #ifdef CONFIG_SLAB
  20170. struct list_head slabs_partial; /* partial list first, better asm code */
  20171. diff -Nur linux-4.9.6.orig/mm/slub.c linux-4.9.6/mm/slub.c
  20172. --- linux-4.9.6.orig/mm/slub.c 2017-01-26 08:25:24.000000000 +0100
  20173. +++ linux-4.9.6/mm/slub.c 2017-01-28 13:59:10.099662644 +0100
  20174. @@ -1141,7 +1141,7 @@
  20175. unsigned long uninitialized_var(flags);
  20176. int ret = 0;
  20177. - spin_lock_irqsave(&n->list_lock, flags);
  20178. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20179. slab_lock(page);
  20180. if (s->flags & SLAB_CONSISTENCY_CHECKS) {
  20181. @@ -1176,7 +1176,7 @@
  20182. bulk_cnt, cnt);
  20183. slab_unlock(page);
  20184. - spin_unlock_irqrestore(&n->list_lock, flags);
  20185. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20186. if (!ret)
  20187. slab_fix(s, "Object at 0x%p not freed", object);
  20188. return ret;
  20189. @@ -1304,6 +1304,12 @@
  20190. #endif /* CONFIG_SLUB_DEBUG */
  20191. +struct slub_free_list {
  20192. + raw_spinlock_t lock;
  20193. + struct list_head list;
  20194. +};
  20195. +static DEFINE_PER_CPU(struct slub_free_list, slub_free_list);
  20196. +
  20197. /*
  20198. * Hooks for other subsystems that check memory allocations. In a typical
  20199. * production configuration these hooks all should produce no code at all.
  20200. @@ -1523,10 +1529,17 @@
  20201. void *start, *p;
  20202. int idx, order;
  20203. bool shuffle;
  20204. + bool enableirqs = false;
  20205. flags &= gfp_allowed_mask;
  20206. if (gfpflags_allow_blocking(flags))
  20207. + enableirqs = true;
  20208. +#ifdef CONFIG_PREEMPT_RT_FULL
  20209. + if (system_state == SYSTEM_RUNNING)
  20210. + enableirqs = true;
  20211. +#endif
  20212. + if (enableirqs)
  20213. local_irq_enable();
  20214. flags |= s->allocflags;
  20215. @@ -1601,7 +1614,7 @@
  20216. page->frozen = 1;
  20217. out:
  20218. - if (gfpflags_allow_blocking(flags))
  20219. + if (enableirqs)
  20220. local_irq_disable();
  20221. if (!page)
  20222. return NULL;
  20223. @@ -1660,6 +1673,16 @@
  20224. __free_pages(page, order);
  20225. }
  20226. +static void free_delayed(struct list_head *h)
  20227. +{
  20228. + while(!list_empty(h)) {
  20229. + struct page *page = list_first_entry(h, struct page, lru);
  20230. +
  20231. + list_del(&page->lru);
  20232. + __free_slab(page->slab_cache, page);
  20233. + }
  20234. +}
  20235. +
  20236. #define need_reserve_slab_rcu \
  20237. (sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
  20238. @@ -1691,6 +1714,12 @@
  20239. }
  20240. call_rcu(head, rcu_free_slab);
  20241. + } else if (irqs_disabled()) {
  20242. + struct slub_free_list *f = this_cpu_ptr(&slub_free_list);
  20243. +
  20244. + raw_spin_lock(&f->lock);
  20245. + list_add(&page->lru, &f->list);
  20246. + raw_spin_unlock(&f->lock);
  20247. } else
  20248. __free_slab(s, page);
  20249. }
  20250. @@ -1798,7 +1827,7 @@
  20251. if (!n || !n->nr_partial)
  20252. return NULL;
  20253. - spin_lock(&n->list_lock);
  20254. + raw_spin_lock(&n->list_lock);
  20255. list_for_each_entry_safe(page, page2, &n->partial, lru) {
  20256. void *t;
  20257. @@ -1823,7 +1852,7 @@
  20258. break;
  20259. }
  20260. - spin_unlock(&n->list_lock);
  20261. + raw_spin_unlock(&n->list_lock);
  20262. return object;
  20263. }
  20264. @@ -2069,7 +2098,7 @@
  20265. * that acquire_slab() will see a slab page that
  20266. * is frozen
  20267. */
  20268. - spin_lock(&n->list_lock);
  20269. + raw_spin_lock(&n->list_lock);
  20270. }
  20271. } else {
  20272. m = M_FULL;
  20273. @@ -2080,7 +2109,7 @@
  20274. * slabs from diagnostic functions will not see
  20275. * any frozen slabs.
  20276. */
  20277. - spin_lock(&n->list_lock);
  20278. + raw_spin_lock(&n->list_lock);
  20279. }
  20280. }
  20281. @@ -2115,7 +2144,7 @@
  20282. goto redo;
  20283. if (lock)
  20284. - spin_unlock(&n->list_lock);
  20285. + raw_spin_unlock(&n->list_lock);
  20286. if (m == M_FREE) {
  20287. stat(s, DEACTIVATE_EMPTY);
  20288. @@ -2147,10 +2176,10 @@
  20289. n2 = get_node(s, page_to_nid(page));
  20290. if (n != n2) {
  20291. if (n)
  20292. - spin_unlock(&n->list_lock);
  20293. + raw_spin_unlock(&n->list_lock);
  20294. n = n2;
  20295. - spin_lock(&n->list_lock);
  20296. + raw_spin_lock(&n->list_lock);
  20297. }
  20298. do {
  20299. @@ -2179,7 +2208,7 @@
  20300. }
  20301. if (n)
  20302. - spin_unlock(&n->list_lock);
  20303. + raw_spin_unlock(&n->list_lock);
  20304. while (discard_page) {
  20305. page = discard_page;
  20306. @@ -2218,14 +2247,21 @@
  20307. pobjects = oldpage->pobjects;
  20308. pages = oldpage->pages;
  20309. if (drain && pobjects > s->cpu_partial) {
  20310. + struct slub_free_list *f;
  20311. unsigned long flags;
  20312. + LIST_HEAD(tofree);
  20313. /*
  20314. * partial array is full. Move the existing
  20315. * set to the per node partial list.
  20316. */
  20317. local_irq_save(flags);
  20318. unfreeze_partials(s, this_cpu_ptr(s->cpu_slab));
  20319. + f = this_cpu_ptr(&slub_free_list);
  20320. + raw_spin_lock(&f->lock);
  20321. + list_splice_init(&f->list, &tofree);
  20322. + raw_spin_unlock(&f->lock);
  20323. local_irq_restore(flags);
  20324. + free_delayed(&tofree);
  20325. oldpage = NULL;
  20326. pobjects = 0;
  20327. pages = 0;
  20328. @@ -2297,7 +2333,22 @@
  20329. static void flush_all(struct kmem_cache *s)
  20330. {
  20331. + LIST_HEAD(tofree);
  20332. + int cpu;
  20333. +
  20334. on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1, GFP_ATOMIC);
  20335. + for_each_online_cpu(cpu) {
  20336. + struct slub_free_list *f;
  20337. +
  20338. + if (!has_cpu_slab(cpu, s))
  20339. + continue;
  20340. +
  20341. + f = &per_cpu(slub_free_list, cpu);
  20342. + raw_spin_lock_irq(&f->lock);
  20343. + list_splice_init(&f->list, &tofree);
  20344. + raw_spin_unlock_irq(&f->lock);
  20345. + free_delayed(&tofree);
  20346. + }
  20347. }
  20348. /*
  20349. @@ -2352,10 +2403,10 @@
  20350. unsigned long x = 0;
  20351. struct page *page;
  20352. - spin_lock_irqsave(&n->list_lock, flags);
  20353. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20354. list_for_each_entry(page, &n->partial, lru)
  20355. x += get_count(page);
  20356. - spin_unlock_irqrestore(&n->list_lock, flags);
  20357. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20358. return x;
  20359. }
  20360. #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
  20361. @@ -2493,8 +2544,10 @@
  20362. * already disabled (which is the case for bulk allocation).
  20363. */
  20364. static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
  20365. - unsigned long addr, struct kmem_cache_cpu *c)
  20366. + unsigned long addr, struct kmem_cache_cpu *c,
  20367. + struct list_head *to_free)
  20368. {
  20369. + struct slub_free_list *f;
  20370. void *freelist;
  20371. struct page *page;
  20372. @@ -2554,6 +2607,13 @@
  20373. VM_BUG_ON(!c->page->frozen);
  20374. c->freelist = get_freepointer(s, freelist);
  20375. c->tid = next_tid(c->tid);
  20376. +
  20377. +out:
  20378. + f = this_cpu_ptr(&slub_free_list);
  20379. + raw_spin_lock(&f->lock);
  20380. + list_splice_init(&f->list, to_free);
  20381. + raw_spin_unlock(&f->lock);
  20382. +
  20383. return freelist;
  20384. new_slab:
  20385. @@ -2585,7 +2645,7 @@
  20386. deactivate_slab(s, page, get_freepointer(s, freelist));
  20387. c->page = NULL;
  20388. c->freelist = NULL;
  20389. - return freelist;
  20390. + goto out;
  20391. }
  20392. /*
  20393. @@ -2597,6 +2657,7 @@
  20394. {
  20395. void *p;
  20396. unsigned long flags;
  20397. + LIST_HEAD(tofree);
  20398. local_irq_save(flags);
  20399. #ifdef CONFIG_PREEMPT
  20400. @@ -2608,8 +2669,9 @@
  20401. c = this_cpu_ptr(s->cpu_slab);
  20402. #endif
  20403. - p = ___slab_alloc(s, gfpflags, node, addr, c);
  20404. + p = ___slab_alloc(s, gfpflags, node, addr, c, &tofree);
  20405. local_irq_restore(flags);
  20406. + free_delayed(&tofree);
  20407. return p;
  20408. }
  20409. @@ -2795,7 +2857,7 @@
  20410. do {
  20411. if (unlikely(n)) {
  20412. - spin_unlock_irqrestore(&n->list_lock, flags);
  20413. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20414. n = NULL;
  20415. }
  20416. prior = page->freelist;
  20417. @@ -2827,7 +2889,7 @@
  20418. * Otherwise the list_lock will synchronize with
  20419. * other processors updating the list of slabs.
  20420. */
  20421. - spin_lock_irqsave(&n->list_lock, flags);
  20422. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20423. }
  20424. }
  20425. @@ -2869,7 +2931,7 @@
  20426. add_partial(n, page, DEACTIVATE_TO_TAIL);
  20427. stat(s, FREE_ADD_PARTIAL);
  20428. }
  20429. - spin_unlock_irqrestore(&n->list_lock, flags);
  20430. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20431. return;
  20432. slab_empty:
  20433. @@ -2884,7 +2946,7 @@
  20434. remove_full(s, n, page);
  20435. }
  20436. - spin_unlock_irqrestore(&n->list_lock, flags);
  20437. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20438. stat(s, FREE_SLAB);
  20439. discard_slab(s, page);
  20440. }
  20441. @@ -3089,6 +3151,7 @@
  20442. void **p)
  20443. {
  20444. struct kmem_cache_cpu *c;
  20445. + LIST_HEAD(to_free);
  20446. int i;
  20447. /* memcg and kmem_cache debug support */
  20448. @@ -3112,7 +3175,7 @@
  20449. * of re-populating per CPU c->freelist
  20450. */
  20451. p[i] = ___slab_alloc(s, flags, NUMA_NO_NODE,
  20452. - _RET_IP_, c);
  20453. + _RET_IP_, c, &to_free);
  20454. if (unlikely(!p[i]))
  20455. goto error;
  20456. @@ -3124,6 +3187,7 @@
  20457. }
  20458. c->tid = next_tid(c->tid);
  20459. local_irq_enable();
  20460. + free_delayed(&to_free);
  20461. /* Clear memory outside IRQ disabled fastpath loop */
  20462. if (unlikely(flags & __GFP_ZERO)) {
  20463. @@ -3271,7 +3335,7 @@
  20464. init_kmem_cache_node(struct kmem_cache_node *n)
  20465. {
  20466. n->nr_partial = 0;
  20467. - spin_lock_init(&n->list_lock);
  20468. + raw_spin_lock_init(&n->list_lock);
  20469. INIT_LIST_HEAD(&n->partial);
  20470. #ifdef CONFIG_SLUB_DEBUG
  20471. atomic_long_set(&n->nr_slabs, 0);
  20472. @@ -3615,6 +3679,10 @@
  20473. const char *text)
  20474. {
  20475. #ifdef CONFIG_SLUB_DEBUG
  20476. +#ifdef CONFIG_PREEMPT_RT_BASE
  20477. + /* XXX move out of irq-off section */
  20478. + slab_err(s, page, text, s->name);
  20479. +#else
  20480. void *addr = page_address(page);
  20481. void *p;
  20482. unsigned long *map = kzalloc(BITS_TO_LONGS(page->objects) *
  20483. @@ -3635,6 +3703,7 @@
  20484. slab_unlock(page);
  20485. kfree(map);
  20486. #endif
  20487. +#endif
  20488. }
  20489. /*
  20490. @@ -3648,7 +3717,7 @@
  20491. struct page *page, *h;
  20492. BUG_ON(irqs_disabled());
  20493. - spin_lock_irq(&n->list_lock);
  20494. + raw_spin_lock_irq(&n->list_lock);
  20495. list_for_each_entry_safe(page, h, &n->partial, lru) {
  20496. if (!page->inuse) {
  20497. remove_partial(n, page);
  20498. @@ -3658,7 +3727,7 @@
  20499. "Objects remaining in %s on __kmem_cache_shutdown()");
  20500. }
  20501. }
  20502. - spin_unlock_irq(&n->list_lock);
  20503. + raw_spin_unlock_irq(&n->list_lock);
  20504. list_for_each_entry_safe(page, h, &discard, lru)
  20505. discard_slab(s, page);
  20506. @@ -3916,7 +3985,7 @@
  20507. for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
  20508. INIT_LIST_HEAD(promote + i);
  20509. - spin_lock_irqsave(&n->list_lock, flags);
  20510. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20511. /*
  20512. * Build lists of slabs to discard or promote.
  20513. @@ -3947,7 +4016,7 @@
  20514. for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
  20515. list_splice(promote + i, &n->partial);
  20516. - spin_unlock_irqrestore(&n->list_lock, flags);
  20517. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20518. /* Release empty slabs */
  20519. list_for_each_entry_safe(page, t, &discard, lru)
  20520. @@ -4123,6 +4192,12 @@
  20521. {
  20522. static __initdata struct kmem_cache boot_kmem_cache,
  20523. boot_kmem_cache_node;
  20524. + int cpu;
  20525. +
  20526. + for_each_possible_cpu(cpu) {
  20527. + raw_spin_lock_init(&per_cpu(slub_free_list, cpu).lock);
  20528. + INIT_LIST_HEAD(&per_cpu(slub_free_list, cpu).list);
  20529. + }
  20530. if (debug_guardpage_minorder())
  20531. slub_max_order = 0;
  20532. @@ -4331,7 +4406,7 @@
  20533. struct page *page;
  20534. unsigned long flags;
  20535. - spin_lock_irqsave(&n->list_lock, flags);
  20536. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20537. list_for_each_entry(page, &n->partial, lru) {
  20538. validate_slab_slab(s, page, map);
  20539. @@ -4353,7 +4428,7 @@
  20540. s->name, count, atomic_long_read(&n->nr_slabs));
  20541. out:
  20542. - spin_unlock_irqrestore(&n->list_lock, flags);
  20543. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20544. return count;
  20545. }
  20546. @@ -4541,12 +4616,12 @@
  20547. if (!atomic_long_read(&n->nr_slabs))
  20548. continue;
  20549. - spin_lock_irqsave(&n->list_lock, flags);
  20550. + raw_spin_lock_irqsave(&n->list_lock, flags);
  20551. list_for_each_entry(page, &n->partial, lru)
  20552. process_slab(&t, s, page, alloc, map);
  20553. list_for_each_entry(page, &n->full, lru)
  20554. process_slab(&t, s, page, alloc, map);
  20555. - spin_unlock_irqrestore(&n->list_lock, flags);
  20556. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  20557. }
  20558. for (i = 0; i < t.count; i++) {
  20559. diff -Nur linux-4.9.6.orig/mm/swap.c linux-4.9.6/mm/swap.c
  20560. --- linux-4.9.6.orig/mm/swap.c 2017-01-26 08:25:24.000000000 +0100
  20561. +++ linux-4.9.6/mm/swap.c 2017-01-28 13:59:10.103662798 +0100
  20562. @@ -32,6 +32,7 @@
  20563. #include <linux/memcontrol.h>
  20564. #include <linux/gfp.h>
  20565. #include <linux/uio.h>
  20566. +#include <linux/locallock.h>
  20567. #include <linux/hugetlb.h>
  20568. #include <linux/page_idle.h>
  20569. @@ -50,6 +51,8 @@
  20570. #ifdef CONFIG_SMP
  20571. static DEFINE_PER_CPU(struct pagevec, activate_page_pvecs);
  20572. #endif
  20573. +static DEFINE_LOCAL_IRQ_LOCK(rotate_lock);
  20574. +DEFINE_LOCAL_IRQ_LOCK(swapvec_lock);
  20575. /*
  20576. * This path almost never happens for VM activity - pages are normally
  20577. @@ -240,11 +243,11 @@
  20578. unsigned long flags;
  20579. get_page(page);
  20580. - local_irq_save(flags);
  20581. + local_lock_irqsave(rotate_lock, flags);
  20582. pvec = this_cpu_ptr(&lru_rotate_pvecs);
  20583. if (!pagevec_add(pvec, page) || PageCompound(page))
  20584. pagevec_move_tail(pvec);
  20585. - local_irq_restore(flags);
  20586. + local_unlock_irqrestore(rotate_lock, flags);
  20587. }
  20588. }
  20589. @@ -294,12 +297,13 @@
  20590. {
  20591. page = compound_head(page);
  20592. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  20593. - struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
  20594. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  20595. + activate_page_pvecs);
  20596. get_page(page);
  20597. if (!pagevec_add(pvec, page) || PageCompound(page))
  20598. pagevec_lru_move_fn(pvec, __activate_page, NULL);
  20599. - put_cpu_var(activate_page_pvecs);
  20600. + put_locked_var(swapvec_lock, activate_page_pvecs);
  20601. }
  20602. }
  20603. @@ -326,7 +330,7 @@
  20604. static void __lru_cache_activate_page(struct page *page)
  20605. {
  20606. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  20607. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  20608. int i;
  20609. /*
  20610. @@ -348,7 +352,7 @@
  20611. }
  20612. }
  20613. - put_cpu_var(lru_add_pvec);
  20614. + put_locked_var(swapvec_lock, lru_add_pvec);
  20615. }
  20616. /*
  20617. @@ -390,12 +394,12 @@
  20618. static void __lru_cache_add(struct page *page)
  20619. {
  20620. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  20621. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  20622. get_page(page);
  20623. if (!pagevec_add(pvec, page) || PageCompound(page))
  20624. __pagevec_lru_add(pvec);
  20625. - put_cpu_var(lru_add_pvec);
  20626. + put_locked_var(swapvec_lock, lru_add_pvec);
  20627. }
  20628. /**
  20629. @@ -593,9 +597,15 @@
  20630. unsigned long flags;
  20631. /* No harm done if a racing interrupt already did this */
  20632. - local_irq_save(flags);
  20633. +#ifdef CONFIG_PREEMPT_RT_BASE
  20634. + local_lock_irqsave_on(rotate_lock, flags, cpu);
  20635. pagevec_move_tail(pvec);
  20636. - local_irq_restore(flags);
  20637. + local_unlock_irqrestore_on(rotate_lock, flags, cpu);
  20638. +#else
  20639. + local_lock_irqsave(rotate_lock, flags);
  20640. + pagevec_move_tail(pvec);
  20641. + local_unlock_irqrestore(rotate_lock, flags);
  20642. +#endif
  20643. }
  20644. pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
  20645. @@ -627,11 +637,12 @@
  20646. return;
  20647. if (likely(get_page_unless_zero(page))) {
  20648. - struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
  20649. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  20650. + lru_deactivate_file_pvecs);
  20651. if (!pagevec_add(pvec, page) || PageCompound(page))
  20652. pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
  20653. - put_cpu_var(lru_deactivate_file_pvecs);
  20654. + put_locked_var(swapvec_lock, lru_deactivate_file_pvecs);
  20655. }
  20656. }
  20657. @@ -646,27 +657,31 @@
  20658. void deactivate_page(struct page *page)
  20659. {
  20660. if (PageLRU(page) && PageActive(page) && !PageUnevictable(page)) {
  20661. - struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
  20662. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  20663. + lru_deactivate_pvecs);
  20664. get_page(page);
  20665. if (!pagevec_add(pvec, page) || PageCompound(page))
  20666. pagevec_lru_move_fn(pvec, lru_deactivate_fn, NULL);
  20667. - put_cpu_var(lru_deactivate_pvecs);
  20668. + put_locked_var(swapvec_lock, lru_deactivate_pvecs);
  20669. }
  20670. }
  20671. void lru_add_drain(void)
  20672. {
  20673. - lru_add_drain_cpu(get_cpu());
  20674. - put_cpu();
  20675. + lru_add_drain_cpu(local_lock_cpu(swapvec_lock));
  20676. + local_unlock_cpu(swapvec_lock);
  20677. }
  20678. -static void lru_add_drain_per_cpu(struct work_struct *dummy)
  20679. +#ifdef CONFIG_PREEMPT_RT_BASE
  20680. +static inline void remote_lru_add_drain(int cpu, struct cpumask *has_work)
  20681. {
  20682. - lru_add_drain();
  20683. + local_lock_on(swapvec_lock, cpu);
  20684. + lru_add_drain_cpu(cpu);
  20685. + local_unlock_on(swapvec_lock, cpu);
  20686. }
  20687. -static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
  20688. +#else
  20689. /*
  20690. * lru_add_drain_wq is used to do lru_add_drain_all() from a WQ_MEM_RECLAIM
  20691. @@ -686,6 +701,22 @@
  20692. }
  20693. early_initcall(lru_init);
  20694. +static void lru_add_drain_per_cpu(struct work_struct *dummy)
  20695. +{
  20696. + lru_add_drain();
  20697. +}
  20698. +
  20699. +static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
  20700. +static inline void remote_lru_add_drain(int cpu, struct cpumask *has_work)
  20701. +{
  20702. + struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);
  20703. +
  20704. + INIT_WORK(work, lru_add_drain_per_cpu);
  20705. + queue_work_on(cpu, lru_add_drain_wq, work);
  20706. + cpumask_set_cpu(cpu, has_work);
  20707. +}
  20708. +#endif
  20709. +
  20710. void lru_add_drain_all(void)
  20711. {
  20712. static DEFINE_MUTEX(lock);
  20713. @@ -697,21 +728,18 @@
  20714. cpumask_clear(&has_work);
  20715. for_each_online_cpu(cpu) {
  20716. - struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);
  20717. -
  20718. if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
  20719. pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
  20720. pagevec_count(&per_cpu(lru_deactivate_file_pvecs, cpu)) ||
  20721. pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
  20722. - need_activate_page_drain(cpu)) {
  20723. - INIT_WORK(work, lru_add_drain_per_cpu);
  20724. - queue_work_on(cpu, lru_add_drain_wq, work);
  20725. - cpumask_set_cpu(cpu, &has_work);
  20726. - }
  20727. + need_activate_page_drain(cpu))
  20728. + remote_lru_add_drain(cpu, &has_work);
  20729. }
  20730. +#ifndef CONFIG_PREEMPT_RT_BASE
  20731. for_each_cpu(cpu, &has_work)
  20732. flush_work(&per_cpu(lru_add_drain_work, cpu));
  20733. +#endif
  20734. put_online_cpus();
  20735. mutex_unlock(&lock);
  20736. diff -Nur linux-4.9.6.orig/mm/truncate.c linux-4.9.6/mm/truncate.c
  20737. --- linux-4.9.6.orig/mm/truncate.c 2017-01-26 08:25:24.000000000 +0100
  20738. +++ linux-4.9.6/mm/truncate.c 2017-01-28 13:59:10.103662798 +0100
  20739. @@ -62,9 +62,12 @@
  20740. * protected by mapping->tree_lock.
  20741. */
  20742. if (!workingset_node_shadows(node) &&
  20743. - !list_empty(&node->private_list))
  20744. - list_lru_del(&workingset_shadow_nodes,
  20745. + !list_empty(&node->private_list)) {
  20746. + local_lock(workingset_shadow_lock);
  20747. + list_lru_del(&__workingset_shadow_nodes,
  20748. &node->private_list);
  20749. + local_unlock(workingset_shadow_lock);
  20750. + }
  20751. __radix_tree_delete_node(&mapping->page_tree, node);
  20752. unlock:
  20753. spin_unlock_irq(&mapping->tree_lock);
  20754. diff -Nur linux-4.9.6.orig/mm/vmalloc.c linux-4.9.6/mm/vmalloc.c
  20755. --- linux-4.9.6.orig/mm/vmalloc.c 2017-01-26 08:25:24.000000000 +0100
  20756. +++ linux-4.9.6/mm/vmalloc.c 2017-01-28 13:59:10.103662798 +0100
  20757. @@ -845,7 +845,7 @@
  20758. struct vmap_block *vb;
  20759. struct vmap_area *va;
  20760. unsigned long vb_idx;
  20761. - int node, err;
  20762. + int node, err, cpu;
  20763. void *vaddr;
  20764. node = numa_node_id();
  20765. @@ -888,11 +888,12 @@
  20766. BUG_ON(err);
  20767. radix_tree_preload_end();
  20768. - vbq = &get_cpu_var(vmap_block_queue);
  20769. + cpu = get_cpu_light();
  20770. + vbq = this_cpu_ptr(&vmap_block_queue);
  20771. spin_lock(&vbq->lock);
  20772. list_add_tail_rcu(&vb->free_list, &vbq->free);
  20773. spin_unlock(&vbq->lock);
  20774. - put_cpu_var(vmap_block_queue);
  20775. + put_cpu_light();
  20776. return vaddr;
  20777. }
  20778. @@ -961,6 +962,7 @@
  20779. struct vmap_block *vb;
  20780. void *vaddr = NULL;
  20781. unsigned int order;
  20782. + int cpu;
  20783. BUG_ON(offset_in_page(size));
  20784. BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
  20785. @@ -975,7 +977,8 @@
  20786. order = get_order(size);
  20787. rcu_read_lock();
  20788. - vbq = &get_cpu_var(vmap_block_queue);
  20789. + cpu = get_cpu_light();
  20790. + vbq = this_cpu_ptr(&vmap_block_queue);
  20791. list_for_each_entry_rcu(vb, &vbq->free, free_list) {
  20792. unsigned long pages_off;
  20793. @@ -998,7 +1001,7 @@
  20794. break;
  20795. }
  20796. - put_cpu_var(vmap_block_queue);
  20797. + put_cpu_light();
  20798. rcu_read_unlock();
  20799. /* Allocate new block if nothing was found */
  20800. diff -Nur linux-4.9.6.orig/mm/vmstat.c linux-4.9.6/mm/vmstat.c
  20801. --- linux-4.9.6.orig/mm/vmstat.c 2017-01-26 08:25:24.000000000 +0100
  20802. +++ linux-4.9.6/mm/vmstat.c 2017-01-28 13:59:10.103662798 +0100
  20803. @@ -245,6 +245,7 @@
  20804. long x;
  20805. long t;
  20806. + preempt_disable_rt();
  20807. x = delta + __this_cpu_read(*p);
  20808. t = __this_cpu_read(pcp->stat_threshold);
  20809. @@ -254,6 +255,7 @@
  20810. x = 0;
  20811. }
  20812. __this_cpu_write(*p, x);
  20813. + preempt_enable_rt();
  20814. }
  20815. EXPORT_SYMBOL(__mod_zone_page_state);
  20816. @@ -265,6 +267,7 @@
  20817. long x;
  20818. long t;
  20819. + preempt_disable_rt();
  20820. x = delta + __this_cpu_read(*p);
  20821. t = __this_cpu_read(pcp->stat_threshold);
  20822. @@ -274,6 +277,7 @@
  20823. x = 0;
  20824. }
  20825. __this_cpu_write(*p, x);
  20826. + preempt_enable_rt();
  20827. }
  20828. EXPORT_SYMBOL(__mod_node_page_state);
  20829. @@ -306,6 +310,7 @@
  20830. s8 __percpu *p = pcp->vm_stat_diff + item;
  20831. s8 v, t;
  20832. + preempt_disable_rt();
  20833. v = __this_cpu_inc_return(*p);
  20834. t = __this_cpu_read(pcp->stat_threshold);
  20835. if (unlikely(v > t)) {
  20836. @@ -314,6 +319,7 @@
  20837. zone_page_state_add(v + overstep, zone, item);
  20838. __this_cpu_write(*p, -overstep);
  20839. }
  20840. + preempt_enable_rt();
  20841. }
  20842. void __inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  20843. @@ -322,6 +328,7 @@
  20844. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  20845. s8 v, t;
  20846. + preempt_disable_rt();
  20847. v = __this_cpu_inc_return(*p);
  20848. t = __this_cpu_read(pcp->stat_threshold);
  20849. if (unlikely(v > t)) {
  20850. @@ -330,6 +337,7 @@
  20851. node_page_state_add(v + overstep, pgdat, item);
  20852. __this_cpu_write(*p, -overstep);
  20853. }
  20854. + preempt_enable_rt();
  20855. }
  20856. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  20857. @@ -350,6 +358,7 @@
  20858. s8 __percpu *p = pcp->vm_stat_diff + item;
  20859. s8 v, t;
  20860. + preempt_disable_rt();
  20861. v = __this_cpu_dec_return(*p);
  20862. t = __this_cpu_read(pcp->stat_threshold);
  20863. if (unlikely(v < - t)) {
  20864. @@ -358,6 +367,7 @@
  20865. zone_page_state_add(v - overstep, zone, item);
  20866. __this_cpu_write(*p, overstep);
  20867. }
  20868. + preempt_enable_rt();
  20869. }
  20870. void __dec_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  20871. @@ -366,6 +376,7 @@
  20872. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  20873. s8 v, t;
  20874. + preempt_disable_rt();
  20875. v = __this_cpu_dec_return(*p);
  20876. t = __this_cpu_read(pcp->stat_threshold);
  20877. if (unlikely(v < - t)) {
  20878. @@ -374,6 +385,7 @@
  20879. node_page_state_add(v - overstep, pgdat, item);
  20880. __this_cpu_write(*p, overstep);
  20881. }
  20882. + preempt_enable_rt();
  20883. }
  20884. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  20885. diff -Nur linux-4.9.6.orig/mm/workingset.c linux-4.9.6/mm/workingset.c
  20886. --- linux-4.9.6.orig/mm/workingset.c 2017-01-26 08:25:24.000000000 +0100
  20887. +++ linux-4.9.6/mm/workingset.c 2017-01-28 13:59:10.103662798 +0100
  20888. @@ -334,7 +334,8 @@
  20889. * point where they would still be useful.
  20890. */
  20891. -struct list_lru workingset_shadow_nodes;
  20892. +struct list_lru __workingset_shadow_nodes;
  20893. +DEFINE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  20894. static unsigned long count_shadow_nodes(struct shrinker *shrinker,
  20895. struct shrink_control *sc)
  20896. @@ -344,9 +345,9 @@
  20897. unsigned long pages;
  20898. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  20899. - local_irq_disable();
  20900. - shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
  20901. - local_irq_enable();
  20902. + local_lock_irq(workingset_shadow_lock);
  20903. + shadow_nodes = list_lru_shrink_count(&__workingset_shadow_nodes, sc);
  20904. + local_unlock_irq(workingset_shadow_lock);
  20905. if (sc->memcg) {
  20906. pages = mem_cgroup_node_nr_lru_pages(sc->memcg, sc->nid,
  20907. @@ -438,9 +439,9 @@
  20908. spin_unlock(&mapping->tree_lock);
  20909. ret = LRU_REMOVED_RETRY;
  20910. out:
  20911. - local_irq_enable();
  20912. + local_unlock_irq(workingset_shadow_lock);
  20913. cond_resched();
  20914. - local_irq_disable();
  20915. + local_lock_irq(workingset_shadow_lock);
  20916. spin_lock(lru_lock);
  20917. return ret;
  20918. }
  20919. @@ -451,10 +452,10 @@
  20920. unsigned long ret;
  20921. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  20922. - local_irq_disable();
  20923. - ret = list_lru_shrink_walk(&workingset_shadow_nodes, sc,
  20924. + local_lock_irq(workingset_shadow_lock);
  20925. + ret = list_lru_shrink_walk(&__workingset_shadow_nodes, sc,
  20926. shadow_lru_isolate, NULL);
  20927. - local_irq_enable();
  20928. + local_unlock_irq(workingset_shadow_lock);
  20929. return ret;
  20930. }
  20931. @@ -492,7 +493,7 @@
  20932. pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n",
  20933. timestamp_bits, max_order, bucket_order);
  20934. - ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
  20935. + ret = list_lru_init_key(&__workingset_shadow_nodes, &shadow_nodes_key);
  20936. if (ret)
  20937. goto err;
  20938. ret = register_shrinker(&workingset_shadow_shrinker);
  20939. @@ -500,7 +501,7 @@
  20940. goto err_list_lru;
  20941. return 0;
  20942. err_list_lru:
  20943. - list_lru_destroy(&workingset_shadow_nodes);
  20944. + list_lru_destroy(&__workingset_shadow_nodes);
  20945. err:
  20946. return ret;
  20947. }
  20948. diff -Nur linux-4.9.6.orig/mm/zsmalloc.c linux-4.9.6/mm/zsmalloc.c
  20949. --- linux-4.9.6.orig/mm/zsmalloc.c 2017-01-26 08:25:24.000000000 +0100
  20950. +++ linux-4.9.6/mm/zsmalloc.c 2017-01-28 13:59:10.103662798 +0100
  20951. @@ -53,6 +53,7 @@
  20952. #include <linux/mount.h>
  20953. #include <linux/migrate.h>
  20954. #include <linux/pagemap.h>
  20955. +#include <linux/locallock.h>
  20956. #define ZSPAGE_MAGIC 0x58
  20957. @@ -70,9 +71,22 @@
  20958. */
  20959. #define ZS_MAX_ZSPAGE_ORDER 2
  20960. #define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
  20961. -
  20962. #define ZS_HANDLE_SIZE (sizeof(unsigned long))
  20963. +#ifdef CONFIG_PREEMPT_RT_FULL
  20964. +
  20965. +struct zsmalloc_handle {
  20966. + unsigned long addr;
  20967. + struct mutex lock;
  20968. +};
  20969. +
  20970. +#define ZS_HANDLE_ALLOC_SIZE (sizeof(struct zsmalloc_handle))
  20971. +
  20972. +#else
  20973. +
  20974. +#define ZS_HANDLE_ALLOC_SIZE (sizeof(unsigned long))
  20975. +#endif
  20976. +
  20977. /*
  20978. * Object location (<PFN>, <obj_idx>) is encoded as
  20979. * as single (unsigned long) handle value.
  20980. @@ -327,7 +341,7 @@
  20981. static int create_cache(struct zs_pool *pool)
  20982. {
  20983. - pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,
  20984. + pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_ALLOC_SIZE,
  20985. 0, 0, NULL);
  20986. if (!pool->handle_cachep)
  20987. return 1;
  20988. @@ -351,10 +365,27 @@
  20989. static unsigned long cache_alloc_handle(struct zs_pool *pool, gfp_t gfp)
  20990. {
  20991. - return (unsigned long)kmem_cache_alloc(pool->handle_cachep,
  20992. - gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE));
  20993. + void *p;
  20994. +
  20995. + p = kmem_cache_alloc(pool->handle_cachep,
  20996. + gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE));
  20997. +#ifdef CONFIG_PREEMPT_RT_FULL
  20998. + if (p) {
  20999. + struct zsmalloc_handle *zh = p;
  21000. +
  21001. + mutex_init(&zh->lock);
  21002. + }
  21003. +#endif
  21004. + return (unsigned long)p;
  21005. }
  21006. +#ifdef CONFIG_PREEMPT_RT_FULL
  21007. +static struct zsmalloc_handle *zs_get_pure_handle(unsigned long handle)
  21008. +{
  21009. + return (void *)(handle &~((1 << OBJ_TAG_BITS) - 1));
  21010. +}
  21011. +#endif
  21012. +
  21013. static void cache_free_handle(struct zs_pool *pool, unsigned long handle)
  21014. {
  21015. kmem_cache_free(pool->handle_cachep, (void *)handle);
  21016. @@ -373,12 +404,18 @@
  21017. static void record_obj(unsigned long handle, unsigned long obj)
  21018. {
  21019. +#ifdef CONFIG_PREEMPT_RT_FULL
  21020. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21021. +
  21022. + WRITE_ONCE(zh->addr, obj);
  21023. +#else
  21024. /*
  21025. * lsb of @obj represents handle lock while other bits
  21026. * represent object value the handle is pointing so
  21027. * updating shouldn't do store tearing.
  21028. */
  21029. WRITE_ONCE(*(unsigned long *)handle, obj);
  21030. +#endif
  21031. }
  21032. /* zpool driver */
  21033. @@ -467,6 +504,7 @@
  21034. /* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
  21035. static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
  21036. +static DEFINE_LOCAL_IRQ_LOCK(zs_map_area_lock);
  21037. static bool is_zspage_isolated(struct zspage *zspage)
  21038. {
  21039. @@ -902,7 +940,13 @@
  21040. static unsigned long handle_to_obj(unsigned long handle)
  21041. {
  21042. +#ifdef CONFIG_PREEMPT_RT_FULL
  21043. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21044. +
  21045. + return zh->addr;
  21046. +#else
  21047. return *(unsigned long *)handle;
  21048. +#endif
  21049. }
  21050. static unsigned long obj_to_head(struct page *page, void *obj)
  21051. @@ -916,22 +960,46 @@
  21052. static inline int testpin_tag(unsigned long handle)
  21053. {
  21054. +#ifdef CONFIG_PREEMPT_RT_FULL
  21055. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21056. +
  21057. + return mutex_is_locked(&zh->lock);
  21058. +#else
  21059. return bit_spin_is_locked(HANDLE_PIN_BIT, (unsigned long *)handle);
  21060. +#endif
  21061. }
  21062. static inline int trypin_tag(unsigned long handle)
  21063. {
  21064. +#ifdef CONFIG_PREEMPT_RT_FULL
  21065. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21066. +
  21067. + return mutex_trylock(&zh->lock);
  21068. +#else
  21069. return bit_spin_trylock(HANDLE_PIN_BIT, (unsigned long *)handle);
  21070. +#endif
  21071. }
  21072. static void pin_tag(unsigned long handle)
  21073. {
  21074. +#ifdef CONFIG_PREEMPT_RT_FULL
  21075. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21076. +
  21077. + return mutex_lock(&zh->lock);
  21078. +#else
  21079. bit_spin_lock(HANDLE_PIN_BIT, (unsigned long *)handle);
  21080. +#endif
  21081. }
  21082. static void unpin_tag(unsigned long handle)
  21083. {
  21084. +#ifdef CONFIG_PREEMPT_RT_FULL
  21085. + struct zsmalloc_handle *zh = zs_get_pure_handle(handle);
  21086. +
  21087. + return mutex_unlock(&zh->lock);
  21088. +#else
  21089. bit_spin_unlock(HANDLE_PIN_BIT, (unsigned long *)handle);
  21090. +#endif
  21091. }
  21092. static void reset_page(struct page *page)
  21093. @@ -1423,7 +1491,7 @@
  21094. class = pool->size_class[class_idx];
  21095. off = (class->size * obj_idx) & ~PAGE_MASK;
  21096. - area = &get_cpu_var(zs_map_area);
  21097. + area = &get_locked_var(zs_map_area_lock, zs_map_area);
  21098. area->vm_mm = mm;
  21099. if (off + class->size <= PAGE_SIZE) {
  21100. /* this object is contained entirely within a page */
  21101. @@ -1477,7 +1545,7 @@
  21102. __zs_unmap_object(area, pages, off, class->size);
  21103. }
  21104. - put_cpu_var(zs_map_area);
  21105. + put_locked_var(zs_map_area_lock, zs_map_area);
  21106. migrate_read_unlock(zspage);
  21107. unpin_tag(handle);
  21108. diff -Nur linux-4.9.6.orig/net/core/dev.c linux-4.9.6/net/core/dev.c
  21109. --- linux-4.9.6.orig/net/core/dev.c 2017-01-26 08:25:24.000000000 +0100
  21110. +++ linux-4.9.6/net/core/dev.c 2017-01-28 13:59:10.103662798 +0100
  21111. @@ -190,6 +190,7 @@
  21112. static DEFINE_READ_MOSTLY_HASHTABLE(napi_hash, 8);
  21113. static seqcount_t devnet_rename_seq;
  21114. +static DEFINE_MUTEX(devnet_rename_mutex);
  21115. static inline void dev_base_seq_inc(struct net *net)
  21116. {
  21117. @@ -211,14 +212,14 @@
  21118. static inline void rps_lock(struct softnet_data *sd)
  21119. {
  21120. #ifdef CONFIG_RPS
  21121. - spin_lock(&sd->input_pkt_queue.lock);
  21122. + raw_spin_lock(&sd->input_pkt_queue.raw_lock);
  21123. #endif
  21124. }
  21125. static inline void rps_unlock(struct softnet_data *sd)
  21126. {
  21127. #ifdef CONFIG_RPS
  21128. - spin_unlock(&sd->input_pkt_queue.lock);
  21129. + raw_spin_unlock(&sd->input_pkt_queue.raw_lock);
  21130. #endif
  21131. }
  21132. @@ -888,7 +889,8 @@
  21133. strcpy(name, dev->name);
  21134. rcu_read_unlock();
  21135. if (read_seqcount_retry(&devnet_rename_seq, seq)) {
  21136. - cond_resched();
  21137. + mutex_lock(&devnet_rename_mutex);
  21138. + mutex_unlock(&devnet_rename_mutex);
  21139. goto retry;
  21140. }
  21141. @@ -1157,20 +1159,17 @@
  21142. if (dev->flags & IFF_UP)
  21143. return -EBUSY;
  21144. - write_seqcount_begin(&devnet_rename_seq);
  21145. + mutex_lock(&devnet_rename_mutex);
  21146. + __raw_write_seqcount_begin(&devnet_rename_seq);
  21147. - if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
  21148. - write_seqcount_end(&devnet_rename_seq);
  21149. - return 0;
  21150. - }
  21151. + if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
  21152. + goto outunlock;
  21153. memcpy(oldname, dev->name, IFNAMSIZ);
  21154. err = dev_get_valid_name(net, dev, newname);
  21155. - if (err < 0) {
  21156. - write_seqcount_end(&devnet_rename_seq);
  21157. - return err;
  21158. - }
  21159. + if (err < 0)
  21160. + goto outunlock;
  21161. if (oldname[0] && !strchr(oldname, '%'))
  21162. netdev_info(dev, "renamed from %s\n", oldname);
  21163. @@ -1183,11 +1182,12 @@
  21164. if (ret) {
  21165. memcpy(dev->name, oldname, IFNAMSIZ);
  21166. dev->name_assign_type = old_assign_type;
  21167. - write_seqcount_end(&devnet_rename_seq);
  21168. - return ret;
  21169. + err = ret;
  21170. + goto outunlock;
  21171. }
  21172. - write_seqcount_end(&devnet_rename_seq);
  21173. + __raw_write_seqcount_end(&devnet_rename_seq);
  21174. + mutex_unlock(&devnet_rename_mutex);
  21175. netdev_adjacent_rename_links(dev, oldname);
  21176. @@ -1208,7 +1208,8 @@
  21177. /* err >= 0 after dev_alloc_name() or stores the first errno */
  21178. if (err >= 0) {
  21179. err = ret;
  21180. - write_seqcount_begin(&devnet_rename_seq);
  21181. + mutex_lock(&devnet_rename_mutex);
  21182. + __raw_write_seqcount_begin(&devnet_rename_seq);
  21183. memcpy(dev->name, oldname, IFNAMSIZ);
  21184. memcpy(oldname, newname, IFNAMSIZ);
  21185. dev->name_assign_type = old_assign_type;
  21186. @@ -1221,6 +1222,11 @@
  21187. }
  21188. return err;
  21189. +
  21190. +outunlock:
  21191. + __raw_write_seqcount_end(&devnet_rename_seq);
  21192. + mutex_unlock(&devnet_rename_mutex);
  21193. + return err;
  21194. }
  21195. /**
  21196. @@ -2263,6 +2269,7 @@
  21197. sd->output_queue_tailp = &q->next_sched;
  21198. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  21199. local_irq_restore(flags);
  21200. + preempt_check_resched_rt();
  21201. }
  21202. void __netif_schedule(struct Qdisc *q)
  21203. @@ -2344,6 +2351,7 @@
  21204. __this_cpu_write(softnet_data.completion_queue, skb);
  21205. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  21206. local_irq_restore(flags);
  21207. + preempt_check_resched_rt();
  21208. }
  21209. EXPORT_SYMBOL(__dev_kfree_skb_irq);
  21210. @@ -3078,7 +3086,11 @@
  21211. * This permits qdisc->running owner to get the lock more
  21212. * often and dequeue packets faster.
  21213. */
  21214. +#ifdef CONFIG_PREEMPT_RT_FULL
  21215. + contended = true;
  21216. +#else
  21217. contended = qdisc_is_running(q);
  21218. +#endif
  21219. if (unlikely(contended))
  21220. spin_lock(&q->busylock);
  21221. @@ -3141,8 +3153,10 @@
  21222. #define skb_update_prio(skb)
  21223. #endif
  21224. +#ifndef CONFIG_PREEMPT_RT_FULL
  21225. DEFINE_PER_CPU(int, xmit_recursion);
  21226. EXPORT_SYMBOL(xmit_recursion);
  21227. +#endif
  21228. /**
  21229. * dev_loopback_xmit - loop back @skb
  21230. @@ -3376,8 +3390,7 @@
  21231. int cpu = smp_processor_id(); /* ok because BHs are off */
  21232. if (txq->xmit_lock_owner != cpu) {
  21233. - if (unlikely(__this_cpu_read(xmit_recursion) >
  21234. - XMIT_RECURSION_LIMIT))
  21235. + if (unlikely(xmit_rec_read() > XMIT_RECURSION_LIMIT))
  21236. goto recursion_alert;
  21237. skb = validate_xmit_skb(skb, dev);
  21238. @@ -3387,9 +3400,9 @@
  21239. HARD_TX_LOCK(dev, txq, cpu);
  21240. if (!netif_xmit_stopped(txq)) {
  21241. - __this_cpu_inc(xmit_recursion);
  21242. + xmit_rec_inc();
  21243. skb = dev_hard_start_xmit(skb, dev, txq, &rc);
  21244. - __this_cpu_dec(xmit_recursion);
  21245. + xmit_rec_dec();
  21246. if (dev_xmit_complete(rc)) {
  21247. HARD_TX_UNLOCK(dev, txq);
  21248. goto out;
  21249. @@ -3763,6 +3776,7 @@
  21250. rps_unlock(sd);
  21251. local_irq_restore(flags);
  21252. + preempt_check_resched_rt();
  21253. atomic_long_inc(&skb->dev->rx_dropped);
  21254. kfree_skb(skb);
  21255. @@ -3781,7 +3795,7 @@
  21256. struct rps_dev_flow voidflow, *rflow = &voidflow;
  21257. int cpu;
  21258. - preempt_disable();
  21259. + migrate_disable();
  21260. rcu_read_lock();
  21261. cpu = get_rps_cpu(skb->dev, skb, &rflow);
  21262. @@ -3791,13 +3805,13 @@
  21263. ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);
  21264. rcu_read_unlock();
  21265. - preempt_enable();
  21266. + migrate_enable();
  21267. } else
  21268. #endif
  21269. {
  21270. unsigned int qtail;
  21271. - ret = enqueue_to_backlog(skb, get_cpu(), &qtail);
  21272. - put_cpu();
  21273. + ret = enqueue_to_backlog(skb, get_cpu_light(), &qtail);
  21274. + put_cpu_light();
  21275. }
  21276. return ret;
  21277. }
  21278. @@ -3831,11 +3845,9 @@
  21279. trace_netif_rx_ni_entry(skb);
  21280. - preempt_disable();
  21281. + local_bh_disable();
  21282. err = netif_rx_internal(skb);
  21283. - if (local_softirq_pending())
  21284. - do_softirq();
  21285. - preempt_enable();
  21286. + local_bh_enable();
  21287. return err;
  21288. }
  21289. @@ -4314,7 +4326,7 @@
  21290. skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
  21291. if (skb->dev->reg_state == NETREG_UNREGISTERING) {
  21292. __skb_unlink(skb, &sd->input_pkt_queue);
  21293. - kfree_skb(skb);
  21294. + __skb_queue_tail(&sd->tofree_queue, skb);
  21295. input_queue_head_incr(sd);
  21296. }
  21297. }
  21298. @@ -4324,11 +4336,14 @@
  21299. skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
  21300. if (skb->dev->reg_state == NETREG_UNREGISTERING) {
  21301. __skb_unlink(skb, &sd->process_queue);
  21302. - kfree_skb(skb);
  21303. + __skb_queue_tail(&sd->tofree_queue, skb);
  21304. input_queue_head_incr(sd);
  21305. }
  21306. }
  21307. + if (!skb_queue_empty(&sd->tofree_queue))
  21308. + raise_softirq_irqoff(NET_RX_SOFTIRQ);
  21309. local_bh_enable();
  21310. +
  21311. }
  21312. static void flush_all_backlogs(void)
  21313. @@ -4809,6 +4824,7 @@
  21314. sd->rps_ipi_list = NULL;
  21315. local_irq_enable();
  21316. + preempt_check_resched_rt();
  21317. /* Send pending IPI's to kick RPS processing on remote cpus. */
  21318. while (remsd) {
  21319. @@ -4822,6 +4838,7 @@
  21320. } else
  21321. #endif
  21322. local_irq_enable();
  21323. + preempt_check_resched_rt();
  21324. }
  21325. static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
  21326. @@ -4851,7 +4868,9 @@
  21327. while (again) {
  21328. struct sk_buff *skb;
  21329. + local_irq_disable();
  21330. while ((skb = __skb_dequeue(&sd->process_queue))) {
  21331. + local_irq_enable();
  21332. rcu_read_lock();
  21333. __netif_receive_skb(skb);
  21334. rcu_read_unlock();
  21335. @@ -4859,9 +4878,9 @@
  21336. if (++work >= quota)
  21337. return work;
  21338. + local_irq_disable();
  21339. }
  21340. - local_irq_disable();
  21341. rps_lock(sd);
  21342. if (skb_queue_empty(&sd->input_pkt_queue)) {
  21343. /*
  21344. @@ -4899,9 +4918,11 @@
  21345. local_irq_save(flags);
  21346. ____napi_schedule(this_cpu_ptr(&softnet_data), n);
  21347. local_irq_restore(flags);
  21348. + preempt_check_resched_rt();
  21349. }
  21350. EXPORT_SYMBOL(__napi_schedule);
  21351. +#ifndef CONFIG_PREEMPT_RT_FULL
  21352. /**
  21353. * __napi_schedule_irqoff - schedule for receive
  21354. * @n: entry to schedule
  21355. @@ -4913,6 +4934,7 @@
  21356. ____napi_schedule(this_cpu_ptr(&softnet_data), n);
  21357. }
  21358. EXPORT_SYMBOL(__napi_schedule_irqoff);
  21359. +#endif
  21360. void __napi_complete(struct napi_struct *n)
  21361. {
  21362. @@ -5202,13 +5224,21 @@
  21363. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  21364. unsigned long time_limit = jiffies + 2;
  21365. int budget = netdev_budget;
  21366. + struct sk_buff_head tofree_q;
  21367. + struct sk_buff *skb;
  21368. LIST_HEAD(list);
  21369. LIST_HEAD(repoll);
  21370. + __skb_queue_head_init(&tofree_q);
  21371. +
  21372. local_irq_disable();
  21373. + skb_queue_splice_init(&sd->tofree_queue, &tofree_q);
  21374. list_splice_init(&sd->poll_list, &list);
  21375. local_irq_enable();
  21376. + while ((skb = __skb_dequeue(&tofree_q)))
  21377. + kfree_skb(skb);
  21378. +
  21379. for (;;) {
  21380. struct napi_struct *n;
  21381. @@ -5239,7 +5269,7 @@
  21382. list_splice_tail(&repoll, &list);
  21383. list_splice(&list, &sd->poll_list);
  21384. if (!list_empty(&sd->poll_list))
  21385. - __raise_softirq_irqoff(NET_RX_SOFTIRQ);
  21386. + __raise_softirq_irqoff_ksoft(NET_RX_SOFTIRQ);
  21387. net_rps_action_and_irq_enable(sd);
  21388. }
  21389. @@ -8000,16 +8030,20 @@
  21390. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  21391. local_irq_enable();
  21392. + preempt_check_resched_rt();
  21393. /* Process offline CPU's input_pkt_queue */
  21394. while ((skb = __skb_dequeue(&oldsd->process_queue))) {
  21395. netif_rx_ni(skb);
  21396. input_queue_head_incr(oldsd);
  21397. }
  21398. - while ((skb = skb_dequeue(&oldsd->input_pkt_queue))) {
  21399. + while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) {
  21400. netif_rx_ni(skb);
  21401. input_queue_head_incr(oldsd);
  21402. }
  21403. + while ((skb = __skb_dequeue(&oldsd->tofree_queue))) {
  21404. + kfree_skb(skb);
  21405. + }
  21406. return NOTIFY_OK;
  21407. }
  21408. @@ -8314,8 +8348,9 @@
  21409. INIT_WORK(flush, flush_backlog);
  21410. - skb_queue_head_init(&sd->input_pkt_queue);
  21411. - skb_queue_head_init(&sd->process_queue);
  21412. + skb_queue_head_init_raw(&sd->input_pkt_queue);
  21413. + skb_queue_head_init_raw(&sd->process_queue);
  21414. + skb_queue_head_init_raw(&sd->tofree_queue);
  21415. INIT_LIST_HEAD(&sd->poll_list);
  21416. sd->output_queue_tailp = &sd->output_queue;
  21417. #ifdef CONFIG_RPS
  21418. diff -Nur linux-4.9.6.orig/net/core/filter.c linux-4.9.6/net/core/filter.c
  21419. --- linux-4.9.6.orig/net/core/filter.c 2017-01-26 08:25:24.000000000 +0100
  21420. +++ linux-4.9.6/net/core/filter.c 2017-01-28 13:59:10.103662798 +0100
  21421. @@ -1645,7 +1645,7 @@
  21422. {
  21423. int ret;
  21424. - if (unlikely(__this_cpu_read(xmit_recursion) > XMIT_RECURSION_LIMIT)) {
  21425. + if (unlikely(xmit_rec_read() > XMIT_RECURSION_LIMIT)) {
  21426. net_crit_ratelimited("bpf: recursion limit reached on datapath, buggy bpf program?\n");
  21427. kfree_skb(skb);
  21428. return -ENETDOWN;
  21429. @@ -1653,9 +1653,9 @@
  21430. skb->dev = dev;
  21431. - __this_cpu_inc(xmit_recursion);
  21432. + xmit_rec_inc();
  21433. ret = dev_queue_xmit(skb);
  21434. - __this_cpu_dec(xmit_recursion);
  21435. + xmit_rec_dec();
  21436. return ret;
  21437. }
  21438. diff -Nur linux-4.9.6.orig/net/core/gen_estimator.c linux-4.9.6/net/core/gen_estimator.c
  21439. --- linux-4.9.6.orig/net/core/gen_estimator.c 2017-01-26 08:25:24.000000000 +0100
  21440. +++ linux-4.9.6/net/core/gen_estimator.c 2017-01-28 13:59:10.103662798 +0100
  21441. @@ -84,7 +84,7 @@
  21442. struct gnet_stats_basic_packed *bstats;
  21443. struct gnet_stats_rate_est64 *rate_est;
  21444. spinlock_t *stats_lock;
  21445. - seqcount_t *running;
  21446. + net_seqlock_t *running;
  21447. int ewma_log;
  21448. u32 last_packets;
  21449. unsigned long avpps;
  21450. @@ -213,7 +213,7 @@
  21451. struct gnet_stats_basic_cpu __percpu *cpu_bstats,
  21452. struct gnet_stats_rate_est64 *rate_est,
  21453. spinlock_t *stats_lock,
  21454. - seqcount_t *running,
  21455. + net_seqlock_t *running,
  21456. struct nlattr *opt)
  21457. {
  21458. struct gen_estimator *est;
  21459. @@ -309,7 +309,7 @@
  21460. struct gnet_stats_basic_cpu __percpu *cpu_bstats,
  21461. struct gnet_stats_rate_est64 *rate_est,
  21462. spinlock_t *stats_lock,
  21463. - seqcount_t *running, struct nlattr *opt)
  21464. + net_seqlock_t *running, struct nlattr *opt)
  21465. {
  21466. gen_kill_estimator(bstats, rate_est);
  21467. return gen_new_estimator(bstats, cpu_bstats, rate_est, stats_lock, running, opt);
  21468. diff -Nur linux-4.9.6.orig/net/core/gen_stats.c linux-4.9.6/net/core/gen_stats.c
  21469. --- linux-4.9.6.orig/net/core/gen_stats.c 2017-01-26 08:25:24.000000000 +0100
  21470. +++ linux-4.9.6/net/core/gen_stats.c 2017-01-28 13:59:10.107662951 +0100
  21471. @@ -130,7 +130,7 @@
  21472. }
  21473. void
  21474. -__gnet_stats_copy_basic(const seqcount_t *running,
  21475. +__gnet_stats_copy_basic(net_seqlock_t *running,
  21476. struct gnet_stats_basic_packed *bstats,
  21477. struct gnet_stats_basic_cpu __percpu *cpu,
  21478. struct gnet_stats_basic_packed *b)
  21479. @@ -143,10 +143,10 @@
  21480. }
  21481. do {
  21482. if (running)
  21483. - seq = read_seqcount_begin(running);
  21484. + seq = net_seq_begin(running);
  21485. bstats->bytes = b->bytes;
  21486. bstats->packets = b->packets;
  21487. - } while (running && read_seqcount_retry(running, seq));
  21488. + } while (running && net_seq_retry(running, seq));
  21489. }
  21490. EXPORT_SYMBOL(__gnet_stats_copy_basic);
  21491. @@ -164,7 +164,7 @@
  21492. * if the room in the socket buffer was not sufficient.
  21493. */
  21494. int
  21495. -gnet_stats_copy_basic(const seqcount_t *running,
  21496. +gnet_stats_copy_basic(net_seqlock_t *running,
  21497. struct gnet_dump *d,
  21498. struct gnet_stats_basic_cpu __percpu *cpu,
  21499. struct gnet_stats_basic_packed *b)
  21500. diff -Nur linux-4.9.6.orig/net/core/skbuff.c linux-4.9.6/net/core/skbuff.c
  21501. --- linux-4.9.6.orig/net/core/skbuff.c 2017-01-26 08:25:24.000000000 +0100
  21502. +++ linux-4.9.6/net/core/skbuff.c 2017-01-28 13:59:10.107662951 +0100
  21503. @@ -64,6 +64,7 @@
  21504. #include <linux/errqueue.h>
  21505. #include <linux/prefetch.h>
  21506. #include <linux/if_vlan.h>
  21507. +#include <linux/locallock.h>
  21508. #include <net/protocol.h>
  21509. #include <net/dst.h>
  21510. @@ -360,6 +361,8 @@
  21511. static DEFINE_PER_CPU(struct page_frag_cache, netdev_alloc_cache);
  21512. static DEFINE_PER_CPU(struct napi_alloc_cache, napi_alloc_cache);
  21513. +static DEFINE_LOCAL_IRQ_LOCK(netdev_alloc_lock);
  21514. +static DEFINE_LOCAL_IRQ_LOCK(napi_alloc_cache_lock);
  21515. static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
  21516. {
  21517. @@ -367,10 +370,10 @@
  21518. unsigned long flags;
  21519. void *data;
  21520. - local_irq_save(flags);
  21521. + local_lock_irqsave(netdev_alloc_lock, flags);
  21522. nc = this_cpu_ptr(&netdev_alloc_cache);
  21523. data = __alloc_page_frag(nc, fragsz, gfp_mask);
  21524. - local_irq_restore(flags);
  21525. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  21526. return data;
  21527. }
  21528. @@ -389,9 +392,13 @@
  21529. static void *__napi_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
  21530. {
  21531. - struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  21532. + struct napi_alloc_cache *nc;
  21533. + void *data;
  21534. - return __alloc_page_frag(&nc->page, fragsz, gfp_mask);
  21535. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21536. + data = __alloc_page_frag(&nc->page, fragsz, gfp_mask);
  21537. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21538. + return data;
  21539. }
  21540. void *napi_alloc_frag(unsigned int fragsz)
  21541. @@ -438,13 +445,13 @@
  21542. if (sk_memalloc_socks())
  21543. gfp_mask |= __GFP_MEMALLOC;
  21544. - local_irq_save(flags);
  21545. + local_lock_irqsave(netdev_alloc_lock, flags);
  21546. nc = this_cpu_ptr(&netdev_alloc_cache);
  21547. data = __alloc_page_frag(nc, len, gfp_mask);
  21548. pfmemalloc = nc->pfmemalloc;
  21549. - local_irq_restore(flags);
  21550. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  21551. if (unlikely(!data))
  21552. return NULL;
  21553. @@ -485,9 +492,10 @@
  21554. struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
  21555. gfp_t gfp_mask)
  21556. {
  21557. - struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  21558. + struct napi_alloc_cache *nc;
  21559. struct sk_buff *skb;
  21560. void *data;
  21561. + bool pfmemalloc;
  21562. len += NET_SKB_PAD + NET_IP_ALIGN;
  21563. @@ -505,7 +513,10 @@
  21564. if (sk_memalloc_socks())
  21565. gfp_mask |= __GFP_MEMALLOC;
  21566. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21567. data = __alloc_page_frag(&nc->page, len, gfp_mask);
  21568. + pfmemalloc = nc->page.pfmemalloc;
  21569. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21570. if (unlikely(!data))
  21571. return NULL;
  21572. @@ -516,7 +527,7 @@
  21573. }
  21574. /* use OR instead of assignment to avoid clearing of bits in mask */
  21575. - if (nc->page.pfmemalloc)
  21576. + if (pfmemalloc)
  21577. skb->pfmemalloc = 1;
  21578. skb->head_frag = 1;
  21579. @@ -760,23 +771,26 @@
  21580. void __kfree_skb_flush(void)
  21581. {
  21582. - struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  21583. + struct napi_alloc_cache *nc;
  21584. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21585. /* flush skb_cache if containing objects */
  21586. if (nc->skb_count) {
  21587. kmem_cache_free_bulk(skbuff_head_cache, nc->skb_count,
  21588. nc->skb_cache);
  21589. nc->skb_count = 0;
  21590. }
  21591. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21592. }
  21593. static inline void _kfree_skb_defer(struct sk_buff *skb)
  21594. {
  21595. - struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  21596. + struct napi_alloc_cache *nc;
  21597. /* drop skb->head and call any destructors for packet */
  21598. skb_release_all(skb);
  21599. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21600. /* record skb to CPU local list */
  21601. nc->skb_cache[nc->skb_count++] = skb;
  21602. @@ -791,6 +805,7 @@
  21603. nc->skb_cache);
  21604. nc->skb_count = 0;
  21605. }
  21606. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  21607. }
  21608. void __kfree_skb_defer(struct sk_buff *skb)
  21609. {
  21610. diff -Nur linux-4.9.6.orig/net/core/sock.c linux-4.9.6/net/core/sock.c
  21611. --- linux-4.9.6.orig/net/core/sock.c 2017-01-26 08:25:24.000000000 +0100
  21612. +++ linux-4.9.6/net/core/sock.c 2017-01-28 13:59:10.107662951 +0100
  21613. @@ -2488,12 +2488,11 @@
  21614. if (sk->sk_lock.owned)
  21615. __lock_sock(sk);
  21616. sk->sk_lock.owned = 1;
  21617. - spin_unlock(&sk->sk_lock.slock);
  21618. + spin_unlock_bh(&sk->sk_lock.slock);
  21619. /*
  21620. * The sk_lock has mutex_lock() semantics here:
  21621. */
  21622. mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
  21623. - local_bh_enable();
  21624. }
  21625. EXPORT_SYMBOL(lock_sock_nested);
  21626. diff -Nur linux-4.9.6.orig/net/ipv4/icmp.c linux-4.9.6/net/ipv4/icmp.c
  21627. --- linux-4.9.6.orig/net/ipv4/icmp.c 2017-01-26 08:25:24.000000000 +0100
  21628. +++ linux-4.9.6/net/ipv4/icmp.c 2017-01-28 13:59:10.107662951 +0100
  21629. @@ -69,6 +69,7 @@
  21630. #include <linux/jiffies.h>
  21631. #include <linux/kernel.h>
  21632. #include <linux/fcntl.h>
  21633. +#include <linux/sysrq.h>
  21634. #include <linux/socket.h>
  21635. #include <linux/in.h>
  21636. #include <linux/inet.h>
  21637. @@ -77,6 +78,7 @@
  21638. #include <linux/string.h>
  21639. #include <linux/netfilter_ipv4.h>
  21640. #include <linux/slab.h>
  21641. +#include <linux/locallock.h>
  21642. #include <net/snmp.h>
  21643. #include <net/ip.h>
  21644. #include <net/route.h>
  21645. @@ -204,6 +206,8 @@
  21646. *
  21647. * On SMP we have one ICMP socket per-cpu.
  21648. */
  21649. +static DEFINE_LOCAL_IRQ_LOCK(icmp_sk_lock);
  21650. +
  21651. static struct sock *icmp_sk(struct net *net)
  21652. {
  21653. return *this_cpu_ptr(net->ipv4.icmp_sk);
  21654. @@ -215,12 +219,14 @@
  21655. local_bh_disable();
  21656. + local_lock(icmp_sk_lock);
  21657. sk = icmp_sk(net);
  21658. if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
  21659. /* This can happen if the output path signals a
  21660. * dst_link_failure() for an outgoing ICMP packet.
  21661. */
  21662. + local_unlock(icmp_sk_lock);
  21663. local_bh_enable();
  21664. return NULL;
  21665. }
  21666. @@ -230,6 +236,7 @@
  21667. static inline void icmp_xmit_unlock(struct sock *sk)
  21668. {
  21669. spin_unlock_bh(&sk->sk_lock.slock);
  21670. + local_unlock(icmp_sk_lock);
  21671. }
  21672. int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
  21673. @@ -358,6 +365,7 @@
  21674. struct sock *sk;
  21675. struct sk_buff *skb;
  21676. + local_lock(icmp_sk_lock);
  21677. sk = icmp_sk(dev_net((*rt)->dst.dev));
  21678. if (ip_append_data(sk, fl4, icmp_glue_bits, icmp_param,
  21679. icmp_param->data_len+icmp_param->head_len,
  21680. @@ -380,6 +388,7 @@
  21681. skb->ip_summed = CHECKSUM_NONE;
  21682. ip_push_pending_frames(sk, fl4);
  21683. }
  21684. + local_unlock(icmp_sk_lock);
  21685. }
  21686. /*
  21687. @@ -891,6 +900,30 @@
  21688. }
  21689. /*
  21690. + * 32bit and 64bit have different timestamp length, so we check for
  21691. + * the cookie at offset 20 and verify it is repeated at offset 50
  21692. + */
  21693. +#define CO_POS0 20
  21694. +#define CO_POS1 50
  21695. +#define CO_SIZE sizeof(int)
  21696. +#define ICMP_SYSRQ_SIZE 57
  21697. +
  21698. +/*
  21699. + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
  21700. + * pattern and if it matches send the next byte as a trigger to sysrq.
  21701. + */
  21702. +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
  21703. +{
  21704. + int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
  21705. + char *p = skb->data;
  21706. +
  21707. + if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
  21708. + !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
  21709. + p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
  21710. + handle_sysrq(p[CO_POS0 + CO_SIZE]);
  21711. +}
  21712. +
  21713. +/*
  21714. * Handle ICMP_ECHO ("ping") requests.
  21715. *
  21716. * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
  21717. @@ -917,6 +950,11 @@
  21718. icmp_param.data_len = skb->len;
  21719. icmp_param.head_len = sizeof(struct icmphdr);
  21720. icmp_reply(&icmp_param, skb);
  21721. +
  21722. + if (skb->len == ICMP_SYSRQ_SIZE &&
  21723. + net->ipv4.sysctl_icmp_echo_sysrq) {
  21724. + icmp_check_sysrq(net, skb);
  21725. + }
  21726. }
  21727. /* should there be an ICMP stat for ignored echos? */
  21728. return true;
  21729. diff -Nur linux-4.9.6.orig/net/ipv4/sysctl_net_ipv4.c linux-4.9.6/net/ipv4/sysctl_net_ipv4.c
  21730. --- linux-4.9.6.orig/net/ipv4/sysctl_net_ipv4.c 2017-01-26 08:25:24.000000000 +0100
  21731. +++ linux-4.9.6/net/ipv4/sysctl_net_ipv4.c 2017-01-28 13:59:10.107662951 +0100
  21732. @@ -681,6 +681,13 @@
  21733. .proc_handler = proc_dointvec
  21734. },
  21735. {
  21736. + .procname = "icmp_echo_sysrq",
  21737. + .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
  21738. + .maxlen = sizeof(int),
  21739. + .mode = 0644,
  21740. + .proc_handler = proc_dointvec
  21741. + },
  21742. + {
  21743. .procname = "icmp_ignore_bogus_error_responses",
  21744. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  21745. .maxlen = sizeof(int),
  21746. diff -Nur linux-4.9.6.orig/net/ipv4/tcp_ipv4.c linux-4.9.6/net/ipv4/tcp_ipv4.c
  21747. --- linux-4.9.6.orig/net/ipv4/tcp_ipv4.c 2017-01-26 08:25:24.000000000 +0100
  21748. +++ linux-4.9.6/net/ipv4/tcp_ipv4.c 2017-01-28 13:59:10.107662951 +0100
  21749. @@ -62,6 +62,7 @@
  21750. #include <linux/init.h>
  21751. #include <linux/times.h>
  21752. #include <linux/slab.h>
  21753. +#include <linux/locallock.h>
  21754. #include <net/net_namespace.h>
  21755. #include <net/icmp.h>
  21756. @@ -564,6 +565,7 @@
  21757. }
  21758. EXPORT_SYMBOL(tcp_v4_send_check);
  21759. +static DEFINE_LOCAL_IRQ_LOCK(tcp_sk_lock);
  21760. /*
  21761. * This routine will send an RST to the other tcp.
  21762. *
  21763. @@ -691,6 +693,8 @@
  21764. offsetof(struct inet_timewait_sock, tw_bound_dev_if));
  21765. arg.tos = ip_hdr(skb)->tos;
  21766. +
  21767. + local_lock(tcp_sk_lock);
  21768. local_bh_disable();
  21769. ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
  21770. skb, &TCP_SKB_CB(skb)->header.h4.opt,
  21771. @@ -700,6 +704,7 @@
  21772. __TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
  21773. __TCP_INC_STATS(net, TCP_MIB_OUTRSTS);
  21774. local_bh_enable();
  21775. + local_unlock(tcp_sk_lock);
  21776. #ifdef CONFIG_TCP_MD5SIG
  21777. out:
  21778. @@ -775,6 +780,7 @@
  21779. if (oif)
  21780. arg.bound_dev_if = oif;
  21781. arg.tos = tos;
  21782. + local_lock(tcp_sk_lock);
  21783. local_bh_disable();
  21784. ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
  21785. skb, &TCP_SKB_CB(skb)->header.h4.opt,
  21786. @@ -783,6 +789,7 @@
  21787. __TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
  21788. local_bh_enable();
  21789. + local_unlock(tcp_sk_lock);
  21790. }
  21791. static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
  21792. diff -Nur linux-4.9.6.orig/net/mac80211/rx.c linux-4.9.6/net/mac80211/rx.c
  21793. --- linux-4.9.6.orig/net/mac80211/rx.c 2017-01-26 08:25:24.000000000 +0100
  21794. +++ linux-4.9.6/net/mac80211/rx.c 2017-01-28 13:59:10.107662951 +0100
  21795. @@ -4166,7 +4166,7 @@
  21796. struct ieee80211_supported_band *sband;
  21797. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  21798. - WARN_ON_ONCE(softirq_count() == 0);
  21799. + WARN_ON_ONCE_NONRT(softirq_count() == 0);
  21800. if (WARN_ON(status->band >= NUM_NL80211_BANDS))
  21801. goto drop;
  21802. diff -Nur linux-4.9.6.orig/net/netfilter/core.c linux-4.9.6/net/netfilter/core.c
  21803. --- linux-4.9.6.orig/net/netfilter/core.c 2017-01-26 08:25:24.000000000 +0100
  21804. +++ linux-4.9.6/net/netfilter/core.c 2017-01-28 13:59:10.107662951 +0100
  21805. @@ -22,12 +22,18 @@
  21806. #include <linux/proc_fs.h>
  21807. #include <linux/mutex.h>
  21808. #include <linux/slab.h>
  21809. +#include <linux/locallock.h>
  21810. #include <linux/rcupdate.h>
  21811. #include <net/net_namespace.h>
  21812. #include <net/sock.h>
  21813. #include "nf_internals.h"
  21814. +#ifdef CONFIG_PREEMPT_RT_BASE
  21815. +DEFINE_LOCAL_IRQ_LOCK(xt_write_lock);
  21816. +EXPORT_PER_CPU_SYMBOL(xt_write_lock);
  21817. +#endif
  21818. +
  21819. static DEFINE_MUTEX(afinfo_mutex);
  21820. const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly;
  21821. diff -Nur linux-4.9.6.orig/net/packet/af_packet.c linux-4.9.6/net/packet/af_packet.c
  21822. --- linux-4.9.6.orig/net/packet/af_packet.c 2017-01-26 08:25:24.000000000 +0100
  21823. +++ linux-4.9.6/net/packet/af_packet.c 2017-01-28 13:59:10.111663104 +0100
  21824. @@ -63,6 +63,7 @@
  21825. #include <linux/if_packet.h>
  21826. #include <linux/wireless.h>
  21827. #include <linux/kernel.h>
  21828. +#include <linux/delay.h>
  21829. #include <linux/kmod.h>
  21830. #include <linux/slab.h>
  21831. #include <linux/vmalloc.h>
  21832. @@ -694,7 +695,7 @@
  21833. if (BLOCK_NUM_PKTS(pbd)) {
  21834. while (atomic_read(&pkc->blk_fill_in_prog)) {
  21835. /* Waiting for skb_copy_bits to finish... */
  21836. - cpu_relax();
  21837. + cpu_chill();
  21838. }
  21839. }
  21840. @@ -956,7 +957,7 @@
  21841. if (!(status & TP_STATUS_BLK_TMO)) {
  21842. while (atomic_read(&pkc->blk_fill_in_prog)) {
  21843. /* Waiting for skb_copy_bits to finish... */
  21844. - cpu_relax();
  21845. + cpu_chill();
  21846. }
  21847. }
  21848. prb_close_block(pkc, pbd, po, status);
  21849. diff -Nur linux-4.9.6.orig/net/rds/ib_rdma.c linux-4.9.6/net/rds/ib_rdma.c
  21850. --- linux-4.9.6.orig/net/rds/ib_rdma.c 2017-01-26 08:25:24.000000000 +0100
  21851. +++ linux-4.9.6/net/rds/ib_rdma.c 2017-01-28 13:59:10.111663104 +0100
  21852. @@ -34,6 +34,7 @@
  21853. #include <linux/slab.h>
  21854. #include <linux/rculist.h>
  21855. #include <linux/llist.h>
  21856. +#include <linux/delay.h>
  21857. #include "rds_single_path.h"
  21858. #include "ib_mr.h"
  21859. @@ -210,7 +211,7 @@
  21860. for_each_online_cpu(cpu) {
  21861. flag = &per_cpu(clean_list_grace, cpu);
  21862. while (test_bit(CLEAN_LIST_BUSY_BIT, flag))
  21863. - cpu_relax();
  21864. + cpu_chill();
  21865. }
  21866. }
  21867. diff -Nur linux-4.9.6.orig/net/rxrpc/security.c linux-4.9.6/net/rxrpc/security.c
  21868. --- linux-4.9.6.orig/net/rxrpc/security.c 2017-01-26 08:25:24.000000000 +0100
  21869. +++ linux-4.9.6/net/rxrpc/security.c 2017-01-28 13:59:10.111663104 +0100
  21870. @@ -19,9 +19,6 @@
  21871. #include <keys/rxrpc-type.h>
  21872. #include "ar-internal.h"
  21873. -static LIST_HEAD(rxrpc_security_methods);
  21874. -static DECLARE_RWSEM(rxrpc_security_sem);
  21875. -
  21876. static const struct rxrpc_security *rxrpc_security_types[] = {
  21877. [RXRPC_SECURITY_NONE] = &rxrpc_no_security,
  21878. #ifdef CONFIG_RXKAD
  21879. diff -Nur linux-4.9.6.orig/net/sched/sch_api.c linux-4.9.6/net/sched/sch_api.c
  21880. --- linux-4.9.6.orig/net/sched/sch_api.c 2017-01-26 08:25:24.000000000 +0100
  21881. +++ linux-4.9.6/net/sched/sch_api.c 2017-01-28 13:59:10.111663104 +0100
  21882. @@ -981,7 +981,7 @@
  21883. rcu_assign_pointer(sch->stab, stab);
  21884. }
  21885. if (tca[TCA_RATE]) {
  21886. - seqcount_t *running;
  21887. + net_seqlock_t *running;
  21888. err = -EOPNOTSUPP;
  21889. if (sch->flags & TCQ_F_MQROOT)
  21890. diff -Nur linux-4.9.6.orig/net/sched/sch_generic.c linux-4.9.6/net/sched/sch_generic.c
  21891. --- linux-4.9.6.orig/net/sched/sch_generic.c 2017-01-26 08:25:24.000000000 +0100
  21892. +++ linux-4.9.6/net/sched/sch_generic.c 2017-01-28 13:59:10.111663104 +0100
  21893. @@ -425,7 +425,11 @@
  21894. .ops = &noop_qdisc_ops,
  21895. .q.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
  21896. .dev_queue = &noop_netdev_queue,
  21897. +#ifdef CONFIG_PREEMPT_RT_BASE
  21898. + .running = __SEQLOCK_UNLOCKED(noop_qdisc.running),
  21899. +#else
  21900. .running = SEQCNT_ZERO(noop_qdisc.running),
  21901. +#endif
  21902. .busylock = __SPIN_LOCK_UNLOCKED(noop_qdisc.busylock),
  21903. };
  21904. EXPORT_SYMBOL(noop_qdisc);
  21905. @@ -624,9 +628,17 @@
  21906. lockdep_set_class(&sch->busylock,
  21907. dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
  21908. +#ifdef CONFIG_PREEMPT_RT_BASE
  21909. + seqlock_init(&sch->running);
  21910. + lockdep_set_class(&sch->running.seqcount,
  21911. + dev->qdisc_running_key ?: &qdisc_running_key);
  21912. + lockdep_set_class(&sch->running.lock,
  21913. + dev->qdisc_running_key ?: &qdisc_running_key);
  21914. +#else
  21915. seqcount_init(&sch->running);
  21916. lockdep_set_class(&sch->running,
  21917. dev->qdisc_running_key ?: &qdisc_running_key);
  21918. +#endif
  21919. sch->ops = ops;
  21920. sch->enqueue = ops->enqueue;
  21921. @@ -925,7 +937,7 @@
  21922. /* Wait for outstanding qdisc_run calls. */
  21923. list_for_each_entry(dev, head, close_list)
  21924. while (some_qdisc_is_busy(dev))
  21925. - yield();
  21926. + msleep(1);
  21927. }
  21928. void dev_deactivate(struct net_device *dev)
  21929. diff -Nur linux-4.9.6.orig/net/sunrpc/svc_xprt.c linux-4.9.6/net/sunrpc/svc_xprt.c
  21930. --- linux-4.9.6.orig/net/sunrpc/svc_xprt.c 2017-01-26 08:25:24.000000000 +0100
  21931. +++ linux-4.9.6/net/sunrpc/svc_xprt.c 2017-01-28 13:59:10.111663104 +0100
  21932. @@ -396,7 +396,7 @@
  21933. goto out;
  21934. }
  21935. - cpu = get_cpu();
  21936. + cpu = get_cpu_light();
  21937. pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
  21938. atomic_long_inc(&pool->sp_stats.packets);
  21939. @@ -432,7 +432,7 @@
  21940. atomic_long_inc(&pool->sp_stats.threads_woken);
  21941. wake_up_process(rqstp->rq_task);
  21942. - put_cpu();
  21943. + put_cpu_light();
  21944. goto out;
  21945. }
  21946. rcu_read_unlock();
  21947. @@ -453,7 +453,7 @@
  21948. goto redo_search;
  21949. }
  21950. rqstp = NULL;
  21951. - put_cpu();
  21952. + put_cpu_light();
  21953. out:
  21954. trace_svc_xprt_do_enqueue(xprt, rqstp);
  21955. }
  21956. diff -Nur linux-4.9.6.orig/scripts/mkcompile_h linux-4.9.6/scripts/mkcompile_h
  21957. --- linux-4.9.6.orig/scripts/mkcompile_h 2017-01-26 08:25:24.000000000 +0100
  21958. +++ linux-4.9.6/scripts/mkcompile_h 2017-01-28 13:59:10.111663104 +0100
  21959. @@ -4,7 +4,8 @@
  21960. ARCH=$2
  21961. SMP=$3
  21962. PREEMPT=$4
  21963. -CC=$5
  21964. +RT=$5
  21965. +CC=$6
  21966. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  21967. @@ -57,6 +58,7 @@
  21968. CONFIG_FLAGS=""
  21969. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  21970. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  21971. +if [ -n "$RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS RT"; fi
  21972. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  21973. # Truncate to maximum length
  21974. diff -Nur linux-4.9.6.orig/sound/core/pcm_native.c linux-4.9.6/sound/core/pcm_native.c
  21975. --- linux-4.9.6.orig/sound/core/pcm_native.c 2017-01-26 08:25:24.000000000 +0100
  21976. +++ linux-4.9.6/sound/core/pcm_native.c 2017-01-28 13:59:10.111663104 +0100
  21977. @@ -135,7 +135,7 @@
  21978. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  21979. {
  21980. if (!substream->pcm->nonatomic)
  21981. - local_irq_disable();
  21982. + local_irq_disable_nort();
  21983. snd_pcm_stream_lock(substream);
  21984. }
  21985. EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
  21986. @@ -150,7 +150,7 @@
  21987. {
  21988. snd_pcm_stream_unlock(substream);
  21989. if (!substream->pcm->nonatomic)
  21990. - local_irq_enable();
  21991. + local_irq_enable_nort();
  21992. }
  21993. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq);
  21994. @@ -158,7 +158,7 @@
  21995. {
  21996. unsigned long flags = 0;
  21997. if (!substream->pcm->nonatomic)
  21998. - local_irq_save(flags);
  21999. + local_irq_save_nort(flags);
  22000. snd_pcm_stream_lock(substream);
  22001. return flags;
  22002. }
  22003. @@ -176,7 +176,7 @@
  22004. {
  22005. snd_pcm_stream_unlock(substream);
  22006. if (!substream->pcm->nonatomic)
  22007. - local_irq_restore(flags);
  22008. + local_irq_restore_nort(flags);
  22009. }
  22010. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore);