Message ID | 20230319001535.23210-7-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6DA3C76196 for <linux-mm@archiver.kernel.org>; Sun, 19 Mar 2023 00:16:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46A46280004; Sat, 18 Mar 2023 20:16:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F33F280001; Sat, 18 Mar 2023 20:16:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A96D280004; Sat, 18 Mar 2023 20:16:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F1793280001 for <linux-mm@kvack.org>; Sat, 18 Mar 2023 20:16:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C3375160C80 for <linux-mm@kvack.org>; Sun, 19 Mar 2023 00:16:07 +0000 (UTC) X-FDA: 80583730374.23.E3C9C68 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf16.hostedemail.com (Postfix) with ESMTP id C1053180006 for <linux-mm@kvack.org>; Sun, 19 Mar 2023 00:16:05 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QPuaQR5V; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679184966; a=rsa-sha256; cv=none; b=VmkHpSuYjTQ3uHhg9bIG3C6Qklq72+RTWv+GuIL77pm6DXxbWUNVnRGKtyHjIzb13az6o/ zfrIsvFUqyNhwRXZFkQ7n1w1NtFbiwCay/cTCGb0fbj36NbyDrshKStIUHWnUzQiYOQMjh U2AYD9qwXf4DESqiySHhblGY22YPc2w= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QPuaQR5V; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679184966; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=+zckbUWRWZvfPROGysXYXzeczc+/ZvxVdCvyMsXY99o=; b=bdVqBnf+RofA6H9lHVvJvmVg/578kLvHg3WZMGMCFWnGQhSqbYEeNg1jeuFU+bqAjZw8nn feWvM/SkSHkNaMDe7AyH3YhW0f53SRNlFLLF61mNV/MSPt9+/IVOmXrvY7ui7lVNwiQRav WpF4V/vGC2DDcH3CZxMkbCZDfXJQ82A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679184965; x=1710720965; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=JJ3ES6pKzLeV3jf7I3FnSvx/TVTiB5ybDZUP+4xGp5E=; b=QPuaQR5Vi4d3Z/x3CyUxK59vRUKuToq9j9Djl3/AZNL5VFrnUhj3+wUS V+e8hk9uYSdvuoi7snnZcabq/H97SMjgC/94Oiyhn4OBrSpsOjSsWFMKD 0sx6AGCXVvti9Z3q2ksWZj5JnmwWuILMgcnTDdsGO6Y/xCr4bHZxJazG9 Si0JexYLGLmk68X+e2DuZPa7ZDHZe7y1nuq4P4aAdoZjLBy1S+uSgzatH cy0tvjF7m8G+QX3T6zROWHoVh+MfCc4WON3GU8QSrgZULpwTQRKx3AAo1 BFJUin+YZv+Z8HBnlSKGexLK6XJkxCKnAtpOWNI39avew12wcnf7Z4WZs A==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338490860" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338490860" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="749672788" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="749672788" Received: from bmahatwo-mobl1.gar.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.135.34.5]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:02 -0700 From: Rick Edgecombe <rick.p.edgecombe@intel.com> To: x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>, Balbir Singh <bsingharora@gmail.com>, Borislav Petkov <bp@alien8.de>, Cyrill Gorcunov <gorcunov@gmail.com>, Dave Hansen <dave.hansen@linux.intel.com>, Eugene Syromiatnikov <esyr@redhat.com>, Florian Weimer <fweimer@redhat.com>, "H . J . Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Mike Kravetz <mike.kravetz@oracle.com>, Nadav Amit <nadav.amit@gmail.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Machek <pavel@ucw.cz>, Peter Zijlstra <peterz@infradead.org>, Randy Dunlap <rdunlap@infradead.org>, Weijiang Yang <weijiang.yang@intel.com>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, John Allen <john.allen@amd.com>, kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com, szabolcs.nagy@arm.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH v8 06/40] x86/fpu: Add helper for modifying xstate Date: Sat, 18 Mar 2023 17:15:01 -0700 Message-Id: <20230319001535.23210-7-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com> References: <20230319001535.23210-1-rick.p.edgecombe@intel.com> X-Rspam-User: X-Rspamd-Queue-Id: C1053180006 X-Rspamd-Server: rspam01 X-Stat-Signature: 1rg8duppp8cqacpnqhd8x79kcgsboar7 X-HE-Tag: 1679184965-826996 X-HE-Meta: U2FsdGVkX196o1YugrQdV8G50lSj9vew4gateym0I7/x6rWz6tP16coVt0+uW2SnLyfV43oLc9eS8IQUrrCDL6bw0TUc1LU/mJ8ntgUXbvAbQB5airPgvdm468yZquS6UoAeGxwU3fUgGS1cvFKCYHS12/izUpC4Ovt9PGNiP5FxnteA7ubJ5Vlmtz0LPnAWvMAjXJ5Lxf1HR0OrFtD+UF2WP7bf+AKFdbfg8kVxAXcXymKGp+FFT0FruCqFZIDNEdZ1JwG8xVPAYoHx6vWEwreAowvW4mJJQModcAsEYflhpLn+W88g/BMwkMlsAFDj8gjl+ln83lJU8u1GsSio0ncJExM2ckbLKdlLe2wjRxCOs9vG+TkPt3gjQnYp3JHjt5m/tU6Tf9TcnEAxCS8EgTGkGUHxTCPP/O3E4ayJlIdi/l6yU24bD1dOrWa8LfxoFvQt/GrZzEHT7bqhuXa9X+MkN9TYgFRSUriDv27B1I3PLIAGSy+5YU9NcSz9jmP0RVyPsBj1/T1i4r4RVvvr22nlciRS06nbPy3HC374wYiNMebOORBvudhN1gfgyKuMhtRg/dRqbIju/hjdHEwkAiO6grJQ2erfOv87WJVZBEgp5kakk9jxRQCRMvoGqy41Uu7VigT8C46UJIdl/DJU5AcI82s2nKPVnKux/lZTyx7/uiqWTroHRWE+TuQ0xTh1nm3LmEo8aX8sbyrrwniBkY8sazy/oZtJvAKNeLkojMEy4tQR8cJL9lCKmR+HY/HOHWCf0ShUrmdBCaHIzoUlugdVzwlVg9F1s8XTRliqTOFI+Dr8eJwUkL7TJYQE7Y4LUmmXOd11F3L/VZOsGEUsK6+ybLUjSQgh4ixAASPHxshT/pF6jwwU5+eCSdMuI+2yFElIO3VjW/mukLNYCaHH2XLB937UB780+sse44MPqJxiReYIIgKn8AxuijKmULgXLaGCtcXeSc+5H0Dvacb CEmR7Cao 1yhZy5WU15mfNACcO2GwnEexg9gh4o9psN9UexUoSDjT3Mz6zhaeW8NZShLE4NSf+WVpO9QPTxHzRODL9un3ncdiT9SlY06WEYh2A4lx62KFnziDWKURpen1vPOdlWv/ZVzqeUJAWuV50F7/6AAEsLu6ydMhY+/+Vi/Lwz5URCg2njTPLLr4cEbudJF9fQdc9RfVpQBqLM7tniLNGy9icS+v6iTp7I7lA2FwNx5l+PPc2r2agXKBmDgajhAgFW8X+3MqqXu7Cf4r1MRFRJjB5/wX8HxdFe4+v9LpFji7bE1wZKEN1Tn/4Z5jIdpqPwCgNQIvNSVJqfbHb7n42/rim98Zz2vCC5yMRKsRq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> |
Series |
Shadow stacks for userspace
|
expand
|
diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index 503a577814b2..aadc6893dcaa 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -82,6 +82,15 @@ static inline void fpregs_unlock(void) preempt_enable(); } +/* + * FPU state gets lazily restored before returning to userspace. So when in the + * kernel, the valid FPU state may be kept in the buffer. This function will force + * restore all the fpu state to the registers early if needed, and lock them from + * being automatically saved/restored. Then FPU state can be modified safely in the + * registers, before unlocking with fpregs_unlock(). + */ +void fpregs_lock_and_load(void); + #ifdef CONFIG_X86_DEBUG_FPU extern void fpregs_assert_state_consistent(void); #else diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index caf33486dc5e..f851558b673f 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -753,6 +753,24 @@ void switch_fpu_return(void) } EXPORT_SYMBOL_GPL(switch_fpu_return); +void fpregs_lock_and_load(void) +{ + /* + * fpregs_lock() only disables preemption (mostly). So modifying state + * in an interrupt could screw up some in progress fpregs operation. + * Warn about it. + */ + WARN_ON_ONCE(!irq_fpu_usable()); + WARN_ON_ONCE(current->flags & PF_KTHREAD); + + fpregs_lock(); + + fpregs_assert_state_consistent(); + + if (test_thread_flag(TIF_NEED_FPU_LOAD)) + fpregs_restore_userregs(); +} + #ifdef CONFIG_X86_DEBUG_FPU /* * If current FPU state according to its tracking (loaded FPU context on this