From: deraadt Date: Wed, 2 Feb 2022 04:05:16 +0000 (+0000) Subject: acpi_addtask() calls malloc() w/ M_NOWAIT (because some calls come from X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f48369e00dd0c5bcc6b1c49c8787d8007deeb4e2;p=openbsd acpi_addtask() calls malloc() w/ M_NOWAIT (because some calls come from interrupt context), this however means occasional resource shortage will result in callbacks registration failing, and unknown consequences for the task-submitting caller. Changing this to use pools with a low water mark, decreases the odds of that problem occuring. ok kettenis --- diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index acbaa1b07c0..6644c52464a 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.407 2022/02/01 18:09:00 deraadt Exp $ */ +/* $OpenBSD: acpi.c,v 1.408 2022/02/02 04:05:16 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,8 @@ int acpi_poll_enabled; int acpi_hasprocfvs; int acpi_haspci; +struct pool acpiwqpool; + #define ACPIEN_RETRIES 15 struct aml_node *acpi_pci_match(struct device *, struct pci_attach_args *); @@ -1007,6 +1010,10 @@ acpi_attach_common(struct acpi_softc *sc, paddr_t base) } rsdp = (struct acpi_rsdp *)handle.va; + pool_init(&acpiwqpool, sizeof(struct acpi_taskq), 0, IPL_BIO, 0, + "acpiwqpl", NULL); + pool_setlowat(&acpiwqpool, 16); + SIMPLEQ_INIT(&sc->sc_tables); SIMPLEQ_INIT(&sc->sc_wakedevs); #if NACPIPWRRES > 0 @@ -1798,9 +1805,11 @@ acpi_addtask(struct acpi_softc *sc, void (*handler)(void *, int), struct acpi_taskq *wq; int s; - wq = malloc(sizeof(*wq), M_DEVBUF, M_ZERO | M_NOWAIT); - if (wq == NULL) + wq = pool_get(&acpiwqpool, PR_ZERO | PR_NOWAIT); + if (wq == NULL) { + printf("unable to create task"); return; + } wq->handler = handler; wq->arg0 = arg0; wq->arg1 = arg1; @@ -1829,7 +1838,7 @@ acpi_dotask(struct acpi_softc *sc) wq->handler(wq->arg0, wq->arg1); - free(wq, M_DEVBUF, sizeof(*wq)); + pool_put(&acpiwqpool, wq); /* We did something */ return (1);