Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1109142pxb; Thu, 21 Oct 2021 16:06:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgnlX1tQBpaseWHKBAUwwr2JKEMNvAdWOFz4zZkblLzOzm7Era5LTbiRgwtMnTaNG4ulzS X-Received: by 2002:a17:902:788d:b0:13f:7484:ef54 with SMTP id q13-20020a170902788d00b0013f7484ef54mr7983800pll.61.1634857612269; Thu, 21 Oct 2021 16:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634857612; cv=none; d=google.com; s=arc-20160816; b=GCExVUTiagBZWU5ADG1TCdlGk76JEEQiYThp49RJM/B6vzzFthhdu8YzYhlW0w2jg8 zSS2tWiVGypVOBtoFlEZMCYTOOFsWICSBf3+U+oareIr/72w8oa0OcSkq0r7t94izozq y50DeXyWjFJ3mIVeErZMY/ixWG60XBkE46vYhyZFMMDrgj9kMyw0NudbPSaXeEetQ6mQ V/wetRSqANpQUFCjwQfkSQiWpE6YFLyDNZL8ktNLW46IIVQ+XsbjaMQpCiNneQiD9N5n ESmSy3IDVnYejC8RD4i1sz87RhMi9VMB3G/NyyLQNqNBXknGteKs5uAZUyOuRIVGGzS8 5uzQ== 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=k+JLSLuqmXz7OcgoD7A5BbT6waeiqmtkew9kt2s5+Dc=; b=eqr29pLE+KK6BvieJzOaOSKfylTrwXdlldFcphrZopyqWjb/YDb7yL3tG8VnqanXWb dRNYPoi7lcT8xsrUMlXMXBcheWMO+2yzXHikR5EFVPs/ymC5sr5erDfp4VbOYfZYXDwf cDrtzESMhyLMn3k/WNSh4BHvy+yhlXC0gC6KuReUrf5FIVaV6vEGMOhtfC7YSSf5vr0c oa0i1JOd7OewENlN1gYxrH391bUbRT7qBrcb4e23u7eancoGqOyMtkwoDUWyEQoSH2Wq qh/53cixg1WH9bbjkU35Bcek3tNsBAL9Bi2OsvVVqrMRZ9PtPQxcKvuP9KwN+LM4iSif M1SQ== 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 i127si9668131pgc.84.2021.10.21.16.06.39; Thu, 21 Oct 2021 16:06:52 -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 S230190AbhJUXHU (ORCPT + 99 others); Thu, 21 Oct 2021 19:07:20 -0400 Received: from mga05.intel.com ([192.55.52.43]:58059 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbhJUXHN (ORCPT ); Thu, 21 Oct 2021 19:07:13 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10144"; a="315380010" X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="315380010" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2021 16:02:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,170,1631602800"; d="scan'208";a="445033244" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by orsmga006.jf.intel.com with ESMTP; 21 Oct 2021 16:02:20 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, arjan@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com Subject: [PATCH 03/23] x86/fpu/xstate: Provide xstate_calculate_size() Date: Thu, 21 Oct 2021 15:55:07 -0700 Message-Id: <20211021225527.10184-4-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211021225527.10184-1-chang.seok.bae@intel.com> References: <20211021225527.10184-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split out the size calculation from the paranoia check, so it can be used for recalculating buffer sizes when dynamically enabled features becomes supported. Signed-off-by: Chang S. Bae [ tglx: Adopted to changed base code ] Signed-off-by: Thomas Gleixner Signed-off-by: Chang S. Bae --- arch/x86/kernel/fpu/xstate.c | 46 ++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index cbba3812a160..310c4201e056 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -549,6 +549,33 @@ static bool __init check_xstate_against_struct(int nr) return true; } +static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted) +{ + unsigned int size = FXSAVE_SIZE + XSAVE_HDR_SIZE; + int i; + + for_each_extended_xfeature(i, xfeatures) { + /* Align from the end of the previous feature */ + if (xfeature_is_aligned(i)) + size = ALIGN(size, 64); + /* + * In compacted format the enabled features are packed, + * i.e. disabled features do not occupy space. + * + * In non-compacted format the offsets are fixed and + * disabled states still occupy space in the memory buffer. + */ + if (!compacted) + size = xfeature_uncompacted_offset(i); + /* + * Add the feature size even for non-compacted format + * to make the end result correct + */ + size += xfeature_size(i); + } + return size; +} + /* * This essentially double-checks what the cpu told us about * how large the XSAVE buffer needs to be. We are recalculating @@ -575,25 +602,8 @@ static bool __init paranoid_xstate_size_valid(unsigned int kernel_size) XSTATE_WARN_ON(1); return false; } - - /* Align from the end of the previous feature */ - if (xfeature_is_aligned(i)) - size = ALIGN(size, 64); - /* - * In compacted format the enabled features are packed, - * i.e. disabled features do not occupy space. - * - * In non-compacted format the offsets are fixed and - * disabled states still occupy space in the memory buffer. - */ - if (!compacted) - size = xfeature_uncompacted_offset(i); - /* - * Add the feature size even for non-compacted format - * to make the end result correct - */ - size += xfeature_size(i); } + size = xstate_calculate_size(fpu_kernel_cfg.max_features, compacted); XSTATE_WARN_ON(size != kernel_size); return size == kernel_size; } -- 2.17.1