On 01/02/21 07:01, Like Xu wrote:
+uint64_t rdmsr_on_cpu(uint32_t reg) +{ + uint64_t data; + int fd; + char msr_file[64]; + + sprintf(msr_file, "/dev/cpu/%d/msr", 0); + fd = open(msr_file, O_RDONLY); + if (fd < 0) + exit(KSFT_SKIP); + + if (pread(fd, &data, sizeof(data), reg) != sizeof(data)) + exit(KSFT_SKIP); + + close(fd); + return data; +}
In order to allow running as non-root, it's better to use the KVM_GET_MSRS ioctl on the /dev/kvm file descriptor.
The tests pass, but please take a look at the kvm/queue branch to see if everything is ok.
Paolo