xen/debugfs: Check debugfs initialization before using it
Subsystems (2)
PATCH 1/1 xen/debugfs: Check debugfs initialization before using it
Should check debugfs initialization with debugfs_initialized() before using it, Because if it isn't initialized, the return value of fake debugfs_create_dir() etc functions would be ERR_PTR(-ENODEV), checking with NULL will not work.
--- arch/x86/xen/debugfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/xen/debugfs.c +6 -0
@@ -9,12 +9,18 @@ static struct dentry *d_xen_debug;struct dentry *__init xen_init_debugfs (void ) { +if (!debugfs_initialized ()) { + d_xen_debug =NULL ; + goto nodebugfs; + } +if (!d_xen_debug) { d_xen_debug =debugfs_create_dir ("xen" ,NULL );if (!d_xen_debug)pr_warning ("Could not create 'xen' debugfs directory\n" ); } +nodebugfs:return d_xen_debug; }
Signature · 1 line
1.8.3.4 (Apple Git-47)
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.
So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
greg k-h
Quoted 1 line
Signed-off-by ethan.zhao <[email protected]>
Please put your "real" name here, not one with a '.' in it.
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured, debugfs_initialized() and other functions are defined as following,
static inline bool debugfs_initialized(void)
{
return false;
}
static inline struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data,
const struct file_operations *fops)
{
return ERR_PTR(-ENODEV);
}
static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
return ERR_PTR(-ENODEV);
}
And the checking code in xen\debugfs.c xen_init_debugfs() will not work, the return value is not NULL.d_xen_debug = debugfs_create_dir("xen", NULL);
if (!d_xen_debug)pr_warning("Could not create 'xen' debugfs directory\n");
Quoted 6 lines
greg k-h
Quoted 1 line
Signed-off-by ethan.zhao <[email protected]>Please put your "real" name here, not one with a '.' in it.
The real name used in company is [email protected], but I couldn't send and receive mails of
community with that mailbox for some reason you may know.
Thanks,
Ethan
Quoted 4 lines
thanks,
greg k-h
Quoted 30 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}
Quoted 6 lines
And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");
Which is just fine, what is wrong with this?
Quoted 10 lines
Quoted 6 lines
greg k-h
Quoted 1 line
Signed-off-by ethan.zhao <[email protected]>Please put your "real" name here, not one with a '.' in it.
The real name used in company is [email protected], but I couldn't send and receive mails of
community with that mailbox for some reason you may know.
I mean the "ethan.zhao" part, it should be "Ethan Zhao" :)
thanks,
greg k-h
Quoted 31 lines · Greg KH
Quoted 30 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}
Quoted 8 lines
Quoted 6 lines
And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");Which is just fine, what is wrong with this?
If we no check with debugfs_initialized(), the above code should be if (!d_xen_debug || IS_ERR (d_xen_debug))
pr_warning("Could not create 'xen' debugfs directory\n");Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
greg k-h
Quoted 1 line
Signed-off-by ethan.zhao <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Please put your "real" name here, not one with a '.' in it.
The real name used in company is [email protected], but I couldn't send and receive mails of
community with that mailbox for some reason you may know.I mean the "ethan.zhao" part, it should be "Ethan Zhao" :)
You got the my real name, thanks. :>
Ethan
Quoted 4 lines
thanks,
greg k-h
Quoted 36 lines · Ethan Zhao
Quoted 35 lines · Greg KH
Quoted 34 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");Which is just fine, what is wrong with this?
If we no check with
debugfs_initialized(), the above code should be if (!d_xen_debug ||IS_ERR(d_xen_debug))pr_warning("Could not create 'xen' debugfs directory\n");
No, you don't want to print out that message if debugfs is not enabled.
You really don't want to print anything out, as what can a user do about this?
I still think the original code is correct, have you tried it with debugfs disabled?
greg k-h
Quoted 42 lines · Greg KH
Quoted 41 lines · Ethan Zhao
Quoted 39 lines · Greg KH
Quoted 30 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}Quoted 6 lines
And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");Which is just fine, what is wrong with this?
Quoted 9 lines
Quoted 3 lines
If we no check with
debugfs_initialized(), the above code should be if (!d_xen_debug ||IS_ERR(d_xen_debug))pr_warning("Could not create 'xen' debugfs directory\n");No, you don't want to print out that message if debugfs is not enabled.
You really don't want to print anything out, as what can a user do about this?
Yep, should output a warning about "Debugfs is not configured and enabled"
Quoted 2 lines
I still think the original code is correct, have you tried it with debugfs disabled?
If debugfs is not configured, no "Could not create 'xen' debugfs directory" warning.
Ok, send V3 to imporve it.
Quoted 2 lines
greg k-h
Quoted 47 lines · Ethan Zhao
Quoted 46 lines · Greg KH
Quoted 44 lines · Ethan Zhao
Quoted 31 lines · Greg KH
Quoted 30 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}Quoted 8 lines
Quoted 6 lines
And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");Which is just fine, what is wrong with this?
If we no check with
debugfs_initialized(), the above code should be if (!d_xen_debug ||IS_ERR(d_xen_debug))pr_warning("Could not create 'xen' debugfs directory\n");
Quoted 6 lines
Quoted 5 lines
No, you don't want to print out that message if debugfs is not enabled.
You really don't want to print anything out, as what can a user do about this?
Yep, should output a warning about "Debugfs is not configured and enabled"
No, not at all, it's not an issue you need to warn about because it was explicitly told to be that way by the person who built that kernel.
It's not an error, please don't treat it as such.
greg k-h
Greg,
I am the man who built a Xen dom0, but couldn't see debugfs
directory and files as expected. there is no warning or tip for me to enable the CONFIG_DEBUG_FS=y in .config , it cost me minutes to figure out what's
the matter. and I know should check defugfs config and initialization as zswap_debugfs, tracer_debugfs ,rproc_debugfs did. Is it useless ? if it could save me just 1 minute next time ?
Thanks,
Ethan
Quoted 61 lines · Greg KH
Quoted 47 lines · Ethan Zhao
Quoted 46 lines · Greg KH
Quoted 44 lines · Ethan Zhao
Quoted 31 lines · Greg KH
Quoted 30 lines · Ethan Zhao
Quoted 7 lines · Greg KH
Quoted 3 lines · ethan.zhao
Should check debugfs initialization with
debugfs_initialized()before using it, Because if it isn't initialized, the return value of fakedebugfs_create_dir()etc functions would beERR_PTR(-ENODEV), checking with NULL will not work.So? It should "just work" without this check, right? What happens if your patch isn't applied and debugfs isn't enabled?
If debugfs isn't configured,
debugfs_initialized()and other functions are defined as following,static inline bool
debugfs_initialized(void)
{
return false;
}static inline struct dentry *debugfs_create_file(const char *name,
umode_tmode, struct dentry *parent, void *data,
const structfile_operations*fops)
{
returnERR_PTR(-ENODEV);
}static inline struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
returnERR_PTR(-ENODEV);
}Quoted 8 lines
Quoted 6 lines
And the checking code in xen\debugfs.c
xen_init_debugfs()will not work, the return value is not NULL.d_xen_debug=debugfs_create_dir("xen", NULL);if (!d_xen_debug)
pr_warning("Could not create 'xen' debugfs directory\n");Which is just fine, what is wrong with this?
If we no check with
debugfs_initialized(), the above code should be if (!d_xen_debug ||IS_ERR(d_xen_debug))pr_warning("Could not create 'xen' debugfs directory\n");Quoted 6 lines
Quoted 5 lines
No, you don't want to print out that message if debugfs is not enabled.
You really don't want to print anything out, as what can a user do about this?
Yep, should output a warning about "Debugfs is not configured and enabled"
No, not at all, it's not an issue you need to warn about because it was explicitly told to be that way by the person who built that kernel.
It's not an error, please don't treat it as such.
greg k-h
Quoted 8 lines · Ethan Zhao
Greg,
I am the man who built a Xen dom0, but couldn't see debugfs
directory and files as expected. there is no warning or tip for me to enable theCONFIG_DEBUG_FS=yin .config , it cost me minutes to figure out what's
the matter. and I know should check defugfs config and initialization aszswap_debugfs,tracer_debugfs,rproc_debugfs did. Is it useless ? if it could save me just 1 minute next time ?
So you would want a "warning" showing up for every single part of the kernel that uses debugfs for when it isn't enabled? That doesn't make too much sense now, does it?
If you need/want debugfs then enable it in the kernel build, it's not that hard, right?
greg k-h
Quoted 10 lines · Greg KH
Quoted 8 lines · Ethan Zhao
Greg,
I am the man who built a Xen dom0, but couldn't see debugfs
directory and files as expected. there is no warning or tip for me to enable theCONFIG_DEBUG_FS=yin .config , it cost me minutes to figure out what's
the matter. and I know should check defugfs config and initialization aszswap_debugfs,tracer_debugfs,rproc_debugfs did. Is it useless ? if it could save me just 1 minute next time ?
Quoted 3 lines
So you would want a "warning" showing up for every single part of the kernel that uses debugfs for when it isn't enabled? That doesn't make too much sense now, does it?
No, It is nice and like sun light when someone is struggling with the bugs in darkness,
if some tips or warning output to them.
You have forgotten the initial stage you met :)
Quoted 3 lines
If you need/want debugfs then enable it in the kernel build, it's not that hard, right?
of coz, not hard. and It not so hard to merge it too.
Thanks,
Ethan
Quoted 2 lines
greg k-h
Quoted 15 lines · Ethan Zhao
Quoted 10 lines · Greg KH
Quoted 8 lines · Ethan Zhao
Greg,
I am the man who built a Xen dom0, but couldn't see debugfs
directory and files as expected. there is no warning or tip for me to enable theCONFIG_DEBUG_FS=yin .config , it cost me minutes to figure out what's
the matter. and I know should check defugfs config and initialization aszswap_debugfs,tracer_debugfs,rproc_debugfs did. Is it useless ? if it could save me just 1 minute next time ?Quoted 3 lines
So you would want a "warning" showing up for every single part of the kernel that uses debugfs for when it isn't enabled? That doesn't make too much sense now, does it?
Quoted 5 lines
No, It is nice and like sun light when someone is struggling with the bugs in darkness,
if some tips or warning output to them.You have forgotten the initial stage you met :)
So, you really want to see 20+ KERNEL WARNINGS in your system when you boot without CONFIG_DEBUGFS enabled? No, that's not ok at all, sorry, that is not going to happen.
Running a kernel without debugfs is a valid state, you are treating it as an error, which isn't ok.
greg k-h
Quoted 20 lines · Greg KH
Quoted 19 lines · Ethan Zhao
Quoted 10 lines · Greg KH
Quoted 8 lines · Ethan Zhao
Greg,
I am the man who built a Xen dom0, but couldn't see debugfs
directory and files as expected. there is no warning or tip for me to enable theCONFIG_DEBUG_FS=yin .config , it cost me minutes to figure out what's
the matter. and I know should check defugfs config and initialization aszswap_debugfs,tracer_debugfs,rproc_debugfs did. Is it useless ? if it could save me just 1 minute next time ?Quoted 3 lines
So you would want a "warning" showing up for every single part of the kernel that uses debugfs for when it isn't enabled? That doesn't make too much sense now, does it?
No, It is nice and like sun light when someone is struggling with the bugs in darkness,
if some tips or warning output to them.
Quoted 5 lines
Quoted 1 line
You have forgotten the initial stage you met :)
So, you really want to see 20+ KERNEL WARNINGS in your system when you boot without
CONFIG_DEBUGFSenabled? No, that's not ok at all, sorry, that is not going to happen.
You got the right reason to make me give up !
Thanks,
Ethan
Quoted 5 lines
Running a kernel without debugfs is a valid state, you are treating it as an error, which isn't ok.
greg k-h