Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C46EC433E0 for ; Mon, 27 Jul 2020 17:06:22 +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 D16982064B for ; Mon, 27 Jul 2020 17:06:21 +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="TZ9nwE2D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D16982064B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass 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.92) (envelope-from ) id 1k06Zi-0006sp-4h; Mon, 27 Jul 2020 17:06:06 +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.92) (envelope-from ) id 1k06Zh-0006qK-7w for xen-devel@lists.xenproject.org; Mon, 27 Jul 2020 17:06:05 +0000 X-Inumbo-ID: 7062a6ee-d02b-11ea-a7b1-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7062a6ee-d02b-11ea-a7b1-12813bfff9fa; Mon, 27 Jul 2020 17:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595869559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=saiDrgvFoGPsvHXwjrhIy9joLoxVibLVmDC510j+ikM=; b=TZ9nwE2DH71zn7T3PV+juoG9+N6zGMOToH/bDr1Oe5n3I9yhxf3tk36L gTgxeg/0OiucXSacAWIdnq1UOKZDQAFzbRczDhnNwVYfG11c/Ux98XPDd 0VAJ/wsafXs4XCd+r6KadlZfDI648LPPSF8k5VTbwzXVKkMZajQzXMV+D k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: NgwrdsjxFH/xaOvgM3zcURG7VC2t47NoPT9WCA+NYDz0pOkGAEBir4ieksjaq60g1CaMvh66Yc oHyamu8lkusknUi3B9lV/UGWODQqIYOFWylWXp1/pdtO+rLYjcAPmds6eJ/Gs2WcWr6dVrgJ9Z iOsAU7lTqtT3B82XPtDrf5tFl00hAwGTTHY98J4VTTgMZXczofvtAXHUqbvQ1ZLCQg6LB6Z7xS 5zMM4luNKAbPztVazylyRJbRpcjAe02awLB5yTeBzVHN1JpuGZpjMGi0spnS6/wxgcJpjNmNc4 IL4= X-SBRS: 2.7 X-MesageID: 23613409 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,402,1589256000"; d="scan'208";a="23613409" From: Roger Pau Monne To: Subject: [PATCH v2 3/5] x86/hvm: fix ISA IRQ 0 handling when set as lowest priority mode in IO APIC Date: Mon, 27 Jul 2020 19:05:37 +0200 Message-ID: <20200727170539.55798-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727170539.55798-1-roger.pau@citrix.com> References: <20200727170539.55798-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Lowest priority destination mode does allow the vIO APIC code to select a vCPU to inject the interrupt to, but the selected vCPU must be part of the possible destinations configured for such IO APIC pin. Fix the code in order to only force vCPU 0 if it's part of the listed destinations. Signed-off-by: Roger Pau Monné --- Changes since v1: - Add a comment regarding the vlapic_enabled check. --- NB: I haven't added a fallback to vCPU 0 if no destination is found, as it's not how real hardware behaves. I think we should assume that no user have relied on this bogus Xen behavior for IRQ 0 interrupt injection. --- xen/arch/x86/hvm/vioapic.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 123191db75..67d4a6237f 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -415,12 +415,14 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) case dest_LowestPrio: { #ifdef IRQ0_SPECIAL_ROUTING - /* Force round-robin to pick VCPU 0 */ - if ( (irq == hvm_isa_irq_to_gsi(0)) && pt_active(&d->arch.vpit.pt0) ) - { - v = d->vcpu ? d->vcpu[0] : NULL; - target = v ? vcpu_vlapic(v) : NULL; - } + struct vlapic *lapic0 = vcpu_vlapic(d->vcpu[0]); + + /* Force to pick vCPU 0 if part of the destination list */ + if ( (irq == hvm_isa_irq_to_gsi(0)) && pt_active(&d->arch.vpit.pt0) && + vlapic_match_dest(lapic0, NULL, 0, dest, dest_mode) && + /* Mimic the vlapic_enabled check found in vlapic_lowest_prio. */ + vlapic_enabled(lapic0) ) + target = lapic0; else #endif target = vlapic_lowest_prio(d, NULL, 0, dest, dest_mode); -- 2.27.0