ptrace.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/m68k/kernel/ptrace.c"
  6. * Copyright (C) 1994 by Hamish Macdonald
  7. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  8. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  9. *
  10. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  11. * and Paul Mackerras (paulus@samba.org).
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file README.legal in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/regset.h>
  24. #include <linux/tracehook.h>
  25. #include <linux/elf.h>
  26. #include <linux/user.h>
  27. #include <linux/security.h>
  28. #include <linux/signal.h>
  29. #include <linux/seccomp.h>
  30. #include <linux/audit.h>
  31. #include <trace/syscall.h>
  32. #include <linux/hw_breakpoint.h>
  33. #include <linux/perf_event.h>
  34. #include <linux/context_tracking.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/pkeys.h>
  37. #include <asm/page.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/switch_to.h>
  40. #include <asm/tm.h>
  41. #include <asm/asm-prototypes.h>
  42. #include <asm/debug.h>
  43. #define CREATE_TRACE_POINTS
  44. #include <trace/events/syscalls.h>
  45. /*
  46. * The parameter save area on the stack is used to store arguments being passed
  47. * to callee function and is located at fixed offset from stack pointer.
  48. */
  49. #ifdef CONFIG_PPC32
  50. #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
  51. #else /* CONFIG_PPC32 */
  52. #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
  53. #endif
  54. struct pt_regs_offset {
  55. const char *name;
  56. int offset;
  57. };
  58. #define STR(s) #s /* convert to string */
  59. #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
  60. #define GPR_OFFSET_NAME(num) \
  61. {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
  62. {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
  63. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  64. #define TVSO(f) (offsetof(struct thread_vr_state, f))
  65. #define TFSO(f) (offsetof(struct thread_fp_state, f))
  66. #define TSO(f) (offsetof(struct thread_struct, f))
  67. static const struct pt_regs_offset regoffset_table[] = {
  68. GPR_OFFSET_NAME(0),
  69. GPR_OFFSET_NAME(1),
  70. GPR_OFFSET_NAME(2),
  71. GPR_OFFSET_NAME(3),
  72. GPR_OFFSET_NAME(4),
  73. GPR_OFFSET_NAME(5),
  74. GPR_OFFSET_NAME(6),
  75. GPR_OFFSET_NAME(7),
  76. GPR_OFFSET_NAME(8),
  77. GPR_OFFSET_NAME(9),
  78. GPR_OFFSET_NAME(10),
  79. GPR_OFFSET_NAME(11),
  80. GPR_OFFSET_NAME(12),
  81. GPR_OFFSET_NAME(13),
  82. GPR_OFFSET_NAME(14),
  83. GPR_OFFSET_NAME(15),
  84. GPR_OFFSET_NAME(16),
  85. GPR_OFFSET_NAME(17),
  86. GPR_OFFSET_NAME(18),
  87. GPR_OFFSET_NAME(19),
  88. GPR_OFFSET_NAME(20),
  89. GPR_OFFSET_NAME(21),
  90. GPR_OFFSET_NAME(22),
  91. GPR_OFFSET_NAME(23),
  92. GPR_OFFSET_NAME(24),
  93. GPR_OFFSET_NAME(25),
  94. GPR_OFFSET_NAME(26),
  95. GPR_OFFSET_NAME(27),
  96. GPR_OFFSET_NAME(28),
  97. GPR_OFFSET_NAME(29),
  98. GPR_OFFSET_NAME(30),
  99. GPR_OFFSET_NAME(31),
  100. REG_OFFSET_NAME(nip),
  101. REG_OFFSET_NAME(msr),
  102. REG_OFFSET_NAME(ctr),
  103. REG_OFFSET_NAME(link),
  104. REG_OFFSET_NAME(xer),
  105. REG_OFFSET_NAME(ccr),
  106. #ifdef CONFIG_PPC64
  107. REG_OFFSET_NAME(softe),
  108. #else
  109. REG_OFFSET_NAME(mq),
  110. #endif
  111. REG_OFFSET_NAME(trap),
  112. REG_OFFSET_NAME(dar),
  113. REG_OFFSET_NAME(dsisr),
  114. REG_OFFSET_END,
  115. };
  116. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  117. static void flush_tmregs_to_thread(struct task_struct *tsk)
  118. {
  119. /*
  120. * If task is not current, it will have been flushed already to
  121. * it's thread_struct during __switch_to().
  122. *
  123. * A reclaim flushes ALL the state or if not in TM save TM SPRs
  124. * in the appropriate thread structures from live.
  125. */
  126. if ((!cpu_has_feature(CPU_FTR_TM)) || (tsk != current))
  127. return;
  128. if (MSR_TM_SUSPENDED(mfmsr())) {
  129. tm_reclaim_current(TM_CAUSE_SIGNAL);
  130. } else {
  131. tm_enable();
  132. tm_save_sprs(&(tsk->thread));
  133. }
  134. }
  135. #else
  136. static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
  137. #endif
  138. /**
  139. * regs_query_register_offset() - query register offset from its name
  140. * @name: the name of a register
  141. *
  142. * regs_query_register_offset() returns the offset of a register in struct
  143. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  144. */
  145. int regs_query_register_offset(const char *name)
  146. {
  147. const struct pt_regs_offset *roff;
  148. for (roff = regoffset_table; roff->name != NULL; roff++)
  149. if (!strcmp(roff->name, name))
  150. return roff->offset;
  151. return -EINVAL;
  152. }
  153. /**
  154. * regs_query_register_name() - query register name from its offset
  155. * @offset: the offset of a register in struct pt_regs.
  156. *
  157. * regs_query_register_name() returns the name of a register from its
  158. * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
  159. */
  160. const char *regs_query_register_name(unsigned int offset)
  161. {
  162. const struct pt_regs_offset *roff;
  163. for (roff = regoffset_table; roff->name != NULL; roff++)
  164. if (roff->offset == offset)
  165. return roff->name;
  166. return NULL;
  167. }
  168. /*
  169. * does not yet catch signals sent when the child dies.
  170. * in exit.c or in signal.c.
  171. */
  172. /*
  173. * Set of msr bits that gdb can change on behalf of a process.
  174. */
  175. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  176. #define MSR_DEBUGCHANGE 0
  177. #else
  178. #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
  179. #endif
  180. /*
  181. * Max register writeable via put_reg
  182. */
  183. #ifdef CONFIG_PPC32
  184. #define PT_MAX_PUT_REG PT_MQ
  185. #else
  186. #define PT_MAX_PUT_REG PT_CCR
  187. #endif
  188. static unsigned long get_user_msr(struct task_struct *task)
  189. {
  190. return task->thread.regs->msr | task->thread.fpexc_mode;
  191. }
  192. static int set_user_msr(struct task_struct *task, unsigned long msr)
  193. {
  194. task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
  195. task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
  196. return 0;
  197. }
  198. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  199. static unsigned long get_user_ckpt_msr(struct task_struct *task)
  200. {
  201. return task->thread.ckpt_regs.msr | task->thread.fpexc_mode;
  202. }
  203. static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr)
  204. {
  205. task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE;
  206. task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE;
  207. return 0;
  208. }
  209. static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap)
  210. {
  211. task->thread.ckpt_regs.trap = trap & 0xfff0;
  212. return 0;
  213. }
  214. #endif
  215. #ifdef CONFIG_PPC64
  216. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  217. {
  218. *data = task->thread.dscr;
  219. return 0;
  220. }
  221. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  222. {
  223. task->thread.dscr = dscr;
  224. task->thread.dscr_inherit = 1;
  225. return 0;
  226. }
  227. #else
  228. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  229. {
  230. return -EIO;
  231. }
  232. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  233. {
  234. return -EIO;
  235. }
  236. #endif
  237. /*
  238. * We prevent mucking around with the reserved area of trap
  239. * which are used internally by the kernel.
  240. */
  241. static int set_user_trap(struct task_struct *task, unsigned long trap)
  242. {
  243. task->thread.regs->trap = trap & 0xfff0;
  244. return 0;
  245. }
  246. /*
  247. * Get contents of register REGNO in task TASK.
  248. */
  249. int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)
  250. {
  251. if ((task->thread.regs == NULL) || !data)
  252. return -EIO;
  253. if (regno == PT_MSR) {
  254. *data = get_user_msr(task);
  255. return 0;
  256. }
  257. if (regno == PT_DSCR)
  258. return get_user_dscr(task, data);
  259. #ifdef CONFIG_PPC64
  260. /*
  261. * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask is
  262. * no more used as a flag, lets force usr to alway see the softe value as 1
  263. * which means interrupts are not soft disabled.
  264. */
  265. if (regno == PT_SOFTE) {
  266. *data = 1;
  267. return 0;
  268. }
  269. #endif
  270. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) {
  271. *data = ((unsigned long *)task->thread.regs)[regno];
  272. return 0;
  273. }
  274. return -EIO;
  275. }
  276. /*
  277. * Write contents of register REGNO in task TASK.
  278. */
  279. int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
  280. {
  281. if (task->thread.regs == NULL)
  282. return -EIO;
  283. if (regno == PT_MSR)
  284. return set_user_msr(task, data);
  285. if (regno == PT_TRAP)
  286. return set_user_trap(task, data);
  287. if (regno == PT_DSCR)
  288. return set_user_dscr(task, data);
  289. if (regno <= PT_MAX_PUT_REG) {
  290. ((unsigned long *)task->thread.regs)[regno] = data;
  291. return 0;
  292. }
  293. return -EIO;
  294. }
  295. static int gpr_get(struct task_struct *target, const struct user_regset *regset,
  296. unsigned int pos, unsigned int count,
  297. void *kbuf, void __user *ubuf)
  298. {
  299. int i, ret;
  300. if (target->thread.regs == NULL)
  301. return -EIO;
  302. if (!FULL_REGS(target->thread.regs)) {
  303. /* We have a partial register set. Fill 14-31 with bogus values */
  304. for (i = 14; i < 32; i++)
  305. target->thread.regs->gpr[i] = NV_REG_POISON;
  306. }
  307. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  308. target->thread.regs,
  309. 0, offsetof(struct pt_regs, msr));
  310. if (!ret) {
  311. unsigned long msr = get_user_msr(target);
  312. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  313. offsetof(struct pt_regs, msr),
  314. offsetof(struct pt_regs, msr) +
  315. sizeof(msr));
  316. }
  317. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  318. offsetof(struct pt_regs, msr) + sizeof(long));
  319. if (!ret)
  320. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  321. &target->thread.regs->orig_gpr3,
  322. offsetof(struct pt_regs, orig_gpr3),
  323. sizeof(struct pt_regs));
  324. if (!ret)
  325. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  326. sizeof(struct pt_regs), -1);
  327. return ret;
  328. }
  329. static int gpr_set(struct task_struct *target, const struct user_regset *regset,
  330. unsigned int pos, unsigned int count,
  331. const void *kbuf, const void __user *ubuf)
  332. {
  333. unsigned long reg;
  334. int ret;
  335. if (target->thread.regs == NULL)
  336. return -EIO;
  337. CHECK_FULL_REGS(target->thread.regs);
  338. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  339. target->thread.regs,
  340. 0, PT_MSR * sizeof(reg));
  341. if (!ret && count > 0) {
  342. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  343. PT_MSR * sizeof(reg),
  344. (PT_MSR + 1) * sizeof(reg));
  345. if (!ret)
  346. ret = set_user_msr(target, reg);
  347. }
  348. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  349. offsetof(struct pt_regs, msr) + sizeof(long));
  350. if (!ret)
  351. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  352. &target->thread.regs->orig_gpr3,
  353. PT_ORIG_R3 * sizeof(reg),
  354. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  355. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  356. ret = user_regset_copyin_ignore(
  357. &pos, &count, &kbuf, &ubuf,
  358. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  359. PT_TRAP * sizeof(reg));
  360. if (!ret && count > 0) {
  361. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  362. PT_TRAP * sizeof(reg),
  363. (PT_TRAP + 1) * sizeof(reg));
  364. if (!ret)
  365. ret = set_user_trap(target, reg);
  366. }
  367. if (!ret)
  368. ret = user_regset_copyin_ignore(
  369. &pos, &count, &kbuf, &ubuf,
  370. (PT_TRAP + 1) * sizeof(reg), -1);
  371. return ret;
  372. }
  373. /*
  374. * Regardless of transactions, 'fp_state' holds the current running
  375. * value of all FPR registers and 'ckfp_state' holds the last checkpointed
  376. * value of all FPR registers for the current transaction.
  377. *
  378. * Userspace interface buffer layout:
  379. *
  380. * struct data {
  381. * u64 fpr[32];
  382. * u64 fpscr;
  383. * };
  384. */
  385. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  386. unsigned int pos, unsigned int count,
  387. void *kbuf, void __user *ubuf)
  388. {
  389. #ifdef CONFIG_VSX
  390. u64 buf[33];
  391. int i;
  392. flush_fp_to_thread(target);
  393. /* copy to local buffer then write that out */
  394. for (i = 0; i < 32 ; i++)
  395. buf[i] = target->thread.TS_FPR(i);
  396. buf[32] = target->thread.fp_state.fpscr;
  397. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  398. #else
  399. BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
  400. offsetof(struct thread_fp_state, fpr[32]));
  401. flush_fp_to_thread(target);
  402. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  403. &target->thread.fp_state, 0, -1);
  404. #endif
  405. }
  406. /*
  407. * Regardless of transactions, 'fp_state' holds the current running
  408. * value of all FPR registers and 'ckfp_state' holds the last checkpointed
  409. * value of all FPR registers for the current transaction.
  410. *
  411. * Userspace interface buffer layout:
  412. *
  413. * struct data {
  414. * u64 fpr[32];
  415. * u64 fpscr;
  416. * };
  417. *
  418. */
  419. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  420. unsigned int pos, unsigned int count,
  421. const void *kbuf, const void __user *ubuf)
  422. {
  423. #ifdef CONFIG_VSX
  424. u64 buf[33];
  425. int i;
  426. flush_fp_to_thread(target);
  427. for (i = 0; i < 32 ; i++)
  428. buf[i] = target->thread.TS_FPR(i);
  429. buf[32] = target->thread.fp_state.fpscr;
  430. /* copy to local buffer then write that out */
  431. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  432. if (i)
  433. return i;
  434. for (i = 0; i < 32 ; i++)
  435. target->thread.TS_FPR(i) = buf[i];
  436. target->thread.fp_state.fpscr = buf[32];
  437. return 0;
  438. #else
  439. BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
  440. offsetof(struct thread_fp_state, fpr[32]));
  441. flush_fp_to_thread(target);
  442. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  443. &target->thread.fp_state, 0, -1);
  444. #endif
  445. }
  446. #ifdef CONFIG_ALTIVEC
  447. /*
  448. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  449. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  450. * corresponding vector registers. Quadword 32 contains the vscr as the
  451. * last word (offset 12) within that quadword. Quadword 33 contains the
  452. * vrsave as the first word (offset 0) within the quadword.
  453. *
  454. * This definition of the VMX state is compatible with the current PPC32
  455. * ptrace interface. This allows signal handling and ptrace to use the
  456. * same structures. This also simplifies the implementation of a bi-arch
  457. * (combined (32- and 64-bit) gdb.
  458. */
  459. static int vr_active(struct task_struct *target,
  460. const struct user_regset *regset)
  461. {
  462. flush_altivec_to_thread(target);
  463. return target->thread.used_vr ? regset->n : 0;
  464. }
  465. /*
  466. * Regardless of transactions, 'vr_state' holds the current running
  467. * value of all the VMX registers and 'ckvr_state' holds the last
  468. * checkpointed value of all the VMX registers for the current
  469. * transaction to fall back on in case it aborts.
  470. *
  471. * Userspace interface buffer layout:
  472. *
  473. * struct data {
  474. * vector128 vr[32];
  475. * vector128 vscr;
  476. * vector128 vrsave;
  477. * };
  478. */
  479. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  480. unsigned int pos, unsigned int count,
  481. void *kbuf, void __user *ubuf)
  482. {
  483. int ret;
  484. flush_altivec_to_thread(target);
  485. BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
  486. offsetof(struct thread_vr_state, vr[32]));
  487. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  488. &target->thread.vr_state, 0,
  489. 33 * sizeof(vector128));
  490. if (!ret) {
  491. /*
  492. * Copy out only the low-order word of vrsave.
  493. */
  494. int start, end;
  495. union {
  496. elf_vrreg_t reg;
  497. u32 word;
  498. } vrsave;
  499. memset(&vrsave, 0, sizeof(vrsave));
  500. vrsave.word = target->thread.vrsave;
  501. start = 33 * sizeof(vector128);
  502. end = start + sizeof(vrsave);
  503. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  504. start, end);
  505. }
  506. return ret;
  507. }
  508. /*
  509. * Regardless of transactions, 'vr_state' holds the current running
  510. * value of all the VMX registers and 'ckvr_state' holds the last
  511. * checkpointed value of all the VMX registers for the current
  512. * transaction to fall back on in case it aborts.
  513. *
  514. * Userspace interface buffer layout:
  515. *
  516. * struct data {
  517. * vector128 vr[32];
  518. * vector128 vscr;
  519. * vector128 vrsave;
  520. * };
  521. */
  522. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  523. unsigned int pos, unsigned int count,
  524. const void *kbuf, const void __user *ubuf)
  525. {
  526. int ret;
  527. flush_altivec_to_thread(target);
  528. BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
  529. offsetof(struct thread_vr_state, vr[32]));
  530. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  531. &target->thread.vr_state, 0,
  532. 33 * sizeof(vector128));
  533. if (!ret && count > 0) {
  534. /*
  535. * We use only the first word of vrsave.
  536. */
  537. int start, end;
  538. union {
  539. elf_vrreg_t reg;
  540. u32 word;
  541. } vrsave;
  542. memset(&vrsave, 0, sizeof(vrsave));
  543. vrsave.word = target->thread.vrsave;
  544. start = 33 * sizeof(vector128);
  545. end = start + sizeof(vrsave);
  546. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  547. start, end);
  548. if (!ret)
  549. target->thread.vrsave = vrsave.word;
  550. }
  551. return ret;
  552. }
  553. #endif /* CONFIG_ALTIVEC */
  554. #ifdef CONFIG_VSX
  555. /*
  556. * Currently to set and and get all the vsx state, you need to call
  557. * the fp and VMX calls as well. This only get/sets the lower 32
  558. * 128bit VSX registers.
  559. */
  560. static int vsr_active(struct task_struct *target,
  561. const struct user_regset *regset)
  562. {
  563. flush_vsx_to_thread(target);
  564. return target->thread.used_vsr ? regset->n : 0;
  565. }
  566. /*
  567. * Regardless of transactions, 'fp_state' holds the current running
  568. * value of all FPR registers and 'ckfp_state' holds the last
  569. * checkpointed value of all FPR registers for the current
  570. * transaction.
  571. *
  572. * Userspace interface buffer layout:
  573. *
  574. * struct data {
  575. * u64 vsx[32];
  576. * };
  577. */
  578. static int vsr_get(struct task_struct *target, const struct user_regset *regset,
  579. unsigned int pos, unsigned int count,
  580. void *kbuf, void __user *ubuf)
  581. {
  582. u64 buf[32];
  583. int ret, i;
  584. flush_tmregs_to_thread(target);
  585. flush_fp_to_thread(target);
  586. flush_altivec_to_thread(target);
  587. flush_vsx_to_thread(target);
  588. for (i = 0; i < 32 ; i++)
  589. buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
  590. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  591. buf, 0, 32 * sizeof(double));
  592. return ret;
  593. }
  594. /*
  595. * Regardless of transactions, 'fp_state' holds the current running
  596. * value of all FPR registers and 'ckfp_state' holds the last
  597. * checkpointed value of all FPR registers for the current
  598. * transaction.
  599. *
  600. * Userspace interface buffer layout:
  601. *
  602. * struct data {
  603. * u64 vsx[32];
  604. * };
  605. */
  606. static int vsr_set(struct task_struct *target, const struct user_regset *regset,
  607. unsigned int pos, unsigned int count,
  608. const void *kbuf, const void __user *ubuf)
  609. {
  610. u64 buf[32];
  611. int ret,i;
  612. flush_tmregs_to_thread(target);
  613. flush_fp_to_thread(target);
  614. flush_altivec_to_thread(target);
  615. flush_vsx_to_thread(target);
  616. for (i = 0; i < 32 ; i++)
  617. buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
  618. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  619. buf, 0, 32 * sizeof(double));
  620. if (!ret)
  621. for (i = 0; i < 32 ; i++)
  622. target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  623. return ret;
  624. }
  625. #endif /* CONFIG_VSX */
  626. #ifdef CONFIG_SPE
  627. /*
  628. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  629. *
  630. * struct {
  631. * u32 evr[32];
  632. * u64 acc;
  633. * u32 spefscr;
  634. * }
  635. */
  636. static int evr_active(struct task_struct *target,
  637. const struct user_regset *regset)
  638. {
  639. flush_spe_to_thread(target);
  640. return target->thread.used_spe ? regset->n : 0;
  641. }
  642. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  643. unsigned int pos, unsigned int count,
  644. void *kbuf, void __user *ubuf)
  645. {
  646. int ret;
  647. flush_spe_to_thread(target);
  648. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  649. &target->thread.evr,
  650. 0, sizeof(target->thread.evr));
  651. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  652. offsetof(struct thread_struct, spefscr));
  653. if (!ret)
  654. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  655. &target->thread.acc,
  656. sizeof(target->thread.evr), -1);
  657. return ret;
  658. }
  659. static int evr_set(struct task_struct *target, const struct user_regset *regset,
  660. unsigned int pos, unsigned int count,
  661. const void *kbuf, const void __user *ubuf)
  662. {
  663. int ret;
  664. flush_spe_to_thread(target);
  665. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  666. &target->thread.evr,
  667. 0, sizeof(target->thread.evr));
  668. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  669. offsetof(struct thread_struct, spefscr));
  670. if (!ret)
  671. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  672. &target->thread.acc,
  673. sizeof(target->thread.evr), -1);
  674. return ret;
  675. }
  676. #endif /* CONFIG_SPE */
  677. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  678. /**
  679. * tm_cgpr_active - get active number of registers in CGPR
  680. * @target: The target task.
  681. * @regset: The user regset structure.
  682. *
  683. * This function checks for the active number of available
  684. * regisers in transaction checkpointed GPR category.
  685. */
  686. static int tm_cgpr_active(struct task_struct *target,
  687. const struct user_regset *regset)
  688. {
  689. if (!cpu_has_feature(CPU_FTR_TM))
  690. return -ENODEV;
  691. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  692. return 0;
  693. return regset->n;
  694. }
  695. /**
  696. * tm_cgpr_get - get CGPR registers
  697. * @target: The target task.
  698. * @regset: The user regset structure.
  699. * @pos: The buffer position.
  700. * @count: Number of bytes to copy.
  701. * @kbuf: Kernel buffer to copy from.
  702. * @ubuf: User buffer to copy into.
  703. *
  704. * This function gets transaction checkpointed GPR registers.
  705. *
  706. * When the transaction is active, 'ckpt_regs' holds all the checkpointed
  707. * GPR register values for the current transaction to fall back on if it
  708. * aborts in between. This function gets those checkpointed GPR registers.
  709. * The userspace interface buffer layout is as follows.
  710. *
  711. * struct data {
  712. * struct pt_regs ckpt_regs;
  713. * };
  714. */
  715. static int tm_cgpr_get(struct task_struct *target,
  716. const struct user_regset *regset,
  717. unsigned int pos, unsigned int count,
  718. void *kbuf, void __user *ubuf)
  719. {
  720. int ret;
  721. if (!cpu_has_feature(CPU_FTR_TM))
  722. return -ENODEV;
  723. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  724. return -ENODATA;
  725. flush_tmregs_to_thread(target);
  726. flush_fp_to_thread(target);
  727. flush_altivec_to_thread(target);
  728. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  729. &target->thread.ckpt_regs,
  730. 0, offsetof(struct pt_regs, msr));
  731. if (!ret) {
  732. unsigned long msr = get_user_ckpt_msr(target);
  733. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  734. offsetof(struct pt_regs, msr),
  735. offsetof(struct pt_regs, msr) +
  736. sizeof(msr));
  737. }
  738. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  739. offsetof(struct pt_regs, msr) + sizeof(long));
  740. if (!ret)
  741. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  742. &target->thread.ckpt_regs.orig_gpr3,
  743. offsetof(struct pt_regs, orig_gpr3),
  744. sizeof(struct pt_regs));
  745. if (!ret)
  746. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  747. sizeof(struct pt_regs), -1);
  748. return ret;
  749. }
  750. /*
  751. * tm_cgpr_set - set the CGPR registers
  752. * @target: The target task.
  753. * @regset: The user regset structure.
  754. * @pos: The buffer position.
  755. * @count: Number of bytes to copy.
  756. * @kbuf: Kernel buffer to copy into.
  757. * @ubuf: User buffer to copy from.
  758. *
  759. * This function sets in transaction checkpointed GPR registers.
  760. *
  761. * When the transaction is active, 'ckpt_regs' holds the checkpointed
  762. * GPR register values for the current transaction to fall back on if it
  763. * aborts in between. This function sets those checkpointed GPR registers.
  764. * The userspace interface buffer layout is as follows.
  765. *
  766. * struct data {
  767. * struct pt_regs ckpt_regs;
  768. * };
  769. */
  770. static int tm_cgpr_set(struct task_struct *target,
  771. const struct user_regset *regset,
  772. unsigned int pos, unsigned int count,
  773. const void *kbuf, const void __user *ubuf)
  774. {
  775. unsigned long reg;
  776. int ret;
  777. if (!cpu_has_feature(CPU_FTR_TM))
  778. return -ENODEV;
  779. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  780. return -ENODATA;
  781. flush_tmregs_to_thread(target);
  782. flush_fp_to_thread(target);
  783. flush_altivec_to_thread(target);
  784. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  785. &target->thread.ckpt_regs,
  786. 0, PT_MSR * sizeof(reg));
  787. if (!ret && count > 0) {
  788. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  789. PT_MSR * sizeof(reg),
  790. (PT_MSR + 1) * sizeof(reg));
  791. if (!ret)
  792. ret = set_user_ckpt_msr(target, reg);
  793. }
  794. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  795. offsetof(struct pt_regs, msr) + sizeof(long));
  796. if (!ret)
  797. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  798. &target->thread.ckpt_regs.orig_gpr3,
  799. PT_ORIG_R3 * sizeof(reg),
  800. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  801. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  802. ret = user_regset_copyin_ignore(
  803. &pos, &count, &kbuf, &ubuf,
  804. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  805. PT_TRAP * sizeof(reg));
  806. if (!ret && count > 0) {
  807. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  808. PT_TRAP * sizeof(reg),
  809. (PT_TRAP + 1) * sizeof(reg));
  810. if (!ret)
  811. ret = set_user_ckpt_trap(target, reg);
  812. }
  813. if (!ret)
  814. ret = user_regset_copyin_ignore(
  815. &pos, &count, &kbuf, &ubuf,
  816. (PT_TRAP + 1) * sizeof(reg), -1);
  817. return ret;
  818. }
  819. /**
  820. * tm_cfpr_active - get active number of registers in CFPR
  821. * @target: The target task.
  822. * @regset: The user regset structure.
  823. *
  824. * This function checks for the active number of available
  825. * regisers in transaction checkpointed FPR category.
  826. */
  827. static int tm_cfpr_active(struct task_struct *target,
  828. const struct user_regset *regset)
  829. {
  830. if (!cpu_has_feature(CPU_FTR_TM))
  831. return -ENODEV;
  832. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  833. return 0;
  834. return regset->n;
  835. }
  836. /**
  837. * tm_cfpr_get - get CFPR registers
  838. * @target: The target task.
  839. * @regset: The user regset structure.
  840. * @pos: The buffer position.
  841. * @count: Number of bytes to copy.
  842. * @kbuf: Kernel buffer to copy from.
  843. * @ubuf: User buffer to copy into.
  844. *
  845. * This function gets in transaction checkpointed FPR registers.
  846. *
  847. * When the transaction is active 'ckfp_state' holds the checkpointed
  848. * values for the current transaction to fall back on if it aborts
  849. * in between. This function gets those checkpointed FPR registers.
  850. * The userspace interface buffer layout is as follows.
  851. *
  852. * struct data {
  853. * u64 fpr[32];
  854. * u64 fpscr;
  855. *};
  856. */
  857. static int tm_cfpr_get(struct task_struct *target,
  858. const struct user_regset *regset,
  859. unsigned int pos, unsigned int count,
  860. void *kbuf, void __user *ubuf)
  861. {
  862. u64 buf[33];
  863. int i;
  864. if (!cpu_has_feature(CPU_FTR_TM))
  865. return -ENODEV;
  866. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  867. return -ENODATA;
  868. flush_tmregs_to_thread(target);
  869. flush_fp_to_thread(target);
  870. flush_altivec_to_thread(target);
  871. /* copy to local buffer then write that out */
  872. for (i = 0; i < 32 ; i++)
  873. buf[i] = target->thread.TS_CKFPR(i);
  874. buf[32] = target->thread.ckfp_state.fpscr;
  875. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  876. }
  877. /**
  878. * tm_cfpr_set - set CFPR registers
  879. * @target: The target task.
  880. * @regset: The user regset structure.
  881. * @pos: The buffer position.
  882. * @count: Number of bytes to copy.
  883. * @kbuf: Kernel buffer to copy into.
  884. * @ubuf: User buffer to copy from.
  885. *
  886. * This function sets in transaction checkpointed FPR registers.
  887. *
  888. * When the transaction is active 'ckfp_state' holds the checkpointed
  889. * FPR register values for the current transaction to fall back on
  890. * if it aborts in between. This function sets these checkpointed
  891. * FPR registers. The userspace interface buffer layout is as follows.
  892. *
  893. * struct data {
  894. * u64 fpr[32];
  895. * u64 fpscr;
  896. *};
  897. */
  898. static int tm_cfpr_set(struct task_struct *target,
  899. const struct user_regset *regset,
  900. unsigned int pos, unsigned int count,
  901. const void *kbuf, const void __user *ubuf)
  902. {
  903. u64 buf[33];
  904. int i;
  905. if (!cpu_has_feature(CPU_FTR_TM))
  906. return -ENODEV;
  907. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  908. return -ENODATA;
  909. flush_tmregs_to_thread(target);
  910. flush_fp_to_thread(target);
  911. flush_altivec_to_thread(target);
  912. for (i = 0; i < 32; i++)
  913. buf[i] = target->thread.TS_CKFPR(i);
  914. buf[32] = target->thread.ckfp_state.fpscr;
  915. /* copy to local buffer then write that out */
  916. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  917. if (i)
  918. return i;
  919. for (i = 0; i < 32 ; i++)
  920. target->thread.TS_CKFPR(i) = buf[i];
  921. target->thread.ckfp_state.fpscr = buf[32];
  922. return 0;
  923. }
  924. /**
  925. * tm_cvmx_active - get active number of registers in CVMX
  926. * @target: The target task.
  927. * @regset: The user regset structure.
  928. *
  929. * This function checks for the active number of available
  930. * regisers in checkpointed VMX category.
  931. */
  932. static int tm_cvmx_active(struct task_struct *target,
  933. const struct user_regset *regset)
  934. {
  935. if (!cpu_has_feature(CPU_FTR_TM))
  936. return -ENODEV;
  937. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  938. return 0;
  939. return regset->n;
  940. }
  941. /**
  942. * tm_cvmx_get - get CMVX registers
  943. * @target: The target task.
  944. * @regset: The user regset structure.
  945. * @pos: The buffer position.
  946. * @count: Number of bytes to copy.
  947. * @kbuf: Kernel buffer to copy from.
  948. * @ubuf: User buffer to copy into.
  949. *
  950. * This function gets in transaction checkpointed VMX registers.
  951. *
  952. * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
  953. * the checkpointed values for the current transaction to fall
  954. * back on if it aborts in between. The userspace interface buffer
  955. * layout is as follows.
  956. *
  957. * struct data {
  958. * vector128 vr[32];
  959. * vector128 vscr;
  960. * vector128 vrsave;
  961. *};
  962. */
  963. static int tm_cvmx_get(struct task_struct *target,
  964. const struct user_regset *regset,
  965. unsigned int pos, unsigned int count,
  966. void *kbuf, void __user *ubuf)
  967. {
  968. int ret;
  969. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  970. if (!cpu_has_feature(CPU_FTR_TM))
  971. return -ENODEV;
  972. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  973. return -ENODATA;
  974. /* Flush the state */
  975. flush_tmregs_to_thread(target);
  976. flush_fp_to_thread(target);
  977. flush_altivec_to_thread(target);
  978. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  979. &target->thread.ckvr_state, 0,
  980. 33 * sizeof(vector128));
  981. if (!ret) {
  982. /*
  983. * Copy out only the low-order word of vrsave.
  984. */
  985. union {
  986. elf_vrreg_t reg;
  987. u32 word;
  988. } vrsave;
  989. memset(&vrsave, 0, sizeof(vrsave));
  990. vrsave.word = target->thread.ckvrsave;
  991. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  992. 33 * sizeof(vector128), -1);
  993. }
  994. return ret;
  995. }
  996. /**
  997. * tm_cvmx_set - set CMVX registers
  998. * @target: The target task.
  999. * @regset: The user regset structure.
  1000. * @pos: The buffer position.
  1001. * @count: Number of bytes to copy.
  1002. * @kbuf: Kernel buffer to copy into.
  1003. * @ubuf: User buffer to copy from.
  1004. *
  1005. * This function sets in transaction checkpointed VMX registers.
  1006. *
  1007. * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
  1008. * the checkpointed values for the current transaction to fall
  1009. * back on if it aborts in between. The userspace interface buffer
  1010. * layout is as follows.
  1011. *
  1012. * struct data {
  1013. * vector128 vr[32];
  1014. * vector128 vscr;
  1015. * vector128 vrsave;
  1016. *};
  1017. */
  1018. static int tm_cvmx_set(struct task_struct *target,
  1019. const struct user_regset *regset,
  1020. unsigned int pos, unsigned int count,
  1021. const void *kbuf, const void __user *ubuf)
  1022. {
  1023. int ret;
  1024. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  1025. if (!cpu_has_feature(CPU_FTR_TM))
  1026. return -ENODEV;
  1027. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1028. return -ENODATA;
  1029. flush_tmregs_to_thread(target);
  1030. flush_fp_to_thread(target);
  1031. flush_altivec_to_thread(target);
  1032. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1033. &target->thread.ckvr_state, 0,
  1034. 33 * sizeof(vector128));
  1035. if (!ret && count > 0) {
  1036. /*
  1037. * We use only the low-order word of vrsave.
  1038. */
  1039. union {
  1040. elf_vrreg_t reg;
  1041. u32 word;
  1042. } vrsave;
  1043. memset(&vrsave, 0, sizeof(vrsave));
  1044. vrsave.word = target->thread.ckvrsave;
  1045. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  1046. 33 * sizeof(vector128), -1);
  1047. if (!ret)
  1048. target->thread.ckvrsave = vrsave.word;
  1049. }
  1050. return ret;
  1051. }
  1052. /**
  1053. * tm_cvsx_active - get active number of registers in CVSX
  1054. * @target: The target task.
  1055. * @regset: The user regset structure.
  1056. *
  1057. * This function checks for the active number of available
  1058. * regisers in transaction checkpointed VSX category.
  1059. */
  1060. static int tm_cvsx_active(struct task_struct *target,
  1061. const struct user_regset *regset)
  1062. {
  1063. if (!cpu_has_feature(CPU_FTR_TM))
  1064. return -ENODEV;
  1065. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1066. return 0;
  1067. flush_vsx_to_thread(target);
  1068. return target->thread.used_vsr ? regset->n : 0;
  1069. }
  1070. /**
  1071. * tm_cvsx_get - get CVSX registers
  1072. * @target: The target task.
  1073. * @regset: The user regset structure.
  1074. * @pos: The buffer position.
  1075. * @count: Number of bytes to copy.
  1076. * @kbuf: Kernel buffer to copy from.
  1077. * @ubuf: User buffer to copy into.
  1078. *
  1079. * This function gets in transaction checkpointed VSX registers.
  1080. *
  1081. * When the transaction is active 'ckfp_state' holds the checkpointed
  1082. * values for the current transaction to fall back on if it aborts
  1083. * in between. This function gets those checkpointed VSX registers.
  1084. * The userspace interface buffer layout is as follows.
  1085. *
  1086. * struct data {
  1087. * u64 vsx[32];
  1088. *};
  1089. */
  1090. static int tm_cvsx_get(struct task_struct *target,
  1091. const struct user_regset *regset,
  1092. unsigned int pos, unsigned int count,
  1093. void *kbuf, void __user *ubuf)
  1094. {
  1095. u64 buf[32];
  1096. int ret, i;
  1097. if (!cpu_has_feature(CPU_FTR_TM))
  1098. return -ENODEV;
  1099. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1100. return -ENODATA;
  1101. /* Flush the state */
  1102. flush_tmregs_to_thread(target);
  1103. flush_fp_to_thread(target);
  1104. flush_altivec_to_thread(target);
  1105. flush_vsx_to_thread(target);
  1106. for (i = 0; i < 32 ; i++)
  1107. buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
  1108. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1109. buf, 0, 32 * sizeof(double));
  1110. return ret;
  1111. }
  1112. /**
  1113. * tm_cvsx_set - set CFPR registers
  1114. * @target: The target task.
  1115. * @regset: The user regset structure.
  1116. * @pos: The buffer position.
  1117. * @count: Number of bytes to copy.
  1118. * @kbuf: Kernel buffer to copy into.
  1119. * @ubuf: User buffer to copy from.
  1120. *
  1121. * This function sets in transaction checkpointed VSX registers.
  1122. *
  1123. * When the transaction is active 'ckfp_state' holds the checkpointed
  1124. * VSX register values for the current transaction to fall back on
  1125. * if it aborts in between. This function sets these checkpointed
  1126. * FPR registers. The userspace interface buffer layout is as follows.
  1127. *
  1128. * struct data {
  1129. * u64 vsx[32];
  1130. *};
  1131. */
  1132. static int tm_cvsx_set(struct task_struct *target,
  1133. const struct user_regset *regset,
  1134. unsigned int pos, unsigned int count,
  1135. const void *kbuf, const void __user *ubuf)
  1136. {
  1137. u64 buf[32];
  1138. int ret, i;
  1139. if (!cpu_has_feature(CPU_FTR_TM))
  1140. return -ENODEV;
  1141. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1142. return -ENODATA;
  1143. /* Flush the state */
  1144. flush_tmregs_to_thread(target);
  1145. flush_fp_to_thread(target);
  1146. flush_altivec_to_thread(target);
  1147. flush_vsx_to_thread(target);
  1148. for (i = 0; i < 32 ; i++)
  1149. buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
  1150. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1151. buf, 0, 32 * sizeof(double));
  1152. if (!ret)
  1153. for (i = 0; i < 32 ; i++)
  1154. target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  1155. return ret;
  1156. }
  1157. /**
  1158. * tm_spr_active - get active number of registers in TM SPR
  1159. * @target: The target task.
  1160. * @regset: The user regset structure.
  1161. *
  1162. * This function checks the active number of available
  1163. * regisers in the transactional memory SPR category.
  1164. */
  1165. static int tm_spr_active(struct task_struct *target,
  1166. const struct user_regset *regset)
  1167. {
  1168. if (!cpu_has_feature(CPU_FTR_TM))
  1169. return -ENODEV;
  1170. return regset->n;
  1171. }
  1172. /**
  1173. * tm_spr_get - get the TM related SPR registers
  1174. * @target: The target task.
  1175. * @regset: The user regset structure.
  1176. * @pos: The buffer position.
  1177. * @count: Number of bytes to copy.
  1178. * @kbuf: Kernel buffer to copy from.
  1179. * @ubuf: User buffer to copy into.
  1180. *
  1181. * This function gets transactional memory related SPR registers.
  1182. * The userspace interface buffer layout is as follows.
  1183. *
  1184. * struct {
  1185. * u64 tm_tfhar;
  1186. * u64 tm_texasr;
  1187. * u64 tm_tfiar;
  1188. * };
  1189. */
  1190. static int tm_spr_get(struct task_struct *target,
  1191. const struct user_regset *regset,
  1192. unsigned int pos, unsigned int count,
  1193. void *kbuf, void __user *ubuf)
  1194. {
  1195. int ret;
  1196. /* Build tests */
  1197. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  1198. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  1199. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  1200. if (!cpu_has_feature(CPU_FTR_TM))
  1201. return -ENODEV;
  1202. /* Flush the states */
  1203. flush_tmregs_to_thread(target);
  1204. flush_fp_to_thread(target);
  1205. flush_altivec_to_thread(target);
  1206. /* TFHAR register */
  1207. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1208. &target->thread.tm_tfhar, 0, sizeof(u64));
  1209. /* TEXASR register */
  1210. if (!ret)
  1211. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1212. &target->thread.tm_texasr, sizeof(u64),
  1213. 2 * sizeof(u64));
  1214. /* TFIAR register */
  1215. if (!ret)
  1216. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1217. &target->thread.tm_tfiar,
  1218. 2 * sizeof(u64), 3 * sizeof(u64));
  1219. return ret;
  1220. }
  1221. /**
  1222. * tm_spr_set - set the TM related SPR registers
  1223. * @target: The target task.
  1224. * @regset: The user regset structure.
  1225. * @pos: The buffer position.
  1226. * @count: Number of bytes to copy.
  1227. * @kbuf: Kernel buffer to copy into.
  1228. * @ubuf: User buffer to copy from.
  1229. *
  1230. * This function sets transactional memory related SPR registers.
  1231. * The userspace interface buffer layout is as follows.
  1232. *
  1233. * struct {
  1234. * u64 tm_tfhar;
  1235. * u64 tm_texasr;
  1236. * u64 tm_tfiar;
  1237. * };
  1238. */
  1239. static int tm_spr_set(struct task_struct *target,
  1240. const struct user_regset *regset,
  1241. unsigned int pos, unsigned int count,
  1242. const void *kbuf, const void __user *ubuf)
  1243. {
  1244. int ret;
  1245. /* Build tests */
  1246. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  1247. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  1248. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  1249. if (!cpu_has_feature(CPU_FTR_TM))
  1250. return -ENODEV;
  1251. /* Flush the states */
  1252. flush_tmregs_to_thread(target);
  1253. flush_fp_to_thread(target);
  1254. flush_altivec_to_thread(target);
  1255. /* TFHAR register */
  1256. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1257. &target->thread.tm_tfhar, 0, sizeof(u64));
  1258. /* TEXASR register */
  1259. if (!ret)
  1260. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1261. &target->thread.tm_texasr, sizeof(u64),
  1262. 2 * sizeof(u64));
  1263. /* TFIAR register */
  1264. if (!ret)
  1265. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1266. &target->thread.tm_tfiar,
  1267. 2 * sizeof(u64), 3 * sizeof(u64));
  1268. return ret;
  1269. }
  1270. static int tm_tar_active(struct task_struct *target,
  1271. const struct user_regset *regset)
  1272. {
  1273. if (!cpu_has_feature(CPU_FTR_TM))
  1274. return -ENODEV;
  1275. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1276. return regset->n;
  1277. return 0;
  1278. }
  1279. static int tm_tar_get(struct task_struct *target,
  1280. const struct user_regset *regset,
  1281. unsigned int pos, unsigned int count,
  1282. void *kbuf, void __user *ubuf)
  1283. {
  1284. int ret;
  1285. if (!cpu_has_feature(CPU_FTR_TM))
  1286. return -ENODEV;
  1287. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1288. return -ENODATA;
  1289. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1290. &target->thread.tm_tar, 0, sizeof(u64));
  1291. return ret;
  1292. }
  1293. static int tm_tar_set(struct task_struct *target,
  1294. const struct user_regset *regset,
  1295. unsigned int pos, unsigned int count,
  1296. const void *kbuf, const void __user *ubuf)
  1297. {
  1298. int ret;
  1299. if (!cpu_has_feature(CPU_FTR_TM))
  1300. return -ENODEV;
  1301. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1302. return -ENODATA;
  1303. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1304. &target->thread.tm_tar, 0, sizeof(u64));
  1305. return ret;
  1306. }
  1307. static int tm_ppr_active(struct task_struct *target,
  1308. const struct user_regset *regset)
  1309. {
  1310. if (!cpu_has_feature(CPU_FTR_TM))
  1311. return -ENODEV;
  1312. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1313. return regset->n;
  1314. return 0;
  1315. }
  1316. static int tm_ppr_get(struct task_struct *target,
  1317. const struct user_regset *regset,
  1318. unsigned int pos, unsigned int count,
  1319. void *kbuf, void __user *ubuf)
  1320. {
  1321. int ret;
  1322. if (!cpu_has_feature(CPU_FTR_TM))
  1323. return -ENODEV;
  1324. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1325. return -ENODATA;
  1326. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1327. &target->thread.tm_ppr, 0, sizeof(u64));
  1328. return ret;
  1329. }
  1330. static int tm_ppr_set(struct task_struct *target,
  1331. const struct user_regset *regset,
  1332. unsigned int pos, unsigned int count,
  1333. const void *kbuf, const void __user *ubuf)
  1334. {
  1335. int ret;
  1336. if (!cpu_has_feature(CPU_FTR_TM))
  1337. return -ENODEV;
  1338. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1339. return -ENODATA;
  1340. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1341. &target->thread.tm_ppr, 0, sizeof(u64));
  1342. return ret;
  1343. }
  1344. static int tm_dscr_active(struct task_struct *target,
  1345. const struct user_regset *regset)
  1346. {
  1347. if (!cpu_has_feature(CPU_FTR_TM))
  1348. return -ENODEV;
  1349. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1350. return regset->n;
  1351. return 0;
  1352. }
  1353. static int tm_dscr_get(struct task_struct *target,
  1354. const struct user_regset *regset,
  1355. unsigned int pos, unsigned int count,
  1356. void *kbuf, void __user *ubuf)
  1357. {
  1358. int ret;
  1359. if (!cpu_has_feature(CPU_FTR_TM))
  1360. return -ENODEV;
  1361. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1362. return -ENODATA;
  1363. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1364. &target->thread.tm_dscr, 0, sizeof(u64));
  1365. return ret;
  1366. }
  1367. static int tm_dscr_set(struct task_struct *target,
  1368. const struct user_regset *regset,
  1369. unsigned int pos, unsigned int count,
  1370. const void *kbuf, const void __user *ubuf)
  1371. {
  1372. int ret;
  1373. if (!cpu_has_feature(CPU_FTR_TM))
  1374. return -ENODEV;
  1375. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1376. return -ENODATA;
  1377. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1378. &target->thread.tm_dscr, 0, sizeof(u64));
  1379. return ret;
  1380. }
  1381. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1382. #ifdef CONFIG_PPC64
  1383. static int ppr_get(struct task_struct *target,
  1384. const struct user_regset *regset,
  1385. unsigned int pos, unsigned int count,
  1386. void *kbuf, void __user *ubuf)
  1387. {
  1388. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1389. &target->thread.ppr, 0, sizeof(u64));
  1390. }
  1391. static int ppr_set(struct task_struct *target,
  1392. const struct user_regset *regset,
  1393. unsigned int pos, unsigned int count,
  1394. const void *kbuf, const void __user *ubuf)
  1395. {
  1396. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1397. &target->thread.ppr, 0, sizeof(u64));
  1398. }
  1399. static int dscr_get(struct task_struct *target,
  1400. const struct user_regset *regset,
  1401. unsigned int pos, unsigned int count,
  1402. void *kbuf, void __user *ubuf)
  1403. {
  1404. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1405. &target->thread.dscr, 0, sizeof(u64));
  1406. }
  1407. static int dscr_set(struct task_struct *target,
  1408. const struct user_regset *regset,
  1409. unsigned int pos, unsigned int count,
  1410. const void *kbuf, const void __user *ubuf)
  1411. {
  1412. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1413. &target->thread.dscr, 0, sizeof(u64));
  1414. }
  1415. #endif
  1416. #ifdef CONFIG_PPC_BOOK3S_64
  1417. static int tar_get(struct task_struct *target,
  1418. const struct user_regset *regset,
  1419. unsigned int pos, unsigned int count,
  1420. void *kbuf, void __user *ubuf)
  1421. {
  1422. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1423. &target->thread.tar, 0, sizeof(u64));
  1424. }
  1425. static int tar_set(struct task_struct *target,
  1426. const struct user_regset *regset,
  1427. unsigned int pos, unsigned int count,
  1428. const void *kbuf, const void __user *ubuf)
  1429. {
  1430. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1431. &target->thread.tar, 0, sizeof(u64));
  1432. }
  1433. static int ebb_active(struct task_struct *target,
  1434. const struct user_regset *regset)
  1435. {
  1436. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1437. return -ENODEV;
  1438. if (target->thread.used_ebb)
  1439. return regset->n;
  1440. return 0;
  1441. }
  1442. static int ebb_get(struct task_struct *target,
  1443. const struct user_regset *regset,
  1444. unsigned int pos, unsigned int count,
  1445. void *kbuf, void __user *ubuf)
  1446. {
  1447. /* Build tests */
  1448. BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
  1449. BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
  1450. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1451. return -ENODEV;
  1452. if (!target->thread.used_ebb)
  1453. return -ENODATA;
  1454. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1455. &target->thread.ebbrr, 0, 3 * sizeof(unsigned long));
  1456. }
  1457. static int ebb_set(struct task_struct *target,
  1458. const struct user_regset *regset,
  1459. unsigned int pos, unsigned int count,
  1460. const void *kbuf, const void __user *ubuf)
  1461. {
  1462. int ret = 0;
  1463. /* Build tests */
  1464. BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
  1465. BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
  1466. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1467. return -ENODEV;
  1468. if (target->thread.used_ebb)
  1469. return -ENODATA;
  1470. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1471. &target->thread.ebbrr, 0, sizeof(unsigned long));
  1472. if (!ret)
  1473. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1474. &target->thread.ebbhr, sizeof(unsigned long),
  1475. 2 * sizeof(unsigned long));
  1476. if (!ret)
  1477. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1478. &target->thread.bescr,
  1479. 2 * sizeof(unsigned long), 3 * sizeof(unsigned long));
  1480. return ret;
  1481. }
  1482. static int pmu_active(struct task_struct *target,
  1483. const struct user_regset *regset)
  1484. {
  1485. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1486. return -ENODEV;
  1487. return regset->n;
  1488. }
  1489. static int pmu_get(struct task_struct *target,
  1490. const struct user_regset *regset,
  1491. unsigned int pos, unsigned int count,
  1492. void *kbuf, void __user *ubuf)
  1493. {
  1494. /* Build tests */
  1495. BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
  1496. BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
  1497. BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
  1498. BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
  1499. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1500. return -ENODEV;
  1501. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1502. &target->thread.siar, 0,
  1503. 5 * sizeof(unsigned long));
  1504. }
  1505. static int pmu_set(struct task_struct *target,
  1506. const struct user_regset *regset,
  1507. unsigned int pos, unsigned int count,
  1508. const void *kbuf, const void __user *ubuf)
  1509. {
  1510. int ret = 0;
  1511. /* Build tests */
  1512. BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
  1513. BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
  1514. BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
  1515. BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
  1516. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1517. return -ENODEV;
  1518. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1519. &target->thread.siar, 0,
  1520. sizeof(unsigned long));
  1521. if (!ret)
  1522. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1523. &target->thread.sdar, sizeof(unsigned long),
  1524. 2 * sizeof(unsigned long));
  1525. if (!ret)
  1526. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1527. &target->thread.sier, 2 * sizeof(unsigned long),
  1528. 3 * sizeof(unsigned long));
  1529. if (!ret)
  1530. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1531. &target->thread.mmcr2, 3 * sizeof(unsigned long),
  1532. 4 * sizeof(unsigned long));
  1533. if (!ret)
  1534. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1535. &target->thread.mmcr0, 4 * sizeof(unsigned long),
  1536. 5 * sizeof(unsigned long));
  1537. return ret;
  1538. }
  1539. #endif
  1540. #ifdef CONFIG_PPC_MEM_KEYS
  1541. static int pkey_active(struct task_struct *target,
  1542. const struct user_regset *regset)
  1543. {
  1544. if (!arch_pkeys_enabled())
  1545. return -ENODEV;
  1546. return regset->n;
  1547. }
  1548. static int pkey_get(struct task_struct *target,
  1549. const struct user_regset *regset,
  1550. unsigned int pos, unsigned int count,
  1551. void *kbuf, void __user *ubuf)
  1552. {
  1553. BUILD_BUG_ON(TSO(amr) + sizeof(unsigned long) != TSO(iamr));
  1554. BUILD_BUG_ON(TSO(iamr) + sizeof(unsigned long) != TSO(uamor));
  1555. if (!arch_pkeys_enabled())
  1556. return -ENODEV;
  1557. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1558. &target->thread.amr, 0,
  1559. ELF_NPKEY * sizeof(unsigned long));
  1560. }
  1561. static int pkey_set(struct task_struct *target,
  1562. const struct user_regset *regset,
  1563. unsigned int pos, unsigned int count,
  1564. const void *kbuf, const void __user *ubuf)
  1565. {
  1566. u64 new_amr;
  1567. int ret;
  1568. if (!arch_pkeys_enabled())
  1569. return -ENODEV;
  1570. /* Only the AMR can be set from userspace */
  1571. if (pos != 0 || count != sizeof(new_amr))
  1572. return -EINVAL;
  1573. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1574. &new_amr, 0, sizeof(new_amr));
  1575. if (ret)
  1576. return ret;
  1577. /* UAMOR determines which bits of the AMR can be set from userspace. */
  1578. target->thread.amr = (new_amr & target->thread.uamor) |
  1579. (target->thread.amr & ~target->thread.uamor);
  1580. return 0;
  1581. }
  1582. #endif /* CONFIG_PPC_MEM_KEYS */
  1583. /*
  1584. * These are our native regset flavors.
  1585. */
  1586. enum powerpc_regset {
  1587. REGSET_GPR,
  1588. REGSET_FPR,
  1589. #ifdef CONFIG_ALTIVEC
  1590. REGSET_VMX,
  1591. #endif
  1592. #ifdef CONFIG_VSX
  1593. REGSET_VSX,
  1594. #endif
  1595. #ifdef CONFIG_SPE
  1596. REGSET_SPE,
  1597. #endif
  1598. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1599. REGSET_TM_CGPR, /* TM checkpointed GPR registers */
  1600. REGSET_TM_CFPR, /* TM checkpointed FPR registers */
  1601. REGSET_TM_CVMX, /* TM checkpointed VMX registers */
  1602. REGSET_TM_CVSX, /* TM checkpointed VSX registers */
  1603. REGSET_TM_SPR, /* TM specific SPR registers */
  1604. REGSET_TM_CTAR, /* TM checkpointed TAR register */
  1605. REGSET_TM_CPPR, /* TM checkpointed PPR register */
  1606. REGSET_TM_CDSCR, /* TM checkpointed DSCR register */
  1607. #endif
  1608. #ifdef CONFIG_PPC64
  1609. REGSET_PPR, /* PPR register */
  1610. REGSET_DSCR, /* DSCR register */
  1611. #endif
  1612. #ifdef CONFIG_PPC_BOOK3S_64
  1613. REGSET_TAR, /* TAR register */
  1614. REGSET_EBB, /* EBB registers */
  1615. REGSET_PMR, /* Performance Monitor Registers */
  1616. #endif
  1617. #ifdef CONFIG_PPC_MEM_KEYS
  1618. REGSET_PKEY, /* AMR register */
  1619. #endif
  1620. };
  1621. static const struct user_regset native_regsets[] = {
  1622. [REGSET_GPR] = {
  1623. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  1624. .size = sizeof(long), .align = sizeof(long),
  1625. .get = gpr_get, .set = gpr_set
  1626. },
  1627. [REGSET_FPR] = {
  1628. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  1629. .size = sizeof(double), .align = sizeof(double),
  1630. .get = fpr_get, .set = fpr_set
  1631. },
  1632. #ifdef CONFIG_ALTIVEC
  1633. [REGSET_VMX] = {
  1634. .core_note_type = NT_PPC_VMX, .n = 34,
  1635. .size = sizeof(vector128), .align = sizeof(vector128),
  1636. .active = vr_active, .get = vr_get, .set = vr_set
  1637. },
  1638. #endif
  1639. #ifdef CONFIG_VSX
  1640. [REGSET_VSX] = {
  1641. .core_note_type = NT_PPC_VSX, .n = 32,
  1642. .size = sizeof(double), .align = sizeof(double),
  1643. .active = vsr_active, .get = vsr_get, .set = vsr_set
  1644. },
  1645. #endif
  1646. #ifdef CONFIG_SPE
  1647. [REGSET_SPE] = {
  1648. .core_note_type = NT_PPC_SPE, .n = 35,
  1649. .size = sizeof(u32), .align = sizeof(u32),
  1650. .active = evr_active, .get = evr_get, .set = evr_set
  1651. },
  1652. #endif
  1653. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1654. [REGSET_TM_CGPR] = {
  1655. .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
  1656. .size = sizeof(long), .align = sizeof(long),
  1657. .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set
  1658. },
  1659. [REGSET_TM_CFPR] = {
  1660. .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
  1661. .size = sizeof(double), .align = sizeof(double),
  1662. .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
  1663. },
  1664. [REGSET_TM_CVMX] = {
  1665. .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
  1666. .size = sizeof(vector128), .align = sizeof(vector128),
  1667. .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
  1668. },
  1669. [REGSET_TM_CVSX] = {
  1670. .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
  1671. .size = sizeof(double), .align = sizeof(double),
  1672. .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set
  1673. },
  1674. [REGSET_TM_SPR] = {
  1675. .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
  1676. .size = sizeof(u64), .align = sizeof(u64),
  1677. .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
  1678. },
  1679. [REGSET_TM_CTAR] = {
  1680. .core_note_type = NT_PPC_TM_CTAR, .n = 1,
  1681. .size = sizeof(u64), .align = sizeof(u64),
  1682. .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set
  1683. },
  1684. [REGSET_TM_CPPR] = {
  1685. .core_note_type = NT_PPC_TM_CPPR, .n = 1,
  1686. .size = sizeof(u64), .align = sizeof(u64),
  1687. .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set
  1688. },
  1689. [REGSET_TM_CDSCR] = {
  1690. .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
  1691. .size = sizeof(u64), .align = sizeof(u64),
  1692. .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set
  1693. },
  1694. #endif
  1695. #ifdef CONFIG_PPC64
  1696. [REGSET_PPR] = {
  1697. .core_note_type = NT_PPC_PPR, .n = 1,
  1698. .size = sizeof(u64), .align = sizeof(u64),
  1699. .get = ppr_get, .set = ppr_set
  1700. },
  1701. [REGSET_DSCR] = {
  1702. .core_note_type = NT_PPC_DSCR, .n = 1,
  1703. .size = sizeof(u64), .align = sizeof(u64),
  1704. .get = dscr_get, .set = dscr_set
  1705. },
  1706. #endif
  1707. #ifdef CONFIG_PPC_BOOK3S_64
  1708. [REGSET_TAR] = {
  1709. .core_note_type = NT_PPC_TAR, .n = 1,
  1710. .size = sizeof(u64), .align = sizeof(u64),
  1711. .get = tar_get, .set = tar_set
  1712. },
  1713. [REGSET_EBB] = {
  1714. .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
  1715. .size = sizeof(u64), .align = sizeof(u64),
  1716. .active = ebb_active, .get = ebb_get, .set = ebb_set
  1717. },
  1718. [REGSET_PMR] = {
  1719. .core_note_type = NT_PPC_PMU, .n = ELF_NPMU,
  1720. .size = sizeof(u64), .align = sizeof(u64),
  1721. .active = pmu_active, .get = pmu_get, .set = pmu_set
  1722. },
  1723. #endif
  1724. #ifdef CONFIG_PPC_MEM_KEYS
  1725. [REGSET_PKEY] = {
  1726. .core_note_type = NT_PPC_PKEY, .n = ELF_NPKEY,
  1727. .size = sizeof(u64), .align = sizeof(u64),
  1728. .active = pkey_active, .get = pkey_get, .set = pkey_set
  1729. },
  1730. #endif
  1731. };
  1732. static const struct user_regset_view user_ppc_native_view = {
  1733. .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
  1734. .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
  1735. };
  1736. #ifdef CONFIG_PPC64
  1737. #include <linux/compat.h>
  1738. static int gpr32_get_common(struct task_struct *target,
  1739. const struct user_regset *regset,
  1740. unsigned int pos, unsigned int count,
  1741. void *kbuf, void __user *ubuf,
  1742. unsigned long *regs)
  1743. {
  1744. compat_ulong_t *k = kbuf;
  1745. compat_ulong_t __user *u = ubuf;
  1746. compat_ulong_t reg;
  1747. pos /= sizeof(reg);
  1748. count /= sizeof(reg);
  1749. if (kbuf)
  1750. for (; count > 0 && pos < PT_MSR; --count)
  1751. *k++ = regs[pos++];
  1752. else
  1753. for (; count > 0 && pos < PT_MSR; --count)
  1754. if (__put_user((compat_ulong_t) regs[pos++], u++))
  1755. return -EFAULT;
  1756. if (count > 0 && pos == PT_MSR) {
  1757. reg = get_user_msr(target);
  1758. if (kbuf)
  1759. *k++ = reg;
  1760. else if (__put_user(reg, u++))
  1761. return -EFAULT;
  1762. ++pos;
  1763. --count;
  1764. }
  1765. if (kbuf)
  1766. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  1767. *k++ = regs[pos++];
  1768. else
  1769. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  1770. if (__put_user((compat_ulong_t) regs[pos++], u++))
  1771. return -EFAULT;
  1772. kbuf = k;
  1773. ubuf = u;
  1774. pos *= sizeof(reg);
  1775. count *= sizeof(reg);
  1776. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  1777. PT_REGS_COUNT * sizeof(reg), -1);
  1778. }
  1779. static int gpr32_set_common(struct task_struct *target,
  1780. const struct user_regset *regset,
  1781. unsigned int pos, unsigned int count,
  1782. const void *kbuf, const void __user *ubuf,
  1783. unsigned long *regs)
  1784. {
  1785. const compat_ulong_t *k = kbuf;
  1786. const compat_ulong_t __user *u = ubuf;
  1787. compat_ulong_t reg;
  1788. pos /= sizeof(reg);
  1789. count /= sizeof(reg);
  1790. if (kbuf)
  1791. for (; count > 0 && pos < PT_MSR; --count)
  1792. regs[pos++] = *k++;
  1793. else
  1794. for (; count > 0 && pos < PT_MSR; --count) {
  1795. if (__get_user(reg, u++))
  1796. return -EFAULT;
  1797. regs[pos++] = reg;
  1798. }
  1799. if (count > 0 && pos == PT_MSR) {
  1800. if (kbuf)
  1801. reg = *k++;
  1802. else if (__get_user(reg, u++))
  1803. return -EFAULT;
  1804. set_user_msr(target, reg);
  1805. ++pos;
  1806. --count;
  1807. }
  1808. if (kbuf) {
  1809. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
  1810. regs[pos++] = *k++;
  1811. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  1812. ++k;
  1813. } else {
  1814. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
  1815. if (__get_user(reg, u++))
  1816. return -EFAULT;
  1817. regs[pos++] = reg;
  1818. }
  1819. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  1820. if (__get_user(reg, u++))
  1821. return -EFAULT;
  1822. }
  1823. if (count > 0 && pos == PT_TRAP) {
  1824. if (kbuf)
  1825. reg = *k++;
  1826. else if (__get_user(reg, u++))
  1827. return -EFAULT;
  1828. set_user_trap(target, reg);
  1829. ++pos;
  1830. --count;
  1831. }
  1832. kbuf = k;
  1833. ubuf = u;
  1834. pos *= sizeof(reg);
  1835. count *= sizeof(reg);
  1836. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  1837. (PT_TRAP + 1) * sizeof(reg), -1);
  1838. }
  1839. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1840. static int tm_cgpr32_get(struct task_struct *target,
  1841. const struct user_regset *regset,
  1842. unsigned int pos, unsigned int count,
  1843. void *kbuf, void __user *ubuf)
  1844. {
  1845. return gpr32_get_common(target, regset, pos, count, kbuf, ubuf,
  1846. &target->thread.ckpt_regs.gpr[0]);
  1847. }
  1848. static int tm_cgpr32_set(struct task_struct *target,
  1849. const struct user_regset *regset,
  1850. unsigned int pos, unsigned int count,
  1851. const void *kbuf, const void __user *ubuf)
  1852. {
  1853. return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
  1854. &target->thread.ckpt_regs.gpr[0]);
  1855. }
  1856. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1857. static int gpr32_get(struct task_struct *target,
  1858. const struct user_regset *regset,
  1859. unsigned int pos, unsigned int count,
  1860. void *kbuf, void __user *ubuf)
  1861. {
  1862. int i;
  1863. if (target->thread.regs == NULL)
  1864. return -EIO;
  1865. if (!FULL_REGS(target->thread.regs)) {
  1866. /*
  1867. * We have a partial register set.
  1868. * Fill 14-31 with bogus values.
  1869. */
  1870. for (i = 14; i < 32; i++)
  1871. target->thread.regs->gpr[i] = NV_REG_POISON;
  1872. }
  1873. return gpr32_get_common(target, regset, pos, count, kbuf, ubuf,
  1874. &target->thread.regs->gpr[0]);
  1875. }
  1876. static int gpr32_set(struct task_struct *target,
  1877. const struct user_regset *regset,
  1878. unsigned int pos, unsigned int count,
  1879. const void *kbuf, const void __user *ubuf)
  1880. {
  1881. if (target->thread.regs == NULL)
  1882. return -EIO;
  1883. CHECK_FULL_REGS(target->thread.regs);
  1884. return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
  1885. &target->thread.regs->gpr[0]);
  1886. }
  1887. /*
  1888. * These are the regset flavors matching the CONFIG_PPC32 native set.
  1889. */
  1890. static const struct user_regset compat_regsets[] = {
  1891. [REGSET_GPR] = {
  1892. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  1893. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  1894. .get = gpr32_get, .set = gpr32_set
  1895. },
  1896. [REGSET_FPR] = {
  1897. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  1898. .size = sizeof(double), .align = sizeof(double),
  1899. .get = fpr_get, .set = fpr_set
  1900. },
  1901. #ifdef CONFIG_ALTIVEC
  1902. [REGSET_VMX] = {
  1903. .core_note_type = NT_PPC_VMX, .n = 34,
  1904. .size = sizeof(vector128), .align = sizeof(vector128),
  1905. .active = vr_active, .get = vr_get, .set = vr_set
  1906. },
  1907. #endif
  1908. #ifdef CONFIG_SPE
  1909. [REGSET_SPE] = {
  1910. .core_note_type = NT_PPC_SPE, .n = 35,
  1911. .size = sizeof(u32), .align = sizeof(u32),
  1912. .active = evr_active, .get = evr_get, .set = evr_set
  1913. },
  1914. #endif
  1915. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1916. [REGSET_TM_CGPR] = {
  1917. .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
  1918. .size = sizeof(long), .align = sizeof(long),
  1919. .active = tm_cgpr_active,
  1920. .get = tm_cgpr32_get, .set = tm_cgpr32_set
  1921. },
  1922. [REGSET_TM_CFPR] = {
  1923. .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
  1924. .size = sizeof(double), .align = sizeof(double),
  1925. .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
  1926. },
  1927. [REGSET_TM_CVMX] = {
  1928. .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
  1929. .size = sizeof(vector128), .align = sizeof(vector128),
  1930. .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
  1931. },
  1932. [REGSET_TM_CVSX] = {
  1933. .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
  1934. .size = sizeof(double), .align = sizeof(double),
  1935. .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set
  1936. },
  1937. [REGSET_TM_SPR] = {
  1938. .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
  1939. .size = sizeof(u64), .align = sizeof(u64),
  1940. .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
  1941. },
  1942. [REGSET_TM_CTAR] = {
  1943. .core_note_type = NT_PPC_TM_CTAR, .n = 1,
  1944. .size = sizeof(u64), .align = sizeof(u64),
  1945. .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set
  1946. },
  1947. [REGSET_TM_CPPR] = {
  1948. .core_note_type = NT_PPC_TM_CPPR, .n = 1,
  1949. .size = sizeof(u64), .align = sizeof(u64),
  1950. .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set
  1951. },
  1952. [REGSET_TM_CDSCR] = {
  1953. .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
  1954. .size = sizeof(u64), .align = sizeof(u64),
  1955. .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set
  1956. },
  1957. #endif
  1958. #ifdef CONFIG_PPC64
  1959. [REGSET_PPR] = {
  1960. .core_note_type = NT_PPC_PPR, .n = 1,
  1961. .size = sizeof(u64), .align = sizeof(u64),
  1962. .get = ppr_get, .set = ppr_set
  1963. },
  1964. [REGSET_DSCR] = {
  1965. .core_note_type = NT_PPC_DSCR, .n = 1,
  1966. .size = sizeof(u64), .align = sizeof(u64),
  1967. .get = dscr_get, .set = dscr_set
  1968. },
  1969. #endif
  1970. #ifdef CONFIG_PPC_BOOK3S_64
  1971. [REGSET_TAR] = {
  1972. .core_note_type = NT_PPC_TAR, .n = 1,
  1973. .size = sizeof(u64), .align = sizeof(u64),
  1974. .get = tar_get, .set = tar_set
  1975. },
  1976. [REGSET_EBB] = {
  1977. .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
  1978. .size = sizeof(u64), .align = sizeof(u64),
  1979. .active = ebb_active, .get = ebb_get, .set = ebb_set
  1980. },
  1981. #endif
  1982. };
  1983. static const struct user_regset_view user_ppc_compat_view = {
  1984. .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
  1985. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  1986. };
  1987. #endif /* CONFIG_PPC64 */
  1988. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  1989. {
  1990. #ifdef CONFIG_PPC64
  1991. if (test_tsk_thread_flag(task, TIF_32BIT))
  1992. return &user_ppc_compat_view;
  1993. #endif
  1994. return &user_ppc_native_view;
  1995. }
  1996. void user_enable_single_step(struct task_struct *task)
  1997. {
  1998. struct pt_regs *regs = task->thread.regs;
  1999. if (regs != NULL) {
  2000. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2001. task->thread.debug.dbcr0 &= ~DBCR0_BT;
  2002. task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  2003. regs->msr |= MSR_DE;
  2004. #else
  2005. regs->msr &= ~MSR_BE;
  2006. regs->msr |= MSR_SE;
  2007. #endif
  2008. }
  2009. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  2010. }
  2011. void user_enable_block_step(struct task_struct *task)
  2012. {
  2013. struct pt_regs *regs = task->thread.regs;
  2014. if (regs != NULL) {
  2015. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2016. task->thread.debug.dbcr0 &= ~DBCR0_IC;
  2017. task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT;
  2018. regs->msr |= MSR_DE;
  2019. #else
  2020. regs->msr &= ~MSR_SE;
  2021. regs->msr |= MSR_BE;
  2022. #endif
  2023. }
  2024. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  2025. }
  2026. void user_disable_single_step(struct task_struct *task)
  2027. {
  2028. struct pt_regs *regs = task->thread.regs;
  2029. if (regs != NULL) {
  2030. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2031. /*
  2032. * The logic to disable single stepping should be as
  2033. * simple as turning off the Instruction Complete flag.
  2034. * And, after doing so, if all debug flags are off, turn
  2035. * off DBCR0(IDM) and MSR(DE) .... Torez
  2036. */
  2037. task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT);
  2038. /*
  2039. * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
  2040. */
  2041. if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
  2042. task->thread.debug.dbcr1)) {
  2043. /*
  2044. * All debug events were off.....
  2045. */
  2046. task->thread.debug.dbcr0 &= ~DBCR0_IDM;
  2047. regs->msr &= ~MSR_DE;
  2048. }
  2049. #else
  2050. regs->msr &= ~(MSR_SE | MSR_BE);
  2051. #endif
  2052. }
  2053. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  2054. }
  2055. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2056. void ptrace_triggered(struct perf_event *bp,
  2057. struct perf_sample_data *data, struct pt_regs *regs)
  2058. {
  2059. struct perf_event_attr attr;
  2060. /*
  2061. * Disable the breakpoint request here since ptrace has defined a
  2062. * one-shot behaviour for breakpoint exceptions in PPC64.
  2063. * The SIGTRAP signal is generated automatically for us in do_dabr().
  2064. * We don't have to do anything about that here
  2065. */
  2066. attr = bp->attr;
  2067. attr.disabled = true;
  2068. modify_user_hw_breakpoint(bp, &attr);
  2069. }
  2070. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2071. static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  2072. unsigned long data)
  2073. {
  2074. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2075. int ret;
  2076. struct thread_struct *thread = &(task->thread);
  2077. struct perf_event *bp;
  2078. struct perf_event_attr attr;
  2079. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2080. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  2081. bool set_bp = true;
  2082. struct arch_hw_breakpoint hw_brk;
  2083. #endif
  2084. /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
  2085. * For embedded processors we support one DAC and no IAC's at the
  2086. * moment.
  2087. */
  2088. if (addr > 0)
  2089. return -EINVAL;
  2090. /* The bottom 3 bits in dabr are flags */
  2091. if ((data & ~0x7UL) >= TASK_SIZE)
  2092. return -EIO;
  2093. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  2094. /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
  2095. * It was assumed, on previous implementations, that 3 bits were
  2096. * passed together with the data address, fitting the design of the
  2097. * DABR register, as follows:
  2098. *
  2099. * bit 0: Read flag
  2100. * bit 1: Write flag
  2101. * bit 2: Breakpoint translation
  2102. *
  2103. * Thus, we use them here as so.
  2104. */
  2105. /* Ensure breakpoint translation bit is set */
  2106. if (data && !(data & HW_BRK_TYPE_TRANSLATE))
  2107. return -EIO;
  2108. hw_brk.address = data & (~HW_BRK_TYPE_DABR);
  2109. hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
  2110. hw_brk.len = 8;
  2111. set_bp = (data) && (hw_brk.type & HW_BRK_TYPE_RDWR);
  2112. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2113. bp = thread->ptrace_bps[0];
  2114. if (!set_bp) {
  2115. if (bp) {
  2116. unregister_hw_breakpoint(bp);
  2117. thread->ptrace_bps[0] = NULL;
  2118. }
  2119. return 0;
  2120. }
  2121. if (bp) {
  2122. attr = bp->attr;
  2123. attr.bp_addr = hw_brk.address;
  2124. arch_bp_generic_fields(hw_brk.type, &attr.bp_type);
  2125. /* Enable breakpoint */
  2126. attr.disabled = false;
  2127. ret = modify_user_hw_breakpoint(bp, &attr);
  2128. if (ret) {
  2129. return ret;
  2130. }
  2131. thread->ptrace_bps[0] = bp;
  2132. thread->hw_brk = hw_brk;
  2133. return 0;
  2134. }
  2135. /* Create a new breakpoint request if one doesn't exist already */
  2136. hw_breakpoint_init(&attr);
  2137. attr.bp_addr = hw_brk.address;
  2138. attr.bp_len = 8;
  2139. arch_bp_generic_fields(hw_brk.type,
  2140. &attr.bp_type);
  2141. thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
  2142. ptrace_triggered, NULL, task);
  2143. if (IS_ERR(bp)) {
  2144. thread->ptrace_bps[0] = NULL;
  2145. return PTR_ERR(bp);
  2146. }
  2147. #else /* !CONFIG_HAVE_HW_BREAKPOINT */
  2148. if (set_bp && (!ppc_breakpoint_available()))
  2149. return -ENODEV;
  2150. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2151. task->thread.hw_brk = hw_brk;
  2152. #else /* CONFIG_PPC_ADV_DEBUG_REGS */
  2153. /* As described above, it was assumed 3 bits were passed with the data
  2154. * address, but we will assume only the mode bits will be passed
  2155. * as to not cause alignment restrictions for DAC-based processors.
  2156. */
  2157. /* DAC's hold the whole address without any mode flags */
  2158. task->thread.debug.dac1 = data & ~0x3UL;
  2159. if (task->thread.debug.dac1 == 0) {
  2160. dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  2161. if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
  2162. task->thread.debug.dbcr1)) {
  2163. task->thread.regs->msr &= ~MSR_DE;
  2164. task->thread.debug.dbcr0 &= ~DBCR0_IDM;
  2165. }
  2166. return 0;
  2167. }
  2168. /* Read or Write bits must be set */
  2169. if (!(data & 0x3UL))
  2170. return -EINVAL;
  2171. /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
  2172. register */
  2173. task->thread.debug.dbcr0 |= DBCR0_IDM;
  2174. /* Check for write and read flags and set DBCR0
  2175. accordingly */
  2176. dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
  2177. if (data & 0x1UL)
  2178. dbcr_dac(task) |= DBCR_DAC1R;
  2179. if (data & 0x2UL)
  2180. dbcr_dac(task) |= DBCR_DAC1W;
  2181. task->thread.regs->msr |= MSR_DE;
  2182. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  2183. return 0;
  2184. }
  2185. /*
  2186. * Called by kernel/ptrace.c when detaching..
  2187. *
  2188. * Make sure single step bits etc are not set.
  2189. */
  2190. void ptrace_disable(struct task_struct *child)
  2191. {
  2192. /* make sure the single step bit is not set. */
  2193. user_disable_single_step(child);
  2194. }
  2195. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2196. static long set_instruction_bp(struct task_struct *child,
  2197. struct ppc_hw_breakpoint *bp_info)
  2198. {
  2199. int slot;
  2200. int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0);
  2201. int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0);
  2202. int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0);
  2203. int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0);
  2204. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  2205. slot2_in_use = 1;
  2206. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  2207. slot4_in_use = 1;
  2208. if (bp_info->addr >= TASK_SIZE)
  2209. return -EIO;
  2210. if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
  2211. /* Make sure range is valid. */
  2212. if (bp_info->addr2 >= TASK_SIZE)
  2213. return -EIO;
  2214. /* We need a pair of IAC regsisters */
  2215. if ((!slot1_in_use) && (!slot2_in_use)) {
  2216. slot = 1;
  2217. child->thread.debug.iac1 = bp_info->addr;
  2218. child->thread.debug.iac2 = bp_info->addr2;
  2219. child->thread.debug.dbcr0 |= DBCR0_IAC1;
  2220. if (bp_info->addr_mode ==
  2221. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  2222. dbcr_iac_range(child) |= DBCR_IAC12X;
  2223. else
  2224. dbcr_iac_range(child) |= DBCR_IAC12I;
  2225. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  2226. } else if ((!slot3_in_use) && (!slot4_in_use)) {
  2227. slot = 3;
  2228. child->thread.debug.iac3 = bp_info->addr;
  2229. child->thread.debug.iac4 = bp_info->addr2;
  2230. child->thread.debug.dbcr0 |= DBCR0_IAC3;
  2231. if (bp_info->addr_mode ==
  2232. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  2233. dbcr_iac_range(child) |= DBCR_IAC34X;
  2234. else
  2235. dbcr_iac_range(child) |= DBCR_IAC34I;
  2236. #endif
  2237. } else
  2238. return -ENOSPC;
  2239. } else {
  2240. /* We only need one. If possible leave a pair free in
  2241. * case a range is needed later
  2242. */
  2243. if (!slot1_in_use) {
  2244. /*
  2245. * Don't use iac1 if iac1-iac2 are free and either
  2246. * iac3 or iac4 (but not both) are free
  2247. */
  2248. if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
  2249. slot = 1;
  2250. child->thread.debug.iac1 = bp_info->addr;
  2251. child->thread.debug.dbcr0 |= DBCR0_IAC1;
  2252. goto out;
  2253. }
  2254. }
  2255. if (!slot2_in_use) {
  2256. slot = 2;
  2257. child->thread.debug.iac2 = bp_info->addr;
  2258. child->thread.debug.dbcr0 |= DBCR0_IAC2;
  2259. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  2260. } else if (!slot3_in_use) {
  2261. slot = 3;
  2262. child->thread.debug.iac3 = bp_info->addr;
  2263. child->thread.debug.dbcr0 |= DBCR0_IAC3;
  2264. } else if (!slot4_in_use) {
  2265. slot = 4;
  2266. child->thread.debug.iac4 = bp_info->addr;
  2267. child->thread.debug.dbcr0 |= DBCR0_IAC4;
  2268. #endif
  2269. } else
  2270. return -ENOSPC;
  2271. }
  2272. out:
  2273. child->thread.debug.dbcr0 |= DBCR0_IDM;
  2274. child->thread.regs->msr |= MSR_DE;
  2275. return slot;
  2276. }
  2277. static int del_instruction_bp(struct task_struct *child, int slot)
  2278. {
  2279. switch (slot) {
  2280. case 1:
  2281. if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0)
  2282. return -ENOENT;
  2283. if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
  2284. /* address range - clear slots 1 & 2 */
  2285. child->thread.debug.iac2 = 0;
  2286. dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
  2287. }
  2288. child->thread.debug.iac1 = 0;
  2289. child->thread.debug.dbcr0 &= ~DBCR0_IAC1;
  2290. break;
  2291. case 2:
  2292. if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0)
  2293. return -ENOENT;
  2294. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  2295. /* used in a range */
  2296. return -EINVAL;
  2297. child->thread.debug.iac2 = 0;
  2298. child->thread.debug.dbcr0 &= ~DBCR0_IAC2;
  2299. break;
  2300. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  2301. case 3:
  2302. if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0)
  2303. return -ENOENT;
  2304. if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
  2305. /* address range - clear slots 3 & 4 */
  2306. child->thread.debug.iac4 = 0;
  2307. dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
  2308. }
  2309. child->thread.debug.iac3 = 0;
  2310. child->thread.debug.dbcr0 &= ~DBCR0_IAC3;
  2311. break;
  2312. case 4:
  2313. if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0)
  2314. return -ENOENT;
  2315. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  2316. /* Used in a range */
  2317. return -EINVAL;
  2318. child->thread.debug.iac4 = 0;
  2319. child->thread.debug.dbcr0 &= ~DBCR0_IAC4;
  2320. break;
  2321. #endif
  2322. default:
  2323. return -EINVAL;
  2324. }
  2325. return 0;
  2326. }
  2327. static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
  2328. {
  2329. int byte_enable =
  2330. (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT)
  2331. & 0xf;
  2332. int condition_mode =
  2333. bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE;
  2334. int slot;
  2335. if (byte_enable && (condition_mode == 0))
  2336. return -EINVAL;
  2337. if (bp_info->addr >= TASK_SIZE)
  2338. return -EIO;
  2339. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
  2340. slot = 1;
  2341. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  2342. dbcr_dac(child) |= DBCR_DAC1R;
  2343. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  2344. dbcr_dac(child) |= DBCR_DAC1W;
  2345. child->thread.debug.dac1 = (unsigned long)bp_info->addr;
  2346. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  2347. if (byte_enable) {
  2348. child->thread.debug.dvc1 =
  2349. (unsigned long)bp_info->condition_value;
  2350. child->thread.debug.dbcr2 |=
  2351. ((byte_enable << DBCR2_DVC1BE_SHIFT) |
  2352. (condition_mode << DBCR2_DVC1M_SHIFT));
  2353. }
  2354. #endif
  2355. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2356. } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
  2357. /* Both dac1 and dac2 are part of a range */
  2358. return -ENOSPC;
  2359. #endif
  2360. } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
  2361. slot = 2;
  2362. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  2363. dbcr_dac(child) |= DBCR_DAC2R;
  2364. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  2365. dbcr_dac(child) |= DBCR_DAC2W;
  2366. child->thread.debug.dac2 = (unsigned long)bp_info->addr;
  2367. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  2368. if (byte_enable) {
  2369. child->thread.debug.dvc2 =
  2370. (unsigned long)bp_info->condition_value;
  2371. child->thread.debug.dbcr2 |=
  2372. ((byte_enable << DBCR2_DVC2BE_SHIFT) |
  2373. (condition_mode << DBCR2_DVC2M_SHIFT));
  2374. }
  2375. #endif
  2376. } else
  2377. return -ENOSPC;
  2378. child->thread.debug.dbcr0 |= DBCR0_IDM;
  2379. child->thread.regs->msr |= MSR_DE;
  2380. return slot + 4;
  2381. }
  2382. static int del_dac(struct task_struct *child, int slot)
  2383. {
  2384. if (slot == 1) {
  2385. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
  2386. return -ENOENT;
  2387. child->thread.debug.dac1 = 0;
  2388. dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  2389. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2390. if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
  2391. child->thread.debug.dac2 = 0;
  2392. child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE;
  2393. }
  2394. child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
  2395. #endif
  2396. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  2397. child->thread.debug.dvc1 = 0;
  2398. #endif
  2399. } else if (slot == 2) {
  2400. if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
  2401. return -ENOENT;
  2402. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2403. if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE)
  2404. /* Part of a range */
  2405. return -EINVAL;
  2406. child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
  2407. #endif
  2408. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  2409. child->thread.debug.dvc2 = 0;
  2410. #endif
  2411. child->thread.debug.dac2 = 0;
  2412. dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  2413. } else
  2414. return -EINVAL;
  2415. return 0;
  2416. }
  2417. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  2418. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2419. static int set_dac_range(struct task_struct *child,
  2420. struct ppc_hw_breakpoint *bp_info)
  2421. {
  2422. int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK;
  2423. /* We don't allow range watchpoints to be used with DVC */
  2424. if (bp_info->condition_mode)
  2425. return -EINVAL;
  2426. /*
  2427. * Best effort to verify the address range. The user/supervisor bits
  2428. * prevent trapping in kernel space, but let's fail on an obvious bad
  2429. * range. The simple test on the mask is not fool-proof, and any
  2430. * exclusive range will spill over into kernel space.
  2431. */
  2432. if (bp_info->addr >= TASK_SIZE)
  2433. return -EIO;
  2434. if (mode == PPC_BREAKPOINT_MODE_MASK) {
  2435. /*
  2436. * dac2 is a bitmask. Don't allow a mask that makes a
  2437. * kernel space address from a valid dac1 value
  2438. */
  2439. if (~((unsigned long)bp_info->addr2) >= TASK_SIZE)
  2440. return -EIO;
  2441. } else {
  2442. /*
  2443. * For range breakpoints, addr2 must also be a valid address
  2444. */
  2445. if (bp_info->addr2 >= TASK_SIZE)
  2446. return -EIO;
  2447. }
  2448. if (child->thread.debug.dbcr0 &
  2449. (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
  2450. return -ENOSPC;
  2451. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  2452. child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
  2453. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  2454. child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
  2455. child->thread.debug.dac1 = bp_info->addr;
  2456. child->thread.debug.dac2 = bp_info->addr2;
  2457. if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
  2458. child->thread.debug.dbcr2 |= DBCR2_DAC12M;
  2459. else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  2460. child->thread.debug.dbcr2 |= DBCR2_DAC12MX;
  2461. else /* PPC_BREAKPOINT_MODE_MASK */
  2462. child->thread.debug.dbcr2 |= DBCR2_DAC12MM;
  2463. child->thread.regs->msr |= MSR_DE;
  2464. return 5;
  2465. }
  2466. #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
  2467. static long ppc_set_hwdebug(struct task_struct *child,
  2468. struct ppc_hw_breakpoint *bp_info)
  2469. {
  2470. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2471. int len = 0;
  2472. struct thread_struct *thread = &(child->thread);
  2473. struct perf_event *bp;
  2474. struct perf_event_attr attr;
  2475. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2476. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  2477. struct arch_hw_breakpoint brk;
  2478. #endif
  2479. if (bp_info->version != 1)
  2480. return -ENOTSUPP;
  2481. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2482. /*
  2483. * Check for invalid flags and combinations
  2484. */
  2485. if ((bp_info->trigger_type == 0) ||
  2486. (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE |
  2487. PPC_BREAKPOINT_TRIGGER_RW)) ||
  2488. (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) ||
  2489. (bp_info->condition_mode &
  2490. ~(PPC_BREAKPOINT_CONDITION_MODE |
  2491. PPC_BREAKPOINT_CONDITION_BE_ALL)))
  2492. return -EINVAL;
  2493. #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
  2494. if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  2495. return -EINVAL;
  2496. #endif
  2497. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) {
  2498. if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
  2499. (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
  2500. return -EINVAL;
  2501. return set_instruction_bp(child, bp_info);
  2502. }
  2503. if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
  2504. return set_dac(child, bp_info);
  2505. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2506. return set_dac_range(child, bp_info);
  2507. #else
  2508. return -EINVAL;
  2509. #endif
  2510. #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  2511. /*
  2512. * We only support one data breakpoint
  2513. */
  2514. if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 ||
  2515. (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 ||
  2516. bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  2517. return -EINVAL;
  2518. if ((unsigned long)bp_info->addr >= TASK_SIZE)
  2519. return -EIO;
  2520. brk.address = bp_info->addr & ~7UL;
  2521. brk.type = HW_BRK_TYPE_TRANSLATE;
  2522. brk.len = 8;
  2523. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  2524. brk.type |= HW_BRK_TYPE_READ;
  2525. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  2526. brk.type |= HW_BRK_TYPE_WRITE;
  2527. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2528. /*
  2529. * Check if the request is for 'range' breakpoints. We can
  2530. * support it if range < 8 bytes.
  2531. */
  2532. if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
  2533. len = bp_info->addr2 - bp_info->addr;
  2534. else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
  2535. len = 1;
  2536. else
  2537. return -EINVAL;
  2538. bp = thread->ptrace_bps[0];
  2539. if (bp)
  2540. return -ENOSPC;
  2541. /* Create a new breakpoint request if one doesn't exist already */
  2542. hw_breakpoint_init(&attr);
  2543. attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN;
  2544. attr.bp_len = len;
  2545. arch_bp_generic_fields(brk.type, &attr.bp_type);
  2546. thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
  2547. ptrace_triggered, NULL, child);
  2548. if (IS_ERR(bp)) {
  2549. thread->ptrace_bps[0] = NULL;
  2550. return PTR_ERR(bp);
  2551. }
  2552. return 1;
  2553. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2554. if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT)
  2555. return -EINVAL;
  2556. if (child->thread.hw_brk.address)
  2557. return -ENOSPC;
  2558. if (!ppc_breakpoint_available())
  2559. return -ENODEV;
  2560. child->thread.hw_brk = brk;
  2561. return 1;
  2562. #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  2563. }
  2564. static long ppc_del_hwdebug(struct task_struct *child, long data)
  2565. {
  2566. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2567. int ret = 0;
  2568. struct thread_struct *thread = &(child->thread);
  2569. struct perf_event *bp;
  2570. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2571. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2572. int rc;
  2573. if (data <= 4)
  2574. rc = del_instruction_bp(child, (int)data);
  2575. else
  2576. rc = del_dac(child, (int)data - 4);
  2577. if (!rc) {
  2578. if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0,
  2579. child->thread.debug.dbcr1)) {
  2580. child->thread.debug.dbcr0 &= ~DBCR0_IDM;
  2581. child->thread.regs->msr &= ~MSR_DE;
  2582. }
  2583. }
  2584. return rc;
  2585. #else
  2586. if (data != 1)
  2587. return -EINVAL;
  2588. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2589. bp = thread->ptrace_bps[0];
  2590. if (bp) {
  2591. unregister_hw_breakpoint(bp);
  2592. thread->ptrace_bps[0] = NULL;
  2593. } else
  2594. ret = -ENOENT;
  2595. return ret;
  2596. #else /* CONFIG_HAVE_HW_BREAKPOINT */
  2597. if (child->thread.hw_brk.address == 0)
  2598. return -ENOENT;
  2599. child->thread.hw_brk.address = 0;
  2600. child->thread.hw_brk.type = 0;
  2601. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2602. return 0;
  2603. #endif
  2604. }
  2605. long arch_ptrace(struct task_struct *child, long request,
  2606. unsigned long addr, unsigned long data)
  2607. {
  2608. int ret = -EPERM;
  2609. void __user *datavp = (void __user *) data;
  2610. unsigned long __user *datalp = datavp;
  2611. switch (request) {
  2612. /* read the word at location addr in the USER area. */
  2613. case PTRACE_PEEKUSR: {
  2614. unsigned long index, tmp;
  2615. ret = -EIO;
  2616. /* convert to index and check */
  2617. #ifdef CONFIG_PPC32
  2618. index = addr >> 2;
  2619. if ((addr & 3) || (index > PT_FPSCR)
  2620. || (child->thread.regs == NULL))
  2621. #else
  2622. index = addr >> 3;
  2623. if ((addr & 7) || (index > PT_FPSCR))
  2624. #endif
  2625. break;
  2626. CHECK_FULL_REGS(child->thread.regs);
  2627. if (index < PT_FPR0) {
  2628. ret = ptrace_get_reg(child, (int) index, &tmp);
  2629. if (ret)
  2630. break;
  2631. } else {
  2632. unsigned int fpidx = index - PT_FPR0;
  2633. flush_fp_to_thread(child);
  2634. if (fpidx < (PT_FPSCR - PT_FPR0))
  2635. memcpy(&tmp, &child->thread.TS_FPR(fpidx),
  2636. sizeof(long));
  2637. else
  2638. tmp = child->thread.fp_state.fpscr;
  2639. }
  2640. ret = put_user(tmp, datalp);
  2641. break;
  2642. }
  2643. /* write the word at location addr in the USER area */
  2644. case PTRACE_POKEUSR: {
  2645. unsigned long index;
  2646. ret = -EIO;
  2647. /* convert to index and check */
  2648. #ifdef CONFIG_PPC32
  2649. index = addr >> 2;
  2650. if ((addr & 3) || (index > PT_FPSCR)
  2651. || (child->thread.regs == NULL))
  2652. #else
  2653. index = addr >> 3;
  2654. if ((addr & 7) || (index > PT_FPSCR))
  2655. #endif
  2656. break;
  2657. CHECK_FULL_REGS(child->thread.regs);
  2658. if (index < PT_FPR0) {
  2659. ret = ptrace_put_reg(child, index, data);
  2660. } else {
  2661. unsigned int fpidx = index - PT_FPR0;
  2662. flush_fp_to_thread(child);
  2663. if (fpidx < (PT_FPSCR - PT_FPR0))
  2664. memcpy(&child->thread.TS_FPR(fpidx), &data,
  2665. sizeof(long));
  2666. else
  2667. child->thread.fp_state.fpscr = data;
  2668. ret = 0;
  2669. }
  2670. break;
  2671. }
  2672. case PPC_PTRACE_GETHWDBGINFO: {
  2673. struct ppc_debug_info dbginfo;
  2674. dbginfo.version = 1;
  2675. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2676. dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
  2677. dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
  2678. dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
  2679. dbginfo.data_bp_alignment = 4;
  2680. dbginfo.sizeof_condition = 4;
  2681. dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
  2682. PPC_DEBUG_FEATURE_INSN_BP_MASK;
  2683. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  2684. dbginfo.features |=
  2685. PPC_DEBUG_FEATURE_DATA_BP_RANGE |
  2686. PPC_DEBUG_FEATURE_DATA_BP_MASK;
  2687. #endif
  2688. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  2689. dbginfo.num_instruction_bps = 0;
  2690. if (ppc_breakpoint_available())
  2691. dbginfo.num_data_bps = 1;
  2692. else
  2693. dbginfo.num_data_bps = 0;
  2694. dbginfo.num_condition_regs = 0;
  2695. #ifdef CONFIG_PPC64
  2696. dbginfo.data_bp_alignment = 8;
  2697. #else
  2698. dbginfo.data_bp_alignment = 4;
  2699. #endif
  2700. dbginfo.sizeof_condition = 0;
  2701. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  2702. dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
  2703. if (cpu_has_feature(CPU_FTR_DAWR))
  2704. dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR;
  2705. #else
  2706. dbginfo.features = 0;
  2707. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  2708. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  2709. if (copy_to_user(datavp, &dbginfo,
  2710. sizeof(struct ppc_debug_info)))
  2711. return -EFAULT;
  2712. return 0;
  2713. }
  2714. case PPC_PTRACE_SETHWDEBUG: {
  2715. struct ppc_hw_breakpoint bp_info;
  2716. if (copy_from_user(&bp_info, datavp,
  2717. sizeof(struct ppc_hw_breakpoint)))
  2718. return -EFAULT;
  2719. return ppc_set_hwdebug(child, &bp_info);
  2720. }
  2721. case PPC_PTRACE_DELHWDEBUG: {
  2722. ret = ppc_del_hwdebug(child, data);
  2723. break;
  2724. }
  2725. case PTRACE_GET_DEBUGREG: {
  2726. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  2727. unsigned long dabr_fake;
  2728. #endif
  2729. ret = -EINVAL;
  2730. /* We only support one DABR and no IABRS at the moment */
  2731. if (addr > 0)
  2732. break;
  2733. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  2734. ret = put_user(child->thread.debug.dac1, datalp);
  2735. #else
  2736. dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
  2737. (child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
  2738. ret = put_user(dabr_fake, datalp);
  2739. #endif
  2740. break;
  2741. }
  2742. case PTRACE_SET_DEBUGREG:
  2743. ret = ptrace_set_debugreg(child, addr, data);
  2744. break;
  2745. #ifdef CONFIG_PPC64
  2746. case PTRACE_GETREGS64:
  2747. #endif
  2748. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  2749. return copy_regset_to_user(child, &user_ppc_native_view,
  2750. REGSET_GPR,
  2751. 0, sizeof(struct pt_regs),
  2752. datavp);
  2753. #ifdef CONFIG_PPC64
  2754. case PTRACE_SETREGS64:
  2755. #endif
  2756. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  2757. return copy_regset_from_user(child, &user_ppc_native_view,
  2758. REGSET_GPR,
  2759. 0, sizeof(struct pt_regs),
  2760. datavp);
  2761. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  2762. return copy_regset_to_user(child, &user_ppc_native_view,
  2763. REGSET_FPR,
  2764. 0, sizeof(elf_fpregset_t),
  2765. datavp);
  2766. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  2767. return copy_regset_from_user(child, &user_ppc_native_view,
  2768. REGSET_FPR,
  2769. 0, sizeof(elf_fpregset_t),
  2770. datavp);
  2771. #ifdef CONFIG_ALTIVEC
  2772. case PTRACE_GETVRREGS:
  2773. return copy_regset_to_user(child, &user_ppc_native_view,
  2774. REGSET_VMX,
  2775. 0, (33 * sizeof(vector128) +
  2776. sizeof(u32)),
  2777. datavp);
  2778. case PTRACE_SETVRREGS:
  2779. return copy_regset_from_user(child, &user_ppc_native_view,
  2780. REGSET_VMX,
  2781. 0, (33 * sizeof(vector128) +
  2782. sizeof(u32)),
  2783. datavp);
  2784. #endif
  2785. #ifdef CONFIG_VSX
  2786. case PTRACE_GETVSRREGS:
  2787. return copy_regset_to_user(child, &user_ppc_native_view,
  2788. REGSET_VSX,
  2789. 0, 32 * sizeof(double),
  2790. datavp);
  2791. case PTRACE_SETVSRREGS:
  2792. return copy_regset_from_user(child, &user_ppc_native_view,
  2793. REGSET_VSX,
  2794. 0, 32 * sizeof(double),
  2795. datavp);
  2796. #endif
  2797. #ifdef CONFIG_SPE
  2798. case PTRACE_GETEVRREGS:
  2799. /* Get the child spe register state. */
  2800. return copy_regset_to_user(child, &user_ppc_native_view,
  2801. REGSET_SPE, 0, 35 * sizeof(u32),
  2802. datavp);
  2803. case PTRACE_SETEVRREGS:
  2804. /* Set the child spe register state. */
  2805. return copy_regset_from_user(child, &user_ppc_native_view,
  2806. REGSET_SPE, 0, 35 * sizeof(u32),
  2807. datavp);
  2808. #endif
  2809. default:
  2810. ret = ptrace_request(child, request, addr, data);
  2811. break;
  2812. }
  2813. return ret;
  2814. }
  2815. #ifdef CONFIG_SECCOMP
  2816. static int do_seccomp(struct pt_regs *regs)
  2817. {
  2818. if (!test_thread_flag(TIF_SECCOMP))
  2819. return 0;
  2820. /*
  2821. * The ABI we present to seccomp tracers is that r3 contains
  2822. * the syscall return value and orig_gpr3 contains the first
  2823. * syscall parameter. This is different to the ptrace ABI where
  2824. * both r3 and orig_gpr3 contain the first syscall parameter.
  2825. */
  2826. regs->gpr[3] = -ENOSYS;
  2827. /*
  2828. * We use the __ version here because we have already checked
  2829. * TIF_SECCOMP. If this fails, there is nothing left to do, we
  2830. * have already loaded -ENOSYS into r3, or seccomp has put
  2831. * something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
  2832. */
  2833. if (__secure_computing(NULL))
  2834. return -1;
  2835. /*
  2836. * The syscall was allowed by seccomp, restore the register
  2837. * state to what audit expects.
  2838. * Note that we use orig_gpr3, which means a seccomp tracer can
  2839. * modify the first syscall parameter (in orig_gpr3) and also
  2840. * allow the syscall to proceed.
  2841. */
  2842. regs->gpr[3] = regs->orig_gpr3;
  2843. return 0;
  2844. }
  2845. #else
  2846. static inline int do_seccomp(struct pt_regs *regs) { return 0; }
  2847. #endif /* CONFIG_SECCOMP */
  2848. /**
  2849. * do_syscall_trace_enter() - Do syscall tracing on kernel entry.
  2850. * @regs: the pt_regs of the task to trace (current)
  2851. *
  2852. * Performs various types of tracing on syscall entry. This includes seccomp,
  2853. * ptrace, syscall tracepoints and audit.
  2854. *
  2855. * The pt_regs are potentially visible to userspace via ptrace, so their
  2856. * contents is ABI.
  2857. *
  2858. * One or more of the tracers may modify the contents of pt_regs, in particular
  2859. * to modify arguments or even the syscall number itself.
  2860. *
  2861. * It's also possible that a tracer can choose to reject the system call. In
  2862. * that case this function will return an illegal syscall number, and will put
  2863. * an appropriate return value in regs->r3.
  2864. *
  2865. * Return: the (possibly changed) syscall number.
  2866. */
  2867. long do_syscall_trace_enter(struct pt_regs *regs)
  2868. {
  2869. user_exit();
  2870. /*
  2871. * The tracer may decide to abort the syscall, if so tracehook
  2872. * will return !0. Note that the tracer may also just change
  2873. * regs->gpr[0] to an invalid syscall number, that is handled
  2874. * below on the exit path.
  2875. */
  2876. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  2877. tracehook_report_syscall_entry(regs))
  2878. goto skip;
  2879. /* Run seccomp after ptrace; allow it to set gpr[3]. */
  2880. if (do_seccomp(regs))
  2881. return -1;
  2882. /* Avoid trace and audit when syscall is invalid. */
  2883. if (regs->gpr[0] >= NR_syscalls)
  2884. goto skip;
  2885. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  2886. trace_sys_enter(regs, regs->gpr[0]);
  2887. #ifdef CONFIG_PPC64
  2888. if (!is_32bit_task())
  2889. audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4],
  2890. regs->gpr[5], regs->gpr[6]);
  2891. else
  2892. #endif
  2893. audit_syscall_entry(regs->gpr[0],
  2894. regs->gpr[3] & 0xffffffff,
  2895. regs->gpr[4] & 0xffffffff,
  2896. regs->gpr[5] & 0xffffffff,
  2897. regs->gpr[6] & 0xffffffff);
  2898. /* Return the possibly modified but valid syscall number */
  2899. return regs->gpr[0];
  2900. skip:
  2901. /*
  2902. * If we are aborting explicitly, or if the syscall number is
  2903. * now invalid, set the return value to -ENOSYS.
  2904. */
  2905. regs->gpr[3] = -ENOSYS;
  2906. return -1;
  2907. }
  2908. void do_syscall_trace_leave(struct pt_regs *regs)
  2909. {
  2910. int step;
  2911. audit_syscall_exit(regs);
  2912. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  2913. trace_sys_exit(regs, regs->result);
  2914. step = test_thread_flag(TIF_SINGLESTEP);
  2915. if (step || test_thread_flag(TIF_SYSCALL_TRACE))
  2916. tracehook_report_syscall_exit(regs, step);
  2917. user_enter();
  2918. }