ia64/xen-unstable

changeset 11034:7c79d49033c6

[IA64] convert stats to perfc, get rid of unsafe hypercall

Convert remaining stat counter to perfc.
Get rid of unsafe hypercall.

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Mon Aug 14 13:20:40 2006 -0600 (2006-08-14)
parents 50837fb04807
children fa584e5d17b6
files xen/arch/ia64/xen/domain.c xen/arch/ia64/xen/faults.c xen/arch/ia64/xen/hypercall.c xen/arch/ia64/xen/privop.c xen/arch/ia64/xen/privop_stat.c xen/arch/ia64/xen/vcpu.c xen/arch/ia64/xen/vhpt.c xen/include/asm-ia64/config.h xen/include/asm-ia64/perfc.h xen/include/asm-ia64/perfc_defn.h xen/include/asm-ia64/privop_stat.h xen/include/asm-ia64/vhpt.h
line diff
     1.1 --- a/xen/arch/ia64/xen/domain.c	Mon Aug 14 11:46:40 2006 -0600
     1.2 +++ b/xen/arch/ia64/xen/domain.c	Mon Aug 14 13:20:40 2006 -0600
     1.3 @@ -47,7 +47,6 @@
     1.4  #include <asm/regionreg.h>
     1.5  #include <asm/dom_fw.h>
     1.6  #include <asm/shadow.h>
     1.7 -#include <asm/privop_stat.h>
     1.8  
     1.9  unsigned long dom0_size = 512*1024*1024;
    1.10  unsigned long dom0_align = 64*1024*1024;
     2.1 --- a/xen/arch/ia64/xen/faults.c	Mon Aug 14 11:46:40 2006 -0600
     2.2 +++ b/xen/arch/ia64/xen/faults.c	Mon Aug 14 13:20:40 2006 -0600
     2.3 @@ -26,7 +26,6 @@
     2.4  #include <asm/debugger.h>
     2.5  #include <asm/fpswa.h>
     2.6  #include <asm/bundle.h>
     2.7 -#include <asm/privop_stat.h>
     2.8  #include <asm/asm-xsi-offsets.h>
     2.9  #include <asm/shadow.h>
    2.10  
     3.1 --- a/xen/arch/ia64/xen/hypercall.c	Mon Aug 14 11:46:40 2006 -0600
     3.2 +++ b/xen/arch/ia64/xen/hypercall.c	Mon Aug 14 13:20:40 2006 -0600
     3.3 @@ -28,7 +28,6 @@
     3.4  #include <xen/domain.h>
     3.5  #include <public/callback.h>
     3.6  #include <xen/event.h>
     3.7 -#include <asm/privop_stat.h>
     3.8  
     3.9  static long do_physdev_op_compat(XEN_GUEST_HANDLE(physdev_op_t) uop);
    3.10  static long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg);
    3.11 @@ -275,11 +274,6 @@ fw_hypercall (struct pt_regs *regs)
    3.12  	return IA64_NO_FAULT;
    3.13  }
    3.14  
    3.15 -/* opt_unsafe_hypercall: If true, unsafe debugging hypercalls are allowed.
    3.16 -   These can create security hole.  */
    3.17 -static int opt_unsafe_hypercall = 0;
    3.18 -boolean_param("unsafe_hypercall", opt_unsafe_hypercall);
    3.19 -
    3.20  IA64FAULT
    3.21  ia64_hypercall (struct pt_regs *regs)
    3.22  {
    3.23 @@ -287,32 +281,6 @@ ia64_hypercall (struct pt_regs *regs)
    3.24  	unsigned long index = regs->r2;
    3.25  	int privlvl = (regs->cr_ipsr & IA64_PSR_CPL) >> IA64_PSR_CPL0_BIT;
    3.26  
    3.27 -	if (index >= FW_HYPERCALL_FIRST_USER) {
    3.28 -	    /* Note: user hypercalls are not safe, since Xen doesn't
    3.29 -	       check memory access privilege: Xen does not deny reading
    3.30 -	       or writing to kernel memory.  */
    3.31 -	    if (!opt_unsafe_hypercall) {
    3.32 -		printf("user xen/ia64 hypercalls disabled\n");
    3.33 -		regs->r8 = -1;
    3.34 -	    }
    3.35 -	    else switch (index) {
    3.36 -		case 0xffff:
    3.37 -			regs->r8 = dump_privop_counts_to_user(
    3.38 -				(char *) vcpu_get_gr(v,32),
    3.39 -				(int) vcpu_get_gr(v,33));
    3.40 -			break;
    3.41 -		case 0xfffe:
    3.42 -			regs->r8 = zero_privop_counts_to_user(
    3.43 -				(char *) vcpu_get_gr(v,32),
    3.44 -				(int) vcpu_get_gr(v,33));
    3.45 -			break;
    3.46 -		default:
    3.47 -			printf("unknown user xen/ia64 hypercall %lx\n", index);
    3.48 -			regs->r8 = do_ni_hypercall();
    3.49 -	    }
    3.50 -	    return IA64_NO_FAULT;
    3.51 -	}
    3.52 -
    3.53  	/* Hypercalls are only allowed by kernel.
    3.54  	   Kernel checks memory accesses.  */
    3.55  	if (VMX_DOMAIN(v) ? (privlvl != 0) : (privlvl != 2)) {
     4.1 --- a/xen/arch/ia64/xen/privop.c	Mon Aug 14 11:46:40 2006 -0600
     4.2 +++ b/xen/arch/ia64/xen/privop.c	Mon Aug 14 13:20:40 2006 -0600
     4.3 @@ -13,7 +13,6 @@
     4.4  #include <asm/dom_fw.h>
     4.5  #include <asm/vhpt.h>
     4.6  #include <asm/bundle.h>
     4.7 -#include <asm/privop_stat.h>
     4.8  
     4.9  long priv_verbose=0;
    4.10  unsigned long privop_trace = 0;
     5.1 --- a/xen/arch/ia64/xen/privop_stat.c	Mon Aug 14 11:46:40 2006 -0600
     5.2 +++ b/xen/arch/ia64/xen/privop_stat.c	Mon Aug 14 13:20:40 2006 -0600
     5.3 @@ -1,26 +1,55 @@
     5.4 +#include <xen/lib.h>
     5.5 +#include <public/xen.h>
     5.6 +#include <xen/perfc.h>
     5.7 +#include <asm/atomic.h>
     5.8  #include <asm/privop_stat.h>
     5.9 -#include <asm/vhpt.h>
    5.10 -#include <xen/lib.h>
    5.11 -#include <asm/uaccess.h>
    5.12  
    5.13 -#ifdef PRIVOP_ADDR_COUNT
    5.14 -#define PRIVOP_COUNT_NINSTS 2
    5.15 -#define PRIVOP_COUNT_NADDRS 30
    5.16 +#ifdef CONFIG_PRIVOP_ADDRS
    5.17  
    5.18  struct privop_addr_count {
    5.19 -	const char *instname;
    5.20  	unsigned long addr[PRIVOP_COUNT_NADDRS];
    5.21 -	unsigned long count[PRIVOP_COUNT_NADDRS];
    5.22 -	unsigned long overflow;
    5.23 +	unsigned int count[PRIVOP_COUNT_NADDRS];
    5.24 +	unsigned int overflow;
    5.25 +	atomic_t *perfc_addr;
    5.26 +	atomic_t *perfc_count;
    5.27 +	atomic_t *perfc_overflow;
    5.28  };
    5.29  
    5.30 +#undef  PERFCOUNTER
    5.31 +#define PERFCOUNTER(var, name)
    5.32  
    5.33 -static struct privop_addr_count privop_addr_counter[PRIVOP_COUNT_NINSTS] = {
    5.34 -	[_GET_IFA] = { "=ifa",  { 0 }, { 0 }, 0 },
    5.35 -	[_THASH] = { "thash", { 0 }, { 0 }, 0 }
    5.36 +#undef  PERFCOUNTER_CPU
    5.37 +#define PERFCOUNTER_CPU(var, name)
    5.38 +
    5.39 +#undef  PERFCOUNTER_ARRAY
    5.40 +#define PERFCOUNTER_ARRAY(var, name, size)
    5.41 +
    5.42 +#undef  PERFSTATUS
    5.43 +#define PERFSTATUS(var, name)
    5.44 +
    5.45 +#undef  PERFSTATUS_CPU
    5.46 +#define PERFSTATUS_CPU(var, name)
    5.47 +
    5.48 +#undef  PERFSTATUS_ARRAY
    5.49 +#define PERFSTATUS_ARRAY(var, name, size)
    5.50 +
    5.51 +#undef PERFPRIVOPADDR
    5.52 +#define PERFPRIVOPADDR(name)                        \
    5.53 +    {                                               \
    5.54 +        { 0 }, { 0 }, 0,                            \
    5.55 +        perfcounters.privop_addr_##name##_addr,     \
    5.56 +        perfcounters.privop_addr_##name##_count,    \
    5.57 +        perfcounters.privop_addr_##name##_overflow  \
    5.58 +    },
    5.59 +
    5.60 +static struct privop_addr_count privop_addr_counter[] = {
    5.61 +#include <asm/perfc_defn.h>
    5.62  };
    5.63  
    5.64 -void privop_count_addr(unsigned long iip, int inst)
    5.65 +#define PRIVOP_COUNT_NINSTS \
    5.66 +        (sizeof(privop_addr_counter) / sizeof(privop_addr_counter[0]))
    5.67 +
    5.68 +void privop_count_addr(unsigned long iip, enum privop_inst inst)
    5.69  {
    5.70  	struct privop_addr_count *v = &privop_addr_counter[inst];
    5.71  	int i;
    5.72 @@ -41,29 +70,28 @@ void privop_count_addr(unsigned long iip
    5.73  	v->overflow++;;
    5.74  }
    5.75  
    5.76 -static int dump_privop_addrs(char *buf)
    5.77 +void gather_privop_addrs(void)
    5.78  {
    5.79  	int i, j;
    5.80 -	char *s = buf;
    5.81 -	s += sprintf(s, "Privop addresses:\n");
    5.82 +	atomic_t *v;
    5.83  	for (i = 0; i < PRIVOP_COUNT_NINSTS; i++) {
    5.84 -		struct privop_addr_count *v = &privop_addr_counter[i];
    5.85 -		s += sprintf(s, "%s:\n", v->instname);
    5.86 -		for (j = 0; j < PRIVOP_COUNT_NADDRS; j++) {
    5.87 -			if (!v->addr[j])
    5.88 -				break;
    5.89 -			s += sprintf(s, " at 0x%lx #%ld\n",
    5.90 -			             v->addr[j], v->count[j]);
    5.91 -		}
    5.92 -		if (v->overflow) 
    5.93 -			s += sprintf(s, " other #%ld\n", v->overflow);
    5.94 +		/* Note: addresses are truncated!  */
    5.95 +		v = privop_addr_counter[i].perfc_addr;
    5.96 +		for (j = 0; j < PRIVOP_COUNT_NADDRS; j++)
    5.97 +			atomic_set(&v[j], privop_addr_counter[i].addr[j]);
    5.98 +
    5.99 +		v = privop_addr_counter[i].perfc_count;
   5.100 +		for (j = 0; j < PRIVOP_COUNT_NADDRS; j++)
   5.101 +			atomic_set(&v[j], privop_addr_counter[i].count[j]);
   5.102 +		
   5.103 +		atomic_set(privop_addr_counter[i].perfc_overflow,
   5.104 +		           privop_addr_counter[i].overflow);
   5.105  	}
   5.106 -	return s - buf;
   5.107  }
   5.108  
   5.109 -static void zero_privop_addrs(void)
   5.110 +void reset_privop_addrs(void)
   5.111  {
   5.112 -	int i,j;
   5.113 +	int i, j;
   5.114  	for (i = 0; i < PRIVOP_COUNT_NINSTS; i++) {
   5.115  		struct privop_addr_count *v = &privop_addr_counter[i];
   5.116  		for (j = 0; j < PRIVOP_COUNT_NADDRS; j++)
   5.117 @@ -119,30 +147,3 @@ static const char * const hyperpriv_str[
   5.118  	"=rr", "rr=", "kr=", "fc", "=cpuid", "=pmd", "=ar.eflg", "ar.eflg="
   5.119  };
   5.120  #endif
   5.121 -
   5.122 -#define TMPBUFLEN 8*1024
   5.123 -int dump_privop_counts_to_user(char __user *ubuf, int len)
   5.124 -{
   5.125 -	char buf[TMPBUFLEN];
   5.126 -	int n;
   5.127 -
   5.128 -	if (len < TMPBUFLEN)
   5.129 -		return -1;
   5.130 -
   5.131 -	n = 0;
   5.132 -#ifdef PRIVOP_ADDR_COUNT
   5.133 -	n += dump_privop_addrs(buf + n);
   5.134 -#endif
   5.135 -	n += dump_vhpt_stats(buf + n);
   5.136 -	if (__copy_to_user(ubuf,buf,n))
   5.137 -		return -1;
   5.138 -	return n;
   5.139 -}
   5.140 -
   5.141 -int zero_privop_counts_to_user(char __user *ubuf, int len)
   5.142 -{
   5.143 -#ifdef PRIVOP_ADDR_COUNT
   5.144 -	zero_privop_addrs();
   5.145 -#endif
   5.146 -	return 0;
   5.147 -}
     6.1 --- a/xen/arch/ia64/xen/vcpu.c	Mon Aug 14 11:46:40 2006 -0600
     6.2 +++ b/xen/arch/ia64/xen/vcpu.c	Mon Aug 14 13:20:40 2006 -0600
     6.3 @@ -473,7 +473,7 @@ IA64FAULT vcpu_get_iip(VCPU *vcpu, UINT6
     6.4  
     6.5  IA64FAULT vcpu_get_ifa(VCPU *vcpu, UINT64 *pval)
     6.6  {
     6.7 -	PRIVOP_COUNT_ADDR(vcpu_regs(vcpu),_GET_IFA);
     6.8 +	PRIVOP_COUNT_ADDR(vcpu_regs(vcpu), privop_inst_get_ifa);
     6.9  	*pval = PSCB(vcpu,ifa);
    6.10  	return (IA64_NO_FAULT);
    6.11  }
    6.12 @@ -540,7 +540,7 @@ IA64FAULT vcpu_get_iim(VCPU *vcpu, UINT6
    6.13  
    6.14  IA64FAULT vcpu_get_iha(VCPU *vcpu, UINT64 *pval)
    6.15  {
    6.16 -	PRIVOP_COUNT_ADDR(vcpu_regs(vcpu),_THASH);
    6.17 +	PRIVOP_COUNT_ADDR(vcpu_regs(vcpu), privop_inst_thash);
    6.18  	*pval = PSCB(vcpu,iha);
    6.19  	return (IA64_NO_FAULT);
    6.20  }
     7.1 --- a/xen/arch/ia64/xen/vhpt.c	Mon Aug 14 11:46:40 2006 -0600
     7.2 +++ b/xen/arch/ia64/xen/vhpt.c	Mon Aug 14 13:20:40 2006 -0600
     7.3 @@ -261,13 +261,12 @@ void flush_tlb_mask(cpumask_t mask)
     7.4              (cpu, (void (*)(void *))flush_tlb_vhpt_all, NULL, 1, 1);
     7.5  }
     7.6  
     7.7 -int dump_vhpt_stats(char *buf)
     7.8 +#ifdef PERF_COUNTERS
     7.9 +void gather_vhpt_stats(void)
    7.10  {
    7.11  	int i, cpu;
    7.12 -	char *s = buf;
    7.13  
    7.14 -	s += sprintf(s,"VHPT usage (%ld entries):\n",
    7.15 -		     (unsigned long) VHPT_NUM_ENTRIES);
    7.16 +	perfc_set(vhpt_nbr_entries, VHPT_NUM_ENTRIES);
    7.17  
    7.18  	for_each_present_cpu (cpu) {
    7.19  		struct vhpt_lf_entry *v = __va(per_cpu(vhpt_paddr, cpu));
    7.20 @@ -276,8 +275,7 @@ int dump_vhpt_stats(char *buf)
    7.21  		for (i = 0; i < VHPT_NUM_ENTRIES; i++, v++)
    7.22  			if (!(v->ti_tag & INVALID_TI_TAG))
    7.23  				vhpt_valid++;
    7.24 -		s += sprintf(s,"  cpu %d: %ld\n", cpu, vhpt_valid);
    7.25 +		perfc_seta(vhpt_valid_entries, cpu, vhpt_valid);
    7.26  	}
    7.27 -
    7.28 -	return s - buf;
    7.29  }
    7.30 +#endif
     8.1 --- a/xen/include/asm-ia64/config.h	Mon Aug 14 11:46:40 2006 -0600
     8.2 +++ b/xen/include/asm-ia64/config.h	Mon Aug 14 13:20:40 2006 -0600
     8.3 @@ -37,6 +37,12 @@
     8.4  
     8.5  #define MAX_DMADOM_PFN (0x7FFFFFFFUL >> PAGE_SHIFT) /* 31 addressable bits */
     8.6  
     8.7 +/* If PERFC is used, include privop maps.  */
     8.8 +#ifdef PERF_COUNTERS
     8.9 +#define CONFIG_PRIVOP_ADDRS
    8.10 +#define PRIVOP_COUNT_NADDRS 30
    8.11 +#endif
    8.12 +
    8.13  #ifndef __ASSEMBLY__
    8.14  
    8.15  // can't find where this typedef was before?!?
     9.1 --- a/xen/include/asm-ia64/perfc.h	Mon Aug 14 11:46:40 2006 -0600
     9.2 +++ b/xen/include/asm-ia64/perfc.h	Mon Aug 14 13:20:40 2006 -0600
     9.3 @@ -1,16 +1,22 @@
     9.4  #ifndef __ASM_PERFC_H__
     9.5  #define __ASM_PERFC_H__
     9.6  
     9.7 -static inline void arch_perfc_printall (void)
     9.8 +#include <asm/vhpt.h>
     9.9 +#include <asm/privop_stat.h>
    9.10 +
    9.11 +static inline void arch_perfc_printall(void)
    9.12  {
    9.13  }
    9.14  
    9.15 -static inline void arch_perfc_reset (void)
    9.16 +static inline void arch_perfc_reset(void)
    9.17  {
    9.18 +  reset_privop_addrs();
    9.19  }
    9.20  
    9.21 -static inline void arch_perfc_gather (void)
    9.22 +static inline void arch_perfc_gather(void)
    9.23  {
    9.24 +  gather_vhpt_stats();
    9.25 +  gather_privop_addrs();
    9.26  }
    9.27  
    9.28  #endif
    10.1 --- a/xen/include/asm-ia64/perfc_defn.h	Mon Aug 14 11:46:40 2006 -0600
    10.2 +++ b/xen/include/asm-ia64/perfc_defn.h	Mon Aug 14 13:20:40 2006 -0600
    10.3 @@ -40,3 +40,20 @@ PERFCOUNTER_ARRAY(fast_hyperprivop,   "f
    10.4  
    10.5  PERFCOUNTER_ARRAY(slow_reflect,       "slow reflection", 0x80)
    10.6  PERFCOUNTER_ARRAY(fast_reflect,       "fast reflection", 0x80)
    10.7 +
    10.8 +PERFSTATUS(vhpt_nbr_entries,          "nbr of entries per VHPT")
    10.9 +PERFSTATUS_CPU(vhpt_valid_entries,    "nbr of valid entries in VHPT")
   10.10 +
   10.11 +#ifdef CONFIG_PRIVOP_ADDRS
   10.12 +#ifndef PERFPRIVOPADDR
   10.13 +#define PERFPRIVOPADDR(name) \
   10.14 +PERFSTATUS_ARRAY(privop_addr_##name##_addr, "privop-addrs addr " #name, \
   10.15 +                 PRIVOP_COUNT_NADDRS) \
   10.16 +PERFSTATUS_ARRAY(privop_addr_##name##_count, "privop-addrs count " #name, \
   10.17 +                 PRIVOP_COUNT_NADDRS) \
   10.18 +PERFSTATUS(privop_addr_##name##_overflow, "privop-addrs overflow " #name)
   10.19 +#endif
   10.20 +
   10.21 +PERFPRIVOPADDR(get_ifa)
   10.22 +PERFPRIVOPADDR(thash)
   10.23 +#endif
    11.1 --- a/xen/include/asm-ia64/privop_stat.h	Mon Aug 14 11:46:40 2006 -0600
    11.2 +++ b/xen/include/asm-ia64/privop_stat.h	Mon Aug 14 13:20:40 2006 -0600
    11.3 @@ -1,22 +1,46 @@
    11.4  #ifndef _XEN_UA64_PRIVOP_STAT_H
    11.5  #define _XEN_UA64_PRIVOP_STAT_H
    11.6 -#include <public/arch-ia64.h>
    11.7 +#include <asm/config.h>
    11.8 +
    11.9 +#ifdef CONFIG_PRIVOP_ADDRS
   11.10 +
   11.11 +extern void gather_privop_addrs(void);
   11.12 +extern void reset_privop_addrs(void);
   11.13  
   11.14 -extern int dump_privop_counts_to_user(char *, int);
   11.15 -extern int zero_privop_counts_to_user(char *, int);
   11.16 +#undef  PERFCOUNTER
   11.17 +#define PERFCOUNTER(var, name)
   11.18  
   11.19 -#define PRIVOP_ADDR_COUNT
   11.20 +#undef  PERFCOUNTER_CPU
   11.21 +#define PERFCOUNTER_CPU(var, name)
   11.22 +
   11.23 +#undef  PERFCOUNTER_ARRAY
   11.24 +#define PERFCOUNTER_ARRAY(var, name, size)
   11.25  
   11.26 -#ifdef PRIVOP_ADDR_COUNT
   11.27 +#undef  PERFSTATUS
   11.28 +#define PERFSTATUS(var, name)
   11.29 +
   11.30 +#undef  PERFSTATUS_CPU
   11.31 +#define PERFSTATUS_CPU(var, name)
   11.32 +
   11.33 +#undef  PERFSTATUS_ARRAY
   11.34 +#define PERFSTATUS_ARRAY(var, name, size)
   11.35  
   11.36 -/* INST argument of PRIVOP_COUNT_ADDR.  */
   11.37 -#define _GET_IFA 0
   11.38 -#define _THASH 1
   11.39 +#undef  PERFPRIVOPADDR
   11.40 +#define PERFPRIVOPADDR(name) privop_inst_##name,
   11.41 +
   11.42 +enum privop_inst {
   11.43 +#include <asm/perfc_defn.h>
   11.44 +};
   11.45 +
   11.46 +#undef PERFPRIVOPADDR
   11.47 +
   11.48  #define	PRIVOP_COUNT_ADDR(regs,inst) privop_count_addr(regs->cr_iip,inst)
   11.49 -extern void privop_count_addr(unsigned long addr, int inst);
   11.50 +extern void privop_count_addr(unsigned long addr, enum privop_inst inst);
   11.51  
   11.52  #else
   11.53 -#define	PRIVOP_COUNT_ADDR(x,y) do {} while (0)
   11.54 +#define PRIVOP_COUNT_ADDR(x,y) do {} while (0)
   11.55 +#define gather_privop_addrs() do {} while (0)
   11.56 +#define reset_privop_addrs() do {} while (0)
   11.57  #endif
   11.58  
   11.59  #endif /* _XEN_UA64_PRIVOP_STAT_H */
    12.1 --- a/xen/include/asm-ia64/vhpt.h	Mon Aug 14 11:46:40 2006 -0600
    12.2 +++ b/xen/include/asm-ia64/vhpt.h	Mon Aug 14 13:20:40 2006 -0600
    12.3 @@ -32,7 +32,7 @@ struct vhpt_lf_entry {
    12.4  #define INVALID_TI_TAG 0x8000000000000000L
    12.5  
    12.6  extern void vhpt_init (void);
    12.7 -extern int dump_vhpt_stats(char *buf);
    12.8 +extern void gather_vhpt_stats(void);
    12.9  extern void vhpt_multiple_insert(unsigned long vaddr, unsigned long pte,
   12.10  				 unsigned long logps);
   12.11  extern void vhpt_insert (unsigned long vadr, unsigned long pte,