Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linprocfs: Add support for proc/sysvipc/{msg,sem,shm} #1218

Merged
merged 3 commits into from
May 11, 2024

Conversation

ricardobranco777
Copy link
Contributor

@ricardobranco777 ricardobranco777 commented May 4, 2024

Add support for proc/sysvipc/{msg,sem,shm}

Tracking in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=278812

To build:

  1. cd /sys/modules/linprocfs
  2. make && doas make install && doas cp -f /boot/modules/linprocfs.ko /boot/kernel/
  3. doas kldxref /boot/kernel/
  4. doas umount -a -t linprocfs
  5. doas kldunload -v linprocfs
  6. doas kldload -v linprocfs
  7. doas mount -t linprocfs linprocfs /compat/linux/proc/

How I tested it (needs ipcmk from the util-linux package):

$ ipcmk --shmem 128K
Shared memory id: 131072

$ cat /compat/linux/proc/sysvipc/shm 
       key      shmid perms                  size  cpid  lpid nattch   uid   gid  cuid  cgid      atime      dtime      ctime                   rss                  swap
-264176145     131072  4644                131072 39330     0      0  1000  1000  1000  1000          0          0 1714846976                    -1                    -1

$ ipcmk --semaphore 7 
Semaphore id: 196608

$ cat /compat/linux/proc/sysvipc/sem
       key      semid perms      nsems   uid   gid  cuid  cgid      otime      ctime
1038146433     196608  1644          7  1000  1000  1000  1000          0 1714847009

$ ipcmk --queue
Message queue id: 131072

$ cat /compat/linux/proc/sysvipc/msg
       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime
 756788372     131072   644           0          0     0     0  1000  1000  1000  1000          0          0 1714847025

$ ipcs -a
Message Queues:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP                 CBYTES                 QNUM               QBYTES        LSPID        LRPID STIME    RTIME    CTIME
q       131072    756788372 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             0            0                 2048            0            0 no-entry no-entry 20:23:45

Shared Memory:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP         NATTCH        SEGSZ         CPID         LPID ATIME    DTIME    CTIME
m       131072   -264176145 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             0       131072        39330            0 no-entry no-entry 20:22:56

Semaphores:
T           ID          KEY MODE        OWNER    GROUP    CREATOR  CGROUP          NSEMS OTIME    CTIME
s       196608   1038146433 --rw-r--r-- ricardo  ricardo  ricardo  ricardo             7 no-entry 20:23:29

The filtering is the same as done by ipcs:

Format string adapted from:

Copy link
Member

@bsdimp bsdimp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of poorly handled races I think?

VexedUXR and others added 3 commits May 11, 2024 13:32
In some cases, the USB_QUIRK_VP macro was being misused. Instead of
setting quirks to the intended value, the first two supplied quirks
would go into lo_rev and hi_rev. Replace it with USB_QUIRK_VO which only
takes the needed args. This also makes the Dummy products, which where
being used to correctly set vendor only quirks, not necessary.

Reviewed by: imp
Pull Request: freebsd#1153
Seperate usb quirks that target specific revisions from those that
dont. Alot of the quirks dont use lo_rev and hi_rev, so we can abstract
the 0x0000, 0xffff into a macro.

[[ This commit is a bit more churn than we like. I carefully reviewed
   each one and they are all good. The end product is better -- imp ]]

Reviewed by: imp
Pull Request: freebsd#1153
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp
Pull Request: freebsd#1218
@freebsd-git freebsd-git merged commit 099a81a into freebsd:main May 11, 2024
7 of 9 checks passed
@bsdimp
Copy link
Member

bsdimp commented May 12, 2024

I've had to revert this. There's a race and some issues with it that need to be resolved. Please either reopen with them fixed, or create a new review and reference this one in the first comment.

msqids[id].u.msg_stime,
msqids[id].u.msg_rtime,
msqids[id].u.msg_ctime);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These times need to be cast to (intmax_t) and %jd should be used to print them.

if (msgmni != msginfo.msgmni) {
free(msqids, M_TEMP);
goto again;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is msginfo.msgmni changing? It would be better to just reply on the sysctl to get the data. It will return ENOMEM when the data size is too small. The case where it's too big is now handled corrected.

semids[id].u.sem_perm.cgid,
semids[id].u.sem_otime,
semids[id].u.sem_ctime);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above: intmax_t cast.

free(semids, M_TEMP);
goto again;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. I think removing this check and keying off ENOMEM in the sysctl return value is the cleaner way to deal with this since we don't seem to have a cleaner, race-free interface to extract this info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. I think removing this check and keying off ENOMEM in the sysctl return value is the cleaner way to deal with this since we don't seem to have a cleaner, race-free interface to extract this info.

What do you mean by "keying off ENOMEM" ?

free(shmids, M_TEMP);
goto again;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same again race.

shmids[id].u.shm_atime,
shmids[id].u.shm_dtime,
shmids[id].u.shm_ctime,
0, 0); /* XXX rss & swp are not supported */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same again intmax_t cast.

if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) != 0)
sbuf_printf(sb,
"%10d %10lu %4o %21lu %5u %5u %5u %5u %5u %5u %5u %10ld %10ld %10ld %21d %21d\n",
(int) shmids[id].u.shm_perm.key,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the %21lu should be %21zu because this is a size_t.

@bsdimp
Copy link
Member

bsdimp commented May 12, 2024

Also from kib: "The recheck is more problematic, I do agree. Also, I realized one more
issue there: the data structures like msginfo are from sysvmsg.ko modules.
Then, the change make linprocfs depending on the sysv*.ko, but this is
not directly recorded with MODULE_DEPENDS(). It worked because GENERIC
compiles SysV support statically."

@ricardobranco777
Copy link
Contributor Author

Also from kib: "The recheck is more problematic, I do agree. Also, I realized one more issue there: the data structures like msginfo are from sysvmsg.ko modules. Then, the change make linprocfs depending on the sysv*.ko, but this is not directly recorded with MODULE_DEPENDS(). It worked because GENERIC compiles SysV support statically."

We already have these at EOF:

MODULE_DEPEND(linprocfs, sysvmsg, 1, 1, 1);
MODULE_DEPEND(linprocfs, sysvsem, 1, 1, 1);
MODULE_DEPEND(linprocfs, sysvshm, 1, 1, 1);

@ricardobranco777 ricardobranco777 deleted the linprocfs_sysvipc branch May 16, 2024 21:48
bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this pull request Aug 28, 2024
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp
Pull Request: freebsd/freebsd-src#1218
bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this pull request Aug 29, 2024
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed by: imp
Pull Request: freebsd/freebsd-src#1218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants