From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 A0250C433F5 for ; Tue, 4 Oct 2022 04:05:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C74C6B0072; Tue, 4 Oct 2022 00:05:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 276C66B0073; Tue, 4 Oct 2022 00:05:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 118386B0074; Tue, 4 Oct 2022 00:05:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 018C56B0072 for ; Tue, 4 Oct 2022 00:05:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C9D4E1C5D39 for ; Tue, 4 Oct 2022 04:05:07 +0000 (UTC) X-FDA: 79981926654.24.CA33424 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf30.hostedemail.com (Postfix) with ESMTP id 7380D80012 for ; Tue, 4 Oct 2022 04:05:07 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id u21so6475027pfc.13 for ; Mon, 03 Oct 2022 21:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=rlkPZtF7+K01teV+qG5sp8ViMTTB6RT0WVQ9H3WnvE4=; b=as3TWS6vBJAwdPKL7Ajuqj38rPxasTcQIh1irqo0CAA7cvBEF+uAJRGRPyZKmUniFK hZH9s6Hq0G3/ziJ96FzcfD7oyvL2sBn0E+cWJKokpn1/rON4zoBi86CQsJLEnWjkHwNR Jfgemw+H/hgCiW8ZpRt/KFghtfuPy7nCx3ctg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=rlkPZtF7+K01teV+qG5sp8ViMTTB6RT0WVQ9H3WnvE4=; b=DogAhyT/I46EM811UjWAxV7nk9+EdtE8qegtvrzLSPFv64iEJv4jgUif4+8BEMGeDU Vyi9PQ/l+JCF9Kyp/QbscnlaGblYpVwkLCzzOOM/wQQt9EhaZpQgBVExFghmXEhxo/wt afVEZDFSbAhhvDdYYu+CRDSZetS64yRQgH4r0LqAyAk+7pmE/2vpqUk8i+zuCR83rRtR NL4zMrEBMr78l1r5WJT1MO+F2QNGjSGZRfThT0tiziOSD98fqv9SOT4Ogfa2gSujw2HG XZbz5T0Mu0mPFgVrFnXkZHi0VKot8t9l4OgFp04BwWvITklfti62Pg13gYAv3uJxe2YT Bwbw== X-Gm-Message-State: ACrzQf0yNEWfT2kQeunwNKOExLT9IIJo34eCYhUR8+175qWSu5+p5QZj REakb1lktE5+uXpjVDLaDV9EfA== X-Google-Smtp-Source: AMsMyM6Ha442SkRQ6wKXMX6e1qRe1PBeZzv9qyIqdVkVOMiMZugJD0MtKhgFiqaiyI1c30RP7vQhzg== X-Received: by 2002:a63:1a53:0:b0:44d:e5ba:5acf with SMTP id a19-20020a631a53000000b0044de5ba5acfmr7673606pgm.461.1664856306515; Mon, 03 Oct 2022 21:05:06 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 127-20020a621585000000b0056179d750efsm2665145pfv.103.2022.10.03.21.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 21:05:05 -0700 (PDT) Date: Mon, 3 Oct 2022 21:05:04 -0700 From: Kees Cook To: "Edgecombe, Rick P" Cc: "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "dave.hansen@linux.intel.com" , "kirill.shutemov@linux.intel.com" , "Eranian, Stephane" , "linux-mm@kvack.org" , "fweimer@redhat.com" , "nadav.amit@gmail.com" , "jannh@google.com" , "dethoma@microsoft.com" , "linux-arch@vger.kernel.org" , "kcc@google.com" , "bp@alien8.de" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "Yang, Weijiang" , "Lutomirski, Andy" , "pavel@ucw.cz" , "arnd@arndb.de" , "Moreira, Joao" , "tglx@linutronix.de" , "mike.kravetz@oracle.com" , "x86@kernel.org" , "linux-doc@vger.kernel.org" , "jamorris@linux.microsoft.com" , "john.allen@amd.com" , "rppt@kernel.org" , "mingo@redhat.com" , "Shankar, Ravi V" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" Subject: Re: [PATCH v2 06/39] x86/fpu: Add helper for modifying xstate Message-ID: <202210032104.A1029D23@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-7-rick.p.edgecombe@intel.com> <202210031045.419F7DB396@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664856307; a=rsa-sha256; cv=none; b=Tv43pe29KqjKY+4XKIiYoP4BQRMa43nvk7qEIIT0JSzABqkdZPUP2ZWwPoYK35ZWlks8mV Qxoaq6s6fuBZW5i1+mY2WpX7HQVEXDzehFQuF8wY2H6mhi67jRAn6KY6ZFGPkYRhEWYiAl 6NsreNss/kNdwlaBknKd4urRoEPwd68= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=as3TWS6v; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.174 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664856307; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rlkPZtF7+K01teV+qG5sp8ViMTTB6RT0WVQ9H3WnvE4=; b=fLvKfjSICU5Dg2IJcvb/OzGbxExcwQs64NIZHJu7zQnlPsVh1IM7eF3mUQR1lRU3k4bECj pAdGJwWD+ksvl8ZD7O/256OEXK1+CtGdwF941AU25nzpnRk8WzmWebLBrHlugAMI75pNf5 cJOUIxaP4hazrrZqdvt9DqWKS+DU4ts= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7380D80012 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=as3TWS6v; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.174 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: n8378mheg98oshb74fzyyxn3nonu7qzh X-HE-Tag: 1664856307-444303 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: On Mon, Oct 03, 2022 at 08:05:13PM +0000, Edgecombe, Rick P wrote: > On Mon, 2022-10-03 at 10:48 -0700, Kees Cook wrote: > > > The easiest way to modify supervisor xfeature data is to force > > > restore > > > the registers and write directly to the MSRs. Often times this is > > > just fine > > > anyway as the registers need to be restored before returning to > > > userspace. > > > Do this for now, leaving buffer writing optimizations for the > > > future. > > > > Just for my own clarity, does this mean lock/load _needs_ to happen > > before MSR access, or is it just a convenient place to do it? From > > later > > patches it seems it's a requirement during MSR access, which might be > > a > > good idea to detail here. It answers the question "when is this > > function > > needed?" > > The CET state is xsaves managed. It gets lazily restored before > returning to userspace with the rest of the fpu stuff. This function > will force restore all the fpu state to the registers early and lock > them from being automatically saved/restored. Then the tasks CET state > can be modified in the MSRs, before unlocking the fpregs. Last time I > tried to modify the state directly in the xsave buffer when it was > efficient, but it had issues and Thomas suggested this. Okay, gotcha. Thanks! -- Kees Cook