From patchwork Tue Jun 22 22:24:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 12338679 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_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 C31DBC49EA4 for ; Tue, 22 Jun 2021 22:25:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4F88D61352 for ; Tue, 22 Jun 2021 22:25:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F88D61352 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 F12E16B006C; Tue, 22 Jun 2021 18:25:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEAA96B006E; Tue, 22 Jun 2021 18:25:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD9196B0070; Tue, 22 Jun 2021 18:25:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id 9F5E56B006C for ; Tue, 22 Jun 2021 18:25:46 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CCD161ADB8 for ; Tue, 22 Jun 2021 22:25:46 +0000 (UTC) X-FDA: 78282793092.35.4CD4CF3 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf23.hostedemail.com (Postfix) with ESMTP id 273B7A0021EA for ; Tue, 22 Jun 2021 22:25:43 +0000 (UTC) IronPort-SDR: bo30JXU97N6atmDzKxTeIhhrAVFwcyrv6QsZn9wEzOpfnDz6yNQHTnTZk7BOF9YjVJZVn4zgoQ iPJQshizaQxw== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="187534845" X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="187534845" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 15:25:40 -0700 IronPort-SDR: 9Vo/oWFEeuu5HZhoFInXkcDeivD8e9SylwhJZyH+7PDnYEmPFYOWmcaX3QBwlEowsZEAF5cB7h Az3yixY2F1YQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="473922775" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga004.fm.intel.com with ESMTP; 22 Jun 2021 15:25:40 -0700 Subject: [RFC][PATCH 0/8] x86/pkeys: remove PKRU from kernel XSAVE buffer 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:55 -0700 Message-Id: <20210622222455.E901B5AC@viggo.jf.intel.com> Authentication-Results: imf23.hostedemail.com; dkim=none; spf=none (imf23.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: 273B7A0021EA X-Stat-Signature: uf6wok9t3pz5adszo8xa3o95m616epeu X-HE-Tag: 1624400743-580435 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: This is a rework of the kernel's Protection Keys Register code. It severs the connection between PKRU and XSAVE as thoroughly as possible without affecting the existing ABIs. This compiles in a few configurations and passes the pkeys selftest, but that's about it. It's not been pummeled enough yet for merging anywhere. This is on top of the current: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git x86/fpu specifically: 3d168301c78d ("x86/fpu/signal: Let xrstor handle the features to init") --- PKRU is currently a strange beast. It can be XSAVE-managed and it has space allocated in the thread 'fpstate' buffer. However, it is switched more eagerly than other FPU state because PKRU affects things like copy_to/from_user(). This is because PKRU affects user *PERMISSION* accesses, not just accesses made from user *MODE* itself. This leaves PKRU in a very odd position. It is stored in the kernel XSAVE buffer but the XSAVE architecture is not used to manage it. Move PKRU out of the 'fpstate' buffer. Instead, allocate space in the thread_struct for it and save/restore it in the context-switch path separately from the XSAVE-managed features. This removes the ambiguity of having PKRU state in two places for each task. include/asm/fpu/internal.h | 2 - include/asm/fpu/xstate.h | 2 - include/asm/pkru.h | 10 +++-- kernel/cpu/common.c | 19 +++++++++- kernel/fpu/core.c | 8 ++-- kernel/fpu/signal.c | 12 +++++- kernel/fpu/xstate.c | 83 ++++++++++++++++++++++++++++++--------------- kernel/process_64.c | 9 ++-- kernel/signal.c | 1 kvm/x86.c | 8 ++-- mm/pkeys.c | 21 ++--------- 11 files changed, 113 insertions(+), 62 deletions(-) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski