Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: socketcan@hartkopp.net
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de,
	o.rempel@pengutronix.de, mailhol@kernel.org, zhuling0805@qq.com,
	kuba@kernel.org
Subject: Re: [PATCH v6 2/8] can: bcm: do not remove the procfs entry in bcm_notify()
Date: Thu, 19 Nov 2026 06:59:20 +0000	[thread overview]
Message-ID: <179507156037.3132.17606018249927571458@kernel.org> (raw)
In-Reply-To: <20261117-can-bcmlock-memcg-v6-2-6826a6227d36@hartkopp.net>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] bcm_proc_show() (net/can/bcm.c:222) reads bo->ifindex into a
  local first.

--

can: bcm: do not remove the procfs entry in bcm_notify()

This patch stops bcm_notify() from removing a CAN_BCM socket's procfs
entry under RTNL on NETDEV_UNREGISTER. The entry now stays until
bcm_release(), bcm_connect() only creates it if it does not exist yet,
and bcm_proc_show() reports unbound sockets as "unbound". The bo->ifindex
accesses are annotated with READ_ONCE()/WRITE_ONCE() for the lockless
readers.

> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 3f4c8d8283376..1595b7720c981 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -219,11 +219,16 @@ static int bcm_proc_show(struct seq_file *m, void *v)
>  	struct net *net = m->private;
>  	struct sock *sk = (struct sock *)pde_data(m->file->f_inode);
>  	struct bcm_sock *bo = bcm_sk(sk);
> +	int ifindex = READ_ONCE(bo->ifindex);
>  	struct bcm_op *op;
>  
>  	seq_printf(m, ">>> sock inode %s", bo->procname);
>  	seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
> -	seq_printf(m, " / bound %s", bcm_proc_getifname(net, ifname, bo->ifindex));
> +	if (READ_ONCE(bo->bound))
> +		seq_printf(m, " / bound %s",
> +			   bcm_proc_getifname(net, ifname, ifindex));
> +	else
> +		seq_puts(m, " / unbound");
>  	seq_printf(m, " <<<\n");

[Severity: Low]
Can this print "bound any" for a socket that is being connected to a
specific CAN device?

bcm_proc_show() takes its bo->ifindex snapshot first and reads bo->bound
only later. bcm_connect() writes the two fields in the opposite order:

bcm_connect()
    WRITE_ONCE(bo->ifindex, dev->ifindex);
    ...
    WRITE_ONCE(bo->bound, 1);

With this patch the procfs entry stays in place while the socket is
unbound (bound == 0, ifindex == 0). If the socket is connected again
while a reader is running, this interleaving looks possible:

reader                                bcm_connect()
ifindex = READ_ONCE(bo->ifindex);
  /* 0 */
                                      WRITE_ONCE(bo->ifindex, X);
                                      WRITE_ONCE(bo->bound, 1);
READ_ONCE(bo->bound)
  /* 1 */
bcm_proc_getifname(net, ifname, 0)
  /* "any" */

This is a plain interleaving. It does not need CPU reordering, so it can
happen on x86 too.

The commit message says:

    bcm_proc_show() reports an unbound socket as "unbound" instead of
    showing the cleared ifindex as "any".

It also says that "a concurrent bind or unbind may show an intermediate
state in the procfs output". When the socket is connected to device X,
it never actually has bound == 1 with ifindex == 0. So "bound any" here
is a state that never existed, not an intermediate one.

The NETDEV_DOWN check in bcm_notify() has a similar lockless pattern:

    if (READ_ONCE(bo->bound) &&
        READ_ONCE(bo->ifindex) == dev->ifindex) {

It has no acquire ordering. On weakly ordered CPUs, a concurrent
bcm_connect() could let it see bound == 1 together with the old ifindex.
That would drop one ENETDOWN report or add a spurious one.

Would reading bo->bound before bo->ifindex in bcm_proc_show() close the
window on TSO? Pairing smp_store_release(&bo->bound, 1) in bcm_connect()
with smp_load_acquire(&bo->bound) in the lockless readers would also
cover weakly ordered architectures.

The final patch of the series seems to keep the same read order in
bcm_proc_show().

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-can-bcmlock-memcg-v6-0-6826a6227d36%40hartkopp.net

  reply	other threads:[~2026-11-19  6:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 16:35 [PATCH v6 0/8] can: avoid RTNL stalls and fix CAN_ISOTP and netlink issues Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 1/8] can: bcm: copy the CAN frames outside of lock_sock() Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 2/8] can: bcm: do not remove the procfs entry in bcm_notify() Oliver Hartkopp
2026-11-19  6:59   ` netdev-bot+sashiko [this message]
2026-11-17 16:35 ` [PATCH v6 3/8] can: raw: use a private mutex instead of lock_sock() Oliver Hartkopp
2026-11-19  6:59   ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 4/8] can: isotp: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 5/8] can: bcm: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Oliver Hartkopp
2026-11-19  6:59   ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 7/8] can: isotp: reject socket options while a transfer is active Oliver Hartkopp
2026-11-17 17:17   ` sashiko-bot
2026-11-17 18:58     ` Oliver Hartkopp
2026-11-19  6:59   ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 8/8] can: netlink: fix static FD-NON-ISO mode validation Oliver Hartkopp

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=179507156037.3132.17606018249927571458@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --cc=zhuling0805@qq.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