Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen/xen Reorder the receive code to avoid a possibl...



details:   https://anonhg.NetBSD.org/src/rev/39ac48bc117a
branches:  trunk
changeset: 580985:39ac48bc117a
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed May 18 16:11:32 2005 +0000

description:
Reorder the receive code to avoid a possible race with the sc_rx->event
stuff, and fix a possible infinite loop in case of ressource shortage.

diffstat:

 sys/arch/xen/xen/if_xennet.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (53 lines):

diff -r 69f13b41e89b -r 39ac48bc117a sys/arch/xen/xen/if_xennet.c
--- a/sys/arch/xen/xen/if_xennet.c      Wed May 18 16:11:11 2005 +0000
+++ b/sys/arch/xen/xen/if_xennet.c      Wed May 18 16:11:32 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_xennet.c,v 1.23 2005/05/17 04:14:57 christos Exp $  */
+/*     $NetBSD: if_xennet.c,v 1.24 2005/05/18 16:11:32 bouyer Exp $    */
 
 /*
  *
@@ -33,7 +33,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.23 2005/05/17 04:14:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.24 2005/05/18 16:11:32 bouyer Exp $");
 
 #include "opt_inet.h"
 #include "rnd.h"
@@ -650,7 +650,7 @@
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
        netif_rx_response_t *rx;
        paddr_t pa;
-       NETIF_RING_IDX ringidx;
+       NETIF_RING_IDX ringidx, resp_prod;
        mmu_update_t *mmu = rx_mmu;
        multicall_entry_t *mcl = rx_mcl;
        struct mbuf *m;
@@ -662,8 +662,10 @@
 #endif
 
  again:
+       resp_prod = sc->sc_rx->resp_prod;
+       x86_lfence(); /* ensure we see all requests up to resp_prod */
        for (ringidx = sc->sc_rx_resp_cons;
-            ringidx != sc->sc_rx->resp_prod;
+            ringidx != resp_prod;
             ringidx++) {
                rx = &sc->sc_rx->ring[MASK_NETIF_RX_IDX(ringidx)].resp;
 
@@ -766,9 +768,11 @@
        }
 
        sc->sc_rx_resp_cons = ringidx;
-       sc->sc_rx->event = sc->sc_rx_resp_cons + 1;
+       sc->sc_rx->event = resp_prod + 1;
+       x86_lfence();
+         /* ensure backend see the new sc_rx->event before we start again */
 
-       if (sc->sc_rx->resp_prod != ringidx)
+       if (sc->sc_rx->resp_prod != resp_prod)
                goto again;
 
        return 0;



Home | Main Index | Thread Index | Old Index