From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390717; b=F1BBA98a5YnXeRPGUi0ordAyO/KbCSbu0XVdEUCJ4VcyCg24SfF/ed8kckuy3fw6n5Nm 4xkt/rgXWYhSfvLrrmyoBfqhdFLW6leaYGOvcpTRgFV1oRcx++N6nLriDO+Ya9bb+dhen QiVqJJiMV31Veiiuk5UNowlM3wuzxeA+25A0FtFDx1wsNh+VNrj1NyeIBzWwrD7G33QWd LOveNHVn3EA/skw2Z95OIwiE/0kvsKOYfYcoq9b/dxk7yJke4tFFGBQ9FsEG0vapNTOCb dTZDVt1Dh9NddYgpgvG4i9tfcDZ5whqXvi/Bd5DnpMG2efQNSC4EcMHCPVImxX9cm3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390717; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=409Dx/4OA8UwRh5ZjDfRKKuNFzLlmxy8Vgfamfr3tBA=; b=5R7bt8n80pa+3H6Z2E8sboviHWIUUUcTlWdOo4ZoXBksnuR+ZnvIEg17gVLkg677gzs4 ahZGaOhYOlduKgxuuujoPHUukNI3R01TOJ/Yya/zrYofxRSs6cPrttwSAbcmHAkH+UCqh XW4JenG0YvYrgpw6hT/a4ikkTnuczXcPDZB2T1TgUaZ1b0qhqYAEGjwfvg3g0CBCx/vWQ yqQ78il9xM1KakGacOzADK32vc6xPgmWiJoqPeWqyySzEBUrzi6K7uMLz/U06NFajj3nG Oz/nui3vr9IpV1JxUiX51/qtDmNb8SdhUuPxoOJb8G6rUooSuUmObgxTXW0Nusq82dw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iLyZf850; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17DD8606A332; Fri, 4 Dec 2026 13:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iLyZf850 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58EDB1F00A16; Fri, 4 Dec 2026 13:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796390716; bh=409Dx/4OA8UwRh5ZjDfRKKuNFzLlmxy8Vgfamfr3tBA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=iLyZf850dlTqp84KWEKJrkObX+X/HH47WT6o8JVo53BLiS8H69ZZURzVwDQhq2aiJ Ujgj9aNJY2pSIdrXDACN44YfEBpH4HJuqpHaIbT+/HDNi04XUtt3QarOLnjv/c2a5g MzZ98WbU+iOFGpcLuf3bTtwC/CUwQNbVdN/3pkDeNfW3eYAOtqv/DTfoV2x0Ndle53 EMVza9zaL5/wf8hn7i609kE4bR2XCEJ//2CQyrw6UyGRQArDsEcWknlbWNSrJkJe2O Bj4b60R0kgmp86wC4gAFjrJc8i3ZT2BbuOqD7/HEb9lMGlt93pgTM2lT6/LqbzDqsM UmwgKlWIMNm4Q== Subject: Re: [PATCH net-next v2 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support From: netdev-bot+sashiko@kernel.org To: m-malladi@ti.com Cc: marco.crivellari@suse.com, kees+treewide@kernel.org, laixiangwu@cmss.chinamobile.com, philippe.schenker@impulsing.ch, haokexin@gmail.com, devnexen@gmail.com, horms@kernel.org, sdf@fomichev.me, john.fastabend@gmail.com, hawk@kernel.org, daniel@iogearbox.net, ast@kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@kernel.org, davem@davemloft.net, andrew+netdev@lunn.ch, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, srk@ti.com, vigneshr@ti.com, rogerq@kernel.org, danishanwar@ti.com Date: Fri, 04 Dec 2026 13:25:14 +0000 Message-ID: <179639071494.3146.718771287839030360@kernel.org> In-Reply-To: <20261203121447.2605779-3-m-malladi@ti.com> References: <20261203121447.2605779-3-m-malladi@ti.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 Thank you for your contribution! Sashiko AI review found 16 potential issue(s) to consider. Critical: 0 · High: 4 · Medium: 9 · Low: 3 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The rule installed in icssg_rxnfc_classifier_update() widens the classifier match instead of narrowing it. - [High] net: ti: icssg-prueth: uncapped multi-flow breaks AM654 shared RX FDQ - [High] net: ti: icssg-prueth: live-channel XSK teardown in prueth_xsk_pool_enable() - [High] net: ti: icssg-prueth: NULL deref of emac->xsk_queues in SR1.0 emac_ndo_open() - [Medium] The commit message says FT3 slot 9 is reserved in HSR offload mode, because classifier 10's OR_EN (RX_CLASS_OR_DUP_PTP = 0x4200)… - [Medium] The series is split so that the previous patch, commit "net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI", does… - [Medium] This patch is the first to steer RX traffic to flows 1..N, via the classifier programming in icssg_rxnfc_classifier_update(). - [Medium] icssg_ft3_program_filter() always sets FT3_START to PRP_PTP_ETHERTYPE_OFFSET (12), whatever the HSR/PRP mode. - [Medium] icssg_ft3_program_filter() writes `(__force u32)ether_type` (the raw __be16 h_proto) into FT3_T (icssg_classifier.c:609-610). - [Medium] net: ti: icssg-prueth: unbalanced enable_irq() from stale flow->irq_disabled - [Medium] net: ti: icssg-prueth: leak of RX NAPIs and IRQs in SR1.0 emac_ndo_open() - [Medium] net: ti: icssg-prueth: icssg_rxnfc_rule_get_all() misses EMSGSIZE on empty buf - [Medium] net: ti: icssg-prueth: ETHTOOL_GRXCLSRLALL sets RX_CLS_LOC_SPECIAL in data - [Low] include/uapi/linux/ethtool.h says that for ETHTOOL_SRXCLSRLINS '@fs specifies the rule to add or update'. - [Low] net: ti: icssg-prueth: emac_get_rx_ring_count() reports 4 rings on SR1 - [Low] net: ti: icssg: guard(mutex) used in >20-line functions in icssg_classifier.c -- net: ti: icssg-prueth: Add ethtool RX flow classification support This adds ethtool get_rxnfc/set_rxnfc support to the ICSSG driver, so EtherType rules can steer received frames to specific RX flows using the FT3 hardware filters. Rules are kept in a per-EMAC list and programmed into FT3 slots and the RX classifier OR_EN registers. They are restored after a firmware restart. > - Add RXNFC rule tracking structures and lifecycle management [Severity: Medium] Is this accurate for this patch? The previous patch, "net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI", already adds these: - struct prueth_rxnfc - the icssg_rxnfc_rule_* prototypes - the call sites: prueth_netdev_init() icssg_rxnfc_rule_init(emac); emac_ndo_open() icssg_rxnfc_rule_restore(emac); prueth_netdev_exit() icssg_rxnfc_rule_cleanup(emac); The definitions only appear in this patch, in icssg_classifier.c. Doesn't that leave the previous commit failing to link, which breaks bisection? > Known limitation: > - ndev->stats.rx_errors/rx_dropped racy with concurrent NAPIs; > per-cpu stats refactor deferred. [Severity: Medium] Can this be deferred when this patch is the one that makes the race reachable? Before this patch, non-SR1 hardware only enabled classifier 0 (icssg_class_default() uses num_classifiers = 1), so only one RX NAPI got traffic. Once a rule steers an EtherType to queue N >= 1, the flow 0 and flow N NAPIs can run at the same time on different CPUs. Both then do plain read-modify-write updates on the shared ndev->stats fields. The rx_dropped and rx_errors error paths do this, and so does the fast path in emac_rx_packet(): ndev->stats.rx_bytes += pkt_len; ndev->stats.rx_packets++; Won't concurrent increments be lost? icssg_ndo_get_stats64() would also report the racy rx_errors and rx_dropped values directly. The limitation as written also leaves out rx_bytes and rx_packets. > diff --git a/drivers/net/ethernet/ti/icssg/icssg_classifier.c b/drivers/net/ethernet/ti/icssg/icssg_classifier.c > index 87a8577093dbb..cf664e93d5c3d 100644 > --- a/drivers/net/ethernet/ti/icssg/icssg_classifier.c > +++ b/drivers/net/ethernet/ti/icssg/icssg_classifier.c [ ... ] > @@ -532,3 +543,430 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice, [ ... ] > +/* Program FT3 filter slot with ethertype pattern */ > +static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice, > + int slot, struct icssg_rxnfc_rule *rule) > +{ > + const struct ethtool_rx_flow_spec *fs = &rule->flow_spec; > + __be16 ether_type; > + > + /* Extract EtherType from flow spec (network byte order) */ > + ether_type = fs->h_u.ether_spec.h_proto; > + > + /* Deactivate filter before programming */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0); > + > + /* EtherType is at byte 12 in standard Ethernet frames */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START), > + PRP_PTP_ETHERTYPE_OFFSET); [Severity: Medium] How do these rules behave in HSR offload mode? icssg_ft3_hsr_configurations() chooses the offset by HSR/PRP version, because HSR-tagged frames carry a 6-byte tag before the payload EtherType: u8 offset = (prueth->hsr_prp_version == PRP_V1) ? PRP_PTP_ETHERTYPE_OFFSET : HSR_PTP_ETHERTYPE_OFFSET; With FT3_START fixed at 12, offset 12 of an HSR-tagged frame holds the HSR EtherType 0x892F. Wouldn't a rule such as proto 0x0800 then never match HSR-tagged IPv4 frames? The driver would still accept it and report it as installed. > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0); > + [ ... ] > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T), > + (__force u32)ether_type); [Severity: Medium] Does this still match on big-endian kernels? The comment above says no conversion is needed because, on LE, the raw h_proto value equals the lower 16 bits of the LE word at the EtherType offset. The HSR filter instead uses the endian-independent constant FT3_PTP_PATTERN (0xF788). TI_ICSSG_PRUETH depends on ARCH_K3 with no !CPU_BIG_ENDIAN restriction. On a big-endian build the raw value of htons(0x0800) is 0x0800, while the hardware expects 0x0008. It looks like no rule would ever match there. Would something like swab16(ntohs(ether_type)) give the same encoding as FT3_PTP_PATTERN on both endiannesses? > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T_MASK), FT3_ETHERTYPE_MASK); [ ... ] > + for (n = 0; n < emac->rx_flow_num; n++) { > + u32 val; > + > + if (n == 0) { > + /* Classifier 0: RMW to preserve default BC|DA_P bits > + * set by icssg_class_default(). > + */ > + regmap_read(miig_rt, > + RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val); > + val &= ~RX_CLASS_FT_FT3_MATCH_MASK; > + val |= or_table[n]; > + } else if (or_table[n]) { > + /* Classifiers 1..N with active rules: add BC|DA_P so > + * only host-addressed frames are steered. > + */ > + val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n]; [Severity: High] Can this widen the match for classifier N instead of narrowing it? icssg_class_disable() leaves classifiers 1..15 with AND_EN = 0 and the select type set to OR: /* AND_EN = 0 */ rx_class_set_and(miig_rt, slice, n, 0); ... /* set CFG1 to OR */ rx_class_sel_set_type(miig_rt, slice, n, RX_CLASS_SEL_TYPE_OR); Nothing in this patch changes AND_EN or the select type for those classifiers. The existing code treats OR_EN as a disjunction: icssg_class_default() { ... /* match on Broadcast or MAC_PRU address */ data = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P; ... } With OR_EN = BC | DA_P | FT3_MATCH(slot), wouldn't classifier N fire on broadcast, or own MAC, or the EtherType? That covers all host traffic plus foreign-DA frames of that EtherType. It looks like the case the else branch below warns about ("it would steal all host traffic away from classifier 0"), and it would happen as soon as one rule targets queue N >= 1. For a rule targeting queue 0, the RMW path ORs the FT3 bit into classifier 0's OR_EN. Would frames of that EtherType then reach the host whatever their destination MAC? Either way, the hardware steering would not match what get_rxnfc reports. > + } else { [ ... ] > +void icssg_rxnfc_rule_restore(struct prueth_emac *emac) > +{ > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + struct icssg_rxnfc_rule *rule; > + > + if (slice < 0) > + return; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + list_for_each_entry(rule, &emac->rxnfc.rules, list) > + icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule); [Severity: Low] Documentation/process/maintainer-netdev.rst discourages guard() in any function longer than 20 lines, considers scoped_guard() more readable, and still weakly prefers plain lock/unlock. These functions all take rxnfc_lock with guard(mutex) and are well past that length: - icssg_rxnfc_rule_add() - icssg_rxnfc_rule_cleanup() - icssg_rxnfc_rule_del() - icssg_rxnfc_rule_get_all() This also came up in the v1 review, where the reply was that the locking would go back to explicit mutex_lock()/mutex_unlock(). Was that dropped from v2 by accident? [Severity: Medium] This isn't introduced here. It comes from the previous patch in the series, but it sits on the open path that now calls icssg_rxnfc_rule_restore(). Can flow->irq_disabled survive an ifdown/ifup cycle? With RX coalescing enabled (rx_pace_timeout_ns != 0), prueth_rx_irq() sets flow->irq_disabled = true and disables the IRQ. icssg_napi_rx_poll() leaves it set while flow->rx_hrtimer is armed. If emac_ndo_stop() runs in that window: prueth_destroy_rxq() hrtimer_cancel(&flow->rx_hrtimer); prueth_ndev_del_rx_napi() free_irq() Neither of these clears flow->irq_disabled, and prueth_init_rx_chns() doesn't reset it on the next emac_ndo_open() either. request_irq() in prueth_ndev_add_rx_napi() then installs the handler with the line enabled, and prueth_create_rxq() does: if (flow->irq_disabled) { flow->irq_disabled = false; enable_irq(flow->irq); } Wouldn't that hit the "Unbalanced enable for IRQ" WARN in __enable_irq()? Should irq_disabled be reset when the flows are initialized in prueth_init_rx_chns(), or cleared on the stop path once the hrtimer has been cancelled? [Severity: Medium] Can this re-arm a user rule in FT3 slot 9 after HSR offload is enabled? The slot 9 reservation is only checked at insert time, in allocate_ft3_slot() and in the explicit location check in icssg_rxnfc_rule_add(). A rule placed in slot 9 before HSR offload is enabled stays in the list. That can be loc 9, or an auto-allocated slot once slots 0-8 are in use. When both ports then join an HSR device: prueth_hsr_port_link() prueth->is_hsr_offload_mode = true; icssg_change_mode() prueth_emac_restart() prueth_emac_common_start() icssg_ft3_hsr_configurations() icssg_rxnfc_rule_restore(emac0) icssg_rxnfc_rule_restore(emac1) icssg_ft3_hsr_configurations() enables classifier 10 with OR_EN bits 9 and 14. icssg_rxnfc_rule_restore() then reprograms slot 9 without checking is_hsr_offload_mode. emac_ndo_open() does the same in HSR mode. Wouldn't classifier 10 then fire on the user's EtherType? The commit message says reserving slot 9 is meant to prevent exactly that. > + > + icssg_rxnfc_classifier_update(emac); > +} [ ... ] > + /* Check for duplicate flow spec */ > + if (rule_exists(emac, fs)) > + return -EEXIST; > + [ ... ] > + if (fs->location != RX_CLS_LOC_ANY) { > + ft3_slot = fs->location; > + if (emac->rxnfc.ft3_slots_used & BIT(ft3_slot)) > + return -EBUSY; [Severity: Low] Should ETHTOOL_SRXCLSRLINS be able to update an existing rule here? include/uapi/linux/ethtool.h documents it as: For %ETHTOOL_SRXCLSRLINS, @fs specifies the rule to add or update. rule_exists() returns -EEXIST for any rule with the same EtherType, and an occupied explicit location returns -EBUSY. So re-running a command such as: ethtool -N ethX flow-type ether proto 0x88b5 action 2 loc 3 to move an existing rule to another queue always fails. The rule has to be deleted and re-inserted, and matching traffic falls back to the default queue in between. > + emac->rxnfc.ft3_slots_used |= BIT(ft3_slot); [ ... ] > diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c > --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c > +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c > @@ -302,6 +302,63 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue, > return 0; > } > > +static u32 emac_get_rx_ring_count(struct net_device *ndev) > +{ > + struct prueth_emac *emac = netdev_priv(ndev); > + > + return emac->rx_flow_num; > +} > + > +static int emac_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info, > + u32 *rule_locs) > +{ > + struct prueth_emac *emac = netdev_priv(ndev); > + int ret = 0; > + > + if (emac->is_sr1) [Severity: High] Not part of this patch, but it breaks SR1, which this patch otherwise keeps away from rxnfc. The previous patch adds this to the SR1 emac_ndo_open() in icssg_prueth_sr1.c: bitmap_zero(emac->xsk_queues, PRUETH_MAX_RX_FLOWS); icssg_prueth.c allocates emac->xsk_queues in prueth_netdev_init() with devm_bitmap_zalloc(). The SR1 prueth_netdev_init() never does, so the pointer is still NULL from alloc_etherdev_mq(). Doesn't that oops on every SR1 interface bring-up? Should SR1 allocate the bitmap too, or skip the XSK bookkeeping if it isn't used there? [Severity: Medium] This is outside this patch, in the SR1 emac_ndo_open() added by the previous patch. It follows from the same SR1 rx_flow_num handling. emac_ndo_open() in icssg_prueth_sr1.c sets emac->rx_flow_num to PRUETH_MAX_RX_FLOWS_SR1 and then calls prueth_ndev_add_rx_napi(). That function does netif_napi_add(), hrtimer_setup() and request_irq() for each of the rx_flow_num flows. The error unwind only undoes one of them: free_rx_irq: prueth_ndev_del_rx_napi(emac, 1); emac_ndo_stop(), by contrast, passes PRUETH_MAX_RX_FLOWS_SR1. Suppose request_threaded_irq(), prueth_emac_start() or a later step fails. Don't flows 1..3 then keep their IRQ handlers registered and their NAPI instances on ndev->napi_list? The next open would add the same napi_rx structures again. Device removal could also run with handlers still pointing into emac->rx_chns.flows[]. Should the unwind use emac->rx_flow_num to match the add? > + return -EOPNOTSUPP; > + > + switch (info->cmd) { > + case ETHTOOL_GRXCLSRLCNT: > + info->rule_cnt = emac->rxnfc.rxnfc_rule_count; > + info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL; > + break; > + case ETHTOOL_GRXCLSRULE: > + ret = icssg_rxnfc_rule_get(emac, info->fs.location, &info->fs); > + break; > + case ETHTOOL_GRXCLSRLALL: { > + u32 rule_cnt = 0; > + > + info->data = ICSSG_NUM_FT3_SLOTS | RX_CLS_LOC_SPECIAL; > + ret = icssg_rxnfc_rule_get_all(emac, rule_locs, > + info->rule_cnt, &rule_cnt); > + info->rule_cnt = rule_cnt; > + break; > + } > + default: > + return -EOPNOTSUPP; > + } > + > + return ret; > +} > + > +static int emac_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info) > +{ > + struct prueth_emac *emac = netdev_priv(ndev); > + > + if (emac->is_sr1) > + return -EOPNOTSUPP; > + > + switch (info->cmd) { > + case ETHTOOL_SRXCLSRLINS: > + return icssg_rxnfc_rule_add(emac, info); > + case ETHTOOL_SRXCLSRLDEL: > + return icssg_rxnfc_rule_del(emac, info->fs.location); > + default: > + return -EOPNOTSUPP; > + } > +} > + > const struct ethtool_ops icssg_ethtool_ops = { > .get_drvinfo = emac_get_drvinfo, > .get_msglevel = emac_get_msglevel, [Severity: Medium] include/uapi/linux/ethtool.h only defines RX_CLS_LOC_SPECIAL as a flag in @data for ETHTOOL_GRXCLSRLCNT. For ETHTOOL_GRXCLSRLALL, @data on return is just the size of the rule table. With the flag ORed in here, ETHTOOL_GRXCLSRLALL reports a table size of 0x80000010 instead of 16. Userspace that takes @data from this command as the table size gets a bogus value, for example when it sizes a bitmap of rule locations from it. Other drivers that support special locations, such as fbnic, set the flag only for ETHTOOL_GRXCLSRLCNT. The v2 changelog says this was added to both cases deliberately. Was there a reason for doing it in ETHTOOL_GRXCLSRLALL, or can this be plain ICSSG_NUM_FT3_SLOTS? [Severity: Low] Should this check emac->is_sr1, like emac_get_rxnfc() and emac_set_rxnfc() do? On SR1, icssg_prueth_sr1.c sets emac->rx_flow_num to PRUETH_MAX_RX_FLOWS_SR1 (4) because its UDMA RX channel has four flows. However, the SR1 netdev has a single RX queue, allocated by alloc_etherdev_mq(sizeof(*emac), 1). Only PRUETH_RX_FLOW_DATA_SR1 is prepared and enabled for data, and emac_get_channels() reports max_rx = 1. ETHTOOL_GRXRINGS would then report 4 RX rings on SR1, which disagrees with the rest of the ethtool interface. Since rxnfc isn't supported on SR1 anyway, would returning 1 there be more accurate? [ ... ] > @@ -532,3 +543,430 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice, > } > } > EXPORT_SYMBOL_GPL(icssg_ft3_hsr_configurations); > + > +/* RX Flow Classification (ethtool) rule management */ > + > +/* Allocate free FT3 slot, avoiding reserved slots */ > +static int allocate_ft3_slot(struct prueth_emac *emac) > +{ > + u16 used = emac->rxnfc.ft3_slots_used | ICSSG_FT3_RESERVED_SLOTS; > + int slot; > + > + /* Slot 9 is implicitly used by the HSR PTP duplicate classifier's OR_EN. > + * Prevent user rules from triggering it accidentally. > + */ > + if (emac->prueth->is_hsr_offload_mode) > + used |= BIT(FT3_HSR_OR_SLOT); > + > + for (slot = 0; slot < ICSSG_NUM_FT3_SLOTS; slot++) { > + if (!(used & BIT(slot))) { > + emac->rxnfc.ft3_slots_used |= BIT(slot); > + return slot; > + } > + } > + return -ENOSPC; > +} > + > +/* Free allocated FT3 slot */ > +static void free_ft3_slot(struct prueth_emac *emac, int slot) > +{ > + emac->rxnfc.ft3_slots_used &= ~BIT(slot); > +} > + > +/* Program FT3 filter slot with ethertype pattern */ > +static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice, > + int slot, struct icssg_rxnfc_rule *rule) > +{ > + const struct ethtool_rx_flow_spec *fs = &rule->flow_spec; > + __be16 ether_type; > + > + /* Extract EtherType from flow spec (network byte order) */ > + ether_type = fs->h_u.ether_spec.h_proto; > + > + /* Deactivate filter before programming */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0); > + > + /* EtherType is at byte 12 in standard Ethernet frames */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START), > + PRP_PTP_ETHERTYPE_OFFSET); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0); > + > + /* FT3 compares a 32-bit LE word at FT3_START. EtherType occupies the > + * lower 16 bits of that word. FT3_T_MASK=0xFFFF0000 masks the upper > + * 16 bits (payload bytes), so only the lower 16 bits are compared. > + * > + * h_proto is __be16 (network byte order). On LE the raw integer value > + * equals the lower 16 bits of the LE 32-bit word at the EtherType > + * offset in the frame — e.g. IPv4 0x0800 BE → h_proto = 0x0008 on LE, > + * which is exactly what FT3 sees in the lower 16 bits of the word at > + * byte 12. No conversion needed; using be16_to_cpu() here would invert > + * the byte order and break the match. > + * Reference: FT3_PTP_PATTERN = 0xF788 = htons(0x88F7) = raw h_proto value. > + */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T), > + (__force u32)ether_type); > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T_MASK), FT3_ETHERTYPE_MASK); > + > + /* Enable filter: register-equal mode (same value as FT3_VLAN_MODE_BOTH) */ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), > + FT3_VLAN_MODE_BOTH); > +} > + > +/* Disable FT3 filter slot */ > +static void icssg_ft3_disable_filter(struct regmap *miig_rt, int slice, int slot) > +{ > + regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0); > +} > + > +/* Update RX classifiers for all active FT3 rules. > + * Classifier N maps to RX flow N (firmware routes classifier-N hits to [Severity: High] This is in the previous patch. This patch is what makes RX flows 1..N carry traffic, so it seems worth raising here. What keeps rx_flow_num at 1 on AM654 SR2.0? The multi-flow patch says AM654 multi-flow support is deferred, but emac_get_channels() still sets ch->max_rx = ICSSG_MAX_RFLOWS for every non-SR1 device, including ti,am654-icssg-prueth. AM654 uses UDMAP, where k3_udma_glue sets rx_chn->single_fdq and all flows share flow 0's free descriptor ring. After ethtool -L with rx > 1 there, a few things look wrong: - prueth_init_rx_chns() sizes the shared FDQ to PRUETH_MAX_RX_DESC, and each flow then pushes PRUETH_MAX_RX_DESC buffers into it, so the ring overflows while flow 1 is being prepared on open. - k3_udma_glue_reset_rx_chn() skips the FDQ drain for flow_num != 0 on a single_fdq channel. The prueth_create_rxqs() error unwind runs from the highest flow down, so flows[i].pg_pool for i > 0 is destroyed before flow 0 drains their buffers from the shared FDQ. prueth_rx_cleanup() then sees a NULL pg_pool for those buffers and the pages leak. - prueth_destroy_rxqs() goes from flow 0 up. The shared FDQ is reset and flows[0].pg_pool destroyed while flows 1..N still have NAPI enabled and undrained completion rings. - emac_rx_packet() syncs and recycles against rx_flow->pg_pool, but with a shared FDQ the buffer can come from another flow's pool, i.e. rx_chn->flows[swdata->flow_id].pg_pool. - NAPIs for different flows refill the same FDQ ring concurrently with no serialization. Should max_rx be capped to 1 on AM654 until the shared FDQ case is handled? > + * UDMA flow rx_flow_id_base + N). Build a per-classifier OR table so > + * that each target queue gets its own classifier entry. > + */ > +static void icssg_rxnfc_classifier_update(struct prueth_emac *emac) > +{ > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + u32 or_table[ICSSG_NUM_CLASSIFIERS] = { }; > + struct icssg_rxnfc_rule *rule; > + int n; > + > + if (slice < 0) > + return; > + > + /* Build per-classifier OR table: classifier index = target queue index */ > + list_for_each_entry(rule, &emac->rxnfc.rules, list) { > + int cls = rule->queue_index; > + > + if (cls < emac->rx_flow_num) > + or_table[cls] |= RX_CLASS_FT_FT3_MATCH(rule->ft3_slot); > + } > + > + /* Update OR tables for classifiers 0..rx_flow_num-1 using RMW so that > + * non-FT3 bits (e.g. RX_CLASS_FT_BC | RX_CLASS_FT_DA_P set by > + * icssg_class_default()) are preserved. Only the FT3-match field > + * (RX_CLASS_FT_FT3_MATCH_MASK) is replaced. > + * > + * Classifiers 1..N start with OR_EN=0 after icssg_class_default() > + * (non-SR1 sets num_classifiers=1, leaving them zeroed). Add BC|DA_P > + * when they carry FT3 rules so that only host-addressed frames are > + * steered — without it the classifier is a promiscuous EtherType match. > + * > + * Use RX_CLASS_N_REG (rx_class_base), NOT RX_CLASS_OR_REG > + * (rx_class_or_base = rx_class_base + 4): the latter lands on AND_EN > + * of classifier n+1 instead of OR_EN of classifier n. > + */ > + for (n = 0; n < emac->rx_flow_num; n++) { > + u32 val; > + > + if (n == 0) { > + /* Classifier 0: RMW to preserve default BC|DA_P bits > + * set by icssg_class_default(). > + */ > + regmap_read(miig_rt, > + RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val); > + val &= ~RX_CLASS_FT_FT3_MATCH_MASK; > + val |= or_table[n]; > + } else if (or_table[n]) { > + /* Classifiers 1..N with active rules: add BC|DA_P so > + * only host-addressed frames are steered. > + */ > + val = RX_CLASS_FT_BC | RX_CLASS_FT_DA_P | or_table[n]; > + } else { > + /* Classifiers 1..N with no rules: clear entirely. > + * Must not leave BC|DA_P here — it would steal all > + * host traffic away from classifier 0. > + */ > + val = 0; > + } > + regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val); > + } > +} > + > +/* Validate rule parameters */ > +static int validate_rule(struct prueth_emac *emac, > + struct ethtool_rx_flow_spec *fs) > +{ > + /* Only ETHER_FLOW supported; reject extension flags */ > + if (fs->flow_type != ETHER_FLOW) > + return -EOPNOTSUPP; > + > + /* Only exact EtherType match supported — reject partial proto mask, > + * non-zero MAC address masks, and flow extension flags. > + */ > + if (fs->m_u.ether_spec.h_proto != htons(0xFFFF)) > + return -EOPNOTSUPP; > + if (!is_zero_ether_addr(fs->m_u.ether_spec.h_dest) || > + !is_zero_ether_addr(fs->m_u.ether_spec.h_source)) > + return -EOPNOTSUPP; > + > + /* Check RX queue is valid */ > + if (fs->ring_cookie >= emac->rx_flow_num) [Severity: High] This is in prueth_xsk_pool_enable() and prueth_xsk_pool_disable() from the previous patch. A rule steering traffic to a queue is the natural way to feed an AF_XDP socket bound to it, so this patch makes that path more likely to be used. When the interface is running, both functions call icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE) and then prueth_destroy_rxq(emac, queue_id). That pops the flow's completion ring, calls k3_udma_glue_reset_rx_chn() for the flow and destroys flow->pg_pool. The shared UDMA RX channel is never disabled with k3_udma_glue_disable_rx_chn() and keeps running for the other flows. Can the DMA engine still hold descriptors it prefetched from this flow's FDQ at that point? If so, wouldn't the page_pool pages or XSK buffers be released or unmapped while the hardware can still write to them? On single_fdq UDMAP platforms, resetting flow 0 also resets the FDQ shared by all flows. Resetting queue_id > 0 doesn't drain the FDQ at all. Is there a supported way to quiesce a single flow on this hardware, or does this need the full RX channel teardown done on the stop path? > + return -EINVAL; > + > + return 0; > +} > + > +/* Check if identical rule already exists */ > +static bool rule_exists(struct prueth_emac *emac, > + struct ethtool_rx_flow_spec *fs) > +{ > + struct icssg_rxnfc_rule *rule; > + > + list_for_each_entry(rule, &emac->rxnfc.rules, list) { > + if (rule->flow_spec.flow_type == fs->flow_type && > + rule->flow_spec.h_u.ether_spec.h_proto == > + fs->h_u.ether_spec.h_proto) { > + return true; > + } > + } > + return false; > +} > + > +/* Initialize RX flow classification */ > +void icssg_rxnfc_rule_init(struct prueth_emac *emac) > +{ > + INIT_LIST_HEAD(&emac->rxnfc.rules); > + mutex_init(&emac->rxnfc.rxnfc_lock); > + emac->rxnfc.rxnfc_rule_count = 0; > + emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS; /* Mark slot 14 reserved */ > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_init); > + > +/* Restore RX flow classification hardware state from the in-memory rule list. > + * Call after icssg_class_default() resets the classifier registers on open or > + * after firmware restart so that existing rules take effect again. > + */ > +void icssg_rxnfc_rule_restore(struct prueth_emac *emac) > +{ > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + struct icssg_rxnfc_rule *rule; > + > + if (slice < 0) > + return; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + list_for_each_entry(rule, &emac->rxnfc.rules, list) > + icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule); > + > + icssg_rxnfc_classifier_update(emac); > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_restore); > + > +/* Cleanup RX flow classification */ > +void icssg_rxnfc_rule_cleanup(struct prueth_emac *emac) > +{ > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + struct icssg_rxnfc_rule *rule, *tmp; > + int n; > + > + if (slice < 0) > + return; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + /* Disable all active FT3 filters */ > + list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) { > + icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot); > + free_ft3_slot(emac, rule->ft3_slot); > + list_del(&rule->list); > + kfree(rule); > + } > + > + emac->rxnfc.rxnfc_rule_count = 0; > + emac->rxnfc.ft3_slots_used = ICSSG_FT3_RESERVED_SLOTS; > + > + /* Clear FT3 bits from classifiers 0..rx_flow_num-1. Use RMW for > + * classifier 0 to preserve its BC|DA_P default-accept bits; for > + * classifiers 1..N (which had BC|DA_P added by classifier_update) > + * clear everything since no rules remain to steer traffic there. > + */ > + for (n = 0; n < emac->rx_flow_num; n++) { > + u32 val; > + > + if (n == 0) { > + regmap_read(miig_rt, > + RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), &val); > + val &= ~RX_CLASS_FT_FT3_MATCH_MASK; > + } else { > + val = 0; > + } > + regmap_write(miig_rt, RX_CLASS_N_REG(slice, n, RX_CLASS_OR_EN), val); > + } > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_cleanup); > + > +/* Add a new RX flow classification rule */ > +int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info) > +{ > + struct ethtool_rx_flow_spec *fs = &info->fs; > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + struct icssg_rxnfc_rule *rule; > + int ft3_slot; > + int ret; > + > + if (slice < 0) > + return -EINVAL; > + > + /* Validate rule parameters */ > + ret = validate_rule(emac, fs); > + if (ret) > + return ret; > + > + /* Validate explicit location: reject special specifiers, out-of-range > + * values, and the reserved slot 14 used by HSR/PRP. > + * Bound against ICSSG_NUM_FT3_SLOTS (16), not ICSSG_RXNFC_MAX_RULES > + * (15), so that slot 15 is reachable as an explicit location. > + */ > + if (fs->location != RX_CLS_LOC_ANY) { > + if (fs->location >= ICSSG_NUM_FT3_SLOTS || > + BIT(fs->location) & ICSSG_FT3_RESERVED_SLOTS || > + (emac->prueth->is_hsr_offload_mode && > + fs->location == FT3_HSR_OR_SLOT)) > + return -EINVAL; > + } > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + /* Check max rules */ > + if (emac->rxnfc.rxnfc_rule_count >= ICSSG_RXNFC_MAX_RULES) > + return -ENOSPC; > + > + /* Check for duplicate flow spec */ > + if (rule_exists(emac, fs)) > + return -EEXIST; > + > + /* Allocate FT3 slot. For explicit locations, the location IS the FT3 > + * slot — this keeps location and slot aligned so rule_del operates on > + * the correct hardware slot. For RX_CLS_LOC_ANY, auto-allocate the > + * lowest free slot and assign it as the location. > + */ > + if (fs->location != RX_CLS_LOC_ANY) { > + ft3_slot = fs->location; > + if (emac->rxnfc.ft3_slots_used & BIT(ft3_slot)) > + return -EBUSY; > + emac->rxnfc.ft3_slots_used |= BIT(ft3_slot); > + } else { > + ft3_slot = allocate_ft3_slot(emac); > + if (ft3_slot < 0) > + return -ENOSPC; > + fs->location = ft3_slot; > + } > + > + /* Allocate rule structure */ > + rule = kzalloc(sizeof(*rule), GFP_KERNEL); > + if (!rule) { > + free_ft3_slot(emac, ft3_slot); > + return -ENOMEM; > + } > + > + /* Program FT3 hardware */ > + rule->flow_spec = *fs; > + rule->ft3_slot = ft3_slot; > + rule->queue_index = fs->ring_cookie; > + rule->location = fs->location; > + > + icssg_ft3_program_filter(miig_rt, slice, ft3_slot, rule); > + > + /* Add to rule list */ > + list_add(&rule->list, &emac->rxnfc.rules); > + emac->rxnfc.rxnfc_rule_count++; > + > + /* Update classifier */ > + icssg_rxnfc_classifier_update(emac); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_add); > + > +/* Delete a RX flow classification rule */ > +int icssg_rxnfc_rule_del(struct prueth_emac *emac, u32 location) > +{ > + struct prueth *prueth = emac->prueth; > + struct regmap *miig_rt = prueth->miig_rt; > + int slice = prueth_emac_slice(emac); > + struct icssg_rxnfc_rule *rule, *tmp; > + int ret = -ENOENT; > + > + if (slice < 0) > + return -EINVAL; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + list_for_each_entry_safe(rule, tmp, &emac->rxnfc.rules, list) { > + if (rule->location == location) { > + icssg_ft3_disable_filter(miig_rt, slice, rule->ft3_slot); > + free_ft3_slot(emac, rule->ft3_slot); > + list_del(&rule->list); > + kfree(rule); > + emac->rxnfc.rxnfc_rule_count--; > + icssg_rxnfc_classifier_update(emac); > + ret = 0; > + break; > + } > + } > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_del); > + > +/* Get single RX flow classification rule */ > +int icssg_rxnfc_rule_get(struct prueth_emac *emac, u32 location, > + struct ethtool_rx_flow_spec *fs) > +{ > + struct icssg_rxnfc_rule *rule; > + int ret = -ENOENT; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + list_for_each_entry(rule, &emac->rxnfc.rules, list) { > + if (rule->location == location) { > + *fs = rule->flow_spec; > + ret = 0; > + break; > + } > + } > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get); > + > +/* Get all RX flow classification rules */ > +int icssg_rxnfc_rule_get_all(struct prueth_emac *emac, u32 *rule_locs, > + u32 rule_locs_capacity, u32 *rule_cnt) > +{ > + struct icssg_rxnfc_rule *rule; > + u32 count = 0; > + int ret = 0; > + > + guard(mutex)(&emac->rxnfc.rxnfc_lock); > + > + list_for_each_entry(rule, &emac->rxnfc.rules, list) { > + if (!rule_locs) { > + /* Caller passed rule_cnt=0: just count active rules */ > + count++; > + continue; > + } > + if (count >= rule_locs_capacity) { > + ret = -EMSGSIZE; > + break; > + } > + rule_locs[count++] = rule->location; > + } > + > + *rule_cnt = count; > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get_all); [Severity: Medium] When userspace issues ETHTOOL_GRXCLSRLALL with rule_cnt == 0, ethtool_get_rxnfc() doesn't allocate rule_buf. It calls get_rxnfc() with rule_locs == NULL. With one or more rules installed, this branch counts them and skips the capacity check. icssg_rxnfc_rule_get_all() then returns 0, and emac_get_rxnfc() sets info->rule_cnt to the number of rules. The caller is told the request succeeded with N rule locations, but none were written. Other drivers return -EMSGSIZE once the rule count exceeds the supplied rule_cnt, including when it is zero. The comment describes ETHTOOL_GRXCLSRLCNT behaviour, but this helper is only called for ETHTOOL_GRXCLSRLALL, and emac_get_rxnfc() answers the count query itself. Can the NULL special case be dropped, so that the capacity check also covers rule_cnt == 0? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203121447.2605779-1-m-malladi%40ti.com