From patchwork Sun Jan 30 21:18:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 12730157 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 AB90DC433EF for ; Sun, 30 Jan 2022 21:22:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B90576B00B5; Sun, 30 Jan 2022 16:22:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B2D3E6B00B7; Sun, 30 Jan 2022 16:22:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 992636B00B8; Sun, 30 Jan 2022 16:22:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 8515E6B00B5 for ; Sun, 30 Jan 2022 16:22:09 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 43CC695295 for ; Sun, 30 Jan 2022 21:22:09 +0000 (UTC) X-FDA: 79088226378.15.07CC77A Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf16.hostedemail.com (Postfix) with ESMTP id A1899180004 for ; Sun, 30 Jan 2022 21:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577728; x=1675113728; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=AKky5ODZPWXr+Y60awjhLEp8vC5Ov5UFi7xn02fKIeA=; b=BS1SE8yxQbMUjI+hN9oxic1spgFdmETJ0HnV6S3nkuNriOvmgIgovzP4 gDaWJcQaEroJtv5rNlTPjBMXLBSahkTmRE5hRnC/C39uyjv5vaIMc1sMK ZhN8tsauSnVHpS4i/dMO9sqyClOINlsvijEpiv1ZRHaRxNzypVDZ++jvk u5jXwMqK/dxT9UXvsP2zDGcrAvRZGSQO8EI+hPA8dINR72T7TsVvhyxJe kTi57jqAb6vbbsqbEQyO1xwXGHNUvdBaih81I/tbwOsyR8LiY3RnqZLli paf2rFKJDbQgYDis6Z1Y2zhYuPOCEMrEH7CeDdL6P1jhMI1SMR9Z0QH++ Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="244970226" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="244970226" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:08 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856924" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:07 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , 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 , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH 27/35] x86/fpu: Add unsafe xsave buffer helpers Date: Sun, 30 Jan 2022 13:18:30 -0800 Message-Id: <20220130211838.8382-28-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=BS1SE8yx; spf=none (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: nil X-Rspamd-Queue-Id: A1899180004 X-Stat-Signature: zufjex1xqr5odwweqe9b6rsua93zat5p X-Rspamd-Server: rspam12 X-HE-Tag: 1643577728-482436 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: CET will need to modify the xsave buffer of a new FPU that was just created in the process of copying a thread. In this case the normal helpers will not work, because they operate on the current thread's FPU. So add unsafe helpers to allow for this kind of modification. Make the unsafe helpers operate on the MSR like the safe helpers for symmetry and to avoid exposing the underling xsave structures. Don't add a read helper because it is not needed at this time. Signed-off-by: Rick Edgecombe --- arch/x86/include/asm/fpu/api.h | 9 ++++++--- arch/x86/kernel/fpu/xstate.c | 27 ++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index 6aec27984b62..5cb557b9d118 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -167,7 +167,10 @@ extern long fpu_xstate_prctl(struct task_struct *tsk, int option, unsigned long void *start_update_xsave_msrs(int xfeature_nr); void end_update_xsave_msrs(void); -int xsave_rdmsrl(void *state, unsigned int msr, unsigned long long *p); -int xsave_wrmsrl(void *state, u32 msr, u64 val); -int xsave_set_clear_bits_msrl(void *state, u32 msr, u64 set, u64 clear); +int xsave_rdmsrl(void *xstate, unsigned int msr, unsigned long long *p); +int xsave_wrmsrl(void *xstate, u32 msr, u64 val); +int xsave_set_clear_bits_msrl(void *xstate, u32 msr, u64 set, u64 clear); + +void *get_xsave_buffer_unsafe(struct fpu *fpu, int xfeature_nr); +int xsave_wrmsrl_unsafe(void *xstate, u32 msr, u64 val); #endif /* _ASM_X86_FPU_API_H */ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 25b1b0c417fd..71b08026474c 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1881,6 +1881,17 @@ static u64 *__get_xsave_member(void *xstate, u32 msr) } } +/* + * Operate on the xsave buffer directly. It makes no gaurantees that the + * buffer will stay valid now or in the futre. This function is pretty + * much only useful when the caller knows the fpu's thread can't be + * scheduled or otherwise operated on concurrently. + */ +void *get_xsave_buffer_unsafe(struct fpu *fpu, int xfeature_nr) +{ + return get_xsave_addr(&fpu->fpstate->regs.xsave, xfeature_nr); +} + /* * Return a pointer to the xstate for the feature if it should be used, or NULL * if the MSRs should be written to directly. To do this safely, using the @@ -1971,14 +1982,11 @@ int xsave_rdmsrl(void *xstate, unsigned int msr, unsigned long long *p) return 0; } -int xsave_wrmsrl(void *xstate, u32 msr, u64 val) + +int xsave_wrmsrl_unsafe(void *xstate, u32 msr, u64 val) { u64 *member_ptr; - __xsave_msrl_prepare_write(); - if (!xstate) - return wrmsrl_safe(msr, val); - member_ptr = __get_xsave_member(xstate, msr); if (!member_ptr) return 1; @@ -1988,6 +1996,15 @@ int xsave_wrmsrl(void *xstate, u32 msr, u64 val) return 0; } +int xsave_wrmsrl(void *xstate, u32 msr, u64 val) +{ + __xsave_msrl_prepare_write(); + if (!xstate) + return wrmsrl_safe(msr, val); + + return xsave_wrmsrl_unsafe(xstate, msr, val); +} + int xsave_set_clear_bits_msrl(void *xstate, u32 msr, u64 set, u64 clear) { u64 val, new_val;