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.



Hi,

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;

   m = MGETHDR(m, M_DONTWAIT, MT_DATA);
   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
   panic(c077421a,1,1,c08790e0,0)
   lockmgr(c084c924,10012,c084c9cc,0,0)
   uvm_map_prepare(c084c920,c0000000,8000,0,ffffffff)
   uvm_map(c084c920,c0931a00,8000,0,ffffffff)
   uvm_km_alloc(c084c920,8000,0,4,c07f3b40)
   bus_dmamem_map()

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