Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2184049pxb; Fri, 25 Mar 2022 12:35:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsomXE7eaK0OJ+GFNMlwow2Ambq3EgoHrvTR3NxM2OwTB1mp6+QTP1uXs+mHGIHlCmeFXh X-Received: by 2002:a17:903:11d0:b0:155:c240:a2c0 with SMTP id q16-20020a17090311d000b00155c240a2c0mr9389582plh.143.1648236922464; Fri, 25 Mar 2022 12:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648236922; cv=none; d=google.com; s=arc-20160816; b=Zc8QHdAai14xOkYdUlkYQJmV/4an9Qd5br4ehH9QTPAYltgiSFGgcn6E5uyFz7X7wa UnUpQTZmnWOEJtj9ElQpsO+C2HJ3J+K3AnNmL+lj66+N1E5LQSv6WgNJgABabJH3fJzA l+1KtP4iOdg0Njy3RBsxb22EVhfyt56w9e9TDFaCktknTNsJI3WjrmgZLNuErqbbMDGB qzVS+Np8PsaCBCeFd5eom8QCfdmV7aS/aSOPAUuOn3gPelhRC73yDKjozUMeH2oxme5S 8417Ab6btvED+LbTGkEiB6Bf9AJJUFpnIyfieukSANGCvlFVDyHo+rPKImElNuS/G9VT /b6w== 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=FlS4rDJenRO6wkC0JNfcNEGDOUzk/9jo8hCEAjDstZo=; b=k4KPtewkW4qDYD9rrBUsczfJa9Z1uszoavyZFGwP+oFR3TxW99GkJBwJv/6031NgTu AhVY9HHkhzR6EHQfogKAgWgj5pkftXNm+/ngxnNUopcDfQ/7g9eaqFUGaMG/SbW5/C/h EzKvMng9NbKjGur3h8z1Hf0MKOFcupTkimOsN+mUR8MDodQw0wFrxkRFEjSYLrMvSySZ adkFyCuVs+3OrZKBgpgs5VrzucWQyEB88gfm9ABxPN+eG9wADvrGx3PUQYvwTtrxrfTI RD0BkZYeNT34r9yKOb4bvCfKg6YP6rBmsS7aguyUogt9xwg6HtH3Ue7AuOs24zH57fbB Oidw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="rmrVo/s1"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FAG7FSdV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mw11-20020a17090b4d0b00b001bf020c5dafsi7859728pjb.32.2022.03.25.12.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:35:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="rmrVo/s1"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FAG7FSdV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5DE225DAB9; Fri, 25 Mar 2022 11:26:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350601AbiCXNs7 (ORCPT + 99 others); Thu, 24 Mar 2022 09:48:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350577AbiCXNsr (ORCPT ); Thu, 24 Mar 2022 09:48:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E18FA94D5 for ; Thu, 24 Mar 2022 06:47:13 -0700 (PDT) Message-ID: <20220324134623.573656209@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1648129632; 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=FlS4rDJenRO6wkC0JNfcNEGDOUzk/9jo8hCEAjDstZo=; b=rmrVo/s1ODwYu0HnOGUT7eAg3WFoEuXeL0tUpdCsaePLqweClDRipWWresthvglwM0urGQ /XKN4m+KzDB1EnqlLc87acckS53pqVCciAf+lErK81GHY3SeSqdWyes5ffv2GFBi86279b 9hM3Sf2Gu1dp/fcXiugSNg0bvoIXRndxR61vHP/O5Zo9klpwG7rWOVazif3B4pg/WMleuy DEJK9hWDpSDWX9mNnqYvaZHZXFDbBedl9Z68POjrA+Bb7Wa4Do0z/NNXguMKyB0KR75Rso devgcxiixtZMR/bPJ8ozGoDJHAU+h8Aw8MZE91fONbKXu3X3rDWCifJ7b1KwvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1648129632; 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=FlS4rDJenRO6wkC0JNfcNEGDOUzk/9jo8hCEAjDstZo=; b=FAG7FSdVTHDktEb/RD0aHM9TV4wUNhx3uIeUaskfpWIEO9Dr1kmMt8K0RehEkkOzmV3Mp3 HFWbAl4VLHX4DnAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, "Chang S. Bae" Subject: [patch 4/7] x86/fpu: Cache xfeature flags from CPUID References: <20220324134548.432837672@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Thu, 24 Mar 2022 14:47:12 +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 In preparation for runtime calculation of XSAVE offsets cache the feature flags for each XSTATE component during feature enumeration via CPUID(0xD). EDX has two relevant bits: 0 Supervisor component 1 Feature storage must be 64 byte aligned These bits are currently only evaluated during init, but the alignment bit must be cached to make runtime calculation of XSAVE offsets efficient. Cache the full EDX content and use it for the existing alignment and supervisor checks. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/fpu/xstate.c | 49 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -83,6 +83,10 @@ static unsigned int xstate_sizes[XFEATUR { [ 0 ... XFEATURE_MAX - 1] = -1}; static unsigned int xstate_comp_offsets[XFEATURE_MAX] __ro_after_init = { [ 0 ... XFEATURE_MAX - 1] = -1}; +static unsigned int xstate_flags[XFEATURE_MAX] __ro_after_init; + +#define XSTATE_FLAG_SUPERVISOR BIT(0) +#define XSTATE_FLAG_ALIGNED64 BIT(1) /* * Return whether the system supports a given xfeature. @@ -122,17 +126,14 @@ int cpu_has_xfeatures(u64 xfeatures_need } EXPORT_SYMBOL_GPL(cpu_has_xfeatures); -static bool xfeature_is_supervisor(int xfeature_nr) +static bool xfeature_is_aligned64(int xfeature_nr) { - /* - * Extended State Enumeration Sub-leaves (EAX = 0DH, ECX = n, n > 1) - * returns ECX[0] set to (1) for a supervisor state, and cleared (0) - * for a user state. - */ - u32 eax, ebx, ecx, edx; + return xstate_flags[xfeature_nr] & XSTATE_FLAG_ALIGNED64; +} - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); - return ecx & 1; +static bool xfeature_is_supervisor(int xfeature_nr) +{ + return xstate_flags[xfeature_nr] & XSTATE_FLAG_SUPERVISOR; } /* @@ -203,6 +204,7 @@ static void __init setup_xstate_cache(vo cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx); xstate_sizes[i] = eax; + xstate_flags[i] = ecx; /* * If an xfeature is supervisor state, the offset in EBX is @@ -262,31 +264,6 @@ static void __init print_xstate_features } while (0) /* - * We could cache this like xstate_size[], but we only use - * it here, so it would be a waste of space. - */ -static int xfeature_is_aligned(int xfeature_nr) -{ - u32 eax, ebx, ecx, edx; - - CHECK_XFEATURE(xfeature_nr); - - if (!xfeature_enabled(xfeature_nr)) { - WARN_ONCE(1, "Checking alignment of disabled xfeature %d\n", - xfeature_nr); - return 0; - } - - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); - /* - * The value returned by ECX[1] indicates the alignment - * of state component 'i' when the compacted format - * of the extended region of an XSAVE area is used: - */ - return !!(ecx & 2); -} - -/* * This function sets up offsets and sizes of all extended states in * xsave area. This supports both standard format and compacted format * of the xsave area. @@ -314,7 +291,7 @@ static void __init setup_xstate_comp_off next_offset = FXSAVE_SIZE + XSAVE_HDR_SIZE; for_each_extended_xfeature(i, fpu_kernel_cfg.max_features) { - if (xfeature_is_aligned(i)) + if (xfeature_is_aligned64(i)) next_offset = ALIGN(next_offset, 64); xstate_comp_offsets[i] = next_offset; @@ -619,7 +596,7 @@ static unsigned int xstate_calculate_siz for_each_extended_xfeature(i, xfeatures) { /* Align from the end of the previous feature */ - if (xfeature_is_aligned(i)) + if (xfeature_is_aligned64(i)) size = ALIGN(size, 64); /* * In compacted format the enabled features are packed,