From nobody Mon Oct 07 08:25:01 2024 X-Original-To: dev-commits-src-main@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 4XMXJY6fxNz5XVww; Mon, 07 Oct 2024 08:25:01 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XMXJY54MNz4sfV; Mon, 7 Oct 2024 08:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728289501; 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=nTNqw6JHDEKO5VurjkLm6QqLQCjJZwcudG2/j7MDxBo=; b=ApQegMbvCZSVyqobgqx13PVRt5Xbrh1jCjJrrshYzQLqwXIBn78rY2oPsOfgdqVeq88nqE S7tgmW755VNq1dvJte9TDLjDPw4xMTB17j7UGUsCZcWJTVB/w+jue6LgMKsRg+RjufibyZ pdxIdkE2+501jjZ8mfHCLVqWZNKaK9KyCZ8gYTSBv7clk5hpeWf48eUuqf+9Bik1PFYZ3j Kn/VSefnnvAxpsCLngG0x4Si3o8JJkKCMWYWovN+bytml8p42qJ2Qt45YL/FlZow5qVSFf mXgGN7uLj3XQw+uSC6Rj3nF/pgJoDEAhLKg6nnm61+Axc8HzGflSA0yXmY+S0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728289501; 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=nTNqw6JHDEKO5VurjkLm6QqLQCjJZwcudG2/j7MDxBo=; b=OhWxBSD9q3TJrDmo5kotzp0S3W8501SZwQtaic5fawVnGMVWUrUGKKQ7xGH3CSpJKieLCQ wed0J+I+YKfoBILZKahWoZCpQ9sr5CwxfZCHRI+0UggUmxg9K8c1YQySH2AG1qNUXc7THj Gg1w09h47jaG4KXiLawACyrNuqKZYIi46C2dcw0gng3dF3HgIiCnI3o7pHCDwdrlVVSM+o Xpqx/OwL7X7NTI9r9Ifaar0CDmiXgikegOb2qweYIwjMG/pWVc+V3ZkQ3dkZzWRB25yIW4 B1OVNgUYqaJ1t5k64PwtkYh4OvPIcKFW2W4S1qEIA2msrhytq3Ne2LSAlzyRlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728289501; a=rsa-sha256; cv=none; b=vlebvSWDqsx4yyCgULu1d7yxEkvcRcSgrQLTjVAnJY+0v1a3liRugcGZaozefvr+b7sq49 Fqk0RGDaHBs3Zh/TSFtQPYoZcmcEvUOZcOQgSWc1C+4ZbQ3qmwuxcpglyQst8dYxzSR2a+ CcOPwUX2Sta75/47eg+rpeZVsJ1UgZ5TjPoAdGfbNFLu0g3n5WniIGZAvAQnfdx0fhGsx/ 4wIIgRcQPH/sncpsiPn+k+qiHFYV+XtgxEkMHfGbqdHPATm3n7BNN5ZJjOcpJ/psfnYfP+ Ak6hfDS0yvy8sGGp9Y6u43U2UKQHXEQl8AExz/UNDsdVp8dbXAOHr55Bx9CQVg== 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 4XMXJY3JNkzfMN; Mon, 7 Oct 2024 08:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4978P1NR011904; Mon, 7 Oct 2024 08:25:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4978P1jA011901; Mon, 7 Oct 2024 08:25:01 GMT (envelope-from git) Date: Mon, 7 Oct 2024 08:25:01 GMT Message-Id: <202410070825.4978P1jA011901@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: b72029589e64 - main - sysvshm: add shmobjinfo() function to find key/seq of the segment backed by obj List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b72029589e64e04b8f9714ad8535b723276e2e02 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b72029589e64e04b8f9714ad8535b723276e2e02 commit b72029589e64e04b8f9714ad8535b723276e2e02 Author: Konstantin Belousov AuthorDate: 2024-10-05 09:14:15 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-07 08:22:12 +0000 sysvshm: add shmobjinfo() function to find key/seq of the segment backed by obj Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46959 --- sys/kern/sysv_ipc.c | 11 +++++++++++ sys/kern/sysv_shm.c | 27 +++++++++++++++++++++++++++ sys/sys/ipc.h | 3 +++ sys/sys/shm.h | 2 ++ 4 files changed, 43 insertions(+) diff --git a/sys/kern/sysv_ipc.c b/sys/kern/sysv_ipc.c index dc7cac13fdd8..7240d7cd7150 100644 --- a/sys/kern/sysv_ipc.c +++ b/sys/kern/sysv_ipc.c @@ -50,6 +50,8 @@ #ifndef SYSVSHM void (*shmfork_hook)(struct proc *, struct proc *) = NULL; void (*shmexit_hook)(struct vmspace *) = NULL; +void (*shmobjinfo_hook)(struct vm_object *, key_t *key, + unsigned short *seq) = NULL; /* called from kern_fork.c */ void @@ -66,6 +68,15 @@ shmexit(struct vmspace *vm) if (shmexit_hook != NULL) shmexit_hook(vm); } + +void +shmobjinfo(struct vm_object *obj, key_t *key, unsigned short *seq) +{ + *key = 0; /* For non-present sysvshm.ko */ + *seq = 0; + if (shmobjinfo_hook != NULL) + shmobjinfo_hook(obj, key, seq); +} #endif /* diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 4dbe77f19b07..60e3fe92a4b7 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -133,6 +133,8 @@ static int shmunload(void); #ifndef SYSVSHM static void shmexit_myhook(struct vmspace *vm); static void shmfork_myhook(struct proc *p1, struct proc *p2); +static void shmobjinfo_myhook(vm_object_t obj, key_t *key, + unsigned short *seq); #endif static int sysctl_shmsegs(SYSCTL_HANDLER_ARGS); static void shm_remove(struct shmid_kernel *, int); @@ -856,6 +858,29 @@ shmexit_myhook(struct vmspace *vm) } } +#ifdef SYSVSHM +void +shmobjinfo(vm_object_t obj, key_t *key, unsigned short *seq) +#else +static void +shmobjinfo_myhook(vm_object_t obj, key_t *key, unsigned short *seq) +#endif +{ + int i; + + *key = 0; /* For statically compiled-in sysv_shm.c */ + *seq = 0; + SYSVSHM_LOCK(); + for (i = 0; i < shmalloced; i++) { + if (shmsegs[i].object == obj) { + *key = shmsegs[i].u.shm_perm.key; + *seq = shmsegs[i].u.shm_perm.seq; + break; + } + } + SYSVSHM_UNLOCK(); +} + static void shmrealloc(void) { @@ -962,6 +987,7 @@ shminit(void) #ifndef SYSVSHM shmexit_hook = &shmexit_myhook; shmfork_hook = &shmfork_myhook; + shmobjinfo_hook = &shmobjinfo_myhook; #endif /* Set current prisons according to their allow.sysvipc. */ @@ -1029,6 +1055,7 @@ shmunload(void) #ifndef SYSVSHM shmexit_hook = NULL; shmfork_hook = NULL; + shmobjinfo_hook = NULL; #endif sx_destroy(&sysvshmsx); return (0); diff --git a/sys/sys/ipc.h b/sys/sys/ipc.h index ab4d2bdb567f..e945d385ae33 100644 --- a/sys/sys/ipc.h +++ b/sys/sys/ipc.h @@ -127,6 +127,7 @@ struct ipc_perm { struct thread; struct proc; struct vmspace; +struct vm_object; #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) @@ -137,6 +138,8 @@ void ipcperm_new2old(struct ipc_perm *, struct ipc_perm_old *); int ipcperm(struct thread *, struct ipc_perm *, int); extern void (*shmfork_hook)(struct proc *, struct proc *); extern void (*shmexit_hook)(struct vmspace *); +extern void (*shmobjinfo_hook)(struct vm_object *obj, key_t *key, + unsigned short *seq); #else /* ! _KERNEL */ diff --git a/sys/sys/shm.h b/sys/sys/shm.h index df32230dcdc7..d50168a087ba 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -149,6 +149,7 @@ struct shm_info { #ifdef _KERNEL struct proc; struct vmspace; +struct vm_object; extern struct shminfo shminfo; @@ -158,6 +159,7 @@ extern struct shminfo shminfo; void shmexit(struct vmspace *); void shmfork(struct proc *, struct proc *); +void shmobjinfo(struct vm_object *obj, key_t *key, unsigned short *seq); int kern_get_shmsegs(struct thread *td, struct shmid_kernel **res, size_t *sz);