From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zeniv.linux.org.uk ([195.92.253.2]:53470 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752022AbeAZXNy (ORCPT ); Fri, 26 Jan 2018 18:13:54 -0500 Date: Fri, 26 Jan 2018 23:13:51 +0000 From: Al Viro To: Omar Sandoval Cc: linux-fsdevel@vger.kernel.org, kernel-team@fb.com, "Eric W . Biederman" , Tejun Heo Subject: Re: [PATCH] fs: only sync() superblocks reachable from the current namespace Message-ID: <20180126231350.GC13338@ZenIV.linux.org.uk> References: <05434cda5cc3b461b5d70467b094904ad23fdc11.1517007510.git.osandov@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <05434cda5cc3b461b5d70467b094904ad23fdc11.1517007510.git.osandov@fb.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Jan 26, 2018 at 02:58:39PM -0800, Omar Sandoval wrote: > From: Omar Sandoval > > Currently, the sync() syscall is system-wide, so any process in a > container can cause significant I/O stalls across the system by calling > sync(). This is even true for filesystems which are not accessible in > the process' mount namespace. This patch scopes sync() to only write out > filesystems reachable in the current mount namespace, except for the > initial mount namespace, which still syncs everything to avoid > surprises. This fixes the broken isolation we were seeing here. > +static int sb_reachable(struct super_block *sb, struct mnt_namespace *mnt_ns) > +{ > + struct mount *mnt; > + > + if (!mnt_ns) > + return 1; > + > + list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { > + if (mnt->mnt_ns == mnt_ns) > + return 1; > + } > + return 0; > +} Erm... And just what is protecting the list here? > static void fdatawrite_one_bdev(struct block_device *bdev, void *arg) > @@ -107,12 +138,18 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg) > */ > SYSCALL_DEFINE0(sync) > { > - int nowait = 0, wait = 1; > + struct sb_sync arg = { > + .mnt_ns = current->nsproxy->mnt_ns, > + }; > + > + if (arg.mnt_ns == init_task.nsproxy->mnt_ns) > + arg.mnt_ns = NULL; > > wakeup_flusher_threads(WB_REASON_SYNC); > - iterate_supers(sync_inodes_one_sb, NULL); > - iterate_supers(sync_fs_one_sb, &nowait); > - iterate_supers(sync_fs_one_sb, &wait); > + iterate_supers(sync_inodes_one_sb, &arg); > + iterate_supers(sync_fs_one_sb, &arg); > + arg.wait = 1; > + iterate_supers(sync_fs_one_sb, &arg); So now sync() includes O(total vfsmounts on the system) walking the lists, no matter what *and* in a situation when a lazy-unmounted filesystem is held active by an opened file sync(2) won't touch that filesystem. Unless done in the magical namespace init(8) happens to run in.