From owner-svn-src-all@freebsd.org Wed Oct 9 17:08:41 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 83287128C48; Wed, 9 Oct 2019 17:08:41 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46pLK52xJ3z3Bvx; Wed, 9 Oct 2019 17:08:41 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 48BBB1B9E6; Wed, 9 Oct 2019 17:08:41 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x99H8fKe092486; Wed, 9 Oct 2019 17:08:41 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x99H8fZO092485; Wed, 9 Oct 2019 17:08:41 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201910091708.x99H8fZO092485@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 9 Oct 2019 17:08:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353359 - head/sys/netinet X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/netinet X-SVN-Commit-Revision: 353359 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Oct 2019 17:08:41 -0000 Author: hselasky Date: Wed Oct 9 17:08:40 2019 New Revision: 353359 URL: https://svnweb.freebsd.org/changeset/base/353359 Log: Factor out TCP rateset destruction code. Ensure the epoch_call() function is not called more than one time before the callback has been executed, by always checking the RS_FUNERAL_SCHD flag before invoking epoch_call(). The "rs_number_dead" is balanced again after r353353. Discussed with: rrs@ Sponsored by: Mellanox Technologies Modified: head/sys/netinet/tcp_ratelimit.c Modified: head/sys/netinet/tcp_ratelimit.c ============================================================================== --- head/sys/netinet/tcp_ratelimit.c Wed Oct 9 17:06:56 2019 (r353358) +++ head/sys/netinet/tcp_ratelimit.c Wed Oct 9 17:08:40 2019 (r353359) @@ -270,6 +270,23 @@ rs_destroy(epoch_context_t ctx) } } +static void +rs_defer_destroy(struct tcp_rate_set *rs) +{ + + mtx_assert(&rs_mtx, MA_OWNED); + + /* Check if already pending. */ + if (rs->rs_flags & RS_FUNERAL_SCHD) + return; + + rs_number_dead++; + + /* Set flag to only defer once. */ + rs->rs_flags |= RS_FUNERAL_SCHD; + epoch_call(net_epoch, &rs->rs_epoch_ctx, rs_destroy); +} + #ifdef INET extern counter_u64_t rate_limit_set_ok; extern counter_u64_t rate_limit_active; @@ -989,7 +1006,6 @@ tcp_rl_ifnet_departure(void *arg __unused, struct ifne (rs->rs_if_dunit == ifp->if_dunit)) { CK_LIST_REMOVE(rs, next); rs_number_alive--; - rs_number_dead++; rs->rs_flags |= RS_IS_DEAD; for (i = 0; i < rs->rs_rate_cnt; i++) { if (rs->rs_rlt[i].flags & HDWRPACE_TAGPRESENT) { @@ -999,14 +1015,8 @@ tcp_rl_ifnet_departure(void *arg __unused, struct ifne } rs->rs_rlt[i].flags = HDWRPACE_IFPDEPARTED; } - if (rs->rs_flows_using == 0) { - /* - * No references left, so we can schedule the - * destruction after the epoch (with a caveat). - */ - rs->rs_flags |= RS_FUNERAL_SCHD; - epoch_call(net_epoch, &rs->rs_epoch_ctx, rs_destroy); - } + if (rs->rs_flows_using == 0) + rs_defer_destroy(rs); break; } } @@ -1024,7 +1034,6 @@ tcp_rl_shutdown(void *arg __unused, int howto __unused CK_LIST_FOREACH_SAFE(rs, &int_rs, next, nrs) { CK_LIST_REMOVE(rs, next); rs_number_alive--; - rs_number_dead++; rs->rs_flags |= RS_IS_DEAD; for (i = 0; i < rs->rs_rate_cnt; i++) { if (rs->rs_rlt[i].flags & HDWRPACE_TAGPRESENT) { @@ -1034,20 +1043,8 @@ tcp_rl_shutdown(void *arg __unused, int howto __unused } rs->rs_rlt[i].flags = HDWRPACE_IFPDEPARTED; } - if (rs->rs_flows_using != 0) { - /* - * We dont hold a reference - * so we have nothing left to - * do. - */ - } else { - /* - * No references left, so we can destroy it - * after the epoch. - */ - rs->rs_flags |= RS_FUNERAL_SCHD; - epoch_call(net_epoch, &rs->rs_epoch_ctx, rs_destroy); - } + if (rs->rs_flows_using == 0) + rs_defer_destroy(rs); } mtx_unlock(&rs_mtx); } @@ -1190,16 +1187,8 @@ tcp_rel_pacing_rate(const struct tcp_hwrate_limit_tabl /* * Is it dead? */ - if ((rs->rs_flags & RS_IS_DEAD) && - ((rs->rs_flags & RS_FUNERAL_SCHD) == 0)){ - /* - * We were the last, - * and a funeral is not pending, so - * we must schedule it. - */ - rs->rs_flags |= RS_FUNERAL_SCHD; - epoch_call(net_epoch, &rs->rs_epoch_ctx, rs_destroy); - } + if (rs->rs_flags & RS_IS_DEAD) + rs_defer_destroy(rs); mtx_unlock(&rs_mtx); } in_pcbdetach_txrtlmt(tp->t_inpcb);