Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1472131pxb; Thu, 28 Oct 2021 04:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpRcpGXtSoOQm98jZYVQBFZYRnC3YWz6undgDtEUSwBPq8Rlmjyv5HSfEcEqrBtMEsTF25 X-Received: by 2002:a50:d80d:: with SMTP id o13mr5326855edj.204.1635420676252; Thu, 28 Oct 2021 04:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635420676; cv=none; d=google.com; s=arc-20160816; b=nw2zUl4A1eXNcfcWA4PIt6C2D4NVwoM4c2JvQGgcCRRCAzz09qf/ocnfkg94VQAC1s bZWeHICS7tPiVXYNEGyN4ZN15NrfWvfFMzvyt9ot64sHXAyI/6zRxzG3CkJChqnVWWsW J1qoRi7SaeF0pM5buwWoPGiRLqxDC8f2jp+jcXa6WFyFOOPKIASc2T2BVLJqz6+OwjyK XmWOAXrc9sNHtaAw7f1bhr/xEpImrFk0xp8dDxk4Dn2Nn+WXYBc4lqwDV0N4Q48/RJHU Ki2f1r8JJ/pfAq2/B/pEgEK2vxxvcprn367oioLp8/EvY+KL/OJW86z0bGV458U5djeq U1Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=MHpIfrYfSW8Oruu5gZzONXfOs5cqhayPI05VEPrlFqI=; b=bUBdsE3QhopWSfiOEIm4eZuL5jt2Lklu09ZSioM05LaOK5YaZN46rUik5TiSkobgvN Gjs5mUsjYCCzvZwL3CslE3LARn8eeOkARSw8K5lLAng8t2Zm8gkZnjIr7yNMuHxLEvon Gqdb1dqDm0CAaYGN/LBRMAGA9EK+qMvwMRorYD228gXvkydgbeg9UE+/vcCeJsc5E9pL zCXR9RUsxd8MSMYqydSX+Cw3Ekh4JDbJKusuvNeuMr8lLBi8FyYdBOq6211xQ5LtP0sG BhuuyrDO1HPTzm0p+ynZa1lspxSDRzi1H5jkfi2heaWzlePL1pmCriqsrDUfZHGB1gOp cReQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZXK1SsSc; 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 u20si3300401edv.439.2021.10.28.04.30.52; Thu, 28 Oct 2021 04:31:16 -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=ZXK1SsSc; 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 S230122AbhJ1LbU (ORCPT + 99 others); Thu, 28 Oct 2021 07:31:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30357 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbhJ1LbT (ORCPT ); Thu, 28 Oct 2021 07:31:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635420532; 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=MHpIfrYfSW8Oruu5gZzONXfOs5cqhayPI05VEPrlFqI=; b=ZXK1SsScmTgtnETpIVi2QXHMMs18RzTZPLNJsMQPBJZrv9133Un6zEiD04wYDmRLk8iqrN iuZX4yT7S6TUZoHT9hESffo8pukWCq5lQV0yzXImlSkMPgQqKPN/CyfuhIr/OGE6dxfDS+ vegJ1oDUxlGxo3f0//TYGU5zmJ/np9g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-301-eJZbxn5mNyK61ySDSBCRrA-1; Thu, 28 Oct 2021 07:28:46 -0400 X-MC-Unique: eJZbxn5mNyK61ySDSBCRrA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF9359F92B; Thu, 28 Oct 2021 11:28:42 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 108AF5DA61; Thu, 28 Oct 2021 11:28:30 +0000 (UTC) Message-ID: <643d9c249b5863f04290a6f047ea1a2d98bd75f9.camel@redhat.com> Subject: Re: [PATCH v2 27/43] KVM: VMX: Move Posted Interrupt ndst computation out of write loop From: Maxim Levitsky To: Sean Christopherson , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang Date: Thu, 28 Oct 2021 14:28:29 +0300 In-Reply-To: <20211009021236.4122790-28-seanjc@google.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-28-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-10-08 at 19:12 -0700, Sean Christopherson wrote: > Hoist the CPU => APIC ID conversion for the Posted Interrupt descriptor > out of the loop to write the descriptor, preemption is disabled so the > CPU won't change, and if the APIC ID changes KVM has bigger problems. > > No functional change intended. Is preemption always disabled in vmx_vcpu_pi_load? vmx_vcpu_pi_load is called from vmx_vcpu_load, which is called indirectly from vcpu_load which is called from many ioctls, which userspace does. In these places I don't think that preemption is disabled. Best regards, Maxim Levitsky > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/posted_intr.c | 25 +++++++++++-------------- > 1 file changed, 11 insertions(+), 14 deletions(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index fea343dcc011..2b2206339174 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -51,17 +51,15 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) > goto after_clear_sn; > } > > - /* The full case. */ > + /* The full case. Set the new destination and clear SN. */ > + dest = cpu_physical_id(cpu); > + if (!x2apic_mode) > + dest = (dest << 8) & 0xFF00; > + > do { > old.control = new.control = READ_ONCE(pi_desc->control); > > - dest = cpu_physical_id(cpu); > - > - if (x2apic_mode) > - new.ndst = dest; > - else > - new.ndst = (dest << 8) & 0xFF00; > - > + new.ndst = dest; > new.sn = 0; > } while (cmpxchg64(&pi_desc->control, old.control, > new.control) != old.control); > @@ -103,15 +101,14 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) > WARN(pi_desc->nv != POSTED_INTR_WAKEUP_VECTOR, > "Wakeup handler not enabled while the vCPU was blocking"); > > + dest = cpu_physical_id(vcpu->cpu); > + if (!x2apic_mode) > + dest = (dest << 8) & 0xFF00; > + > do { > old.control = new.control = READ_ONCE(pi_desc->control); > > - dest = cpu_physical_id(vcpu->cpu); > - > - if (x2apic_mode) > - new.ndst = dest; > - else > - new.ndst = (dest << 8) & 0xFF00; > + new.ndst = dest; > > /* set 'NV' to 'notification vector' */ > new.nv = POSTED_INTR_VECTOR;