tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lockmgr: no context panic in bus_dmamem_map() call.


I've a technical difficulty for bus_dmamem_map() call to cause
lock fail and would like to have any help to solve.

... short description ...
bus_dmamap_map() call in interrupt context cause lockmgr panic
when (and only when) it is called in lwp == NULL state.

... background ...
I have been helping build a NetBSD device driver for a certain
PCI NIC card which can handle extremely large, 32KB in fact,
Ethernet frame.  To manage such the large mbuf I decided my
mind to utilize rather rare MEXTADD() construct;

add_rxbuf(struct local *sc, int idx)
   struct mbuf *m;

   if (m == NULL)
       return ENOBUFS;
   p = mext_malloc(sc->sc_dmat, TXRXSIZE);
if (p == NULL) return ENOBUFS;
   MEXTADD(m, p, TXRXSIZE, M_MBUF, mext_free, rxs);
   rxs->rxs_mbuf = m;

here mext_malloc() and mext_free() are like;

mext_malloc(bus_dma_tag_t dmat, size_t size)
   bus_dmamem_alloc(dmat, size, PAGE_SIZE, 0, &seg, 1, &nseg, 0);
   bus_dmamem_map(dmat, &seg, nseg, size,
       (caddr_t *)&p, BUS_DMA_COHERENT); /* we're using NB4 */
   return p;

mext_free(struct mbuf *m, caddr_t p, size_t size, void *arg)
   bus_dmamem_unmap(rxs->rxs_dmat, p, size);
   bus_dmamem_free(rxs->rxs_dmat, dmamap->dm_segs, dmamap->dm_nsegs);

... trouble to address ...
MEXTADD() works mostly well.  The one issue we experience is lockmgr
makes panic when add_rxbuf() is called inside rxdone() interrupt handler
which is responsible to create a new mbuf to hook to RX descriptor array.

   lockmgr: no context lwp == NULL

Our analysis has concluded the panic does occur when bus_dmamem_map()
is called during kernel stays in lwp==NULL state.  Apparently standard mbuf
API allows the condition but bus_dmamem_map() does not.

... solution? ...

Toru Nishimura / ALKYL Technology

Home | Main Index | Thread Index | Old Index