Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Anshuman Khandual and committed by
Michael Ellerman
a67ae758 cf89d4e1

+77 -1
+2 -1
arch/powerpc/include/uapi/asm/elf.h
··· 94 94 #define ELF_NVMX 34 /* includes all vector registers */ 95 95 #define ELF_NVSX 32 /* includes all VSX registers */ 96 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 100 typedef unsigned long elf_greg_t64; 100 101 typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG];
+75
arch/powerpc/kernel/ptrace.c
··· 1824 1824 1825 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 1896 #endif 1828 1897 /* 1829 1898 * These are our native regset flavors. ··· 1926 1857 #ifdef CONFIG_PPC_BOOK3S_64 1927 1858 REGSET_TAR, /* TAR register */ 1928 1859 REGSET_EBB, /* EBB registers */ 1860 + REGSET_PMR, /* Performance Monitor Registers */ 1929 1861 #endif 1930 1862 }; 1931 1863 ··· 2026 1956 .core_note_type = NT_PPC_EBB, .n = ELF_NEBB, 2027 1957 .size = sizeof(u64), .align = sizeof(u64), 2028 1958 .active = ebb_active, .get = ebb_get, .set = ebb_set 1959 + }, 1960 + [REGSET_PMR] = { 1961 + .core_note_type = NT_PPC_PMU, .n = ELF_NPMU, 1962 + .size = sizeof(u64), .align = sizeof(u64), 1963 + .active = pmu_active, .get = pmu_get, .set = pmu_set 2029 1964 }, 2030 1965 #endif 2031 1966 };