Commit graph

520 commits

Author SHA1 Message Date
Jake Freeland 0cd9cde767 ktrace: Record namei violations with KTR_CAPFAIL
Report namei path lookups while Capsicum violation tracing with
CAPFAIL_NAMEI. vfs caching is also ignored when tracing to mimic
capability mode behavior.

Reviewed by:	markj
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D40680
2024-04-07 18:52:51 -05:00
Mark Johnston 55edc40e0c file: Remove the fd parameter to fgetvp_lookup() and fgetvp_lookup_smr()
The fd is always obtained from nameidata, so just fetch it from there
instead.  No functional change intended.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43257
2024-01-04 08:39:53 -05:00
Warner Losh 29363fb446 sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Dmitry Chagin bb8ecf259f vfs cache: Fallback to namei to resolve symlinks with leading / in target for non-native ABI
This is a temporary solution to fix PR before release.
During 15.0 it's necessary to refactor symlinks handling
between vfs & namecache.

PR:			273414
Reported by:		Vincent Milum Jr, Dan Kotowski, glebius
Tested by:		Dan Kotowski, glebius
Reviewed by:
Differential Revision:	https://reviews.freebsd.org/D41806
MFC after:		3 days
2023-10-19 13:33:58 +03:00
Mateusz Guzik 8b622172ba vfs cache: add 2 more optimizaiton ideas 2023-10-05 12:44:43 +00:00
Mateusz Guzik cd2105d691 vfs cache: denote a known bug in cache_remove_cnp 2023-10-05 12:44:43 +00:00
Mateusz Guzik 0f15054f79 vfs cache: plug a hypothetical corner case when freeing
cache_zap_unlocked_bucket is called with a bunch of addresses and
without any locks held, forcing it to revalidate everything from
scratch.

It did not account for a case where the entry is reallocated with
everything the same except for the target vnode.

Should the target use a different lock than the one expected, freeing
would proceed without being properly synchronized.

Note this is almost impossible to happen in practice.
2023-10-05 12:44:42 +00:00
Mateusz Guzik 2749c222da vfs cache: sanitize debug counters
They are very rarely triggered, so no need for per-cpu distribution.

At the same time the non-cpu ones still should use atomics to not lose
any updates.
2023-10-05 12:44:42 +00:00
Mateusz Guzik 4862e8ac02 vfs cache: describe various optimization ideas
While here report a sample result from running on Sapphire Rapids:

An access(2) loop slapped into will-it-scale, like so:
        while (1) {
                int error = access(tmpfile, R_OK);
                assert(error == 0);

                (*iterations)++;
        }

.. operating on /usr/obj/usr/src/amd64.amd64/sys/GENERIC/vnode_if.c

In operations per second:
lockless:	3462164
locked:		1362376

While the over 3.4 mln may seem like a big number, a critical look shows
it should be significantly higher.

A poor man's profiler, counting how many times given routine was sampled:
dtrace -w -n 'profile:::profile-4999 /execname == "a.out"/ {
@[sym(arg0)] = count(); } tick-5s { system("clear"); trunc(@, 40);
printa("%40a %@16d\n", @); clear(@); }'

