From nobody Tue Sep 9 21:40:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1757114881; cv=none; d=zohomail.com; s=zohoarc; b=LQtZIMglr2N6ui1rxJqy19rBc5l9ptk4jUIuPI1UQ99ahZVRjsQY5dFoCAZGhq3tkHE0c9Vjiy0LIFxyFVmpZOHvzTtBc/RTpmd6zP+N4Dh0PJcBdFD0g0WihiGeEBqKW1T5p2R/v8kZ4l78KT5522E+ke8h824bj4di6HkCmgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757114881; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3mwBazL9kANwQ3BnZxsZTOwFxpPGlCvixHJoTT4Lu2c=; b=GtcATLkD7JF0kDa+M2KRxyonIz0MSUO7dcHZ4g6HaeebvxqWQQPZd5ef7OKn0AloLk1j8bdPHcTeMSglR5brYT1YB5WpC/IRYHOiap2BT9oz4A189Gh/aebna5IjxfGwzYW66btOeRqxmuv2ikIT1N/mqN94iKdgnJDsUOr5+I0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1757114880997901.9234884952042; Fri, 5 Sep 2025 16:28:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1112649.1460961 (Exim 4.92) (envelope-from ) id 1uufqF-0005Fj-Vr; Fri, 05 Sep 2025 23:27:39 +0000 Received: by outflank-mailman (output) from mailman id 1112649.1460961; Fri, 05 Sep 2025 23:27:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uufqF-0005CQ-AU; Fri, 05 Sep 2025 23:27:39 +0000 Received: by outflank-mailman (input) for mailman id 1112649; Fri, 05 Sep 2025 23:27:35 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uufqB-0004Ts-IH for xen-devel@lists.xenproject.org; Fri, 05 Sep 2025 23:27:35 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1uufqB-008AD3-0N; Fri, 05 Sep 2025 23:27:35 +0000 Received: from [19.12.91.86] (helo=localhost) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uufqB-0005Dk-0M; Fri, 05 Sep 2025 23:27:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From; bh=3mwBazL9kANwQ3BnZxsZTOwFxpPGlCvixHJoTT4Lu2c=; b=YlcGtW3+chCoHlxxDwnt0y8l13 sIv7ttz6hYQ0OurpgLhVhQQ95/EEVfqYbKSPaCNFXpLDqoRK9x4EhwXNcY1QoefMyQGYtiDIBbkwn PP+ivJWyufaoLcSB930NB9DcAHQbiKxUbejx0DWCnT0ZsYP6pZw8hLqWWjd144N3aIJc=; From: dmukhin@xen.org To: xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v6 15/15] emul/ns16x50: implement IRQ emulation via vIOAPIC Date: Fri, 5 Sep 2025 16:27:14 -0700 Message-ID: <20250905232715.440758-16-dmukhin@ford.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250905232715.440758-1-dmukhin@ford.com> References: <20250905232715.440758-1-dmukhin@ford.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1757114882928124101 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin =20 PVH domains use vIOAPIC, not vPIC and NS16550 emulates ISA IRQs which cannot be asserted on vIOAPIC. {map,unmap}_domain_pirq_emuirq() infrastructure is modified by adding new type of interrupt resources 'IRQ_EMU' which means 'emulated device IRQ' (similarly to IRQ_MSI_EMU). This is necessary to for IOAPIC emulation code to skip IRQ->PIRQ mapping (vioapic_hwdom_map_gsi()) when guest OS unmasks vIOAPIC pin corresponding to virtual device's IRQ. Also, hvm_gsi_eoi() is modified to trigger assertion in hvm_gsi_deassert() path for ISA IRQs. Signed-off-by: Denis Mukhin --- Changes since v5: - did cosmetic renaming and dropped unneeded changes - fixed ns16x50_irq_assert() and ns16x50_irq_deassert() as per Jan's suggestion in v4 (missed to address in v5) - fixed __hvm_dpci_eoi() - Link to v5: https://lore.kernel.org/xen-devel/20250828235409.2835815-16-d= mukhin@ford.com/ --- xen/arch/x86/hvm/vioapic.c | 10 ++++++++++ xen/arch/x86/include/asm/irq.h | 6 ++++++ xen/common/emul/vuart/ns16x50.c | 28 ++++++++++++++++++++++++++++ xen/drivers/passthrough/x86/hvm.c | 11 ++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 7c725f9e471f..6314874b64f7 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -177,6 +177,16 @@ static int vioapic_hwdom_map_gsi(unsigned int gsi, uns= igned int trig, =20 ASSERT(is_hardware_domain(currd)); =20 + /* + * Interrupt is claimed by one of the platform virtual devices (e.g. + * NS16550); do nothing. + */ + write_lock(&currd->event_lock); + ret =3D is_domain_emuirq_claimed(currd, gsi); + write_unlock(&currd->event_lock); + if ( ret ) + return 0; + /* Interrupt has been unmasked, bind it now. */ ret =3D mp_register_gsi(gsi, trig, pol); if ( ret =3D=3D -EEXIST ) diff --git a/xen/arch/x86/include/asm/irq.h b/xen/arch/x86/include/asm/irq.h index 8bffec3bbfee..bdbe700274e9 100644 --- a/xen/arch/x86/include/asm/irq.h +++ b/xen/arch/x86/include/asm/irq.h @@ -168,6 +168,11 @@ void free_domain_pirqs(struct domain *d); int map_domain_emuirq_pirq(struct domain *d, int pirq, int emuirq); int unmap_domain_pirq_emuirq(struct domain *d, int pirq); =20 +#define domain_emuirq_claim(d, irq) map_domain_emuirq_pirq(d, irq, IRQ= _EMU) +#define domain_emuirq_unclaim(d, irq) unmap_domain_pirq_emuirq(d, irq) +#define is_domain_emuirq_claimed(d, irq) \ + (domain_pirq_to_emuirq(d, irq) !=3D IRQ_UNBOUND) + /* Evacuate interrupts assigned to CPUs not present in the CPU online map.= */ void fixup_irqs(void); void fixup_eoi(void); @@ -221,6 +226,7 @@ void cleanup_domain_irq_mapping(struct domain *d); #define IRQ_UNBOUND (-1) #define IRQ_PT (-2) #define IRQ_MSI_EMU (-3) +#define IRQ_EMU (-4) =20 bool cpu_has_pending_apic_eoi(void); =20 diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x5= 0.c index bcbd765b815d..723b1b0bb55d 100644 --- a/xen/common/emul/vuart/ns16x50.c +++ b/xen/common/emul/vuart/ns16x50.c @@ -292,6 +292,8 @@ static void ns16x50_irq_assert(const struct vuart_ns16x= 50 *vdev) =20 if ( has_vpic(d) ) vector =3D hvm_isa_irq_assert(d, info->irq, vioapic_get_vector); + else if ( has_vioapic(d) ) + vector =3D hvm_ioapic_assert(d, info->irq, false); else ASSERT_UNREACHABLE(); =20 @@ -305,6 +307,8 @@ static void ns16x50_irq_deassert(const struct vuart_ns1= 6x50 *vdev) =20 if ( has_vpic(d) ) hvm_isa_irq_deassert(d, info->irq); + else if ( has_vioapic(d) ) + hvm_ioapic_deassert(d, info->irq); else ASSERT_UNREACHABLE(); =20 @@ -815,6 +819,17 @@ static int ns16x50_init(void *arg) return rc; } =20 + /* Claim virtual IRQ */ + write_lock(&d->event_lock); + rc =3D domain_emuirq_claim(d, info->irq); + write_unlock(&d->event_lock); + if ( rc ) + { + ns16x50_err(info, "virtual IRQ#%d: cannot claim: %d\n", + info->irq, rc); + return rc; + } + /* NB: report 115200 baud rate. */ vdev->regs[NS16X50_REGS_NUM + UART_DLL] =3D divisor & 0xff; vdev->regs[NS16X50_REGS_NUM + UART_DLM] =3D (divisor >> 8) & 0xff; @@ -834,9 +849,22 @@ static int ns16x50_init(void *arg) static void cf_check ns16x50_deinit(void *arg) { struct vuart_ns16x50 *vdev =3D arg; + const struct vuart_info *info; + struct domain *d; + int rc; =20 ASSERT(vdev); =20 + d =3D vdev->owner; + info =3D vdev->info; + + write_lock(&d->event_lock); + rc =3D domain_emuirq_unclaim(d, info->irq); + write_unlock(&d->event_lock); + if ( rc ) + ns16x50_err(vdev, "virtual IRQ#%d: cannot unclaim: %d\n", + info->irq, rc); + spin_lock(&vdev->lock); ns16x50_fifo_tx_flush(vdev); spin_unlock(&vdev->lock); diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x8= 6/hvm.c index a2ca7e0e570c..20641194561f 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -922,7 +922,16 @@ static void __hvm_dpci_eoi(struct domain *d, =20 static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) { - struct pirq *pirq =3D pirq_info(d, gsi); + struct pirq *pirq; + + /* Check if GSI is claimed by one of the virtual devices. */ + if ( is_domain_emuirq_claimed(d, gsi) ) + { + hvm_gsi_deassert(d, gsi); + return; + } + + pirq =3D pirq_info(d, gsi); =20 /* Check if GSI is actually mapped. */ if ( !pirq_dpci(pirq) ) --=20 2.51.0