From owner-svn-src-head@freebsd.org Tue Nov 7 15:14:49 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 389ADE5B6EF; Tue, 7 Nov 2017 15:14:49 +0000 (UTC) (envelope-from robak@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [96.47.72.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 02D796DE7B; Tue, 7 Nov 2017 15:14:48 +0000 (UTC) (envelope-from robak@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vA7FDXZf035040; Tue, 7 Nov 2017 15:13:33 GMT (envelope-from robak@FreeBSD.org) Received: (from robak@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vA7FDXHa035038; Tue, 7 Nov 2017 15:13:33 GMT (envelope-from robak@FreeBSD.org) Message-Id: <201711071513.vA7FDXHa035038@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: robak set sender to robak@FreeBSD.org using -f From: Bartek Rutkowski Date: Tue, 7 Nov 2017 15:13:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325516 - in head: lib/libc/gen sys/kern X-SVN-Group: head X-SVN-Commit-Author: robak X-SVN-Commit-Paths: in head: lib/libc/gen sys/kern X-SVN-Commit-Revision: 325516 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Nov 2017 15:14:49 -0000 Author: robak (ports committer) Date: Tue Nov 7 15:13:32 2017 New Revision: 325516 URL: https://svnweb.freebsd.org/changeset/base/325516 Log: Make sysctl_kern_proc_umask execute fast path when requested pid in curproc->p_pid or 0, avoiding unnecessary locking. Update libc consumer to skip calling getpid(). Submitted by: Pawel Biernacki Reviewed by: mjg, robak Approved by: mjg Sponsored by: Mysterious Code Ltd. Differential Revision: D12972 Modified: head/lib/libc/gen/setmode.c head/sys/kern/kern_proc.c Modified: head/lib/libc/gen/setmode.c ============================================================================== --- head/lib/libc/gen/setmode.c Tue Nov 7 15:01:38 2017 (r325515) +++ head/lib/libc/gen/setmode.c Tue Nov 7 15:13:32 2017 (r325516) @@ -356,7 +356,7 @@ getumask(void) * security.bsd.unprivileged_proc_debug is set to 0. */ len = sizeof(smask); - if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() }, + if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, 0 }, 4, &smask, &len, NULL, 0) == 0) return (smask); Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Tue Nov 7 15:01:38 2017 (r325515) +++ head/sys/kern/kern_proc.c Tue Nov 7 15:13:32 2017 (r325516) @@ -2770,18 +2770,25 @@ sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS) struct proc *p; int error; u_short fd_cmask; + pid_t pid; if (namelen != 1) return (EINVAL); - error = pget((pid_t)name[0], PGET_WANTREAD, &p); + pid = (pid_t)name[0]; + p = curproc; + if (pid == p->p_pid || pid == 0) { + fd_cmask = p->p_fd->fd_cmask; + goto out; + } + + error = pget(pid, PGET_WANTREAD, &p); if (error != 0) return (error); - FILEDESC_SLOCK(p->p_fd); fd_cmask = p->p_fd->fd_cmask; - FILEDESC_SUNLOCK(p->p_fd); PRELE(p); +out: error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask)); return (error); }