From: Andrew Lunn <andrew@lunn.ch>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
Vivien Didelot <vivien.didelot@gmail.com>,
Tobias Waldekranz <tobias@waldekranz.com>
Subject: Re: [PATCH v2 net-next] net: dsa: reference count the host mdb addresses
Date: Sat, 12 Dec 2020 20:28:08 +0100 [thread overview]
Message-ID: <20201212192808.GA2779451@lunn.ch> (raw)
In-Reply-To: <20201212190352.214642-1-vladimir.oltean@nxp.com>
> +/* DSA can directly translate this to a normal MDB add, but on the CPU port.
> + * But because multiple user ports can join the same multicast group and the
> + * bridge will emit a notification for each port, we need to add/delete the
> + * entry towards the host only once, so we reference count it.
> + */
> +static int dsa_host_mdb_add(struct dsa_port *dp,
> + const struct switchdev_obj_port_mdb *mdb,
> + struct switchdev_trans *trans)
> +{
> + struct dsa_port *cpu_dp = dp->cpu_dp;
> + struct dsa_switch *ds = dp->ds;
> + struct dsa_host_addr *a;
> + int err;
> +
> + a = dsa_host_addr_find(&ds->host_mdb, mdb);
> + if (a) {
> + /* Only the commit phase is refcounted */
> + if (switchdev_trans_ph_commit(trans))
> + refcount_inc(&a->refcount);
> + return 0;
> + }
> +
> + err = dsa_port_mdb_add(cpu_dp, mdb, trans);
> + if (err)
> + return err;
> +
> + /* Only the commit phase is refcounted, so don't save this just yet */
> + if (switchdev_trans_ph_prepare(trans))
> + return 0;
> +
> + a = kzalloc(sizeof(*a), GFP_KERNEL);
> + if (!a)
> + return -ENOMEM;
Hi Vladimir
This allocation should be done in the prepare phase, since it can
fail. You should only return catastrophic errors during the commit
phase.
So i think you can allocate it in the prepare phase, but leave the
reference count as 0. Then increment it in the commit phase.
And then make the dsa_host_mdb_del() decrement the specific refcount,
and then do a generic garbage collect for all entries with refcount of
0, to cleanup any left over failures.
Andrew
prev parent reply other threads:[~2020-12-12 19:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-12 19:03 [PATCH v2 net-next] net: dsa: reference count the host mdb addresses Vladimir Oltean
2020-12-12 19:28 ` Andrew Lunn [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=20201212192808.GA2779451@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tobias@waldekranz.com \
--cc=vivien.didelot@gmail.com \
--cc=vladimir.oltean@nxp.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;
as well as URLs for NNTP newsgroup(s).