From patchwork Mon Apr 15 13:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630042 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 677E37602F for ; Mon, 15 Apr 2024 13:20:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187260; cv=none; b=TmhZ97fKGo7ScXTMCKytgQGjwTfT1TmPPnJiMh4fm78npQHqlDYtGU2HqZA/8DUJRg3CpmbQDUdbKAAr/76laWaHiNFGCgQ5fXWdbHzCK88i/HqgxSnEj+Cq9AlfpaoWBtLtm9FQ4iBuQFfTCXCaujKkd4tnLZkcGxr8KnodRsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187260; c=relaxed/simple; bh=1LrVvpHwl5Q0OP6teAGVGyCBH2+nTLW0svqDJN2z3ns=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kel8zXniZbl6UgioIPF/tGmtumkkt86+oyMoqepPuqEVLTgQPyNTYctNEPN6IvwGjh0Kt/vvFxvHbej/9fnfCT8c/mFkShufiMl2XZTsWZJvz1tu2oImo2r65Mf+AzGUraQz9+cdt+zNZT0kScbUEqSN/apsBZ9pXiPB2iNsVio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=K+Jbm2U5; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K+Jbm2U5" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dccc49ef73eso4561281276.2 for ; Mon, 15 Apr 2024 06:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187257; x=1713792057; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZY8WWl883t9Zpst/1rwsXwHEeahEKmKW1hgRm0oxIEg=; b=K+Jbm2U59lkLiU2xlBZDSkrt9iqvK1NBIRoEm/lSF4znhvvMKXwUdAeaY77iAv7rOQ yoKgWWtc8F1MbInM9M6PxaBjDspiNXd+moQr5WKaunRgXvm0gpzw8q8XSVjU9tUTKx+v LZb3fXjSqCdVkbFzK5HvkSsQBDfCOQ3f+oVxgrvdHMnkXrur9FX49GsgZpbUB6WPCCCo Dce2aVTmNaCnA5EzYu8WeUG7AYTYDVzjoaA+d8zxofm1rSJjqTBYTfVz1hOORrH6YWsw RDuLkfocQUWdOhpL63KG9TKwvDu27LZhKOi7DMA0RCgD/UbqOzY1C9k2GZwEdJzLFAil /eGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187257; x=1713792057; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZY8WWl883t9Zpst/1rwsXwHEeahEKmKW1hgRm0oxIEg=; b=HldmFpfN0QTt3MgD6mn6fLdL6K9wfPNn425SjkkFjTUmw7Gp+UTt+Q/86eOSN9r5K2 sOag5gGuzxY0sxRS6P5E5k1IoF2PgTH4Ij+qhecEfF1s517RiziiBCt41QJ3eDs0FMSr G7NBn7YtjqPA44Dk109F5SZyfx4ZRjrOSuu3oSEm5bNSNiCAu0NE2J88uz6h1bDFxAhz 9tADKHwHb+EacnMTe+5/gVIx0HahkQq941DGIHYKo3f3tnF1O9t1peRtMWPdJpl0Kypg U1KNeRtdLnJuoH6cYjboHV+sam87JTTVszGk18MFMJkWwJ584dVqrAjB5lgp5isJzhob 00CA== X-Forwarded-Encrypted: i=1; AJvYcCXuk1L558Vgmw3arUDtOg6dzwi+n1LRRXiRU/EaQYr99zWNmqj4DCYRoJGn8wLb7+0O0dHNKxjUfwGzYT5Nhqr2mCHMkl+R X-Gm-Message-State: AOJu0YyEHpBKAae8wK/v+fQn3PUxa/UL8tDIFT7n1846Nc5xdFWVmshn 3qx3uASEHb9Ut6IDHETgmr4IrFY7S7bqh+0GRPcKy56JEIkfiHiVpLZqYeCDMHULzmO24r/+zX3 R6JFFyS3QKQ== X-Google-Smtp-Source: AGHT+IG/7selW0iwrDbacMDjCw53546axoiRed8maGMXnhKDe1WA/x3C/hkTu52vHtUpR2uUGtDDR1npB/c/uQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:114c:b0:dcc:8be2:7cb0 with SMTP id p12-20020a056902114c00b00dcc8be27cb0mr1174214ybu.0.1713187257451; Mon, 15 Apr 2024 06:20:57 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:41 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-2-edumazet@google.com> Subject: [PATCH net-next 01/14] net_sched: sch_fq: implement lockless fq_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, fq_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() in fq_change() Signed-off-by: Eric Dumazet --- net/sched/sch_fq.c | 96 +++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c index cdf23ff16f40bf244bb822e76016fde44e0c439b..934c220b3f4336dc2f70af74d7758218492b675d 100644 --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -888,7 +888,7 @@ static int fq_resize(struct Qdisc *sch, u32 log) fq_rehash(q, old_fq_root, q->fq_trees_log, array, log); q->fq_root = array; - q->fq_trees_log = log; + WRITE_ONCE(q->fq_trees_log, log); sch_tree_unlock(sch); @@ -931,7 +931,7 @@ static void fq_prio2band_compress_crumb(const u8 *in, u8 *out) memset(out, 0, num_elems / 4); for (i = 0; i < num_elems; i++) - out[i / 4] |= in[i] << (2 * (i & 0x3)); + out[i / 4] |= READ_ONCE(in[i]) << (2 * (i & 0x3)); } static void fq_prio2band_decompress_crumb(const u8 *in, u8 *out) @@ -958,7 +958,7 @@ static int fq_load_weights(struct fq_sched_data *q, } } for (i = 0; i < FQ_BANDS; i++) - q->band_flows[i].quantum = weights[i]; + WRITE_ONCE(q->band_flows[i].quantum, weights[i]); return 0; } @@ -1011,16 +1011,18 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, err = -EINVAL; } if (tb[TCA_FQ_PLIMIT]) - sch->limit = nla_get_u32(tb[TCA_FQ_PLIMIT]); + WRITE_ONCE(sch->limit, + nla_get_u32(tb[TCA_FQ_PLIMIT])); if (tb[TCA_FQ_FLOW_PLIMIT]) - q->flow_plimit = nla_get_u32(tb[TCA_FQ_FLOW_PLIMIT]); + WRITE_ONCE(q->flow_plimit, + nla_get_u32(tb[TCA_FQ_FLOW_PLIMIT])); if (tb[TCA_FQ_QUANTUM]) { u32 quantum = nla_get_u32(tb[TCA_FQ_QUANTUM]); if (quantum > 0 && quantum <= (1 << 20)) { - q->quantum = quantum; + WRITE_ONCE(q->quantum, quantum); } else { NL_SET_ERR_MSG_MOD(extack, "invalid quantum"); err = -EINVAL; @@ -1028,7 +1030,8 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, } if (tb[TCA_FQ_INITIAL_QUANTUM]) - q->initial_quantum = nla_get_u32(tb[TCA_FQ_INITIAL_QUANTUM]); + WRITE_ONCE(q->initial_quantum, + nla_get_u32(tb[TCA_FQ_INITIAL_QUANTUM])); if (tb[TCA_FQ_FLOW_DEFAULT_RATE]) pr_warn_ratelimited("sch_fq: defrate %u ignored.\n", @@ -1037,17 +1040,19 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_FQ_FLOW_MAX_RATE]) { u32 rate = nla_get_u32(tb[TCA_FQ_FLOW_MAX_RATE]); - q->flow_max_rate = (rate == ~0U) ? ~0UL : rate; + WRITE_ONCE(q->flow_max_rate, + (rate == ~0U) ? ~0UL : rate); } if (tb[TCA_FQ_LOW_RATE_THRESHOLD]) - q->low_rate_threshold = - nla_get_u32(tb[TCA_FQ_LOW_RATE_THRESHOLD]); + WRITE_ONCE(q->low_rate_threshold, + nla_get_u32(tb[TCA_FQ_LOW_RATE_THRESHOLD])); if (tb[TCA_FQ_RATE_ENABLE]) { u32 enable = nla_get_u32(tb[TCA_FQ_RATE_ENABLE]); if (enable <= 1) - q->rate_enable = enable; + WRITE_ONCE(q->rate_enable, + enable); else err = -EINVAL; } @@ -1055,7 +1060,8 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_FQ_FLOW_REFILL_DELAY]) { u32 usecs_delay = nla_get_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]) ; - q->flow_refill_delay = usecs_to_jiffies(usecs_delay); + WRITE_ONCE(q->flow_refill_delay, + usecs_to_jiffies(usecs_delay)); } if (!err && tb[TCA_FQ_PRIOMAP]) @@ -1065,21 +1071,26 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt, err = fq_load_weights(q, tb[TCA_FQ_WEIGHTS], extack); if (tb[TCA_FQ_ORPHAN_MASK]) - q->orphan_mask = nla_get_u32(tb[TCA_FQ_ORPHAN_MASK]); + WRITE_ONCE(q->orphan_mask, + nla_get_u32(tb[TCA_FQ_ORPHAN_MASK])); if (tb[TCA_FQ_CE_THRESHOLD]) - q->ce_threshold = (u64)NSEC_PER_USEC * - nla_get_u32(tb[TCA_FQ_CE_THRESHOLD]); + WRITE_ONCE(q->ce_threshold, + (u64)NSEC_PER_USEC * + nla_get_u32(tb[TCA_FQ_CE_THRESHOLD])); if (tb[TCA_FQ_TIMER_SLACK]) - q->timer_slack = nla_get_u32(tb[TCA_FQ_TIMER_SLACK]); + WRITE_ONCE(q->timer_slack, + nla_get_u32(tb[TCA_FQ_TIMER_SLACK])); if (tb[TCA_FQ_HORIZON]) - q->horizon = (u64)NSEC_PER_USEC * - nla_get_u32(tb[TCA_FQ_HORIZON]); + WRITE_ONCE(q->horizon, + (u64)NSEC_PER_USEC * + nla_get_u32(tb[TCA_FQ_HORIZON])); if (tb[TCA_FQ_HORIZON_DROP]) - q->horizon_drop = nla_get_u8(tb[TCA_FQ_HORIZON_DROP]); + WRITE_ONCE(q->horizon_drop, + nla_get_u8(tb[TCA_FQ_HORIZON_DROP])); if (!err) { @@ -1160,13 +1171,13 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt, static int fq_dump(struct Qdisc *sch, struct sk_buff *skb) { struct fq_sched_data *q = qdisc_priv(sch); - u64 ce_threshold = q->ce_threshold; struct tc_prio_qopt prio = { .bands = FQ_BANDS, }; - u64 horizon = q->horizon; struct nlattr *opts; + u64 ce_threshold; s32 weights[3]; + u64 horizon; opts = nla_nest_start_noflag(skb, TCA_OPTIONS); if (opts == NULL) @@ -1174,35 +1185,48 @@ static int fq_dump(struct Qdisc *sch, struct sk_buff *skb) /* TCA_FQ_FLOW_DEFAULT_RATE is not used anymore */ + ce_threshold = READ_ONCE(q->ce_threshold); do_div(ce_threshold, NSEC_PER_USEC); + + horizon = READ_ONCE(q->horizon); do_div(horizon, NSEC_PER_USEC); - if (nla_put_u32(skb, TCA_FQ_PLIMIT, sch->limit) || - nla_put_u32(skb, TCA_FQ_FLOW_PLIMIT, q->flow_plimit) || - nla_put_u32(skb, TCA_FQ_QUANTUM, q->quantum) || - nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, q->initial_quantum) || - nla_put_u32(skb, TCA_FQ_RATE_ENABLE, q->rate_enable) || + if (nla_put_u32(skb, TCA_FQ_PLIMIT, + READ_ONCE(sch->limit)) || + nla_put_u32(skb, TCA_FQ_FLOW_PLIMIT, + READ_ONCE(q->flow_plimit)) || + nla_put_u32(skb, TCA_FQ_QUANTUM, + READ_ONCE(q->quantum)) || + nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, + READ_ONCE(q->initial_quantum)) || + nla_put_u32(skb, TCA_FQ_RATE_ENABLE, + READ_ONCE(q->rate_enable)) || nla_put_u32(skb, TCA_FQ_FLOW_MAX_RATE, - min_t(unsigned long, q->flow_max_rate, ~0U)) || + min_t(unsigned long, + READ_ONCE(q->flow_max_rate), ~0U)) || nla_put_u32(skb, TCA_FQ_FLOW_REFILL_DELAY, - jiffies_to_usecs(q->flow_refill_delay)) || - nla_put_u32(skb, TCA_FQ_ORPHAN_MASK, q->orphan_mask) || + jiffies_to_usecs(READ_ONCE(q->flow_refill_delay))) || + nla_put_u32(skb, TCA_FQ_ORPHAN_MASK, + READ_ONCE(q->orphan_mask)) || nla_put_u32(skb, TCA_FQ_LOW_RATE_THRESHOLD, - q->low_rate_threshold) || + READ_ONCE(q->low_rate_threshold)) || nla_put_u32(skb, TCA_FQ_CE_THRESHOLD, (u32)ce_threshold) || - nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, q->fq_trees_log) || - nla_put_u32(skb, TCA_FQ_TIMER_SLACK, q->timer_slack) || + nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, + READ_ONCE(q->fq_trees_log)) || + nla_put_u32(skb, TCA_FQ_TIMER_SLACK, + READ_ONCE(q->timer_slack)) || nla_put_u32(skb, TCA_FQ_HORIZON, (u32)horizon) || - nla_put_u8(skb, TCA_FQ_HORIZON_DROP, q->horizon_drop)) + nla_put_u8(skb, TCA_FQ_HORIZON_DROP, + READ_ONCE(q->horizon_drop))) goto nla_put_failure; fq_prio2band_decompress_crumb(q->prio2band, prio.priomap); if (nla_put(skb, TCA_FQ_PRIOMAP, sizeof(prio), &prio)) goto nla_put_failure; - weights[0] = q->band_flows[0].quantum; - weights[1] = q->band_flows[1].quantum; - weights[2] = q->band_flows[2].quantum; + weights[0] = READ_ONCE(q->band_flows[0].quantum); + weights[1] = READ_ONCE(q->band_flows[1].quantum); + weights[2] = READ_ONCE(q->band_flows[2].quantum); if (nla_put(skb, TCA_FQ_WEIGHTS, sizeof(weights), &weights)) goto nla_put_failure; From patchwork Mon Apr 15 13:20:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630043 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C647B2B9CE for ; Mon, 15 Apr 2024 13:20:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187261; cv=none; b=r1jPVeLJv3arBnGE/yfo6x3LKiVuwCA58+/61Y+CyjAyP7/7hgjX1SzScn7KwpMNNwJttXp5WC5Edz7TaHWjEnmRZRZd7Whw1n5DLzMIezdQPi1adpF6+fRen9Z6C+8/DNsWeXmSXpMd4eS+w/qSqivfRoi9ltH2EykbWwRF9Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187261; c=relaxed/simple; bh=q6M6Ex39MfrFakJpmp5HooXS3YphEoOikGGulyXu9P0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TT2rvF6zS0Pz/VjjTsNwbgcaUXBlKJkJfhU7YWxeNPV/r6r0aT9CKPkH5H332XmzXb/UVytK3mAstlan4MeXGVx5D4XUg351F+nmY/ipQpg7pIvkE+rIkdIV8WL33GX+e6BuwHBUuXSBZGO8+QxETDYRaahn1kzq1d2+J5I5pPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=i80ZAl2w; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i80ZAl2w" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so3591407276.0 for ; Mon, 15 Apr 2024 06:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187259; x=1713792059; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EmIru7fcJ7rrvTGZ/l5sMATbKyH6SUanCIhRJqeORnQ=; b=i80ZAl2wy9Dyl2BRsgPCqBwva3p9pZkX9mZe2n8RQBuLeUiiLAjTEc1JzpeSk2OjvL EKFusy17im6YqLhm5HZcHBErmq8w+SL3klmzppFkSJUnxiBlSW7ulnDGaMcMLa2njFrf E0p0YyR4t5d8856SsQofJoNmuXaFPLTopLKBYLwZ92ff0ePTVMgipMZwlJQGAgCVyDqv LfYxLfoFqoMzB/dwA/K6F9gMDW508aSeTDEipv0O4fpsUeperghnZlA0oT9zOPAs6te/ e/sozRjBsy2ULyNur3vaX1Z5I7ec8zUbSZ9dG6KXyUwT7rVN0vI7QfRfskPPgYPuNIZf 3POw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187259; x=1713792059; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EmIru7fcJ7rrvTGZ/l5sMATbKyH6SUanCIhRJqeORnQ=; b=nsrXMjhm3umvl/CzYVdGmSQr1tqw7LMG9w+8Bh9qAqeyQqSYVDvybVZoGEnGCZQ5z7 ylJltk+d/BmQmqOLv8NC8BNOLLH+LsMW0T38v082Zn/iMk9ep5OYQgPODeMA9TxCKbwa 5foGWv3YCWnwiuiClPGTD58JwK/bFwY94QygcZbEM3gY5PI/SDVGwmqU7NPd554DaK/K J/n3tYLocLcF6OPdkBP4ibOK6puqVlFv7i4cUnZ86V3ITGSsjq0bX9MkV3+N1ujO4ZPl 7rwDdw4m5jd4lrOPrrSewOZWAjm1XijFcktJ8/tmJ51Z18P2b+QGdPLLneIxe9V9ZxAw Kotg== X-Forwarded-Encrypted: i=1; AJvYcCU5bWlu/eIvokZsk8HuVrQ3eTmkW565uifnC0/QcpiPHOaivKJ3gKr4anyp7zhcTK49FyoQmnpbnzxPS1rwm4978qlG9zrE X-Gm-Message-State: AOJu0Yy+e/pYgmckQNjIrfPQrDaZH4AXPSMBZtT/PNKQMtHcy1IzmHBe Kz0U1QV6DT7uLwg6sutwMpcn6l2hpWqsf6lsaglrftoZSABE5N1apS8UQr0Wq0H09QkcVv3GnXi Gk6O1CpJAHA== X-Google-Smtp-Source: AGHT+IGr+yU9JbowwKBNsCn8b5MYWhgZ4gNvM1ySV8O0jtZ8a9u7FgLRzCvG9HbFC9kUiH8zFv9Sk2lzeChBfw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:102d:b0:dbe:387d:a8ef with SMTP id x13-20020a056902102d00b00dbe387da8efmr599455ybt.1.1713187258823; Mon, 15 Apr 2024 06:20:58 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:42 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-3-edumazet@google.com> Subject: [PATCH net-next 02/14] net_sched: cake: implement lockless cake_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, cake_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in cake_change(). Signed-off-by: Eric Dumazet --- net/sched/sch_cake.c | 98 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 2eabc4dc5b79a83ce423f73c9cccec86f14be7cf..bb37a0dedcc1e4b3418f6681d87108aad7ea066f 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -2572,6 +2572,7 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, { struct cake_sched_data *q = qdisc_priv(sch); struct nlattr *tb[TCA_CAKE_MAX + 1]; + u16 rate_flags; int err; err = nla_parse_nested_deprecated(tb, TCA_CAKE_MAX, opt, cake_policy, @@ -2592,16 +2593,19 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, } if (tb[TCA_CAKE_BASE_RATE64]) - q->rate_bps = nla_get_u64(tb[TCA_CAKE_BASE_RATE64]); + WRITE_ONCE(q->rate_bps, + nla_get_u64(tb[TCA_CAKE_BASE_RATE64])); if (tb[TCA_CAKE_DIFFSERV_MODE]) - q->tin_mode = nla_get_u32(tb[TCA_CAKE_DIFFSERV_MODE]); + WRITE_ONCE(q->tin_mode, + nla_get_u32(tb[TCA_CAKE_DIFFSERV_MODE])); + rate_flags = q->rate_flags; if (tb[TCA_CAKE_WASH]) { if (!!nla_get_u32(tb[TCA_CAKE_WASH])) - q->rate_flags |= CAKE_FLAG_WASH; + rate_flags |= CAKE_FLAG_WASH; else - q->rate_flags &= ~CAKE_FLAG_WASH; + rate_flags &= ~CAKE_FLAG_WASH; } if (tb[TCA_CAKE_FLOW_MODE]) @@ -2610,11 +2614,13 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, CAKE_FLOW_MASK)); if (tb[TCA_CAKE_ATM]) - q->atm_mode = nla_get_u32(tb[TCA_CAKE_ATM]); + WRITE_ONCE(q->atm_mode, + nla_get_u32(tb[TCA_CAKE_ATM])); if (tb[TCA_CAKE_OVERHEAD]) { - q->rate_overhead = nla_get_s32(tb[TCA_CAKE_OVERHEAD]); - q->rate_flags |= CAKE_FLAG_OVERHEAD; + WRITE_ONCE(q->rate_overhead, + nla_get_s32(tb[TCA_CAKE_OVERHEAD])); + rate_flags |= CAKE_FLAG_OVERHEAD; q->max_netlen = 0; q->max_adjlen = 0; @@ -2623,7 +2629,7 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, } if (tb[TCA_CAKE_RAW]) { - q->rate_flags &= ~CAKE_FLAG_OVERHEAD; + rate_flags &= ~CAKE_FLAG_OVERHEAD; q->max_netlen = 0; q->max_adjlen = 0; @@ -2632,54 +2638,57 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, } if (tb[TCA_CAKE_MPU]) - q->rate_mpu = nla_get_u32(tb[TCA_CAKE_MPU]); + WRITE_ONCE(q->rate_mpu, + nla_get_u32(tb[TCA_CAKE_MPU])); if (tb[TCA_CAKE_RTT]) { - q->interval = nla_get_u32(tb[TCA_CAKE_RTT]); + u32 interval = nla_get_u32(tb[TCA_CAKE_RTT]); - if (!q->interval) - q->interval = 1; + WRITE_ONCE(q->interval, max(interval, 1U)); } if (tb[TCA_CAKE_TARGET]) { - q->target = nla_get_u32(tb[TCA_CAKE_TARGET]); + u32 target = nla_get_u32(tb[TCA_CAKE_TARGET]); - if (!q->target) - q->target = 1; + WRITE_ONCE(q->target, max(target, 1U)); } if (tb[TCA_CAKE_AUTORATE]) { if (!!nla_get_u32(tb[TCA_CAKE_AUTORATE])) - q->rate_flags |= CAKE_FLAG_AUTORATE_INGRESS; + rate_flags |= CAKE_FLAG_AUTORATE_INGRESS; else - q->rate_flags &= ~CAKE_FLAG_AUTORATE_INGRESS; + rate_flags &= ~CAKE_FLAG_AUTORATE_INGRESS; } if (tb[TCA_CAKE_INGRESS]) { if (!!nla_get_u32(tb[TCA_CAKE_INGRESS])) - q->rate_flags |= CAKE_FLAG_INGRESS; + rate_flags |= CAKE_FLAG_INGRESS; else - q->rate_flags &= ~CAKE_FLAG_INGRESS; + rate_flags &= ~CAKE_FLAG_INGRESS; } if (tb[TCA_CAKE_ACK_FILTER]) - q->ack_filter = nla_get_u32(tb[TCA_CAKE_ACK_FILTER]); + WRITE_ONCE(q->ack_filter, + nla_get_u32(tb[TCA_CAKE_ACK_FILTER])); if (tb[TCA_CAKE_MEMORY]) - q->buffer_config_limit = nla_get_u32(tb[TCA_CAKE_MEMORY]); + WRITE_ONCE(q->buffer_config_limit, + nla_get_u32(tb[TCA_CAKE_MEMORY])); if (tb[TCA_CAKE_SPLIT_GSO]) { if (!!nla_get_u32(tb[TCA_CAKE_SPLIT_GSO])) - q->rate_flags |= CAKE_FLAG_SPLIT_GSO; + rate_flags |= CAKE_FLAG_SPLIT_GSO; else - q->rate_flags &= ~CAKE_FLAG_SPLIT_GSO; + rate_flags &= ~CAKE_FLAG_SPLIT_GSO; } if (tb[TCA_CAKE_FWMARK]) { - q->fwmark_mask = nla_get_u32(tb[TCA_CAKE_FWMARK]); - q->fwmark_shft = q->fwmark_mask ? __ffs(q->fwmark_mask) : 0; + WRITE_ONCE(q->fwmark_mask, nla_get_u32(tb[TCA_CAKE_FWMARK])); + WRITE_ONCE(q->fwmark_shft, + q->fwmark_mask ? __ffs(q->fwmark_mask) : 0); } + WRITE_ONCE(q->rate_flags, rate_flags); if (q->tins) { sch_tree_lock(sch); cake_reconfigure(sch); @@ -2774,68 +2783,71 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb) { struct cake_sched_data *q = qdisc_priv(sch); struct nlattr *opts; + u16 rate_flags; opts = nla_nest_start_noflag(skb, TCA_OPTIONS); if (!opts) goto nla_put_failure; - if (nla_put_u64_64bit(skb, TCA_CAKE_BASE_RATE64, q->rate_bps, - TCA_CAKE_PAD)) + if (nla_put_u64_64bit(skb, TCA_CAKE_BASE_RATE64, + READ_ONCE(q->rate_bps), TCA_CAKE_PAD)) goto nla_put_failure; if (nla_put_u32(skb, TCA_CAKE_FLOW_MODE, - q->flow_mode & CAKE_FLOW_MASK)) + READ_ONCE(q->flow_mode) & CAKE_FLOW_MASK)) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_RTT, q->interval)) + if (nla_put_u32(skb, TCA_CAKE_RTT, READ_ONCE(q->interval))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_TARGET, q->target)) + if (nla_put_u32(skb, TCA_CAKE_TARGET, READ_ONCE(q->target))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_MEMORY, q->buffer_config_limit)) + if (nla_put_u32(skb, TCA_CAKE_MEMORY, + READ_ONCE(q->buffer_config_limit))) goto nla_put_failure; + rate_flags = READ_ONCE(q->rate_flags); if (nla_put_u32(skb, TCA_CAKE_AUTORATE, - !!(q->rate_flags & CAKE_FLAG_AUTORATE_INGRESS))) + !!(rate_flags & CAKE_FLAG_AUTORATE_INGRESS))) goto nla_put_failure; if (nla_put_u32(skb, TCA_CAKE_INGRESS, - !!(q->rate_flags & CAKE_FLAG_INGRESS))) + !!(rate_flags & CAKE_FLAG_INGRESS))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_ACK_FILTER, q->ack_filter)) + if (nla_put_u32(skb, TCA_CAKE_ACK_FILTER, READ_ONCE(q->ack_filter))) goto nla_put_failure; if (nla_put_u32(skb, TCA_CAKE_NAT, - !!(q->flow_mode & CAKE_FLOW_NAT_FLAG))) + !!(READ_ONCE(q->flow_mode) & CAKE_FLOW_NAT_FLAG))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_DIFFSERV_MODE, q->tin_mode)) + if (nla_put_u32(skb, TCA_CAKE_DIFFSERV_MODE, READ_ONCE(q->tin_mode))) goto nla_put_failure; if (nla_put_u32(skb, TCA_CAKE_WASH, - !!(q->rate_flags & CAKE_FLAG_WASH))) + !!(rate_flags & CAKE_FLAG_WASH))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_OVERHEAD, q->rate_overhead)) + if (nla_put_u32(skb, TCA_CAKE_OVERHEAD, READ_ONCE(q->rate_overhead))) goto nla_put_failure; - if (!(q->rate_flags & CAKE_FLAG_OVERHEAD)) + if (!(rate_flags & CAKE_FLAG_OVERHEAD)) if (nla_put_u32(skb, TCA_CAKE_RAW, 0)) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_ATM, q->atm_mode)) + if (nla_put_u32(skb, TCA_CAKE_ATM, READ_ONCE(q->atm_mode))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_MPU, q->rate_mpu)) + if (nla_put_u32(skb, TCA_CAKE_MPU, READ_ONCE(q->rate_mpu))) goto nla_put_failure; if (nla_put_u32(skb, TCA_CAKE_SPLIT_GSO, - !!(q->rate_flags & CAKE_FLAG_SPLIT_GSO))) + !!(rate_flags & CAKE_FLAG_SPLIT_GSO))) goto nla_put_failure; - if (nla_put_u32(skb, TCA_CAKE_FWMARK, q->fwmark_mask)) + if (nla_put_u32(skb, TCA_CAKE_FWMARK, READ_ONCE(q->fwmark_mask))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630044 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591378289B for ; Mon, 15 Apr 2024 13:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187262; cv=none; b=FKBPxehLRF3FjKTG2ZE6KlVuWBuqtD7xGIYq8OpVS/mxnOlsOpfZpMCrGO4ip6TDS0GMQ9nohIIrBgKC8yiaNfCv8TYAh64rv1/PcYAgT0QVhpbnjvX/b/ynSOE81vu5MVfaiRgc6s6eiQcp234ibJUk1QNTkpS37HWFX/Xri8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187262; c=relaxed/simple; bh=ruvLiSlq3Dc7Lz8ZO4NMF69SqHjGjfB/FNswnLKViKI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ktTLQveGeIs0+EKnxZlUZZBA8EXmsfhz0KwyHnNYB98aDI4Nhimo3LD4gkzf424Yq353ZYysSNsi2KnNX75OlGlTnHDXP1xk2vBi5htkfkdf/BuemPoYps5nIMV+81wiqNOnLoRsiB7byX/NyTCzPZf+8nciaqeG6LTG6b7eW74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NUHV6LCG; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NUHV6LCG" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b269686aso4572354276.1 for ; Mon, 15 Apr 2024 06:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187260; x=1713792060; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bvUVpVUdw8ikpyFUAyziYlm1LIWlMR1iKHn0hu++PQA=; b=NUHV6LCGtmtGJ13YOhQz36wlJTFLWqCFZ9WC9/rG5OHMTUqoXzaZtGeaN0/RUytv68 SxQHgLSB4PBKf5bH02W58idNhKmpsh6LzN9ceAdy9hzpXxD0ZA056w+WTJDFTdHS9Vxe sFh5uiuHMDD69BvUm0Q99sq1+2FaEH26p94EI01TfIbBbvF0r3mNOeLE9vkWcih/zvx+ gddTrlUFs4LrnK/Dg9SXi+FXEYsULJiJR4e9Kdjt2MRx99mTUf4pAe/TtDoiKZAfPA8c NeSbLLzidT/4Skv0Sc7KmeeHdwwjYS00/hH9RoBGxZs+7tjeklcB4G+08phkVHCbw6uS fi2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187260; x=1713792060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bvUVpVUdw8ikpyFUAyziYlm1LIWlMR1iKHn0hu++PQA=; b=Yp24zmO1WI5dr63XrPC/DvJ3T282/r/5jOPXEjbSvwUCQufmHTtwS2Cpjw8nk1pqCX KqQs13WB8KuFpboTUpdJBzNQqZgVHSKOun2UQyYxCRE5NC8NRKYLEnZXC6zAeMRkmi8J DOV16z3adsST6mluOR2Q1Th6jx+TQCZTCimuzMuqKtMrGAQJxuPw9x178TPCsrAYNi6m mMqVYcauGvom/G7VFR5rfO1ySTYA85NRWQOcrRyvvb1kZUh19IvbfIQRtSPr0UZ2svZH eGpHyVDQV3ct+HANlyXNlgtJY3grahJ/GQOfIgBe7peeUVwvIAW1AN4TcUiST1g/2PnE wbMQ== X-Forwarded-Encrypted: i=1; AJvYcCU9SNf+p/S80rN9gJMWrEqJEf+l6dMuNDtkQ3D2a8iIJLRTU6Zt6//70Wreab+ps1JWnaxYk6EWAQZ/6mTbbKxiRQ122N9K X-Gm-Message-State: AOJu0Yw1ZqQDap0Nsjs5ucr/amjaD3Kei5pPFNcx9jDiQ1EgvPT7fUIL +BMCS8Y/BVg82DoOnPqnl6qXutNLB8zuBdOyGnQTbPcmaoa4yMHnWSZFqaJOJh6td5WStg87Vba nZ5GM9m+jDg== X-Google-Smtp-Source: AGHT+IH4k1v0Z5g1XikuWk8mkJFLq6tUk/3EPeBXwJM3W01nXus5oBdKN+72E9PHflRnXuFbPGFtpCbIFB1OpA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:120b:b0:de0:ecc6:87b with SMTP id s11-20020a056902120b00b00de0ecc6087bmr784102ybu.1.1713187260269; Mon, 15 Apr 2024 06:21:00 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:43 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-4-edumazet@google.com> Subject: [PATCH net-next 03/14] net_sched: sch_cbs: implement lockless cbs_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, cbs_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in cbs_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_cbs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c index 69001eff0315584df23a24f81ae3b4cf7bf5fd79..939425da18955bc8a3f3d2d5b852b2585e9bcaee 100644 --- a/net/sched/sch_cbs.c +++ b/net/sched/sch_cbs.c @@ -389,11 +389,11 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt, } /* Everything went OK, save the parameters used. */ - q->hicredit = qopt->hicredit; - q->locredit = qopt->locredit; - q->idleslope = qopt->idleslope * BYTES_PER_KBIT; - q->sendslope = qopt->sendslope * BYTES_PER_KBIT; - q->offload = qopt->offload; + WRITE_ONCE(q->hicredit, qopt->hicredit); + WRITE_ONCE(q->locredit, qopt->locredit); + WRITE_ONCE(q->idleslope, qopt->idleslope * BYTES_PER_KBIT); + WRITE_ONCE(q->sendslope, qopt->sendslope * BYTES_PER_KBIT); + WRITE_ONCE(q->offload, qopt->offload); return 0; } @@ -459,11 +459,11 @@ static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb) if (!nest) goto nla_put_failure; - opt.hicredit = q->hicredit; - opt.locredit = q->locredit; - opt.sendslope = div64_s64(q->sendslope, BYTES_PER_KBIT); - opt.idleslope = div64_s64(q->idleslope, BYTES_PER_KBIT); - opt.offload = q->offload; + opt.hicredit = READ_ONCE(q->hicredit); + opt.locredit = READ_ONCE(q->locredit); + opt.sendslope = div64_s64(READ_ONCE(q->sendslope), BYTES_PER_KBIT); + opt.idleslope = div64_s64(READ_ONCE(q->idleslope), BYTES_PER_KBIT); + opt.offload = READ_ONCE(q->offload); if (nla_put(skb, TCA_CBS_PARMS, sizeof(opt), &opt)) goto nla_put_failure; From patchwork Mon Apr 15 13:20:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630045 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A02CF82D72 for ; Mon, 15 Apr 2024 13:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187264; cv=none; b=eDO6j4VqdqB5UnOjsJ2D96mtZ5wQVOiDRUkASvDAQhPdj2opbwRoPz70uNlHxjz4axzKxNfYzkq7wGkEh6hkGk7TXG3aVLhbQQlxAf1+cRaxbA0PYoQkrp+RI93hFa6FRuC3kT54tapy8bot2+gR15dbEFkgyKv3hgpoXQ9tjXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187264; c=relaxed/simple; bh=je/HGq+WT63hPeXHXiqGA5Bqj2KxfYiW15d84nbQb+A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rsQEDCq9XXBpwHc7+JKj6ArkQk6upDKPcRWRvtABb+XYN9XlIHqFYtww6btzdzUpNblLVvn5hqFdhxz1rmknRDC7C6HQGSiu9OVnwIwX/E5b0a120ziMVtEMHhdoYtJWI9LXwMNEwv7ZsG0AcJNbdbXdBWlwPMvuoXD1OmPLibw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PQFgEl3G; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PQFgEl3G" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6180225775bso45263717b3.2 for ; Mon, 15 Apr 2024 06:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187261; x=1713792061; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6qqkpTUsvu108xyewMzYbQAX65lAMkHa/u0k7gz7zg4=; b=PQFgEl3G4OgBOxdhDJxAh/2X968D54tw/J+r5vy5kUvk/uDHIJp4xjtB3HT0m854Ym Y8SLkhaD5aFzykJzDXSn0imssdx4jMa6LyKK+0zcCU3E9R3iAkFchv989Ts99M2KXX6u a1ZQDVtlTpicBQROWGZCLOPTSWGIKcV3qUpyQu3Gexlr6x7Xtx4w5f0AdIwz6VYzlqTq dmcQ9Pgwetuv43sbunyRHgVBZA/FnZMoeTHrEkwv2Ce5H1zx9GPb+b0NnXJkdZNzZROD /1a8Hg5ng+SDc5PPwzd5zXFvCF/8vK5aCAA2ITcV+aAKljtbXLnfrkcw27S6k/IPSGVg ZK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187261; x=1713792061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6qqkpTUsvu108xyewMzYbQAX65lAMkHa/u0k7gz7zg4=; b=vA1va9nOpHhbhx3kMLSt6Pz0Mv/doIVmfi0ligLV7LRKD/Bo8Z7GwaE98zmd1XB7uv BJozrnXGcTDyvgIYKhwIDPTHQbKgVquL1b6PfQeENxsON72uswV4PbJeinB4ZtDrFSLU GndiMCtwII5YdPbopvDjmp78qLdklBAjnG9HD1mCx9cmDiun1hrAainlB/upBJORlmuQ Udf0rP4837IZutrHgMAriv6qIenBkBxJVfWyajkLx4yoOX0SOPAtAEdMi7jWj91J9YKB oLVv6vwUW3TyKU7oekLwaVnRJhI7g6Wqs2t0NZrqlb5BHULNkhfG5SPh2j9xYlaD8j2V yo8A== X-Forwarded-Encrypted: i=1; AJvYcCXXIZdtoMKry2frlgvEzbXNVcnQ4VykmNzIH3YycXrxxFLPi+OECLvqszlfB0T5TFMMYUZV7r0lygvI35XBPY1+spKgadG9 X-Gm-Message-State: AOJu0YwohfA9XYxq9SPKwvWC0prSsGSO6yKoLCWSKeVvM+FpKgovGnpP 2uiHS3cJrULcoRhjQaRYhnx3uuslDxUrT+AHTJCuoPsuDrniVP74W6wGGWogfHrp1PQo3anwRj0 wo2U19e2UpQ== X-Google-Smtp-Source: AGHT+IG821hMwVnKrdAfgwP+f6KLnu5+LA85YJsbpq5zSW/D+0e5gnwuhn4V4WrphFZFv0B2bx+8W35ajrQ6Rg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:100b:b0:dcd:875:4c40 with SMTP id w11-20020a056902100b00b00dcd08754c40mr3248673ybt.10.1713187261710; Mon, 15 Apr 2024 06:21:01 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:44 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-5-edumazet@google.com> Subject: [PATCH net-next 04/14] net_sched: sch_choke: implement lockless choke_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, choke_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in choke_change(). Also use READ_ONCE(q->limit) in choke_enqueue() as the value could change from choke_change(). Signed-off-by: Eric Dumazet --- include/net/red.h | 10 +++++----- net/sched/sch_choke.c | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/net/red.h b/include/net/red.h index 425364de0df7913cdd6361a0eb8d18b418372787..7daf7cf6130aeccf3d81a77600f4445759f174b7 100644 --- a/include/net/red.h +++ b/include/net/red.h @@ -233,10 +233,10 @@ static inline void red_set_parms(struct red_parms *p, int delta = qth_max - qth_min; u32 max_p_delta; - p->qth_min = qth_min << Wlog; - p->qth_max = qth_max << Wlog; - p->Wlog = Wlog; - p->Plog = Plog; + WRITE_ONCE(p->qth_min, qth_min << Wlog); + WRITE_ONCE(p->qth_max, qth_max << Wlog); + WRITE_ONCE(p->Wlog, Wlog); + WRITE_ONCE(p->Plog, Plog); if (delta <= 0) delta = 1; p->qth_delta = delta; @@ -244,7 +244,7 @@ static inline void red_set_parms(struct red_parms *p, max_P = red_maxp(Plog); max_P *= delta; /* max_P = (qth_max - qth_min)/2^Plog */ } - p->max_P = max_P; + WRITE_ONCE(p->max_P, max_P); max_p_delta = max_P / delta; max_p_delta = max(max_p_delta, 1U); p->max_P_reciprocal = reciprocal_value(max_p_delta); diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c index ea108030c6b410418f0b58ba7ea51e1b524d4df9..51e68c9661727e64862392a76880bed5fa0c27a2 100644 --- a/net/sched/sch_choke.c +++ b/net/sched/sch_choke.c @@ -264,7 +264,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch, } /* Admit new packet */ - if (sch->q.qlen < q->limit) { + if (sch->q.qlen < READ_ONCE(q->limit)) { q->tab[q->tail] = skb; q->tail = (q->tail + 1) & q->tab_mask; ++sch->q.qlen; @@ -405,8 +405,8 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt, } else sch_tree_lock(sch); - q->flags = ctl->flags; - q->limit = ctl->limit; + WRITE_ONCE(q->flags, ctl->flags); + WRITE_ONCE(q->limit, ctl->limit); red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Plog, ctl->Scell_log, @@ -431,15 +431,16 @@ static int choke_init(struct Qdisc *sch, struct nlattr *opt, static int choke_dump(struct Qdisc *sch, struct sk_buff *skb) { struct choke_sched_data *q = qdisc_priv(sch); + u8 Wlog = READ_ONCE(q->parms.Wlog); struct nlattr *opts = NULL; struct tc_red_qopt opt = { - .limit = q->limit, - .flags = q->flags, - .qth_min = q->parms.qth_min >> q->parms.Wlog, - .qth_max = q->parms.qth_max >> q->parms.Wlog, - .Wlog = q->parms.Wlog, - .Plog = q->parms.Plog, - .Scell_log = q->parms.Scell_log, + .limit = READ_ONCE(q->limit), + .flags = READ_ONCE(q->flags), + .qth_min = READ_ONCE(q->parms.qth_min) >> Wlog, + .qth_max = READ_ONCE(q->parms.qth_max) >> Wlog, + .Wlog = Wlog, + .Plog = READ_ONCE(q->parms.Plog), + .Scell_log = READ_ONCE(q->parms.Scell_log), }; opts = nla_nest_start_noflag(skb, TCA_OPTIONS); @@ -447,7 +448,7 @@ static int choke_dump(struct Qdisc *sch, struct sk_buff *skb) goto nla_put_failure; if (nla_put(skb, TCA_CHOKE_PARMS, sizeof(opt), &opt) || - nla_put_u32(skb, TCA_CHOKE_MAX_P, q->parms.max_P)) + nla_put_u32(skb, TCA_CHOKE_MAX_P, READ_ONCE(q->parms.max_P))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630046 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 261F78289B for ; Mon, 15 Apr 2024 13:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187265; cv=none; b=l4Dx4Cq72IjzHQRLf2O+I9Y1X4jybaDHD1c8ykJVg+O0EjTdZTE3Su3Nf9OcZDq/H6uWPWwnYapXSH6JfWWGxpwH9jgBVxoMMVbeF28J2IBrNAYKby0KqHrGwF/9w+AbTpn47kJtGNWp53j1QNBVEVmfBazH9C+0CNS8wBbOii8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187265; c=relaxed/simple; bh=LYA3bwzFSwWXh7vf+q+2yIEdnY74hIz5IAwuZ+3bA4k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r46Twx2LhttrrnaTpEfkS0y9o12AQ395y9yCQly39VM8Al8hzA6Iqt1YtkWf5LdqpSzMWCNOpz5GrkxUU4hvffWoadwrSFog9884LWjAwA/X7DR9w+WX4RyUA6HUYrYof023CrAQPKncn+kDXbfapqdo8XKOzNRNeVRjjz+/5Wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4KeWPlxv; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4KeWPlxv" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6156b93c768so56246107b3.1 for ; Mon, 15 Apr 2024 06:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187263; x=1713792063; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cmuUPJtBk0bwiZ86MTFxSbeY1/eRlpmjyYithlp1dMc=; b=4KeWPlxvy8T3ohz3EoVPNIeQiBu9TeH/VcrHUEQOXrvowGc8kudV/mNivXBq1wHpDn hbKxhIcGeK0nb0oFVYXGOQP5POh2KpewVBmbyrSB4rHozgP9Txp3BWu+3V68eH/PjrI1 eGAh0d5pN9m0Szpou3DyOW/nuWusDW8IjtT8Zfb2IzXgncfGzy49VbdEm/dIMXLH47Rs 0xMHdMVa4ThjnXVp9ICP9z3T1/tGnfJTRn3FrB1z0gSAzqNu6gfSMLvCXoSYOHyKheDw +LB+kWFNeHOlg+3SRqANQX1z5yOVxhXrdZ/DSoxXv/KtJaq8s626M5rBugcBZmj6MFcT cTsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187263; x=1713792063; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cmuUPJtBk0bwiZ86MTFxSbeY1/eRlpmjyYithlp1dMc=; b=LCgUVzVRUaaoDv1/LqNiXRGjgsfTtOFMbHiREOfOjR0r+e1ngkeSZWwXYu0X+0TuPr Xfr0VRZjEMAQ1MxKXt1hBls7ft02ytRd9sGMoOtI9EMIrh0lLCG3qhgwkUC5bhda+Ziw 0b6YeCoJV+FAKLaxczMb6jzlqTY+72Q6/LlESY3aiPBU9dpTw87U/sKnP8ZW8Pdj6ah6 EF/RICLPF7W32vUxrQspceoT876eP59g+YMHKbiEOdt7vdGCyUiygnI4ZMd9UEYPvNDs FzpoyIc7DS8VWlrQTu8V6BVVVP08lro0j5NBN/zhXQahSR09vrKugXRMv5lYUFcimMDf qgjw== X-Forwarded-Encrypted: i=1; AJvYcCV9YdGg6A3FiP1LcLG6v9aDyt/9KOvhaLS+iYGb7NNIrii5XgFKWg8jWAa/h5TUWDIXzXTvlOMD+xGuBLB/I4/qK7Wxm++0 X-Gm-Message-State: AOJu0YyvESPOIvLQiaZGXR5ehSAsIiEMD/2BkFptGCFAFuxKQ592qm15 bqeBV0tee0ktsJgglt0SyeozYIWJkiMcbxKzlT9hoFNvGo9LaOfg9Ca+TQ9UJ81fXft7BxOGHS3 1Hu660B8RAw== X-Google-Smtp-Source: AGHT+IGty+tnPcOsU5sURA0IQZyM08U+3ZehF8sHkjN6CsvWmUG+IPJseEXRSPk9i5TYzPpjwYiL1NVGaKo6KQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:848b:0:b0:617:d650:11e2 with SMTP id u133-20020a81848b000000b00617d65011e2mr2895762ywf.3.1713187263177; Mon, 15 Apr 2024 06:21:03 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:45 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-6-edumazet@google.com> Subject: [PATCH net-next 05/14] net_sched: sch_codel: implement lockless codel_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, codel_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in codel_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_codel.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_codel.c b/net/sched/sch_codel.c index ecb3f164bb25b33bd662c8ee07dc1b5945fd882d..3e8d4fe4d91e3ef2b7715640f6675aa5e8e2a326 100644 --- a/net/sched/sch_codel.c +++ b/net/sched/sch_codel.c @@ -118,26 +118,31 @@ static int codel_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_CODEL_TARGET]) { u32 target = nla_get_u32(tb[TCA_CODEL_TARGET]); - q->params.target = ((u64)target * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->params.target, + ((u64)target * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_CODEL_CE_THRESHOLD]) { u64 val = nla_get_u32(tb[TCA_CODEL_CE_THRESHOLD]); - q->params.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->params.ce_threshold, + (val * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_CODEL_INTERVAL]) { u32 interval = nla_get_u32(tb[TCA_CODEL_INTERVAL]); - q->params.interval = ((u64)interval * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->params.interval, + ((u64)interval * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_CODEL_LIMIT]) - sch->limit = nla_get_u32(tb[TCA_CODEL_LIMIT]); + WRITE_ONCE(sch->limit, + nla_get_u32(tb[TCA_CODEL_LIMIT])); if (tb[TCA_CODEL_ECN]) - q->params.ecn = !!nla_get_u32(tb[TCA_CODEL_ECN]); + WRITE_ONCE(q->params.ecn, + !!nla_get_u32(tb[TCA_CODEL_ECN])); qlen = sch->q.qlen; while (sch->q.qlen > sch->limit) { @@ -183,6 +188,7 @@ static int codel_init(struct Qdisc *sch, struct nlattr *opt, static int codel_dump(struct Qdisc *sch, struct sk_buff *skb) { struct codel_sched_data *q = qdisc_priv(sch); + codel_time_t ce_threshold; struct nlattr *opts; opts = nla_nest_start_noflag(skb, TCA_OPTIONS); @@ -190,17 +196,18 @@ static int codel_dump(struct Qdisc *sch, struct sk_buff *skb) goto nla_put_failure; if (nla_put_u32(skb, TCA_CODEL_TARGET, - codel_time_to_us(q->params.target)) || + codel_time_to_us(READ_ONCE(q->params.target))) || nla_put_u32(skb, TCA_CODEL_LIMIT, - sch->limit) || + READ_ONCE(sch->limit)) || nla_put_u32(skb, TCA_CODEL_INTERVAL, - codel_time_to_us(q->params.interval)) || + codel_time_to_us(READ_ONCE(q->params.interval))) || nla_put_u32(skb, TCA_CODEL_ECN, - q->params.ecn)) + READ_ONCE(q->params.ecn))) goto nla_put_failure; - if (q->params.ce_threshold != CODEL_DISABLED_THRESHOLD && + ce_threshold = READ_ONCE(q->params.ce_threshold); + if (ce_threshold != CODEL_DISABLED_THRESHOLD && nla_put_u32(skb, TCA_CODEL_CE_THRESHOLD, - codel_time_to_us(q->params.ce_threshold))) + codel_time_to_us(ce_threshold))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630047 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C380983A0A for ; Mon, 15 Apr 2024 13:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187267; cv=none; b=jErPpXYcN5YpcbYfpwsdxqcKA3nTxFATRYTFuYEAm6m2BmA9o64MC14qpkIg23MijIaIycJ12gqMDoZcRwqbRLeFKrS+AEsjlg6kDvqmdVfY42Zl2u1g67fKV3zM/GrV9ZMQ8pkBGo46Lcd18neXaGS+1MPrbquU/yXbOaQ1wrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187267; c=relaxed/simple; bh=CjsjQ+yVMr/aYiDnmks5Z/g6Vq5gK5w2SOGR5dDm4mg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=umQetc77b/SFeC2SOJbN2yJBshkHs5BeleJ88yYg623Bh9kxmDltaE/PiLFKjmQTsfR4v9ZE89/Dt0SxTWm7doOkjtMRc6Fj1S4MXavhX7YTiKqEp3AmNOQmvn25F4vwkqPbZVPOvAqKHgZLRoKKF7NJlIh13W4w4oD0cRyPros= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PiMcoc5U; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PiMcoc5U" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ddaf2f115f2so4579916276.3 for ; Mon, 15 Apr 2024 06:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187265; x=1713792065; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=shuoDMWDIQAb4xjF8TvMXV0W+kS1OzrCQN9OhM8Lglk=; b=PiMcoc5Uvm4unhBFr2CT7AgZa4jHCsu7v4N1OtYeLE3YXPVjxLvzVPFVWYSt5lHLLY aIV7Pva63Pr7u8UT4XBfCgdkuGGAxPD3tkabclW9eGKM9Ly9GyBpsRUePyd/3JpAIJa2 rjXKnXNOBKE65IsFsiksqJ+SmYkCdoGIokSLuXV1bhDHdSOijC+fcVOU0dSpnFaa3nX3 G+Hf4Wv9R6oyCYcPqvP+GfeVz0scvc3BhFLau+NLf33HETt0OXxI5zNDS5cB+dsLFJf3 wV7agor0A+nEAB9B+jiJ3bi0ZaOTTIQk9gAHQEZc0IlT+NbTY2GyT3jjJdmS2LuSlFkI BRMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187265; x=1713792065; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=shuoDMWDIQAb4xjF8TvMXV0W+kS1OzrCQN9OhM8Lglk=; b=ADL0RZq/wWclmbVmU09b3VKVEIv7Jw0Lv0co008n2n94lrhHcw0ngE5cafoc28CkxT h2Qop5tSS8M9rbauvFtexQ2ZGlQy97xF55wAmCr5fvxlQgOGUa2Ej862zbciW/56ld0W pEtVnPc33pPF0Ac+6hc+sf5Cyo9noEv+udnhzDKSn+0VbWek++w6p7gkS8+L68URdnZb LAz7stTQMDvIcMCWpH5xEILEWFsTVon8rBx3qd1ek25ifVGak72E4ONYCAFynZgxZA7b Ty8LR86GsWGJTpRnePoH51T4pruIJnWgxTuhatAuVqwUkRVLUju5clY9EWLIYrPxSt9a KdhQ== X-Forwarded-Encrypted: i=1; AJvYcCWwXbM6f0WZ3QtFw2hCepwMrim43rrsAYjNabXNMlSK/Qb90c9ySYLI9R9z/We4pd9OZ3M8eJCjFETQLAWe89omPCCTlxhT X-Gm-Message-State: AOJu0YyFJTmTEV42fcYMUM53TQjrYIPv+pzPDtA6g41ydxbZ+/1bKFUL wEk8Fox0hqfBYw0tA6Fme28bS1cTztCfY5kKU4YyIwilJejQQ6V/nYeZXRzAlz+rogtLtqGASle +HW4Nd+m4qQ== X-Google-Smtp-Source: AGHT+IGS4HDaAwYtHiB4d0v1vJVf3HJMxbOnopv+Z/8XURMaq12XB8fwmcFRwrzl8IdnnwyqvbZceHrzsh5oXg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:c0c:b0:de1:d49:7ff6 with SMTP id fs12-20020a0569020c0c00b00de10d497ff6mr802725ybb.7.1713187264733; Mon, 15 Apr 2024 06:21:04 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:46 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-7-edumazet@google.com> Subject: [PATCH net-next 06/14] net_sched: sch_tfs: implement lockless etf_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, codel_dump() can use READ_ONCE() annotations. There is no etf_change() yet, this patch imply aligns this qdisc with others. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_etf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_etf.c b/net/sched/sch_etf.c index 2e4bef713b6abc4aad836bc9248796c20a22e476..c74d778c32a1eda639650df4d1d103c5338f14e6 100644 --- a/net/sched/sch_etf.c +++ b/net/sched/sch_etf.c @@ -467,15 +467,15 @@ static int etf_dump(struct Qdisc *sch, struct sk_buff *skb) if (!nest) goto nla_put_failure; - opt.delta = q->delta; - opt.clockid = q->clockid; - if (q->offload) + opt.delta = READ_ONCE(q->delta); + opt.clockid = READ_ONCE(q->clockid); + if (READ_ONCE(q->offload)) opt.flags |= TC_ETF_OFFLOAD_ON; - if (q->deadline_mode) + if (READ_ONCE(q->deadline_mode)) opt.flags |= TC_ETF_DEADLINE_MODE_ON; - if (q->skip_sock_check) + if (READ_ONCE(q->skip_sock_check)) opt.flags |= TC_ETF_SKIP_SOCK_CHECK; if (nla_put(skb, TCA_ETF_PARMS, sizeof(opt), &opt)) From patchwork Mon Apr 15 13:20:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630048 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28D5083CB6 for ; Mon, 15 Apr 2024 13:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187268; cv=none; b=dy9u10vNUbS65QwuFX9zs+xsc2nRp2J9kV2SiirQEWumCN17EMFaM8cyfvfVZN8LUytvbf/CGnQT6WkwgcgtGVZx+On0ESo1syhR6X4U5OQUEXzJGVvEOBJd2FIpPEbIuUNEZiJW53S9gQvPQeiep6fIkWJKAsstgJ2nsC6rvI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187268; c=relaxed/simple; bh=5GcSjD5Ym+nqccmyQLd6LAe0ImS79AgIRrEIxO96ny4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kpp8MRg0nlNB5O/fSSlt7bM9Bp4FqUH0ZOm3OZKVcaWZ8OHwngglxLXPC2rBGMvlEU3zeHKJcyp13ZwzRBHoFpxGN8JlamvoHBsdwJz+8mr80HZ76HBKbMNuoVd2zT+4ZPeb+49n234w9RJUOfuFpHzWdpLMgn/RDKB3NFuJo28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dyzs/HKD; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dyzs/HKD" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-618891b439eso49545577b3.3 for ; Mon, 15 Apr 2024 06:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187266; x=1713792066; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h9w4FpwtNbIZ1f6iZyUM+W9GcBTruH/kwzNUAVqphXM=; b=dyzs/HKDBbpZo6PDSlO24h4v2dVaCMne9L9FUiivf3hhBfqCLPCZGAKWiiH9yX8LsQ jf7QI3bZlMGwWa0osvLnGhk8NUdKvP4lAvqQQ9JxXX19y9G2oCIFfktaPAGWgcadKgiW Ha+hRqI4mytz8LemPTk8fLx+kvmjBxr7S1Je5bUqmFHBAJrdiA/0rDPod0C18jO+anJq u8xnpW1gI900tdLNOWT71zEeA/RRdST6uDmE6Ex2x/dVHHyHwBNtz9y24ksTC5khRlyy 5uPpPuDfOjRT3nRoEfPAVo3MZrN/kNXh9JDHAR81mLsTfKmm/6/VRti2vGzCBfU6YT/7 I+RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187266; x=1713792066; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h9w4FpwtNbIZ1f6iZyUM+W9GcBTruH/kwzNUAVqphXM=; b=Ijh77MlhAKYPF5xa10qClL00/5EL0V0p/wQpUBGKb6iaPozyhzkcQ9EpxHe2YuXN0s KG35QA/kLICWw1rCF2ihOfFdLIws1XgBRpyQZo9uv+xmMZV1D3vLz9mjoUVU77Ekzb5K OpekrLQRkI5sJsVx4T9c4lTyUXxMXle56HjTmR3pWVbdUBpmfVXMbniUDr2VbipUuxny c36Rq7mnxQ8+qdA1m0yl4/abuc/N/CxyHJhWmnigg/dw7G/wRyr3wALiZDBvmp1eVDML u3RPGY0nyXmB9ZkOZfka2uvk7EyZjJm2vOUs/R4dl9QhvydzTZYLFSkgBnKaZXmujTTJ q4KQ== X-Forwarded-Encrypted: i=1; AJvYcCX/3UO266FTIikQ1AjjLqhr5cCByH1C8Lh04HOX4zFL3jvSy0dLivrgAqSHURtcDZXM1u2MJiENYi2kP6/e9Es7SK7yePjW X-Gm-Message-State: AOJu0YxhK75NT7MY2VJ5/Hbc9s7IunvpDuViPIYUi9MTOPZLv56/WkvW OIzxrCwXExQoclJ4iz6bJNDZpGrgVukwHKMphWFnw2cSaawRfF8xjBz6J1Q6EGe/y/SJ9Y7T9Zi lc0stvKUD7A== X-Google-Smtp-Source: AGHT+IFg7Diji1Un3wK6mnePZN7mYKBF/w2QVgvNxbwfAWtYTIdkaHyIM225wdh0ul7FEpqZHuHN+k/uhwHPHQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:d17:b0:611:2c40:e8d0 with SMTP id cn23-20020a05690c0d1700b006112c40e8d0mr2536454ywb.3.1713187266160; Mon, 15 Apr 2024 06:21:06 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:47 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-8-edumazet@google.com> Subject: [PATCH net-next 07/14] net_sched: sch_ets: implement lockless ets_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, ets_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in ets_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_ets.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_ets.c b/net/sched/sch_ets.c index 835b4460b44854a803d3054e744702022b7551f4..f80bc05d4c5a5050226e6cfd30fa951c0b61029f 100644 --- a/net/sched/sch_ets.c +++ b/net/sched/sch_ets.c @@ -646,7 +646,7 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt, sch_tree_lock(sch); - q->nbands = nbands; + WRITE_ONCE(q->nbands, nbands); for (i = nstrict; i < q->nstrict; i++) { if (q->classes[i].qdisc->q.qlen) { list_add_tail(&q->classes[i].alist, &q->active); @@ -658,11 +658,11 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt, list_del(&q->classes[i].alist); qdisc_tree_flush_backlog(q->classes[i].qdisc); } - q->nstrict = nstrict; + WRITE_ONCE(q->nstrict, nstrict); memcpy(q->prio2band, priomap, sizeof(priomap)); for (i = 0; i < q->nbands; i++) - q->classes[i].quantum = quanta[i]; + WRITE_ONCE(q->classes[i].quantum, quanta[i]); for (i = oldbands; i < q->nbands; i++) { q->classes[i].qdisc = queues[i]; @@ -676,7 +676,7 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt, for (i = q->nbands; i < oldbands; i++) { qdisc_put(q->classes[i].qdisc); q->classes[i].qdisc = NULL; - q->classes[i].quantum = 0; + WRITE_ONCE(q->classes[i].quantum, 0); q->classes[i].deficit = 0; gnet_stats_basic_sync_init(&q->classes[i].bstats); memset(&q->classes[i].qstats, 0, sizeof(q->classes[i].qstats)); @@ -733,6 +733,7 @@ static int ets_qdisc_dump(struct Qdisc *sch, struct sk_buff *skb) struct ets_sched *q = qdisc_priv(sch); struct nlattr *opts; struct nlattr *nest; + u8 nbands, nstrict; int band; int prio; int err; @@ -745,21 +746,22 @@ static int ets_qdisc_dump(struct Qdisc *sch, struct sk_buff *skb) if (!opts) goto nla_err; - if (nla_put_u8(skb, TCA_ETS_NBANDS, q->nbands)) + nbands = READ_ONCE(q->nbands); + if (nla_put_u8(skb, TCA_ETS_NBANDS, nbands)) goto nla_err; - if (q->nstrict && - nla_put_u8(skb, TCA_ETS_NSTRICT, q->nstrict)) + nstrict = READ_ONCE(q->nstrict); + if (nstrict && nla_put_u8(skb, TCA_ETS_NSTRICT, nstrict)) goto nla_err; - if (q->nbands > q->nstrict) { + if (nbands > nstrict) { nest = nla_nest_start(skb, TCA_ETS_QUANTA); if (!nest) goto nla_err; - for (band = q->nstrict; band < q->nbands; band++) { + for (band = nstrict; band < nbands; band++) { if (nla_put_u32(skb, TCA_ETS_QUANTA_BAND, - q->classes[band].quantum)) + READ_ONCE(q->classes[band].quantum))) goto nla_err; } @@ -771,7 +773,8 @@ static int ets_qdisc_dump(struct Qdisc *sch, struct sk_buff *skb) goto nla_err; for (prio = 0; prio <= TC_PRIO_MAX; prio++) { - if (nla_put_u8(skb, TCA_ETS_PRIOMAP_BAND, q->prio2band[prio])) + if (nla_put_u8(skb, TCA_ETS_PRIOMAP_BAND, + READ_ONCE(q->prio2band[prio]))) goto nla_err; } From patchwork Mon Apr 15 13:20:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630049 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BD8183A0A for ; Mon, 15 Apr 2024 13:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187269; cv=none; b=Qwg6bauiuZOabchnTH7uJJ0mfpugew6IkR8J8ERxb4se+as3W4MjEqGFJ20g+j5XyGwOnNLDRfXX4x8chv1N8w3zwebgT/BuENz7Zi1+u8VCEHHjv1coaAr++vozz7yyZR8AxWklm+9pAkxen4faQqeAYpsc8zOr7bZrbLJFNTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187269; c=relaxed/simple; bh=FOH0bg2dj6T984pv4vB3lHHu3oghm8AmO3cizV67C4U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LGfNRuQ0zvsHj5o8loEdaTdPEofjLiAuXp6CeWu8WAOgXtFmSy4aPY/1UBX68XAQtWFNr4z21Z5XeScXv2if07JOIN7GcDqLjvpYndR6ZfmMsVL8j5BbTzgK8Qu/kzAat/+J933T5IdLbxMQ66ihoRjRMyeGh5TLBTMv0sJUalk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OocEPncW; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OocEPncW" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61892d91207so37853797b3.3 for ; Mon, 15 Apr 2024 06:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187267; x=1713792067; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/Mgoe9sPgEPC/OjJ+22EBFraLcJf05jCazYFAHI/DlQ=; b=OocEPncWaCI//v5zPQSotHwc2Y1paTnmIbNnO9lNRWzVc1bYQudeifiFb+uEDNp2li t+KZMOdEuvSPhXGEiQk9kBuJLCq9y2m8/ctZD5/OIc5j3x08L/HrS0HNXOJ1gx8BV355 E1T8syCJ2RRNxoRdTMYuZphcxUjh/R6Ll5nY2jQARPBT7vLPrHCOzMA+cpnwrMpx04tH w66ApMMjoX6fkbx9UBvKHLECjDnAUjBpBXEUDofixe1yigU+vqvcVz/+XpMQuqM/g+CI RYpL7fpfiunky6kIldo2/LUNYxO5OwDeUTsNle1w8cOR+ZLafNjfj+CqBriwL96m//Bu pCYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187267; x=1713792067; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/Mgoe9sPgEPC/OjJ+22EBFraLcJf05jCazYFAHI/DlQ=; b=r5hB+DJbF6MN4Stw8sCex41tyWXLdECDeWOCWmBk9s486I18rU9MXd2Qp8ZAAaaOl/ mvKZcyBx3DmeairIVRJ/kSPv6otqf/KW1pRGKinHSlwIfb1Q4KXlnWdYP9EpTUcKsnve zQ5/C3wmgVJFXukiQ9bbhjHccFzmGXKrxVFOIP5TUOTcKiJ1jmV2Z2uBcKwDpVkFXazm FVKjLisGIrD4phDiGw1PU7I7+dG7lbxvh9HIlrA9UwZo+Vox0O242qnq7eNabAle+gpb 19RcRwegJlAOIoeZoQkqPLkmCpro6jpA/uwLeTcRdi6/AkGUYxvGynKj/iNSjSI0HCdw oGnw== X-Forwarded-Encrypted: i=1; AJvYcCX23Fhu07yZ36JHc6eNBnpEhpU5aoMfklXtu9+ibTjHaZHSyAJhqad+ppJDn0hKKpNBV881TiZs0a4oDcri96ETrinBhyGr X-Gm-Message-State: AOJu0YwYuuD3sbP8PLEoBA3Pp3Kzwba+TXHyVscH5aWCGisyj6uUba27 3rCdakyZbufD52YPCoJhVYbTk0r4LXBxXh0IvvAZnF4iHLQWk/jkyzjR+nn5vIAoDkZzfqMwKse JFJ1fMt/BOw== X-Google-Smtp-Source: AGHT+IH2Xjl+5INpqY0J4mc3TnCIponu0WyJk+DNZXvLgUF+0FBlJp7EMxHL6trfR5nz4on1BcoBoAx2/CqebQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:690b:b0:61a:d0d7:85af with SMTP id if11-20020a05690c690b00b0061ad0d785afmr711983ywb.4.1713187267595; Mon, 15 Apr 2024 06:21:07 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:48 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-9-edumazet@google.com> Subject: [PATCH net-next 08/14] net_sched: sch_fifo: implement lockless __fifo_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, __fifo_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in __fifo_init(). Also add missing READ_ONCE(sh->limit) in bfifo_enqueue(), pfifo_enqueue() and pfifo_tail_enqueue(). Signed-off-by: Eric Dumazet --- net/sched/sch_fifo.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c index 450f5c67ac4956e21b544dfd81f886714171eced..b50b2c2cc09bc6ee5b23d9d5d3abea4423ff75b9 100644 --- a/net/sched/sch_fifo.c +++ b/net/sched/sch_fifo.c @@ -19,7 +19,8 @@ static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { - if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit)) + if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <= + READ_ONCE(sch->limit))) return qdisc_enqueue_tail(skb, sch); return qdisc_drop(skb, sch, to_free); @@ -28,7 +29,7 @@ static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch, static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) { - if (likely(sch->q.qlen < sch->limit)) + if (likely(sch->q.qlen < READ_ONCE(sch->limit))) return qdisc_enqueue_tail(skb, sch); return qdisc_drop(skb, sch, to_free); @@ -39,7 +40,7 @@ static int pfifo_tail_enqueue(struct sk_buff *skb, struct Qdisc *sch, { unsigned int prev_backlog; - if (likely(sch->q.qlen < sch->limit)) + if (likely(sch->q.qlen < READ_ONCE(sch->limit))) return qdisc_enqueue_tail(skb, sch); prev_backlog = sch->qstats.backlog; @@ -105,14 +106,14 @@ static int __fifo_init(struct Qdisc *sch, struct nlattr *opt, if (is_bfifo) limit *= psched_mtu(qdisc_dev(sch)); - sch->limit = limit; + WRITE_ONCE(sch->limit, limit); } else { struct tc_fifo_qopt *ctl = nla_data(opt); if (nla_len(opt) < sizeof(*ctl)) return -EINVAL; - sch->limit = ctl->limit; + WRITE_ONCE(sch->limit, ctl->limit); } if (is_bfifo) @@ -154,7 +155,7 @@ static void fifo_destroy(struct Qdisc *sch) static int __fifo_dump(struct Qdisc *sch, struct sk_buff *skb) { - struct tc_fifo_qopt opt = { .limit = sch->limit }; + struct tc_fifo_qopt opt = { .limit = READ_ONCE(sch->limit) }; if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt)) goto nla_put_failure; From patchwork Mon Apr 15 13:20:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630050 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0444684A33 for ; Mon, 15 Apr 2024 13:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187271; cv=none; b=fcCf/9y1l/zHfOnfVqT/Fgy1EwkrXBY8lMA92pF8IIYfq9py+IBigp914QE3XnlOrwgZYwLMFqzx9Ys7I8XuPR3+uEeCfoo99rOxYz4IULomv4GH8SMp5QxtPFew89/t+U2cK2g68f8WXD89LC3y0muPOUJjuI1ot97FTAwNjyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187271; c=relaxed/simple; bh=q2pf/Q8BK2H67JUn3au0skahLZKNULIFJDuie3swDPs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ACTxnjLd6GddUobjf1zWzFkR2afR9/qSUZCs4CQYgRUVdv+MBnwOnxW7Dl1HSejHOv+vzMXXdrhlHKJ8E97PDImQcCbUILeg/SA4RZleOqXcjN32FSoyV/mRt84CIE+nq9Gqvv2fyd8f3JYcSs3sR259bWGiJmOhROvAUCkOGOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jk3eBhks; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jk3eBhks" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-615073c8dfbso68320397b3.1 for ; Mon, 15 Apr 2024 06:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187269; x=1713792069; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wtygv0E7O7SETFeC6r/7sohZugpAD6woKpEovIj2Kds=; b=Jk3eBhks8Qg3vQ+y4eEClke6Ium0TGHSC8AIUkSiL6gZmGHdibBoFlPsMHbn25WXWV f/UhQz4fhBsL/RBA/EyZud61BKxoY9n5Z/XdqI8vRScNzMV+ba1C77ydB0LLIlj+xd3l ktCAdxHPA5rd5ETQSVf9H7YW0HrmcNFTMB4wXbp1JypFP4zQWPJcQJ4P72XT6fRsVZt4 lC8I9W4WGTlau4QWF8MUBPtTp3x2whucAceTVupA9R5DJSORAeK61uUiKg75RKVfg8c/ xXrsbJVs9O+RX1bMNljPyqiulRLzm962HiT+1zKvu39PsNZYnCOxY7FfHwcOvlJ/idvy 9Hog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187269; x=1713792069; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wtygv0E7O7SETFeC6r/7sohZugpAD6woKpEovIj2Kds=; b=NWIn6SUIefmkACGpalFE6kVmqkLLKGpYht6NYJs6t0RTt8nOXl66bBVwsQLgj26czX 2jzohLocms7XCOA01X5BkwaqqME3UbfZ9uwylU1CfD37a+bFUTWqa96i0OdnaS+ZQNLo kZRQc/xyw6A9twmoIXMNPlme+fctCp+z4GxYNYs0Ko0DTtG91gt/Dpw7jEr1l14+M3KU VjX7GcavGzb7jFwIzrpnLgh/QeI0FtOw8upT95Sz/4NSExbN9bXWNaecNY4TS0AxfIyL UQmxkAbDmGeSIVEmCKaDvWtEHaLNEMRGgy/b8w12dwQdvdS/UxadX00t3QZGBjPRrPJb s2+Q== X-Forwarded-Encrypted: i=1; AJvYcCXpn/qCAjWsuYk5Gfj82xOu8h7OrfqPGLWArSs2FRogJP6V0rVOMFCFfnRiGGEexrqVbwgOf4eDjsHuHeDOIjwBT+/F0V+U X-Gm-Message-State: AOJu0Ywnj5e1pZqKDuCbQY8wMBis6UnR48InxuuG+S5MdEF3oA1iVTuk FvZE3XeNlz0/BEN/X2Qy3JJBhP4btG/jC+nMlVgLLXIrIVTcpfg6tx5szc6noQ8Fo5VTKUxo4Iu tojQTHecHlw== X-Google-Smtp-Source: AGHT+IHCmEZ22WcUXTZxRpkjgy/6qTaoahXzi20/tfJsbt6gkaqAK72fzjavTOmCrf0OclL7yTqDhGXmrEyxzQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:100e:b0:de0:ecc6:4681 with SMTP id w14-20020a056902100e00b00de0ecc64681mr1223343ybt.1.1713187269112; Mon, 15 Apr 2024 06:21:09 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:49 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-10-edumazet@google.com> Subject: [PATCH net-next 09/14] net_sched: sch_fq_codel: implement lockless fq_codel_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, fq_codel_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in fq_codel_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_fq_codel.c | 57 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c index 79f9d6de6c852268fa293f8067d029d385b54976..4f908c11ba9528f8f9f3af6752ff10005d6f6511 100644 --- a/net/sched/sch_fq_codel.c +++ b/net/sched/sch_fq_codel.c @@ -396,40 +396,49 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_FQ_CODEL_TARGET]) { u64 target = nla_get_u32(tb[TCA_FQ_CODEL_TARGET]); - q->cparams.target = (target * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->cparams.target, + (target * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_FQ_CODEL_CE_THRESHOLD]) { u64 val = nla_get_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]); - q->cparams.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->cparams.ce_threshold, + (val * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR]) - q->cparams.ce_threshold_selector = nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR]); + WRITE_ONCE(q->cparams.ce_threshold_selector, + nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR])); if (tb[TCA_FQ_CODEL_CE_THRESHOLD_MASK]) - q->cparams.ce_threshold_mask = nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_MASK]); + WRITE_ONCE(q->cparams.ce_threshold_mask, + nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_MASK])); if (tb[TCA_FQ_CODEL_INTERVAL]) { u64 interval = nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]); - q->cparams.interval = (interval * NSEC_PER_USEC) >> CODEL_SHIFT; + WRITE_ONCE(q->cparams.interval, + (interval * NSEC_PER_USEC) >> CODEL_SHIFT); } if (tb[TCA_FQ_CODEL_LIMIT]) - sch->limit = nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]); + WRITE_ONCE(sch->limit, + nla_get_u32(tb[TCA_FQ_CODEL_LIMIT])); if (tb[TCA_FQ_CODEL_ECN]) - q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]); + WRITE_ONCE(q->cparams.ecn, + !!nla_get_u32(tb[TCA_FQ_CODEL_ECN])); if (quantum) - q->quantum = quantum; + WRITE_ONCE(q->quantum, quantum); if (tb[TCA_FQ_CODEL_DROP_BATCH_SIZE]) - q->drop_batch_size = max(1U, nla_get_u32(tb[TCA_FQ_CODEL_DROP_BATCH_SIZE])); + WRITE_ONCE(q->drop_batch_size, + max(1U, nla_get_u32(tb[TCA_FQ_CODEL_DROP_BATCH_SIZE]))); if (tb[TCA_FQ_CODEL_MEMORY_LIMIT]) - q->memory_limit = min(1U << 31, nla_get_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT])); + WRITE_ONCE(q->memory_limit, + min(1U << 31, nla_get_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT]))); while (sch->q.qlen > sch->limit || q->memory_usage > q->memory_limit) { @@ -522,6 +531,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt, static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb) { struct fq_codel_sched_data *q = qdisc_priv(sch); + codel_time_t ce_threshold; struct nlattr *opts; opts = nla_nest_start_noflag(skb, TCA_OPTIONS); @@ -529,30 +539,33 @@ static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb) goto nla_put_failure; if (nla_put_u32(skb, TCA_FQ_CODEL_TARGET, - codel_time_to_us(q->cparams.target)) || + codel_time_to_us(READ_ONCE(q->cparams.target))) || nla_put_u32(skb, TCA_FQ_CODEL_LIMIT, - sch->limit) || + READ_ONCE(sch->limit)) || nla_put_u32(skb, TCA_FQ_CODEL_INTERVAL, - codel_time_to_us(q->cparams.interval)) || + codel_time_to_us(READ_ONCE(q->cparams.interval))) || nla_put_u32(skb, TCA_FQ_CODEL_ECN, - q->cparams.ecn) || + READ_ONCE(q->cparams.ecn)) || nla_put_u32(skb, TCA_FQ_CODEL_QUANTUM, - q->quantum) || + READ_ONCE(q->quantum)) || nla_put_u32(skb, TCA_FQ_CODEL_DROP_BATCH_SIZE, - q->drop_batch_size) || + READ_ONCE(q->drop_batch_size)) || nla_put_u32(skb, TCA_FQ_CODEL_MEMORY_LIMIT, - q->memory_limit) || + READ_ONCE(q->memory_limit)) || nla_put_u32(skb, TCA_FQ_CODEL_FLOWS, - q->flows_cnt)) + READ_ONCE(q->flows_cnt))) goto nla_put_failure; - if (q->cparams.ce_threshold != CODEL_DISABLED_THRESHOLD) { + ce_threshold = READ_ONCE(q->cparams.ce_threshold); + if (ce_threshold != CODEL_DISABLED_THRESHOLD) { if (nla_put_u32(skb, TCA_FQ_CODEL_CE_THRESHOLD, - codel_time_to_us(q->cparams.ce_threshold))) + codel_time_to_us(ce_threshold))) goto nla_put_failure; - if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR, q->cparams.ce_threshold_selector)) + if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR, + READ_ONCE(q->cparams.ce_threshold_selector))) goto nla_put_failure; - if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_MASK, q->cparams.ce_threshold_mask)) + if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_MASK, + READ_ONCE(q->cparams.ce_threshold_mask))) goto nla_put_failure; } From patchwork Mon Apr 15 13:20:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630051 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6456C84D2D for ; Mon, 15 Apr 2024 13:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187272; cv=none; b=rRSVNPM3LT2wNK5GewBtDwH/EqwNEzHYY1Jis/ayLzK3LHiW6gAq35tlr9DVo8nH9eyYKzO8i6jwHt31kEyCi2dridO/0uMa+jh2JB1/MfF85gMArBeHiXZMvlgPECYdUziLK7akary0NSc9imDuC5cQZcH2BewkPXYJ7XZz9lI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187272; c=relaxed/simple; bh=/of19FzXX03r5e9tp3Y4j/IZFUS4PnQYt6YCu5IkHPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TrXzgDfLSYbQB2VPeyGnsAObW5GV4wikFrVWzmpj6tAuCUleLa9xcvQ+TKIz6gEQojE+AOADz3JRo2R6GE/hxf9riP5kZJfUrylxE3lRYybYyP7XJJksr9WrlK1Z2ypbhDj92b81pyFqsXY5VysgeaI9ZZLECSBiQb5z1Gh2vio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=K6qQv5A5; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K6qQv5A5" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-615073c8dfbso68320697b3.1 for ; Mon, 15 Apr 2024 06:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187270; x=1713792070; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZAhtOdfHh8IMtHNXHnfeZAq6fP+T0FBuITQAqtTMUL4=; b=K6qQv5A54yLQX6g3RJEoZAN7hwVaDWtFYB5q5sme6VaU1Wynatj77SY5Pz6tGKKW70 81SnHIWO7dogERfIBmm0b9rB6Jqsi4YUXA6KsHD+GUj6Xwd6ncjJhbluaKRuMtnW7Sfr T1Vhl7sfxmlko7VW+HsOOWu/uiizn1PSvVwHAPvO9n2u69n7gRo2QU88hhRhyLYOF4Rb 7stscErAmf2wj0+MkLxzfRT4CrRGDxKvnhoD4GsauPru8+f+REQjp/Y+sTmfuVvx7B01 KJCvsafcDVs6hpMwbfuir74D7ywgFkMy3KbsMeEAQ51rWb4rUi7FRrcnCTT9e5oQKyAZ 0bjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187270; x=1713792070; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZAhtOdfHh8IMtHNXHnfeZAq6fP+T0FBuITQAqtTMUL4=; b=VRYVvQuCx66Y9lNwt6nhIVPCmMu/4Y7Xv7HLzye5R6mBSM74RMlqVUM9++8mIOj4Gf 57rbpeTo1BgAqg4RTb/zhSz9logpivbI6eC72Etj8/tHUcGDisYp3irOz3y32n3siQrt 56pvHU+p4A8W+YvgkyaYfdQrkvKRkRN7MCsec8yLEqv8qXK4Es4jXRHI2+PS/G1gPxI5 QzQWrcykAE3qS1WH2piuW1IKicvWSVXTACnTqbx7/fHuoADZnEb3D1UeTj9tbF/IHUKQ TlqHB7Su6DsgMFkMfVqg/fkoGKlSrA5zrOE1crdE0UUSQzq++7whd6lBUZCaH7EANxVO J24g== X-Forwarded-Encrypted: i=1; AJvYcCXheq83bQ5eyQ0ZBiAbl01EsMtpWeVdoxG7A1WV5/MDae15wdx6FaT9B2uoZ7tCj7OakJq7m3Kwkm9bvdGmRSI7xSChnPLI X-Gm-Message-State: AOJu0YyxKOUvwy7lOTf83+iLrgEN/tNP4uSMhs3CwNHqJ3WeYCzAAIMV myxYgCq667+d41Im2Oc5WQ722bQr55kiOKTU/Csepu8cIOiJQjQcTbjqNwWnq8jH4HtXZ54Svom 4y2lO0QZldA== X-Google-Smtp-Source: AGHT+IEsoaJnnJ8S6Ge4B/Sq97N3Jd7PDPqz+/ZK5hNhm1tC3mfu5EQgJbI2YTa/WjwxFuoTqoC/clS26Mlh9A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:9293:0:b0:618:876d:b881 with SMTP id j141-20020a819293000000b00618876db881mr2138269ywg.9.1713187270503; Mon, 15 Apr 2024 06:21:10 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:50 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-11-edumazet@google.com> Subject: [PATCH net-next 10/14] net_sched: sch_fq_pie: implement lockless fq_pie_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, fq_pie_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in fq_pie_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_fq_pie.c | 61 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c index 358cf304f4c91203749bac10f6e9154eda0a3778..c38f33ff80bde74cfe33de7558f66e5962ffe56b 100644 --- a/net/sched/sch_fq_pie.c +++ b/net/sched/sch_fq_pie.c @@ -299,8 +299,8 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_FQ_PIE_LIMIT]) { u32 limit = nla_get_u32(tb[TCA_FQ_PIE_LIMIT]); - q->p_params.limit = limit; - sch->limit = limit; + WRITE_ONCE(q->p_params.limit, limit); + WRITE_ONCE(sch->limit, limit); } if (tb[TCA_FQ_PIE_FLOWS]) { if (q->flows) { @@ -322,39 +322,45 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt, u32 target = nla_get_u32(tb[TCA_FQ_PIE_TARGET]); /* convert to pschedtime */ - q->p_params.target = - PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC); + WRITE_ONCE(q->p_params.target, + PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC)); } /* tupdate is in jiffies */ if (tb[TCA_FQ_PIE_TUPDATE]) - q->p_params.tupdate = - usecs_to_jiffies(nla_get_u32(tb[TCA_FQ_PIE_TUPDATE])); + WRITE_ONCE(q->p_params.tupdate, + usecs_to_jiffies(nla_get_u32(tb[TCA_FQ_PIE_TUPDATE]))); if (tb[TCA_FQ_PIE_ALPHA]) - q->p_params.alpha = nla_get_u32(tb[TCA_FQ_PIE_ALPHA]); + WRITE_ONCE(q->p_params.alpha, + nla_get_u32(tb[TCA_FQ_PIE_ALPHA])); if (tb[TCA_FQ_PIE_BETA]) - q->p_params.beta = nla_get_u32(tb[TCA_FQ_PIE_BETA]); + WRITE_ONCE(q->p_params.beta, + nla_get_u32(tb[TCA_FQ_PIE_BETA])); if (tb[TCA_FQ_PIE_QUANTUM]) - q->quantum = nla_get_u32(tb[TCA_FQ_PIE_QUANTUM]); + WRITE_ONCE(q->quantum, nla_get_u32(tb[TCA_FQ_PIE_QUANTUM])); if (tb[TCA_FQ_PIE_MEMORY_LIMIT]) - q->memory_limit = nla_get_u32(tb[TCA_FQ_PIE_MEMORY_LIMIT]); + WRITE_ONCE(q->memory_limit, + nla_get_u32(tb[TCA_FQ_PIE_MEMORY_LIMIT])); if (tb[TCA_FQ_PIE_ECN_PROB]) - q->ecn_prob = nla_get_u32(tb[TCA_FQ_PIE_ECN_PROB]); + WRITE_ONCE(q->ecn_prob, + nla_get_u32(tb[TCA_FQ_PIE_ECN_PROB])); if (tb[TCA_FQ_PIE_ECN]) - q->p_params.ecn = nla_get_u32(tb[TCA_FQ_PIE_ECN]); + WRITE_ONCE(q->p_params.ecn, + nla_get_u32(tb[TCA_FQ_PIE_ECN])); if (tb[TCA_FQ_PIE_BYTEMODE]) - q->p_params.bytemode = nla_get_u32(tb[TCA_FQ_PIE_BYTEMODE]); + WRITE_ONCE(q->p_params.bytemode, + nla_get_u32(tb[TCA_FQ_PIE_BYTEMODE])); if (tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR]) - q->p_params.dq_rate_estimator = - nla_get_u32(tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR]); + WRITE_ONCE(q->p_params.dq_rate_estimator, + nla_get_u32(tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR])); /* Drop excess packets if new limit is lower */ while (sch->q.qlen > sch->limit) { @@ -471,22 +477,23 @@ static int fq_pie_dump(struct Qdisc *sch, struct sk_buff *skb) return -EMSGSIZE; /* convert target from pschedtime to us */ - if (nla_put_u32(skb, TCA_FQ_PIE_LIMIT, sch->limit) || - nla_put_u32(skb, TCA_FQ_PIE_FLOWS, q->flows_cnt) || + if (nla_put_u32(skb, TCA_FQ_PIE_LIMIT, READ_ONCE(sch->limit)) || + nla_put_u32(skb, TCA_FQ_PIE_FLOWS, READ_ONCE(q->flows_cnt)) || nla_put_u32(skb, TCA_FQ_PIE_TARGET, - ((u32)PSCHED_TICKS2NS(q->p_params.target)) / + ((u32)PSCHED_TICKS2NS(READ_ONCE(q->p_params.target))) / NSEC_PER_USEC) || nla_put_u32(skb, TCA_FQ_PIE_TUPDATE, - jiffies_to_usecs(q->p_params.tupdate)) || - nla_put_u32(skb, TCA_FQ_PIE_ALPHA, q->p_params.alpha) || - nla_put_u32(skb, TCA_FQ_PIE_BETA, q->p_params.beta) || - nla_put_u32(skb, TCA_FQ_PIE_QUANTUM, q->quantum) || - nla_put_u32(skb, TCA_FQ_PIE_MEMORY_LIMIT, q->memory_limit) || - nla_put_u32(skb, TCA_FQ_PIE_ECN_PROB, q->ecn_prob) || - nla_put_u32(skb, TCA_FQ_PIE_ECN, q->p_params.ecn) || - nla_put_u32(skb, TCA_FQ_PIE_BYTEMODE, q->p_params.bytemode) || + jiffies_to_usecs(READ_ONCE(q->p_params.tupdate))) || + nla_put_u32(skb, TCA_FQ_PIE_ALPHA, READ_ONCE(q->p_params.alpha)) || + nla_put_u32(skb, TCA_FQ_PIE_BETA, READ_ONCE(q->p_params.beta)) || + nla_put_u32(skb, TCA_FQ_PIE_QUANTUM, READ_ONCE(q->quantum)) || + nla_put_u32(skb, TCA_FQ_PIE_MEMORY_LIMIT, + READ_ONCE(q->memory_limit)) || + nla_put_u32(skb, TCA_FQ_PIE_ECN_PROB, READ_ONCE(q->ecn_prob)) || + nla_put_u32(skb, TCA_FQ_PIE_ECN, READ_ONCE(q->p_params.ecn)) || + nla_put_u32(skb, TCA_FQ_PIE_BYTEMODE, READ_ONCE(q->p_params.bytemode)) || nla_put_u32(skb, TCA_FQ_PIE_DQ_RATE_ESTIMATOR, - q->p_params.dq_rate_estimator)) + READ_ONCE(q->p_params.dq_rate_estimator))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630052 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 931CE84DEA for ; Mon, 15 Apr 2024 13:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187273; cv=none; b=tH2vO2nbO/hna3W6nFkDupb63EFvCSoxMJLGsmW0VYn2s12jh3OthnBmwobPQx8YUlUgssLyrgqG70wSyLyjFa8A+SoQF2qjjL7HAu6kocMISQpqX+nVfnhsM1t2qNVOotsyvPMBMXt5DHVu0DUUUJ2dYcbHQZ9l5iqH4beKsKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187273; c=relaxed/simple; bh=HLoq1i+V4ApQOMYBc6PZyJGfENZMo+oN8p9CzxOHy6g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QPxM9tSB85iHD+qeuvGrNqVX5UJMtAHBX8Ei8FY4Dkj3OGIN6966e/1bfJT6JdE5zia3Kkbp8KssekLK1aG1BWmiFRgaMLM5nT8eQxgKpByRZBf3V08kDOPTRb5xZ3MW3I3a39eZdSQC+fV0bt7jQereXoFWmM0lbHPj5Vz31oE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Qm7PWi8x; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Qm7PWi8x" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-618891b439eso49547007b3.3 for ; Mon, 15 Apr 2024 06:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187271; x=1713792071; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=t2TA0iHMw7gZTifXWG5WTrNRKCCbxVowF92cfYPY/pw=; b=Qm7PWi8xAPVgSDAFOHy4av01U0b5iR6yh8R4LE+a2pP52EM4/UjDHnEDQAGzpbEqw8 PNwqLKYoao3fUCcLO0MDMdtA/sKRdkbnNw6Y2onZXgmzQEKeHlPr9ctxDnNT7ggxyKHE uLh/qHQ9LIAaS3nNcct0GAyWNB7AhB47hc6R1Qj2gGIM3J4tiHDKGJPcUWXxjUjNNHuc n3GryekXj5urP9d1iqlQYpQMfzv1m/MQjcphbnR8yvlrDexAdXzC2uhAr40/mNb8u2Ei OnBDjWUaB22s3l1yw7G7G5C2pMohAneaTydMmRei8AxceEeDb7VV/uJFRX1np5faRALk Ernw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187271; x=1713792071; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t2TA0iHMw7gZTifXWG5WTrNRKCCbxVowF92cfYPY/pw=; b=Cxu0aeIJkhVD0OC/RBq9yWDXtHjuHAo2cvPo6YEkdF4am184RMuJtg7Ne14YFXjCv4 AfSUMgjT1WKY57TydH2dLYZTTPAIMtzMGO4VyMjsfAhW2vZyehPPJu6eyhoVx4FX6Vxp reX0d+mTGKGUiA+zjS0+PvhtWPq/QydGeII8dyomRZEr0UTpX4vi8Bzu/4q/Qu6hVzHL 6EinU7rLKhX0whF2md54NoS+bNQo2DQNTs0rIod9wR3ODRWpOb+5dMVy2YhgcgcHTGHX krTMJSWjua+5IEZ7sNzEloPL8YyCSog3Tj7xkTAgZYAndIOGKZkgPN9xterw94W4O+53 6xEA== X-Forwarded-Encrypted: i=1; AJvYcCXcO3fBOWwFUD2/HHRZiS/xswbyTKYnp+8upX71sf5hCB5ZXzIjpwMZnIwEQSvFZ/89BX/Oyg2iZvALIJduNQCL3/6qKGeb X-Gm-Message-State: AOJu0Yxe27xw9S+BVrVUFPeOfOditIbkVLvw472NfamWA/jR/0Zmrrjp c0M4qixsFZaYAn8UV98Crc8OCTEJhvROrmHBDfLGb4x81BBw/wYIXBaC4oKzVfnJSpQUB+hUxls J1YnOlPyzAg== X-Google-Smtp-Source: AGHT+IGm877feMvQOycbWKE5li8/Ai0eyKu4WqTrADN/pv2FJs4AXcGIn6zx3MsV+wb3c07fdAMW8mPOO/zndA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:ebc2:0:b0:614:94ef:5027 with SMTP id u185-20020a0debc2000000b0061494ef5027mr2309424ywe.10.1713187271745; Mon, 15 Apr 2024 06:21:11 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:51 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-12-edumazet@google.com> Subject: [PATCH net-next 11/14] net_sched: sch_hfsc: implement lockless accesses to q->defcls From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, hfsc_dump_qdisc() can use READ_ONCE() annotation, paired with WRITE_ONCE() one in hfsc_change_qdisc(). Use READ_ONCE(q->defcls) in hfsc_classify() to no longer acquire qdisc lock from hfsc_change_qdisc(). Signed-off-by: Eric Dumazet --- net/sched/sch_hfsc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c index 4e626df742d7a937c219ae9755816f099b6f0680..c287bf8423b47b7ca022fc2e6ca19b77f3ec13a0 100644 --- a/net/sched/sch_hfsc.c +++ b/net/sched/sch_hfsc.c @@ -1174,7 +1174,8 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) } /* classification failed, try default class */ - cl = hfsc_find_class(TC_H_MAKE(TC_H_MAJ(sch->handle), q->defcls), sch); + cl = hfsc_find_class(TC_H_MAKE(TC_H_MAJ(sch->handle), + READ_ONCE(q->defcls)), sch); if (cl == NULL || cl->level > 0) return NULL; @@ -1443,9 +1444,7 @@ hfsc_change_qdisc(struct Qdisc *sch, struct nlattr *opt, return -EINVAL; qopt = nla_data(opt); - sch_tree_lock(sch); - q->defcls = qopt->defcls; - sch_tree_unlock(sch); + WRITE_ONCE(q->defcls, qopt->defcls); return 0; } @@ -1525,7 +1524,7 @@ hfsc_dump_qdisc(struct Qdisc *sch, struct sk_buff *skb) unsigned char *b = skb_tail_pointer(skb); struct tc_hfsc_qopt qopt; - qopt.defcls = q->defcls; + qopt.defcls = READ_ONCE(q->defcls); if (nla_put(skb, TCA_OPTIONS, sizeof(qopt), &qopt)) goto nla_put_failure; return skb->len; From patchwork Mon Apr 15 13:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630053 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BB9B84DFE for ; Mon, 15 Apr 2024 13:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187275; cv=none; b=O/2ReJwKQcVbMtKvrYALAwz70UAAtKZD861VyaPqMJUan9smY53ed3JFIRf6/vGZ5DwpDFi+nBGoTPor2VfWAJk5RNsI3m9Y6BcocIIz2fQ5cuorVrwfkRw5oujTBE3L2/fmctPusAjlglVQ4Xws27yQukMpDCeWOUAIl1N7CuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187275; c=relaxed/simple; bh=EQA1BiJY1jBZJPIIc5yC2exh9WrGdW0bhSkZv5Qbajw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pJ99CDFPzY3fzSxdek6AM58sVpZRLCeGDr20qlz8XJ3VMGSWXX4wtWdyuTFqC/R2wmrkXYG60IwLLgxQdhdEYhRghFrGxCQDW3ckdywuQO39KK0j9VGOLiSdYs/EyfZ1NFYfEp1acgJlkA81sDAydAE1dIHsIUi8Oe25ZoC1Nms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P9Ywngnl; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P9Ywngnl" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6156b93c768so56247877b3.1 for ; Mon, 15 Apr 2024 06:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187273; x=1713792073; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ITIRmHhSvZFTMFP25iD5aD7JQsFtRfJxKTY/gI0nHPM=; b=P9Ywngnlayb8z2O3btVI43Bcpjw6C4xNXwl6yfFcQ/Q04WZpM4GicmVwhOh10jmqXO sym4MWVylgT0PTJIAXyg0plVNnM+1MowUCHTwVU/YiIdWyYtoB7gf2zMF2tcQWC+Okyb FUr3icO2FJexqi2AYZZnRDc5wHfCyZbvNXbzDkek1qOO27c2b8ohzv12JI5oJd3NR2yc dHXNYdkXK/5+5mbf1sE6R8oCFBvedUpXTiFjE/YTyoj9MDfX9Wh47qDpGmUVKle4uVkG tL6V6ieayxWGOpzrYFlEp69tfNzK9I/0BfuViMgTcmyyiWPdSbE6hdGCSHHd/g2gNeqZ KZYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187273; x=1713792073; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ITIRmHhSvZFTMFP25iD5aD7JQsFtRfJxKTY/gI0nHPM=; b=Fx9RVdRs3AW4+jfmaS3Hp/fOBIhPkFFq6vfD68dwVJkc8REmV7Np7JJym/0Q5Poa6+ OvMYggJ6zWauMe5daiYZqkEcR8qOA+5gAfB3B+tEtJx0HNaWqYzxhqMAb3880WtQ0lIo EgB7fFs8ISvuwJQmZpFVU4xkh0p3BAX4bzITG0HgMLbyI1y27vhn5hr+xaSnvqn3ue4U fAIn2Y+0DquDw1WczcYl6mx9/srAoTNFfxbbrMaEvp4Vez9IWqO9pQB+PAD2AaOsNIm2 kLMqyrnLt2aI/NZTEAX3YYYbJilrHEFvf1M+48mKk541vyEt3h2RQ3tom2urhSuEQDV8 F/Dw== X-Forwarded-Encrypted: i=1; AJvYcCVAGSouOeCxfJE6xllMglcUmLB9ioqMcWBnb0AwH/RbAts6VejWjDjZquSKQ/LiU8aZqxcm7D+byhQsXaaCT1IXDtGRLpGU X-Gm-Message-State: AOJu0Ywi6uhuvivNF7jrd7cKDOCXDmrrkl/SUo5eRvnad5HiE/jWJCle bv9Ht8C1zvCWbX9h48SKDqC0XhZ57NXNUCLFiCIZ9HE/RgWreARuJPVfBL5nlM6pcjmUozueQJZ XDosG5Lv8Fg== X-Google-Smtp-Source: AGHT+IHsPG7dTS8BfJJ2t+ufJxJo67vwLNGqT3JtspuzL/dcIx633ixkHiKY8yx0N+/r3P4XLfEaDu9gkWMU9g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:e:b0:618:9044:4f8b with SMTP id bc14-20020a05690c000e00b0061890444f8bmr2535416ywb.7.1713187273113; Mon, 15 Apr 2024 06:21:13 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:52 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-13-edumazet@google.com> Subject: [PATCH net-next 12/14] net_sched: sch_hhf: implement lockless hhf_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, hhf_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in hhf_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_hhf.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c index 3f906df1435b2edea4286ba56bab68066be238b1..44d9efe1a96a89bdb44a6d48071b3eed90fd5554 100644 --- a/net/sched/sch_hhf.c +++ b/net/sched/sch_hhf.c @@ -534,27 +534,31 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt, sch_tree_lock(sch); if (tb[TCA_HHF_BACKLOG_LIMIT]) - sch->limit = nla_get_u32(tb[TCA_HHF_BACKLOG_LIMIT]); + WRITE_ONCE(sch->limit, nla_get_u32(tb[TCA_HHF_BACKLOG_LIMIT])); - q->quantum = new_quantum; - q->hhf_non_hh_weight = new_hhf_non_hh_weight; + WRITE_ONCE(q->quantum, new_quantum); + WRITE_ONCE(q->hhf_non_hh_weight, new_hhf_non_hh_weight); if (tb[TCA_HHF_HH_FLOWS_LIMIT]) - q->hh_flows_limit = nla_get_u32(tb[TCA_HHF_HH_FLOWS_LIMIT]); + WRITE_ONCE(q->hh_flows_limit, + nla_get_u32(tb[TCA_HHF_HH_FLOWS_LIMIT])); if (tb[TCA_HHF_RESET_TIMEOUT]) { u32 us = nla_get_u32(tb[TCA_HHF_RESET_TIMEOUT]); - q->hhf_reset_timeout = usecs_to_jiffies(us); + WRITE_ONCE(q->hhf_reset_timeout, + usecs_to_jiffies(us)); } if (tb[TCA_HHF_ADMIT_BYTES]) - q->hhf_admit_bytes = nla_get_u32(tb[TCA_HHF_ADMIT_BYTES]); + WRITE_ONCE(q->hhf_admit_bytes, + nla_get_u32(tb[TCA_HHF_ADMIT_BYTES])); if (tb[TCA_HHF_EVICT_TIMEOUT]) { u32 us = nla_get_u32(tb[TCA_HHF_EVICT_TIMEOUT]); - q->hhf_evict_timeout = usecs_to_jiffies(us); + WRITE_ONCE(q->hhf_evict_timeout, + usecs_to_jiffies(us)); } qlen = sch->q.qlen; @@ -657,15 +661,18 @@ static int hhf_dump(struct Qdisc *sch, struct sk_buff *skb) if (opts == NULL) goto nla_put_failure; - if (nla_put_u32(skb, TCA_HHF_BACKLOG_LIMIT, sch->limit) || - nla_put_u32(skb, TCA_HHF_QUANTUM, q->quantum) || - nla_put_u32(skb, TCA_HHF_HH_FLOWS_LIMIT, q->hh_flows_limit) || + if (nla_put_u32(skb, TCA_HHF_BACKLOG_LIMIT, READ_ONCE(sch->limit)) || + nla_put_u32(skb, TCA_HHF_QUANTUM, READ_ONCE(q->quantum)) || + nla_put_u32(skb, TCA_HHF_HH_FLOWS_LIMIT, + READ_ONCE(q->hh_flows_limit)) || nla_put_u32(skb, TCA_HHF_RESET_TIMEOUT, - jiffies_to_usecs(q->hhf_reset_timeout)) || - nla_put_u32(skb, TCA_HHF_ADMIT_BYTES, q->hhf_admit_bytes) || + jiffies_to_usecs(READ_ONCE(q->hhf_reset_timeout))) || + nla_put_u32(skb, TCA_HHF_ADMIT_BYTES, + READ_ONCE(q->hhf_admit_bytes)) || nla_put_u32(skb, TCA_HHF_EVICT_TIMEOUT, - jiffies_to_usecs(q->hhf_evict_timeout)) || - nla_put_u32(skb, TCA_HHF_NON_HH_WEIGHT, q->hhf_non_hh_weight)) + jiffies_to_usecs(READ_ONCE(q->hhf_evict_timeout))) || + nla_put_u32(skb, TCA_HHF_NON_HH_WEIGHT, + READ_ONCE(q->hhf_non_hh_weight))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630054 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8505E84DEA for ; Mon, 15 Apr 2024 13:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187277; cv=none; b=OzcmQLtbnbw4sJQ7E66NImhGIqcxwrB5jH3rEnU4NWD6QYPsjhFpBIwAstQZoVFiMUD3OVm5K2NP0r8qhQPkc9w0FB6pN1Q8KU2CwfZK/r9yAHStRKy220Uc/vjSumtozYcZpGXmCx1ybkafyaE/wQJG5jv8FKdo8GH1ZJHawYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187277; c=relaxed/simple; bh=5q+k7NS9vI3SEuKwoY/Rbn+q2xtRsNm+6ilKKD6RYR8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IYxxcRjA0HAuHfoXfqbpVlLpfEc9yZ611mG8qnfQS8inw7eBcveLHgXPt1wsr7GdHdVROS/rdAsmE4NdAYp2k4yiW3v/DmS41DUS4vsTAnTh1xrUGvevTNb1IsMdP7CPTdRXCZt0dKzba4RKbuDtoesywcUKvppwqg9g738xJeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rHM8vMNJ; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rHM8vMNJ" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd169dd4183so4147063276.3 for ; Mon, 15 Apr 2024 06:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187274; x=1713792074; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Jkbl/RvKGDbnlrh/Ut87xj2shjaLFrAnvS+ShejraVk=; b=rHM8vMNJcqkmZ3fbzwMrU1f+3ipym7o/ehFdtyWbR5ZSFOvs+5v3vbRlIbvsD4LHDk 6aWYL0ny7/Sami/PNn9EdmgJN+sOTtbtshPdTQ1qPy3BjNStQBmAQM0OP3igwSpbW3Ml WEkQSS4jbzjyH8xByI/K+AxPuaXisU8qsUgfr2gSRtc9D39Gau2DsJ0gqWITWpZBkItx oj+akHWfFU2txYjFBVxki1J1pX3oveyvQwBpUgN/AxTnXV3dHZv3nsJ9fkXT3krp23uI L4YExhhSWbn5CVtPaSSb9kpOpFowD6aPPpM4eNWwzNH+9saVwqnnLGtwhPK5INFm9JUJ ggUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187274; x=1713792074; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jkbl/RvKGDbnlrh/Ut87xj2shjaLFrAnvS+ShejraVk=; b=HXetnvcFI77ucDBqZgCypP3l6/y2RkOGvmoM92oJZo8XOMgICLbHIu4TGlu2nDG0Bn PBmJtjGM7yW/yfMv2iMAR9WdEQ22ks/iOt8q3xWX0PNMCyXs8eNUvX5/PVvbMwvBDHTE wcwKzgUUPLyFNlrXNdB2cxA8KeBjjGk1I0ACGLXWTuE+57lvwXnExZqFvlEPIWlUN+4a Czs5o044VzfkaZbAZarcABw7KDPkEuCRmaFQQA714oI54lZhsNoLIKvdluBSYf9X0SK5 JvuXR+4dynhkSYakANND4Rl1mMGfe3lCSnXpRVEwXYDWYJqIHzYL3ZT+G8X4h3hQPMVG siEA== X-Forwarded-Encrypted: i=1; AJvYcCXa2lcMdKTTLgAjk9ivlMIHHzi2Wft4bZNUqVodVOkVL2ORL+YR8Egf8Ou291YeEQ8CRivSJSqqDycnw3bvOfjR3O+Usmcl X-Gm-Message-State: AOJu0YzBMPoM6tRrINy8YeFlwdCxTYquFF8wQvjpS3iouiQXV8JtAOFy BViZe30UXgH6vaqCDqZV5vkmxDgYU87fzEgjBBEbXLIYzHUlkldcANlI0wcwI0YQU7Er5LOYc+1 UDazh542EiQ== X-Google-Smtp-Source: AGHT+IGrfJjlNzAyzfCLUR2NfKPN6Ut3n+9udb5RmcF6iZnfhZSo2BW4f2JaMcWxuqDgQJD2CSm7dCjWANr6Hw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1026:b0:dc2:5456:d9ac with SMTP id x6-20020a056902102600b00dc25456d9acmr1082322ybt.5.1713187274534; Mon, 15 Apr 2024 06:21:14 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:53 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-14-edumazet@google.com> Subject: [PATCH net-next 13/14] net_sched: sch_pie: implement lockless pie_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, pie_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in pie_change(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_pie.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c index 1764059b063536f619fb4a32b53adfe8c639a8e5..b3dcb845b32759357f4db1980a7cb4db531bfad5 100644 --- a/net/sched/sch_pie.c +++ b/net/sched/sch_pie.c @@ -156,36 +156,38 @@ static int pie_change(struct Qdisc *sch, struct nlattr *opt, u32 target = nla_get_u32(tb[TCA_PIE_TARGET]); /* convert to pschedtime */ - q->params.target = PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC); + WRITE_ONCE(q->params.target, + PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC)); } /* tupdate is in jiffies */ if (tb[TCA_PIE_TUPDATE]) - q->params.tupdate = - usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])); + WRITE_ONCE(q->params.tupdate, + usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE]))); if (tb[TCA_PIE_LIMIT]) { u32 limit = nla_get_u32(tb[TCA_PIE_LIMIT]); - q->params.limit = limit; - sch->limit = limit; + WRITE_ONCE(q->params.limit, limit); + WRITE_ONCE(sch->limit, limit); } if (tb[TCA_PIE_ALPHA]) - q->params.alpha = nla_get_u32(tb[TCA_PIE_ALPHA]); + WRITE_ONCE(q->params.alpha, nla_get_u32(tb[TCA_PIE_ALPHA])); if (tb[TCA_PIE_BETA]) - q->params.beta = nla_get_u32(tb[TCA_PIE_BETA]); + WRITE_ONCE(q->params.beta, nla_get_u32(tb[TCA_PIE_BETA])); if (tb[TCA_PIE_ECN]) - q->params.ecn = nla_get_u32(tb[TCA_PIE_ECN]); + WRITE_ONCE(q->params.ecn, nla_get_u32(tb[TCA_PIE_ECN])); if (tb[TCA_PIE_BYTEMODE]) - q->params.bytemode = nla_get_u32(tb[TCA_PIE_BYTEMODE]); + WRITE_ONCE(q->params.bytemode, + nla_get_u32(tb[TCA_PIE_BYTEMODE])); if (tb[TCA_PIE_DQ_RATE_ESTIMATOR]) - q->params.dq_rate_estimator = - nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]); + WRITE_ONCE(q->params.dq_rate_estimator, + nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR])); /* Drop excess packets if new limit is lower */ qlen = sch->q.qlen; @@ -469,17 +471,18 @@ static int pie_dump(struct Qdisc *sch, struct sk_buff *skb) /* convert target from pschedtime to us */ if (nla_put_u32(skb, TCA_PIE_TARGET, - ((u32)PSCHED_TICKS2NS(q->params.target)) / + ((u32)PSCHED_TICKS2NS(READ_ONCE(q->params.target))) / NSEC_PER_USEC) || - nla_put_u32(skb, TCA_PIE_LIMIT, sch->limit) || + nla_put_u32(skb, TCA_PIE_LIMIT, READ_ONCE(sch->limit)) || nla_put_u32(skb, TCA_PIE_TUPDATE, - jiffies_to_usecs(q->params.tupdate)) || - nla_put_u32(skb, TCA_PIE_ALPHA, q->params.alpha) || - nla_put_u32(skb, TCA_PIE_BETA, q->params.beta) || + jiffies_to_usecs(READ_ONCE(q->params.tupdate))) || + nla_put_u32(skb, TCA_PIE_ALPHA, READ_ONCE(q->params.alpha)) || + nla_put_u32(skb, TCA_PIE_BETA, READ_ONCE(q->params.beta)) || nla_put_u32(skb, TCA_PIE_ECN, q->params.ecn) || - nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode) || + nla_put_u32(skb, TCA_PIE_BYTEMODE, + READ_ONCE(q->params.bytemode)) || nla_put_u32(skb, TCA_PIE_DQ_RATE_ESTIMATOR, - q->params.dq_rate_estimator)) + READ_ONCE(q->params.dq_rate_estimator))) goto nla_put_failure; return nla_nest_end(skb, opts); From patchwork Mon Apr 15 13:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13630055 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A62BA84E16 for ; Mon, 15 Apr 2024 13:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187278; cv=none; b=oudDyu9bUE5kE+LjFq2y59AkYV2A5tuHoaCz7P52bDtpYjPq1L7zQMWsL/AZs2dN00Bm+eajsjEC7Wp5u5hCJv1joxmtIFBhzqRDWU0juYXrdeGWUJoQnB6Lni8ve89lDAmAXPYOw8EU8OaP1t1ia/2y6MD74TPwNGsJwVp4gVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713187278; c=relaxed/simple; bh=UihTBynof5ByLo8nWwjGOmB5TjVe1WZ5vmelRO+R5AQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ovJ7tYoClMteh/e8gKPcgfHStbSKgyDF0JmcrMr2mOoXaJuhD+4CteDgnF9rW+5WysGntNGjdQv7KNNnFz08z5WNs27t+ttMESVX7b3cOtc1u3W6CqrpaGNhB4Pn2Q0pBDdgoUk+qAQRD7bTt2nbsYNb6GbImE7/O3viMUvtLk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ut4Jt07v; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ut4Jt07v" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6183c4a6d18so48984647b3.3 for ; Mon, 15 Apr 2024 06:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713187276; x=1713792076; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Znp+vQdYzVYcETVz3Us8OPerpcvuVBrznxNI9AWwpzs=; b=ut4Jt07vZU04zpBfku9lVNqs+/grYh7Az12LblHHQLEBmkOQXKBPRKT4fobdNhLJvI DOMAEZGaR7dgIzuu/Xdy9udqWurrdFpADQB9yB6Sr9LWTb47XJWgM5Ozib6h/R0Y8Ah/ mSC8w63RSmTfob3e2B7WLEgVWyM0vfHcD6Xn1RhPEzHDvXfY4oxCo+UbXjQkM2rVuU88 ag+ZSl1TuGyF7p0Sq7kFCH78ur367bBwLr0cU3fM1LLSd0SKtdU058/3wZXfsz/y7YeH LwSo9HK4EYrAUZWUYOHhuaLcnrRE5Ma+jiCljJUfsG81l56AGNl+/iOV638xQtZ7tV9X ygug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713187276; x=1713792076; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Znp+vQdYzVYcETVz3Us8OPerpcvuVBrznxNI9AWwpzs=; b=FfdSeHsAiUf5KQrapZtfmFc/Zh8hnFa/kxGUYSZj05vqZnlVmB1p9Z8wU9lMYoB0gY fMQu6Am33N3m2JJbLFeN3l3eiECOi9Yl3d7u4cgpDwGSTeyC1/CIOmeiLyNfD4UQCRnN 2IjOD3Zf7VdPoSbjU/6EWFEDDA46rHli7YhRRJzdm3AupT0SCg+C1P/PgWOEicJfBKsc IwB9M1iXMMinTkmUslUVoFDEDD6Y3GmE+e54l9QX/w026F8TKI/G0E8c3VPqZ80IS27B UU5fgnzU8g3uLRti+dNNwMjPy2wEj4I19dgegFOhIYWW8JoryV5y8Ow0fwwzF0sLKY0M cbCQ== X-Forwarded-Encrypted: i=1; AJvYcCU5SuGEb8BhwMqJQf/yj7P61FAFdYB+mbpiKu+MhngyyzH982j87DdgQyHUMcKR1eweXJT2lG39YtmOz5ogrya6H0g26D3g X-Gm-Message-State: AOJu0YxZvyzyx7v14PczzKCp95rpccku5+6zyiQLCeoXASJEv8pSzj9W 4G07s0dn47EFzBl2PUAS2sTBVHVpoysbSexUpa54KmqsoPrjq+0RtUwlwk4QCH2SWHe3ipRYUh5 1Vj1QDAXVVA== X-Google-Smtp-Source: AGHT+IGWSeEEmDug5+P0RUq8SP/KB5Iio3SLbLzm77PNN1+ENHvqpoQocbx+PXobEhN4yCnwTL4Ifn3udB16hA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d886:0:b0:dd9:2d94:cd8a with SMTP id p128-20020a25d886000000b00dd92d94cd8amr736954ybg.9.1713187275828; Mon, 15 Apr 2024 06:21:15 -0700 (PDT) Date: Mon, 15 Apr 2024 13:20:54 +0000 In-Reply-To: <20240415132054.3822230-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415132054.3822230-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415132054.3822230-15-edumazet@google.com> Subject: [PATCH net-next 14/14] net_sched: sch_skbprio: implement lockless skbprio_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Instead of relying on RTNL, skbprio_dump() can use READ_ONCE() annotation, paired with WRITE_ONCE() one in skbprio_change(). Also add a READ_ONCE(sch->limit) in skbprio_enqueue(). Signed-off-by: Eric Dumazet --- net/sched/sch_skbprio.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_skbprio.c b/net/sched/sch_skbprio.c index b4dd626c309c36725e6030a338d21d1fabcb6704..20ff7386b74bd89c00b50a8f0def91b6c5cce7f4 100644 --- a/net/sched/sch_skbprio.c +++ b/net/sched/sch_skbprio.c @@ -79,7 +79,9 @@ static int skbprio_enqueue(struct sk_buff *skb, struct Qdisc *sch, prio = min(skb->priority, max_priority); qdisc = &q->qdiscs[prio]; - if (sch->q.qlen < sch->limit) { + + /* sch->limit can change under us from skbprio_change() */ + if (sch->q.qlen < READ_ONCE(sch->limit)) { __skb_queue_tail(qdisc, skb); qdisc_qstats_backlog_inc(sch, skb); q->qstats[prio].backlog += qdisc_pkt_len(skb); @@ -172,7 +174,7 @@ static int skbprio_change(struct Qdisc *sch, struct nlattr *opt, if (opt->nla_len != nla_attr_size(sizeof(*ctl))) return -EINVAL; - sch->limit = ctl->limit; + WRITE_ONCE(sch->limit, ctl->limit); return 0; } @@ -200,7 +202,7 @@ static int skbprio_dump(struct Qdisc *sch, struct sk_buff *skb) { struct tc_skbprio_qopt opt; - opt.limit = sch->limit; + opt.limit = READ_ONCE(sch->limit); if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt)) return -1;