Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B5B5C433F5 for ; Tue, 30 Nov 2021 20:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343786AbhK3Ums (ORCPT ); Tue, 30 Nov 2021 15:42:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233340AbhK3Ums (ORCPT ); Tue, 30 Nov 2021 15:42:48 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1784C061746 for ; Tue, 30 Nov 2021 12:39:28 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id g19so21814295pfb.8 for ; Tue, 30 Nov 2021 12:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fBpsUP5CKk7s0uj08S+UkM336obzKaZtMzyYiDf1hEY=; b=OfFDrf4VmCwLGLX2gfKWZDsNVEmSiSQJW8psXUnnxekGgpVN3NVbBDC+/kjNIT7/fP zSyPRIyayrzypfNcKKp4uZ+GnGzUQG5Q9S1aqNOfyWAWGX0q6IUQbY2E9YiZRLL0HWSs qLHJg/GzdAseFQEh9A8bpnRYCXrS+n7RJ0O3O6C+eSmgNT+5FY2ZkXPO7Tdv2CRiyIph Zx+OmKK+0cwXSJ5Oe47OnrDznManNTHHRZF8rFPvebPLD3MY5FNW58zsLBSdgwOsVH54 5+30l/opb53A+3huptbU+5KNYNzlM7wZwF46yQyEBUfD+q5043eOBCDP5pdJPUnogjIl C8Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fBpsUP5CKk7s0uj08S+UkM336obzKaZtMzyYiDf1hEY=; b=TwuMoY8q2uWAh9Ts1SWq2vLdqETtSbu44tsvG+eAoDSVcM4YAFz8it3VuspxJ7LYCl edufQm5abBsOfZgizyt85DcOa/WWgDEaOhTaMKXphOTyAq7GhT9e1c3IlXRFmwJzBhY2 nheKhyPUBmxdWXdMVoTfG8klzC4NBchrd1SA0DYMYyLUe5jLoosqQ8trWA7NL+8letht EZeflEMADI8bRZ9bg3p+4B1FCrEoi/lP39Jo7U9r8SxSrAfDO5G+w6WnCl3LuqSXJsau xEkAaXD3lBITdalYCDi074tX1/URBCWLKMcKe7Uk9TDsvc0C+tm9Te8277eXtQgrRQJk bloQ== X-Gm-Message-State: AOAM532yYRP3txAoQHCNKasyrj0jcqvwWphYCyBxGVaevwfQ+Kb1kp+7 VZM7n45zwZ6SJuOROG3uA4Seng== X-Google-Smtp-Source: ABdhPJydBiJCdW+yjKkga6Nv7oxbzoVSFw2vGl/utAzNzOHiJc4lwvgc1LQyopdl0zVEHZDgS6CbPw== X-Received: by 2002:a63:78c:: with SMTP id 134mr1179791pgh.373.1638304767990; Tue, 30 Nov 2021 12:39:27 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id e10sm22543608pfv.140.2021.11.30.12.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 12:39:27 -0800 (PST) Date: Tue, 30 Nov 2021 20:39:24 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Ignat Korchagin Subject: Re: [PATCH] KVM: ensure APICv is considered inactive if there is no APIC Message-ID: References: <20211130123746.293379-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211130123746.293379-1-pbonzini@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 30, 2021, Paolo Bonzini wrote: > kvm_vcpu_apicv_active() returns false if a virtual machine has no in-kernel > local APIC, however kvm_apicv_activated might still be true if there are > no reasons to disable APICv; in fact it is quite likely that there is none > because APICv is inhibited by specific configurations of the local APIC > and those configurations cannot be programmed. This triggers a WARN: > > WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm) != kvm_vcpu_apicv_active(vcpu)); > > To avoid this, introduce another cause for APICv inhibition, namely the > absence of an in-kernel local APIC. This cause is enabled by default, > and is dropped by either KVM_CREATE_IRQCHIP or the enabling of > KVM_CAP_IRQCHIP_SPLIT. > > Reported-by: Ignat Korchagin > Fixes: ee49a8932971 ("KVM: x86: Move SVM's APICv sanity check to common x86", 2021-10-22) > Signed-off-by: Paolo Bonzini > --- Reviewed-by: Sean Christopherson > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 0ee1a039b490..e0aa4dd53c7f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -5740,6 +5740,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, > smp_wmb(); > kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT; > kvm->arch.nr_reserved_ioapic_pins = cap->args[0]; > + kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT); > r = 0; > split_irqchip_unlock: > mutex_unlock(&kvm->lock); > @@ -6120,6 +6121,7 @@ long kvm_arch_vm_ioctl(struct file *filp, > /* Write kvm->irq_routing before enabling irqchip_in_kernel. */ > smp_wmb(); > kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL; > + kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT); Blech, kvm_request_apicv_update() is very counter-intuitive, true == clear. :-/ Wrappers along the lines of kvm_{set,clear}_apicv_inhibit() would help a lot, and would likely avoid a handful of newlines as well. I'll send a patch on top of this, unless you want to do it while pushing this one out. > create_irqchip_unlock: > mutex_unlock(&kvm->lock); > break; > @@ -8818,10 +8820,9 @@ static void kvm_apicv_init(struct kvm *kvm) > { > init_rwsem(&kvm->arch.apicv_update_lock); > > - if (enable_apicv) > - clear_bit(APICV_INHIBIT_REASON_DISABLE, > - &kvm->arch.apicv_inhibit_reasons); > - else > + set_bit(APICV_INHIBIT_REASON_ABSENT, > + &kvm->arch.apicv_inhibit_reasons); Nit, this one fits on a single line. > + if (!enable_apicv) > set_bit(APICV_INHIBIT_REASON_DISABLE, > &kvm->arch.apicv_inhibit_reasons); > } > -- > 2.31.1 >