Linux CAN drivers development
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol@kernel.org>
To: Oliver Hartkopp <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Subject: Re: [RFC PATCH v5 2/2] can: reject CAN FD content when disabled on CAN XL interfaces
Date: Wed, 10 Sep 2025 14:13:22 +0900	[thread overview]
Message-ID: <7578f44d-d85c-473e-8e7a-65d1fc974e68@kernel.org> (raw)
In-Reply-To: <f7b59c7c-30ad-4cf4-ad0e-bff0e39b3337@hartkopp.net>

On 10/09/2025 at 01:36, Oliver Hartkopp wrote:
> Hi Vincent,
> 
> On 09.09.25 11:24, Oliver Hartkopp wrote:
> 
> 
>> -static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff
>> *skb, int mtu)
>> +static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
>> +                      struct net_device *dev)
>>   {
>>       /* Classical CAN -> no checks for flags and device capabilities */
>>       if (can_is_can_skb(skb))
>>           return CAN_MTU;
>>   -    /* CAN FD -> needs to be enabled and a CAN FD or CAN XL device */
>> -    if (ro->fd_frames && can_is_canfd_skb_mtu_len(skb) &&
>> -        (mtu == CANFD_MTU || can_is_canxl_dev_mtu(mtu)))
>> -        return CANFD_MTU;
>> +    /* CAN FD -> needs to be enabled in a CAN FD or CAN XL device */
>> +    if (ro->fd_frames && can_is_canfd_skb_mtu_len(skb)) {
>> +        /* real/virtual CAN FD interface */
>> +        if (dev->mtu == CANFD_MTU)
>> +            return CANFD_MTU;
>> +        if (can_is_canxl_dev_mtu(dev->mtu) &&
>> +            can_dev_ctrlmode_fd_on(dev))
>> +            return CANFD_MTU;
>> +    }
> 
> I've simplified the above code and rewrote the commit message in v6
> 
>>       /* CAN XL -> needs to be enabled and a CAN XL device */
>>       if (ro->xl_frames && can_is_canxl_skb(skb) &&
>> -        can_is_canxl_dev_mtu(mtu))
>> +        can_is_canxl_dev_mtu(dev->mtu))
>>           return CANXL_MTU;
> 
> We might also discuss if we create a can_dev_ctrlmode_xl_on(dev) function to
> check if the CAN XL interface has CAN_CTRLMODE_XL enabled.

I checked ISO 11898-1:2024 again and the relevant wording I can found is in
§6.6.21.4.1:

  When error signalling is disabled, the node shall transmit and
  receive only XLFF frames. It shall not transmit EF, OF and RF, nor
  DFs in CBFF, CEFF, FBFF and FEFF.

TLDR; Classical CAN is deactivated when error signaling is off.

So, I think that we also need the same logic for the Classical CAN. The nuance
is that instead of using CAN_CTRLMODE_CC (which does not exist), we can check
CAN_CTRLMODE_XL_ERR_SIGNAL. Note that CAN_CTRLMODE_XL_TMS implies that error
signalling is off, so no need for extra checks on TMS. This is what I have in
mind at the moment.

  static inline bool can_dev_cc_on(struct net_device *dev)
  {
  	struct can_priv *priv = safe_candev_priv(dev);

  	/* Classical CAN frames are always allowed on virtual interfaces */
  	if (!priv)
  		return true;

  	/* When error signalling is off only CAN XL frames are allowed */
  	return !(priv->ctrlmode & CAN_CTRLMODE_XL) ||
  		(priv->ctrlmode & CAN_CTRLMODE_XL_ERR_SIGNAL);
  }

  static inline bool can_dev_fd_on(struct net_device *dev)
  {
  	struct can_priv *priv = safe_candev_priv(dev);

	/* CAN FD is allowed on virtual interfaces if it fits the MTU */
  	if (!priv)
  		return dev->mtu == CANFD_MTU;

  	return can_dev_cc_on(dev) && (priv->ctrlmode & CAN_CTRLMODE_FD);
  }

  static inline bool can_dev_xl_on(struct net_device *dev)
  {
  	struct can_priv *priv = safe_candev_priv(dev);

	/* CAN XL is allowed on virtual interfaces if it fits the MTU */
  	if (!priv)
  		return dev->mtu == CANXL_MTU;

  	return priv->ctrlmode & CAN_CTRLMODE_XL;
  }

(the above is not yet tested, so beware of silly errors!)

> Currently my patches are based on Linus' rc5 tree where CAN_CTRLMODE_XL is not
> defined. But I can rebase it on your b4/canxl-netlink branch if you like it.

I still want to finish the XL preparation series before moving to the actual thing.

You can do what is convinient for you:

  1/ rebase on b4/canxl-netlink branch but I take no claims if your code breaks
     after one of my force push.

  2/ add the flags you need in netlink.h. I will then chery pick your patches in
     my series when ready and take care of any conflict for you!

I am going to send the v2 of my XL preparation series. Hopefully we can finalyse
it soon so that we can focus on one sigle topic :)


Yours sincerely,
Vincent Mailhol


  reply	other threads:[~2025-09-10  5:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09  9:24 [RFC PATCH v5 1/2] can: skb: enforce CANFD_FDF check in can_is_canfd_skb() Oliver Hartkopp
2025-09-09  9:24 ` [RFC PATCH v5 2/2] can: reject CAN FD content when disabled on CAN XL interfaces Oliver Hartkopp
2025-09-09 16:36   ` Oliver Hartkopp
2025-09-10  5:13     ` Vincent Mailhol [this message]
2025-09-10  7:27       ` Oliver Hartkopp
2025-09-10  7:40         ` Vincent Mailhol
2025-09-10  8:48           ` Oliver Hartkopp
2025-09-10 16:19             ` Vincent Mailhol
2025-09-10 20:12               ` Oliver Hartkopp
2025-09-15 10:55                 ` Vincent Mailhol
2025-09-15 13:59                   ` Vincent Mailhol
2025-09-15 18:08                     ` Oliver Hartkopp
2025-09-15 18:54                       ` Vincent Mailhol
2025-09-16  9:14                         ` Oliver Hartkopp
2025-09-16 13:17                           ` Vincent Mailhol
2025-09-17 21:29                             ` Oliver Hartkopp
2025-09-18  9:18                               ` Vincent Mailhol
2025-09-20 17:38                                 ` Oliver Hartkopp
2025-09-20 17:57                                   ` Vincent Mailhol

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=7578f44d-d85c-473e-8e7a-65d1fc974e68@kernel.org \
    --to=mailhol@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /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