Print this page
11844 add rdmsr utility
Reviewed by: Dan McDonald <danmcd@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/cpuid_drv.c
          +++ new/usr/src/uts/common/io/cpuid_drv.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   */
  24   24  /*
  25      - * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
       25 + * Copyright 2019 Joyent, Inc.
  26   26   */
  27   27  
  28   28  
  29   29  #include <sys/types.h>
  30   30  #include <sys/file.h>
  31   31  #include <sys/errno.h>
  32   32  #include <sys/open.h>
  33   33  #include <sys/cred.h>
  34   34  #include <sys/conf.h>
  35   35  #include <sys/stat.h>
  36   36  #include <sys/processor.h>
  37   37  #include <sys/cpuvar.h>
  38   38  #include <sys/kmem.h>
  39   39  #include <sys/modctl.h>
  40   40  #include <sys/ddi.h>
  41   41  #include <sys/sunddi.h>
       42 +#include <sys/policy.h>
  42   43  
  43   44  #include <sys/auxv.h>
  44   45  #include <sys/cpuid_drv.h>
  45   46  #include <sys/systeminfo.h>
  46   47  
  47   48  #if defined(__x86)
  48   49  #include <sys/x86_archext.h>
  49   50  #endif
  50   51  
  51   52  static dev_info_t *cpuid_devi;
↓ open down ↓ 124 lines elided ↑ open up ↑
 176  177                  } else {
 177  178                          STRUCT_FSET(h, cgh_hwcap[0], 0);
 178  179                          STRUCT_FSET(h, cgh_hwcap[1], 0);
 179  180                  }
 180  181                  if (ddi_copyout(STRUCT_BUF(h),
 181  182                      (void *)arg, STRUCT_SIZE(h), mode))
 182  183                          return (EFAULT);
 183  184                  return (0);
 184  185          }
 185  186  
      187 +#ifdef __x86
      188 +        case CPUID_RDMSR: {
      189 +                struct cpuid_rdmsr crm = { 0, };
      190 +                label_t label;
      191 +
      192 +                if (secpolicy_sys_config(cr, B_FALSE) != 0)
      193 +                        return (EPERM);
      194 +
      195 +                if (ddi_copyin((void *)arg, &crm, sizeof (crm), mode))
      196 +                        return (EFAULT);
      197 +
      198 +                kpreempt_disable();
      199 +
      200 +                if (on_fault(&label)) {
      201 +                        kpreempt_enable();
      202 +                        return (ENOENT);
      203 +                }
      204 +
      205 +                crm.cr_msr_val = rdmsr(crm.cr_msr_nr);
      206 +
      207 +                no_fault();
      208 +                kpreempt_enable();
      209 +
      210 +                if (ddi_copyout(&crm, (void *)arg, sizeof (crm), mode))
      211 +                        return (EFAULT);
      212 +                return (0);
      213 +        }
      214 +#endif
      215 +
 186  216          default:
 187  217                  return (ENOTTY);
 188  218          }
 189  219  }
 190  220  
 191  221  static struct cb_ops cpuid_cb_ops = {
 192  222          cpuid_open,
 193  223          nulldev,        /* close */
 194  224          nodev,          /* strategy */
 195  225          nodev,          /* print */
↓ open down ↓ 56 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX