Bug 264709

Summary: Inappropriate ioctl for /dev/cd0 after upgrade 13.0 -> 13.1
Product: Base System Reporter: amahling <andreas.mahling>
Component: kernAssignee: Alexander Motin <mav>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, markj, martymac, mav, mgrooms, pi
Priority: --- Keywords: regression
Version: 13.1-RELEASEFlags: markj: mfc-stable13+
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
truss output for freac none

Description amahling 2022-06-16 08:10:38 UTC
I have an issue with CD ripping tool audio/freac v1.1.5

It runs flawlessly under 13.0, after upgrading base system to 13.1 it fails to connect to /dev/cd0 with error 

++ WARN: ioctl(fd, CDIOCALLOW) failed: Invalid argument

++ WARN: open: Inappropriate ioctl for device

It doesn't matter whether I use the freac package or compile it from the ports tree

uname -a 
FreeBSD NomadBSD 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC amd64

I've added the comment, because I suppose it is a problem with the base system. Please let me know, if I would better open a bug report for the freac port. Thank you.

There is a similar bug report https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=198336, where I've added my issue as comment first, but maybe that's not the appropriate place
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2022-06-20 18:02:33 UTC
Can you show the output of running freac under truss(1)?

Do any relevant messages appear in the dmesg after an error?
Comment 2 amahling 2022-06-22 06:06:56 UTC
Created attachment 234852 [details]
truss output for freac

There is no dmesg output related to freac

I suppose, the relevant truss output lines are

fstatat(AT_FDCWD,"/dev/cd0",{ mode=crw-rw---- ,inode=108,size=0,blksize=4096 },0
x0) = 0 (0x0)
readlink("/dev/cd0",0x7fffffffbd80,255)          ERR#22 'Invalid argument'
fstatat(AT_FDCWD,"/dev/cd0",{ mode=crw-rw---- ,inode=108,size=0,blksize=4096 },0
x0) = 0 (0x0)
nanosleep({ 0.100000000 })                       = 0 (0x0)
openat(AT_FDCWD,"/dev/cd0",O_RDONLY,00)          = 11 (0xb)
ioctl(11,CDIOCALLOW,0x0)                         = 0 (0x0)
ioctl(11,0xc4e01903 { IORW 0x19('?'), 3, 1248 },0x805156608) ERR#25 'Inappropria
te ioctl for device'
fstat(1,{ mode=p--------- ,inode=5190,size=0,blksize=4096 }) = 0 (0x0)
++ WARN: open: Inappropriate ioctl for device
write(1,"++ WARN: open: Inappropriate ioc"...,46) = 46 (0x2e)
close(11)                                        = 0 (0x0)

complete truss output attached

It doesn't matter whether a cd is inserted or not, the error is always thrown.
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2022-06-22 15:44:27 UTC
0xc4e01903 { IORW 0x19('?'), 3, 1248 } is CAMGETPASSTHRU.  In commit 7d7168478380f08b3a7fd58ca7cf83182fae6850 CAM_VERSION was bumped (0x19->0x1a), changing the ioctl identity.  The commit added some compat shims, but it seems cam_periph_ioctl() doesn't use them, so compatibility is indeed broken for various periph drivers.
Comment 4 mgrooms 2022-08-14 22:46:01 UTC
Same issue here ...

mgrooms@desktop:~ $ freac
Property "/Xft/DPI" does not exist on channel "xsettings".
++ WARN: open: Inappropriate ioctl for device

mgrooms@desktop:~ $ freebsd-version
13.1-RELEASE-p1
Comment 5 mgrooms 2022-08-22 18:36:44 UTC
Is there anything that can be done as an end user to work around this issue?

Can this bug be assigned to the CAM group or to Alexander Motin so that it gets the attention of a CAM developer?
Comment 6 mgrooms 2022-08-31 00:13:33 UTC
Hi Mark. Thanks for creating a patch and posting it in phabricator for review ...

https://reviews.freebsd.org/D36389

Unfortunately I'm out for the country for the next 5 weeks so I won't have access to my optical drive until I return. Maybe the original bug reporter can test this out with freac and verify the problem is resolved.

Assuming your patch resolves the issue, will this fix eventually show up in a 13.1 patch level release distributed via Freebsd-update?

