Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: michael.dege@renesas.com
Cc: Jakub Kicinski <kuba@kernel.org>,
	yoshihiro.shimoda.uh@renesas.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	niklas.soderlund@ragnatech.se, paul@pbarker.dev,
	richardcochran@gmail.com, netdev@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v5 14/14] net: renesas: rswitch: add vlan aware switching
Date: Mon, 25 May 2026 13:41:22 -0700	[thread overview]
Message-ID: <20260525204122.2471553-1-kuba@kernel.org> (raw)
In-Reply-To: <20260522-rswitch_add_vlans-v5-14-53589d944a9f@renesas.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
Subject: net: renesas: rswitch: add vlan aware switching

This patch adds VLAN support to the L2 HW bridge for the Renesas switch.
It implements the standard switchdev callbacks for configuring STP state,
aging time, and VLAN filtering. The implementation works around hardware
limitations by keeping all ports in a default VLAN.

> diff --git a/drivers/net/ethernet/renesas/rswitch_l2.c b/drivers/net/ethernet/renesas/rswitch_l2.c
> --- a/drivers/net/ethernet/renesas/rswitch_l2.c
> +++ b/drivers/net/ethernet/renesas/rswitch_l2.c
[ ... ]
> +static void rswitch_update_vlan_filtering(struct rswitch_private *priv,
> +					  bool vlan_filtering)
> +{
> +	if (vlan_filtering)
> +		rswitch_modify(priv->addr, FWPC0(AGENT_INDEX_GWCA),
> +			       0, FWPC0_VLANSA | FWPC0_VLANRU);
> +	else
> +		rswitch_modify(priv->addr, FWPC0(AGENT_INDEX_GWCA),
> +			       FWPC0_VLANSA | FWPC0_VLANRU, 0);
> +}

[Severity: Medium]
Does this properly synchronize the VLAN filtering state to the physical
switch ports? This seems to update the FWPC0 registers only for the CPU
port (AGENT_INDEX_GWCA) without iterating over the external physical
ports, which might leave the hardware in an inconsistent state.

