[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: map_domain_pirq(): pirq already mapped?
- To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- From: Jason Andryuk <jason.andryuk@xxxxxxx>
- Date: Thu, 14 May 2026 21:01:28 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Je8W8zM4s44lRTI5pNkIFUj9YashlH2zchz5vH3mpi8=; b=WLNhOVND3xPRvodRehhcgSAG9L1qjINHIzSrfJzUn1OgBxFy+dAchTjoL1laQNJzhPO88ljKToVpvcvKyiAce6HtG0bnBbt8/XysGztfLn6f/aPnIZQA5zAFGlO/z/npSt5bGl0coIs+/54/Yr3Y3p6AZ50Zn2DYvNIyKBWzhDoUfp4Nst0IE6dIl0YNSQUvljlxVRQgNeqepVzFHBowp4aY6Yx36s4/hMZX/yGLVzsAfAUDfPziHqweNnNIeZ/F3zI2ldrCFgB7ZdhPctN2mf2hjefmvyPuHCLWEJRsZuU4FlsYmeixOW86nrvezV3AeQytv0obyMahzyV0jsW9ng==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LC5mk99qvxWRCon06e0XE2+eORAxlWCTT/7BtMiVpst2KC2cjsMqXeTeN7LcpZX/Z0r5wMyKWhrV6H024zxpMXcGmqJOL2BCbIo2nWOAvywMosTOjs2Q3Fymi+CBIhy2eP7Mayqk8/yuPC9xgzCxuExdQ2cyd25FARixK5He/uFXou9mlDhuWlMc7HxhAQJEyZqvZ8gdfduX+bA50I2o/k+9Gwwm+M61lvXl5lEDebfkcPC4YqneNPTptTOiW6U2mZ+aZzZfKwYU2kLqGIZJZU+qyphyx1tGvvroNI6gDBXukriarUr472PE+3vSeNUSkDTF0WonpvQy1g2IBh/Y1Q==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Fri, 15 May 2026 01:01:56 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Hi Roger,
Thanks for taking a look.
On 2026-05-14 04:26, Roger Pau Monné wrote:
On Wed, May 13, 2026 at 09:18:46PM -0400, Jason Andryuk wrote:
Hi,
Early in map_domain_pirq(), we have this block:
old_irq = domain_pirq_to_irq(d, pirq);
old_pirq = domain_irq_to_pirq(d, irq);
if ( (old_irq > 0 && (old_irq != irq) ) ||
(old_pirq && (old_pirq != pirq)) )
{
dprintk(XENLOG_G_WARNING,
"dom%d: pirq %d or irq %d already mapped (%d,%d)\n",
d->domain_id, pirq, irq, old_pirq, old_irq);
return 0;
}
Why do we return 0 instead of -EEXIST? Since the pirq is not updated, the
caller doesn't know that pirq won't fire - only old_pirq. For
allocate_and_map_gsi_pirq(), the new pirq is still returned to the caller.
I would expect old_pirq to be returned so the caller knows what to use. Am
I missing something?
Looking at bfc341a65cfb2 it seems like this might have been an attempt
to keep the previous logic in ioapic_guest_write() that didn't return
an error when attempting to add/move an in use IRQ, while switching
ioapic_guest_write() to use map_domain_pirq()?
The commit description is not very helpful sadly. I think the mention
of "And this patch also makes broken NetBSD dom0 work again." is
relevant. AFAICT NetBSD will do PHYSDEVOP_apic_read -> modify RTE (ie:
set mask bit for example) -> PHYSDEVOP_apic_write. However the
semantics of those hypercalls is not symmetric. PHYSDEVOP_apic_read
will return the vector used by Xen in the RTE, while
PHYSDEVOP_apic_write expects the vector field of the RTE to contain
the pIRQ. I think this is why map_domain_pirq() was adjusted in such
a weird way, to ignore requests with bogus pIRQs and still succeed, so
that PHYSDEVOP_apic_write would also succeed. Ideally the interface
should have been adjusted so that read/modify/write cycles using
PHYSDEVOP_apic_{read,write} would work as expected (iow:
PHYSDEVOP_apic_read should have returned the pIRQ in the vector
field).
In the context of GSIs, I think we aim for Xen to always identity map
them (so IRQ == pIRQ), but there might be (or might have been)
hypercalls that could allow you to create non-identity mappings
between GSIs and pIRQs.
To support non-PCI passthrough with Hyperlaunch, we added code to map a
GSI to a vIOAPIC. It does not require identity mapping, and that works.
It was while testing conditions that I expected to fail that I found
the behavior.
First map:
machine A -> guest B
Then map:
machine A -> guest C "success" from the return 0
Explicitly looking at allocate_and_map_gsi_pirq() do you know what
causes the domain_irq_to_pirq() in allocate_pirq() to not return the
already allocated pIRQ that matches the passed IRQ?
Well, it's PVH and I'm making up a "PIRQ" for the vIOAPIC.
Overall we should likely adjust map_domain_pirq() to return -EEIXST,
and then fix ioapic_guest_write() to shallow such error so we can keep
the current behavior for that specific interface.
Having been focused on PVH, I didn't look much at the PV behavior. But
it was still surprising to see the "no-op" success.
Thanks for the pointers.
Regards,
Jason
|