[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 2 Feb 2021 15:53:38 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Like Xu <like.xu@...ux.intel.com>,
Sean Christopherson <seanjc@...gle.com>
Cc: Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, ak@...ux.intel.com,
wei.w.wang@...el.com, kan.liang@...el.com,
alex.shi@...ux.alibaba.com, kvm@...r.kernel.org, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v14 11/11] selftests: kvm/x86: add test for pmu msr
MSR_IA32_PERF_CAPABILITIES
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
Powered by blists - more mailing lists