Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2840557pxj; Sun, 23 May 2021 12:40:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt2LLuePsqHF9J/O1ZUSGLzNpl/MUDok5yV5e3xWk8fOg3Pb53Apg5IwqxPDMC17mWog7F X-Received: by 2002:a05:6e02:df2:: with SMTP id m18mr11660206ilj.77.1621798857109; Sun, 23 May 2021 12:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621798857; cv=none; d=google.com; s=arc-20160816; b=ysceoBm0tOkLXBmsI7F2B8r9wYC72maHBz1Z/d/4sb5SaTd2Hz6DgfnUR/mwRWJguf 8+kR/YnPVXZaEmjyEsQI2fXbVqW4/7DCILx0DZZw0ICpZgcteCscmdIc3LvT45ASmreB CwZmkDiaxusiKPWj7uYErn8vxrY469UGTlUaziYF1DNHIq3Qx2NeIXqqtCcjXfXaUd1P z2amiu+PVKEsyQ/65Ue1mtm0qnuAS4E1eY/zrbOlSDfVfja7+CTZSizbVlcq02JxHR+c am0LkT1bsyB+u1iBCVAXBlDh3ybSb+TBWc7LnvVbLTZ0VkWw8vOUGnan6Zs8N6Hjc4Zv 7JtQ== 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:ironport-sdr:ironport-sdr; bh=yhYu6KPnPutQ5866vKGg6pJ1f7TMvB+6XpUf7pdw+Ng=; b=Ir6ywyQzbZ6YQDWwXdZseZVZm0/wIvnBliJ+Ye+hcw1c6m9v/BQCeLzL4gxgCfqBdn RziVuli3StizgggnNP3JjJ7PaRymfGy9yPh48z6bK4Kd7l8lngrzVwGWyCtbOR08JXEd x7A+a/Z87PQAd9XjJOGchsKcq6GW4QG8zNIEkQEj/xjQ6UOjYMAfy/TKBN81263DUpGg wZY9sGg2eqcfHaTSvl3MEQGRy2Ouy5h6hBg7psiU/sEevUdG1Zws+dbhQlBnRC3a6Obt BO47pY96ern2iSPbBLFS8LbfwZfWQy8LvZ91S2hbMQ+jMqJ8c/hQa0A5VYr/vlJjqm/R HsxQ== 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 a11si13283872jat.23.2021.05.23.12.40.44; Sun, 23 May 2021 12:40:57 -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 S232002AbhEWTkz (ORCPT + 99 others); Sun, 23 May 2021 15:40:55 -0400 Received: from mga07.intel.com ([134.134.136.100]:12061 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232009AbhEWTj6 (ORCPT ); Sun, 23 May 2021 15:39:58 -0400 IronPort-SDR: ncBjkgSqMH1QrG2HMSKfUjMFQORK9XfyII4cKgLINdHMQ94P0DQ4VkaYOr/x0qdHgszlc4XE+k W1H8YaHIMX5g== X-IronPort-AV: E=McAfee;i="6200,9189,9993"; a="265703543" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="265703543" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2021 12:38:29 -0700 IronPort-SDR: pW0i4o6A+8STy2bRHvm9yaPzFGeq+4YaoEIKgckMIxuHFFlImlHxxtt+KvleMDf6iFWo8nwjXR W6RV4tTzRrVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="407467141" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by fmsmga007.fm.intel.com with ESMTP; 23 May 2021 12:38:29 -0700 From: "Chang S. Bae" To: bp@suse.de, luto@kernel.org, tglx@linutronix.de, mingo@kernel.org, x86@kernel.org Cc: len.brown@intel.com, dave.hansen@intel.com, jing2.liu@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com Subject: [PATCH v5 25/28] x86/fpu/xstate: Skip writing zeros to signal frame for dynamic user states if in INIT-state Date: Sun, 23 May 2021 12:32:56 -0700 Message-Id: <20210523193259.26200-26-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210523193259.26200-1-chang.seok.bae@intel.com> References: <20210523193259.26200-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By default, for xstate features in the INIT-state, XSAVE writes zeros to the uncompressed destination buffer. E.g., if you are not using AVX-512, you will still get a bunch of zeros on the signal stack where live AVX-512 data would go. For 'dynamic user state' (currently only XTILEDATA), explicitly skip this data transfer. The result is that the user buffer for the AMX region will not be touched by XSAVE. Signed-off-by: Chang S. Bae Reviewed-by: Len Brown Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- Changes from v4: * Added as a new patch. --- arch/x86/include/asm/fpu/internal.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 4a3436684805..131f2557fc85 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -354,11 +354,27 @@ static inline void copy_kernel_to_xregs(struct xregs_state *xstate, u64 mask) */ static inline int copy_xregs_to_user(struct xregs_state __user *buf) { - u64 mask = current->thread.fpu.state_mask; - u32 lmask = mask; - u32 hmask = mask >> 32; + u64 state_mask = current->thread.fpu.state_mask; + u64 dynamic_state_mask; + u32 lmask, hmask; int err; + dynamic_state_mask = state_mask & xfeatures_mask_user_dynamic; + if (dynamic_state_mask && boot_cpu_has(X86_FEATURE_XGETBV1)) { + u64 dynamic_xinuse, dynamic_init; + u64 xinuse = xgetbv(1); + + dynamic_xinuse = xinuse & dynamic_state_mask; + dynamic_init = ~(xinuse) & dynamic_state_mask; + if (dynamic_init) { + state_mask &= ~xfeatures_mask_user_dynamic; + state_mask |= dynamic_xinuse; + } + } + + lmask = state_mask; + hmask = state_mask >> 32; + /* * Clear the xsave header first, so that reserved fields are * initialized to zero. -- 2.17.1