diff mbox series

vsock: ratelimit unknown ioctl error message

Message ID 20201023122113.35517-1-colin.king@canonical.com
State New
Headers show
Series vsock: ratelimit unknown ioctl error message | expand

Commit Message

Colin King Oct. 23, 2020, 12:21 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

When exercising the kernel with stress-ng with some ioctl tests the
"Unknown ioctl" error message is spamming the kernel log at a high
rate. Rate limit this message to reduce the noise.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 net/vmw_vsock/af_vsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Garzarella Oct. 23, 2020, 2:09 p.m. UTC | #1
On Fri, Oct 23, 2020 at 01:21:13PM +0100, Colin King wrote:
>From: Colin Ian King <colin.king@canonical.com>

>

>When exercising the kernel with stress-ng with some ioctl tests the

>"Unknown ioctl" error message is spamming the kernel log at a high

>rate. Rate limit this message to reduce the noise.

>

>Signed-off-by: Colin Ian King <colin.king@canonical.com>

>---

> net/vmw_vsock/af_vsock.c | 2 +-

> 1 file changed, 1 insertion(+), 1 deletion(-)

>

>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c

>index 9e93bc201cc0..b8feb9223454 100644

>--- a/net/vmw_vsock/af_vsock.c

>+++ b/net/vmw_vsock/af_vsock.c

>@@ -2072,7 +2072,7 @@ static long vsock_dev_do_ioctl(struct file *filp,

> 		break;

>

> 	default:

>-		pr_err("Unknown ioctl %d\n", cmd);

>+		pr_err_ratelimited("Unknown ioctl %d\n", cmd);


Make sense, or maybe can we remove the error message returning only the
-EINVAL?

Both cases are fine for me:
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


> 		retval = -EINVAL;

> 	}

>

>-- 

>2.27.0

>
Jakub Kicinski Oct. 23, 2020, 8:25 p.m. UTC | #2
On Fri, 23 Oct 2020 16:09:47 +0200 Stefano Garzarella wrote:
> On Fri, Oct 23, 2020 at 01:21:13PM +0100, Colin King wrote:

> >From: Colin Ian King <colin.king@canonical.com>

> >

> >When exercising the kernel with stress-ng with some ioctl tests the

> >"Unknown ioctl" error message is spamming the kernel log at a high

> >rate. Rate limit this message to reduce the noise.

> >

> >Signed-off-by: Colin Ian King <colin.king@canonical.com>

> >---

> > net/vmw_vsock/af_vsock.c | 2 +-

> > 1 file changed, 1 insertion(+), 1 deletion(-)

> >

> >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c

> >index 9e93bc201cc0..b8feb9223454 100644

> >--- a/net/vmw_vsock/af_vsock.c

> >+++ b/net/vmw_vsock/af_vsock.c

