Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2143859pxb; Fri, 25 Mar 2022 11:52:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7Q+6Azfzeh6VQT8f7gl2xi/V+2FP/LHnkZQHVkfYIdGmPK8uVBor4W6ZB0v1nJXUEoYfI X-Received: by 2002:a05:6a00:170a:b0:4f7:918a:1eac with SMTP id h10-20020a056a00170a00b004f7918a1eacmr11545580pfc.16.1648234366674; Fri, 25 Mar 2022 11:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648234366; cv=none; d=google.com; s=arc-20160816; b=L3FiuK2Qvx0h/CuzLYqCHKlb3CVX6T+5pJCj3a0QGtqXEWmuV4PwGNs9xUibh17Fry XTucETCikym2I/keEh0laxw9yQ7M2Lw+zeJk8IbQEBj/P/BBtxd7cP4md/BG+CKvCA/v N6CoJCBcXWdc+pzqUCvKgJw1Sl0VT6P1NHKYWJucdeCkYFO7nSQzB1pW9u2MjYvBYhMR lSmMwTY7mM15uHSWZ9Q/YaJI0E0PfHFMd/ElX0NoqIadVdM23TZsoq9i4vCvalVPI+X9 ooB84O7jcR2ARPPtb6S4kDtFM21Fv1taACQBQ8NUHfsEJH59p6NP33rsMNRR8Jk4fsT7 rELQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=R6A5qasfkCP1yilN3Hx1CqR1fLfcwGqb+MZxXGRxBLk=; b=PbhoLKgE6iW8Ha8inaaff+7frgHZzb4fNGK6Yj8dyQosArj+HWJSe1qGA2Ce9rIGhG 0b4DdHmoarCT/CPaeAiNoj0Px5cm1cGmj3ZKj9y0mTeXVCf4EeGR2puFYY4SV+IK5ZaN hFssQs/sml7le+WsTqcsFb+2emxmhn+Sju+2YX685pbOZtu7oJdAzz3K7jlxWKDtZyiO kcco9wKl5MkRTk03c/wH7OhsyAjTZY5MgED5LGAY4klJSniWv13/P0aa/PqNe81wyhFH k9RRFvBpVMZcDurZmRRQ/YBHyuHkZ4i1UeC4obfldZDHnRGTiQfn6xVLh16zl60Qg2a8 ydsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BUwWnm++; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r6-20020a635146000000b003825c501389si3654375pgl.158.2022.03.25.11.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:52:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BUwWnm++; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 607BC1C405F; Fri, 25 Mar 2022 11:05:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350686AbiCXNtK (ORCPT + 99 others); Thu, 24 Mar 2022 09:49:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350591AbiCXNsu (ORCPT ); Thu, 24 Mar 2022 09:48:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06FFFA94D9 for ; Thu, 24 Mar 2022 06:47:17 -0700 (PDT) Message-ID: <20220324134623.736990161@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1648129636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=R6A5qasfkCP1yilN3Hx1CqR1fLfcwGqb+MZxXGRxBLk=; b=BUwWnm++qyFfkfypVTGJcfty77bat2cZNnIS5b82BWBviYGp5UPe6KuR2MJQKx3uh37vid NbfmjvslxGzTO7nYXj65CWwXcR3evAWa68bKcYZk8YtmMmHicXI1E0LJd52CAEBiXA0quf 56OIUDl/GNxbWE6FDU+Crdpfa2ItQBvMlcSDdso2tffBEXChz6RjEt3/SKm/0eUaacTFY5 l/tmK903vuESeFxXdeth3esrhBXVo6uZyBEf1a+0gaPf+BrBWSlNoV6Cffxin31eODbS4O 7uv09KMl/8nIZNstLriQNPPlaFm1fFpNmnyNVYhVL0auICTe9KHBeQTtPDyYrw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1648129636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=R6A5qasfkCP1yilN3Hx1CqR1fLfcwGqb+MZxXGRxBLk=; b=uhku3XA5lZTnxAOLGPuoRxWvdslUdVxMWjjkv45KcVkPta+muLG5Rnj8fRC4NE+q0r5PRy iq6KGsGndBtZeJCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, "Chang S. Bae" Subject: [patch 7/7] x86/fpu/xstate: Consolidate size calculations References: <20220324134548.432837672@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Thu, 24 Mar 2022 14:47:16 +0100 (CET) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the offset calculation to do the size calculation which avoids yet another series of CPUID instructions for each invocation. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/fpu/xstate.c | 46 ++++--------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -385,25 +385,6 @@ static void __init setup_init_fpu_buf(vo fxsave(&init_fpstate.regs.fxsave); } -static int xfeature_uncompacted_offset(int xfeature_nr) -{ - u32 eax, ebx, ecx, edx; - - /* - * Only XSAVES supports supervisor states and it uses compacted - * format. Checking a supervisor state's uncompacted offset is - * an error. - */ - if (XFEATURE_MASK_SUPERVISOR_ALL & BIT_ULL(xfeature_nr)) { - WARN_ONCE(1, "No fixed offset for xstate %d\n", xfeature_nr); - return -1; - } - - CHECK_XFEATURE(xfeature_nr); - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); - return ebx; -} - int xfeature_size(int xfeature_nr) { u32 eax, ebx, ecx, edx; @@ -581,29 +562,12 @@ static bool __init check_xstate_against_ static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted) { - unsigned int size = FXSAVE_SIZE + XSAVE_HDR_SIZE; - int i; + unsigned int topmost = fls64(xfeatures) - 1; + unsigned int offset = xstate_offsets[topmost]; - for_each_extended_xfeature(i, xfeatures) { - /* Align from the end of the previous feature */ - if (xfeature_is_aligned64(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; + if (compacted) + offset = xfeature_get_offset(xfeatures, topmost); + return offset + xstate_sizes[topmost]; } /*