Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1521491pxb; Wed, 20 Oct 2021 06:47:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFph07Q6Tf9L2Naf114rxaj6MJUEeTjxZMUo3OJTJniLdCht2w/L20itJldNBNBYmr7wAa X-Received: by 2002:a17:902:82cb:b0:13f:99af:921d with SMTP id u11-20020a17090282cb00b0013f99af921dmr28308889plz.79.1634737677446; Wed, 20 Oct 2021 06:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634737677; cv=none; d=google.com; s=arc-20160816; b=yqr+9QZEn10tB0FbIAtvfUaCO1eJBJUULkNgarEDjL+X5DGDWTCODjnSy0KLZfFjMc EwojqWNy+2HTPZg3p8HLryj+dPChlpbJ9WNVLueIVE5jBb5Cc5FkpqFFbFOSigfRZUws XQ7KgVLEIKbrbEWL0XeD1tI0lAxMxNDgg7e0VeT9xVXEKl/uC0WXL17lYnJtISuR1JVz sJ5zSITQxI0KPz8QMfmoJZ25Kx52QtpfDptwhOoFD/84naG0QBOLSMTlBrlG2tQdDZtX BnhIQijmZGlwdVOmygv5l0nm3/8MeC/1dHtzLB1S2y4a6KsxOYwovzy45miYhk9PfaXn hKDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=aoDvuqZuXvNzCvNxUgVT3AHSokgyRhu0AKYTEBirvak=; b=DwuYXEYg+dSKnnOlFGzFe8YwQ4qNEDxIuy3qOsIshkCqy9tLFCQ5mxeY86XpnIC/lr 9bzMMtlAQUHVvNXRSuWc5xxxw7FvhSz6Ho7oe3GtSS3oz2AqpUW0MW3ivUVdgbgv5Ayi SUDktjWZoYoWHv8iWbbVKOoyGOibYvqOrBB5xgT+hdLH3fwuzIamVegQBD0A+XMdxMh4 cOhkanmCrqX/X4Z2XpV3AglPhVkZGz6DtRVhcuR6tRdpxCGNK1N05j7EeGcq4AX4e2Sh nvVoijgimLJTc0klgav1YlVB7YEjqQpWFI37jlmJGcIcxmOi4UpXj/LxW1gvtnBgJ+jR CDYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r5Vu3Sa+; dkim=neutral (no key) header.i=@linutronix.de header.b="D/AJc5OC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pc8si3330690pjb.18.2021.10.20.06.47.43; Wed, 20 Oct 2021 06:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r5Vu3Sa+; dkim=neutral (no key) header.i=@linutronix.de header.b="D/AJc5OC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbhJTNsH (ORCPT + 99 others); Wed, 20 Oct 2021 09:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbhJTNrD (ORCPT ); Wed, 20 Oct 2021 09:47:03 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3FECC061755; Wed, 20 Oct 2021 06:44:39 -0700 (PDT) Date: Wed, 20 Oct 2021 13:44:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1634737478; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoDvuqZuXvNzCvNxUgVT3AHSokgyRhu0AKYTEBirvak=; b=r5Vu3Sa+Cgz7sgFvsafckwT5gALOKFxBbCxksFh0FfXAxgGv1GvKagANaTtUSfmwCbeNya K41beRY4ntKR+tUc2WEPUehghHLyc8YLTeBpWBPJYfBfNb7crBc0aNHf3pCA/4boBRiEYc kBiIAtgopYDnJErAWrRVxc1kIjTteMOmE8mu91DoJM6zoxxGPXLr+ZxFtvzxPWAYJQXWov tddx/qGa+JX54kAJ0yycS8z0qEgnn6ej57KiwbVWipPYfekxTy1fo2EACNcS4WAnAv5b+R WJiPIoOMnxBN/GIN7Jz/t2qLH40TR7LVXdF7q9L9e6jS38U46xwGFezl1ToxQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1634737478; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoDvuqZuXvNzCvNxUgVT3AHSokgyRhu0AKYTEBirvak=; b=D/AJc5OC55Lllc/f0dP2bT3FyXV19ekp3nGq8svUCaL6GG1SzNBAREnWPA5/B3oVy1s9it BdGYuBbdi5NgVUAA== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fpu] x86/fpu: Rework copy_xstate_to_uabi_buf() Cc: Thomas Gleixner , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20211015011539.191902137@linutronix.de> References: <20211015011539.191902137@linutronix.de> MIME-Version: 1.0 Message-ID: <163473747755.25758.4060031587900668086.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/fpu branch of tip: Commit-ID: ca834defd33bae9cf9542ff92b15635a84e91946 Gitweb: https://git.kernel.org/tip/ca834defd33bae9cf9542ff92b15635a84e91946 Author: Thomas Gleixner AuthorDate: Fri, 15 Oct 2021 03:16:15 +02:00 Committer: Borislav Petkov CommitterDate: Wed, 20 Oct 2021 15:27:27 +02:00 x86/fpu: Rework copy_xstate_to_uabi_buf() Prepare for replacing the KVM copy xstate to user function by extending copy_xstate_to_uabi_buf() with a pkru argument which allows the caller to hand in the pkru value, which is required for KVM because the guest PKRU is not accessible via current. Fixup all callsites accordingly. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20211015011539.191902137@linutronix.de --- arch/x86/kernel/fpu/xstate.c | 34 ++++++++++++++++++++++++++-------- arch/x86/kernel/fpu/xstate.h | 3 +++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index eeeb807..b2537a8 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -940,9 +940,10 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate, } /** - * copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer + * __copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer * @to: membuf descriptor - * @tsk: The task from which to copy the saved xstate + * @xsave: The xsave from which to copy + * @pkru_val: The PKRU value to store in the PKRU component * @copy_mode: The requested copy mode * * Converts from kernel XSAVE or XSAVES compacted format to UABI conforming @@ -951,11 +952,10 @@ static void copy_feature(bool from_xstate, struct membuf *to, void *xstate, * * It supports partial copy but @to.pos always starts from zero. */ -void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk, - enum xstate_copy_mode copy_mode) +void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, + u32 pkru_val, enum xstate_copy_mode copy_mode) { const unsigned int off_mxcsr = offsetof(struct fxregs_state, mxcsr); - struct xregs_state *xsave = &tsk->thread.fpu.state.xsave; struct xregs_state *xinit = &init_fpstate.xsave; struct xstate_header header; unsigned int zerofrom; @@ -1033,10 +1033,9 @@ void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk, struct pkru_state pkru = {0}; /* * PKRU is not necessarily up to date in the - * thread's XSAVE buffer. Fill this part from the - * per-thread storage. + * XSAVE buffer. Use the provided value. */ - pkru.pkru = tsk->thread.pkru; + pkru.pkru = pkru_val; membuf_write(&to, &pkru, sizeof(pkru)); } else { copy_feature(header.xfeatures & BIT_ULL(i), &to, @@ -1056,6 +1055,25 @@ out: membuf_zero(&to, to.left); } +/** + * copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer + * @to: membuf descriptor + * @tsk: The task from which to copy the saved xstate + * @copy_mode: The requested copy mode + * + * Converts from kernel XSAVE or XSAVES compacted format to UABI conforming + * format, i.e. from the kernel internal hardware dependent storage format + * to the requested @mode. UABI XSTATE is always uncompacted! + * + * It supports partial copy but @to.pos always starts from zero. + */ +void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk, + enum xstate_copy_mode copy_mode) +{ + __copy_xstate_to_uabi_buf(to, &tsk->thread.fpu.state.xsave, + tsk->thread.pkru, copy_mode); +} + static int copy_from_buffer(void *dst, unsigned int offset, unsigned int size, const void *kbuf, const void __user *ubuf) { diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 0789a04..81f4202 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -15,4 +15,7 @@ static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask) xsave->header.xcomp_bv = mask | XCOMP_BV_COMPACTED_FORMAT; } +extern void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsave, + u32 pkru_val, enum xstate_copy_mode copy_mode); + #endif