From patchwork Thu Apr 18 07:32:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634254 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 8138A53E3F for ; Thu, 18 Apr 2024 07:32:53 +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=1713425575; cv=none; b=ikaP+JWS7UBsalTAjaD+SftYkTxvVKbqyruzy9lKrnWURkBxhtBTPe8b/Dv40o82TStJGcseLcA2vtQUVUlL73J1rvw6OTQeoM4Lu57hM1wlHgx8QTrBCo1Sg9AHinoZDXqywz91vHsevzmKY3XGVHOdycS1QID1FbVL8a4wSy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425575; c=relaxed/simple; bh=IQuUsn4nMzlTFL3vWlSTMlmnJgl7603HuASUWWjsFdU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Rl57mWZvWFfdSCRJv6ktXBa5obE3hU0h3YWWn8zpsW6DUnMR/9PMtqHXv12uKGHB3E2VuueP1oODeePU/HVJJ40a5SmE4/hpNNOMZiHj/wuydaD4Tx06urSrKOZwgI+IUIQUTWlE3bENI3fZheK00/D1M5flbZUxaSmnUCglOuc= 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=VyfZ4nP9; 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="VyfZ4nP9" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-619151db81cso22037957b3.0 for ; Thu, 18 Apr 2024 00:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425572; x=1714030372; 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=x2SaESb7cjcGNnqko6JfoxSkcTvVz1ZvXGocgbM0jGY=; b=VyfZ4nP94kw0Zq7ggSbDQluQg2aVixYfMY45pZhUHUSC0DOS8nbFrQ5cDDPeKIFK8Y Gv7kpKXmRknTL0q98CknDYy7d+NUKAekWKMYazh8YrNhNJlYFcZ4IRNrOy2WHqdn5rTB dc2xaStPK4BdISVHHVuj9ZUqJsoa/cYbEj6Kny2HbDYwNGMWJgrAU/YVSLimxQDSk/l/ dFDD9QtP4W9Tm30pC1PGl/bEQUCb0pOc4uCopTH2UCMee1NbBOw3y0T/Kg3Z4BMo84g/ ENBvkP4eBBgZbeG3JBeDsGUYAsVABBAct8SInvojk61kuEQDD+2nfguSWrEiZgmw7xXI aVTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425572; x=1714030372; 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=x2SaESb7cjcGNnqko6JfoxSkcTvVz1ZvXGocgbM0jGY=; b=pLR8wmk7vuvlPgVB0PqrO+sKG5HgnRd083gl4nZVWQwUA8MSw8TnIogb3CTcMrZda1 6MP80Cjs5SwDBjxdQT6Jc+ScCzeDux85eRfArkCBdeDnrn+2nR08CecVIMs6aiyODi9g sUUcyPrWwXcB87X19e4LbCtksT/EZuG+4c1sueiK0Y9gCc8nRYXIeEK7+uigsn/LvXQI SkxKcPVpAt9fgh0xQYZAvqyguig74t23QmeLTi8ea6V8L3JpMwfd3WtmvlIKAzGbXu8y X+2zipd5c2C2rg7UCQTSLLoTNkPdElEI/Ll23LeDf6WCDRhIunhQi9enQ8f5gQQSF5rM bKlA== X-Forwarded-Encrypted: i=1; AJvYcCVN+0MYN0JG1O8tKyL3EfN49KP8woakiw1hXFU3VQYxEpi0cCbUqgiS8zwby5sDFj/ckhMFrJq7f0JBQwa57zD7+d0dbdTs X-Gm-Message-State: AOJu0YzzX4GtKgYqzTvbbYluM4F4KzkEELsrACNWRygjAobIjqG9/tbH sVPu8uODTyfyZv9rLsxRDI2A6D4aWTxox5Qyd9LfF3wRXcqCiA1GeSoI//24u6XvL3ohxTsaaTj gZehWeCbR/A== X-Google-Smtp-Source: AGHT+IELWxuievh3jgzhP6kEuiZhbR/dkXBuKa4rSFjXxMltZa+HbCHuqbnbGIk1Xa64HjtwKhndPXh1tVKI0w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1001:b0:dda:c4ec:7db5 with SMTP id w1-20020a056902100100b00ddac4ec7db5mr449085ybt.4.1713425572518; Thu, 18 Apr 2024 00:32:52 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:35 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-2-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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() v2: Addressed Simon feedback in V1: https://lore.kernel.org/netdev/20240416181915.GT2320920@kernel.org/ Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/sched/sch_fq.c | 108 +++++++++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c index cdf23ff16f40bf244bb822e76016fde44e0c439b..238974725679327b0a0d483c011e15fc94ab0878 100644 --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -106,6 +106,8 @@ struct fq_perband_flows { int quantum; /* based on band nr : 576KB, 192KB, 64KB */ }; +#define FQ_PRIO2BAND_CRUMB_SIZE ((TC_PRIO_MAX + 1) >> 2) + struct fq_sched_data { /* Read mostly cache line */ @@ -122,7 +124,7 @@ struct fq_sched_data { u8 rate_enable; u8 fq_trees_log; u8 horizon_drop; - u8 prio2band[(TC_PRIO_MAX + 1) >> 2]; + u8 prio2band[FQ_PRIO2BAND_CRUMB_SIZE]; u32 timer_slack; /* hrtimer slack in ns */ /* Read/Write fields. */ @@ -159,7 +161,7 @@ struct fq_sched_data { /* return the i-th 2-bit value ("crumb") */ static u8 fq_prio2band(const u8 *prio2band, unsigned int prio) { - return (prio2band[prio / 4] >> (2 * (prio & 0x3))) & 0x3; + return (READ_ONCE(prio2band[prio / 4]) >> (2 * (prio & 0x3))) & 0x3; } /* @@ -888,7 +890,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); @@ -927,11 +929,15 @@ static const struct nla_policy fq_policy[TCA_FQ_MAX + 1] = { static void fq_prio2band_compress_crumb(const u8 *in, u8 *out) { const int num_elems = TC_PRIO_MAX + 1; + u8 tmp[FQ_PRIO2BAND_CRUMB_SIZE]; int i; - memset(out, 0, num_elems / 4); + memset(tmp, 0, sizeof(tmp)); for (i = 0; i < num_elems; i++) - out[i / 4] |= in[i] << (2 * (i & 0x3)); + tmp[i / 4] |= in[i] << (2 * (i & 0x3)); + + for (i = 0; i < FQ_PRIO2BAND_CRUMB_SIZE; i++) + WRITE_ONCE(out[i], tmp[i]); } static void fq_prio2band_decompress_crumb(const u8 *in, u8 *out) @@ -958,7 +964,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 +1017,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 +1036,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 +1046,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 +1066,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 +1077,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 +1177,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 +1191,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 Thu Apr 18 07:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634255 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 3233D7441A for ; Thu, 18 Apr 2024 07:32:54 +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=1713425576; cv=none; b=UcvnE7uqxOV+agBs+r9r/BxXVb/3BcepicM1Hd9HprdjdCqOIpnxBuT+0bv7E+XpIEas0OKmG+6lb/4/btw+hAC89SH5wMLoTKx44wI2nTMtu9IE1dMpo14PQcjYPoj5lLYJTXs+hGKNA5SRIwjopRtgk/vnMzTX7DoejYqtfpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425576; c=relaxed/simple; bh=VA3q+py6+0bIP4RFIUYyvmm6mwWK/L1YqBrFYQUkRv4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NIZz2yGysh6gq8X+MAXba9rfNc/FixpNToEhdb+EK/9KFefEP4vcErK5ooVK/Ht5n8DhchthTfJn+JLkk/6uU3NznMlHdUieyVggudBNLkMKpUyuKQIQNvYILzetHY7bKx3MSI5ylJNRoSqo2eAPaFXSpwb/tQ05o6PkyawQUH4= 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=0Wz1a2St; 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="0Wz1a2St" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de46620afd7so775513276.0 for ; Thu, 18 Apr 2024 00:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425574; x=1714030374; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=4i80YcpXlTakcqdlswld70FgnUZ4IoM5N9iASZpSALs=; b=0Wz1a2Stj/zweAAu1j2mrlQ9p4SjlO2ipiZKv6nTKPFBCxAckzp9uQXn7YO6WU3JSd 4jrpoTrRYwGHB05NE0vBShhhAI8HlFOoz5+aCpN/eHptBwx7SRAsEaX/Us32gpJy1wZh F8xWTvbSbyZeI0TQi3/irUqrLREufLNsKj9BGENQK3qh/sbC1teZAYXF68PifRSHA6hr yyXuxd1dLOEPceWIZPY7cNVjW+dy9RNA2+x+8W0cPbW+BH8KuyMSvOv07g98KxkHi/do F+2jNDjchya/cW5uukEFAsqtIyDJ2EKG8P1hRfQ19JqXfoacQ01wr6awSVHwgNmsw+b5 oZIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425574; x=1714030374; h=content-transfer-encoding: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=4i80YcpXlTakcqdlswld70FgnUZ4IoM5N9iASZpSALs=; b=kqn9CDK/y98xDEdEQw1OAoBkSsdD/xyeHm0u97ExbSmuEjJZ+FAM43YVSpGSLOOysY gWOxsjRzEZUi2qxtFXuild7z8VMvSsLCeBHmdFz9VcHFTiMz3EU+8UbC9f+UF4KUmNJb C11YcEKvUX2xN+xBb3bwwQt13HfdelPEHifI3ZcT6kJK5HXKVXTzCObX/W7w4l9wDuDA niatA++fnFv1VCBh0y/oIADvqshqKYY9S1+gIF2Dg0FBb45pkM4y/5rVlD9/xPbuNm+V 2C9cjPJ2LAIsaDHKxtBstNMSlczO4KKf9eVPTqzTfYmpGuabcsZiyoC3Ky+f+nWxaSCE E1IA== X-Forwarded-Encrypted: i=1; AJvYcCW7kMH3mdzvOePDWfyOdurLjbyZkrXuB2ziG9m0z2EwFWubLPN8iZYgwyfvhRCubdYxcTAxhIOnHsQ1E84zvQtPpVLTM0s5 X-Gm-Message-State: AOJu0Yxfd3bk2SehC5wmBMw/jwSWTIFvIZdxQVCmi2Wb3oGQWqYVvG0p Iw4+tqg+xnLD9cX95VTblaxyLi1TNLR6mPjGUIs3JtbP4GT62Q1Zy7Bwaa1zs2uelu22GpxX2VF xYrSdtif2Ow== X-Google-Smtp-Source: AGHT+IHZwYse95tmVltlJAH+GaM7RmC1SmhKBoxpsyzbg4o/QJ9IFo4f5ZEuoWUFGvxrwV58x2KahmgiDsLTJw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1209:b0:dc6:dfd9:d423 with SMTP id s9-20020a056902120900b00dc6dfd9d423mr207227ybu.3.1713425574110; Thu, 18 Apr 2024 00:32:54 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:36 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-3-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8?= =?utf-8?q?rgensen?= " 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(). v2: addressed Simon feedback in V1: https://lore.kernel.org/netdev/20240417083549.GA3846178@kernel.org/ Signed-off-by: Eric Dumazet Cc: Toke Høiland-Jørgensen Reviewed-by: Simon Horman Acked-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 110 +++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 47 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 2eabc4dc5b79a83ce423f73c9cccec86f14be7cf..9602dafe32e61d38dc00b0a35e1ee3f530989610 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -2572,6 +2572,8 @@ 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; + u8 flow_mode; int err; err = nla_parse_nested_deprecated(tb, TCA_CAKE_MAX, opt, cake_policy, @@ -2579,10 +2581,11 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, if (err < 0) return err; + flow_mode = q->flow_mode; if (tb[TCA_CAKE_NAT]) { #if IS_ENABLED(CONFIG_NF_CONNTRACK) - q->flow_mode &= ~CAKE_FLOW_NAT_FLAG; - q->flow_mode |= CAKE_FLOW_NAT_FLAG * + flow_mode &= ~CAKE_FLOW_NAT_FLAG; + flow_mode |= CAKE_FLOW_NAT_FLAG * !!nla_get_u32(tb[TCA_CAKE_NAT]); #else NL_SET_ERR_MSG_ATTR(extack, tb[TCA_CAKE_NAT], @@ -2592,29 +2595,34 @@ 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]) - q->flow_mode = ((q->flow_mode & CAKE_FLOW_NAT_FLAG) | + flow_mode = ((flow_mode & CAKE_FLOW_NAT_FLAG) | (nla_get_u32(tb[TCA_CAKE_FLOW_MODE]) & 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 +2631,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 +2640,58 @@ 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); + WRITE_ONCE(q->flow_mode, flow_mode); if (q->tins) { sch_tree_lock(sch); cake_reconfigure(sch); @@ -2774,68 +2786,72 @@ 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; + u8 flow_mode; 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)) + flow_mode = READ_ONCE(q->flow_mode); + if (nla_put_u32(skb, TCA_CAKE_FLOW_MODE, 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))) + !!(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 Thu Apr 18 07:32:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634256 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 8EF1D53E3F for ; Thu, 18 Apr 2024 07:32:56 +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=1713425578; cv=none; b=PUw/ncJbfkkgT4P9CyoXAXAViWPpXtbCleK3AAvvntwOJvxIWEef6hjOdeYwMeOGKgu2I9jkYiD5XE2nfmQ6jIYKYRF10CMjCtpqAg8HpOrc/xXRL8TUY7fe76NK86gUMFaTR6vWFGc97sHOodv2vZZlHG+58n3Xsrmq6ZpWfEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425578; c=relaxed/simple; bh=o1C4rkkaRhTIn8JKPJwSZY4szztCcHHb3B+Gqgn7Lf8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YQe+MWMqbLCCZZ/TpUKcnem3jrhGDqIpnYqJXz5r/pBvO0jjJR4kqDBcNm29M+2orMlI7u5+p+peGnvG88+HpeZI8CiEcNQA0GgYAoPJIVeLyWtKo62PjkyzVjEYJNLgU+NTFZlThrnhqbgvQXNQZXGnorD5XeGROItpPoRlRDY= 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=F5ahAiP7; 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="F5ahAiP7" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de4691a0918so603051276.0 for ; Thu, 18 Apr 2024 00:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425575; x=1714030375; 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=C2eTMFAEJNkYixMviBRtFiCkX59OC1AUV6clrpwB4sk=; b=F5ahAiP782aNdklTiepRv3LeTZrM8IshnhMtgXDBWeTkIORQyWNZrC3lOIfsDSKt4d FedVxykQqS7jrPHPLPG1lGtT9YDHm77AZgeA+CEZyXSdYcKBGov6mZGygsO09c8vziEf GK1xtMcQS43Tu3hra+HLmLGddtLBFU7tZ6uC/7vw6R7/A4C0k4WD9D28i8SYqWj4I2OC YKxzvqs0cts+4PdfUULUJsn7h8H+pAt93lL6HrnZSNfOBdCd0EJIy18+zC13S7l2V+l5 H4yMQM5IJcbw6/QRk+713sRVLCBFWe24MXJonTJEirk2AJVnJWwK7FjEj7+WK+uHQT7x EWDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425575; x=1714030375; 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=C2eTMFAEJNkYixMviBRtFiCkX59OC1AUV6clrpwB4sk=; b=cnfxfNpNCcO6m4dwC+JQwqBzFw8tjYLAJYDHnwOZzUo1ojsFgRduS/9nARUlvv8/Y+ F/HkXD6bvnqgL2m7YxBe8pkBUDaYHL3AtwflIdJXIRhb+w0UzuUJ4i8VXhq8nCG5A5rl M+81bAs5ClNfpgSDi6mv6QrXT5vkyYETiGBthRLiiOFZZKtW2907RfwJw/AF7M2KTB/u +2SgAuso+4mRUqf1aetwrhsmxfsfC+rdkdOblEfqOJPyipDf8Vm4kW9EyHF/vywPqLBy Qay+STWhKmrQ6h9PRwEngbf8YM0lggEoEOu3AAYYX6xY1vK7O5zWffGZLoMiTLhFfzo6 Cq6A== X-Forwarded-Encrypted: i=1; AJvYcCX27TJTD4O7HTYxFNKkH5q88eVH4g5j1VAhX17nh9F0sLHHEZPBnA3rKAH2yvPR9PxZ2EUG8diRTsTHY4+N44MivZEsU6Nv X-Gm-Message-State: AOJu0YzspD5MK1XL4J1ZsO8dyqluzD8gdngDg59YfThGTI+GSCLwzRVX zVS/Nu3e8YywhTipn2TF8qaGc6p/uZ1f7wCyh3FWx2zIp7hOCzfHuytEKBnM7t0exie2Ud6zi4j 7QWHpLgaqMg== X-Google-Smtp-Source: AGHT+IFH59AxRrWBkRPNTeChaBvTZL4dve5kvy/nSuVhcqBVrBxiO/FVIp+nqFF1JVAjYp9JVEdTmkwwcv/41g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1001:b0:dda:c4ec:7db5 with SMTP id w1-20020a056902100100b00ddac4ec7db5mr449112ybt.4.1713425575648; Thu, 18 Apr 2024 00:32:55 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:37 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-4-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634257 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 5AF7877F1B for ; Thu, 18 Apr 2024 07:32:58 +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=1713425579; cv=none; b=CWJF3bIXAKf9TjdkeJavwkofDeLEvzjHQnBpsWB+1DXePVunHL7jkgtgdF/ZiCwiUNxdAIP/0gZl/QbhJHr+AMElEmog3eIhj6QFGHHyJrLHMRfiPePaTjbFzf+WsUX14zBWOqaLajQuycqBicp2mJ6rsKQkKbl6Ke8VWmGbN6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425579; c=relaxed/simple; bh=x5VJ1Us9w79jidF/vPIqCn72gVsrgxq6aMRQh1RFXNk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YXszRI2JPEi41Lj/p14Iwq7w7UPHeHUxOz/znpen/6gbckhKgoRAvcI0SPnNJOguyaxMhEOYLNnFEGL3vx0Bpq39HKZmwdc6basRPzqn8qgXFSj/UCbULPCV+go6LVSHxXoo/vBcwR/8QJTcU+/b0G7inpRySqjjw/eqEoUSwM0= 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=ssCnUjNm; 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="ssCnUjNm" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc64f63d768so1105133276.2 for ; Thu, 18 Apr 2024 00:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425577; x=1714030377; 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=HjV4KNU0EJXj03hKcT3S+WchClfC9oEABVsClf5q3lU=; b=ssCnUjNmAP0/QM5sUJY0J+4/apJdOy8CRarJIsXjA/JtARCk44xiMV9W4IcF4hnu+3 sNpuQIDMmJ8AObYehJIxIW8+DmZEgfm7SwmneP2iJU97yF8TQOQJzMzq5HkH6cdfjgiE Ooh5c01PyNzrWTuNGSBi5jH8XPemZgKfmMn6d/dlGd24/wsaw4p+/xg1CwpqIWHKqKpC yuMSqS+5VnVe+zfNbVVUGEGhKpYmEOf7zk3QLHjqcduG5f71jCPNGbcC23gDVfTCV7iX ORMvdDUTXergdreVPsTrKG3swqbu2DZVEV25CtzNiOO25AVPnIgaVjum6JsBEd2/bRq6 c56w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425577; x=1714030377; 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=HjV4KNU0EJXj03hKcT3S+WchClfC9oEABVsClf5q3lU=; b=O0D2LY3DuTwPI5YKf9nWBAoRmalgXR8qlBpGqE41bendv56TyIHyYSjJPE+fUnivu3 yq6MLONTEEDGFbu6IIXewPq+BFDZ9T+k0Ph7OOcciGLKsWyeoHp1n4iXZi0SeKTuAcxH Z1OUmc8yXIu6G0Oijxs1Go5foHXQCowgwbeybxoXyMPKd7AkhDS4k6QDCfLPrCzipJp3 aWuk7Fok7DA7TIdMYWZ6DTDmXsEMawzlbGf6tuTAvpYOLEyeb9yDorRFuAy5KdXGM/wd lUdpS9ftOPavN1L0NppWu2eRW3XZ5sjSW0lylY2u2CKqwG8qAsFTA8VXAdS1WLQet6BF b02w== X-Forwarded-Encrypted: i=1; AJvYcCU9Ab11AMCc0Qzg7Ll5vUD7Nm0GypAPoaMYkwol9OpuESn+CiU9Ggkf5q0h9ewaymjlmndjTfgY3KH5GDHam+diV2circN/ X-Gm-Message-State: AOJu0Yw5FEK8rGHBQqExnmi+3mtoW8PatJoG3SXVlO3vbwQ5pTV08R60 iBb0tzNUFQHUNj2b+uBWxGNaSikcb8H/I8b87+2gdpxpmqeH58jCj55dLEjwHdDDapElUT/GQ/n Z7N8Ehgo1Gw== X-Google-Smtp-Source: AGHT+IGjzQ/PnoXPkX0BJ/dYDhjoDpAEVesCpQWZtJ6BAla+GeBDdQsHNcRBicCZpmwPChwlY9PUnns+vFxyjQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:18ce:b0:ddd:7581:1825 with SMTP id ck14-20020a05690218ce00b00ddd75811825mr498924ybb.8.1713425577409; Thu, 18 Apr 2024 00:32:57 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:38 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-5-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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(). v2: added a WRITE_ONCE(p->Scell_log, Scell_log) per Simon feedback in V1 Removed the READ_ONCE(q->limit) in choke_enqueue() Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- include/net/red.h | 12 ++++++------ net/sched/sch_choke.c | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/net/red.h b/include/net/red.h index 425364de0df7913cdd6361a0eb8d18b418372787..802287d52c9e37e76ba9154539f511629e4b9780 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); @@ -257,7 +257,7 @@ static inline void red_set_parms(struct red_parms *p, p->target_min = qth_min + 2*delta; p->target_max = qth_min + 3*delta; - p->Scell_log = Scell_log; + WRITE_ONCE(p->Scell_log, Scell_log); p->Scell_max = (255 << Scell_log); if (stab) diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c index ea108030c6b410418f0b58ba7ea51e1b524d4df9..91072010923d1825e811adbb8ea2b3035dda57b3 100644 --- a/net/sched/sch_choke.c +++ b/net/sched/sch_choke.c @@ -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 Thu Apr 18 07:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634258 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 1369976020 for ; Thu, 18 Apr 2024 07:32: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=1713425581; cv=none; b=owXWnxXF/8nfwSt8XPWo+Z6VmyjMvhqStzEOUqLF+GBYZXn1e1XMfcT2+VqesNEDIazi3XtbaLpoyJAmvXqKWtYJ9WxGKJGvG5VExOY066cyfKX01O/Soh0J98/Qrk6qDKUJyg/ou+iO3Tbh7UlpKEeg1XXZHP4uqHl+OTF37Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425581; c=relaxed/simple; bh=2hIFyipII8OOWNDZdnuv0t8Itw/RcH+X7pyy715i53g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bFwZAd12rWF1scP5rqPff4vtAL3p3Bk0SKlUotqPwddnxlBsC4dZ+Y7HwfRGUIze3CQcsr9rrt5jbFOUoKm04sV+OGxfO5uHOA2E2mOWWo/QLPFWFl7lUWKEzN+JdjUlpqaXK+D2IRFPpNgvdNeed7Wkq6qrAhq7FltDhJCtL5c= 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=XBuYwoyn; 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="XBuYwoyn" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de4691a0918so603144276.0 for ; Thu, 18 Apr 2024 00:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425579; x=1714030379; 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=vSEp7O/SdcZldqzKBrdGB5o96F65O2dgiyTSqodJorE=; b=XBuYwoynJ3oY4bkj02tuUWtAtCWz6NKRXHk7q/nZIZt0Yk7joWoMMJMk52NNjEtJTt qL/tdrZ3O1E6MYPGwNRxXIeK7SqzC2mKdd+MT13okhJ+9nt2OALhg1SiY1jMs9XrWrDm canJGzN5CjuLRQebAuGHyx3sfPcpSRlZjWVsK5oV6Z8be/RK/zOjOTnF/rz4KPLy17nA 1nDttnwcYzOdR9n5716Q66Friltug9u2/UpjJYictBj9iUZLnHDVkgX5jlYS2/q6i5xX D934wurUf760Gbbm6XSZLbWFP9sukx7boasJXBgMgOjLswIVadH8IJFLHO6IM6Flsv2y jeLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425579; x=1714030379; 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=vSEp7O/SdcZldqzKBrdGB5o96F65O2dgiyTSqodJorE=; b=jR3jxFnFo4Dv0kFMR0IU8TvCIxq7TOFXLuP0uZ46MQGQjq02eOYbw2wO9tt7tTMIxN 4JQjePln5eBrcaz0f1Bzp54bvp6USSPy4z9EXncC8gmv37MnWD9t2ZG/kA65RMcrBbLn 0pb87MPF2U6qLng7LDnqRyRlUZuyNaEeQM5LUywllcZw6CAQ4liu5oD//5ijAbzEMdS5 dK2cTX3o6P3dFrVIQFYptbwY6Dx0BXLnzwXsDFtBAKA8aj9HRBjfWt/4bwSw8n3RPMxi 06esbfRBBqdmTwUV26ydYf6nnEUVogi+ZvwSQTyBTCUFLOy0PXLR0VGleTMuR8lrDBqf 44Vg== X-Forwarded-Encrypted: i=1; AJvYcCWwJTBawR72jeyeUyHfY+HKZK6atO0UKg/One+NA06tr1ZAQcMRoSeCVM4S2j3fHlwbmIZKZ1Wo7oy+YTfClzmfoQOaNByB X-Gm-Message-State: AOJu0Yw24EDQfLWzVVEXLN8h2RTVMg1KVNLie/u0EQ/RTQRzNKeOesuR U0Jfl5Wq0SKdZVnywRKvxasjV2g5SqfRXAZ/v51TiTAhiePN6U/6Sn1CE/97fRF3C0fk/5aR+8r Vu3vMB76mWA== X-Google-Smtp-Source: AGHT+IEE4Wrsyq6gG13/tp9NyaWks54IOzQgWC50CJdH/TFXdbnWB+U6BDHLE9o0vsCfc9YmMQStimNxCLfTAg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1001:b0:dda:c4ec:7db5 with SMTP id w1-20020a056902100100b00ddac4ec7db5mr449151ybt.4.1713425579078; Thu, 18 Apr 2024 00:32:59 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:39 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-6-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13634259 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 CB73A6A356 for ; Thu, 18 Apr 2024 07:33:01 +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=1713425583; cv=none; b=IgmGxTK65drunhUwT4C5r83S254OfPZPi5+JtvueSFArPiaCE8Km1yYbB/5EKZJnD7Q9KxiB/RM1FDZse7YFKM28eZigYSANnZN5BZzhY7YCA/EzjW69HO7vb1K4u9GN2aPXfJXLdwbSO8pFqR8CtLhDPP0lEgU+IFK8gM2GZCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425583; c=relaxed/simple; bh=vGDRsF2SQuhzhsL9wSQ8KZPZPJN1nEctETCneR7xS0Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NWLiid4ThfRq/1tBn3+Wfx/fTfeKzvHDPhqCo5Ex50Y7OH9icAqEgmD3jFY6tbnnKspkyVowZmqGY0lWKu2epPmSsXejGX15+I8jIn1gCXkNkz4HJSX6w6jxuvy1AQRGGJ0cJh2LuYKMjBff0eOFRnKJxc9b22Io1+HIYMup2KE= 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=FlOstQqj; 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="FlOstQqj" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6150e36ca0dso10110937b3.1 for ; Thu, 18 Apr 2024 00:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425581; x=1714030381; 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=PjbA9Hm94DgM6gUo1HGzOdv08CERKaJKOCV/kzrCO/o=; b=FlOstQqjgM2rg7vsIlRs1PgOmXhoJIMOWDjttqFj1XXg5GVomokFVWz/NAVm5Z19aT YvsVbnsy90V1jZcM4yB9FzXcK0FnT8iGt504JgQGjeYu5hhpZSOv7lz1OVf4AVU1vk/d lgy35tAZFFcxpacLMl++oYQXhYjV/0ZeNPYpiYQH5YbGfL+cXIliVzzzxWvpLHl/2JsZ oF7EfBLce+raALbUHdANt+MHX/K4YY507KFyp3IOMOAtIlotZ8qf+eY0DF83FUNVnv5y SHb13H7DAh4yC2470at0je26xqAmI9UAtbzPPsVxYQo8dzr1qjrodOWkXN70BmVpmnA7 Ih+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425581; x=1714030381; 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=PjbA9Hm94DgM6gUo1HGzOdv08CERKaJKOCV/kzrCO/o=; b=KaZXT9TcWqKAwD2PsjM2ZdFPXmX7MkGshjuLwiUqhve0nghRDzrcxcGprFuv4r2Ynx M/sbz622v35vISUk7+1Tmwe/VnhU93RZQTyqTGoyTP3xz66vG2iZi/0F3Fp0Vp2os4+a IYiMf5p0j5U00uCbzI3amUrgMSfit6NZBheJv+8MbXWRARyz5SVr7+Ohmbgd8oz7M3wQ MUYxuPzGoZVTsWWv++5EmJZGq8GyNyrll9NS6mGtEBSdHMvHADMVU0+vFGj5fZFgdSE0 JphunvYyzVaFcWQ9gxNnwGlHfu8sH4wCghyARsNq4ylgEtWThvKAngd9DvLRDLDT5OZj Vr0Q== X-Forwarded-Encrypted: i=1; AJvYcCULWkQiqv6OIPjaW4z8JflwQSSg42P5M72rNevYFFAWgCmc0agzAwLle2WOt6RzqM3wDnjmM6QmEwZGGo3r1U/cnlmEE5Eb X-Gm-Message-State: AOJu0YwSEKgH8TEXquKCY1zBniIW2pXmiKscatia12IxKpbloguyKGbc VXpeAXia1U/cT3+9f5KnVfeUGFMGdo7bkb2KcsoscQawKa6xNSMqLcXJVp3nALFO5v1DHlaJHPz esIvK3M6J3w== X-Google-Smtp-Source: AGHT+IHQgiXzPz/RbfPTLrk16d0yT7utDif2qCm3fdg6LsIQPZmjjg6BQwu7TVsoYvw9USBsr9pQijJ6OOcc/w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:2c05:b0:dda:c566:dadd with SMTP id fk5-20020a0569022c0500b00ddac566daddmr134882ybb.4.1713425580690; Thu, 18 Apr 2024 00:33:00 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:40 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-7-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634260 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 50D2F6CDDF for ; Thu, 18 Apr 2024 07:33:03 +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=1713425584; cv=none; b=iY3Y+rmD+8bc/aWHEzbz684HEqFwSmGjRWe2jkfzp3sFFCLr8ZK1IQfXMwtO5F1BWrcu3vjGzYLH1dX4keuBX1R5ICpQV+KcalT/AdXD2DibAZuPOtIrIJAdAMgbThS06Hh/R4Qzbu5dwU4m6XdCD4rWUrV8hrVgKT+cXVw9yO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425584; c=relaxed/simple; bh=Vmkft94CeXm1utOByhhbQk2dGA/tV6M1rzjjDE+0I8c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o+kxfpvtCgsRn8qNcbRzDwPbcrv8wP9uXXC7gAPXJYgaWIOS8BUFArXILLwqgy42Lz1NPT8AfoDDUh+VE5tmhDR771JacB09DcuZngZwARG5zpVeI0WjHKLzf95tLzFgLqUXKJKIPSfdS0xboIBGyRsJlaaI3kpM6vSV4H5tCoQ= 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=RPT0ziME; 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="RPT0ziME" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6ceade361so1338647276.0 for ; Thu, 18 Apr 2024 00:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425582; x=1714030382; 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=CZ6xGx7SCL04/2YLzMv5yVEEGM7jH9ixgUc8FyaXnxA=; b=RPT0ziMEuVv/5m40w3bN2j2W8Mi4BaQdqc/SJDe3jXP6r7rOOLvkmIOejwaP6h3NFC p5dusf2AgrrHmSPirNUof54oz1RTPXKJqkzdrSfjucY8z/K1fliBsZuyIz2dCQehmIHS h7LEdJmWZQbEAej3ErGXlvfkgW/YxDt+Sp9RbyOC7I0ntPejI+ESUKxueXLdcwjDnZJr nQID7UrBAT9eQ5tV2GwaTMNX40xt+sVoLgxJh3+B/TYTuK1aiz14/Hm017j1LTAfu/Tg Zu1zW2VQ+aDDBt4TYkQMKORUXi/KCMyPjh8lhfcxZ5kRtBq0FkEOy86aNzQbq6NuLbUd Q4jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425582; x=1714030382; 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=CZ6xGx7SCL04/2YLzMv5yVEEGM7jH9ixgUc8FyaXnxA=; b=Che5TmVSu/XcMfxYrekK6VNQ9Vj05jVhoNzHhBXGXRRm/vXvV9KS1/VCq8mcSIeoqm dofsImYBP18/3OOdVk8/codDjWvadNpkdaV+XSjpZslPdiatIMg10pY4A1z13JaqwlJb ihaUNC3C+/2ylfFSVwkykN1tvOhM0dEyCE7DBDGyEP/thCenE31H6wx58/qX8IrFXYfy 7Q4WJzPp5IRJVEWT76tzpPRVa5qXKqZrmX9jGivVIvjB6RVvQPcZ1+MI7z8GbT5KPb+E 0fbqmpJhor+C1cZsB1ruv0DDgrUTrnFedGIg0MTVWizDCTR1LG8AgYIH1fgee+nkl90F VmGg== X-Forwarded-Encrypted: i=1; AJvYcCW4Q4Ms/P/07uNaG4lvJvHoLVy7Vi5vAkjQR7H3Y/q5utqpEBJZk/Lrl49JxY5VSuB2mk4kvTGLA4zThv5L6WJerkmxzCPW X-Gm-Message-State: AOJu0Yzw0WQyp67GPeqo9sGITmXyQYbNHEMygK/dV7B8uEAmhtalvLHa 1gNvk6MMHMSExs29sxdkhXVbhwGKxaY6Xqri8BuKNFIJJnPkvaqXb83mQ7V7TyiwOs8jHdf9st7 6dKetjqGTGQ== X-Google-Smtp-Source: AGHT+IEOysJ/o2JBt8MpjJNm9RKDrsiBVxPKyHFe5ZUYV92MyyJUCqpq9VAa9N2e7j7ZoIutIhPrJs5UvToKXA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:c0e:b0:dc2:550b:a4f4 with SMTP id fs14-20020a0569020c0e00b00dc2550ba4f4mr511441ybb.1.1713425582523; Thu, 18 Apr 2024 00:33:02 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:41 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-8-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634261 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 E5D167BB15 for ; Thu, 18 Apr 2024 07:33:04 +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=1713425586; cv=none; b=qo/Igevb0+KpL7VYq71mFR9X+AArosW838AjP+1Axl5+kokhfhxuR4wutX5XfiiGXlqLn+txlcLGOlWZMq9lH6afWGmrDr4QcqEuGq2gDRGwsZnhXKEs/Q6K+qj8q/WXHTTgehULlbuJHGI0ztRUd4MAnU7doLFiBigQIlBMsW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425586; c=relaxed/simple; bh=FOH0bg2dj6T984pv4vB3lHHu3oghm8AmO3cizV67C4U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=J2PmkDuigwu4L2YmH7MA6Lvp8tI2A0x2Ygjm/QySIlZ9CXtA16AVmZaXpK1hwlNNbLRyfXoeH/grxXlTm/Ap6TKB1XdmjFACt6kUwTwpz46Rn0lCkj/owZZEsNeOc/njIzTjtmJMKWwmW4OwcmgZvp1hDo9FIaVEViw/oRLt0p8= 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=dIAQ2Bbh; 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="dIAQ2Bbh" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609fe93b5cfso8197477b3.0 for ; Thu, 18 Apr 2024 00:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425584; x=1714030384; 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=dIAQ2Bbhog2EtSnV5THRDPVKfQdWfdSHA8ISJvRMePr0W/XLuVUhY/7QTxT1B92lYv uauLgkIFp/Yao5wCV4SJL2wf1C4Ev8qqhLOwv4JshSpgzm5nn1UJNY3EL26GOxC729Kg 5moAIXARZw7BkejLzVQNhI4NZr8ppirtv+ZmF/PsPFr6qnhkrFJqSm+OHhoSnGJijHeK RF4OniMJZDbMO/o7UzIgN2JgG7NhnBX1ZgREfn+YKvxRC4pLHJGEKHvOfSnWZxaz666F HSPFQkRDOx3NhooMZVdPAVJXtt98jMwHzO4S0t+vDtm9loyZG108YLP37DB+lObphVNW /8sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425584; x=1714030384; 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=ctiTrozkeYS+PAn9oz5U6GPSw94MuIRK0ZTJl5OmONAdD7wAuPl41IyurntxNraivh 4zgIYz8sQwBbSBFy02KqLaGUhyg1pSeUTvHXE1ThV/kdsXD9aK4WS7jsY1AsQqlCl5DR Ldpq33t/m1u0pKSwJfiOzrTLzIx+VuDYqqGOwA8oACE5C61eK5cj+oWy8f9ghdnJ93en /zf6GFBTAkcwE0P8qBVbKyM/Hwn1IeV4tlurRK2Rojko8zo3fluneos5X2i9IukR2A5D xgbp4iKcIYRkBymdbyLYeV8RxHgZ7dyvioHdT7Sp2963gEi3uySjdFyQwM5G6478tLPd IEfQ== X-Forwarded-Encrypted: i=1; AJvYcCXoJ+BIz4nUmDBO1jFO7K5VOdOx9tayi1nyUQKcTWAA4GL36X184bMdbOhODyfOrf1+Wxk1XMl0pIxCrOkzoo1YRWlLiroV X-Gm-Message-State: AOJu0YxgGFj/S9O0mdhpdT8dc0EQNifAV7MVIOnTePLOe8pGkG19deCM pvDkpHInrJxCFszLfRNMCbor5URmAFAD80xr7kbrorB+sKv/NA4unEg1b4waAwGiHpWR14+fjOr GuImAq2mY+Q== X-Google-Smtp-Source: AGHT+IGTvstfTjtXZlgZ+fjC6VOgu60knvwQkZRMcKSXXEaeCjTHAQE4GyYZQ1WCOtZaoJdpWfGFku3wkIaRfg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:2988:b0:de4:7037:69a2 with SMTP id ew8-20020a056902298800b00de4703769a2mr10067ybb.5.1713425583961; Thu, 18 Apr 2024 00:33:03 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:42 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-9-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Reviewed-by: Simon Horman --- 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 Thu Apr 18 07:32: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: 13634262 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 67FA57C08C for ; Thu, 18 Apr 2024 07:33: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=1713425587; cv=none; b=CVf3kH/DIAPdq/VOoUPI7lDkHv+KBrybYoY6TvkKcoSL1o2TMNwXanXfE9fsZBMhBKhkekiKA5Xf2RTe0fCwfXrTV3u/c6YP0JDRIe7THWSamEFWxGxTnm0CY4AM6XYVuijBK+1fTa2TUh6Zbbhc+A8j6P0AVcfawT7R4RvWOSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425587; c=relaxed/simple; bh=OJR8GFUO8+pJk0/M0QUGFcusMywbZZPVv+N+t3FyK/I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BtxjyeI/EviGaNWQACOuEN52JQuM9/P5GJwWYxQqRXTStqK/lFtbz1/lEepX8mEZHMWhc13XfQs3GmRDybGXkEZGi8IGaj7Qq3sNIPDhpDdFcFGlDYgU89Ru0GP0nMesIs6mOztIvo/BVKlS4dHt9qitaqDunwYBokYAxVuCTbQ= 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=KxxAoSF+; 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="KxxAoSF+" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a20c33f06so7549847b3.2 for ; Thu, 18 Apr 2024 00:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425585; x=1714030385; 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=1P53Qros0rXXpmScM4sJQZHx9M+c/CX8Dd9IiqSMITA=; b=KxxAoSF+HaVJSUkChioNgH8fZKfn750Wuzf9kMX6Rq3vuV/eEMNNvECPJ9/h8Us5gN rRp1Y1ik5oV7ush3YKyzx7oRWZnwh1wafsNjffq76EolOtesCKk2YxaVf0J+fS/jmQb5 SBRE1j9H8l62/vVCmL50LxHmByKQwGXh4JfuXutIGmNBcF5MxbaRAQOzxf676+6zoVHG Hyu5DVd2yh35d1J32CeZzGPEXe7alWiw7gXJrWi8m+yjm9DiiQ6HCrNxRo08nObsBDy0 wioDWDRJN53vwZzyNOygMGl+pkF61pNE5/URFiqktt5KB3cS8J/ruDR3iaQbF+2ZUcsB 2q0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425585; x=1714030385; 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=1P53Qros0rXXpmScM4sJQZHx9M+c/CX8Dd9IiqSMITA=; b=sKq01bP0QqdCnk0L3FE0/uTDHnEQijSbpDWdLefaxsBzxG/+nUQd1eyPCMgBx6pf5O HM52D40QybKplYzC9Axc/D9y0A9RpK6uToR1iKP8ee3EjThkBF57/E2gJT0l6S1a6y0s mX4wb8AP5cPFoHiKrjoaHNzurxjj0ZnIKI4AfkY8Pt/gRTlu4mT1E+GCR6safw5+MGKx XeLIzjWJWJDml3cQIPJU94YMgpNKUABFBGAj4tAAFu6W20yYG/uCX3IJobGNAE86OHXx di78Jn/sE/qrAzIXLcb/c+tDHrAenC6rhlcM9YylxG0o0G4cElkgcn4QU3a8Mcikvuv7 0Xxw== X-Forwarded-Encrypted: i=1; AJvYcCUB2w0fe2H4GMt8bfS0tOL6oWX3Z1aeuKe1D46KU/2AeJk654NsmpHERCaLq8V4jDzSQnugDThFwHzfgX0uRXLIebkgN3r+ X-Gm-Message-State: AOJu0YwfBiohRMqYIXtqASyJtU44crRRH4kNsF169rrAqBLIF6x/8Wpb Z7qJ2psyykk9VPuHfaQTjIjjOcOPdF0DGy+cQxjdao/aPOg+2dCzbdNIVMK++aAdtxX7CdKDLmi bTdo4ObnrZw== X-Google-Smtp-Source: AGHT+IFVsSehM5IIMMpaAGTVzuEwav4O+VMwiSf03Uiik3zsuz/+ioFCI+f3z5RCfBHnNXytHuMsT3DeqEg2eA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:804b:0:b0:de4:71ad:72f5 with SMTP id a11-20020a25804b000000b00de471ad72f5mr2118ybn.12.1713425585508; Thu, 18 Apr 2024 00:33:05 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:43 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-10-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634263 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 D92EB7BB15 for ; Thu, 18 Apr 2024 07:33:07 +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=1713425589; cv=none; b=f8Q0i+YdiSV7mP3ALexAwjjC2QxJa4bSNbTCosK/OfHj4he/eud8eDMTjvtOz16A32GUOvdxpX2xMOQnQ58tJTLejEt4nNHG2Xwb1keEE4i8E8KN0NwGmmXq9u37yjCpmm8YIuIFtn4uqkxoP5mckBL48leRugTb0Q4cKi+5hJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425589; c=relaxed/simple; bh=b9geUwdvrCVApCZ+TDEP6S5A5EH3GkVRnsbA9/mj3W4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aIESwF9stZxoNM5EM5JPjzjdpjSakXl4c5kGDJUZ1RRn56TzWLRW10hp+sfzVoIEpN1+JrftzHE9NWr/xxRRBr9LzQzKL2AEptpaxC1k1yyOXcbxvZjY2NuSrIL1YsA5TjGnAFSr4RkReB2mN3pbV1we5ydS0xu/0J3YaChtmXc= 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=R0hIawiQ; 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="R0hIawiQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de46620afd7so775770276.0 for ; Thu, 18 Apr 2024 00:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425587; x=1714030387; 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=JcvxTE64aBwZTgLCzhIFcmEI8tlRcvvT0NRZ+mhM1Bc=; b=R0hIawiQjZLuoe4par7zicOgpTrY14qHbDLCbmtk8CUCWKOsGoqhV5Cu6GByPKfGjH q0hqSApVJLK28pb5wt9q4nWi6nrtUlY0ciP9NGx4oG1hpgFKPrsZiyxXCUJrWEXwROgV g9vlc1fsALJOSuRs01YeLRED8Iqj8LKdyhmjLLaSF1eXsRg3CuLxhsYXKbnNQG2vLtgD 0qRdm27NXVUeYjLHo2uhGNmPcTZd9LTWci5PX/ENV88kQmFza3hJckDWRZ4hw0ubjCMK tcfCa6AZ55RP/nXULkYqmDPOENxEJxETC9Q4mue88JvF/o6A0ekBNaqeyBjT6sgfRWz0 AiKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425587; x=1714030387; 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=JcvxTE64aBwZTgLCzhIFcmEI8tlRcvvT0NRZ+mhM1Bc=; b=NCRCdj+fJUiliaHZ10VomAR+ZNYN01Hk0KphLIQkT15w8+BYh2ntD0yjCQIdFjtP8P 2oUlycC1SJeRD/hBSZU+C9yrDJuAt6qSebULbic/Cwb7G/qoNtNjWVvkanHSqnbZcX+4 iKjB10aIkp1G7OLwvwaBgQ4bxvISOS6brHfJe54W5xVAcvzehlvYXpl46cmQklGgeWiA BEyQwaCPM3xqiwoP7WMMm1xcJfAjURY5TxtpEHOSuzUgx72ojE0/wG1nVMOATf/VUFWU E4pKcQm0y8afBh1Mhi7DiXOqdMZVLSgz27JgokYlRET7KnW1shYkoeYpwZUYvF9rCX3l 0w+Q== X-Forwarded-Encrypted: i=1; AJvYcCUtYV9UfIl7JlEV2RWZXc5U+Abj6SkFgaZyifGZykc/Fz3ytYKs2/2cYGdbREq3YghvLwL1KrDnD/5MtrIrMP4vxe7566V/ X-Gm-Message-State: AOJu0YxFVoI1v4QmCVH3Lsb86ZwTeGhz9Ifw7s+Rx4qnITsMCPulh9yI 2iuqbhv81nDneaNeO45uA4msk0XMPSIw4Iw71WId1UL22y5Mji8E6dZNK5GRaEhd628UkpkVEO5 6PgawmwFU6w== X-Google-Smtp-Source: AGHT+IELn3i+Y2Ad7iHrb4eX+JhyqQnWx+5HibSai60IL32eTAFN2QkFiqSgLa1BdsUyI4ZaaMhSyABmBj+2Tg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d352:0:b0:dcd:c091:e86 with SMTP id e79-20020a25d352000000b00dcdc0910e86mr197710ybf.13.1713425587057; Thu, 18 Apr 2024 00:33:07 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:44 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-11-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634264 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 9DC8A7C6E9 for ; Thu, 18 Apr 2024 07:33:09 +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=1713425591; cv=none; b=YQfd5pfMHqBi9ttXxg1CpVNq8qGoseaeLsYMVwH4eDSidPq7C1bWO4oKBPZtkGJzHfNChUJAwe2ATwtPW7xL1wpvdWK/uyKiAi8IjQOsB9rU60dcY+e5dOEiJLfwWJoHPHgwctNCp0tJquYLHT/U2z+DFlFfyP4ldJV1UT2S81g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425591; c=relaxed/simple; bh=HLoq1i+V4ApQOMYBc6PZyJGfENZMo+oN8p9CzxOHy6g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i7HqD0a+zSWA/rqHetPdIIiYbr+cTB3rM/aDArFF4PVCI84vq439CmI99vBf4TE6wGIM4tJpUC8ocZKR7uPYFm6n9YALyVwl/N2Jz5q9TYhr+kGe8NDe641BPHycz6bBkATmpGbPNPWrfB51z4uMZBU8gb1YxFonlKCqe0Xpbe8= 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=Lh/unBkB; 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="Lh/unBkB" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de46620afd7so775836276.0 for ; Thu, 18 Apr 2024 00:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425588; x=1714030388; 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=Lh/unBkBUhUelW2CtPmtbmSwkznmAx0FnsABHqaG+Kxw69Ua3v9g3t5HqwYG0UHQKK 2flVnaTxVFTNxAQ0efiMZQjBassbt2ochX0rKy/6ppm4CNqJjjMcMw3VsYFwp6tFXiFi B4TCGiSDmL/aO0/IWDMwdG2EyCZfZbnoOk9+7h8MRkrWUJRBv61Vj7PRcvYsmGJ/Qhlh TvwzxMCZcXOLopCs6Q7FjH3oHKSTr+VbYkBP/U2nh0Y8eiy4qjGFATazBNbCOydQhIT4 1Nu3kRCjawTnV7+Lem6t0i9LThv54nuGUylak/s0f9nnuQ1vqb+pkVtAoS+AFEouXrza 3xjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425588; x=1714030388; 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=nYrxlfDhM0uE84LorNP0BqIBF5Cg5jwn7qC4KkHBJFmn9rpcrrlZ7zR4izwtQMpYoN Cx/d2cJv0+JWRsgYZJNnsVPUb0SuyinKpOAeX7mSKk8fF4UznaJOPEHVEp1ctsa8llrs +Lk1gyTCQbPrp+3G6hfJOYNTYtLJm0/rxFp2GZM0FWltln5zaNykRcJ2I344C0kHI2df QavhNU4H0DrSM1zH4lyRuQtqSo7z9tXW1YNX5kqrGpzIZLwoULe3dQYTnf8yOzm+GewW gaU9+cGmIrYezC/t9tNthIQIis3EczjhiiX3PdCpVE41d3QTj4L355hUUNabUly4Lh4Y wvGA== X-Forwarded-Encrypted: i=1; AJvYcCXcMIu/YaOaxHuUfcP0xmX9S2N8I7GuDjGYv7KbeAraQmCuOw78QJS4JSGv0lL7+8yi5ZA4ME/YXH2El8F/oXZT6nc2Q326 X-Gm-Message-State: AOJu0YxGzGDxZBm4VCC4K+cCjdtOnW27YtAYOfBrqqnidcL73t9i9uxK zaGx+Ul9/IlrBypp1opE0mDCkho0TUjonHr3EycW/4dv6HjhEukTvA18mOL//kGwiDeTJIEaRLy CVUi0a2WMTQ== X-Google-Smtp-Source: AGHT+IGCdemKID5Ih8hkY73Nm2GNNuUItojO8QfUPVqCBKDzmRhHzkpG34NIqSXw+vWOS1nciXqGlO+vaZYt7Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:20c6:b0:dce:5218:c89b with SMTP id dj6-20020a05690220c600b00dce5218c89bmr206655ybb.5.1713425588684; Thu, 18 Apr 2024 00:33:08 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:45 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-12-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Reviewed-by: Simon Horman --- 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 Thu Apr 18 07:32: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: 13634265 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 1D1D87BB15 for ; Thu, 18 Apr 2024 07:33:10 +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=1713425592; cv=none; b=MgbbnJyK2gH6ol8lzzHPb8oBDCJHiB4jXljSRnq1vvvEmeiUbieT4YnZaH8lKGUY4wiKnOItOhyOe3Q25yx0uA4CgeSydE0wKXFvY9AWIRmYQKIma1eXXJbd1U0keIe5wKm82m9B7Flm3qURlFQJne7PfJv+zO6p4xh49qsSHik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425592; c=relaxed/simple; bh=RrAEiqTycPvR23uJjnmgLpr6iHcROS6X7iTHehRp2Zc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SArLCTsvtxazsGv2K5OL5L/F/HW9ynXBFFFlZ4U44JnYDCoyQonOyjQh5C26UIC96xcmWOZbQyLw74ny7pYz1SgUbi+maD5NlENnbmEevXOhvHzaplsK+DEcUOXZIBxv7PheL1wgVheVgXcm/TMUSpwv16IxNZsD0edIayTnLVU= 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=E43GOGan; 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="E43GOGan" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609fe93b5cfso8198947b3.0 for ; Thu, 18 Apr 2024 00:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425590; x=1714030390; 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=CpZjAKuvNjDoXx43qMPEogquDjmJ6HzWGNcLYJbWwN8=; b=E43GOGanb/QFiek3rmf68XqjDT2WE2a8xOB0zOopxIDwOXdAymDywru0qCyQgJLM8g KfPI5mqDj7usY312V0NyTZt0IUdmzqt1BWijnr+0A7QQa+t5NcWqPNYSBD3LsjeUmCB0 e4ZLH/73cHfvZ2d70sP1326CAETTkk4mTvKagm7PH8ryLgkGSpX83sXyRoNuJBfUkwg8 YAyF4o460/fp9Uy3U+WDeK0ykbJgnXz92S7Jj2bEYaB62bk5OsioP47NRSXzVp4wlXhx U2aJmDHa++cFH/Ih/hZ3Sv1KhwV3iXZwfJPXMW1g2ilE72SpntI1wzaOV54rVi/swcLA ZlIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425590; x=1714030390; 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=CpZjAKuvNjDoXx43qMPEogquDjmJ6HzWGNcLYJbWwN8=; b=kf6Kj2w7aBdA5x8myASp7KRIlfeKbbKKPApvCCU9axRQaH4pP2aOlG/VGEXPUgrw+P pfFOQStLucQ1f+zA78/lJ5X2cYgcmX+cpPN/CNAEwHnLMM3xTNDCs7vFp1TcyIozAkn+ D6DtZA65DYa14IRmQeGnx30hc/aqDV785C4csesYx0h2xTy8tpXvjLSw0AhYABbY6gtv zDD+O+FriBxxv984xu4babWnKiF8IlbwkDte1bmR/c1592WHZVSXSz3VkbU5D3CLlNx6 0YV+/PjWjgsz3KZkqwU3x3gs2+XVXcXrblxI+yjo+ACNtHToI10rQtveBeOJ2NnOEG4W 3C/A== X-Forwarded-Encrypted: i=1; AJvYcCU35fjLLcj8OkAygD+j/fXMI7eSbzPaYmTVA4zEi0XSG151UhG2pLRUeXujw+0cpd7+5O+ijb6AuM3efYOVbPSsTlO5zEQV X-Gm-Message-State: AOJu0Yyivo/xcwFYSywO2WVMjRscs2faDDXqYTG9zTb/95MLSWv5Iqxe 2a2rRfd33dQMnk2I/mcdIbsQxZYGPkeg8Mb/6inu5nS2dS+Z8ymzelip61cKc/+inJbVbEdYZ+c MTGeIyvhxlA== X-Google-Smtp-Source: AGHT+IFLhIKF2KRB7nroXxKAbixsG7ZmEMXkid7ZtRUKgbIowrzLTp6h2kJOLOWiIoXjgilVahiPCUE4ftxA/g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:83d3:0:b0:61a:e7f7:a4cc with SMTP id t202-20020a8183d3000000b0061ae7f7a4ccmr328640ywf.4.1713425590174; Thu, 18 Apr 2024 00:33:10 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:46 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-13-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634266 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 A7CFA76413 for ; Thu, 18 Apr 2024 07:33:12 +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=1713425594; cv=none; b=NTv0uvWtMP/cYiYxtpZDwreB/ACIWSLNMEeQbVOQ4/ktiuE122jcYsfX0gFsS9Qz4KRWNh/8mSXMy7/znD76L6CIIVwx0eSdGpIWkKtU7EAdfurkKy61CFI5leM5JIkRu2QRf3fCduU/AleFaZC5QiAggKGD5bgD9lLyq88yyec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425594; c=relaxed/simple; bh=wrXy/PV/Lsgi1DF+BVNGyixdSpb26Ldc/jEQJnK9Iws=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nodZtrx+5I3x6h2TXj8R72kO/agtkZXGI2Bjd1f0/kncJQH5S/UT1ko1huUuRK32sb6DytzWWafCXDQNOkGYVypHghQsDOB53RJ3BeYZkhTIYjgQaA9awULJdG5dMMnQlCjqgNenr44PleNDd/+kUsnXa82ioK4ryjn5ZByysqo= 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=QcWDly8Z; 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="QcWDly8Z" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b269686aso1201365276.1 for ; Thu, 18 Apr 2024 00:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425591; x=1714030391; 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=1C3+w31/OE8eGi0fp5VXsJt9kUQGzlsndAxqYP/W1dM=; b=QcWDly8Z6Em6r3nwnY57zbG4H19EwmI/eeX2P84L+5kfQiSY/ZTsOcazzVesXTpwex iU+GSLtqNf8Awo0PFRHYcjqPiKQ1ayZQTrpKVl5efx6Nt073h/FCC4hnSNBdl1huRAgc 8UTU2XJcoCIsdMFm38DdX5ZXFOrBLbxrNYHojMmWmFbPffWdqLMBrjAzCM5rmuieFvZX A42be4BsJ/Y3VIv0nmz32TPQx5OGhN24YuSGlV2lowzw+JxjjOZTs0a4+tIc5vyNF+Q5 C1JvMuvj2q48TFd5r3bnu/dMQRpu+jfRnLET4BpnhW8oURKaTy+uxeXVLYfSOyqKIFOs 7h4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425591; x=1714030391; 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=1C3+w31/OE8eGi0fp5VXsJt9kUQGzlsndAxqYP/W1dM=; b=C8LFbO6UOzYdxYO8SQm23Po/kWf+RSYOea8wZy0WVasuqWxgpzD7Vj5t4dtZcrT8ch JN7jSwIIvz9t6dYSn3ujWxy7ZiOah1CAfx5vnAhhsX5+P5EdE0CvAXd0OH67xgy0nUzL gWRC6+4BI/HGiN65tbO8b4HxB7ZUNMOFaUHyfEAoz8Yb/Oup0wFpAaGzJX9qtaqPAmXa umfUpJ7IXEMnG0gM81Pi3mxcSrQ3/ALxkX8pDy74iET92gwtKzeeLpr5Z0PRfTZwi2ZV hYcZwcrHZ0SPDiD28WqLetJFZYTvsWP/c7VG+Hkod40g5YEeHY+d92nvuti9HDN1EsqI elaA== X-Forwarded-Encrypted: i=1; AJvYcCWVKILzsVelNLGO8fVZ3heRZfynY/pbSoUBAft0WfZAESr69ewEaE+sq05GN4JOjGmoyTjhQ5TDNAq8eBLHuHaJuIxj/M25 X-Gm-Message-State: AOJu0YyblS1qW4w44aqcbOZR7Lcw3LxtgkodFThhqAVBARRioccndZ0j GuJ3Nr3hDajGOh+RQ0KVzQMehnfS9z4Q7SXK3Fo0oSH0e+SYZ4m6TtN/zK5o60k9vzLSMUYET76 RLntRBvRm8g== X-Google-Smtp-Source: AGHT+IHzAnMBckNs581oisgT1gEYkmGLUuXsG6GSAMHJ9yffFaNVeoyRFnwHsRwXE5hTHthbiTIkPj2k0gkj+Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:20c6:b0:dce:5218:c89b with SMTP id dj6-20020a05690220c600b00dce5218c89bmr206659ybb.5.1713425591703; Thu, 18 Apr 2024 00:33:11 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:47 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-14-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Thu Apr 18 07:32: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: 13634267 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 3149E7D3E5 for ; Thu, 18 Apr 2024 07:33:14 +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=1713425595; cv=none; b=VNkEeXUJREeoVivEI3LoQgEj73XWSWTubqTWcxs2qFMWnocIawm18n3iuHOVcmg5CNwklc3jktnguBEORKV4G1wu9dVVIYVOnRfQtTTYCdSUmlg7ICvQlakGoCUMsE66OglQw3m8hXXJVqmKEoxjspbSqiVMxniICp6OKb5k4Co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713425595; c=relaxed/simple; bh=UihTBynof5ByLo8nWwjGOmB5TjVe1WZ5vmelRO+R5AQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Uq/y0vpQDkvEQeuvcMlW6EdYhf4hxtWJPymtdjGXUKVTtIPDl3O99N5n3OB0h9Xzv2H38oWaD7CTHJSpElH4el3ps4Ul+JejgcbOdKXVbcMlTJCm8cgVO3VEb3T6uQvYNNHALKSGidkqRGoRrcsgxOIxVZV8aWbS/0Mfu5Nr8zs= 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=uDETwkoJ; 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="uDETwkoJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de463fb34c9so1134331276.3 for ; Thu, 18 Apr 2024 00:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713425593; x=1714030393; 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=uDETwkoJCXyWc2guV3bYm9zuzPpQf+51WvgovrtI5/31mLdspbU/jdPIUuyPj3NkT+ 85AV76GQnKY9aeKjR/RgNnv9axP6qebVTgwOz8pbZfdwfWDbzlnk5+1sazQ8YK1jxEpG j+coICyiCtLcxD8RUkY9BMYTCRMTpLecJLBEGGC2A2Z2F4+UhtFbcgrikNClLxwjgYLc ZtwRO6r5uL4UhzGe/8uxcvxQomIrv+TXJyDXUqdDW6omD3jYdK4WLMvYELj0XL2NpqPN 5Ag1REQIbLkVf8JhfmLz4LUKq9juA1TmReiQ3jgAwAuTWDCcxrWDcOMVjFmYDsVWGETC VmYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713425593; x=1714030393; 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=BAxOYPyc6LhSJCZ9H3Dm1v4lvRo5n9qeNuRQW1eCOzYwXP3tTeoMEZuGL+WOGj9zON 2ZIj5lvm6b9Q85pnIPG4k+izHBYFMpzxVI00oLKXhZS757UpIFURHb5/iluPd5cjJxPX H+dMlRWV23MHI9kSDFonq3AchiwhP8r5xNpXQ7638KGuzKmIFTcj/VI+FK90hYgcAof0 IKErPgNQe2jox3nE+ijgWASejGiy1q49Wkq2NAK2CMtZ1c68vDuQqBGri2RI78sRS5t4 iXoSXc+AAOifGqIRWwgpRDN+BQYfO7T/TwvmDj3CwLXIFJKmCYqNG4UkZ5oT7RFFpKKz pbfw== X-Forwarded-Encrypted: i=1; AJvYcCUqxo5qwRarVgzBrtG/YDt7ffIRIpVyAgntPENJ6oVeBouhTfyZ4f20NyhmygMkcQURM5g0ct94+/k7qicUP4fGOf6K7g1j X-Gm-Message-State: AOJu0Yzu96wMVo2hTrEa94Ygh+MLTyyxQJSeTGMrn+hdX37NQG9gT3nn nnNj/oKR85LnZF0sucae+ceTvLcFA3PRikzl7jJDKDfNthTG3gzJTp0gQ1AUOzw2uiS5Y6TML7X Lf8g8J4fyxw== X-Google-Smtp-Source: AGHT+IE8Hie13hSVq0XWDGdiW0SI6fH903dqPHpHeTAYIDwA2H+Nn9Zo3at3R4HRHYL85tUuCRxL1KsK3epIzQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1141:b0:dcc:8be2:7cb0 with SMTP id p1-20020a056902114100b00dcc8be27cb0mr175009ybu.0.1713425593327; Thu, 18 Apr 2024 00:33:13 -0700 (PDT) Date: Thu, 18 Apr 2024 07:32:48 +0000 In-Reply-To: <20240418073248.2952954-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418073248.2952954-1-edumazet@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240418073248.2952954-15-edumazet@google.com> Subject: [PATCH v2 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 , Simon Horman , " =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= " , 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 Reviewed-by: Simon Horman --- 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;