Skip to content

Commit eb7091b

Browse files
taoyuhongwenlingz
authored andcommitted
HV: add rdmsr/wrmsr debug cmd
Add these commands to HV console: 1.rdmsr [-p<pcpu_id>] [msr_index] read MSR register, eg., 'rdmsr 0xc8f' read MSR with address 0xc8f; 'rdmsr -p1 0xc8f' read MSR address 0xc8f, on PCPU1. 1.wrmsr [-p<pcpu_id>] [msr_index] [value] write to MSR register, eg., 'wrmsr 0xc8f 0x100000000' write 0x100000000 to MSR, which address is 0xc8f; 'wrmsr -p1 0xc8f 0x100000000' write 0x100000000 to MSR address 0xc8f, on PCPU1. Tracked-On: #2462 Signed-off-by: Tao Yuhong <yuhong.tao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 648450c commit eb7091b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

hypervisor/debug/shell.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static int32_t shell_show_ioapic_info(__unused int32_t argc, __unused char **arg
3333
static int32_t shell_loglevel(int32_t argc, char **argv);
3434
static int32_t shell_cpuid(int32_t argc, char **argv);
3535
static int32_t shell_trigger_crash(int32_t argc, char **argv);
36+
static int32_t shell_rdmsr(int32_t argc, char **argv);
37+
static int32_t shell_wrmsr(int32_t argc, char **argv);
3638

3739
static struct shell_cmd shell_cmds[] = {
3840
{
@@ -113,6 +115,18 @@ static struct shell_cmd shell_cmds[] = {
113115
.help_str = SHELL_CMD_REBOOT_HELP,
114116
.fcn = shell_trigger_crash,
115117
},
118+
{
119+
.str = SHELL_CMD_RDMSR,
120+
.cmd_param = SHELL_CMD_RDMSR_PARAM,
121+
.help_str = SHELL_CMD_RDMSR_HELP,
122+
.fcn = shell_rdmsr,
123+
},
124+
{
125+
.str = SHELL_CMD_WRMSR,
126+
.cmd_param = SHELL_CMD_WRMSR_PARAM,
127+
.help_str = SHELL_CMD_WRMSR_HELP,
128+
.fcn = shell_wrmsr,
129+
},
116130
};
117131

118132
/* The initial log level*/
@@ -1233,3 +1247,76 @@ static int32_t shell_trigger_crash(int32_t argc, char **argv)
12331247

12341248
return 0;
12351249
}
1250+
1251+
static int32_t shell_rdmsr(int32_t argc, char **argv)
1252+
{
1253+
uint16_t pcpu_id = 0;
1254+
int32_t ret = 0;
1255+
uint32_t msr_index = 0;
1256+
uint64_t val = 0;
1257+
char str[MAX_STR_SIZE] = {0};
1258+
1259+
pcpu_id = get_cpu_id();
1260+
1261+
switch (argc) {
1262+
case 3:
1263+
/* rdrmsr -p<PCPU_ID> <MSR_INDEX>*/
1264+
if ((argv[1][0] == '-') && (argv[1][1] == 'p')) {
1265+
pcpu_id = (uint16_t)strtol_deci(&(argv[1][2]));
1266+
msr_index = (uint32_t)strtoul_hex(argv[2]);
1267+
} else {
1268+
ret = -EINVAL;
1269+
}
1270+
break;
1271+
case 2:
1272+
/* rdmsr <MSR_INDEX> */
1273+
msr_index = (uint32_t)strtoul_hex(argv[1]);
1274+
break;
1275+
default:
1276+
ret = -EINVAL;
1277+
}
1278+
1279+
if (ret == 0) {
1280+
val = msr_read_pcpu(msr_index, pcpu_id);
1281+
snprintf(str, MAX_STR_SIZE, "rdmsr(0x%x):0x%llx\n", msr_index, val);
1282+
shell_puts(str);
1283+
}
1284+
1285+
return ret;
1286+
}
1287+
1288+
static int32_t shell_wrmsr(int32_t argc, char **argv)
1289+
{
1290+
uint16_t pcpu_id = 0;
1291+
int32_t ret = 0;
1292+
uint32_t msr_index = 0;
1293+
uint64_t val = 0;
1294+
1295+
pcpu_id = get_cpu_id();
1296+
1297+
switch (argc) {
1298+
case 4:
1299+
/* wrmsr -p<PCPU_ID> <MSR_INDEX> <VALUE>*/
1300+
if ((argv[1][0] == '-') && (argv[1][1] == 'p')) {
1301+
pcpu_id = (uint16_t)strtol_deci(&(argv[1][2]));
1302+
msr_index = (uint32_t)strtoul_hex(argv[2]);
1303+
val = strtoul_hex(argv[3]);
1304+
} else {
1305+
ret = -EINVAL;
1306+
}
1307+
break;
1308+
case 3:
1309+
/* wrmsr <MSR_INDEX> <VALUE>*/
1310+
msr_index = (uint32_t)strtoul_hex(argv[1]);
1311+
val = strtoul_hex(argv[2]);
1312+
break;
1313+
default:
1314+
ret = -EINVAL;
1315+
}
1316+
1317+
if (ret == 0) {
1318+
msr_write_pcpu(msr_index, val, pcpu_id);
1319+
}
1320+
1321+
return ret;
1322+
}

hypervisor/debug/shell_priv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,12 @@ struct shell {
8686
#define SHELL_CMD_CPUID "cpuid"
8787
#define SHELL_CMD_CPUID_PARAM "<leaf> [subleaf]"
8888
#define SHELL_CMD_CPUID_HELP "cpuid leaf [subleaf], in hexadecimal"
89+
90+
#define SHELL_CMD_RDMSR "rdmsr"
91+
#define SHELL_CMD_RDMSR_PARAM "[-p<pcpu_id>] <msr_index>"
92+
#define SHELL_CMD_RDMSR_HELP "rdmsr -p<pcpu_id> <msr_index>, msr_index in hexadecimal"
93+
94+
#define SHELL_CMD_WRMSR "wrmsr"
95+
#define SHELL_CMD_WRMSR_PARAM "[-p<pcpu_id>] <msr_index> <value>"
96+
#define SHELL_CMD_WRMSR_HELP "wrmsr -p<pcpu_id> <msr_index> <value>, msr_index and value in hexadecimal"
8997
#endif /* SHELL_PRIV_H */

0 commit comments

Comments
 (0)