Index: rtable.c =================================================================== RCS file: /cvs/src/sys/net/rtable.c,v retrieving revision 1.84 diff -u -p -r1.84 rtable.c --- rtable.c 11 Nov 2023 12:17:50 -0000 1.84 +++ rtable.c 11 Nov 2023 18:01:07 -0000 @@ -26,6 +26,7 @@ #include #include #include +#include #endif #include @@ -49,7 +50,6 @@ * | AF_MPLS | indexed by ``rtableid''. * ----------- */ -struct srp *afmap; uint8_t af2idx[AF_MAX+1]; /* To only allocate supported AF */ uint8_t af2idx_max; @@ -59,6 +59,8 @@ struct rtmap { void **tbl; }; +struct rtmap **afmap; /* smr protected */ + /* * Array of rtableid -> rdomain mapping. * @@ -79,9 +81,6 @@ unsigned int rtmap_limit = 0; void rtmap_init(void); void rtmap_grow(unsigned int, sa_family_t); -void rtmap_dtor(void *, void *); - -struct srp_gc rtmap_gc = SRP_GC_INITIALIZER(rtmap_dtor, NULL); void rtable_init_backend(void); void *rtable_alloc(unsigned int, unsigned int, unsigned int); @@ -125,28 +124,32 @@ rtmap_grow(unsigned int nlimit, sa_famil nmap->tbl = mallocarray(nlimit, sizeof(*nmap[0].tbl), M_RTABLE, M_WAITOK|M_ZERO); - map = srp_get_locked(&afmap[af2idx[af]]); + map = SMR_PTR_GET_LOCKED(&afmap[af2idx[af]]); if (map != NULL) { KASSERT(map->limit == rtmap_limit); - for (i = 0; i < map->limit; i++) - nmap->tbl[i] = map->tbl[i]; + for (i = 0; i < map->limit; i++) { + /* + * nmap isn't visible yet, so don't need + * SMR_PTR_SET_LOCKED and its membar. + */ + nmap->tbl[i] = SMR_PTR_GET_LOCKED(&map->tbl[i]); + } } - srp_update_locked(&rtmap_gc, &afmap[af2idx[af]], nmap); -} + SMR_PTR_SET_LOCKED(&afmap[af2idx[af]], nmap); -void -rtmap_dtor(void *null, void *xmap) -{ - struct rtmap *map = xmap; + if (map != NULL) { + smr_barrier(); - /* - * doesn't need to be serialized since this is the last reference - * to this map. there's nothing to race against. - */ - free(map->tbl, M_RTABLE, map->limit * sizeof(*map[0].tbl)); - free(map, M_RTABLE, sizeof(*map)); + /* + * doesn't need to be serialized since this is the + * last reference to this map. there's nothing to + * race against. + */ + free(map->tbl, M_RTABLE, map->limit * sizeof(*map[0].tbl)); + free(map, M_RTABLE, sizeof(*map)); + } } void @@ -224,8 +227,8 @@ rtable_add(unsigned int id) goto out; } - map = srp_get_locked(&afmap[af2idx[af]]); - map->tbl[id] = tbl; + map = SMR_PTR_GET_LOCKED(&afmap[af2idx[af]]); + SMR_PTR_SET_LOCKED(&map->tbl[id], tbl); } /* Reflect possible growth. */ @@ -235,7 +238,7 @@ rtable_add(unsigned int id) } /* Use main rtable/rdomain by default. */ - dmm = srp_get_locked(&afmap[0]); + dmm = (struct dommp *)SMR_PTR_GET_LOCKED(&afmap[0]); dmm->value[id] = 0; out: KERNEL_UNLOCK(); @@ -248,15 +251,15 @@ rtable_get(unsigned int rtableid, sa_fam { struct rtmap *map; void *tbl = NULL; - struct srp_ref sr; if (af >= nitems(af2idx) || af2idx[af] == 0) return (NULL); - map = srp_enter(&sr, &afmap[af2idx[af]]); + smr_read_enter(); + map = SMR_PTR_GET(&afmap[af2idx[af]]); if (rtableid < map->limit) - tbl = map->tbl[rtableid]; - srp_leave(&sr); + tbl = SMR_PTR_GET(&map->tbl[rtableid]); + smr_read_leave(); return (tbl); } @@ -306,12 +309,14 @@ rtable_l2(unsigned int rtableid) { struct dommp *dmm; unsigned int rdomain = 0; - struct srp_ref sr; - dmm = srp_enter(&sr, &afmap[0]); - if (rtableid < dmm->limit) - rdomain = (dmm->value[rtableid] & RT_TABLEID_MASK); - srp_leave(&sr); + smr_read_enter(); + dmm = (struct dommp *)SMR_PTR_GET(&afmap[0]); + if (rtableid < dmm->limit) { + rdomain = atomic_load_int(&dmm->value[rtableid]) & + RT_TABLEID_MASK; + } + smr_read_leave(); return (rdomain); } @@ -321,12 +326,14 @@ rtable_loindex(unsigned int rtableid) { struct dommp *dmm; unsigned int loifidx = 0; - struct srp_ref sr; - dmm = srp_enter(&sr, &afmap[0]); - if (rtableid < dmm->limit) - loifidx = (dmm->value[rtableid] >> RT_TABLEID_BITS); - srp_leave(&sr); + smr_read_enter(); + dmm = (struct dommp *)SMR_PTR_GET(&afmap[0]); + if (rtableid < dmm->limit) { + loifidx = atomic_load_int(&dmm->value[rtableid]) >> + RT_TABLEID_BITS; + } + smr_read_leave(); return (loifidx); } @@ -344,10 +351,9 @@ rtable_l2set(unsigned int rtableid, unsi value = (rdomain & RT_TABLEID_MASK) | (loifidx << RT_TABLEID_BITS); - dmm = srp_get_locked(&afmap[0]); - dmm->value[rtableid] = value; + dmm = (struct dommp *)SMR_PTR_GET_LOCKED(&afmap[0]); + atomic_store_int(&dmm->value[rtableid], value); } - static inline const uint8_t *satoaddr(struct art_root *, const struct sockaddr *);