From nobody Fri May 06 17:03:34 2022 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 3EE381A825A5; Fri, 6 May 2022 17:03:35 +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 4KvxjL4HYMz4TQb; Fri, 6 May 2022 17:03:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651856614; 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=u//uv+MWBbxrYNcTeVXvlf5xG+xPKLwTfhgDlzqmgzg=; b=VhHK8c34QS5YPxqDQVLm4aiX1Qa9vUK4d4CDJNKx1DLkzaKcoOIEJpFrhi1Y9/AUHt5ih8 KTqQ0r26b2ClJ5Z8E5XvyDeSk0939QfN+UWBzutc421gz/c4jyfWUpVHdqOqgWuiOVhg+m /y6TTTRHmLYqWIiYRlud05pibd0qKnAeljhjLhXH56RGZotoPzvxTuULJ3cm97O0/5sJds 7SIRdPob6CnpYhqDKf19WNzjRcsCjC+RId4jKGQFTZ4V2TY+xSzFnXFm2quDZDcdaGMGWC kB3Ch27gqDvkw3ftTuE9Okx/p62gVesFyY2+WR4W0RfVY/QGTniF8Y/xRSHvjw== 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 431BF1F675; Fri, 6 May 2022 17:03:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 246H3Yf0058843; Fri, 6 May 2022 17:03:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 246H3YJF058842; Fri, 6 May 2022 17:03:34 GMT (envelope-from git) Date: Fri, 6 May 2022 17:03:34 GMT Message-Id: <202205061703.246H3YJF058842@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: f04534f5c84e - main - sysvsem: Add a timeout argument to the semop. 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f04534f5c84e58009efbb7f378803da3f33585b9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651856614; 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=u//uv+MWBbxrYNcTeVXvlf5xG+xPKLwTfhgDlzqmgzg=; b=tBI9/4dddGf2S3bcYctwDFrMiWt5t3vDurPR+P3UdZY+Ywf1KqReHrQEwR/kFzXjmSV3e7 hmapkdDQS89107rPJt4uvsqgvJCsXHlQ97//yo3+rNbWUjnNxk6xN/tZ4WwYDe6Ovf2iIz Wdmei/zCV1a2kFxh75Ri8ifjwqf0lR7HEOSRPIWf+TFYdRvY+KDq+tVMuLOu3EDLRP0lUr zmo/CeSQDX+Ul4xaUJzToUuGL3TQUg57hEhOBQIF8bkftC59YGNNs3b3qBT8xNi62nh8Bi dlEUkfhXv2+lFSMml1YH82boLCfrov/b1cGckPgR5LfoBf6P9wXD5RH1y2uiuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651856614; a=rsa-sha256; cv=none; b=lJgFxMTES6dll7LMkSg3TvIiu1hC60Ag4ezk4amvI2yc5ZS2PTl3rmTVbeQ2P+00pJ6EVu SF0R8Ksvg+l1NMF2Fs1fRYzWclPwvue6hFlP+XSgZfmZm6KZgyDyG/YHI0Fvk6/Ysqy1d7 8eHYMkk4IyuN6l/dHAIJmhAwvYDRAdnjimeIPw2ZVFtk6qEx7De/aMQoq/dFizq5q6K0wx r4y5kqX1p2AzaBROPvbj7ftr6MBD62d38CrBQiExsOUZMRFb3PUaNK2M9RXlk+NK1+KLum F98ytOzO7qrcKLbIDJ68cRUGDBruu5gb/gKgRUBPBKIpwNF8ZoQ2BCZzsxOisw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=f04534f5c84e58009efbb7f378803da3f33585b9 commit f04534f5c84e58009efbb7f378803da3f33585b9 Author: Dmitry Chagin AuthorDate: 2022-05-06 16:51:48 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-06 16:51:48 +0000 sysvsem: Add a timeout argument to the semop. For future use in the Linux emulation layer for the semtimedop syscall split the sys_semop syscall into two counterparts and add struct timespec *timeout argument to the last one. Reviewed by: jhb, kib Differential revision: https://reviews.freebsd.org/D35121 MFC after: 2 weeks --- sys/kern/sysv_sem.c | 50 ++++++++++++++++++++++++++++++++++++++------------ sys/sys/syscallsubr.h | 3 +++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index b55ef00c9c70..d489821e983b 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1097,11 +1097,18 @@ struct semop_args { #endif int sys_semop(struct thread *td, struct semop_args *uap) +{ + + return (kern_semop(td, uap->semid, uap->sops, uap->nsops, NULL)); +} + +int +kern_semop(struct thread *td, int usemid, struct sembuf *usops, + size_t nsops, struct timespec *timeout) { #define SMALL_SOPS 8 struct sembuf small_sops[SMALL_SOPS]; - int semid = uap->semid; - size_t nsops = uap->nsops; + int semid; struct prison *rpr; struct sembuf *sops; struct semid_kernel *semakptr; @@ -1109,6 +1116,7 @@ sys_semop(struct thread *td, struct semop_args *uap) struct sem *semptr = NULL; struct sem_undo *suptr; struct mtx *sema_mtxp; + sbintime_t sbt, precision; size_t i, j, k; int error; int do_wakeup, do_undos; @@ -1117,18 +1125,35 @@ sys_semop(struct thread *td, struct semop_args *uap) #ifdef SEM_DEBUG sops = NULL; #endif - DPRINTF(("call to semop(%d, %p, %u)\n", semid, sops, nsops)); + DPRINTF(("call to semop(%d, %p, %u)\n", usemid, usops, nsops)); - AUDIT_ARG_SVIPC_ID(semid); + AUDIT_ARG_SVIPC_ID(usemid); rpr = sem_find_prison(td->td_ucred); if (sem == NULL) return (ENOSYS); - semid = IPCID_TO_IX(semid); /* Convert back to zero origin */ + semid = IPCID_TO_IX(usemid); /* Convert back to zero origin */ if (semid < 0 || semid >= seminfo.semmni) return (EINVAL); + if (timeout != NULL) { + if (!timespecvalid_interval(timeout)) + return (EINVAL); + precision = 0; + if (timespecisset(timeout)) { + if (timeout->tv_sec < INT32_MAX / 2) { + precision = tstosbt(*timeout); + if (TIMESEL(&sbt, precision)) + sbt += tc_tick_sbt; + sbt += precision; + precision >>= tc_precexp; + } else + sbt = 0; + } else + sbt = -1; + } else + precision = sbt = 0; /* Allocate memory for sem_ops */ if (nsops <= SMALL_SOPS) @@ -1152,9 +1177,9 @@ sys_semop(struct thread *td, struct semop_args *uap) sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK); } - if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) { + if ((error = copyin(usops, sops, nsops * sizeof(sops[0]))) != 0) { DPRINTF(("error = %d from copyin(%p, %p, %d)\n", error, - uap->sops, sops, nsops * sizeof(sops[0]))); + usops, sops, nsops * sizeof(sops[0]))); if (sops != small_sops) free(sops, M_TEMP); return (error); @@ -1168,7 +1193,7 @@ sys_semop(struct thread *td, struct semop_args *uap) goto done2; } seq = semakptr->u.sem_perm.seq; - if (seq != IPCID_TO_SEQ(uap->semid)) { + if (seq != IPCID_TO_SEQ(usemid)) { error = EINVAL; goto done2; } @@ -1286,8 +1311,8 @@ sys_semop(struct thread *td, struct semop_args *uap) semptr->semncnt++; DPRINTF(("semop: good night!\n")); - error = msleep(semakptr, sema_mtxp, (PZERO - 4) | PCATCH, - "semwait", 0); + error = msleep_sbt(semakptr, sema_mtxp, (PZERO - 4) | PCATCH, + "semwait", sbt, precision, C_ABSOLUTE); DPRINTF(("semop: good morning (error=%d)!\n", error)); /* return code is checked below, after sem[nz]cnt-- */ @@ -1296,7 +1321,7 @@ sys_semop(struct thread *td, struct semop_args *uap) */ seq = semakptr->u.sem_perm.seq; if ((semakptr->u.sem_perm.mode & SEM_ALLOC) == 0 || - seq != IPCID_TO_SEQ(uap->semid)) { + seq != IPCID_TO_SEQ(usemid)) { error = EIDRM; goto done2; } @@ -1323,7 +1348,8 @@ sys_semop(struct thread *td, struct semop_args *uap) * need to decrement sem[nz]cnt either way.) */ if (error != 0) { - error = EINTR; + if (error == ERESTART) + error = EINTR; goto done2; } DPRINTF(("semop: good morning!\n")); diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index c66a34536444..1f5f4cd2369d 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -57,6 +57,7 @@ struct ogetdirentries_args; struct rlimit; struct rusage; struct sched_param; +struct sembuf; union semun; struct sockaddr; struct spacectl_range; @@ -328,6 +329,8 @@ int kern_ktimer_settime(struct thread *td, int timer_id, int flags, int kern_ktimer_gettime(struct thread *td, int timer_id, struct itimerspec *val); int kern_ktimer_getoverrun(struct thread *td, int timer_id); +int kern_semop(struct thread *td, int usemid, struct sembuf *usops, + size_t nsops, struct timespec *timeout); int kern_thr_alloc(struct proc *, int pages, struct thread **); int kern_thr_exit(struct thread *td); int kern_thr_new(struct thread *td, struct thr_param *param);