From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796523688; b=JmgWxGEdTMSZeBl3iHu1kxjqb8H9+yqS10mllKsKPHSqgzwqZCGZ1HPh3fHV8oMhh92u bmL9ZZvYRpqVLu8ls1K+kIjrAzmz1DcYzj5D+IKmaH0KWmskVgrUNnwHF3KEB/Zwc3Scl bPvET/aKrSn35Phlaz8NjwUzKEWRE8Kl6o2Qa0A8qflNtmaJ+2sq0A/71ONtbOPJagdjM /3NYpWvzJvU33nkZxrcHDVEGFMFGjlwiCOwUt2LzVK2RKkr8+jluf7aGfZKbhQU4S/JBZ Gs8fuKMEP3q9NFroioJGVg3HykhELexrr0Y55Jqi3fZJEGs1aeOZBI9k2c9bkC2ceWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796523688; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=fQOGuuoCPL0mCkICfiyVx7Mr47eYwE8Eg9wwjsDXsqI=; b=ufE7H1viMQhJdXU0iyN3r/1bNYa45bDWZCtMzoiJ4bIsENIQoQzHqCHpz4n8VpvjZzVV W+QDGWe6s3yRtpDfD6ZnHrqoPKmOmQNeL1YolHw2hZ7awb9kMtcr6uiEwSZj220re71Sm Ul6avvZZfG3bXGwT7kP2R5axQbAbaoA6CkaPuQ8TfQJa3KKf3j5JHa9XXf6JPrE06Ut5M QHf/956mBh4HeRbKjrG6dpheYR+KlXk49bZMb0dQNeruxiDmycs3FnTMrJiV3MjtuiA4T 6lJkoFzi7ESYMNMGlICdsGODkJMbwzx4Z2ZtZrmkJ75MvTckEH48/m9ltXtF8OO+RIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=V1gWtYpX; arc=none smtp.remote-ip=209.85.216.53 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A0F1606A322 for ; Sun, 6 Dec 2026 02:21:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A0F1606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=V1gWtYpX Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3b5e015ce05so1471870a91.0 for ; Sat, 05 Dec 2026 18:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796523686; x=1797128486; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fQOGuuoCPL0mCkICfiyVx7Mr47eYwE8Eg9wwjsDXsqI=; b=V1gWtYpXAqx4cxtzTdtGpkKoNsFsij7hePWdVdKbrI+p8Fb2xdy/ECR5uVlY5QgrqK O1x2Fjz2knjkfuDiHS4mVy8YC5z6RIkMfsP93lwd4pUUOrG+Rl/IbhdD0K5Drbv+UG3Z nR9huyU10x/66GEpHHIu6kBoSPbZOX4eirbgGLOTIBFBzrNKBhZv/Ks1J5pnNkdc/PYE 5nZx3+OrucV+g5SuvzGvBtoxWrCKfZ/ioKJgkw2N++KgixsesOysBNXpTC63+8BDsvQo TRQAXlBi0NnMxzOv/m/Pf63TGdDvhIgg6SI+EbNvwmNKwvHYzK/i//96TN2D80dSZT6t F+lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796523686; x=1797128486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fQOGuuoCPL0mCkICfiyVx7Mr47eYwE8Eg9wwjsDXsqI=; b=U/nLg8RNRvXrwl3wRCks5Nhsn8j9lEbLT+MOZixy6k7m6MTSkru6vGe9fO7v0i+tHq aSinboVtzwrGgbUcziFSRMJYVzhfhRFVE303cA0I90ruvM9TYcC2c4wAd53rQlz53+Xv 9bi4+fRO2nczQL7IXklNLT+s/xpONnT71kLmzHqvGgnr3/tH3dSnZOooFYnfrJnI0tmh jq/s8Q4owyJniIv81ovR2XZzAAqMpmklR7m7eSUDAsSankEbNGCLqnwq1jOvNcdMrv6G /L0Vs7glg/OhKJ3AIl75zmLmWTfbCyAg5vev2M1XyTNVs/PVoyEHYaxWe0JqD0CUMeRr G7Kw== X-Gm-Message-State: AB4q+uHzPzxkw68DZaYWhdWxaD0L0Qs7ZjfXCSQRfEsl/D+GGwcuBgru n9BzXZZU74z83kTLmjgDyLexqJxw8bcNlWSK1SJs1oouykTm4WvGi6wFY60q4w== X-Gm-Gg: AZFdTZed62LMnJdmNJ3+CbYGtvmx8DcOndnlKIpwtjPzm1zAbrMzofBXZzUVFlF3l1h jlY0iLY9C4WMeAAYvR2pAp3LVYJZJ5d+oPBFF+s8x/NE738D6/Cetd/zhnrGZLZbVatqctTn7Qy 3izjWJT/1LxTWGW7F9/pXi1WV5Bvwj32NeN20RAf1NGIJJfHHolG23VjTSYNY17Wye19nIbDLU1 96Pb/vOdTTirXynF7LqYoFv/Kljqx43iPn5DL4FBX1wG+ZmFLu3s2xM+bee4ZxG9vsFViHWsHR/ mH7WAsd5k+0H2GqJEFjh7CKh5/kLGa7jp1XXhQ+MeUK9kTZkbccKkbEqEpT44nSWqGkneqY3cM3 83hTzGpjosEAump10xNh11ILu1a5U5HPEGoFwn2HUrQy1RXc6+8cRMrSofNyatiG5mLK1FCiL6x GWleQzR9jbP2LNSTWP4pcEGcD3kB0LIlbG6geXIEDw5rv/X85hra25DDTy+3OAx2vSYmkX6b0vI wL34sqX6LBFKPiTL+9dtRftLMSHWDoUNjWMkCBjegotO6Acvc8jQ7ThUf90kwqZRZ+wh9zvGiNY MkIESgdomb3taH0PIttsOX+wP4j6UZprHFWg0KiTwYPRZ2heWXMNWSU= X-Received: by 2002:a17:90b:498d:b0:3ac:97bc:4c7b with SMTP id 98e67ed59e1d1-3b5e063ecb8mr6417189a91.14.1796523686066; Sat, 05 Dec 2026 18:21:26 -0800 (PST) Received: from d.home.yangfl.dn42 ([2a09:bac1:76a0:d30::1d0:db]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc7157dsm10435971a91.15.2026.12.05.18.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 18:21:25 -0800 (PST) From: David Yang To: netdev@vger.kernel.org Cc: David Yang , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman Subject: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes Date: Sun, 6 Dec 2026 10:20:38 +0800 Message-ID: <20261206022040.4020726-8-mmyangfl@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261206022040.4020726-1-mmyangfl@gmail.com> References: <20261206022040.4020726-1-mmyangfl@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Bridge join, leave and flag changes rewrite the isolation masks, so a redirect rule that was trapped because of isolation may become reachable again, and a reachable one may need software assistant. Reload such non-skip_sw redirect rules accordingly. skip_sw rules are not touched at all: they cannot be degraded, port_bridge_leave() cannot be rejected (return value is void), nor can tc be told which rule got invalidated. Warn if any skip_sw rules are invalidated. Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support") Signed-off-by: David Yang --- drivers/net/dsa/motorcomm/chip.c | 75 +++++++++++++++++++++++++++--- drivers/net/dsa/motorcomm/chip.h | 2 + drivers/net/dsa/motorcomm/tc.c | 80 ++++++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 2 + 4 files changed, 153 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 0bc03ead8d36..dd8e06da7b2a 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1371,7 +1371,7 @@ yt921x_isolation_calc_bridge(struct yt921x_priv *priv, u16 ports_mask, } } -static void +void yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp, u16 *isolation_masks) { @@ -1496,12 +1496,40 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port) return 0; } +static void +yt921x_acl_refresh_extack(struct yt921x_priv *priv, int port, int res, int res2, + struct netlink_ext_ack *extack) +{ + struct device *dev = yt921x_priv_to_device(priv); + + if (!res || (res > 0 && res2 < 0)) + res = res2; + + if (res < 0) + if (extack) + NL_SET_ERR_MSG_FMT_MOD(extack, + "Failed to refresh ACL rules: %i", + res); + else + dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n", + port, res); + else if (res > 0) + if (extack) + NL_SET_ERR_MSG_MOD(extack, + "Could not reload some redirect rules due to skip_sw, they no longer work as expected"); + else + dev_warn(dev, "Could not reload some redirect rules for port %d due to skip_sw, they no longer work as expected\n", + port); +} + static int yt921x_bridge_flags(struct yt921x_priv *priv, int port, - struct switchdev_brport_flags flags) + struct switchdev_brport_flags flags, + struct netlink_ext_ack *extack) { u32 mask; int res; + int ret; if (flags.mask & BR_LEARNING) { bool learning = flags.val & BR_LEARNING; @@ -1520,9 +1548,23 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port, /* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */ if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) { - res = yt921x_isolation_refresh(priv, BIT(port), true); - if (res) - return res; + int res1; + int res2; + + res1 = yt921x_acl_refresh(priv, port, false); + + ret = yt921x_isolation_refresh(priv, BIT(port), true); + if (!ret) { + int res2 = yt921x_acl_refresh(priv, port, true); + + if (!res) + res = res2; + } + if (ret) + return ret; + + res2 = yt921x_acl_refresh(priv, port, true); + yt921x_acl_refresh_extack(priv, port, res1, res2, extack); } return 0; @@ -1597,7 +1639,7 @@ yt921x_dsa_port_bridge_flags(struct dsa_switch *ds, int port, return 0; mutex_lock(&priv->reg_lock); - res = yt921x_bridge_flags(priv, port, flags); + res = yt921x_bridge_flags(priv, port, flags, extack); mutex_unlock(&priv->reg_lock); return res; @@ -1609,13 +1651,25 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); struct device *dev = yt921x_priv_to_device(priv); + int res1; + int res2; int res; if (dsa_is_cpu_port(ds, port)) return; mutex_lock(&priv->reg_lock); + + res1 = yt921x_acl_refresh(priv, port, false); + res = yt921x_bridge_leave(priv, port); + if (res) + goto end; + + res2 = yt921x_acl_refresh(priv, port, true); + yt921x_acl_refresh_extack(priv, port, res1, res2, NULL); + +end: mutex_unlock(&priv->reg_lock); if (res) @@ -1630,6 +1684,8 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); u16 isolation_mask; + int res1; + int res2; int res; if (dsa_is_cpu_port(ds, port)) @@ -1649,7 +1705,14 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, goto end; } + res1 = yt921x_acl_refresh(priv, port, false); + res = yt921x_bridge_join(priv, port); + if (res) + goto end; + + res2 = yt921x_acl_refresh(priv, port, true); + yt921x_acl_refresh_extack(priv, port, res1, res2, extack); end: mutex_unlock(&priv->reg_lock); diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 4085a3c52f20..55876707126e 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -560,6 +560,8 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr) return (addr[4] << 8) | addr[5]; } +void yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp, + u16 *isolation_masks); u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port); #endif diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index b4c531ea9664..00c6f5ab02b3 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1394,6 +1394,86 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) return 0; } +/* To ensure no frames are dropped during isolation update, two passes are + * required for refreshing: trap rules (redirect to software) which may be + * blocked by the new mask, then untrap fully offloadable ones after new mask + * is applied. + * + * Only non-skip_sw rules are refreshed: skip_sw rules cannot be degraded, + * port_bridge_leave() cannot be rejected (return value is void), nor can tc be + * told which rule got invalidated. + * + * Return 1 if any skip_sw rules are now invalidated. + */ +int yt921x_acl_refresh(struct yt921x_priv *priv, int port, bool untrap) +{ + u16 isolation_masks[YT921X_PORT_NUM]; + bool inability = false; + int res; + int ret; + + yt921x_isolation_calc(priv, NULL, isolation_masks); + + ret = 0; + + for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) { + const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid]; + unsigned long dsts; + unsigned long srcs; + unsigned int o; + bool assisting; + + if (!aclblk) + continue; + + for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) { + struct yt921x_acl_rule *aclrule; + unsigned int entid; + + aclrule = aclblk->rules[i]; + if (!aclrule) + continue; + + if (!(aclrule->action[2] & YT921X_ACL_ACTc_FWD_EN) || + (aclrule->action[2] & YT921X_ACL_ACTc_FWD_M) != + YT921X_ACL_ACTc_FWD_REDIR) + continue; + + srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, + aclrule->entries[0].key[1]); + dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M, + aclrule->action[2]); + if (!((srcs | dsts) & BIT(port))) + continue; + + assisting = false; + for_each_set_bit(o, &srcs, YT921X_PORT_NUM) + if (dsts & isolation_masks[o]) { + assisting = true; + break; + } + + if (!aclrule->sw_assisted) { + if (assisting) + inability = true; + continue; + } + + entid = YT921X_ACL_ENT_PER_BLK * blkid + i; + + if (aclrule->sw_assisting != assisting && + assisting != untrap) { + aclrule->sw_assisting = assisting; + res = yt921x_acl_commit(priv, entid, 0); + if (res && !ret) + ret = res; + } + } + } + + return ret ? ret : inability ? 1 : 0; +} + static int yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, unsigned long tag, u16 ports_mask) diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h index 81c29a8eec5a..fb58beec8e13 100644 --- a/drivers/net/dsa/motorcomm/tc.h +++ b/drivers/net/dsa/motorcomm/tc.h @@ -371,6 +371,8 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, int yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port, enum tc_setup_type type, void *type_data); + +int yt921x_acl_refresh(struct yt921x_priv *priv, int port, bool untrap); int yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress); -- 2.53.0