Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp694079pxb; Thu, 21 Apr 2022 08:23:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9XF6Nfq/PjsuV7hr5uUFFaZI+n2d75WUKD26okTsVAUwQ183M1nU3fmS+8O/hVoL7FWki X-Received: by 2002:a17:90b:2685:b0:1cb:6521:dd78 with SMTP id pl5-20020a17090b268500b001cb6521dd78mr192951pjb.194.1650554595114; Thu, 21 Apr 2022 08:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650554595; cv=none; d=google.com; s=arc-20160816; b=u5eOTShcTADHq3gkYcjveT9MeElQW/JEyoUDRv/a5xmUXC+ejDBceoWY1jRzDFuI0l CYRLlK5D7V/0CxIFhdHKKhUFdGBsaV6shGkHbD+qm1Tr5rv0grb8B2ZJRMs1NPHxHc4l dn/+43woF87q+Eo3btDeTTTj/DWxuuP5sK44KdjRCI+TJbEmHQj2YdA0KxypgPrFCBbL 4nt6Fs3PGP8hTbJUMPtW+XtVoqr6S+Zgfhgvp7uy4aZlWWE54r7E8YDkEyQNRbMpuAQf B2Iq25D5QsfEmAQ/Ryh0j0Kl27hvnARIWL9eUAzQ417V/ibdynxw29hBkzBv9xX1J0ox 4q+Q== 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=MF+7qROFoEOvzyRK5hVUBGkBczRRTYInOgZkYwFL3HI=; b=UhmJwFhDUp1KkIXGVucqShKp/Z5Qp+ENiJBPq4a8aMbz1V1iuLpob8Mzaoz91kZSEZ +ncWgI7VIqbQ9xtKs3wApqPIPcDY+uJ35zylJX+HLtharwuNR8OkXoXDyO1FiBeQ5E6Z a1fSpjIKSmNpPBim76HD4hYJEUfiTFFQXaCDcRVKfkibcwUnYpp3OCZJdRIqVQcU4zsE LUr5fdbbiXxxqoqPXybmrFxLhlnWgwu0vLdstEiRcVhYz0R9CnxQ/FXaPR6XH3ZGeySq dRpdm/CTxbl0Hp4qAohZocMyejQ/fNsSnVGXNpehnyXsvCqI+6TgCHRBwte/zDSZONO2 46JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NQtt8JdM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mq3-20020a17090b380300b001d2843013ddsi10034556pjb.50.2022.04.21.08.22.58; Thu, 21 Apr 2022 08:23:15 -0700 (PDT) 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=@intel.com header.s=Intel header.b=NQtt8JdM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355606AbiDSRKj (ORCPT + 99 others); Tue, 19 Apr 2022 13:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355596AbiDSRJr (ORCPT ); Tue, 19 Apr 2022 13:09:47 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783A95F59 for ; Tue, 19 Apr 2022 10:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650388021; x=1681924021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPfCwCLIhEO1e+fi1mrejHCAQdkmQVhrehDTb7JigWc=; b=NQtt8JdMpk2xQL8r4FzslBkss92fWgqoV1bQfymgJSeYNkL/ctxuFgrr wNYHRc5hkNsbNh21U4hvsN5ZT1Pu7FB8yspUxk42YNGulugGdXGmb2+Ct bwOsVbigJd1zA6Elszk+ICEkLu4/apDAcHAqD/h+NFSafDreqRV14d5IZ 4W2kMUDOKi8XIzOl9eSEdkHRWQYGtM51A8t7zixvfkEYaPMdHGVu95m/K j77HHe6FC/TSKV2kwAS+wdSSUs8wrFKYsgLP5wKBrIsOkp8i4zHBRBOKR 07x/7rDgtN+36rDr32jlPbXoGS1fskam8YL8CppWKfU1Cw7tbnkNiQNFA A==; X-IronPort-AV: E=McAfee;i="6400,9594,10322"; a="251123589" X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="251123589" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:01 -0700 X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="727145527" Received: from ajacosta-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.11.4]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:00 -0700 From: ira.weiny@intel.com To: Dave Hansen , "H. Peter Anvin" , Dan Williams Cc: Ira Weiny , Fenghua Yu , Rick Edgecombe , "Shankar, Ravi V" , linux-kernel@vger.kernel.org Subject: [PATCH V10 11/44] mm/pkeys: Define PKS page table macros Date: Tue, 19 Apr 2022 10:06:16 -0700 Message-Id: <20220419170649.1022246-12-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220419170649.1022246-1-ira.weiny@intel.com> References: <20220419170649.1022246-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 From: Fenghua Yu Kernel PKS consumers will need a way to assign their pkey to pages. Define _PAGE_PKEY() and PAGE_KERNEL_PKEY() to allow users to set a pkey on a PTE. Add documentation. Co-developed-by: Ira Weiny Signed-off-by: Ira Weiny Signed-off-by: Fenghua Yu --- Changes for V9 From Dave Hansen s/PKey/pkey Changes for V8 Split out from the 'Add PKS kernel API' patch Include documentation in this patch --- Documentation/core-api/protection-keys.rst | 6 ++++++ arch/x86/include/asm/pgtable_types.h | 22 ++++++++++++++++++++++ include/linux/pgtable.h | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/Documentation/core-api/protection-keys.rst b/Documentation/core-api/protection-keys.rst index d501bd27ee29..fe63acf5abbe 100644 --- a/Documentation/core-api/protection-keys.rst +++ b/Documentation/core-api/protection-keys.rst @@ -136,3 +136,9 @@ PKS Key Allocation ------------------ .. kernel-doc:: include/linux/pks-keys.h :doc: PKS_KEY_ALLOCATION + +Adding pages to a pkey protected domain +--------------------------------------- + +.. kernel-doc:: arch/x86/include/asm/pgtable_types.h + :doc: PKS_KEY_ASSIGNMENT diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 40497a9020c6..e1d4535b525e 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -71,6 +71,22 @@ _PAGE_PKEY_BIT2 | \ _PAGE_PKEY_BIT3) +/** + * DOC: PKS_KEY_ASSIGNMENT + * + * The following macros are used to set a pkey value in a supervisor PTE. + * + * .. code-block:: c + * + * #define _PAGE_KEY(pkey) + * #define PAGE_KERNEL_PKEY(pkey) + */ +#ifdef CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS +#define _PAGE_PKEY(pkey) (_AT(pteval_t, pkey) << _PAGE_BIT_PKEY_BIT0) +#else +#define _PAGE_PKEY(pkey) (_AT(pteval_t, 0)) +#endif + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) #define _PAGE_KNL_ERRATUM_MASK (_PAGE_DIRTY | _PAGE_ACCESSED) #else @@ -226,6 +242,12 @@ enum page_cache_mode { #define PAGE_KERNEL_IO __pgprot_mask(__PAGE_KERNEL_IO) #define PAGE_KERNEL_IO_NOCACHE __pgprot_mask(__PAGE_KERNEL_IO_NOCACHE) +#ifdef CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS +#define PAGE_KERNEL_PKEY(pkey) __pgprot_mask(__PAGE_KERNEL | _PAGE_PKEY(pkey)) +#else +#define PAGE_KERNEL_PKEY(pkey) PAGE_KERNEL +#endif + #endif /* __ASSEMBLY__ */ /* xwr */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index f4f4077b97aa..bcef6b306fcb 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1511,6 +1511,10 @@ static inline bool arch_has_pfn_modify_check(void) # define PAGE_KERNEL_EXEC PAGE_KERNEL #endif +#ifndef PAGE_KERNEL_PKEY +#define PAGE_KERNEL_PKEY(pkey) PAGE_KERNEL +#endif + /* * Page Table Modification bits for pgtbl_mod_mask. * -- 2.35.1