Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp41085pxb; Wed, 18 Aug 2021 15:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynkiScmUtR9+2ZT0TzWhQ/nJNy5Y1cLx8hjbj6piT89iL4J94xKbz2iReXID7xCILTEMvZ X-Received: by 2002:a17:906:d7af:: with SMTP id pk15mr12103060ejb.51.1629325555754; Wed, 18 Aug 2021 15:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629325555; cv=none; d=google.com; s=arc-20160816; b=Z1VsoebnNTEWs1m6KYmNVzwDbwT6hv8Lp7/n6/Wr18F4ebBjHu9XvJXVCzisV0GLXl FuxA/GtJVY/1pLhdIgsL/+LLuHRJUp800+ONTKZP6mtmu15f/qxqF+0NwRzKUco4Mk21 Mh3JUcKfPxHCn9rrQLohcxkXnEbpj6F0CSsKX/0Ee5/wI9zB3+Pu03R5J0CTdZLDEl1R HOUjNHFrLjOmf2itRYoNqZ3jD9nYDmTzU3bBmK1pEhXqwaCsaCp49UX2omw69kbqoj8r qdfRGHygyGfexDIOFbYDYv9skOsMYCh0jUsuLjWYtAo0Xm+kp+6+yIQ6DosbstXgteS7 mxoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=63gVPEj1noUQl8SV7kXsZsczRwjyhAO39ZV+DC8YyRw=; b=MhSML6FSYRTP+MCA322AiLqhi3Ez4XDvYP/7+bV2De6Qes9+9OC/mu9vyyyes1hJdq rbQkH7stuxlvbY3s1T8M3GZU+iStFBp9kgm75tx2CMHWLPkiJDX04N57myP1XOD6p8B2 /CqbDZkmtHY2TWkPmS+L1z23Kb9euW8zKPW9axZlGpA+QuAmH0u5CBeR5jMVltMvwslw zy8nPJFY4ydg9YuZ+Hf+NDGnAcJkqPAiDuSd2PG4tz5LsVES8ZAsVJ2vC2AJ96KhFP15 6wT/hdB0RDC382WYrLen4UGOA/YIpeZkTDzyOwllejZjQBiWJxo62yasKiBRkrcz9hCs wVDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pVOi6N+y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si950927edr.294.2021.08.18.15.25.27; Wed, 18 Aug 2021 15:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pVOi6N+y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234586AbhHRWYd (ORCPT + 99 others); Wed, 18 Aug 2021 18:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232456AbhHRWYd (ORCPT ); Wed, 18 Aug 2021 18:24:33 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E470BC0613CF for ; Wed, 18 Aug 2021 15:23:57 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id x1so191251plg.10 for ; Wed, 18 Aug 2021 15:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=63gVPEj1noUQl8SV7kXsZsczRwjyhAO39ZV+DC8YyRw=; b=pVOi6N+ypgp22caV5JNSMiXFyj+4Go0ociFoiwmYF1UKaigF81J/i++Qt6xgDm0fVZ 0WOPkNXk72ny+7vUL5QIXYb4hH6U9Rst0RCj4UR6otmrtTG38yNbW30kXJ9bUQ1le8VJ bvergKmKhgpagDEnu/bataPp70vuy9xuZkXRbPbSfG6HAKosD4LRLt1TGZwQx8yGP5TA nBsRJyHkGbvCusf9+BK+HG6K6zdrCnOHoheePcgX7wUHJf9DdAQAku+kxAZmZd1B7roD WYksjgb5U+78tZo7OYG2QwTd2rfTY+LLll7qR6wrIerXFcxIyN6ZwgMCMRK3eSHthwPb d1Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=63gVPEj1noUQl8SV7kXsZsczRwjyhAO39ZV+DC8YyRw=; b=oFV1AajBnAy8oh/g3sdV12hhfci8GB8MZb6bYaXoS+Iyq/uxH1/7aZwdFNktSH1oQr uNGNh9VMe9PhehutTHFImQq7leDWUslZWUFoROjTXCnbJrr3gDfJjHoKr8NWdlis/X4i wF/x5HQ29xnJhdAjIFeVTcJFOAWYC8iYjh1exClwFcyzPYpyPKEAqF6YNlbENISrP/85 Gb0Br4paZjsDUEr83SBNXngYUM7LiwztutNAgagJXuMZbVnyegwdOPhCd1+bZVMh3YRF nIAEAdQeiZ/w1fIdN+p9LM/pWZPFwz2nV3cvdjnMR8SDZqKSzvHNVNYDNefH20dPWPty DRdg== X-Gm-Message-State: AOAM5327rqp/G4ExWdupEqvRtFjgZuzGZbw17PYyvOJYVlW8N58S8yzK CFVXpaKwA5BzTIi/bQJSmpkulw== X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr11327705pjb.42.1629325437205; Wed, 18 Aug 2021 15:23:57 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id q3sm934192pgl.23.2021.08.18.15.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:23:56 -0700 (PDT) Date: Wed, 18 Aug 2021 22:23:51 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: Paul Menzel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Ingo Molnar , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH] x86: kvm: Demote level of already loaded message from error to info Message-ID: References: <20210818114956.7171-1-pmenzel@molgen.mpg.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. From 3528e66bd5107d5ac4f6a6ae50503cf64446866a Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Wed, 18 Aug 2021 15:17:43 -0700 Subject: [PATCH] KVM: x86: Tweak handling and message when vendor module is already loaded Reword KVM's error message if a vendor module is already loaded to state exactly that instead of assuming "the other" module is loaded, ratelimit said message to match the other errors, and move the check down below the basic functionality checks so that attempting to load an unsupported module provides the same result regardless of whether or not a supported vendor module is already loaded. Reported-by: Paul Menzel Cc: Maciej S. Szmigiero Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fdc0c18339fb..15bd4bd3c81d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8357,12 +8357,6 @@ int kvm_arch_init(void *opaque) struct kvm_x86_init_ops *ops = opaque; int r; - if (kvm_x86_ops.hardware_enable) { - printk(KERN_ERR "kvm: already loaded the other module\n"); - r = -EEXIST; - goto out; - } - if (!ops->cpu_has_kvm_support()) { pr_err_ratelimited("kvm: no hardware support\n"); r = -EOPNOTSUPP; @@ -8374,6 +8368,12 @@ int kvm_arch_init(void *opaque) goto out; } + if (kvm_x86_ops.hardware_enable) { + pr_err_ratelimited("kvm: already loaded a vendor module\n"); + r = -EEXIST; + goto out; + } + /* * KVM explicitly assumes that the guest has an FPU and * FXSAVE/FXRSTOR. For example, the KVM_GET_FPU explicitly casts the -- 2.33.0.rc2.250.ged5fa647cd-goog