Re: [PATCH] x86: kvm: Demote level of already loaded message from error to info

From: Sean Christopherson
Date: Wed Aug 18 2021 - 18:24:01 EST


On Wed, Aug 18, 2021, Maciej S. Szmigiero wrote:
> On 18.08.2021 13:49, Paul Menzel wrote:
> > In scripts, running
> >
> > modprobe kvm_amd 2>/dev/null
> > modprobe kvm_intel 2>/dev/null
> >
> > to ensure the modules are loaded causes Linux to log errors.
> >
> > $ dmesg --level=err
> > [ 0.641747] [Firmware Bug]: TSC_DEADLINE disabled due to Errata; please update microcode to version: 0x3a (or later)
> > [ 40.196868] kvm: already loaded the other module
> > [ 40.219857] kvm: already loaded the other module
> > [ 55.501362] kvm [1177]: vcpu0, guest rIP: 0xffffffff96e5b644 disabled perfctr wrmsr: 0xc2 data 0xffff
> > [ 56.397974] kvm [1418]: vcpu0, guest rIP: 0xffffffff81046158 disabled perfctr wrmsr: 0xc1 data 0xabcd
> > [1007981.827781] kvm: already loaded the other module
> > [1008000.394089] kvm: already loaded the other module
> > [1008030.706999] kvm: already loaded the other module
> > [1020396.054470] kvm: already loaded the other module
> > [1020405.614774] kvm: already loaded the other module
> > [1020410.140069] kvm: already loaded the other module
> > [1020704.049231] kvm: already loaded the other module
> >
> > As one of the two KVM modules is already loaded, KVM is functioning, and
> > their is no error condition. Therefore, demote the log message level to
> > informational.

Hrm, but there is an error condition. Userspace explicitly requested something
and KVM couldn't satisfy the request.

KVM is also going to complain at level=err one way or another, e.g. if a script
probes kvm_amd before kvm_intel on an Intel CPU it's going to get "kvm: no hardware
support", so this isn't truly fixing the problem. Is the issue perhaps that this
particular message isn't ratelimited?

It's also easy for the script to grep /proc/cpuinfo, so it's hard to feel too
bad about the kludgy message, e.g. look for a specific vendor, 'vmx' or 'svm', etc...

if [[ -z $kvm ]]; then
grep vendor_id "/proc/cpuinfo" | grep -q AuthenticAMD
if [[ $? -eq 0 ]]; then
kvm=kvm_amd
else
kvm=kvm_intel
fi
fi


> Shouldn't this return ENODEV when loading one of these modules instead
> as there is no hardware that supports both VMX and SVM?

Probably not, as KVM would effectively be speculating, e.g. someone could load an
out-of-tree variant of kvm_{intel,amd}. Maybe instead of switching to ENODEV,
reword the comment, make it ratelimited, and shove it down? That way the message
and -EEXIST fires iff the vendor module actually has some chance of being loaded.