From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62CCFC433EF for ; Fri, 5 Nov 2021 20:04:05 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id CBC6861183 for ; Fri, 5 Nov 2021 20:04:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CBC6861183 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 3C8BE4A1B0; Fri, 5 Nov 2021 16:04:04 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0zMf8mq3u4WV; Fri, 5 Nov 2021 16:04:03 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 028E54B163; Fri, 5 Nov 2021 16:04:03 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 780F84A1B0 for ; Fri, 5 Nov 2021 16:04:01 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BEwcVliflLRX for ; Fri, 5 Nov 2021 16:03:59 -0400 (EDT) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 916094B160 for ; Fri, 5 Nov 2021 16:03:59 -0400 (EDT) Received: by mail-pf1-f171.google.com with SMTP id g11so9808080pfv.7 for ; Fri, 05 Nov 2021 13:03:59 -0700 (PDT) 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=f5rhbj9pb5GgTT0825+tujieonyli7SwThgHMXaD3NP3Mog1A094HPsqZZlkGOJ/Q+ r3ZJnNzRBB3NhkN8VE/G5vrgRKhdENk2u9DuDgAERoqocOOeFGdBNvbmuevHRGuv/PzT 2oM9e8uLyVHxjP0SBflIjCbS2YVvFiGTQPV4FXb1yFhkAV2Dwb/b8vz1V1fKzExBfVLb Xj15HqIIyyCqzeQTYv54iKEeMFkAbdprvcVA6NgVuqrrvC5EFRz5/vl/ehO9cRPXvPHn fwuRS81bHhHxNVlMCQCaLVr17+7bYqD4G5MIyYU1T+K/ui2sRBFDHO8DZRxHvFM9pN8W 0Kfw== 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=rvs0mepdsaATwE+No4Po1f2buxzEt+Iu2my29n+tLuxj8pxjB3UBOHuA3ahHVM2KAc rukbX1RiH7VKaAKU63MB+fud8MZSl+1h1C19NphJM3TOqs/U3eFa+UxIabv00u/FpZ0O 3lsuN1a0gv3J+TYKfujyYN7Jgg+LiJ8MkXKEmB49v/Q9X06Rhzfo3AvlxYIpEj4gClQ5 jIvQkm2yW2PsQM5bjBGRhFCOks3S1f2lp/LNg461vJLStVtKKFbjMglTX8bGKWX185GJ oDetUhTFFNgZ/ry1mgJJiHzjORC6VLa0WvQG5OFOWvKitY3LGjhg+7jE5TIjE+wD9Trs wveQ== X-Gm-Message-State: AOAM5319809vuntMKaIFgoaDWkA2TNJ/TpOBVFA7pXzhEXdNv/PdYtfG DLohxusRNmgDUFqP1wfrEv16IQ== X-Google-Smtp-Source: ABdhPJyd4QYc+InpdUIun9J0aiQkUM13aDBr60E6YJVxeHTQZZxRXWXSmp46OuKH+1B6vf2ZVsVbyQ== X-Received: by 2002:a05:6a00:22d1:b0:494:72c5:803b with SMTP id f17-20020a056a0022d100b0049472c5803bmr10239284pfj.84.1636142638330; Fri, 05 Nov 2021 13:03:58 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id c198sm6639870pga.6.2021.11.05.13.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 13:03:57 -0700 (PDT) Date: Fri, 5 Nov 2021 20:03:53 +0000 From: Sean Christopherson To: Marc Zyngier Subject: Re: [PATCH 4/5] KVM: x86: Use kvm_get_vcpu() instead of open-coded access Message-ID: References: <20211105192101.3862492-1-maz@kernel.org> <20211105192101.3862492-5-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211105192101.3862492-5-maz@kernel.org> Cc: Juergen Gross , Anup Patel , Janosch Frank , kvm@vger.kernel.org, Christian Borntraeger , Michael Ellerman , Huacai Chen , David Hildenbrand , linux-mips@vger.kernel.org, Nicholas Piggin , Atish Patra , Aleksandar Markovic , Paul Mackerras , Paolo Bonzini , kernel-team@android.com, Claudio Imbrenda , linuxppc-dev@lists.ozlabs.org, kvmarm@lists.cs.columbia.edu X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Fri, Nov 05, 2021, Marc Zyngier wrote: > As we are about to change the way vcpus are allocated, mandate > the use of kvm_get_vcpu() instead of open-coding the access. > > Signed-off-by: Marc Zyngier > --- > arch/x86/kvm/vmx/posted_intr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index 5f81ef092bd4..82a49720727d 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, > > if (!kvm_arch_has_assigned_device(kvm) || > !irq_remapping_cap(IRQ_POSTING_CAP) || > - !kvm_vcpu_apicv_active(kvm->vcpus[0])) > + !kvm_vcpu_apicv_active(kvm_get_vcpu(kvm, 0))) Huh. The existing code is decidedly odd. I think it might even be broken, as it's not obvious that vCPU0 _must_ be created when e.g. kvm_arch_irq_bypass_add_producer() is called. An equivalent, safe check would be: diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..a3100591a9ca 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !kvm_apicv_activated(kvm)) return 0; idx = srcu_read_lock(&kvm->irq_srcu); But I think even that is flawed, as APICv can be dynamically deactivated and re-activated while the VM is running, and I don't see a path that re-updates the IRTE when APICv is re-activated. So I think a more conservative check is needed, e.g. diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..6cf5b2e86118 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !irqchip_in_kernel(kvm) || !enable_apicv) return 0; idx = srcu_read_lock(&kvm->irq_srcu); Paolo, am I missing something? _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 923A2C433EF for ; Fri, 5 Nov 2021 20:04:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BE4461183 for ; Fri, 5 Nov 2021 20:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232930AbhKEUGj (ORCPT ); Fri, 5 Nov 2021 16:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbhKEUGj (ORCPT ); Fri, 5 Nov 2021 16:06:39 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C6E1C061714 for ; Fri, 5 Nov 2021 13:03:59 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id m26so9846586pff.3 for ; Fri, 05 Nov 2021 13:03:59 -0700 (PDT) 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=f5rhbj9pb5GgTT0825+tujieonyli7SwThgHMXaD3NP3Mog1A094HPsqZZlkGOJ/Q+ r3ZJnNzRBB3NhkN8VE/G5vrgRKhdENk2u9DuDgAERoqocOOeFGdBNvbmuevHRGuv/PzT 2oM9e8uLyVHxjP0SBflIjCbS2YVvFiGTQPV4FXb1yFhkAV2Dwb/b8vz1V1fKzExBfVLb Xj15HqIIyyCqzeQTYv54iKEeMFkAbdprvcVA6NgVuqrrvC5EFRz5/vl/ehO9cRPXvPHn fwuRS81bHhHxNVlMCQCaLVr17+7bYqD4G5MIyYU1T+K/ui2sRBFDHO8DZRxHvFM9pN8W 0Kfw== 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=aD2WUPu6lov7+lsacB8P0u0jFVjPZye+y70riqIyj1c5wPp12K2GXtun72K4ktW7kw W5lCKHhMS89enuaHegNQTD95myNWR2ClDtieHfDK1c8F2RpabF5v3VMLA0cjaMuf4wnb hCC8VEfihcfyu5mo2v3tlXLBToOZjdEpuLXuvV/QJO3p1UzU84W/EbpW8cNX6uEP1MFK xBsQ8MZdGLhzEcHG5lizxqFxaeShhdNeHdrhptv3A7nexCMztK7YnCuKmiMD3Z8YdokA /FxqnBxHkpgo6ng43m1+6zB5N776m2LuRGwFQ9w2dNCJ3IbyD6MKXB7uZKQkxd3Ah6vB mSGQ== X-Gm-Message-State: AOAM530BmRDz8ToqSKug7+C/est9KcqDEZAMzM9WomXpZwa0U7pFXijO 9MDaWM2qG9mFtctLSEb+rfd6yw== X-Google-Smtp-Source: ABdhPJyd4QYc+InpdUIun9J0aiQkUM13aDBr60E6YJVxeHTQZZxRXWXSmp46OuKH+1B6vf2ZVsVbyQ== X-Received: by 2002:a05:6a00:22d1:b0:494:72c5:803b with SMTP id f17-20020a056a0022d100b0049472c5803bmr10239284pfj.84.1636142638330; Fri, 05 Nov 2021 13:03:58 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id c198sm6639870pga.6.2021.11.05.13.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 13:03:57 -0700 (PDT) Date: Fri, 5 Nov 2021 20:03:53 +0000 From: Sean Christopherson To: Marc Zyngier Cc: kvm@vger.kernel.org, linux-mips@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linuxppc-dev@lists.ozlabs.org, Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , David Hildenbrand , Claudio Imbrenda , Paolo Bonzini , Juergen Gross , Nicholas Piggin , Paul Mackerras , Michael Ellerman , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: Re: [PATCH 4/5] KVM: x86: Use kvm_get_vcpu() instead of open-coded access Message-ID: References: <20211105192101.3862492-1-maz@kernel.org> <20211105192101.3862492-5-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211105192101.3862492-5-maz@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Fri, Nov 05, 2021, Marc Zyngier wrote: > As we are about to change the way vcpus are allocated, mandate > the use of kvm_get_vcpu() instead of open-coding the access. > > Signed-off-by: Marc Zyngier > --- > arch/x86/kvm/vmx/posted_intr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index 5f81ef092bd4..82a49720727d 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, > > if (!kvm_arch_has_assigned_device(kvm) || > !irq_remapping_cap(IRQ_POSTING_CAP) || > - !kvm_vcpu_apicv_active(kvm->vcpus[0])) > + !kvm_vcpu_apicv_active(kvm_get_vcpu(kvm, 0))) Huh. The existing code is decidedly odd. I think it might even be broken, as it's not obvious that vCPU0 _must_ be created when e.g. kvm_arch_irq_bypass_add_producer() is called. An equivalent, safe check would be: diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..a3100591a9ca 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !kvm_apicv_activated(kvm)) return 0; idx = srcu_read_lock(&kvm->irq_srcu); But I think even that is flawed, as APICv can be dynamically deactivated and re-activated while the VM is running, and I don't see a path that re-updates the IRTE when APICv is re-activated. So I think a more conservative check is needed, e.g. diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..6cf5b2e86118 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !irqchip_in_kernel(kvm) || !enable_apicv) return 0; idx = srcu_read_lock(&kvm->irq_srcu); Paolo, am I missing something? From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFCC4C433F5 for ; Fri, 5 Nov 2021 20:04:46 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B7DEE60F59 for ; Fri, 5 Nov 2021 20:04:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B7DEE60F59 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HmBLN2xH0z3c4q for ; Sat, 6 Nov 2021 07:04:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=f5rhbj9p; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2607:f8b0:4864:20::42c; helo=mail-pf1-x42c.google.com; envelope-from=seanjc@google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=f5rhbj9p; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HmBKd1PqXz2ybM for ; Sat, 6 Nov 2021 07:04:03 +1100 (AEDT) Received: by mail-pf1-x42c.google.com with SMTP id g18so5036957pfk.5 for ; Fri, 05 Nov 2021 13:04:03 -0700 (PDT) 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=f5rhbj9pb5GgTT0825+tujieonyli7SwThgHMXaD3NP3Mog1A094HPsqZZlkGOJ/Q+ r3ZJnNzRBB3NhkN8VE/G5vrgRKhdENk2u9DuDgAERoqocOOeFGdBNvbmuevHRGuv/PzT 2oM9e8uLyVHxjP0SBflIjCbS2YVvFiGTQPV4FXb1yFhkAV2Dwb/b8vz1V1fKzExBfVLb Xj15HqIIyyCqzeQTYv54iKEeMFkAbdprvcVA6NgVuqrrvC5EFRz5/vl/ehO9cRPXvPHn fwuRS81bHhHxNVlMCQCaLVr17+7bYqD4G5MIyYU1T+K/ui2sRBFDHO8DZRxHvFM9pN8W 0Kfw== 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=PN/lxoi+e5tCVO5pPjxKDOBewixY35Ifh+V+MQmKh2Y=; b=NlAQnAeDtOBd2quA2BMv+TVjVM2I5blG9hNGwsHoFQYZjOuONl40/vMwyuXfZmoiLJ GzmHZjBeFgas0A8SXL6wilyD/2PPHfOuAYmFDLTkGPjM+HnEgxddkaaLCVysC9vcHsB7 Ct1TrlYr2g+5fXLtHz4kcLgjEPvQn6muPL7Qshl/FMOO2cSU/1f2OTZ1/U9c5k4MzpLy /LltqOGFcqcYQ0VSn6Uhylt9Biy8ah6C9vmL7ixt6XAdTAMdjr4fmUKRH3LvbzCXRjt7 JmV1GK2nb3YdxblZJPiFc01NFCBPCdP5IJt5i7Cu5o9YYKqj1goE2mXU02QokiivWaek /Yvg== X-Gm-Message-State: AOAM532XLure2Sg6/JTKhdeLpk4o+PKvi3XpzcOhzvINhiQ+HO59jNJO fPnJNNF3VGbmpyzgATiJiFy7ng== X-Google-Smtp-Source: ABdhPJyd4QYc+InpdUIun9J0aiQkUM13aDBr60E6YJVxeHTQZZxRXWXSmp46OuKH+1B6vf2ZVsVbyQ== X-Received: by 2002:a05:6a00:22d1:b0:494:72c5:803b with SMTP id f17-20020a056a0022d100b0049472c5803bmr10239284pfj.84.1636142638330; Fri, 05 Nov 2021 13:03:58 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id c198sm6639870pga.6.2021.11.05.13.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 13:03:57 -0700 (PDT) Date: Fri, 5 Nov 2021 20:03:53 +0000 From: Sean Christopherson To: Marc Zyngier Subject: Re: [PATCH 4/5] KVM: x86: Use kvm_get_vcpu() instead of open-coded access Message-ID: References: <20211105192101.3862492-1-maz@kernel.org> <20211105192101.3862492-5-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211105192101.3862492-5-maz@kernel.org> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Alexandru Elisei , Anup Patel , Janosch Frank , kvm@vger.kernel.org, Christian Borntraeger , Huacai Chen , David Hildenbrand , linux-mips@vger.kernel.org, Nicholas Piggin , Atish Patra , Aleksandar Markovic , Paul Mackerras , James Morse , Paolo Bonzini , kernel-team@android.com, Claudio Imbrenda , linuxppc-dev@lists.ozlabs.org, kvmarm@lists.cs.columbia.edu, Suzuki K Poulose Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Nov 05, 2021, Marc Zyngier wrote: > As we are about to change the way vcpus are allocated, mandate > the use of kvm_get_vcpu() instead of open-coding the access. > > Signed-off-by: Marc Zyngier > --- > arch/x86/kvm/vmx/posted_intr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index 5f81ef092bd4..82a49720727d 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, > > if (!kvm_arch_has_assigned_device(kvm) || > !irq_remapping_cap(IRQ_POSTING_CAP) || > - !kvm_vcpu_apicv_active(kvm->vcpus[0])) > + !kvm_vcpu_apicv_active(kvm_get_vcpu(kvm, 0))) Huh. The existing code is decidedly odd. I think it might even be broken, as it's not obvious that vCPU0 _must_ be created when e.g. kvm_arch_irq_bypass_add_producer() is called. An equivalent, safe check would be: diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..a3100591a9ca 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !kvm_apicv_activated(kvm)) return 0; idx = srcu_read_lock(&kvm->irq_srcu); But I think even that is flawed, as APICv can be dynamically deactivated and re-activated while the VM is running, and I don't see a path that re-updates the IRTE when APICv is re-activated. So I think a more conservative check is needed, e.g. diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 5f81ef092bd4..6cf5b2e86118 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, if (!kvm_arch_has_assigned_device(kvm) || !irq_remapping_cap(IRQ_POSTING_CAP) || - !kvm_vcpu_apicv_active(kvm->vcpus[0])) + !irqchip_in_kernel(kvm) || !enable_apicv) return 0; idx = srcu_read_lock(&kvm->irq_srcu); Paolo, am I missing something?