diff --git a/sys/dev/xen/bus/xen_intr.c b/sys/dev/xen/bus/xen_intr.c --- a/sys/dev/xen/bus/xen_intr.c +++ b/sys/dev/xen/bus/xen_intr.c @@ -166,6 +166,7 @@ struct xen_intr_pcpu_data *pcpu; pcpu = DPCPU_ID_PTR(cpu, xen_intr_pcpu); + KASSERT(is_valid_evtchn(port), ("Invalid event channel port")); xen_clear_bit(port, pcpu->evtchn_enabled); } @@ -188,6 +189,7 @@ struct xen_intr_pcpu_data *pcpu; pcpu = DPCPU_ID_PTR(cpu, xen_intr_pcpu); + KASSERT(is_valid_evtchn(port), ("Invalid event channel port")); xen_set_bit(port, pcpu->evtchn_enabled); } @@ -619,7 +621,8 @@ xen_intr_disable_intr(struct xenisrc *isrc) { - evtchn_mask_port(isrc->xi_port); + if (__predict_true(is_valid_evtchn(isrc->xi_port))) + evtchn_mask_port(isrc->xi_port); } /** @@ -706,7 +709,8 @@ * unmasked by the generic interrupt code. The event channel * device will unmask them when needed. */ - isrc->xi_masked = !!evtchn_test_and_set_mask(isrc->xi_port); + if (__predict_true(is_valid_evtchn(isrc->xi_port))) + isrc->xi_masked = !!evtchn_test_and_set_mask(isrc->xi_port); } /* diff --git a/sys/xen/evtchn/evtchnvar.h b/sys/xen/evtchn/evtchnvar.h --- a/sys/xen/evtchn/evtchnvar.h +++ b/sys/xen/evtchn/evtchnvar.h @@ -37,8 +37,11 @@ #include /* Macros for accessing event channel values */ -#define EVTCHN_PTR(type, port) \ - (HYPERVISOR_shared_info->evtchn_##type + ((port) / __LONG_BIT)) +#define EVTCHN_PTR(type, port) ({ \ + KASSERT(port < nitems(HYPERVISOR_shared_info->evtchn_##type) * \ + sizeof(xen_ulong_t) * 8, ("Invalid event channel port")); \ + (HYPERVISOR_shared_info->evtchn_##type + ((port) / __LONG_BIT));\ +}) #define EVTCHN_BIT(port) ((port) & (__LONG_BIT - 1)) #define EVTCHN_MASK(port) (1UL << EVTCHN_BIT(port))