Commit e6ae5d9540727b0e2e5e2fbeb683c84671ed0a31

Authored by Markus Metzger
Committed by Ingo Molnar
1 parent da35c37198

x86, ptrace: support 32bit-cross-64bit BTS recording

Support BTS recording of 32bit and 64bit tasks from 32bit or 64bit tasks.

Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Showing 4 changed files with 53 additions and 54 deletions Side-by-side Diff

arch/x86/kernel/ds.c
... ... @@ -111,53 +111,53 @@
111 111 * Accessor functions for some DS and BTS fields using the above
112 112 * global ptrace_bts_cfg.
113 113 */
114   -static inline void *get_bts_buffer_base(char *base)
  114 +static inline unsigned long get_bts_buffer_base(char *base)
115 115 {
116   - return *(void **)(base + ds_cfg.bts_buffer_base.offset);
  116 + return *(unsigned long *)(base + ds_cfg.bts_buffer_base.offset);
117 117 }
118   -static inline void set_bts_buffer_base(char *base, void *value)
  118 +static inline void set_bts_buffer_base(char *base, unsigned long value)
119 119 {
120   - (*(void **)(base + ds_cfg.bts_buffer_base.offset)) = value;
  120 + (*(unsigned long *)(base + ds_cfg.bts_buffer_base.offset)) = value;
121 121 }
122   -static inline void *get_bts_index(char *base)
  122 +static inline unsigned long get_bts_index(char *base)
123 123 {
124   - return *(void **)(base + ds_cfg.bts_index.offset);
  124 + return *(unsigned long *)(base + ds_cfg.bts_index.offset);
125 125 }
126   -static inline void set_bts_index(char *base, void *value)
  126 +static inline void set_bts_index(char *base, unsigned long value)
127 127 {
128   - (*(void **)(base + ds_cfg.bts_index.offset)) = value;
  128 + (*(unsigned long *)(base + ds_cfg.bts_index.offset)) = value;
129 129 }
130   -static inline void *get_bts_absolute_maximum(char *base)
  130 +static inline unsigned long get_bts_absolute_maximum(char *base)
131 131 {
132   - return *(void **)(base + ds_cfg.bts_absolute_maximum.offset);
  132 + return *(unsigned long *)(base + ds_cfg.bts_absolute_maximum.offset);
133 133 }
134   -static inline void set_bts_absolute_maximum(char *base, void *value)
  134 +static inline void set_bts_absolute_maximum(char *base, unsigned long value)
135 135 {
136   - (*(void **)(base + ds_cfg.bts_absolute_maximum.offset)) = value;
  136 + (*(unsigned long *)(base + ds_cfg.bts_absolute_maximum.offset)) = value;
137 137 }
138   -static inline void *get_bts_interrupt_threshold(char *base)
  138 +static inline unsigned long get_bts_interrupt_threshold(char *base)
139 139 {
140   - return *(void **)(base + ds_cfg.bts_interrupt_threshold.offset);
  140 + return *(unsigned long *)(base + ds_cfg.bts_interrupt_threshold.offset);
141 141 }
142   -static inline void set_bts_interrupt_threshold(char *base, void *value)
  142 +static inline void set_bts_interrupt_threshold(char *base, unsigned long value)
143 143 {
144   - (*(void **)(base + ds_cfg.bts_interrupt_threshold.offset)) = value;
  144 + (*(unsigned long *)(base + ds_cfg.bts_interrupt_threshold.offset)) = value;
145 145 }
146   -static inline long get_from_ip(char *base)
  146 +static inline unsigned long get_from_ip(char *base)
147 147 {
148   - return *(long *)(base + ds_cfg.from_ip.offset);
  148 + return *(unsigned long *)(base + ds_cfg.from_ip.offset);
149 149 }
150   -static inline void set_from_ip(char *base, long value)
  150 +static inline void set_from_ip(char *base, unsigned long value)
151 151 {
152   - (*(long *)(base + ds_cfg.from_ip.offset)) = value;
  152 + (*(unsigned long *)(base + ds_cfg.from_ip.offset)) = value;
153 153 }
154   -static inline long get_to_ip(char *base)
  154 +static inline unsigned long get_to_ip(char *base)
