Skip to content

Commit

Permalink
Merge #205
Browse files Browse the repository at this point in the history
  • Loading branch information
ivatet-amd committed Feb 19, 2024
2 parents 0277646 + 0992391 commit 46dce1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
13 changes: 0 additions & 13 deletions src/driver/linux_onload/onload_kernel_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,5 @@ static inline int efrm_unregister_netdevice_notifier(struct notifier_block *b)
#define unregister_netdevice_notifier efrm_unregister_netdevice_notifier
#endif

/* Linux-6.7 introduces lookup_fdget_rcu().
* 5.11 >= linux < 6.7 - lookup_fd_rcu().
* linux < 5.11 - fcheck(). */
#ifndef EFRM_HAS_LOOKUP_FDGET_RCU
static inline struct file *lookup_fdget_rcu(unsigned int fd)
{
#ifdef EFRM_HAS_LOOKUP_FD_RCU
return lookup_fd_rcu(fd);
#else
return fcheck(fd);
#endif
}
#endif

#endif /* __ONLOAD_KERNEL_COMPAT_H__ */
12 changes: 8 additions & 4 deletions src/driver/linux_onload/ossock_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static int
oo_fd_replace_file(struct file* old_filp, struct file* new_filp,
int old_fd, int* new_fd_p)
{
struct file* tmp_filp = NULL;

task_lock(current);
if( atomic_read(&current->files->count) != 1 ) {
/* This is a multithreaded application, and someone can be already
Expand Down Expand Up @@ -111,16 +113,18 @@ oo_fd_replace_file(struct file* old_filp, struct file* new_filp,
return 0;
}

rcu_read_lock();
if( lookup_fdget_rcu(old_fd) != old_filp ) {
rcu_read_unlock();
tmp_filp = fget(old_fd);
if( tmp_filp != old_filp ) {
if( tmp_filp )
fput(tmp_filp);
task_unlock(current);
return -EINVAL;
}

fput(tmp_filp);

get_file(new_filp);
rcu_assign_pointer(files_fdtable(current->files)->fd[old_fd], new_filp);
rcu_read_unlock();
task_unlock(current);

/* No synchronize_rcu() is needed here. See do_dup2() for an example,
Expand Down
2 changes: 0 additions & 2 deletions src/driver/linux_resource/kernel_compat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ EFRM_HAS_REMAP_VMALLOC_RANGE_PARTIAL export remap_vmalloc_range_partial include/
EFRM_HAS_KTIME_GET_REAL_SECONDS export ktime_get_real_seconds include/linux/timekeeping.h kernel/time/timekeeping.c
EFRM_FILE_HAS_F_EP member struct_file f_ep include/linux/fs.h
EFRM_HAS_LOOKUP_FD_RCU symbol lookup_fd_rcu include/linux/fdtable.h
EFRM_HAS_LOOKUP_FDGET_RCU symbol lookup_fdget_rcu include/linux/fdtable.h
EFRM_HAS_FLUSH_DELAYED_FPUT export flush_delayed_fput include/linux/file.h fs/file_table.c
Expand Down

0 comments on commit 46dce1f

Please sign in to comment.