Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3614528ybl; Mon, 3 Feb 2020 03:32:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxViqck1AWWWKjU5orWfNxJOIXAxB6C3p2H0pk3efxekN4jO7Yfb7w2XSN5ZEG7BlYqG9w7 X-Received: by 2002:a54:4117:: with SMTP id l23mr13776550oic.140.1580729536231; Mon, 03 Feb 2020 03:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580729536; cv=none; d=google.com; s=arc-20160816; b=s6Z+0SjDuW5JYtgCuHG1AMBKM4cZsJ+Gr5t7QXQKQPXXm8PWxSnImTDeZ8KX7b5hX+ fjt9JlxbtIkf9AIb4GOrsYjTCLQsC8senzEG8fjsxLALpAIePNXXg/KyHAq6FfJ9aOCZ 8DdiGpfe0zGi9zlAfqvW6gWM3GvM/aoLFi3flb5xSj4ll4HMHa7sXdt17P87LauZCmQE QaKgDOyZAl1a/fDLKN2nsOP0NysflgdLwgPgew9erfxWW9yFT7IyHJbxw0PLl67nrskA XgVNgu4Rp33Tab0/LZ/K0R66kBryqDnr0fybxS8TA2XFYlfDOf0AtQzzp8JbZBXoAX3i lPwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=pzqUysm6XclWAatODuaOEu/wUw5kSI/bubUSt/jY4N8=; b=pY0QZG2mW5BR/BoTeCrS2nH4psmd5kvZCQeH0nom019VAMIC7WKeMoCQVfMekOMMDB Vt64//bxdXxPcxzt7CG5f3tCX9zhIc64UFwLbnwxp0eCtpzcxqIHh/x+HLHvvaBKhABe 2CRsOUedAF3qu8T+OC/kOeLm1dVAsNCKkG9skF4ps2IA/z1w4RzhSfRoSm7xHRGnzH1w S7HWA8i/4KnIWpxEcyEU02fMQqCLx6yX163MA6LZqXd+atLDFOSytWe6S8IRqPvdkApx lEeQIshCbLYvE1t2TBCZ0sOx8iyIiveZn0cYNv3FwF7UPEymn6DbD3JMcARhb7xA+Knc ThFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si8084246oih.206.2020.02.03.03.32.03; Mon, 03 Feb 2020 03:32:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727834AbgBCKP4 (ORCPT + 99 others); Mon, 3 Feb 2020 05:15:56 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:40270 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727389AbgBCKP4 (ORCPT ); Mon, 3 Feb 2020 05:15:56 -0500 Received: from 189-68-179-241.dsl.telesp.net.br ([189.68.179.241] helo=calabresa) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iyYlF-0006lq-8V; Mon, 03 Feb 2020 10:15:21 +0000 Date: Mon, 3 Feb 2020 07:15:14 -0300 From: Thadeu Lima de Souza Cascardo To: Vitaly Kuznetsov Cc: pbonzini@redhat.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] x86/kvm: do not setup pv tlb flush when not paravirtualized Message-ID: <20200203101514.GG40679@calabresa> References: <20200131155655.49812-1-cascardo@canonical.com> <87wo94ng9d.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wo94ng9d.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 03, 2020 at 10:59:10AM +0100, Vitaly Kuznetsov wrote: > Thadeu Lima de Souza Cascardo writes: > > > kvm_setup_pv_tlb_flush will waste memory and print a misguiding message > > when KVM paravirtualization is not available. > > > > Intel SDM says that the when cpuid is used with EAX higher than the > > maximum supported value for basic of extended function, the data for the > > highest supported basic function will be returned. > > > > So, in some systems, kvm_arch_para_features will return bogus data, > > causing kvm_setup_pv_tlb_flush to detect support for pv tlb flush. > > > > Testing for kvm_para_available will work as it checks for the hypervisor > > signature. > > > > Besides, when the "nopv" command line parameter is used, it should not > > continue as well, as kvm_guest_init will no be called in that case. > > > > Signed-off-by: Thadeu Lima de Souza Cascardo > > --- > > arch/x86/kernel/kvm.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > > index 81045aabb6f4..d817f255aed8 100644 > > --- a/arch/x86/kernel/kvm.c > > +++ b/arch/x86/kernel/kvm.c > > @@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) > > { > > int cpu; > > > > + if (!kvm_para_available() || nopv) > > + return 0; > > + > > if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && > > !kvm_para_has_hint(KVM_HINTS_REALTIME) && > > kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { > > The patch will fix the immediate issue, but why kvm_setup_pv_tlb_flush() > is just an arch_initcall() which will be executed regardless of the fact > if we are running on KVM or not? > > In Hyper-V we setup PV TLB flush from ms_hyperv_init_platform() -- which > only happens if Hyper-V platform was detected. Why don't we do it from > kvm_init_platform() in KVM? > > -- > Vitaly > Because we can't call the allocator that early. Also, see the thread where this was "decided", the v6 of the original patch: https://lore.kernel.org/kvm/20171129162118.GA10661@flask/ Regards. Cascardo.