From 73761654ab07138a0bfe0af6e4be4de49f341dab Mon Sep 17 00:00:00 2001 From: Carsten Beckmann Date: Mon, 21 Sep 2026 11:49:48 +0200 Subject: [PATCH 5/8] iavf: fix allocations using WAITOK during attach WAITOK is not allowed during attach and would panic, so switch to the respective NOWAIT variants. --- sys/dev/pci/if_iavf.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/sys/dev/pci/if_iavf.c b/sys/dev/pci/if_iavf.c index 6c17b44057a..dced9e1269a 100644 --- a/sys/dev/pci/if_iavf.c +++ b/sys/dev/pci/if_iavf.c @@ -688,7 +688,7 @@ struct iavf_softc { #define delaymsec(_ms) delay(1000 * (_ms)) static int iavf_dmamem_alloc(struct iavf_softc *, struct iavf_dmamem *, - bus_size_t, u_int); + bus_size_t, u_int, int); static void iavf_dmamem_free(struct iavf_softc *, struct iavf_dmamem *); static struct iavf_aq_buf * @@ -882,7 +882,7 @@ iavf_setup_interrupts(struct iavf_softc *sc, struct pci_attach_args *pa) } sc->sc_vectors = mallocarray(sizeof(*sc->sc_vectors), nqueues, - M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO); + M_DEVBUF, M_NOWAIT|M_CANFAIL|M_ZERO); if (sc->sc_vectors == NULL) { printf("%s: unable to allocate vectors\n", DEVNAME(sc)); return -1; @@ -983,7 +983,7 @@ iavf_attach(struct device *parent, struct device *self, void *aux) mtx_init(&sc->sc_atq_mtx, IPL_NET); if (iavf_dmamem_alloc(sc, &sc->sc_atq, - sizeof(struct iavf_aq_desc) * IAVF_AQ_NUM, IAVF_AQ_ALIGN) != 0) { + sizeof(struct iavf_aq_desc) * IAVF_AQ_NUM, IAVF_AQ_ALIGN, 0) != 0) { printf("\n" "%s: unable to allocate atq\n", DEVNAME(sc)); goto unmap; } @@ -995,7 +995,7 @@ iavf_attach(struct device *parent, struct device *self, void *aux) sc->sc_arq_prod = 0; if (iavf_dmamem_alloc(sc, &sc->sc_arq, - sizeof(struct iavf_aq_desc) * IAVF_AQ_NUM, IAVF_AQ_ALIGN) != 0) { + sizeof(struct iavf_aq_desc) * IAVF_AQ_NUM, IAVF_AQ_ALIGN, 0) != 0) { printf("\n" "%s: unable to allocate arq\n", DEVNAME(sc)); goto free_atq; } @@ -1017,7 +1017,8 @@ iavf_attach(struct device *parent, struct device *self, void *aux) } timeout_set(&sc->sc_admin_timeout, iavf_arq_timeout, sc); - if (iavf_dmamem_alloc(sc, &sc->sc_scratch, PAGE_SIZE, IAVF_AQ_ALIGN) != 0) { + if (iavf_dmamem_alloc(sc, &sc->sc_scratch, + PAGE_SIZE, IAVF_AQ_ALIGN, 0) != 0) { printf("\n" "%s: unable to allocate scratch\n", DEVNAME(sc)); goto shutdown; } @@ -1869,7 +1870,7 @@ iavf_txr_alloc(struct iavf_softc *sc, unsigned int qid) if (iavf_dmamem_alloc(sc, &txr->txr_mem, sizeof(struct iavf_tx_desc) * sc->sc_tx_ring_ndescs, - IAVF_TX_QUEUE_ALIGN) != 0) + IAVF_TX_QUEUE_ALIGN, 1) != 0) goto freemap; for (i = 0; i < sc->sc_tx_ring_ndescs; i++) { @@ -2240,7 +2241,7 @@ iavf_rxr_alloc(struct iavf_softc *sc, unsigned int qid) if (iavf_dmamem_alloc(sc, &rxr->rxr_mem, sizeof(struct iavf_rx_rd_desc_32) * sc->sc_rx_ring_ndescs, - IAVF_RX_QUEUE_ALIGN) != 0) + IAVF_RX_QUEUE_ALIGN, 1) != 0) goto freemap; for (i = 0; i < sc->sc_rx_ring_ndescs; i++) { @@ -3056,22 +3057,22 @@ iavf_aqb_alloc(struct iavf_softc *sc) { struct iavf_aq_buf *aqb; - aqb = malloc(sizeof(*aqb), M_DEVBUF, M_WAITOK); + aqb = malloc(sizeof(*aqb), M_DEVBUF, M_NOWAIT); if (aqb == NULL) return (NULL); - aqb->aqb_data = dma_alloc(IAVF_AQ_BUFLEN, PR_WAITOK); + aqb->aqb_data = dma_alloc(IAVF_AQ_BUFLEN, PR_NOWAIT); if (aqb->aqb_data == NULL) goto free; if (bus_dmamap_create(sc->sc_dmat, IAVF_AQ_BUFLEN, 1, IAVF_AQ_BUFLEN, 0, - BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW | BUS_DMA_64BIT, + BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW | BUS_DMA_64BIT, &aqb->aqb_map) != 0) goto dma_free; if (bus_dmamap_load(sc->sc_dmat, aqb->aqb_map, aqb->aqb_data, - IAVF_AQ_BUFLEN, NULL, BUS_DMA_WAITOK) != 0) + IAVF_AQ_BUFLEN, NULL, BUS_DMA_NOWAIT) != 0) goto destroy; return (aqb); @@ -3188,24 +3189,26 @@ iavf_arq_wait(struct iavf_softc *sc, int msec) static int iavf_dmamem_alloc(struct iavf_softc *sc, struct iavf_dmamem *ixm, - bus_size_t size, u_int align) + bus_size_t size, u_int align, int waitok) { + int wait_flag = waitok ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT; + ixm->ixm_size = size; if (bus_dmamap_create(sc->sc_dmat, ixm->ixm_size, 1, ixm->ixm_size, 0, - BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW | BUS_DMA_64BIT, + wait_flag | BUS_DMA_ALLOCNOW | BUS_DMA_64BIT, &ixm->ixm_map) != 0) return (1); if (bus_dmamem_alloc(sc->sc_dmat, ixm->ixm_size, align, 0, &ixm->ixm_seg, 1, &ixm->ixm_nsegs, - BUS_DMA_WAITOK | BUS_DMA_ZERO | BUS_DMA_64BIT) != 0) + wait_flag | BUS_DMA_ZERO | BUS_DMA_64BIT) != 0) goto destroy; if (bus_dmamem_map(sc->sc_dmat, &ixm->ixm_seg, ixm->ixm_nsegs, - ixm->ixm_size, &ixm->ixm_kva, BUS_DMA_WAITOK) != 0) + ixm->ixm_size, &ixm->ixm_kva, wait_flag) != 0) goto free; if (bus_dmamap_load(sc->sc_dmat, ixm->ixm_map, ixm->ixm_kva, - ixm->ixm_size, NULL, BUS_DMA_WAITOK) != 0) + ixm->ixm_size, NULL, wait_flag) != 0) goto unmap; return (0); -- 2.53.0