From 92a15f946bfdba03e7a2cd8c35d205ff2655caaf Mon Sep 17 00:00:00 2001 From: Ryan Stone Date: Wed, 23 Oct 2019 17:20:20 +0000 Subject: [PATCH] Add missing M_NOWAIT flag The LinuxKPI linux_dma code calls PCTRIE_INSERT with a mutex held, but does not set M_NOWAIT when allocating nodes, leading to a potential panic. All of this code can handle an allocation failure here, so prefer an allocation failure to sleeping on memory. Also fix a related case where NOWAIT/WAITOK was not specified. In this case it's not clear whether sleeping is allowed so be conservative and assume not. There are a lot of other paths in this code that can fail due to a lack of memory anyway. Differential Revision: https://reviews.freebsd.org/D22127 Reviewed by: imp Sponsored by: Dell EMC Isilon MFC After: 1 week --- sys/compat/linuxkpi/common/src/linux_pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 32835d3d133a..31a41492a367 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -500,7 +500,7 @@ static void * linux_dma_trie_alloc(struct pctrie *ptree) { - return (uma_zalloc(linux_dma_trie_zone, 0)); + return (uma_zalloc(linux_dma_trie_zone, M_NOWAIT)); } static void @@ -569,7 +569,10 @@ linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len) if (bus_dma_id_mapped(priv->dmat, phys, len)) return (phys); - obj = uma_zalloc(linux_dma_obj_zone, 0); + obj = uma_zalloc(linux_dma_obj_zone, M_NOWAIT); + if (obj == NULL) { + return (0); + } DMA_PRIV_LOCK(priv); if (bus_dmamap_create(priv->dmat, 0, &obj->dmamap) != 0) {