Skip to content

Commit

Permalink
restrict concept of pIRQ to x86
Browse files Browse the repository at this point in the history
... by way of a new arch-selectable Kconfig control.

Note that some smaller pieces of code are left without #ifdef, to keep
things better readable. Hence items like ECS_PIRQ, nr_static_irqs, or
domain_pirq_to_irq() remain uniformly.

As to XEN_DOMCTL_irq_permission - this, despite having a uniformly
available wrapper in libxc, is unused on Arm: libxl bypasses those
calls, and the Python and OCamL bindings have no users at all.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
  • Loading branch information
jbeulich committed Mar 14, 2024
1 parent 4dc9a8b commit 13a7b0f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/misc/xen-command-line.pandoc
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ introduced with the Nehalem architecture.
intended as an emergency option for people who first chose fast, then
change their minds to secure, and wish not to reboot.**

### extra_guest_irqs
### extra_guest_irqs (x86)
> `= [<domU number>][,<dom0 number>]`

> Default: `32,<variable>`
Expand Down
1 change: 0 additions & 1 deletion xen/arch/arm/include/asm/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct arch_irq_desc {

extern const unsigned int nr_irqs;
#define nr_static_irqs NR_IRQS
#define arch_hwdom_irqs(domid) NR_IRQS

struct irq_desc;
struct irqaction;
Expand Down
1 change: 1 addition & 0 deletions xen/arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ config X86
select HAS_PASSTHROUGH
select HAS_PCI
select HAS_PCI_MSI
select HAS_PIRQ
select HAS_SCHED_GRANULARITY
select HAS_UBSAN
select HAS_VPCI if HVM
Expand Down
3 changes: 3 additions & 0 deletions xen/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ config HAS_IOPORTS
config HAS_KEXEC
bool

config HAS_PIRQ
bool

config HAS_PMAP
bool

Expand Down
14 changes: 14 additions & 0 deletions xen/common/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ static int late_hwdom_init(struct domain *d)
#endif
}

#ifdef CONFIG_HAS_PIRQ

static unsigned int __read_mostly extra_hwdom_irqs;
static unsigned int __read_mostly extra_domU_irqs = 32;

Expand All @@ -364,6 +366,8 @@ static int __init cf_check parse_extra_guest_irqs(const char *s)
}
custom_param("extra_guest_irqs", parse_extra_guest_irqs);

#endif /* CONFIG_HAS_PIRQ */

