diff --git a/sys/arch/i386/i386/pmc.c b/sys/arch/i386/i386/pmc.c index 198d002ac29e..9a0eb82c9d10 100644 --- a/sys/arch/i386/i386/pmc.c +++ b/sys/arch/i386/i386/pmc.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $ */ +/* $NetBSD: pmc.c,v 1.24 2017/03/08 16:42:27 maxv Exp $ */ /* * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.24 2017/03/08 16:42:27 maxv Exp $"); #include #include @@ -275,6 +275,7 @@ sys_pmc_info(struct lwp *l, struct x86_pmc_info_args *uargs, register_t *retval) memset(&rv, 0, sizeof(rv)); + rv.vers = PMC_VERSION; rv.type = pmc_type; rv.flags = pmc_flags; @@ -297,7 +298,7 @@ sys_pmc_startstop(struct lwp *l, struct x86_pmc_startstop_args *uargs, if (error) return error; - if (args.counter < 0 || args.counter >= pmc_ncounters) + if (args.counter >= pmc_ncounters) return EINVAL; start = (args.flags & (PMC_SETUP_KERNEL|PMC_SETUP_USER)) != 0; @@ -338,7 +339,7 @@ sys_pmc_read(struct lwp *l, struct x86_pmc_read_args *uargs, register_t *retval) if (error) return error; - if (args.counter < 0 || args.counter >= pmc_ncounters) + if (args.counter >= pmc_ncounters) return EINVAL; pmc = &pmc_state[args.counter]; diff --git a/sys/arch/x86/include/sysarch.h b/sys/arch/x86/include/sysarch.h index 1803bf9b8ac2..d31447cb667e 100644 --- a/sys/arch/x86/include/sysarch.h +++ b/sys/arch/x86/include/sysarch.h @@ -1,4 +1,4 @@ -/* $NetBSD: sysarch.h,v 1.9 2010/07/07 01:14:53 chs Exp $ */ +/* $NetBSD: sysarch.h,v 1.10 2017/03/08 16:42:27 maxv Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -34,62 +34,62 @@ #define X86_GET_LDT 0 #define X86_SET_LDT 1 -#define X86_IOPL 2 -#define X86_GET_IOPERM 3 -#define X86_SET_IOPERM 4 -#define X86_OLD_VM86 5 -#define X86_PMC_INFO 8 -#define X86_PMC_STARTSTOP 9 -#define X86_PMC_READ 10 +#define X86_IOPL 2 +#define X86_GET_IOPERM 3 +#define X86_SET_IOPERM 4 +#define X86_OLD_VM86 5 +#define X86_PMC_INFO 8 +#define X86_PMC_STARTSTOP 9 +#define X86_PMC_READ 10 #define X86_GET_MTRR 11 #define X86_SET_MTRR 12 -#define X86_VM86 13 -#define X86_GET_GSBASE 14 -#define X86_GET_FSBASE 15 -#define X86_SET_GSBASE 16 -#define X86_SET_FSBASE 17 +#define X86_VM86 13 +#define X86_GET_GSBASE 14 +#define X86_GET_FSBASE 15 +#define X86_SET_GSBASE 16 +#define X86_SET_FSBASE 17 #ifdef _KERNEL -#define _X86_SYSARCH_L(x) x86_##x -#define _X86_SYSARCH_U(x) X86_##x +#define _X86_SYSARCH_L(x) x86_##x +#define _X86_SYSARCH_U(x) X86_##x #elif defined(__i386__) -#define _X86_SYSARCH_L(x) i386_##x -#define _X86_SYSARCH_U(x) I386_##x +#define _X86_SYSARCH_L(x) i386_##x +#define _X86_SYSARCH_U(x) I386_##x #define I386_GET_LDT X86_GET_LDT #define I386_SET_LDT X86_SET_LDT -#define I386_IOPL X86_IOPL -#define I386_GET_IOPERM X86_GET_IOPERM -#define I386_SET_IOPERM X86_SET_IOPERM -#define I386_OLD_VM86 X86_OLD_VM86 -#define I386_PMC_INFO X86_PMC_INFO -#define I386_PMC_STARTSTOP X86_PMC_STARTSTOP -#define I386_PMC_READ X86_PMC_READ +#define I386_IOPL X86_IOPL +#define I386_GET_IOPERM X86_GET_IOPERM +#define I386_SET_IOPERM X86_SET_IOPERM +#define I386_OLD_VM86 X86_OLD_VM86 +#define I386_PMC_INFO X86_PMC_INFO +#define I386_PMC_STARTSTOP X86_PMC_STARTSTOP +#define I386_PMC_READ X86_PMC_READ #define I386_GET_MTRR X86_GET_MTRR #define I386_SET_MTRR X86_SET_MTRR -#define I386_VM86 X86_VM86 -#define I386_GET_GSBASE X86_GET_GSBASE -#define I386_GET_FSBASE X86_GET_FSBASE -#define I386_SET_GSBASE X86_SET_GSBASE -#define I386_SET_FSBASE X86_SET_FSBASE +#define I386_VM86 X86_VM86 +#define I386_GET_GSBASE X86_GET_GSBASE +#define I386_GET_FSBASE X86_GET_FSBASE +#define I386_SET_GSBASE X86_SET_GSBASE +#define I386_SET_FSBASE X86_SET_FSBASE #else -#define _X86_SYSARCH_L(x) x86_64_##x -#define _X86_SYSARCH_U(x) X86_64_##x +#define _X86_SYSARCH_L(x) x86_64_##x +#define _X86_SYSARCH_U(x) X86_64_##x #define X86_64_GET_LDT X86_GET_LDT #define X86_64_SET_LDT X86_SET_LDT -#define X86_64_IOPL X86_IOPL -#define X86_64_GET_IOPERM X86_GET_IOPERM -#define X86_64_SET_IOPERM X86_SET_IOPERM -#define X86_64_OLD_VM86 X86_OLD_VM86 -#define X86_64_PMC_INFO X86_PMC_INFO -#define X86_64_PMC_STARTSTOP X86_PMC_STARTSTOP -#define X86_64_PMC_READ X86_PMC_READ +#define X86_64_IOPL X86_IOPL +#define X86_64_GET_IOPERM X86_GET_IOPERM +#define X86_64_SET_IOPERM X86_SET_IOPERM +#define X86_64_OLD_VM86 X86_OLD_VM86 +#define X86_64_PMC_INFO X86_PMC_INFO +#define X86_64_PMC_STARTSTOP X86_PMC_STARTSTOP +#define X86_64_PMC_READ X86_PMC_READ #define X86_64_GET_MTRR X86_GET_MTRR #define X86_64_SET_MTRR X86_SET_MTRR -#define X86_64_VM86 X86_VM86 +#define X86_64_VM86 X86_VM86 #define X86_64_GET_GSBASE X86_GET_GSBASE -#define X86_64_GET_FSBASE X86_GET_FSBASE +#define X86_64_GET_FSBASE X86_GET_FSBASE #define X86_64_SET_GSBASE X86_SET_GSBASE -#define X86_64_SET_FSBASE X86_SET_FSBASE +#define X86_64_SET_FSBASE X86_SET_FSBASE #endif /* @@ -131,30 +131,30 @@ struct _X86_SYSARCH_L(set_ioperm_args) { }; struct _X86_SYSARCH_L(pmc_info_args) { - int type; - int flags; + int vers; + int type; + int flags; }; +#define PMC_VERSION 1 + #define PMC_TYPE_NONE 0 #define PMC_TYPE_I586 1 #define PMC_TYPE_I686 2 #define PMC_TYPE_K7 3 +#define PMC_TYPE_F10H 4 #define PMC_INFO_HASTSC 0x01 -#ifdef __i386__ #define PMC_NCOUNTERS 4 -#else -#define PMC_NCOUNTERS 2 -#endif struct _X86_SYSARCH_L(pmc_startstop_args) { - int counter; + uint32_t counter; uint64_t val; - uint8_t event; - uint8_t unit; - uint8_t compare; - uint8_t flags; + uint32_t event; + uint32_t unit; + uint32_t compare; + uint32_t flags; }; #define PMC_SETUP_KERNEL 0x01 diff --git a/usr.bin/pmc/pmc.c b/usr.bin/pmc/pmc.c index 928ee6559de7..44d898202d72 100644 --- a/usr.bin/pmc/pmc.c +++ b/usr.bin/pmc/pmc.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmc.c,v 1.18 2017/02/18 16:48:38 maxv Exp $ */ +/* $NetBSD: pmc.c,v 1.19 2017/03/08 16:42:27 maxv Exp $ */ /* * Copyright 2000 Wasabi Systems, Inc. @@ -37,7 +37,7 @@ #include #ifndef lint -__RCSID("$NetBSD: pmc.c,v 1.18 2017/02/18 16:48:38 maxv Exp $"); +__RCSID("$NetBSD: pmc.c,v 1.19 2017/03/08 16:42:27 maxv Exp $"); #endif #include @@ -426,6 +426,8 @@ main(int argc, char **argv) if (x86_pmc_info(&pmcinfo) < 0) errx(2, "PMC support is not compiled into the kernel"); + if (pmcinfo.vers != 1) + errx(2, "Wrong PMC version"); pncp = pmc_lookup_cpu(pmcinfo.type); if (pncp == NULL)