Skip to contentSkip to conversation

eal/windows: detect insufficient privileges for hugepages

PATCH Superseded Dmitry Kozlyuk 4 participants 8 messages Jul 7, 2020 – Jul 10, 2020

lore
Share & tools
lore
#0 lore raw

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
index 5779cd325..07a5467d0 100644
@@ -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
#1 lore raw
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.

---
  lib/librte_eal/windows/eal_hugepages.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/librte_eal/windows/eal_hugepages.c +0 -0
index 5779cd325..07a5467d0 100644

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.

#2 lore raw
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.

---
  lib/librte_eal/windows/eal_hugepages.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/librte_eal/windows/eal_hugepages.c +4 -0
index 5779cd325..07a5467d0 100644
@@ -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 -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.

Message is printed at ERR level by the caller. There's no context to add here.

Signature · 1 line
Dmitry Kozlyuk
Tested-by
#3 lore raw
Quoted 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.

---
  lib/librte_eal/windows/eal_hugepages.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/librte_eal/windows/eal_hugepages.c +0 -0
index 5779cd325..07a5467d0 100644
@@ -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_ASSIGNED return 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

#4 lore raw

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
#5 lore raw

PATCH v2 1/1 eal/windows: detect insufficient privileges for hugepages

In reply to 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.

---

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
index 5779cd325..7f8a7dfca 100644
@@ -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;
 	}
 
Signature · 1 line
2.25.4
Acked-by on v2 1/1
#6 lore raw
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.

---

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
index 5779cd325..7f8a7dfca 100644
@@ -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 "

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;
  	}
 
#7 lore raw

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.

[...]

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

Applied with merged log lines, thanks.