From nobody Sun Feb 11 01:52:46 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TXVwG531yz596bC; Sun, 11 Feb 2024 01:52:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TXVwG3BtMz45dc; Sun, 11 Feb 2024 01:52:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707616366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H7L0glSPnwoP9iq6Ve0jb6sZL45r5ykliJ1e1zA/qBc=; b=Uh+Oesr9J4Zp/ZHcOliXotIU2gON76sGX+YKhB/PRADRaNIqI/PBMQsliHsQBQ03SI2wIH gzxfUs+Mo5R4adVF6Cx/Loyyy8e51BB1b99m2ZrBdSRA3T//vv3oY+986QIk/KT4DNG1RW 9e/7SZVsaiEh59el6KSsIJycrujW3AI9LrgsofgiCRrZ73fbtBQoiOiBfzDRK9XVtAdXHO 04Zixo+iE2OMkxyz3HLX+2Jgc7jZxeKSWX5l5o/5PSvFl527muLPH4wXZLyxJ/sbU9vi/m /XbvD3JVdYsAjwpBF3NdgWsI/5ViA9bMtrTv6w2Qgb/lX8eyKcOoXdMGkdgUHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707616366; a=rsa-sha256; cv=none; b=D67BSwY1NxspUg8bXwE6c4hqrlZgFvLnQPDnDiyZISXHlHVPsN8AmIf+zvu4LUJQbDs3cD mBR10Q21MvdHcQVUvW0xjb2P0NbuENX4FAj+xleUO6+8takCLHx1CnnJOneTszZ4zOSMdb iktdbk/FPGK9DgNHBiEjpcZqhCic2JPchleTTTwhLYBWTIK8vijC0RvnET5dllhYwzbo+h kp4yyCQ8+nvxjt+PR0lyWI+vRmZdtbZO6VmIn8Hw1Q+Vn8OXkh36vNy5HnxurAWwmC4XOL IHV73nWEc1wz4Qxd/pglslEbFRnYSOCumFRXX0RKsG+PPRU9dssrkSL3tZQokQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707616366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H7L0glSPnwoP9iq6Ve0jb6sZL45r5ykliJ1e1zA/qBc=; b=G5xg1zSgBnmDBTdXlzR3AJb4hjuhsFFjIPKcHu73zFQNMlL1Armeb6W2Q3JnF94IvwmdJM gX1cuUHzLiNjTUSKkpZx+aQhSVbPOjH40jArdOaFJle7yo60S6WQVfHjqSpd1QQumue0Ak SsnoTf4ZHV/WPOOw3xjLnXJ6ikSxZM4kc5NQCvSm/JiDyK5dOzkxRyw9IJTYvOUY+1Yndc a61wtgl7Dl17dCs9ej91EMt5Y5+patYRT3b6YBcmzdNv14GcBsYtVVcHbwegKBdsAu6FU7 kgP5Q6sdguHD/t1R+b2kgTAELj99XqgEni6stYupldLvhIBQtvDgn+hpWNS1dQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TXVwG271Tzgjs; Sun, 11 Feb 2024 01:52:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41B1qkVL089375; Sun, 11 Feb 2024 01:52:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41B1qklO089372; Sun, 11 Feb 2024 01:52:46 GMT (envelope-from git) Date: Sun, 11 Feb 2024 01:52:46 GMT Message-Id: <202402110152.41B1qklO089372@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 096fe82004b1 - stable/13 - Add kcmp(2) kernel bits List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 096fe82004b1ff8671c0dc1c0279d5b34873efb6 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=096fe82004b1ff8671c0dc1c0279d5b34873efb6 commit 096fe82004b1ff8671c0dc1c0279d5b34873efb6 Author: Konstantin Belousov AuthorDate: 2024-01-19 19:49:36 +0000 Commit: Konstantin Belousov CommitDate: 2024-02-11 01:40:29 +0000 Add kcmp(2) kernel bits (cherry picked from commit d8decc9ae31af7ffc77276c89639fb13eb1020cc) --- sys/compat/freebsd32/syscalls.master | 8 ++++ sys/kern/sys_generic.c | 87 ++++++++++++++++++++++++++++++++++++ sys/kern/syscalls.master | 13 +++++- sys/sys/syscallsubr.h | 2 + sys/sys/systm.h | 2 + sys/sys/unistd.h | 7 +++ 6 files changed, 118 insertions(+), 1 deletion(-) diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/syscalls.master index 06216bc4cca7..bf4480d3daba 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -1178,4 +1178,12 @@ 580 AUE_NULL UNIMPL fspacectl 581 AUE_NULL NOPROTO { int sched_getcpu(void); } 582 AUE_NULL UNIMPL swapoff +583 AUE_NULL UNIMPL kqueuex +584 AUE_NULL UNIMPL membarrier +585 AUE_NULL UNIMPL timerfd_create +586 AUE_NULL UNIMPL timerfd_gettime +587 AUE_NULL UNIMPL timerfd_settime +588 AUE_NULL NOPROTO { int kcmp(pid_t pid1, pid_t pid2, int type, \ + u_int idx1, u_int idx2); } + ; vim: syntax=off diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 36c09ab02730..cbb17026894b 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -2003,3 +2004,89 @@ kern_posix_error(struct thread *td, int error) td->td_retval[0] = error; return (0); } + +int +kcmp_cmp(uintptr_t a, uintptr_t b) +{ + if (a == b) + return (0); + else if (a < b) + return (1); + return (2); +} + +static int +kcmp_pget(struct thread *td, pid_t pid, struct proc **pp) +{ + if (pid == td->td_proc->p_pid) { + *pp = td->td_proc; + return (0); + } + return (pget(pid, PGET_CANDEBUG | PGET_NOTWEXIT | PGET_HOLD, pp)); +} + +int +kern_kcmp(struct thread *td, pid_t pid1, pid_t pid2, int type, + uintptr_t idx1, uintptr_t idx2) +{ + struct proc *p1, *p2; + struct file *fp1, *fp2; + int error, res; + + res = -1; + p1 = p2 = NULL; + error = kcmp_pget(td, pid1, &p1); + if (error == 0) + error = kcmp_pget(td, pid2, &p2); + if (error != 0) + goto out; + + switch (type) { + case KCMP_FILE: + case KCMP_FILEOBJ: + error = fget_remote(td, p1, idx1, &fp1); + if (error == 0) { + error = fget_remote(td, p2, idx2, &fp2); + if (error == 0) { + if (type == KCMP_FILEOBJ) + res = fo_cmp(fp1, fp2, td); + else + res = kcmp_cmp((uintptr_t)fp1, + (uintptr_t)fp2); + fdrop(fp2, td); + } + fdrop(fp1, td); + } + break; + case KCMP_FILES: + res = kcmp_cmp((uintptr_t)p1->p_fd, (uintptr_t)p2->p_fd); + break; + case KCMP_SIGHAND: + res = kcmp_cmp((uintptr_t)p1->p_sigacts, + (uintptr_t)p2->p_sigacts); + break; + case KCMP_VM: + res = kcmp_cmp((uintptr_t)p1->p_vmspace, + (uintptr_t)p2->p_vmspace); + break; + default: + error = EINVAL; + break; + } + +out: + if (p1 != NULL && p1 != td->td_proc) + PRELE(p1); + if (p2 != NULL && p2 != td->td_proc) + PRELE(p2); + + td->td_retval[0] = res; + return (error); +} + +int +sys_kcmp(struct thread *td, struct kcmp_args *uap) +{ + return (kern_kcmp(td, uap->pid1, uap->pid2, uap->type, + uap->idx1, uap->idx2)); +} diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index ace9ad5268b5..117dac7e992f 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -3294,7 +3294,18 @@ int cpu_id ); } - +585 AUE_NULL UNIMPL timerfd_create +586 AUE_NULL UNIMPL timerfd_gettime +587 AUE_NULL UNIMPL timerfd_settime +588 AUE_NULL STD { + int kcmp( + pid_t pid1, + pid_t pid2, + int type, + uintptr_t idx1, + uintptr_t idx2 + ); + } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 77c16d8fffc0..c0ae30dff3c7 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -177,6 +177,8 @@ int kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data); int kern_jail(struct thread *td, struct jail *j); int kern_jail_get(struct thread *td, struct uio *options, int flags); int kern_jail_set(struct thread *td, struct uio *options, int flags); +int kern_kcmp(struct thread *td, pid_t pid1, pid_t pid2, int type, + uintptr_t idx1, uintptr_t idx2); int kern_kevent(struct thread *td, int fd, int nchanges, int nevents, struct kevent_copyops *k_ops, const struct timespec *timeout); int kern_kevent_anonymous(struct thread *td, int nevents, diff --git a/sys/sys/systm.h b/sys/sys/systm.h index bffa4c93c8f2..dcfe84e91cc2 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -455,6 +455,8 @@ int poll_no_poll(int events); /* XXX: Should be void nanodelay(u_int nsec); */ void DELAY(int usec); +int kcmp_cmp(uintptr_t a, uintptr_t b); + /* Root mount holdback API */ struct root_hold_token { int flags; diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index 6adca008f955..93c6658a009a 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -196,6 +196,13 @@ RFPROCDESC | RFSPAWN | RFPPWAIT) #define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC) +/* kcmp() options. */ +#define KCMP_FILE 100 +#define KCMP_FILEOBJ 101 +#define KCMP_FILES 102 +#define KCMP_SIGHAND 103 +#define KCMP_VM 104 + #define SWAPOFF_FORCE 0x00000001 /*