155 155 {
156   - return *(long *)(base + ds_cfg.to_ip.offset);
  156 + return *(unsigned long *)(base + ds_cfg.to_ip.offset);
157 157 }
158   -static inline void set_to_ip(char *base, long value)
  158 +static inline void set_to_ip(char *base, unsigned long value)
159 159 {
160   - (*(long *)(base + ds_cfg.to_ip.offset)) = value;
  160 + (*(unsigned long *)(base + ds_cfg.to_ip.offset)) = value;
161 161 }
162 162 static inline unsigned char get_info_type(char *base)
163 163 {
... ... @@ -180,7 +180,7 @@
180 180 int ds_allocate(void **dsp, size_t bts_size_in_bytes)
181 181 {
182 182 size_t bts_size_in_records;
183   - void *bts;
  183 + unsigned long bts;
184 184 void *ds;
185 185  
186 186 if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)
... ... @@ -197,7 +197,7 @@
197 197 if (bts_size_in_bytes <= 0)
198 198 return -EINVAL;
199 199  
200   - bts = kzalloc(bts_size_in_bytes, GFP_KERNEL);
  200 + bts = (unsigned long)kzalloc(bts_size_in_bytes, GFP_KERNEL);
201 201  
202 202 if (!bts)
203 203 return -ENOMEM;
... ... @@ -205,7 +205,7 @@
205 205 ds = kzalloc(ds_cfg.sizeof_ds, GFP_KERNEL);
206 206  
207 207 if (!ds) {
208   - kfree(bts);
  208 + kfree((void *)bts);
209 209 return -ENOMEM;
210 210 }
211 211  
... ... @@ -221,7 +221,7 @@
221 221 int ds_free(void **dsp)
222 222 {
223 223 if (*dsp)
224   - kfree(get_bts_buffer_base(*dsp));
  224 + kfree((void *)get_bts_buffer_base(*dsp));
225 225 kfree(*dsp);
226 226 *dsp = 0;
227 227  
... ... @@ -230,7 +230,7 @@
230 230  
231 231 int ds_get_bts_size(void *ds)
232 232 {
233   - size_t size_in_bytes;
  233 + int size_in_bytes;
234 234  
235 235 if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)
236 236 return -EOPNOTSUPP;
... ... @@ -246,7 +246,7 @@
246 246  
247 247 int ds_get_bts_end(void *ds)
248 248 {
249   - size_t size_in_bytes = ds_get_bts_size(ds);
  249 + int size_in_bytes = ds_get_bts_size(ds);
250 250  
251 251 if (size_in_bytes <= 0)
252 252 return size_in_bytes;
... ... @@ -256,7 +256,7 @@
256 256  
257 257 int ds_get_bts_index(void *ds)
258 258 {
259   - size_t index_offset_in_bytes;
  259 + int index_offset_in_bytes;
260 260  
261 261 if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)
262 262 return -EOPNOTSUPP;
263 263  
264 264  
... ... @@ -288,19 +288,19 @@
288 288 int ds_clear(void *ds)
289 289 {
290 290 int bts_size = ds_get_bts_size(ds);
291   - void *bts_base;
  291 + unsigned long bts_base;
292 292  
293 293 if (bts_size <= 0)
294 294 return bts_size;
295 295  
296 296 bts_base = get_bts_buffer_base(ds);
297   - memset(bts_base, 0, bts_size);
  297 + memset((void *)bts_base, 0, bts_size);
298 298  
299 299 set_bts_index(ds, bts_base);
300 300 return 0;
301 301 }
302 302  
303   -int ds_read_bts(void *ds, size_t index, struct bts_struct *out)
  303 +int ds_read_bts(void *ds, int index, struct bts_struct *out)
304 304 {
305 305 void *bts;
306 306  
... ... @@ -313,8 +313,7 @@
313 313 if (index >= ds_get_bts_size(ds))
314 314 return -EINVAL;
315 315  
316   - bts = get_bts_buffer_base(ds);
317   - bts = (char *)bts + (index * ds_cfg.sizeof_bts);
  316 + bts = (void *)(get_bts_buffer_base(ds) + (index * ds_cfg.sizeof_bts));
318 317  
319 318 memset(out, 0, sizeof(*out));
320 319 if (get_from_ip(bts) == BTS_ESCAPE_ADDRESS) {
321 320  
... ... @@ -326,12 +325,12 @@
326 325 out->variant.lbr.to_ip = get_to_ip(bts);
327 326 }
328 327  
329   - return 0;
  328 + return sizeof(*out);;
330 329 }
331 330  
332 331 int ds_write_bts(void *ds, const struct bts_struct *in)
333 332 {
334   - void *bts;
  333 + unsigned long bts;
335 334  
336 335 if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)
337 336 return -EOPNOTSUPP;
338 337  
339 338  
340 339  
341 340  
... ... @@ -341,33 +340,33 @@
341 340  
342 341 bts = get_bts_index(ds);
343 342  
344   - memset(bts, 0, ds_cfg.sizeof_bts);
  343 + memset((void *)bts, 0, ds_cfg.sizeof_bts);
345 344 switch (in->qualifier) {
346 345 case BTS_INVALID:
347 346 break;
348 347  
349 348 case BTS_BRANCH:
350   - set_from_ip(bts, in->variant.lbr.from_ip);
351   - set_to_ip(bts, in->variant.lbr.to_ip);
  349 + set_from_ip((void *)bts, in->variant.lbr.from_ip);
  350 + set_to_ip((void *)bts, in->variant.lbr.to_ip);
352 351 break;
353 352  
354 353 case BTS_TASK_ARRIVES:
355 354 case BTS_TASK_DEPARTS:
356   - set_from_ip(bts, BTS_ESCAPE_ADDRESS);
357   - set_info_type(bts, in->qualifier);
358   - set_info_data(bts, in->variant.jiffies);
  355 + set_from_ip((void *)bts, BTS_ESCAPE_ADDRESS);
  356 + set_info_type((void *)bts, in->qualifier);
  357 + set_info_data((void *)bts, in->variant.jiffies);
359 358 break;
360 359  
361 360 default:
362 361 return -EINVAL;
363 362 }
364 363  
365   - bts = (char *)bts + ds_cfg.sizeof_bts;
  364 + bts = bts + ds_cfg.sizeof_bts;
366 365 if (bts >= get_bts_absolute_maximum(ds))
367 366 bts = get_bts_buffer_base(ds);
368 367 set_bts_index(ds, bts);
369 368  
370   - return 0;
  369 + return ds_cfg.sizeof_bts;
371 370 }
372 371  
373 372 unsigned long ds_debugctl_mask(void)
arch/x86/kernel/ptrace.c
... ... @@ -558,7 +558,7 @@
558 558  
559 559 retval = ds_read_bts((void *)child->thread.ds_area_msr,
560 560 bts_index, &ret);
561   - if (retval)
  561 + if (retval < 0)
562 562 return retval;
563 563  
564 564 if (copy_to_user(out, &ret, sizeof(ret)))
include/asm-x86/ds.h
... ... @@ -39,16 +39,16 @@
39 39 };
40 40  
41 41 struct bts_struct {
42   - enum bts_qualifier qualifier;
  42 + u64 qualifier;
43 43 union {
44 44 /* BTS_BRANCH */
45 45 struct {
46   - long from_ip;
47   - long to_ip;
  46 + u64 from_ip;
  47 + u64 to_ip;
48 48 } lbr;
49 49 /* BTS_TASK_ARRIVES or
50 50 BTS_TASK_DEPARTS */
51   - unsigned long jiffies;
  51 + u64 jiffies;
52 52 } variant;
53 53 };
54 54  
... ... @@ -64,7 +64,7 @@
64 64 extern int ds_set_overflow(void *, int);
65 65 extern int ds_get_overflow(void *);
66 66 extern int ds_clear(void *);
67   -extern int ds_read_bts(void *, size_t, struct bts_struct *);
  67 +extern int ds_read_bts(void *, int, struct bts_struct *);
68 68 extern int ds_write_bts(void *, const struct bts_struct *);
69 69 extern unsigned long ds_debugctl_mask(void);
70 70 extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *c);
include/asm-x86/ptrace-abi.h
... ... @@ -85,9 +85,9 @@
85 85 */
86 86 struct ptrace_bts_config {
87 87 /* requested or actual size of BTS buffer in bytes */
88   - unsigned long size;
  88 + unsigned int size;
89 89 /* bitmask of below flags */
90   - unsigned long flags;
  90 + unsigned int flags;
91 91 };
92 92  
93 93 #define PTRACE_BTS_O_TRACE 0x1 /* branch trace */