linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: linux-can@vger.kernel.org,
	"Sottas Guillaume (LMB)" <Guillaume.Sottas@liebherr.com>
Subject: Re: [PATCH] can: isotp: return -ECOMM on FC timeout on TX path
Date: Wed, 28 Apr 2021 14:07:51 +0200	[thread overview]
Message-ID: <20210428120751.xkczqby455rexpne@pengutronix.de> (raw)
In-Reply-To: <ee8058e0-af0a-8759-a62b-b1585c8992b3@hartkopp.net>

[-- Attachment #1: Type: text/plain, Size: 3601 bytes --]

On 28.04.2021 13:45:10, Oliver Hartkopp wrote:
> On 28.04.21 12:47, Marc Kleine-Budde wrote:
> > On 28.04.2021 12:24:32, Oliver Hartkopp wrote:
> > > > Maybe the way to trigger the sk_error_report(sk) we might return '-1'
> > > > while the error is then propagated inside errno.
> > > 
> > > I added some debug print in isotpsend:
> > > 
> > > diff --git a/isotpsend.c b/isotpsend.c
> > > index 3ea574c..c2937fa 100644
> > > --- a/isotpsend.c
> > > +++ b/isotpsend.c
> > > @@ -45,10 +45,11 @@
> > >   #include <libgen.h>
> > >   #include <stdio.h>
> > >   #include <stdlib.h>
> > >   #include <string.h>
> > >   #include <unistd.h>
> > > +#include <errno.h>
> > > 
> > >   #include <net/if.h>
> > >   #include <sys/ioctl.h>
> > >   #include <sys/socket.h>
> > >   #include <sys/types.h>
> > > @@ -252,10 +253,11 @@ int main(int argc, char **argv)
> > >                      buf[buflen] = ((buflen % 0xFF) + 1) & 0xFF;
> > >       }
> > > 
> > > 
> > >       retval = write(s, buf, buflen);
> > > +    printf("retval %d errno %d\n", retval, errno);
> > 
> > Note: in user space errno is only valid if retval is "-1"...
> 
> Ok, just returned '-1' in that case of blocking write (which runs into the
> timeout) ...
> 
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 9f94ad3caee9..d5d541b4fed5 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -952,10 +952,11 @@ static int isotp_sendmsg(struct socket *sock, struct
> msghdr *msg, size_t size)
>         }
> 
>         if (wait_tx_done) {
>                 /* wait for complete transmission of current pdu */
>                 wait_event_interruptible(so->wait, so->tx.state ==
> ISOTP_IDLE);
> +               return -1;
>         }
> 
>         return size;
>  }
> 
> And now got this:
> 
> $ date +%S.%N && ./isotpsend vcan0 -s 123 -d 321 -D 44 -b && date +%S.%N
> 22.411570468
> retval -1 errno 1
         ^        ^
         |     that is your -1
      it's -1, as your return value was negative
      
> write: Operation not permitted
> 
> So still nothing to see from "sk->sk_err = ECOMM;"
> 
> But when adding 'return -ECOMM' at the above section it works like this:
> 
> $ date +%S.%N && ./isotpsend vcan0 -s 123 -d 321 -D 44 -b && date +%S.%N
> 58.453452222
> retval -1 errno 70
> write: Communication error on send

looks good

> This is obviously the expected behaviour for user space:
> 
> - get '-1' in the case of socket related errors
> - get the details from errno

ACK

> Maybe all that sk_err stuff is only relevant for listen/accept constructions
> for connection oriented sockets and can be removed inside isotp.c ...

My theory is:
- return bytes send from isotp_sendmsg() or -errno as usual
- use sk->sk_error_report(sk) to wake up user space if it is blocked in
  poll() or blocking in sendmsg()/recvmsg()

For example, if you have a normal read() blocking on a CAN_RAW socket on
an interface, you get a ENETDOWN when you ifdown the interface:

https://elixir.bootlin.com/linux/latest/source/net/can/raw.c#L302

e.g.:

| ➜ (pts/54) frogger@hardanger:/tmp candump can0 &
| [1] 260474
| ➜ (pts/54) frogger@hardanger:/tmp (1) sudo ip link set can0 down
| read: Network is down
| [1]  + 260474 exit 1     candump can0

regards,
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-04-28 12:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  9:09 [PATCH] can: isotp: return -ECOMM on FC timeout on TX path Marc Kleine-Budde
2021-04-28  9:12 ` Marc Kleine-Budde
2021-04-28  9:26   ` Oliver Hartkopp
2021-04-28 10:24     ` Oliver Hartkopp
2021-04-28 10:47       ` Marc Kleine-Budde
2021-04-28 11:45         ` Oliver Hartkopp
2021-04-28 12:07           ` Marc Kleine-Budde [this message]
2021-04-28 11:43 Sottas Guillaume (LMB)
2021-04-28 11:48 ` Oliver Hartkopp
2021-05-06 12:45 Sottas Guillaume (LMB)
2021-05-06 13:38 ` Marc Kleine-Budde

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=20210428120751.xkczqby455rexpne@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=Guillaume.Sottas@liebherr.com \
    --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;
as well as URLs for NNTP newsgroup(s).