pda.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef X86_64_PDA_H
  2. #define X86_64_PDA_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/stddef.h>
  5. #include <linux/types.h>
  6. #include <linux/cache.h>
  7. #include <asm/page.h>
  8. /* Per processor datastructure. %gs points to it while the kernel runs */
  9. struct x8664_pda {
  10. struct task_struct *pcurrent; /* 0 Current process */
  11. unsigned long data_offset; /* 8 Per cpu data offset from linker
  12. address */
  13. unsigned long kernelstack; /* 16 top of kernel stack for current */
  14. unsigned long oldrsp; /* 24 user rsp for system call */
  15. int irqcount; /* 32 Irq nesting counter. Starts with -1 */
  16. int cpunumber; /* 36 Logical CPU number */
  17. #ifdef CONFIG_CC_STACKPROTECTOR
  18. unsigned long stack_canary; /* 40 stack canary value */
  19. /* gcc-ABI: this canary MUST be at
  20. offset 40!!! */
  21. #endif
  22. char *irqstackptr;
  23. int nodenumber; /* number of current node */
  24. unsigned int __softirq_pending;
  25. unsigned int __nmi_count; /* number of NMI on this CPUs */
  26. int mmu_state;
  27. struct mm_struct *active_mm;
  28. unsigned apic_timer_irqs;
  29. } ____cacheline_aligned_in_smp;
  30. extern struct x8664_pda *_cpu_pda[];
  31. extern struct x8664_pda boot_cpu_pda[];
  32. #define cpu_pda(i) (_cpu_pda[i])
  33. /*
  34. * There is no fast way to get the base address of the PDA, all the accesses
  35. * have to mention %fs/%gs. So it needs to be done this Torvaldian way.
  36. */
  37. extern void __bad_pda_field(void);
  38. /* proxy_pda doesn't actually exist, but tell gcc it is accessed
  39. for all PDA accesses so it gets read/write dependencies right. */
  40. extern struct x8664_pda _proxy_pda;
  41. #define pda_offset(field) offsetof(struct x8664_pda, field)
  42. #define pda_to_op(op,field,val) do { \
  43. typedef typeof(_proxy_pda.field) T__; \
  44. if (0) { T__ tmp__; tmp__ = (val); } \
  45. switch (sizeof(_proxy_pda.field)) { \
  46. case 2: \
  47. asm(op "w %1,%%gs:%c2" : "+m" (_proxy_pda.field) : \
  48. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  49. case 4: \
  50. asm(op "l %1,%%gs:%c2" : "+m" (_proxy_pda.field) : \
  51. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  52. case 8: \
  53. asm(op "q %1,%%gs:%c2": "+m" (_proxy_pda.field) : \
  54. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  55. default: __bad_pda_field(); \
  56. } \
  57. } while (0)
  58. #define pda_from_op(op,field) ({ \
  59. typeof(_proxy_pda.field) ret__; \
  60. switch (sizeof(_proxy_pda.field)) { \
  61. case 2: \
  62. asm(op "w %%gs:%c1,%0":"=r" (ret__):\
  63. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  64. case 4: \
  65. asm(op "l %%gs:%c1,%0":"=r" (ret__):\
  66. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  67. case 8: \
  68. asm(op "q %%gs:%c1,%0":"=r" (ret__):\
  69. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  70. default: __bad_pda_field(); \
  71. } \
  72. ret__; })
  73. #define read_pda(field) pda_from_op("mov",field)
  74. #define write_pda(field,val) pda_to_op("mov",field,val)
  75. #define add_pda(field,val) pda_to_op("add",field,val)
  76. #define sub_pda(field,val) pda_to_op("sub",field,val)
  77. #define or_pda(field,val) pda_to_op("or",field,val)
  78. #endif
  79. #define PDA_STACKOFFSET (5*8)
  80. #endif