Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3708301pxv; Mon, 19 Jul 2021 06:59:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+g0OqnCEmsaJCE2sxxsgx87QaufUYeezfcMwErU9E9LIWTT8vcHffeh0lxx1HAXRHiggJ X-Received: by 2002:a05:6638:4115:: with SMTP id ay21mr20248409jab.13.1626703179625; Mon, 19 Jul 2021 06:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626703179; cv=none; d=google.com; s=arc-20160816; b=SXRwttzawNsnw1AUsfpBSXjfaI9UGHX69MaX786FMSIRv7cGYcTH+M1jHWANLLjFBN QGxYyDAYkox2Xn0khdc1gAb2rOJG2aqKibGImNWSnnm6h5xWnGOLRFn7TsIxzEz6vk5i CmPf+1GsFDXT5qQDpPvRDT+6VEywT7hssouxoI/hfwMUu9wGFJNGxuYvE6tEUe+TfZgz /THPcp05S2N+45aVAwZl0zE1QMirRRklK5Xs5vSDk1kyjjBhCJFBVLIRnu7GuLyEk8H3 Ne4giGkrRE9XY/dyOlVy+XunL5JCSd5FUxIFBg8DajH6lVb2CkAdl+gSib0HeVFGAKI8 KFoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=FSsNgc3FXhuejogM0XmHxCm/t5uymckMKilt3/jtVjE=; b=GEwcVxMOsms8wfYWb4xy476eJd41/snNUPHtYzkOsVT+ce8xaSYKdRfgTOQ0pzOiBe XkxApZi3Ioy/Gb/sh/AtpcrKv3/SprUBfb2XoXrBFkfEG2PhzT+hSgiO1p/kxL/xmfA8 K/dCXM/ALox306dAHm7nMHYjHxvlLt2BHcmIfkLxRDfs33zC4MSdqtOKZ/mRHYaB7MYJ ppzIIfsMNYaMn1B9h0TLTb0qAocisNv8X2M6eljh98DsqYXWoWhaTPfH/BB/ipfUt/Ra piNwxhpSLS+iYlEIXs/wkBSD50UciKAiwBYU1u9cyB/NXY4FHVgI/x8icxFF6iWINDg0 FZAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LBJoo111; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k12si20443719ilc.36.2021.07.19.06.59.27; Mon, 19 Jul 2021 06:59:39 -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=@redhat.com header.s=mimecast20190719 header.b=LBJoo111; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240822AbhGSNRp (ORCPT + 99 others); Mon, 19 Jul 2021 09:17:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50692 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237309AbhGSNRo (ORCPT ); Mon, 19 Jul 2021 09:17:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626703103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FSsNgc3FXhuejogM0XmHxCm/t5uymckMKilt3/jtVjE=; b=LBJoo111WkdNq4kX+FiyckXeFIfvqZChFcWLKgVpERzohJS+8ESKdQvYGSQGTrZZVLLwuC ketZ/srUsoDC4KGGsmkh8RfpgRpdxAbB+cTIG+6xveQpo+byYhyaplbNCYqfo+CDap/1kz JUp7F7o2vwMs8QBtM5N+Ju/ygfcTM9M= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-203-ZYpF9H_jPJKIJKwlBEmWcA-1; Mon, 19 Jul 2021 09:58:22 -0400 X-MC-Unique: ZYpF9H_jPJKIJKwlBEmWcA-1 Received: by mail-ed1-f70.google.com with SMTP id eg53-20020a05640228b5b02903ad3cc35040so7940535edb.11 for ; Mon, 19 Jul 2021 06:58:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FSsNgc3FXhuejogM0XmHxCm/t5uymckMKilt3/jtVjE=; b=n77wRmed46gG0Nfu77nCPgHubvasPWOX3cGTDCKzDalk/Hj8nTwd93DQne3QDRWgvo eQBW5YYRf96yCQAsKFOSNY9PgxWF39D/iqRPZZq5IACjoPuMK0AWWTYS13KGbiJLdo43 FN+gDEZdoHsh3XWdTH2TrwvNavo8jW2fukuXXqYJAXNUovje5scFDAzTNgxH58c/YD5e ECVz1yHrzYVHOuxYaSaMILWZRGiyobbF3zgRiFj4jL1JJehlZxa2/B8u3Kal3vsHDwMs KD6DZ30K9691jb84ZyvIta52Lf7ZIqZgAMXSNi+6jbQe89aAygevSS66BhKKymGFlxDN AFSA== X-Gm-Message-State: AOAM531VAcNFNhSi+6KDwVnCy9qnCz2M2d9HHazeB9cE4yxA3EI+VsCf tfn/WNJKW99zVP5eK0TlhsWvk5pKU39jiDsRJ2zJl7MPSyctEh03CaUqeHgLiv+kWlDw8scdFgs ZKFGrrzDg74u81PGs2CLGdw8V X-Received: by 2002:a05:6402:2023:: with SMTP id ay3mr34167624edb.383.1626703100290; Mon, 19 Jul 2021 06:58:20 -0700 (PDT) X-Received: by 2002:a05:6402:2023:: with SMTP id ay3mr34167600edb.383.1626703100099; Mon, 19 Jul 2021 06:58:20 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a5sm7793388edj.20.2021.07.19.06.58.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jul 2021 06:58:19 -0700 (PDT) Subject: Re: [PATCH 6/6] KVM: VMX: enable IPI virtualization To: Zeng Guang , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , Dave Hansen , "Luck, Tony" , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , "Huang, Kai" Cc: "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "Hu, Robert" , "Gao, Chao" , Emanuele Giuseppe Esposito References: <20210716064808.14757-1-guang.zeng@intel.com> <20210716064808.14757-7-guang.zeng@intel.com> <8aed2541-082d-d115-09ac-e7fcc05f96dc@redhat.com> <89f240cb-cb3a-c362-7ded-ee500cc12dc3@intel.com> <0d6f7852-95b3-d628-955b-f44d88a86478@redhat.com> <949abcb7-5f24-2107-a089-5e6c1bee8cf2@intel.com> From: Paolo Bonzini Message-ID: <223af27a-2412-40f6-f4a6-e0a662041855@redhat.com> Date: Mon, 19 Jul 2021 15:58:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <949abcb7-5f24-2107-a089-5e6c1bee8cf2@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/07/21 14:38, Zeng Guang wrote: >> Understood, but in practice all uses of vmx->ipiv_active are >> guarded by kvm_vcpu_apicv_active so they are always reached with >> vmx->ipiv_active == enable_ipiv. >> >> The one above instead seems wrong and should just use enable_ipiv. > > enable_ipiv associate with "IPI virtualization" setting in tertiary > exec controls and enable_apicv which depends on cpu_has_vmx_apicv(). > kvm_vcpu_apicv_active still can be false even if enable_ipiv is true, > e.g. in case irqchip not emulated in kernel. Right, kvm_vcpu_apicv_active *is* set in init_vmcs. But there's an "if (kvm_vcpu_apicv_active(&vmx->vcpu))" above. You can just stick if (enable_ipicv) install_pid(vmx); inside there. As to the other occurrences of vmx->ipiv_active, look here: > + if (!kvm_vcpu_apicv_active(vcpu)) > + return; > + > + if ((!kvm_arch_has_assigned_device(vcpu->kvm) || > + !irq_remapping_cap(IRQ_POSTING_CAP)) && > + !to_vmx(vcpu)->ipiv_active) > return; > This one can be enable_ipiv because APICv must be active. > + if (!kvm_vcpu_apicv_active(vcpu)) > + return 0; > + > + /* Put vCPU into a list and set NV to wakeup vector if it is > + * one of the following cases: > + * 1. any assigned device is in use. > + * 2. IPI virtualization is enabled. > + */ > + if ((!kvm_arch_has_assigned_device(vcpu->kvm) || > + !irq_remapping_cap(IRQ_POSTING_CAP)) && !to_vmx(vcpu)->ipiv_active) > return 0; This one can be !enable_ipiv because APICv must be active. > > @@ -3870,6 +3877,8 @@ static void vmx_update_msr_bitmap_x2apic(struct kvm_vcpu *vcpu, u8 mode) > vmx_enable_intercept_for_msr(vcpu, X2APIC_MSR(APIC_TMCCT), MSR_TYPE_RW); > vmx_disable_intercept_for_msr(vcpu, X2APIC_MSR(APIC_EOI), MSR_TYPE_W); > vmx_disable_intercept_for_msr(vcpu, X2APIC_MSR(APIC_SELF_IPI), MSR_TYPE_W); > + vmx_set_intercept_for_msr(vcpu, X2APIC_MSR(APIC_ICR), > + MSR_TYPE_RW, !to_vmx(vcpu)->ipiv_active); > } > } Is inside "if (mode & MSR_BITMAP_MODE_X2APIC_APICV)" so APICv must be activ; so it can be enable_ipiv as well. In conclusion, you do not need vmx->ipiv_active. Paolo