Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2919760pxb; Fri, 8 Oct 2021 19:18:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8/vLcT9m8srrgPFwun1nCePrMF2vdmvsfgv7khslxz/UwvSWZGPEc/6AYrOXHZDMGhuGj X-Received: by 2002:a17:906:d182:: with SMTP id c2mr8250195ejz.47.1633745922606; Fri, 08 Oct 2021 19:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745922; cv=none; d=google.com; s=arc-20160816; b=JDIH2G7LeCgH6iZNZUGBY/HnpkapUQ4muxea9DYCTyEVPazuOUyFOcMEfQLIgn81jU PL4Ay2yq5HiCAga2gtpdv6N6rfC4pwbDX42C1S8Lms5spCICdoov8az3QeAJGhaZkTVa mtzfuQrrUxv4LXDHEsQMemcUd07DDWvKTrQMzi2NgU/kmIAmOc0E+Sxz+23lUyJHojXD e++5Qc+yBN0i2R6eZYfXgacRAzu3Ru91nUHseLkPlouT1dPB0Xn2MC+7KXe3TrlmvzZe NshT0drpULyrVicscw0B9hMgoZzedicQ3RrIadJkHL8K4Oyc0R5Tf6u0JC0s0t7x7KP9 sYzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=wjQtX4Ec6wZvrLi6PMkrNqIQ2oyMcPdDf1m/MoA8d+0=; b=L7DkXVpZVnnUN/F5lcW9XSXDE4/e2TqTDVUgHg3JHZjzRJzlv25ablk+1V7oVRCCX/ aHbK7Iqps/dSwm+fNW2seQYwRj5Ke4Jv0T8MPzTCJTeg/SWf42mPfyUxYFwoGkkLByk3 Z0hnKUgc0d8VpVpkQWGWVMY0Wuhfc7VIbQwpX/KG8zj0Zmib6ht5wOnH4KiZVKffBSIt dBNa5ye+AlMPYb0h6HiG2Xr9RF+XP+mU4/6mgRobQ6ugQpjrLum36oVI7LupgTCPVoqr 4H49of+1ws3B7dumnOqCwBVuUcbaa+r/C4Aux0rTU+NoLfSqyljCbYMpePghTFCNmxoG +bQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Lnm/cjPX"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si1374885ejg.467.2021.10.08.19.18.19; Fri, 08 Oct 2021 19:18:42 -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=@google.com header.s=20210112 header.b="Lnm/cjPX"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244336AbhJICRa (ORCPT + 99 others); Fri, 8 Oct 2021 22:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244607AbhJICQz (ORCPT ); Fri, 8 Oct 2021 22:16:55 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE6BC0613A3 for ; Fri, 8 Oct 2021 19:13:49 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id b189-20020a3799c6000000b0045eb0c29072so9836941qke.12 for ; Fri, 08 Oct 2021 19:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=wjQtX4Ec6wZvrLi6PMkrNqIQ2oyMcPdDf1m/MoA8d+0=; b=Lnm/cjPXbd272GpMZC0UeDF+UHTqiJU1haGCknMr5AmNFQOxgzVQrkCrFXx8cCosZZ vhad/H/bU6EtWHdiaGljqq6NEDe4jYwnagw1hmypkZVWw7KopTXWbIioXhrKeB9WZIoL ReDT+1R5eLOhM0x5my19UH6pmlRFdnAMJjCjW90ue2a+3KqjCQ5KVltKsfzvFJct3Or4 f9Oft1KiecdRxszaICFl0MAY6x3TalLjCr4OG45jGmzTw8bdrlGkucMOEXd/i271jan6 0hz+LH0reRdSJS/sNXpSqjCOVK3W+uTEL9F4YDHRKI7A05LpPRMlHE+Kaw+W+rV3UGa5 UrVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=wjQtX4Ec6wZvrLi6PMkrNqIQ2oyMcPdDf1m/MoA8d+0=; b=GDJ07CTYdLSXMQpCbCU1MJIyW0gCpVlN9EGfzmCpkdwGNZcfFk+Yxsm+hKeYCHsRVk CtX3cu5zqcuCOKEWDbctAEtLZMtmMIRdpcbO3VMjDWbXhfNO+s9XNsinipnAP8OrEOyA UeUQFpYFj2KvN6ro0N89W4UxXN8hj9cBDoUZGSw3HRYaVUVJzLmqBH8Ufcpac/c44ANQ FkULBOQPDDorYQ15U/atRRxaAJVvcHF7sDNEGoKBPzwz+++WCCFsmXNADbSA6QuyPCz/ TS6XTAifeA6/D3mkZlmBv65zHyzSJPzdCyrTED4KtnxvmOEi6vXMgcfb8M8CQDaBq0wA yh+g== X-Gm-Message-State: AOAM531lXLe/T+0/OZ9EVozd7x9bbAivb+n1QdB1eaUL7vNRor8v6og9 1G3A9lEaZaZwkdj6LMQaP6xChIevXqM= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:ac8:6113:: with SMTP id a19mr1849269qtm.307.1633745628357; Fri, 08 Oct 2021 19:13:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:20 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-28-seanjc@google.com> Mime-Version: 1.0 References: <20211009021236.4122790-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v2 27/43] KVM: VMX: Move Posted Interrupt ndst computation out of write loop From: Sean Christopherson To: 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 , Sean Christopherson , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; -- 2.33.0.882.g93a45727a2-goog