ptrace.c 85 KB

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