[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v8 18/26] emul/ns16x50: resolve physical I/O port sharing
- To: dmukhin@xxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Fri, 20 Nov 2026 11:17:38 +0100
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
- Cc: andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, roger@xxxxxxxxxxxxxx, sstabellini@xxxxxxxxxx, xakep.amatop@xxxxxxxxx, dmukhin@xxxxxxx
- Delivery-date: Fri, 20 Nov 2026 10:18:00 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 11/11/26 8:47 PM, dmukhin@xxxxxxxx wrote:
From: Denis Mukhin <dmukhin@xxxxxxxx>
Ensure NS16550 emulator does not share I/O ports with the physical I/O
ports, which is essential for emulation in PVH hwdom case (dom0).
Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
xen/common/emul/vuart/ns16x50.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
index cda21c15cf78..97e12a99368a 100644
--- a/xen/common/emul/vuart/ns16x50.c
+++ b/xen/common/emul/vuart/ns16x50.c
@@ -901,14 +901,27 @@ static int ns16x50_init(void *arg)
struct vuart_ns16x50 *vdev = arg;
const struct vuart_info *info;
struct domain *d;
+ const char *as;
+ int rc;
ASSERT(vdev);
d = vdev->owner;
info = vdev->info;
+ as = (info->base_type & IORESOURCE_IO) ? "ioport": "iomem";
if ( info->base_type & IORESOURCE_IO )
{
+ /* Disallow sharing physical I/O port */
+ rc = ioports_deny_access(d, info->base_addr,
+ info->base_addr + info->size - 1);
+ if ( rc )
+ {
+ ns16x50_err(info, "virtual %s range [%#"PRIx64"..%#"PRIx64"]: conflict
w/ physical range\n",
+ as, info->base_addr, info->base_addr + info->size - 1);
+ return rc;
+ }
+
register_portio_handler(d, info->base_addr, info->size,
ns16x50_io_handle);
}
else if ( info->base_type & IORESOURCE_MEM )
@@ -928,13 +941,20 @@ static int ns16x50_init(void *arg)
static void cf_check ns16x50_deinit(void *arg)
{
struct vuart_ns16x50 *vdev = arg;
+ const struct vuart_info *info;
unsigned long flags;
ASSERT(vdev);
+ info = vdev->info;
+
ns16x50_lock(vdev, &flags);
ns16x50_fifo_tx_flush(vdev);
ns16x50_unlock(vdev, &flags);
+
+ if ( info->base_type & IORESOURCE_IO )
+ ioports_permit_access(d, info->base_addr,
+ info->base_addr + info->size - 1);
Two things. d isn't declared in ns16x50_deinit() until 21/26, so this
patch, 19/26 and 20/26 don't build with CONFIG_VUART_NS16X50=y (see my
reply to the cover letter). And the permit is unconditional: for a
domain that never had access to the range (any domU), this grants it.
As deinit only runs when the domain is going away, I'd drop the permit;
otherwise it has to restore the state from before ns16x50_init() rather
than assume access was there.
Also, on the error paths of ns16x50_init() that follow (20/26, 21/26),
the range stays denied and the portio handler stays registered. That's
harmless only because the domain then fails to be created; worth a
comment at least.
Another one question I would like to rise is this is x86-specific (I/O
ports, ioport_caps, the PVH hwdom I/O bitmap) in otherwise
arch-independent code, and it isn't specific to an NS16550 either: any
emulated device handed to a domain at a resource the domain could
otherwise reach directly needs the same.
I'd do it in the framework, through a per-arch hook called by
vuart_init() before emulator->alloc() (together with the IRQ part from
20/26), rather than in ns16x50_init(). That's also where an MMIO-based
variant would use iomem_deny_access() instead.
~ Oleksii
|