Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1505416lqt; Sat, 8 Jun 2024 00:33:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUm47ZcpG+qYuaDV8lvTeqCbiflmZVhlpVdNWEc2CG3QpvhGN1qoQ2D4imCzfYkj2m7yLL0C9jNmCZb6DIp/Ne/WFCMJim4krOAJg8smA== X-Google-Smtp-Source: AGHT+IEp0+Yny1VZ+wOBBGkPPUDs9boFo/PlnjWOq3/fpZ2C+ePIZ+9qs91HQqI0NoUFeyZ9HE5E X-Received: by 2002:a17:90a:b38a:b0:2c1:9e98:70bb with SMTP id 98e67ed59e1d1-2c2bc9bf71dmr4608045a91.10.1717832025741; Sat, 08 Jun 2024 00:33:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717832025; cv=pass; d=google.com; s=arc-20160816; b=pwO7IgjYDNEe1k/Q977kV6vRYd2xhHAbfcuWveXySgwzXZREeK4ou+Z5p8SxuiWIVx SzMYudNxWhdJxYefIzxuSuSmuFVFc4aENUYsK2i1DlVK0kkvea2DekvISvFbNalywlWr dWrQpzc7f1r1ZDLfqkilPbpYUght/fUZ/+HBRtgXVaJSlxZrVM+7aRx+S+LFDPm8RA3e A9YMzV6kJpE0s3d8zzJkkIsj3xcC9cwPkgFbBHlvLtQiPrv25lv31bguUX4449VXnkyT IZPeg4IC99pbNycv/X+f6rl2x645OBAan0FpMWsCZgWLkZLAHsI7Dww4jStOIotw0Ozc Fi+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=g+lBgMuuZ2Dd+zsmU6HUgP6ijp+tIzvqzbKgCVJv1Uw=; fh=ZrHbDSiANSBCmvivbV48JgZ35KGtehFV6ZNj4vR8U9I=; b=gjZJbDFbSPxfyOkeVEd1dtI0S+EKVHIT+Sv2an4Bwzwa6jMIcFHLuqJfpKFHKjRqW1 XcfWBTntI1YkUGmd/sI+EbPc3xcwnMDxLgtjUz8im20JwsYM0vv1XbiVXgtut5sJUarX CSUlFEF4R8ZQd0+PfeaUEAapnmKMPK88+yYT7c9I33dao02JpTs+Y7dqwHkM44VY3SVl uoxV+rRHj/Gd2oZn02zr1uZCZwmZfJZXTybG27hH1lFcxAzfVFXjbBNuC1i5s+x14vE1 vNSJd0XJHXh/3urqHJZT/dUqwFvuL1xA/RiKjH8vpcukO40jMIcNQX5ArQ6n2HUN0Vd4 9arQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AeofsdE5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-206930-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206930-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2de9c4456si331006a91.57.2024.06.08.00.33.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 00:33:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206930-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AeofsdE5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-206930-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206930-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A8B9E2842A4 for ; Sat, 8 Jun 2024 07:33:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 359DB17964F; Sat, 8 Jun 2024 07:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AeofsdE5" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3661713DB90 for ; Sat, 8 Jun 2024 07:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717831947; cv=none; b=LCIbGkz1GJTA1Pj1+gS2iAGw9yV2PQpchf5yiPN7e+eWm67N4UUbUf52nI8aaUsYY4D5a1o+DIpF9VjEY/ljB5e9qUXPw3adAZDqdeyIh4RXePRJRBCV4bHo9NLKeOQayX83sonx6b3dbbjgWsVUZp3wAqOYyTOuQhPZijsBkb8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717831947; c=relaxed/simple; bh=XDZH9IEws56z+IXOYnMIYkJZCzATTFYM+Rp1MP4HDm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1n0agFRq/hKCBG3UGJ9B9iJbWmg5O+1UhdhVTNEww9LtFBwxr/q5e5hd78DNbrw8V8TXFetjRo6K+eeyhh6xeZHsJyM1aaq6V68v9RjJNPRjR1vLv6rtccc202h/0Ih3XJsvKfkjPsg9TF75fFKx6iSUrLieuMh7cyrzPdg/dE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AeofsdE5; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-52bc29c79fdso1293937e87.1 for ; Sat, 08 Jun 2024 00:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717831943; x=1718436743; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=g+lBgMuuZ2Dd+zsmU6HUgP6ijp+tIzvqzbKgCVJv1Uw=; b=AeofsdE5Zz07ot8Jejhr2RkQ/c+i1TGRhWNXlrAtyOJOP5xX0b1kY67k/tR3NghLZ2 FaAlOgZtpppV8mEGWrBax8JJUaaNyieTKBEMt5RTaswIRvateUbU1VndiTGj+pL8pvF7 qSRe538kKWrX76Ik+H5TgkkKSGc1KfZ4S6FrdGrQfgSqcrxu9c6EiInBPL+Kq64vL6hl IkbIiPUvNCLVi0BEpJIvqyNh21jTQHpbROOk8lOHfpE1jawa+qQ0r+a1142D0jB38yLv W2bSfmDqnbwVRmi5vc5EBnpJYLhW4j4wav2iFOvE2PxnxT6Ep7ugt0rVH7DO32dd6kK/ KeVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717831943; x=1718436743; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=g+lBgMuuZ2Dd+zsmU6HUgP6ijp+tIzvqzbKgCVJv1Uw=; b=ObmjYa62tQtC984VIyJROQzdw3ww4n7ddgSGFlEUn0h6GbL4PQixVOa/MqjT7Zb989 vxBHYlUdeokZ9IFJonwk7zRZY6cFfc4TKdh/OdGyIdMyyaGmQIFngniujnhWza0wN6WE +CI3kTL/pqx3Yl3LWLvIO7x+QL5M6pJRJNYFYQ6nnKQ7Dj2fM55QuVpu87pfkEmgmpEq IcDHNIi+Wva93CUKHA7LZR+re5LIMYuF7pv0ILzvuOeoDmWQ5qmcIyDJWpfCWFFfFUbw dxSJCA1KyVilwRzrPSdF4szgzCEh49VLV4yN0lbckJrTbKk42uG8cGwVbWZ+Jb7KJFsG OLkQ== X-Gm-Message-State: AOJu0YzPlkSSnb0XyVJJATloPZoUmM1trndIrwDAwQtyNBp7DZega2vG s4fm4Oiq2UY9owyBjN14dmQ0eo6O1Q2/Yg+wMk0aRMEhGua8U7FE/C4FaNr6 X-Received: by 2002:ac2:43ad:0:b0:529:b718:8d00 with SMTP id 2adb3069b0e04-52bb9f624f4mr3311999e87.8.1717831943027; Sat, 08 Jun 2024 00:32:23 -0700 (PDT) Received: from kepler.. (1F2EF20A.nat.pool.telekom.hu. [31.46.242.10]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6efe5262cdsm61350466b.117.2024.06.08.00.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 00:32:22 -0700 (PDT) Sender: Ingo Molnar From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Andy Lutomirski , Andrew Morton , Dave Hansen , Peter Zijlstra , Borislav Petkov , Brian Gerst , "H . Peter Anvin" , Linus Torvalds , Oleg Nesterov , Thomas Gleixner , Uros Bizjak Subject: [PATCH 7/9] x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks Date: Sat, 8 Jun 2024 09:31:32 +0200 Message-ID: <20240608073134.264210-8-mingo@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240608073134.264210-1-mingo@kernel.org> References: <20240608073134.264210-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit init_task's FPU state initialization was a bit of a hack: __x86_init_fpu_begin = .; . = __x86_init_fpu_begin + 128*PAGE_SIZE; __x86_init_fpu_end = .; But the init task isn't supposed to be using the FPU context in any case, so remove the hack and add in some debug warnings. As Linus noted in the discussion, the init task (and other PF_KTHREAD tasks) *can* use the FPU via kernel_fpu_begin()/_end(), but they don't need the context area because their FPU use is not preemptible or reentrant, and they don't return to user-space. Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Dave Hansen Cc: Thomas Gleixner Cc: Uros Bizjak Link: https://lore.kernel.org/r/20240605083557.2051480-4-mingo@kernel.org --- arch/x86/include/asm/processor.h | 6 +++++- arch/x86/kernel/fpu/core.c | 15 +++++++++++---- arch/x86/kernel/fpu/init.c | 3 +-- arch/x86/kernel/fpu/xstate.c | 3 --- arch/x86/kernel/vmlinux.lds.S | 4 ---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 3de609aad0af..4fd3364dbc73 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -504,7 +504,11 @@ struct thread_struct { #endif }; -#define x86_task_fpu(task) ((struct fpu *)((void *)(task) + sizeof(*(task)))) +#ifdef CONFIG_X86_DEBUG_FPU +extern struct fpu *x86_task_fpu(struct task_struct *task); +#else +# define x86_task_fpu(task) ((struct fpu *)((void *)(task) + sizeof(*(task)))) +#endif /* * X86 doesn't need any embedded-FPU-struct quirks: diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 52d5843c886c..db608afa686f 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -51,6 +51,16 @@ static DEFINE_PER_CPU(bool, in_kernel_fpu); */ DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx); +#ifdef CONFIG_X86_DEBUG_FPU +struct fpu *x86_task_fpu(struct task_struct *task) +{ + if (WARN_ON_ONCE(task->flags & PF_KTHREAD)) + return NULL; + + return (void *)task + sizeof(*task); +} +#endif + /* * Can we use the FPU in kernel mode with the * whole "kernel_fpu_begin/end()" sequence? @@ -590,11 +600,9 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal, * * This is safe because task_struct size is a multiple of cacheline size. */ - struct fpu *src_fpu = x86_task_fpu(current); - struct fpu *dst_fpu = x86_task_fpu(dst); + struct fpu *dst_fpu = (void *)dst + sizeof(*dst); BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES != 0); - BUG_ON(!src_fpu); /* The new task's FPU state cannot be valid in the hardware. */ dst_fpu->last_cpu = -1; @@ -657,7 +665,6 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal, if (update_fpu_shstk(dst, ssp)) return 1; - trace_x86_fpu_copy_src(src_fpu); trace_x86_fpu_copy_dst(dst_fpu); return 0; diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 794682b52373..53580e59e5db 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -38,7 +38,7 @@ static void fpu__init_cpu_generic(void) /* Flush out any pending x87 state: */ #ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has(X86_FEATURE_FPU)) - fpstate_init_soft(&x86_task_fpu(current)->fpstate->regs.soft); + ; else #endif asm volatile ("fninit"); @@ -209,7 +209,6 @@ static void __init fpu__init_system_xstate_size_legacy(void) fpu_kernel_cfg.default_size = size; fpu_user_cfg.max_size = size; fpu_user_cfg.default_size = size; - fpstate_reset(x86_task_fpu(current)); } /* diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 90b11671e943..1f37da22ddbe 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -844,9 +844,6 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) if (err) goto out_disable; - /* Reset the state for the current task */ - fpstate_reset(x86_task_fpu(current)); - /* * Update info used for ptrace frames; use standard-format size and no * supervisor xstates: diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 226244a894da..3509afc6a672 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -170,10 +170,6 @@ SECTIONS /* equivalent to task_pt_regs(&init_task) */ __top_init_kernel_stack = __end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE; - __x86_init_fpu_begin = .; - . = __x86_init_fpu_begin + 128*PAGE_SIZE; - __x86_init_fpu_end = .; - #ifdef CONFIG_X86_32 /* 32 bit has nosave before _edata */ NOSAVE_DATA -- 2.43.0