From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073558; b=he6klqWQmYa6Yzp2khJP3UN7hDoltdJD98u89U90hy+G1S+3QK9CiuicjKvVWd2jWXBO 29y+6A0/nf4bHELmoZcUY/6mD3HzbwyTWUZe23uKVh6vap1K25qbanNF11MwnaLgxLsZd nONfQ+cG8W0Di/+UXjyI4CXTLJBmOhYDUuwYOS0oZ3a5sijsJ1vwXJet0Pgo9Cqlczww5 ekmyTPrIZ6LS5vHOVeFZsCEyGgIIAjmTTUPipBfZMmF4BaxmjAdxX4TqbCGwsNZRLCz9h jDi2rS33K69EI3hyTwMk5+XOOYQ7et1G+QIKWBt+hZiEEjGuC9LO+7aYR/NFI32i3uQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073558; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=eZPDYjCyPRX+ZjLrswXK8BmxLXMXZzWEDwVw/0BUxLc=; b=3gMuhvlSukaFXJl/YQP7OrbWo/jLO39SwdbP6q1UzmJy8mOgj6LHYUyXcnnWOh9+kUmK yXm4pQqU6uAQA1Q7u83FuDc09R2hasVUHt2UxDnc1dI0krKjfIker31xVBuk/+aUvb5wy vPut9CNw0W5c7tjZKqW/XMxAacJlBz6wVITpxzU0K+2i9Y/DRvfYY0hOwyWL6mvwjytpY jfk7reG97ObGCTLrUjqKS5liTLSXn2mBScFSKp5ZbgAa4KlczxWCAfXXLqY6yr7G/GkiU Dh5DA2SmrWUPM6AJmKNUITHWZqyxQcLJ6gZJVaF/Lqm2e4ZcCI3sjzE9Q+pXefTnGyw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Z7qfqQzu; arc=none smtp.remote-ip=198.175.65.19 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B7FD606A688; Mon, 30 Nov 2026 21:19:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B7FD606A688 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Z7qfqQzu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796073559; x=1827609559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eZPDYjCyPRX+ZjLrswXK8BmxLXMXZzWEDwVw/0BUxLc=; b=Z7qfqQzuSvkvNMQ4By300NnYh/yOb5GeOpxefEs7LezAQy8zVy60VcWK JifW6NwvM6qMpXq5QQpAVR3p6Ss5nDZ0CxOw5fOIB28Eob2VC6nq8AuLZ sCP4SOUAVDPZLdOCnO4McMRfOD5E6MK8gqi5cYUl8QsU5TMBjGz8NzWfM KQxFLpMD66K1SHpxstcTEh8nGdCoFO/WG8oHyIXLRPmPQX1fEWYhaVR7w zVIYtE1rJzdqksWkABz90QSUmsuWBLf+IRLApF/bY9dtT8D0ZM078K59d HiyBpxfzl8M/0fspQqgDp6qEZs9T1DUPZylMt/iMlhhMZRw0Ho7+TgYTU w==; X-CSE-ConnectionGUID: moB1/XOAQe65r1RNt8EVFA== X-CSE-MsgGUID: 4A0HeteWQG+IHJNHUoVWJg== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4989770" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4989770" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 13:19:17 -0800 X-CSE-ConnectionGUID: X0u/c0I5Q8+84J5mNZ9Q1g== X-CSE-MsgGUID: 21UxXTpYTviOz+s0DhmNQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13166766" Received: from chang-linux-3.sc.intel.com (HELO chang-linux-3) ([172.25.66.174]) by fmviesa005.fm.intel.com with ESMTP; 30 Nov 2026 13:19:16 -0800 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, weiguixiong@bytedance.com, omermetekaya0@gmail.com, chang.seok.bae@intel.com, stable@vger.kernel.org Subject: [PATCH 4/6] x86/fpu: Refactor fpstate memory free helpers Date: Mon, 30 Nov 2026 20:51:40 +0000 Message-ID: <20261130205143.1258369-5-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130205143.1258369-1-chang.seok.bae@intel.com> References: <20261130205143.1258369-1-chang.seok.bae@intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Upcoming changes to free up vmalloc'ed fpstate memory will have the same code under fpstate_realloc(). Refactor the code into a helper in advance. Rename the existing fpstate_free() to fpu_free_fpstate() since it takes a struct fpu pointer. Then convert fpstate_free() to free a vmalloc'ed fpstate and use it where it can. No functional change. Signed-off-by: Chang S. Bae Cc: stable@vger.kernel.org --- Note for backporting, this prepares: Fixes: 500afbf645a0 ("x86/fpu/xstate: Add fpstate_realloc()/free()") --- arch/x86/include/asm/fpu/api.h | 6 ++++-- arch/x86/kernel/fpu/xstate.c | 17 +++++++++++------ arch/x86/kernel/process.c | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index 90c63fe19c0fb..d3f5536f092ad 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -125,9 +125,11 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx); /* Process cleanup */ #ifdef CONFIG_X86_64 -extern void fpstate_free(struct fpu *fpu); +extern void fpu_free_fpstate(struct fpu *fpu); +extern void fpstate_free(struct fpstate *fpstate); #else -static inline void fpstate_free(struct fpu *fpu) { } +static inline void fpu_free_fpstate(struct fpu *fpu) { } +static inline void fpstate_free(struct fpstate *fpstate) { } #endif /* fpstate-related functions which are exported to KVM */ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index f69eb0a596f44..22ddc00689a6b 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1594,10 +1594,17 @@ static int __init xfd_update_static_branch(void) } arch_initcall(xfd_update_static_branch) -void fpstate_free(struct fpu *fpu) +void fpstate_free(struct fpstate *fpstate) { - if (fpu->fpstate && fpu->fpstate != &fpu->__fpstate) - vfree(fpu->fpstate); + /* Only free valloc'ed state */ + if (fpstate && fpstate->is_valloc) + vfree(fpstate); +} + +void fpu_free_fpstate(struct fpu *fpu) +{ + if (fpu->fpstate != &fpu->__fpstate) + fpstate_free(fpu->fpstate); } /** @@ -1678,9 +1685,7 @@ static int fpstate_realloc(u64 xfeatures, unsigned int ksize, xfd_update_state(fpu->fpstate); fpregs_unlock(); - /* Only free valloc'ed state */ - if (curfps && curfps->is_valloc) - vfree(curfps); + fpstate_free(curfps); return 0; } diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 85e6b076ef17b..b4fd62c1921d8 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -118,7 +118,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) void arch_release_task_struct(struct task_struct *tsk) { if (fpu_state_size_dynamic() && !(tsk->flags & (PF_KTHREAD | PF_USER_WORKER))) - fpstate_free(x86_task_fpu(tsk)); + fpu_free_fpstate(x86_task_fpu(tsk)); } #endif -- 2.53.0