From nobody Fri Apr 26 11:35:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574869773; cv=none; d=zohomail.com; s=zohoarc; b=WTb6+7BSdfDlTodzT+qNFGMQy6Q5yfjFoWxup4CfcOiMS23RSMZARq7UG5PSUB2sCe5/ur9kGVrcr474apKpi18ZFL0KwVRabZi3IrzZw6w/nxu8iHggITM/8kWX1Zr/mh5Q/zd+053N6zeB51mCuHdqWSt9bETCTjnZtMb8h/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574869773; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=LAzHz3RG4hl2VoLE57oBDMgJA/hICYLNy7u9JON6YJU=; b=eUs37HEq06sbKMyGmGunyVFfoHhc7UBxn4ug0YCIolSnKW65YFEb4gIx5qr1m1UiBbZbhNLuDDnWnGK8CvLMtxlZxP0e+OzPzuzixMdHiwCTpmrCWnFiIpxVeV+vf04fdMYGkg6ariIQwcGM+lHqUPaM7Khv8IPyz0rOr8wQv/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15748697734111017.8772082192133; Wed, 27 Nov 2019 07:49:33 -0800 (PST) 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 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) X-Inumbo-ID: 5e372f84-112d-11ea-a3b8-12813bfff9fa 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 (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 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 =3D &v->domain->arch.hvm; int vector; =20 + /* + * Always call vlapic_sync_pir_to_irr so that PIR is synced into IRR w= hen + * 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; =20 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]); } =20 -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)); =20 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; =20 - sync_pir_to_irr(v); + vlapic_sync_pir_to_irr(v); =20 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/vla= pic.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); =20 +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__ */ --=20 2.24.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel