Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2226379pxb; Thu, 4 Nov 2021 16:31:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeGsghQ0fTTfoFbsrlwJSgUJHEXpU4Gu3TybjmtYeSBqDjHxCsLIloGWa8RIx4xOXteurz X-Received: by 2002:a17:906:7ccf:: with SMTP id h15mr20871873ejp.386.1636068676863; Thu, 04 Nov 2021 16:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636068676; cv=none; d=google.com; s=arc-20160816; b=IP1reNg6M5VsC9srcGxIb8fqZPs9WTqHba6p9afO7wMRkqpUVUwopow5Bz3YTFEV6R pl4QgpoE+4JH8Rls0GMaoBT71k9j7tRWMKJ3Wdn0IrC5VQea/MrJxtFsU3fWXVvBRjOe nbB2sC1VH4DdSAQJhLE4H3/NI4T1GbnUUzRzmIl/hKd5Ig1t3Qt54i5Mf54vkk1FmV9M F9/ZMYcFQNpZQ1rlh60WnNUNzYAO4wGigCjSUBiSPt5kYeI0pqlWbbLt69avfDk6MqAH zDatIMzbL6Nzl1WRHJPYDWGkoQ//ZJ9S7witufE3Kx4GbuV1eDbkEZ1YK8ZFJR1p5Py/ 4Ifg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=HFF1Jh9cv2dxrJHuBkebqPRn3X2TL97dZXMHDJP4T9w=; b=k5IuxUtfS3mEeF/p9hrps7X7D0nGgnQFZ3ezeYMgiiFYAl8/+yd+Jrhtsyd/pTpt+D Q2L5XIhgyvrARAwlz2BT0Ow1WSpHumil9Jp+oyJrMf4rfytA42rGO7KYzNKtrM/5eFZZ uiPYyOGYiJXJ8MJNEurcQmNXaVg6mrRE88GmwneiA5i5jShU+9qGUz7mmPwHVmNZd6xN NJl3bv4xGTM9zNB9VFkGJb/7nJTHPTaRz4UesvPhj1xYh63y14Lyz7SIGNzliAZUOhZi oiwi0UqV94a2lcwkhrTYuxqAFWGq9IIFRZQJsGoq688Y/2rZzlunqooih9HWEjgLQhYr /LYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si9579655edy.580.2021.11.04.16.30.53; Thu, 04 Nov 2021 16:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232405AbhKDXCh (ORCPT + 99 others); Thu, 4 Nov 2021 19:02:37 -0400 Received: from mga17.intel.com ([192.55.52.151]:49616 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbhKDXCd (ORCPT ); Thu, 4 Nov 2021 19:02:33 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10158"; a="212554544" X-IronPort-AV: E=Sophos;i="5.87,209,1631602800"; d="scan'208";a="212554544" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2021 15:59:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,209,1631602800"; d="scan'208";a="490138587" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by orsmga007.jf.intel.com with ESMTP; 04 Nov 2021 15:59:54 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, peterz@infradead.org, bp@alien8.de, mingo@redhat.com, chang.seok.bae@intel.com Subject: [PATCH 2/4] x86/fpu: Add a helper to prepare AMX state for CPU idle Date: Thu, 4 Nov 2021 15:52:24 -0700 Message-Id: <20211104225226.5031-3-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211104225226.5031-1-chang.seok.bae@intel.com> References: <20211104225226.5031-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a CPU enters an idle state, non-initialized states left in large registers may be the cause of preventing deeper low-power states. The new helper ensures the AMX state is initialized to make the CPU ready for low-power states. Signed-off-by: Chang S. Bae Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- arch/x86/include/asm/fpu/api.h | 2 ++ arch/x86/include/asm/special_insns.h | 9 +++++++++ arch/x86/kernel/fpu/core.c | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index b7267b9e452f..c4965d2d0bb6 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -162,4 +162,6 @@ static inline bool fpstate_is_confidential(struct fpu_guest *gfpu) struct task_struct; extern long fpu_xstate_prctl(struct task_struct *tsk, 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 68c257a3de0d..d434fbaeb3ff 100644 --- a/arch/x86/include/asm/special_insns.h +++ b/arch/x86/include/asm/special_insns.h @@ -294,6 +294,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 8ea306b1bf8e..15d7bd67715f 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -753,3 +753,24 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr) */ return 0; } + +/* + * Leaving state in some large registers may prevent the processor from + * entering lower-power idle states. Initialize those states when needed. + * + * A caller needs to make sure fpregs are saved before this. + */ +void fpu_idle_fpregs(void) +{ + /* + * Ensure AMX TILE registers in INIT-state before entering the idle + * state. + * + * Dynamic states are enabled only when X86_FEATURE_XGETBV1 is + * available. + */ + if (fpu_state_size_dynamic() && (xfeatures_in_use() & XFEATURE_MASK_XTILE)) { + tile_release(); + fpregs_deactivate(¤t->thread.fpu); + } +} -- 2.17.1