From owner-svn-src-head@freebsd.org Fri Oct 12 23:48:11 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 51FD610CF0F8; Fri, 12 Oct 2018 23:48:11 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 02BEF7BC66; Fri, 12 Oct 2018 23:48:11 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F1D322669B; Fri, 12 Oct 2018 23:48:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9CNmARU053830; Fri, 12 Oct 2018 23:48:10 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9CNmA3w053827; Fri, 12 Oct 2018 23:48:10 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201810122348.w9CNmA3w053827@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 12 Oct 2018 23:48:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339341 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 339341 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.27 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: Fri, 12 Oct 2018 23:48:11 -0000 Author: mjg Date: Fri Oct 12 23:48:10 2018 New Revision: 339341 URL: https://svnweb.freebsd.org/changeset/base/339341 Log: capsicum: provide cap_rights_fde_inline Reading caps is in the hot path (on each successful fd lookup), but completely unnecessarily requires a function call. Approved by: re (gjb) Sponsored by: The FreeBSD Foundation Modified: head/sys/kern/kern_descrip.c head/sys/kern/sys_capability.c head/sys/sys/capsicum.h Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Fri Oct 12 22:57:52 2018 (r339340) +++ head/sys/kern/kern_descrip.c Fri Oct 12 23:48:10 2018 (r339341) @@ -2560,7 +2560,7 @@ fget_cap_locked(struct filedesc *fdp, int fd, cap_righ } #ifdef CAPABILITIES - error = cap_check(cap_rights_fde(fde), needrightsp); + error = cap_check(cap_rights_fde_inline(fde), needrightsp); if (error != 0) goto out; #endif @@ -2651,7 +2651,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights #ifdef CAPABILITIES seq = seq_read(fd_seq(fdt, fd)); fde = &fdt->fdt_ofiles[fd]; - haverights = *cap_rights_fde(fde); + haverights = *cap_rights_fde_inline(fde); fp = fde->fde_file; if (!seq_consistent(fd_seq(fdt, fd), seq)) continue; Modified: head/sys/kern/sys_capability.c ============================================================================== --- head/sys/kern/sys_capability.c Fri Oct 12 22:57:52 2018 (r339340) +++ head/sys/kern/sys_capability.c Fri Oct 12 23:48:10 2018 (r339341) @@ -208,7 +208,7 @@ const cap_rights_t * cap_rights_fde(const struct filedescent *fdep) { - return (&fdep->fde_rights); + return (cap_rights_fde_inline(fdep)); } const cap_rights_t * Modified: head/sys/sys/capsicum.h ============================================================================== --- head/sys/sys/capsicum.h Fri Oct 12 22:57:52 2018 (r339340) +++ head/sys/sys/capsicum.h Fri Oct 12 23:48:10 2018 (r339341) @@ -465,7 +465,13 @@ u_char cap_rights_to_vmprot(const cap_rights_t *havep) /* * For the purposes of procstat(1) and similar tools, allow kern_descrip.c to * extract the rights from a capability. + * + * Dereferencing fdep requires filedesc.h, but including it would cause + * significant pollution. Instead add a macro for consumers which want it, + * most notably kern_descrip.c. */ +#define cap_rights_fde_inline(fdep) (&(fdep)->fde_rights) + const cap_rights_t *cap_rights_fde(const struct filedescent *fde); const cap_rights_t *cap_rights(struct filedesc *fdp, int fd);