ptrace.c 84 KB

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