Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3017pxb; Mon, 31 Jan 2022 03:49:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIn5om/35vPafL+NjN7U2uqKt7UrL6wc8lbP3smtBR1yozK5OlBCrIvBYV7Wxxyt/t3KPi X-Received: by 2002:a63:5146:: with SMTP id r6mr16166303pgl.455.1643629780509; Mon, 31 Jan 2022 03:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643629780; cv=none; d=google.com; s=arc-20160816; b=PnjgpW9stQwz5C9i1SVC8ufYW/Hawsao0RIGEi/Fs6PhXrXdxqzVgmVz/BMN4WP1CL 4joVVbRtDlGcjZD1xIZSBu+/PJmIP1bkNSdf6euVNc42Uf71u7WuvOTnw/pqdUzWfyno QFfKhq/N9In2h2brFhDXQu6b3bQ/TS8t9wIZt2RlEnXnYWxRJK6Ia5mplq2TlZtQt4oc 0fKR4u92BUxSQcbcBiWj/cKifEHfZcWsfU+P+/n73E+u4OEw0Sp3d0gtDjqiN2mB/5Lq yHMA6smmHFC44XQ0uKzUu5KG8oX9UWTRHRNDIQ9Tsa2Tej/X4CTKdqliR1/AFZtonW2a P7vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=RuYA1ywlmMZcQ1T7YGGwqSrj/mz1glyEx1HPIY+fZCM=; b=KYB4JPq85beTXSIb5fHxAW59UQLEZxV8RG9oNlE5LhrAL/0Vwoa9lnxnAvrUvbBlJy cN9zyBzhyB8+V0zecRtUCj6W+ia7J/5x4Re36jj0KakoWu8msshapPyhoJWbRoegW4LM mDhYGMigKIXdCg76HU6NTYeupTZp4+fWJYUXSCrjbBKyJ1VqnPBFiUiDgKF3+ukEIOim FZZcduhadXFZX/sKE1zOzMUdpOJsIm17C1Bjx8ntpa2cAvpF4s/+deaJ7F4oIeBFn54v 6Cv5cj951uDsjgSgNOx5vodWcbE3PbKZ6id2lNOZbMzu0BpaJFlmTERdLymroT2eZ0qt 75VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ghpDxoVk; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si13740211pfj.221.2022.01.31.03.49.29; Mon, 31 Jan 2022 03:49:40 -0800 (PST) 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=@intel.com header.s=Intel header.b=ghpDxoVk; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344507AbiA1XlG (ORCPT + 99 others); Fri, 28 Jan 2022 18:41:06 -0500 Received: from mga06.intel.com ([134.134.136.31]:42619 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbiA1XlE (ORCPT ); Fri, 28 Jan 2022 18:41:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643413264; x=1674949264; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nf2qFgTJ6fU4pbmhpPpUz4DEKZhXCEzLYp+lk4cBfBw=; b=ghpDxoVk8dWi1gn0nqeUFD6khzIp3E3x5JmZ4WwOPh0hmYvbsukHp4ly p5BPA57DKpfY+e6ckeWA39UjU+rU/7b410s2FnlmiXodHw/Qc+buK9pxd tHlcn8U6ngtyV/mnNNfBUr5zLNPZLX62GbQim0+6iKiPEaEChxhxhiTEG mPvpT61xbApC45/4Lkk4L3djl5meSyBfVnvuek7LekEjiRTxVSZXnKuvG bq1EdR5AKlF/rNpiqmeAdnoEd8C2tBo6TK04L/6IihmyNwNi6sMhnCQcG uqXWbs/fItEnY06mb5MNW/SxeDMw9hQ/i+GFeJKQByy+pZ5juUQSUaYRl g==; X-IronPort-AV: E=McAfee;i="6200,9189,10241"; a="307947244" X-IronPort-AV: E=Sophos;i="5.88,325,1635231600"; d="scan'208";a="307947244" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 15:41:04 -0800 X-IronPort-AV: E=Sophos;i="5.88,325,1635231600"; d="scan'208";a="536332950" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 15:41:03 -0800 Date: Fri, 28 Jan 2022 15:41:03 -0800 From: Ira Weiny To: Dave Hansen Cc: Dave Hansen , "H. Peter Anvin" , Dan Williams , Fenghua Yu , Rick Edgecombe , linux-kernel@vger.kernel.org Subject: Re: [PATCH V8 09/44] x86/pkeys: Enable PKS on cpus which support it Message-ID: <20220128234103.GL785175@iweiny-DESK2.sc.intel.com> References: <20220127175505.851391-1-ira.weiny@intel.com> <20220127175505.851391-10-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1 (2018-12-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 28, 2022 at 03:18:29PM -0800, Dave Hansen wrote: > On 1/27/22 09:54, ira.weiny@intel.com wrote: > > Protection Keys for Supervisor pages (PKS) enables fast, hardware thread > > specific, manipulation of permission restrictions on supervisor page > > mappings. It uses the same mechanism of Protection Keys as those on > > User mappings but applies that mechanism to supervisor mappings using a > > supervisor specific MSR. > > > > Bit 24 of CR4 is used to enable the feature by software. Define > > pks_setup() to be called when PKS is configured. > > Again, no need to specify the bit numbers. We have it in the code. :) > At most, just say something like: > > PKS is enabled by a new bit in a control register. > or > PKS is enabled by a new bit in CR4. > > > Initially, pks_setup() initializes the per-cpu MSR with 0 to enable all > > access on all pkeys. > > Why not just make it restrictive to start out? That's what we do for PKU. This maintains compatibility with the code prior to this patch. Ie no restrictions on kernel mappings. I'll place the default value patch before this one and use it in this patch. > > > asm/pks.h is added as a new file to store new > > internal functions and structures such as pks_setup(). > > One writing nit: try to speak in active voice. > > Passive: "Foo is added" > Active: "Add foo" > > It actually makes thing shorter and easier to read: > > Add asm/pks.h to store new internal functions and structures > such as pks_setup(). Ok. I'll update the commit message. > > > diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h > > index bcba3c643e63..191c574b2390 100644 > > --- a/arch/x86/include/uapi/asm/processor-flags.h > > +++ b/arch/x86/include/uapi/asm/processor-flags.h > > @@ -130,6 +130,8 @@ > > #define X86_CR4_SMAP _BITUL(X86_CR4_SMAP_BIT) > > #define X86_CR4_PKE_BIT 22 /* enable Protection Keys support */ > > #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) > > +#define X86_CR4_PKS_BIT 24 /* enable Protection Keys for Supervisor */ > > +#define X86_CR4_PKS _BITUL(X86_CR4_PKS_BIT) > > > > /* > > * x86-64 Task Priority Register, CR8 > > diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c > > index 7b8382c11788..83c1abce7d93 100644 > > --- a/arch/x86/kernel/cpu/common.c > > +++ b/arch/x86/kernel/cpu/common.c > > @@ -59,6 +59,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "cpu.h" > > > > @@ -1632,6 +1633,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) > > > > x86_init_rdrand(c); > > setup_pku(c); > > + pks_setup(); > > > > /* > > * Clear/Set all flags overridden by options, need do it > > diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c > > index cf12d8bf122b..02629219e683 100644 > > --- a/arch/x86/mm/pkeys.c > > +++ b/arch/x86/mm/pkeys.c > > @@ -206,3 +206,19 @@ u32 pkey_update_pkval(u32 pkval, int pkey, u32 accessbits) > > pkval &= ~(PKEY_ACCESS_MASK << shift); > > return pkval | accessbits << shift; > > } > > + > > +#ifdef CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS > > + > > +/* > > + * PKS is independent of PKU and either or both may be supported on a CPU. > > + */ > > +void pks_setup(void) > > +{ > > + if (!cpu_feature_enabled(X86_FEATURE_PKS)) > > + return; > > + > > + wrmsrl(MSR_IA32_PKRS, 0); > > This probably needs a one-line comment about what it's doing. As a > general rule, I'd much rather have a one-sentence note in a code comment > than in the changelog. Fair enough, Ira > > > + cr4_set_bits(X86_CR4_PKS); > > +} > > + > > +#endif /* CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS */ >