From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9A74C433EF for ; Thu, 24 Mar 2022 13:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350617AbiCXNtO (ORCPT ); Thu, 24 Mar 2022 09:49:14 -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) 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]; } /*