git: 45bb8beacc2f - main - fd: elide one acquire fence in fget_unlocked_seq
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 11 Feb 2022 13:58:04 UTC
The branch main has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=45bb8beacc2fadbbc32428df0f2f5683863df289
commit 45bb8beacc2fadbbc32428df0f2f5683863df289
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-02-01 16:58:12 +0000
Commit: Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-02-11 12:29:26 +0000
fd: elide one acquire fence in fget_unlocked_seq
Still validate we got the stable state before returning an error though.
---
sys/kern/kern_descrip.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index c4f435002907..e5ffdb01255f 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -3060,13 +3060,19 @@ fget_unlocked_seq(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
fde = &fdt->fdt_ofiles[fd];
haverights = *cap_rights_fde_inline(fde);
fp = fde->fde_file;
- if (!seqc_consistent(fd_seqc(fdt, fd), seq))
+ if (__predict_false(fp == NULL)) {
+ if (seqc_consistent(fd_seqc(fdt, fd), seq))
+ return (EBADF);
+ fdt = atomic_load_ptr(&fdp->fd_files);
continue;
- if (__predict_false(fp == NULL))
- return (EBADF);
+ }
error = cap_check_inline(&haverights, needrightsp);
- if (__predict_false(error != 0))
- return (error);
+ if (__predict_false(error != 0)) {
+ if (seqc_consistent(fd_seqc(fdt, fd), seq))
+ return (error);
+ fdt = atomic_load_ptr(&fdp->fd_files);
+ continue;
+ }
if (__predict_false(!refcount_acquire_if_not_zero(&fp->f_count))) {
fdt = atomic_load_ptr(&fdp->fd_files);
continue;