> >@@ -2072,7 +2072,7 @@ static long vsock_dev_do_ioctl(struct file *filp,

> > 		break;

> >

> > 	default:

> >-		pr_err("Unknown ioctl %d\n", cmd);

> >+		pr_err_ratelimited("Unknown ioctl %d\n", cmd);  

> 

> Make sense, or maybe can we remove the error message returning only the

> -EINVAL?


+1

> Both cases are fine for me:

> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
David Laight Oct. 23, 2020, 9:30 p.m. UTC | #3
From: Stefano Garzarella

> Sent: 23 October 2020 15:10

> 

> On Fri, Oct 23, 2020 at 01:21:13PM +0100, Colin King wrote:

> >From: Colin Ian King <colin.king@canonical.com>

> >

> >When exercising the kernel with stress-ng with some ioctl tests the

> >"Unknown ioctl" error message is spamming the kernel log at a high

> >rate. Rate limit this message to reduce the noise.

> >

> >Signed-off-by: Colin Ian King <colin.king@canonical.com>

> >---

> > net/vmw_vsock/af_vsock.c | 2 +-

> > 1 file changed, 1 insertion(+), 1 deletion(-)

> >

> >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c

> >index 9e93bc201cc0..b8feb9223454 100644

> >--- a/net/vmw_vsock/af_vsock.c

> >+++ b/net/vmw_vsock/af_vsock.c

> >@@ -2072,7 +2072,7 @@ static long vsock_dev_do_ioctl(struct file *filp,

> > 		break;

> >

> > 	default:

> >-		pr_err("Unknown ioctl %d\n", cmd);

> >+		pr_err_ratelimited("Unknown ioctl %d\n", cmd);

> 

> Make sense, or maybe can we remove the error message returning only the

> -EINVAL?


Isn't the canonical error for unknown ioctl codes -ENOTTY?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Stefano Garzarella Oct. 26, 2020, 8:43 a.m. UTC | #4
On Fri, Oct 23, 2020 at 09:30:59PM +0000, David Laight wrote:
>

>From: Stefano Garzarella

>> Sent: 23 October 2020 15:10

>>

>> On Fri, Oct 23, 2020 at 01:21:13PM +0100, Colin King wrote:

>> >From: Colin Ian King <colin.king@canonical.com>

>> >

>> >When exercising the kernel with stress-ng with some ioctl tests the

>> >"Unknown ioctl" error message is spamming the kernel log at a high

>> >rate. Rate limit this message to reduce the noise.

>> >

>> >Signed-off-by: Colin Ian King <colin.king@canonical.com>

>> >---

>> > net/vmw_vsock/af_vsock.c | 2 +-

>> > 1 file changed, 1 insertion(+), 1 deletion(-)

>> >

>> >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c

>> >index 9e93bc201cc0..b8feb9223454 100644

>> >--- a/net/vmw_vsock/af_vsock.c

>> >+++ b/net/vmw_vsock/af_vsock.c

>> >@@ -2072,7 +2072,7 @@ static long vsock_dev_do_ioctl(struct file *filp,

>> > 		break;

>> >

>> > 	default:

>> >-		pr_err("Unknown ioctl %d\n", cmd);

>> >+		pr_err_ratelimited("Unknown ioctl %d\n", cmd);

>>

>> Make sense, or maybe can we remove the error message returning only the

>> -EINVAL?

>

>Isn't the canonical error for unknown ioctl codes -ENOTTY?

>


Oh, thanks for pointing that out!

I had not paid attention to the error returned, but looking at it I 
noticed that perhaps the most appropriate would be -ENOIOCTLCMD.
In the ioctl syscall we return -ENOTTY, if the callback returns 
-ENOIOCTLCMD.

What do you think?

Stefano
David Laight Oct. 26, 2020, 9:13 a.m. UTC | #5
From: Stefano Garzarella

> Sent: 26 October 2020 08:43

...
> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

> >

> 

> Oh, thanks for pointing that out!

> 

> I had not paid attention to the error returned, but looking at it I

> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

> In the ioctl syscall we return -ENOTTY, if the callback returns

> -ENOIOCTLCMD.

> 

> What do you think?


It is 729 v 443 in favour of ENOTTY (based on grep).

No idea where ENOIOCTLCMD comes from, but ENOTTY probably
goes back to the early 1970s.

The fact that the ioctl wrapper converts the value is a good
hint that userspace expects ENOTTY.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Stefano Garzarella Oct. 26, 2020, 9:39 a.m. UTC | #6
On Mon, Oct 26, 2020 at 09:13:23AM +0000, David Laight wrote:
>From: Stefano Garzarella

>> Sent: 26 October 2020 08:43

>...

>> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

>> >

>>

>> Oh, thanks for pointing that out!

>>

>> I had not paid attention to the error returned, but looking at it I

>> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

>> In the ioctl syscall we return -ENOTTY, if the callback returns

>> -ENOIOCTLCMD.

>>

>> What do you think?

>

>It is 729 v 443 in favour of ENOTTY (based on grep).


Under net/ it is 6 vs 83 in favour of ENOIOCTLCMD.

>

>No idea where ENOIOCTLCMD comes from, but ENOTTY probably

>goes back to the early 1970s.


Me too.

>

>The fact that the ioctl wrapper converts the value is a good

>hint that userspace expects ENOTTY.


Agree on that, but since we are not interfacing directly with userspace, 
I think it is better to return the more specific error (ENOIOCTLCMD).

Thanks,
Stefano
David Laight Oct. 26, 2020, 9:46 a.m. UTC | #7
From: Stefano Garzarella

> Sent: 26 October 2020 09:39

> 

> On Mon, Oct 26, 2020 at 09:13:23AM +0000, David Laight wrote:

> >From: Stefano Garzarella

> >> Sent: 26 October 2020 08:43

> >...

> >> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

> >> >

> >>

> >> Oh, thanks for pointing that out!

> >>

> >> I had not paid attention to the error returned, but looking at it I

> >> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

> >> In the ioctl syscall we return -ENOTTY, if the callback returns

> >> -ENOIOCTLCMD.

> >>

> >> What do you think?

> >

> >It is 729 v 443 in favour of ENOTTY (based on grep).

> 

> Under net/ it is 6 vs 83 in favour of ENOIOCTLCMD.

> 

> >

> >No idea where ENOIOCTLCMD comes from, but ENOTTY probably

> >goes back to the early 1970s.

> 

> Me too.

> 

> >

> >The fact that the ioctl wrapper converts the value is a good

> >hint that userspace expects ENOTTY.

> 

> Agree on that, but since we are not interfacing directly with userspace,

> I think it is better to return the more specific error (ENOIOCTLCMD).


I bet Linux thought it could use a different error code then
found that 'unknown ioctl' was spelt ENOTTY.

Back in the old days error values were probably almost unique.
strerror(EAGIAN) was "No more processes" for a long time!

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Stefano Garzarella Oct. 26, 2020, 10:01 a.m. UTC | #8
On Mon, Oct 26, 2020 at 09:46:17AM +0000, David Laight wrote:
>From: Stefano Garzarella

>> Sent: 26 October 2020 09:39

>>

>> On Mon, Oct 26, 2020 at 09:13:23AM +0000, David Laight wrote:

>> >From: Stefano Garzarella

>> >> Sent: 26 October 2020 08:43

>> >...

>> >> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

>> >> >

>> >>

>> >> Oh, thanks for pointing that out!

>> >>

>> >> I had not paid attention to the error returned, but looking at it I

>> >> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

>> >> In the ioctl syscall we return -ENOTTY, if the callback returns

>> >> -ENOIOCTLCMD.

>> >>

>> >> What do you think?

>> >

>> >It is 729 v 443 in favour of ENOTTY (based on grep).

>>

>> Under net/ it is 6 vs 83 in favour of ENOIOCTLCMD.

>>

>> >

>> >No idea where ENOIOCTLCMD comes from, but ENOTTY probably

>> >goes back to the early 1970s.

>>

>> Me too.

>>

>> >

>> >The fact that the ioctl wrapper converts the value is a good

>> >hint that userspace expects ENOTTY.

>>

>> Agree on that, but since we are not interfacing directly with userspace,

>> I think it is better to return the more specific error (ENOIOCTLCMD).

>

>I bet Linux thought it could use a different error code then

>found that 'unknown ioctl' was spelt ENOTTY.


It could be :-)

Anyway, as you pointed out, I think we should change the -EINVAL with 
-ENOTTY or -ENOIOCTLCMD.

@Jakub what do you suggest?

Thanks,
Stefano
Jakub Kicinski Oct. 26, 2020, 5:55 p.m. UTC | #9
On Mon, 26 Oct 2020 11:01:12 +0100 Stefano Garzarella wrote:
> On Mon, Oct 26, 2020 at 09:46:17AM +0000, David Laight wrote:

> >From: Stefano Garzarella  

> >> Sent: 26 October 2020 09:39

> >>

> >> On Mon, Oct 26, 2020 at 09:13:23AM +0000, David Laight wrote:  

> >> >From: Stefano Garzarella  

> >> >> Sent: 26 October 2020 08:43  

> >> >...  

> >> >> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

> >> >> >  

> >> >>

> >> >> Oh, thanks for pointing that out!

> >> >>

> >> >> I had not paid attention to the error returned, but looking at it I

> >> >> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

> >> >> In the ioctl syscall we return -ENOTTY, if the callback returns

> >> >> -ENOIOCTLCMD.

> >> >>

> >> >> What do you think?  

> >> >

> >> >It is 729 v 443 in favour of ENOTTY (based on grep).  

> >>

> >> Under net/ it is 6 vs 83 in favour of ENOIOCTLCMD.

> >>  

> >> >

> >> >No idea where ENOIOCTLCMD comes from, but ENOTTY probably

> >> >goes back to the early 1970s.  

> >>

> >> Me too.

> >>  

> >> >

> >> >The fact that the ioctl wrapper converts the value is a good

> >> >hint that userspace expects ENOTTY.  

> >>

> >> Agree on that, but since we are not interfacing directly with userspace,

> >> I think it is better to return the more specific error (ENOIOCTLCMD).  

> >

> >I bet Linux thought it could use a different error code then

> >found that 'unknown ioctl' was spelt ENOTTY.  

> 

> It could be :-)

> 

> Anyway, as you pointed out, I think we should change the -EINVAL with 

> -ENOTTY or -ENOIOCTLCMD.

> 

> @Jakub what do you suggest?


ENOIOCTLCMD is a kernel-internal high return code (515) which should 
be returned by the driver, but it's then caught inside the core and
translated to ENOTTY which is then returned to user space.

So you're both right, I guess? But the driver should use ENOIOCTLCMD.
Stefano Garzarella Oct. 26, 2020, 6:24 p.m. UTC | #10
On Mon, Oct 26, 2020 at 10:55:48AM -0700, Jakub Kicinski wrote:
>On Mon, 26 Oct 2020 11:01:12 +0100 Stefano Garzarella wrote:

>> On Mon, Oct 26, 2020 at 09:46:17AM +0000, David Laight wrote:

>> >From: Stefano Garzarella

>> >> Sent: 26 October 2020 09:39

>> >>

>> >> On Mon, Oct 26, 2020 at 09:13:23AM +0000, David Laight wrote:

>> >> >From: Stefano Garzarella

>> >> >> Sent: 26 October 2020 08:43

>> >> >...

>> >> >> >Isn't the canonical error for unknown ioctl codes -ENOTTY?

>> >> >> >

>> >> >>

>> >> >> Oh, thanks for pointing that out!

>> >> >>

>> >> >> I had not paid attention to the error returned, but looking at it I

>> >> >> noticed that perhaps the most appropriate would be -ENOIOCTLCMD.

>> >> >> In the ioctl syscall we return -ENOTTY, if the callback returns

>> >> >> -ENOIOCTLCMD.

>> >> >>

>> >> >> What do you think?

>> >> >

>> >> >It is 729 v 443 in favour of ENOTTY (based on grep).

>> >>

>> >> Under net/ it is 6 vs 83 in favour of ENOIOCTLCMD.

>> >>

>> >> >

>> >> >No idea where ENOIOCTLCMD comes from, but ENOTTY probably

>> >> >goes back to the early 1970s.

>> >>

>> >> Me too.

>> >>

>> >> >

>> >> >The fact that the ioctl wrapper converts the value is a good

>> >> >hint that userspace expects ENOTTY.

>> >>

>> >> Agree on that, but since we are not interfacing directly with userspace,

>> >> I think it is better to return the more specific error (ENOIOCTLCMD).

>> >

>> >I bet Linux thought it could use a different error code then

>> >found that 'unknown ioctl' was spelt ENOTTY.

>>

>> It could be :-)

>>

>> Anyway, as you pointed out, I think we should change the -EINVAL with

>> -ENOTTY or -ENOIOCTLCMD.

>>

>> @Jakub what do you suggest?

>

>ENOIOCTLCMD is a kernel-internal high return code (515) which should

>be returned by the driver, but it's then caught inside the core and

>translated to ENOTTY which is then returned to user space.

>

>So you're both right, I guess? But the driver should use ENOIOCTLCMD.

>


Thanks for clarify!

@Colin, can you send a v2 removing the error message and updating the 
return value?

Thanks,
Stefano
Jakub Kicinski Oct. 26, 2020, 6:37 p.m. UTC | #11
On Mon, 26 Oct 2020 19:24:57 +0100 Stefano Garzarella wrote:
> @Colin, can you send a v2 removing the error message and updating the 

> return value?


Not as a single patch, please, these are two different changes.
diff mbox series

Patch

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 9e93bc201cc0..b8feb9223454 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2072,7 +2072,7 @@  static long vsock_dev_do_ioctl(struct file *filp,
 		break;
 
 	default:
-		pr_err("Unknown ioctl %d\n", cmd);
+		pr_err_ratelimited("Unknown ioctl %d\n", cmd);
 		retval = -EINVAL;
 	}