[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: map_domain_pirq(): pirq already mapped?


  • To: Jason Andryuk <jason.andryuk@xxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 14 May 2026 10:26:20 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • 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=0yarz+iCBQ6fwySuMnC6plDb2Fr9B9vp4POLRhIBt/8=; b=PCn+5KYdwHi27x4WNhE8U9CKq0owXHzd7tIAkfK2LTKsuAqYAoI/oeBHCPaHcqUF0dAe88vl2laB3mx7uyCKlVHM7B7pITLd49pbNRSMhrKpK8M18ww99ZcmYS/nqSI35kzmviipvCDZI0AqQbkvJIPc0wPaiI+A8yMq2jekimrz4N2+KzfktuH3RcwiHeWdVa4zBOaifIYYaq4GYxZk1jfLzI4r/XrjG1u4wI+oefLIvf/mN1Vd1hjUTr4JEmU9uwACzRW/bIAzuce8Cud0t+YSHBSDB12kMHIaZJymMYP3WFf3Iqk/w2kRlvgjcrgv7ZIkhV+RAmDbox3kKaBA9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QIEO/Rlckm/N/aqvY5pU3+9CserO23BXZiLPT3uTuSj/Cw91kD8UJLhTnLr3lsZE5eZWY5kY+k64wlt11w7R/o4j9CL8XwWJytwfE+vMod2C1bM0g8axe7YaUPR0g3tdzQ9kcS3faeNJVe+j10MqFupM/AM/FPD7FXq9JnibZlOV2poJkvPy54gXD2McDTzTc4qofN7LozI9gdlCBAtQ1PwPXub++WiOrwapWLIR7tu76z5M/dx7+Odfb2iIJsivR0F6BlpPVJfmx8rlodBP0zHF3N7vI8pHqo84+tQ+qtcpGwByvH3BlH3OtnTrBI+zFlJGZcW22q16XZS46UtJLg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 14 May 2026 08:26:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

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?

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.

Regards, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.