ptrace.c 85 KB

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