All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org
Cc: tglx@linutronix.de, dave.hansen@linux.intel.com,
	peterz@infradead.org, bp@alien8.de, rafael@kernel.org,
	riel@fb.com, bigeasy@linutronix.de, hch@lst.de,
	fenghua.yu@intel.com, rui.zhang@intel.com,
	artem.bityutskiy@linux.intel.com, jacob.jun.pan@linux.intel.com,
	lenb@kernel.org, chang.seok.bae@intel.com
Subject: [PATCH v5 1/2] x86/fpu: Add a helper to prepare AMX state for low-power CPU idle
Date: Wed,  8 Jun 2022 09:47:47 -0700	[thread overview]
Message-ID: <20220608164748.11864-2-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20220608164748.11864-1-chang.seok.bae@intel.com>

When a CPU enters an idle state, a non-initialized AMX register state may
be the cause of preventing a deeper low-power state. Other extended
register states whether initialized or not do not impact the CPU idle
state.

The new helper can ensure the AMX state is initialized before the CPU is
idle, and it will be used by the intel idle driver.

Check the AMX_TILE feature bit before using XGETBV1 as a chain of
dependencies was established via cpuid_deps[]: AMX->XFD->XGETBV1.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Rik van Riel <riel@fb.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
Changes from v4:
* Switch to check the AMX_TILE flag instead XGETBV1 (Dave Hansen).
* Massage the changelog.

Changes from v3:
* Call out AMX state in changelog (Thomas Glexiner).

Changes from v2:
* Check the feature flag instead of fpu_state_size_dynamic() (Dave Hansen).

Changes from v1:
* Check the dynamic state flag first, to avoid #UD with XGETBV(1).
---
 arch/x86/include/asm/fpu/api.h       |  2 ++
 arch/x86/include/asm/special_insns.h |  9 +++++++++
 arch/x86/kernel/fpu/core.c           | 14 ++++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index 6b0f31fb53f7..503a577814b2 100644
--- a/arch/x86/include/asm/fpu/api.h
+++ b/arch/x86/include/asm/fpu/api.h
@@ -164,4 +164,6 @@ static inline bool fpstate_is_confidential(struct fpu_guest *gfpu)
 /* prctl */
 extern long fpu_xstate_prctl(int option, unsigned long arg2);
 
+extern void fpu_idle_fpregs(void);
+
 #endif /* _ASM_X86_FPU_API_H */
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 45b18eb94fa1..35f709f619fb 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -295,6 +295,15 @@ static inline int enqcmds(void __iomem *dst, const void *src)
 	return 0;
 }
 
+static inline void tile_release(void)
+{
+	/*
+	 * Instruction opcode for TILERELEASE; supported in binutils
+	 * version >= 2.36.
+	 */
+	asm volatile(".byte 0xc4, 0xe2, 0x78, 0x49, 0xc0");
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_SPECIAL_INSNS_H */
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 0531d6a06df5..3b28c5b25e12 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -851,3 +851,17 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
 	 */
 	return 0;
 }
+
+/*
+ * Initialize register state that may prevent from entering low-power idle.
+ * This function will be invoked from the cpuidle driver only when needed.
+ */
+void fpu_idle_fpregs(void)
+{
+	/* Note: AMX_TILE being enabled implies XGETBV1 support */
+	if (cpu_feature_enabled(X86_FEATURE_AMX_TILE) &&
+	    (xfeatures_in_use() & XFEATURE_MASK_XTILE)) {
+		tile_release();
+		fpregs_deactivate(&current->thread.fpu);
+	}
+}
-- 
2.17.1


  reply	other threads:[~2022-06-08 17:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 16:47 [PATCH v5 0/2] x86/fpu: Make AMX state ready for CPU idle Chang S. Bae
2022-06-08 16:47 ` Chang S. Bae [this message]
2022-06-08 19:32   ` [tip: x86/fpu] x86/fpu: Add a helper to prepare AMX state for low-power " tip-bot2 for Chang S. Bae
2022-06-14 22:46   ` tip-bot2 for Chang S. Bae
2022-06-14 22:53   ` tip-bot2 for Chang S. Bae
2022-07-19 17:31   ` tip-bot2 for Chang S. Bae
2022-06-08 16:47 ` [PATCH v5 2/2] intel_idle: Add a new flag to initialize the AMX state Chang S. Bae
2022-06-08 19:32   ` [tip: x86/fpu] " tip-bot2 for Chang S. Bae
2022-06-09 10:23     ` Peter Zijlstra
2022-06-14 16:41       ` [PATCH][Rebased] " Chang S. Bae
2022-07-19 17:31         ` [tip: x86/fpu] " tip-bot2 for Chang S. Bae
     [not found]   ` <38cd51750ef7b995506d001eae3e4ec872cf5b77.camel@linux.intel.com>
2022-06-14 17:23     ` [PATCH v5 2/2] " Chang S. Bae
2022-06-15  6:25       ` Artem Bityutskiy
2022-06-14 22:53   ` [tip: x86/fpu] " tip-bot2 for Chang S. Bae
2022-07-18  9:06     ` Borislav Petkov
2022-07-18 18:56       ` [PATCH][Rebased] " Chang S. Bae

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=20220608164748.11864-2-chang.seok.bae@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hch@lst.de \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=riel@fb.com \
    --cc=rui.zhang@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.