[snip]
                    kernel`kern_accessat              231
           kernel`cpu_fetch_syscall_args              324
       kernel`cache_fplookup_cross_mount              340
                            kernel`namei              346
                    kernel`amd64_syscall              352
             kernel`tmpfs_fplookup_vexec              388
                             kernel`vput              467
                      kernel`vget_finish              499
                   kernel`lockmgr_unlock              529
                    kernel`lockmgr_slock              558
                    kernel`vget_prep_smr              571
                       kernel`vput_final              578
                           kernel`vdropl             1070
                           kernel`memcmp             1174
                     kernel`0xffffffff80             2080
                                     0x0             2231
                   kernel`copyinstr_smap             2492
                   kernel`cache_fplookup             9246
2023-10-03 13:36:50 +00:00
Mateusz Guzik 38a375c472 vfs cache: s/vfs.cache_fast_lookup/vfs.cache.param.fast_lookup 2023-10-03 13:35:17 +00:00
Mateusz Guzik bb124a0f61 vfs cache: retire dothits and dotdothits counters
They demonstrate nothing, and in case of dotdot they are not even hits.
This is just a count of lookups with "..", which are not worth
mentioniong.
2023-09-23 00:08:49 +00:00
Mateusz Guzik 33fdf1afae vfs cache: mark vfs.cache.param.size as read-only
It was not meant to be writable and writes don't work correctly as they
fail to resize the hash.
2023-09-22 21:32:23 +00:00
Olivier Certner 02ef039c28 vfs cache: Drop known argument of internal cache_recalc_neg_min()
'ncnegminpct' is to be passed always, so just drop the unneeded parameter.

Sponsored by:   The FreeBSD Foundation
Reviewed by:	mjg

Differential Revision: https://reviews.freebsd.org/D41763
2023-09-22 21:25:50 +00:00
Mateusz Guzik 07f52c4b5a vfs cache: garbage collect the fullpathfail2 counter
The conditions it checks cannot legally be true (modulo races against
forced unmount), so assert on it instead.
2023-09-14 20:34:20 +00:00
Mateusz Guzik 32988c1499 vfs cache: fix a hang when bumping vnode limit too high
Overflow in cache_changesize would make the value flip to 0 and stay
there as 0 << 1 does not do anything.

Note callers limit the outcome to something below u_int.

Also note there entire vnode handling thing both in vfs layer as a whole
and this file can't decide whether to long, u_long or u_int.
2023-09-02 14:45:27 +00:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Dmitry Chagin dbac8474fe vfs: Deleting a doubled inclusion of sys/capsicum.h
Reviewed by:
Differential Revision:	https://reviews.freebsd.org/D41223
MFC after:		1 week
2023-07-29 11:21:58 +03:00
Mateusz Guzik ba8cc6d727 vfs: use __enum_uint8 for vtype and vstate
This whacks hackery around only reading v_type once.

Bump __FreeBSD_version to 1400093
2023-07-05 15:06:30 +00:00
Konstantin Belousov d7614c010c vn_path_to_global_path_hardlink(): initialize len
before calling vn_fullpath_hardlink().  Otherwise we get random failures
when the len is automatically clipped.

Reported and tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-07-04 19:00:24 +03:00
Konstantin Belousov d6b900c915 vn_path_to_global_path_hardlink(): avoid freeing non-initialized pointer
Reported by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-07-04 06:19:47 +03:00
Mateusz Guzik 60bd7f97b6 vfs cache: restore sorted order of CACHE_FPL_SUPPORTED_CN_FLAGS 2023-05-30 13:19:53 +00:00
Dmitry Chagin 3d2fec7db8 namei: Add the abilty for the ABI to specify an alternate root path
For now a non-native ABI (i.e., Linux) uses the kern_alternate_path()
facility to dynamically reroot lookups. First, an attempt is made to
lookup the file in /compat/linux/original-path. If that fails, the
lookup is done in /original-path. Thats requires a bit of code in
every ABI syscall implementation where path name translation is needed.
Also our kern_alternate_path() does not properly lookups absolute symlinks
in second attempt, i.e., does not append /compat/linux part to the resolved
link.
The change is intended to avoid this by specifiyng the ABI root directory
for namei(), using one call to pwd_altroot() during exec-time into the ABI.
In that case namei() will dynamically reroot lookups as mentioned above.

PR:			72920
Reviewed by:		kib
Differential revision:	https://reviews.freebsd.org/D38933
MFC after:		2 month
2023-05-29 11:15:28 +03:00
Igor Ostapenko 0e0c47ecd6 vfs cache: fix vfs.cache.stats.* name typos
Two vfs.cache.stats names are fixed:
- s/.dotdothis/.dotdothits/
- s/.posszaps/.poszaps/

Signed-off-by: Igor Ostapenko <pm@igoro.pro>
[mjg: massaged the header a little bit]
2023-04-19 18:47:38 +00:00
Mateusz Guzik 26b9648750 vfs: more informative panic for missing fplookup ops 2023-04-07 20:39:06 +00:00
Mateusz Guzik 5f6df17775 vfs: validate that vop vectors provide all or none fplookup vops
In order to prevent later susprises.
2023-04-06 15:20:41 +00:00
Mateusz Guzik 22eb66d961 vfs cache: always assert on ndp->ni_resflags 2023-03-25 21:57:55 +00:00
Mateusz Guzik c16c4ea6d3 vfs cache: return ENOTDIR for not_a_dir/{.,..} lookups
Reported by:	Oliver Kiddle
PR:	270419
MFC:	3 days
2023-03-23 19:31:18 +00:00
Mateusz Guzik dbcd7e7e32 vfs cache: whack set-but-not-used warn in cache_purgevfs
Reported by:	kib
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-02-21 13:48:35 +00:00
Doug Rabson a1d74b2dab Allow realpath to work for file mounts
For file mounts, the directory vnode is not available from namei and this
prevents the use of vn_fullpath_hardlink. In this case, we can use the
vnode which was covered by the file mount with vn_fullpath.

This also disallows file mounts over files with link counts greater than
one to ensure a deterministic path to the mount point.

Reviewed by:    mjg, kib
Tested by:      pho
2022-12-19 16:46:27 +00:00
Doug Rabson 78d35459a2 Add vn_path_to_global_path_hardlink
This is similar to vn_path_to_global_path but allows for regular files
which may not be present in the cache.

Reviewed by:    mjg, kib
Tested by:      pho
2022-12-19 16:44:59 +00:00
Mateusz Guzik 8f7859e800 vfs: retire the now unused SAVESTART flag
Bump __FreeBSD_version to 1400075

Tested by:      pho
2022-12-19 08:11:08 +00:00
Mateusz Guzik 85dac03e30 vfs: stop using NDFREE
It provides nothing but a branchfest and next to no consumers want it
anyway.

Tested by:	pho
2022-12-19 08:07:23 +00:00
Mateusz Guzik d653aaec7a cache: add cache_assert_no_entries 2022-10-24 15:37:43 +00:00
Mateusz Guzik 5b5b7e2ca2 vfs: always retain path buffer after lookup
This removes some of the complexity needed to maintain HASBUF and
allows for removing injecting SAVENAME by filesystems.

Reviewed by:	kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D36542
2022-09-17 09:10:38 +00:00
Mateusz Guzik 7388fb714a cache: drop the vfs.cache_rename_add tunable
The functionality has been in use since Jan 2021 -- long enough(tm).
2022-06-27 09:56:20 +02:00
Gordon Bergling c9b04ee4f8 kern: Fix two typos in source code comments
- s/accomodate/accommodate/

MFC after:	3 days
2022-04-02 14:52:49 +02:00
Mateusz Guzik 0c805718cb vfs: fix memory leak on lookup with fds with ioctl caps
Reviewed by:	markj
PR:		262515
Noted by:	firk@cantconnect.ru
Differential Revision:	https://reviews.freebsd.org/D34667
2022-04-02 12:09:07 +00:00
Mateusz Guzik bb92cd7bcd vfs: NDFREE(&nd, NDF_ONLY_PNBUF) -> NDFREE_PNBUF(&nd) 2022-03-24 10:20:51 +00:00
Mateusz Guzik 6ff3e8a316 cache: add a comment about a realpath bug 2022-03-19 15:11:25 +00:00
Mateusz Guzik 02fc4e319c cache: use flexible array member
... instead of 0-sizing the array
2022-03-13 14:43:35 +00:00
Mateusz Guzik afb08a6d07 cache: hide hash stats behind DEBUG_CACHE
They take a long time to dump and hinder sysctl -a when used with
DIAGNOSTIC.
2022-03-03 17:21:58 +00:00
Mateusz Guzik 1d65a9b47e cache: improve vnode vs name assertion in cache_enter_time 2022-02-11 12:29:26 +00:00
Mateusz Guzik 611470a515 cache: remove NOCACHE handling from cache_fplookup_noentry
It was copy-pasted from locked lookup. As LOOKUP operation cannot have
the flag set it was always ending up setting MAKEENTRY.
2022-02-11 12:29:26 +00:00
Mateusz Guzik 7e1d3eefd4 vfs: remove the unused thread argument from NDINIT*
See b4a58fbf64 ("vfs: remove cn_thread")

Bump __FreeBSD_version to 1400043.
2021-11-25 22:50:42 +00:00
Mateusz Guzik 7e9680d3be cache: whack "set but not used" warnings 2021-11-14 16:57:43 +00:00
Konstantin Belousov 9a0bee9f6a Make vn_fullpath_hardlink() externally callable
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32611
2021-10-28 20:49:26 +03:00
Mateusz Guzik 628c3b307f cache: only let non-dir descriptors through when doing EMPTYPATH lookups
Otherwise things like realpath against a file and '.' end up with an
illegal state of having a regular vnode for the parent.

Reported by:	syzbot+9aa5439dd9c708aeb1a8@syzkaller.appspotmail.com
2021-10-27 18:27:47 +00:00
Mateusz Guzik 1045352f15 cache: only assert on flags when dealing with EMPTYPATH
Reported by:	syzbot+bd48ee0843206a09e6b8@syzkaller.appspotmail.com
Fixes:		7dd419cabc ("cache: add empty path support")
2021-10-17 08:42:47 +00:00
Mateusz Guzik 7dd419cabc cache: add empty path support
This avoids spurious drop offs as EMPTY is passed regardless of the
actual path name.

Pushign the work inside the lookup instead of just ignorign the flag
allows avoid checking for empty pathname for all other lookups.
2021-10-16 20:08:37 +00:00
Mateusz Guzik b4a58fbf64 vfs: remove cn_thread
It is always curthread.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D32453
2021-10-11 13:21:47 +00:00