sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at
PATCH 1/1 sysfs: Remove page boundary align limitation on sysfs_emit and sysfs_emit_at
The key purpose of sysfs_emit and sysfs_emit_at is to ensure that no overrun is done. Make them more equivalent with scnprintf.
--- fs/sysfs/file.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/sysfs/file.c +10 -6
@@ -732,14 +732,16 @@ EXPORT_SYMBOL_GPL(sysfs_change_owner);int sysfs_emit (char *buf,const char *fmt, ...) {va_list args; -int len; +int len, offset; -if (WARN (!buf ||offset_in_page (buf), + offset =offset_in_page (buf); + +if (WARN (!buf,"invalid sysfs_emit: buf:%p\n" , buf))return 0 ;va_start (args, fmt); - len =vscnprintf (buf,PAGE_SIZE , fmt, args); + len =vscnprintf (buf,PAGE_SIZE - offset, fmt, args);va_end (args);return len;
@@ -760,14 +762,16 @@ EXPORT_SYMBOL_GPL(sysfs_emit);int sysfs_emit_at (char *buf,int at,const char *fmt, ...) {va_list args; -int len; +int len, offset; + + offset =offset_in_page (buf); -if (WARN (!buf ||offset_in_page (buf) || at <0 || at >=PAGE_SIZE , +if (WARN (!buf || at <0 || at + offset >=PAGE_SIZE ,"invalid sysfs_emit_at: buf:%p at:%d\n" , buf, at))return 0 ;va_start (args, fmt); - len =vscnprintf (buf + at,PAGE_SIZE - at, fmt, args); + len =vscnprintf (buf + at,PAGE_SIZE - at - offset, fmt, args);va_end (args);return len;
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 3 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.
That's not the only purpose.
So why are you changing this?
What in-kernel users are being tripped up by this, shouldn't we fix them instead?
Remember, sysfs files are "one value per file", so why are the boundries not properly set here?
thanks,
greg k-h
[AMD Official Use Only]
Thanks for your reply.
Just curious if we don't put such a limitation, what are the consequences? If we remove the limitation, sys_emit/sys_emit_at api will be more flexible. Since the comments of sysfs_emit/ sys_emit_at api are
" sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer. ", Why not make them more equivalent with scnprintf?
Regards,
Lang
Quoted 25 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Wednesday, September 8, 2021 8:32 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.That's not the only purpose.
So why are you changing this?
What in-kernel users are being tripped up by this, shouldn't we fix them instead?
Remember, sysfs files are "one value per file", so why are the boundries not properly set here?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerA: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
Quoted 8 lines · Lang
[AMD Official Use Only]
Thanks for your reply.
Just curious if we don't put such a limitation, what are the consequences? If we remove the limitation, sys_emit/sys_emit_at api will be more flexible. Since the comments of sysfs_emit/sys_emit_atapi are
"sysfs_emit- scnprintf equivalent, aware ofPAGE_SIZEbuffer. ", Why not make them more equivalent with scnprintf?
Because this is not a general replacement for scnprintf(), it is only to be used with sysfs files.
Where else are you wanting to use these functions that this patch woulud be required that does not haver to deal with sysfs?
thanks,
greg k-h
[AMD Official Use Only]
Quoted 48 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Wednesday, September 8, 2021 9:04 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atA:
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fen.wikipe
dia.org%2Fwiki%2FTop_post&data=04%7C01%7CLang.Yu%40amd.com%7C fed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d994e183d %7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000& amp;sdata=LHujj041jxZjvoYxVYUKtNr7us%2FX4pl%2FdOkFSOP1W8U%3D&r eserved=0
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?A: No.
Q: Should I include quotations after my reply?https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdaringfire
ball.net%2F2007%2F07%2Fon_top&data=04%7C01%7CLang.Yu%40amd.co m%7Cfed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d99 4e183d%7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d8ey JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C 1000&sdata=AOLGBdj01XiEjhmsBSGTNuqejgU%2B6jg416Paz5XdM1A%3D&a mp;reserved=0Quoted 8 lines · Lang
[AMD Official Use Only]
Thanks for your reply.
Just curious if we don't put such a limitation, what are the consequences? If we remove the limitation, sys_emit/sys_emit_at api will be more flexible. Since the comments of sysfs_emit/sys_emit_atapi are "sysfs_emit- scnprintf equivalent, aware ofPAGE_SIZEbuffer. ", Why not make them more equivalent with scnprintf?Because this is not a general replacement for
scnprintf(), it is only to be used with sysfs files.
Quoted 6 lines
Where else are you wanting to use these functions that this patch woulud be required that does not haver to deal with sysfs?
thanks,
greg k-h
But some guys think it is a general replacement for scnprintf(), and recommend that use sysfs_emit() instead of scnprintf(),
and send many patches that replace scnprintf() with sysfs_emit(), and finally cause some invalid sysfs_emit_at: buf:00000000f19bdfde warnings.
I think we better not put " scnprintf equivalent, aware of PAGE_SIZE buffer " words in comments. It is obviously not. Some guys are misled by that. Thanks!
Regards,
Lang
Greg Kroah-Hartman
maintainerQuoted 52 lines · Lang
[AMD Official Use Only]
Quoted 48 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Wednesday, September 8, 2021 9:04 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atA:
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fen.wikipe
dia.org%2Fwiki%2FTop_post&data=04%7C01%7CLang.Yu%40amd.com%7C fed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d994e183d %7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000& amp;sdata=LHujj041jxZjvoYxVYUKtNr7us%2FX4pl%2FdOkFSOP1W8U%3D&r eserved=0
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?A: No.
Q: Should I include quotations after my reply?https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdaringfire
ball.net%2F2007%2F07%2Fon_top&data=04%7C01%7CLang.Yu%40amd.co m%7Cfed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d99 4e183d%7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d8ey JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C 1000&sdata=AOLGBdj01XiEjhmsBSGTNuqejgU%2B6jg416Paz5XdM1A%3D&a mp;reserved=0Quoted 8 lines · Lang
[AMD Official Use Only]
Thanks for your reply.
Just curious if we don't put such a limitation, what are the consequences? If we remove the limitation, sys_emit/sys_emit_at api will be more flexible. Since the comments of sysfs_emit/sys_emit_atapi are "sysfs_emit- scnprintf equivalent, aware ofPAGE_SIZEbuffer. ", Why not make them more equivalent with scnprintf?Because this is not a general replacement for
scnprintf(), it is only to be used with sysfs files.
Quoted 8 lines
Quoted 6 lines
Where else are you wanting to use these functions that this patch woulud be required that does not haver to deal with sysfs?
thanks,
greg k-h
But some guys think it is a general replacement for
scnprintf(),
Who thinks that? Where? The name should give them a clue that this is not true.
Quoted 1 line
and recommend that use
sysfs_emit()instead ofscnprintf(),
Please no.
Quoted 2 lines
and send many patches that replace
scnprintf()withsysfs_emit(), and finally cause some invalidsysfs_emit_at: buf:00000000f19bdfde warnings.
Where were those patches sent? I will be glad to review those.
Quoted 2 lines
I think we better not put " scnprintf equivalent, aware of
PAGE_SIZEbuffer " words in comments. It is obviously not. Some guys are misled by that. Thanks!
Please feel free to add better documentation for the functions if you feel people are getting confused, do not change the existing behavior of the code as it rightly caught it being misused.
thanks,
greg k-h
[AMD Official Use Only]
Quoted 102 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Wednesday, September 8, 2021 9:49 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 16 lines · Lang
[AMD Official Use Only]
Quoted 12 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Wednesday, September 8, 2021 9:04 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atA:
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fen.w
ikipe%2F&data=04%7C01%7CLang.Yu%40amd.com%7C43d1354fdeda45713a340
Quoted 1 line
Quoted 1 line
8d972cf6fcd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C63766
7057520
Quoted 1 line
Quoted 1 line
373013%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2l
uMzIiLC
Quoted 1 line
Quoted 1 line
JBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tfUI5HXg6YbMRtFXs7
X0o7Z
Quoted 2 lines
Quoted 2 lines
rRgKdwJfk%2FwIykAEkNCY%3D&reserved=0 dia.org%2Fwiki%2FTop_post&data=04%7C01%7CLang.Yu%40amd.com%
7C
Quoted 1 line
Quoted 1 line
fed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d994e1
83d
Quoted 1 line
Quoted 1 line
%7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d8eyJWIj
oi
Quoted 1 line
Quoted 1 line
MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100
0&
Quoted 1 line
Quoted 1 line
amp;sdata=LHujj041jxZjvoYxVYUKtNr7us%2FX4pl%2FdOkFSOP1W8U%3D&am
p;r
Quoted 7 lines
Quoted 7 lines
eserved=0
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?Quoted 6 lines
Quoted 6 lines
A: No.
Q: Should I include quotations after my reply?https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdari
ngfire ball.net%2F2007%2F07%2Fon_top&data=04%7C01%7CLang.Yu%40amd.co
Quoted 1 line
Quoted 1 line
m%7Cfed047de547541548fcc08d972c92627%7C3dd8961fe4884e608e11a82d
99
Quoted 1 line
Quoted 1 line
4e183d%7C0%7C0%7C637667030534349355%7CUnknown%7CTWFpbGZsb3d
8ey
Quoted 1 line
Quoted 1 line
JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%
7C
Quoted 1 line
Quoted 1 line
1000&sdata=AOLGBdj01XiEjhmsBSGTNuqejgU%2B6jg416Paz5XdM1A%3D
&a
Quoted 16 lines
Quoted 16 lines
mp;reserved=0
Quoted 8 lines · Lang
[AMD Official Use Only]
Thanks for your reply.
Just curious if we don't put such a limitation, what are the consequences? If we remove the limitation, sys_emit/sys_emit_at api will be more flexible. Since the comments of sysfs_emit/sys_emit_atapi are "sysfs_emit
- scnprintf equivalent, aware ofPAGE_SIZEbuffer. ", Why not make them more equivalent with scnprintf?Because this is not a general replacement for
scnprintf(), it is only to be used with sysfs files.Quoted 8 lines
Quoted 6 lines
Where else are you wanting to use these functions that this patch woulud be required that does not haver to deal with sysfs?
thanks,
greg k-h
But some guys think it is a general replacement for
scnprintf(),Who thinks that? Where? The name should give them a clue that this is not true.
Quoted 1 line
and recommend that use
sysfs_emit()instead ofscnprintf(),Please no.
Quoted 2 lines
and send many patches that replace
scnprintf()withsysfs_emit(), and finally cause some invalidsysfs_emit_at: buf:00000000f19bdfde warnings.Where were those patches sent? I will be glad to review those.
Quoted 7 lines
Quoted 1 line
I think we better not put " scnprintf equivalent, aware of
PAGE_SIZEbuffer "words in comments.
Quoted 1 line
It is obviously not. Some guys are misled by that. Thanks!
Please feel free to add better documentation for the functions if you feel people are getting confused, do not change the existing behavior of the code as it rightly caught it being misused.
You can find many patches named "convert sysfs scnprintf/snprintf to syfs_emit/sysfs_emit_at".
or "use sysfs_emit/sysfs_emit_at in show functions". They may think it's better to use syfs_emit/sysfs_emit_at given its overrun avoidance. But there are still some corner cases(e.g., a non page boundary aligned buf address : ). Thanks for your explanations and have a nice day!
Regards,
Lang
Quoted 4 lines
thanks,
greg k-h
Quoted 3 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.
I can't think of a single reason to do this. sysfs_emit and sysfs_emit_at are specific to sysfs.
Use of these functions outside of sysfs is not desired or supported.
Greg Kroah-Hartman
maintainerQuoted 7 lines · Lang
Quoted 3 lines
Please feel free to add better documentation for the functions if you feel people are getting confused, do not change the existing behavior of the code as it rightly caught it being misused.
You can find many patches named "convert sysfs scnprintf/snprintf to syfs_emit/sysfs_emit_at". or "use sysfs_emit/sysfs_emit_at in show functions". They may think it's better to use syfs_emit/sysfs_emit_at given its overrun avoidance.
Yes, and using that in sysfs functions is fine, there is nothing wrong with this usage.
Quoted 1 line
But there are still some corner
cases(e.g., a non page boundary aligned buf address : ).
I need a specific example of where this has gone wrong. Please provide a lore.kernel.org link as I fail to see the problem here.
Are you sure that you are not just abusing sysfs and having more than one value per file? Does this mean I need to go audit all of the gpu sysfs file entries?
thanks,
greg k-h
[AMD Official Use Only]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:06 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_at
Quoted 10 lines
Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "Documentation/filesystems/sysfs.rst" described, we can just use scnprintf(buf, PAGE_SIZE, "%s\n", dev->name) in show functions without such a limitation.
But you said that " - show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. " in Documentation/filesystems/sysfs.rst.
Some guys just try to replace scnprintf with sysfs_emit() or sysfs_emit_at() per above documents. But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page boundary align).
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api? Thanks.
Regards,
Lang
[AMD Official Use Only]
Quoted 22 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 1:19 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 5 lines · Lang
Quoted 3 lines
Please feel free to add better documentation for the functions if you feel people are getting confused, do not change the existing behavior of the code as it rightly caught it being misused.
You can find many patches named "convert sysfs scnprintf/snprintf to
syfs_emit/sysfs_emit_at".
Quoted 2 lines
or "use sysfs_emit/sysfs_emit_at in show functions". They may think it's better to use syfs_emit/sysfs_emit_at given its overrun avoidance.
Yes, and using that in sysfs functions is fine, there is nothing wrong with this usage.
Quoted 9 lines
Quoted 1 line
But there are still some corner cases(e.g., a non page boundary aligned buf
address : ).
I need a specific example of where this has gone wrong. Please provide a lore.kernel.org link as I fail to see the problem here.
Are you sure that you are not just abusing sysfs and having more than one value per file? Does this mean I need to go audit all of the gpu sysfs file entries?
Indeed, the one value per file rule was broken... Thanks.
Regard,
Lang
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 28 lines · Lang
[AMD Official Use Only]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:06 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 10 lines
Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.
Quoted 4 lines
But you said that " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " inDocumentation/filesystems/sysfs.rst.Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()per above documents.
That is just fine in sysfs show() functions.
Quoted 1 line
But sprintf and sysfs_emit/sysfs_emit_at are not totally
equivalent(e.g., page boundary align).
Which is good, it checks for more error conditions.
I fail to understand what problem you have had with this. What sysfs file was converted and had issues?
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api? Thanks.
There is no "old api" here. People used a wide variety of different things in sysfs file show() functions, now you can just use a single one.
thanks,
greg k-h
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Quoted 9 lines
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.
Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.
There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that sysfs_emit exists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.
The issue there is that buf is already known to be both a PAGE_SIZE buffer and PAGE_SIZE aligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emit is a shorter/smaller function and using it could avoid some sprintf defects.
Quoted 1 line
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()per above documents.
So don't do that.
Quoted 4 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally
equivalent(e.g., page boundary align).In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
[Public]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_at
Quoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 35 lines
Quoted 10 lines
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]>Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 1 line
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 8 lines
Quoted 1 line
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 3 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
But why you said " - show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. " in Documentation/filesystems/sysfs.rst ?
Obviously, sysfs_emit() and sysfs_emit_at() can't cover all the cases in show functions.
Regards,
Lang
[AMD Official Use Only]
Quoted 51 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 1:35 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 22 lines · Lang
Quoted 12 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:06 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 10 lines
Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Use of these functions outside of sysfs is not desired or supported.
Quoted 7 lines
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.But you said that " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
That is just fine in sysfs
show()functions.Quoted 1 line
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Which is good, it checks for more error conditions.
Quoted 8 lines
I fail to understand what problem you have had with this. What sysfs file was converted and had issues?
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api? Thanks.
There is no "old api" here. People used a wide variety of different things in sysfs file
show()functions, now you can just use a single one.
Yes, replace these things in sysfs show functions to avoid sprintf defects makes life better. But assume users will put a page boundary align buffer address in its' first argument makes life so hard.
Regards,
Lang
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 29 lines · Lang
[AMD Official Use Only]
Quoted 25 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 1:19 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 5 lines · Lang
Quoted 3 lines
Please feel free to add better documentation for the functions if you feel people are getting confused, do not change the existing behavior of the code as it rightly caught it being misused.
You can find many patches named "convert sysfs scnprintf/snprintf to
syfs_emit/sysfs_emit_at".
Quoted 2 lines
or "use sysfs_emit/sysfs_emit_at in show functions". They may think it's better to use syfs_emit/sysfs_emit_at given its overrun avoidance.
Yes, and using that in sysfs functions is fine, there is nothing wrong with this usage.
Quoted 1 line
But there are still some corner cases(e.g., a non page boundary aligned buf
address : ).
Quoted 7 lines
Quoted 6 lines
I need a specific example of where this has gone wrong. Please provide a lore.kernel.org link as I fail to see the problem here.
Are you sure that you are not just abusing sysfs and having more than one value per file? Does this mean I need to go audit all of the gpu sysfs file entries?
Indeed, the one value per file rule was broken... Thanks.
Great, which file is that so we can fix it!
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 58 lines · Lang
[AMD Official Use Only]
Quoted 54 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 1:35 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 22 lines · Lang
Quoted 12 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:06 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 10 lines
Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Use of these functions outside of sysfs is not desired or supported.
Quoted 7 lines
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.But you said that " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
That is just fine in sysfs
show()functions.Quoted 1 line
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Which is good, it checks for more error conditions.
I fail to understand what problem you have had with this. What sysfs file was converted and had issues?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api? Thanks.
There is no "old api" here. People used a wide variety of different things in sysfs file
show()functions, now you can just use a single one.Yes, replace these things in sysfs show functions to avoid sprintf defects makes life better. But assume users will put a page boundary align buffer address in its' first argument makes life so hard.
Not at all, that is what sysfs requires.
As you have pointed out, someone violated the sysfs rules, and these functions caught that, which shows that the code is correct and that the driver needs to be fixed.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 60 lines · Lang
[Public]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 41 lines
Quoted 10 lines
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]>Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 1 line
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 1 line
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 3 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
Quoted 6 lines
Quoted 2 lines
IMO: no.
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " inDocumentation/filesystems/sysfs.rst?Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in show functions.
Why not, what usage model can it not cover?
thanks,
greg k-h
[Public]
Quoted 74 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:08 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 64 lines · Lang
[Public]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 45 lines
Quoted 10 lines
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]> On Wed, 2021-09-08 at 20:07Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 2 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 3 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
Quoted 8 lines
Quoted 2 lines
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst?Quoted 2 lines
Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in showfunctions.
Why not, what usage model can it not cover?
Of course, we can modify driver code to obey sysfs_emit and sysfs_emit_at rules or just use scnprintf in show functions. Now that you introduced them, why not make them more flexible like scnprintf family functions.
The page boundary align rule makes life hard and I don't like it : ). Many thanks for your explanations!
Regards,
Lang
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 80 lines · Lang
[Public]
Quoted 76 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:08 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 66 lines · Lang
[Public]
Quoted 9 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 36 lines
Quoted 10 lines
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]> On Wed, 2021-09-08 at 20:07Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 9 lines
Quoted 2 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 3 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Quoted 8 lines
Quoted 6 lines
Documentation/filesystems/sysfs.rst?Quoted 2 lines
Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in showfunctions.
Why not, what usage model can it not cover?
Of course, we can modify driver code to obey
sysfs_emitandsysfs_emit_atrules or just use scnprintf in show functions.
Great, please do.
Quoted 1 line
Now that you introduced them, why not make them more flexible like scnprintf family functions.
Because that is not what they are for.
Quoted 1 line
The page boundary align rule makes life hard and I don't like it : ). Many thanks for your explanations!
Then fix your sysfs files to not violate the sysfs rules.
Again, which files are having problems and need to be fixed? I will be glad to do this for you.
thanks,
greg k-h
[Public]
Quoted 111 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:36 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 85 lines · Lang
[Public]
Quoted 81 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:08 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 61 lines · Lang
[Public]
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>;
linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 41 lines
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: Joe Perches <[email protected]> On Wed, 2021-09-08 at 20:07Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 2 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst?Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in showfunctions.
Why not, what usage model can it not cover?
Of course, we can modify driver code to obey
sysfs_emitandsysfs_emit_atrules or just use scnprintf in show functions.
Great, please do.
Quoted 1 line
Now that you introduced them, why not make them more flexible like scnprintf
family functions.
Because that is not what they are for.
Quoted 7 lines
Quoted 1 line
The page boundary align rule makes life hard and I don't like it : ). Many thanks
for your explanations!
Then fix your sysfs files to not violate the sysfs rules.
Again, which files are having problems and need to be fixed? I will be glad to do this for you.
Thanks. I can do it by myself instead of wasting your time... Many thanks!
Regards,
Lang
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 116 lines · Lang
[Public]
Quoted 112 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:36 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 85 lines · Lang
[Public]
Quoted 81 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:08 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 61 lines · Lang
[Public]
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>;
linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 41 lines
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: Joe Perches <[email protected]> On Wed, 2021-09-08 at 20:07Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent with scnprintf.I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Quoted 6 lines
Quoted 2 lines
Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a limitation. As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 2 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst?Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in showfunctions.
Why not, what usage model can it not cover?
Of course, we can modify driver code to obey
sysfs_emitandsysfs_emit_atrules or just use scnprintf in show functions.
Great, please do.
Quoted 1 line
Now that you introduced them, why not make them more flexible like scnprintf
family functions.
Because that is not what they are for.
Quoted 1 line
The page boundary align rule makes life hard and I don't like it : ). Many thanks
Quoted 8 lines
Quoted 6 lines
for your explanations!
Then fix your sysfs files to not violate the sysfs rules.
Again, which files are having problems and need to be fixed? I will be glad to do this for you.
Thanks. I can do it by myself instead of wasting your time... Many thanks!
When doing so, please switch to using DEVICE_ATTR_RO() instead of the "open coded" DEVICE_ATTR() usage in the driver. That way we all "know" that these are read-only attributes.
thanks,
greg k-h
[Public]
Quoted 135 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 4:00 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 55 lines · Lang
[Public]
Quoted 51 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:36 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 41 lines · Lang
[Public]
Quoted 37 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, September 9, 2021 2:08 PM
To: Yu, Lang <[email protected]>
Cc: Joe Perches <[email protected]>; Rafael J . Wysocki <[email protected]>; [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 27 lines · Lang
[Public]
Quoted 10 lines
-----Original Message-----
From: Joe Perches <[email protected]>
Sent: Thursday, September 9, 2021 1:44 PM
To: Yu, Lang <[email protected]>; Greg Kroah-Hartman <[email protected]>; Rafael J . Wysocki <[email protected]>;
linux- [email protected]
Subject: Re: [PATCH] sysfs: Remove page boundary align limitation onsysfs_emitandsysfs_emit_atQuoted 4 lines
Quoted 1 line · Lang
[AMD Official Use Only]
this is a public list and this marker is not appropriate.
Sorry for that.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Joe Perches <[email protected]> On Wed, 2021-09-08 at 20:07Quoted 2 lines · Lang Yu
The key purpose of
sysfs_emitandsysfs_emit_atis to ensure that no overrun is done. Make them more equivalent withscnprintf.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
I can't think of a single reason to do this.
sysfs_emitandsysfs_emit_atare specific to sysfs.Use of these functions outside of sysfs is not desired or supported.
Thanks for your reply. But I'm still curious why you put such a
limitation.
Quoted 61 lines
Quoted 61 lines
Quoted 37 lines
Quoted 37 lines
Quoted 27 lines
Quoted 27 lines
Quoted 3 lines
As "
Documentation/filesystems/sysfs.rst" described, we can just usescnprintf(buf, PAGE_SIZE, "%s\n", dev->name)in show functions without such a limitation.There's nothing particularly wrong with the use of scnprintf as above.
The only real reason that
sysfs_emitexists is to be able to reduce the kernel treewide quantity of uses of the sprintf family of functions that need to be analyzed for possible buffer overruns.The issue there is that buf is already known to be both a
PAGE_SIZEbuffer andPAGE_SIZEaligned for sysfs show functions so there's no real reason to use scnprintf.
sysfs_emitis a shorter/smaller function and using it could avoid some sprintf defects.Quoted 2 lines
Some guys just try to replace scnprintf with
sysfs_emit()orsysfs_emit_at()perabove documents.
So don't do that.
Quoted 2 lines
But sprintf and sysfs_emit/sysfs_emit_at are not totally equivalent(e.g., page
boundary align).
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In my opinion, we add a new api and try to replace an old api. Does we need to make it more compatible with old api?
IMO: no.
But why you said " -
show()should only usesysfs_emit()orsysfs_emit_at()when formatting the value to be returned to user space. " in
Documentation/filesystems/sysfs.rst?Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Obviously,
sysfs_emit()andsysfs_emit_at()can't cover all the cases in showfunctions.
Why not, what usage model can it not cover?
Of course, we can modify driver code to obey
sysfs_emitandsysfs_emit_atrules or just use scnprintf in show functions.
Great, please do.
Quoted 2 lines
Now that you introduced them, why not make them more flexible like scnprintf
family functions.
Because that is not what they are for.
Quoted 2 lines
The page boundary align rule makes life hard and I don't like it :
). Many thanksfor your explanations!
Then fix your sysfs files to not violate the sysfs rules.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Again, which files are having problems and need to be fixed? I will be glad to do this for you.
Thanks. I can do it by myself instead of wasting your time... Many thanks!
When doing so, please switch to using
DEVICE_ATTR_RO()instead of the "open coded"DEVICE_ATTR()usage in the driver. That way we all "know" that these are read-only attributes.
Many thanks for you reminders! Have a nice day!
Regards,
Lang
Quoted 4 lines
thanks,
greg k-h