Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Jul 2020 23:45:42 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r363501 - in stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys
Message-ID:  <202007242345.06ONjguV028251@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Fri Jul 24 23:45:42 2020
New Revision: 363501
URL: https://svnweb.freebsd.org/changeset/base/363501

Log:
  MFC r357282:
  
      zfs: fix spurious lock contention during path lookup

Modified:
  stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_acl.h
  stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_acl.c
  stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_acl.h
==============================================================================
--- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_acl.h	Fri Jul 24 23:44:35 2020	(r363500)
+++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_acl.h	Fri Jul 24 23:45:42 2020	(r363501)
@@ -214,7 +214,10 @@ void zfs_oldace_byteswap(ace_t *, int);
 void zfs_ace_byteswap(void *, size_t, boolean_t);
 extern boolean_t zfs_has_access(struct znode *zp, cred_t *cr);
 extern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *);
+#ifdef illumos
 int zfs_fastaccesschk_execute(struct znode *, cred_t *);
+#endif
+int zfs_freebsd_fastaccesschk_execute(struct vnode *, cred_t *);
 extern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *);
 extern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *);
 extern int zfs_acl_access(struct znode *, int, cred_t *);

Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_acl.c
==============================================================================
--- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_acl.c	Fri Jul 24 23:44:35 2020	(r363500)
+++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_acl.c	Fri Jul 24 23:45:42 2020	(r363501)
@@ -2299,7 +2299,41 @@ zfs_zaccess_append(znode_t *zp, uint32_t *working_mode
 	    check_privs, B_FALSE, cr));
 }
 
+/*
+ * Check if VEXEC is allowed.
+ *
+ * This routine is based on zfs_fastaccesschk_execute which has slowpath
+ * calling zfs_zaccess. This would be incorrect on FreeBSD (see
+ * zfs_freebsd_access for the difference). Thus this variant let's the
+ * caller handle the slowpath (if necessary).
+ *
+ * We only check for ZFS_NO_EXECS_DENIED and fail early. This routine can
+ * be extended to cover more cases, but the flag covers the majority.
+ */
 int
+zfs_freebsd_fastaccesschk_execute(struct vnode *vp, cred_t *cr)
+{
+	boolean_t is_attr;
+	znode_t *zdp = VTOZ(vp);
+
+	ASSERT_VOP_LOCKED(vp, __func__);
+
+	if (zdp->z_pflags & ZFS_AV_QUARANTINED)
+		return (1);
+
+	is_attr = ((zdp->z_pflags & ZFS_XATTR) &&
+	    (ZTOV(zdp)->v_type == VDIR));
+	if (is_attr)
+		return (1);
+
+	if (zdp->z_pflags & ZFS_NO_EXECS_DENIED)
+		return (0);
+
+	return (1);
+}
+
+#ifdef illumos
+int
 zfs_fastaccesschk_execute(znode_t *zdp, cred_t *cr)
 {
 	boolean_t owner = B_FALSE;
@@ -2365,6 +2399,7 @@ slow:
 	ZFS_EXIT(zdp->z_zfsvfs);
 	return (error);
 }
+#endif
 
 /*
  * Determine whether Access should be granted/denied.

Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
==============================================================================
--- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Fri Jul 24 23:44:35 2020	(r363500)
+++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Fri Jul 24 23:45:42 2020	(r363501)
@@ -4915,6 +4915,11 @@ zfs_freebsd_access(ap)
 	accmode_t accmode;
 	int error = 0;
 
+	if (ap->a_accmode == VEXEC) {
+		if (zfs_freebsd_fastaccesschk_execute(ap->a_vp, ap->a_cred) == 0)
+			return (0);
+	}
+
 	/*
 	 * ZFS itself only knowns about VREAD, VWRITE, VEXEC and VAPPEND,
 	 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007242345.06ONjguV028251>