[ ... ]
> +static int rswitch_handle_port_attr_set(struct net_device *ndev,
> +					struct notifier_block *nb,
> +					struct switchdev_notifier_port_attr_info *info)
> +{
[ ... ]
> +	switch (attr->id) {
> +	case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
> +		err = rswitch_port_update_stp_state(ndev, attr->u.stp_state);
> +
> +		break;
[ ... ]
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	if (err < 0)
> +		return err;
> +
> +	info->handled = true;
> +
> +	return NOTIFY_DONE;
> +}

[Severity: High]
Could this block switchdev configurations for other network devices on the
system? 

The switchdev notifiers are broadcast globally, and without a check
verifying the target ndev belongs to this driver, the default case here
returns -EOPNOTSUPP for unrelated devices. When passed to
notifier_from_errno(), this stops the global notifier chain.

[ ... ]
> +static int rswitch_gwca_set_vlan_tag(struct rswitch_private *priv,
> +				     struct switchdev_obj_port_vlan *p_vlan,
> +				     bool delete)
> +{
> +	u32 vem_val;
> +	int err;
> +
> +	err = rswitch_gwca_change_mode(priv, GWMC_OPC_CONFIG);

[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a self-
deadlock in rswitch_gwca_change_mode() when trying to enable the agent
clock:

drivers/net/ethernet/renesas/rswitch_main.c:rswitch_gwca_change_mode() {
        if (!rswitch_agent_clock_is_enabled(priv->addr, priv->gwca.index)) {
                spin_lock(&priv->agent_lock);
                rswitch_agent_clock_ctrl(priv->addr, priv->gwca.index, 1);
                spin_lock(&priv->agent_lock);
        }
...
}

Will the second spin_lock() cause a deadlock on the same CPU?

> +	if (err < 0)
> +		return err;

[ ... ]
> +static int rswitch_port_obj_do_add_gwca(struct net_device *ndev,
> +					struct rswitch_private *priv,
> +					struct switchdev_obj_port_vlan *p_vlan)
> +{
> +	int err;
> +
> +	if (!(p_vlan->flags & BRIDGE_VLAN_INFO_BRENTRY))
> +		return NOTIFY_DONE;
> +
> +	/* Set Rswitch VLAN mode */
> +	iowrite32(br_vlan_enabled(ndev) ? FIELD_PREP(FWGC_SVM, C_TAG) : 0, priv->addr + FWGC);

[Severity: High]
Is it safe to pass ndev directly to br_vlan_enabled() here? 

Because the notifier runs globally and routes non-rdev devices into this
function, ndev might be an unrelated physical port rather than a bridge
master. This seems like it could lead to out-of-bounds memory reads when
the function dereferences the foreign driver's private data.

[ ... ]
> +static int rswitch_port_obj_do_del(struct net_device *ndev,
> +				   struct switchdev_obj_port_vlan *p_vlan)
> +{
> +	struct rswitch_device *rdev = netdev_priv(ndev);
> +	struct rswitch_private *priv = rdev->priv;
> +	struct rswitch_etha *etha = rdev->etha;
> +	int err;
> +
> +	err = rswitch_port_set_vlan_tag(etha, p_vlan, true);
> +	if (err < 0)
> +		return err;
> +
> +	rswitch_modify(priv->addr, FWPC0(etha->index), FWPC0_VLANSA | FWPC0_VLANRU, 0);
> +	rswitch_modify(priv->addr, FWPC2(AGENT_INDEX_GWCA), 0,
> +		       FIELD_PREP(FWPC2_LTWFW, BIT(etha->index)));
> +	rswitch_modify(priv->addr, FWPC2(rdev->port),
> +		       0, FIELD_PREP(FWPC2_LTWFW, GENMASK(RSWITCH_NUM_AGENTS - 1, 0)));

[Severity: High]
Does this unconditionally break connectivity for all remaining active VLANs
on this port? 

When handling a VLAN deletion event, clearing these forwarding masks happens
regardless of whether the port is still a member of other VLANs.

> +
> +	return rswitch_erase_vlan_table(priv, p_vlan->vid, etha->index);
> +}

[ ... ]
>  static int rswitch_switchdev_blocking_event(struct notifier_block *nb,
> -					    unsigned long event, void *ptr)
> +					    unsigned long event,
> +					    void *ptr)
>  {
>  	struct net_device *ndev = switchdev_notifier_info_to_dev(ptr);
> -	int ret;
>  
>  	switch (event) {
>  	case SWITCHDEV_PORT_OBJ_ADD:
> -		return -EOPNOTSUPP;
> +		err = rswitch_handle_port_obj_add(ndev, nb, ptr);
> +
> +		return notifier_from_errno(err);
>  	case SWITCHDEV_PORT_OBJ_DEL:
> -		return -EOPNOTSUPP;
> +		err = rswitch_handle_port_obj_del(ndev, nb, ptr);
> +
> +		return notifier_from_errno(err);
>  	case SWITCHDEV_PORT_ATTR_SET:
> -		ret = switchdev_handle_port_attr_set(ndev, ptr,
> -						     is_rdev,
> -						     rswitch_port_attr_set);
> -		break;
> -	default:
> -		if (is_rdev(ndev))
> -			return -EOPNOTSUPP;
> -		return NOTIFY_DONE;
> +		err = rswitch_handle_port_attr_set(ndev, nb, ptr);
> +
> +		return notifier_from_errno(err);
>  	}

[Severity: High]
Could removing the is_rdev check from the attribute and object handler
paths cause the driver to wrongly modify its own MMIO registers based on
events meant for other hardware? 

Since switchdev_handle_port_attr_set previously guarded against unrelated
devices, removing it exposes the handlers to global broadcast events.

      reply	other threads:[~2026-05-25 20:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22 12:12 [net-next PATCH v5 00/14] net: renesas: rswitch: R-Car S4 add VLAN aware switching Michael Dege
2026-05-22 12:12 ` [PATCH net-next v5 01/14] net: renesas: rswitch: improve port change mode functions Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 02/14] net: renesas: rswitch: use device instead of net_device Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 03/14] net: renesas: rswitch: fix FWPC2 register access macros Michael Dege
2026-05-22 12:12 ` [PATCH net-next v5 04/14] net: renesas: rswitch: add register definitions for vlan support Michael Dege
2026-05-22 12:12 ` [PATCH net-next v5 05/14] net: renesas: rswitch: add exception path for packets with unknown dst MAC Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 06/14] net: renesas: rswitch: add forwarding rules for gwca Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 07/14] net: renesas: rswitch: make helper functions available to whole driver Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 08/14] net: renesas: rswitch: add locking for agent clock control Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 09/14] net: renesas: rswitch: add basic vlan init to rswitch_fwd_init Michael Dege
2026-05-22 12:12 ` [PATCH net-next v5 10/14] net: renesas: rswitch: update port HW init Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 11/14] net: renesas: rswitch: clean up is_rdev rswitch_device checking Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 12/14] net: renesas: rswitch: add passing of rswitch_private into notifiers Michael Dege
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 13/14] net: renesas: rswitch: add handler for FDB notification Michael Dege
2026-05-25 20:40   ` Jakub Kicinski
2026-05-25 20:41   ` Jakub Kicinski
2026-05-22 12:12 ` [PATCH net-next v5 14/14] net: renesas: rswitch: add vlan aware switching Michael Dege
2026-05-25 20:41   ` Jakub Kicinski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260525204122.2471553-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=michael.dege@renesas.com \
    --cc=netdev@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=pabeni@redhat.com \
    --cc=paul@pbarker.dev \
    --cc=richardcochran@gmail.com \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox