Messages in this thread | | | Subject | Re: [PATCH v14 11/11] selftests: kvm/x86: add test for pmu msr MSR_IA32_PERF_CAPABILITIES | From | Paolo Bonzini <> | Date | Tue, 2 Feb 2021 15:53:38 +0100 |
| |
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
| |