From patchwork Tue Jun 22 22:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 12338685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EADA3C49EA5 for ; Tue, 22 Jun 2021 22:25:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9808D613B0 for ; Tue, 22 Jun 2021 22:25:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9808D613B0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E6FC6B0070; Tue, 22 Jun 2021 18:25:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F11736B0071; Tue, 22 Jun 2021 18:25:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA3846B0072; Tue, 22 Jun 2021 18:25:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 7D6696B0071 for ; Tue, 22 Jun 2021 18:25:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B1850180397D6 for ; Tue, 22 Jun 2021 22:25:47 +0000 (UTC) X-FDA: 78282793134.08.A361655 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf26.hostedemail.com (Postfix) with ESMTP id 29B7740002E4 for ; Tue, 22 Jun 2021 22:25:44 +0000 (UTC) IronPort-SDR: OcktdInwEbLXyiMwQcZri9OOVyfNDddUuoo/eQdUqmLMG8dYZcDWmEZ5Xbd/ACZ4PwQJ0zPuMK dOkTs55EFk2w== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="187534850" X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="187534850" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 15:25:44 -0700 IronPort-SDR: l/2YXcZIURD4o4Mz8p7B9GgFYO6mzupeXtmpv8/Lii3Yi7ndbLUqPRyV4pM9pjUFP/Z5jhG50m 6atJVNRTCPfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="444756931" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga007.jf.intel.com with ESMTP; 22 Jun 2021 15:25:43 -0700 Subject: [RFC][PATCH 2/8] x86/fpu: hook up PKRU into signal user ABIs To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org,Dave Hansen ,tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,x86@kernel.org,luto@kernel.org From: Dave Hansen Date: Tue, 22 Jun 2021 15:24:59 -0700 References: <20210622222455.E901B5AC@viggo.jf.intel.com> In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com> Message-Id: <20210622222459.9C76B034@viggo.jf.intel.com> Authentication-Results: imf26.hostedemail.com; dkim=none; spf=none (imf26.hostedemail.com: domain of dave.hansen@linux.intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=dave.hansen@linux.intel.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 29B7740002E4 X-Stat-Signature: 7zd1oq5pjsnt36nfpwsuku94coauxxa3 X-HE-Tag: 1624400744-415619 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: From: Dave Hansen One nice thing about having PKRU be XSAVE-managed is that it gets naturally exposed into the XSAVE-using ABIs. Now that XSAVE will not be used to manage PKRU, these ABIs need to be manually enabled to deal with PKRU. For signals (the restore_hwregs_from_user() path), it's quite straightforward. restore_hwregs_from_user() will update PKRU in from the user signal buffer. Ensure that PKRU is shuffled into the thread storage. Signed-off-by: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski --- b/arch/x86/kernel/fpu/signal.c | 7 +++++++ 1 file changed, 7 insertions(+) diff -puN arch/x86/kernel/fpu/signal.c~fpu-sig-stash-pkru arch/x86/kernel/fpu/signal.c --- a/arch/x86/kernel/fpu/signal.c~fpu-sig-stash-pkru 2021-06-22 14:49:07.899051760 -0700 +++ b/arch/x86/kernel/fpu/signal.c 2021-06-22 14:49:07.903051760 -0700 @@ -233,6 +233,13 @@ static int restore_hwregs_from_user(void if (!ret && unlikely(init_bv)) os_xrstor(&init_fpstate.xsave, init_bv); + + /* + * PKRU may have been modified by XRSTOR, + * save the possibly updated value: + */ + current->thread.pkru = read_pkru(); + return ret; } else if (use_fxsr()) { return fxrstor_from_user_sigframe(buf);