]> git.lizzy.rs Git - plan9front.git/commitdiff
ether8169: deal with kernel memory exhaution
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sun, 7 Jan 2018 23:23:26 +0000 (00:23 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sun, 7 Jan 2018 23:23:26 +0000 (00:23 +0100)
when kernel memory is exhausted, rtl8169replenish() can fail
to plant more receive descriptors and rtl8169receive() would
run over the receive tail and crash on the nil ctlr->rb[x].

rtl8169receive() is called on "Receive Descriptor Unavailable"
and "Packet Underrun" so we will try to replenish descriptors
in the beginning first in case memory was exhausted and memory
is available again and make sure not to run over the tail.

sys/src/9/pc/ether8169.c

index 02f39c5f3855c29c3fd719d3e9f9352796921dcd..734608ab96ddb8fc083a0b8b7e7c8b869bd653a4 100644 (file)
@@ -919,8 +919,10 @@ rtl8169receive(Ether* edev)
        int x;
 
        ctlr = edev->ctlr;
-       x = ctlr->rdh;
-       for(;;){
+       if(ctlr->nrq < ctlr->nrd/2)
+               rtl8169replenish(ctlr);
+
+       for(x = ctlr->rdh; x != ctlr->rdt;){
                d = &ctlr->rd[x];
                if((control = d->control) & Own)
                        break;