From patchwork Wed Nov 27 15:48:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11264395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B04F14ED for ; Wed, 27 Nov 2019 15:49:53 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 3530620665 for ; Wed, 27 Nov 2019 15:49:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="PhKi2d3I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3530620665 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iZzYc-0001rb-QA; Wed, 27 Nov 2019 15:48:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iZzYb-0001rW-C4 for xen-devel@lists.xenproject.org; Wed, 27 Nov 2019 15:48:45 +0000 X-Inumbo-ID: 5e372f84-112d-11ea-a3b8-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5e372f84-112d-11ea-a3b8-12813bfff9fa; Wed, 27 Nov 2019 15:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574869714; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=kVDypD4sPqXKLmr73CcGJEkBmUwhcwzXp4DfqPPHFww=; b=PhKi2d3Isb7x/7qHUXzkChx04gN6DZ9+U6+XaUE3Hiz/YPGu2a31THBc CXEdnPUF273YF5YlsdX1HT3bV0MM46vVLtgoGmnYZ7uCm2L9OZirHYLSL RGLYBHqWDmQqCIvVwFU8biBSXeARRLM3IQQfbU1iGRdMAAkshdb8NL576 U=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 3EVHjUxFnSwhp1DcWDXhZ715COB8D44yhoqPD94ufoXMyjvUEtWu3gD66XZvCUZ0ngbzHTf2U7 VyRe1AOgxSLZFRhXUUMPosI8S2UtPMRVp5CH5KkNaucCFReRMDy3hZlofaY4YybVdwDBHOnBWj CDSBkdAsnLn0zNpWpR2zytVaThl2V6rOu4G7NGwhpyUuB/KDCal3ehcxp/4WtuJenQ8a+W00cR RtBSUaDtgFW64laX+UA1aRO8KZ3Vh8szG47jRYEdUdZYWcPev7O2v8lIQhaVEmPODhC7FRGP0N Yzg= X-SBRS: 2.7 X-MesageID: 9460162 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,250,1571716800"; d="scan'208";a="9460162" From: Roger Pau Monne To: Date: Wed, 27 Nov 2019 16:48:17 +0100 Message-ID: <20191127154817.12103-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH for-4.13 v4] x86/vmx: always sync PIR to IRR before vmentry X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Wei Liu , Andrew Cooper , Joe Jin , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected vlapic_has_pending_irq might not be called, and thus PIR won't be synced into IRR. Fix this by making sure PIR is always synced to IRR in hvm_vcpu_has_pending_irq regardless of what interrupts are pending. Reported-by: Joe Jin Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich Tested-by: Joe Jin --- Cc: Juergen Gross --- Changes since v3: - Introduce and use vlapic_sync_pir_to_irr in order to sync PIR with IRR. - Do not move the call to vlapic_has_pending_irq in hvm_vcpu_has_pending_irq. - Remove the changes done to __vmx_deliver_posted_interrupt. Changes since v2: - Raise a softirq if in interrupt context and the vCPU is the current one. - Use is_running instead of runnable. - Remove the call to vmx_sync_pir_to_irr in vmx_intr_assist and instead always call vlapic_has_pending_irq in hvm_vcpu_has_pending_irq. --- xen/arch/x86/hvm/irq.c | 9 +++++++++ xen/arch/x86/hvm/vlapic.c | 10 ++-------- xen/include/asm-x86/hvm/vlapic.h | 6 ++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c index e03a87ad50..c684422b24 100644 --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -517,6 +517,15 @@ struct hvm_intack hvm_vcpu_has_pending_irq(struct vcpu *v) struct hvm_domain *plat = &v->domain->arch.hvm; int vector; + /* + * Always call vlapic_sync_pir_to_irr so that PIR is synced into IRR when + * using posted interrupts. Note this is also done by + * vlapic_has_pending_irq but depending on which interrupts are pending + * hvm_vcpu_has_pending_irq will return early without calling + * vlapic_has_pending_irq. + */ + vlapic_sync_pir_to_irr(v); + if ( unlikely(v->nmi_pending) ) return hvm_intack_nmi; diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 9466258d6f..6fcce95713 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -106,15 +106,9 @@ static void vlapic_clear_irr(int vector, struct vlapic *vlapic) vlapic_clear_vector(vector, &vlapic->regs->data[APIC_IRR]); } -static void sync_pir_to_irr(struct vcpu *v) -{ - if ( hvm_funcs.sync_pir_to_irr ) - alternative_vcall(hvm_funcs.sync_pir_to_irr, v); -} - static int vlapic_find_highest_irr(struct vlapic *vlapic) { - sync_pir_to_irr(vlapic_vcpu(vlapic)); + vlapic_sync_pir_to_irr(vlapic_vcpu(vlapic)); return vlapic_find_highest_vector(&vlapic->regs->data[APIC_IRR]); } @@ -1493,7 +1487,7 @@ static int lapic_save_regs(struct vcpu *v, hvm_domain_context_t *h) if ( !has_vlapic(v->domain) ) return 0; - sync_pir_to_irr(v); + vlapic_sync_pir_to_irr(v); return hvm_save_entry(LAPIC_REGS, v->vcpu_id, h, vcpu_vlapic(v)->regs); } diff --git a/xen/include/asm-x86/hvm/vlapic.h b/xen/include/asm-x86/hvm/vlapic.h index dde66b4f0f..f0d5e3fbc9 100644 --- a/xen/include/asm-x86/hvm/vlapic.h +++ b/xen/include/asm-x86/hvm/vlapic.h @@ -150,4 +150,10 @@ bool_t vlapic_match_dest( const struct vlapic *target, const struct vlapic *source, int short_hand, uint32_t dest, bool_t dest_mode); +static inline void vlapic_sync_pir_to_irr(struct vcpu *v) +{ + if ( hvm_funcs.sync_pir_to_irr ) + alternative_vcall(hvm_funcs.sync_pir_to_irr, v); +} + #endif /* __ASM_X86_HVM_VLAPIC_H__ */