static int __init cf_check parse_dom0_param(const char *s)
{
const char *ss;
Expand Down Expand Up @@ -683,6 +687,7 @@ struct domain *domain_create(domid_t domid,
if ( is_system_domain(d) && !is_idle_domain(d) )
return d;

#ifdef CONFIG_HAS_PIRQ
if ( !is_idle_domain(d) )
{
if ( !is_hardware_domain(d) )
Expand All @@ -694,6 +699,7 @@ struct domain *domain_create(domid_t domid,

radix_tree_init(&d->pirq_tree);
}
#endif

if ( (err = arch_domain_create(d, config, flags)) != 0 )
goto fail;
Expand Down Expand Up @@ -793,7 +799,9 @@ struct domain *domain_create(domid_t domid,
{
evtchn_destroy(d);
evtchn_destroy_final(d);
#ifdef CONFIG_HAS_PIRQ
radix_tree_destroy(&d->pirq_tree, free_pirq_struct);
#endif
}
if ( init_status & INIT_watchdog )
watchdog_domain_destroy(d);
Expand Down Expand Up @@ -1192,7 +1200,9 @@ static void cf_check complete_domain_destroy(struct rcu_head *head)

evtchn_destroy_final(d);

#ifdef CONFIG_HAS_PIRQ
radix_tree_destroy(&d->pirq_tree, free_pirq_struct);
#endif

xfree(d->vcpu);

Expand Down Expand Up @@ -2058,6 +2068,8 @@ long do_vm_assist(unsigned int cmd, unsigned int type)
}
#endif

#ifdef CONFIG_HAS_PIRQ

struct pirq *pirq_get_info(struct domain *d, int pirq)
{
struct pirq *info = pirq_info(d, pirq);
Expand Down Expand Up @@ -2087,6 +2099,8 @@ void cf_check free_pirq_struct(void *ptr)
call_rcu(&pirq->rcu_head, _free_pirq_struct);
}

#endif /* CONFIG_HAS_PIRQ */

struct migrate_info {
long (*func)(void *data);
void *data;
Expand Down
2 changes: 2 additions & 0 deletions xen/common/domctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
}
break;

#ifdef CONFIG_HAS_PIRQ
case XEN_DOMCTL_irq_permission:
{
unsigned int pirq = op->u.irq_permission.pirq, irq;
Expand All @@ -667,6 +668,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
ret = irq_deny_access(d, irq);
break;
}
#endif

case XEN_DOMCTL_iomem_permission:
{
Expand Down
14 changes: 12 additions & 2 deletions xen/common/event_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ static int evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
return rc;
}

#ifdef CONFIG_HAS_PIRQ

static void link_pirq_port(int port, struct evtchn *chn, struct vcpu *v)
{
Expand All @@ -591,9 +592,11 @@ static void unlink_pirq_port(struct evtchn *chn, struct vcpu *v)
chn->u.pirq.prev_port;
}

#endif /* CONFIG_HAS_PIRQ */

static int evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
{
#ifdef CONFIG_HAS_PIRQ
struct evtchn *chn;
struct domain *d = current->domain;
struct vcpu *v = d->vcpu[0];
Expand Down Expand Up @@ -663,6 +666,9 @@ static int evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
write_unlock(&d->event_lock);

return rc;
#else /* !CONFIG_HAS_PIRQ */
return -EOPNOTSUPP;
#endif
}


Expand Down Expand Up @@ -695,6 +701,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
case ECS_UNBOUND:
break;

#ifdef CONFIG_HAS_PIRQ
case ECS_PIRQ: {
struct pirq *pirq = pirq_info(d1, chn1->u.pirq.irq);

Expand All @@ -704,14 +711,13 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
pirq_guest_unbind(d1, pirq);
pirq->evtchn = 0;
pirq_cleanup_check(pirq, d1);
#ifdef CONFIG_X86
if ( is_hvm_domain(d1) && domain_pirq_to_irq(d1, pirq->pirq) > 0 )
unmap_domain_pirq_emuirq(d1, pirq->pirq);
#endif
}
unlink_pirq_port(chn1, d1->vcpu[chn1->notify_vcpu_id]);
break;
}
#endif

case ECS_VIRQ: {
struct vcpu *v;
Expand Down Expand Up @@ -1121,6 +1127,8 @@ int evtchn_bind_vcpu(evtchn_port_t port, unsigned int vcpu_id)
case ECS_INTERDOMAIN:
chn->notify_vcpu_id = v->vcpu_id;
break;

#ifdef CONFIG_HAS_PIRQ
case ECS_PIRQ:
if ( chn->notify_vcpu_id == v->vcpu_id )
break;
Expand All @@ -1130,6 +1138,8 @@ int evtchn_bind_vcpu(evtchn_port_t port, unsigned int vcpu_id)
cpumask_of(v->processor));
link_pirq_port(port, chn, v);
break;
#endif

default:
rc = -EINVAL;
break;
Expand Down
2 changes: 2 additions & 0 deletions xen/include/xen/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ struct domain

struct grant_table *grant_table;

#ifdef CONFIG_HAS_PIRQ
/*
* Interrupt to event-channel mappings and other per-guest-pirq data.
* Protected by the domain's event-channel spinlock.
*/
struct radix_tree_root pirq_tree;
unsigned int nr_pirqs;
#endif

unsigned int options; /* copy of createdomain flags */

Expand Down

0 comments on commit 13a7b0f

Please sign in to comment.