Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2840548pxj; Sun, 23 May 2021 12:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM7qbJqQ8BgFXQXifipcL5FsFnE8FwVircP4oQ+r5KYdOL8kR25/DfJu2grbp3Gc5sbkLz X-Received: by 2002:a02:ba08:: with SMTP id z8mr20177117jan.74.1621798855954; Sun, 23 May 2021 12:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621798855; cv=none; d=google.com; s=arc-20160816; b=F4qD1+pAudnh5P0nkpxL5LqNenVUyfz8rmXWa/ps9msTl1+O8AQVtyF7Y8XKikHLi4 xmhfJ5/mAMoV8YT5zSFN95JYTB19BozMBohE2WGfE199SMT76liPBWwyIzxGq6FWuVb0 kpR/0w5E0UBZZjjwlNLscuS/VaTxf0orBlC/Bm2YjQw5FmbVbie3ibcp6T9K+vdUfvI0 Bm3GC0Fcu7IgdtVdJQqgKJFvWhdJpgj9u/SyQaaieYj10u54T53UpgdwY8Y1seF6pmjd K/djz+IKPH1/i78VKQMCHYMtMHF3mk5JmMPuczQ6xwurAwMf/0OlbCtYiWjF27MF/QdY Tayw== 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:ironport-sdr:ironport-sdr; bh=I3DokyK+PRLYd4ow913VYzXb/q62y3h5Lt190apbeL4=; b=oU0IpPa41cQZsCnmK9xSGi9HYi8XxbbyqKYb26zMuN4mftCBRLorSkHC4g9qFB6juU loLuQqCwSV/hnteyD33eEOQqeq/2YD9xdq8RrRvUsJ1fBCOKzeNFdwv7Zng5iThAwHqi G76HVO8lY8hWIHkizwISSpSfEH39c3jCbsA9KtdUnm0meUCLKyl24xtG4B4ni9N5ZjEq +vdXyOXKzZLCbEYNFi1JFFRmRyyMzvR1Uter02WGdj2/G4pFPQdswKR7prVm8AY2PYPi DUON68x/jg3iTL+rpbk0YRpFsB0LFuL1vKhqueG69S3VyNgziZsSXwHmjqtzVOFyrKa6 rPEw== 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 w31si9982632jal.77.2021.05.23.12.40.43; Sun, 23 May 2021 12:40:55 -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 S232120AbhEWTk0 (ORCPT + 99 others); Sun, 23 May 2021 15:40:26 -0400 Received: from mga07.intel.com ([134.134.136.100]:12053 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbhEWTj5 (ORCPT ); Sun, 23 May 2021 15:39:57 -0400 IronPort-SDR: JV1bdqwO5kscVap7FwNu8xAwWyN8YZGDf3vSn8HRyeyk3l1RaqK2SRT/l0KlWzPrHl6WVmkrPQ zAVQcX6CZLLw== X-IronPort-AV: E=McAfee;i="6200,9189,9993"; a="265703536" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="265703536" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2021 12:38:29 -0700 IronPort-SDR: BRXig8pw9PpDWE/DsQj5RdcSls0asJgB1zxoopGku0qnrpIhBqahweMykJLXFaWEUKp8ZUDcPy +etPmXvJmTRQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="407467111" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by fmsmga007.fm.intel.com with ESMTP; 23 May 2021 12:38:28 -0700 From: "Chang S. Bae" To: bp@suse.de, luto@kernel.org, tglx@linutronix.de, mingo@kernel.org, x86@kernel.org Cc: len.brown@intel.com, dave.hansen@intel.com, jing2.liu@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com Subject: [PATCH v5 17/28] x86/fpu/xstate: Adjust the XSAVE feature table to address gaps in state component numbers Date: Sun, 23 May 2021 12:32:48 -0700 Message-Id: <20210523193259.26200-18-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210523193259.26200-1-chang.seok.bae@intel.com> References: <20210523193259.26200-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At compile-time xfeatures_mask_all includes all possible XCR0 features. At run-time fpu__init_system_xstate() clears features in xfeatures_mask_all that are not enabled in CPUID. It does this by looping through all possible XCR0 features. Update the code to handle the possibility that there will be gaps in the XCR0 feature bit numbers. No functional change. Signed-off-by: Chang S. Bae Reviewed-by: Len Brown Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- Changes from v4: * Simplified the implementation. (Thomas Gleixner) * Updated the patch title accordingly. Changes from v1: * Rebased on the upstream kernel (5.10) --- arch/x86/kernel/fpu/xstate.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 126c4a509669..1cf5888210aa 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -44,18 +44,17 @@ static const char *xfeature_names[] = "unknown xstate feature" , }; -static short xsave_cpuid_features[] __initdata = { - X86_FEATURE_FPU, - X86_FEATURE_XMM, - X86_FEATURE_AVX, - X86_FEATURE_MPX, - X86_FEATURE_MPX, - X86_FEATURE_AVX512F, - X86_FEATURE_AVX512F, - X86_FEATURE_AVX512F, - X86_FEATURE_INTEL_PT, - X86_FEATURE_PKU, - X86_FEATURE_ENQCMD, +static unsigned short xsave_cpuid_features[] __initdata = { + [XFEATURE_SSE] = X86_FEATURE_XMM, + [XFEATURE_YMM] = X86_FEATURE_AVX, + [XFEATURE_BNDREGS] = X86_FEATURE_MPX, + [XFEATURE_BNDCSR] = X86_FEATURE_MPX, + [XFEATURE_OPMASK] = X86_FEATURE_AVX512F, + [XFEATURE_ZMM_Hi256] = X86_FEATURE_AVX512F, + [XFEATURE_Hi16_ZMM] = X86_FEATURE_AVX512F, + [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, + [XFEATURE_PKRU] = X86_FEATURE_PKU, + [XFEATURE_PASID] = X86_FEATURE_ENQCMD, }; /* @@ -1022,8 +1021,13 @@ void __init fpu__init_system_xstate(void) /* * Clear XSAVE features that are disabled in the normal CPUID. */ - for (i = 0; i < ARRAY_SIZE(xsave_cpuid_features); i++) { - if (!boot_cpu_has(xsave_cpuid_features[i])) + + /* Handle the first component separately as its value is zero. */ + if (!boot_cpu_has(X86_FEATURE_FPU)) + xfeatures_mask_all &= ~BIT_ULL(XFEATURE_FP); + + for (i = 1; i < ARRAY_SIZE(xsave_cpuid_features); i++) { + if (xsave_cpuid_features[i] && !boot_cpu_has(xsave_cpuid_features[i])) xfeatures_mask_all &= ~BIT_ULL(i); } -- 2.17.1