ptrace.c 85 KB

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