From patchwork Tue Nov 15 23:09:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 20629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2987378wru; Tue, 15 Nov 2022 15:14:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5wSPfbfoSWWNCdl3lPQlB6WFxNMKmFQNjyR9kJp2dEUBQmUhg1M62dSU6e+hcavVbv2p/6 X-Received: by 2002:a17:90a:d595:b0:213:f8a9:356c with SMTP id v21-20020a17090ad59500b00213f8a9356cmr628079pju.224.1668554085479; Tue, 15 Nov 2022 15:14:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668554085; cv=none; d=google.com; s=arc-20160816; b=uSG42aoWGEc2W2RuuCrpyx8crHcZGaC3i4xSVnhMvrDkSo9jg/aAakefdHH45O7fKV FKyz8QLx2GBiynFJE6nQIu9MHEXjNtubono8xJxpV388Ek4edTD3U3L0fkQNe1nnzFk1 GdG7k7Z9c2CbxYb8iGb3Wm0pU/fy4H5bZCMMRQ+hOQ2rs18fmFjU8uBf9hGCaedMKwI6 a2uWTlzd1AuebZ+gUMvBaJrPhoAgov+LC1Jb75Ub+n3LX/Etp/TbPeNN3DZTXI62SBcp ch4dCxusIwxOYjQd9OMlmLRWTjI2jbf6+RKqqNVkfo5Y0rV8EMqI5+nL9pgrUKF0QO5y oAgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IkcqOwsa0mNg6ehrFGqMru8FrDdXrPVN26VUHl2O8Uk=; b=TbjKBvR10iDG4ZT26kxZz2ouktPrcswWIvRThPxBuNGT7TFyJm4vPunTra5vavBcCO vDhhm6sCsHMtr+xkoOd36xRGggKpNvgv7BDQbdUAkCKfG1/BxyqAIP4DFQYSCK5k/U4H H/WmfY1etHpGk0movoErGvJFNiWbasBVA6YrppczR5ZvdOeWVMFVKiuwa7e3emEbIKgD d/jkRcDVSkeO8M+QKJZP0KUvjEyRL1+NuCyp+X6FMjwm9Ew8I0zQ7R3jZu4WbJtJaKwP HMkcpsxjxuS3b0KTNevuDjbQSawCniB8VtknsEefnAIib2stPKx7rnc5UymmAqgSz1Z+ q6pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=COkajg1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a170903019100b00183243c7a2dsi15369353plg.406.2022.11.15.15.14.31; Tue, 15 Nov 2022 15:14:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=COkajg1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231578AbiKOXMQ (ORCPT + 99 others); Tue, 15 Nov 2022 18:12:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238530AbiKOXLh (ORCPT ); Tue, 15 Nov 2022 18:11:37 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640422B611 for ; Tue, 15 Nov 2022 15:11:36 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so625219pjk.1 for ; Tue, 15 Nov 2022 15:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IkcqOwsa0mNg6ehrFGqMru8FrDdXrPVN26VUHl2O8Uk=; b=COkajg1xfIWppQNgvV1yPMUIBGJNDsN7XOZhgcmUBNkuQT5h7POGLw7aCrSgOJf1TM fi7NPk3zvATxjZv2bNJcrHavWcRc2UgJAIP6OCemRQn3b/U6IWlcE7pn+5h1em+rNTul dzS9rv2/1ApGIHuka4h6ZnT7Kkg/TNMxfv+hcGk4Brs4h4vfyIqc/JprwgljCNFZg+/x 3nAyLM4Y+r/cslbUQ7jeW+L9I4aGcWyK0cnm1r5cbcnQtlYkw/v6LwqzmcrfBRb9dOQH Vos5+xpdw5OowrlXFlUM6umMxnMY9+Y3UBnE2eqKNCAOLOgVeg0qKEGNs0Bv4+m4ydV6 QivA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IkcqOwsa0mNg6ehrFGqMru8FrDdXrPVN26VUHl2O8Uk=; b=pfPyQG0aM63uE+qNHBQ29hewMivwjK9bBfuw438S/P4KjmmDSP39mtIUoiwhU3LWjn wDYA04ClkOQypfxGznCahEPzmUgdpx78MrfENUJGUXNXwBaijpMXe5MlQqINbn+bDBUA IZ15dlRr9iBTba3Eqmbz0VfRC3LPmFhXUePUZSw+uyW+QuvbC1Bc3CEF8wGfvpHWtTFX IIwq6TIf3BfNjp8W6H911UQLHTRuo2Izl0hQLNnlxxrNu45B0VGA4DDSbn1cbdG1Uvti IaMlO1Vk+TmV9F748HI4kdwswXBd3jeWvUiRZBf3WMkejOXWdccNheMHbB4+jFqUaPIu 12Ag== X-Gm-Message-State: ANoB5plkur5kBOjL47YjRvukJJuiK5rpM5FPIzi0KfqjCvZHqIoml7rA +/d5C4PzIDqxBv29fqMJruCYAw== X-Received: by 2002:a17:902:8c8d:b0:17f:73d6:4375 with SMTP id t13-20020a1709028c8d00b0017f73d64375mr6208515plo.24.1668553896035; Tue, 15 Nov 2022 15:11:36 -0800 (PST) Received: from minbar.home.kylehuey.com (c-71-198-251-229.hsd1.ca.comcast.net. [71.198.251.229]) by smtp.gmail.com with ESMTPSA id f15-20020a62380f000000b0056c360af4e3sm9308372pfa.9.2022.11.15.15.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 15:11:35 -0800 (PST) From: Kyle Huey X-Google-Original-From: Kyle Huey To: Dave Hansen Cc: Linus Torvalds , Thomas Gleixner , Borislav Petkov , Ingo Molnar , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Robert O'Callahan , David Manouchehri , Kyle Huey Subject: [PATCH v7 3/6] x86/fpu: Add a pkru argument to copy_uabi_to_xstate() Date: Tue, 15 Nov 2022 15:09:29 -0800 Message-Id: <20221115230932.7126-4-khuey@kylehuey.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115230932.7126-1-khuey@kylehuey.com> References: <20221115230932.7126-1-khuey@kylehuey.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749605769132999202?= X-GMAIL-MSGID: =?utf-8?q?1749605769132999202?= In preparation for moving PKRU handling code out of fpu_copy_uabi_to_guest_fpstate() and into copy_uabi_to_xstate(), add an argument that copy_uabi_from_kernel_to_xstate() can use to pass the canonical location of the PKRU value. For copy_sigframe_from_user_to_xstate() the kernel will actually restore the PKRU value from the fpstate, but pass in the thread_struct's pkru location anyways for consistency. Signed-off-by: Kyle Huey --- arch/x86/kernel/fpu/xstate.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index a4d24ae66796..3a6ced76e932 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1200,8 +1200,18 @@ static int copy_from_buffer(void *dst, unsigned int offset, unsigned int size, } +/** + * copy_uabi_to_xstate - Copy a UABI format buffer to the kernel xstate + * @fpstate: The fpstate buffer to copy to + * @kbuf: The UABI format buffer, if it comes from the kernel + * @ubuf: The UABI format buffer, if it comes from userspace + * @pkru: unused + * + * Converts from the UABI format into the kernel internal hardware + * dependent format. + */ static int copy_uabi_to_xstate(struct fpstate *fpstate, const void *kbuf, - const void __user *ubuf) + const void __user *ubuf, u32 *pkru) { struct xregs_state *xsave = &fpstate->regs.xsave; unsigned int offset, size; @@ -1270,7 +1280,7 @@ static int copy_uabi_to_xstate(struct fpstate *fpstate, const void *kbuf, */ int copy_uabi_from_kernel_to_xstate(struct fpstate *fpstate, const void *kbuf, u32 *pkru) { - return copy_uabi_to_xstate(fpstate, kbuf, NULL); + return copy_uabi_to_xstate(fpstate, kbuf, NULL, pkru); } /* @@ -1281,7 +1291,7 @@ int copy_uabi_from_kernel_to_xstate(struct fpstate *fpstate, const void *kbuf, u int copy_sigframe_from_user_to_xstate(struct task_struct *tsk, const void __user *ubuf) { - return copy_uabi_to_xstate(tsk->thread.fpu.fpstate, NULL, ubuf); + return copy_uabi_to_xstate(tsk->thread.fpu.fpstate, NULL, ubuf, &tsk->thread.pkru); } static bool validate_independent_components(u64 mask)