Re: [PATCH] files: rcu free files_struct

2020-12-10 Thread Al Viro
On Thu, Dec 10, 2020 at 10:54:05PM +, Al Viro wrote: > On Thu, Dec 10, 2020 at 11:30:24PM +0100, Christian Brauner wrote: > > (requiring btf), i.e. security_file_open, then follow > > file->f_inode->i_sb->s_type->s_magic. If we change the say struct > > super_block I'd expect these bpf

Re: [PATCH] files: rcu free files_struct

2020-12-10 Thread Christian Brauner
On Thu, Dec 10, 2020 at 09:36:24PM +, Al Viro wrote: > On Thu, Dec 10, 2020 at 01:29:01PM -0600, Eric W. Biederman wrote: > > Al Viro writes: > > > > What are the users of that thing and is there any chance to replace it > > > with something saner? IOW, what *is* realistically called for

Re: [PATCH] files: rcu free files_struct

2020-12-10 Thread Al Viro
On Thu, Dec 10, 2020 at 11:30:24PM +0100, Christian Brauner wrote: > (requiring btf), i.e. security_file_open, then follow > file->f_inode->i_sb->s_type->s_magic. If we change the say struct > super_block I'd expect these bpf programs to break. To break they would need to have compiled in the

Re: [PATCH] files: rcu free files_struct

2020-12-10 Thread Al Viro
On Thu, Dec 10, 2020 at 01:29:01PM -0600, Eric W. Biederman wrote: > Al Viro writes: > > What are the users of that thing and is there any chance to replace it > > with something saner? IOW, what *is* realistically called for each > > struct file by the users of that iterator? > > The bpf guys

Re: [PATCH] files: rcu free files_struct

2020-12-10 Thread Eric W. Biederman
Al Viro writes: > On Wed, Dec 09, 2020 at 03:32:38PM -0600, Eric W. Biederman wrote: >> Al Viro writes: >> >> > On Wed, Dec 09, 2020 at 11:13:38AM -0800, Linus Torvalds wrote: >> >> On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman >> >> wrote: >> >> > >> >> > -

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Al Viro
On Wed, Dec 09, 2020 at 03:32:38PM -0600, Eric W. Biederman wrote: > Al Viro writes: > > > On Wed, Dec 09, 2020 at 11:13:38AM -0800, Linus Torvalds wrote: > >> On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman > >> wrote: > >> > > >> > - struct file * file =

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Paul E. McKenney
On Wed, Dec 09, 2020 at 04:41:06PM -0800, Linus Torvalds wrote: > On Wed, Dec 9, 2020 at 4:39 PM Paul E. McKenney wrote: > > > > Like this, then? > > Ack. Queued with Matthew's Reported-by and your Acked-by, thank you all! Thanx, Paul

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Linus Torvalds
On Wed, Dec 9, 2020 at 4:39 PM Paul E. McKenney wrote: > > Like this, then? Ack. Linus

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Paul E. McKenney
On Wed, Dec 09, 2020 at 03:29:09PM -0800, Linus Torvalds wrote: > On Wed, Dec 9, 2020 at 3:07 PM Matthew Wilcox wrote: > > > > #. It is not necessary to use rcu_assign_pointer() when creating > > linked structures that are to be published via a single external > > - pointer. The

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Linus Torvalds
On Wed, Dec 9, 2020 at 3:07 PM Matthew Wilcox wrote: > > #. It is not necessary to use rcu_assign_pointer() when creating > linked structures that are to be published via a single external > - pointer. The RCU_INIT_POINTER() macro is provided for this task > - and also for assigning

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Paul E. McKenney
On Wed, Dec 09, 2020 at 11:07:55PM +, Matthew Wilcox wrote: > On Wed, Dec 09, 2020 at 03:01:36PM -0800, Linus Torvalds wrote: > > On Wed, Dec 9, 2020 at 2:58 PM Al Viro wrote: > > > > > > On Wed, Dec 09, 2020 at 07:49:38PM +, Matthew Wilcox wrote: > > > > > > > > Assuming this is safe,

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Matthew Wilcox
On Wed, Dec 09, 2020 at 03:01:36PM -0800, Linus Torvalds wrote: > On Wed, Dec 9, 2020 at 2:58 PM Al Viro wrote: > > > > On Wed, Dec 09, 2020 at 07:49:38PM +, Matthew Wilcox wrote: > > > > > > Assuming this is safe, you can use RCU_INIT_POINTER() here because you're > > > storing NULL, so you

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Linus Torvalds
On Wed, Dec 9, 2020 at 3:01 PM Linus Torvalds wrote: > > rcu_assign_pointer() itself already does the optimization for the case > of a constant NULL pointer assignment. > > So there's no need to manually change things to RCU_INIT_POINTER(). Side note: what should be done instead is to delete the

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Linus Torvalds
On Wed, Dec 9, 2020 at 2:58 PM Al Viro wrote: > > On Wed, Dec 09, 2020 at 07:49:38PM +, Matthew Wilcox wrote: > > > > Assuming this is safe, you can use RCU_INIT_POINTER() here because you're > > storing NULL, so you don't need the wmb() before storing the pointer. > > fs/file.c:pick_file()

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Al Viro
On Wed, Dec 09, 2020 at 07:49:38PM +, Matthew Wilcox wrote: > On Wed, Dec 09, 2020 at 12:04:38PM -0600, Eric W. Biederman wrote: > > @@ -397,8 +397,9 @@ static struct fdtable *close_files(struct files_struct > > * files) > > set = fdt->open_fds[j++]; > > while (set) {

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Eric W. Biederman
Matthew Wilcox writes: > On Wed, Dec 09, 2020 at 12:04:38PM -0600, Eric W. Biederman wrote: >> @@ -397,8 +397,9 @@ static struct fdtable *close_files(struct files_struct * >> files) >> set = fdt->open_fds[j++]; >> while (set) { >> if (set & 1) { >>

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Eric W. Biederman
Linus Torvalds writes: > On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman > wrote: >> >> - struct file * file = xchg(>fd[i], NULL); >> + struct file * file = fdt->fd[i]; >> if (file) { >> +

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Eric W. Biederman
Al Viro writes: > On Wed, Dec 09, 2020 at 11:13:38AM -0800, Linus Torvalds wrote: >> On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman >> wrote: >> > >> > - struct file * file = xchg(>fd[i], >> > NULL); >> > + struct file * file =

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Al Viro
On Wed, Dec 09, 2020 at 11:13:38AM -0800, Linus Torvalds wrote: > On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman > wrote: > > > > - struct file * file = xchg(>fd[i], > > NULL); > > + struct file * file = fdt->fd[i]; > >

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Matthew Wilcox
On Wed, Dec 09, 2020 at 12:04:38PM -0600, Eric W. Biederman wrote: > @@ -397,8 +397,9 @@ static struct fdtable *close_files(struct files_struct * > files) > set = fdt->open_fds[j++]; > while (set) { > if (set & 1) { > -

Re: [PATCH] files: rcu free files_struct

2020-12-09 Thread Linus Torvalds
On Wed, Dec 9, 2020 at 10:05 AM Eric W. Biederman wrote: > > - struct file * file = xchg(>fd[i], NULL); > + struct file * file = fdt->fd[i]; > if (file) { > +

[PATCH] files: rcu free files_struct

2020-12-09 Thread Eric W. Biederman
This makes it safe to deference task->files with just rcu_read_lock held, removing the need to take task_lock. Signed-off-by: Eric W. Biederman --- I have cleaned up my patch a little more and made this a little more explicitly rcu. I took a completley different approach to documenting the