Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1770028pxb; Tue, 26 Oct 2021 15:44:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBAecKT0wReuSba0q2+XBSMjTtyz0oRoVcJ8v/ohXIqNNdUOJproGa+MFTMjQz9u9HARz+ X-Received: by 2002:a17:90b:89:: with SMTP id bb9mr1793598pjb.17.1635288292590; Tue, 26 Oct 2021 15:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635288292; cv=none; d=google.com; s=arc-20160816; b=yt4m/GXBcn0U180eLisGr0iu/+EszoXQxqR3tvDWT+cDO6+AksfzVKQeQ7yTBjnjor 4XMrh32W9qEyK0h18fTHYVZ6PZFIHa7pcZWKNwAgM4tESLqaD3NKcnHhL0ns1kZISnnK 9XNrDXGroKi5y22fpApdWuuaD4kgk55FsaW0JcRbGlpqZ6a44qaRmrs94Leq8hx+Ldsb 9dbITgEsZm0/zDu7nYxyjFabikqbjIDus2Majq8G6Kk5XqOfLfmN5qDlSmJeUud3jVza xdoQssUbHoaUhPJL9ONDTHq+YIrRaX5G1ZLxLB+DNRSfr3CnV2W3/SnQx6p3zlQnogGH DzXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=30XCVgmwaovkWEUMbRcyHPfNsu0Xryx+pyJdstab2r0=; b=CIlcWKxEDdqVYGVHRrp92UO3IHJJQmJGTAvWntkyKUjinDwSzvEVZ7iyArOMYeEjd6 31+loJSl27z3y4zdIlqhmmqHHRkLy5YX3n9kFL+XJkVagCGMWUvjgLYZwMdifs+wFz1y MIrJbCmqe7e9gKfgEbV5GLw0JaZl0RD3a8onwfUy4OTIhEZ8ntAH9D8bMaFjAwL7lDLm CD77aAquyE970k5RNcJZX2ZXKQ7lR6WEhQ8E/wrpXCQ3/cFWs1CcxsfZNFKTmrxHC4CO 35HM3h45Mm73pHbmX6pW+WlDkl5jW79sLRMdMe/JSK2QDhEAICU/CBrLlteWlppiDJTE 0GFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="tTgq/yw/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t41si11243080pfg.56.2021.10.26.15.44.39; Tue, 26 Oct 2021 15:44: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; dkim=pass header.i=@linutronix.de header.s=2020 header.b="tTgq/yw/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237617AbhJZQT7 (ORCPT + 99 others); Tue, 26 Oct 2021 12:19:59 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:34666 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237357AbhJZQTN (ORCPT ); Tue, 26 Oct 2021 12:19:13 -0400 Date: Tue, 26 Oct 2021 16:16:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1635265008; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=30XCVgmwaovkWEUMbRcyHPfNsu0Xryx+pyJdstab2r0=; b=tTgq/yw/NdeWaN/I57IKCZRzqFwxctM12+NeafcSHSbB7jKO4S6NAybZtGV9ydUprUqMA0 AtWLxXKvbfJx7jYmQR+X4u16bTRKAS7DlENiIbagJ0dUApXeYj2RyNwbfeIE4IKLnT/oyC kcYjBHx3Hrop1C5xHxCKM0Fluh3Da32avGK7cYIhSeOIi22h9VZuJLWOg8um9wjLmaZjFB wpbCoRnSUAjgmhul0ua+/kL67ge1BkMHUZ5qnu4tODHHpdLF9GhjREad4Y5XZXnGadyv4z 5sEa/0ct/vhdmvGLe15ZGZklm9dGi/qqDNpwkeeAnvhpDRP9xhpbg0/+ngHbbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1635265008; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=30XCVgmwaovkWEUMbRcyHPfNsu0Xryx+pyJdstab2r0=; b=ATeIhhIkNbbLREdXcjv+rjwZWnnZT8E6lNLpYt3VAEpkJk5mLQrEjqqyTsGnTtT6lqXS5n AyP6hV83GqN0WqCA== From: "tip-bot2 for Chang S. Bae" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fpu] x86/fpu/xstate: Provide xstate_calculate_size() Cc: "Chang S. Bae" , Thomas Gleixner , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20211021225527.10184-4-chang.seok.bae@intel.com> References: <20211021225527.10184-4-chang.seok.bae@intel.com> MIME-Version: 1.0 Message-ID: <163526500769.626.2064661725935611440.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/fpu branch of tip: Commit-ID: 84e4dccc8fce20b497388d756e12de5c9006eb48 Gitweb: https://git.kernel.org/tip/84e4dccc8fce20b497388d756e12de5c9006eb48 Author: Chang S. Bae AuthorDate: Thu, 21 Oct 2021 15:55:07 -07:00 Committer: Borislav Petkov CommitterDate: Tue, 26 Oct 2021 10:18:09 +02:00 x86/fpu/xstate: Provide xstate_calculate_size() Split out the size calculation from the paranoia check so it can be used for recalculating buffer sizes when dynamically enabled features are supported. Signed-off-by: Chang S. Bae [ tglx: Adopted to changed base code ] Signed-off-by: Thomas Gleixner Signed-off-by: Chang S. Bae Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20211021225527.10184-4-chang.seok.bae@intel.com --- 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 cbba381..310c420 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; }