DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: anatoly.burakov@intel.com, David Hunt <david.hunt@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH] eal/x86: fix segfaults in waitpkg power intrinsics
Date: Tue,  7 Nov 2023 16:19:01 +0000	[thread overview]
Message-ID: <20231107161900.46058-1-bruce.richardson@intel.com> (raw)

From: David Hunt <david.hunt@intel.com>

The code was recently enhanced to allow the use of the waitpkg
intrinsics rather than the raw assembly in the rte_power functions.
However, the parameters to the intrinsics, while compiling fine, were
incorrect, and would segfault when run on the appropriate hardware.
This patch fixes the intrinsic parameters. Tested on a system with
tpause and umonitor/umwait instructions.

Fixes: 60943c04f3bc ("eal/x86: use intrinsics for power management")

Signed-off-by: David Hunt <david.hunt@intel.com>
Reviewed-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/eal/x86/rte_power_intrinsics.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/eal/x86/rte_power_intrinsics.c b/lib/eal/x86/rte_power_intrinsics.c
index 483395dcd5..532a2e646b 100644
--- a/lib/eal/x86/rte_power_intrinsics.c
+++ b/lib/eal/x86/rte_power_intrinsics.c
@@ -40,12 +40,12 @@ static void intel_umonitor(volatile void *addr)
 
 static void intel_umwait(const uint64_t timeout)
 {
+#if defined(RTE_TOOLCHAIN_MSVC) || defined(__WAITPKG__)
+	_umwait(0, timeout);
+#else
 	const uint32_t tsc_l = (uint32_t)timeout;
 	const uint32_t tsc_h = (uint32_t)(timeout >> 32);
 
-#if defined(RTE_TOOLCHAIN_MSVC) || defined(__WAITPKG__)
-	_umwait(tsc_l, tsc_h);
-#else
 	asm volatile(".byte 0xf2, 0x0f, 0xae, 0xf7;"
 			: /* ignore rflags */
 			: "D"(0), /* enter C0.2 */
@@ -208,17 +208,17 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc,
 int
 rte_power_pause(const uint64_t tsc_timestamp)
 {
-	const uint32_t tsc_l = (uint32_t)tsc_timestamp;
-	const uint32_t tsc_h = (uint32_t)(tsc_timestamp >> 32);
-
 	/* prevent user from running this instruction if it's not supported */
 	if (!wait_supported)
 		return -ENOTSUP;
 
 	/* execute TPAUSE */
 #if defined(RTE_TOOLCHAIN_MSVC) || defined(__WAITPKG__)
-	_tpause(tsc_l, tsc_h);
+	_tpause(0, tsc_timestamp);
 #else
+	const uint32_t tsc_l = (uint32_t)tsc_timestamp;
+	const uint32_t tsc_h = (uint32_t)(tsc_timestamp >> 32);
+
 	asm volatile(".byte 0x66, 0x0f, 0xae, 0xf7;"
 			: /* ignore rflags */
 			: "D"(0), /* enter C0.2 */
-- 
2.39.2


             reply	other threads:[~2023-11-07 16:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 16:19 Bruce Richardson [this message]
2023-11-08  3:19 ` Tyler Retzlaff
2023-11-08 15:15   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231107161900.46058-1-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).