Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1742305pxb; Thu, 28 Oct 2021 09:13:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy65XpClH2pB28lE7MC6vN/gs3D7XZjhdXbk6Rbq8BNX9OWNEmtBZm2jb1asUwP5wKjb8lG X-Received: by 2002:a17:902:7c8d:b0:13a:768b:d6c0 with SMTP id y13-20020a1709027c8d00b0013a768bd6c0mr4833011pll.83.1635437601495; Thu, 28 Oct 2021 09:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635437601; cv=none; d=google.com; s=arc-20160816; b=RIYnDzaff67bgbgp3HqELMeBTXqX1R5PVthkuWZp6r9xnckf3YTlwKi7wk/mSGBE79 hGmKRqhIbudj9dptQscTNMy44JYd6z86Korp4MIZFCRq5q3OO/x8MHJKMc0QjGkAzXHn bM91FYEfSPhhWU6C5eFCqNWd9l+gFXcel017M6Cjmmdp7avGonOHKkQ6T7Pk3CU0JZPN wZW/33JNBP5GBj0UYGGEgZu27MxhwJefUeRY3LrMPxLTamrzWGZJ4vFmMvly2kE0w1/P s7IToGc0ttE/aLOlfaBujnbDrb+P49BMbLP5ofV4W/sInxthbpP6Jk5J8ZzNkzq9KVXt tFHQ== 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=RPIozLU8n1iGsiSzHPyPa84e4ejX/UYwSJJGhpw0Bzs=; b=VPoFl27qhBdEmdEylZjmXQOoQm6fS4fkj6q0m6oA9jx7PdGSfc72b+ycbBwYs8UriS GtPUkyX8FUVar80aZTRfgilfliSjAZFVPh0uXq8uNTYI5ean7kB/s4puss2XqRckcmWj Ry8CjIG08aNNO+dtNDgUMNGIZ75VYWJtQz6Le7/nPwus8rePaqBw07o1kMIb/3ODdUqR e0w3weiA/eOImBvLPTRpCO81Tx1LVA/kl8yfirSnYDTEnTM+0T9pjNH5uBWpwKtjUI6V 6j7g+KorW042Ct7GyvfF5oFUcl6Hajnl1y3Z4g0eSw7iRwDc20NwggF5chP/pf1pxIGn DcVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cavcg8kY; 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 m4si5191725pfk.76.2021.10.28.09.13.07; Thu, 28 Oct 2021 09:13:21 -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=Cavcg8kY; 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 S229946AbhJ1QM0 (ORCPT + 99 others); Thu, 28 Oct 2021 12:12:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43287 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbhJ1QMZ (ORCPT ); Thu, 28 Oct 2021 12:12:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635437398; 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=RPIozLU8n1iGsiSzHPyPa84e4ejX/UYwSJJGhpw0Bzs=; b=Cavcg8kYCez3L1P7/Nryd2w594yDq1v5IjOY0wGJh60DlGqsu9s08DFBWTqcZA3VNy7aVr ukCGsHvefXozm+ZKZbOn2v5yjgJdxOvQb9alkA6ib/93ADvNdPtnhBT4z4xU+FyfwkJ6jv dTZxJztXlZPNndIg585IXCxkEr3gVds= 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-46-PimS6ymnOV-UnZZtG5v5zw-1; Thu, 28 Oct 2021 12:09:56 -0400 X-MC-Unique: PimS6ymnOV-UnZZtG5v5zw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E21580A5C0; Thu, 28 Oct 2021 16:09:52 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79BD660843; Thu, 28 Oct 2021 16:09:42 +0000 (UTC) Message-ID: <5769bb700d94c3828bdef57963a3fe9422e801e7.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 19:09:41 +0300 In-Reply-To: <643d9c249b5863f04290a6f047ea1a2d98bd75f9.camel@redhat.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-28-seanjc@google.com> <643d9c249b5863f04290a6f047ea1a2d98bd75f9.camel@redhat.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.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-10-28 at 14:28 +0300, Maxim Levitsky wrote: > 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. You can disregard this, I missed the fact that we have 'int cpu = get_cpu();' which disables preemption in 'vcpu_load' Thus, Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky > > 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;