lkml.org 
[lkml]   [2015]   [Nov]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] vfs: clear remainder of 'full_fds_bits' in dup_fd()
Date
This fixes a bug from commit f3f86e33dc3d ("vfs: Fix pathological
performance case for __alloc_fd()").

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
---
fs/file.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 6f6eb2b..36e5103 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -276,7 +276,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
{
struct files_struct *newf;
struct file **old_fds, **new_fds;
- int open_files, size, i;
+ int open_files, i;
struct fdtable *old_fdt, *new_fdt;

*errorp = -ENOMEM;
@@ -357,18 +357,16 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
}
spin_unlock(&oldf->file_lock);

- /* compute the remainder to be cleared */
- size = (new_fdt->max_fds - open_files) * sizeof(struct file *);
-
- /* This is long word aligned thus could use a optimized version */
- memset(new_fds, 0, size);
-
+ /* clear the remainder if needed */
if (new_fdt->max_fds > open_files) {
- int left = (new_fdt->max_fds - open_files) / 8;
+ int left = new_fdt->max_fds - open_files;
int start = open_files / BITS_PER_LONG;

- memset(&new_fdt->open_fds[start], 0, left);
- memset(&new_fdt->close_on_exec[start], 0, left);
+ memset(new_fds, 0, left * sizeof(struct file *));
+ memset(&new_fdt->open_fds[start], 0, left / 8);
+ memset(&new_fdt->close_on_exec[start], 0, left / 8);
+ memset(&new_fdt->full_fds_bits[BITBIT_NR(open_files)], 0,
+ BITBIT_SIZE(new_fdt->max_fds) - BITBIT_SIZE(open_files));
}

rcu_assign_pointer(newf->fdt, new_fdt);
--
2.6.2


\
 
 \ /
  Last update: 2015-11-06 05:01    [W:0.045 / U:0.624 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site