Thanks again for your help.
Comment 7 amahling 2022-09-02 06:31:00 UTC
I've applied the patch to the 13.1 source and can happily report, that the issue is fixed :)
Thank you very much. I hope the patch will arrive in 13.1-p3?
Comment 8 Mark Johnston freebsd_committer freebsd_triage 2022-09-03 14:23:17 UTC
(In reply to amahling from comment #7)
Thanks for testing.  Yes, I can ask for an erratum notice, so it'll arrive in some 13.1-pN patch.
Comment 9 commit-hook freebsd_committer freebsd_triage 2022-09-29 17:25:16 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0cd631ee0693dd7337c38b251044e018aad6fbaf

commit 0cd631ee0693dd7337c38b251044e018aad6fbaf
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-29 17:07:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-09-29 17:14:57 +0000

    cam: Provide compatibility for CAMGETPASSTHRU for periph drivers

    The CAM version bump 0x19 -> 0x1a changed the CAMGETPASSTHRU definition,
    so applications using the old ioctl are broken.  However, that version
    change did not affect anything relating to the ioctl implementation for
    periphs.

    Fixes:          8f9be1eed11c ("cam(4): Improve XPT_DEV_MATCH")
    PR:             264709
    Tested by:      andreas.mahling@googlemail.com
    Reviewed by:    imp
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D36389

 sys/cam/cam_periph.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 10 commit-hook freebsd_committer freebsd_triage 2022-10-13 00:51:43 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=16d4c1de7b40f1cc0d323b9ecc5a38afb7a42f8a

commit 16d4c1de7b40f1cc0d323b9ecc5a38afb7a42f8a
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-29 17:07:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-10-13 00:44:16 +0000

    cam: Provide compatibility for CAMGETPASSTHRU for periph drivers

    The CAM version bump 0x19 -> 0x1a changed the CAMGETPASSTHRU definition,
    so applications using the old ioctl are broken.  However, that version
    change did not affect anything relating to the ioctl implementation for
    periphs.

    Fixes:          8f9be1eed11c ("cam(4): Improve XPT_DEV_MATCH")
    PR:             264709
    Tested by:      andreas.mahling@googlemail.com
    Reviewed by:    imp

    (cherry picked from commit 0cd631ee0693dd7337c38b251044e018aad6fbaf)

 sys/cam/cam_periph.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 11 Ganael LAPLANCHE freebsd_committer freebsd_triage 2022-10-17 10:07:09 UTC
(In reply to Mark Johnston from comment #8)

Hello Mark,

I would be nice to have an erratum notice indeed. Have you got news on that point ?

Best regards,

Ganael.
Comment 12 Mark Johnston freebsd_committer freebsd_triage 2022-10-17 14:13:42 UTC
(In reply to Ganael LAPLANCHE from comment #11)
I've staged this patch for the next round of EN/SAs.  I don't know when they will be released, hopefully in the next couple of weeks.
Comment 13 Ganael LAPLANCHE freebsd_committer freebsd_triage 2022-10-18 05:45:10 UTC
(In reply to Mark Johnston from comment #12)

Perfect, thanks!
Comment 14 commit-hook freebsd_committer freebsd_triage 2022-11-01 20:34:47 UTC
A commit in branch releng/13.1 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=fff5c5fe911e7067390e6ff73c4c58489a30c849

commit fff5c5fe911e7067390e6ff73c4c58489a30c849
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-29 17:07:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-11-01 13:28:11 +0000

    cam: Provide compatibility for CAMGETPASSTHRU for periph drivers

    The CAM version bump 0x19 -> 0x1a changed the CAMGETPASSTHRU definition,
    so applications using the old ioctl are broken.  However, that version
    change did not affect anything relating to the ioctl implementation for
    periphs.

    Approved by:    so
    Security:       FreeBSD-EN-22:26.cam
    Fixes:          8f9be1eed11c ("cam(4): Improve XPT_DEV_MATCH")
    PR:             264709
    Tested by:      andreas.mahling@googlemail.com
    Reviewed by:    imp

    (cherry picked from commit 0cd631ee0693dd7337c38b251044e018aad6fbaf)
    (cherry picked from commit 16d4c1de7b40f1cc0d323b9ecc5a38afb7a42f8a)

 sys/cam/cam_periph.c | 2 ++
 1 file changed, 2 insertions(+)