linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: raw: add missing error queue support
@ 2020-09-26 16:24 Vincent Mailhol
  2020-10-01 11:03 ` Oliver Hartkopp
  2020-10-04  9:39 ` Marc Kleine-Budde
  0 siblings, 2 replies; 3+ messages in thread
From: Vincent Mailhol @ 2020-09-26 16:24 UTC (permalink / raw)
  To: linux-can
  Cc: Vincent Mailhol, Oliver Hartkopp, Marc Kleine-Budde,
	David S. Miller, Jakub Kicinski, linux-kernel, netdev

Error queue are not yet implemented in CAN-raw sockets.

The problem: a userland call to recvmsg(soc, msg, MSG_ERRQUEUE) on a
CAN-raw socket would unqueue messages from the normal queue without
any kind of error or warning. As such, it prevented CAN drivers from
using the functionalities that relies on the error queue such as
skb_tx_timestamp().

SCM_CAN_RAW_ERRQUEUE is defined as the type for the CAN raw error
queue. SCM stands for "Socket control messages". The name is inspired
from SCM_J1939_ERRQUEUE of include/uapi/linux/can/j1939.h.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
 include/uapi/linux/can/raw.h | 3 +++
 net/can/raw.c                | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/include/uapi/linux/can/raw.h b/include/uapi/linux/can/raw.h
index 6a11d308eb5c..3386aa81fdf2 100644
--- a/include/uapi/linux/can/raw.h
+++ b/include/uapi/linux/can/raw.h
@@ -49,6 +49,9 @@
 #include <linux/can.h>
 
 #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+enum {
+	SCM_CAN_RAW_ERRQUEUE = 1,
+};
 
 /* for socket options affecting the socket (not the global system) */
 
diff --git a/net/can/raw.c b/net/can/raw.c
index 94a9405658dc..98abab119136 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -804,6 +804,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
 	noblock =  flags & MSG_DONTWAIT;
 	flags   &= ~MSG_DONTWAIT;
 
+	if (flags & MSG_ERRQUEUE)
+		return sock_recv_errqueue(sk, msg, size,
+					  SOL_CAN_RAW, SCM_CAN_RAW_ERRQUEUE);
+
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb)
 		return err;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: raw: add missing error queue support
  2020-09-26 16:24 [PATCH] can: raw: add missing error queue support Vincent Mailhol
@ 2020-10-01 11:03 ` Oliver Hartkopp
  2020-10-04  9:39 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Oliver Hartkopp @ 2020-10-01 11:03 UTC (permalink / raw)
  To: Vincent Mailhol, linux-can
  Cc: Marc Kleine-Budde, David S. Miller, Jakub Kicinski, linux-kernel, netdev



On 26.09.20 18:24, Vincent Mailhol wrote:
> Error queue are not yet implemented in CAN-raw sockets.
> 
> The problem: a userland call to recvmsg(soc, msg, MSG_ERRQUEUE) on a
> CAN-raw socket would unqueue messages from the normal queue without
> any kind of error or warning. As such, it prevented CAN drivers from
> using the functionalities that relies on the error queue such as
> skb_tx_timestamp().
> 
> SCM_CAN_RAW_ERRQUEUE is defined as the type for the CAN raw error
> queue. SCM stands for "Socket control messages". The name is inspired
> from SCM_J1939_ERRQUEUE of include/uapi/linux/can/j1939.h.
> 
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

Thanks Vincent!

> ---
>   include/uapi/linux/can/raw.h | 3 +++
>   net/can/raw.c                | 4 ++++
>   2 files changed, 7 insertions(+)
> 
> diff --git a/include/uapi/linux/can/raw.h b/include/uapi/linux/can/raw.h
> index 6a11d308eb5c..3386aa81fdf2 100644
> --- a/include/uapi/linux/can/raw.h
> +++ b/include/uapi/linux/can/raw.h
> @@ -49,6 +49,9 @@
>   #include <linux/can.h>
>   
>   #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
> +enum {
> +	SCM_CAN_RAW_ERRQUEUE = 1,
> +};
>   
>   /* for socket options affecting the socket (not the global system) */
>   
> diff --git a/net/can/raw.c b/net/can/raw.c
> index 94a9405658dc..98abab119136 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -804,6 +804,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
>   	noblock =  flags & MSG_DONTWAIT;
>   	flags   &= ~MSG_DONTWAIT;
>   
> +	if (flags & MSG_ERRQUEUE)
> +		return sock_recv_errqueue(sk, msg, size,
> +					  SOL_CAN_RAW, SCM_CAN_RAW_ERRQUEUE);
> +
>   	skb = skb_recv_datagram(sk, flags, noblock, &err);
>   	if (!skb)
>   		return err;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: raw: add missing error queue support
  2020-09-26 16:24 [PATCH] can: raw: add missing error queue support Vincent Mailhol
  2020-10-01 11:03 ` Oliver Hartkopp
@ 2020-10-04  9:39 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2020-10-04  9:39 UTC (permalink / raw)
  To: Vincent Mailhol, linux-can
  Cc: Oliver Hartkopp, David S. Miller, Jakub Kicinski, linux-kernel, netdev


[-- Attachment #1.1: Type: text/plain, Size: 1005 bytes --]

On 9/26/20 6:24 PM, Vincent Mailhol wrote:
> Error queue are not yet implemented in CAN-raw sockets.
> 
> The problem: a userland call to recvmsg(soc, msg, MSG_ERRQUEUE) on a
> CAN-raw socket would unqueue messages from the normal queue without
> any kind of error or warning. As such, it prevented CAN drivers from
> using the functionalities that relies on the error queue such as
> skb_tx_timestamp().
> 
> SCM_CAN_RAW_ERRQUEUE is defined as the type for the CAN raw error
> queue. SCM stands for "Socket control messages". The name is inspired
> from SCM_J1939_ERRQUEUE of include/uapi/linux/can/j1939.h.
> 
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

Applied to linux-can-next.

Tnx,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-04  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-26 16:24 [PATCH] can: raw: add missing error queue support Vincent Mailhol
2020-10-01 11:03 ` Oliver Hartkopp
2020-10-04  9:39 ` Marc Kleine-Budde

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).