* [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void *
@ 2018-05-17 15:46 Jeff Layton
2018-05-17 16:39 ` Jan Kara
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jeff Layton @ 2018-05-17 15:46 UTC (permalink / raw)
To: viro; +Cc: jack, linux-kernel, linux-fsdevel
From: Jeff Layton <jlayton@redhat.com>
All of the callback functions for iterate_supers either ignore the
opaque argument, or dereference the pointer only to fetch the int
to which it points.
Change iterate_supers to pass an opaque int arg to the callback
instead of a void pointer.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/drop_caches.c | 4 ++--
fs/quota/quota.c | 6 ++----
fs/super.c | 3 ++-
fs/sync.c | 32 ++++++++++++++------------------
include/linux/fs.h | 2 +-
mm/cleancache.c | 4 ++--
security/selinux/hooks.c | 4 ++--
7 files changed, 25 insertions(+), 30 deletions(-)
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index 82377017130f..1850e7276fdf 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -14,7 +14,7 @@
/* A global variable is a bit ugly, but it keeps the code simple */
int sysctl_drop_caches;
-static void drop_pagecache_sb(struct super_block *sb, void *unused)
+static void drop_pagecache_sb(struct super_block *sb, int unused)
{
struct inode *inode, *toput_inode = NULL;
@@ -52,7 +52,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
static int stfu;
if (sysctl_drop_caches & 1) {
- iterate_supers(drop_pagecache_sb, NULL);
+ iterate_supers(drop_pagecache_sb, 0);
count_vm_event(DROP_PAGECACHE);
}
if (sysctl_drop_caches & 2) {
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 860bfbe7a07a..5f1e1c494c07 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -46,10 +46,8 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
return security_quotactl(cmd, type, id, sb);
}
-static void quota_sync_one(struct super_block *sb, void *arg)
+static void quota_sync_one(struct super_block *sb, int type)
{
- int type = *(int *)arg;
-
if (sb->s_qcop && sb->s_qcop->quota_sync &&
(sb->s_quota_types & (1 << type)))
sb->s_qcop->quota_sync(sb, type);
@@ -63,7 +61,7 @@ static int quota_sync_all(int type)
return -EINVAL;
ret = security_quotactl(Q_SYNC, type, 0, NULL);
if (!ret)
- iterate_supers(quota_sync_one, &type);
+ iterate_supers(quota_sync_one, type);
return ret;
}
diff --git a/fs/super.c b/fs/super.c
index 122c402049a2..30b7490bd049 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -596,6 +596,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
__put_super(p);
spin_unlock(&sb_lock);
}
+
/**
* iterate_supers - call function for all active superblocks
* @f: function to call
@@ -604,7 +605,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
* Scans the superblock list and calls given function, passing it
* locked superblock and given argument.
*/
-void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
+void iterate_supers(void (*f)(struct super_block *, int), int arg)
{
struct super_block *sb, *p = NULL;
diff --git a/fs/sync.c b/fs/sync.c
index b54e0541ad89..8c418da67e41 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -68,16 +68,16 @@ int sync_filesystem(struct super_block *sb)
}
EXPORT_SYMBOL(sync_filesystem);
-static void sync_inodes_one_sb(struct super_block *sb, void *arg)
+static void sync_inodes_one_sb(struct super_block *sb, int unused)
{
if (!sb_rdonly(sb))
sync_inodes_sb(sb);
}
-static void sync_fs_one_sb(struct super_block *sb, void *arg)
+static void sync_fs_one_sb(struct super_block *sb, int arg)
{
if (!sb_rdonly(sb) && sb->s_op->sync_fs)
- sb->s_op->sync_fs(sb, *(int *)arg);
+ sb->s_op->sync_fs(sb, arg);
}
static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
@@ -107,14 +107,12 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
*/
void ksys_sync(void)
{
- int nowait = 0, wait = 1;
-
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_bdevs(fdatawrite_one_bdev, NULL);
- iterate_bdevs(fdatawait_one_bdev, NULL);
+ iterate_supers(sync_inodes_one_sb, 0);
+ iterate_supers(sync_fs_one_sb, 0);
+ iterate_supers(sync_fs_one_sb, 1);
+ iterate_bdevs(fdatawrite_one_bdev, 0);
+ iterate_bdevs(fdatawait_one_bdev, 0);
if (unlikely(laptop_mode))
laptop_sync_completion();
}
@@ -127,18 +125,16 @@ SYSCALL_DEFINE0(sync)
static void do_sync_work(struct work_struct *work)
{
- int nowait = 0;
-
/*
* Sync twice to reduce the possibility we skipped some inodes / pages
* because they were temporarily locked
*/
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
- iterate_bdevs(fdatawrite_one_bdev, NULL);
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
- iterate_bdevs(fdatawrite_one_bdev, NULL);
+ iterate_supers(sync_inodes_one_sb, 0);
+ iterate_supers(sync_fs_one_sb, 0);
+ iterate_bdevs(fdatawrite_one_bdev, 0);
+ iterate_supers(sync_inodes_one_sb, 0);
+ iterate_supers(sync_fs_one_sb, 0);
+ iterate_bdevs(fdatawrite_one_bdev, 0);
printk("Emergency Sync complete\n");
kfree(work);
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 760d8da1b6c7..7107d291d853 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3115,7 +3115,7 @@ extern struct super_block *get_super_exclusive_thawed(struct block_device *bdev)
extern struct super_block *get_active_super(struct block_device *bdev);
extern void drop_super(struct super_block *sb);
extern void drop_super_exclusive(struct super_block *sb);
-extern void iterate_supers(void (*)(struct super_block *, void *), void *);
+extern void iterate_supers(void (*)(struct super_block *, int), int);
extern void iterate_supers_type(struct file_system_type *,
void (*)(struct super_block *, void *), void *);
diff --git a/mm/cleancache.c b/mm/cleancache.c
index f7b9fdc79d97..92d27cc10274 100644
--- a/mm/cleancache.c
+++ b/mm/cleancache.c
@@ -34,7 +34,7 @@ static u64 cleancache_failed_gets;
static u64 cleancache_puts;
static u64 cleancache_invalidates;
-static void cleancache_register_ops_sb(struct super_block *sb, void *unused)
+static void cleancache_register_ops_sb(struct super_block *sb, int unused)
{
switch (sb->cleancache_poolid) {
case CLEANCACHE_NO_BACKEND:
@@ -105,7 +105,7 @@ int cleancache_register_ops(const struct cleancache_ops *ops)
* until the corresponding ->init_fs has been actually called and
* cleancache_ops has been set.
*/
- iterate_supers(cleancache_register_ops_sb, NULL);
+ iterate_supers(cleancache_register_ops_sb, 0);
return 0;
}
EXPORT_SYMBOL(cleancache_register_ops);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 4cafe6a19167..91c13b72b427 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -7138,7 +7138,7 @@ static __init int selinux_init(void)
return 0;
}
-static void delayed_superblock_init(struct super_block *sb, void *unused)
+static void delayed_superblock_init(struct super_block *sb, int unused)
{
superblock_doinit(sb, NULL);
}
@@ -7149,7 +7149,7 @@ void selinux_complete_init(void)
/* Set up any superblocks initialized prior to the policy load. */
printk(KERN_DEBUG "SELinux: Setting up existing superblocks.\n");
- iterate_supers(delayed_superblock_init, NULL);
+ iterate_supers(delayed_superblock_init, 0);
}
/* SELinux requires early initialization in order to label
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void *
2018-05-17 15:46 [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void * Jeff Layton
@ 2018-05-17 16:39 ` Jan Kara
2018-05-17 16:55 ` Jeff Layton
2018-05-17 17:43 ` [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks Jeff Layton
2018-05-17 21:54 ` [PATCH v3] " Jeff Layton
2 siblings, 1 reply; 8+ messages in thread
From: Jan Kara @ 2018-05-17 16:39 UTC (permalink / raw)
To: Jeff Layton; +Cc: viro, jack, linux-kernel, linux-fsdevel, lurodriguez
On Thu 17-05-18 11:46:46, Jeff Layton wrote:
> From: Jeff Layton <jlayton@redhat.com>
>
> All of the callback functions for iterate_supers either ignore the
> opaque argument, or dereference the pointer only to fetch the int
> to which it points.
>
> Change iterate_supers to pass an opaque int arg to the callback
> instead of a void pointer.
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
Hum, I'm not sure if Luis didn't have any plan with the argument in his
fs-freeze-during-hibernate series. Luis?
Honza
> ---
> fs/drop_caches.c | 4 ++--
> fs/quota/quota.c | 6 ++----
> fs/super.c | 3 ++-
> fs/sync.c | 32 ++++++++++++++------------------
> include/linux/fs.h | 2 +-
> mm/cleancache.c | 4 ++--
> security/selinux/hooks.c | 4 ++--
> 7 files changed, 25 insertions(+), 30 deletions(-)
>
> diff --git a/fs/drop_caches.c b/fs/drop_caches.c
> index 82377017130f..1850e7276fdf 100644
> --- a/fs/drop_caches.c
> +++ b/fs/drop_caches.c
> @@ -14,7 +14,7 @@
> /* A global variable is a bit ugly, but it keeps the code simple */
> int sysctl_drop_caches;
>
> -static void drop_pagecache_sb(struct super_block *sb, void *unused)
> +static void drop_pagecache_sb(struct super_block *sb, int unused)
> {
> struct inode *inode, *toput_inode = NULL;
>
> @@ -52,7 +52,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
> static int stfu;
>
> if (sysctl_drop_caches & 1) {
> - iterate_supers(drop_pagecache_sb, NULL);
> + iterate_supers(drop_pagecache_sb, 0);
> count_vm_event(DROP_PAGECACHE);
> }
> if (sysctl_drop_caches & 2) {
> diff --git a/fs/quota/quota.c b/fs/quota/quota.c
> index 860bfbe7a07a..5f1e1c494c07 100644
> --- a/fs/quota/quota.c
> +++ b/fs/quota/quota.c
> @@ -46,10 +46,8 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
> return security_quotactl(cmd, type, id, sb);
> }
>
> -static void quota_sync_one(struct super_block *sb, void *arg)
> +static void quota_sync_one(struct super_block *sb, int type)
> {
> - int type = *(int *)arg;
> -
> if (sb->s_qcop && sb->s_qcop->quota_sync &&
> (sb->s_quota_types & (1 << type)))
> sb->s_qcop->quota_sync(sb, type);
> @@ -63,7 +61,7 @@ static int quota_sync_all(int type)
> return -EINVAL;
> ret = security_quotactl(Q_SYNC, type, 0, NULL);
> if (!ret)
> - iterate_supers(quota_sync_one, &type);
> + iterate_supers(quota_sync_one, type);
> return ret;
> }
>
> diff --git a/fs/super.c b/fs/super.c
> index 122c402049a2..30b7490bd049 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -596,6 +596,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
> __put_super(p);
> spin_unlock(&sb_lock);
> }
> +
> /**
> * iterate_supers - call function for all active superblocks
> * @f: function to call
> @@ -604,7 +605,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
> * Scans the superblock list and calls given function, passing it
> * locked superblock and given argument.
> */
> -void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
> +void iterate_supers(void (*f)(struct super_block *, int), int arg)
> {
> struct super_block *sb, *p = NULL;
>
> diff --git a/fs/sync.c b/fs/sync.c
> index b54e0541ad89..8c418da67e41 100644
> --- a/fs/sync.c
> +++ b/fs/sync.c
> @@ -68,16 +68,16 @@ int sync_filesystem(struct super_block *sb)
> }
> EXPORT_SYMBOL(sync_filesystem);
>
> -static void sync_inodes_one_sb(struct super_block *sb, void *arg)
> +static void sync_inodes_one_sb(struct super_block *sb, int unused)
> {
> if (!sb_rdonly(sb))
> sync_inodes_sb(sb);
> }
>
> -static void sync_fs_one_sb(struct super_block *sb, void *arg)
> +static void sync_fs_one_sb(struct super_block *sb, int arg)
> {
> if (!sb_rdonly(sb) && sb->s_op->sync_fs)
> - sb->s_op->sync_fs(sb, *(int *)arg);
> + sb->s_op->sync_fs(sb, arg);
> }
>
> static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
> @@ -107,14 +107,12 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
> */
> void ksys_sync(void)
> {
> - int nowait = 0, wait = 1;
> -
> 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_bdevs(fdatawrite_one_bdev, NULL);
> - iterate_bdevs(fdatawait_one_bdev, NULL);
> + iterate_supers(sync_inodes_one_sb, 0);
> + iterate_supers(sync_fs_one_sb, 0);
> + iterate_supers(sync_fs_one_sb, 1);
> + iterate_bdevs(fdatawrite_one_bdev, 0);
> + iterate_bdevs(fdatawait_one_bdev, 0);
> if (unlikely(laptop_mode))
> laptop_sync_completion();
> }
> @@ -127,18 +125,16 @@ SYSCALL_DEFINE0(sync)
>
> static void do_sync_work(struct work_struct *work)
> {
> - int nowait = 0;
> -
> /*
> * Sync twice to reduce the possibility we skipped some inodes / pages
> * because they were temporarily locked
> */
> - iterate_supers(sync_inodes_one_sb, &nowait);
> - iterate_supers(sync_fs_one_sb, &nowait);
> - iterate_bdevs(fdatawrite_one_bdev, NULL);
> - iterate_supers(sync_inodes_one_sb, &nowait);
> - iterate_supers(sync_fs_one_sb, &nowait);
> - iterate_bdevs(fdatawrite_one_bdev, NULL);
> + iterate_supers(sync_inodes_one_sb, 0);
> + iterate_supers(sync_fs_one_sb, 0);
> + iterate_bdevs(fdatawrite_one_bdev, 0);
> + iterate_supers(sync_inodes_one_sb, 0);
> + iterate_supers(sync_fs_one_sb, 0);
> + iterate_bdevs(fdatawrite_one_bdev, 0);
> printk("Emergency Sync complete\n");
> kfree(work);
> }
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 760d8da1b6c7..7107d291d853 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3115,7 +3115,7 @@ extern struct super_block *get_super_exclusive_thawed(struct block_device *bdev)
> extern struct super_block *get_active_super(struct block_device *bdev);
> extern void drop_super(struct super_block *sb);
> extern void drop_super_exclusive(struct super_block *sb);
> -extern void iterate_supers(void (*)(struct super_block *, void *), void *);
> +extern void iterate_supers(void (*)(struct super_block *, int), int);
> extern void iterate_supers_type(struct file_system_type *,
> void (*)(struct super_block *, void *), void *);
>
> diff --git a/mm/cleancache.c b/mm/cleancache.c
> index f7b9fdc79d97..92d27cc10274 100644
> --- a/mm/cleancache.c
> +++ b/mm/cleancache.c
> @@ -34,7 +34,7 @@ static u64 cleancache_failed_gets;
> static u64 cleancache_puts;
> static u64 cleancache_invalidates;
>
> -static void cleancache_register_ops_sb(struct super_block *sb, void *unused)
> +static void cleancache_register_ops_sb(struct super_block *sb, int unused)
> {
> switch (sb->cleancache_poolid) {
> case CLEANCACHE_NO_BACKEND:
> @@ -105,7 +105,7 @@ int cleancache_register_ops(const struct cleancache_ops *ops)
> * until the corresponding ->init_fs has been actually called and
> * cleancache_ops has been set.
> */
> - iterate_supers(cleancache_register_ops_sb, NULL);
> + iterate_supers(cleancache_register_ops_sb, 0);
> return 0;
> }
> EXPORT_SYMBOL(cleancache_register_ops);
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 4cafe6a19167..91c13b72b427 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -7138,7 +7138,7 @@ static __init int selinux_init(void)
> return 0;
> }
>
> -static void delayed_superblock_init(struct super_block *sb, void *unused)
> +static void delayed_superblock_init(struct super_block *sb, int unused)
> {
> superblock_doinit(sb, NULL);
> }
> @@ -7149,7 +7149,7 @@ void selinux_complete_init(void)
>
> /* Set up any superblocks initialized prior to the policy load. */
> printk(KERN_DEBUG "SELinux: Setting up existing superblocks.\n");
> - iterate_supers(delayed_superblock_init, NULL);
> + iterate_supers(delayed_superblock_init, 0);
> }
>
> /* SELinux requires early initialization in order to label
> --
> 2.17.0
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void *
2018-05-17 16:39 ` Jan Kara
@ 2018-05-17 16:55 ` Jeff Layton
0 siblings, 0 replies; 8+ messages in thread
From: Jeff Layton @ 2018-05-17 16:55 UTC (permalink / raw)
To: Jan Kara; +Cc: viro, jack, linux-kernel, linux-fsdevel, lurodriguez
On Thu, 2018-05-17 at 18:39 +0200, Jan Kara wrote:
> On Thu 17-05-18 11:46:46, Jeff Layton wrote:
> > From: Jeff Layton <jlayton@redhat.com>
> >
> > All of the callback functions for iterate_supers either ignore the
> > opaque argument, or dereference the pointer only to fetch the int
> > to which it points.
> >
> > Change iterate_supers to pass an opaque int arg to the callback
> > instead of a void pointer.
> >
> > Signed-off-by: Jeff Layton <jlayton@redhat.com>
>
> Hum, I'm not sure if Luis didn't have any plan with the argument in his
> fs-freeze-during-hibernate series. Luis?
>
> Honza
>
No worries... Al already NAK'ed this over IRC. I'm reworking the patch
to avoid dereferencing in the existing callers, but leave the callback
prototypes intact. I'll send a v2 patch shortly...
Thanks,
Jeff
> > ---
> > fs/drop_caches.c | 4 ++--
> > fs/quota/quota.c | 6 ++----
> > fs/super.c | 3 ++-
> > fs/sync.c | 32 ++++++++++++++------------------
> > include/linux/fs.h | 2 +-
> > mm/cleancache.c | 4 ++--
> > security/selinux/hooks.c | 4 ++--
> > 7 files changed, 25 insertions(+), 30 deletions(-)
> >
> > diff --git a/fs/drop_caches.c b/fs/drop_caches.c
> > index 82377017130f..1850e7276fdf 100644
> > --- a/fs/drop_caches.c
> > +++ b/fs/drop_caches.c
> > @@ -14,7 +14,7 @@
> > /* A global variable is a bit ugly, but it keeps the code simple */
> > int sysctl_drop_caches;
> >
> > -static void drop_pagecache_sb(struct super_block *sb, void *unused)
> > +static void drop_pagecache_sb(struct super_block *sb, int unused)
> > {
> > struct inode *inode, *toput_inode = NULL;
> >
> > @@ -52,7 +52,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
> > static int stfu;
> >
> > if (sysctl_drop_caches & 1) {
> > - iterate_supers(drop_pagecache_sb, NULL);
> > + iterate_supers(drop_pagecache_sb, 0);
> > count_vm_event(DROP_PAGECACHE);
> > }
> > if (sysctl_drop_caches & 2) {
> > diff --git a/fs/quota/quota.c b/fs/quota/quota.c
> > index 860bfbe7a07a..5f1e1c494c07 100644
> > --- a/fs/quota/quota.c
> > +++ b/fs/quota/quota.c
> > @@ -46,10 +46,8 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
> > return security_quotactl(cmd, type, id, sb);
> > }
> >
> > -static void quota_sync_one(struct super_block *sb, void *arg)
> > +static void quota_sync_one(struct super_block *sb, int type)
> > {
> > - int type = *(int *)arg;
> > -
> > if (sb->s_qcop && sb->s_qcop->quota_sync &&
> > (sb->s_quota_types & (1 << type)))
> > sb->s_qcop->quota_sync(sb, type);
> > @@ -63,7 +61,7 @@ static int quota_sync_all(int type)
> > return -EINVAL;
> > ret = security_quotactl(Q_SYNC, type, 0, NULL);
> > if (!ret)
> > - iterate_supers(quota_sync_one, &type);
> > + iterate_supers(quota_sync_one, type);
> > return ret;
> > }
> >
> > diff --git a/fs/super.c b/fs/super.c
> > index 122c402049a2..30b7490bd049 100644
> > --- a/fs/super.c
> > +++ b/fs/super.c
> > @@ -596,6 +596,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
> > __put_super(p);
> > spin_unlock(&sb_lock);
> > }
> > +
> > /**
> > * iterate_supers - call function for all active superblocks
> > * @f: function to call
> > @@ -604,7 +605,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
> > * Scans the superblock list and calls given function, passing it
> > * locked superblock and given argument.
> > */
> > -void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
> > +void iterate_supers(void (*f)(struct super_block *, int), int arg)
> > {
> > struct super_block *sb, *p = NULL;
> >
> > diff --git a/fs/sync.c b/fs/sync.c
> > index b54e0541ad89..8c418da67e41 100644
> > --- a/fs/sync.c
> > +++ b/fs/sync.c
> > @@ -68,16 +68,16 @@ int sync_filesystem(struct super_block *sb)
> > }
> > EXPORT_SYMBOL(sync_filesystem);
> >
> > -static void sync_inodes_one_sb(struct super_block *sb, void *arg)
> > +static void sync_inodes_one_sb(struct super_block *sb, int unused)
> > {
> > if (!sb_rdonly(sb))
> > sync_inodes_sb(sb);
> > }
> >
> > -static void sync_fs_one_sb(struct super_block *sb, void *arg)
> > +static void sync_fs_one_sb(struct super_block *sb, int arg)
> > {
> > if (!sb_rdonly(sb) && sb->s_op->sync_fs)
> > - sb->s_op->sync_fs(sb, *(int *)arg);
> > + sb->s_op->sync_fs(sb, arg);
> > }
> >
> > static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
> > @@ -107,14 +107,12 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
> > */
> > void ksys_sync(void)
> > {
> > - int nowait = 0, wait = 1;
> > -
> > 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_bdevs(fdatawrite_one_bdev, NULL);
> > - iterate_bdevs(fdatawait_one_bdev, NULL);
> > + iterate_supers(sync_inodes_one_sb, 0);
> > + iterate_supers(sync_fs_one_sb, 0);
> > + iterate_supers(sync_fs_one_sb, 1);
> > + iterate_bdevs(fdatawrite_one_bdev, 0);
> > + iterate_bdevs(fdatawait_one_bdev, 0);
> > if (unlikely(laptop_mode))
> > laptop_sync_completion();
> > }
> > @@ -127,18 +125,16 @@ SYSCALL_DEFINE0(sync)
> >
> > static void do_sync_work(struct work_struct *work)
> > {
> > - int nowait = 0;
> > -
> > /*
> > * Sync twice to reduce the possibility we skipped some inodes / pages
> > * because they were temporarily locked
> > */
> > - iterate_supers(sync_inodes_one_sb, &nowait);
> > - iterate_supers(sync_fs_one_sb, &nowait);
> > - iterate_bdevs(fdatawrite_one_bdev, NULL);
> > - iterate_supers(sync_inodes_one_sb, &nowait);
> > - iterate_supers(sync_fs_one_sb, &nowait);
> > - iterate_bdevs(fdatawrite_one_bdev, NULL);
> > + iterate_supers(sync_inodes_one_sb, 0);
> > + iterate_supers(sync_fs_one_sb, 0);
> > + iterate_bdevs(fdatawrite_one_bdev, 0);
> > + iterate_supers(sync_inodes_one_sb, 0);
> > + iterate_supers(sync_fs_one_sb, 0);
> > + iterate_bdevs(fdatawrite_one_bdev, 0);
> > printk("Emergency Sync complete\n");
> > kfree(work);
> > }
> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > index 760d8da1b6c7..7107d291d853 100644
> > --- a/include/linux/fs.h
> > +++ b/include/linux/fs.h
> > @@ -3115,7 +3115,7 @@ extern struct super_block *get_super_exclusive_thawed(struct block_device *bdev)
> > extern struct super_block *get_active_super(struct block_device *bdev);
> > extern void drop_super(struct super_block *sb);
> > extern void drop_super_exclusive(struct super_block *sb);
> > -extern void iterate_supers(void (*)(struct super_block *, void *), void *);
> > +extern void iterate_supers(void (*)(struct super_block *, int), int);
> > extern void iterate_supers_type(struct file_system_type *,
> > void (*)(struct super_block *, void *), void *);
> >
> > diff --git a/mm/cleancache.c b/mm/cleancache.c
> > index f7b9fdc79d97..92d27cc10274 100644
> > --- a/mm/cleancache.c
> > +++ b/mm/cleancache.c
> > @@ -34,7 +34,7 @@ static u64 cleancache_failed_gets;
> > static u64 cleancache_puts;
> > static u64 cleancache_invalidates;
> >
> > -static void cleancache_register_ops_sb(struct super_block *sb, void *unused)
> > +static void cleancache_register_ops_sb(struct super_block *sb, int unused)
> > {
> > switch (sb->cleancache_poolid) {
> > case CLEANCACHE_NO_BACKEND:
> > @@ -105,7 +105,7 @@ int cleancache_register_ops(const struct cleancache_ops *ops)
> > * until the corresponding ->init_fs has been actually called and
> > * cleancache_ops has been set.
> > */
> > - iterate_supers(cleancache_register_ops_sb, NULL);
> > + iterate_supers(cleancache_register_ops_sb, 0);
> > return 0;
> > }
> > EXPORT_SYMBOL(cleancache_register_ops);
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 4cafe6a19167..91c13b72b427 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -7138,7 +7138,7 @@ static __init int selinux_init(void)
> > return 0;
> > }
> >
> > -static void delayed_superblock_init(struct super_block *sb, void *unused)
> > +static void delayed_superblock_init(struct super_block *sb, int unused)
> > {
> > superblock_doinit(sb, NULL);
> > }
> > @@ -7149,7 +7149,7 @@ void selinux_complete_init(void)
> >
> > /* Set up any superblocks initialized prior to the policy load. */
> > printk(KERN_DEBUG "SELinux: Setting up existing superblocks.\n");
> > - iterate_supers(delayed_superblock_init, NULL);
> > + iterate_supers(delayed_superblock_init, 0);
> > }
> >
> > /* SELinux requires early initialization in order to label
> > --
> > 2.17.0
> >
> >
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks
2018-05-17 15:46 [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void * Jeff Layton
2018-05-17 16:39 ` Jan Kara
@ 2018-05-17 17:43 ` Jeff Layton
2018-05-17 18:26 ` Matthew Wilcox
2018-05-17 21:54 ` [PATCH v3] " Jeff Layton
2 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2018-05-17 17:43 UTC (permalink / raw)
To: viro; +Cc: jack, linux-kernel, linux-fsdevel, lurodriguez
From: Jeff Layton <jlayton@redhat.com>
All of the callback functions for iterate_supers either ignore the
opaque argument, or dereference the pointer only to fetch the int
to which it points.
Change quota_sync_one to just cast the int from the pointer,
and change sync_fs_one_sb to just use a NULL/non-NULL pointer as a
flag.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/quota/quota.c | 4 ++--
fs/sync.c | 20 +++++++++-----------
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 860bfbe7a07a..8dc76d5f87c7 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -48,7 +48,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
static void quota_sync_one(struct super_block *sb, void *arg)
{
- int type = *(int *)arg;
+ int type = (unsigned long)arg;
if (sb->s_qcop && sb->s_qcop->quota_sync &&
(sb->s_quota_types & (1 << type)))
@@ -63,7 +63,7 @@ static int quota_sync_all(int type)
return -EINVAL;
ret = security_quotactl(Q_SYNC, type, 0, NULL);
if (!ret)
- iterate_supers(quota_sync_one, &type);
+ iterate_supers(quota_sync_one, (void *)((unsigned long)type));
return ret;
}
diff --git a/fs/sync.c b/fs/sync.c
index b54e0541ad89..d7330bb97f05 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -76,8 +76,10 @@ static void sync_inodes_one_sb(struct super_block *sb, void *arg)
static void sync_fs_one_sb(struct super_block *sb, void *arg)
{
+ int wait = arg ? 1 : 0;
+
if (!sb_rdonly(sb) && sb->s_op->sync_fs)
- sb->s_op->sync_fs(sb, *(int *)arg);
+ sb->s_op->sync_fs(sb, wait);
}
static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
@@ -107,12 +109,10 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
*/
void ksys_sync(void)
{
- int nowait = 0, wait = 1;
-
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_fs_one_sb, NULL);
+ iterate_supers(sync_fs_one_sb, (void *)1UL);
iterate_bdevs(fdatawrite_one_bdev, NULL);
iterate_bdevs(fdatawait_one_bdev, NULL);
if (unlikely(laptop_mode))
@@ -127,17 +127,15 @@ SYSCALL_DEFINE0(sync)
static void do_sync_work(struct work_struct *work)
{
- int nowait = 0;
-
/*
* Sync twice to reduce the possibility we skipped some inodes / pages
* because they were temporarily locked
*/
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
+ iterate_supers(sync_inodes_one_sb, NULL);
+ iterate_supers(sync_fs_one_sb, NULL);
iterate_bdevs(fdatawrite_one_bdev, NULL);
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
+ iterate_supers(sync_inodes_one_sb, NULL);
+ iterate_supers(sync_fs_one_sb, NULL);
iterate_bdevs(fdatawrite_one_bdev, NULL);
printk("Emergency Sync complete\n");
kfree(work);
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks
2018-05-17 17:43 ` [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks Jeff Layton
@ 2018-05-17 18:26 ` Matthew Wilcox
2018-05-17 18:55 ` Jeff Layton
0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2018-05-17 18:26 UTC (permalink / raw)
To: Jeff Layton; +Cc: viro, jack, linux-kernel, linux-fsdevel, lurodriguez
On Thu, May 17, 2018 at 01:43:36PM -0400, Jeff Layton wrote:
> @@ -107,12 +109,10 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
> */
> void ksys_sync(void)
> {
> - int nowait = 0, wait = 1;
> -
> 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_fs_one_sb, NULL);
> + iterate_supers(sync_fs_one_sb, (void *)1UL);
I think this is actually less clear. How about:
void *wait = (void *)1UL;
iterate_supers(sync_fs_one_sb, !wait);
iterate_supers(sync_fs_one_sb, wait);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks
2018-05-17 18:26 ` Matthew Wilcox
@ 2018-05-17 18:55 ` Jeff Layton
0 siblings, 0 replies; 8+ messages in thread
From: Jeff Layton @ 2018-05-17 18:55 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: viro, jack, linux-kernel, linux-fsdevel, lurodriguez
On Thu, 2018-05-17 at 11:26 -0700, Matthew Wilcox wrote:
> On Thu, May 17, 2018 at 01:43:36PM -0400, Jeff Layton wrote:
> > @@ -107,12 +109,10 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
> > */
> > void ksys_sync(void)
> > {
> > - int nowait = 0, wait = 1;
> > -
> > 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_fs_one_sb, NULL);
> > + iterate_supers(sync_fs_one_sb, (void *)1UL);
>
> I think this is actually less clear. How about:
>
> void *wait = (void *)1UL;
>
> iterate_supers(sync_fs_one_sb, !wait);
> iterate_supers(sync_fs_one_sb, wait);
>
Sure, I could do that. We could also keep the wait/nowait vars too, I
guess.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] vfs: avoid dereferencing pointers in iterate_supers callbacks
2018-05-17 15:46 [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void * Jeff Layton
2018-05-17 16:39 ` Jan Kara
2018-05-17 17:43 ` [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks Jeff Layton
@ 2018-05-17 21:54 ` Jeff Layton
2018-05-18 9:32 ` Jan Kara
2 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2018-05-17 21:54 UTC (permalink / raw)
To: viro; +Cc: jack, linux-kernel, linux-fsdevel, lurodriguez, willy
From: Jeff Layton <jlayton@redhat.com>
All of the callback functions for iterate_supers either ignore the
opaque argument, or dereference the pointer only to fetch the int
to which it points.
Change quota_sync_one to just cast the int from the pointer,
and change sync_fs_one_sb to just use a NULL/non-NULL pointer as a
flag.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/quota/quota.c | 4 ++--
fs/sync.c | 20 +++++++++++---------
2 files changed, 13 insertions(+), 11 deletions(-)
v3: reinstate wait/nowait variables for clarity
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 860bfbe7a07a..8dc76d5f87c7 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -48,7 +48,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
static void quota_sync_one(struct super_block *sb, void *arg)
{
- int type = *(int *)arg;
+ int type = (unsigned long)arg;
if (sb->s_qcop && sb->s_qcop->quota_sync &&
(sb->s_quota_types & (1 << type)))
@@ -63,7 +63,7 @@ static int quota_sync_all(int type)
return -EINVAL;
ret = security_quotactl(Q_SYNC, type, 0, NULL);
if (!ret)
- iterate_supers(quota_sync_one, &type);
+ iterate_supers(quota_sync_one, (void *)((unsigned long)type));
return ret;
}
diff --git a/fs/sync.c b/fs/sync.c
index b54e0541ad89..a863cd2490ce 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -76,8 +76,10 @@ static void sync_inodes_one_sb(struct super_block *sb, void *arg)
static void sync_fs_one_sb(struct super_block *sb, void *arg)
{
+ int wait = arg ? 1 : 0;
+
if (!sb_rdonly(sb) && sb->s_op->sync_fs)
- sb->s_op->sync_fs(sb, *(int *)arg);
+ sb->s_op->sync_fs(sb, wait);
}
static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
@@ -107,12 +109,12 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
*/
void ksys_sync(void)
{
- int nowait = 0, wait = 1;
+ void *nowait = NULL, *wait = (void *)1UL;
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_fs_one_sb, nowait);
+ iterate_supers(sync_fs_one_sb, wait);
iterate_bdevs(fdatawrite_one_bdev, NULL);
iterate_bdevs(fdatawait_one_bdev, NULL);
if (unlikely(laptop_mode))
@@ -127,17 +129,17 @@ SYSCALL_DEFINE0(sync)
static void do_sync_work(struct work_struct *work)
{
- int nowait = 0;
+ void *nowait = NULL;
/*
* Sync twice to reduce the possibility we skipped some inodes / pages
* because they were temporarily locked
*/
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
+ iterate_supers(sync_inodes_one_sb, NULL);
+ iterate_supers(sync_fs_one_sb, nowait);
iterate_bdevs(fdatawrite_one_bdev, NULL);
- iterate_supers(sync_inodes_one_sb, &nowait);
- iterate_supers(sync_fs_one_sb, &nowait);
+ iterate_supers(sync_inodes_one_sb, NULL);
+ iterate_supers(sync_fs_one_sb, nowait);
iterate_bdevs(fdatawrite_one_bdev, NULL);
printk("Emergency Sync complete\n");
kfree(work);
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] vfs: avoid dereferencing pointers in iterate_supers callbacks
2018-05-17 21:54 ` [PATCH v3] " Jeff Layton
@ 2018-05-18 9:32 ` Jan Kara
0 siblings, 0 replies; 8+ messages in thread
From: Jan Kara @ 2018-05-18 9:32 UTC (permalink / raw)
To: Jeff Layton; +Cc: viro, jack, linux-kernel, linux-fsdevel, lurodriguez, willy
On Thu 17-05-18 17:54:20, Jeff Layton wrote:
> From: Jeff Layton <jlayton@redhat.com>
>
> All of the callback functions for iterate_supers either ignore the
> opaque argument, or dereference the pointer only to fetch the int
> to which it points.
>
> Change quota_sync_one to just cast the int from the pointer,
> and change sync_fs_one_sb to just use a NULL/non-NULL pointer as a
> flag.
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
As much as I have a feeling "why do we bother", the patch looks correct :).
So feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/quota/quota.c | 4 ++--
> fs/sync.c | 20 +++++++++++---------
> 2 files changed, 13 insertions(+), 11 deletions(-)
>
> v3: reinstate wait/nowait variables for clarity
>
> diff --git a/fs/quota/quota.c b/fs/quota/quota.c
> index 860bfbe7a07a..8dc76d5f87c7 100644
> --- a/fs/quota/quota.c
> +++ b/fs/quota/quota.c
> @@ -48,7 +48,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
>
> static void quota_sync_one(struct super_block *sb, void *arg)
> {
> - int type = *(int *)arg;
> + int type = (unsigned long)arg;
>
> if (sb->s_qcop && sb->s_qcop->quota_sync &&
> (sb->s_quota_types & (1 << type)))
> @@ -63,7 +63,7 @@ static int quota_sync_all(int type)
> return -EINVAL;
> ret = security_quotactl(Q_SYNC, type, 0, NULL);
> if (!ret)
> - iterate_supers(quota_sync_one, &type);
> + iterate_supers(quota_sync_one, (void *)((unsigned long)type));
> return ret;
> }
>
> diff --git a/fs/sync.c b/fs/sync.c
> index b54e0541ad89..a863cd2490ce 100644
> --- a/fs/sync.c
> +++ b/fs/sync.c
> @@ -76,8 +76,10 @@ static void sync_inodes_one_sb(struct super_block *sb, void *arg)
>
> static void sync_fs_one_sb(struct super_block *sb, void *arg)
> {
> + int wait = arg ? 1 : 0;
> +
> if (!sb_rdonly(sb) && sb->s_op->sync_fs)
> - sb->s_op->sync_fs(sb, *(int *)arg);
> + sb->s_op->sync_fs(sb, wait);
> }
>
> static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
> @@ -107,12 +109,12 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
> */
> void ksys_sync(void)
> {
> - int nowait = 0, wait = 1;
> + void *nowait = NULL, *wait = (void *)1UL;
>
> 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_fs_one_sb, nowait);
> + iterate_supers(sync_fs_one_sb, wait);
> iterate_bdevs(fdatawrite_one_bdev, NULL);
> iterate_bdevs(fdatawait_one_bdev, NULL);
> if (unlikely(laptop_mode))
> @@ -127,17 +129,17 @@ SYSCALL_DEFINE0(sync)
>
> static void do_sync_work(struct work_struct *work)
> {
> - int nowait = 0;
> + void *nowait = NULL;
>
> /*
> * Sync twice to reduce the possibility we skipped some inodes / pages
> * because they were temporarily locked
> */
> - iterate_supers(sync_inodes_one_sb, &nowait);
> - iterate_supers(sync_fs_one_sb, &nowait);
> + iterate_supers(sync_inodes_one_sb, NULL);
> + iterate_supers(sync_fs_one_sb, nowait);
> iterate_bdevs(fdatawrite_one_bdev, NULL);
> - iterate_supers(sync_inodes_one_sb, &nowait);
> - iterate_supers(sync_fs_one_sb, &nowait);
> + iterate_supers(sync_inodes_one_sb, NULL);
> + iterate_supers(sync_fs_one_sb, nowait);
> iterate_bdevs(fdatawrite_one_bdev, NULL);
> printk("Emergency Sync complete\n");
> kfree(work);
> --
> 2.17.0
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-05-18 9:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17 15:46 [PATCH] vfs: change iterate_supers callback to take an int arg instead of a void * Jeff Layton
2018-05-17 16:39 ` Jan Kara
2018-05-17 16:55 ` Jeff Layton
2018-05-17 17:43 ` [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks Jeff Layton
2018-05-17 18:26 ` Matthew Wilcox
2018-05-17 18:55 ` Jeff Layton
2018-05-17 21:54 ` [PATCH v3] " Jeff Layton
2018-05-18 9:32 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).