Re: ix(4) shouldn't crash on memory allocation failure

2023-07-08 Thread Hrvoje Popovski
On 7.7.2023. 11:24, Jonathan Matthew wrote:
> One of the problems described here:
> https://www.mail-archive.com/tech@openbsd.org/msg71790.html
> amounts to ix(4) not checking that it allocated a dma map before trying to 
> free it.
> 
> ok?
> 
> 

Hi,

with this diff box won't panic if I have em multiqueue diff and bring
ix(4) up...

without diff
x3550m4# ifconfig ix0 up
ix0: Unable to create Pack DMA map
uvm_fault(0xfd877edf6180, 0xc, 0, 1) -> e
kernel: page fault trap, code=0
Stopped at  _bus_dmamap_destroy+0xd:movl0xc(%rsi),%eax
TIDPIDUID PRFLAGS PFLAGS  CPU  COMMAND
* 11781  20784  0 0x3  01K ifconfig
_bus_dmamap_destroy(824a5a40,0) at _bus_dmamap_destroy+0xd
ixgbe_free_receive_buffers(800e8910) at
ixgbe_free_receive_buffers+0xb2
ixgbe_init(800e6000) at ixgbe_init+0x788
ixgbe_ioctl(800e6048,80206910,800021bb6d80) at ixgbe_ioctl+0x327
ifioctl(fd87809651f8,80206910,800021bb6d80,800021bed8a0) at
ifioctl+0x7cc
sys_ioctl(800021bed8a0,800021bb6e90,800021bb6ef0) at
sys_ioctl+0x2c4
syscall(800021bb6f60) at syscall+0x3d4
Xsyscall() at Xsyscall+0x128
end of kernel
end trace frame: 0x7931b1531760, count: 7
https://www.openbsd.org/ddb.html describes the minimum info required in bug
reports.  Insufficient info makes it difficult to find and fix bugs.
ddb{1}>


with diff
x3550m4# ifconfig ix0 up
ix0: Unable to create Pack DMA map
ix0: Could not setup receive structures
x3550m4# ifconfig ix1 up
ix1: Unable to create Pack DMA map
ix1: Could not setup receive structures
x3550m4#


x3550m4# vmstat -iz
interrupt   total rate
irq144/com0  3537   11
irq145/com1 00
irq96/acpi0 00
irq97/ppb0  00
irq98/ppb1  00
irq99/ppb2  00
irq114/ix0:000
irq115/ix0:100
irq116/ix0:200
irq117/ix0:300
irq118/ix0:400
irq119/ix0:500
irq120/ix0:600
irq121/ix0:700
irq122/ix0:800
irq123/ix0:900
irq124/ix0:10   00
irq125/ix0:11   00
irq126/ix0  00
irq127/ix1:000
irq128/ix1:100
irq129/ix1:200
irq130/ix1:300
irq131/ix1:400
irq132/ix1:500
irq133/ix1:600
irq134/ix1:700
irq135/ix1:800
irq136/ix1:900
irq137/ix1:10   00
irq138/ix1:11   00
irq139/ix1  00
irq100/ppb3 00
irq101/mfii042327  135
irq102/ehci0   230
irq103/ppb5 00
irq140/em0:0  8732
irq141/em0:1  3261
irq142/em0:210
irq143/em0:3   230
irq146/em0:4   550
irq147/em0:500
irq148/em0:6   240
irq149/em0:760
irq150/em0  20
irq151/em1:020
irq152/em1:100
irq153/em1:200
irq154/em1:300
irq155/em1:400
irq156/em1:500
irq157/em1:600
irq158/em1:700
irq159/em1  20
irq160/em2:020
irq161/em2:100
irq162/em2:200
irq163/em2:300
irq164/em2:400
irq165/em2:500
irq166/em2:600
irq167/em2:700
irq168/em2  20
irq169/em3:020
irq170/em3:100
irq171/em3:200
irq172/em3:300
irq173/em3:400
irq174/em3:500
irq175/em3:600
irq176/em3:7

ix(4) shouldn't crash on memory allocation failure

2023-07-07 Thread Jonathan Matthew
One of the problems described here:
https://www.mail-archive.com/tech@openbsd.org/msg71790.html
amounts to ix(4) not checking that it allocated a dma map before trying to free 
it.

ok?


Index: if_ix.c
===
RCS file: /cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.197
diff -u -p -r1.197 if_ix.c
--- if_ix.c 1 Jun 2023 09:05:33 -   1.197
+++ if_ix.c 7 Jul 2023 09:22:30 -
@@ -3094,8 +3094,11 @@ ixgbe_free_receive_buffers(struct rx_rin
m_freem(rxbuf->buf);
rxbuf->buf = NULL;
}
-   bus_dmamap_destroy(rxr->rxdma.dma_tag, rxbuf->map);
-   rxbuf->map = NULL;
+   if (rxbuf->map != NULL) {
+   bus_dmamap_destroy(rxr->rxdma.dma_tag,
+   rxbuf->map);
+   rxbuf->map = NULL;
+   }
}
free(rxr->rx_buffers, M_DEVBUF,
sc->num_rx_desc * sizeof(struct ixgbe_rx_buf));