Allow interrupt driven config hooks to be registered from config hook callbacks.
Interrupt driven configuration hooks serve two purposes: they are a mechanism for registering for a callback that is invoked once interrupt services are available, and they hold off root device selection so long as any configuration hooks are still active. Before this change, it was not possible to safely register additional hooks from the context of a configuration hook callback. The need for this feature arises when interrupts are required to discover new devices (e.g. access to the XenStore to find para-virtualized devices) which in turn also require the ability to hold off root device selection until some lengthy, interrupt driven, configuration task has completed (e.g. Xen front/back device driver negotiation). More specifically, the mutex protecting the list of active configuration hooks is never held during a callback, and static information is used to ensure proper ordering and only a single callback to each hook even when faced with registration or removal of a hook during an active run. Sponsored by: Spectra Logic Corporation MFC after: 1 week.
This commit is contained in:
parent
af7198501c
commit
5ef8fb65f9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211236
@ -55,11 +55,12 @@ __FBSDID("$FreeBSD$");
|
||||
*/
|
||||
static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
|
||||
TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
|
||||
static struct intr_config_hook *next_to_notify;
|
||||
static struct mtx intr_config_hook_lock;
|
||||
MTX_SYSINIT(intr_config_hook, &intr_config_hook_lock, "intr config", MTX_DEF);
|
||||
|
||||
/* ARGSUSED */
|
||||
static void run_interrupt_driven_config_hooks(void *dummy);
|
||||
static void run_interrupt_driven_config_hooks(void);
|
||||
|
||||
/*
|
||||
* If we wait too long for an interrupt-driven config hook to return, print
|
||||
@ -91,19 +92,46 @@ run_interrupt_driven_config_hooks_warning(int warned)
|
||||
}
|
||||
|
||||
static void
|
||||
run_interrupt_driven_config_hooks(void *dummy)
|
||||
run_interrupt_driven_config_hooks()
|
||||
{
|
||||
struct intr_config_hook *hook_entry, *next_entry;
|
||||
int warned;
|
||||
static int running;
|
||||
struct intr_config_hook *hook_entry;
|
||||
|
||||
mtx_lock(&intr_config_hook_lock);
|
||||
TAILQ_FOREACH_SAFE(hook_entry, &intr_config_hook_list, ich_links,
|
||||
next_entry) {
|
||||
|
||||
/*
|
||||
* If hook processing is already active, any newly
|
||||
* registered hooks will eventually be notified.
|
||||
* Let the currently running session issue these
|
||||
* notifications.
|
||||
*/
|
||||
if (running != 0) {
|
||||
mtx_unlock(&intr_config_hook_lock);
|
||||
return;
|
||||
}
|
||||
running = 1;
|
||||
|
||||
while (next_to_notify != NULL) {
|
||||
hook_entry = next_to_notify;
|
||||
next_to_notify = TAILQ_NEXT(hook_entry, ich_links);
|
||||
mtx_unlock(&intr_config_hook_lock);
|
||||
(*hook_entry->ich_func)(hook_entry->ich_arg);
|
||||
mtx_lock(&intr_config_hook_lock);
|
||||
}
|
||||
|
||||
running = 0;
|
||||
mtx_unlock(&intr_config_hook_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
boot_run_interrupt_driven_config_hooks(void *dummy)
|
||||
{
|
||||
int warned;
|
||||
|
||||
run_interrupt_driven_config_hooks();
|
||||
|
||||
/* Block boot processing until all hooks are disestablished. */
|
||||
mtx_lock(&intr_config_hook_lock);
|
||||
warned = 0;
|
||||
while (!TAILQ_EMPTY(&intr_config_hook_list)) {
|
||||
if (msleep(&intr_config_hook_list, &intr_config_hook_lock,
|
||||
@ -117,8 +145,9 @@ run_interrupt_driven_config_hooks(void *dummy)
|
||||
}
|
||||
mtx_unlock(&intr_config_hook_lock);
|
||||
}
|
||||
|
||||
SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
|
||||
run_interrupt_driven_config_hooks, NULL);
|
||||
boot_run_interrupt_driven_config_hooks, NULL);
|
||||
|
||||
/*
|
||||
* Register a hook that will be called after "cold"
|
||||
@ -141,10 +170,16 @@ config_intrhook_establish(struct intr_config_hook *hook)
|
||||
return (1);
|
||||
}
|
||||
TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
|
||||
if (next_to_notify == NULL)
|
||||
next_to_notify = hook;
|
||||
mtx_unlock(&intr_config_hook_lock);
|
||||
if (cold == 0)
|
||||
/*
|
||||
* XXX Call from a task since not all drivers expect
|
||||
* to be re-entered at the time a hook is established.
|
||||
*/
|
||||
/* XXX Sufficient for modules loaded after initial config??? */
|
||||
run_interrupt_driven_config_hooks(NULL);
|
||||
run_interrupt_driven_config_hooks();
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -161,6 +196,8 @@ config_intrhook_disestablish(struct intr_config_hook *hook)
|
||||
panic("config_intrhook_disestablish: disestablishing an "
|
||||
"unestablished hook");
|
||||
|
||||
if (next_to_notify == hook)
|
||||
next_to_notify = TAILQ_NEXT(hook, ich_links);
|
||||
TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
|
||||
|
||||
/* Wakeup anyone watching the list */
|
||||
|
Loading…
Reference in New Issue
Block a user