ptrace.c 85 KB

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