eal/windows: detect insufficient privileges for hugepages
PATCH 1/1 eal/windows: detect insufficient privileges for hugepages
AdjustTokenPrivileges() succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.
--- lib/librte_eal/windows/eal_hugepages.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/librte_eal/windows/eal_hugepages.c +4 -0
@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; } +/* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */ +if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ; exit:
Signature · 1 line
2.25.4
Quoted 14 lines · Dmitry Kozlyuk
AdjustTokenPrivileges()succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/librte_eal/windows/eal_hugepages.c | 4 ++++ 1 file changed, 4 insertions(+)lib/librte_eal/windows/eal_hugepages.c +0
-0
lib/librte_eal/windows/eal_hugepages.c hugepage_claim_privilege(void) · line 50
Quoted 10 lines
lib/librte_eal/windows/eal_hugepages.c +4
-0@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; } +/* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */ +if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ; exit:
Wouldn't this be better if we could print a message here after explicitly checking for the ERROR_NOT_ALL_ASSIGNED return value?
Otherwise, the caller simply gets a -1 return value for a failure with no message.
ranjit m.
Quoted 24 lines · Ranjit Menon
Quoted 23 lines · Dmitry Kozlyuk
AdjustTokenPrivileges()succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/librte_eal/windows/eal_hugepages.c | 4 ++++ 1 file changed, 4 insertions(+)lib/librte_eal/windows/eal_hugepages.c +4
-0@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; } +/* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */ +if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ;
Quoted 7 lines
lib/librte_eal/windows/eal_hugepages.c hugepage_claim_privilege(void) · line 50
Quoted 1 line
lib/librte_eal/windows/eal_hugepages.c +0
-0exit:Wouldn't this be better if we could print a message here after explicitly checking for the
ERROR_NOT_ALL_ASSIGNEDreturn value?Otherwise, the caller simply gets a -1 return value for a failure with no message.
Message is printed at ERR level by the caller. There's no context to add here.
Signature · 1 line
Dmitry Kozlyuk
Tal Shnaiderman
Tested-byQuoted 35 lines
Subject: Re: [PATCH] eal/windows: detect insufficient privileges for hugepages
Quoted 19 lines · Ranjit Menon
Quoted 18 lines · Dmitry Kozlyuk
AdjustTokenPrivileges()succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/librte_eal/windows/eal_hugepages.c | 4 ++++ 1 file changed, 4 insertions(+)lib/librte_eal/windows/eal_hugepages.c +0
-0@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; }Quoted 1 line
lib/librte_eal/windows/eal_hugepages.c hugepage_claim_privilege(void) · line 44
Quoted 1 line
lib/librte_eal/windows/eal_hugepages.c +1
-0+/* AdjustTokenPrivileges() may succeed with
ERROR_NOT_ALL_ASSIGNED. */Quoted 10 lines
lib/librte_eal/windows/eal_hugepages.c hugepage_claim_privilege(void) · line 50
Quoted 6 lines
lib/librte_eal/windows/eal_hugepages.c +3
-0+if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ; exit:Wouldn't this be better if we could print a message here after explicitly checking for the
ERROR_NOT_ALL_ASSIGNEDreturn value?
Quoted 5 lines
Quoted 2 lines
Otherwise, the caller simply gets a -1 return value for a failure with no message.
Message is printed at ERR level by the caller. There's no context to add here.
Tested successfully on Windows server 2019.
The output in case of missing privilege is:
EAL: Cannot claim hugepage privilege
EAL: FATAL: Cannot get hugepage information
EAL: Cannot get hugepage information
Do you think this is enough or do we want to give the user further indication that configuration action from his side might be needed? Something alike "Please verify OS Large-Page support is enabled for the current user"
Quoted 2 lines
--
Dmitry Kozlyuk
On Wed, 8 Jul 2020 06:43:57 +0000, Tal Shnaiderman wrote:
[snip]
Thanks for the testing.
Quoted 1 line
Do you think this is enough or do we want to give the user further indication that configuration action from his side might be needed? Something alike "Please verify OS Large-Page support is enabled for the current user"
Yes, troubleshooting suggestions would be useful.
From Microsoft "Error Message Guidelines" [1]:
Avoid the word "please". It can be interpreted to mean that a required action is optional.
[1]:
https://docs.microsoft.com/en-us/windows/win32/debug/error-message-guidelines
Signature · 1 line
Dmitry Kozlyuk
PATCH v2 1/1 eal/windows: detect insufficient privileges for hugepages
In reply to Dmitry KozlyukAdjustTokenPrivileges() succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.
Make error messages more specific and add troubleshooting hint.
---
v2:
Improve error reporting (Tal Shnaiderman).
lib/librte_eal/windows/eal_hugepages.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_eal/windows/eal_hugepages.c +8 -2
@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; } +/* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */ +if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ; exit:
@@ -98,12 +102,14 @@ inteal_hugepage_info_init (void) {if (hugepage_claim_privilege () <0 ) { -RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" ); +RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" +"Verify that large-page support privilege " +"is assigned to the current user\n" );return -1 ; }if (hugepage_info_init () <0 ) { -RTE_LOG (ERR ,EAL ,"Cannot get hugepage information\n" ); +RTE_LOG (ERR ,EAL ,"Cannot discover available hugepages\n" );return -1 ; }
Signature · 1 line
2.25.4
Quoted 37 lines · Dmitry Kozlyuk
AdjustTokenPrivileges()succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.Make error messages more specific and add troubleshooting hint.
Signed-off-by Dmitry Kozlyuk <[email protected]>---
v2:
Improve error reporting (Tal Shnaiderman).lib/librte_eal/windows/eal_hugepages.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)lib/librte_eal/windows/eal_hugepages.c +6
-1@@ -41,6 +41,10 @@ hugepage_claim_privilege(void) goto exit; } +/* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */ +if (GetLastError () !=ERROR_SUCCESS ) + goto exit; + ret =0 ; exit:@@ -98,12 +102,14 @@ inteal_hugepage_info_init (void) {if (hugepage_claim_privilege () <0 ) { -RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" ); +RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" + "Verify that large-page support privilege "
lib/librte_eal/windows/eal_hugepages.c int · line 115
Quoted 10 lines
lib/librte_eal/windows/eal_hugepages.c +2
-1+ "is assigned to the current user\n");return -1 ; }if (hugepage_info_init () <0 ) { -RTE_LOG (ERR ,EAL ,"Cannot get hugepage information\n" ); +RTE_LOG (ERR ,EAL ,"Cannot discover available hugepages\n" );return -1 ; }
09/07/2020 00:27, Ranjit Menon:
Quoted 8 lines · Dmitry Kozlyuk
Quoted 7 lines
AdjustTokenPrivileges()succeeds even if no requested privileges have been granted; this behavior is documented. Check last error code in addition to return value to detect such case.Make error messages more specific and add troubleshooting hint.
Signed-off-by Dmitry Kozlyuk <[email protected]>
[...]
Quoted 5 lines
lib/librte_eal/windows/eal_hugepages.c int · line 107
Quoted 5 lines
if (hugepage_claim_privilege() < 0) {lib/librte_eal/windows/eal_hugepages.c +3
-1-RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" ); +RTE_LOG (ERR ,EAL ,"Cannot claim hugepage privilege\n" +"Verify that large-page support privilege " +"is assigned to the current user\n" );
The error message can be searched in the code,
so it is better not to break lines.
Quoted 1 line
Acked-by Ranjit Menon <[email protected]>
Applied with merged log lines, thanks.