[v2] eal/windows: detect insufficient privileges for hugepages

Message ID 20200708214843.3080-1-dmitry.kozliuk@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] eal/windows: detect insufficient privileges for hugepages |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Dmitry Kozlyuk July 8, 2020, 9:48 p.m. UTC
  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 <dmitry.kozliuk@gmail.com>
---

v2:
    Improve error reporting (Tal Shnaiderman).

 lib/librte_eal/windows/eal_hugepages.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Menon, Ranjit July 8, 2020, 10:27 p.m. UTC | #1
On 7/8/2020 2:48 PM, Dmitry Kozlyuk wrote:
> 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 <dmitry.kozliuk@gmail.com>
> ---
>
> v2:
>      Improve error reporting (Tal Shnaiderman).
>
>   lib/librte_eal/windows/eal_hugepages.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
> index 5779cd325..7f8a7dfca 100644
> --- a/lib/librte_eal/windows/eal_hugepages.c
> +++ b/lib/librte_eal/windows/eal_hugepages.c
> @@ -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 @@ int
>   eal_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;
>   	}
>   


Acked-by: Ranjit Menon <ranjit.menon@intel.com>
  
Thomas Monjalon July 10, 2020, 9:25 p.m. UTC | #2
09/07/2020 00:27, Ranjit Menon:
> On 7/8/2020 2:48 PM, Dmitry Kozlyuk wrote:
> > 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 <dmitry.kozliuk@gmail.com>
[...]
> >   	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");

The error message can be searched in the code,
so it is better not to break lines.

> Acked-by: Ranjit Menon <ranjit.menon@intel.com>

Applied with merged log lines, thanks.
  

Patch

diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 5779cd325..7f8a7dfca 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -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 @@  int
 eal_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;
 	}