* Re: [regression] ENOTTY returned for tty fds [not found] ` <2024072452-pegboard-undying-4245@gregkh> @ 2024-07-24 8:07 ` stsp 2024-07-24 9:08 ` Greg KH 0 siblings, 1 reply; 8+ messages in thread From: stsp @ 2024-07-24 8:07 UTC (permalink / raw) To: Greg KH; +Cc: linux-serial, Linux kernel 24.07.2024 09:51, Greg KH пишет: > What caused this change/regression? I have absolutely no idea. I've found it by debugging userspace, and wrote a test-case to make sure the problem is not in user-space. > And does any real-world programs > rely on this? dosemu > What exactly are you trying to determine with this ioctl > test? Whether it is a PTS (Pseudo-Tty-Slave), or a real comport with MSR signalling. > Is there a different way to determine that? I am not aware of any "canonical" way of determining this. Maybe you tell me. :) So far the only fix I know, is to stop checking errno. But you return ENOTTY for a tty-associated fd (isatty(fd)==1), so I believe this is a bug in a kernel. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 8:07 ` [regression] ENOTTY returned for tty fds stsp @ 2024-07-24 9:08 ` Greg KH 2024-07-24 9:55 ` stsp 0 siblings, 1 reply; 8+ messages in thread From: Greg KH @ 2024-07-24 9:08 UTC (permalink / raw) To: stsp; +Cc: linux-serial, Linux kernel On Wed, Jul 24, 2024 at 11:07:32AM +0300, stsp wrote: > 24.07.2024 09:51, Greg KH пишет: > > What caused this change/regression? > > I have absolutely no idea. > I've found it by debugging userspace, > and wrote a test-case to make sure the > problem is not in user-space. So this has always worked this way? Or has it changed? If changed, when did it work before? > > And does any real-world programs > > rely on this? > > dosemu It does this today or wants to do this in the future? > > What exactly are you trying to determine with this ioctl > > test? > > Whether it is a PTS (Pseudo-Tty-Slave), or > a real comport with MSR signalling. Why is that needed? And why not do it how other programs (like stty) does it? > > Is there a different way to determine that? > I am not aware of any "canonical" way > of determining this. Maybe you tell me. :) > So far the only fix I know, is to stop checking > errno. But you return ENOTTY for a tty-associated > fd (isatty(fd)==1), so I believe this is a > bug in a kernel. isatty() is a libc provided function, not a kernel call. thanks, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 9:08 ` Greg KH @ 2024-07-24 9:55 ` stsp 2024-07-24 10:15 ` Greg KH 0 siblings, 1 reply; 8+ messages in thread From: stsp @ 2024-07-24 9:55 UTC (permalink / raw) To: Greg KH; +Cc: linux-serial, Linux kernel, Herbert Xu, Johan Hovold 24.07.2024 12:08, Greg KH пишет: > On Wed, Jul 24, 2024 at 11:07:32AM +0300, stsp wrote: >> 24.07.2024 09:51, Greg KH пишет: >>> What caused this change/regression? >> I have absolutely no idea. >> I've found it by debugging userspace, >> and wrote a test-case to make sure the >> problem is not in user-space. > So this has always worked this way? Or has it changed? If changed, > when did it work before? OK, I did some extensive digging, and now am pretty sure its this one: commit 1b8b20868a6d64cfe8174a21b25b74367bdf0560 Author: Johan Hovold <johan@kernel.org> AuthorDate: Wed Apr 7 11:52:02 2021 +0200 Commit: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CommitDate: Sat Apr 10 10:36:34 2021 +0200 tty: fix return value for unsupported ioctls Drivers should return -ENOTTY ("Inappropriate I/O control operation") when an ioctl isn't supported, while -EINVAL is used for invalid arguments. >>> And does any real-world programs >>> rely on this? >> dosemu > It does this today or wants to do this in the future? It does so since 2003/03/15, according to a change-log (so for 21 year now). Adding Herbert Xu to CC as an author of that feature. >>> What exactly are you trying to determine with this ioctl >>> test? >> Whether it is a PTS (Pseudo-Tty-Slave), or >> a real comport with MSR signalling. > Why is that needed? To fake modem status lines, mustly DCD. > And why not do it how other programs (like stty) > does it? I am not sure stty is interested in faking modem status lines. It doesn't seem to be using TIOCM ioctls at all. >>> Is there a different way to determine that? >> I am not aware of any "canonical" way >> of determining this. Maybe you tell me. :) >> So far the only fix I know, is to stop checking >> errno. But you return ENOTTY for a tty-associated >> fd (isatty(fd)==1), so I believe this is a >> bug in a kernel. > isatty() is a libc provided function, not a kernel call. It seems to be using TCGETS ioctl() and looks for it to not return an error. I still think returning ENOTTY where TCGETS succeeds, is more than strange. I looked at the tty code of current linux kernel, and it returns EOPNOTSUPP in most such cases. At least that makes sense, but ENOTTY? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 9:55 ` stsp @ 2024-07-24 10:15 ` Greg KH 2024-07-24 10:53 ` Herbert Xu 0 siblings, 1 reply; 8+ messages in thread From: Greg KH @ 2024-07-24 10:15 UTC (permalink / raw) To: stsp; +Cc: linux-serial, Linux kernel, Herbert Xu, Johan Hovold On Wed, Jul 24, 2024 at 12:55:22PM +0300, stsp wrote: > 24.07.2024 12:08, Greg KH пишет: > > On Wed, Jul 24, 2024 at 11:07:32AM +0300, stsp wrote: > > > 24.07.2024 09:51, Greg KH пишет: > > > > What caused this change/regression? > > > I have absolutely no idea. > > > I've found it by debugging userspace, > > > and wrote a test-case to make sure the > > > problem is not in user-space. > > So this has always worked this way? Or has it changed? If changed, > > when did it work before? > > OK, I did some extensive digging, and > now am pretty sure its this one: > > commit 1b8b20868a6d64cfe8174a21b25b74367bdf0560 > Author: Johan Hovold <johan@kernel.org> > AuthorDate: Wed Apr 7 11:52:02 2021 +0200 > Commit: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > CommitDate: Sat Apr 10 10:36:34 2021 +0200 > > tty: fix return value for unsupported ioctls > > Drivers should return -ENOTTY ("Inappropriate I/O control operation") > when an ioctl isn't supported, while -EINVAL is used for invalid > arguments. > > > > > And does any real-world programs > > > > rely on this? > > > dosemu > > It does this today or wants to do this in the future? > > It does so since 2003/03/15, according > to a change-log (so for 21 year now). > Adding Herbert Xu to CC as an author of > that feature. > > > > > What exactly are you trying to determine with this ioctl > > > > test? > > > Whether it is a PTS (Pseudo-Tty-Slave), or > > > a real comport with MSR signalling. > > Why is that needed? > > To fake modem status lines, mustly DCD. > > > > And why not do it how other programs (like stty) > > does it? > > I am not sure stty is interested in faking > modem status lines. It doesn't seem to be > using TIOCM ioctls at all. > > > > > Is there a different way to determine that? > > > I am not aware of any "canonical" way > > > of determining this. Maybe you tell me. :) > > > So far the only fix I know, is to stop checking > > > errno. But you return ENOTTY for a tty-associated > > > fd (isatty(fd)==1), so I believe this is a > > > bug in a kernel. > > isatty() is a libc provided function, not a kernel call. > It seems to be using TCGETS ioctl() and looks > for it to not return an error. > I still think returning ENOTTY where TCGETS > succeeds, is more than strange. > I looked at the tty code of current linux kernel, > and it returns EOPNOTSUPP in most such cases. > At least that makes sense, but ENOTTY? -ENOTTY is the documented result of invalid ioctl arguments sent, I am pretty sure POSIX requires this somewhere. So this was fixing a requirement here... thanks, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 10:15 ` Greg KH @ 2024-07-24 10:53 ` Herbert Xu 2024-07-24 10:58 ` Herbert Xu 0 siblings, 1 reply; 8+ messages in thread From: Herbert Xu @ 2024-07-24 10:53 UTC (permalink / raw) To: Greg KH, Linus Torvalds; +Cc: stsp, linux-serial, Linux kernel, Johan Hovold On Wed, Jul 24, 2024 at 12:15:39PM +0200, Greg KH wrote: > > -ENOTTY is the documented result of invalid ioctl arguments sent, I am > pretty sure POSIX requires this somewhere. So this was fixing a > requirement here... POSIX does not specify this at all: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html I think this should be reverted as it breaks user-space code that dates back to 2003. ENOTTY doesn't even make sense anyway as it literally means "is not a terminal" and pseudo-ttys certainly are terminals. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 10:53 ` Herbert Xu @ 2024-07-24 10:58 ` Herbert Xu 2024-07-31 10:25 ` Greg KH 0 siblings, 1 reply; 8+ messages in thread From: Herbert Xu @ 2024-07-24 10:58 UTC (permalink / raw) To: Greg KH, Linus Torvalds; +Cc: stsp, linux-serial, Linux kernel, Johan Hovold On Wed, Jul 24, 2024 at 06:53:00PM +0800, Herbert Xu wrote: > On Wed, Jul 24, 2024 at 12:15:39PM +0200, Greg KH wrote: > > > > -ENOTTY is the documented result of invalid ioctl arguments sent, I am > > pretty sure POSIX requires this somewhere. So this was fixing a > > requirement here... > > POSIX does not specify this at all: > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html In fact it says: If an underlying device driver detects an error, then ioctl() shall fail if: [EINVAL] The request or arg argument is not valid for this device. [ENOTTY] The file associated with the fildes argument is not a STREAMS device that accepts control functions. Of course this is all moot since POSIX only specifies ioctl(2) for STREAMS devices, but this patch in question is literally going against the woring here. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-24 10:58 ` Herbert Xu @ 2024-07-31 10:25 ` Greg KH 2024-07-31 16:12 ` Johan Hovold 0 siblings, 1 reply; 8+ messages in thread From: Greg KH @ 2024-07-31 10:25 UTC (permalink / raw) To: Herbert Xu; +Cc: Linus Torvalds, stsp, linux-serial, Linux kernel, Johan Hovold On Wed, Jul 24, 2024 at 06:58:22PM +0800, Herbert Xu wrote: > On Wed, Jul 24, 2024 at 06:53:00PM +0800, Herbert Xu wrote: > > On Wed, Jul 24, 2024 at 12:15:39PM +0200, Greg KH wrote: > > > > > > -ENOTTY is the documented result of invalid ioctl arguments sent, I am > > > pretty sure POSIX requires this somewhere. So this was fixing a > > > requirement here... > > > > POSIX does not specify this at all: > > > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html > > In fact it says: > > If an underlying device driver detects an error, then ioctl() shall fail if: > > [EINVAL] > The request or arg argument is not valid for this device. > > [ENOTTY] > The file associated with the fildes argument is not a STREAMS device that accepts control functions. > > Of course this is all moot since POSIX only specifies ioctl(2) > for STREAMS devices, but this patch in question is literally > going against the woring here. That's going to be going against a lot of existing kernel code then. -ENOTTY is the default action of almost all ioctl handlers when the command is not a valid one, sorry. thanks, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [regression] ENOTTY returned for tty fds 2024-07-31 10:25 ` Greg KH @ 2024-07-31 16:12 ` Johan Hovold 0 siblings, 0 replies; 8+ messages in thread From: Johan Hovold @ 2024-07-31 16:12 UTC (permalink / raw) To: Greg KH; +Cc: Herbert Xu, Linus Torvalds, stsp, linux-serial, Linux kernel [ For some reason I never received Herbert's replies so I didn't see them until today. ] On Wed, Jul 31, 2024 at 12:25:43PM +0200, Greg Kroah-Hartman wrote: > On Wed, Jul 24, 2024 at 06:58:22PM +0800, Herbert Xu wrote: > > On Wed, Jul 24, 2024 at 06:53:00PM +0800, Herbert Xu wrote: > > > On Wed, Jul 24, 2024 at 12:15:39PM +0200, Greg KH wrote: > > > > > > > > -ENOTTY is the documented result of invalid ioctl arguments sent, I am > > > > pretty sure POSIX requires this somewhere. So this was fixing a > > > > requirement here... > > > > > > POSIX does not specify this at all: > > > > > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html > > > > In fact it says: > > > > If an underlying device driver detects an error, then ioctl() shall fail if: > > > > [EINVAL] > > The request or arg argument is not valid for this device. > > > > [ENOTTY] > > The file associated with the fildes argument is not a STREAMS device that accepts control functions. > > > > Of course this is all moot since POSIX only specifies ioctl(2) > > for STREAMS devices, but this patch in question is literally > > going against the woring here. > > That's going to be going against a lot of existing kernel code then. > -ENOTTY is the default action of almost all ioctl handlers when the > command is not a valid one, sorry. This has been discussed at length before, and Linus made it clear that ENOTTY is the right errno for unsupported ioctls, for example, here: https://lore.kernel.org/lkml/BANLkTi=6W0quy1M71UapwKDe97E67b4EiA@mail.gmail.com/ The tty code has been returning this since 2012 and commit bbb63c514a34 ("drivers:tty:fix up ENOIOCTLCMD error handling") except for a few cases that were missed and that I fixed up in 2021. If this breaks real applications me may need to revert to EINVAL for the affected ioctls however. Apparently, dosemu hasn't been updated since 2013, but it looks like it indeed expects EINVAL for unsupported TIOCMBIC. Johan ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-07-31 16:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <b6f4aa5c-10ba-411b-994b-6dbed2bf63db@yandex.ru>
[not found] ` <2024072452-pegboard-undying-4245@gregkh>
2024-07-24 8:07 ` [regression] ENOTTY returned for tty fds stsp
2024-07-24 9:08 ` Greg KH
2024-07-24 9:55 ` stsp
2024-07-24 10:15 ` Greg KH
2024-07-24 10:53 ` Herbert Xu
2024-07-24 10:58 ` Herbert Xu
2024-07-31 10:25 ` Greg KH
2024-07-31 16:12 ` Johan Hovold
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox