diff options
author | Anshuman Khandual <khandual@linux.vnet.ibm.com> | 2016-07-27 22:57:44 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-07-31 21:15:24 -0400 |
commit | a67ae75802f178b0b790f1cd7f9c2954a85707fa (patch) | |
tree | 36aabd36804ec8607b700274fb9f182405925982 | |
parent | cf89d4e1b181bda27a5d52f4afd239ea07e84eb0 (diff) |
powerpc/ptrace: Enable support for Performance Monitor registers
This patch enables support for Performance monitor registers related
ELF core note NT_PPC_PMU based ptrace requests through
PTRACE_GETREGSET, PTRACE_SETREGSET calls. This is achieved
through adding one new register sets REGSET_PMU in powerpc
corresponding to the ELF core note sections added in this
regard. It also implements the get, set and active functions
for this new register sets added.
Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Simon Guo <wei.guo.simon@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | arch/powerpc/include/uapi/asm/elf.h | 3 | ||||
-rw-r--r-- | arch/powerpc/kernel/ptrace.c | 75 |
2 files changed, 77 insertions, 1 deletions
diff --git a/arch/powerpc/include/uapi/asm/elf.h b/arch/powerpc/include/uapi/asm/elf.h index 8c4d71a59259..3a9e44c45c78 100644 --- a/arch/powerpc/include/uapi/asm/elf.h +++ b/arch/powerpc/include/uapi/asm/elf.h | |||
@@ -94,7 +94,8 @@ | |||
94 | #define ELF_NVMX 34 /* includes all vector registers */ | 94 | #define ELF_NVMX 34 /* includes all vector registers */ |
95 | #define ELF_NVSX 32 /* includes all VSX registers */ | 95 | #define ELF_NVSX 32 /* includes all VSX registers */ |
96 | #define ELF_NTMSPRREG 3 /* include tfhar, tfiar, texasr */ | 96 | #define ELF_NTMSPRREG 3 /* include tfhar, tfiar, texasr */ |
97 | #define ELF_NEBB 3 /* includes ebbrr, ebbhr, bescr */ | 97 | #define ELF_NEBB 3 /* includes ebbrr, ebbhr, bescr */ |
98 | #define ELF_NPMU 5 /* includes siar, sdar, sier, mmcr2, mmcr0 */ | ||
98 | 99 | ||
99 | typedef unsigned long elf_greg_t64; | 100 | typedef unsigned long elf_greg_t64; |
100 | typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG]; | 101 | typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG]; |
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index 7942f9c575ef..4f3c5756cc09 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c | |||
@@ -1824,6 +1824,75 @@ static int ebb_set(struct task_struct *target, | |||
1824 | 1824 | ||
1825 | return ret; | 1825 | return ret; |
1826 | } | 1826 | } |
1827 | static int pmu_active(struct task_struct *target, | ||
1828 | const struct user_regset *regset) | ||
1829 | { | ||
1830 | if (!cpu_has_feature(CPU_FTR_ARCH_207S)) | ||
1831 | return -ENODEV; | ||
1832 | |||
1833 | return regset->n; | ||
1834 | } | ||
1835 | |||
1836 | static int pmu_get(struct task_struct *target, | ||
1837 | const struct user_regset *regset, | ||
1838 | unsigned int pos, unsigned int count, | ||
1839 | void *kbuf, void __user *ubuf) | ||
1840 | { | ||
1841 | /* Build tests */ | ||
1842 | BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); | ||
1843 | BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); | ||
1844 | BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); | ||
1845 | BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); | ||
1846 | |||
1847 | if (!cpu_has_feature(CPU_FTR_ARCH_207S)) | ||
1848 | return -ENODEV; | ||
1849 | |||
1850 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | ||
1851 | &target->thread.siar, 0, | ||
1852 | 5 * sizeof(unsigned long)); | ||
1853 | } | ||
1854 | |||
1855 | static int pmu_set(struct task_struct *target, | ||
1856 | const struct user_regset *regset, | ||
1857 | unsigned int pos, unsigned int count, | ||
1858 | const void *kbuf, const void __user *ubuf) | ||
1859 | { | ||
1860 | int ret = 0; | ||
1861 | |||
1862 | /* Build tests */ | ||
1863 | BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); | ||
1864 | BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); | ||
1865 | BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2)); | ||
1866 | BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0)); | ||
1867 | |||
1868 | if (!cpu_has_feature(CPU_FTR_ARCH_207S)) | ||
1869 | return -ENODEV; | ||
1870 | |||
1871 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | ||
1872 | &target->thread.siar, 0, | ||
1873 | sizeof(unsigned long)); | ||
1874 | |||
1875 | if (!ret) | ||
1876 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | ||
1877 | &target->thread.sdar, sizeof(unsigned long), | ||
1878 | 2 * sizeof(unsigned long)); | ||
1879 | |||
1880 | if (!ret) | ||
1881 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | ||
1882 | &target->thread.sier, 2 * sizeof(unsigned long), | ||
1883 | 3 * sizeof(unsigned long)); | ||
1884 | |||
1885 | if (!ret) | ||
1886 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | ||
1887 | &target->thread.mmcr2, 3 * sizeof(unsigned long), | ||
1888 | 4 * sizeof(unsigned long)); | ||
1889 | |||
1890 | if (!ret) | ||
1891 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | ||
1892 | &target->thread.mmcr0, 4 * sizeof(unsigned long), | ||
1893 | 5 * sizeof(unsigned long)); | ||
1894 | return ret; | ||
1895 | } | ||
1827 | #endif | 1896 | #endif |
1828 | /* | 1897 | /* |
1829 | * These are our native regset flavors. | 1898 | * These are our native regset flavors. |
@@ -1857,6 +1926,7 @@ enum powerpc_regset { | |||
1857 | #ifdef CONFIG_PPC_BOOK3S_64 | 1926 | #ifdef CONFIG_PPC_BOOK3S_64 |
1858 | REGSET_TAR, /* TAR register */ | 1927 | REGSET_TAR, /* TAR register */ |
1859 | REGSET_EBB, /* EBB registers */ | 1928 | REGSET_EBB, /* EBB registers */ |
1929 | REGSET_PMR, /* Performance Monitor Registers */ | ||
1860 | #endif | 1930 | #endif |
1861 | }; | 1931 | }; |
1862 | 1932 | ||
@@ -1957,6 +2027,11 @@ static const struct user_regset native_regsets[] = { | |||
1957 | .size = sizeof(u64), .align = sizeof(u64), | 2027 | .size = sizeof(u64), .align = sizeof(u64), |
1958 | .active = ebb_active, .get = ebb_get, .set = ebb_set | 2028 | .active = ebb_active, .get = ebb_get, .set = ebb_set |
1959 | }, | 2029 | }, |
2030 | [REGSET_PMR] = { | ||
2031 | .core_note_type = NT_PPC_PMU, .n = ELF_NPMU, | ||
2032 | .size = sizeof(u64), .align = sizeof(u64), | ||
2033 | .active = pmu_active, .get = pmu_get, .set = pmu_set | ||
2034 | }, | ||
1960 | #endif | 2035 | #endif |
1961 | }; | 2036 | }; |
1962 | 2037 | ||