From nobody Tue Oct 15 15:05:24 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 4XScpr3W1bz5YYbR; Tue, 15 Oct 2024 15:05:24 +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 4XScpr1B0wz45xW; Tue, 15 Oct 2024 15:05:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729004724; 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=W+tbEINcGT5kjupsqHFRqB1l0DQK6Z4ovxop8srTYks=; b=vPYi0ZN4Z3v+UomkroRLnBZNhDcOGrMSi259Xrmov1ip+JOIIEjvMlbSqPEmlqNcmXCjoq KRKNMvctGUdO2NGZ97ZcfnFvgjXTFLByPHD8AHHs7My3wpNyAGLXww0MvxZ5uG4iYSTn16 ixRRqGJXV/ojpQV85zulZ06FmQ4EKwZGC1gAC40+jFWMRa60CQ5dKO272WYHkUT55vDDWA yWKnhrH2rLk6Q8Hk+eKq0ANBns7UDttQ/dGMIo6x1xJVvGN6Jn11/qknyC5VS2bytgak56 WkFoOJp1wjUfO/vNEclLc2c78ZSb4BccPzcYIGY/Qv5nCs1KZ030namxEG4kHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729004724; 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=W+tbEINcGT5kjupsqHFRqB1l0DQK6Z4ovxop8srTYks=; b=ypc6W2ageynoUc6QZdkXEZjwJk8SCqbwQPgxDnEZJHPGMtYzdeiPg07vERgdcZgCLuiOCr icyZMQ+KPMdxuapkU9xLBaCr/C5AY2drZTRdCUbIpq3Dpi/DRQI7Y1BlCjp+rB8yGaincF Rkvaw+QIaBIn+4M8GMSztkq/PdlMl8bYQjRtAEJXuj+TX8YZG4C6mY9Dp0CTrzo9+AMytJ 33KsBL0fkhiHecTUpMq9LyAIEIoCFtnkj3pk6OtWm3WOHZY3Kelm1y4U0ABRJkbwgf7Ha6 1psL6pG++IhZknFmmJNT3VM92LgKQFCdFvlO5wxoYksca6Caz79AgWreZ3td4g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729004724; a=rsa-sha256; cv=none; b=d+8/CqjC/3KZJpuhkPFIyQO/izscLzYOkkM7N/uYXjMQWT63C7mpxcvXH/epeihm/e16RW c1D2H30xQ3+GO/yF0XGD1jKaD0sj3DTS+PWX2VwR9iApds5gzdk/hwsIiZi4ISnaH36GaC vko/poLsixVmOb+DQ3D8Y6iLSGHPCYEQOHjyklHvrz9OVXPPHVLBanufawDz6F+/MqXBbQ 8jPAlEZEf3r4HkMglcnHblvN8nQ0QjQIoKDVVSO7k1YSChxSxhC0c0Izz0GBGrguulrnCZ 3gsMJsDfIkmPUcv5iOE7A6W3G+2szwUypnlh1dgBknk3+nHlGDCauL7iPXUj2g== 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 4XScpr0nSXzRT4; Tue, 15 Oct 2024 15:05:24 +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 49FF5OZe089172; Tue, 15 Oct 2024 15:05:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49FF5ODQ089169; Tue, 15 Oct 2024 15:05:24 GMT (envelope-from git) Date: Tue, 15 Oct 2024 15:05:24 GMT Message-Id: <202410151505.49FF5ODQ089169@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: 30a5ba9ded03 - stable/14 - sysvshm: add shmobjinfo() function to find key/seq of the segment backed by obj 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/14 X-Git-Reftype: branch X-Git-Commit: 30a5ba9ded0321410345cb52cfe8ad0301f7a199 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=30a5ba9ded0321410345cb52cfe8ad0301f7a199 commit 30a5ba9ded0321410345cb52cfe8ad0301f7a199 Author: Konstantin Belousov AuthorDate: 2024-10-05 09:14:15 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-15 14:50:16 +0000 sysvshm: add shmobjinfo() function to find key/seq of the segment backed by obj (cherry picked from commit b72029589e64e04b8f9714ad8535b723276e2e02) --- 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 95a01be20eec..ce0f550900fb 100644 --- a/sys/sys/ipc.h +++ b/sys/sys/ipc.h @@ -129,6 +129,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) @@ -139,6 +140,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 a1aa6ca54c60..15d08becc072 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);